Java Code Examples for java.awt.event.KeyEvent#CHAR_UNDEFINED

The following examples show how to use java.awt.event.KeyEvent#CHAR_UNDEFINED . 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: KeyGestureState.java    From consulo with Apache License 2.0 6 votes vote down vote up
boolean process() {
  if (isPureModifierEvent(KeyEvent.KEY_PRESSED)) {
    myContext.actionKey = myContext.keyToProcess;
    return true;
  }

  if (myContext.keyToProcess.getID() == KeyEvent.KEY_RELEASED && myContext.keyToProcess.getKeyChar() == KeyEvent.CHAR_UNDEFINED) {
    final int pressedModifiers = myContext.keyToProcess.getKeyCode() & myContext.actionKey.getModifiersEx();
    if (pressedModifiers == 0) {
      myProcessor.setState(myProcessor.myFinish);
      return myProcessor.myState.process();
    }
  }

  if (myContext.keyToProcess.getID() == KeyEvent.KEY_PRESSED) {
    myContext.actionKey = myContext.keyToProcess;
    myProcessor.setState(myProcessor.myWaitForActionEnd);
    return true;
  }

  return false;
}
 
Example 2
Source File: Test.java    From native-obfuscator with GNU General Public License v3.0 6 votes vote down vote up
public int test(String [] args) {
    boolean ret = false;
    
    myAWTKeyStroke s = new myAWTKeyStroke(); 
    
    System.out.println(
        "s.getKeyChar() = " + (int) s.getKeyChar() + " (65535 expected).");      
    System.out.println("s.getKeyChar() == KeyEvent.CHAR_UNDEFINED: " 
        + (s.getKeyChar() == KeyEvent.CHAR_UNDEFINED));
    System.out.println("s.getKeyCode() == KeyEvent.VK_UNDEFINED: "
        + (s.getKeyCode() == KeyEvent.VK_UNDEFINED));
    System.out.println(
        "s.getModifiers() = " + s.getModifiers() + " (0 expected)");
    System.out.println(
        "s.isOnKeyRelease() = " + s.isOnKeyRelease() + " (false expected)");
    
    return ((int) s.getKeyChar() == 65535) 
            && (s.getKeyChar() == KeyEvent.CHAR_UNDEFINED)
            && (s.getKeyCode() == KeyEvent.VK_UNDEFINED)
            && (s.getModifiers() == 0) 
            && (!s.isOnKeyRelease())
        ? (0) : (1);

}
 
Example 3
Source File: ActionButtonUI.java    From consulo with Apache License 2.0 6 votes vote down vote up
private int getMnemonicCharIndex(ActionButton button, AnAction action, String text) {
  final int mnemonicIndex = button.getPresentation().getDisplayedMnemonicIndex();
  if (mnemonicIndex != -1) {
    return mnemonicIndex;
  }
  final ShortcutSet shortcutSet = action.getShortcutSet();
  final Shortcut[] shortcuts = shortcutSet.getShortcuts();
  for (int i = 0; i < shortcuts.length; i++) {
    Shortcut shortcut = shortcuts[i];
    if (shortcut instanceof KeyboardShortcut) {
      KeyboardShortcut keyboardShortcut = (KeyboardShortcut)shortcut;
      if (keyboardShortcut.getSecondKeyStroke() == null) { // we are interested only in "mnemonic-like" shortcuts
        final KeyStroke keyStroke = keyboardShortcut.getFirstKeyStroke();
        final int modifiers = keyStroke.getModifiers();
        if ((modifiers & KeyEvent.ALT_MASK) != 0) {
          return (keyStroke.getKeyChar() != KeyEvent.CHAR_UNDEFINED)
                 ? text.indexOf(keyStroke.getKeyChar())
                 : text.indexOf(KeyEvent.getKeyText(keyStroke.getKeyCode()));
        }
      }
    }
  }
  return -1;
}
 
