void jTextFieldSendMessages_keyPressed(KeyEvent e) { if (e.getKeyCode() == e.VK_DOWN) { String s = msgHistory.forward(); if (s != null) { jTextFieldSendMessages.setText(s); } } else if (e.getKeyCode() == e.VK_UP) { String s = msgHistory.back(); if (s != null) { jTextFieldSendMessages.setText(s); } } else if (e.getKeyChar() == '\n') { String body = jTextFieldSendMessages.getText(); if (body.length() > 0) { if (body.charAt(body.length() - 1) == '\n') body = body.substring(0, body.length() - 1); String subject = jTextFieldSendSubject.getText(); if (subject.length() > 0) { if (subject.charAt(subject.length() - 1) == '\n') subject = subject.substring(0, subject.length() - 1); } if (session != null && session.isConnected()) { session.postMessage(jTextFieldTargetUser.getText(), subject, body); displaySendMessage(subject, jTextFieldTargetUser.getText(), body, outgoingMsgAttrSet); } msgHistory.add(body); subjectHistory.add(subject); subjectHistory.reset(); msgHistory.reset(); jTextFieldSendMessages.setText(""); jTextFieldSendSubject.setText(""); } } }
public void keyReleased(KeyEvent ke) { if (ke.getKeyCode() == KeyEvent.VK_UP) { String up = history.getUp(); if (up != null) messageText.setText(up); } else if (ke.getKeyCode() == KeyEvent.VK_DOWN) { String down = history.getDown(); if (down != null) messageText.setText(down); } }
void jTextFieldSendSubject_keyPressed(KeyEvent e) { if (e.getKeyCode() == e.VK_DOWN) { String s = subjectHistory.forward(); if (s != null) { jTextFieldSendSubject.setText(s); } } else if (e.getKeyCode() == e.VK_UP) { String s = subjectHistory.back(); if (s != null) { jTextFieldSendSubject.setText(s); } } else if (e.getKeyChar() == '\n') { jTextFieldSendMessages.requestFocus(); } }
/** * The keyReleased event ensures that the caret-position is updated for both peers, when the * user moves the caret with the arrow-keys. */ public void keyReleased(KeyEvent e) { int left = e.VK_LEFT; int right = e.VK_RIGHT; int up = e.VK_UP; int down = e.VK_DOWN; int home = e.VK_HOME; int end = e.VK_END; int A = e.VK_A; int kc = e.getKeyCode(); if (kc == left || kc == right || kc == up || kc == down || kc == home || kc == end || (kc == A && e.isControlDown())) { if (dec == null) return; lc.increment(); TextEvent cu = new CaretUpdate(area1.getCaretPosition(), lc.getTimeStamp()); dec.sendObjectToAllPeers(cu); er.getEventHistoryLock().lock(); er.getEventHistory().add(cu); er.getEventHistoryLock().unlock(); } }
public void keyPressed(KeyEvent e) { int code = e.getKeyCode(); if (code == KeyEvent.VK_ENTER) { document.enter(); e.consume(); } }
@Override public void keyPressed(KeyEvent e) { // Accept "copy" key strokes KeyStroke ks = KeyStroke.getKeyStroke(e.getKeyCode(), e.getModifiers()); JComponent comp = (JComponent) e.getSource(); for (int i = 0; i < 3; i++) { InputMap im = comp.getInputMap(i); Object key = im.get(ks); if (defaultEditorKitCopyActionName.equals(key) || transferHandlerCopyActionName.equals(key)) { return; } } // Accept JTable navigation key strokes if (!tableNavigationKeys.contains(e.getKeyCode())) { e.consume(); } }
public void keyPressed(KeyEvent e) { // Nothing to do if the contact list is empty if (contactList.getModel().getSize() <= 0) return; int keyCode = e.getKeyCode(); if (keyCode == KeyEvent.VK_LEFT) { closeGroup(); } else if (keyCode == KeyEvent.VK_RIGHT) { openGroup(); } else if (keyCode == KeyEvent.VK_ENTER) { openOrCloseGroup(); } }
void editorPane_keyPressed(KeyEvent e) { StyledDocument doc = editorPane.getStyledDocument(); int pos = editorPane.getCaretPosition(); int code = e.getKeyCode(); Element el; switch (code) { case KeyEvent.VK_BACK_SPACE: case KeyEvent.VK_DELETE: case KeyEvent.VK_LEFT: case KeyEvent.VK_KP_LEFT: if (pos == 0) return; // we want to get the element to the left of position. el = doc.getCharacterElement(pos - 1); break; case KeyEvent.VK_RIGHT: case KeyEvent.VK_KP_RIGHT: // we want to get the element to the right of position. el = doc.getCharacterElement(pos + 1); break; default: return; // bail we don't handle it. } AttributeSet attr = el.getAttributes(); String el_name = (String) attr.getAttribute(StyleConstants.NameAttribute); int el_range = el.getEndOffset() - el.getStartOffset() - 1; if (el_name.startsWith("Parameter") && StyleConstants.getComponent(attr) != null) { try { switch (code) { case KeyEvent.VK_BACK_SPACE: case KeyEvent.VK_DELETE: doc.remove(el.getStartOffset(), el_range); break; case KeyEvent.VK_LEFT: case KeyEvent.VK_KP_LEFT: editorPane.setCaretPosition(pos - el_range); break; case KeyEvent.VK_RIGHT: case KeyEvent.VK_KP_RIGHT: editorPane.setCaretPosition(pos + (el_range)); break; } } catch (BadLocationException ex) { } } }
private synchronized void type(KeyEvent e) { switch (e.getKeyCode()) { case (KeyEvent.VK_ENTER): if (e.getID() == KeyEvent.KEY_PRESSED) { processCommand(); initCommandPos(); text.setCaretPosition(commandPos); } e.consume(); text.repaint(); break; case (KeyEvent.VK_UP): if (e.getID() == KeyEvent.KEY_PRESSED) prevHistory(); e.consume(); break; case (KeyEvent.VK_DOWN): if (e.getID() == KeyEvent.KEY_PRESSED) nextHistory(); e.consume(); break; case (KeyEvent.VK_LEFT): case (KeyEvent.VK_BACK_SPACE): case (KeyEvent.VK_DELETE): if (text.getCaretPosition() <= commandPos) e.consume(); break; case (KeyEvent.VK_HOME): text.setCaretPosition(commandPos); e.consume(); break; case (KeyEvent.VK_U): if ((e.getModifiers() & InputEvent.CTRL_MASK) > 0) { replaceConsoleText("", commandPos, textLength()); commandHistoryIndex = 0; e.consume(); } break; case (KeyEvent.VK_ALT): case (KeyEvent.VK_CAPS_LOCK): case (KeyEvent.VK_CONTROL): case (KeyEvent.VK_META): case (KeyEvent.VK_SHIFT): case (KeyEvent.VK_PRINTSCREEN): case (KeyEvent.VK_SCROLL_LOCK): case (KeyEvent.VK_PAUSE): case (KeyEvent.VK_INSERT): case (KeyEvent.VK_F1): case (KeyEvent.VK_F2): case (KeyEvent.VK_F3): case (KeyEvent.VK_F4): case (KeyEvent.VK_F5): case (KeyEvent.VK_F6): case (KeyEvent.VK_F7): case (KeyEvent.VK_F8): case (KeyEvent.VK_F9): case (KeyEvent.VK_F10): case (KeyEvent.VK_F11): case (KeyEvent.VK_F12): case (KeyEvent.VK_ESCAPE): case (KeyEvent.VK_C): break; default: if ((e.getModifiers() & (InputEvent.CTRL_MASK | InputEvent.ALT_MASK | InputEvent.META_MASK)) == 0) { moveCaret(); } if ((e.paramString().contains("Backspace")) && (text.getCaretPosition() <= commandPos)) { e.consume(); } break; } }