TextInfopublic class TextInfo extends Object Class that represents the line-wrapping and scroll position of
text in a TextBox (editable) or Label, StringItem, or ListItem(uneditable)
From this structure, Text.paintText() should be able to
quickly render wrapped text |
Fields Summary |
---|
public int | numLinestotal number of lines | public int | visLinesnumber of visible lines | public int | topVisfirst visible line | public int | cursorLinethe line where the cursor resides | public boolean | isModifiedset to true to indicate this has been modified | public boolean | scrollYset to true if this has been scrolled in the Y direction | public boolean | scrollXset to true if this has been scrolled in the X direction | public int[] | lineStartstarting offset of each line | public int[] | lineEndoffset of last character of each line | public int | heightthe height of the block of text described by this object | public static final int | BACKscroll up | public static final int | FORWARDscroll down |
Constructors Summary |
---|
public TextInfo(int size)Construct a new TextInfo object with size
lines initially
isModified = true;
scrollY = true;
scrollX = true;
lineStart = new int[size];
lineEnd = new int[size];
|
Methods Summary |
---|
public void | expand()Expand the capacity of this TextInfo structure by doubling the
length of the lineStart and lineEnd arrays
int[] tmpStart = new int [lineStart.length * 2];
int[] tmpEnd = new int [tmpStart.length];
System.arraycopy(lineStart, 0, tmpStart, 0,
lineStart.length);
System.arraycopy(lineEnd, 0, tmpEnd, 0,
lineEnd.length);
lineStart = tmpStart;
lineEnd = tmpEnd;
| public int | getScrollPosition()Returns scroll position from 0-100
// used to set scroll indicator visibility
if (numLines == 0 || numLines <= visLines) {
return 0;
} else {
return (topVis * 100) / (numLines - visLines);
}
| public int | getScrollProportion()Returns scroll proportion from 0-100
// used to set scroll indicator visibility
if (visLines >= numLines || numLines == 0) {
return 100;
} else {
return (visLines * 100) / numLines;
}
| public boolean | scroll(int dir)Scroll Up or down by one line if possible
return scroll(dir, 1);
| public boolean | scroll(int dir, int length)Scroll Up or down by one line if possible
boolean rv = false;
if (visLines < numLines) {
switch (dir) {
case FORWARD:
if (topVis + visLines < numLines) {
topVis += length;
if (topVis + visLines > numLines) {
topVis = numLines - visLines;
}
rv = true;
}
break;
case BACK:
if (topVis > 0) {
topVis -= length;
if (topVis < 0) {
topVis = 0;
}
rv = true;
}
break;
default:
// no-op
}
}
scrollY |= rv;
return rv;
| public int | scrollByPage(int dir)Scroll Up or down by page if possible
int oldTopVis = topVis;
if (visLines < numLines) {
switch (dir) {
case FORWARD:
if ((topVis + visLines) < numLines) {
topVis = numLines - (topVis + visLines - 1) < visLines ?
numLines - visLines : topVis + visLines - 1;
}
break;
case BACK:
if (topVis > 0) {
topVis = (topVis - visLines + 1) < 0 ?
0 : topVis - visLines + 1;
}
break;
default:
// no-op
}
}
scrollY |= (topVis != oldTopVis);
return topVis - oldTopVis;
|
|