Source Code Cross Referenced for StyleSheet_Large_Test.java in  » Apache-Harmony-Java-SE » javax-package » javax » swing » text » html » 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 » Apache Harmony Java SE » javax package » javax.swing.text.html 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:        /**
018:         * @author Alexey A. Ivanov
019:         * @version $Revision$
020:         */package javax.swing.text.html;
021:
022:        import java.util.Enumeration;
023:
024:        import javax.swing.BasicSwingTestCase;
025:        import javax.swing.text.AttributeSet;
026:        import javax.swing.text.MutableAttributeSet;
027:        import javax.swing.text.SimpleAttributeSet;
028:        import javax.swing.text.StyleConstants;
029:        import javax.swing.text.html.CSS.Attribute;
030:
031:        /**
032:         * Tests <code>MutableAttributeSet</code> returned by
033:         * <code>StyleSheet.addAttribute</code> method. The returned attribute set
034:         * contains <code>CSS.Attribute</code>. It converts the value to
035:         * <code>StyleConstants</code> when a <code>StyleConstants</code> attribute
036:         * is requested.
037:         * <p>
038:         * The attribute used for testing is <code>StyleConstants.Italic</code>.
039:         * It corresponds to <code>Attribute.FONT_STYLE</code>.
040:         *
041:         * @see StyleSheet
042:         * @see StyleSheet#addAttribute(Object, Object)
043:         * @see StyleSheet#createLargeAttributeSet(AttributeSet)
044:         * @see CSS.Attribute
045:         * @see javax.swing.text.StyleContext.SmallAttributeSet
046:         */
047:        public class StyleSheet_Large_Test extends BasicSwingTestCase {
048:            private static final Object scAttribute = StyleConstants.Italic;
049:            private static final Object scValue = Boolean.TRUE;
050:            private static final Object cssAttribute = Attribute.FONT_STYLE;
051:
052:            private StyleSheet ss;
053:            private AttributeSet empty;
054:            private AttributeSet attr;
055:            private MutableAttributeSet mutable;
056:            private int count;
057:
058:            protected void setUp() throws Exception {
059:                super .setUp();
060:                ss = new StyleSheet();
061:                empty = ss.getEmptySet();
062:                attr = empty;
063:
064:                int no = 0;
065:                while (!(attr instanceof  MutableAttributeSet)) {
066:                    String number = String.valueOf(no++);
067:                    attr = ss.addAttribute(attr, "key" + number, "value"
068:                            + number);
069:                }
070:                attr = ss.addAttribute(attr, scAttribute, scValue);
071:                assertTrue(attr instanceof  MutableAttributeSet);
072:                count = no + 1;
073:
074:                mutable = (MutableAttributeSet) attr;
075:            }
076:
077:            public void testGetAttribute() throws Exception {
078:                Object value = attr.getAttribute(cssAttribute);
079:                assertNotSame(Boolean.class, value.getClass());
080:                assertNotSame(String.class, value.getClass());
081:                assertEquals("italic", value.toString());
082:
083:                value = attr.getAttribute(scAttribute);
084:                assertSame(Boolean.class, value.getClass());
085:                assertTrue(((Boolean) value).booleanValue());
086:                assertSame(scValue, value);
087:            }
088:
089:            public void testIsDefined() throws Exception {
090:                assertTrue(attr.isDefined(scAttribute));
091:                assertTrue(attr.isDefined(cssAttribute));
092:            }
093:
094:            public void testGetNames() throws Exception {
095:                final Enumeration keys = attr.getAttributeNames();
096:                int stringKeyCount = 0;
097:                int nonStringKeyCount = 0;
098:                while (keys.hasMoreElements()) {
099:                    Object key = keys.nextElement();
100:                    if (key instanceof  String) {
101:                        stringKeyCount++;
102:                    } else {
103:                        nonStringKeyCount++;
104:                        assertSame(cssAttribute, key);
105:                    }
106:                }
107:
108:                assertEquals(count - 1, stringKeyCount);
109:                assertEquals(1, nonStringKeyCount);
110:            }
111:
112:            public void testGetAttributeCount() throws Exception {
113:                assertEquals(count, attr.getAttributeCount());
114:            }
115:
116:            public void testIsEqualSame() throws Exception {
117:                assertTrue(attr.isEqual(attr));
118:
119:                final MutableAttributeSet simple = new SimpleAttributeSet(attr);
120:                assertTrue(attr.isEqual(simple));
121:                assertTrue(simple.isEqual(attr));
122:            }
123:
124:            public void testIsEqualAnother() throws Exception {
125:                final MutableAttributeSet simple = new SimpleAttributeSet();
126:                fillAttributeSet(simple);
127:
128:                if (isHarmony()) {
129:                    assertTrue(simple.isEqual(attr));
130:                    assertFalse(attr.isEqual(simple));
131:                } else {
132:                    assertFalse(simple.isEqual(attr));
133:                    assertTrue(attr.isEqual(simple));
134:                }
135:            }
136:
137:            public void testCopyAttributes() throws Exception {
138:                final AttributeSet copy = attr.copyAttributes();
139:                assertNotSame(attr, copy);
140:                assertTrue(attr.isEqual(copy));
141:                assertTrue(copy.isEqual(attr));
142:                assertTrue(copy instanceof  MutableAttributeSet);
143:            }
144:
145:            public void testContainsAttribute() throws Exception {
146:                assertTrue(attr.containsAttribute(cssAttribute, attr
147:                        .getAttribute(cssAttribute)));
148:                assertTrue(attr.containsAttribute(scAttribute, scValue));
149:            }
150:
151:            public void testContainsAttributeAnother() throws Exception {
152:                final AttributeSet another = ss.addAttribute(empty,
153:                        scAttribute, scValue);
154:
155:                assertEquals(attr.getAttribute(cssAttribute).toString(),
156:                        another.getAttribute(cssAttribute).toString());
157:                if (isHarmony()) {
158:                    assertTrue(attr.containsAttribute(cssAttribute, another
159:                            .getAttribute(cssAttribute)));
160:                } else {
161:                    assertFalse(attr.containsAttribute(cssAttribute, another
162:                            .getAttribute(cssAttribute)));
163:                }
164:            }
165:
166:            public void testContainsAttributesSame() throws Exception {
167:                assertTrue(attr.containsAttributes(attr));
168:
169:                final MutableAttributeSet simple = new SimpleAttributeSet(attr);
170:
171:                assertTrue(attr.containsAttributes(simple));
172:                assertTrue(simple.containsAttributes(attr));
173:            }
174:
175:            public void testContainsAttributesMutable() throws Exception {
176:                final MutableAttributeSet simple = new SimpleAttributeSet();
177:                simple.addAttribute(scAttribute, scValue);
178:
179:                assertTrue(attr.containsAttributes(simple));
180:                assertFalse(simple.containsAttributes(attr));
181:            }
182:
183:            public void testContainsAttributesSmall() throws Exception {
184:                final AttributeSet another = ss.addAttribute(empty,
185:                        scAttribute, scValue);
186:
187:                if (isHarmony()) {
188:                    assertSame(attr.getAttribute(Attribute.FONT_STYLE), another
189:                            .getAttribute(Attribute.FONT_STYLE));
190:                    assertTrue(attr.containsAttributes(another));
191:                    assertFalse(another.containsAttributes(attr));
192:                } else {
193:                    assertNotSame(attr.getAttribute(Attribute.FONT_STYLE),
194:                            another.getAttribute(Attribute.FONT_STYLE));
195:                    assertFalse(attr.containsAttributes(another));
196:                    assertFalse(another.containsAttributes(attr));
197:                }
198:            }
199:
200:            public void testAddAttribute() throws Exception {
201:                mutable.addAttribute(StyleConstants.Bold, Boolean.TRUE);
202:                assertEquals(count + 1, mutable.getAttributeCount());
203:                assertItalicButNotBold();
204:            }
205:
206:            public void testAddAttributes() throws Exception {
207:                MutableAttributeSet simple = new SimpleAttributeSet();
208:                simple.addAttribute(StyleConstants.Bold, Boolean.TRUE);
209:
210:                mutable.addAttributes(simple);
211:                assertEquals(count + 1, mutable.getAttributeCount());
212:                assertItalicButNotBold();
213:            }
214:
215:            public void testRemoveAttribute() throws Exception {
216:                mutable.removeAttribute(scAttribute);
217:                assertEquals(count, mutable.getAttributeCount()); // Didn't change
218:
219:                mutable.removeAttribute(cssAttribute);
220:                assertEquals(count - 1, mutable.getAttributeCount());
221:            }
222:
223:            public void testRemoveAttributesEnumeration() throws Exception {
224:                mutable.removeAttributes(new Enumeration() {
225:                    private int returnedCount = 0;
226:
227:                    public boolean hasMoreElements() {
228:                        return returnedCount == 0;
229:                    }
230:
231:                    public Object nextElement() {
232:                        return returnedCount++ == 0 ? scAttribute : null;
233:                    }
234:                });
235:                assertEquals(count, mutable.getAttributeCount()); // Didn't change
236:
237:                mutable.removeAttributes(new Enumeration() {
238:                    private int returnedCount = 0;
239:
240:                    public boolean hasMoreElements() {
241:                        return returnedCount == 0;
242:                    }
243:
244:                    public Object nextElement() {
245:                        return returnedCount++ == 0 ? cssAttribute : null;
246:                    }
247:                });
248:                assertEquals(count - 1, mutable.getAttributeCount());
249:            }
250:
251:            public void testRemoveAttributesAttributeSet() throws Exception {
252:                final MutableAttributeSet sc = new SimpleAttributeSet();
253:                sc.addAttribute(scAttribute, scValue);
254:
255:                mutable.removeAttributes(sc);
256:                assertEquals(count, mutable.getAttributeCount()); // Didn't change
257:
258:                final MutableAttributeSet css = new SimpleAttributeSet();
259:                css.addAttribute(cssAttribute, mutable
260:                        .getAttribute(cssAttribute));
261:                mutable.removeAttributes(css);
262:                assertEquals(count - 1, mutable.getAttributeCount());
263:            }
264:
265:            private void fillAttributeSet(final MutableAttributeSet simple) {
266:                for (int i = 0; i < count - 1; i++) {
267:                    simple.addAttribute("key" + i, "value" + i);
268:                }
269:                simple.addAttribute(scAttribute, scValue);
270:            }
271:
272:            private void assertItalicButNotBold() {
273:                final Enumeration keys = attr.getAttributeNames();
274:                int stringKeyCount = 0;
275:                int nonStringKeyCount = 0;
276:                boolean cssItalic = false;
277:                boolean cssBold = false;
278:                boolean scBold = false;
279:                while (keys.hasMoreElements()) {
280:                    Object key = keys.nextElement();
281:                    if (key instanceof  String) {
282:                        stringKeyCount++;
283:                    } else {
284:                        nonStringKeyCount++;
285:                        cssItalic |= cssAttribute == key;
286:                        cssBold |= Attribute.FONT_WEIGHT == key;
287:                        scBold |= StyleConstants.Bold == key;
288:                    }
289:                }
290:
291:                assertEquals(count - 1, stringKeyCount);
292:                assertEquals(2, nonStringKeyCount);
293:                assertTrue(cssItalic);
294:                assertFalse(cssBold); // No convertion is performed when used
295:                assertTrue(scBold); // as mutable set
296:            }
297:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.