本文整理汇总了Java中java.awt.font.TextHitInfo类的典型用法代码示例。如果您正苦于以下问题:Java TextHitInfo类的具体用法?Java TextHitInfo怎么用?Java TextHitInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TextHitInfo类属于java.awt.font包,在下文中一共展示了TextHitInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRealAlloc
import java.awt.font.TextHitInfo; //导入依赖的package包/类
/**
* Get real allocation (possibly not rectangular) of a part of layout.
* <br>
* It's used when rendering the text layout for filling background highlights of the view.
*
* @param length Total number of characters for which the allocation is computed.
* @param alloc Allocation given by a parent view.
* @return
*/
public static Shape getRealAlloc(TextLayout textLayout, Rectangle2D textLayoutRect,
TextHitInfo startHit, TextHitInfo endHit)
{
// Quick-fix to eliminate missing line in rendering italic "d" - more elaborate fix is needed
textLayoutRect = new Rectangle2D.Double(textLayoutRect.getX(), textLayoutRect.getY(),
textLayoutRect.getWidth() + 2, textLayoutRect.getHeight());
Rectangle2D.Double zeroBasedRect = ViewUtils.shape2Bounds(textLayoutRect);
zeroBasedRect.x = 0;
zeroBasedRect.y = 0;
Shape ret = textLayout.getVisualHighlightShape(startHit, endHit, zeroBasedRect);
AffineTransform transform = AffineTransform.getTranslateInstance(
textLayoutRect.getX(),
textLayoutRect.getY()
);
ret = transform.createTransformedShape(ret);
// The following gives bad result for some reason (works for layout but not for caret modelToView())
// Shape ret2 = textLayout.getVisualHighlightShape(startHit.getCharIndex(), endHit.getCharIndex(), textLayoutRect);
return ret;
}
示例2: runTest
import java.awt.font.TextHitInfo; //导入依赖的package包/类
public void runTest(Object ctx, int numReps) {
TLExContext tlctx = (TLExContext)ctx;
TextLayout tl = tlctx.tl;
TextHitInfo[] hits = tlctx.hits;
Rectangle2D lb = tlctx.lb;
Shape s;
if (hits.length < 3) {
do {
s = tl.getVisualHighlightShape(hits[0], hits[hits.length - 1], lb);
} while (--numReps >= 0);
} else {
do {
for (int i = 3; i < hits.length; ++i) {
s = tl.getVisualHighlightShape(hits[i-3], hits[i], lb);
}
} while (--numReps >= 0);
}
}
示例3: moveCaretLeft
import java.awt.font.TextHitInfo; //导入依赖的package包/类
/**
* Move the insertion point one position to the left in the composed text.
* Do not let the caret move to the left of the "\\u" or "\\U".
*/
private void moveCaretLeft() {
int len = buffer.length();
if (--insertionPoint < 2) {
insertionPoint++;
beep();
} else if (format == SURROGATE_PAIR && insertionPoint == 7) {
insertionPoint = 8;
beep();
}
context.dispatchInputMethodEvent(
InputMethodEvent.CARET_POSITION_CHANGED,
null, 0,
TextHitInfo.leading(insertionPoint), null);
}
示例4: getTextLocation
import java.awt.font.TextHitInfo; //导入依赖的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);
}
}
}
}
示例5: dispatchInputMethodEvent
import java.awt.font.TextHitInfo; //导入依赖的package包/类
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);
}
}
}
示例6: getLocationOffset
import java.awt.font.TextHitInfo; //导入依赖的package包/类
public TextHitInfo getLocationOffset(int x, int y) {
if (composedTextAttribute == null) {
return null;
} else {
Point p = getLocationOnScreen();
p.x = x - p.x;
p.y = y - p.y;
int pos = viewToModel(p);
if ((pos >= composedTextStart.getOffset()) &&
(pos <= composedTextEnd.getOffset())) {
return TextHitInfo.leading(pos - composedTextStart.getOffset());
} else {
return null;
}
}
}
示例7: getTextLocation
import java.awt.font.TextHitInfo; //导入依赖的package包/类
public Rectangle getTextLocation(TextHitInfo offset) {
Rectangle r;
try {
r = modelToView(getCaretPosition());
if (r != null) {
Point p = getLocationOnScreen();
r.translate(p.x, p.y);
}
} catch (BadLocationException ble) {
r = null;
}
if (r == null)
r = new Rectangle();
return r;
}
示例8: getCaretRectangle
import java.awt.font.TextHitInfo; //导入依赖的package包/类
private Rectangle getCaretRectangle(TextHitInfo caret) {
int caretLocation = 0;
TextLayout layout = composedTextLayout;
if (layout != null) {
caretLocation = Math.round(layout.getCaretInfo(caret)[0]);
}
Graphics g = getGraphics();
FontMetrics metrics = null;
try {
metrics = g.getFontMetrics();
} finally {
g.dispose();
}
return new Rectangle(TEXT_ORIGIN_X + caretLocation,
TEXT_ORIGIN_Y - metrics.getAscent(),
0, metrics.getAscent() + metrics.getDescent());
}
示例9: x2RelOffset
import java.awt.font.TextHitInfo; //导入依赖的package包/类
static TextHitInfo x2RelOffset(TextLayout textLayout, float x) {
TextHitInfo hit;
x -= EXTRA_MARGIN_WIDTH;
if (x >= textLayout.getAdvance()) {
hit = TextHitInfo.trailing(textLayout.getCharacterCount());
} else {
hit = textLayout.hitTestChar(x, 0); // What about backward bias -> with higher offsets it may go back visually
}
return hit;
}
示例10: viewToIndex
import java.awt.font.TextHitInfo; //导入依赖的package包/类
static int viewToIndex(TextLayout textLayout, double x, Shape alloc, Position.Bias[] biasReturn) {
Rectangle2D bounds = ViewUtils.shapeAsRect(alloc);
TextHitInfo hitInfo = x2Index(textLayout, (float)(x - bounds.getX()));
if (biasReturn != null) {
biasReturn[0] = hitInfo.isLeadingEdge() ? Position.Bias.Forward : Position.Bias.Backward;
}
return hitInfo.getInsertionIndex();
}
示例11: x2Index
import java.awt.font.TextHitInfo; //导入依赖的package包/类
static TextHitInfo x2Index(TextLayout textLayout, float x) {
TextHitInfo hit;
hit = textLayout.hitTestChar(x, 0);
// Use forward bias only since BaseCaret and other code is not sensitive to backward bias yet
if (!hit.isLeadingEdge()) {
hit = TextHitInfo.leading(hit.getInsertionIndex());
}
return hit;
}
示例12: init
import java.awt.font.TextHitInfo; //导入依赖的package包/类
public void init(TestEnvironment env, Result results) {
super.init(env, results);
ArrayList list = new ArrayList(text.length() * 2 + 2);
TextHitInfo hit = TextHitInfo.trailing(-1);
do {
list.add(hit);
hit = tl.getNextRightHit(hit);
} while (hit != null);
hits = (TextHitInfo[])list.toArray(new TextHitInfo[list.size()]);
lb = tl.getBounds();
lb.setRect(lb.getMinX() - 10, lb.getMinY(), lb.getWidth() + 20, lb.getHeight());
}
示例13: sendComposedText
import java.awt.font.TextHitInfo; //导入依赖的package包/类
/**
* Send the composed text to the client.
*/
private void sendComposedText() {
AttributedString as = new AttributedString(buffer.toString());
as.addAttribute(TextAttribute.INPUT_METHOD_HIGHLIGHT,
InputMethodHighlight.SELECTED_RAW_TEXT_HIGHLIGHT);
context.dispatchInputMethodEvent(
InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
as.getIterator(), 0,
TextHitInfo.leading(insertionPoint), null);
}
示例14: sendCommittedText
import java.awt.font.TextHitInfo; //导入依赖的package包/类
/**
* Send the committed text to the client.
*/
private void sendCommittedText() {
AttributedString as = new AttributedString(buffer.toString());
context.dispatchInputMethodEvent(
InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
as.getIterator(), buffer.length(),
TextHitInfo.leading(insertionPoint), null);
buffer.setLength(0);
insertionPoint = 0;
format = UNSET;
}
示例15: moveCaretRight
import java.awt.font.TextHitInfo; //导入依赖的package包/类
/**
* Move the insertion point one position to the right in the composed text.
*/
private void moveCaretRight() {
int len = buffer.length();
if (++insertionPoint > len) {
insertionPoint = len;
beep();
}
context.dispatchInputMethodEvent(
InputMethodEvent.CARET_POSITION_CHANGED,
null, 0,
TextHitInfo.leading(insertionPoint), null);
}