FileDocCategorySizeDatePackage
TextInfo.javaAPI DocphoneME MR2 API (J2ME)5821Wed May 02 18:00:20 BST 2007com.sun.midp.lcdui

TextInfo

public 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
numLines
total number of lines
public int
visLines
number of visible lines
public int
topVis
first visible line
public int
cursorLine
the line where the cursor resides
public boolean
isModified
set to true to indicate this has been modified
public boolean
scrollY
set to true if this has been scrolled in the Y direction
public boolean
scrollX
set to true if this has been scrolled in the X direction
public int[]
lineStart
starting offset of each line
public int[]
lineEnd
offset of last character of each line
public int
height
the height of the block of text described by this object
public static final int
BACK
scroll up
public static final int
FORWARD
scroll down
Constructors Summary
public TextInfo(int size)
Construct a new TextInfo object with size lines initially

param
size maximum number of lines this TextInfo struct can store without expanding


                                         
       
	isModified = true;
	scrollY = true;
	scrollX = true;
	lineStart = new int[size];
	lineEnd = new int[size];
    
Methods Summary
public voidexpand()
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 intgetScrollPosition()
Returns scroll position from 0-100

return
scroll position mapped to the range 0-100

        // used to set scroll indicator visibility
        if (numLines == 0 || numLines <= visLines) {
            return 0;
        } else {
            return (topVis * 100) / (numLines - visLines);
        }
    
public intgetScrollProportion()
Returns scroll proportion from 0-100

return
scroll proportion, as a percentage of the screen that is viewable.

        // used to set scroll indicator visibility
        if (visLines >= numLines || numLines == 0) {
            return 100;
        } else {
            return (visLines * 100) / numLines;
        }
    
public booleanscroll(int dir)
Scroll Up or down by one line if possible

param
dir direction of scroll, FORWARD or BACK
return
true if scrolling happened, false if not

        return scroll(dir, 1);
    
public booleanscroll(int dir, int length)
Scroll Up or down by one line if possible

param
dir direction of scroll, FORWARD or BACK
param
length how many lines to scroll
return
true if scrolling happened, false if not

	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 intscrollByPage(int dir)
Scroll Up or down by page if possible

param
dir direction of scroll, FORWARD or BACK
return
number of scrolled lines

	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;