Java Code Examples for com.intellij.openapi.actionSystem.impl.ActionButton

The following examples show how to use com.intellij.openapi.actionSystem.impl.ActionButton. These examples are extracted from open source projects. 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 Project: consulo   Source File: SearchTextArea.java    License: Apache License 2.0 6 votes vote down vote up
public List<Component> setExtraActions(AnAction... actions) {
  myExtraActionsPanel.removeAll();
  myExtraActionsPanel.setBorder(JBUI.Borders.empty());
  ArrayList<Component> addedButtons = new ArrayList<>();
  if (actions != null && actions.length > 0) {
    JPanel buttonsGrid = new NonOpaquePanel(new GridLayout(1, actions.length, 0, 0));
    for (AnAction action : actions) {
      ActionButton button = new MyActionButton(action, true);
      addedButtons.add(button);
      buttonsGrid.add(button);
    }
    myExtraActionsPanel.setLayout(new BorderLayout());
    myExtraActionsPanel.add(buttonsGrid, BorderLayout.NORTH);
    myExtraActionsPanel.setBorder(new CompoundBorder(JBUI.Borders.customLine(JBUI.CurrentTheme.CustomFrameDecorations.separatorForeground(), 0, 1, 0, 0), JBUI.Borders.emptyLeft(4)));
  }
  return addedButtons;
}
 
Example 2
Source Project: consulo   Source File: RunAnythingAction.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public JComponent createCustomComponent(@Nonnull Presentation presentation, @Nonnull String place) {
  return new ActionButton(this, presentation, place, ActionToolbar.DEFAULT_MINIMUM_BUTTON_SIZE) {

    @Nullable
    @Override
    protected String getShortcutText() {
      if (myIsDoubleCtrlRegistered) {
        return IdeBundle.message("run.anything.double.ctrl.shortcut", SystemInfo.isMac ? FontUtil.thinSpace() + MacKeymapUtil.CONTROL : "Ctrl");
      }
      //keymap shortcut is added automatically
      return null;
    }

    @Override
    public void setToolTipText(String s) {
      String shortcutText = getShortcutText();
      super.setToolTipText(StringUtil.isNotEmpty(shortcutText) ? (s + " (" + shortcutText + ")") : s);
    }
  };
}
 
Example 3
Source Project: consulo   Source File: SearchEverywhereAction.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public JComponent createCustomComponent(Presentation presentation, String place) {
  return new ActionButton(this, presentation, place, ActionToolbar.DEFAULT_MINIMUM_BUTTON_SIZE) {
    @Override
    protected void updateToolTipText() {
      String shortcutText = getShortcut();

      if (Registry.is("ide.helptooltip.enabled")) {
        HelpTooltip.dispose(this);

        new HelpTooltip().setTitle(myPresentation.getText()).setShortcut(shortcutText).setDescription("Searches for:<br/> - Classes<br/> - Files<br/> - Tool Windows<br/> - Actions<br/> - Settings")
                .installOn(this);
      }
      else {
        setToolTipText("<html><body>Search Everywhere<br/>Press <b>" + shortcutText + "</b> to access<br/> - Classes<br/> - Files<br/> - Tool Windows<br/> - Actions<br/> - Settings</body></html>");
      }
    }
  };
}
 
Example 4
Source Project: consulo   Source File: DarculaActionButtonUI.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void paintBackground(ActionButton button, Graphics g, Dimension size, int state) {
  if (state == ActionButtonComponent.NORMAL && !button.isBackgroundSet()) return;

  Rectangle rect = new Rectangle(button.getSize());
  JBInsets.removeFrom(rect, button.getInsets());

  Color color = state == ActionButtonComponent.PUSHED ? JBUI.CurrentTheme.ActionButton.pressedBackground() : JBUI.CurrentTheme.ActionButton.hoverBackground();
  Graphics2D g2 = (Graphics2D)g.create();

  try {
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
    g2.setColor(color);

    float arc = DarculaUIUtil.BUTTON_ARC.getFloat();
    g2.fill(new RoundRectangle2D.Float(rect.x, rect.y, rect.width, rect.height, arc, arc));
  }
  finally {
    g2.dispose();
  }
}
 
