Source Code Cross Referenced for JLabelOperator.java in  » Testing » jemmy » org » netbeans » jemmy » operators » 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 » jemmy » org.netbeans.jemmy.operators 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s): Alexandre Iline.
025:         *
026:         * The Original Software is the Jemmy library.
027:         * The Initial Developer of the Original Software is Alexandre Iline.
028:         * All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         *
041:         *
042:         *
043:         * $Id: JLabelOperator.java,v 1.8 2007/10/05 11:35:52 jskrivanek Exp $ $Revision: 1.8 $ $Date: 2007/10/05 11:35:52 $
044:         *
045:         */
046:
047:        package org.netbeans.jemmy.operators;
048:
049:        import org.netbeans.jemmy.ComponentChooser;
050:        import org.netbeans.jemmy.ComponentSearcher;
051:        import org.netbeans.jemmy.TimeoutExpiredException;
052:
053:        import java.awt.Component;
054:        import java.awt.Container;
055:
056:        import java.util.Hashtable;
057:
058:        import javax.swing.Icon;
059:        import javax.swing.JLabel;
060:
061:        import javax.swing.plaf.LabelUI;
062:
063:        /**
064:         * <BR><BR>Timeouts used: <BR>
065:         * ComponentOperator.WaitComponentTimeout - time to wait component displayed <BR>
066:         * ComponentOperator.WaitStateTimeout - time to wait for text <BR>.
067:         *
068:         * @see org.netbeans.jemmy.Timeouts
069:         * @author Alexandre Iline (alexandre.iline@sun.com)
070:         *	
071:         */
072:
073:        public class JLabelOperator extends JComponentOperator {
074:
075:            /**
076:             * Identifier for a "text" property.
077:             * @see #getDump
078:             */
079:            public static final String TEXT_DPROP = "Text";
080:
081:            /**
082:             * Constructor.
083:             * @param b a component
084:             */
085:            public JLabelOperator(JLabel b) {
086:                super (b);
087:            }
088:
089:            /**
090:             * Constructs a JLabelOperator object.
091:             * @param cont a container
092:             * @param chooser a component chooser specifying searching criteria.
093:             * @param index an index between appropriate ones.
094:             */
095:            public JLabelOperator(ContainerOperator cont,
096:                    ComponentChooser chooser, int index) {
097:                this ((JLabel) cont.waitSubComponent(new JLabelFinder(chooser),
098:                        index));
099:                copyEnvironment(cont);
100:            }
101:
102:            /**
103:             * Constructs a JLabelOperator object.
104:             * @param cont a container
105:             * @param chooser a component chooser specifying searching criteria.
106:             */
107:            public JLabelOperator(ContainerOperator cont,
108:                    ComponentChooser chooser) {
109:                this (cont, chooser, 0);
110:            }
111:
112:            /**
113:             * Constructor.
114:             * Waits component in container first.
115:             * Uses cont's timeout and output for waiting and to init operator.
116:             * @param cont a container
117:             * @param text Button text. 
118:             * @param index Ordinal component index.
119:             * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
120:             * 
121:             */
122:            public JLabelOperator(ContainerOperator cont, String text, int index) {
123:                this ((JLabel) waitComponent(cont, new JLabelByLabelFinder(text,
124:                        cont.getComparator()), index));
125:                copyEnvironment(cont);
126:            }
127:
128:            /**
129:             * Constructor.
130:             * Waits component in container first.
131:             * Uses cont's timeout and output for waiting and to init operator.
132:             * @param cont a container
133:             * @param text Button text. 
134:             * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
135:             * 
136:             */
137:            public JLabelOperator(ContainerOperator cont, String text) {
138:                this (cont, text, 0);
139:            }
140:
141:            /**
142:             * Constructor.
143:             * Waits component in container first.
144:             * Uses cont's timeout and output for waiting and to init operator.
145:             * @param cont a container
146:             * @param index Ordinal component index.
147:             * 
148:             */
149:            public JLabelOperator(ContainerOperator cont, int index) {
150:                this ((JLabel) waitComponent(cont, new JLabelFinder(), index));
151:                copyEnvironment(cont);
152:            }
153:
154:            /**
155:             * Constructor.
156:             * Waits component in container first.
157:             * Uses cont's timeout and output for waiting and to init operator.
158:             * @param cont a container
159:             * 
160:             */
161:            public JLabelOperator(ContainerOperator cont) {
162:                this (cont, 0);
163:            }
164:
165:            /**
166:             * Searches JLabel in container.
167:             * @param cont Container to search component in.
168:             * @param chooser a component chooser specifying searching criteria.
169:             * @param index Ordinal component index.
170:             * @return JLabel instance or null if component was not found.
171:             */
172:            public static JLabel findJLabel(Container cont,
173:                    ComponentChooser chooser, int index) {
174:                return ((JLabel) findComponent(cont, new JLabelFinder(chooser),
175:                        index));
176:            }
177:
178:            /**
179:             * Searches JLabel in container.
180:             * @param cont Container to search component in.
181:             * @param chooser a component chooser specifying searching criteria.
182:             * @return JLabel instance or null if component was not found.
183:             */
184:            public static JLabel findJLabel(Container cont,
185:                    ComponentChooser chooser) {
186:                return (findJLabel(cont, chooser, 0));
187:            }
188:
189:            /**
190:             * Searches JLabel by text.
191:             * @param cont Container to search component in.
192:             * @param text Component text.
193:             * @param ce Compare text exactly.
194:             * @param ccs Compare text case sensitively.
195:             * @param index Ordinal component index.
196:             * @return JLabel instance or null if component was not found.
197:             * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
198:             */
199:            public static JLabel findJLabel(Container cont, String text,
200:                    boolean ce, boolean ccs, int index) {
201:                return (findJLabel(cont, new JLabelByLabelFinder(text,
202:                        new DefaultStringComparator(ce, ccs)), index));
203:            }
204:
205:            /**
206:             * Searches JLabel by text.
207:             * @param cont Container to search component in.
208:             * @param text Component text.
209:             * @param ce Compare text exactly.
210:             * @param ccs Compare text case sensitively.
211:             * @return JLabel instance or null if component was not found.
212:             * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
213:             */
214:            public static JLabel findJLabel(Container cont, String text,
215:                    boolean ce, boolean ccs) {
216:                return (findJLabel(cont, text, ce, ccs, 0));
217:            }
218:
219:            /**
220:             * Waits JLabel in container.
221:             * @param cont Container to search component in.
222:             * @param chooser a component chooser specifying searching criteria.
223:             * @param index Ordinal component index.
224:             * @return JLabel instance.
225:             * 
226:             */
227:            public static JLabel waitJLabel(final Container cont,
228:                    final ComponentChooser chooser, final int index) {
229:                return ((JLabel) waitComponent(cont, new JLabelFinder(chooser),
230:                        index));
231:            }
232:
233:            /**
234:             * Waits JLabel in container.
235:             * @param cont Container to search component in.
236:             * @param chooser a component chooser specifying searching criteria.
237:             * @return JLabel instance.
238:             * 
239:             */
240:            public static JLabel waitJLabel(Container cont,
241:                    ComponentChooser chooser) {
242:                return (waitJLabel(cont, chooser, 0));
243:            }
244:
245:            /**
246:             * Waits JLabel by text.
247:             * @param cont Container to search component in.
248:             * @param text Component text.
249:             * @param ce Compare text exactly.
250:             * @param ccs Compare text case sensitively.
251:             * @param index Ordinal component index.
252:             * @return JLabel instance.
253:             * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
254:             * 
255:             */
256:            public static JLabel waitJLabel(Container cont, String text,
257:                    boolean ce, boolean ccs, int index) {
258:                return (waitJLabel(cont, new JLabelByLabelFinder(text,
259:                        new DefaultStringComparator(ce, ccs)), index));
260:            }
261:
262:            /**
263:             * Waits JLabel by text.
264:             * @param cont Container to search component in.
265:             * @param text Component text.
266:             * @param ce Compare text exactly.
267:             * @param ccs Compare text case sensitively.
268:             * @return JLabel instance.
269:             * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
270:             * 
271:             */
272:            public static JLabel waitJLabel(Container cont, String text,
273:                    boolean ce, boolean ccs) {
274:                return (waitJLabel(cont, text, ce, ccs, 0));
275:            }
276:
277:            /**
278:             * Waits for text. Uses getComparator() comparator.
279:             * @param text Text to wait for.
280:             */
281:            public void waitText(String text) {
282:                getOutput().printLine(
283:                        "Wait \"" + text + "\" text in component \n    : "
284:                                + toStringSource());
285:                getOutput().printGolden("Wait \"" + text + "\" text");
286:                waitState(new JLabelByLabelFinder(text, getComparator()));
287:            }
288:
289:            /**
290:             * Returns information about component.
291:             */
292:            public Hashtable getDump() {
293:                Hashtable result = super .getDump();
294:                if (((JLabel) getSource()).getText() != null) {
295:                    result.put(TEXT_DPROP, ((JLabel) getSource()).getText());
296:                } else {
297:                    result.put(TEXT_DPROP, "null");
298:                }
299:                return (result);
300:            }
301:
302:            ////////////////////////////////////////////////////////
303:            //Mapping                                             //
304:
305:            /**Maps <code>JLabel.getDisabledIcon()</code> through queue*/
306:            public Icon getDisabledIcon() {
307:                return ((Icon) runMapping(new MapAction("getDisabledIcon") {
308:                    public Object map() {
309:                        return (((JLabel) getSource()).getDisabledIcon());
310:                    }
311:                }));
312:            }
313:
314:            /**Maps <code>JLabel.getDisplayedMnemonic()</code> through queue*/
315:            public int getDisplayedMnemonic() {
316:                return (runMapping(new MapIntegerAction("getDisplayedMnemonic") {
317:                    public int map() {
318:                        return (((JLabel) getSource()).getDisplayedMnemonic());
319:                    }
320:                }));
321:            }
322:
323:            /**Maps <code>JLabel.getHorizontalAlignment()</code> through queue*/
324:            public int getHorizontalAlignment() {
325:                return (runMapping(new MapIntegerAction(
326:                        "getHorizontalAlignment") {
327:                    public int map() {
328:                        return (((JLabel) getSource()).getHorizontalAlignment());
329:                    }
330:                }));
331:            }
332:
333:            /**Maps <code>JLabel.getHorizontalTextPosition()</code> through queue*/
334:            public int getHorizontalTextPosition() {
335:                return (runMapping(new MapIntegerAction(
336:                        "getHorizontalTextPosition") {
337:                    public int map() {
338:                        return (((JLabel) getSource())
339:                                .getHorizontalTextPosition());
340:                    }
341:                }));
342:            }
343:
344:            /**Maps <code>JLabel.getIcon()</code> through queue*/
345:            public Icon getIcon() {
346:                return ((Icon) runMapping(new MapAction("getIcon") {
347:                    public Object map() {
348:                        return (((JLabel) getSource()).getIcon());
349:                    }
350:                }));
351:            }
352:
353:            /**Maps <code>JLabel.getIconTextGap()</code> through queue*/
354:            public int getIconTextGap() {
355:                return (runMapping(new MapIntegerAction("getIconTextGap") {
356:                    public int map() {
357:                        return (((JLabel) getSource()).getIconTextGap());
358:                    }
359:                }));
360:            }
361:
362:            /**Maps <code>JLabel.getLabelFor()</code> through queue*/
363:            public Component getLabelFor() {
364:                return ((Component) runMapping(new MapAction("getLabelFor") {
365:                    public Object map() {
366:                        return (((JLabel) getSource()).getLabelFor());
367:                    }
368:                }));
369:            }
370:
371:            /**Maps <code>JLabel.getText()</code> through queue*/
372:            public String getText() {
373:                return ((String) runMapping(new MapAction("getText") {
374:                    public Object map() {
375:                        return (((JLabel) getSource()).getText());
376:                    }
377:                }));
378:            }
379:
380:            /**Maps <code>JLabel.getUI()</code> through queue*/
381:            public LabelUI getUI() {
382:                return ((LabelUI) runMapping(new MapAction("getUI") {
383:                    public Object map() {
384:                        return (((JLabel) getSource()).getUI());
385:                    }
386:                }));
387:            }
388:
389:            /**Maps <code>JLabel.getVerticalAlignment()</code> through queue*/
390:            public int getVerticalAlignment() {
391:                return (runMapping(new MapIntegerAction("getVerticalAlignment") {
392:                    public int map() {
393:                        return (((JLabel) getSource()).getVerticalAlignment());
394:                    }
395:                }));
396:            }
397:
398:            /**Maps <code>JLabel.getVerticalTextPosition()</code> through queue*/
399:            public int getVerticalTextPosition() {
400:                return (runMapping(new MapIntegerAction(
401:                        "getVerticalTextPosition") {
402:                    public int map() {
403:                        return (((JLabel) getSource())
404:                                .getVerticalTextPosition());
405:                    }
406:                }));
407:            }
408:
409:            /**Maps <code>JLabel.setDisabledIcon(Icon)</code> through queue*/
410:            public void setDisabledIcon(final Icon icon) {
411:                runMapping(new MapVoidAction("setDisabledIcon") {
412:                    public void map() {
413:                        ((JLabel) getSource()).setDisabledIcon(icon);
414:                    }
415:                });
416:            }
417:
418:            /**Maps <code>JLabel.setDisplayedMnemonic(char)</code> through queue*/
419:            public void setDisplayedMnemonic(final char c) {
420:                runMapping(new MapVoidAction("setDisplayedMnemonic") {
421:                    public void map() {
422:                        ((JLabel) getSource()).setDisplayedMnemonic(c);
423:                    }
424:                });
425:            }
426:
427:            /**Maps <code>JLabel.setDisplayedMnemonic(int)</code> through queue*/
428:            public void setDisplayedMnemonic(final int i) {
429:                runMapping(new MapVoidAction("setDisplayedMnemonic") {
430:                    public void map() {
431:                        ((JLabel) getSource()).setDisplayedMnemonic(i);
432:                    }
433:                });
434:            }
435:
436:            /**Maps <code>JLabel.setHorizontalAlignment(int)</code> through queue*/
437:            public void setHorizontalAlignment(final int i) {
438:                runMapping(new MapVoidAction("setHorizontalAlignment") {
439:                    public void map() {
440:                        ((JLabel) getSource()).setHorizontalAlignment(i);
441:                    }
442:                });
443:            }
444:
445:            /**Maps <code>JLabel.setHorizontalTextPosition(int)</code> through queue*/
446:            public void setHorizontalTextPosition(final int i) {
447:                runMapping(new MapVoidAction("setHorizontalTextPosition") {
448:                    public void map() {
449:                        ((JLabel) getSource()).setHorizontalTextPosition(i);
450:                    }
451:                });
452:            }
453:
454:            /**Maps <code>JLabel.setIcon(Icon)</code> through queue*/
455:            public void setIcon(final Icon icon) {
456:                runMapping(new MapVoidAction("setIcon") {
457:                    public void map() {
458:                        ((JLabel) getSource()).setIcon(icon);
459:                    }
460:                });
461:            }
462:
463:            /**Maps <code>JLabel.setIconTextGap(int)</code> through queue*/
464:            public void setIconTextGap(final int i) {
465:                runMapping(new MapVoidAction("setIconTextGap") {
466:                    public void map() {
467:                        ((JLabel) getSource()).setIconTextGap(i);
468:                    }
469:                });
470:            }
471:
472:            /**Maps <code>JLabel.setLabelFor(Component)</code> through queue*/
473:            public void setLabelFor(final Component component) {
474:                runMapping(new MapVoidAction("setLabelFor") {
475:                    public void map() {
476:                        ((JLabel) getSource()).setLabelFor(component);
477:                    }
478:                });
479:            }
480:
481:            /**Maps <code>JLabel.setText(String)</code> through queue*/
482:            public void setText(final String string) {
483:                runMapping(new MapVoidAction("setText") {
484:                    public void map() {
485:                        ((JLabel) getSource()).setText(string);
486:                    }
487:                });
488:            }
489:
490:            /**Maps <code>JLabel.setUI(LabelUI)</code> through queue*/
491:            public void setUI(final LabelUI labelUI) {
492:                runMapping(new MapVoidAction("setUI") {
493:                    public void map() {
494:                        ((JLabel) getSource()).setUI(labelUI);
495:                    }
496:                });
497:            }
498:
499:            /**Maps <code>JLabel.setVerticalAlignment(int)</code> through queue*/
500:            public void setVerticalAlignment(final int i) {
501:                runMapping(new MapVoidAction("setVerticalAlignment") {
502:                    public void map() {
503:                        ((JLabel) getSource()).setVerticalAlignment(i);
504:                    }
505:                });
506:            }
507:
508:            /**Maps <code>JLabel.setVerticalTextPosition(int)</code> through queue*/
509:            public void setVerticalTextPosition(final int i) {
510:                runMapping(new MapVoidAction("setVerticalTextPosition") {
511:                    public void map() {
512:                        ((JLabel) getSource()).setVerticalTextPosition(i);
513:                    }
514:                });
515:            }
516:
517:            //End of mapping                                      //
518:            ////////////////////////////////////////////////////////
519:
520:            /**
521:             * Allows to find component by text.
522:             */
523:            public static class JLabelByLabelFinder implements  ComponentChooser {
524:                String label;
525:                StringComparator comparator;
526:
527:                /**
528:                 * Constructs JLabelByLabelFinder.
529:                 * @param lb a text pattern
530:                 * @param comparator specifies string comparision algorithm.
531:                 */
532:                public JLabelByLabelFinder(String lb,
533:                        StringComparator comparator) {
534:                    label = lb;
535:                    this .comparator = comparator;
536:                }
537:
538:                /**
539:                 * Constructs JLabelByLabelFinder.
540:                 * @param lb a text pattern
541:                 */
542:                public JLabelByLabelFinder(String lb) {
543:                    this (lb, Operator.getDefaultStringComparator());
544:                }
545:
546:                public boolean checkComponent(Component comp) {
547:                    if (comp instanceof  JLabel) {
548:                        if (((JLabel) comp).getText() != null) {
549:                            return (comparator.equals(
550:                                    ((JLabel) comp).getText(), label));
551:                        }
552:                    }
553:                    return (false);
554:                }
555:
556:                public String getDescription() {
557:                    return ("JLabel with text \"" + label + "\"");
558:                }
559:            }
560:
561:            /**
562:             * Checks component type.
563:             */
564:            public static class JLabelFinder extends Finder {
565:                /**
566:                 * Constructs JLabelFinder.
567:                 * @param sf other searching criteria.
568:                 */
569:                public JLabelFinder(ComponentChooser sf) {
570:                    super (JLabel.class, sf);
571:                }
572:
573:                /**
574:                 * Constructs JLabelFinder.
575:                 */
576:                public JLabelFinder() {
577:                    super (JLabel.class);
578:                }
579:            }
580:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.