Example 4
Source File: MetaData.java    From jdk-1.7-annotated with Apache License 2.0 5 votes vote down vote up
protected Expression instantiate(Object oldInstance, Encoder out) {
    AWTKeyStroke key = (AWTKeyStroke) oldInstance;

    char ch = key.getKeyChar();
    int code = key.getKeyCode();
    int mask = key.getModifiers();
    boolean onKeyRelease = key.isOnKeyRelease();

    Object[] args = null;
    if (ch == KeyEvent.CHAR_UNDEFINED) {
        args = !onKeyRelease
                ? new Object[]{code, mask}
                : new Object[]{code, mask, onKeyRelease};
    } else if (code == KeyEvent.VK_UNDEFINED) {
        if (!onKeyRelease) {
            args = (mask == 0)
                    ? new Object[]{ch}
                    : new Object[]{ch, mask};
        } else if (mask == 0) {
            args = new Object[]{ch, onKeyRelease};
        }
    }
    if (args == null) {
        throw new IllegalStateException("Unsupported KeyStroke: " + key);
    }
    Class type = key.getClass();
    String name = type.getName();
    // get short name of the class
    int index = name.lastIndexOf('.') + 1;
    if (index > 0) {
        name = name.substring(index);
    }
    return new Expression( key, type, "get" + name, args );
}
 
Example 5
Source File: KeyListenerNavigator.java    From pumpernickel with MIT License 5 votes vote down vote up
protected void keyEvent(KeyEvent e) {
	Number delay = (Number) UIManager.get("textSelectionDelay");
	if (delay == null)
		delay = Integer.valueOf(500);
	if (e.getWhen() - lastKeyEvent > delay.intValue()) {
		typedText.delete(0, typedText.length());
	}

	String origTypedText = typedText.toString();

	if (e.getKeyCode() == KeyEvent.VK_BACK_SPACE
			|| e.getKeyCode() == KeyEvent.VK_DELETE) {
		if (typedText.length() != 0) {
			typedText.substring(0, typedText.length() - 1);
		}
	} else {
		char ch = e.getKeyChar();
		if (ch != KeyEvent.CHAR_UNDEFINED) {
			typedText.append(ch);
		}
	}

	if (!origTypedText.equals(typedText.toString())) {
		lastKeyEvent = e.getWhen();
		boolean success = changeSelectionUsingText(e, typedText.toString());
		if (success)
			e.consume();
	}
}
 
Example 6
Source File: CsvTableEditorKeyListenerTest.java    From intellij-csv-validator with Apache License 2.0 5 votes vote down vote up
public void testDeleteRowActionByDelete() {
    KeyEvent keyEvent = new KeyEvent(fileEditor.getTable(), KeyEvent.KEY_RELEASED, JComponent.WHEN_FOCUSED,
            KeyEvent.CTRL_DOWN_MASK, KeyEvent.VK_DELETE, KeyEvent.CHAR_UNDEFINED);

    fileEditor.tableEditorKeyListener.keyReleased(keyEvent);
    assertTrue(fileEditor.getDataHandler().equalsCurrentState(initialState));

    fileEditor.getTable().setRowSelectionInterval(1, 1);
    fileEditor.getTable().setColumnSelectionInterval(1, 1);
    fileEditor.tableEditorKeyListener.keyReleased(keyEvent);
    Object[][] newState = fileEditor.getDataHandler().getCurrentState();
    assertEquals(3, newState.length);
    assertEquals("just another line with leading and trailing whitespaces", newState[1][0]);
    assertEquals("  and one more value  ", newState[1][1]);
}
 
