示例#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
 protected int indexOfToneCarrier(int pos, String strContent) {
   int idx = indexOfLastVowel(pos, strContent);
   if (idx <= 0) return idx;
   char c = strContent.charAt(idx - 1);
   if (!encoding.isVowel(c) && !eq(c, 'q')) return idx;
   if (encoding.hasDiacritic(strContent.charAt(idx))) return idx;
   if (encoding.hasDiacritic(c)) return idx - 1;
   if (eq(c, 'q') && eq(strContent.charAt(idx), 'u')) return -1;
   if (eq(c, 'o') && eq(strContent.charAt(idx), 'a')) return idx;
   if (eq(c, 'o') && eq(strContent.charAt(idx), 'e')) return idx;
   if (eq(c, 'u') && eq(strContent.charAt(idx), 'y')) return idx;
   if ((idx >= 2) && eq(c, 'u') && eq(strContent.charAt(idx - 2), 'q')) return idx;
   if ((idx >= 2) && eq(c, 'i') && eq(strContent.charAt(idx - 2), 'g')) return idx;
   return idx - 1;
 }
示例#3
0
 protected int indexOfLastVowel(int pos, String strContent) {
   int beg = Math.max(0, pos - 3);
   for (int i = pos - 1; i >= beg; i--) {
     char c = strContent.charAt(i);
     if (encoding.isVowel(c)) return i;
   }
   return -1;
 }