Source Code Cross Referenced for StyledEditorKitTest.java in  » Apache-Harmony-Java-SE » javax-package » javax » swing » 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 » Apache Harmony Java SE » javax package » javax.swing.text 
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 Evgeniya G. Maenkova
019:         * @version $Revision$
020:         */package javax.swing.text;
021:
022:        import java.util.Enumeration;
023:
024:        import javax.swing.Action;
025:        import javax.swing.JEditorPane;
026:        import javax.swing.SwingTestCase;
027:        import javax.swing.event.ChangeListener;
028:
029:        public class StyledEditorKitTest extends SwingTestCase {
030:            StyledEditorKit kit;
031:
032:            class SimpleElement implements  Element {
033:                String name;
034:
035:                AttributeSet set = new SimpleAttributeSet();
036:
037:                public SimpleElement(final String s) {
038:                    name = s;
039:                }
040:
041:                public AttributeSet getAttributes() {
042:                    return set;
043:                }
044:
045:                public Document getDocument() {
046:                    return new PlainDocument();
047:                }
048:
049:                public Element getElement(final int arg0) {
050:                    return null;
051:                }
052:
053:                public int getElementCount() {
054:                    return 0;
055:                }
056:
057:                public int getElementIndex(final int arg0) {
058:                    return 0;
059:                }
060:
061:                public int getEndOffset() {
062:                    return 0;
063:                }
064:
065:                public String getName() {
066:                    return name;
067:                }
068:
069:                public Element getParentElement() {
070:                    return null;
071:                }
072:
073:                public int getStartOffset() {
074:                    return 0;
075:                }
076:
077:                public boolean isLeaf() {
078:                    return false;
079:                }
080:
081:                final void setAttributeSet(final AttributeSet as) {
082:                    set = as;
083:                }
084:            }
085:
086:            @Override
087:            protected void setUp() throws Exception {
088:                super .setUp();
089:                setIgnoreNotImplemented(true);
090:                kit = new StyledEditorKit();
091:            }
092:
093:            @Override
094:            protected void tearDown() throws Exception {
095:                super .tearDown();
096:            }
097:
098:            public void testStyledEditorKit() {
099:            }
100:
101:            public void testClone() {
102:                Object kit1 = kit.clone();
103:                assertNotSame(kit1, kit);
104:                assertTrue(kit1 instanceof  StyledEditorKit);
105:            }
106:
107:            public void testGetActions() {
108:                Action[] actions = kit.getActions();
109:                Action[] super Actions = new DefaultEditorKit().getActions();
110:                Action[] newActions = new Action[] {
111:                        new StyledEditorKit.FontSizeAction("font-size-48", 48),
112:                        new StyledEditorKit.FontSizeAction("font-size-36", 36),
113:                        new StyledEditorKit.FontSizeAction("font-size-24", 24),
114:                        new StyledEditorKit.FontSizeAction("font-size-18", 18),
115:                        new StyledEditorKit.FontSizeAction("font-size-16", 16),
116:                        new StyledEditorKit.FontSizeAction("font-size-14", 14),
117:                        new StyledEditorKit.FontSizeAction("font-size-12", 12),
118:                        new StyledEditorKit.FontSizeAction("font-size-10", 10),
119:                        new StyledEditorKit.FontSizeAction("font-size-8", 8),
120:                        new StyledEditorKit.FontFamilyAction(
121:                                "font-family-SansSerif", "SansSerif"),
122:                        new StyledEditorKit.FontFamilyAction(
123:                                "font-family-Serif", "Serif"),
124:                        new StyledEditorKit.FontFamilyAction(
125:                                "font-family-Monospaced", "Monospaced"),
126:                        new StyledEditorKit.BoldAction(),
127:                        new StyledEditorKit.UnderlineAction(),
128:                        new StyledEditorKit.ItalicAction(),
129:                        new StyledEditorKit.AlignmentAction("right-justify",
130:                                StyleConstants.ALIGN_RIGHT),
131:                        new StyledEditorKit.AlignmentAction("left-justify",
132:                                StyleConstants.ALIGN_LEFT),
133:                        new StyledEditorKit.AlignmentAction("center-justify",
134:                                StyleConstants.ALIGN_CENTER)
135:                //,
136:                //new StyledEditorKit.StyledInsertBreakAction("insert-break")
137:                };
138:                //There are some problems
139:                //1) no Foreground action in StyledEditorKit.getActions
140:                //2) DefaultEditorKit.InsertBreakAction is replaced by
141:                // StyledEditorKit.StyledInsertBreakAction
142:                for (int i = 0; i < super Actions.length; i++) {
143:                    boolean was = false;
144:                    if (super Actions[i]
145:                            .getClass()
146:                            .getName()
147:                            .equals(
148:                                    "javax.swing.text.DefaultEditorKit$InsertBreakAction")) {
149:                        continue;
150:                    }
151:                    for (int j = 0; j < actions.length; j++) {
152:                        if (super Actions[i] == actions[j]) {
153:                            was = true;
154:                            break;
155:                        }
156:                    }
157:                    assertTrue("action missed: " + super Actions[i], was);
158:                }
159:                for (int i = 0; i < newActions.length; i++) {
160:                    boolean was = false;
161:                    for (int j = 0; j < actions.length; j++) {
162:                        if (newActions[i].getClass().getName().equals(
163:                                actions[j].getClass().getName())
164:                                && newActions[i].getValue(Action.NAME).equals(
165:                                        actions[j].getValue(Action.NAME))) {
166:                            was = true;
167:                            break;
168:                        }
169:                    }
170:                    assertTrue("action missed: " + super Actions[i], was);
171:                }
172:            }
173:
174:            public void testCreateDefaultDocument() {
175:                Document doc1 = kit.createDefaultDocument();
176:                Document doc2 = kit.createDefaultDocument();
177:                String className = "javax.swing.text.DefaultStyledDocument";
178:                assertEquals(className, doc1.getClass().getName());
179:                assertEquals(className, doc2.getClass().getName());
180:                assertNotSame(doc1, doc2);
181:            }
182:
183:            final SimpleAttributeSet createAttributeSet() {
184:                SimpleAttributeSet sas = new SimpleAttributeSet();
185:                sas.addAttribute(AbstractDocument.ParagraphElementName, "p");
186:                sas.addAttribute(AbstractDocument.ContentElementName, "c");
187:                sas.addAttribute(AbstractDocument.SectionElementName, "s");
188:                sas.addAttribute(StyleConstants.ComponentElementName, "1");
189:                sas.addAttribute(StyleConstants.IconElementName, "2");
190:                sas.addAttribute(StyleConstants.IconElementName, "3");
191:                sas.addAttribute(StyleConstants.IconAttribute, "4");
192:                sas.addAttribute(AbstractDocument.ElementNameAttribute, "7");
193:                sas.addAttribute("##", "5");
194:                return sas;
195:            }
196:
197:            static final void removeObsolete(final MutableAttributeSet as) {
198:                as.removeAttribute(StyleConstants.IconAttribute);
199:                as.removeAttribute(StyleConstants.ComponentAttribute);
200:                as.removeAttribute(AbstractDocument.ElementNameAttribute);
201:            }
202:
203:            public void testCreateInputAttributes() {
204:                SimpleAttributeSet sas = createAttributeSet();
205:                SimpleElement element = new SimpleElement("");
206:                element.setAttributeSet(sas);
207:                SimpleAttributeSet set = new SimpleAttributeSet();
208:                set.addAttribute(StyleConstants.ComponentAttribute, "3");
209:                set.addAttribute(AbstractDocument.ContentElementName, "~");
210:                set.addAttribute("^^$$$", "%%%%");
211:                kit.createInputAttributes(element, set);
212:                removeObsolete(sas);
213:                assertEquals(sas, set);
214:            }
215:
216:            public void testDeinstallJEditorPane() {
217:            }
218:
219:            public void testGetCharacterAttributeRun() {
220:                SimpleAttributeSet set = createAttributeSet();
221:                JEditorPane jep = new JEditorPane();
222:                DefaultStyledDocument doc = new DefaultStyledDocument();
223:                jep.setEditorKit(kit);
224:                jep.setDocument(doc);
225:                jep.setText("ABCDEDFGHIGKLMN\n");
226:                doc.setCharacterAttributes(3, 8, set, true);
227:                int length = doc.getLength();
228:                removeObsolete(set);
229:                for (int i = 0; i < length; i++) {
230:                    jep.setCaretPosition(i);
231:                    assertEquals(getElementByOffset(doc, i), kit
232:                            .getCharacterAttributeRun());
233:                }
234:            }
235:
236:            public void testGetInputAttributes() {
237:                SimpleAttributeSet set = createAttributeSet();
238:                JEditorPane jep = new JEditorPane();
239:                DefaultStyledDocument doc = new DefaultStyledDocument();
240:                jep.setEditorKit(kit);
241:                jep.setDocument(doc);
242:                jep.setText("ABCDEDFGHIGKLMN\n");
243:                doc.setCharacterAttributes(3, 8, set, true);
244:                int length = doc.getLength();
245:                removeObsolete(set);
246:                for (int i = 0; i < length; i++) {
247:                    jep.setCaretPosition(i);
248:                    if (i > 3 && i < 12) {
249:                        assertEquals(set, kit.getInputAttributes());
250:                    } else {
251:                        assertEquals(new SimpleAttributeSet(), kit
252:                                .getInputAttributes());
253:                    }
254:                }
255:            }
256:
257:            public void testGetInputAttributesNoComponent() throws Exception {
258:                final AttributeSet as = kit.getInputAttributes();
259:                assertNotNull(as);
260:                assertEquals(0, as.getAttributeCount());
261:            }
262:
263:            static final Element getElementByOffset(final Document doc,
264:                    final int offset) {
265:                int pos = (offset == 0) ? 0 : offset - 1;
266:                Element elem = doc.getDefaultRootElement();
267:                while (elem.getElementCount() > 0) {
268:                    elem = elem.getElement(elem.getElementIndex(pos));
269:                }
270:                return elem;
271:            }
272:
273:            public void testGetViewFactory() {
274:                ViewFactory factory = kit.getViewFactory();
275:                Element element = new SimpleElement(
276:                        AbstractDocument.ContentElementName);
277:                assertEquals("javax.swing.text.LabelView", factory.create(
278:                        element).getClass().getName());
279:                element = new SimpleElement(
280:                        AbstractDocument.ParagraphElementName);
281:                assertEquals("javax.swing.text.ParagraphView", factory.create(
282:                        element).getClass().getName());
283:                element = new SimpleElement(AbstractDocument.SectionElementName);
284:                View v = factory.create(element);
285:                assertEquals("javax.swing.text.BoxView", v.getClass().getName());
286:                assertEquals(View.Y_AXIS, ((BoxView) v).getAxis());
287:                element = new SimpleElement(StyleConstants.ComponentElementName);
288:                assertEquals("javax.swing.text.ComponentView", factory.create(
289:                        element).getClass().getName());
290:                element = new SimpleElement(StyleConstants.IconElementName);
291:                assertEquals("javax.swing.text.IconView", factory.create(
292:                        element).getClass().getName());
293:                element = new SimpleElement("something");
294:                assertEquals("javax.swing.text.LabelView", factory.create(
295:                        element).getClass().getName());
296:                ViewFactory factory1 = kit.getViewFactory();
297:                assertEquals(factory, factory1);
298:            }
299:
300:            public void testInstallJEditorPane() {
301:            }
302:
303:            /**
304:             * Regression test for HARMONY-2594
305:             * */
306:            public void testcreateInputAttributes() {
307:                MyStyledEditorKit msek = new MyStyledEditorKit();
308:                MutableAttributeSet set = new Style() {
309:                    public void removeChangeListener(ChangeListener p0) {
310:                        return;
311:                    }
312:
313:                    public void addChangeListener(ChangeListener p0) {
314:                        return;
315:                    }
316:
317:                    public String getName() {
318:                        return "AA";
319:                    }
320:
321:                    public void setResolveParent(AttributeSet p0) {
322:                        return;
323:                    }
324:
325:                    public void removeAttributes(AttributeSet p0) {
326:                        return;
327:                    }
328:
329:                    public void removeAttributes(Enumeration p0) {
330:                        return;
331:                    }
332:
333:                    public void removeAttribute(Object p0) {
334:                        return;
335:                    }
336:
337:                    public void addAttributes(AttributeSet p0) {
338:                        return;
339:                    }
340:
341:                    public void addAttribute(Object p0, Object p1) {
342:                        return;
343:                    }
344:
345:                    public AttributeSet getResolveParent() {
346:                        return null;
347:                    }
348:
349:                    public boolean containsAttributes(AttributeSet p0) {
350:                        return false;
351:                    }
352:
353:                    public boolean containsAttribute(Object p0, Object p1) {
354:                        return false;
355:                    }
356:
357:                    public Enumeration getAttributeNames() {
358:                        return null;
359:                    }
360:
361:                    public Object getAttribute(Object p0) {
362:                        return null;
363:                    }
364:
365:                    public AttributeSet copyAttributes() {
366:                        return null;
367:                    }
368:
369:                    public boolean isEqual(AttributeSet p0) {
370:                        return false;
371:                    }
372:
373:                    public boolean isDefined(Object p0) {
374:                        return false;
375:                    }
376:
377:                    public int getAttributeCount() {
378:                        return 0;
379:                    }
380:                };
381:                try {
382:                    msek.createInputAttributes(null, set);
383:                    fail("NPE not thrown when Element is null!");
384:                } catch (NullPointerException npe) {
385:                    // expected
386:                }
387:            }
388:
389:            /**
390:             * Regression test for HARMONY-2594
391:             * */
392:            public void testCreateInputAttributes2() {
393:                MyStyledEditorKit msek = new MyStyledEditorKit();
394:                try {
395:                    msek.createInputAttributes(new SimpleElement(""), null);
396:                    fail("NPE not thrown when MutableAttributeSet is null!");
397:                } catch (NullPointerException npe) {
398:                    // expected
399:                }
400:            }
401:
402:            class MyStyledEditorKit extends StyledEditorKit {
403:                public MyStyledEditorKit() {
404:                    super ();
405:                }
406:
407:                public void createInputAttributes(Element element,
408:                        MutableAttributeSet set) {
409:                    super.createInputAttributes(element, set);
410:                }
411:            }
412:
413:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.