Example 7
Source File: MetaData.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
protected Expression instantiate(Object oldInstance, Encoder out) {
    AWTKeyStroke key = (AWTKeyStroke) oldInstance;

    char ch = key.getKeyChar();
    int code = key.getKeyCode();
    int mask = key.getModifiers();
    boolean onKeyRelease = key.isOnKeyRelease();

    Object[] args = null;
    if (ch == KeyEvent.CHAR_UNDEFINED) {
        args = !onKeyRelease
                ? new Object[]{code, mask}
                : new Object[]{code, mask, onKeyRelease};
    } else if (code == KeyEvent.VK_UNDEFINED) {
        if (!onKeyRelease) {
            args = (mask == 0)
                    ? new Object[]{ch}
                    : new Object[]{ch, mask};
        } else if (mask == 0) {
            args = new Object[]{ch, onKeyRelease};
        }
    }
    if (args == null) {
        throw new IllegalStateException("Unsupported KeyStroke: " + key);
    }
    Class<?> type = key.getClass();
    String name = type.getName();
    // get short name of the class
    int index = name.lastIndexOf('.') + 1;
    if (index > 0) {
        name = name.substring(index);
    }
    return new Expression( key, type, "get" + name, args );
}
 
Example 8
Source File: CMenuItem.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void setLabel(String label, char keyChar, int keyCode, int modifiers) {
    int keyMask = modifiers;
    if (keyCode == KeyEvent.VK_UNDEFINED) {
        MenuShortcut shortcut = ((MenuItem)getTarget()).getShortcut();

        if (shortcut != null) {
            keyCode = shortcut.getKey();
            keyMask |= InputEvent.META_MASK;

            if (shortcut.usesShiftModifier()) {
                keyMask |= InputEvent.SHIFT_MASK;
            }
        }
    }

    if (label == null) {
        label = "";
    }

    // <rdar://problem/3654824>
    // Native code uses a keyChar of 0 to indicate that the
    // keyCode should be used to generate the shortcut.  Translate
    // CHAR_UNDEFINED into 0.
    if (keyChar == KeyEvent.CHAR_UNDEFINED) {
        keyChar = 0;
    }

    final String finalLabel = label;
    final char finalKeyChar = keyChar;
    final int finalKeyCode = keyCode;
    final int finalKeyMask = keyMask;
    execute(ptr -> nativeSetLabel(ptr, finalLabel, finalKeyChar,
                                  finalKeyCode, finalKeyMask));
}
 
Example 9
Source File: GPTreeTableBase.java    From ganttproject with GNU General Public License v3.0 5 votes vote down vote up
private boolean isStartEditingEvent(KeyEvent e, boolean includeCharTyping) {
  boolean result = e.getKeyCode() == KeyEvent.VK_F2
      || e.getKeyCode() == KeyEvent.VK_INSERT
      || (myNewRowAction != null && KeyStroke.getKeyStrokeForEvent(e).equals(myNewRowAction.getKeyStroke()));
  if (!result && includeCharTyping) {
    result = e.getKeyChar() != KeyEvent.CHAR_UNDEFINED && !e.isMetaDown() && !e.isControlDown();
  }
  return result;
}
 
Example 10
Source File: MetaData.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
protected Expression instantiate(Object oldInstance, Encoder out) {
    AWTKeyStroke key = (AWTKeyStroke) oldInstance;

    char ch = key.getKeyChar();
    int code = key.getKeyCode();
    int mask = key.getModifiers();
    boolean onKeyRelease = key.isOnKeyRelease();

    Object[] args = null;
    if (ch == KeyEvent.CHAR_UNDEFINED) {
        args = !onKeyRelease
                ? new Object[]{code, mask}
                : new Object[]{code, mask, onKeyRelease};
    } else if (code == KeyEvent.VK_UNDEFINED) {
        if (!onKeyRelease) {
            args = (mask == 0)
                    ? new Object[]{ch}
                    : new Object[]{ch, mask};
        } else if (mask == 0) {
            args = new Object[]{ch, onKeyRelease};
        }
    }
    if (args == null) {
        throw new IllegalStateException("Unsupported KeyStroke: " + key);
    }
    Class<?> type = key.getClass();
    String name = type.getName();
    // get short name of the class
    int index = name.lastIndexOf('.') + 1;
    if (index > 0) {
        name = name.substring(index);
    }
    return new Expression( key, type, "get" + name, args );
}
 
