本文整理汇总了Java中java.awt.im.InputMethodRequests.getTextLocation方法的典型用法代码示例。如果您正苦于以下问题:Java InputMethodRequests.getTextLocation方法的具体用法?Java InputMethodRequests.getTextLocation怎么用?Java InputMethodRequests.getTextLocation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.im.InputMethodRequests
的用法示例。
在下文中一共展示了InputMethodRequests.getTextLocation方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTextLocation
import java.awt.im.InputMethodRequests; //导入方法依赖的package包/类
public Rectangle getTextLocation(TextHitInfo offset) {
synchronized (compositionAreaLock) {
if (compositionAreaOwner == this && isCompositionAreaVisible()) {
return compositionArea.getTextLocation(offset);
} else if (composedText != null) {
// there's composed text, but it's not displayed, so fake a rectangle
return new Rectangle(0, 0, 0, 10);
} else {
InputMethodRequests requests = getClientInputMethodRequests();
if (requests != null) {
return requests.getTextLocation(offset);
} else {
// passive client, no composed text, so fake a rectangle
return new Rectangle(0, 0, 0, 10);
}
}
}
}
示例2: updateWindowLocation
import java.awt.im.InputMethodRequests; //导入方法依赖的package包/类
/**
* Positions the composition window near (usually below) the
* insertion point in the client component if the client
* component is an active client (below-the-spot input).
*/
void updateWindowLocation() {
InputMethodRequests req = handler.getClientInputMethodRequests();
if (req == null) {
// not an active client
return;
}
Point windowLocation = new Point();
Rectangle caretRect = req.getTextLocation(null);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension windowSize = compositionWindow.getSize();
final int SPACING = 2;
if (caretRect.x + windowSize.width > screenSize.width) {
windowLocation.x = screenSize.width - windowSize.width;
} else {
windowLocation.x = caretRect.x;
}
if (caretRect.y + caretRect.height + SPACING + windowSize.height > screenSize.height) {
windowLocation.y = caretRect.y - SPACING - windowSize.height;
} else {
windowLocation.y = caretRect.y + caretRect.height + SPACING;
}
compositionWindow.setLocation(windowLocation);
}
示例3: ActiveClient
import java.awt.im.InputMethodRequests; //导入方法依赖的package包/类
ActiveClient() throws HeadlessException {
// prevent IM invocation on this component
enableInputMethods(false);
ComponentInternals ci = ComponentInternals.getComponentInternals();
TextKit textKit = ci.getTextKit(this);
caret = (DefaultCaret) textKit.getCaret();
caret.setBlinkRate(0);
caret.setVisible(true);
imRequests = new InputMethodRequestsImpl(textKit) {
@Override
public TextHitInfo getLocationOffset(int x, int y) {
if (!isShowing()) {
return null;
}
return super.getLocationOffset(x, y);
}
};
imListener = new InputMethodListenerImpl(textKit) {
@Override
public void inputMethodTextChanged(InputMethodEvent ime) {
super.inputMethodTextChanged(ime);
// create KEY_TYPED event for each committed char
// and send it to passive client or just
// redirect this event to active client
if (client == null) {
return;
}
InputMethodRequests imr = client.getInputMethodRequests();
if (imr != null) {
if (IMManager.belowTheSpot()) {
// position window below the spot:
TextHitInfo offset = TextHitInfo.leading(0);
Rectangle textLoc = imr.getTextLocation(offset);
setLocationBelow(textLoc);
} else {
client.dispatchEvent(ime);
return;
}
}
sendCommittedText(ime);
}
};
addInputMethodListener(imListener);
}