1 /*
2  * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation. Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 package org.netbeans.jemmy.operators;
26 
27 import java.awt.Component;
28 import java.awt.Container;
29 import java.awt.Dimension;
30 import java.awt.Insets;
31 import java.awt.Point;
32 import java.awt.Rectangle;
33 import java.awt.Window;
34 import java.awt.event.ActionListener;
35 import java.awt.event.MouseEvent;
36 import java.beans.VetoableChangeListener;
37 import java.util.Hashtable;
38 
39 import javax.accessibility.AccessibleContext;
40 import javax.swing.JComponent;
41 import javax.swing.JInternalFrame;
42 import javax.swing.JRootPane;
43 import javax.swing.JToolTip;
44 import javax.swing.KeyStroke;
45 import javax.swing.border.Border;
46 import javax.swing.event.AncestorListener;
47 
48 import org.netbeans.jemmy.ComponentChooser;
49 import org.netbeans.jemmy.ComponentSearcher;
50 import org.netbeans.jemmy.Outputable;
51 import org.netbeans.jemmy.TestOut;
52 import org.netbeans.jemmy.TimeoutExpiredException;
53 import org.netbeans.jemmy.Timeoutable;
54 import org.netbeans.jemmy.Timeouts;
55 
56 /**
57  * <BR><BR>Timeouts used: <BR>
58  * JComponentOperator.WaitToolTipTimeout - time to wait tool tip displayed <BR>
59  * JComponentOperator.ShowToolTipTimeout - time to show tool tip <BR>
60  * ComponentOperator.WaitComponentTimeout - time to wait component displayed
61  * <BR>.
62  *
63  * @see org.netbeans.jemmy.Timeouts
64  *
65  * @author Alexandre Iline (alexandre.iline@oracle.com)
66  *
67  */
68 public class JComponentOperator extends ContainerOperator<Container>
69         implements Timeoutable, Outputable {
70 
71     /**
72      * Identifier for a "tooltip text" property.
73      *
74      * @see #getDump
75      */
76     public static final String TOOLTIP_TEXT_DPROP = "Tooltip text";
77     public static final String A11Y_DATA = "Accessible data (yes/no)";
78     public static final String A11Y_NAME_DPROP = "Accessible name";
79     public static final String A11Y_DESCRIPTION_DPROP = "Accessible decription";
80 
81     private final static long WAIT_TOOL_TIP_TIMEOUT = 10000;
82     private final static long SHOW_TOOL_TIP_TIMEOUT = 0;
83 
84     private Timeouts timeouts;
85     private TestOut output;
86 
87     /**
88      * Constructor.
89      *
90      * @param b a component
91      */
JComponentOperator(JComponent b)92     public JComponentOperator(JComponent b) {
93         super(b);
94     }
95 
96     /**
97      * Constructs a JComponentOperator object.
98      *
99      * @param cont a container
100      * @param chooser a component chooser specifying searching criteria.
101      * @param index an index between appropriate ones.
102      */
JComponentOperator(ContainerOperator<?> cont, ComponentChooser chooser, int index)103     public JComponentOperator(ContainerOperator<?> cont, ComponentChooser chooser, int index) {
104         this((JComponent) cont.
105                 waitSubComponent(new JComponentFinder(chooser),
106                         index));
107         copyEnvironment(cont);
108     }
109 
110     /**
111      * Constructs a JComponentOperator object.
112      *
113      * @param cont a container
114      * @param chooser a component chooser specifying searching criteria.
115      */
JComponentOperator(ContainerOperator<?> cont, ComponentChooser chooser)116     public JComponentOperator(ContainerOperator<?> cont, ComponentChooser chooser) {
117         this(cont, chooser, 0);
118     }
119 
120     /**
121      * Constructor. Waits component in container first. Uses cont's timeout and
122      * output for waiting and to init operator.
123      *
124      * @param cont Operator pointing a container to search component in.
125      * @param index Ordinal component index.
126      * @throws TimeoutExpiredException
127      */
JComponentOperator(ContainerOperator<?> cont, int index)128     public JComponentOperator(ContainerOperator<?> cont, int index) {
129         this((JComponent) waitComponent(cont,
130                 new JComponentFinder(ComponentSearcher.getTrueChooser("Any JComponent")),
131                 index));
132         copyEnvironment(cont);
133     }
134 
135     /**
136      * Constructor. Waits component in container first. Uses cont's timeout and
137      * output for waiting and to init operator.
138      *
139      * @param cont Operator pointing a container to search component in.
140      * @throws TimeoutExpiredException
141      */
JComponentOperator(ContainerOperator<?> cont)142     public JComponentOperator(ContainerOperator<?> cont) {
143         this(cont, 0);
144     }
145 
146     /**
147      * Searches JComponent in container.
148      *
149      * @param cont Container to search component in.
150      * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
151      * @param index Ordinal component index.
152      * @return JComponent instance or null if component was not found.
153      */
findJComponent(Container cont, ComponentChooser chooser, int index)154     public static JComponent findJComponent(Container cont, ComponentChooser chooser, int index) {
155         return (JComponent) findComponent(cont, new JComponentFinder(chooser), index);
156     }
157 
158     /**
159      * Searches 0'th JComponent in container.
160      *
161      * @param cont Container to search component in.
162      * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
163      * @return JComponent instance or null if component was not found.
164      */
findJComponent(Container cont, ComponentChooser chooser)165     public static JComponent findJComponent(Container cont, ComponentChooser chooser) {
166         return findJComponent(cont, chooser, 0);
167     }
168 
169     /**
170      * Searches JComponent by tooltip text.
171      *
172      * @param cont Container to search component in.
173      * @param toolTipText Tooltip text. If null, contents is not checked.
174      * @param ce Compare text exactly.
175      * @param ccs Compare text case sensitively.
176      * @param index Ordinal component index.
177      * @return JComponent instance or null if component was not found.
178      * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
179      */
findJComponent(Container cont, String toolTipText, boolean ce, boolean ccs, int index)180     public static JComponent findJComponent(Container cont, String toolTipText, boolean ce, boolean ccs, int index) {
181         return findJComponent(cont, new JComponentByTipFinder(toolTipText, new DefaultStringComparator(ce, ccs)), index);
182     }
183 
184     /**
185      * Searches JComponent by tooltip text.
186      *
187      * @param cont Container to search component in.
188      * @param toolTipText Tooltip text. If null, contents is not checked.
189      * @param ce Compare text exactly.
190      * @param ccs Compare text case sensitively.
191      * @return JComponent instance or null if component was not found.
192      * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
193      */
findJComponent(Container cont, String toolTipText, boolean ce, boolean ccs)194     public static JComponent findJComponent(Container cont, String toolTipText, boolean ce, boolean ccs) {
195         return findJComponent(cont, toolTipText, ce, ccs, 0);
196     }
197 
198     /**
199      * Waits JComponent in container.
200      *
201      * @param cont Container to search component in.
202      * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
203      * @param index Ordinal component index.
204      * @return JComponent instance or null if component was not found.
205      * @throws TimeoutExpiredException
206      */
waitJComponent(Container cont, ComponentChooser chooser, final int index)207     public static JComponent waitJComponent(Container cont, ComponentChooser chooser, final int index) {
208         return (JComponent) waitComponent(cont, new JComponentFinder(chooser), index);
209     }
210 
211     /**
212      * Waits 0'th JComponent in container.
213      *
214      * @param cont Container to search component in.
215      * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
216      * @return JComponent instance or null if component was not found.
217      * @throws TimeoutExpiredException
218      */
waitJComponent(Container cont, ComponentChooser chooser)219     public static JComponent waitJComponent(Container cont, ComponentChooser chooser) {
220         return waitJComponent(cont, chooser, 0);
221     }
222 
223     /**
224      * Waits JComponent by tooltip text.
225      *
226      * @param cont Container to search component in.
227      * @param toolTipText Tooltip text. If null, contents is not checked.
228      * @param ce Compare text exactly.
229      * @param ccs Compare text case sensitively.
230      * @param index Ordinal component index.
231      * @return JComponent instance or null if component was not found.
232      * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
233      * @throws TimeoutExpiredException
234      */
waitJComponent(Container cont, String toolTipText, boolean ce, boolean ccs, int index)235     public static JComponent waitJComponent(Container cont, String toolTipText, boolean ce, boolean ccs, int index) {
236         return waitJComponent(cont, new JComponentByTipFinder(toolTipText, new DefaultStringComparator(ce, ccs)), index);
237     }
238 
239     /**
240      * Waits JComponent by tooltip text.
241      *
242      * @param cont Container to search component in.
243      * @param toolTipText Tooltip text. If null, contents is not checked.
244      * @param ce Compare text exactly.
245      * @param ccs Compare text case sensitively.
246      * @return JComponent instance or null if component was not found.
247      * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
248      * @throws TimeoutExpiredException
249      */
waitJComponent(Container cont, String toolTipText, boolean ce, boolean ccs)250     public static JComponent waitJComponent(Container cont, String toolTipText, boolean ce, boolean ccs) {
251         return waitJComponent(cont, toolTipText, ce, ccs, 0);
252     }
253 
254     static {
255         Timeouts.initDefault("JComponentOperator.WaitToolTipTimeout", WAIT_TOOL_TIP_TIMEOUT);
256         Timeouts.initDefault("JComponentOperator.ShowToolTipTimeout", SHOW_TOOL_TIP_TIMEOUT);
257     }
258 
259     @Override
setTimeouts(Timeouts timeouts)260     public void setTimeouts(Timeouts timeouts) {
261         super.setTimeouts(timeouts);
262         this.timeouts = timeouts;
263     }
264 
265     @Override
getTimeouts()266     public Timeouts getTimeouts() {
267         return timeouts;
268     }
269 
270     @Override
setOutput(TestOut out)271     public void setOutput(TestOut out) {
272         output = out;
273         super.setOutput(output.createErrorOutput());
274     }
275 
276     @Override
getOutput()277     public TestOut getOutput() {
278         return output;
279     }
280 
281     @Override
getCenterXForClick()282     public int getCenterXForClick() {
283         Rectangle rect = getVisibleRect();
284         return ((int) rect.getX()
285                 + (int) rect.getWidth() / 2);
286     }
287 
288     @Override
getCenterYForClick()289     public int getCenterYForClick() {
290         Rectangle rect = getVisibleRect();
291         return ((int) rect.getY()
292                 + (int) rect.getHeight() / 2);
293     }
294 
295     /**
296      * Showes tool tip.
297      *
298      * @return JToolTip component.
299      * @throws TimeoutExpiredException
300      */
showToolTip()301     public JToolTip showToolTip() {
302         enterMouse();
303         moveMouse(getCenterXForClick(),
304                 getCenterYForClick());
305         return waitToolTip();
306     }
307 
waitToolTip()308     public JToolTip waitToolTip() {
309         return JToolTipOperator.waitJToolTip(this);
310     }
311 
312     /**
313      * Looks for a first window-like container.
314      *
315      * @return either WindowOperator of JInternalFrameOperator
316      */
getWindowContainerOperator()317     public ContainerOperator<?> getWindowContainerOperator() {
318         Component resultComp;
319         if (getSource() instanceof Window) {
320             resultComp = getSource();
321         } else {
322             resultComp = getContainer(new ComponentChooser() {
323                 @Override
324                 public boolean checkComponent(Component comp) {
325                     return (comp instanceof Window
326                             || comp instanceof JInternalFrame);
327                 }
328 
329                 @Override
330                 public String getDescription() {
331                     return "";
332                 }
333             });
334         }
335         ContainerOperator<?> result;
336         if (resultComp instanceof Window) {
337             result = new WindowOperator((Window) resultComp);
338         } else {
339             result = new ContainerOperator<>((Container) resultComp);
340         }
341         result.copyEnvironment(this);
342         return result;
343     }
344 
345     @Override
getDump()346     public Hashtable<String, Object> getDump() {
347         Hashtable<String, Object> result = super.getDump();
348         if (getToolTipText() != null) {
349             result.put(TOOLTIP_TEXT_DPROP, getToolTipText());
350         }
351         //System.out.println("Dump a11y = " + System.getProperty("jemmy.dump.a11y"));
352         if (System.getProperty("jemmy.dump.a11y") != null
353                 && System.getProperty("jemmy.dump.a11y").equals("on")) {
354             AccessibleContext a11y = getSource().getAccessibleContext();
355             if (a11y != null) {
356                 result.put(A11Y_DATA, "yes");
357                 String accName = (a11y.getAccessibleName() == null) ? "null" : a11y.getAccessibleName();
358                 String accDesc = (a11y.getAccessibleDescription() == null) ? "null" : a11y.getAccessibleDescription();
359                 result.put(A11Y_NAME_DPROP, accName);
360                 result.put(A11Y_DESCRIPTION_DPROP, accDesc);
361             } else {
362                 result.put(A11Y_DATA, "no");
363             }
364         }
365         return result;
366     }
367 
368     ////////////////////////////////////////////////////////
369     //Mapping                                             //
370     /**
371      * Maps {@code JComponent.addAncestorListener(AncestorListener)}
372      * through queue
373      */
addAncestorListener(final AncestorListener ancestorListener)374     public void addAncestorListener(final AncestorListener ancestorListener) {
375         runMapping(new MapVoidAction("addAncestorListener") {
376             @Override
377             public void map() {
378                 ((JComponent) getSource()).addAncestorListener(ancestorListener);
379             }
380         });
381     }
382 
383     /**
384      * Maps
385      * {@code JComponent.addVetoableChangeListener(VetoableChangeListener)}
386      * through queue
387      */
addVetoableChangeListener(final VetoableChangeListener vetoableChangeListener)388     public void addVetoableChangeListener(final VetoableChangeListener vetoableChangeListener) {
389         runMapping(new MapVoidAction("addVetoableChangeListener") {
390             @Override
391             public void map() {
392                 ((JComponent) getSource()).addVetoableChangeListener(vetoableChangeListener);
393             }
394         });
395     }
396 
397     /**
398      * Maps {@code JComponent.computeVisibleRect(Rectangle)} through queue
399      */
computeVisibleRect(final Rectangle rectangle)400     public void computeVisibleRect(final Rectangle rectangle) {
401         runMapping(new MapVoidAction("computeVisibleRect") {
402             @Override
403             public void map() {
404                 ((JComponent) getSource()).computeVisibleRect(rectangle);
405             }
406         });
407     }
408 
409     /**
410      * Maps {@code JComponent.createToolTip()} through queue
411      */
createToolTip()412     public JToolTip createToolTip() {
413         return (runMapping(new MapAction<JToolTip>("createToolTip") {
414             @Override
415             public JToolTip map() {
416                 return ((JComponent) getSource()).createToolTip();
417             }
418         }));
419     }
420 
421     /**
422      * Maps {@code JComponent.firePropertyChange(String, byte, byte)}
423      * through queue
424      */
425     public void firePropertyChange(final String string, final byte b, final byte b1) {
426         runMapping(new MapVoidAction("firePropertyChange") {
427             @Override
428             public void map() {
429                 getSource().firePropertyChange(string, b, b1);
430             }
431         });
432     }
433 
434     /**
435      * Maps {@code JComponent.firePropertyChange(String, char, char)}
436      * through queue
437      */
438     public void firePropertyChange(final String string, final char c, final char c1) {
439         runMapping(new MapVoidAction("firePropertyChange") {
440             @Override
441             public void map() {
442                 getSource().firePropertyChange(string, c, c1);
443             }
444         });
445     }
446 
447     /**
448      * Maps {@code JComponent.firePropertyChange(String, double, double)}
449      * through queue
450      */
451     public void firePropertyChange(final String string, final double d, final double d1) {
452         runMapping(new MapVoidAction("firePropertyChange") {
453             @Override
454             public void map() {
455                 getSource().firePropertyChange(string, d, d1);
456             }
457         });
458     }
459 
460     /**
461      * Maps {@code JComponent.firePropertyChange(String, float, float)}
462      * through queue
463      */
464     public void firePropertyChange(final String string, final float f, final float f1) {
465         runMapping(new MapVoidAction("firePropertyChange") {
466             @Override
467             public void map() {
468                 getSource().firePropertyChange(string, f, f1);
469             }
470         });
471     }
472 
473     /**
474      * Maps {@code JComponent.firePropertyChange(String, int, int)} through queue
475      */
476     public void firePropertyChange(final String string, final int i, final int i1) {
477         runMapping(new MapVoidAction("firePropertyChange") {
478             @Override
479             public void map() {
480                 ((JComponent) getSource()).firePropertyChange(string, i, i1);
481             }
482         });
483     }
484 
485     /**
486      * Maps {@code JComponent.firePropertyChange(String, long, long)}
487      * through queue
488      */
489     public void firePropertyChange(final String string, final long l, final long l1) {
490         runMapping(new MapVoidAction("firePropertyChange") {
491             @Override
492             public void map() {
493                 getSource().firePropertyChange(string, l, l1);
494             }
495         });
496     }
497 
498     /**
499      * Maps {@code JComponent.firePropertyChange(String, short, short)}
500      * through queue
501      */
502     public void firePropertyChange(final String string, final short s, final short s1) {
503         runMapping(new MapVoidAction("firePropertyChange") {
504             @Override
505             public void map() {
506                 getSource().firePropertyChange(string, s, s1);
507             }
508         });
509     }
510 
511     /**
512      * Maps {@code JComponent.firePropertyChange(String, boolean, boolean)}
513      * through queue
514      */
515     public void firePropertyChange(final String string, final boolean b, final boolean b1) {
516         runMapping(new MapVoidAction("firePropertyChange") {
517             @Override
518             public void map() {
519                 ((JComponent) getSource()).firePropertyChange(string, b, b1);
520             }
521         });
522     }
523 
524     /**
525      * Maps {@code JComponent.getAccessibleContext()} through queue
526      */
527     public AccessibleContext getAccessibleContext() {
528         return (runMapping(new MapAction<AccessibleContext>("getAccessibleContext") {
529             @Override
530             public AccessibleContext map() {
531                 return getSource().getAccessibleContext();
532             }
533         }));
534     }
535 
536     /**
537      * Maps {@code JComponent.getActionForKeyStroke(KeyStroke)} through queue
538      */
539     public ActionListener getActionForKeyStroke(final KeyStroke keyStroke) {
540         return (runMapping(new MapAction<ActionListener>("getActionForKeyStroke") {
541             @Override
542             public ActionListener map() {
543                 return ((JComponent) getSource()).getActionForKeyStroke(keyStroke);
544             }
545         }));
546     }
547 
548     /**
549      * Maps {@code JComponent.getAutoscrolls()} through queue
550      */
551     public boolean getAutoscrolls() {
552         return (runMapping(new MapBooleanAction("getAutoscrolls") {
553             @Override
554             public boolean map() {
555                 return ((JComponent) getSource()).getAutoscrolls();
556             }
557         }));
558     }
559 
560     /**
561      * Maps {@code JComponent.getBorder()} through queue
562      */
563     public Border getBorder() {
564         return (runMapping(new MapAction<Border>("getBorder") {
565             @Override
566             public Border map() {
567                 return ((JComponent) getSource()).getBorder();
568             }
569         }));
570     }
571 
572     /**
573      * Maps {@code JComponent.getClientProperty(Object)} through queue
574      */
575     public Object getClientProperty(final Object object) {
576         return (runMapping(new MapAction<Object>("getClientProperty") {
577             @Override
578             public Object map() {
579                 return ((JComponent) getSource()).getClientProperty(object);
580             }
581         }));
582     }
583 
584     /**
585      * Maps {@code JComponent.getConditionForKeyStroke(KeyStroke)} through queue
586      */
587     public int getConditionForKeyStroke(final KeyStroke keyStroke) {
588         return (runMapping(new MapIntegerAction("getConditionForKeyStroke") {
589             @Override
590             public int map() {
591                 return ((JComponent) getSource()).getConditionForKeyStroke(keyStroke);
592             }
593         }));
594     }
595 
596     /**
597      * Maps {@code JComponent.getDebugGraphicsOptions()} through queue
598      */
599     public int getDebugGraphicsOptions() {
600         return (runMapping(new MapIntegerAction("getDebugGraphicsOptions") {
601             @Override
602             public int map() {
603                 return ((JComponent) getSource()).getDebugGraphicsOptions();
604             }
605         }));
606     }
607 
608     /**
609      * Maps {@code JComponent.getInsets(Insets)} through queue
610      */
611     public Insets getInsets(final Insets insets) {
612         return (runMapping(new MapAction<Insets>("getInsets") {
613             @Override
614             public Insets map() {
615                 return ((JComponent) getSource()).getInsets(insets);
616             }
617         }));
618     }
619 
620     /**
621      * Maps {@code JComponent.getNextFocusableComponent()} through queue
622      */
623     @Deprecated
624     public Component getNextFocusableComponent() {
625         return (runMapping(new MapAction<Component>("getNextFocusableComponent") {
626             @Override
627             public Component map() {
628                 return ((JComponent) getSource()).getNextFocusableComponent();
629             }
630         }));
631     }
632 
633     /**
634      * Maps {@code JComponent.getRegisteredKeyStrokes()} through queue
635      */
636     public KeyStroke[] getRegisteredKeyStrokes() {
637         return ((KeyStroke[]) runMapping(new MapAction<Object>("getRegisteredKeyStrokes") {
638             @Override
639             public Object map() {
640                 return ((JComponent) getSource()).getRegisteredKeyStrokes();
641             }
642         }));
643     }
644 
645     /**
646      * Maps {@code JComponent.getRootPane()} through queue
647      */
648     public JRootPane getRootPane() {
649         return (runMapping(new MapAction<JRootPane>("getRootPane") {
650             @Override
651             public JRootPane map() {
652                 return ((JComponent) getSource()).getRootPane();
653             }
654         }));
655     }
656 
657     /**
658      * Maps {@code JComponent.getToolTipLocation(MouseEvent)} through queue
659      */
660     public Point getToolTipLocation(final MouseEvent mouseEvent) {
661         return (runMapping(new MapAction<Point>("getToolTipLocation") {
662             @Override
663             public Point map() {
664                 return ((JComponent) getSource()).getToolTipLocation(mouseEvent);
665             }
666         }));
667     }
668 
669     /**
670      * Maps {@code JComponent.getToolTipText()} through queue
671      */
672     public String getToolTipText() {
673         return (runMapping(new MapAction<String>("getToolTipText") {
674             @Override
675             public String map() {
676                 return ((JComponent) getSource()).getToolTipText();
677             }
678         }));
679     }
680 
681     /**
682      * Maps {@code JComponent.getToolTipText(MouseEvent)} through queue
683      */
684     public String getToolTipText(final MouseEvent mouseEvent) {
685         return (runMapping(new MapAction<String>("getToolTipText") {
686             @Override
687             public String map() {
688                 return ((JComponent) getSource()).getToolTipText(mouseEvent);
689             }
690         }));
691     }
692 
693     /**
694      * Maps {@code JComponent.getTopLevelAncestor()} through queue
695      */
696     public Container getTopLevelAncestor() {
697         return (runMapping(new MapAction<Container>("getTopLevelAncestor") {
698             @Override
699             public Container map() {
700                 return ((JComponent) getSource()).getTopLevelAncestor();
701             }
702         }));
703     }
704 
705     /**
706      * Maps {@code JComponent.getUIClassID()} through queue
707      */
708     public String getUIClassID() {
709         return (runMapping(new MapAction<String>("getUIClassID") {
710             @Override
711             public String map() {
712                 return ((JComponent) getSource()).getUIClassID();
713             }
714         }));
715     }
716 
717     /**
718      * Maps {@code JComponent.getVisibleRect()} through queue
719      */
720     public Rectangle getVisibleRect() {
721         return (runMapping(new MapAction<Rectangle>("getVisibleRect") {
722             @Override
723             public Rectangle map() {
724                 return ((JComponent) getSource()).getVisibleRect();
725             }
726         }));
727     }
728 
729     /**
730      * Maps {@code JComponent.grabFocus()} through queue
731      */
732     public void grabFocus() {
733         runMapping(new MapVoidAction("grabFocus") {
734             @Override
735             public void map() {
736                 ((JComponent) getSource()).grabFocus();
737             }
738         });
739     }
740 
741     /**
742      * Maps {@code JComponent.isFocusCycleRoot()} through queue
743      */
744     public boolean isFocusCycleRoot() {
745         return (runMapping(new MapBooleanAction("isFocusCycleRoot") {
746             @Override
747             public boolean map() {
748                 return ((JComponent) getSource()).isFocusCycleRoot();
749             }
750         }));
751     }
752 
753     /**
754      * Maps {@code JComponent.isManagingFocus()} through queue
755      */
756     @Deprecated
757     public boolean isManagingFocus() {
758         return (runMapping(new MapBooleanAction("isManagingFocus") {
759             @Override
760             public boolean map() {
761                 return ((JComponent) getSource()).isManagingFocus();
762             }
763         }));
764     }
765 
766     /**
767      * Maps {@code JComponent.isOptimizedDrawingEnabled()} through queue
768      */
769     public boolean isOptimizedDrawingEnabled() {
770         return (runMapping(new MapBooleanAction("isOptimizedDrawingEnabled") {
771             @Override
772             public boolean map() {
773                 return ((JComponent) getSource()).isOptimizedDrawingEnabled();
774             }
775         }));
776     }
777 
778     /**
779      * Maps {@code JComponent.isPaintingTile()} through queue
780      */
781     public boolean isPaintingTile() {
782         return (runMapping(new MapBooleanAction("isPaintingTile") {
783             @Override
784             public boolean map() {
785                 return ((JComponent) getSource()).isPaintingTile();
786             }
787         }));
788     }
789 
790     /**
791      * Maps {@code JComponent.isRequestFocusEnabled()} through queue
792      */
793     public boolean isRequestFocusEnabled() {
794         return (runMapping(new MapBooleanAction("isRequestFocusEnabled") {
795             @Override
796             public boolean map() {
797                 return ((JComponent) getSource()).isRequestFocusEnabled();
798             }
799         }));
800     }
801 
802     /**
803      * Maps {@code JComponent.isValidateRoot()} through queue
804      */
805     public boolean isValidateRoot() {
806         return (runMapping(new MapBooleanAction("isValidateRoot") {
807             @Override
808             public boolean map() {
809                 return ((JComponent) getSource()).isValidateRoot();
810             }
811         }));
812     }
813 
814     /**
815      * Maps {@code JComponent.paintImmediately(int, int, int, int)} through queue
816      */
817     public void paintImmediately(final int i, final int i1, final int i2, final int i3) {
818         runMapping(new MapVoidAction("paintImmediately") {
819             @Override
820             public void map() {
821                 ((JComponent) getSource()).paintImmediately(i, i1, i2, i3);
822             }
823         });
824     }
825 
826     /**
827      * Maps {@code JComponent.paintImmediately(Rectangle)} through queue
828      */
829     public void paintImmediately(final Rectangle rectangle) {
830         runMapping(new MapVoidAction("paintImmediately") {
831             @Override
832             public void map() {
833                 ((JComponent) getSource()).paintImmediately(rectangle);
834             }
835         });
836     }
837 
838     /**
839      * Maps {@code JComponent.putClientProperty(Object, Object)} through queue
840      */
841     public void putClientProperty(final Object object, final Object object1) {
842         runMapping(new MapVoidAction("putClientProperty") {
843             @Override
844             public void map() {
845                 ((JComponent) getSource()).putClientProperty(object, object1);
846             }
847         });
848     }
849 
850     /**
851      * Maps
852      * {@code JComponent.registerKeyboardAction(ActionListener, String, KeyStroke, int)}
853      * through queue
854      */
855     public void registerKeyboardAction(final ActionListener actionListener, final String string, final KeyStroke keyStroke, final int i) {
856         runMapping(new MapVoidAction("registerKeyboardAction") {
857             @Override
858             public void map() {
859                 ((JComponent) getSource()).registerKeyboardAction(actionListener, string, keyStroke, i);
860             }
861         });
862     }
863 
864     /**
865      * Maps
866      * {@code JComponent.registerKeyboardAction(ActionListener, KeyStroke, int)}
867      * through queue
868      */
869     public void registerKeyboardAction(final ActionListener actionListener, final KeyStroke keyStroke, final int i) {
870         runMapping(new MapVoidAction("registerKeyboardAction") {
871             @Override
872             public void map() {
873                 ((JComponent) getSource()).registerKeyboardAction(actionListener, keyStroke, i);
874             }
875         });
876     }
877 
878     /**
879      * Maps {@code JComponent.removeAncestorListener(AncestorListener)}
880      * through queue
881      */
882     public void removeAncestorListener(final AncestorListener ancestorListener) {
883         runMapping(new MapVoidAction("removeAncestorListener") {
884             @Override
885             public void map() {
886                 ((JComponent) getSource()).removeAncestorListener(ancestorListener);
887             }
888         });
889     }
890 
891     /**
892      * Maps
893      * {@code JComponent.removeVetoableChangeListener(VetoableChangeListener)}
894      * through queue
895      */
896     public void removeVetoableChangeListener(final VetoableChangeListener vetoableChangeListener) {
897         runMapping(new MapVoidAction("removeVetoableChangeListener") {
898             @Override
899             public void map() {
900                 ((JComponent) getSource()).removeVetoableChangeListener(vetoableChangeListener);
901             }
902         });
903     }
904 
905     /**
906      * Maps {@code JComponent.repaint(Rectangle)} through queue
907      */
908     public void repaint(final Rectangle rectangle) {
909         runMapping(new MapVoidAction("repaint") {
910             @Override
911             public void map() {
912                 ((JComponent) getSource()).repaint(rectangle);
913             }
914         });
915     }
916 
917     /**
918      * Maps {@code JComponent.requestDefaultFocus()} through queue
919      */
920     @Deprecated
921     public boolean requestDefaultFocus() {
922         return (runMapping(new MapBooleanAction("requestDefaultFocus") {
923             @Override
924             public boolean map() {
925                 return ((JComponent) getSource()).requestDefaultFocus();
926             }
927         }));
928     }
929 
930     /**
931      * Maps {@code JComponent.resetKeyboardActions()} through queue
932      */
933     public void resetKeyboardActions() {
934         runMapping(new MapVoidAction("resetKeyboardActions") {
935             @Override
936             public void map() {
937                 ((JComponent) getSource()).resetKeyboardActions();
938             }
939         });
940     }
941 
942     /**
943      * Maps {@code JComponent.revalidate()} through queue
944      */
945     public void revalidate() {
946         runMapping(new MapVoidAction("revalidate") {
947             @Override
948             public void map() {
949                 getSource().revalidate();
950             }
951         });
952     }
953 
954     /**
955      * Maps {@code JComponent.scrollRectToVisible(Rectangle)} through queue
956      */
957     public void scrollRectToVisible(final Rectangle rectangle) {
958         runMapping(new MapVoidAction("scrollRectToVisible") {
959             @Override
960             public void map() {
961                 ((JComponent) getSource()).scrollRectToVisible(rectangle);
962             }
963         });
964     }
965 
966     /**
967      * Maps {@code JComponent.setAlignmentX(float)} through queue
968      */
969     public void setAlignmentX(final float f) {
970         runMapping(new MapVoidAction("setAlignmentX") {
971             @Override
972             public void map() {
973                 ((JComponent) getSource()).setAlignmentX(f);
974             }
975         });
976     }
977 
978     /**
979      * Maps {@code JComponent.setAlignmentY(float)} through queue
980      */
981     public void setAlignmentY(final float f) {
982         runMapping(new MapVoidAction("setAlignmentY") {
983             @Override
984             public void map() {
985                 ((JComponent) getSource()).setAlignmentY(f);
986             }
987         });
988     }
989 
990     /**
991      * Maps {@code JComponent.setAutoscrolls(boolean)} through queue
992      */
993     public void setAutoscrolls(final boolean b) {
994         runMapping(new MapVoidAction("setAutoscrolls") {
995             @Override
996             public void map() {
997                 ((JComponent) getSource()).setAutoscrolls(b);
998             }
999         });
1000     }
1001 
1002     /**
1003      * Maps {@code JComponent.setBorder(Border)} through queue
1004      */
1005     public void setBorder(final Border border) {
1006         runMapping(new MapVoidAction("setBorder") {
1007             @Override
1008             public void map() {
1009                 ((JComponent) getSource()).setBorder(border);
1010             }
1011         });
1012     }
1013 
1014     /**
1015      * Maps {@code JComponent.setDebugGraphicsOptions(int)} through queue
1016      */
1017     public void setDebugGraphicsOptions(final int i) {
1018         runMapping(new MapVoidAction("setDebugGraphicsOptions") {
1019             @Override
1020             public void map() {
1021                 ((JComponent) getSource()).setDebugGraphicsOptions(i);
1022             }
1023         });
1024     }
1025 
1026     /**
1027      * Maps {@code JComponent.setDoubleBuffered(boolean)} through queue
1028      */
1029     public void setDoubleBuffered(final boolean b) {
1030         runMapping(new MapVoidAction("setDoubleBuffered") {
1031             @Override
1032             public void map() {
1033                 ((JComponent) getSource()).setDoubleBuffered(b);
1034             }
1035         });
1036     }
1037 
1038     /**
1039      * Maps {@code JComponent.setMaximumSize(Dimension)} through queue
1040      */
1041     public void setMaximumSize(final Dimension dimension) {
1042         runMapping(new MapVoidAction("setMaximumSize") {
1043             @Override
1044             public void map() {
1045                 getSource().setMaximumSize(dimension);
1046             }
1047         });
1048     }
1049 
1050     /**
1051      * Maps {@code JComponent.setMinimumSize(Dimension)} through queue
1052      */
1053     public void setMinimumSize(final Dimension dimension) {
1054         runMapping(new MapVoidAction("setMinimumSize") {
1055             @Override
1056             public void map() {
1057                 getSource().setMinimumSize(dimension);
1058             }
1059         });
1060     }
1061 
1062     /**
1063      * Maps {@code JComponent.setNextFocusableComponent(Component)} through queue
1064      */
1065     @Deprecated
1066     public void setNextFocusableComponent(final Component component) {
1067         runMapping(new MapVoidAction("setNextFocusableComponent") {
1068             @Override
1069             public void map() {
1070                 ((JComponent) getSource()).setNextFocusableComponent(component);
1071             }
1072         });
1073     }
1074 
1075     /**
1076      * Maps {@code JComponent.setOpaque(boolean)} through queue
1077      */
1078     public void setOpaque(final boolean b) {
1079         runMapping(new MapVoidAction("setOpaque") {
1080             @Override
1081             public void map() {
1082                 ((JComponent) getSource()).setOpaque(b);
1083             }
1084         });
1085     }
1086 
1087     /**
1088      * Maps {@code JComponent.setPreferredSize(Dimension)} through queue
1089      */
1090     public void setPreferredSize(final Dimension dimension) {
1091         runMapping(new MapVoidAction("setPreferredSize") {
1092             @Override
1093             public void map() {
1094                 getSource().setPreferredSize(dimension);
1095             }
1096         });
1097     }
1098 
1099     /**
1100      * Maps {@code JComponent.setRequestFocusEnabled(boolean)} through queue
1101      */
1102     public void setRequestFocusEnabled(final boolean b) {
1103         runMapping(new MapVoidAction("setRequestFocusEnabled") {
1104             @Override
1105             public void map() {
1106                 ((JComponent) getSource()).setRequestFocusEnabled(b);
1107             }
1108         });
1109     }
1110 
1111     /**
1112      * Maps {@code JComponent.setToolTipText(String)} through queue
1113      */
1114     public void setToolTipText(final String string) {
1115         runMapping(new MapVoidAction("setToolTipText") {
1116             @Override
1117             public void map() {
1118                 ((JComponent) getSource()).setToolTipText(string);
1119             }
1120         });
1121     }
1122 
1123     /**
1124      * Maps {@code JComponent.unregisterKeyboardAction(KeyStroke)} through queue
1125      */
1126     public void unregisterKeyboardAction(final KeyStroke keyStroke) {
1127         runMapping(new MapVoidAction("unregisterKeyboardAction") {
1128             @Override
1129             public void map() {
1130                 ((JComponent) getSource()).unregisterKeyboardAction(keyStroke);
1131             }
1132         });
1133     }
1134 
1135     /**
1136      * Maps {@code JComponent.updateUI()} through queue
1137      */
1138     public void updateUI() {
1139         runMapping(new MapVoidAction("updateUI") {
1140             @Override
1141             public void map() {
1142                 ((JComponent) getSource()).updateUI();
1143             }
1144         });
1145     }
1146 
1147     //End of mapping                                      //
1148     ////////////////////////////////////////////////////////
1149     /**
1150      * Allows to find component by tooltip.
1151      */
1152     public static class JComponentByTipFinder implements ComponentChooser {
1153 
1154         String label;
1155 
1156         StringComparator comparator;
1157 
1158         /**
1159          * Constructs JComponentByTipFinder.
1160          *
1161          * @param lb a text pattern
1162          * @param comparator specifies string comparision algorithm.
1163          */
1164         public JComponentByTipFinder(String lb, StringComparator comparator) {
1165             label = lb;
1166             this.comparator = comparator;
1167         }
1168 
1169         /**
1170          * Constructs JComponentByTipFinder.
1171          *
1172          * @param lb a text pattern
1173          */
1174         public JComponentByTipFinder(String lb) {
1175             this(lb, Operator.getDefaultStringComparator());
1176         }
1177 
1178         @Override
1179         public boolean checkComponent(Component comp) {
1180             if (comp instanceof JComponent) {
1181                 if (((JComponent) comp).getToolTipText() != null) {
1182                     return (comparator.equals(((JComponent) comp).getToolTipText(),
1183                             label));
1184                 }
1185             }
1186             return false;
1187         }
1188 
1189         @Override
1190         public String getDescription() {
1191             return "JComponent with tool tip \"" + label + "\"";
1192         }
1193 
1194         @Override
1195         public String toString() {
1196             return "JComponentByTipFinder{" + "label=" + label + ", comparator=" + comparator + '}';
1197         }
1198     }
1199 
1200     /**
1201      * Checks component type.
1202      */
1203     public static class JComponentFinder extends Finder {
1204 
1205         /**
1206          * Constructs JComponentFinder.
1207          *
1208          * @param sf other searching criteria.
1209          */
1210         public JComponentFinder(ComponentChooser sf) {
1211             super(JComponent.class, sf);
1212         }
1213 
1214         /**
1215          * Constructs JComponentFinder.
1216          */
1217         public JComponentFinder() {
1218             super(JComponent.class);
1219         }
1220     }
1221 
1222 }
1223