Search in sources :

Example 1 with KeyEvent

use of java.awt.event.KeyEvent in project buck by facebook.

the class ChooseTargetAction method gotoActionPerformed.

@Override
protected void gotoActionPerformed(AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    if (project == null) {
        return;
    }
    final ChooseTargetModel model = new ChooseTargetModel(project);
    GotoActionCallback<String> callback = new GotoActionCallback<String>() {

        @Override
        public void elementChosen(ChooseByNamePopup chooseByNamePopup, Object element) {
            if (element == null) {
                return;
            }
            BuckSettingsProvider buckSettingsProvider = BuckSettingsProvider.getInstance();
            if (buckSettingsProvider == null || buckSettingsProvider.getState() == null) {
                return;
            }
            ChooseTargetItem item = (ChooseTargetItem) element;
            // if the target selected isn't an alias, then it has to have :
            if (item.getName().contains("//") && !item.getName().contains(":")) {
                return;
            }
            if (buckSettingsProvider.getState().lastAlias != null) {
                buckSettingsProvider.getState().lastAlias.put(project.getBasePath(), item.getBuildTarget());
            }
            BuckToolWindowFactory.updateBuckToolWindowTitle(project);
        }
    };
    showNavigationPopup(e, model, callback, "Choose Build Target", true, false);
    // Add navigation listener for auto complete
    final ChooseByNamePopup chooseByNamePopup = project.getUserData(ChooseByNamePopup.CHOOSE_BY_NAME_POPUP_IN_PROJECT_KEY);
    chooseByNamePopup.getTextField().addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (KeyEvent.VK_RIGHT == e.getKeyCode()) {
                ChooseTargetItem obj = (ChooseTargetItem) chooseByNamePopup.getChosenElement();
                if (obj != null) {
                    chooseByNamePopup.getTextField().setText(obj.getName());
                    chooseByNamePopup.getTextField().repaint();
                }
            } else {
                super.keyPressed(e);
            }
            String adText = chooseByNamePopup.getAdText();
            if (adText != null) {
                chooseByNamePopup.setAdText(adText + " and " + KeymapUtil.getKeystrokeText(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 2)) + " to use autocomplete");
            }
        }
    });
}
Also used : KeyEvent(java.awt.event.KeyEvent) Project(com.intellij.openapi.project.Project) ChooseTargetModel(com.facebook.buck.intellij.ideabuck.actions.choosetargets.ChooseTargetModel) KeyAdapter(java.awt.event.KeyAdapter) ChooseByNamePopup(com.intellij.ide.util.gotoByName.ChooseByNamePopup) BuckSettingsProvider(com.facebook.buck.intellij.ideabuck.config.BuckSettingsProvider) ChooseTargetItem(com.facebook.buck.intellij.ideabuck.actions.choosetargets.ChooseTargetItem)

Example 2 with KeyEvent

use of java.awt.event.KeyEvent in project enumerable by hraberg.

the class LambdaTest method lambdaAsKeyListenerWithRegex.

@Test
public void lambdaAsKeyListenerWithRegex() throws Exception {
    List<KeyEvent> events = new ArrayList<KeyEvent>();
    KeyListener keyListener = λ(ke, events.add(ke)).as(KeyListener.class, ".*Typed");
    KeyEvent event = new KeyEvent(new JButton(), 0, 0, 0, 0, (char) 0);
    keyListener.keyPressed(event);
    assertTrue(events.isEmpty());
    keyListener.keyReleased(event);
    assertTrue(events.isEmpty());
    keyListener.keyTyped(event);
    assertEquals(1, events.size());
}
Also used : KeyEvent(java.awt.event.KeyEvent) KeyListener(java.awt.event.KeyListener) Test(org.junit.Test)

Example 3 with KeyEvent

use of java.awt.event.KeyEvent in project screenbird by adamhub.

the class RecorderPanel method addShortcutsListener.

/**
     * Binds certain Recorder Panel Actions to key shortcuts. <BR/>
     * Current bindings <BR/>
     * - Start/Pause Recording <BR/>
     * - Toggling of Full/Custom sized screen capture <BR/>
     * - Bringing up the settings form <BR/>
     * - Start Preview/Editing Mode <BR/>
     * - Finalizing screen capture <BR/>
     */
