Search in sources :

Example 6 with TextHitInfo

use of java.awt.font.TextHitInfo in project jdk8u_jdk by JetBrains.

the class X11InputMethod method dispatchComposedText.

/**
     * Updates composed text with XIM preedit information and
     * posts composed text to the awt event queue. The args of
     * this method correspond to the XIM preedit callback
     * information. The XIM highlight attributes are translated via
     * fixed mapping (i.e., independent from any underlying input
     * method engine). This method is invoked in the AWT Toolkit
     * (X event loop) thread context and thus inside the AWT Lock.
     */
// NOTE: This method may be called by privileged threads.
//       This functionality is implemented in a package-private method
//       to insure that it cannot be overridden by client subclasses.
//       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
void dispatchComposedText(String chgText, int[] chgStyles, int chgOffset, int chgLength, int caretPosition, long when) {
    if (disposed) {
        return;
    }
    //Workaround for deadlock bug on solaris2.6_zh bug#4170760
    if (chgText == null && chgStyles == null && chgOffset == 0 && chgLength == 0 && caretPosition == 0 && composedText == null && committedText == null)
        return;
    if (composedText == null) {
        // TODO: avoid reallocation of those buffers
        composedText = new StringBuffer(INITIAL_SIZE);
        rawFeedbacks = new IntBuffer(INITIAL_SIZE);
    }
    if (chgLength > 0) {
        if (chgText == null && chgStyles != null) {
            rawFeedbacks.replace(chgOffset, chgStyles);
        } else {
            if (chgLength == composedText.length()) {
                // optimization for the special case to replace the
                // entire previous text
                composedText = new StringBuffer(INITIAL_SIZE);
                rawFeedbacks = new IntBuffer(INITIAL_SIZE);
            } else {
                if (composedText.length() > 0) {
                    if (chgOffset + chgLength < composedText.length()) {
                        String text;
                        text = composedText.toString().substring(chgOffset + chgLength, composedText.length());
                        composedText.setLength(chgOffset);
                        composedText.append(text);
                    } else {
                        // in case to remove substring from chgOffset
                        // to the end
                        composedText.setLength(chgOffset);
                    }
                    rawFeedbacks.remove(chgOffset, chgLength);
                }
            }
        }
    }
    if (chgText != null) {
        composedText.insert(chgOffset, chgText);
        if (chgStyles != null)
            rawFeedbacks.insert(chgOffset, chgStyles);
    }
    if (composedText.length() == 0) {
        composedText = null;
        rawFeedbacks = null;
        // client component.
        if (committedText != null) {
            dispatchCommittedText(committedText, when);
            committedText = null;
            return;
        }
        // otherwise, send null text to delete client's composed
        // text.
        postInputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED, null, 0, null, null, when);
        return;
    }
    // Now sending the composed text to the client
    int composedOffset;
    AttributedString inputText;
    // the composed text.
    if (committedText != null) {
        composedOffset = committedText.length();
        inputText = new AttributedString(committedText + composedText);
        committedText = null;
    } else {
        composedOffset = 0;
        inputText = new AttributedString(composedText.toString());
    }
    int currentFeedback;
    int nextFeedback;
    int startOffset = 0;
    int currentOffset;
    int visiblePosition = 0;
    TextHitInfo visiblePositionInfo = null;
    rawFeedbacks.rewind();
    currentFeedback = rawFeedbacks.getNext();
    rawFeedbacks.unget();
    while ((nextFeedback = rawFeedbacks.getNext()) != -1) {
        if (visiblePosition == 0) {
            visiblePosition = nextFeedback & XIMVisibleMask;
            if (visiblePosition != 0) {
                int index = rawFeedbacks.getOffset() - 1;
                if (visiblePosition == XIMVisibleToBackward)
                    visiblePositionInfo = TextHitInfo.leading(index);
                else
                    visiblePositionInfo = TextHitInfo.trailing(index);
            }
        }
        nextFeedback &= ~XIMVisibleMask;
        if (currentFeedback != nextFeedback) {
            rawFeedbacks.unget();
            currentOffset = rawFeedbacks.getOffset();
            inputText.addAttribute(TextAttribute.INPUT_METHOD_HIGHLIGHT, convertVisualFeedbackToHighlight(currentFeedback), composedOffset + startOffset, composedOffset + currentOffset);
            startOffset = currentOffset;
            currentFeedback = nextFeedback;
        }
    }
    currentOffset = rawFeedbacks.getOffset();
    if (currentOffset >= 0) {
        inputText.addAttribute(TextAttribute.INPUT_METHOD_HIGHLIGHT, convertVisualFeedbackToHighlight(currentFeedback), composedOffset + startOffset, composedOffset + currentOffset);
    }
    postInputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED, inputText.getIterator(), composedOffset, TextHitInfo.leading(caretPosition), visiblePositionInfo, when);
}
Also used : AttributedString(java.text.AttributedString) TextHitInfo(java.awt.font.TextHitInfo) AttributedString(java.text.AttributedString)

