/** * InputMethod implementation For details read * http://docs.oracle.com/javase/7/docs/technotes/guides/imf/api-tutorial.html */ @Override protected void processInputMethodEvent(InputMethodEvent e) { int commitCount = e.getCommittedCharacterCount(); if (commitCount > 0) { myInputMethodUncommitedChars = null; AttributedCharacterIterator text = e.getText(); if (text != null) { StringBuilder sb = new StringBuilder(); //noinspection ForLoopThatDoesntUseLoopVariable for (char c = text.first(); commitCount > 0; c = text.next(), commitCount--) { if (c >= 0x20 && c != 0x7F) { // Hack just like in // javax.swing.text.DefaultEditorKit.DefaultKeyTypedAction sb.append(c); } } myTerminalStarter.sendString(sb.toString()); } } else { myInputMethodUncommitedChars = uncommitedChars(e.getText()); } }
private static String uncommitedChars(AttributedCharacterIterator text) { StringBuilder sb = new StringBuilder(); for (char c = text.first(); c != CharacterIterator.DONE; c = text.next()) { if (c >= 0x20 && c != 0x7F) { // Hack just like in // javax.swing.text.DefaultEditorKit.DefaultKeyTypedAction sb.append(c); } } return sb.toString(); }