Example usage for java.awt.event KeyEvent VK_LEFT

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

Introduction

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

Prototype

int VK_LEFT

To view the source code for java.awt.event KeyEvent VK_LEFT.

Click Source Link

Document

Constant for the non-numpad left arrow key.

Usage

From source file:org.yccheok.jstock.gui.charting.InvestmentFlowLayerUI.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;/* w  ww.ja  v a  2  s  .c  o m*/
    }
    final int code = e.getKeyCode();
    switch (code) {
    case KeyEvent.VK_LEFT:
        this.updatePointAndIndexIfPossible(-1);
        break;
    case KeyEvent.VK_RIGHT:
        this.updatePointAndIndexIfPossible(+1);
        break;
    case KeyEvent.VK_UP:
        // Switch to another stock.
        this.investmentFlowChartJDialog.selectPreviousJComboBoxSelection();
        break;
    case KeyEvent.VK_DOWN:
        // Switch to another stock.
        this.investmentFlowChartJDialog.selectNextJComboBoxSelection();
        break;
    }
}

From source file:com.sshtools.sshterm.emulation.TerminalEmulation.java

public void keyPressed(int keyCode, char keyChar, int modifiers) {
    if (debug > 0) {
        System.out.println("keyPressed(" + keyCode + "," + keyChar + "," + modifiers);
    }//from   w  w w.  j ava  2  s.  c om
    boolean control = (modifiers & VDUInput.KEY_CONTROL) != 0;
    boolean shift = (modifiers & VDUInput.KEY_SHIFT) != 0;
    boolean alt = (modifiers & VDUInput.KEY_ALT) != 0;
    int xind;
    String[] fmap;
    xind = 0;
    fmap = FunctionKey;
    if (shift) {
        fmap = FunctionKeyShift;
        xind = 1;
    }
    if (control) {
        fmap = FunctionKeyCtrl;
        xind = 2;
    }
    if (alt) {
        fmap = FunctionKeyAlt;
        xind = 3;
    }
    switch (keyCode) {
    case KeyEvent.VK_PAUSE:
        if (shift || control) {
            sendTelnetCommand((byte) 243);
        }

        // BREAK
        break;
    case KeyEvent.VK_ESCAPE:
        writeSpecial(Escape[xind]);
        break;
    case KeyEvent.VK_F1:
        writeSpecial(fmap[1]);
        break;
    case KeyEvent.VK_F2:
        writeSpecial(fmap[2]);
        break;
    case KeyEvent.VK_F3:
        writeSpecial(fmap[3]);
        break;
    case KeyEvent.VK_F4:
        writeSpecial(fmap[4]);
        break;
    case KeyEvent.VK_F5:
        writeSpecial(fmap[5]);
        break;
    case KeyEvent.VK_F6:
        writeSpecial(fmap[6]);
        break;
    case KeyEvent.VK_F7:
        writeSpecial(fmap[7]);
        break;
    case KeyEvent.VK_F8:
        writeSpecial(fmap[8]);
        break;
    case KeyEvent.VK_F9:
        writeSpecial(fmap[9]);
        break;
    case KeyEvent.VK_F10:
        writeSpecial(fmap[10]);
        break;
    case KeyEvent.VK_F11:
        writeSpecial(fmap[11]);
        break;
    case KeyEvent.VK_F12:
        writeSpecial(fmap[12]);
        break;
    case KeyEvent.VK_UP:
        writeSpecial(KeyUp[xind]);
        break;
    case KeyEvent.VK_DOWN:
        writeSpecial(KeyDown[xind]);
        break;
    case KeyEvent.VK_LEFT:
        writeSpecial(KeyLeft[xind]);
        break;
    case KeyEvent.VK_RIGHT:
        writeSpecial(KeyRight[xind]);
        break;
    case KeyEvent.VK_PAGE_DOWN:
        writeSpecial(NextScn[xind]);
        break;
    case KeyEvent.VK_PAGE_UP:
        writeSpecial(PrevScn[xind]);
        break;
    case KeyEvent.VK_INSERT:
        writeSpecial(Insert[xind]);
        break;
    case KeyEvent.VK_DELETE:
        writeSpecial(Remove[xind]);
        break;
    case KeyEvent.VK_BACK_SPACE:
        writeSpecial(BackSpace[xind]);
        if (localecho) {
            if (BackSpace[xind] == "\b" || BackSpace[xind] == "\u007f") {
                putString("\b \b");
                // make the last char 'deleted'
            } else {
                putString(BackSpace[xind]);
                // echo it
            }
        }
        break;
    case KeyEvent.VK_HOME:
        writeSpecial(KeyHome[xind]);
        break;
    case KeyEvent.VK_END:
        writeSpecial(KeyEnd[xind]);
        break;
    case KeyEvent.VK_NUM_LOCK:
        if (vms && control) {
            writeSpecial(PF1);
        }
        if (!control) {
            numlock = !numlock;
        }
        break;
    case KeyEvent.VK_CAPS_LOCK:
        capslock = !capslock;
        return;
    case KeyEvent.VK_SHIFT:
    case KeyEvent.VK_CONTROL:
    case KeyEvent.VK_ALT:
        return;
    default:
        break;
    }
}

