New line detection mechanics described before can be easily used in class implementation to perform first text formatting, and prepare new version of String containing text – one with new line indicators (“|”) placed at end of each displayed line. But to make really flexible tool for text management some kind of indexed array of lines should be prepared to allow user determine order and manner in which each line is shown.
Having parsed String containing text with added new line indicators in proper places an array like that can be easily constructed. Another loop on all characters is needed, and this time when application meets new line indicator it should create new instance of String – a line, starting where the previous line ended. This String can be added than to a Vector collection object, which will keep all lines nicely indexed and in order. Having such a Vector representation of all lines in texts allows implementation of scrolling mechanism.
Its main idea is simple – determine how many lines can be displayed in a text box at one time, check whether given text is too long, if it is, scrolling will be needed. Display first n lines that can fit into text area, and set currentStartLine indicator to point at first line. If navigation button action is detected (for example DOWN), increment currentStartLine indicator and display lines from currentStartLine indicator to currentStartLine indicator + n.
Thursday, 20 November 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment