Example usage for java.awt.event KeyEvent getKeyCode

List of usage examples for java.awt.event KeyEvent getKeyCode

Introduction

In this page you can find the example usage for java.awt.event KeyEvent getKeyCode.

Prototype

public int getKeyCode() 

Source Link

Document

Returns the integer keyCode associated with the key in this event.

Usage

From source file:com.projity.pm.graphic.spreadsheet.SpreadSheet.java

protected void initListeners() {
    addKeyListener(new KeyAdapter() { // TODO need to fix focus problems elsewhere for this to always work
        public void keyPressed(KeyEvent e) {
            int row = getSelectedRow();
            if (row < 0)
                return;
            CommonSpreadSheetModel model = (CommonSpreadSheetModel) getModel();
            if (e.getKeyCode() == KeyEvent.VK_INSERT)
                executeAction(MenuActionConstants.ACTION_NEW);
            else if (e.getKeyCode() == KeyEvent.VK_DELETE)
                executeAction(MenuActionConstants.ACTION_DELETE);
            else if (e.getKeyCode() == KeyEvent.VK_F3)
                GraphicManager.getInstance().doFind(SpreadSheet.this, null);
            else if (e.getKeyCode() == KeyEvent.VK_F && e.getModifiers() == KeyEvent.CTRL_MASK)
                GraphicManager.getInstance().doFind(SpreadSheet.this, null);

        }//w  ww.j a  v a 2  s. c o m
    });

}

From source file:be.ac.ua.comp.scarletnebula.gui.windows.GUI.java

private JPanel getOverlayPanel() {
    final JPanel overlayPanel = new JPanel();
    overlayPanel.setOpaque(false);//from ww w  .j  av  a  2s.c  o  m
    overlayPanel.setLayout(new GridBagLayout());
    filterTextField.addKeyListener(new KeyListener() {
        @Override
        public void keyTyped(final KeyEvent e) {

        }

        @Override
        public void keyReleased(final KeyEvent e) {
        }

        @Override
        public void keyPressed(final KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                hideFilter();
            }
        }
    });
    filterTextField.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void removeUpdate(final DocumentEvent e) {
            textChanged();

        }

        @Override
        public void insertUpdate(final DocumentEvent e) {
            textChanged();
        }

        @Override
        public void changedUpdate(final DocumentEvent e) {

        }

        private void textChanged() {
            serverListModel.filter(filterTextField.getText());
        }
    });

    final SearchField searchField = new SearchField(filterTextField);

    final ImageIcon closeIcon = Utils.icon("cross16.png");
    final JButton closeButton = new JButton(closeIcon);
    closeButton.setBounds(10, 10, closeIcon.getIconWidth(), closeIcon.getIconHeight());
    closeButton.setMargin(new Insets(0, 0, 0, 0));
    closeButton.setOpaque(false);
    closeButton.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
    closeButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            hideFilter();
        }
    });

    searchPanel.add(searchField);
    searchPanel.add(closeButton);
    // searchPanel.setBorder(BorderFactory
    // .createBevelBorder(BevelBorder.RAISED));
    searchPanel.setBorder(BorderFactory.createEtchedBorder());
    searchPanel.setVisible(false);
    searchPanel.setAlignmentX(RIGHT_ALIGNMENT);

    final GridBagConstraints c = new GridBagConstraints();
    c.anchor = GridBagConstraints.LAST_LINE_END;
    c.fill = GridBagConstraints.NONE;
    c.gridx = 0;
    c.gridy = 0;
    c.weightx = 1.0;
    c.weighty = 1.0;
    c.insets = new Insets(3, 3, 3, 3);
    overlayPanel.add(searchPanel, c);
    return overlayPanel;
}

From source file:dictionary.GUI.GUI_Main.java

private void fieldMeanKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_fieldMeanKeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        fieldWord.requestFocus();//from   w w w . ja  v  a2s  . c om
    }
}

From source file:net.minelord.gui.panes.IRCPane.java

