예제 #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();
    }
  }