예제 #1
0
  public void keyTyped(KeyEvent e) {
    if (!enabled) return;
    TextComponent input = (TextComponent) e.getSource();
    String strContent = input.getText();

    char c = e.getKeyChar();
    if (!isModifier(c)) return;
    int pos = input.getCaretPosition();
    if (pos <= 0) return;
    int idx = pos - 1; // position of the character to be modified
    char last = strContent.charAt(idx);
    char newVal = last;
    if (isCircumflex(c, last)) newVal = encoding.addCircumflex(last);
    else if (isBreve(c, last)) newVal = encoding.addBreveHorn(last);
    else if (isHorn(c, last)) newVal = encoding.addBreveHorn(last);
    else if (isStroke(c, last)) newVal = encoding.addStroke(last);
    else if (isToneMark(c)) {
      idx = indexOfToneCarrier(pos, strContent);
      if (idx < 0) return;
      last = strContent.charAt(idx);
      newVal = encoding.modifyTone(last, getToneMarkId(c));
    }
    if (last != newVal) {
      input.setCaretPosition(idx);
      TextField txt;
      //			input.moveCaretPosition(idx+1);
      //			input.replaceSelection("" + newVal);
      input.setCaretPosition(pos);
      e.consume();
    }
  }
예제 #2
0
 private void selectAll(Component focusOwner) {
   if (focusOwner instanceof TextComponent) {
     ((TextComponent) focusOwner).selectAll();
   } else {
     Editor editor =
         PlatformDataKeys.EDITOR.getData(DataManager.getInstance().getDataContext(focusOwner));
     if (editor != null) {
       editor.getSelectionModel().setSelection(0, editor.getDocument().getTextLength());
     }
   }
 }
 @Override
 public void textValueChanged(TextEvent e) {
   TextComponent tc = (TextComponent) e.getSource();
   tc.setBackground(Color.red);
 }