Example 11
Source File: CsvTableEditorKeyListenerTest.java    From intellij-csv-validator with Apache License 2.0 5 votes vote down vote up
public void testDeleteRowActionByBackSpace() {
    KeyEvent keyEvent = new KeyEvent(fileEditor.getTable(), KeyEvent.KEY_RELEASED, JComponent.WHEN_FOCUSED,
            KeyEvent.CTRL_DOWN_MASK, KeyEvent.VK_BACK_SPACE, KeyEvent.CHAR_UNDEFINED);

    fileEditor.tableEditorKeyListener.keyReleased(keyEvent);
    assertTrue(fileEditor.getDataHandler().equalsCurrentState(initialState));

    fileEditor.getTable().setRowSelectionInterval(1, 1);
    fileEditor.getTable().setColumnSelectionInterval(1, 1);
    fileEditor.tableEditorKeyListener.keyReleased(keyEvent);
    Object[][] newState = fileEditor.getDataHandler().getCurrentState();
    assertEquals(3, newState.length);
    assertEquals("just another line with leading and trailing whitespaces", newState[1][0]);
    assertEquals("  and one more value  ", newState[1][1]);
}
 
Example 12
Source File: CsvTableEditorKeyListenerTest.java    From intellij-csv-validator with Apache License 2.0 5 votes vote down vote up
public void testNotClearCellActionByDeleteWhenEditing() {
    KeyEvent enterKeyEvent = new KeyEvent(fileEditor.getTable(), KeyEvent.KEY_RELEASED, JComponent.WHEN_FOCUSED,
            0, KeyEvent.VK_ENTER, KeyEvent.CHAR_UNDEFINED);
    KeyEvent deleteKeyEvent = new KeyEvent(fileEditor.getTable(), KeyEvent.KEY_RELEASED, JComponent.WHEN_FOCUSED,
            0, KeyEvent.VK_DELETE, KeyEvent.CHAR_UNDEFINED);

    fileEditor.getTable().setRowSelectionInterval(1, 1);
    fileEditor.getTable().setColumnSelectionInterval(1, 1);

    fileEditor.tableEditorKeyListener.keyReleased(enterKeyEvent);
    fileEditor.tableEditorKeyListener.keyReleased(deleteKeyEvent);

    Object[][] newState = fileEditor.getDataHandler().getCurrentState();
    assertEquals("this is column header 2", newState[1][1]);
}
 
Example 13
Source File: NbKeymap.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public Action getAction(final KeyStroke key) {
    switch (key.getKeyCode()) {
    case KeyEvent.VK_SHIFT:
    case KeyEvent.VK_CONTROL:
    case KeyEvent.VK_ALT:
    case KeyEvent.VK_ALT_GRAPH:
    case KeyEvent.VK_META:
    case KeyEvent.VK_UNDEFINED:
    case KeyEvent.CHAR_UNDEFINED:
            // Not actually a bindable key press.
            return null;
    }
    if (key.isOnKeyRelease()) {
        // Again, not really our business here.
        return null;
    }
    LOG.log(Level.FINE, "getAction {0}", key);
    Map<KeyStroke,Binding> binder = bindings();
    for (KeyStroke ctx : context) {
        Binding sub = binder.get(ctx);
        if (sub == null) {
            resetContext();
            return BROKEN; // no entry found after known prefix
        }
        binder = sub.nested;
        if (binder == null) {
            resetContext();
            return BROKEN; // anomalous, expected to find submap here
        }
    }
    Binding b = binder.get(key);
    if (b == null) {
        resetContext();
        return null; // normal, not found
    }
    if (b.nested == null) {
        resetContext();
        return b.loadAction(); // found real action
    } else {
        return new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
                shiftContext(key); // entering submap
            }
        };
    }
}
 
