Java Code Examples for javax.swing.KeyStroke#getKeyEventType()

The following examples show how to use javax.swing.KeyStroke#getKeyEventType() . 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: Utils.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
public static boolean isKeyStrokeEvent(@Nullable final KeyStroke keyStroke, final int keyEventType, @Nullable final KeyEvent event) {
  boolean result = false;
  if (keyStroke != null && event != null) {
    if (keyEventType == keyStroke.getKeyEventType()) {
      result = ((keyStroke.getModifiers() & event.getModifiers()) == keyStroke.getModifiers()) && (keyStroke.getKeyCode() == event.getKeyCode());
    }
  }
  return result;
}
 
Example 2
Source File: StringUtils.java    From xyTalk-pc with GNU Affero General Public License v3.0 4 votes vote down vote up
public static String keyStroke2String(KeyStroke key) {
StringBuilder s = new StringBuilder(50);
int m = key.getModifiers();

if ((m & (InputEvent.SHIFT_DOWN_MASK | InputEvent.SHIFT_MASK)) != 0) {
    s.append("shift ");
}
if ((m & (InputEvent.CTRL_DOWN_MASK | InputEvent.CTRL_MASK)) != 0) {
    s.append("ctrl ");
}
if ((m & (InputEvent.META_DOWN_MASK | InputEvent.META_MASK)) != 0) {
    s.append("meta ");
}
if ((m & (InputEvent.ALT_DOWN_MASK | InputEvent.ALT_MASK)) != 0) {
    s.append("alt ");
}
if ((m & (InputEvent.BUTTON1_DOWN_MASK | InputEvent.BUTTON1_MASK)) != 0) {
    s.append("button1 ");
}
if ((m & (InputEvent.BUTTON2_DOWN_MASK | InputEvent.BUTTON2_MASK)) != 0) {
    s.append("button2 ");
}
if ((m & (InputEvent.BUTTON3_DOWN_MASK | InputEvent.BUTTON3_MASK)) != 0) {
    s.append("button3 ");
}

switch (key.getKeyEventType()) {
case KeyEvent.KEY_TYPED:
    s.append("typed ");
    s.append(key.getKeyChar()).append(" ");
    break;
case KeyEvent.KEY_PRESSED:
    s.append("pressed ");
    s.append(getKeyText(key.getKeyCode())).append(" ");
    break;
case KeyEvent.KEY_RELEASED:
    s.append("released ");
    s.append(getKeyText(key.getKeyCode())).append(" ");
    break;
default:
    s.append("unknown-event-type ");
    break;
}

return s.toString();
   }
 
Example 3
Source File: StringUtils.java    From Spark with Apache License 2.0 4 votes vote down vote up
public static String keyStroke2String(KeyStroke key) {
StringBuilder s = new StringBuilder(50);
int m = key.getModifiers();

if ((m & (InputEvent.SHIFT_DOWN_MASK | InputEvent.SHIFT_MASK)) != 0) {
    s.append("shift ");
}
if ((m & (InputEvent.CTRL_DOWN_MASK | InputEvent.CTRL_MASK)) != 0) {
    s.append("ctrl ");
}
if ((m & (InputEvent.META_DOWN_MASK | InputEvent.META_MASK)) != 0) {
    s.append("meta ");
}
if ((m & (InputEvent.ALT_DOWN_MASK | InputEvent.ALT_MASK)) != 0) {
    s.append("alt ");
}
if ((m & (InputEvent.BUTTON1_DOWN_MASK | InputEvent.BUTTON1_MASK)) != 0) {
    s.append("button1 ");
}
if ((m & (InputEvent.BUTTON2_DOWN_MASK | InputEvent.BUTTON2_MASK)) != 0) {
    s.append("button2 ");
}
if ((m & (InputEvent.BUTTON3_DOWN_MASK | InputEvent.BUTTON3_MASK)) != 0) {
    s.append("button3 ");
}

switch (key.getKeyEventType()) {
case KeyEvent.KEY_TYPED:
    s.append("typed ");
    s.append(key.getKeyChar()).append(" ");
    break;
case KeyEvent.KEY_PRESSED:
    s.append("pressed ");
    s.append(getKeyText(key.getKeyCode())).append(" ");
    break;
case KeyEvent.KEY_RELEASED:
    s.append("released ");
    s.append(getKeyText(key.getKeyCode())).append(" ");
    break;
default:
    s.append("unknown-event-type ");
    break;
}

return s.toString();
   }