use of automenta.vivisect.gui.StyledString.TextLayoutInfo in project opennars by opennars.
the class GTextArea method getTextLength.
/**
* Get the length of text on a particular line in the text area. <br>
* The line does not need to be visible and the line numbers
* always start at 0. <br>
* The result is not dependent on what is visible at any
* particular time but on the overall position in text area
* control. <br>
* If ignoreEOL is true then EOL characters are not included in the count.
*
* @param lineNo the text area line number we want
* @param ignoreEOL if true do not include trailing end=of-line characters
* @return the length of the line, or <) if the line number is invalid
*/
public int getTextLength(int lineNo, boolean ignoreEOL) {
Graphics2D g2d = buffer.g2;
// Get the latest lines of text
LinkedList<TextLayoutInfo> lines = stext.getLines(g2d);
if (lineNo < 0 || lineNo >= lines.size())
return -1;
TextLayoutInfo tli = lines.get(lineNo);
// String s = stext.getPlainText(tli.startCharIndex, tli.startCharIndex + tli.nbrChars);
String s = stext.getPlainText();
int len = tli.nbrChars;
if (ignoreEOL) {
// Strip off trailing EOL
int p = tli.startCharIndex + tli.nbrChars - 1;
while (p > tli.startCharIndex && s.charAt(p) == EOL) {
p--;
len--;
}
}
return len;
}
use of automenta.vivisect.gui.StyledString.TextLayoutInfo in project opennars by opennars.
the class GTextArea method getText.
/**
* Get the text on a particular line in the text area. <br>
* The line does not need to be visible and the line numbers
* always start at 0. <br>
* The result is not dependent on what is visible at any
* particular time but on the overall position in text area
* control. <br>
* If the line number is invalid then an empty string is returned. <br>
* Trailing EOL characters are removed.
*
* @param lineNo the text area line number we want
* @return the plain text in a display line
*/
public String getText(int lineNo) {
Graphics2D g2d = buffer.g2;
// Get the latest lines of text
LinkedList<TextLayoutInfo> lines = stext.getLines(g2d);
if (lineNo < 0 || lineNo >= lines.size())
return "";
TextLayoutInfo tli = lines.get(lineNo);
String s = stext.getPlainText(tli.startCharIndex, tli.startCharIndex + tli.nbrChars);
// Strip off trailing EOL
int p = s.length() - 1;
while (p > 0 && s.charAt(p) == EOL) p--;
return (p == s.length() - 1) ? s : s.substring(0, p + 1);
}
use of automenta.vivisect.gui.StyledString.TextLayoutInfo in project opennars by opennars.
the class GEditableTextControl 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);
calculateCaretPos(endTLHI);
bufferInvalid = true;
}
keepCursorInView = true;
takeFocus();
}
use of automenta.vivisect.gui.StyledString.TextLayoutInfo in project opennars by opennars.
the class GPassword method changeText.
protected boolean changeText() {
TextLayoutInfo tli;
TextHitInfo thi = null, thiRight = null;
pos += adjust;
// Force layouts to be updated
stext.getLines(buffer.g2);
// Try to get text layout info for the current position
tli = stext.getTLIforCharNo(pos);
if (tli == null) {
// If unable to get a layout for pos then reset everything
endTLHI = null;
startTLHI = null;
ptx = pty = 0;
caretX = caretY = 0;
return false;
}
// We have a text layout so we can do something
// First find the position in line
int posInLine = pos - tli.startCharIndex;
// Get some hit info so we can see what is happening
try {
thiRight = tli.layout.getNextRightHit(posInLine);
} catch (Exception excp) {
thiRight = null;
}
if (posInLine <= 0) {
// At start of line
thi = tli.layout.getNextLeftHit(thiRight);
} else if (posInLine >= tli.nbrChars) {
// End of line
thi = tli.layout.getNextRightHit(tli.nbrChars - 1);
} else {
// Character in line;
thi = tli.layout.getNextLeftHit(thiRight);
}
endTLHI.setInfo(tli, thi);
// Cursor at end of paragraph graphic
calculateCaretPos(endTLHI);
bufferInvalid = true;
startTLHI.copyFrom(endTLHI);
return true;
}
use of automenta.vivisect.gui.StyledString.TextLayoutInfo 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