本文整理匯總了Java中java.awt.event.InputMethodEvent.getText方法的典型用法代碼示例。如果您正苦於以下問題:Java InputMethodEvent.getText方法的具體用法?Java InputMethodEvent.getText怎麽用?Java InputMethodEvent.getText使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.event.InputMethodEvent
的用法示例。
在下文中一共展示了InputMethodEvent.getText方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: processInputMethodEvent
import java.awt.event.InputMethodEvent; //導入方法依賴的package包/類
/**
* 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);
}
示例2: sendCommittedText
import java.awt.event.InputMethodEvent; //導入方法依賴的package包/類
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();
}
}
}
示例3: inputMethodTextChanged
import java.awt.event.InputMethodEvent; //導入方法依賴的package包/類
@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();
// }
// }
}
}
示例4: inputMethodTextChanged
import java.awt.event.InputMethodEvent; //導入方法依賴的package包/類
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();
}