Search in sources :

Example 26 with KeyEvent

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

the class GrTypeComboBox method registerUpDownHint.

public static void registerUpDownHint(JComponent component, final GrTypeComboBox combo) {
    final AnAction arrow = new AnAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            if (e.getInputEvent() instanceof KeyEvent) {
                final int code = ((KeyEvent) e.getInputEvent()).getKeyCode();
                scrollBy(code == KeyEvent.VK_DOWN ? 1 : code == KeyEvent.VK_UP ? -1 : 0, combo);
            }
        }
    };
    final KeyboardShortcut up = new KeyboardShortcut(KeyStroke.getKeyStroke(KeyEvent.VK_UP, InputEvent.ALT_DOWN_MASK), null);
    final KeyboardShortcut down = new KeyboardShortcut(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, InputEvent.ALT_DOWN_MASK), null);
    arrow.registerCustomShortcutSet(new CustomShortcutSet(up, down), component);
}
Also used : KeyEvent(java.awt.event.KeyEvent) CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) KeyboardShortcut(com.intellij.openapi.actionSystem.KeyboardShortcut) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 27 with KeyEvent

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

the class IpnbEditablePanel method createEditablePanel.

private JTextArea createEditablePanel() {
    final JTextArea textArea = new JTextArea(getRawCellText());
    textArea.setLineWrap(true);
    textArea.setEditable(true);
    textArea.setBorder(BorderFactory.createLineBorder(JBColor.lightGray));
    textArea.setBackground(IpnbEditorUtil.getEditablePanelBackground());
    textArea.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 1) {
                setEditing(true);
                final Container parent = getParent();
                parent.repaint();
                if (parent instanceof IpnbFilePanel) {
                    ((IpnbFilePanel) parent).setSelectedCellPanel(IpnbEditablePanel.this);
                    IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
                        IdeFocusManager.getGlobalInstance().requestFocus(textArea, true);
                    });
                }
            }
        }
    });
    textArea.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                setEditing(false);
                final Container parent = getParent();
                if (parent instanceof IpnbFilePanel) {
                    parent.repaint();
                    UIUtil.requestFocus((IpnbFilePanel) parent);
                }
            }
        }
    });
    return textArea;
}
Also used : KeyEvent(java.awt.event.KeyEvent) MouseEvent(java.awt.event.MouseEvent) KeyAdapter(java.awt.event.KeyAdapter) MouseAdapter(java.awt.event.MouseAdapter)

Example 28 with KeyEvent

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

the class AddRepositoryLocationDialog method createCenterPanel.

protected JComponent createCenterPanel() {
    JLabel selectText = new JLabel(message("repository.browser.add.location.prompt"));
    selectText.setUI(new MultiLineLabelUI());
    JPanel mainPanel = new JPanel(new GridBagLayout());
    GridBagConstraints gb = new GridBagConstraints(0, 0, 1, 1, 1, 0, NORTHWEST, NONE, insets(5), 0, 0);
    mainPanel.add(selectText, gb);
    ++gb.gridy;
    myCombo = new ComboBox<>(new CollectionComboBoxModel<>(myPreviousLocations));
    myCombo.setEditable(true);
    myCombo.setMinimumSize(size(250, 20));
    gb.fill = HORIZONTAL;
    mainPanel.add(myCombo, gb);
    gb.fill = NONE;
    myComboField = (JTextField) myCombo.getEditor().getEditorComponent();
    myComboField.addInputMethodListener(new InputMethodListener() {

        public void inputMethodTextChanged(InputMethodEvent event) {
            validateMe();
        }

        public void caretPositionChanged(InputMethodEvent event) {
            validateMe();
        }
    });
    myComboField.addKeyListener(new KeyListener() {

        public void keyTyped(KeyEvent e) {
            validateMe();
        }

        public void keyPressed(KeyEvent e) {
            validateMe();
        }

        public void keyReleased(KeyEvent e) {
            validateMe();
        }
    });
    myCombo.addActionListener(e -> validateMe());
    validateMe();
    JPanel wrapper = new JPanel(new GridBagLayout());
    wrapper.add(mainPanel, new GridBagConstraints(0, 0, 1, 1, 1, 1, NORTHWEST, HORIZONTAL, emptyInsets(), 0, 0));
    wrapper.setPreferredSize(size(400, 70));
    return wrapper;
}
Also used : MultiLineLabelUI(com.intellij.openapi.ui.MultiLineLabelUI) KeyEvent(java.awt.event.KeyEvent) GridBagConstraints(java.awt.GridBagConstraints) CollectionComboBoxModel(com.intellij.ui.CollectionComboBoxModel) InputMethodListener(java.awt.event.InputMethodListener) KeyListener(java.awt.event.KeyListener) InputMethodEvent(java.awt.event.InputMethodEvent)

Example 29 with KeyEvent

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

the class EmmetAbbreviationBalloon method show.

