Search in sources :

Example 1 with ClickListener

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

the class AbstractCustomizeWizardStep method createBigButtonPanel.

protected static JPanel createBigButtonPanel(LayoutManager layout, final JToggleButton anchorButton, final Runnable action) {
    final JPanel panel = new JPanel(layout) {

        @Override
        public Color getBackground() {
            return anchorButton.isSelected() ? getSelectionBackground() : super.getBackground();
        }
    };
    panel.setOpaque(anchorButton.isSelected());
    new ClickListener() {

        @Override
        public boolean onClick(@NotNull MouseEvent event, int clickCount) {
            anchorButton.setSelected(true);
            return true;
        }
    }.installOn(panel);
    anchorButton.addItemListener(new ItemListener() {

        boolean curState = anchorButton.isSelected();

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED && curState != anchorButton.isSelected()) {
                action.run();
            }
            curState = anchorButton.isSelected();
            panel.setOpaque(curState);
            panel.repaint();
        }
    });
    return panel;
}
Also used : ItemEvent(java.awt.event.ItemEvent) MouseEvent(java.awt.event.MouseEvent) ItemListener(java.awt.event.ItemListener) ClickListener(com.intellij.ui.ClickListener)

Example 2 with ClickListener

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

the class TextFieldAction method createCustomComponent.

@Override
public JComponent createCustomComponent(Presentation presentation) {
    // honestly borrowed from SearchTextField
    final JPanel panel = new JPanel(new BorderLayout());
    final JLabel label = new JLabel(myIcon);
    label.setOpaque(true);
    label.setBackground(myField.getBackground());
    myField.setOpaque(true);
    panel.add(myField, BorderLayout.WEST);
    panel.add(label, BorderLayout.EAST);
    myField.setToolTipText(myDescription);
    label.setToolTipText(myDescription);
    final Border originalBorder;
    if (SystemInfo.isMac) {
        originalBorder = BorderFactory.createLoweredBevelBorder();
    } else {
        originalBorder = myField.getBorder();
    }
    panel.setBorder(new CompoundBorder(IdeBorderFactory.createEmptyBorder(4, 0, 4, 0), originalBorder));
    myField.setOpaque(true);
    myField.setBorder(IdeBorderFactory.createEmptyBorder(0, 5, 0, 5));
    new ClickListener() {

        @Override
        public boolean onClick(@NotNull MouseEvent e, int clickCount) {
            actionPerformed(null);
            return true;
        }
    }.installOn(label);
    return panel;
}
Also used : MouseEvent(java.awt.event.MouseEvent) CompoundBorder(javax.swing.border.CompoundBorder) Border(javax.swing.border.Border) CompoundBorder(javax.swing.border.CompoundBorder) ClickListener(com.intellij.ui.ClickListener)

Example 3 with ClickListener

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

the class XWatchesViewImpl method installEditListeners.

private void installEditListeners() {
    final XDebuggerTree watchTree = getTree();
    final Alarm quitePeriod = new Alarm();
    final Alarm editAlarm = new Alarm();
    final ClickListener mouseListener = new ClickListener() {

        @Override
        public boolean onClick(@NotNull MouseEvent event, int clickCount) {
            if (!SwingUtilities.isLeftMouseButton(event) || ((event.getModifiers() & (InputEvent.SHIFT_MASK | InputEvent.ALT_MASK | InputEvent.CTRL_MASK | InputEvent.META_MASK)) != 0)) {
                return false;
            }
            boolean sameRow = isAboveSelectedItem(event, watchTree, false);
            if (!sameRow || clickCount > 1) {
                editAlarm.cancelAllRequests();
                return false;
            }
            final AnAction editWatchAction = ActionManager.getInstance().getAction(XDebuggerActions.XEDIT_WATCH);
            Presentation presentation = editWatchAction.getTemplatePresentation().clone();
            DataContext context = DataManager.getInstance().getDataContext(watchTree);
            final AnActionEvent actionEvent = new AnActionEvent(null, context, "WATCH_TREE", presentation, ActionManager.getInstance(), 0);
            Runnable runnable = () -> editWatchAction.actionPerformed(actionEvent);
            if (editAlarm.isEmpty() && quitePeriod.isEmpty()) {
                editAlarm.addRequest(runnable, UIUtil.getMultiClickInterval());
            } else {
                editAlarm.cancelAllRequests();
            }
            return false;
        }
    };
    final ClickListener mouseEmptySpaceListener = new DoubleClickListener() {

        @Override
        protected boolean onDoubleClick(MouseEvent event) {
            if (!isAboveSelectedItem(event, watchTree, true)) {
                myRootNode.addNewWatch();
                return true;
            }
            return false;
        }
    };
    ListenerUtil.addClickListener(watchTree, mouseListener);
    ListenerUtil.addClickListener(watchTree, mouseEmptySpaceListener);
    final FocusListener focusListener = new FocusListener() {

        @Override
        public void focusGained(@NotNull FocusEvent e) {
            quitePeriod.addRequest(EmptyRunnable.getInstance(), UIUtil.getMultiClickInterval());
        }

        @Override
        public void focusLost(@NotNull FocusEvent e) {
            editAlarm.cancelAllRequests();
        }
    };
    ListenerUtil.addFocusListener(watchTree, focusListener);
    final TreeSelectionListener selectionListener = new TreeSelectionListener() {

        @Override
        public void valueChanged(@NotNull TreeSelectionEvent e) {
            quitePeriod.addRequest(EmptyRunnable.getInstance(), UIUtil.getMultiClickInterval());
        }
    };
    watchTree.addTreeSelectionListener(selectionListener);
    myDisposables.add(new Disposable() {

        @Override
        public void dispose() {
            ListenerUtil.removeClickListener(watchTree, mouseListener);
            ListenerUtil.removeClickListener(watchTree, mouseEmptySpaceListener);
            ListenerUtil.removeFocusListener(watchTree, focusListener);
            watchTree.removeTreeSelectionListener(selectionListener);
        }
    });
}
Also used : CompositeDisposable(com.intellij.openapi.CompositeDisposable) Disposable(com.intellij.openapi.Disposable) MouseEvent(java.awt.event.MouseEvent) DoubleClickListener(com.intellij.ui.DoubleClickListener) TreeSelectionListener(javax.swing.event.TreeSelectionListener) XDebuggerTree(com.intellij.xdebugger.impl.ui.tree.XDebuggerTree) NotNull(org.jetbrains.annotations.NotNull) FocusEvent(java.awt.event.FocusEvent) Alarm(com.intellij.util.Alarm) EmptyRunnable(com.intellij.openapi.util.EmptyRunnable) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) FocusListener(java.awt.event.FocusListener) DoubleClickListener(com.intellij.ui.DoubleClickListener) ClickListener(com.intellij.ui.ClickListener)

