Search in sources :

Example 11 with TextLayoutHitInfo

use of automenta.vivisect.gui.StyledString.TextLayoutHitInfo in project opennars by opennars.

the class GEditableTextControl method clearSelectionStyle.

/**
 * Clear any styles applied to the selected text.
 */
public void clearSelectionStyle() {
    if (!hasSelection())
        return;
    TextLayoutHitInfo startSelTLHI;
    TextLayoutHitInfo endSelTLHI;
    if (endTLHI.compareTo(startTLHI) == -1) {
        startSelTLHI = endTLHI;
        endSelTLHI = startTLHI;
    } else {
        startSelTLHI = startTLHI;
        endSelTLHI = endTLHI;
    }
    int ss = startSelTLHI.tli.startCharIndex + startSelTLHI.thi.getInsertionIndex();
    int ee = endSelTLHI.tli.startCharIndex + endSelTLHI.thi.getInsertionIndex();
    stext.clearAttributes(ss, ee);
    // We have modified the text style so the end of the selection may have
    // moved, so it needs to be recalculated. The start will be unaffected.
    stext.getLines(buffer.g2);
    endSelTLHI.tli = stext.getTLIforCharNo(ee);
    int cn = ee - endSelTLHI.tli.startCharIndex;
    if (// start of line
    cn == 0)
        endSelTLHI.thi = endSelTLHI.tli.layout.getNextLeftHit(1);
    else
        endSelTLHI.thi = endSelTLHI.tli.layout.getNextRightHit(cn - 1);
    bufferInvalid = true;
}
Also used : TextLayoutHitInfo(automenta.vivisect.gui.StyledString.TextLayoutHitInfo)

Example 12 with TextLayoutHitInfo

use of automenta.vivisect.gui.StyledString.TextLayoutHitInfo in project opennars by opennars.

the class GPassword method mouseEvent.

public void mouseEvent(MouseEvent event) {
    if (!visible || !enabled || !available)
        return;
    calcTransformedOrigin(winApp.getCursorX(), winApp.getCursorY());
    // Remove translation
    ox -= tx;
    // Remove translation
    oy -= ty;
    currSpot = whichHotSpot(ox, oy);
    if (currSpot == 1 || focusIsWith == this)
        cursorIsOver = this;
    else if (cursorIsOver == this)
        cursorIsOver = null;
    switch(event.getAction()) {
        case MouseEvent.PRESS:
            if (currSpot == 1) {
                if (focusIsWith != this && z >= focusObjectZ()) {
                    keepCursorInView = true;
                    takeFocus();
                }
                dragging = false;
                if (stext == null || stext.length() == 0) {
                    stext = new StyledString(" ", wrapWidth);
                    stext.getLines(buffer.g2);
                }
                endTLHI = stext.calculateFromXY(buffer.g2, ox + ptx, oy + pty);
                startTLHI = new TextLayoutHitInfo(endTLHI);
                calculateCaretPos(endTLHI);
                bufferInvalid = true;
            } else {
                // Not over this control so if we have focus loose it
                if (focusIsWith == this)
                    loseFocus(null);
            }
            break;
        case MouseEvent.RELEASE:
            dragging = false;
            bufferInvalid = true;
            break;
    }
}
Also used : TextLayoutHitInfo(automenta.vivisect.gui.StyledString.TextLayoutHitInfo)

Example 13 with TextLayoutHitInfo

use of automenta.vivisect.gui.StyledString.TextLayoutHitInfo in project opennars by opennars.

the class GPassword method setFocus.

/**
 * Determines whether this component is to have focus or not. <br>
 */
public void setFocus(boolean focus) {
    if (!focus) {
        loseFocus(null);
        return;
    }
    // Make sure we have some text
    if (focusIsWith != this) {
        dragging = false;
        if (stext == null || stext.length() == 0)
            stext = new StyledString(" ", wrapWidth);
        LinkedList<TextLayoutInfo> lines = stext.getLines(buffer.g2);
        startTLHI = new TextLayoutHitInfo(lines.getFirst(), null);
        startTLHI.thi = startTLHI.tli.layout.getNextLeftHit(1);
        endTLHI = new TextLayoutHitInfo(lines.getLast(), null);
        int lastChar = endTLHI.tli.layout.getCharacterCount();
        endTLHI.thi = startTLHI.tli.layout.getNextRightHit(lastChar - 1);
        startTLHI.copyFrom(endTLHI);
        calculateCaretPos(endTLHI);
        bufferInvalid = true;
    }
    keepCursorInView = true;
    takeFocus();
}
Also used : TextLayoutHitInfo(automenta.vivisect.gui.StyledString.TextLayoutHitInfo) TextLayoutInfo(automenta.vivisect.gui.StyledString.TextLayoutInfo)

Aggregations

TextLayoutHitInfo (automenta.vivisect.gui.StyledString.TextLayoutHitInfo)13 TextLayoutInfo (automenta.vivisect.gui.StyledString.TextLayoutInfo)5 Graphics2D (java.awt.Graphics2D)2 Shape (java.awt.Shape)2 TextLayout (java.awt.font.TextLayout)2