Example 5
Source Project: consulo   Source File: ActionButtonUI.java    License: Apache License 2.0 6 votes vote down vote up
private int getMnemonicCharIndex(ActionButton button, AnAction action, String text) {
  final int mnemonicIndex = button.getPresentation().getDisplayedMnemonicIndex();
  if (mnemonicIndex != -1) {
    return mnemonicIndex;
  }
  final ShortcutSet shortcutSet = action.getShortcutSet();
  final Shortcut[] shortcuts = shortcutSet.getShortcuts();
  for (int i = 0; i < shortcuts.length; i++) {
    Shortcut shortcut = shortcuts[i];
    if (shortcut instanceof KeyboardShortcut) {
      KeyboardShortcut keyboardShortcut = (KeyboardShortcut)shortcut;
      if (keyboardShortcut.getSecondKeyStroke() == null) { // we are interested only in "mnemonic-like" shortcuts
        final KeyStroke keyStroke = keyboardShortcut.getFirstKeyStroke();
        final int modifiers = keyStroke.getModifiers();
        if ((modifiers & KeyEvent.ALT_MASK) != 0) {
          return (keyStroke.getKeyChar() != KeyEvent.CHAR_UNDEFINED)
                 ? text.indexOf(keyStroke.getKeyChar())
                 : text.indexOf(KeyEvent.getKeyText(keyStroke.getKeyCode()));
        }
      }
    }
  }
  return -1;
}
 
Example 6
Source Project: consulo   Source File: ActionButtonUI.java    License: Apache License 2.0 6 votes vote down vote up
private void paintDefaultButton(Graphics g, ActionButton c) {
  int state = c.getPopState();

  paintBackground(c, g, c.getSize(), state);
  if(!c.isWithoutBorder()) {
    paintBorder(c, g, c.getSize(), state);
  }
  paintIcon(g, c, c.getIcon());

  if (c.shallPaintDownArrow()) {
    int x = JBUI.scale(5);
    int y = JBUI.scale(4);

    if (state == ActionButtonComponent.PUSHED) {
      x += JBUI.scale(1);
      y += JBUI.scale(1);
    }

    AllIcons.General.Dropdown.paintIcon(c, g, x, y);
  }
}
 
Example 7
Source Project: consulo   Source File: ActionButtonUI.java    License: Apache License 2.0 6 votes vote down vote up
public void paintBorder(ActionButton button, Graphics g, Dimension size, int state) {
  if (state == ActionButtonComponent.NORMAL && !button.isBackgroundSet()) return;

  if (UIUtil.isUnderAquaLookAndFeel()) {
    if (state == ActionButtonComponent.POPPED) {
      g.setColor(ALPHA_30);
      g.drawRoundRect(0, 0, size.width - 2, size.height - 2, 4, 4);
    }
  }
  else {
    final double shift = UIUtil.isUnderDarcula() ? 1 / 0.49 : 0.49;
    g.setColor(ColorUtil.shift(UIUtil.getPanelBackground(), shift));
    ((Graphics2D)g).setStroke(BASIC_STROKE);
    final GraphicsConfig config = GraphicsUtil.setupAAPainting(g);
    g.drawRoundRect(0, 0, size.width - JBUI.scale(2), size.height - JBUI.scale(2), JBUI.scale(4), JBUI.scale(4));
    config.restore();
  }
}
 
Example 8
/**
 * Constructor used when have to fall back to inspect an AWT event instead of actions that are directly provided
 * by IDEA. Tool-window stripe buttons are such a case where I'm not notified by IDEA if one is pressed
 *
 * @param event mouse event that happened
 */