From source file:com.mirth.connect.client.ui.browsers.message.MessageBrowser.java

/**
 * Sets the properties and adds the listeners for the Message Table. No data is loaded at this
 * point.//ww w. j a  va  2  s . c o m
 */
private void makeMessageTable() {
    messageTreeTable.setDragEnabled(true);
    messageTreeTable.setSortable(false);
    messageTreeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    messageTreeTable.setColumnFactory(new MessageBrowserTableColumnFactory());
    messageTreeTable.setLeafIcon(null);
    messageTreeTable.setOpenIcon(null);
    messageTreeTable.setClosedIcon(null);
    messageTreeTable.setAutoCreateColumnsFromModel(false);
    messageTreeTable.setMirthColumnControlEnabled(true);
    messageTreeTable.setShowGrid(true, true);
    messageTreeTable.setHorizontalScrollEnabled(true);
    messageTreeTable.setPreferredScrollableViewportSize(messageTreeTable.getPreferredSize());
    messageTreeTable.setMirthTransferHandlerEnabled(true);

    tableModel = new MessageBrowserTableModel(columnMap.size());
    // Add a blank column to the column initially, otherwise it return an exception on load
    // Columns will be re-generated when the message browser is viewed
    tableModel.setColumnIdentifiers(Arrays.asList(new String[] { "" }));
    messageTreeTable.setTreeTableModel(tableModel);

    // Sets the alternating highlighter for the table
    if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
        Highlighter highlighter = HighlighterFactory.createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR,
                UIConstants.BACKGROUND_COLOR);
        messageTreeTable.setHighlighters(highlighter);
    }

    // Add the listener for when the table selection changes
    messageTreeTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent evt) {
            MessageListSelected(evt);
        }

    });

    // Add the mouse listener
    messageTreeTable.addMouseListener(new java.awt.event.MouseAdapter() {

        public void mousePressed(java.awt.event.MouseEvent evt) {
            checkMessageSelectionAndPopupMenu(evt);
        }

        public void mouseReleased(java.awt.event.MouseEvent evt) {
            checkMessageSelectionAndPopupMenu(evt);
        }

        // Opens the send message dialog when a message is double clicked.
        // If the root message or source connector is selected, select all destination connectors initially
        // If a destination connector is selected, select only that destination connector initially
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            if (evt.getClickCount() >= 2) {
                int row = getSelectedMessageIndex();
                if (row >= 0) {
                    MessageBrowserTableNode messageNode = (MessageBrowserTableNode) messageTreeTable
                            .getPathForRow(row).getLastPathComponent();
                    if (messageNode.isNodeActive()) {
                        Long messageId = messageNode.getMessageId();
                        Integer metaDataId = messageNode.getMetaDataId();

                        Message currentMessage = messageCache.get(messageId);
                        ConnectorMessage connectorMessage = currentMessage.getConnectorMessages()
                                .get(metaDataId);
                        List<Integer> selectedMetaDataIds = new ArrayList<Integer>();

                        Map<String, Object> sourceMap = new HashMap<String, Object>();
                        if (connectorMessage.getSourceMap() != null) {
                            sourceMap.putAll(connectorMessage.getSourceMap());
                            // Remove the destination set if it exists, because that will be determined by the selected metadata IDs
                            sourceMap.remove("destinationSet");
                        }

                        if (metaDataId == 0) {
                            selectedMetaDataIds = null;
                        } else {
                            selectedMetaDataIds.add(metaDataId);
                        }

                        if (connectorMessage.getRaw() != null) {
                            parent.editMessageDialog.setPropertiesAndShow(
                                    connectorMessage.getRaw().getContent(),
                                    connectorMessage.getRaw().getDataType(), channelId,
                                    parent.dashboardPanel.getDestinationConnectorNames(channelId),
                                    selectedMetaDataIds, sourceMap);
                        }
                    }
                }
            }
        }
    });

    // Key Listener trigger for DEL
    messageTreeTable.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            int row = getSelectedMessageIndex();
            if (row >= 0) {
                if (e.getKeyCode() == KeyEvent.VK_DELETE) {
                    MessageBrowserTableNode messageNode = (MessageBrowserTableNode) messageTreeTable
                            .getPathForRow(row).getLastPathComponent();

                    if (messageNode.isNodeActive()) {
                        parent.doRemoveMessage();
                    }

                } else if (descriptionTabbedPane.getTitleAt(descriptionTabbedPane.getSelectedIndex())
                        .equals("Messages")) {
                    if (e.getKeyCode() == KeyEvent.VK_LEFT) {
                        List<AbstractButton> buttons = Collections.list(messagesGroup.getElements());
                        boolean passedSelected = false;
                        for (int i = buttons.size() - 1; i >= 0; i--) {
                            AbstractButton button = buttons.get(i);
                            if (passedSelected && button.isShowing()) {
                                lastUserSelectedMessageType = buttons.get(i).getText();
                                updateMessageRadioGroup();
                                break;
                            } else if (button.isSelected()) {
                                passedSelected = true;
                            }
                        }
                    } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
                        List<AbstractButton> buttons = Collections.list(messagesGroup.getElements());
                        boolean passedSelected = false;
                        for (int i = 0; i < buttons.size(); i++) {
                            AbstractButton button = buttons.get(i);
                            if (passedSelected && button.isShowing()) {
                                lastUserSelectedMessageType = buttons.get(i).getText();
                                updateMessageRadioGroup();
                                break;
                            } else if (button.isSelected()) {
                                passedSelected = true;
                            }
                        }
                    }
                }
            }

        }
    });
}

