Search in sources :

Example 1 with ActionButtonLook

use of com.intellij.openapi.actionSystem.ex.ActionButtonLook in project intellij-community by JetBrains.

the class ActionButton method paintButtonLook.

protected void paintButtonLook(Graphics g) {
    ActionButtonLook look = getButtonLook();
    look.paintBackground(g, this);
    look.paintIcon(g, this, getIcon());
    look.paintBorder(g, this);
}
Also used : ActionButtonLook(com.intellij.openapi.actionSystem.ex.ActionButtonLook)

Example 2 with ActionButtonLook

use of com.intellij.openapi.actionSystem.ex.ActionButtonLook in project intellij-community by JetBrains.

the class ActionButtonWithText method paintComponent.

public void paintComponent(Graphics g) {
    Icon icon = getIcon();
    FontMetrics fm = getFontMetrics(getFont());
    Rectangle viewRect = new Rectangle(getSize());
    JBInsets.removeFrom(viewRect, getInsets());
    Rectangle iconRect = new Rectangle();
    Rectangle textRect = new Rectangle();
    String text = SwingUtilities.layoutCompoundLabel(this, fm, getText(), icon, SwingConstants.CENTER, horizontalTextAlignment(), SwingConstants.CENTER, horizontalTextPosition(), viewRect, iconRect, textRect, iconTextSpace());
    ActionButtonLook look = ActionButtonLook.IDEA_LOOK;
    look.paintBackground(g, this);
    look.paintIconAt(g, this, icon, iconRect.x, iconRect.y);
    look.paintBorder(g, this);
    UISettings.setupAntialiasing(g);
    g.setColor(isButtonEnabled() ? getForeground() : getInactiveTextColor());
    SwingUtilities2.drawStringUnderlineCharAt(this, g, text, getMnemonicCharIndex(text), textRect.x, textRect.y + fm.getAscent());
}
Also used : EmptyIcon(com.intellij.util.ui.EmptyIcon) ActionButtonLook(com.intellij.openapi.actionSystem.ex.ActionButtonLook)

Example 3 with ActionButtonLook

use of com.intellij.openapi.actionSystem.ex.ActionButtonLook in project intellij-community by JetBrains.

the class RichTextActionProcessor method process.

@Override
public JComponent process(@NotNull String s) {
    final ActionManager actionManager = ActionManager.getInstance();
    final AnAction action = actionManager.getAction(s);
    if (action == null) {
        return null;
    }
    final Presentation presentation = action.getTemplatePresentation();
    if (presentation.getIcon() != null) {
        return new ActionButton(action, presentation.clone(), GradleConstants.TOOL_WINDOW_TOOLBAR_PLACE, JBUI.emptySize()) {

            @Override
            protected void paintButtonLook(Graphics g) {
                // Don't draw border at the inline button.
                ActionButtonLook look = getButtonLook();
                look.paintBackground(g, this);
                look.paintIcon(g, this, getIcon());
            }
        };
    }
    final String text = action.getTemplatePresentation().getText();
    JLabel result = new JLabel(text) {

        public void paint(Graphics g) {
            super.paint(g);
            final int y = g.getClipBounds().height - getFontMetrics(getFont()).getDescent() + 2;
            final int width = getFontMetrics(getFont()).stringWidth(getText());
            g.drawLine(0, y, width, y);
        }
    };
    Color color = UIUtil.isUnderDarcula() ? Color.ORANGE : Color.BLUE;
    result.setForeground(color);
    result.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    new ClickListener() {

        @Override
        public boolean onClick(@NotNull MouseEvent e, int clickCount) {
            final AsyncResult<DataContext> callback = DataManager.getInstance().getDataContextFromFocus();
            final DataContext context = callback.getResult();
            if (context == null) {
                return false;
            }
            final Presentation presentation = new PresentationFactory().getPresentation(action);
            action.actionPerformed(new AnActionEvent(e, context, GradleConstants.TOOL_WINDOW_TOOLBAR_PLACE, presentation, ActionManager.getInstance(), e.getModifiers()));
            return true;
        }
    }.installOn(result);
    return result;
}
Also used : MouseEvent(java.awt.event.MouseEvent) PresentationFactory(com.intellij.openapi.actionSystem.impl.PresentationFactory) ActionButton(com.intellij.openapi.actionSystem.impl.ActionButton) AsyncResult(com.intellij.openapi.util.AsyncResult) ActionButtonLook(com.intellij.openapi.actionSystem.ex.ActionButtonLook) ClickListener(com.intellij.ui.ClickListener)

Aggregations

ActionButtonLook (com.intellij.openapi.actionSystem.ex.ActionButtonLook)3 ActionButton (com.intellij.openapi.actionSystem.impl.ActionButton)1 PresentationFactory (com.intellij.openapi.actionSystem.impl.PresentationFactory)1 AsyncResult (com.intellij.openapi.util.AsyncResult)1 ClickListener (com.intellij.ui.ClickListener)1 EmptyIcon (com.intellij.util.ui.EmptyIcon)1 MouseEvent (java.awt.event.MouseEvent)1