Source Code Cross Referenced for TextInfo.java in  » 6.0-JDK-Modules » j2me » com » sun » midp » lcdui » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » j2me » com.sun.midp.lcdui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *   
003:         *
004:         * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006:         * 
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License version
009:         * 2 only, as published by the Free Software Foundation.
010:         * 
011:         * This program is distributed in the hope that it will be useful, but
012:         * WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014:         * General Public License version 2 for more details (a copy is
015:         * included at /legal/license.txt).
016:         * 
017:         * You should have received a copy of the GNU General Public License
018:         * version 2 along with this work; if not, write to the Free Software
019:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA
021:         * 
022:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023:         * Clara, CA 95054 or visit www.sun.com if you need additional
024:         * information or have any questions.
025:         */
026:
027:        package com.sun.midp.lcdui;
028:
029:        /**
030:         * Class that represents the line-wrapping and scroll position of 
031:         * text in a TextBox (editable) or Label, StringItem, or ListItem(uneditable)
032:         *
033:         * From this structure, <code>Text.paintText()</code> should be able to 
034:         * quickly render wrapped text 
035:         */
036:        public class TextInfo {
037:
038:            /** total number of lines */
039:            public int numLines;
040:
041:            /** number of visible lines */
042:            public int visLines;
043:
044:            /** first visible line */
045:            public int topVis;
046:
047:            /** the line where the cursor resides */
048:            public int cursorLine;
049:
050:            /** set to true to indicate this has been modified */
051:            public boolean isModified;
052:
053:            /** set to true if this has been scrolled in the Y direction */
054:            public boolean scrollY;
055:
056:            /** set to true if this has been scrolled in the X direction */
057:            public boolean scrollX;
058:
059:            /** starting offset of each line */
060:            public int[] lineStart;
061:
062:            /** offset of last character of each line */
063:            public int[] lineEnd;
064:
065:            /** the height of the block of text described by this object */
066:            public int height;
067:
068:            /** scroll up */
069:            public final static int BACK = 1;
070:
071:            /** scroll down */
072:            public final static int FORWARD = 2;
073:
074:            /**
075:             * Construct a new TextInfo object with <code>size</code> 
076:             * lines initially
077:             * 
078:             * @param size maximum number of lines this TextInfo
079:             *        struct can store without expanding 
080:             */
081:            public TextInfo(int size) {
082:                isModified = true;
083:                scrollY = true;
084:                scrollX = true;
085:                lineStart = new int[size];
086:                lineEnd = new int[size];
087:            }
088:
089:            /**
090:             * Expand the capacity of this TextInfo structure by doubling the
091:             * length of the lineStart and lineEnd arrays
092:             */
093:            public void expand() {
094:                int[] tmpStart = new int[lineStart.length * 2];
095:                int[] tmpEnd = new int[tmpStart.length];
096:
097:                System.arraycopy(lineStart, 0, tmpStart, 0, lineStart.length);
098:                System.arraycopy(lineEnd, 0, tmpEnd, 0, lineEnd.length);
099:
100:                lineStart = tmpStart;
101:                lineEnd = tmpEnd;
102:            }
103:
104:            /**
105:             * Scroll Up or down by one line if possible
106:             *
107:             * @param dir direction of scroll, FORWARD or BACK
108:             * @return true if scrolling happened, false if not
109:             */
110:            public boolean scroll(int dir) {
111:                return scroll(dir, 1);
112:            }
113:
114:            /**
115:             * Scroll Up or down by one line if possible
116:             *
117:             * @param dir direction of scroll, FORWARD or BACK
118:             * @param length how many lines to scroll    
119:             * @return true if scrolling happened, false if not
120:             */
121:            public boolean scroll(int dir, int length) {
122:                boolean rv = false;
123:
124:                if (visLines < numLines) {
125:                    switch (dir) {
126:                    case FORWARD:
127:                        if (topVis + visLines < numLines) {
128:                            topVis += length;
129:                            if (topVis + visLines > numLines) {
130:                                topVis = numLines - visLines;
131:                            }
132:                            rv = true;
133:                        }
134:                        break;
135:                    case BACK:
136:                        if (topVis > 0) {
137:                            topVis -= length;
138:                            if (topVis < 0) {
139:                                topVis = 0;
140:                            }
141:                            rv = true;
142:                        }
143:                        break;
144:                    default:
145:                        // no-op
146:                    }
147:                }
148:                scrollY |= rv;
149:                return rv;
150:            }
151:
152:            /**
153:             * Scroll Up or down by page if possible
154:             *
155:             * @param dir direction of scroll, FORWARD or BACK
156:             * @return number of scrolled lines
157:             */
158:            public int scrollByPage(int dir) {
159:                int oldTopVis = topVis;
160:
161:                if (visLines < numLines) {
162:                    switch (dir) {
163:                    case FORWARD:
164:                        if ((topVis + visLines) < numLines) {
165:                            topVis = numLines - (topVis + visLines - 1) < visLines ? numLines
166:                                    - visLines
167:                                    : topVis + visLines - 1;
168:                        }
169:                        break;
170:                    case BACK:
171:                        if (topVis > 0) {
172:                            topVis = (topVis - visLines + 1) < 0 ? 0 : topVis
173:                                    - visLines + 1;
174:                        }
175:                        break;
176:                    default:
177:                        // no-op
178:                    }
179:                }
180:                scrollY |= (topVis != oldTopVis);
181:                return topVis - oldTopVis;
182:            }
183:
184:            /**
185:             * Returns scroll position from 0-100
186:             * @return scroll position mapped to the range 0-100
187:             */
188:            public int getScrollPosition() {
189:                // used to set scroll indicator visibility
190:                if (numLines == 0 || numLines <= visLines) {
191:                    return 0;
192:                } else {
193:                    return (topVis * 100) / (numLines - visLines);
194:                }
195:            }
196:
197:            /**
198:             * Returns scroll proportion from 0-100
199:             * @return scroll proportion, as a percentage of the screen that
200:             *         is viewable.
201:             */
202:            public int getScrollProportion() {
203:                // used to set scroll indicator visibility
204:                if (visLines >= numLines || numLines == 0) {
205:                    return 100;
206:                } else {
207:                    return (visLines * 100) / numLines;
208:                }
209:            }
210:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.