// This input method handles KeyEvent only.
if (!(event instanceof KeyEvent)) {
return;
}
KeyEvent e = (KeyEvent) event;
int eventID = event.getID();
boolean notInCompositionMode = buffer.length() == 0;
if (eventID == KeyEvent.KEY_PRESSED) {
// If we are not in composition mode, pass through
if (notInCompositionMode) {
return;
}
switch (e.getKeyCode()) {
case KeyEvent.VK_LEFT:
moveCaretLeft();
break;
case KeyEvent.VK_RIGHT:
moveCaretRight();
break;
}
} else if (eventID == KeyEvent.KEY_TYPED) {
char c = e.getKeyChar();
// If we are not in composition mode, wait a back slash
if (notInCompositionMode) {
// If the type character is not a back slash, pass through
if (c != '\\') {
return;
}
startComposition(); // Enter to composition mode
} else {
switch (c) {
case ' ': // Exit from composition mode
finishComposition();
break;
case '\u007f': // Delete
deleteCharacter();
break;
case '\b': // BackSpace
deletePreviousCharacter();
break;
case '\u001b': // Escape
cancelComposition();
break;
case '\n': // Return
case '\t': // Tab
sendCommittedText();
break;
default:
composeUnicodeEscape(c);
break;
}
}
} else { // KeyEvent.KEY_RELEASED
// If we are not in composition mode, pass through
if (notInCompositionMode) {
return;
}
}
e.consume();
}