KeyPromoterAction(AWTEvent event) {
  final Object source = event.getSource();
  if (source instanceof ActionButton) {
    analyzeActionButton((ActionButton) source);
  } else if (source instanceof StripeButton) {
    analyzeStripeButton((StripeButton) source);
  } else if (source instanceof ActionMenuItem) {
    analyzeActionMenuItem((ActionMenuItem) source);
  } else if (source instanceof JButton) {
    analyzeJButton((JButton) source);
  }

}
 
Example 9
/**
 * Information extraction for buttons on the toolbar
 *
 * @param source source of the action
 */
private void analyzeActionButton(ActionButton source) {
  final AnAction action = source.getAction();
  if (action != null) {
    fixValuesFromAction(action);
  }
  mySource = ActionSource.MAIN_TOOLBAR;
}
 
Example 10
/**
 * Finds the button while refreshing over the toolbar.
 * <p>
 * Due to IJ refresh policy (will only refresh if it detects mouse movement over its window),
 * the toolbar needs to be intermittently updated before the ActionButton moves to the target
 * location and update to its final state.
 */
@NotNull
private ActionButtonFixture findActionButtonWithRefresh(@NotNull String actionId, boolean enabled) {
  Ref<ActionButtonFixture> fixtureRef = new Ref<>();
  Wait.seconds(30)
    .expecting("button to enable")
    .until(() -> {
      updateToolbars();
      // Actions can somehow get replaced, so we need to re-get the action when we attempt to check its state.
      ActionButtonFixture fixture = locateActionButtonByActionId(actionId);
      fixtureRef.set(fixture);
      if (hasValidWindowAncestor(fixture.target())) {
        return execute(new GuiQuery<Boolean>() {
          @Nullable
          @Override
          protected Boolean executeInEDT() {
            if (WindowAncestorFinder.windowAncestorOf(fixture.target()) != null) {
              ActionButton button = fixture.target();
              AnAction action = button.getAction();
              Presentation presentation = action.getTemplatePresentation();
              return presentation.isEnabledAndVisible() &&
                     button.isEnabled() == enabled &&
                     button.isShowing() &&
                     button.isVisible();
            }
            return false;
          }
        });
      }

      return false;
    });
  return fixtureRef.get();
}
 
Example 11
@NotNull
public IdeSettingsDialogFixture invokeSdkManager() {
  ActionButton sdkButton = waitUntilShowingAndEnabled(robot(), target(), new GenericTypeMatcher<ActionButton>(ActionButton.class) {
    @Override
    protected boolean isMatching(@NotNull ActionButton actionButton) {
      return "SDK Manager".equals(actionButton.getAccessibleContext().getAccessibleName());
    }
  });
  robot().click(sdkButton);
  return IdeSettingsDialogFixture.find(robot());
}
 
Example 12
Source Project: consulo   Source File: DesktopEditorAnalyzeStatusPanel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void addLayoutComponent(String s, Component component) {
  JComponent jc = (JComponent)component;
  if (ActionToolbar.CUSTOM_COMPONENT_CONSTRAINT.equals(s) && jc instanceof StatusButton) {
    statusComponent = jc;
  }
  else if (ActionToolbar.ACTION_BUTTON_CONSTRAINT.equals(s) && jc instanceof ActionButton) {
    actionButtons.add(jc);
  }
}
 
Example 13
Source Project: consulo   Source File: DesktopEditorAnalyzeStatusPanel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void removeLayoutComponent(Component component) {
  JComponent jc = (JComponent)component;
  if (jc instanceof StatusButton) {
    statusComponent = null;
  }
  else if (jc instanceof ActionButton) {
    actionButtons.remove(jc);
  }
}
 
