当前位置: 首页>>代码示例>>Java>>正文


Java InputMethodEvent.getText方法代码示例

本文整理汇总了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);
}
 
开发者ID:javalovercn,项目名称:j2se_for_android,代码行数:25,代码来源:JFormattedTextField.java

示例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();
        }
    }
    
}
 
开发者ID:shannah,项目名称:cn1,代码行数:18,代码来源:CompositionWindow.java

示例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();
//            }
//         }
        }
    }
 
开发者ID:jeddict,项目名称:NBModeler,代码行数:69,代码来源:EditControlImpl.java

示例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();
}
 
开发者ID:infobip,项目名称:infobip-open-jdk-8,代码行数:44,代码来源:CompositionAreaHandler.java


注:本文中的java.awt.event.InputMethodEvent.getText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。