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;
}
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;
}
}
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();
}
Aggregations