Source Code Cross Referenced for FormView_FormInputElementTest.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 Roman I. Chernyatchik
019:         * @version $Revision$
020:         */package javax.swing.text.html;
021:
022:        import java.awt.ComponentOrientation;
023:        import java.awt.Dimension;
024:        import java.awt.FontMetrics;
025:        import java.io.StringReader;
026:
027:        import javax.swing.AbstractButton;
028:        import javax.swing.Box;
029:        import javax.swing.DefaultButtonModel;
030:        import javax.swing.JButton;
031:        import javax.swing.JCheckBox;
032:        import javax.swing.JComponent;
033:        import javax.swing.JEditorPane;
034:        import javax.swing.JPasswordField;
035:        import javax.swing.JRadioButton;
036:        import javax.swing.JTextField;
037:        import javax.swing.JToggleButton;
038:        import javax.swing.SwingTestCase;
039:        import javax.swing.text.AttributeSet;
040:        import javax.swing.text.Element;
041:        import javax.swing.text.JTextComponent;
042:        import javax.swing.text.StyleConstants;
043:
044:        import org.apache.harmony.x.swing.Utilities;
045:
046:        public class FormView_FormInputElementTest extends SwingTestCase {
047:
048:            private static final char MEAN_CHAR = 'z';
049:            private static final int DEFAULT_TEXTFIELD_SIZE = 20;
050:            private static final String BROWSE_BUTTON_DEFAULT_TEXT = "Browse...";
051:            private static final String SUBMIT_DEFAULT_TEXT = "Submit Query";
052:            private static final String RESET_DEFAULT_TEXT = "Reset";
053:
054:            private HTMLDocument document;
055:            private HTMLEditorKit htmlEditorKit;
056:            private JEditorPane editorPane;
057:
058:            private Element elem;
059:
060:            private FormView formView;
061:
062:            protected void setUp() throws Exception {
063:                super .setUp();
064:
065:                setIgnoreNotImplemented(true);
066:
067:                htmlEditorKit = new HTMLEditorKit();
068:                editorPane = new JEditorPane();
069:                editorPane.setEditorKit(htmlEditorKit);
070:                document = (HTMLDocument) editorPane.getDocument();
071:            }
072:
073:            public void testCreateButtonComponent() throws Exception {
074:                createHTMLSample("button");
075:                JButton button;
076:
077:                if (isHarmony()) {
078:                    // VALUE
079:                    createFormViewWithParent("button_default");
080:                    button = (JButton) formView.createComponent();
081:                    assertEquals("button_default", button.getText());
082:                    assertNull(button.getToolTipText());
083:                    assertEquals(button.getPreferredSize(), button
084:                            .getMaximumSize());
085:                    assertEquals(button.getPreferredSize(), button
086:                            .getMinimumSize());
087:
088:                    //ACCESSKEY
089:                    checkButtonAccessKey("button_accesskey");
090:
091:                    //TITLE
092:                    checkTitle("button_title");
093:
094:                    // SIZE
095:                    checkButtonSize("button_size");
096:
097:                    // ALIGN
098:                    checkButtonAligns("button");
099:
100:                    // DISABLED
101:                    checkDisabled("button_disabled");
102:                }
103:            }
104:
105:            public void testCreateCheckBoxComponent() throws Exception {
106:                createHTMLSample("checkbox");
107:                JCheckBox checkBox;
108:
109:                // VALUE
110:                createFormViewWithParent("checkbox_default");
111:                checkBox = (JCheckBox) formView.createComponent();
112:                assertEquals("", checkBox.getText());
113:                assertEquals(checkBox.getPreferredSize(), checkBox
114:                        .getMaximumSize());
115:                assertEquals(checkBox.getPreferredSize(), checkBox
116:                        .getMinimumSize());
117:                assertNull(checkBox.getToolTipText());
118:
119:                // CHECKED
120:                checkChecked("checkbox_checked");
121:
122:                // ACCESSKEY
123:                checkButtonAccessKey("checkbox_accesskey");
124:
125:                // TITLE
126:                checkTitle("checkbox_title");
127:
128:                // SIZE
129:                checkButtonSize("checkbox_size");
130:
131:                // ALIGN
132:                checkButtonAligns("checkbox");
133:
134:                // DISABLED
135:                checkDisabled("checkbox_disabled");
136:
137:            }
138:
139:            public void testCreateImageComponent() throws Exception {
140:                createHTMLSample("image");
141:                JButton image;
142:
143:                // VALUE
144:                createFormViewWithParent("image_src");
145:                image = (JButton) formView.createComponent();
146:                assertEquals("", image.getText());
147:
148:                createFormViewWithParent("image_default");
149:                image = (JButton) formView.createComponent();
150:                assertEquals("", image.getText());
151:
152:                // ACCESSKEY
153:                checkButtonAccessKey("image_accesskey");
154:
155:                // TITLE
156:                checkTitle("image_title");
157:                createFormViewWithParent("image_alt");
158:                image = (JButton) formView.createComponent();
159:                if (isHarmony()) {
160:                    assertEquals("alt_attribute", image.getToolTipText());
161:                } else {
162:                    assertNull(image.getToolTipText());
163:                }
164:                createFormViewWithParent("image_alt_title");
165:                image = (JButton) formView.createComponent();
166:                if (isHarmony()) {
167:                    assertEquals("title_attribute", image.getToolTipText());
168:                } else {
169:                    assertNull(image.getToolTipText());
170:                }
171:
172:                // ALT
173:                createFormViewWithParent("image_alt");
174:                image = (JButton) formView.createComponent();
175:                if (isHarmony()) {
176:                    assertEquals("alt_attribute", image.getText());
177:                } else {
178:                    assertEquals("", image.getText());
179:                }
180:
181:                // SIZE
182:                checkButtonSize("image_size");
183:
184:                // SRC
185:                createFormViewWithParent("image_src");
186:                image = (JButton) formView.createComponent();
187:                if (isHarmony()) {
188:                    assertNotNull(image.getIcon());
189:                } else {
190:                    assertNull(image.getIcon());
191:                }
192:                createFormViewWithParent("image_alt");
193:                if (isHarmony()) {
194:                    assertNotNull(image.getIcon());
195:                } else {
196:                    assertNull(image.getIcon());
197:                }
198:
199:                // ALIGN
200:                checkButtonAligns("image");
201:
202:                // DISABLED
203:                checkDisabled("image_disabled");
204:            }
205:
206:            public void testCreatePasswordComponent() throws Exception {
207:                JPasswordField passwordField;
208:                createHTMLSample("password");
209:
210:                // VALUE
211:                createFormViewWithParent("password_default");
212:                passwordField = (JPasswordField) formView.createComponent();
213:                assertEquals("password_default", passwordField.getText());
214:                assertNull(passwordField.getToolTipText());
215:
216:                // READONLY
217:                checkTextReadonly("password_readonly");
218:
219:                createFormViewWithParent("password_accesskey");
220:                passwordField = (JPasswordField) formView.createComponent();
221:
222:                // TITLE
223:                checkTitle("password_title");
224:
225:                //SIZE
226:                checkTextSize("password", passwordField.getEchoChar());
227:
228:                //DIR
229:                checkTextDir("password_rtl");
230:
231:                // ALIGN
232:                checkTextAligns("password");
233:
234:                // DISABLED
235:                checkDisabled("password_disabled");
236:            }
237:
238:            public void testCreateRadioComponent() throws Exception {
239:                createHTMLSample("radio");
240:                JRadioButton radioButton;
241:
242:                // VALUE
243:                createFormViewWithParent("radio_default");
244:                radioButton = (JRadioButton) formView.createComponent();
245:                assertEquals("", radioButton.getText());
246:                assertNull(radioButton.getToolTipText());
247:
248:                // CHECKED
249:                checkChecked("radio_checked");
250:
251:                // ACCESSKEY
252:                checkButtonAccessKey("radio_accesskey");
253:
254:                // SIZE
255:                checkButtonSize("radio_size");
256:
257:                //TITLE
258:                checkTitle("radio_title");
259:
260:                // ALIGN
261:                checkButtonAligns("radio");
262:
263:                // DISABLED
264:                checkDisabled("radio_disabled");
265:            }
266:
267:            public void testRadioGroups() throws Exception {
268:                StringBuffer htmlSrc = new StringBuffer();
269:                htmlSrc.append("<HTML> <HEAD></HEAD><BODY>");
270:                htmlSrc.append("   Hello word!");
271:                htmlSrc.append("<FORM ACTION = \"\">");
272:                htmlSrc
273:                        .append("    <INPUT TYPE = \"radio\" NAME =\"name\" ID=\"1\">");
274:                htmlSrc
275:                        .append("    <INPUT TYPE = \"radio\" NAME =\"name\" ID=\"2\">");
276:                htmlSrc
277:                        .append("    <INPUT TYPE = \"radio\" NAME =\"name\" ID=\"3\">");
278:                htmlSrc.append("</FORM></BODY></HTML>");
279:                StringReader reader = new StringReader(htmlSrc.toString());
280:                htmlEditorKit.read(reader, document, 0);
281:
282:                AttributeSet attrs = document.getElement("1").getAttributes();
283:                DefaultButtonModel sourceModel1;
284:                sourceModel1 = (DefaultButtonModel) attrs
285:                        .getAttribute(StyleConstants.ModelAttribute);
286:                assertEquals(0, sourceModel1.getGroup().getButtonCount());
287:                attrs = document.getElement("2").getAttributes();
288:                DefaultButtonModel sourceModel2;
289:                sourceModel2 = (DefaultButtonModel) attrs
290:                        .getAttribute(StyleConstants.ModelAttribute);
291:                assertEquals(0, sourceModel2.getGroup().getButtonCount());
292:
293:                createFormViewWithParent("1");
294:                assertEquals(0, sourceModel1.getGroup().getButtonCount());
295:            }
296:
297:            public void testCreateResetComponent() throws Exception {
298:                createHTMLSample("reset");
299:                JButton resetButton;
300:
301:                //Default VALUE
302:                createFormViewWithParent("reset");
303:                resetButton = (JButton) formView.createComponent();
304:                assertEquals(RESET_DEFAULT_TEXT, resetButton.getText());
305:
306:                // VALUE
307:                createFormViewWithParent("reset_default");
308:                resetButton = (JButton) formView.createComponent();
309:                assertEquals("reset_default", resetButton.getText());
310:                assertNull(resetButton.getToolTipText());
311:
312:                // ACCESSKEY
313:                checkButtonAccessKey("reset_accesskey");
314:
315:                // SIZE
316:                checkButtonSize("reset_size");
317:
318:                //TITLE
319:                checkTitle("reset_title");
320:
321:                // ALIGN
322:                checkButtonAligns("reset");
323:
324:                // DISABLED
325:                checkDisabled("reset_disabled");
326:            }
327:
328:            public void testCreateSubmitComponent() throws Exception {
329:                createHTMLSample("submit");
330:                JButton submitButton;
331:
332:                //Default VALUE
333:                createFormViewWithParent("submit");
334:                submitButton = (JButton) formView.createComponent();
335:                assertEquals(SUBMIT_DEFAULT_TEXT, submitButton.getText());
336:
337:                // VALUE
338:                createFormViewWithParent("submit_default");
339:                submitButton = (JButton) formView.createComponent();
340:                assertEquals("submit_default", submitButton.getText());
341:                assertNull(submitButton.getToolTipText());
342:
343:                // ACCESSKEY
344:                checkButtonAccessKey("submit_accesskey");
345:
346:                // SIZE
347:                checkButtonSize("submit_size");
348:
349:                //TITLE
350:                checkTitle("submit_title");
351:
352:                // ALIGN
353:                checkButtonAlign("submit");
354:
355:                // DISABLED
356:                checkDisabled("submit_disabled");
357:            }
358:
359:            public void testCreateTextComponent() throws Exception {
360:                JTextField textField;
361:                createHTMLSample("text");
362:
363:                // VALUE
364:                createFormViewWithParent("text_default");
365:                textField = (JTextField) formView.createComponent();
366:                assertEquals("text_default", textField.getText());
367:                assertNull(textField.getToolTipText());
368:
369:                // DISABLED
370:                checkDisabled("text_disabled");
371:
372:                // READONLY
373:                checkTextReadonly("text_readonly");
374:
375:                //SIZE
376:                checkTextSize("text", MEAN_CHAR);
377:
378:                // TITLE
379:                checkTitle("text_title");
380:
381:                // ALIGN
382:                checkTextAligns("text");
383:
384:                //DIR
385:                checkTextDir("text_rtl");
386:            }
387:
388:            public void testCreateFileComponent() throws Exception {
389:                createHTMLSample("file");
390:
391:                //Default VALUE
392:                createFormViewWithParent("file");
393:                Box box = (Box) formView.createComponent();
394:                ;
395:                JTextField filePath = (JTextField) box.getComponent(0);
396:                JButton browseButton = (JButton) box.getComponent(2);
397:                assertEquals("", filePath.getText());
398:                assertEquals(BROWSE_BUTTON_DEFAULT_TEXT, browseButton.getText());
399:
400:                //VALUE
401:                createFormViewWithParent("file_default");
402:                box = (Box) formView.createComponent();
403:                ;
404:                filePath = (JTextField) box.getComponent(0);
405:                browseButton = (JButton) box.getComponent(2);
406:                checkTextSize(filePath, MEAN_CHAR, false);
407:                assertEquals(BROWSE_BUTTON_DEFAULT_TEXT, browseButton.getText());
408:
409:                // SIZE
410:                createFormViewWithParent("file_size");
411:                box = (Box) formView.createComponent();
412:                ;
413:                filePath = (JTextField) box.getComponent(0);
414:                Box.Filler filler = (Box.Filler) box.getComponent(1);
415:                browseButton = (JButton) box.getComponent(2);
416:                assertEquals(new Dimension(5, 0), filler.getMinimumSize());
417:                assertEquals(new Dimension(5, 0), filler.getPreferredSize());
418:                assertEquals(new Dimension(5, 32767), filler.getMaximumSize());
419:                checkTextSize(filePath, MEAN_CHAR, true);
420:
421:                // DIR
422:                createFormViewWithParent("file_rtl");
423:                box = (Box) formView.createComponent();
424:                ;
425:                filePath = (JTextField) box.getComponent(0);
426:                if (isHarmony()) {
427:                    assertEquals(box.getComponentOrientation(),
428:                            ComponentOrientation.RIGHT_TO_LEFT);
429:                    assertEquals(filePath.getComponentOrientation(),
430:                            ComponentOrientation.RIGHT_TO_LEFT);
431:                }
432:
433:                // READONLY
434:                createFormViewWithParent("file_readonly");
435:                box = (Box) formView.createComponent();
436:                ;
437:                filePath = (JTextField) box.getComponent(0);
438:                if (isHarmony()) {
439:                    assertFalse(filePath.isEditable());
440:                } else {
441:                    assertTrue(filePath.isEditable());
442:                }
443:
444:                // TITLE
445:                createFormViewWithParent("file_title");
446:                box = (Box) formView.createComponent();
447:                filePath = (JTextField) box.getComponent(0);
448:                browseButton = (JButton) box.getComponent(2);
449:                if (isHarmony()) {
450:                    assertEquals("title_attribute", browseButton
451:                            .getToolTipText());
452:                    assertEquals("title_attribute", filePath.getToolTipText());
453:                } else {
454:                    assertNull(browseButton.getToolTipText());
455:                    assertNull(filePath.getToolTipText());
456:                }
457:
458:                // ALIGN
459:                createFormViewWithParent("file_default");
460:                checkFileAlign();
461:                createFormViewWithParent("file_align_top");
462:                checkFileAlign();
463:                createFormViewWithParent("file_align_right");
464:                checkFileAlign();
465:                createFormViewWithParent("file_align_justify");
466:                checkFileAlign();
467:
468:                // DISABLED
469:                createFormViewWithParent("file_disabled");
470:                box = (Box) formView.createComponent();
471:                ;
472:                filePath = (JTextField) box.getComponent(0);
473:                browseButton = (JButton) box.getComponent(2);
474:                if (isHarmony()) {
475:                    assertFalse(browseButton.isEnabled());
476:                    assertFalse(filePath.isEnabled());
477:                } else {
478:                    assertTrue(browseButton.isEnabled());
479:                    assertTrue(filePath.isEnabled());
480:                }
481:            }
482:
483:            private void checkFileAlign() {
484:                Box box = (Box) formView.createComponent();
485:                JTextField filePath = (JTextField) box.getComponent(0);
486:                JButton browseButton = (JButton) box.getComponent(2);
487:                checkAlign(box, JComponent.CENTER_ALIGNMENT,
488:                        JComponent.BOTTOM_ALIGNMENT);
489:                checkAlign(filePath, JComponent.CENTER_ALIGNMENT,
490:                        JComponent.CENTER_ALIGNMENT);
491:                checkAlign(browseButton, JComponent.LEFT_ALIGNMENT,
492:                        JComponent.CENTER_ALIGNMENT);
493:            }
494:
495:            private void checkAlign(final JComponent component,
496:                    final float alignmentX, final float alignmentY) {
497:                assertEquals(alignmentX, component.getAlignmentX(), 0.0001);
498:                assertEquals(alignmentY, component.getAlignmentY(), 0.0001);
499:            }
500:
501:            private void checkDisabled(final String id) {
502:                createFormViewWithParent(id);
503:                JComponent component = (JComponent) formView.createComponent();
504:                if (isHarmony()) {
505:                    assertFalse(component.isEnabled());
506:                } else {
507:                    assertTrue(component.isEnabled());
508:                }
509:            }
510:
511:            private void checkChecked(final String id) {
512:                JToggleButton togleButton;
513:                createFormViewWithParent(id);
514:                togleButton = (JToggleButton) formView.createComponent();
515:                assertTrue(togleButton.isSelected());
516:            }
517:
518:            private void checkButtonAccessKey(final String id) {
519:                AbstractButton button;
520:                if (isHarmony()) {
521:                    createFormViewWithParent(id);
522:                    button = (AbstractButton) formView.createComponent();
523:                    assertEquals(Utilities.keyCodeToKeyChar(button
524:                            .getMnemonic()), 'U');
525:                }
526:            }
527:
528:            private void checkButtonAlign(final String id) {
529:                createFormViewWithParent(id);
530:                checkAlign((JComponent) formView.createComponent(),
531:                        JComponent.LEFT_ALIGNMENT, JComponent.BOTTOM_ALIGNMENT);
532:            }
533:
534:            private void checkButtonAligns(final String type) {
535:                checkButtonAlign(type + "_default");
536:                checkButtonAlign(type + "_align_top");
537:                checkButtonAlign(type + "_align_right");
538:                checkButtonAlign(type + "_align_justify");
539:            }
540:
541:            private void checkButtonSize(final String id) {
542:                createFormViewWithParent(id);
543:                JComponent component = (JComponent) formView.createComponent();
544:                if (isHarmony()) {
545:                    assertEquals(component.getPreferredSize().width, 100);
546:                }
547:                assertEquals(component.getPreferredSize(), component
548:                        .getMaximumSize());
549:                assertEquals(component.getPreferredSize(), component
550:                        .getMinimumSize());
551:            }
552:
553:            private void checkTextAlign(final String id) {
554:                createFormViewWithParent(id);
555:                checkAlign((JComponent) formView.createComponent(),
556:                        JComponent.CENTER_ALIGNMENT,
557:                        JComponent.BOTTOM_ALIGNMENT);
558:            }
559:
560:            private void checkTextAligns(final String type) {
561:                checkTextAlign(type + "_default");
562:                checkTextAlign(type + "_align_top");
563:                checkTextAlign(type + "_align_right");
564:                checkTextAlign(type + "_align_justify");
565:            }
566:
567:            private void checkTextDir(final String id) {
568:                createFormViewWithParent(id);
569:                JTextField passwordField = (JTextField) formView
570:                        .createComponent();
571:                if (isHarmony()) {
572:                    assertEquals(passwordField.getComponentOrientation(),
573:                            ComponentOrientation.RIGHT_TO_LEFT);
574:                }
575:            }
576:
577:            private void checkTextReadonly(final String id) {
578:                JTextComponent textComponent;
579:                createFormViewWithParent(id);
580:                textComponent = (JTextComponent) formView.createComponent();
581:                if (isHarmony()) {
582:                    assertFalse(textComponent.isEditable());
583:                } else {
584:                    assertTrue(textComponent.isEditable());
585:                }
586:            }
587:
588:            private void checkTextSize(final String type, final char ch) {
589:                JTextComponent textComponent;
590:
591:                createFormViewWithParent(type + "_size");
592:                textComponent = (JTextComponent) formView.createComponent();
593:                checkTextSize(textComponent, ch, true);
594:
595:                createFormViewWithParent(type + "_default");
596:                textComponent = (JTextComponent) formView.createComponent();
597:                checkTextSize(textComponent, ch, false);
598:
599:            }
600:
601:            private void checkTextSize(final JTextComponent textComponent,
602:                    final char ch, final boolean sizeWasSet) {
603:                final FontMetrics fontMetrics = textComponent
604:                        .getFontMetrics(textComponent.getFont());
605:                final int charWidth = fontMetrics.charWidth(ch);
606:                Dimension size = textComponent.getPreferredSize();
607:
608:                size.width = (sizeWasSet ? 100 : DEFAULT_TEXTFIELD_SIZE)
609:                        * charWidth;
610:                if (isHarmony()) {
611:                    assertEquals(size, textComponent.getPreferredSize());
612:                    assertEquals(size, textComponent.getMaximumSize());
613:                    size = new Dimension(DEFAULT_TEXTFIELD_SIZE * charWidth,
614:                            size.height);
615:                    assertEquals(size, textComponent.getMinimumSize());
616:                }
617:            }
618:
619:            private void checkTitle(final String id) {
620:                createFormViewWithParent(id);
621:                JComponent checkBox = (JComponent) formView.createComponent();
622:                if (isHarmony()) {
623:                    assertEquals("title_attribute", checkBox.getToolTipText());
624:                } else {
625:                    assertNull(checkBox.getToolTipText());
626:                }
627:            }
628:
629:            private void createFormViewWithParent(final String id) {
630:                elem = document.getElement(id);
631:                formView = new FormView(elem);
632:                formView.setParent(editorPane.getUI().getRootView(editorPane));
633:            }
634:
635:            private void createHTMLSample(final String typeName)
636:                    throws Exception {
637:                StringBuffer htmlSrc = new StringBuffer();
638:                htmlSrc.append("<HTML>");
639:                htmlSrc.append("<HEAD></HEAD>");
640:                htmlSrc.append("<BODY>");
641:                htmlSrc.append("   Hello word!");
642:                htmlSrc.append("<FORM ACTION = \"\">");
643:                htmlSrc.append("    <INPUT TYPE = \"" + typeName + "\" "
644:                        + "ID=\"" + typeName + "\">");
645:                htmlSrc.append("    <INPUT TYPE = \"" + typeName + "\""
646:                        + "NAME =\"" + typeName + "_name\" " + "VALUE = \""
647:                        + typeName + "_default\" " + "ID=\"" + typeName
648:                        + "_default\">");
649:                htmlSrc.append("    <INPUT TYPE = \"" + typeName + "\""
650:                        + "NAME =\"" + typeName + "_name\" " + "VALUE = \""
651:                        + typeName + "_align_top\" " + "ALIGN = \"top\""
652:                        + "ID=\"" + typeName + "_align_top\">");
653:                htmlSrc.append("    <INPUT TYPE = \"" + typeName + "\""
654:                        + "NAME =\"" + typeName + "_name\" " + "VALUE = \""
655:                        + typeName + "_align_right\" " + "ALIGN = \"right\""
656:                        + "ID=\"" + typeName + "_align_right\">");
657:                htmlSrc.append("    <INPUT TYPE = \"" + typeName + "\""
658:                        + "NAME =\"" + typeName + "_name\" " + "VALUE = \""
659:                        + typeName + "_align_justify\" "
660:                        + "ALIGN = \"justify\"" + "ID=\"" + typeName
661:                        + "_align_justify\">");
662:                htmlSrc.append("    <INPUT TYPE = \"" + typeName + "\" "
663:                        + "NAME =\"\" " + "VALUE = \"" + typeName
664:                        + "_empty_name\" " + "ID=\"" + typeName
665:                        + "_empty_name\">");
666:                htmlSrc.append("    <INPUT TYPE = \"" + typeName + "\" "
667:                        + "NAME =\"" + typeName + "_name\"  " + "ID=\""
668:                        + typeName + "_name_only\">");
669:                htmlSrc.append("    <INPUT TYPE = \"" + typeName + "\" "
670:                        + "SIZE = \"100\" " + "NAME =\"" + typeName
671:                        + "_name1\" " + "VALUE = \"" + typeName + "_size\" "
672:                        + "ID=\"" + typeName + "_size\">");
673:                htmlSrc.append("    <INPUT TYPE = \"" + typeName
674:                        + "\" MAXLENGTH = \"10\" " + "NAME =\"" + typeName
675:                        + "_name\" " + "VALUE = \"" + typeName
676:                        + "_maxlength\" " + "ID=\"" + typeName
677:                        + "_maxlength\">");
678:                htmlSrc.append("    <INPUT TYPE = \"" + typeName
679:                        + "\" CHECKED " + "NAME =\"" + typeName + "_name\""
680:                        + "" + "VALUE = \"" + typeName + "_checked\" "
681:                        + "ID=\"" + typeName + "_checked\">");
682:                htmlSrc.append("    <INPUT TYPE = \"" + typeName + "\" "
683:                        + "SRC = \"\" " + "NAME =\"" + typeName + "_name\" "
684:                        + "VALUE = \"" + typeName + "_src\"" + "ID=\""
685:                        + typeName + "_src\">");
686:                htmlSrc.append("    <INPUT TYPE = \"" + typeName + "\" "
687:                        + "DIR = \"rtl\" " + "NAME =\"" + typeName + "_name\" "
688:                        + "VALUE = \"" + typeName + "_rtl\" " + "ID=\""
689:                        + typeName + "_rtl\">");
690:                htmlSrc.append("    <INPUT TYPE = \"" + typeName + "\" "
691:                        + "ALT = \"alt_attribute\" NAME =\"" + typeName
692:                        + "_name\" " + "VALUE = \"" + typeName + "_alt\" "
693:                        + "ID=\"" + typeName + "_alt\">");
694:                htmlSrc.append("    <INPUT TYPE = \"" + typeName + "\" "
695:                        + "ACCESSKEY=\"U\" " + "NAME =\"" + typeName
696:                        + "_name\" " + "VALUE = \"" + typeName
697:                        + "_accesskey\" " + "ID=\"" + typeName
698:                        + "_accesskey\">");
699:                htmlSrc.append("    <INPUT TYPE = \"" + typeName + "\" "
700:                        + "TABINDEX = \"1\" " + "NAME =\"" + typeName
701:                        + "_name\" " + "VALUE = \"" + typeName + "_tabindex\" "
702:                        + "ID=\"" + typeName + "_tabindex\">");
703:                htmlSrc.append("    <INPUT TYPE = \"" + typeName + "\" "
704:                        + "TITLE = \"title_attribute\" NAME =\"" + typeName
705:                        + "_name\" " + "VALUE = \"" + typeName + "_title\" "
706:                        + "ID=\"" + typeName + "_title\">");
707:                htmlSrc.append("    <INPUT TYPE = \"" + typeName + "\" "
708:                        + "ALIGN = \"right\" NAME =\"" + typeName + "_name\" "
709:                        + "VALUE = \"" + typeName + "\" " + "ID=\"" + typeName
710:                        + "_align_right\">");
711:                htmlSrc.append("    <INPUT TYPE = \"" + typeName + "\" "
712:                        + "ALIGN = \"center\" NAME =\"" + typeName + "_name\" "
713:                        + "VALUE = \"" + typeName + "\" " + "ID=\"" + typeName
714:                        + "_align_center\">");
715:                htmlSrc.append("    <INPUT TYPE = \"" + typeName
716:                        + "\" READONLY " + "NAME =\"" + typeName + "_name\" "
717:                        + "VALUE = \"" + typeName + "_readonly\" " + "ID=\""
718:                        + typeName + "_readonly\">");
719:                htmlSrc.append("    <INPUT TYPE = \"" + typeName
720:                        + "\" DISABLED " + "NAME =\"" + typeName + "_name\" "
721:                        + "VALUE = \"" + typeName + "_disabled\" " + "ID=\""
722:                        + typeName + "_disabled\">");
723:                htmlSrc.append("    <INPUT TYPE = \"" + typeName + "\" "
724:                        + "ALT = \"alt_attribute\" "
725:                        + "TITLE = \"title_attribute\" " + "NAME =\""
726:                        + typeName + "_name\" " + "VALUE = \"" + typeName
727:                        + "_alt_title\" " + "ID=\"" + typeName
728:                        + "_alt_title\">");
729:                htmlSrc.append("    <INPUT TYPE = \"" + typeName + "\" "
730:                        + "USEMAP=\"#map\">");
731:                htmlSrc
732:                        .append("    <INPUT TYPE = \"submit\" NAME =\"submit_name\" "
733:                                + "VALUE = \"submit:JTextField\" "
734:                                + "ID=\"submit\">");
735:                htmlSrc.append("</FORM>");
736:                htmlSrc.append("<MAP name=\"map\">");
737:                htmlSrc.append("    <P> map_title");
738:                htmlSrc
739:                        .append("    <A href=\"\" shape=\"rect\" coords=\"0,0,100,50\"> "
740:                                + "href</A>");
741:                htmlSrc.append("</MAP>");
742:                htmlSrc.append("</BODY>");
743:                htmlSrc.append("</HTML>");
744:
745:                StringReader reader = new StringReader(htmlSrc.toString());
746:                htmlEditorKit.read(reader, document, 0);
747:            }
748:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.