From source file:oct.analysis.application.OCTAnalysisUI.java

private void octAnalysisPanelKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_octAnalysisPanelKeyPressed
    OCTSelection sel = null;//from w  w w .  ja  v  a2 s. co  m
    //determine direction to move the selection
    switch (evt.getKeyCode()) {
    case KeyEvent.VK_RIGHT:
        switch (analysisMngr.getAnalysisMode()) {
        case MIRROR:
            sel = selectionLRPManager.getSelectedSelection();
            if (sel.getSelectionName().equals("Left")) {
                //move left selection to the right and right selection to the left (i.e. move them closer to fovea selection)
                selectionLRPManager.moveSelectionRight(sel);
                sel = selectionLRPManager.getSelections().stream()
                        .filter(s -> s.getSelectionName().equals("Right")).findFirst().get();
                selectionLRPManager.moveSelectionLeft(sel);
            } else {
                //move left selection to the left and right selection to the right (i.e. move them away from the fovea selection)
                selectionLRPManager.moveSelectionRight(sel);
                sel = selectionLRPManager.getSelections().stream()
                        .filter(s -> s.getSelectionName().equals("Left")).findFirst().get();
                selectionLRPManager.moveSelectionLeft(sel);
            }
            break;
        case SINGLE:
        case EZ:
            sel = selectionLRPManager.getSelectedSelection();
            if (sel.isMoveable()) {
                selectionLRPManager.moveSelectionRight(sel);
            }
            break;
        default:
            break;
        }
        break;
    case KeyEvent.VK_LEFT:
        switch (analysisMngr.getAnalysisMode()) {
        case MIRROR:
            sel = selectionLRPManager.getSelectedSelection();
            if (sel.getSelectionName().equals("Right")) {
                //move left selection to the right and right selection to the left (i.e. move them closer to fovea selection)
                selectionLRPManager.moveSelectionLeft(sel);
                sel = selectionLRPManager.getSelections().stream()
                        .filter(s -> s.getSelectionName().equals("Left")).findFirst().get();
                selectionLRPManager.moveSelectionRight(sel);
            } else {
                //move left selection to the left and right selection to the right (i.e. move them away from the fovea selection)
                selectionLRPManager.moveSelectionLeft(sel);
                sel = selectionLRPManager.getSelections().stream()
                        .filter(s -> s.getSelectionName().equals("Right")).findFirst().get();
                selectionLRPManager.moveSelectionRight(sel);
            }
            break;
        case SINGLE:
        case EZ:
            sel = selectionLRPManager.getSelectedSelection();
            if (sel.isMoveable()) {
                selectionLRPManager.moveSelectionRight(sel);
            }
            break;
        default:
            break;
        }
        break;
    default:
        break;
    }
    //refresh the OCT analysis panel with the updated selection information
    octAnalysisPanel.repaint();
}

From source file:Report_PRCR_New_EPF_Excel_File_Generator.java