Example 4 with ClickListener

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

the class OptionTreeWithPreviewPanel method createOptionsTree.

protected JTree createOptionsTree() {
    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();
    String groupName = "";
    DefaultMutableTreeNode groupNode = null;
    List<BooleanOptionKey> result = sortOptions(orderByGroup(myKeys));
    for (BooleanOptionKey key : result) {
        String newGroupName = key.groupName;
        if (!newGroupName.equals(groupName) || groupNode == null) {
            groupName = newGroupName;
            groupNode = new DefaultMutableTreeNode(newGroupName);
            rootNode.add(groupNode);
        }
        if (isOptionVisible(key)) {
            groupNode.add(new MyToggleTreeNode(key, key.title));
        }
    }
    DefaultTreeModel model = new DefaultTreeModel(rootNode);
    final Tree optionsTree = new Tree(model);
    new TreeSpeedSearch(optionsTree).setComparator(new SpeedSearchComparator(false));
    TreeUtil.installActions(optionsTree);
    optionsTree.setRootVisible(false);
    UIUtil.setLineStyleAngled(optionsTree);
    optionsTree.setShowsRootHandles(true);
    optionsTree.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (!optionsTree.isEnabled())
                return;
            if (e.getKeyCode() == KeyEvent.VK_SPACE) {
                TreePath treePath = optionsTree.getLeadSelectionPath();
                selectCheckbox(treePath);
                e.consume();
            }
        }
    });
    new ClickListener() {

        @Override
        public boolean onClick(@NotNull MouseEvent e, int clickCount) {
            if (!optionsTree.isEnabled())
                return false;
            TreePath treePath = optionsTree.getPathForLocation(e.getX(), e.getY());
            selectCheckbox(treePath);
            return true;
        }
    }.installOn(optionsTree);
    int row = 0;
    while (row < optionsTree.getRowCount()) {
        optionsTree.expandRow(row);
        row++;
    }
    return optionsTree;
}
Also used : MouseEvent(java.awt.event.MouseEvent) TreeSpeedSearch(com.intellij.ui.TreeSpeedSearch) KeyAdapter(java.awt.event.KeyAdapter) KeyEvent(java.awt.event.KeyEvent) Tree(com.intellij.ui.treeStructure.Tree) SpeedSearchComparator(com.intellij.ui.SpeedSearchComparator) ClickListener(com.intellij.ui.ClickListener)

Example 5 with ClickListener

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

the class AbstractDescriptionAwareSchemesPanel method createInfoComponent.

@NotNull
@Override
protected JPanel createInfoComponent() {
    JPanel panel = new JPanel();
    myLayout = new CardLayout();
    panel.setLayout(myLayout);
    myDescriptionTextField = new JBTextField();
    myDescriptionTextField.addFocusListener(new FocusAdapter() {

        @Override
        public void focusLost(FocusEvent e) {
            applyDescription();
        }
    });
    myDescriptionTextField.registerKeyboardAction(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            showDescription();
            IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
                IdeFocusManager.getGlobalInstance().requestFocus(getConfigurableFocusComponent(), true);
            });
        }
    }, ESC_KEY_STROKE, JComponent.WHEN_FOCUSED);
    myDescriptionTextField.registerKeyboardAction(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            applyDescription();
            IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
                IdeFocusManager.getGlobalInstance().requestFocus(getConfigurableFocusComponent(), true);
            });
        }
    }, ENTER_KEY_STROKE, JComponent.WHEN_FOCUSED);
    myDescriptionLabel = new DescriptionLabel();
    new ClickListener() {

        @Override
        public boolean onClick(@NotNull MouseEvent event, int clickCount) {
            if (clickCount != 2) {
                return false;
            }
            editDescription(myDescriptionLabel.getText());
            return true;
        }
    }.installOn(myDescriptionLabel);
    myWarningLabel = new JLabel();
    panel.add(myDescriptionTextField, EDIT_DESCRIPTION_CARD);
    panel.add(myDescriptionLabel, SHOW_DESCRIPTION_CARD);
    panel.add(myWarningLabel, ERROR_CARD);
    myLayout.show(panel, ERROR_CARD);
    return panel;
}
Also used : JBTextField(com.intellij.ui.components.JBTextField) ClickListener(com.intellij.ui.ClickListener) NotNull(org.jetbrains.annotations.NotNull)

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