@Override public void paint(Graphics g, JComponent c) { if(c instanceof ActionButtonWithText) { paintTextButton(g, (ActionButtonWithText)c); } else { paintDefaultButton(g, (ActionButton)c); } }
private void paintTextButton(Graphics g, ActionButtonWithText c) { AnAction action = c.getAction(); Icon icon = c.getIcon(); FontMetrics fm = SwingUtilities2.getFontMetrics(c, g, c.getFont()); Rectangle viewRect = new Rectangle(c.getSize()); Insets i = c.getInsets(); viewRect.x += i.left; viewRect.y += i.top; viewRect.width -= (i.right + viewRect.x); viewRect.height -= (i.bottom + viewRect.y); Rectangle iconRect = new Rectangle(); Rectangle textRect = new Rectangle(); String text = SwingUtilities .layoutCompoundLabel(c, fm, c.getText(), icon, SwingConstants.CENTER, c.horizontalTextAlignment(), SwingConstants.CENTER, SwingConstants.TRAILING, viewRect, iconRect, textRect, c.iconTextSpace()); int state = c.getPopState(); if (state != ActionButtonComponent.NORMAL) { paintBackground(c, g, c.getSize(), state); } icon.paintIcon(null, g, iconRect.x, iconRect.y); UIUtil.applyRenderingHints(g); g.setColor(c.isButtonEnabled() ? c.getForeground() : UIUtil.getInactiveTextColor()); SwingUtilities2.drawStringUnderlineCharAt(c, g, text, getMnemonicCharIndex(c, action, text), textRect.x, textRect.y + fm.getAscent()); }
public static JComponent createCustomComponentImpl(final AnAction action, final Presentation presentation) { return new ActionButtonWithText(action, presentation, ActionPlaces.UNKNOWN, ActionToolbar.DEFAULT_MINIMUM_BUTTON_SIZE); }
@Override public JComponent createCustomComponent(Presentation presentation) { return new ActionButtonWithText(this, presentation, ActionPlaces.UNKNOWN, ActionToolbar.DEFAULT_MINIMUM_BUTTON_SIZE); }
public static JComponent createCustomComponentImpl(final AnAction action, final Presentation presentation) { return new ActionButtonWithText(action, presentation, ActionPlaces.UNKNOWN, JBUI.size(ActionToolbar.DEFAULT_MINIMUM_BUTTON_SIZE)); }
@Override public JComponent createCustomComponent(Presentation presentation) { return new ActionButtonWithText(this, presentation, ActionPlaces.UNKNOWN, JBUI.size(ActionToolbar.DEFAULT_MINIMUM_BUTTON_SIZE)); }