Example usage for java.awt.event KeyEvent getID

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

Introduction

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

Prototype

public int getID() 

Source Link

Document

Returns the event type.

Usage

From source file:PVGraph.java

public PVGraph(Calendar date, int initialViewIndex) {
    super(WINDOW_TITLE_PREFIX);
    this.date = date;
    synchronized (graphs) {
        graphs.add(this);
    }/*from   ww w .  j  av a 2 s  .com*/

    views = new PVGraphView[4];
    views[DAY_VIEW_INDEX] = new DayView();
    views[MONTH_VIEW_INDEX] = new MonthView();
    views[YEAR_VIEW_INDEX] = new YearView();
    views[YEARS_VIEW_INDEX] = new YearsView();

    tabPane = new JTabbedPane();
    for (PVGraphView v : views)
        tabPane.addTab(v.getTabLabel(), v.makePanel());
    tabPane.setSelectedIndex(initialViewIndex);
    setContentPane(tabPane);
    pack();
    try {
        java.net.URL url = getClass().getResource("sun.png");
        if (url != null)
            setIconImage(ImageIO.read(url));
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }
    ;
    setVisible(true);

    KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() {
        public boolean dispatchKeyEvent(KeyEvent ke) {
            Object src = ke.getSource();
            if (src instanceof JComponent && ((JComponent) src).getRootPane().getContentPane() == tabPane) {
                if (ke.getID() == KeyEvent.KEY_TYPED) {
                    switch (ke.getKeyChar()) {
                    case 'd':
                        tabPane.setSelectedIndex(DAY_VIEW_INDEX);
                        return true;
                    case 'm':
                        tabPane.setSelectedIndex(MONTH_VIEW_INDEX);
                        return true;
                    case 'N' - 0x40:
                        new PVGraph((Calendar) PVGraph.this.date.clone(), tabPane.getSelectedIndex());
                        return true;
                    case 'Q' - 0x40:
                        dispatchEvent(new WindowEvent(PVGraph.this, WindowEvent.WINDOW_CLOSING));
                        return true;
                    case 'R' - 0x40:
                        loadProperties();
                        updateView();
                        return true;
                    case 'S':
                        try {
                            runSmatool();
                            updateView();
                        } catch (IOException ioe) {
                            System.err.println(ioe.getMessage());
                        }
                        return true;
                    case 'y':
                        tabPane.setSelectedIndex(YEAR_VIEW_INDEX);
                        return true;
                    case 'Y':
                        tabPane.setSelectedIndex(YEARS_VIEW_INDEX);
                        return true;
                    default:
                        return views[tabPane.getSelectedIndex()].handleKey(ke.getKeyChar());
                    }
                }
            }
            return false;
        }
    });
}

From source file:com.github.fritaly.dualcommander.DirectoryBrowser.java

@Override
public void keyPressed(KeyEvent e) {
    if (e.getSource() != table) {
        return;//from www  . jav  a  2s . co  m
    }

    if (e.getKeyCode() == KeyEvent.VK_ENTER) {
        // What's the current selection ?
        final List<File> selection = getSelection();

        if (selection.size() == 1) {
            final File selectedFile = selection.iterator().next();

            if (selectedFile.isDirectory()) {
                // Change to the selected directory
                setDirectory(selectedFile);
            }
        }
    } else if (e.getKeyCode() == KeyEvent.VK_BACK_SPACE) {
        // Return to the parent directory (if any)
        final File parentDir = getParentDirectory();

        if ((parentDir != null) && parentDir.exists()) {
            setDirectory(parentDir);
        }
    } else {
        // Propagate event to our listeners
        processKeyEvent(new KeyEvent(this, e.getID(), e.getWhen(), e.getModifiers(), e.getKeyCode(),
                e.getKeyChar(), e.getKeyLocation()));
    }
}

From source file:com.xyphos.vmtgen.GUI.java

@Override
public boolean dispatchKeyEvent(KeyEvent ke) {
    if (KeyEvent.KEY_PRESSED == ke.getID()) {
        System.out.println(ke.toString());
        switch (ke.getKeyCode()) {
        case KeyEvent.VK_F1:
            generateVMT();//from  www.ja  v  a2  s .c o m
            return true;

        case KeyEvent.VK_F2:
            setAllLocks(true);
            return true;

        case KeyEvent.VK_F3:
            setAllLocks(false);
            return true;

        case KeyEvent.VK_F4:
            toggleAllLocks();
            return true;

        case KeyEvent.VK_F5:
            showTextureFiles();
            return true;

        case KeyEvent.VK_F6:
            resetAllInput();
            return true;
        }
    }
    return false;
}

From source file:fs.MainWindow.java