Example 14
Source Project: consulo   Source File: DaemonTooltipWithActionRenderer.java    License: Apache License 2.0 5 votes vote down vote up
private JComponent createSettingsComponent(HintHint hintHint, TooltipReloader reloader, boolean hasMore, boolean newLayout) {
  Presentation presentation = new Presentation();
  presentation.setIcon(AllIcons.Actions.More);
  presentation.putClientProperty(ActionButton.HIDE_DROPDOWN_ICON, true);

  List<AnAction> actions = new ArrayList<>();
  actions.add(new ShowActionsAction(reloader, tooltipAction != null));
  ShowDocAction docAction = new ShowDocAction(reloader, hasMore);
  actions.add(docAction);
  AnAction actionGroup = new SettingsActionGroup(actions);
  int buttonSize = newLayout ? 20 : 18;

  ActionButton settingsButton = new ActionButton(actionGroup, presentation, ActionPlaces.UNKNOWN, new Dimension(buttonSize, buttonSize));

  settingsButton.setNoIconsInPopup(true);
  settingsButton.setBorder(JBUI.Borders.empty());
  settingsButton.setOpaque(false);

  JPanel wrapper = new JPanel(new BorderLayout());

  wrapper.add(settingsButton, BorderLayout.EAST);

  wrapper.setBorder(JBUI.Borders.empty());

  wrapper.setBackground(hintHint.getTextBackground());

  wrapper.setOpaque(false);

  return wrapper;
}
 
Example 15
Source Project: consulo   Source File: ArrangementListRowDecorator.java    License: Apache License 2.0 5 votes vote down vote up
public ArrangementListRowDecorator(@Nonnull ArrangementUiComponent delegate,
                                   @Nonnull ArrangementMatchingRulesControl control)
{
  myDelegate = delegate;
  myControl = control;

  mySortLabel.setVisible(false);

  AnAction action = ActionManager.getInstance().getAction("Arrangement.Rule.Edit");
  Presentation presentation = action.getTemplatePresentation().clone();
  Icon editIcon = presentation.getIcon();
  Dimension buttonSize = new Dimension(editIcon.getIconWidth(), editIcon.getIconHeight());
  myEditButton = new ActionButton(action, presentation, ArrangementConstants.MATCHING_RULES_CONTROL_PLACE, buttonSize);
  myEditButton.setVisible(false);

  FontMetrics metrics = getFontMetrics(getFont());
  int maxWidth = 0;
  for (int i = 0; i <= 99; i++) {
    maxWidth = Math.max(metrics.stringWidth(String.valueOf(i)), maxWidth);
  }
  int height = metrics.getHeight() - metrics.getDescent() - metrics.getLeading();
  int diameter = Math.max(maxWidth, height) * 5 / 3;
  myRowIndexControl = new ArrangementRuleIndexControl(diameter, height);

  setOpaque(true);
  init();
}
 
Example 16
Source Project: consulo   Source File: ShowMoreOptions.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(@Nonnull AnActionEvent e) {
  final ActionButton secondaryActions = myToolbarComponent.getSecondaryActionsButton();
  if (secondaryActions != null) {
    secondaryActions.click();
  }
}
 
Example 17
Source Project: consulo   Source File: SetTodoFilterAction.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public JComponent createCustomComponent(Presentation presentation) {
  ActionButton button = new ActionButton(
          this,
          presentation,
          ActionPlaces.TODO_VIEW_TOOLBAR,
          ActionToolbar.DEFAULT_MINIMUM_BUTTON_SIZE
  );
  presentation.putClientProperty("button", button);
  return button;
}
 
