Search in sources :

Example 31 with KeyEvent

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

the class MacIntelliJComboBoxUI method createEditor.

@Override
protected ComboBoxEditor createEditor() {
    final ComboBoxEditor comboBoxEditor = new BasicComboBoxEditor.UIResource() {

        @Override
        protected JTextField createEditorComponent() {
            return new JTextField() {

                {
                    setOpaque(false);
                    setBorder(ourDefaultEditorBorder);
                }

                @Override
                public Color getBackground() {
                    if (!isEnabled()) {
                        return Gray.xF8;
                    }
                    return super.getBackground();
                }

                public void setText(String s) {
                    if (getText().equals(s)) {
                        return;
                    }
                    super.setText(s);
                }

                @Override
                public void setBorder(Border border) {
                }

                @Override
                public Border getBorder() {
                    return ourDefaultEditorBorder;
                }

                @Override
                public Dimension getPreferredSize() {
                    Dimension size = super.getPreferredSize();
                    return new Dimension(size.width, DEFAULT_ICON.getIconHeight() - 6);
                }
            };
        }
    };
    if (comboBoxEditor.getEditorComponent() != null) {
        comboBoxEditor.getEditorComponent().addKeyListener(new KeyAdapter() {

            @Override
            public void keyPressed(KeyEvent e) {
                process(e);
            }

            @Override
            public void keyReleased(KeyEvent e) {
                process(e);
            }

            private void process(KeyEvent e) {
                final int code = e.getKeyCode();
                if ((code == KeyEvent.VK_UP || code == KeyEvent.VK_DOWN) && e.getModifiers() == 0) {
                    comboBox.dispatchEvent(e);
                }
            }
        });
        comboBoxEditor.getEditorComponent().addFocusListener(new FocusAdapter() {

            @Override
            public void focusGained(FocusEvent e) {
                update();
            }

            @Override
            public void focusLost(FocusEvent e) {
                update();
            }

            void update() {
                if (comboBox != null) {
                    comboBox.revalidate();
                    comboBox.repaint();
                }
            }
        });
    }
    return comboBoxEditor;
}
Also used : KeyEvent(java.awt.event.KeyEvent) FocusAdapter(java.awt.event.FocusAdapter) KeyAdapter(java.awt.event.KeyAdapter) Border(javax.swing.border.Border) FocusEvent(java.awt.event.FocusEvent)

Example 32 with KeyEvent

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

the class DarculaLaf method initialize.

@Override
public void initialize() {
    try {
        base.initialize();
    } catch (Exception ignore) {
    }
    myDisposable = Disposer.newDisposable();
    Application application = ApplicationManager.getApplication();
    if (application != null) {
        Disposer.register(application, myDisposable);
    }
    myMnemonicAlarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, myDisposable);
    IdeEventQueue.getInstance().addDispatcher(e -> {
        if (e instanceof KeyEvent && ((KeyEvent) e).getKeyCode() == KeyEvent.VK_ALT) {
            myAltPressed = e.getID() == KeyEvent.KEY_PRESSED;
            myMnemonicAlarm.cancelAllRequests();
            final Component focusOwner = IdeFocusManager.findInstance().getFocusOwner();
            if (focusOwner != null) {
                myMnemonicAlarm.addRequest(() -> repaintMnemonics(focusOwner, myAltPressed), 10);
            }
        }
        return false;
    }, myDisposable);
}
Also used : KeyEvent(java.awt.event.KeyEvent) Alarm(com.intellij.util.Alarm) Application(com.intellij.openapi.application.Application) IOException(java.io.IOException)

Example 33 with KeyEvent

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

the class NewRecentProjectPanel method createList.

