Search in sources :

Example 6 with ClickListener

use of com.intellij.ui.ClickListener in project intellij-community by JetBrains.

the class QuickFixAction method createCustomComponent.

@Override
public JComponent createCustomComponent(Presentation presentation) {
    final JButton button = new JButton(presentation.getText());
    Icon icon = presentation.getIcon();
    if (icon == null) {
        icon = AllIcons.Actions.CreateFromUsage;
    }
    button.setEnabled(presentation.isEnabled());
    button.setIcon(IconLoader.getTransparentIcon(icon, 0.75f));
    new ClickListener() {

        @Override
        public boolean onClick(@NotNull MouseEvent event, int clickCount) {
            final ActionToolbar toolbar = UIUtil.getParentOfType(ActionToolbar.class, button);
            actionPerformed(AnActionEvent.createFromAnAction(QuickFixAction.this, event, ActionPlaces.UNKNOWN, toolbar == null ? DataManager.getInstance().getDataContext(button) : toolbar.getToolbarDataContext()));
            return true;
        }
    }.installOn(button);
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS));
    panel.setBorder(IdeBorderFactory.createEmptyBorder(7, 0, 8, 0));
    panel.add(button);
    return panel;
}
Also used : MouseEvent(java.awt.event.MouseEvent) ClickListener(com.intellij.ui.ClickListener)

Example 7 with ClickListener

use of com.intellij.ui.ClickListener in project intellij-community by JetBrains.

the class TrackRunningTestUtil method installStopListeners.

public static void installStopListeners(final JTree tree, final Disposable parentDisposable, final Pass<AbstractTestProxy> setSelection) {
    final ClickListener userSelectionListener = new ClickListener() {

        @Override
        public boolean onClick(@NotNull MouseEvent e, int clickCount) {
            setSelection.pass(setUserSelection(tree.getPathForLocation(e.getX(), e.getY())));
            return true;
        }
    };
    userSelectionListener.installOn(tree);
    final KeyAdapter keyAdapter = new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            final int keyCode = e.getKeyCode();
            if (keyCode == KeyEvent.VK_DOWN || keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_LEFT || keyCode == KeyEvent.VK_RIGHT || keyCode == KeyEvent.VK_PAGE_DOWN || keyCode == KeyEvent.VK_PAGE_UP) {
                setSelection.pass(setUserSelection(tree.getSelectionPath()));
            }
        }
    };
    tree.addKeyListener(keyAdapter);
    Disposer.register(parentDisposable, new Disposable() {

        @Override
        public void dispose() {
            userSelectionListener.uninstall(tree);
            tree.removeKeyListener(keyAdapter);
        }
    });
}
Also used : KeyEvent(java.awt.event.KeyEvent) Disposable(com.intellij.openapi.Disposable) MouseEvent(java.awt.event.MouseEvent) KeyAdapter(java.awt.event.KeyAdapter) NotNull(org.jetbrains.annotations.NotNull) ClickListener(com.intellij.ui.ClickListener)

Example 8 with ClickListener

use of com.intellij.ui.ClickListener 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

ClickListener (com.intellij.ui.ClickListener)8 MouseEvent (java.awt.event.MouseEvent)7 NotNull (org.jetbrains.annotations.NotNull)3 Disposable (com.intellij.openapi.Disposable)2 KeyAdapter (java.awt.event.KeyAdapter)2 KeyEvent (java.awt.event.KeyEvent)2 CompositeDisposable (com.intellij.openapi.CompositeDisposable)1 ActionButtonLook (com.intellij.openapi.actionSystem.ex.ActionButtonLook)1 ActionButton (com.intellij.openapi.actionSystem.impl.ActionButton)1 PresentationFactory (com.intellij.openapi.actionSystem.impl.PresentationFactory)1 AsyncResult (com.intellij.openapi.util.AsyncResult)1 EmptyRunnable (com.intellij.openapi.util.EmptyRunnable)1 DoubleClickListener (com.intellij.ui.DoubleClickListener)1 SpeedSearchComparator (com.intellij.ui.SpeedSearchComparator)1 TreeSpeedSearch (com.intellij.ui.TreeSpeedSearch)1 JBTextField (com.intellij.ui.components.JBTextField)1 Tree (com.intellij.ui.treeStructure.Tree)1 Alarm (com.intellij.util.Alarm)1 XDebuggerTree (com.intellij.xdebugger.impl.ui.tree.XDebuggerTree)1 FocusEvent (java.awt.event.FocusEvent)1