The InputMethodContext class provides methods that input methods
can use to communicate with their client components.
It is a subclass of InputContext, which provides methods for use by
components.
| Method from sun.awt.im.InputMethodContext Detail: |
public AttributedCharacterIterator cancelLatestCommittedText(Attribute[] attributes) {
return getReq().cancelLatestCommittedText(attributes);
}
Calls the current client component's implementation of cancelLatestCommittedText. |
public JFrame createInputMethodJFrame(String title,
boolean attachToInputContext) {
InputContext context = attachToInputContext ? this : null;
return (JFrame)createInputMethodWindow(title, context, true);
}
|
public Window createInputMethodWindow(String title,
boolean attachToInputContext) {
InputContext context = attachToInputContext ? this : null;
return createInputMethodWindow(title, context, false);
}
|
static Window createInputMethodWindow(String title,
InputContext context,
boolean isSwing) {
if (GraphicsEnvironment.isHeadless()) {
throw new HeadlessException();
}
if (isSwing) {
return new InputMethodJFrame(title, context);
} else {
Toolkit toolkit = Toolkit.getDefaultToolkit();
if (toolkit instanceof InputMethodSupport) {
return ((InputMethodSupport)toolkit).createInputMethodWindow(
title, context);
}
}
throw new InternalError("Input methods must be supported");
}
|
synchronized void dispatchCommittedText(Component client,
AttributedCharacterIterator text,
int committedCharacterCount) {
// note that the client is not always the current client component -
// some host input method adapters may dispatch input method events
// through the Java event queue, and we may have switched clients while
// the event was in the queue.
if (committedCharacterCount == 0
|| text.getEndIndex() < = text.getBeginIndex()) {
return;
}
long time = System.currentTimeMillis();
dispatchingCommittedText = true;
try {
InputMethodRequests req = client.getInputMethodRequests();
if (req != null) {
// active client - > send text as InputMethodEvent
int beginIndex = text.getBeginIndex();
AttributedCharacterIterator toBeCommitted =
(new AttributedString(text, beginIndex, beginIndex + committedCharacterCount)).getIterator();
InputMethodEvent inputEvent = new InputMethodEvent(
client,
InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
toBeCommitted,
committedCharacterCount,
null, null);
client.dispatchEvent(inputEvent);
} else {
// passive client - > send text as KeyEvents
char keyChar = text.first();
while (committedCharacterCount-- > 0 && keyChar != CharacterIterator.DONE) {
KeyEvent keyEvent = new KeyEvent(client, KeyEvent.KEY_TYPED,
time, 0, KeyEvent.VK_UNDEFINED, keyChar);
client.dispatchEvent(keyEvent);
keyChar = text.next();
}
}
} finally {
dispatchingCommittedText = false;
}
}
Dispatches committed text to a client component.
Called by composition window. |
public void dispatchEvent(AWTEvent event) {
// some host input method adapters may dispatch input method events
// through the Java event queue. If the component that the event is
// intended for isn't an active client, or if we're using below-the-spot
// input, we need to dispatch this event
// to the input window. Note that that component is not necessarily the
// current client component, since we may have switched clients while
// the event was in the queue.
if (event instanceof InputMethodEvent) {
if (((Component) event.getSource()).getInputMethodRequests() == null
|| (useBelowTheSpotInput() && !dispatchingCommittedText)) {
getCompositionAreaHandler(true).processInputMethodEvent((InputMethodEvent) event);
}
} else {
// make sure we don't dispatch our own key events back to the input method
if (!dispatchingCommittedText) {
super.dispatchEvent(event);
}
}
}
|
public void dispatchInputMethodEvent(int id,
AttributedCharacterIterator text,
int committedCharacterCount,
TextHitInfo caret,
TextHitInfo visiblePosition) {
// We need to record the client component as the source so
// that we have correct information if we later have to break up this
// event into key events.
Component source;
source = getClientComponent();
if (source != null) {
InputMethodEvent event = new InputMethodEvent(source,
id, text, committedCharacterCount, caret, visiblePosition);
if (haveActiveClient() && !useBelowTheSpotInput()) {
source.dispatchEvent(event);
} else {
getCompositionAreaHandler(true).processInputMethodEvent(event);
}
}
}
|
public void enableClientWindowNotification(InputMethod inputMethod,
boolean enable) {
super.enableClientWindowNotification(inputMethod, enable);
}
|
public AttributedCharacterIterator getCommittedText(int beginIndex,
int endIndex,
Attribute[] attributes) {
return getReq().getCommittedText(beginIndex, endIndex, attributes);
}
Calls the current client component's implementation of getCommittedText. |
public int getCommittedTextLength() {
return getReq().getCommittedTextLength();
}
Calls the current client component's implementation of getCommittedTextLength. |
public int getInsertPositionOffset() {
return getReq().getInsertPositionOffset();
}
Calls the current client component's implementation of getInsertPositionOffset. |
public TextHitInfo getLocationOffset(int x,
int y) {
return getReq().getLocationOffset(x, y);
}
Calls the current client component's implementation of getLocationOffset. |
public AttributedCharacterIterator getSelectedText(Attribute[] attributes) {
return getReq().getSelectedText(attributes);
}
Calls the current client component's implementation of getSelectedText. |
public Rectangle getTextLocation(TextHitInfo offset) {
return getReq().getTextLocation(offset);
}
Calls the current client component's implementation of getTextLocation. |
void grabCompositionArea(boolean doUpdate) {
synchronized(compositionAreaHandlerLock) {
if (compositionAreaHandler != null) {
compositionAreaHandler.grabCompositionArea(doUpdate);
} else {
// if this context hasn't seen a need for a composition area yet,
// just close it without creating the machinery
CompositionAreaHandler.closeCompositionArea();
}
}
}
Grabs the composition area for use by this context.
If doUpdate is true, updates the composition area with previously sent
composed text. |
boolean isCompositionAreaVisible() {
if (compositionAreaHandler != null) {
return compositionAreaHandler.isCompositionAreaVisible();
}
return false;
}
Calls CompositionAreaHandler.isCompositionAreaVisible() to see
whether the composition area is visible or not.
Notice that this method is always called on the AWT event dispatch
thread. |
void releaseCompositionArea() {
synchronized(compositionAreaHandlerLock) {
if (compositionAreaHandler != null) {
compositionAreaHandler.releaseCompositionArea();
}
}
}
Releases and closes the composition area if it is currently owned by
this context's composition area handler. |
void setCompositionAreaUndecorated(boolean undecorated) {
if (compositionAreaHandler != null) {
compositionAreaHandler.setCompositionAreaUndecorated(undecorated);
}
}
Disables or enables decorations for the composition window. |
void setCompositionAreaVisible(boolean visible) {
if (compositionAreaHandler != null) {
compositionAreaHandler.setCompositionAreaVisible(visible);
}
}
Calls CompositionAreaHandler.setCompositionAreaVisible to
show or hide the composition area.
As isCompositionAreaVisible method, it is always called
on AWT event dispatch thread. |
void setInputMethodSupportsBelowTheSpot(boolean supported) {
inputMethodSupportsBelowTheSpot = supported;
}
|
boolean useBelowTheSpotInput() {
return belowTheSpotInputRequested && inputMethodSupportsBelowTheSpot;
}
|