private void monthfield1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_monthfield1KeyPressed
    if (monthfield1.getText().equals("Jan")) {
        if (evt.getKeyCode() == KeyEvent.VK_DOWN) {
            monthfield1.setText("Dec");
            int yr = Integer.parseInt(yearfield.getText());

            yearfield1.setText("" + (yr - 1));
            monthfield1.selectAll();/* w  ww .  j a  va2 s .com*/

        }
        if (evt.getKeyCode() == KeyEvent.VK_UP) {
            monthfield1.setText("Feb");
            monthfield1.selectAll();
        }

    } else if (monthfield1.getText().equals("Feb")) {
        if (evt.getKeyCode() == KeyEvent.VK_DOWN) {
            monthfield1.setText("Jan");
            int yr = Integer.parseInt(yearfield.getText());
            monthfield1.selectAll();

        }
        if (evt.getKeyCode() == KeyEvent.VK_UP) {
            monthfield1.setText("Mar");
            monthfield1.selectAll();
        }

    } else if (monthfield1.getText().equals("Mar")) {
        if (evt.getKeyCode() == KeyEvent.VK_DOWN) {
            monthfield1.setText("Feb");
            int yr = Integer.parseInt(yearfield1.getText());
            monthfield1.selectAll();
        }
        if (evt.getKeyCode() == KeyEvent.VK_UP) {
            monthfield1.setText("Apr");
            monthfield1.selectAll();
        }

    } else if (monthfield1.getText().equals("Apr")) {
        if (evt.getKeyCode() == KeyEvent.VK_DOWN) {
            monthfield1.setText("Mar");
            int yr = Integer.parseInt(yearfield1.getText());
            monthfield1.selectAll();
        }
        if (evt.getKeyCode() == KeyEvent.VK_UP) {
            monthfield1.setText("May");
            monthfield1.selectAll();
        }

    } else if (monthfield1.getText().equals("May")) {
        if (evt.getKeyCode() == KeyEvent.VK_DOWN) {
            monthfield1.setText("Apr");
            int yr = Integer.parseInt(yearfield1.getText());
            monthfield1.selectAll();

        }
        if (evt.getKeyCode() == KeyEvent.VK_UP) {

            monthfield1.setText("Jun");
            monthfield1.selectAll();
        }

    } else if (monthfield1.getText().equals("Jun")) {
        if (evt.getKeyCode() == KeyEvent.VK_DOWN) {
            monthfield1.setText("May");
            int yr = Integer.parseInt(yearfield1.getText());
            monthfield1.selectAll();

        }
        if (evt.getKeyCode() == KeyEvent.VK_UP) {
            monthfield1.setText("Jul");
            monthfield1.selectAll();
        }

    } else if (monthfield1.getText().equals("Jul")) {
        if (evt.getKeyCode() == KeyEvent.VK_DOWN) {
            monthfield1.setText("Jun");
            int yr = Integer.parseInt(yearfield1.getText());
            monthfield1.selectAll();

        }
        if (evt.getKeyCode() == KeyEvent.VK_UP) {
            monthfield1.setText("Aug");
            monthfield1.selectAll();
        }

    } else if (monthfield1.getText().equals("Aug")) {
        if (evt.getKeyCode() == KeyEvent.VK_DOWN) {
            monthfield1.setText("Jul");
            int yr = Integer.parseInt(yearfield1.getText());
            monthfield1.selectAll();

        }
        if (evt.getKeyCode() == KeyEvent.VK_UP) {
            monthfield1.setText("Sep");
            monthfield1.selectAll();
        }

    } else if (monthfield1.getText().equals("Sep")) {
        if (evt.getKeyCode() == KeyEvent.VK_DOWN) {
            monthfield1.setText("Aug");
            int yr = Integer.parseInt(yearfield1.getText());
            monthfield1.selectAll();

        }
        if (evt.getKeyCode() == KeyEvent.VK_UP) {
            monthfield1.setText("Oct");
            monthfield1.selectAll();
        }

    } else if (monthfield1.getText().equals("Oct")) {
        if (evt.getKeyCode() == KeyEvent.VK_DOWN) {
            monthfield1.setText("Sep");
            int yr = Integer.parseInt(yearfield1.getText());
            monthfield1.selectAll();

        }
        if (evt.getKeyCode() == KeyEvent.VK_UP) {
            monthfield1.setText("Nov");
            monthfield1.selectAll();
        }

    } else if (monthfield1.getText().equals("Nov")) {
        if (evt.getKeyCode() == KeyEvent.VK_DOWN) {
            monthfield1.setText("Oct");
            int yr = Integer.parseInt(yearfield1.getText());
            monthfield1.selectAll();

        }
        if (evt.getKeyCode() == KeyEvent.VK_UP) {
            monthfield1.setText("Dec");
            monthfield1.selectAll();
        }

    } else if (monthfield1.getText().equals("Dec")) {
        if (evt.getKeyCode() == KeyEvent.VK_DOWN) {
            monthfield1.setText("Nov");
            int yr = Integer.parseInt(yearfield1.getText());
            monthfield1.selectAll();

        }
        if (evt.getKeyCode() == KeyEvent.VK_UP) {
            monthfield1.setText("Jan");
            int yr = Integer.parseInt(yearfield1.getText());

            yearfield1.setText("" + (yr + 1));
            monthfield1.selectAll();
        }

    }
    if (evt.getKeyCode() == KeyEvent.VK_LEFT) {
        dayfield.requestFocus();
        dayfield.selectAll();
    }
    if (evt.getKeyCode() == KeyEvent.VK_RIGHT) {
        yearfield1.requestFocus();
        yearfield1.selectAll();
    }

    if (evt.getKeyCode() == KeyEvent.VK_ENTER) { ////// ChaNGE  focus on enter////////////////
        // recieptNo.requestFocus();

    }
}

