Search in sources :

Example 86 with MouseEvent

use of java.awt.event.MouseEvent in project intellij-community by JetBrains.

the class BaseRunConfigurationAction method actionPerformed.

@Override
public void actionPerformed(final AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();
    final ConfigurationContext context = ConfigurationContext.getFromContext(dataContext);
    final RunnerAndConfigurationSettings existing = context.findExisting();
    if (existing == null) {
        final List<ConfigurationFromContext> producers = getConfigurationsFromContext(context);
        if (producers.isEmpty())
            return;
        if (producers.size() > 1) {
            final Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
            Collections.sort(producers, ConfigurationFromContext.NAME_COMPARATOR);
            final ListPopup popup = JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<ConfigurationFromContext>(ExecutionBundle.message("configuration.action.chooser.title"), producers) {

                @Override
                @NotNull
                public String getTextFor(final ConfigurationFromContext producer) {
                    return childActionName(producer.getConfigurationType(), producer.getConfiguration());
                }

                @Override
                public Icon getIconFor(final ConfigurationFromContext producer) {
                    return producer.getConfigurationType().getIcon();
                }

                @Override
                public PopupStep onChosen(final ConfigurationFromContext producer, final boolean finalChoice) {
                    perform(producer, context);
                    return FINAL_CHOICE;
                }
            });
            final InputEvent event = e.getInputEvent();
            if (event instanceof MouseEvent) {
                popup.show(new RelativePoint((MouseEvent) event));
            } else if (editor != null) {
                popup.showInBestPositionFor(editor);
            } else {
                popup.showInBestPositionFor(dataContext);
            }
        } else {
            perform(producers.get(0), context);
        }
        return;
    }
    perform(context);
}
Also used : MouseEvent(java.awt.event.MouseEvent) ListPopup(com.intellij.openapi.ui.popup.ListPopup) RelativePoint(com.intellij.ui.awt.RelativePoint) NotNull(org.jetbrains.annotations.NotNull) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) PopupStep(com.intellij.openapi.ui.popup.PopupStep) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) InputEvent(java.awt.event.InputEvent) Editor(com.intellij.openapi.editor.Editor)

Example 87 with MouseEvent

use of java.awt.event.MouseEvent in project intellij-community by JetBrains.

the class NavBarPanel method installActions.

public void installActions(final int index, final NavBarItem component) {
    //suppress it for a while
    //installDnD(index, component);
    ListenerUtil.addMouseListener(component, new MouseAdapter() {

        @Override
        public void mouseReleased(final MouseEvent e) {
            if (SystemInfo.isWindows) {
                click(e);
            }
        }

        @Override
        public void mousePressed(final MouseEvent e) {
            if (!SystemInfo.isWindows) {
                click(e);
            }
        }

        private void click(final MouseEvent e) {
            if (e.isConsumed())
                return;
            if (e.isPopupTrigger()) {
                myModel.setSelectedIndex(index);
                IdeFocusManager.getInstance(myProject).requestFocus(NavBarPanel.this, true);
                rightClick(index);
                e.consume();
            } else if (!e.isPopupTrigger()) {
                if (e.getClickCount() == 1) {
                    ctrlClick(index);
                    myModel.setSelectedIndex(index);
                    e.consume();
                } else if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) {
                    myModel.setSelectedIndex(index);
                    IdeFocusManager.getInstance(myProject).requestFocus(NavBarPanel.this, true);
                    doubleClick(index);
                    e.consume();
                }
            }
        }
    });
}
Also used : MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter)

Example 88 with MouseEvent

use of java.awt.event.MouseEvent in project intellij-community by JetBrains.

the class MacrosDialog method addListeners.

private void addListeners() {
    myMacrosList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            Macro macro = getSelectedMacro();
            if (macro == null) {
                myPreviewTextarea.setText("");
                setOKActionEnabled(false);
            } else {
                myPreviewTextarea.setText(macro.preview());
                setOKActionEnabled(true);
            }
        }
    });
    new DoubleClickListener() {

        @Override
        protected boolean onDoubleClick(MouseEvent e) {
            if (getSelectedMacro() != null) {
                close(OK_EXIT_CODE);
                return true;
            }
            return false;
        }
    }.installOn(myMacrosList);
}
Also used : MouseEvent(java.awt.event.MouseEvent) DoubleClickListener(com.intellij.ui.DoubleClickListener) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionListener(javax.swing.event.ListSelectionListener)

Example 89 with MouseEvent

use of java.awt.event.MouseEvent 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 90 with MouseEvent

use of java.awt.event.MouseEvent in project intellij-community by JetBrains.

the class BaseExecuteBeforeRunDialog method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    JPanel panel = new JPanel(new BorderLayout());
    myRoot = buildNodes();
    final Tree tree = new Tree(myRoot);
    final MyTreeCellRenderer cellRenderer = new MyTreeCellRenderer();
    tree.setCellRenderer(cellRenderer);
    tree.setRootVisible(false);
    tree.setShowsRootHandles(true);
    tree.setLineStyleAngled();
    TreeUtil.installActions(tree);
    new TreeSpeedSearch(tree);
    tree.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            int row = tree.getRowForLocation(e.getX(), e.getY());
            if (row >= 0) {
                Rectangle rowBounds = tree.getRowBounds(row);
                cellRenderer.setBounds(rowBounds);
                Rectangle checkBounds = cellRenderer.myCheckbox.getBounds();
                checkBounds.setLocation(rowBounds.getLocation());
                if (checkBounds.contains(e.getPoint())) {
                    toggleNode(tree, (DefaultMutableTreeNode) tree.getPathForRow(row).getLastPathComponent());
                    e.consume();
                    tree.setSelectionRow(row);
                }
            }
        }
    });
    tree.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_SPACE) {
                TreePath treePath = tree.getLeadSelectionPath();
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) treePath.getLastPathComponent();
                toggleNode(tree, node);
                e.consume();
            }
        }
    });
    expacndChecked(tree);
    JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(tree);
    scrollPane.setPreferredSize(JBUI.size(400, 400));
    panel.add(scrollPane, BorderLayout.CENTER);
    return panel;
}
Also used : MouseEvent(java.awt.event.MouseEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeSpeedSearch(com.intellij.ui.TreeSpeedSearch) KeyAdapter(java.awt.event.KeyAdapter) MouseAdapter(java.awt.event.MouseAdapter) KeyEvent(java.awt.event.KeyEvent) TreePath(javax.swing.tree.TreePath) Tree(com.intellij.ui.treeStructure.Tree)

Aggregations

MouseEvent (java.awt.event.MouseEvent)918 MouseAdapter (java.awt.event.MouseAdapter)595 Dimension (java.awt.Dimension)183 JPanel (javax.swing.JPanel)174 ActionEvent (java.awt.event.ActionEvent)172 JLabel (javax.swing.JLabel)169 Point (java.awt.Point)143 ActionListener (java.awt.event.ActionListener)123 BorderLayout (java.awt.BorderLayout)119 JScrollPane (javax.swing.JScrollPane)113 JButton (javax.swing.JButton)109 KeyEvent (java.awt.event.KeyEvent)85 ChangeEvent (javax.swing.event.ChangeEvent)85 ChangeListener (javax.swing.event.ChangeListener)83 Insets (java.awt.Insets)79 MouseListener (java.awt.event.MouseListener)72 KeyAdapter (java.awt.event.KeyAdapter)65 JPopupMenu (javax.swing.JPopupMenu)64 JSlider (javax.swing.JSlider)63 GridBagConstraints (java.awt.GridBagConstraints)62