List of usage examples for java.awt KeyEventDispatcher KeyEventDispatcher
KeyEventDispatcher
From source file:com.willwinder.universalgcodesender.MainWindow.java
private void initProgram() { Localization.initialize(this.settings.getLanguage()); try {/*from w ww. 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; } }); }
From source file:org.datavyu.views.DatavyuView.java
/** * Constructor.// w ww .j ava 2s. c o m * * @param app * The SingleFrameApplication that invoked this main FrameView. */ public DatavyuView(final SingleFrameApplication app) { super(app); KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); manager.addKeyEventDispatcher(new KeyEventDispatcher() { /** * Dispatches the keystroke to the correct action. * * @param evt The event that triggered this action. * @return true if the KeyboardFocusManager should take no further * action with regard to the KeyEvent; false otherwise. */ @Override public boolean dispatchKeyEvent(final KeyEvent evt) { // Pass the keyevent onto the keyswitchboard so that it can // route it to the correct action. // spreadsheetMenuSelected(null); return Datavyu.getApplication().dispatchKeyEvent(evt); } }); // generated GUI builder code initComponents(); // BugzID:492 - Set the shortcut for new cell, so a keystroke that won't // get confused for the "carriage return". The shortcut for new cells // is handled in Datavyu.java newCellMenuItem.setAccelerator(KeyStroke.getKeyStroke('\u21A9')); // BugzID:521 + 468 - Define accelerator keys based on Operating system. int keyMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); weakTemporalOrderMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, keyMask)); strongTemporalOrderMenuItem .setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, InputEvent.SHIFT_MASK | keyMask)); // Set zoom in to keyMask + '+' zoomInMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, keyMask)); // Set zoom out to keyMask + '-' zoomOutMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, keyMask)); // Set reset zoom to keyMask + '0' resetZoomMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_0, keyMask)); // Set the save accelerator to keyMask + 'S' saveMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, keyMask)); // Set the save as accelerator to keyMask + shift + 'S' saveAsMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, keyMask | InputEvent.SHIFT_MASK)); // Set the open accelerator to keyMask + 'o'; openMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, keyMask)); // Set the new accelerator to keyMask + 'N'; newMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, keyMask)); // Set the new accelerator to keyMask + 'L'; newCellLeftMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, keyMask)); // Set the new accelerator to keyMask + 'R'; newCellRightMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, keyMask)); // Set the show spreadsheet accelrator to F5. showSpreadsheetMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0)); // Set the undo accelerator to keyMask + 'Z'; undoSpreadSheetMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, keyMask)); // Set the redo accelerator to keyMask + 'Y' redoSpreadSheetMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Y, keyMask)); if (panel != null) { panel.deregisterListeners(); panel.removeFileDropEventListener(this); } panel = new SpreadsheetPanel(Datavyu.getProjectController().getDB(), null); panel.registerListeners(); panel.addFileDropEventListener(this); setComponent(panel); System.out.println(getComponent()); // initialize the undo/redo system spreadsheetUndoManager = new SpreadsheetUndoManager(); undoSupport = new UndoableEditSupport(); undoSupport.addUndoableEditListener(new UndoAdapter()); refreshUndoRedo(); ////// //Jakrabbit Menu pushMenuItem.setVisible(false); pullMenuItem.setVisible(false); jSeparator10.setVisible(false); }
From source file:vista.ventas.DiagOrdenesDeCompra.java
private void eventosDeTeclas() { KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); manager.addKeyEventDispatcher(new KeyEventDispatcher() { public boolean dispatchKeyEvent(KeyEvent e) { if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow().getClass() .getSimpleName().equals("DiagOrdenesDeCompra")) { if (e.getID() == KeyEvent.KEY_PRESSED) { if (e.getKeyCode() == KeyEvent.VK_F3) { agregarArticulo(); calcularTotal(); }//from w w w. j a va 2s . co m if (e.getKeyCode() == KeyEvent.VK_F7) { realizarVenta(); } if (e.getKeyCode() == KeyEvent.VK_F4) { cerrar(); } if (e.getKeyCode() == KeyEvent.VK_DELETE && tblArticulos.getSelectedRow() != -1) { quitarArticuloLista(); } } } return false; } }); }
From source file:vista.ventas.DialogEntregas.java
private void eventosDeTeclas() { KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); manager.addKeyEventDispatcher(new KeyEventDispatcher() { public boolean dispatchKeyEvent(KeyEvent e) { if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow().getClass() .getSimpleName().equals("DialogEntregas")) { if (e.getID() == KeyEvent.KEY_PRESSED) { if (e.getKeyCode() == KeyEvent.VK_F3) { agregarArticulo(); calcularSubtotalGral(); }// w w w . jav a2 s .c o m if (e.getKeyCode() == KeyEvent.VK_F7) { realizarVenta(); } if (e.getKeyCode() == KeyEvent.VK_F4) { cerrar(); } } } return false; } }); }