public MainWindow() {
    initComponents();/* w ww . jav  a  2  s .co m*/
    //inicializacao do modelo numerido usado na definicao dos parametros.
    jS_QuantizationValue.setModel(new SpinnerNumberModel(2, 1, Integer.MAX_VALUE, 1));
    jS_MaxResultListSE.setModel(new SpinnerNumberModel(3, 1, Integer.MAX_VALUE, 1));
    jS_MaxSetSizeSE.setModel(new SpinnerNumberModel(3, 1, Integer.MAX_VALUE, 1));
    jS_MaxSetSizeCV.setModel(new SpinnerNumberModel(3, 1, Integer.MAX_VALUE, 1));
    jS_NrExecutionsCV.setModel(new SpinnerNumberModel(10, 1, Integer.MAX_VALUE, 1));
    jS_ThresholdEntropy.setModel(new SpinnerNumberModel(0.3, 0, 1, 0.05));
    jS_QEntropyCV.setModel(new SpinnerNumberModel(1d, 0.1d, Double.MAX_VALUE, 0.1d));
    jS_AlphaCV.setModel(new SpinnerNumberModel(1d, 0d, Double.MAX_VALUE, 0.1d));
    jS_QEntropySE.setModel(new SpinnerNumberModel(1d, 0.1d, Double.MAX_VALUE, 0.1d));
    jS_AlphaSE.setModel(new SpinnerNumberModel(1d, 0d, Double.MAX_VALUE, 0.1d));

    //captura teclas pressionadas, se for F1 aciona o JFrame Help.
    KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() {

        @Override
        public boolean dispatchKeyEvent(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_F1 && e.getID() == KeyEvent.KEY_PRESSED) {
                if (help != null) {
                    help.setVisible(false);
                    help.dispose();
                }
                if (jTabbedPane1.getSelectedIndex() == 0) {
                    help = new HelpInput();
                } else if (jTabbedPane1.getSelectedIndex() == 1) {
                    help = new HelpQuantization();
                } else if (jTabbedPane1.getSelectedIndex() == 2) {
                    help = new HelpFS();
                } else if (jTabbedPane1.getSelectedIndex() == 3) {
                    help = new HelpCV();
                }
                help.setVisible(true);
                return true;
            }
            return false;
        }
    });
}

From source file:org.executequery.gui.editor.QueryEditorTextPane.java

/**
 * Overrides <code>processKeyEvent</code> to additional process events.
 *//*from   ww  w  .  ja  v a2s .  co  m*/
protected void processKeyEvent(KeyEvent e) {

    if (e.getID() == KeyEvent.KEY_PRESSED) {

        int keyCode = e.getKeyCode();

        // add the processing for SHIFT-TAB
        if (e.isShiftDown() && keyCode == KeyEvent.VK_TAB) {

            //                int currentPosition = getCurrentPosition();
            int selectionStart = getSelectionStart();
            int selectionEnd = getSelectionEnd();

            if (selectionStart == selectionEnd) {

                int start = getCurrentRowStart();
                int end = getCurrentRowEnd();

                shiftTextLeft(start, end);

                /*
                int newPosition = currentPosition - QueryEditorSettings.getTabSize();
                int currentRowPosition = getCurrentRowStart();
                        
                if (!isAtStartOfRow()) {
                        
                if (newPosition < 0) {
                        
                    setCaretPosition(0);
                        
                } else if (newPosition < currentRowPosition) {
                        
                    setCaretPosition(currentRowPosition);
                        
                } else {
                        
                    setCaretPosition(newPosition);
                }
                        
                }
                */

            } else {

                document.shiftTabEvent(selectionStart, selectionEnd);
            }

        } else if (keyCode == KeyEvent.VK_INSERT && e.getModifiers() == 0) {

            // toggle insert mode on the document

            int insertMode = document.getInsertMode();
            if (insertMode == SqlMessages.INSERT_MODE) {

                document.setInsertMode(SqlMessages.OVERWRITE_MODE);
                editorPanel.getStatusBar().setInsertionMode("OVR");

            } else {

                document.setInsertMode(SqlMessages.INSERT_MODE);
                editorPanel.getStatusBar().setInsertionMode("INS");
            }

            ((EditorCaret) getCaret()).modeChanged();

        } else if (keyCode == KeyEvent.VK_SPACE) {

            checkForShortcutText();
        }

    }

    super.processKeyEvent(e);
    updateLineBorder();
}

From source file:org.sikuli.ide.SikuliIDE.java