From source file:Report_PRCR_New_EPF_Excel_File_Generator.java

private void yearfield1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_yearfield1KeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_UP) {
        yearfield.setText("" + (Integer.parseInt(yearfield.getText()) + 1));
        yearfield.selectAll();/* w ww. jav  a  2s  .  co  m*/
    }
    if (evt.getKeyCode() == KeyEvent.VK_DOWN) {
        yearfield.setText("" + (Integer.parseInt(yearfield.getText()) - 1));
        yearfield.selectAll();
    }
    if (evt.getKeyCode() == KeyEvent.VK_LEFT) {
        monthfield.requestFocus();
        monthfield.selectAll();
    }

    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
    }
}

From source file:net.sf.jabref.gui.BasePanel.java

private void createMainTable() {
    database.registerListener(tableModel.getListSynchronizer());
    database.registerListener(SpecialFieldDatabaseChangeListener.getInstance());

    tableFormat = new MainTableFormat(database);
    tableFormat.updateTableFormat();//from   ww  w. j  ava  2  s .c om
    mainTable = new MainTable(tableFormat, tableModel, frame, this);

    selectionListener = new MainTableSelectionListener(this, mainTable);
    mainTable.updateFont();
    mainTable.addSelectionListener(selectionListener);
    mainTable.addMouseListener(selectionListener);
    mainTable.addKeyListener(selectionListener);
    mainTable.addFocusListener(selectionListener);

    // Add the listener that will take care of highlighting groups as the selection changes:
    groupsHighlightListener = listEvent -> {
        HighlightMatchingGroupPreferences highlightMatchingGroupPreferences = new HighlightMatchingGroupPreferences(
                Globals.prefs);
        if (highlightMatchingGroupPreferences.isAny()) {
            getGroupSelector().showMatchingGroups(mainTable.getSelectedEntries(), false);
        } else if (highlightMatchingGroupPreferences.isAll()) {
            getGroupSelector().showMatchingGroups(mainTable.getSelectedEntries(), true);
        } else {
            // no highlight
            getGroupSelector().showMatchingGroups(null, true);
        }
    };
    mainTable.addSelectionListener(groupsHighlightListener);

    mainTable.getActionMap().put(Actions.CUT, new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                runCommand(Actions.CUT);
            } catch (Throwable ex) {
                LOGGER.warn("Could not cut", ex);
            }
        }
    });
    mainTable.getActionMap().put(Actions.COPY, new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                runCommand(Actions.COPY);
            } catch (Throwable ex) {
                LOGGER.warn("Could not copy", ex);
            }
        }
    });
    mainTable.getActionMap().put(Actions.PASTE, new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                runCommand(Actions.PASTE);
            } catch (Throwable ex) {
                LOGGER.warn("Could not paste", ex);
            }
        }
    });

    mainTable.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            final int keyCode = e.getKeyCode();
            final TreePath path = frame.getGroupSelector().getSelectionPath();
            final GroupTreeNodeViewModel node = path == null ? null
                    : (GroupTreeNodeViewModel) path.getLastPathComponent();

            if (e.isControlDown()) {
                switch (keyCode) {
                // The up/down/left/rightkeystrokes are displayed in the
                // GroupSelector's popup menu, so if they are to be changed,
                // edit GroupSelector.java accordingly!
                case KeyEvent.VK_UP:
                    e.consume();
                    if (node != null) {
                        frame.getGroupSelector().moveNodeUp(node, true);
                    }
                    break;
                case KeyEvent.VK_DOWN:
                    e.consume();
                    if (node != null) {
                        frame.getGroupSelector().moveNodeDown(node, true);
                    }
                    break;
                case KeyEvent.VK_LEFT:
                    e.consume();
                    if (node != null) {
                        frame.getGroupSelector().moveNodeLeft(node, true);
                    }
                    break;
                case KeyEvent.VK_RIGHT:
                    e.consume();
                    if (node != null) {
                        frame.getGroupSelector().moveNodeRight(node, true);
                    }
                    break;
                case KeyEvent.VK_PAGE_DOWN:
                    frame.nextTab.actionPerformed(null);
                    e.consume();
                    break;
                case KeyEvent.VK_PAGE_UP:
                    frame.prevTab.actionPerformed(null);
                    e.consume();
                    break;
                default:
                    break;
                }
            } else if (keyCode == KeyEvent.VK_ENTER) {
                e.consume();
                try {
                    runCommand(Actions.EDIT);
                } catch (Throwable ex) {
                    LOGGER.warn("Could not run action based on key press", ex);
                }
            }
        }
    });
}

