Java Code Examples for java.awt.event.KeyEvent#VK_ESCAPE
The following examples show how to use
java.awt.event.KeyEvent#VK_ESCAPE .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FunctionOptionsDialog.java From ramus with GNU General Public License v3.0 | 6 votes |
/** * This method initializes jContentPane * * @return javax.swing.JPanel */ private javax.swing.JPanel getJContentPane() { if (jContentPane == null) { jContentPane = new javax.swing.JPanel() { @Override protected boolean processKeyBinding(final KeyStroke ks, final KeyEvent e, final int condition, final boolean pressed) { if (e.isControlDown() && ks.getKeyCode() == KeyEvent.VK_ENTER) { onOk(); return false; } if (ks.getKeyCode() == KeyEvent.VK_ESCAPE) { onCancel(); return false; } return super.processKeyBinding(ks, e, condition, pressed); } }; jContentPane.setLayout(new java.awt.BorderLayout()); jContentPane.add(getJPanel(), java.awt.BorderLayout.SOUTH); jContentPane.add(getJPanel1(), java.awt.BorderLayout.CENTER); } return jContentPane; }
Example 2
Source File: GlassPane.java From netbeans with Apache License 2.0 | 6 votes |
/** * Processes key events. * * @param e key event. */ @Override protected void processKeyEvent(KeyEvent e) { int keyCode = e.getKeyCode(); if (keyCode == KeyEvent.VK_DELETE) { if (!selection.isEmpty()) { performAction(new DeleteComponentAction()); } } else if ((keyCode == KeyEvent.VK_ESCAPE) && (moving || resizing)) { // Cancel moving and resizing when Esc is pressed. moving = false; resizing = false; repaint(); } else { super.processKeyEvent(e); } }
Example 3
Source File: Ruler.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@Override public void keyPressed(KeyEvent e) { int step = e.isControlDown() ? 50 : e.isAltDown() ? 1 : 5; switch (e.getKeyCode()) { case KeyEvent.VK_LEFT: setLocation(getX() - step, getY()); break; case KeyEvent.VK_RIGHT: setLocation(getX() + step, getY()); break; case KeyEvent.VK_UP: setLocation(getX(), getY() - step); break; case KeyEvent.VK_DOWN: setLocation(getX(), getY() + step); break; case KeyEvent.VK_ESCAPE: exitAction.actionPerformed(null); } }
Example 4
Source File: FindTextPanel.java From netbeans-mmd-plugin with Apache License 2.0 | 6 votes |
private void textFieldSearchTextKeyPressed(java.awt.event.KeyEvent evt) { switch (evt.getKeyCode()) { case KeyEvent.VK_ESCAPE: { this.deactivate(); evt.consume(); } break; case KeyEvent.VK_ENTER: { if (evt.isShiftDown()) { findPrev(); } else { findNext(); } evt.consume(); } break; } }
Example 5
Source File: MainMenuJPanel.java From defense-solutions-proofs-of-concept with Apache License 2.0 | 6 votes |
private void jTextField_navMgrsKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField_navMgrsKeyReleased switch (evt.getKeyCode()) { case KeyEvent.VK_ESCAPE: { Utilities.closeApplication(app); break; } case KeyEvent.VK_ENTER: { jButton_navGoToMgrsActionPerformed(null); break; } default: { //Clear the error message jLabel_mgrsMessage.setText(" "); } } }
Example 6
Source File: FindTextPanel.java From netbeans-mmd-plugin with Apache License 2.0 | 6 votes |
private void textFieldSearchTextKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textFieldSearchTextKeyPressed switch(evt.getKeyCode()){ case KeyEvent.VK_ESCAPE : { this.context.hideFindTextPane(); evt.consume(); }break; case KeyEvent.VK_ENTER : { if (evt.isShiftDown()){ findPrev(); }else{ findNext(); } evt.consume(); }break; } }
Example 7
Source File: BookmarkHistoryPopup.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void keyPressed(KeyEvent e) { if (LOG.isLoggable(Level.FINE)) { LOG.fine("BookmarkHistoryPopup.keyPressed: e=" + e + '\n'); } int keyCode = e.getKeyCode(); if (gotoPreviousKeyStroke != null && gotoPreviousKeyStroke.getKeyCode() == keyCode) { e.consume(); selectPrevious(); } else if (gotoNextKeyStroke != null && gotoNextKeyStroke.getKeyCode() == keyCode) { e.consume(); selectNext(); } else { switch (keyCode) { case KeyEvent.VK_ENTER: BookmarkInfo selectedBookmark = getSelectedBookmark(); hide(); openBookmark(selectedBookmark); e.consume(); break; case KeyEvent.VK_ESCAPE: e.consume(); hide(); returnFocus(); break; case KeyEvent.VK_DOWN: e.consume(); selectNext(); break; case KeyEvent.VK_UP: e.consume(); selectPrevious(); break; } } }
Example 8
Source File: ShortcutOptionsPanel.java From wpcleaner with Apache License 2.0 | 5 votes |
/** * Action triggered when keyboard is used. * * @param e Event. * @return True if processing should end. * @see java.awt.KeyEventDispatcher#dispatchKeyEvent(java.awt.event.KeyEvent) */ @Override public boolean dispatchKeyEvent(KeyEvent e) { int key = e.getKeyCode(); if ((key == KeyEvent.VK_ALT) || (key == KeyEvent.VK_ALT_GRAPH) || (key == KeyEvent.VK_BACK_SPACE) || (key == KeyEvent.VK_BEGIN) || (key == KeyEvent.VK_CANCEL) || (key == KeyEvent.VK_CAPS_LOCK) || (key == KeyEvent.VK_CONTROL) || (key == KeyEvent.VK_DELETE) || (key == KeyEvent.VK_DOWN) || (key == KeyEvent.VK_END) || (key == KeyEvent.VK_ENTER) || (key == KeyEvent.VK_LEFT) || (key == KeyEvent.VK_PAGE_DOWN) || (key == KeyEvent.VK_PAGE_UP) || (key == KeyEvent.VK_RIGHT) || (key == KeyEvent.VK_SHIFT) || (key == KeyEvent.VK_TAB) || (key == KeyEvent.VK_UP) || (key == KeyEvent.VK_SHIFT)) { return false; } if (key != KeyEvent.VK_ESCAPE) { setKeyCode(key); } showNotice(false); KeyboardFocusManager.getCurrentKeyboardFocusManager().removeKeyEventDispatcher(this); return false; }
Example 9
Source File: FressaFunctions.java From jclic with GNU General Public License v2.0 | 5 votes |
public void eventDispatched(AWTEvent event) { KeyEvent ke = (KeyEvent) event; if (ke.getID() == KeyEvent.KEY_TYPED) { if (ke.getKeyChar() == KeyEvent.VK_ESCAPE) { disableScanning(); } else { // JOptionPane.showMessageDialog(null,ke.getKeyText(ke.getKeyChar()),"JAVA // PLAPHOONS",JOptionPane.INFORMATION_MESSAGE); } } }
Example 10
Source File: BookmarkDialog.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
@Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { BookmarkDialog.this.nameChanged = false; dispose(); } }
Example 11
Source File: ComboCompletionDialog.java From visualvm with GNU General Public License v2.0 | 5 votes |
private void jTxtItemKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTxtItemKeyPressed int i = jLstItems.getSelectedIndex(); switch (evt.getKeyCode()) { case KeyEvent.VK_ESCAPE: result = jTxtItem.getText(); setVisible(false); return; case KeyEvent.VK_DOWN: if (i < jLstItems.getModel().getSize() - 1) { i++; } jLstItems.setSelectedIndex(i); jLstItems.ensureIndexIsVisible(i); break; case KeyEvent.VK_UP: if (i > 0) { i--; } jLstItems.setSelectedIndex(i); jLstItems.ensureIndexIsVisible(i); break; } if (escapeChars.indexOf(evt.getKeyChar()) >= 0) { if (jLstItems.getSelectedIndex() >= 0) { result = jLstItems.getSelectedValue().toString(); } else { result = jTxtItem.getText(); } char pressed = evt.getKeyChar(); // we need to just accept ENTER, and replace the tab with a single // space if (pressed != '\n') { result += (pressed == '\t') ? ' ' : pressed; } setVisible(false); } }
Example 12
Source File: ProfilerPopup.java From visualvm with GNU General Public License v2.0 | 5 votes |
public boolean dispatchKeyEvent(KeyEvent e) { if (skippingEvents || e.isConsumed()) return false; if (e.getID() == KeyEvent.KEY_PRESSED && e.getKeyCode() == KeyEvent.VK_ESCAPE) if (SwingUtilities.getRootPane(this) != e.getSource()) { // Closing JPopupMenu using the ESC key e.consume(); if (DEBUG) System.err.println(">>> Closed by ESC"); // NOI18N ProfilerPopup.this.hide(); return true; } return false; }
Example 13
Source File: KeyboardSupport.java From CrossMobile with GNU Lesser General Public License v3.0 | 5 votes |
public static void reactToReleaseEvent(CEventCallback callback, int vk_event, int modifier) { switch (vk_event) { case KeyEvent.VK_CONTROL: if ((mask & MULTITOUCH.mask) != 0) callback.endMultiTouch(); break; case KeyEvent.VK_B: case KeyEvent.VK_BACK_SPACE: if ((mask & BACK.mask) != 0) callback.back(); break; case KeyEvent.VK_P: case KeyEvent.VK_SPACE: if ((mask & PAUSE.mask) != 0) ((DesktopLifecycleBridge) Native.lifecycle()).toggleActivation(); break; case KeyEvent.VK_ESCAPE: case KeyEvent.VK_Q: if ((mask & QUIT.mask) != 0) callback.powerOff(); break; case KeyEvent.VK_M: if (modifier == KeyEvent.CTRL_MASK) memoryWarning(); break; case KeyEvent.VK_H: case KeyEvent.VK_HOME: if ((mask & HOME.mask) != 0) callback.home(); break; case KeyEvent.VK_LEFT: if ((mask & ROTATE.mask) != 0) callback.rotateLeft(); break; case KeyEvent.VK_RIGHT: if ((mask & ROTATE.mask) != 0) callback.rotateRight(); break; } }
Example 14
Source File: BaselineCorrectorSetupDialog.java From mzmine3 with GNU General Public License v2.0 | 5 votes |
@Override public void keyPressed(KeyEvent ke) { int keyCode = ke.getKeyCode(); if (keyCode == KeyEvent.VK_ESCAPE) { logger.info("<ESC> Presssed."); previewTask.kill(); hidePreview(); } }
Example 15
Source File: ButtonCellEditor.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { JTable table = (JTable) cell.getParent(); table.getCellEditor().cancelCellEditing(); model.update(); } }
Example 16
Source File: KeyToggler.java From Any-Angle-Pathfinding with The Unlicense | 4 votes |
@Override public void keyPressed(KeyEvent arg0) { switch(arg0.getKeyCode()) { case KeyEvent.VK_RIGHT : goRight(1, false); break; case KeyEvent.VK_LEFT : goLeft(1, false); break; case KeyEvent.VK_UP : goRight(1, true); break; case KeyEvent.VK_DOWN : goLeft(1, true); break; case KeyEvent.VK_PAGE_UP : goRight(10, false); break; case KeyEvent.VK_PAGE_DOWN : goLeft(10, false); break; case KeyEvent.VK_D : goRight(3, true); break; case KeyEvent.VK_A : goLeft(3, true); break; case KeyEvent.VK_W : goRight(5, true); break; case KeyEvent.VK_S : goLeft(5, true); break; // O: Go right one step + take screenshot, loops around case KeyEvent.VK_O : if (goRight(1, false)) takeSnapShot(); break; // P: Go right one step + take screenshot, stop at end case KeyEvent.VK_P : if (goRight(1, true)) takeSnapShot(); break; // L: Go right multiple steps + take screenshot, stop at end case KeyEvent.VK_L : if (goRight(13, true)) takeSnapShot(); break; // Esc: Close Window case KeyEvent.VK_ESCAPE : System.exit(0); break; } }
Example 17
Source File: FindAndReplaceDialog.java From 3Dscript with BSD 2-Clause "Simplified" License | 4 votes |
public FindAndReplaceDialog(final AnimationEditor editor) { super(editor); textEditor = editor; final Container root = getContentPane(); root.setLayout(new GridBagLayout()); final JPanel text = new JPanel(new GridBagLayout()); final GridBagConstraints c = new GridBagConstraints(); c.gridx = c.gridy = 0; c.gridwidth = c.gridheight = 1; c.weightx = c.weighty = 1; c.ipadx = c.ipady = 1; c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_START; searchField = createField("Find Next", text, c, null); replaceField = createField("Replace with", text, c, this); c.gridwidth = 4; c.gridheight = c.gridy; c.gridx = c.gridy = 0; c.weightx = c.weighty = 1; c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.LINE_START; root.add(text, c); c.gridy = c.gridheight; c.gridwidth = 1; c.gridheight = 1; c.weightx = 0.001; matchCase = createCheckBox("Match Case", root, c); regex = createCheckBox("Regex", root, c); forward = createCheckBox("Search forward", root, c); forward.setSelected(true); c.gridx = 0; c.gridy++; markAll = createCheckBox("Mark All", root, c); wholeWord = createCheckBox("Whole Word", root, c); c.gridx = 4; c.gridy = 0; findNext = createButton("Find Next", root, c); replace = createButton("Replace", root, c); replaceAll = createButton("Replace All", root, c); cancel = createButton("Cancel", root, c); setResizable(true); pack(); getRootPane().setDefaultButton(findNext); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); final KeyAdapter listener = new KeyAdapter() { @Override public void keyPressed(final KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ESCAPE) dispose(); } }; for (final Component component : getContentPane().getComponents()) component.addKeyListener(listener); searchField.addKeyListener(listener); replaceField.addKeyListener(listener); }
Example 18
Source File: MainFrame.java From android-screen-monitor with Apache License 2.0 | 4 votes |
@Override public void keyPressed(KeyEvent keyEvent) { int code = keyEvent.getKeyCode(); char c = keyEvent.getKeyChar(); System.out.println(c + ":" + code + ":" + (int) c); try { switch (code) { case KeyEvent.VK_BACK_SPACE: case KeyEvent.VK_DELETE: mChimpDevice.getManager().press("KEYCODE_DEL"); break; case KeyEvent.VK_SPACE: if (isGlass()) { mChimpDevice.getManager().press("KEYCODE_DPAD_CENTER"); } else { mChimpDevice.getManager().press("KEYCODE_SPACE"); } break; case KeyEvent.VK_ESCAPE: mChimpDevice.getManager().press("KEYCODE_HOME"); break; case KeyEvent.VK_LEFT: mChimpDevice.getManager().press("KEYCODE_DPAD_LEFT"); break; case KeyEvent.VK_RIGHT: mChimpDevice.getManager().press("KEYCODE_DPAD_RIGHT"); break; case KeyEvent.VK_UP: mChimpDevice.getManager().press("KEYCODE_DPAD_UP"); break; case KeyEvent.VK_DOWN: mChimpDevice.getManager().press("KEYCODE_DPAD_DOWN"); break; default: mChimpDevice.getManager().type(c); break; } } catch (IOException e) { e.printStackTrace(); } }
Example 19
Source File: CfgPropsDialog.java From nb-springboot with Apache License 2.0 | 4 votes |
@Override public void keyPressed(KeyEvent e) { final int keyCode = e.getKeyCode(); if (keyCode == KeyEvent.VK_ESCAPE) { final String filter = txtField.getText(); if (filter == null || filter.isEmpty()) { // close dialog if filter textfield is empty setVisible(false); } else { // clear textfield txtField.setText(null); e.consume(); } } else { final int size = lCfgProps.getModel().getSize(); // short circuit if empty size if (size == 0) { return; } int selIdx = lCfgProps.getSelectedIndex(); final int pageStep = lCfgProps.getVisibleRowCount(); // calculate new index switch (keyCode) { case KeyEvent.VK_PAGE_UP: selIdx -= pageStep; // clamp to [0 : size-1] range if (selIdx < 0) { selIdx = 0; } else if (selIdx >= size) { selIdx = size - 1; } break; case KeyEvent.VK_UP: selIdx -= 1; // wrap if needed if (selIdx < 0) { selIdx += size; } else if (selIdx >= size) { selIdx -= size; } break; case KeyEvent.VK_DOWN: selIdx += 1; // wrap if needed if (selIdx < 0) { selIdx += size; } else if (selIdx >= size) { selIdx -= size; } break; case KeyEvent.VK_PAGE_DOWN: selIdx += pageStep; // clamp to [0 : size-1] range if (selIdx < 0) { selIdx = 0; } else if (selIdx >= size) { selIdx = size - 1; } break; } // move properties list selection and scroll to it lCfgProps.setSelectedIndex(selIdx); lCfgProps.scrollRectToVisible(lCfgProps.getCellBounds(selIdx, selIdx)); } }
Example 20
Source File: FlatInspector.java From FlatLaf with Apache License 2.0 | 4 votes |
public FlatInspector( JRootPane rootPane ) { this.rootPane = rootPane; mouseMotionListener = new MouseMotionAdapter() { @Override public void mouseMoved( MouseEvent e ) { lastX = e.getX(); lastY = e.getY(); inspect( lastX, lastY ); } }; rootPane.getGlassPane().addMouseMotionListener( mouseMotionListener ); keyListener = e -> { KeyEvent keyEvent = (KeyEvent) e; int keyCode = keyEvent.getKeyCode(); int id = e.getID(); if( id == KeyEvent.KEY_PRESSED ) { // this avoids that the inspection level is changed when UI inspector // is enabled with keyboard shortcut (e.g. Ctrl+Shift+Alt+X) if( keyCode == KeyEvent.VK_CONTROL || keyCode == KeyEvent.VK_SHIFT ) wasCtrlOrShiftKeyPressed = true; } else if( id == KeyEvent.KEY_RELEASED && wasCtrlOrShiftKeyPressed ) { if( keyCode == KeyEvent.VK_CONTROL ) { inspectParentLevel++; inspect( lastX, lastY ); } else if( keyCode == KeyEvent.VK_SHIFT && inspectParentLevel > 0 ) { inspectParentLevel--; inspect( lastX, lastY ); } } if( keyCode == KeyEvent.VK_ESCAPE ) { // consume pressed and released ESC key events to e.g. avoid that dialog is closed keyEvent.consume(); if( id == KeyEvent.KEY_PRESSED ) { FlatInspector inspector = (FlatInspector) rootPane.getClientProperty( FlatInspector.class ); if( inspector == FlatInspector.this ) { uninstall(); rootPane.putClientProperty( FlatInspector.class, null ); } else setEnabled( false ); } } }; }