public void show(@NotNull final CustomTemplateCallback customTemplateCallback) {
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        if (ourTestingAbbreviation == null) {
            throw new RuntimeException("Testing abbreviation is not set. See EmmetAbbreviationBalloon#setTestingAbbreviation");
        }
        myCallback.onEnter(ourTestingAbbreviation);
        return;
    }
    final TextFieldWithStoredHistory field = new TextFieldWithStoredHistory(myAbbreviationsHistoryKey);
    final Dimension fieldPreferredSize = field.getPreferredSize();
    field.setPreferredSize(new Dimension(Math.max(220, fieldPreferredSize.width), fieldPreferredSize.height));
    field.setHistorySize(10);
    final JBPopupFactory popupFactory = JBPopupFactory.getInstance();
    final BalloonImpl balloon = (BalloonImpl) popupFactory.createDialogBalloonBuilder(field, myTitle).setCloseButtonEnabled(false).setBlockClicksThroughBalloon(true).setAnimationCycle(0).setHideOnKeyOutside(true).setHideOnClickOutside(true).createBalloon();
    final DocumentAdapter documentListener = new DocumentAdapter() {

        @Override
        protected void textChanged(DocumentEvent e) {
            if (!isValid(customTemplateCallback)) {
                balloon.hide();
                return;
            }
            validateTemplateKey(field, balloon, field.getText(), customTemplateCallback);
        }
    };
    field.addDocumentListener(documentListener);
    final KeyAdapter keyListener = new KeyAdapter() {

        @Override
        public void keyPressed(@NotNull KeyEvent e) {
            if (!field.isPopupVisible()) {
                if (!isValid(customTemplateCallback)) {
                    balloon.hide();
                    return;
                }
                switch(e.getKeyCode()) {
                    case KeyEvent.VK_ENTER:
                        final String abbreviation = field.getText();
                        if (validateTemplateKey(field, balloon, abbreviation, customTemplateCallback)) {
                            myCallback.onEnter(abbreviation);
                            PropertiesComponent.getInstance().setValue(myLastAbbreviationKey, abbreviation);
                            field.addCurrentTextToHistory();
                            balloon.hide();
                        }
                        break;
                    case KeyEvent.VK_ESCAPE:
                        balloon.hide(false);
                        break;
                }
            }
        }
    };
    field.addKeyboardListener(keyListener);
    balloon.addListener(new JBPopupListener.Adapter() {

        @Override
        public void beforeShown(LightweightWindowEvent event) {
            field.setText(PropertiesComponent.getInstance().getValue(myLastAbbreviationKey, ""));
        }

        @Override
        public void onClosed(LightweightWindowEvent event) {
            field.removeKeyListener(keyListener);
            field.removeDocumentListener(documentListener);
            super.onClosed(event);
        }
    });
    balloon.show(popupFactory.guessBestPopupLocation(customTemplateCallback.getEditor()), Balloon.Position.below);
    final IdeFocusManager focusManager = IdeFocusManager.getInstance(customTemplateCallback.getProject());
    focusManager.doWhenFocusSettlesDown(() -> {
        focusManager.requestFocus(field, true);
        field.selectText();
    });
}
Also used : KeyAdapter(java.awt.event.KeyAdapter) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) DocumentEvent(javax.swing.event.DocumentEvent) NotNull(org.jetbrains.annotations.NotNull) LightweightWindowEvent(com.intellij.openapi.ui.popup.LightweightWindowEvent) KeyEvent(java.awt.event.KeyEvent) JBPopupListener(com.intellij.openapi.ui.popup.JBPopupListener) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory)

Example 30 with KeyEvent

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

the class ToBeMergedDialog method addRevisionListListeners.

private void addRevisionListListeners() {
    final int checkboxWidth = new JCheckBox().getPreferredSize().width;
    new ClickListener() {

        @Override
        public boolean onClick(@NotNull MouseEvent e, int clickCount) {
            final int idx = myRevisionsList.rowAtPoint(e.getPoint());
            if (idx >= 0) {
                final Rectangle baseRect = myRevisionsList.getCellRect(idx, 0, false);
                baseRect.setSize(checkboxWidth, baseRect.height);
                if (baseRect.contains(e.getPoint())) {
                    toggleInclusion(myRevisionsModel.getRowValue(idx));
                    myRevisionsList.repaint(baseRect);
                }
            }
            return true;
        }
    }.installOn(myRevisionsList);
    myRevisionsList.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            if (KeyEvent.VK_SPACE == e.getKeyCode()) {
                List<SvnChangeList> selected = myRevisionsList.getSelectedObjects();
                if (!selected.isEmpty()) {
                    selected.forEach(ToBeMergedDialog.this::toggleInclusion);
                    myRevisionsList.repaint();
                    e.consume();
                }
            }
        }
    });
}
Also used : KeyEvent(java.awt.event.KeyEvent) MouseEvent(java.awt.event.MouseEvent) KeyAdapter(java.awt.event.KeyAdapter) Collections.singletonList(java.util.Collections.singletonList) SvnChangeList(org.jetbrains.idea.svn.history.SvnChangeList) List(java.util.List) ContainerUtilRt.emptyList(com.intellij.util.containers.ContainerUtilRt.emptyList)

Aggregations

KeyEvent (java.awt.event.KeyEvent)135 KeyAdapter (java.awt.event.KeyAdapter)69 MouseEvent (java.awt.event.MouseEvent)31 ActionEvent (java.awt.event.ActionEvent)23 ActionListener (java.awt.event.ActionListener)19 KeyListener (java.awt.event.KeyListener)19 JPanel (javax.swing.JPanel)18 MouseAdapter (java.awt.event.MouseAdapter)17 JLabel (javax.swing.JLabel)17 JButton (javax.swing.JButton)14 JTextField (javax.swing.JTextField)14 JScrollPane (javax.swing.JScrollPane)13 BorderLayout (java.awt.BorderLayout)12 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 Project (com.intellij.openapi.project.Project)8 Dimension (java.awt.Dimension)8