Example 18
Source Project: consulo   Source File: DarculaActionButtonUI.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void paintBorder(ActionButton button, Graphics g, Dimension size, int state) {
  if (state == ActionButtonComponent.NORMAL && !button.isBackgroundSet()) return;

  Rectangle rect = new Rectangle(button.getSize());
  JBInsets.removeFrom(rect, button.getInsets());

  Graphics2D g2 = (Graphics2D)g.create();
  g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);

  try {
    Color color = state == ActionButtonComponent.PUSHED ? JBUI.CurrentTheme.ActionButton.pressedBorder() : JBUI.CurrentTheme.ActionButton.hoverBorder();

    g2.setColor(color);

    float arc = DarculaUIUtil.BUTTON_ARC.getFloat();
    float lw = DarculaUIUtil.LW.getFloat();
    Path2D border = new Path2D.Float(Path2D.WIND_EVEN_ODD);
    border.append(new RoundRectangle2D.Float(rect.x, rect.y, rect.width, rect.height, arc, arc), false);
    border.append(new RoundRectangle2D.Float(rect.x + lw, rect.y + lw, rect.width - lw * 2, rect.height - lw * 2, arc - lw, arc - lw), false);

    g2.fill(border);
  }
  finally {
    g2.dispose();
  }
}
 
Example 19
Source Project: consulo   Source File: ActionButtonUI.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void paint(Graphics g, JComponent c) {
  if(c instanceof ActionButtonWithText) {
    paintTextButton(g, (ActionButtonWithText)c);
  }
  else {
    paintDefaultButton(g, (ActionButton)c);
  }
}
 
Example 20
Source Project: consulo   Source File: ActionButtonUI.java    License: Apache License 2.0 5 votes vote down vote up
public void paintBackground(ActionButton button, Graphics g, Dimension size, int state) {
  if (state == ActionButtonComponent.NORMAL && !button.isBackgroundSet()) return;

  if (UIUtil.isUnderAquaLookAndFeel()) {
    if (state == ActionButtonComponent.PUSHED) {
      ((Graphics2D)g).setPaint(UIUtil.getGradientPaint(0, 0, ALPHA_40, size.width, size.height, ALPHA_20));
      g.fillRect(0, 0, size.width - 1, size.height - 1);

      g.setColor(ALPHA_120);
      g.drawLine(0, 0, 0, size.height - 2);
      g.drawLine(1, 0, size.width - 2, 0);

      g.setColor(ALPHA_30);
      g.drawRect(1, 1, size.width - 3, size.height - 3);
    }
    else if (state == ActionButtonComponent.POPPED) {
      ((Graphics2D)g).setPaint(UIUtil.getGradientPaint(0, 0, Gray._235, 0, size.height, Gray._200));
      g.fillRect(1, 1, size.width - 3, size.height - 3);
    }
  }
  else {
    final Color bg = UIUtil.getPanelBackground();
    final boolean dark = UIUtil.isUnderDarcula();
    g.setColor(state == ActionButtonComponent.PUSHED ? ColorUtil.shift(bg, dark ? 1d / 0.7d : 0.7d) : dark ? Gray._255.withAlpha(40) : ALPHA_40);
    g.fillRect(JBUI.scale(1), JBUI.scale(1), size.width - JBUI.scale(2), size.height - JBUI.scale(2));
  }
}
 
Example 21
Source Project: consulo   Source File: ModernActionButtonUI.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void paintBorder(ActionButton button, Graphics g, Dimension size, int state) {
  if (state == ActionButtonComponent.NORMAL && !button.isBackgroundSet()) return;

  final GraphicsConfig config = GraphicsUtil.setupAAPainting(g);
  g.setColor(state == ActionButtonComponent.POPPED || state == ActionButtonComponent.PUSHED
             ? ModernUIUtil.getSelectionBackground()
             : ModernUIUtil.getBorderColor(button));
  RectanglePainter2D.DRAW.paint((Graphics2D)g, 0, 0, size.getWidth(), size.getHeight());
  config.restore();
}
 
Example 22
Source Project: consulo   Source File: ModernActionButtonUI.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void paintBackground(ActionButton button, Graphics g, Dimension size, int state) {
  if (state == ActionButtonComponent.PUSHED) {
    g.setColor(ColorUtil.toAlpha(ModernUIUtil.getSelectionBackground(), 100));
    RectanglePainter2D.FILL.paint((Graphics2D)g, 0, 0, size.getWidth(), size.getHeight());
  }
}
 
