Source Code Cross Referenced for CharacterIteratorFieldDelegate.java in  » 6.0-JDK-Modules » j2me » java » text » 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 » java.text 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * @(#)CharacterIteratorFieldDelegate.java	1.6 06/10/10
003:         *
004:         * Copyright  1990-2006 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:        package java.text;
027:
028:        import java.util.ArrayList;
029:
030:        /**
031:         * CharacterIteratorFieldDelegate combines the notifications from a Format
032:         * into a resulting <code>AttributedCharacterIterator</code>. The resulting
033:         * <code>AttributedCharacterIterator</code> can be retrieved by way of
034:         * the <code>getIterator</code> method.
035:         *
036:         * @version 1.6 10/10/06
037:         */
038:        class CharacterIteratorFieldDelegate implements  Format.FieldDelegate {
039:            /**
040:             * Array of AttributeStrings. Whenever <code>formatted</code> is invoked
041:             * for a region > size, a new instance of AttributedString is added to
042:             * attributedStrings. Subsequent invocations of <code>formatted</code>
043:             * for existing regions result in invoking addAttribute on the existing
044:             * AttributedStrings.
045:             */
046:            private ArrayList attributedStrings;
047:            /**
048:             * Running count of the number of characters that have
049:             * been encountered.
050:             */
051:            private int size;
052:
053:            CharacterIteratorFieldDelegate() {
054:                attributedStrings = new ArrayList();
055:            }
056:
057:            public void formatted(Format.Field attr, Object value, int start,
058:                    int end, StringBuffer buffer) {
059:                if (start != end) {
060:                    if (start < size) {
061:                        // Adjust attributes of existing runs
062:                        int index = size;
063:                        int asIndex = attributedStrings.size() - 1;
064:
065:                        while (start < index) {
066:                            AttributedString as = (AttributedString) attributedStrings
067:                                    .get(asIndex--);
068:                            int newIndex = index - as.length();
069:                            int aStart = Math.max(0, start - newIndex);
070:
071:                            as.addAttribute(attr, value, aStart, Math.min(end
072:                                    - start, as.length() - aStart)
073:                                    + aStart);
074:                            index = newIndex;
075:                        }
076:                    }
077:                    if (size < start) {
078:                        // Pad attributes
079:                        attributedStrings.add(new AttributedString(buffer
080:                                .substring(size, start)));
081:                        size = start;
082:                    }
083:                    if (size < end) {
084:                        // Add new string
085:                        int aStart = Math.max(start, size);
086:                        AttributedString string = new AttributedString(buffer
087:                                .substring(aStart, end));
088:
089:                        string.addAttribute(attr, value);
090:                        attributedStrings.add(string);
091:                        size = end;
092:                    }
093:                }
094:            }
095:
096:            public void formatted(int fieldID, Format.Field attr, Object value,
097:                    int start, int end, StringBuffer buffer) {
098:                formatted(attr, value, start, end, buffer);
099:            }
100:
101:            /**
102:             * Returns an <code>AttributedCharacterIterator</code> that can be used
103:             * to iterate over the resulting formatted String.
104:             *
105:             * @pararm string Result of formatting.
106:             */
107:            public AttributedCharacterIterator getIterator(String string) {
108:                // Add the last AttributedCharacterIterator if necessary
109:                // assert(size <= string.length());
110:                if (string.length() > size) {
111:                    attributedStrings.add(new AttributedString(string
112:                            .substring(size)));
113:                    size = string.length();
114:                }
115:                int iCount = attributedStrings.size();
116:                AttributedCharacterIterator iterators[] = new AttributedCharacterIterator[iCount];
117:
118:                for (int counter = 0; counter < iCount; counter++) {
119:                    iterators[counter] = ((AttributedString) attributedStrings
120:                            .get(counter)).getIterator();
121:                }
122:                return new AttributedString(iterators).getIterator();
123:            }
124:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.