Search in sources :

Example 56 with MouseAdapter

use of java.awt.event.MouseAdapter 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 57 with MouseAdapter

use of java.awt.event.MouseAdapter 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)

Example 58 with MouseAdapter

use of java.awt.event.MouseAdapter in project jadx by skylot.

the class MainWindow method initUI.

private void initUI() {
    mainPanel = new JPanel(new BorderLayout());
    JSplitPane splitPane = new JSplitPane();
    splitPane.setResizeWeight(SPLIT_PANE_RESIZE_WEIGHT);
    mainPanel.add(splitPane);
    DefaultMutableTreeNode treeRoot = new DefaultMutableTreeNode(NLS.str("msg.open_file"));
    treeModel = new DefaultTreeModel(treeRoot);
    tree = new JTree(treeModel);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            treeClickAction();
        }
    });
    tree.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                treeClickAction();
            }
        }
    });
    tree.setCellRenderer(new DefaultTreeCellRenderer() {

        @Override
        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean isLeaf, int row, boolean focused) {
            Component c = super.getTreeCellRendererComponent(tree, value, selected, expanded, isLeaf, row, focused);
            if (value instanceof JNode) {
                setIcon(((JNode) value).getIcon());
            }
            return c;
        }
    });
    tree.addTreeWillExpandListener(new TreeWillExpandListener() {

        @Override
        public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
            TreePath path = event.getPath();
            Object node = path.getLastPathComponent();
            if (node instanceof JClass) {
                JClass cls = (JClass) node;
                cls.getRootClass().load();
            }
        }

        @Override
        public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {
        }
    });
    progressPane = new ProgressPanel(this, true);
    JPanel leftPane = new JPanel(new BorderLayout());
    leftPane.add(new JScrollPane(tree), BorderLayout.CENTER);
    leftPane.add(progressPane, BorderLayout.PAGE_END);
    splitPane.setLeftComponent(leftPane);
    tabbedPane = new TabbedPane(this);
    splitPane.setRightComponent(tabbedPane);
    dropTarget = new DropTarget(this, DnDConstants.ACTION_COPY, new MainDropTarget(this));
    setContentPane(mainPanel);
    setTitle(DEFAULT_TITLE);
}
Also used : JPanel(javax.swing.JPanel) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) KeyAdapter(java.awt.event.KeyAdapter) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer) ExpandVetoException(javax.swing.tree.ExpandVetoException) KeyEvent(java.awt.event.KeyEvent) BorderLayout(java.awt.BorderLayout) JNode(jadx.gui.treemodel.JNode) Component(java.awt.Component) TreeExpansionEvent(javax.swing.event.TreeExpansionEvent) TreeWillExpandListener(javax.swing.event.TreeWillExpandListener) JScrollPane(javax.swing.JScrollPane) MouseEvent(java.awt.event.MouseEvent) JClass(jadx.gui.treemodel.JClass) MouseAdapter(java.awt.event.MouseAdapter) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath) CacheObject(jadx.gui.utils.CacheObject) DropTarget(java.awt.dnd.DropTarget) JSplitPane(javax.swing.JSplitPane)

Example 59 with MouseAdapter

use of java.awt.event.MouseAdapter in project jadx by skylot.

the class TabbedPane method makeTabComponent.

private Component makeTabComponent(final ContentPanel contentPanel) {
    JNode node = contentPanel.getNode();
    String name = node.makeLongString();
    final JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER, 3, 0));
    panel.setOpaque(false);
    final JLabel label = new JLabel(name);
    label.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));
    label.setIcon(node.getIcon());
    final JButton button = new JButton();
    button.setIcon(ICON_CLOSE_INACTIVE);
    button.setRolloverIcon(ICON_CLOSE);
    button.setRolloverEnabled(true);
    button.setOpaque(false);
    button.setUI(new BasicButtonUI());
    button.setContentAreaFilled(false);
    button.setFocusable(false);
    button.setBorder(null);
    button.setBorderPainted(false);
    button.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            closeCodePanel(contentPanel);
        }
    });
    panel.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (SwingUtilities.isMiddleMouseButton(e)) {
                closeCodePanel(contentPanel);
            } else if (SwingUtilities.isRightMouseButton(e)) {
                JPopupMenu menu = createTabPopupMenu(contentPanel);
                menu.show(panel, e.getX(), e.getY());
            } else {
                // TODO: make correct event delegation to tabbed pane
                setSelectedComponent(contentPanel);
            }
        }
    });
    panel.add(label);
    panel.add(button);
    panel.setBorder(BorderFactory.createEmptyBorder(4, 0, 0, 0));
    return panel;
}
Also used : JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) MouseEvent(java.awt.event.MouseEvent) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) BasicButtonUI(javax.swing.plaf.basic.BasicButtonUI) JPopupMenu(javax.swing.JPopupMenu) ActionListener(java.awt.event.ActionListener) JNode(jadx.gui.treemodel.JNode)

Example 60 with MouseAdapter

use of java.awt.event.MouseAdapter in project jadx by skylot.

the class JadxSettingsWindow method makeEditorGroup.

private SettingsGroup makeEditorGroup() {
    JButton fontBtn = new JButton(NLS.str("preferences.select_font"));
    fontBtn.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            JFontChooser fontChooser = new JFontChooser();
            fontChooser.setSelectedFont(settings.getFont());
            int result = fontChooser.showDialog(JadxSettingsWindow.this);
            if (result == JFontChooser.OK_OPTION) {
                Font font = fontChooser.getSelectedFont();
                LOG.info("Selected Font : {}", font);
                settings.setFont(font);
                mainWindow.updateFont(font);
            }
        }
    });
    SettingsGroup other = new SettingsGroup(NLS.str("preferences.editor"));
    other.addRow(NLS.str("preferences.font"), fontBtn);
    return other;
}
Also used : MouseEvent(java.awt.event.MouseEvent) JFontChooser(say.swing.JFontChooser) JButton(javax.swing.JButton) MouseAdapter(java.awt.event.MouseAdapter) Font(java.awt.Font)

Aggregations

MouseAdapter (java.awt.event.MouseAdapter)202 MouseEvent (java.awt.event.MouseEvent)199 JLabel (javax.swing.JLabel)52 JPanel (javax.swing.JPanel)48 ActionEvent (java.awt.event.ActionEvent)36 JScrollPane (javax.swing.JScrollPane)36 BorderLayout (java.awt.BorderLayout)35 Dimension (java.awt.Dimension)34 JButton (javax.swing.JButton)33 ActionListener (java.awt.event.ActionListener)32 Insets (java.awt.Insets)24 GridBagConstraints (java.awt.GridBagConstraints)20 KeyEvent (java.awt.event.KeyEvent)20 KeyAdapter (java.awt.event.KeyAdapter)19 JTextField (javax.swing.JTextField)16 ListSelectionEvent (javax.swing.event.ListSelectionEvent)16 Component (java.awt.Component)15 Point (java.awt.Point)15 JTable (javax.swing.JTable)15 ListSelectionListener (javax.swing.event.ListSelectionListener)15