private void addShortcutsListener() {
    KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() {

        @Override
        public boolean dispatchKeyEvent(KeyEvent e) {
            if (// We do not want to trigger any of this on upload screen 
            !jpUpload.isVisible() && // Recorder app is visible
            (jpRecorderNonRec.isVisible() || jpRecorderRec.isVisible() || jpRecorderBackup.isVisible()) && // Only if applet is in recordable state
            btnRecordNonRec.isEnabled() && // Locks all input while counting down recorder
            (countdownTimer == null) && (e.getWhen() > (lastKeyWhen + 1000))) {
                if (e.getKeyCode() == KeyEvent.VK_SPACE && !scrubManager.isPreviewing()) {
                    // Start Recording
                    e.consume();
                    lastKeyWhen = e.getWhen();
                    recordOrPause(true);
                } else if (e.getKeyCode() == KeyEvent.VK_T && (e.isControlDown() || e.getModifiers() == Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) && recorder.getStatus() != RecorderStatus.RECORDING && !scrubManager.isPreviewing()) {
                    // Toggle Fullscreen/CustomScreen
                    e.consume();
                    lastKeyWhen = e.getWhen();
                    if (Settings.ENABLE_OOPS_FEATURE) {
                        toggleFullScreen.setSelected(!toggleFullScreen.isSelected());
                    } else {
                        toggleFullScreenBackup.setSelected(!toggleFullScreen.isSelected());
                    }
                    toggleCustomFullscreen();
                } else if (e.getKeyCode() == KeyEvent.VK_ENTER && (e.isControlDown() || e.getModifiers() == Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) && !scrubManager.isPreviewing()) {
                    // End Recording
                    e.consume();
                    lastKeyWhen = e.getWhen();
                    processVideo();
                } else if (e.getKeyCode() == KeyEvent.VK_M && (e.isControlDown() || e.getModifiers() == Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) && isRecorderConfigSate() && !scrubManager.isPreviewing()) {
                    // Open Settings Menu
                    e.consume();
                    lastKeyWhen = e.getWhen();
                    showSettingsForm();
                }
            }
            return false;
        }
    });
}
Also used : KeyEvent(java.awt.event.KeyEvent) KeyEventDispatcher(java.awt.KeyEventDispatcher)

Example 4 with KeyEvent

use of java.awt.event.KeyEvent in project pcgen by PCGen.

the class TipOfTheDay method initUI.

//
// initialize the dialog
//
private void initUI() {
    final JPanel panel = new JPanel(new BorderLayout(2, 2));
    panel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
    JLabel iconLabel;
    final Icon icon = Icons.TipOfTheDay24.getImageIcon();
    iconLabel = icon != null ? new JLabel(icon) : new JLabel("TipOfTheDay24.gif");
    iconLabel.setOpaque(true);
    panel.add(iconLabel, BorderLayout.WEST);
    final JLabel lblDidYouKnow = new JLabel("    " + LanguageBundle.getString("in_tod_didyouknow"));
    FontManipulation.xxlarge(lblDidYouKnow);
    lblDidYouKnow.setOpaque(true);
    tipText = new JLabelPane();
    tipText.setBorder(null);
    tipText.setFocusable(false);
    tipText.addHyperlinkListener(new Hyperactive());
    final JScrollPane pane = new JScrollPane(tipText);
    pane.setBorder(null);
    final JPanel content = new JPanel(new BorderLayout(0, 2));
    content.add(lblDidYouKnow, BorderLayout.NORTH);
    content.add(pane, BorderLayout.CENTER);
    content.setPreferredSize(new Dimension(585, 230));
    panel.add(content, BorderLayout.CENTER);
    chkShowTips = new JCheckBox(LanguageBundle.getString("in_tod_showTips"), propertyContext.initBoolean("showTipOfTheDay", true));
    final JButton btnClose = new JButton(LanguageBundle.getString("in_close"));
    btnClose.setMnemonic(LanguageBundle.getMnemonic("in_mn_close"));
    btnClose.addActionListener(this);
    // TODO give focus to close button
    final JButton btnPrevTip = new JButton(LanguageBundle.getString("in_tod_prevTip"));
    btnPrevTip.setMnemonic(LanguageBundle.getMnemonic("in_mn_tod_prevTip"));
    btnPrevTip.addActionListener(this);
    btnPrevTip.setActionCommand(PREV);
    final JButton btnNextTip = new JButton(LanguageBundle.getString("in_tod_nextTip"));
    btnNextTip.setMnemonic(LanguageBundle.getMnemonic("in_mn_tod_nextTip"));
    btnNextTip.addActionListener(this);
    btnNextTip.setActionCommand(NEXT);
    final JPanel actions = new JPanel(new GridBagLayout());
    final GridBagConstraints c = new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 0, 0);
    actions.add(chkShowTips, c);
    final JPanel buttons = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    buttons.add(btnPrevTip);
    buttons.add(btnNextTip);
    buttons.add(btnClose);
    c.gridx = 1;
    c.anchor = GridBagConstraints.EAST;
    actions.add(buttons, c);
    panel.add(actions, BorderLayout.SOUTH);
    setContentPane(panel);
    getRootPane().setDefaultButton(btnClose);
    addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            quit();
        }
    });
    addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                quit();
            }
        }
    });
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) JLabelPane(pcgen.gui2.util.JLabelPane) Insets(java.awt.Insets) FlowLayout(java.awt.FlowLayout) GridBagLayout(java.awt.GridBagLayout) KeyAdapter(java.awt.event.KeyAdapter) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) WindowAdapter(java.awt.event.WindowAdapter) Dimension(java.awt.Dimension) JCheckBox(javax.swing.JCheckBox) KeyEvent(java.awt.event.KeyEvent) BorderLayout(java.awt.BorderLayout) Hyperactive(pcgen.gui2.tools.Hyperactive) WindowEvent(java.awt.event.WindowEvent) Icon(javax.swing.Icon)

