Java Code Examples for com.intellij.util.ui.UIUtil#findComponentOfType()

The following examples show how to use com.intellij.util.ui.UIUtil#findComponentOfType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ComboBox.java    From consulo with Apache License 2.0 6 votes vote down vote up
public ComboBox(final ComboBoxModel model, final int width) {
  super(model);
  myMinimumAndPreferredWidth = width;
  registerCancelOnEscape();
  UIUtil.installComboBoxCopyAction(this);
  final JButton arrowButton = UIUtil.findComponentOfType(this, JButton.class);
  if (arrowButton != null) {
    arrowButton.addMouseListener(new MouseAdapter() {
      @Override
      public void mousePressed(MouseEvent e) {
        if (!mySwingPopup) {
          e.consume();
          setPopupVisible(true);
        }
      }
    });
  }
}
 
Example 2
Source File: FavoritesViewSelectInTarget.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static ActionCallback select(@Nonnull Project project, Object toSelect, VirtualFile virtualFile, boolean requestFocus) {
  final ActionCallback result = new ActionCallback();

  ToolWindowManager windowManager = ToolWindowManager.getInstance(project);
  final ToolWindow favoritesToolWindow = windowManager.getToolWindow(ToolWindowId.FAVORITES_VIEW);

  if (favoritesToolWindow != null) {
    final Runnable runnable = () -> {
      final FavoritesTreeViewPanel panel = UIUtil.findComponentOfType(favoritesToolWindow.getComponent(), FavoritesTreeViewPanel.class);
      if (panel != null) {
        panel.selectElement(toSelect, virtualFile, requestFocus);
        result.setDone();
      }
    };

    if (requestFocus) {
      favoritesToolWindow.activate(runnable, false);
    }
    else {
      favoritesToolWindow.show(runnable);
    }
  }

  return result;
}
 
Example 3
Source File: DarculaComboBoxUI.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void unconfigureEditor() {
  super.unconfigureEditor();

  if (editorKeyListener != null) {
    editor.removeKeyListener(editorKeyListener);
  }

  if (editor instanceof JTextComponent) {
    if (editorFocusListener != null) {
      editor.removeFocusListener(editorFocusListener);
    }
  }
  else {
    EditorTextField etf = UIUtil.findComponentOfType((JComponent)editor, EditorTextField.class);
    if (etf != null) {
      if (editorFocusListener != null) {
        etf.removeFocusListener(editorFocusListener);
      }
    }
  }
}
 
Example 4
Source File: ToolbarDecorator.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static AnActionButton findButton(JComponent comp, CommonActionsPanel.Buttons type) {
  final CommonActionsPanel panel = UIUtil.findComponentOfType(comp, CommonActionsPanel.class);
  if (panel != null) {
    return panel.getAnActionButton(type);
  }
  //noinspection ConstantConditions
  return null;
}
 
Example 5
Source File: IdeGlassPaneImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean isContextMenu(Window window) {
  if (window != null) {
    for (Component component : window.getComponents()) {
      if (component instanceof JComponent && UIUtil.findComponentOfType((JComponent)component, JPopupMenu.class) != null) {
        return true;
      }
    }
  }
  return false;
}
 
Example 6
Source File: DarculaComboBoxUI.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected PropertyChangeListener createPropertyListener() {
  return e -> {
    if ("enabled".equals(e.getPropertyName())) {
      EditorTextField etf = UIUtil.findComponentOfType((JComponent)editor, EditorTextField.class);
      if (etf != null) {
        boolean enabled = e.getNewValue() == Boolean.TRUE;
        Color color = UIManager.getColor(enabled ? "TextField.background" : "ComboBox.disabledBackground");
        etf.setBackground(color);
      }
    }
  };
}
 
Example 7
Source File: DarculaSpinnerBorder.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
  final JSpinner spinner = (JSpinner)c;
  final JFormattedTextField editor = UIUtil.findComponentOfType(spinner, JFormattedTextField.class);
  final int x1 = x + JBUI.scale(3);
  final int y1 = y + JBUI.scale(3);
  final int width1 = width - JBUI.scale(8);
  final int height1 = height - JBUI.scale(6);
  final boolean focused = c.isEnabled() && c.isVisible() && editor != null && editor.hasFocus();
  final GraphicsConfig config = GraphicsUtil.setupAAPainting(g);

  if (c.isOpaque()) {
    g.setColor(UIUtil.getPanelBackground());
    g.fillRect(x, y, width, height);
  }

  g.setColor(UIUtil.getTextFieldBackground());
  g.fillRoundRect(x1, y1, width1, height1, JBUI.scale(5), JBUI.scale(5));
  g.setColor(UIUtil.getPanelBackground());
  if (editor != null) {
    final int off = editor.getBounds().x + editor.getWidth() + ((JSpinner)c).getInsets().left + JBUI.scale(1);
    g.fillRect(off, y1, JBUI.scale(17), height1);
    g.setColor(Gray._100);
    g.drawLine(off, y1, off, height1 + JBUI.scale(2));
  }

  if (!c.isEnabled()) {
    ((Graphics2D)g).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f));
  }

  if (focused) {
    DarculaUIUtil.paintFocusRing(g, new Rectangle(x1, y1, width1, height1));
  }
  else {
    g.setColor(Gray._100);
    g.drawRoundRect(x1, y1, width1, height1, JBUI.scale(5), JBUI.scale(5));
  }
  config.restore();
}
 