From source file:org.forester.archaeopteryx.TreePanel.java

final private void keyPressedCalls(final KeyEvent e) {
    if (isOvOn() && (getMousePosition() != null) && (getMousePosition().getLocation() != null)) {
        if (inOvVirtualRectangle(getMousePosition().x, getMousePosition().y)) {
            if (!isInOvRect()) {
                setInOvRect(true);// ww  w.  j  a  v a2 s.  c o m
            }
        } else if (isInOvRect()) {
            setInOvRect(false);
        }
    }
    if (e.getModifiersEx() == InputEvent.CTRL_DOWN_MASK) {
        if ((e.getKeyCode() == KeyEvent.VK_DELETE) || (e.getKeyCode() == KeyEvent.VK_HOME)
                || (e.getKeyCode() == KeyEvent.VK_F)) {
            getMainPanel().getTreeFontSet().mediumFonts();
            getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged(true);
        } else if ((e.getKeyCode() == KeyEvent.VK_SUBTRACT) || (e.getKeyCode() == KeyEvent.VK_MINUS)) {
            getMainPanel().getTreeFontSet().decreaseFontSize();
            getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged(true);
        } else if (plusPressed(e.getKeyCode())) {
            getMainPanel().getTreeFontSet().increaseFontSize();
            getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged(true);
        }
    } else {
        if ((e.getKeyCode() == KeyEvent.VK_DELETE) || (e.getKeyCode() == KeyEvent.VK_HOME)
                || (e.getKeyCode() == KeyEvent.VK_F)) {
            getControlPanel().showWhole();
        } else if ((e.getKeyCode() == KeyEvent.VK_UP) || (e.getKeyCode() == KeyEvent.VK_DOWN)
                || (e.getKeyCode() == KeyEvent.VK_LEFT) || (e.getKeyCode() == KeyEvent.VK_RIGHT)) {
            if (e.getModifiersEx() == InputEvent.SHIFT_DOWN_MASK) {
                if (e.getKeyCode() == KeyEvent.VK_UP) {
                    getMainPanel().getControlPanel().zoomInY(Constants.WHEEL_ZOOM_IN_FACTOR);
                    getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged(false);
                } else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
                    getMainPanel().getControlPanel().zoomOutY(Constants.WHEEL_ZOOM_OUT_FACTOR);
                    getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged(false);
                } else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
                    getMainPanel().getControlPanel().zoomOutX(Constants.WHEEL_ZOOM_OUT_FACTOR,
                            Constants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR);
                    getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged(false);
                } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
                    getMainPanel().getControlPanel().zoomInX(Constants.WHEEL_ZOOM_IN_FACTOR,
                            Constants.WHEEL_ZOOM_IN_FACTOR);
                    getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged(false);
                }
            } else {
                final int d = 80;
                int dx = 0;
                int dy = -d;
                if (e.getKeyCode() == KeyEvent.VK_DOWN) {
                    dy = d;
                } else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
                    dx = -d;
                    dy = 0;
                } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
                    dx = d;
                    dy = 0;
                }
                final Point scroll_position = getMainPanel().getCurrentScrollPane().getViewport()
                        .getViewPosition();
                scroll_position.x = scroll_position.x + dx;
                scroll_position.y = scroll_position.y + dy;
                if (scroll_position.x <= 0) {
                    scroll_position.x = 0;
                } else {
                    final int max_x = getMainPanel().getCurrentScrollPane().getHorizontalScrollBar()
                            .getMaximum()
                            - getMainPanel().getCurrentScrollPane().getHorizontalScrollBar().getVisibleAmount();
                    if (scroll_position.x >= max_x) {
                        scroll_position.x = max_x;
                    }
                }
                if (scroll_position.y <= 0) {
                    scroll_position.y = 0;
                } else {
                    final int max_y = getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getMaximum()
                            - getMainPanel().getCurrentScrollPane().getVerticalScrollBar().getVisibleAmount();
                    if (scroll_position.y >= max_y) {
                        scroll_position.y = max_y;
                    }
                }
                repaint();
                getMainPanel().getCurrentScrollPane().getViewport().setViewPosition(scroll_position);
            }
        } else if ((e.getKeyCode() == KeyEvent.VK_SUBTRACT) || (e.getKeyCode() == KeyEvent.VK_MINUS)) {
            getMainPanel().getControlPanel().zoomOutY(Constants.WHEEL_ZOOM_OUT_FACTOR);
            getMainPanel().getControlPanel().zoomOutX(Constants.WHEEL_ZOOM_OUT_FACTOR,
                    Constants.WHEEL_ZOOM_OUT_X_CORRECTION_FACTOR);
            getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged(false);
        } else if (plusPressed(e.getKeyCode())) {
            getMainPanel().getControlPanel().zoomInX(Constants.WHEEL_ZOOM_IN_FACTOR,
                    Constants.WHEEL_ZOOM_IN_FACTOR);
            getMainPanel().getControlPanel().zoomInY(Constants.WHEEL_ZOOM_IN_FACTOR);
            getMainPanel().getControlPanel().displayedPhylogenyMightHaveChanged(false);
        } else if (e.getKeyCode() == KeyEvent.VK_S) {
            if ((getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED)
                    || (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR)) {
                setStartingAngle((getStartingAngle() % TWO_PI) + ANGLE_ROTATION_UNIT);
                getControlPanel().displayedPhylogenyMightHaveChanged(false);
            }
        } else if (e.getKeyCode() == KeyEvent.VK_A) {
            if ((getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED)
                    || (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR)) {
                setStartingAngle((getStartingAngle() % TWO_PI) - ANGLE_ROTATION_UNIT);
                if (getStartingAngle() < 0) {
                    setStartingAngle(TWO_PI + getStartingAngle());
                }
                getControlPanel().displayedPhylogenyMightHaveChanged(false);
            }
        } else if (e.getKeyCode() == KeyEvent.VK_D) {
            boolean selected = false;
            if (getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.HORIZONTAL) {
                getOptions().setNodeLabelDirection(NODE_LABEL_DIRECTION.RADIAL);
                selected = true;
            } else {
                getOptions().setNodeLabelDirection(NODE_LABEL_DIRECTION.HORIZONTAL);
            }
            if (getMainPanel().getMainFrame() == null) {
                // Must be "E" applet version.
                final ArchaeopteryxE ae = (ArchaeopteryxE) ((MainPanelApplets) getMainPanel()).getApplet();
                if (ae.getlabelDirectionCbmi() != null) {
                    ae.getlabelDirectionCbmi().setSelected(selected);
                }
            } else {
                getMainPanel().getMainFrame().getlabelDirectionCbmi().setSelected(selected);
            }
            repaint();
        } else if (e.getKeyCode() == KeyEvent.VK_X) {
            switchDisplaygetPhylogenyGraphicsType();
            repaint();
        } else if (e.getKeyCode() == KeyEvent.VK_C) {
            cycleColors();
            repaint();
        } else if (getOptions().isShowOverview() && isOvOn() && (e.getKeyCode() == KeyEvent.VK_O)) {
            MainFrame.cycleOverview(getOptions(), this);
            repaint();
        } else if (getOptions().isShowOverview() && isOvOn() && (e.getKeyCode() == KeyEvent.VK_I)) {
            increaseOvSize();
        } else if (getOptions().isShowOverview() && isOvOn() && (e.getKeyCode() == KeyEvent.VK_U)) {
            decreaseOvSize();
        }
        e.consume();
    }
}

