Java Code Examples for java.awt.event.KeyEvent#getSource()
The following examples show how to use
java.awt.event.KeyEvent#getSource() .
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: FmtSpaces.java From netbeans with Apache License 2.0 | 7 votes |
@Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_SPACE || e.getKeyCode() == KeyEvent.VK_ENTER) { if (e.getSource() instanceof JTree) { JTree tree = (JTree) e.getSource(); TreePath path = tree.getSelectionPath(); if (toggle(path)) { e.consume(); } } } }
Example 2
Source File: NodeSelectionListener.java From netbeans with Apache License 2.0 | 6 votes |
@Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_SPACE) { if (e.getSource() instanceof JTree) { JTree t = (JTree) e.getSource(); TreePath path = t.getSelectionPath(); if (path != null) { CheckNode node = (CheckNode) path.getLastPathComponent(); boolean isSelected = !(node.isSelected()); node.setSelected(isSelected); ((DefaultTreeModel) tree.getModel()).nodeChanged(node); tree.revalidate(); tree.repaint(); } e.consume(); } } }
Example 3
Source File: CheckListener.java From netbeans with Apache License 2.0 | 6 votes |
@Override public void keyPressed(KeyEvent e) { if (e.getKeyChar() == ' ') { // NOI18N JTree tree = (JTree) e.getSource(); TreePath path = tree.getSelectionPath(); if (path == null) { return; } Node node = Visualizer.findNode(path.getLastPathComponent()); if (node == null) { return; } boolean isSelected = model.isNodeSelected(node); model.setNodeSelected(node, !isSelected); tree.repaint(); e.consume(); } }
Example 4
Source File: NameAutocompleter.java From plugins with GNU General Public License v3.0 | 5 votes |
private void newAutocomplete(KeyEvent e) { final JTextComponent input = (JTextComponent) e.getSource(); final String inputText = input.getText(); final String nameStart = inputText.substring(0, input.getSelectionStart()) + e.getKeyChar(); if (findAutocompleteName(nameStart)) { // Assert this.autocompleteName != null final String name = this.autocompleteName; SwingUtilities.invokeLater(() -> { try { input.getDocument().insertString( nameStart.length(), name.substring(nameStart.length()), null); input.select(nameStart.length(), name.length()); } catch (BadLocationException ex) { log.warn("Could not autocomplete name.", ex); } }); } }
Example 5
Source File: Editor.java From i18n-editor with MIT License | 5 votes |
@Override public void keyReleased(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { TranslationKeyField field = (TranslationKeyField) e.getSource(); String key = field.getValue(); addTranslation(key); } }
Example 6
Source File: Client_singleFrame.java From Java with Artistic License 2.0 | 5 votes |
@Override public void keyPressed(KeyEvent arg0) { if(arg0.getKeyCode() == KeyEvent.VK_ENTER){ if(arg0.getSource() == jtf_inputMess){ jbt_trans.doClick(); } } }
Example 7
Source File: JavadocCompletionItem.java From netbeans with Apache License 2.0 | 5 votes |
public void processKeyEvent(KeyEvent evt) { if (evt.getID() == KeyEvent.KEY_TYPED) { if (Utilities.getJavadocCompletionSelectors().indexOf(evt.getKeyChar()) >= 0) { JTextComponent comp = (JTextComponent) evt.getSource(); delegate.defaultAction(comp); if (Utilities.getJavadocCompletionAutoPopupTriggers().indexOf(evt.getKeyChar()) >= 0) { Completion.get().showCompletion(); } evt.consume(); } } }
Example 8
Source File: HintsPanelLogic.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_SPACE) { if ( e.getSource() instanceof JTree ) { JTree tree = (JTree) e.getSource(); TreePath path = tree.getSelectionPath(); if ( toggle( path )) { e.consume(); } } } }
Example 9
Source File: RevertDeletedAction.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void keyPressed(KeyEvent e) { int keyCode = e.getKeyCode(); if (keyCode == KeyEvent.VK_SPACE) { JTree tree = (JTree) e.getSource(); TreePath path = tree.getSelectionPath(); if (path != null) { FileNode node = (FileNode) path.getLastPathComponent(); node.setSelected(!node.isSelected()); tree.repaint(); e.consume(); } } }
Example 10
Source File: KeyboardPopupSwitcher.java From netbeans with Apache License 2.0 | 5 votes |
public void eventDispatched(AWTEvent event) { if (!(event instanceof KeyEvent)) { return; } KeyEvent keyEvent = (KeyEvent)event; if (keyEvent.getKeyCode() == KeyEvent.VK_ALT) { Toolkit.getDefaultToolkit().removeAWTEventListener(this); KeyEvent kev = new KeyEvent( (Component)keyEvent.getSource(), KeyEvent.KEY_RELEASED, keyEvent.getWhen(), keyEvent.getModifiers(), keyEvent.getKeyCode(), keyEvent.getKeyChar() ); KeyboardPopupSwitcher.processInterruption(kev); } }
Example 11
Source File: BegTableUI.java From consulo with Apache License 2.0 | 5 votes |
public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { if (table.isEditing()) { e.consume(); table.removeEditor(); if (e.getSource() != table) { ((JComponent)e.getSource()).removeKeyListener(this); } } } }
Example 12
Source File: SchedulerAuthenticationGUIHelper.java From scheduling with GNU Affero General Public License v3.0 | 5 votes |
/** * @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent) */ public void keyPressed(KeyEvent e) { if (e.getSource() == this.jButton_Cancel && e.getKeyCode() == KeyEvent.VK_ENTER) { this.cancel = true; terminate(); } if (e.getKeyCode() == KeyEvent.VK_ENTER) { terminate(); } }
Example 13
Source File: FmtSpaces.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_SPACE || e.getKeyCode() == KeyEvent.VK_ENTER ) { if ( e.getSource() instanceof JTree ) { JTree tree = (JTree) e.getSource(); TreePath path = tree.getSelectionPath(); if ( toggle( path )) { e.consume(); } } } }
Example 14
Source File: NameAutocompleter.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
@Override public void keyTyped(KeyEvent e) { if (!hiscoreConfig.autocomplete()) { return; } final JTextComponent input = (JTextComponent)e.getSource(); final String inputText = input.getText(); // Only autocomplete if the selection end is at the end of the text. if (input.getSelectionEnd() != inputText.length()) { return; } // Character to be inserted at the selection start. final String charToInsert = Character.toString(e.getKeyChar()); // Don't attempt to autocomplete if the name is invalid. // This condition is also true when the user presses a key like backspace. if (INVALID_CHARS.matcher(charToInsert).find() || INVALID_CHARS.matcher(inputText).find()) { return; } // Check if we are already autocompleting. if (autocompleteName != null && autocompleteNamePattern.matcher(inputText).matches()) { if (isExpectedNext(input, charToInsert)) { try { // Insert the character and move the selection. final int insertIndex = input.getSelectionStart(); Document doc = input.getDocument(); doc.remove(insertIndex, 1); doc.insertString(insertIndex, charToInsert, null); input.select(insertIndex + 1, input.getSelectionEnd()); } catch (BadLocationException ex) { log.warn("Could not insert character.", ex); } // Prevent default behavior. e.consume(); } else // Character to insert does not match current autocompletion. Look for another name. { newAutocomplete(e); } } else // Search for a name to autocomplete { newAutocomplete(e); } }
Example 15
Source File: Patch.java From TrakEM2 with GNU General Public License v3.0 | 4 votes |
@Override public void keyPressed(final KeyEvent ke) { final Object source = ke.getSource(); if (! (source instanceof DisplayCanvas)) return; final DisplayCanvas dc = (DisplayCanvas)source; final Roi roi = dc.getFakeImagePlus().getRoi(); final int mod = ke.getModifiers(); switch (ke.getKeyCode()) { case KeyEvent.VK_C: // copy into ImageJ clipboard // Ignoring masks: outside is already black, and ImageJ cannot handle alpha masks. if (0 == (mod ^ (Event.SHIFT_MASK | Event.ALT_MASK))) { // Place the source image, untransformed, into clipboard: final ImagePlus imp = getImagePlus(); if (null != imp) imp.copy(false); } else if (0 == mod || (0 == (mod ^ Event.SHIFT_MASK))) { CoordinateTransformList<CoordinateTransform> list = null; if (hasCoordinateTransform()) { list = new CoordinateTransformList<CoordinateTransform>(); list.add(getCoordinateTransform()); } if (0 == mod) { //SHIFT is not down final AffineModel2D am = new AffineModel2D(); am.set(this.at); if (null == list) list = new CoordinateTransformList<CoordinateTransform>(); list.add(am); } ImageProcessor ip; if (null != list) { final TransformMesh mesh = new TransformMesh(list, meshResolution, o_width, o_height); final TransformMeshMapping mapping = new TransformMeshMapping(mesh); ip = mapping.createMappedImageInterpolated(getImageProcessor()); } else { ip = getImageProcessor(); } new ImagePlus(this.title, ip).copy(false); } ke.consume(); break; case KeyEvent.VK_F: // fill mask with current ROI using if (null != roi && M.isAreaROI(roi)) { Bureaucrat.createAndStart(new Worker.Task("Filling image mask") { @Override public void exec() { getLayerSet().addDataEditStep(Patch.this); if (0 == mod) { addAlphaMask(roi, ProjectToolbar.getForegroundColorValue()); } else if (0 == (mod ^ Event.SHIFT_MASK)) { // shift is down: fill outside try { final Area localRoi = M.areaInInts(M.getArea(roi)).createTransformedArea(at.createInverse()); final Area invLocalRoi = new Area(new Rectangle(0, 0, getOWidth() , getOHeight())); invLocalRoi.subtract(localRoi); addAlphaMaskLocal(invLocalRoi, ProjectToolbar.getForegroundColorValue()); } catch (final NoninvertibleTransformException e) { IJError.print(e); return; } } getLayerSet().addDataEditStep(Patch.this); try { updateMipMaps().get(); } catch (final Throwable t) { IJError.print(t); } // wait Display.repaint(); } }, project); } // capturing: ke.consume(); break; default: super.keyPressed(ke); break; } }
Example 16
Source File: DefaultKeyboardFocusManager.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
private boolean preDispatchKeyEvent(KeyEvent ke) { if (((AWTEvent) ke).isPosted) { Component focusOwner = getFocusOwner(); ke.setSource(((focusOwner != null) ? focusOwner : getFocusedWindow())); } if (ke.getSource() == null) { return true; } // Explicitly set the key event timestamp here (not in Component.dispatchEventImpl): // - A key event is anyway passed to this method which starts its actual dispatching. // - If a key event is put to the type ahead queue, its time stamp should not be registered // until its dispatching actually starts (by this method). EventQueue.setCurrentEventAndMostRecentTime(ke); /** * Fix for 4495473. * This fix allows to correctly dispatch events when native * event proxying mechanism is active. * If it is active we should redispatch key events after * we detected its correct target. */ if (KeyboardFocusManager.isProxyActive(ke)) { Component source = (Component)ke.getSource(); Container target = source.getNativeContainer(); if (target != null) { ComponentPeer peer = target.getPeer(); if (peer != null) { peer.handleEvent(ke); /** * Fix for 4478780 - consume event after it was dispatched by peer. */ ke.consume(); } } return true; } java.util.List<KeyEventDispatcher> dispatchers = getKeyEventDispatchers(); if (dispatchers != null) { for (java.util.Iterator<KeyEventDispatcher> iter = dispatchers.iterator(); iter.hasNext(); ) { if (iter.next(). dispatchKeyEvent(ke)) { return true; } } } return dispatchKeyEvent(ke); }
Example 17
Source File: DefaultKeyboardFocusManager.java From jdk1.8-source-analysis with Apache License 2.0 | 4 votes |
private boolean preDispatchKeyEvent(KeyEvent ke) { if (((AWTEvent) ke).isPosted) { Component focusOwner = getFocusOwner(); ke.setSource(((focusOwner != null) ? focusOwner : getFocusedWindow())); } if (ke.getSource() == null) { return true; } // Explicitly set the key event timestamp here (not in Component.dispatchEventImpl): // - A key event is anyway passed to this method which starts its actual dispatching. // - If a key event is put to the type ahead queue, its time stamp should not be registered // until its dispatching actually starts (by this method). EventQueue.setCurrentEventAndMostRecentTime(ke); /** * Fix for 4495473. * This fix allows to correctly dispatch events when native * event proxying mechanism is active. * If it is active we should redispatch key events after * we detected its correct target. */ if (KeyboardFocusManager.isProxyActive(ke)) { Component source = (Component)ke.getSource(); Container target = source.getNativeContainer(); if (target != null) { ComponentPeer peer = target.getPeer(); if (peer != null) { peer.handleEvent(ke); /** * Fix for 4478780 - consume event after it was dispatched by peer. */ ke.consume(); } } return true; } java.util.List<KeyEventDispatcher> dispatchers = getKeyEventDispatchers(); if (dispatchers != null) { for (java.util.Iterator<KeyEventDispatcher> iter = dispatchers.iterator(); iter.hasNext(); ) { if (iter.next(). dispatchKeyEvent(ke)) { return true; } } } return dispatchKeyEvent(ke); }
Example 18
Source File: NameAutocompleter.java From plugins with GNU General Public License v3.0 | 4 votes |
@Override public void keyTyped(KeyEvent e) { if (!hiscoreConfig.autocomplete()) { return; } final JTextComponent input = (JTextComponent) e.getSource(); final String inputText = input.getText(); // Only autocomplete if the selection end is at the end of the text. if (input.getSelectionEnd() != inputText.length()) { return; } // Character to be inserted at the selection start. final String charToInsert = Character.toString(e.getKeyChar()); // Don't attempt to autocomplete if the name is invalid. // This condition is also true when the user presses a key like backspace. if (INVALID_CHARS.matcher(charToInsert).find() || INVALID_CHARS.matcher(inputText).find()) { return; } // Check if we are already autocompleting. if (autocompleteName != null && autocompleteNamePattern.matcher(inputText).matches()) { if (isExpectedNext(input, charToInsert)) { try { // Insert the character and move the selection. final int insertIndex = input.getSelectionStart(); Document doc = input.getDocument(); doc.remove(insertIndex, 1); doc.insertString(insertIndex, charToInsert, null); input.select(insertIndex + 1, input.getSelectionEnd()); } catch (BadLocationException ex) { log.warn("Could not insert character.", ex); } // Prevent default behavior. e.consume(); } else // Character to insert does not match current autocompletion. Look for another name. { newAutocomplete(e); } } else // Search for a name to autocomplete { newAutocomplete(e); } }
Example 19
Source File: MenuBar.java From netbeans with Apache License 2.0 | 4 votes |
protected @Override boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) { if (Utilities.isMac()) { int mods = e.getModifiers(); boolean isCtrl = (mods & KeyEvent.CTRL_MASK) != 0; boolean isAlt = (mods & KeyEvent.ALT_MASK) != 0; if (isAlt && (e instanceof MarkedKeyEvent)) { mods = mods & ~ KeyEvent.CTRL_MASK; mods = mods & ~ KeyEvent.CTRL_DOWN_MASK; mods |= KeyEvent.ALT_MASK; mods |= KeyEvent.ALT_DOWN_MASK; KeyEvent newEvent = new MarkedKeyEvent ( (Component) e.getSource(), e.getID(), e.getWhen(), mods, e.getKeyCode(), e.getKeyChar(), e.getKeyLocation()); KeyStroke newStroke = null; if( null != ks ) { newStroke = e.getID() == KeyEvent.KEY_TYPED ? KeyStroke.getKeyStroke (ks.getKeyChar(), mods) : KeyStroke.getKeyStroke (ks.getKeyCode(), mods, !ks.isOnKeyRelease()); } boolean result = super.processKeyBinding (newStroke, newEvent, condition, pressed); if (newEvent.isConsumed()) { e.consume(); } return result; } else if (!isAlt) { return super.processKeyBinding (ks, e, condition, pressed); } else { return false; } } else { return super.processKeyBinding (ks, e, condition, pressed); } }
Example 20
Source File: DefaultKeyboardFocusManager.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
private boolean preDispatchKeyEvent(KeyEvent ke) { getOnTypeaheadFinishedHandler().accept(ke); if (((AWTEvent) ke).isPosted) { Component focusOwner = getFocusOwner(); ke.setSource(((focusOwner != null) ? focusOwner : getFocusedWindow())); } if (ke.getSource() == null) { return true; } // Explicitly set the key event timestamp here (not in Component.dispatchEventImpl): // - A key event is anyway passed to this method which starts its actual dispatching. // - If a key event is put to the type ahead queue, its time stamp should not be registered // until its dispatching actually starts (by this method). EventQueue.setCurrentEventAndMostRecentTime(ke); /** * Fix for 4495473. * This fix allows to correctly dispatch events when native * event proxying mechanism is active. * If it is active we should redispatch key events after * we detected its correct target. */ if (KeyboardFocusManager.isProxyActive(ke)) { Component source = (Component)ke.getSource(); Container target = source.getNativeContainer(); if (target != null) { ComponentPeer peer = target.getPeer(); if (peer != null) { peer.handleEvent(ke); /** * Fix for 4478780 - consume event after it was dispatched by peer. */ ke.consume(); } } return true; } java.util.List<KeyEventDispatcher> dispatchers = getKeyEventDispatchers(); if (dispatchers != null) { for (java.util.Iterator<KeyEventDispatcher> iter = dispatchers.iterator(); iter.hasNext(); ) { if (iter.next(). dispatchKeyEvent(ke)) { return true; } } } return dispatchKeyEvent(ke); }