Example 23
@NotNull
public ActionButtonFixture findAttachDebuggerToAndroidProcessButton() {
  GenericTypeMatcher<ActionButton> matcher = Matchers.byText(ActionButton.class, "Attach Debugger to Android Process").andIsShowing();
  return ActionButtonFixture.findByMatcher(matcher, robot(), target());
}
 
Example 24
Source Project: consulo   Source File: LookupUi.java    License: Apache License 2.0 4 votes vote down vote up
LookupUi(@Nonnull LookupImpl lookup, Advertiser advertiser, JBList list) {
  myLookup = lookup;
  myAdvertiser = advertiser;
  myList = list;

  myProcessIcon.setVisible(false);
  myLookup.resort(false);

  MenuAction menuAction = new MenuAction();
  menuAction.add(new ChangeSortingAction());
  menuAction.add(new DelegatedAction(ActionManager.getInstance().getAction(IdeActions.ACTION_QUICK_JAVADOC)) {
    @Override
    public void update(@Nonnull AnActionEvent e) {
      e.getPresentation().setVisible(!CodeInsightSettings.getInstance().AUTO_POPUP_JAVADOC_INFO);
    }
  });
  menuAction.add(new DelegatedAction(ActionManager.getInstance().getAction(IdeActions.ACTION_QUICK_IMPLEMENTATIONS)));

  Presentation presentation = new Presentation();
  presentation.setIcon(AllIcons.Actions.More);
  presentation.putClientProperty(ActionButton.HIDE_DROPDOWN_ICON, Boolean.TRUE);

  myMenuButton = new ActionButton(menuAction, presentation, ActionPlaces.EDITOR_POPUP, ActionToolbar.NAVBAR_MINIMUM_BUTTON_SIZE);

  AnAction hintAction = new HintAction();
  myHintButton = new ActionButton(hintAction, hintAction.getTemplatePresentation(), ActionPlaces.EDITOR_POPUP, ActionToolbar.NAVBAR_MINIMUM_BUTTON_SIZE);
  myHintButton.setVisible(false);

  myBottomPanel = new NonOpaquePanel(new LookupBottomLayout());
  myBottomPanel.add(myAdvertiser.getAdComponent());
  myBottomPanel.add(myProcessIcon);
  myBottomPanel.add(myHintButton);
  myBottomPanel.add(myMenuButton);

  LookupLayeredPane layeredPane = new LookupLayeredPane();
  layeredPane.mainPanel.add(myBottomPanel, BorderLayout.SOUTH);

  myScrollPane = ScrollPaneFactory.createScrollPane(lookup.getList(), true);
  myScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
  UIUtil.putClientProperty(myScrollPane.getVerticalScrollBar(), JBScrollPane.IGNORE_SCROLLBAR_IN_INSETS, true);

  lookup.getComponent().add(layeredPane, BorderLayout.CENTER);

  layeredPane.mainPanel.add(myScrollPane, BorderLayout.CENTER);

  myModalityState = ModalityState.stateForComponent(lookup.getTopLevelEditor().getComponent());

  addListeners();

  Disposer.register(lookup, myProcessIcon);
  Disposer.register(lookup, myHintAlarm);
}
 
Example 25
Source Project: consulo   Source File: SearchTextArea.java    License: Apache License 2.0 4 votes vote down vote up
public void updateExtraActions() {
  for (ActionButton button : UIUtil.findComponentsOfType(myExtraActionsPanel, ActionButton.class)) {
    button.update();
  }
}
 
Example 26
Source Project: consulo   Source File: ActionButtonUI.java    License: Apache License 2.0 votes vote down vote up
void paintBackground(ActionButton button, Graphics g, Dimension size, int state);