Java Code Examples for java.awt.event.InputMethodEvent.getText()

The following are Jave code examples for showing how to use getText() of the java.awt.event.InputMethodEvent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: j2se_for_android   File: JFormattedTextField.java   Source Code and License Vote up 6 votes
/**
 * Processes any input method events, such as
 * <code>InputMethodEvent.INPUT_METHOD_TEXT_CHANGED</code> or
 * <code>InputMethodEvent.CARET_POSITION_CHANGED</code>.
 * 
 * @param e
 *            the <code>InputMethodEvent</code>
 * @see InputMethodEvent
 */
protected void processInputMethodEvent(InputMethodEvent e) {
	AttributedCharacterIterator text = e.getText();
	int commitCount = e.getCommittedCharacterCount();

	// Keep track of the composed text
	if (text != null) {
		int begin = text.getBeginIndex();
		int end = text.getEndIndex();
		composedTextExists = ((end - begin) > commitCount);
	} else {
		composedTextExists = false;
	}

	super.processInputMethodEvent(e);
}
 
Example 2
Project: cn1   File: CompositionWindow.java   Source Code and License Vote up 6 votes
private void sendCommittedText(InputMethodEvent ime) {
    int n = ime.getCommittedCharacterCount();
    // remove each committed char from text component
    if (n > 0) {
        setText(getText().substring(n));
    }
    char c;
    CharacterIterator text = ime.getText();
    if (text != null) {
        c = text.first();
        while (n-- > 0) {
            sendChar((Component) ime.getSource(), ime.getWhen(), c);                    
            c = text.next();
        }
    }
    
}
 
Example 3
Project: NBModeler   File: EditControlImpl.java   Source Code and License Vote up 4 votes
@Override
    public void inputMethodTextChanged(InputMethodEvent event) {
        if (!ime_Cached) {
            ime_SelectionStartPos = m_Field.getSelectionStart();
            ime_SelectionEndPos = m_Field.getSelectionEnd();
            if (ime_SelectionStartPos != ime_SelectionEndPos) {
                ime_InitialLoc = Math.min(ime_SelectionStartPos, ime_SelectionEndPos);
            } else {
                ime_InitialLoc = m_Field.getCaretPosition();
            }
            ime_Cached = true;
            ime_CachedChars = new StringBuffer();
        }

        int committedCharacterCount = event.getCommittedCharacterCount();
        CharacterIterator iter = event.getText();
        if (iter != null && ((iter.getEndIndex() - iter.getBeginIndex()) > committedCharacterCount)) {
            if (ime_CachedChars != null) {
                char ch = iter.first();
                for (int i = 0; i < committedCharacterCount; i++) {
                    ime_CachedChars.append(ch);
                    ch = iter.next();
                }
            }
        } else {

            // Push the caret back as part of faking the text input.
            int pos = ime_InitialLoc;
            setCurrentPosition(pos);
            // Fake the key input since handleTypedChar() does the right things.

            if (ime_CachedChars != null) {
                for (int i = 0; i < ime_CachedChars.length(); i++) {
                    handleTypedChar(ime_CachedChars.charAt(i));
                    setCurrentPosition(++pos);
                }
            }

            if (iter != null) {
                for (char ch = iter.first(); ch != CharacterIterator.DONE; ch = iter.next()) {
                    handleTypedChar(ch);
                    setCurrentPosition(++pos);
                }
            }
//	 for(int i = ime_SelectionStartPos; i < ime_SelectionEndPos; i++) {
//	     m_Translator.handleKeyDown(127);
//	 }	   
            ime_Cached = false;
            ime_CachedChars = null;

            event.consume();

            //commit the changes to the edit control
            setModified(true);
//         m_Translator.setModified(true);
//         if (getCurrentField() != null)
//         {
//            getCurrentField().setModified(true);
//         }
//         if (getAssociatedParent() != null)
//         {
//                if (getAssociatedParent() instanceof ProjectTreeCellEditor)
//            {
//               ((ProjectTreeCellEditor)getAssociatedParent()).stopCellEditing();
//            }
//         }
        }
    }
 
