Source Code Cross Referenced for Panel.java in  » Testing » UISpec4J » org » uispec4j » 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 » Testing » UISpec4J » org.uispec4j 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.uispec4j;
002:
003:        import junit.framework.Assert;
004:        import junit.framework.AssertionFailedError;
005:        import org.uispec4j.assertion.Assertion;
006:        import org.uispec4j.finder.ComponentFinder;
007:        import org.uispec4j.finder.ComponentMatcher;
008:        import org.uispec4j.finder.ComponentMatchers;
009:        import org.uispec4j.utils.UIComponentAnalyzer;
010:        import org.uispec4j.utils.UIComponentFactory;
011:
012:        import javax.swing.*;
013:        import java.awt.Component;
014:        import java.awt.Container;
015:        import java.util.ArrayList;
016:
017:        /**
018:         * General container for UI components.<p>
019:         * This class offers a set of "getXxx" methods for retrieving the different kinds of UIComponent
020:         * instances laid out in a GUI panel.<p>
021:         * It also provides a set of generic find/get methods, with the following naming logic:
022:         * <ul>
023:         * <li>'find...' stands for a unitary search that returns null when nothing was found</li>
024:         * <li>'getXxxComponent' stands for a unitary search that throws an exception
025:         * when nothing was found</li>
026:         * <li>'getXxxComponent<em>s</em>' stands for plural search and returns an empty array
027:         * when nothing was found</li>
028:         * <li>'getXxxComponent<em>s</em>' stands for plural search and returns an empty array
029:         * when nothing was found</li>
030:         * <li>'containsXxxComponent<em>s</em>' returns an assertion for checking the presence
031:         * of a component</li>
032:         * </ul>
033:         * NOTE: A Panel can be created from any AWT Container, but when a Panel is searched with the
034:         * {@link #getPanel(String)} method only components of type JPanel JInternalFrame, etc. will be
035:         * considered.
036:         *
037:         * @noinspection ReturnOfNull
038:         */
039:        public class Panel extends AbstractUIComponent {
040:            public static final String TYPE_NAME = "panel";
041:            public static final Class[] SWING_CLASSES = { JPanel.class,
042:                    JInternalFrame.class, JViewport.class, JScrollPane.class,
043:                    JRootPane.class };
044:
045:            private Container container;
046:            private ComponentFinder finder;
047:
048:            public Panel(Container container) {
049:                this .container = container;
050:                this .finder = new ComponentFinder(container);
051:            }
052:
053:            public String getDescriptionTypeName() {
054:                return TYPE_NAME;
055:            }
056:
057:            public Component getAwtComponent() {
058:                return container;
059:            }
060:
061:            public Container getAwtContainer() {
062:                return container;
063:            }
064:
065:            public Button getButton(String name) throws ItemNotFoundException,
066:                    ComponentAmbiguityException {
067:                return (Button) getComponent(finder, Button.class, name);
068:            }
069:
070:            public Button getButton() throws ItemNotFoundException,
071:                    ComponentAmbiguityException {
072:                return (Button) getComponent(finder, Button.class, null);
073:            }
074:
075:            public Button getButton(final ComponentMatcher matcher)
076:                    throws ItemNotFoundException, ComponentAmbiguityException {
077:                return (Button) getComponent(finder, getMatcherByClass(
078:                        Button.class, matcher));
079:            }
080:
081:            public ToggleButton getToggleButton(String name)
082:                    throws ItemNotFoundException, ComponentAmbiguityException {
083:                return (ToggleButton) getComponent(finder, ToggleButton.class,
084:                        name);
085:            }
086:
087:            public ToggleButton getToggleButton() throws ItemNotFoundException,
088:                    ComponentAmbiguityException {
089:                return (ToggleButton) getComponent(finder, ToggleButton.class,
090:                        null);
091:            }
092:
093:            public ToggleButton getToggleButton(ComponentMatcher matcher)
094:                    throws ItemNotFoundException, ComponentAmbiguityException {
095:                return (ToggleButton) getComponent(finder, getMatcherByClass(
096:                        ToggleButton.class, matcher));
097:            }
098:
099:            public CheckBox getCheckBox(String name)
100:                    throws ItemNotFoundException, ComponentAmbiguityException {
101:                return (CheckBox) getComponent(finder, CheckBox.class, name);
102:            }
103:
104:            public CheckBox getCheckBox() throws ItemNotFoundException,
105:                    ComponentAmbiguityException {
106:                return (CheckBox) getComponent(finder, CheckBox.class, null);
107:            }
108:
109:            public CheckBox getCheckBox(ComponentMatcher matcher)
110:                    throws ItemNotFoundException, ComponentAmbiguityException {
111:                return (CheckBox) getComponent(finder, getMatcherByClass(
112:                        CheckBox.class, matcher));
113:            }
114:
115:            public Panel getPanel() throws ItemNotFoundException,
116:                    ComponentAmbiguityException {
117:                return (Panel) getComponent(finder, Panel.class, null);
118:            }
119:
120:            public Panel getPanel(String name) throws ItemNotFoundException,
121:                    ComponentAmbiguityException {
122:                return (Panel) getComponent(finder, Panel.class, name);
123:            }
124:
125:            public Panel getPanel(ComponentMatcher matcher)
126:                    throws ItemNotFoundException, ComponentAmbiguityException {
127:                return (Panel) getComponent(finder, getMatcherByClass(
128:                        Panel.class, matcher));
129:            }
130:
131:            public ProgressBar getProgressBar(String name)
132:                    throws ItemNotFoundException, ComponentAmbiguityException {
133:                return (ProgressBar) getComponent(finder, ProgressBar.class,
134:                        name);
135:            }
136:
137:            public ProgressBar getProgressBar() throws ItemNotFoundException,
138:                    ComponentAmbiguityException {
139:                return (ProgressBar) getComponent(finder, ProgressBar.class,
140:                        null);
141:            }
142:
143:            public ProgressBar getProgressBar(ComponentMatcher matcher)
144:                    throws ItemNotFoundException, ComponentAmbiguityException {
145:                return (ProgressBar) getComponent(finder, getMatcherByClass(
146:                        ProgressBar.class, matcher));
147:            }
148:
149:            public Desktop getDesktop(String name)
150:                    throws ItemNotFoundException, ComponentAmbiguityException {
151:                return (Desktop) getComponent(finder, Desktop.class, name);
152:            }
153:
154:            public Desktop getDesktop() throws ItemNotFoundException,
155:                    ComponentAmbiguityException {
156:                return (Desktop) getComponent(finder, Desktop.class, null);
157:            }
158:
159:            public Desktop getDesktop(ComponentMatcher matcher)
160:                    throws ItemNotFoundException, ComponentAmbiguityException {
161:                return (Desktop) getComponent(finder, getMatcherByClass(
162:                        Desktop.class, matcher));
163:            }
164:
165:            public TextBox getTextBox(String name)
166:                    throws ItemNotFoundException, ComponentAmbiguityException {
167:                Class[] swingClasses = UIComponentAnalyzer
168:                        .getSwingClasses(TextBox.class);
169:                String typeName = UIComponentAnalyzer
170:                        .getTypeName(TextBox.class);
171:                Component swingComponent = finder.getComponent(name,
172:                        swingClasses, typeName);
173:                return (TextBox) UIComponentFactory
174:                        .createUIComponent(swingComponent);
175:            }
176:
177:            public TextBox getTextBox() throws ItemNotFoundException,
178:                    ComponentAmbiguityException {
179:                return (TextBox) getComponent(finder, TextBox.class, null);
180:            }
181:
182:            public TextBox getTextBox(ComponentMatcher matcher)
183:                    throws ItemNotFoundException, ComponentAmbiguityException {
184:                return (TextBox) getComponent(finder, getMatcherByClass(
185:                        TextBox.class, matcher));
186:            }
187:
188:            /**
189:             * Retrieves input-only text boxes. This is useful for avoiding ambiguity exceptions
190:             * when the input text boxes are laid out near labels, as in most forms.<p>
191:             * "Input text boxes" are defined as subclasses of the JTextComponent class - in other words,
192:             * JLabel components are excluded from the search. Please note that the is is not necessarily
193:             * visible from the user, since JTextComponent subclasses can be customized to look as ordinary,
194:             * read-only labels.
195:             */
196:            public TextBox getInputTextBox(String name)
197:                    throws ComponentAmbiguityException, ItemNotFoundException {
198:                java.util.List inputComponentClasses = new ArrayList();
199:                Class[] swingClasses = TextBox.SWING_CLASSES;
200:                for (int i = 0; i < swingClasses.length; i++) {
201:                    if (!swingClasses[i].equals(JLabel.class)) {
202:                        inputComponentClasses.add(swingClasses[i]);
203:                    }
204:                }
205:                Class[] inputClassesArray = (Class[]) inputComponentClasses
206:                        .toArray(new Class[inputComponentClasses.size()]);
207:                return (TextBox) getComponent(finder, TextBox.class,
208:                        inputClassesArray, name);
209:            }
210:
211:            /**
212:             * Retrieves input-only text boxes.
213:             *
214:             * @see #getInputTextBox(String)
215:             */
216:            public TextBox getInputTextBox()
217:                    throws ComponentAmbiguityException, ItemNotFoundException {
218:                return getInputTextBox(null);
219:            }
220:
221:            public TabGroup getTabGroup(String name)
222:                    throws ItemNotFoundException, ComponentAmbiguityException {
223:                return (TabGroup) getComponent(finder, TabGroup.class, name);
224:            }
225:
226:            public TabGroup getTabGroup() throws ItemNotFoundException,
227:                    ComponentAmbiguityException {
228:                return (TabGroup) getComponent(finder, TabGroup.class, null);
229:            }
230:
231:            public TabGroup getTabGroup(ComponentMatcher matcher)
232:                    throws ItemNotFoundException, ComponentAmbiguityException {
233:                return (TabGroup) getComponent(finder, getMatcherByClass(
234:                        TabGroup.class, matcher));
235:            }
236:
237:            public ComboBox getComboBox(String name)
238:                    throws ItemNotFoundException, ComponentAmbiguityException {
239:                return (ComboBox) getComponent(finder, ComboBox.class, name);
240:            }
241:
242:            public ComboBox getComboBox() throws ItemNotFoundException,
243:                    ComponentAmbiguityException {
244:                return (ComboBox) getComponent(finder, ComboBox.class, null);
245:            }
246:
247:            public ComboBox getComboBox(ComponentMatcher matcher)
248:                    throws ItemNotFoundException, ComponentAmbiguityException {
249:                return (ComboBox) getComponent(finder, getMatcherByClass(
250:                        ComboBox.class, matcher));
251:            }
252:
253:            public Spinner getSpinner() throws ItemNotFoundException,
254:                    ComponentAmbiguityException {
255:                return (Spinner) getComponent(finder, Spinner.class, null);
256:            }
257:
258:            public Spinner getSpinner(String name)
259:                    throws ItemNotFoundException, ComponentAmbiguityException {
260:                return (Spinner) getComponent(finder, Spinner.class, name);
261:            }
262:
263:            public Spinner getSpinner(ComponentMatcher matcher)
264:                    throws ItemNotFoundException, ComponentAmbiguityException {
265:                return (Spinner) getComponent(finder, getMatcherByClass(
266:                        Spinner.class, matcher));
267:            }
268:
269:            public DateSpinner getDateSpinner() throws ItemNotFoundException,
270:                    ComponentAmbiguityException {
271:                Spinner component = (Spinner) getComponent(finder, Spinner
272:                        .getSpinnerMatcherByModel(SpinnerDateModel.class));
273:                return new DateSpinner((JSpinner) component.getAwtComponent());
274:            }
275:
276:            public DateSpinner getDateSpinner(String componentName) {
277:                ComponentMatcher matcher = ComponentMatchers
278:                        .intersection(new ComponentMatcher[] {
279:                                Spinner
280:                                        .getSpinnerMatcherByModel(SpinnerDateModel.class),
281:                                getMatcherFromName(componentName) });
282:                Spinner component = (Spinner) getComponent(finder, matcher);
283:                return new DateSpinner((JSpinner) component.getAwtComponent());
284:            }
285:
286:            public DateSpinner getDateSpinner(ComponentMatcher matcher) {
287:                ComponentMatcher intersection = ComponentMatchers
288:                        .intersection(new ComponentMatcher[] {
289:                                Spinner
290:                                        .getSpinnerMatcherByModel(SpinnerDateModel.class),
291:                                matcher });
292:                Spinner component = (Spinner) getComponent(finder, intersection);
293:                return new DateSpinner((JSpinner) component.getAwtComponent());
294:            }
295:
296:            public ListSpinner getListSpinner() throws ItemNotFoundException,
297:                    ComponentAmbiguityException {
298:                Spinner component = (Spinner) getComponent(finder, Spinner
299:                        .getSpinnerMatcherByModel(SpinnerListModel.class));
300:                return new ListSpinner((JSpinner) component.getAwtComponent());
301:            }
302:
303:            public ListSpinner getListSpinner(String componentName) {
304:                ComponentMatcher matcher = ComponentMatchers
305:                        .intersection(new ComponentMatcher[] {
306:                                Spinner
307:                                        .getSpinnerMatcherByModel(SpinnerListModel.class),
308:                                getMatcherFromName(componentName) });
309:                Spinner component = (Spinner) getComponent(finder, matcher);
310:                return new ListSpinner((JSpinner) component.getAwtComponent());
311:            }
312:
313:            public ListSpinner getListSpinner(ComponentMatcher matcher) {
314:                ComponentMatcher intersection = ComponentMatchers
315:                        .intersection(new ComponentMatcher[] {
316:                                Spinner
317:                                        .getSpinnerMatcherByModel(SpinnerListModel.class),
318:                                matcher });
319:                Spinner component = (Spinner) getComponent(finder, intersection);
320:                return new ListSpinner((JSpinner) component.getAwtComponent());
321:            }
322:
323:            public NumberSpinner getNumberSpinner()
324:                    throws ItemNotFoundException, ComponentAmbiguityException {
325:                Spinner component = (Spinner) getComponent(finder, Spinner
326:                        .getSpinnerMatcherByModel(SpinnerNumberModel.class));
327:                return new NumberSpinner((JSpinner) component.getAwtComponent());
328:            }
329:
330:            public NumberSpinner getNumberSpinner(String componentName) {
331:                ComponentMatcher matcher = ComponentMatchers
332:                        .intersection(new ComponentMatcher[] {
333:                                Spinner
334:                                        .getSpinnerMatcherByModel(SpinnerNumberModel.class),
335:                                getMatcherFromName(componentName) });
336:                Spinner component = (Spinner) getComponent(finder, matcher);
337:                return new NumberSpinner((JSpinner) component.getAwtComponent());
338:            }
339:
340:            public NumberSpinner getNumberSpinner(ComponentMatcher matcher) {
341:                ComponentMatcher intersection = ComponentMatchers
342:                        .intersection(new ComponentMatcher[] {
343:                                Spinner
344:                                        .getSpinnerMatcherByModel(SpinnerNumberModel.class),
345:                                matcher });
346:                Spinner component = (Spinner) getComponent(finder, intersection);
347:                return new NumberSpinner((JSpinner) component.getAwtComponent());
348:            }
349:
350:            public Slider getSlider() throws ItemNotFoundException,
351:                    ComponentAmbiguityException {
352:                return (Slider) getComponent(finder, Slider.class, null);
353:            }
354:
355:            public Slider getSlider(String name) throws ItemNotFoundException,
356:                    ComponentAmbiguityException {
357:                return (Slider) getComponent(finder, Slider.class, name);
358:            }
359:
360:            public Slider getSlider(ComponentMatcher matcher)
361:                    throws ItemNotFoundException, ComponentAmbiguityException {
362:                return (Slider) getComponent(finder, getMatcherByClass(
363:                        Slider.class, matcher));
364:            }
365:
366:            public Table getTable(String name) throws ItemNotFoundException,
367:                    ComponentAmbiguityException {
368:                return (Table) getComponent(finder, Table.class, name);
369:            }
370:
371:            public Table getTable() throws ItemNotFoundException,
372:                    ComponentAmbiguityException {
373:                return (Table) getComponent(finder, Table.class, null);
374:            }
375:
376:            public Table getTable(ComponentMatcher matcher)
377:                    throws ItemNotFoundException, ComponentAmbiguityException {
378:                return (Table) getComponent(finder, getMatcherByClass(
379:                        Table.class, matcher));
380:            }
381:
382:            public Tree getTree(String name) throws ItemNotFoundException,
383:                    ComponentAmbiguityException {
384:                return (Tree) getComponent(finder, Tree.class, name);
385:            }
386:
387:            public Tree getTree() throws ItemNotFoundException,
388:                    ComponentAmbiguityException {
389:                return (Tree) getComponent(finder, Tree.class, null);
390:            }
391:
392:            public Tree getTree(ComponentMatcher matcher)
393:                    throws ItemNotFoundException, ComponentAmbiguityException {
394:                return (Tree) getComponent(finder, getMatcherByClass(
395:                        Tree.class, matcher));
396:            }
397:
398:            public RadioButton getRadioButton(String name)
399:                    throws ItemNotFoundException, ComponentAmbiguityException {
400:                return (RadioButton) getComponent(finder, RadioButton.class,
401:                        name);
402:            }
403:
404:            public RadioButton getRadioButton() throws ItemNotFoundException,
405:                    ComponentAmbiguityException {
406:                return (RadioButton) getComponent(finder, RadioButton.class,
407:                        null);
408:            }
409:
410:            public RadioButton getRadioButton(ComponentMatcher matcher)
411:                    throws ItemNotFoundException, ComponentAmbiguityException {
412:                return (RadioButton) getComponent(finder, getMatcherByClass(
413:                        RadioButton.class, matcher));
414:            }
415:
416:            public ListBox getListBox(String name)
417:                    throws ItemNotFoundException, ComponentAmbiguityException {
418:                return (ListBox) getComponent(finder, ListBox.class, name);
419:            }
420:
421:            public ListBox getListBox() throws ItemNotFoundException,
422:                    ComponentAmbiguityException {
423:                return (ListBox) getComponent(finder, ListBox.class, null);
424:            }
425:
426:            public ListBox getListBox(ComponentMatcher matcher)
427:                    throws ItemNotFoundException, ComponentAmbiguityException {
428:                return (ListBox) getComponent(finder, getMatcherByClass(
429:                        ListBox.class, matcher));
430:            }
431:
432:            public PasswordField getPasswordField()
433:                    throws ItemNotFoundException, ComponentAmbiguityException {
434:                return (PasswordField) getComponent(finder,
435:                        PasswordField.class, null);
436:            }
437:
438:            public PasswordField getPasswordField(ComponentMatcher matcher) {
439:                return (PasswordField) getComponent(finder, getMatcherByClass(
440:                        PasswordField.class, matcher));
441:            }
442:
443:            public PasswordField getPasswordField(String componentName) {
444:                return (PasswordField) getComponent(finder,
445:                        PasswordField.class, componentName);
446:            }
447:
448:            public UIComponent[] getUIComponents(Class uiComponentClass) {
449:                return getComponents(finder, uiComponentClass, null);
450:            }
451:
452:            public UIComponent[] getUIComponents(Class uiComponentClass,
453:                    String name) {
454:                return getComponents(finder, uiComponentClass, name);
455:            }
456:
457:            public UIComponent[] getUIComponents(ComponentMatcher matcher) {
458:                return getComponents(finder, matcher);
459:            }
460:
461:            public UIComponent findUIComponent(Class uiComponentClass)
462:                    throws ComponentAmbiguityException {
463:                return findComponent(finder, uiComponentClass, null);
464:            }
465:
466:            public UIComponent findUIComponent(Class uiComponentClass,
467:                    String name) throws ComponentAmbiguityException {
468:                return findComponent(finder, uiComponentClass, name);
469:            }
470:
471:            public UIComponent findUIComponent(ComponentMatcher matcher)
472:                    throws ComponentAmbiguityException {
473:                Component swingComponent = finder.findComponent(matcher);
474:                if (swingComponent == null) {
475:                    return null;
476:                }
477:                return UIComponentFactory.createUIComponent(swingComponent);
478:            }
479:
480:            public Component[] getSwingComponents(Class swingComponentClass) {
481:                return finder.getComponents(null,
482:                        new Class[] { swingComponentClass });
483:            }
484:
485:            public Component[] getSwingComponents(Class swingComponentClass,
486:                    String name) {
487:                return finder.getComponents(name,
488:                        new Class[] { swingComponentClass });
489:            }
490:
491:            public Component[] getSwingComponents(ComponentMatcher matcher) {
492:                return finder.getComponents(matcher);
493:            }
494:
495:            public Component findSwingComponent(Class swingComponentClass)
496:                    throws ComponentAmbiguityException {
497:                return finder.findComponent(null,
498:                        new Class[] { swingComponentClass },
499:                        swingComponentClass.getName());
500:            }
501:
502:            public Component findSwingComponent(Class swingComponentClass,
503:                    String componentName) throws ComponentAmbiguityException {
504:                return finder.findComponent(componentName,
505:                        new Class[] { swingComponentClass },
506:                        swingComponentClass.getName());
507:            }
508:
509:            public Component findSwingComponent(ComponentMatcher matcher)
510:                    throws ComponentAmbiguityException {
511:                return finder.findComponent(matcher);
512:            }
513:
514:            private ComponentMatcher getMatcherByClass(
515:                    final Class uiComponentClass, final ComponentMatcher matcher) {
516:                final Class[] swingClasses = UIComponentAnalyzer
517:                        .getSwingClasses(uiComponentClass);
518:                ComponentMatcher[] classMatchers = new ComponentMatcher[swingClasses.length];
519:                for (int i = 0; i < classMatchers.length; i++) {
520:                    classMatchers[i] = ComponentMatchers
521:                            .fromClass(swingClasses[i]);
522:                }
523:                return ComponentMatchers.intersection(new ComponentMatcher[] {
524:                        matcher, ComponentMatchers.union(classMatchers) });
525:            }
526:
527:            private static UIComponent getComponent(ComponentFinder finder,
528:                    ComponentMatcher matcher) throws ItemNotFoundException,
529:                    ComponentAmbiguityException {
530:                return UIComponentFactory.createUIComponent(finder
531:                        .getComponent(matcher));
532:            }
533:
534:            private static UIComponent getComponent(ComponentFinder finder,
535:                    Class uiComponentClass, String componentName)
536:                    throws ComponentAmbiguityException, ItemNotFoundException {
537:                Class[] swingClasses = UIComponentAnalyzer
538:                        .getSwingClasses(uiComponentClass);
539:                return getComponent(finder, uiComponentClass, swingClasses,
540:                        componentName);
541:            }
542:
543:            private static UIComponent getComponent(ComponentFinder finder,
544:                    Class uiComponentClass, Class[] swingClasses,
545:                    String componentName) throws ComponentAmbiguityException,
546:                    ItemNotFoundException {
547:                String typeName = UIComponentAnalyzer
548:                        .getTypeName(uiComponentClass);
549:                Component swingComponent = finder.getComponent(componentName,
550:                        swingClasses, typeName);
551:                return UIComponentFactory.createUIComponent(swingComponent);
552:            }
553:
554:            private static UIComponent findComponent(ComponentFinder finder,
555:                    Class uiComponentClass, String name)
556:                    throws ComponentAmbiguityException {
557:                Class[] swingClasses = UIComponentAnalyzer
558:                        .getSwingClasses(uiComponentClass);
559:                String typeName = UIComponentAnalyzer
560:                        .getTypeName(uiComponentClass);
561:                Component swingComponent = finder.findComponent(name,
562:                        swingClasses, typeName);
563:                return (swingComponent == null) ? null : UIComponentFactory
564:                        .createUIComponent(swingComponent);
565:            }
566:
567:            private static UIComponent[] getComponents(ComponentFinder finder,
568:                    ComponentMatcher matcher) {
569:                Component[] components = finder.getComponents(matcher);
570:                return UIComponentFactory.createUIComponents(components);
571:            }
572:
573:            private static UIComponent[] getComponents(ComponentFinder finder,
574:                    Class uiComponentClass, String name) {
575:                Class[] swingClasses = UIComponentAnalyzer
576:                        .getSwingClasses(uiComponentClass);
577:                Component[] swingComponents = finder.getComponents(name,
578:                        swingClasses);
579:                return UIComponentFactory.createUIComponents(swingComponents);
580:            }
581:
582:            public Assertion containsUIComponent(final Class uicomponentClass) {
583:                return new Assertion() {
584:                    public void check() throws Exception {
585:                        UIComponent[] uiComponents = getUIComponents(uicomponentClass);
586:                        Assert.assertTrue(uiComponents.length > 0);
587:                    }
588:                };
589:            }
590:
591:            public Assertion containsSwingComponent(
592:                    final Class swingComponentClass) {
593:                return new Assertion() {
594:                    public void check() throws Exception {
595:                        Component[] swingComponents = getSwingComponents(swingComponentClass);
596:                        Assert.assertTrue(swingComponents.length > 0);
597:                    }
598:                };
599:            }
600:
601:            public Assertion containsUIComponent(final Class uiComponentClass,
602:                    final String name) {
603:                return new Assertion() {
604:                    public void check() throws Exception {
605:                        UIComponent[] uiComponents = getUIComponents(
606:                                uiComponentClass, name);
607:                        Assert.assertTrue(uiComponents.length > 0);
608:                    }
609:                };
610:            }
611:
612:            public Assertion containsSwingComponent(
613:                    final Class swingComponentClass, final String name) {
614:                return new Assertion() {
615:                    public void check() throws Exception {
616:                        Component[] swingComponents = getSwingComponents(
617:                                swingComponentClass, name);
618:                        Assert.assertTrue(swingComponents.length > 0);
619:                    }
620:                };
621:            }
622:
623:            public Assertion containsComponent(final ComponentMatcher matcher) {
624:                return new Assertion() {
625:                    public void check() throws Exception {
626:                        Assert
627:                                .assertTrue(getSwingComponents(matcher).length > 0);
628:                    }
629:                };
630:            }
631:
632:            /**
633:             * Checks that the panel contains a given non-editable text.
634:             * This method is mainly suited for checking displayed messages in popped-up dialogs.
635:             * NB: Only JLabel components are taken into account.
636:             */
637:            public Assertion containsLabel(final String text) {
638:                return new Assertion() {
639:                    public void check() throws Exception {
640:                        Component[] result = getSwingComponents(ComponentMatchers
641:                                .intersection(new ComponentMatcher[] {
642:                                        ComponentMatchers
643:                                                .fromClass(JLabel.class),
644:                                        ComponentMatchers
645:                                                .displayedNameSubstring(text) }));
646:                        if (result.length == 0) {
647:                            throw new AssertionFailedError(
648:                                    "No label found with text '" + text + "'");
649:                        }
650:                    }
651:                };
652:            }
653:
654:            private static ComponentMatcher getMatcherFromName(
655:                    String componentName) {
656:                return ComponentMatchers.union(new ComponentMatcher[] {
657:                        ComponentMatchers.innerNameIdentity(componentName),
658:                        ComponentMatchers.innerNameSubstring(componentName),
659:                        ComponentMatchers.innerNameRegexp(componentName) });
660:            }
661:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.