Example #1
0
 public void keyPressed(KeyEvent e) {
   int code = e.getKeyCode();
   if (code == KeyEvent.VK_ENTER) {
     document.enter();
     e.consume();
   }
 }
        /**
         * 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();
          }
        }
 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("");
     }
   }
 }
Example #4
0
	/**
	 * If a key is being grabbed, this method should be called with
	 * the appropriate key event. It executes the grab action with
	 * the typed character as the parameter.
	 */
	protected void handleGrabAction(KeyEvent evt)
	{
		// Clear it *before* it is executed so that executeAction()
		// resets the repeat count
		ActionListener _grabAction = grabAction;
		grabAction = null;
		executeAction(_grabAction,evt.getSource(),
			String.valueOf(evt.getKeyChar()));
	}
Example #5
0
 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();
   }
 }
Example #7
0
 @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();
   }
 }
Example #8
0
  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();
    }
  }
Example #9
0
 /**
  * Forwards key events directly to the input handler. This is slightly faster than using a
  * KeyListener because some Swing overhead is avoided.
  */
 public void processKeyEvent(KeyEvent evt) {
   if (inputHandler == null) return;
   switch (evt.getID()) {
     case KeyEvent.KEY_TYPED:
       inputHandler.keyTyped(evt);
       break;
     case KeyEvent.KEY_PRESSED:
       inputHandler.keyPressed(evt);
       break;
     case KeyEvent.KEY_RELEASED:
       inputHandler.keyReleased(evt);
       break;
   }
 }
Example #10
0
 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) {
     }
   }
 }
Example #11
0
 @Override
 public void keyTyped(KeyEvent e) {
   e.consume();
 }
Example #12
0
  /**
   * Searches the contact list when any key, different from "space", "+" or "-" is typed. Selects
   * the Contact name closest to the typed string. The time between two button presses is checked to
   * determine whether the user makes a new search or a continuous search. When user types the same
   * letter consecutively the search mechanism selects the next Contact name starting with the same
   * letter.
   */
  public void keyTyped(KeyEvent e) {

    // Nothing to do if the contact list is empty
    if (contactList.getModel().getSize() <= 0) return;

    long eventTimestamp = e.getWhen();
    char keyChar = e.getKeyChar();

    if (keyChar == ' ') {
      openOrCloseGroup();
    } else if (keyChar == '+') {
      openGroup();
    } else if (keyChar == '-') {
      closeGroup();
    } else {

      if ((lastTypedTimestamp - eventTimestamp) > 1000) {
        keyBuffer.delete(0, keyBuffer.length() - 1);
      }
      this.lastTypedTimestamp = eventTimestamp;
      this.keyBuffer.append(keyChar);

      boolean selectedSameLetterContact = false;

      int selectedIndex = this.contactList.getSelectedIndex();

      // Check if there's any selected contact node and get its name.
      if (selectedIndex != -1) {
        Object selectedObject = this.contactList.getSelectedValue();

        if (selectedObject instanceof MetaContact) {
          String selectedContactName = ((MetaContact) selectedObject).getDisplayName();

          if (selectedContactName != null) {
            selectedSameLetterContact =
                selectedContactName.substring(0, 1).equalsIgnoreCase(keyBuffer.toString());
          }
        } else if (selectedObject instanceof ConferenceChatContact) {
          String selectedContactName = ((ConferenceChatContact) selectedObject).getName();

          if (selectedContactName != null) {
            selectedSameLetterContact =
                selectedContactName.substring(0, 1).equalsIgnoreCase(keyBuffer.toString());
          }
        }
      }
      // The search starts from the beginning if:
      // 1) the newly entered character is different from the last one
      // or
      // 2) the currently selected contact starts with a different letter
      int contactIndex =
          contactList.getNextMatch(
              keyBuffer.toString(),
              (lastTypedKey != keyChar || !selectedSameLetterContact) ? 0 : selectedIndex + 1,
              Position.Bias.Forward);

      int currentlySelectedIndex = this.contactList.getSelectedIndex();

      if (currentlySelectedIndex != contactIndex && contactIndex != -1) {
        this.contactList.setSelectedIndex(contactIndex);
        currentlySelectedIndex = contactList.getSelectedIndex();
      }

      this.contactList.ensureIndexIsVisible(currentlySelectedIndex);

      this.lastTypedKey = keyChar;
    }
  }
Example #13
0
    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;
      }
    }
Example #14
0
 public void keyTyped(KeyEvent ke) {
   if (ke.getKeyChar() == KeyEvent.VK_ENTER) {
     sendMessage();
   }
 }