/** * Insert a String of source code to be highlighted to the document. The string is then inserted * character by character if longer than 1 char. * * @param offs the position in the document * @param str the String containig source code * @param attr the attributes to set */ @Override public void insertString(final int offs, final String str, final AttributeSet attr) { if (offs < 0) { return; } if (str.length() > 1) { int i; for (i = 0; i < str.length(); i++) { if (str.charAt(i) == '\n') { remainingTextString = str.substring(i + 1); remainingTextAttr = attr; inputKeyListener.keyPressed( new KeyEvent(new Container(), KeyEvent.KEY_PRESSED, 0, 0, KeyEvent.VK_ENTER, '\n')); break; } else { insertChar(offs + i, "" + str.charAt(i)); } } } else if (str.length() == 1) { insertChar(offs, str); } }
public void keyPressed(KeyEvent e) { int code = e.getKeyCode(); if (code > 0 && code < keys.length) { keys[code] = true; } if (externalListener != null) { externalListener.keyPressed(e); } }
public void handleKeyEvent(KeyEvent e) { final int id = e.getID(); if (id == KeyEvent.KEY_PRESSED) { myKeyListener.keyPressed(e); } else if (id == KeyEvent.KEY_RELEASED) { /* keyReleased(e); */ } else if (id == KeyEvent.KEY_TYPED) { myKeyListener.keyTyped(e); } }
private void fireKeyEvent(KeyEvent e) { for (KeyListener l : mKeyListeners) { if (e.getID() == KeyEvent.KEY_PRESSED) { l.keyPressed(e); } else if (e.getID() == KeyEvent.KEY_RELEASED) { l.keyReleased(e); } else if (e.getID() == KeyEvent.KEY_TYPED) { l.keyTyped(e); } } }
void notifyKeyEvent(final KeyEvent e) { for (KeyListener l : myKeyListeners) { if (e.getID() == KeyEvent.KEY_PRESSED) { l.keyPressed(e); } else if (e.getID() == KeyEvent.KEY_RELEASED) { l.keyReleased(e); } else if (e.getID() == KeyEvent.KEY_TYPED) { l.keyTyped(e); } } }
private static void dispatchEvent(int eventCode, Key key, int keyCode, Component component) { int modifier = key.getModifier().getCode(); KeyEvent event = new KeyEvent(component, eventCode, 0, modifier, keyCode, key.getChar()); for (KeyListener listener : component.getKeyListeners()) { switch (eventCode) { case KEY_PRESSED: listener.keyPressed(event); break; case KEY_TYPED: listener.keyTyped(event); break; case KEY_RELEASED: listener.keyReleased(event); break; } } SwingUtilities.processKeyBindings(event); }
private void simulateEnterKeyEvent(JTree tree, int keyCode) { keyListener.keyPressed(new KeyEvent(tree, 0, 0, 0, keyCode, KeyEvent.CHAR_UNDEFINED)); }
/** * Handles the keyPressed event by invoking the keyPressed methods on listener-a and listener-b. * * @param e the key event */ public void keyPressed(KeyEvent e) { ((KeyListener) a).keyPressed(e); ((KeyListener) b).keyPressed(e); }