/** * 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()); } }
/** * Handlers INPUT_METHOD_TEXT_CHANGED event. This handler also checks if a invalid key is pressed. * This handler is not necessary for JDK1.1, but in JDK1.2, 'keyTyped' event is never generated * instead this event is generated so it has to be handled. * * <p>Note: In JDK1.1 this method should be commented. * * @param imeEvt event object */ public void inputMethodTextChanged(InputMethodEvent imeEvt) { AttributedCharacterIterator aciIterator = imeEvt.getText(); for (char cChar = aciIterator.first(); cChar != CharacterIterator.DONE; cChar = aciIterator.next()) { // If any one of the characters is not allowed, // consume the event ... if (Character.isDigit(cChar) || cChar == TIME_SEP || cChar == KeyEvent.VK_PERIOD) continue; imeEvt.consume(); return; } return; }
private void TconsolaInputMethodTextChanged( java.awt.event.InputMethodEvent evt) { // GEN-FIRST:event_TconsolaInputMethodTextChanged // TODO add your handling code here: if (evt.getWhen() == evt.INPUT_METHOD_TEXT_CHANGED) System.out.println("Cambio de text"); } // GEN-LAST:event_TconsolaInputMethodTextChanged