Source Code Cross Referenced for TextOffset.java in  » Internationalization-Localization » icu4j » com » ibm » richtext » textformat » 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 » Internationalization Localization » icu4j » com.ibm.richtext.textformat 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * (C) Copyright IBM Corp. 1998-2004.  All Rights Reserved.
003:         *
004:         * The program is provided "as is" without any warranty express or
005:         * implied, including the warranty of non-infringement and the implied
006:         * warranties of merchantibility and fitness for a particular purpose.
007:         * IBM will not be liable for any damages suffered by you as a result
008:         * of using the Program. In no event will IBM be liable for any
009:         * special, indirect or consequential damages or lost profits even if
010:         * IBM has been advised of the possibility of their occurrence. IBM
011:         * will not be liable for any third party claims against you.
012:         */
013:        // Revision: 03 1.16 richtext/TextOffset.java, richtext, richtext
014:        /*
015:         9/5/96 {jbr} added set and equals methods
016:         */
017:
018:        package com.ibm.richtext.textformat;
019:
020:        /**
021:         * A TextOffset indicates both an integer offset into text and a placement
022:         * on one of the characters adjacent to the offset.  An offset is a
023:         * position between two characters;  offset n
024:         * is between character n-1 and character n.  The placement specifies whether
025:         * it is associated with the character
026:         * after the offset
027:         * (character n) or the character before the offset (character n-1).
028:         * <p>
029:         * Knowing which character the TextOffset is associated with is necessary
030:         * when displaying carets.  In bidirectional text, a single offset may
031:         * have two distinct carets.  Also, in multiline text, an offset at a line
032:         * break has a possible caret on each line.
033:         * <p>
034:         * Most clients will not be interested in the placement, and will just use
035:         * the offset.
036:         */
037:        public final class TextOffset {
038:            static final String COPYRIGHT = "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
039:            /**
040:             * Indicates that the TextOffset is associated with character
041:             * <code>fOffset - 1</code> - ie the character before its offset.
042:             */
043:            public final static boolean BEFORE_OFFSET = true;
044:
045:            /**
046:             * Indicates that the TextOffset is associated with character
047:             * <code>fOffset</code> - ie the character after its offset.
048:             */
049:            public final static boolean AFTER_OFFSET = false;
050:
051:            /**
052:             * The offset into the text.
053:             */
054:            public int fOffset = 0;
055:
056:            /**
057:             * The placement - before or after.
058:             */
059:            public boolean fPlacement = AFTER_OFFSET;
060:
061:            /**
062:             * Constructs a new TextOffset
063:             * @param offset the offset into the text to represent.  Placement is implicitly AFTER_OFFSET.
064:             */
065:            public TextOffset(int offset) {
066:                if (offset < 0)
067:                    throw new IllegalArgumentException(
068:                            "Offset is negative in TextOffset constructor.");
069:
070:                fOffset = offset;
071:
072:                fPlacement = AFTER_OFFSET;
073:            }
074:
075:            /**
076:             * Constructs a new TextOffset at 0, with placement AFTER_OFFSET.
077:             */
078:            public TextOffset() {
079:                this (0);
080:            }
081:
082:            /**
083:             * Constructs a new TextOffset with the given offset and placement.
084:             * @param offset the offset into the text
085:             * @param placement indicates the position of the caret; one of BEFORE_OFFSET or AFTER_OFFSET
086:             */
087:            public TextOffset(int offset, boolean placement) {
088:                if (offset < 0)
089:                    throw new IllegalArgumentException(
090:                            "TextOffset constructor offset < 0: " + offset);
091:
092:                fOffset = offset;
093:                fPlacement = placement;
094:            }
095:
096:            /**
097:             * Constructs a new TextOffset from an existing one.
098:             * @param rhs the TextOffset to copy
099:             */
100:            public TextOffset(TextOffset rhs) {
101:
102:                this (rhs.fOffset, rhs.fPlacement);
103:            }
104:
105:            /**
106:             * Set the value of the TextOffset
107:             * @param offset the offset into the text
108:             * @param placement indicates the position of the caret; one of BEFORE_OFFSET or AFTER_OFFSET
109:             */
110:            public void setOffset(int offset, boolean placement) {
111:                if (offset < 0)
112:                    throw new IllegalArgumentException(
113:                            "TextOffset setOffset offset < 0: " + offset);
114:
115:                fOffset = offset;
116:                fPlacement = placement;
117:            }
118:
119:            /**
120:             * Compare this to another Object.
121:             */
122:            public boolean equals(Object other) {
123:
124:                try {
125:                    return equals((TextOffset) other);
126:                } catch (ClassCastException e) {
127:                    return false;
128:                }
129:            }
130:
131:            /**
132:             * Return true if offset and placement are the same.
133:             *
134:             * @param other offset to compare against
135:             * @return true if both offsets are equal
136:             */
137:            public boolean equals(TextOffset other) {
138:
139:                return fOffset == other.fOffset
140:                        && fPlacement == other.fPlacement;
141:            }
142:
143:            /**
144:             * Return the hashCode for this object.
145:             */
146:            public int hashCode() {
147:
148:                return fPlacement == AFTER_OFFSET ? fOffset : -fOffset;
149:            }
150:
151:            /**
152:             * Return true if this offset is 'greaterThan' other.  If the fOffset fields are equal, the
153:             * placement field is considered, and AFTER_OFFSET is considered 'greaterThan' BEFORE_OFFSET.
154:             *
155:             * @param other the other offset
156:             * @return true if this offset appears after other
157:             */
158:            public boolean greaterThan(TextOffset other) {
159:                return fOffset > other.fOffset
160:                        || (fOffset == other.fOffset
161:                                && fPlacement == AFTER_OFFSET && other.fPlacement == BEFORE_OFFSET);
162:            }
163:
164:            /**
165:             * Return true if this offset is 'lessThan' other.  If the fOffset fields are equal, the
166:             * placement field is considered, and BEFORE_OFFSET is considered 'lessThan' AFTER_OFFSET.
167:             *
168:             * @param other the other offset
169:             * @return true if this offset appears before other
170:             */
171:            public boolean lessThan(TextOffset other) {
172:
173:                return fOffset < other.fOffset
174:                        || (fOffset == other.fOffset
175:                                && fPlacement == BEFORE_OFFSET && other.fPlacement == AFTER_OFFSET);
176:            }
177:
178:            /**
179:             * Copy the value of another TextOffset into this
180:             * @param other the TextOffset to copy
181:             */
182:            public void assign(TextOffset other) {
183:                fOffset = other.fOffset;
184:                fPlacement = other.fPlacement;
185:            }
186:
187:            /**
188:             * Return a string representation of this object.
189:             */
190:            public String toString() {
191:
192:                return "[" + (fPlacement ? "before " : "after ") + fOffset
193:                        + "]";
194:            }
195:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.