private void initShortcutKeys() {
    final int scMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
        private boolean isKeyNextTab(java.awt.event.KeyEvent ke) {
            if (ke.getKeyCode() == java.awt.event.KeyEvent.VK_TAB
                    && ke.getModifiers() == InputEvent.CTRL_MASK) {
                return true;
            }//from ww  w.j  a  va  2s  . c o m
            if (ke.getKeyCode() == java.awt.event.KeyEvent.VK_CLOSE_BRACKET
                    && ke.getModifiers() == (InputEvent.META_MASK | InputEvent.SHIFT_MASK)) {
                return true;
            }
            return false;
        }

        private boolean isKeyPrevTab(java.awt.event.KeyEvent ke) {
            if (ke.getKeyCode() == java.awt.event.KeyEvent.VK_TAB
                    && ke.getModifiers() == (InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK)) {
                return true;
            }
            if (ke.getKeyCode() == java.awt.event.KeyEvent.VK_OPEN_BRACKET
                    && ke.getModifiers() == (InputEvent.META_MASK | InputEvent.SHIFT_MASK)) {
                return true;
            }
            return false;
        }

        public void eventDispatched(AWTEvent e) {
            java.awt.event.KeyEvent ke = (java.awt.event.KeyEvent) e;
            //Debug.log(ke.toString());
            if (ke.getID() == java.awt.event.KeyEvent.KEY_PRESSED) {
                if (isKeyNextTab(ke)) {
                    nextTab();
                } else if (isKeyPrevTab(ke)) {
                    prevTab();
                }
            }
        }
    }, AWTEvent.KEY_EVENT_MASK);

}

From source file:pl.otros.logview.gui.actions.MarkAllFoundAction.java

@Override
public void keyPressed(KeyEvent e) {
    if (e.getKeyCode() == 10 && KeyEvent.CTRL_MASK == e.getModifiers()) {
        actionPerformed(new ActionEvent(e.getSource(), e.getID(), ""));
    }//  w  w  w  .j av a  2  s .co m

}

From source file:ru.goodfil.catalog.ui.forms.FiltersPanel.java

private void globalHotkeys() {
    class FiltersPanelGlobalHotkey extends EventQueue {
        protected void dispatchEvent(AWTEvent event) {
            if (event instanceof KeyEvent) {
                KeyEvent keyEvent = (KeyEvent) event;
                if (keyEvent.getKeyCode() == KeyEvent.VK_F1 && keyEvent.getID() == KeyEvent.KEY_PRESSED) {
                } else {
                    super.dispatchEvent(event);
                }//from w  w  w  . ja  v a  2  s  .c  o  m
            } else {
                super.dispatchEvent(event);
            }
        }
    }

    EventQueue ev = Toolkit.getDefaultToolkit().getSystemEventQueue();
    ev.push(new FiltersPanelGlobalHotkey());
}

From source file:thesaurusEditor.gui.graph.MainGraph.java

public void keyEventHappened(KeyEvent e) {
    if (e.getID() == KeyEvent.KEY_PRESSED) {
        graphMouse.getModeKeyListener().keyPressed(e);
    }//from w  ww . j  a v a  2 s  . c  om
    if (e.getID() == KeyEvent.KEY_RELEASED) {
        graphMouse.getModeKeyListener().keyReleased(e);
        ;
    }
}

From source file:view.MainWindow.java

@Override
public boolean dispatchKeyEvent(KeyEvent e) {
    if (e.getID() == KeyEvent.KEY_PRESSED) {
        if (e.isControlDown()) {
            if (e.getKeyCode() == KeyEvent.VK_W) {
                closeDocument(true);//from w  ww.  j  a  v a2  s.  c o m
            } else if (e.getKeyCode() == KeyEvent.VK_ADD) {
                workspacePanel.zoomIn();
            } else if (e.getKeyCode() == KeyEvent.VK_SUBTRACT) {
                workspacePanel.zoomOut();
            } else if (e.getKeyCode() == KeyEvent.VK_DOWN || e.getKeyCode() == KeyEvent.VK_RIGHT) {
                workspacePanel.pageUp();
            } else if (e.getKeyCode() == KeyEvent.VK_UP || e.getKeyCode() == KeyEvent.VK_LEFT) {
                workspacePanel.pageDown();
            }
            if (e.isShiftDown()) {
                if (e.getKeyCode() == KeyEvent.VK_S) {
                    workspacePanel.changeCard(WorkspacePanel.CardEnum.SIGN_PANEL, true);
                } else if (e.getKeyCode() == KeyEvent.VK_V) {
                    workspacePanel.changeCard(WorkspacePanel.CardEnum.VALIDATE_PANEL, true);
                }
            }
        }
    } else if (e.getID() == KeyEvent.KEY_RELEASED) {
    } else if (e.getID() == KeyEvent.KEY_TYPED) {
    }
    return false;
}