public void startClient(final String nick) {
    IRCLog = new ArrayList<String>();
    SwingUtilities.invokeLater(new Runnable() {
        @Override/*from   w ww  .  j a v a  2  s  . c  o  m*/
        public void run() {
            text = new JEditorPane("text/html", "<HTML>");
            text.setEditable(false);
            kit = new HTMLEditorKit();
            text.setEditorKit(kit);
            client.connect("irc.liberty-unleashed.co.uk", "#moomoohk", nick, instance);
            scroller = new JScrollPane(text);
            text.setEditable(false);
            connect();
            scroller.setBounds(20, 20, 810, 250);
            add(scroller);
            input = new JTextField();
            input.setBounds(20, 270, 810, 30);
            Color bgColor = Color.gray.darker().darker();
            UIDefaults defaults = new UIDefaults();
            defaults.put("EditorPane[Enabled].backgroundPainter", bgColor);
            text.putClientProperty("Nimbus.Overrides", defaults);
            text.putClientProperty("Nimbus.Overrides.InheritDefaults", true);
            text.setBackground(bgColor);
            input.setBackground(Color.gray);
            input.setForeground(Color.gray.darker().darker().darker());
            input.setEnabled(false);
            text.addHyperlinkListener(new HyperlinkListener() {
                @Override
                public void hyperlinkUpdate(HyperlinkEvent event) {
                    if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                        if (event.getDescription().charAt(0) == '#') {
                            String[] params = { event.getDescription() };
                            IRCCommand.getCommand("/join").execute(client, params);
                        } else
                            OSUtils.browse(event.getURL().toString());
                    }
                }
            });
            text.addFocusListener(new FocusListener() {

                @Override
                public void focusLost(FocusEvent paramFocusEvent) {
                }

                @Override
                public void focusGained(FocusEvent paramFocusEvent) {
                    input.requestFocus();
                }
            });
            scroller.setViewportView(text);
            add(input);
            input.addKeyListener(new KeyListener() {

                @Override
                public void keyTyped(KeyEvent arg0) {
                }

                @Override
                public void keyReleased(KeyEvent arg0) {
                    if (arg0.getKeyCode() == 10) {
                        if (input.getText().length() > 0) {
                            lastCommandSelector = lastCommands.size();
                            lastCommands.add(input.getText());
                        }
                        sendMessage(input.getText());
                        input.setText("");
                    }
                    if (arg0.getKeyCode() == 27)
                        input.setText("");
                    if (arg0.getKeyCode() == 17) {
                        int before = input.getText().length();
                        if (input.getText().charAt(0) == '/') {
                            input.setText(completeNick(input.getText()));
                            input.select(
                                    input.getText().length() - completeNick(input.getText()).length() + before,
                                    input.getText().length());
                        } else {
                            input.setText(completeCommand(input.getText()));
                            input.select(input.getText().length() - completeCommand(input.getText()).length()
                                    + before, input.getText().length());
                        }
                    }
                    if (arg0.getKeyCode() == 38)
                        if (lastCommandSelector > 0) {
                            lastCommandSelector--;
                            input.setText(lastCommands.get(lastCommandSelector));
                        }
                    if (arg0.getKeyCode() == 40)
                        if (lastCommandSelector < lastCommands.size()) {
                            lastCommandSelector++;
                            if (lastCommandSelector == lastCommands.size())
                                input.setText("");
                            if (lastCommandSelector < lastCommands.size())
                                input.setText(lastCommands.get(lastCommandSelector));
                            return;
                        }
                }

                @Override
                public void keyPressed(KeyEvent arg0) {
                }
            });
        }
    });
}

From source file:org.freeplane.view.swing.features.time.mindmapmode.NodeList.java

public NodeList(final boolean modal, final boolean showAllNodes, final boolean searchInAllMaps) {
    //      this.modeController = modeController;
    //      controller = modeController.getController();
    this.modal = modal;
    this.showAllNodes = showAllNodes;
    this.searchInAllMaps = searchInAllMaps;
    mFilterTextSearchField = new JComboBox();
    mFilterTextSearchField.setEditable(true);
    final FilterTextDocumentListener listener = new FilterTextDocumentListener();
    mFilterTextSearchField.addActionListener(listener);
    final JTextComponent editorComponent = (JTextComponent) mFilterTextSearchField.getEditor()
            .getEditorComponent();//from   ww  w . j  a v a 2  s . c  o  m
    editorComponent.getDocument().addDocumentListener(listener);
    mFilterTextSearchField.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(final KeyEvent pEvent) {
            if (pEvent.getKeyCode() == KeyEvent.VK_DOWN) {
                mFilterTextReplaceField.requestFocusInWindow();
            }
        }
    });
    mFilterTextReplaceField = new JComboBox();
    mFilterTextReplaceField.setEditable(true);
    mFilterTextReplaceField.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(final KeyEvent pEvent) {
            if (pEvent.getKeyCode() == KeyEvent.VK_DOWN) {
                timeTable.requestFocusInWindow();
            } else if (pEvent.getKeyCode() == KeyEvent.VK_UP) {
                mFilterTextSearchField.requestFocusInWindow();
            }
        }
    });
    useRegexInReplace = new JCheckBox();
    useRegexInFind = new JCheckBox();
    useRegexInFind.addChangeListener(listener);
    matchCase = new JCheckBox();
    matchCase.addChangeListener(listener);
    final MapChangeListener mapChangeListener = new MapChangeListener();
    final ModeController modeController = Controller.getCurrentModeController();
    final MapController mapController = modeController.getMapController();
    mapController.addMapChangeListener(mapChangeListener);
    mapController.addNodeChangeListener(mapChangeListener);
    Controller.getCurrentController().getMapViewManager().addMapSelectionListener(mapChangeListener);

}

