类java.awt.font.TextHitInfo源码实例Demo

下面列出了怎么用java.awt.font.TextHitInfo的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: jdk8u_jdk   文件: CodePointInputMethod.java
/**
 * 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);
}
 
源代码2 项目: jdk1.8-source-analysis   文件: JTextComponent.java
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;
}
 
源代码3 项目: jdk8u-jdk   文件: JTextComponent.java
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;
}
 
源代码4 项目: hottub   文件: JTextComponent.java
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;
}
 
源代码5 项目: dragonwell8_jdk   文件: CompositionArea.java
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());
}
 
源代码6 项目: dragonwell8_jdk   文件: CompositionAreaHandler.java
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);
            }
        }
    }
}
 
源代码7 项目: dragonwell8_jdk   文件: InputMethodContext.java
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);
        }
    }
}
 
源代码8 项目: jdk8u60   文件: CodePointInputMethod.java
/**
 * 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);
}
 
源代码9 项目: Java8CN   文件: JTextComponent.java
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;
}
 
源代码10 项目: openjdk-8-source   文件: CodePointInputMethod.java
/**
 * 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);
}
 
源代码11 项目: openjdk-jdk9   文件: CompositionArea.java
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());
}
 
源代码12 项目: jdk8u-jdk   文件: CompositionAreaHandler.java
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);
            }
        }
    }
}
 
源代码13 项目: TencentKona-8   文件: CompositionAreaHandler.java
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);
            }
        }
    }
}
 
源代码14 项目: netbeans   文件: TextLayoutUtils.java
/**
     * 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;
    }
 
源代码15 项目: TencentKona-8   文件: InputMethodContext.java
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);
        }
    }
}
 
源代码16 项目: openjdk-jdk8u-backup   文件: InputMethodContext.java
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);
        }
    }
}
 
源代码17 项目: openjdk-jdk9   文件: JTextComponent.java
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;
        }
    }
}
 
源代码18 项目: hottub   文件: JTextComponent.java
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;
        }
    }
}
 
源代码19 项目: openjdk-8-source   文件: InputMethodContext.java
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);
        }
    }
}
 
源代码20 项目: openjdk-8-source   文件: JTextComponent.java
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;
        }
    }
}
 
源代码21 项目: openjdk-jdk9   文件: JTextComponent.java
private void setInputMethodCaretPosition(InputMethodEvent e) {
    int dot;

    if (composedTextExists()) {
        dot = composedTextStart.getOffset();
        if (!(caret instanceof ComposedTextCaret)) {
            if (composedTextCaret == null) {
                composedTextCaret = new ComposedTextCaret();
            }
            originalCaret = caret;
            // Sets composed text caret
            exchangeCaret(originalCaret, composedTextCaret);
        }

        TextHitInfo caretPos = e.getCaret();
        if (caretPos != null) {
            int index = caretPos.getInsertionIndex();
            dot += index;
            if (index == 0) {
                // Scroll the component if needed so that the composed text
                // becomes visible.
                try {
                    Rectangle d = modelToView(dot);
                    Rectangle end = modelToView(composedTextEnd.getOffset());
                    Rectangle b = getBounds();
                    d.x += Math.min(end.x - d.x, b.width);
                    scrollRectToVisible(d);
                } catch (BadLocationException ble) {}
            }
        }
        caret.setDot(dot);
    } else if (caret instanceof ComposedTextCaret) {
        dot = caret.getDot();
        // Restores original caret
        exchangeCaret(caret, originalCaret);
        caret.setDot(dot);
    }
}
 
/**
 * 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);
}
 
源代码23 项目: openjdk-jdk8u-backup   文件: CompositionArea.java
TextHitInfo getLocationOffset(int x, int y) {
    TextLayout layout = composedTextLayout;
    if (layout == null) {
        return null;
    } else {
        Point location = getLocationOnScreen();
        x -= location.x + TEXT_ORIGIN_X;
        y -= location.y + TEXT_ORIGIN_Y;
        if (layout.getBounds().contains(x, y)) {
            return layout.hitTestChar(x, y);
        } else {
            return null;
        }
    }
}
 
源代码24 项目: openjdk-jdk8u   文件: TextMeasureTests.java
public void runTest(Object ctx, int numReps) {
    TLExContext tlctx = (TLExContext)ctx;
    TextLayout tl = tlctx.tl;
    TextHitInfo[] hits = tlctx.hits;
    Shape s;
    do {
        for (int i = 0; i < hits.length; ++i) {
            s = tl.getCaretShape(hits[i]);
        }
    } while (--numReps >= 0);
}
 
源代码25 项目: jdk8u-jdk   文件: CodePointInputMethod.java
/**
 * 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;
}
 
/**
 * 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);
}
 
源代码27 项目: dragonwell8_jdk   文件: TextMeasureTests.java
public void runTest(Object ctx, int numReps) {
    TLExContext tlctx = (TLExContext)ctx;
    TextLayout tl = tlctx.tl;
    TextHitInfo[] hits = tlctx.hits;
    do {
        for (int i = 0; i < hits.length; ++i) {
            tl.getCaretInfo(hits[i]);
        }
    } while (--numReps >= 0);
}
 
源代码28 项目: jdk8u-jdk   文件: CompositionArea.java
/**
 * Sets the caret to be displayed in this composition area.
 * The text is not changed.
 */
void setCaret(TextHitInfo caret) {
    this.caret = caret;
    if (compositionWindow.isVisible()) {
        Graphics g = getGraphics();
        try {
            paint(g);
        } finally {
            g.dispose();
        }
    }
}
 
源代码29 项目: openjdk-8-source   文件: CompositionArea.java
/**
 * Sets the caret to be displayed in this composition area.
 * The text is not changed.
 */
void setCaret(TextHitInfo caret) {
    this.caret = caret;
    if (compositionWindow.isVisible()) {
        Graphics g = getGraphics();
        try {
            paint(g);
        } finally {
            g.dispose();
        }
    }
}
 
源代码30 项目: hottub   文件: CodePointInputMethod.java
/**
 * 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;
}
 
 类所在包
 同包方法