From source file:Demo3D.java

/**
 * Override Behavior's stimulus method to handle the event. This method is
 * called when a key on the keyboard has been pressed and operates on the
 * specified transform group to move the camera.
 * /*from  www.  jav  a  2 s  . c om*/
 * @param Enumeration
 *            criteria - all pressed keys in a list. This will be passed by
 *            the system.
 */
public void processStimulus(Enumeration criteria) {
    WakeupOnAWTEvent eventToWakeUp;
    AWTEvent[] events;

    if (criteria.hasMoreElements()) {
        // Decode the wakeup criteria
        eventToWakeUp = (WakeupOnAWTEvent) criteria.nextElement();
        events = eventToWakeUp.getAWTEvent();
        keyEvent = (KeyEvent) events[0];
        int keyCode = keyEvent.getKeyCode();

        // Perform our processing

        // Get the initial transformation from target and put it into
        // myKeyNavTransf3D
        target_trGr.getTransform(myKeyNavTransf3D);

        // Set the translational components of myKeyNavTransf3D in
        // translation
        myKeyNavTransf3D.get(translation);

        // Not any of the 8 motions (6 translations and 2 rotations)
        // don't act simultaneously.
        switch (keyCode) {
        case KeyEvent.VK_UP: // Up Arrow - to move forward
            trans_rot.set(new Vector3f(0.0f, 0.0f, -step));
            break;

        case KeyEvent.VK_DOWN: // Down Arrow - to move backwards
            trans_rot.set(new Vector3f(0.0f, 0.0f, step));
            break;

        case KeyEvent.VK_LEFT: // Left Arrow -to turn left or move left
            if (keyEvent.isShiftDown())
                trans_rot.set(new Vector3f(-step, 0.0f, 0.0f));
            else
                trans_rot.rotY(angle);
            break;

        case KeyEvent.VK_RIGHT: // Right Arrow - to turn right or move right
            if (keyEvent.isShiftDown())
                trans_rot.set(new Vector3f(step, 0.0f, 0.0f));
            else
                trans_rot.rotY(-angle);
            break;

        case KeyEvent.VK_PAGE_DOWN: // Page Down - to move down
            trans_rot.set(new Vector3f(0.0f, -step, 0.0f));
            break;

        case KeyEvent.VK_PAGE_UP: // Page Up - to move up
            trans_rot.set(new Vector3f(0.0f, step, 0.0f));
            break;

        default:
            trans_rot.set(new Vector3f(0.0f, 0.0f, 0.0f));
        }

        myKeyNavTransf3D.mul(trans_rot);

        // Return the final transformation myKeyNavTransf3D to target
        target_trGr.setTransform(myKeyNavTransf3D);
    }

    // Set wakeup criteria for next time.
    wakeupOn(wakeUp);
}