@Override
protected JBList createList(AnAction[] recentProjectActions, Dimension size) {
    final JBList list = super.createList(recentProjectActions, size);
    list.setBackground(FlatWelcomeFrame.getProjectsBackground());
    list.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            Object selected = list.getSelectedValue();
            final ProjectGroup group;
            if (selected instanceof ProjectGroupActionGroup) {
                group = ((ProjectGroupActionGroup) selected).getGroup();
            } else {
                group = null;
            }
            int keyCode = e.getKeyCode();
            if (keyCode == KeyEvent.VK_RIGHT) {
                if (group != null) {
                    if (!group.isExpanded()) {
                        group.setExpanded(true);
                        ListModel model = ((NameFilteringListModel) list.getModel()).getOriginalModel();
                        int index = list.getSelectedIndex();
                        RecentProjectsWelcomeScreenActionBase.rebuildRecentProjectDataModel((DefaultListModel) model);
                        list.setSelectedIndex(group.getProjects().isEmpty() ? index : index + 1);
                    }
                } else {
                    FlatWelcomeFrame frame = UIUtil.getParentOfType(FlatWelcomeFrame.class, list);
                    if (frame != null) {
                        FocusTraversalPolicy policy = frame.getFocusTraversalPolicy();
                        if (policy != null) {
                            Component next = policy.getComponentAfter(frame, list);
                            if (next != null) {
                                IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
                                    IdeFocusManager.getGlobalInstance().requestFocus(next, true);
                                });
                            }
                        }
                    }
                }
            } else if (keyCode == KeyEvent.VK_LEFT) {
                if (group != null && group.isExpanded()) {
                    group.setExpanded(false);
                    int index = list.getSelectedIndex();
                    ListModel model = ((NameFilteringListModel) list.getModel()).getOriginalModel();
                    RecentProjectsWelcomeScreenActionBase.rebuildRecentProjectDataModel((DefaultListModel) model);
                    list.setSelectedIndex(index);
                }
            }
        }
    });
    list.addMouseListener(new PopupHandler() {

        @Override
        public void invokePopup(Component comp, int x, int y) {
            final int index = list.locationToIndex(new Point(x, y));
            if (index != -1 && Arrays.binarySearch(list.getSelectedIndices(), index) < 0) {
                list.setSelectedIndex(index);
            }
            final ActionGroup group = (ActionGroup) ActionManager.getInstance().getAction("WelcomeScreenRecentProjectActionGroup");
            if (group != null) {
                ActionManager.getInstance().createActionPopupMenu(ActionPlaces.WELCOME_SCREEN, group).getComponent().show(comp, x, y);
            }
        }
    });
    return list;
}
Also used : PopupHandler(com.intellij.ui.PopupHandler) KeyAdapter(java.awt.event.KeyAdapter) KeyEvent(java.awt.event.KeyEvent) NameFilteringListModel(com.intellij.ui.speedSearch.NameFilteringListModel) ActionGroup(com.intellij.openapi.actionSystem.ActionGroup) NameFilteringListModel(com.intellij.ui.speedSearch.NameFilteringListModel) JBList(com.intellij.ui.components.JBList)

Example 34 with KeyEvent

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

the class IdeEventQueueTest method testKeyboardEventsAreDetected.