Example 7 with TextHitInfo

use of java.awt.font.TextHitInfo in project binnavi by google.

the class ZyCaret method calcCaretPosition.

private int calcCaretPosition(final int hitLine, final double x, final double y) {
    final ZyLineContent content = m_content.getLineContent(hitLine);
    final TextLayout textlayout = m_content.getLineContent(hitLine).getTextLayout();
    final TextHitInfo hitInfo = textlayout.hitTestChar((float) x, (float) y, content.getBounds());
    return hitInfo.getInsertionIndex();
}
Also used : TextHitInfo(java.awt.font.TextHitInfo) TextLayout(java.awt.font.TextLayout)

Example 8 with TextHitInfo

use of java.awt.font.TextHitInfo in project hid-serial by rayshobby.

the class GTextArea method moveCaretRight.

/**
	 * Move caret right by one character. If necessary move to the start of the next line 
	 * @return true if caret was moved else false
	 */
protected boolean moveCaretRight(TextLayoutHitInfo currPos) {
    TextLayoutInfo ntli;
    TextHitInfo nthi = currPos.tli.layout.getNextRightHit(currPos.thi);
    if (nthi == null) {
        // Move the caret to the start of the next line the previous line 
        if (currPos.tli.lineNo >= stext.getNbrLines() - 1)
            // Can't goto next line because this is the last line
            return false;
        else {
            // Move to start of next line
            ntli = stext.getTLIforLineNo(currPos.tli.lineNo + 1);
            nthi = ntli.layout.getNextLeftHit(1);
            currPos.tli = ntli;
            currPos.thi = nthi;
        }
    } else {
        // Move the caret to the right of current position
        currPos.thi = nthi;
    }
    return true;
}
Also used : TextHitInfo(java.awt.font.TextHitInfo) TextLayoutInfo(g4p_controls.StyledString.TextLayoutInfo)

Example 9 with TextHitInfo

use of java.awt.font.TextHitInfo in project hid-serial by rayshobby.

the class GTextArea method moveCaretDown.

protected boolean moveCaretDown(TextLayoutHitInfo currPos) {
    if (currPos.tli.lineNo == stext.getNbrLines() - 1)
        return false;
    TextLayoutInfo ntli = stext.getTLIforLineNo(currPos.tli.lineNo + 1);
    TextHitInfo nthi = ntli.layout.hitTestChar(caretX, 0);
    currPos.tli = ntli;
    currPos.thi = nthi;
    return true;
}
Also used : TextHitInfo(java.awt.font.TextHitInfo) TextLayoutInfo(g4p_controls.StyledString.TextLayoutInfo)

Example 10 with TextHitInfo

use of java.awt.font.TextHitInfo in project hid-serial by rayshobby.

the class StyledString method calculateFromXY.

TextLayoutHitInfo calculateFromXY(Graphics2D g2d, float px, float py) {
    TextHitInfo thi = null;
    TextLayoutInfo tli = null;
    TextLayoutHitInfo tlhi = null;
    if (invalidLayout)
        getLines(g2d);
    if (px < 0)
        px = 0;
    if (py < 0)
        py = 0;
    tli = getTLIforYpos(py);
    // Correct py to match layout's upper-left bounds
    py -= tli.yPosInPara;
    // get hit
    thi = tli.layout.hitTestChar(px, py);
    tlhi = new TextLayoutHitInfo(tli, thi);
    return tlhi;
}
Also used : TextHitInfo(java.awt.font.TextHitInfo)

Aggregations

TextHitInfo (java.awt.font.TextHitInfo)12 TextLayoutInfo (g4p_controls.StyledString.TextLayoutInfo)5 TextLayout (java.awt.font.TextLayout)4 java.awt.print (java.awt.print)1 AttributedString (java.text.AttributedString)1