Example 4
Project: infobip-open-jdk-8   File: CompositionAreaHandler.java   Source Code and License Vote up 4 votes
public void inputMethodTextChanged(InputMethodEvent event) {
    AttributedCharacterIterator text = event.getText();
    int committedCharacterCount = event.getCommittedCharacterCount();

    // extract composed text and prepare it for display
    composedText = null;
    caret = null;
    if (text != null
            && committedCharacterCount < text.getEndIndex() - text.getBeginIndex()) {

        // Create the composition area if necessary
        if (compositionArea == null) {
             createCompositionArea();
        }

        // copy the composed text
        AttributedString composedTextString;
        composedTextString = new AttributedString(text,
                text.getBeginIndex() + committedCharacterCount, // skip over committed text
                text.getEndIndex(), IM_ATTRIBUTES);
        composedTextString.addAttribute(TextAttribute.FONT, compositionArea.getFont());
        composedText = composedTextString.getIterator();
        caret = event.getCaret();
    }

    if (compositionArea != null) {
        compositionArea.setText(composedText, caret);
    }

    // send any committed text to the text component
    if (committedCharacterCount > 0) {
        inputMethodContext.dispatchCommittedText(((Component) event.getSource()),
                                                 text, committedCharacterCount);

        // this may have changed the text location, so reposition the window
        if (isCompositionAreaVisible()) {
            compositionArea.updateWindowLocation();
        }
    }

    // event has been handled, so consume it
    event.consume();
}
 
Example 5
Project: jdk8u-dev-jdk   File: CompositionAreaHandler.java   Source Code and License Vote up 4 votes
public void inputMethodTextChanged(InputMethodEvent event) {
    AttributedCharacterIterator text = event.getText();
    int committedCharacterCount = event.getCommittedCharacterCount();

    // extract composed text and prepare it for display
    composedText = null;
    caret = null;
    if (text != null
            && committedCharacterCount < text.getEndIndex() - text.getBeginIndex()) {

        // Create the composition area if necessary
        if (compositionArea == null) {
             createCompositionArea();
        }

        // copy the composed text
        AttributedString composedTextString;
        composedTextString = new AttributedString(text,
                text.getBeginIndex() + committedCharacterCount, // skip over committed text
                text.getEndIndex(), IM_ATTRIBUTES);
        composedTextString.addAttribute(TextAttribute.FONT, compositionArea.getFont());
        composedText = composedTextString.getIterator();
        caret = event.getCaret();
    }

    if (compositionArea != null) {
        compositionArea.setText(composedText, caret);
    }

    // send any committed text to the text component
    if (committedCharacterCount > 0) {
        inputMethodContext.dispatchCommittedText(((Component) event.getSource()),
                                                 text, committedCharacterCount);

        // this may have changed the text location, so reposition the window
        if (isCompositionAreaVisible()) {
            compositionArea.updateWindowLocation();
        }
    }

    // event has been handled, so consume it
    event.consume();
}
 
Example 6
Project: jdk7-jdk   File: CompositionAreaHandler.java   Source Code and License Vote up 4 votes
public void inputMethodTextChanged(InputMethodEvent event) {
    AttributedCharacterIterator text = event.getText();
    int committedCharacterCount = event.getCommittedCharacterCount();

    // extract composed text and prepare it for display
    composedText = null;
    caret = null;
    if (text != null
            && committedCharacterCount < text.getEndIndex() - text.getBeginIndex()) {

        // Create the composition area if necessary
        if (compositionArea == null) {
             createCompositionArea();
        }

        // copy the composed text
        AttributedString composedTextString;
        composedTextString = new AttributedString(text,
                text.getBeginIndex() + committedCharacterCount, // skip over committed text
                text.getEndIndex(), IM_ATTRIBUTES);
        composedTextString.addAttribute(TextAttribute.FONT, compositionArea.getFont());
        composedText = composedTextString.getIterator();
        caret = event.getCaret();
    }

    if (compositionArea != null) {
        compositionArea.setText(composedText, caret);
    }

    // send any committed text to the text component
    if (committedCharacterCount > 0) {
        inputMethodContext.dispatchCommittedText(((Component) event.getSource()),
                                                 text, committedCharacterCount);

        // this may have changed the text location, so reposition the window
        if (isCompositionAreaVisible()) {
            compositionArea.updateWindowLocation();
        }
    }

    // event has been handled, so consume it
    event.consume();
}
 