From source file:dictionary.GUI.GUI_Main.java

private void fieldWordKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_fieldWordKeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        showMean();//from   w  w  w.j  a va2s . c o m
    }

    if (!onl && (evt.getKeyCode() == KeyEvent.VK_DOWN || evt.getKeyCode() == KeyEvent.VK_UP)) {
        listEntries.requestFocus();
    }

    if (evt.getKeyCode() == KeyEvent.VK_F1) {
        if (comboBoxEV.getSelectedIndex() == 0)
            voice.speechText(fieldWord.getText());
    }
}

From source file:ru.codemine.pos.ui.keydispatcher.MainKeyDispatcher.java

@Override
public boolean dispatchKeyEvent(KeyEvent e) {
    WebTextField inputField = salesPanel.getChequeSetupPanel().getInputField();

    int tabIndex = mainWindow.getActiveTabIndex();
    boolean inputBlocked = mainWindow.isBarcodeInputBlocked();

    //?   ?,  ?   ????     - 
    //  ?  ? ?/*from  w w w  .ja va2s  . c  om*/
    if (tabIndex == 0 && !inputBlocked
            && application.getCurrentScanner()
                    .getType() == BarcodeScannerDevice.BarcodeScannerType.KEYBOARD_SCANNER
            && ("1234567890".indexOf(e.getKeyChar()) >= 0)) {
        e.setSource(inputField);
    }
    //?   Enter   ? ? - ?
    //     ??  
    else if (tabIndex == 0 && !inputBlocked && !"".equals(inputField.getText())
            && (e.getKeyCode() == KeyEvent.VK_ENTER)) {
        String barcode = inputField.getText();
        inputField.clear();
        salesPanel.addProductByBarcode(barcode);
    } else {
        if (tabIndex == 0 && !inputBlocked) {
            switch (e.getKeyCode()) {
            //case KeyEvent.VK_F2 : buttonsPanel.getOpenWorkdayButton().doClick();
            //    break;
            //case KeyEvent.VK_F3 : buttonsPanel.getCloseWorkdayButton().doClick();
            //    break;
            case KeyEvent.VK_F4:
                buttonsPanel.getQuantitySetupButton().doClick();
                break;
            case KeyEvent.VK_F5:
                buttonsPanel.getChequeProcessButton().doClick();
            }
        }
    }

    return false;
}

From source file:dictionary.GUI.GUI_Main.java

private void listEntriesKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_listEntriesKeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        fieldWord.setText(listEntries.getSelectedValue().toString());
        frameEntries.dispose();//from w  w  w .  j  av a  2  s  .  com
        frameMean.setVisible(true);
        String tmp = fieldWord.getText();
        fieldMean.setText(dic.search(new StringBuilder(tmp)));
        fieldMean.select(0, 0);
        frameMean.setLocation(this.getX() + this.getWidth(), this.getY());
        buttonAdd.setEnabled(false);
        buttonSave.setEnabled(false);
        if (recentWord.isEmpty() || !recentWord.getFirst().equals(tmp)) {
            recentWord.addFirst(tmp);
            while (recentWord.size() > 10) {
                recentWord.removeLast();
            }
        }
    }
    if (evt.getKeyCode() == KeyEvent.VK_BACK_SPACE) {
        fieldWord.requestFocus();
    }
}

From source file:com.intuit.tank.tools.debugger.AgentDebuggerFrame.java

private void handleKeyEvent(KeyEvent event) {
    if (!(event.getSource() instanceof JComboBox)) {
        if (event.getKeyCode() == KeyEvent.VK_UP) {
            moveCursor(true);//from  w  ww.j  av  a  2s. c  om
        } else if (event.getKeyCode() == KeyEvent.VK_DOWN) {
            moveCursor(false);
        }
    }
}

From source file:org.yccheok.jstock.gui.charting.ChartLayerUI.java

@Override
public void processKeyEvent(java.awt.event.KeyEvent e, JXLayer<? extends V> l) {
    if (e.getID() != KeyEvent.KEY_PRESSED) {
        // We are only interested in KEY_PRESSED event.
        return;//www.j av a 2 s.  c om
    }
    final int code = e.getKeyCode();
    switch (code) {
    case KeyEvent.VK_LEFT:
        this.updateTraceInfosIfPossible(-1);
        break;
    case KeyEvent.VK_RIGHT:
        this.updateTraceInfosIfPossible(+1);
        break;
    }
}