Example 14
Source File: KeyCodesTest.java    From openmeetings with Apache License 2.0 4 votes vote down vote up
@Override
public void keyPressed(KeyEvent event) {
	msg1 = "";
	System.out.println("keyPressed CODE1 "+event.getKeyCode());

	int myCode = event.getKeyCode();

	System.out.println("keyPressed CODE2 "+myCode);

	System.out.println("keyPressed CHAR3 "+event.getKeyChar());

	System.out.println("keyPressed CHAR4 "+KeyEvent.getKeyText(event.getKeyCode()));

	System.out.println("keyPressed CHAR5 "+KeyEvent.getKeyText(myCode));

	System.out.println("keyPressed isActionKey "+event.isActionKey());
	System.out.println("keyPressed isAltDown "+event.isAltDown());
	System.out.println("keyPressed isAltGraphDown "+event.isAltGraphDown());
	System.out.println("keyPressed isConsumed "+event.isConsumed());
	System.out.println("keyPressed isControlDown "+event.isControlDown());
	System.out.println("keyPressed isMetaDown "+event.isMetaDown());
	System.out.println("keyPressed isShiftDown "+event.isShiftDown());

	System.out.println("keyPressed paramString "+event.paramString());

	if (event.getKeyChar() == KeyEvent.CHAR_UNDEFINED) {
		int key = event.getKeyCode();
		// Funktionstaste abfragen
		if (key == KeyEvent.VK_F1) {
			msg1 = "F1";
		} else if (key == KeyEvent.VK_F2) {
			msg1 = "F2";
		} else if (key == KeyEvent.VK_F3) {
			msg1 = "F3";
		}
		// Modifier abfragen
		if (msg1.length() > 0) {
			if (event.isAltDown()) {
				msg1 = "ALT + " + msg1;
			}
			if (event.isControlDown()) {
				msg1 = "STRG + " + msg1;
			}
			if (event.isShiftDown()) {
				msg1 = "UMSCHALT + " + msg1;
			}
		}
	}
	repaint();
}
 
Example 15
Source File: TAWTKeyStroke.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
public static AWTKeyStroke getAWTKeyStroke(final int keyCode, final int modifiers) {
    return (AWTKeyStroke) (Object) new TAWTKeyStroke(KeyEvent.CHAR_UNDEFINED, keyCode, modifiers, false);
}
 
Example 16
Source File: TAWTKeyStroke.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
public static AWTKeyStroke getAWTKeyStroke(final int keyCode, final int modifiers,
                                           final boolean onKeyRelease) {
    return (AWTKeyStroke) (Object) new TAWTKeyStroke(KeyEvent.CHAR_UNDEFINED, keyCode, modifiers, onKeyRelease);
}
 
Example 17
Source File: DefaultInputHandler.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Handle a key typed event. This inserts the key into the text area.
 */
@Override
@SuppressWarnings("unchecked")
public void keyTyped(KeyEvent evt) {
	int modifiers = evt.getModifiers();
	char c = evt.getKeyChar();
	if (c != KeyEvent.CHAR_UNDEFINED && (modifiers & InputEvent.ALT_MASK) == 0) {
		if (c >= 0x20 && c != 0x7f) {
			KeyStroke keyStroke = KeyStroke.getKeyStroke(Character.toUpperCase(c));
			Object o = currentBindings.get(keyStroke);

			if (o instanceof Hashtable) {
				currentBindings = (Hashtable<KeyStroke, Object>) o;
				return;
			} else if (o instanceof ActionListener) {
				currentBindings = bindings;
				executeAction((ActionListener) o, evt.getSource(), String.valueOf(c));
				return;
			}

			currentBindings = bindings;

			if (grabAction != null) {
				handleGrabAction(evt);
				return;
			}

			// 0-9 adds another 'digit' to the repeat number
			if (repeat && Character.isDigit(c)) {
				repeatCount *= 10;
				repeatCount += (c - '0');
				return;
			}

			executeAction(INSERT_CHAR, evt.getSource(), String.valueOf(evt.getKeyChar()));

			repeatCount = 0;
			repeat = false;
		}
	}
}
 