Example 7
Project: openjdk-source-code-learn   File: CompositionAreaHandler.java   Source Code and License Vote up 4 votes
public void inputMethodTextChanged(InputMethodEvent event) {
    AttributedCharacterIterator text = event.getText();
    int committedCharacterCount = event.getCommittedCharacterCount();

    // extract composed text and prepare it for display
    composedText = null;
    caret = null;
    if (text != null
            && committedCharacterCount < text.getEndIndex() - text.getBeginIndex()) {

        // Create the composition area if necessary
        if (compositionArea == null) {
             createCompositionArea();
        }

        // copy the composed text
        AttributedString composedTextString;
        composedTextString = new AttributedString(text,
                text.getBeginIndex() + committedCharacterCount, // skip over committed text
                text.getEndIndex(), IM_ATTRIBUTES);
        composedTextString.addAttribute(TextAttribute.FONT, compositionArea.getFont());
        composedText = composedTextString.getIterator();
        caret = event.getCaret();
    }

    if (compositionArea != null) {
        compositionArea.setText(composedText, caret);
    }

    // send any committed text to the text component
    if (committedCharacterCount > 0) {
        inputMethodContext.dispatchCommittedText(((Component) event.getSource()),
                                                 text, committedCharacterCount);

        // this may have changed the text location, so reposition the window
        if (isCompositionAreaVisible()) {
            compositionArea.updateWindowLocation();
        }
    }

    // event has been handled, so consume it
    event.consume();
}
 
Example 8
Project: OLD-OpenJDK8   File: CompositionAreaHandler.java   Source Code and License Vote up 4 votes
public void inputMethodTextChanged(InputMethodEvent event) {
    AttributedCharacterIterator text = event.getText();
    int committedCharacterCount = event.getCommittedCharacterCount();

    // extract composed text and prepare it for display
    composedText = null;
    caret = null;
    if (text != null
            && committedCharacterCount < text.getEndIndex() - text.getBeginIndex()) {

        // Create the composition area if necessary
        if (compositionArea == null) {
             createCompositionArea();
        }

        // copy the composed text
        AttributedString composedTextString;
        composedTextString = new AttributedString(text,
                text.getBeginIndex() + committedCharacterCount, // skip over committed text
                text.getEndIndex(), IM_ATTRIBUTES);
        composedTextString.addAttribute(TextAttribute.FONT, compositionArea.getFont());
        composedText = composedTextString.getIterator();
        caret = event.getCaret();
    }

    if (compositionArea != null) {
        compositionArea.setText(composedText, caret);
    }

    // send any committed text to the text component
    if (committedCharacterCount > 0) {
        inputMethodContext.dispatchCommittedText(((Component) event.getSource()),
                                                 text, committedCharacterCount);

        // this may have changed the text location, so reposition the window
        if (isCompositionAreaVisible()) {
            compositionArea.updateWindowLocation();
        }
    }

    // event has been handled, so consume it
    event.consume();
}
 
Example 9
Project: openjdk-jdk7u-jdk   File: CompositionAreaHandler.java   Source Code and License Vote up 4 votes
public void inputMethodTextChanged(InputMethodEvent event) {
    AttributedCharacterIterator text = event.getText();
    int committedCharacterCount = event.getCommittedCharacterCount();

    // extract composed text and prepare it for display
    composedText = null;
    caret = null;
    if (text != null
            && committedCharacterCount < text.getEndIndex() - text.getBeginIndex()) {

        // Create the composition area if necessary
        if (compositionArea == null) {
             createCompositionArea();
        }

        // copy the composed text
        AttributedString composedTextString;
        composedTextString = new AttributedString(text,
                text.getBeginIndex() + committedCharacterCount, // skip over committed text
                text.getEndIndex(), IM_ATTRIBUTES);
        composedTextString.addAttribute(TextAttribute.FONT, compositionArea.getFont());
        composedText = composedTextString.getIterator();
        caret = event.getCaret();
    }

    if (compositionArea != null) {
        compositionArea.setText(composedText, caret);
    }

    // send any committed text to the text component
    if (committedCharacterCount > 0) {
        inputMethodContext.dispatchCommittedText(((Component) event.getSource()),
                                                 text, committedCharacterCount);

        // this may have changed the text location, so reposition the window
        if (isCompositionAreaVisible()) {
            compositionArea.updateWindowLocation();
        }
    }

    // event has been handled, so consume it
    event.consume();
}