From source file:com.willwinder.universalgcodesender.MainWindow.java

private void initProgram() {
    Localization.initialize(this.settings.getLanguage());
    try {//  ww  w . j a v  a 2s .  c  o m
        backend.applySettings(settings);
    } catch (Exception e) {
        displayErrorDialog(e.getMessage());
    }

    this.setLocalLabels();
    this.loadPortSelector();
    this.checkScrollWindow();
    this.loadFirmwareSelector();
    this.setTitle(
            Localization.getString("title") + " (" + Localization.getString("version") + " " + VERSION + ")");

    // Command History
    this.manualCommandHistory = new ArrayList<>();

    // Add keyboard listener for manual controls.
    KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() {
        @Override
        public boolean dispatchKeyEvent(KeyEvent e) {
            // Check context.
            if (((arrowMovementEnabled.isSelected()) && e.getID() == KeyEvent.KEY_PRESSED)
                    && xPlusButton.isEnabled()) {
                switch (e.getKeyCode()) {
                case KeyEvent.VK_RIGHT:
                case KeyEvent.VK_KP_RIGHT:
                case KeyEvent.VK_NUMPAD6:
                    xPlusButtonActionPerformed(null);
                    e.consume();
                    return true;
                case KeyEvent.VK_LEFT:
                case KeyEvent.VK_KP_LEFT:
                case KeyEvent.VK_NUMPAD4:
                    xMinusButtonActionPerformed(null);
                    e.consume();
                    return true;
                case KeyEvent.VK_UP:
                case KeyEvent.VK_KP_UP:
                case KeyEvent.VK_NUMPAD8:
                    yPlusButtonActionPerformed(null);
                    e.consume();
                    return true;
                case KeyEvent.VK_DOWN:
                case KeyEvent.VK_KP_DOWN:
                case KeyEvent.VK_NUMPAD2:
                    yMinusButtonActionPerformed(null);
                    e.consume();
                    return true;
                case KeyEvent.VK_PAGE_UP:
                case KeyEvent.VK_NUMPAD9:
                    zPlusButtonActionPerformed(null);
                    e.consume();
                    return true;
                case KeyEvent.VK_PAGE_DOWN:
                case KeyEvent.VK_NUMPAD3:
                    zMinusButtonActionPerformed(null);
                    e.consume();
                    return true;
                case KeyEvent.VK_ADD:
                    increaseStepActionPerformed(null);
                    e.consume();
                    return true;
                case KeyEvent.VK_SUBTRACT:
                    decreaseStepActionPerformed(null);
                    e.consume();
                    return true;
                case KeyEvent.VK_DIVIDE:
                    divideStepActionPerformed(null);
                    e.consume();
                    return true;
                case KeyEvent.VK_MULTIPLY:
                    multiplyStepActionPerformed(null);
                    e.consume();
                    return true;
                case KeyEvent.VK_INSERT:
                case KeyEvent.VK_NUMPAD0:
                    resetCoordinatesButtonActionPerformed(null);
                    e.consume();
                    return true;
                default:
                    break;
                }
            }

            return false;
        }
    });
}