Example 8
Source File: RemoteServersViewImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static ServersToolWindowContent getServersViewComponent(ToolWindow toolWindow) {
  //todo[nik] register ServersToolWindowContent as project service?
  return UIUtil.findComponentOfType(toolWindow.getComponent(), ServersToolWindowContent.class);
}
 
Example 9
Source File: EditorMouseHoverPopupManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
public DocumentationComponent getDocumentationComponent() {
  AbstractPopup hint = getCurrentHint();
  return hint == null ? null : UIUtil.findComponentOfType(hint.getComponent(), DocumentationComponent.class);
}
 
Example 10
Source File: DarculaComboBoxUI.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
protected void configureEditor() {
  super.configureEditor();

  installEditorKeyListener(comboBox.getEditor());
  if (editor instanceof JComponent) {
    JComponent jEditor = (JComponent)editor;
    jEditor.setOpaque(false);
    jEditor.setBorder(JBUI.Borders.empty());

    editorFocusListener = new FocusAdapter() {
      @Override
      public void focusGained(FocusEvent e) {
        update();
      }

      @Override
      public void focusLost(FocusEvent e) {
        update();
      }

      private void update() {
        if (comboBox != null) {
          comboBox.repaint();
        }
      }
    };

    if (editor instanceof JTextComponent) {
      editor.addFocusListener(editorFocusListener);
    }
    else {
      EditorTextField etf = UIUtil.findComponentOfType((JComponent)editor, EditorTextField.class);
      if (etf != null) {
        etf.addFocusListener(editorFocusListener);
        Color c = UIManager.getColor(comboBox.isEnabled() ? "TextField.background" : "ComboBox.disabledBackground");
        etf.setBackground(c);
      }
    }
  }

  if (Registry.is("ide.ui.composite.editor.for.combobox")) {
    // BasicComboboxUI sets focusability depending on the combobox focusability.
    // JPanel usually is unfocusable and uneditable.
    // It could be set as an editor when people want to have a composite component as an editor.
    // In such cases we should restore unfocusable state for panels.
    if (editor instanceof JPanel) {
      editor.setFocusable(false);
    }
  }
}
 
Example 11
Source File: ModernSpinnerBorder.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
  final JSpinner spinner = (JSpinner)c;
  final JFormattedTextField editor = UIUtil.findComponentOfType(spinner, JFormattedTextField.class);
  final int x1 = x + JBUI.scale(3);
  final int y1 = y + JBUI.scale(3);
  final int width1 = width - JBUI.scale(8);
  final int height1 = height - JBUI.scale(6);
  final GraphicsConfig config = GraphicsUtil.setupAAPainting(g);

  if (c.isOpaque()) {
    g.setColor(UIUtil.getPanelBackground());
    g.fillRect(x, y, width, height);
  }

  g.setColor(UIUtil.getTextFieldBackground());
  g.fillRoundRect(x1, y1, width1, height1, JBUI.scale(5), JBUI.scale(5));
  g.setColor(UIUtil.getPanelBackground());
  if (editor != null) {
    final int off = editor.getBounds().x + editor.getWidth() + ((JSpinner)c).getInsets().left + JBUI.scale(1);
    g.fillRect(off, y1, JBUI.scale(17), height1);
    g.setColor(Gray._100);
    g.drawLine(off, y1, off, height1 + JBUI.scale(2));
  }

  if (!c.isEnabled()) {
    ((Graphics2D)g).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f));
  }

  ComponentUI componentUI = ModernUIUtil.getUI(c);
  if (componentUI instanceof ModernTextBorder.ModernTextUI) {
    if (((ModernTextBorder.ModernTextUI)componentUI).isFocused()) {
      g.setColor(ModernUIUtil.getSelectionBackground());
    }
    else if (((ModernTextBorder.ModernTextUI)componentUI).getMouseEnterHandler().isMouseEntered()) {
      g.setColor(ModernUIUtil.getActiveBorderColor());
    }
    else {
      g.setColor(ModernUIUtil.getDisabledBorderColor());
    }
  }
  else {
    g.setColor(ModernUIUtil.getActiveBorderColor());
  }
  g.drawRect(x1, y1, width1, height1);
  config.restore();
}