Java Code Examples for java.awt.event.KeyListener#keyPressed()

The following examples show how to use java.awt.event.KeyListener#keyPressed() . 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: KeyBindingOverrideKeyEventDispatcher.java    From ghidra with Apache License 2.0 8 votes vote down vote up
private boolean processComponentKeyListeners(KeyEvent keyEvent) {

		Component focusOwner = focusProvider.getFocusOwner();
		if (focusOwner == null) {
			return false;
		}

		KeyListener[] keyListeners = focusOwner.getKeyListeners();
		for (KeyListener listener : keyListeners) {
			int id = keyEvent.getID();
			switch (id) {
				case KeyEvent.KEY_TYPED:
					listener.keyTyped(keyEvent);
					break;
				case KeyEvent.KEY_PRESSED:
					listener.keyPressed(keyEvent);
					break;
				case KeyEvent.KEY_RELEASED:
					listener.keyReleased(keyEvent);
					break;
			}
		}

		return keyEvent.isConsumed();
	}
 
Example 2
Source File: HexOrDecimalInputTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void toggleMode(final HexOrDecimalInput input) {
	KeyEvent event = new KeyEvent(input, 0, System.currentTimeMillis(), 0, KeyEvent.VK_M, 'm');
	KeyListener[] keyListeners = input.getKeyListeners();
	for (KeyListener listener : keyListeners) {
		listener.keyPressed(event);
	}
}
 
Example 3
Source File: WatchesColumnModels.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void processKeyEvent(KeyEvent e) {
    KeyStroke ks = KeyStroke.getKeyStrokeForEvent(e);
    if (enter.equals(ks)) {
        // Prevent JComponent.processKeyBindings() to be called (it is called from
        // JComponent.processKeyEvent() ), notify only registered key listeners
        int id = e.getID();
        for (KeyListener keyListener : getKeyListeners()) {
            switch(id) {
              case KeyEvent.KEY_TYPED:
                  keyListener.keyTyped(e);
                  break;
              case KeyEvent.KEY_PRESSED:
                  keyListener.keyPressed(e);
                  break;
              case KeyEvent.KEY_RELEASED:
                  keyListener.keyReleased(e);
                  break;
            }
        }
        if (!e.isConsumed() && id == KeyEvent.KEY_PRESSED) {
            synchronized(listeners) {
                List<CellEditorListener> list = new ArrayList<CellEditorListener>(listeners);
                for (CellEditorListener listener : list) {
                    listener.editingStopped(new ChangeEvent(this));
                }
            }
        }
        e.consume();
    } else {
        super.processKeyEvent(e);
    }
}
 
Example 4
Source File: ColumnModels.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void processKeyEvent(KeyEvent e) {
    KeyStroke ks = KeyStroke.getKeyStrokeForEvent(e);
    if (enter.equals(ks)) {
        // Prevent JComponent.processKeyBindings() to be called (it is called from
        // JComponent.processKeyEvent() ), notify only registered key listeners
        int id = e.getID();
        for (KeyListener keyListener : getKeyListeners()) {
            switch(id) {
              case KeyEvent.KEY_TYPED:
                  keyListener.keyTyped(e);
                  break;
              case KeyEvent.KEY_PRESSED:
                  keyListener.keyPressed(e);
                  break;
              case KeyEvent.KEY_RELEASED:
                  keyListener.keyReleased(e);
                  break;
            }
        }
        if (!e.isConsumed() && id == KeyEvent.KEY_PRESSED) {
            synchronized(listeners) {
                List<CellEditorListener> list = new ArrayList<CellEditorListener>(listeners);
                for (CellEditorListener listener : list) {
                    listener.editingStopped(new ChangeEvent(this));
                }
            }
        }
        e.consume();
    } else {
        super.processKeyEvent(e);
    }
}
 
Example 5
Source File: KeyboardExtension.java    From 07kit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Invoked when a key has been pressed.
 * See the class description for {@link KeyEvent} for a definition of
 * a key pressed event.
 */
public void keyPressed(KeyEvent e) {
    for (KeyListener child : children) {
        child.keyPressed(e);
        if (e.isConsumed()) {
            return;
        }
    }

    if (acceptingEvents) {
        _keyPressed(e);
    }
}
 
Example 6
Source File: FormulaEditorPanel.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Invoked when a key has been pressed. See the class description for {@link java.awt.event.KeyEvent} for a
 * definition of a key pressed event.
 */
public void keyPressed( final KeyEvent e ) {
  final KeyListener[] keyListeners = listenerList.getListeners( KeyListener.class );
  for ( int i = 0; i < keyListeners.length; i++ ) {
    final KeyListener keyListener = keyListeners[ i ];
    keyListener.keyPressed( e );
  }
}