Example 5 with KeyEvent

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

the class MavenArtifactSearchPanel method initComponents.

private void initComponents(String initialText) {
    myResultList = new Tree();
    myResultList.setExpandableItemsEnabled(false);
    myResultList.getEmptyText().setText("Loading...");
    myResultList.setRootVisible(false);
    myResultList.setShowsRootHandles(true);
    myResultList.setModel(null);
    MyArtifactCellRenderer renderer = myClassMode ? new MyClassCellRenderer(myResultList) : new MyArtifactCellRenderer(myResultList);
    myResultList.setCellRenderer(renderer);
    myResultList.setRowHeight(renderer.getPreferredSize().height);
    mySearchField = new JTextField(initialText);
    mySearchField.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            int d;
            if (e.getKeyCode() == KeyEvent.VK_DOWN) {
                d = 1;
            } else if (e.getKeyCode() == KeyEvent.VK_UP) {
                d = -1;
            } else {
                return;
            }
            int row = myResultList.getSelectionModel().getLeadSelectionRow();
            row += d;
            if (row >= 0 && row < myResultList.getRowCount()) {
                myResultList.setSelectionRow(row);
            }
        }
    });
    setLayout(new BorderLayout());
    add(mySearchField, BorderLayout.NORTH);
    JScrollPane pane = ScrollPaneFactory.createScrollPane(myResultList);
    pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    // Don't remove this line.
    pane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    // Without VERTICAL_SCROLLBAR_ALWAYS policy our custom layout
    // works incorrectly, see https://youtrack.jetbrains.com/issue/IDEA-72986
    add(pane, BorderLayout.CENTER);
    mySearchField.getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        protected void textChanged(DocumentEvent e) {
            scheduleSearch();
        }
    });
    myResultList.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            if (!myAlarm.isEmpty())
                return;
            boolean hasSelection = !myResultList.isSelectionEmpty();
            myListener.canSelectStateChanged(MavenArtifactSearchPanel.this, hasSelection);
        }
    });
    myResultList.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER && myResultList.getLastSelectedPathComponent() != null) {
                myListener.itemSelected();
                e.consume();
            }
        }
    });
    new DoubleClickListener() {

        @Override
        protected boolean onDoubleClick(MouseEvent e) {
            final TreePath path = myResultList.getPathForLocation(e.getX(), e.getY());
            if (path != null && myResultList.isPathSelected(path)) {
                Object sel = path.getLastPathComponent();
                if (sel != null && myResultList.getModel().isLeaf(sel)) {
                    myListener.itemSelected();
                    return true;
                }
            }
            return false;
        }
    }.installOn(myResultList);
}
Also used : MouseEvent(java.awt.event.MouseEvent) KeyAdapter(java.awt.event.KeyAdapter) TreeSelectionListener(javax.swing.event.TreeSelectionListener) DocumentEvent(javax.swing.event.DocumentEvent) KeyEvent(java.awt.event.KeyEvent) TreePath(javax.swing.tree.TreePath) Tree(com.intellij.ui.treeStructure.Tree) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Aggregations

KeyEvent (java.awt.event.KeyEvent)301 KeyAdapter (java.awt.event.KeyAdapter)159 MouseEvent (java.awt.event.MouseEvent)79 ActionEvent (java.awt.event.ActionEvent)74 JPanel (javax.swing.JPanel)69 ActionListener (java.awt.event.ActionListener)61 MouseAdapter (java.awt.event.MouseAdapter)59 KeyListener (java.awt.event.KeyListener)54 Dimension (java.awt.Dimension)50 JLabel (javax.swing.JLabel)48 JTextField (javax.swing.JTextField)44 BorderLayout (java.awt.BorderLayout)40 JButton (javax.swing.JButton)40 JScrollPane (javax.swing.JScrollPane)35 Insets (java.awt.Insets)33 Point (java.awt.Point)33 FocusEvent (java.awt.event.FocusEvent)31 GridBagConstraints (java.awt.GridBagConstraints)23 BoxLayout (javax.swing.BoxLayout)22 GridBagLayout (java.awt.GridBagLayout)20