Example 18
Source File: JBTable.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean editCellAt(final int row, final int column, final EventObject e) {
  if (cellEditor != null && !cellEditor.stopCellEditing()) {
    return false;
  }

  if (row < 0 || row >= getRowCount() || column < 0 || column >= getColumnCount()) {
    return false;
  }

  if (!isCellEditable(row, column)) {
    return false;
  }

  if (e instanceof KeyEvent) {
    // do not start editing in autoStartsEdit mode on Ctrl-Z and other non-typed events
    if (!UIUtil.isReallyTypedEvent((KeyEvent)e) || ((KeyEvent)e).getKeyChar() == KeyEvent.CHAR_UNDEFINED) return false;

    SpeedSearchSupply supply = SpeedSearchSupply.getSupply(this);
    if (supply != null && supply.isPopupActive()) {
      return false;
    }
  }

  final TableCellEditor editor = getCellEditor(row, column);
  if (editor != null && editor.isCellEditable(e)) {
    editorComp = prepareEditor(editor, row, column);
    //((JComponent)editorComp).setBorder(null);
    if (editorComp == null) {
      removeEditor();
      return false;
    }
    editorComp.setBounds(getCellRect(row, column, false));
    add(editorComp);
    editorComp.validate();

    if (surrendersFocusOnKeyStroke()) {
      // this replaces focus request in JTable.processKeyBinding
      final IdeFocusManager focusManager = IdeFocusManager.findInstanceByComponent(this);
      focusManager.setTypeaheadEnabled(false);
      focusManager.requestFocus(editorComp, true).doWhenProcessed(() -> focusManager.setTypeaheadEnabled(true));
    }

    setCellEditor(editor);
    setEditingRow(row);
    setEditingColumn(column);
    editor.addCellEditorListener(this);

    return true;
  }
  return false;
}
 
Example 19
Source File: CDefaultLabelEventHandler.java    From binnavi with Apache License 2.0 4 votes vote down vote up
@Override
public void keyPressed(final KeyEvent event) {
  if (!isActive()) {
    return;
  }

  if (event.getKeyCode() == KeyEvent.VK_ESCAPE) {
    deactivateLabelContent();

    return;
  }

  if ((event.getKeyCode() == KeyEvent.VK_TAB) && (event.getModifiers() != 0)
      && (event.getModifiers() != InputEvent.SHIFT_DOWN_MASK)) {
    return;
  }

  if (!getActiveLabelContent().isSelectable()) {
    return;
  }

  CAbstractKeyBehavior behaviour = null;

  final char keyText = KeyEvent.getKeyText(event.getKeyCode()).charAt(0);

  if (event.isControlDown() && (keyText >= 'A') && (keyText <= 'Z')) {
    behaviour = m_ctrlKeyBehaviourMap.get(event.getKeyCode());
  }

  if (behaviour == null) {
    behaviour = m_keyBehaviourMap.get(event.getKeyCode());

    if ((behaviour == null) && (event.getKeyChar() != KeyEvent.CHAR_UNDEFINED)
        && !event.isControlDown() && getActiveLabelContent().isEditable()) {
      behaviour = m_keyBehaviourMap.get(null);
    }
  }

  if (behaviour != null) {
    int y = -1;
    String oldContent = "";

    if (getActiveLabelContent().isEditable()) {
      y = getActiveLabelContent().getCaret().getYmouseReleased();
      oldContent = getContentSnippet(y);
    }

    behaviour.keyPressed(getActiveLabelContent(), event);

    if (y > -1) {
      final String newContent = getContentSnippet(y);

      if (!oldContent.equals(newContent) && !oldContent.isEmpty()) {
        for (final ILabelEditableContentListener listener : m_editModeListener) {
          listener.editableContentChanged(getActiveLabelContent());
        }
      }
    }

    m_activeRealizer.regenerate();

    m_activeRealizer.repaint();

    m_graph.updateViews();
  }

  event.consume();
}
 
Example 20
Source File: KeyStrokeAdapter.java    From consulo with Apache License 2.0 2 votes vote down vote up
/**
 * @param ch        the specified key character
 * @param modifiers the modifier mask from the event
 * @return a key stroke or {@code null} if {@code ch} is undefined
 */
private static KeyStroke getKeyStroke(char ch, int modifiers) {
  return KeyEvent.CHAR_UNDEFINED == ch ? null : KeyStroke.getKeyStroke(Character.valueOf(ch), modifiers);
}