public void testKeyboardEventsAreDetected() throws InterruptedException {
    assertTrue(EventQueue.isDispatchThread());
    IdeEventQueue ideEventQueue = IdeEventQueue.getInstance();
    assertSame(ideEventQueue, Toolkit.getDefaultToolkit().getSystemEventQueue());
    PlatformTestUtil.dispatchAllEventsInIdeEventQueue();
    ideEventQueue.addDispatcher(e -> {
        LOG.debug("dispatch: " + e);
        return false;
    }, getTestRootDisposable());
    ideEventQueue.addPostprocessor(e -> {
        LOG.debug("post dispatch: " + e);
        return false;
    }, getTestRootDisposable());
    ideEventQueue.addPostEventListener(e -> {
        LOG.debug("post event hook: " + e);
        return false;
    }, getTestRootDisposable());
    int posted = ideEventQueue.myKeyboardEventsPosted.get();
    int dispatched = ideEventQueue.myKeyboardEventsDispatched.get();
    KeyEvent pressX = new KeyEvent(new JLabel("mykeypress"), KeyEvent.KEY_PRESSED, 1, InputEvent.ALT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK, 11, 'x');
    postCarefully(pressX);
    assertEquals(posted + 1, ideEventQueue.myKeyboardEventsPosted.get());
    assertEquals(dispatched, ideEventQueue.myKeyboardEventsDispatched.get());
    assertEquals(pressX, dispatchAllInvocationEventsUntilOtherEvent(ideEventQueue));
    assertEquals(posted + 1, ideEventQueue.myKeyboardEventsPosted.get());
    assertEquals(dispatched + 1, ideEventQueue.myKeyboardEventsDispatched.get());
    // do not react to other events
    AWTEvent ev2 = new ActionEvent(new JLabel(), ActionEvent.ACTION_PERFORMED, "myCommand");
    postCarefully(ev2);
    assertEquals(posted + 1, ideEventQueue.myKeyboardEventsPosted.get());
    assertEquals(dispatched + 1, ideEventQueue.myKeyboardEventsDispatched.get());
    assertEquals(ev2, dispatchAllInvocationEventsUntilOtherEvent(ideEventQueue));
    assertEquals(posted + 1, ideEventQueue.myKeyboardEventsPosted.get());
    assertEquals(dispatched + 1, ideEventQueue.myKeyboardEventsDispatched.get());
    KeyEvent keyRelease = new KeyEvent(new JLabel("mykeyrelease"), KeyEvent.KEY_RELEASED, 1, InputEvent.ALT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK, 11, 'x');
    postCarefully(keyRelease);
    assertEquals(posted + 2, ideEventQueue.myKeyboardEventsPosted.get());
    assertEquals(dispatched + 1, ideEventQueue.myKeyboardEventsDispatched.get());
    assertEquals(keyRelease, dispatchAllInvocationEventsUntilOtherEvent(ideEventQueue));
    assertEquals(posted + 2, ideEventQueue.myKeyboardEventsPosted.get());
    assertEquals(dispatched + 2, ideEventQueue.myKeyboardEventsDispatched.get());
}
Also used : KeyEvent(java.awt.event.KeyEvent) ActionEvent(java.awt.event.ActionEvent)

Example 35 with KeyEvent

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

the class ResumeAction method isEnabled.

@Override
protected boolean isEnabled(AnActionEvent e) {
    Project project = e.getProject();
    if (project == null)
        return false;
    XDebugSession session = XDebuggerManager.getInstance(project).getCurrentSession();
    if (session != null && !session.isStopped()) {
        return session.isPaused();
    }
    // disable visual representation but leave the shortcut action enabled
    return e.getInputEvent() instanceof KeyEvent;
}
Also used : KeyEvent(java.awt.event.KeyEvent) Project(com.intellij.openapi.project.Project) XDebugSession(com.intellij.xdebugger.XDebugSession)

Aggregations

KeyEvent (java.awt.event.KeyEvent)144 KeyAdapter (java.awt.event.KeyAdapter)74 MouseEvent (java.awt.event.MouseEvent)34 ActionEvent (java.awt.event.ActionEvent)24 KeyListener (java.awt.event.KeyListener)22 ActionListener (java.awt.event.ActionListener)20 MouseAdapter (java.awt.event.MouseAdapter)20 JPanel (javax.swing.JPanel)19 JLabel (javax.swing.JLabel)18 JTextField (javax.swing.JTextField)15 BorderLayout (java.awt.BorderLayout)14 JButton (javax.swing.JButton)14 JScrollPane (javax.swing.JScrollPane)14 NotNull (org.jetbrains.annotations.NotNull)12 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)11 TreePath (javax.swing.tree.TreePath)11 FlowLayout (java.awt.FlowLayout)10 Tree (com.intellij.ui.treeStructure.Tree)9 Dimension (java.awt.Dimension)9 FocusEvent (java.awt.event.FocusEvent)9