AbstractButtonOperator.java revision 13978:1993af50385d
155682Smarkm/*
2233294Sstas * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
3233294Sstas * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4233294Sstas *
555682Smarkm * This code is free software; you can redistribute it and/or modify it
6233294Sstas * under the terms of the GNU General Public License version 2 only, as
7233294Sstas * published by the Free Software Foundation.
8233294Sstas *
955682Smarkm * This code is distributed in the hope that it will be useful, but WITHOUT
10233294Sstas * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11233294Sstas * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1255682Smarkm * version 2 for more details (a copy is included in the LICENSE file that
13233294Sstas * accompanied this code).
14233294Sstas *
15233294Sstas * You should have received a copy of the GNU General Public License version
1655682Smarkm * 2 along with this work; if not, write to the Free Software Foundation,
1755682Smarkm * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1855682Smarkm *
1955682Smarkm * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2055682Smarkm * or visit www.oracle.com if you need additional information or have any
2155682Smarkm * questions.
2255682Smarkm */
2355682Smarkmpackage org.netbeans.jemmy.operators;
2455682Smarkm
2555682Smarkmimport java.awt.Component;
2655682Smarkmimport java.awt.Container;
2755682Smarkmimport java.awt.Insets;
2855682Smarkmimport java.awt.event.ActionListener;
2955682Smarkmimport java.awt.event.ItemListener;
3055682Smarkmimport java.util.Hashtable;
3155682Smarkm
3255682Smarkmimport javax.swing.AbstractButton;
33233294Sstasimport javax.swing.ButtonModel;
3455682Smarkmimport javax.swing.Icon;
3555682Smarkmimport javax.swing.event.ChangeListener;
3655682Smarkmimport javax.swing.plaf.ButtonUI;
3755682Smarkm
3855682Smarkmimport org.netbeans.jemmy.ComponentChooser;
39178825Sdfrimport org.netbeans.jemmy.JemmyException;
40178825Sdfrimport org.netbeans.jemmy.Outputable;
4155682Smarkmimport org.netbeans.jemmy.TestOut;
4255682Smarkmimport org.netbeans.jemmy.TimeoutExpiredException;
4355682Smarkmimport org.netbeans.jemmy.Timeoutable;
4455682Smarkmimport org.netbeans.jemmy.Timeouts;
4555682Smarkmimport org.netbeans.jemmy.drivers.ButtonDriver;
4655682Smarkmimport org.netbeans.jemmy.drivers.DriverManager;
4755682Smarkm
4855682Smarkm/**
4955682Smarkm *
5055682Smarkm * <BR><BR>Timeouts used: <BR>
5155682Smarkm * AbstractButtonOperator.PushButtonTimeout - time between button pressing and
5255682Smarkm * releasing<BR>
5355682Smarkm * ComponentOperator.WaitComponentTimeout - time to wait button displayed <BR>
5455682Smarkm * ComponentOperator.WaitComponentEnabledTimeout - time to wait button enabled
5555682Smarkm * <BR>
5655682Smarkm * ComponentOperator.WaitStateTimeout - time to wait for text <BR>.
5755682Smarkm *
5855682Smarkm * @see org.netbeans.jemmy.Timeouts
5955682Smarkm *
6055682Smarkm * @author Alexandre Iline (alexandre.iline@oracle.com)
6155682Smarkm *
6255682Smarkm */
6355682Smarkmpublic class AbstractButtonOperator extends JComponentOperator
6455682Smarkm        implements Timeoutable, Outputable {
6555682Smarkm
6655682Smarkm    /**
6755682Smarkm     * Identifier for a text property.
6855682Smarkm     *
6955682Smarkm     * @see #getDump
7055682Smarkm     */
7155682Smarkm    public static final String TEXT_DPROP = "Text";
7255682Smarkm
7355682Smarkm    /**
7455682Smarkm     * Identifier for a selected text property.
7555682Smarkm     *
7655682Smarkm     * @see #getDump
7755682Smarkm     */
7855682Smarkm    public static final String IS_SELECTED_DPROP = "Selected";
7955682Smarkm
8055682Smarkm    /**
8155682Smarkm     * Default value for AbstractButtonOperator.PushButtonTimeout timeout.
8255682Smarkm     */
8355682Smarkm    private final static long PUSH_BUTTON_TIMEOUT = 0;
8455682Smarkm
8555682Smarkm    private Timeouts timeouts;
8655682Smarkm    private TestOut output;
8755682Smarkm
88    ButtonDriver driver;
89
90    /**
91     * Constructor.
92     *
93     * @param b The {@code java.awt.AbstractButton} managed by this
94     * instance.
95     */
96    public AbstractButtonOperator(AbstractButton b) {
97        super(b);
98        driver = DriverManager.getButtonDriver(getClass());
99    }
100
101    /**
102     * Constructs an AbstractButtonOperator object.
103     *
104     * @param cont container
105     * @param chooser a component chooser specifying searching criteria.
106     * @param index an index between appropriate ones.
107     */
108    public AbstractButtonOperator(ContainerOperator<?> cont, ComponentChooser chooser, int index) {
109        this((AbstractButton) cont.
110                waitSubComponent(new AbstractButtonFinder(chooser),
111                        index));
112        copyEnvironment(cont);
113    }
114
115    /**
116     * Constructs an AbstractButtonOperator object.
117     *
118     * @param cont container
119     * @param chooser a component chooser specifying searching criteria.
120     */
121    public AbstractButtonOperator(ContainerOperator<?> cont, ComponentChooser chooser) {
122        this(cont, chooser, 0);
123    }
124
125    /**
126     * Constructor. Waits for a component in a container to show. The component
127     * is identified as the {@code index+1}'th
128     * {@code javax.swing.AbstractButton} that shows, lies below the
129     * container in the display containment hierarchy, and that has the desired
130     * text. Uses cont's timeout and output for waiting and to init this
131     * operator.
132     *
133     * @param cont The operator for a container containing the sought for
134     * button.
135     * @param text Button text.
136     * @param index Ordinal component index. The first component has
137     * {@code index} 0.
138     * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
139     * @throws TimeoutExpiredException
140     */
141    public AbstractButtonOperator(ContainerOperator<?> cont, String text, int index) {
142        this((AbstractButton) waitComponent(cont,
143                new AbstractButtonByLabelFinder(text,
144                        cont.getComparator()),
145                index));
146        copyEnvironment(cont);
147    }
148
149    /**
150     * Constructor. Waits for a component in a container to show. The component
151     * is identified as the first {@code javax.swing.AbstractButton} that
152     * shows, lies below the container in the display containment hierarchy, and
153     * that has the desired text. Uses cont's timeout and output for waiting and
154     * to init this operator.
155     *
156     * @param cont The operator for a container containing the sought for
157     * button.
158     * @param text Button text.
159     * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
160     * @throws TimeoutExpiredException
161     */
162    public AbstractButtonOperator(ContainerOperator<?> cont, String text) {
163        this(cont, text, 0);
164    }
165
166    /**
167     * Constructor. Waits component in container first. Uses cont's timeout and
168     * output for waiting and to init operator.
169     *
170     * @param cont The operator for a container containing the sought for
171     * button.
172     * @param index Ordinal component index.
173     * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
174     * @throws TimeoutExpiredException
175     */
176    public AbstractButtonOperator(ContainerOperator<?> cont, int index) {
177        this((AbstractButton) waitComponent(cont,
178                new AbstractButtonFinder(),
179                index));
180        copyEnvironment(cont);
181    }
182
183    /**
184     * Constructor. Waits component in container first. Uses cont's timeout and
185     * output for waiting and to init operator.
186     *
187     * @param cont The operator for a container containing the sought for
188     * button.
189     * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
190     * @throws TimeoutExpiredException
191     */
192    public AbstractButtonOperator(ContainerOperator<?> cont) {
193        this(cont, 0);
194    }
195
196    /**
197     * Searches AbstractButton in a container.
198     *
199     * @param cont Container in which to search for the component. The container
200     * lies above the component in the display containment hierarchy. The
201     * containment need not be direct.
202     * @param chooser org.netbeans.jemmy.ComponentChooser implementation,
203     * defining and applying search criteria.
204     * @param index Ordinal component index. The first {@code index} is 0.
205     * @return AbstractButton instance or null if component was not found.
206     */
207    public static AbstractButton findAbstractButton(Container cont, ComponentChooser chooser, int index) {
208        return (AbstractButton) findComponent(cont, new AbstractButtonFinder(chooser), index);
209    }
210
211    /**
212     * Searches for the first AbstractButton in a container.
213     *
214     * @param cont Container in which to search for the component. The container
215     * lies above the component in the display containment hierarchy. The
216     * containment need not be direct.
217     * @param chooser org.netbeans.jemmy.ComponentChooser implementation,
218     * defining and applying search criteria.
219     * @return AbstractButton instance or null if component was not found.
220     */
221    public static AbstractButton findAbstractButton(Container cont, ComponentChooser chooser) {
222        return findAbstractButton(cont, chooser, 0);
223    }
224
225    /**
226     * Searches AbstractButton by text.
227     *
228     * @param cont Container to search component in.
229     * @param text Button text. If null, contents is not checked.
230     * @param ce Compare text exactly.
231     * @param ccs Compare text case sensitively.
232     * @param index Ordinal component index.
233     * @return AbstractButton instance or null if component was not found.
234     * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
235     */
236    public static AbstractButton findAbstractButton(Container cont, String text, boolean ce, boolean ccs, int index) {
237        return findAbstractButton(cont, new AbstractButtonByLabelFinder(text, new DefaultStringComparator(ce, ccs)), index);
238    }
239
240    /**
241     * Searches AbstractButton by text.
242     *
243     * @param cont Container to search component in.
244     * @param text Button text. If null, contents is not checked.
245     * @param ce Compare text exactly.
246     * @param ccs Compare text case sensitively.
247     * @return AbstractButton instance or null if component was not found.
248     * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
249     */
250    public static AbstractButton findAbstractButton(Container cont, String text, boolean ce, boolean ccs) {
251        return findAbstractButton(cont, text, ce, ccs, 0);
252    }
253
254    /**
255     * Waits AbstractButton in container.
256     *
257     * @param cont Container to search component in.
258     * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
259     * @param index Ordinal component index.
260     * @return AbstractButton instance.
261     * @throws TimeoutExpiredException
262     */
263    public static AbstractButton waitAbstractButton(Container cont, ComponentChooser chooser, int index) {
264        return (AbstractButton) waitComponent(cont, new AbstractButtonFinder(chooser), index);
265    }
266
267    /**
268     * Waits 0'th AbstractButton in container.
269     *
270     * @param cont Container to search component in.
271     * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
272     * @return AbstractButton instance.
273     * @throws TimeoutExpiredException
274     */
275    public static AbstractButton waitAbstractButton(Container cont, ComponentChooser chooser) {
276        return waitAbstractButton(cont, chooser, 0);
277    }
278
279    /**
280     * Waits AbstractButton by text.
281     *
282     * @param cont Container to search component in.
283     * @param text Button text. If null, contents is not checked.
284     * @param ce Compare text exactly.
285     * @param ccs Compare text case sensitively.
286     * @param index Ordinal component index.
287     * @return AbstractButton instance.
288     * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
289     * @throws TimeoutExpiredException
290     */
291    public static AbstractButton waitAbstractButton(Container cont, String text, boolean ce, boolean ccs, int index) {
292        return waitAbstractButton(cont, new AbstractButtonByLabelFinder(text, new DefaultStringComparator(ce, ccs)), index);
293    }
294
295    /**
296     * Waits AbstractButton by text.
297     *
298     * @param cont Container to search component in.
299     * @param text Button text. If null, contents is not checked.
300     * @param ce Compare text exactly.
301     * @param ccs Compare text case sensitively.
302     * @return AbstractButton instance.
303     * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
304     * @throws TimeoutExpiredException
305     */
306    public static AbstractButton waitAbstractButton(Container cont, String text, boolean ce, boolean ccs) {
307        return waitAbstractButton(cont, text, ce, ccs, 0);
308    }
309
310    static {
311        Timeouts.initDefault("AbstractButtonOperator.PushButtonTimeout", PUSH_BUTTON_TIMEOUT);
312    }
313
314    @Override
315    public void setTimeouts(Timeouts timeouts) {
316        super.setTimeouts(timeouts);
317        this.timeouts = timeouts;
318    }
319
320    @Override
321    public Timeouts getTimeouts() {
322        return timeouts;
323    }
324
325    @Override
326    public void setOutput(TestOut out) {
327        output = out;
328        super.setOutput(output.createErrorOutput());
329    }
330
331    @Override
332    public TestOut getOutput() {
333        return output;
334    }
335
336    @Override
337    public void copyEnvironment(Operator anotherOperator) {
338        super.copyEnvironment(anotherOperator);
339        driver = DriverManager.getButtonDriver(this);
340    }
341
342    /**
343     * Pushs the button using a ButtonDriver registered for this operator.
344     */
345    public void push() {
346        output.printLine("Push button\n    :" + toStringSource());
347        output.printGolden("Push button");
348        makeComponentVisible();
349        try {
350            waitComponentEnabled();
351        } catch (InterruptedException e) {
352            throw (new JemmyException("Interrupted", e));
353        }
354        driver.push(this);
355    }
356
357    /**
358     * Runs {@code push()} method in a separate thread.
359     */
360    public void pushNoBlock() {
361        produceNoBlocking(new NoBlockingAction<Void, Void>("Button pushing") {
362            @Override
363            public Void doAction(Void param) {
364                push();
365                return null;
366            }
367        });
368    }
369
370    /**
371     * Changes selection if necessary. Uses {@code push()} method in order
372     * to do so.
373     *
374     * @param selected a button selection.
375     */
376    public void changeSelection(boolean selected) {
377        if (isSelected() != selected) {
378            push();
379        }
380        if (getVerification()) {
381            waitSelected(selected);
382        }
383    }
384
385    /**
386     * Runs {@code changeSelection(boolean)} method in a separate thread.
387     *
388     * @param selected a button selection.
389     */
390    public void changeSelectionNoBlock(boolean selected) {
391        produceNoBlocking(new NoBlockingAction<Void, Boolean>("Button selection changing") {
392            @Override
393            public Void doAction(Boolean param) {
394                changeSelection(param);
395                return null;
396            }
397        }, selected ? Boolean.TRUE : Boolean.FALSE);
398    }
399
400    /**
401     * Press the button by mouse.
402     *
403     * @throws TimeoutExpiredException
404     */
405    public void press() {
406        output.printLine("Press button\n    :" + toStringSource());
407        output.printGolden("Press button");
408        makeComponentVisible();
409        try {
410            waitComponentEnabled();
411        } catch (InterruptedException e) {
412            throw (new JemmyException("Interrupted", e));
413        }
414        driver.press(this);
415    }
416
417    /**
418     * Releases the button by mouse.
419     *
420     * @throws TimeoutExpiredException
421     */
422    public void release() {
423        output.printLine("Release button\n    :" + toStringSource());
424        output.printGolden("Release button");
425        try {
426            waitComponentEnabled();
427        } catch (InterruptedException e) {
428            throw (new JemmyException("Interrupted", e));
429        }
430        driver.release(this);
431    }
432
433    /**
434     * Waits for button to be selected.
435     *
436     * @param selected a button selection.
437     */
438    public void waitSelected(final boolean selected) {
439        getOutput().printLine("Wait button to be selected \n    : "
440                + toStringSource());
441        getOutput().printGolden("Wait button to be selected");
442        waitState(new ComponentChooser() {
443            @Override
444            public boolean checkComponent(Component comp) {
445                return isSelected() == selected;
446            }
447
448            @Override
449            public String getDescription() {
450                return ("Items has been "
451                        + (selected ? "" : "un") + "selected");
452            }
453
454            @Override
455            public String toString() {
456                return "waitSelected.ComponentChooser{description = " + getDescription() + '}';
457            }
458        });
459    }
460
461    /**
462     * Waits for text. Uses getComparator() comparator.
463     *
464     * @param text Text to wait for.
465     */
466    public void waitText(String text) {
467        getOutput().printLine("Wait \"" + text + "\" text in component \n    : "
468                + toStringSource());
469        getOutput().printGolden("Wait \"" + text + "\" text");
470        waitState(new AbstractButtonByLabelFinder(text, getComparator()));
471    }
472
473    /**
474     * Returns information about component.
475     */
476    @Override
477    public Hashtable<String, Object> getDump() {
478        Hashtable<String, Object> result = super.getDump();
479        if (((AbstractButton) getSource()).getText() != null) {
480            result.put(TEXT_DPROP, ((AbstractButton) getSource()).getText());
481        }
482        result.put(IS_SELECTED_DPROP, ((AbstractButton) getSource()).isSelected() ? "true" : "false");
483        return result;
484    }
485
486    ////////////////////////////////////////////////////////
487    //Mapping                                             //
488    /**
489     * Maps {@code AbstractButton.addActionListener(ActionListener)}
490     * through queue
491     */
492    public void addActionListener(final ActionListener actionListener) {
493        runMapping(new MapVoidAction("addActionListener") {
494            @Override
495            public void map() {
496                ((AbstractButton) getSource()).addActionListener(actionListener);
497            }
498        });
499    }
500
501    /**
502     * Maps {@code AbstractButton.addChangeListener(ChangeListener)}
503     * through queue
504     */
505    public void addChangeListener(final ChangeListener changeListener) {
506        runMapping(new MapVoidAction("addChangeListener") {
507            @Override
508            public void map() {
509                ((AbstractButton) getSource()).addChangeListener(changeListener);
510            }
511        });
512    }
513
514    /**
515     * Maps {@code AbstractButton.addItemListener(ItemListener)} through queue
516     */
517    public void addItemListener(final ItemListener itemListener) {
518        runMapping(new MapVoidAction("addItemListener") {
519            @Override
520            public void map() {
521                ((AbstractButton) getSource()).addItemListener(itemListener);
522            }
523        });
524    }
525
526    /**
527     * Maps {@code AbstractButton.doClick()} through queue
528     */
529    public void doClick() {
530        runMapping(new MapVoidAction("doClick") {
531            @Override
532            public void map() {
533                ((AbstractButton) getSource()).doClick();
534            }
535        });
536    }
537
538    /**
539     * Maps {@code AbstractButton.doClick(int)} through queue
540     */
541    public void doClick(final int i) {
542        runMapping(new MapVoidAction("doClick") {
543            @Override
544            public void map() {
545                ((AbstractButton) getSource()).doClick(i);
546            }
547        });
548    }
549
550    /**
551     * Maps {@code AbstractButton.getActionCommand()} through queue
552     */
553    public String getActionCommand() {
554        return (runMapping(new MapAction<String>("getActionCommand") {
555            @Override
556            public String map() {
557                return ((AbstractButton) getSource()).getActionCommand();
558            }
559        }));
560    }
561
562    /**
563     * Maps {@code AbstractButton.getDisabledIcon()} through queue
564     */
565    public Icon getDisabledIcon() {
566        return (runMapping(new MapAction<Icon>("getDisabledIcon") {
567            @Override
568            public Icon map() {
569                return ((AbstractButton) getSource()).getDisabledIcon();
570            }
571        }));
572    }
573
574    /**
575     * Maps {@code AbstractButton.getDisabledSelectedIcon()} through queue
576     */
577    public Icon getDisabledSelectedIcon() {
578        return (runMapping(new MapAction<Icon>("getDisabledSelectedIcon") {
579            @Override
580            public Icon map() {
581                return ((AbstractButton) getSource()).getDisabledSelectedIcon();
582            }
583        }));
584    }
585
586    /**
587     * Maps {@code AbstractButton.getHorizontalAlignment()} through queue
588     */
589    public int getHorizontalAlignment() {
590        return (runMapping(new MapIntegerAction("getHorizontalAlignment") {
591            @Override
592            public int map() {
593                return ((AbstractButton) getSource()).getHorizontalAlignment();
594            }
595        }));
596    }
597
598    /**
599     * Maps {@code AbstractButton.getHorizontalTextPosition()} through queue
600     */
601    public int getHorizontalTextPosition() {
602        return (runMapping(new MapIntegerAction("getHorizontalTextPosition") {
603            @Override
604            public int map() {
605                return ((AbstractButton) getSource()).getHorizontalTextPosition();
606            }
607        }));
608    }
609
610    /**
611     * Maps {@code AbstractButton.getIcon()} through queue
612     */
613    public Icon getIcon() {
614        return (runMapping(new MapAction<Icon>("getIcon") {
615            @Override
616            public Icon map() {
617                return ((AbstractButton) getSource()).getIcon();
618            }
619        }));
620    }
621
622    /**
623     * Maps {@code AbstractButton.getMargin()} through queue
624     */
625    public Insets getMargin() {
626        return (runMapping(new MapAction<Insets>("getMargin") {
627            @Override
628            public Insets map() {
629                return ((AbstractButton) getSource()).getMargin();
630            }
631        }));
632    }
633
634    /**
635     * Maps {@code AbstractButton.getMnemonic()} through queue
636     */
637    public int getMnemonic() {
638        return (runMapping(new MapIntegerAction("getMnemonic") {
639            @Override
640            public int map() {
641                return ((AbstractButton) getSource()).getMnemonic();
642            }
643        }));
644    }
645
646    /**
647     * Maps {@code AbstractButton.getModel()} through queue
648     */
649    public ButtonModel getModel() {
650        return (runMapping(new MapAction<ButtonModel>("getModel") {
651            @Override
652            public ButtonModel map() {
653                return ((AbstractButton) getSource()).getModel();
654            }
655        }));
656    }
657
658    /**
659     * Maps {@code AbstractButton.getPressedIcon()} through queue
660     */
661    public Icon getPressedIcon() {
662        return (runMapping(new MapAction<Icon>("getPressedIcon") {
663            @Override
664            public Icon map() {
665                return ((AbstractButton) getSource()).getPressedIcon();
666            }
667        }));
668    }
669
670    /**
671     * Maps {@code AbstractButton.getRolloverIcon()} through queue
672     */
673    public Icon getRolloverIcon() {
674        return (runMapping(new MapAction<Icon>("getRolloverIcon") {
675            @Override
676            public Icon map() {
677                return ((AbstractButton) getSource()).getRolloverIcon();
678            }
679        }));
680    }
681
682    /**
683     * Maps {@code AbstractButton.getRolloverSelectedIcon()} through queue
684     */
685    public Icon getRolloverSelectedIcon() {
686        return (runMapping(new MapAction<Icon>("getRolloverSelectedIcon") {
687            @Override
688            public Icon map() {
689                return ((AbstractButton) getSource()).getRolloverSelectedIcon();
690            }
691        }));
692    }
693
694    /**
695     * Maps {@code AbstractButton.getSelectedIcon()} through queue
696     */
697    public Icon getSelectedIcon() {
698        return (runMapping(new MapAction<Icon>("getSelectedIcon") {
699            @Override
700            public Icon map() {
701                return ((AbstractButton) getSource()).getSelectedIcon();
702            }
703        }));
704    }
705
706    /**
707     * Maps {@code AbstractButton.getSelectedObjects()} through queue
708     */
709    public Object[] getSelectedObjects() {
710        return ((Object[]) runMapping(new MapAction<Object>("getSelectedObjects") {
711            @Override
712            public Object map() {
713                return ((AbstractButton) getSource()).getSelectedObjects();
714            }
715        }));
716    }
717
718    /**
719     * Maps {@code AbstractButton.getText()} through queue
720     */
721    public String getText() {
722        return (runMapping(new MapAction<String>("getText") {
723            @Override
724            public String map() {
725                return ((AbstractButton) getSource()).getText();
726            }
727        }));
728    }
729
730    /**
731     * Maps {@code AbstractButton.getUI()} through queue
732     */
733    public ButtonUI getUI() {
734        return (runMapping(new MapAction<ButtonUI>("getUI") {
735            @Override
736            public ButtonUI map() {
737                return ((AbstractButton) getSource()).getUI();
738            }
739        }));
740    }
741
742    /**
743     * Maps {@code AbstractButton.getVerticalAlignment()} through queue
744     */
745    public int getVerticalAlignment() {
746        return (runMapping(new MapIntegerAction("getVerticalAlignment") {
747            @Override
748            public int map() {
749                return ((AbstractButton) getSource()).getVerticalAlignment();
750            }
751        }));
752    }
753
754    /**
755     * Maps {@code AbstractButton.getVerticalTextPosition()} through queue
756     */
757    public int getVerticalTextPosition() {
758        return (runMapping(new MapIntegerAction("getVerticalTextPosition") {
759            @Override
760            public int map() {
761                return ((AbstractButton) getSource()).getVerticalTextPosition();
762            }
763        }));
764    }
765
766    /**
767     * Maps {@code AbstractButton.isBorderPainted()} through queue
768     */
769    public boolean isBorderPainted() {
770        return (runMapping(new MapBooleanAction("isBorderPainted") {
771            @Override
772            public boolean map() {
773                return ((AbstractButton) getSource()).isBorderPainted();
774            }
775        }));
776    }
777
778    /**
779     * Maps {@code AbstractButton.isContentAreaFilled()} through queue
780     */
781    public boolean isContentAreaFilled() {
782        return (runMapping(new MapBooleanAction("isContentAreaFilled") {
783            @Override
784            public boolean map() {
785                return ((AbstractButton) getSource()).isContentAreaFilled();
786            }
787        }));
788    }
789
790    /**
791     * Maps {@code AbstractButton.isFocusPainted()} through queue
792     */
793    public boolean isFocusPainted() {
794        return (runMapping(new MapBooleanAction("isFocusPainted") {
795            @Override
796            public boolean map() {
797                return ((AbstractButton) getSource()).isFocusPainted();
798            }
799        }));
800    }
801
802    /**
803     * Maps {@code AbstractButton.isRolloverEnabled()} through queue
804     */
805    public boolean isRolloverEnabled() {
806        return (runMapping(new MapBooleanAction("isRolloverEnabled") {
807            @Override
808            public boolean map() {
809                return ((AbstractButton) getSource()).isRolloverEnabled();
810            }
811        }));
812    }
813
814    /**
815     * Maps {@code AbstractButton.isSelected()} through queue
816     */
817    public boolean isSelected() {
818        return (runMapping(new MapBooleanAction("isSelected") {
819            @Override
820            public boolean map() {
821                return ((AbstractButton) getSource()).isSelected();
822            }
823        }));
824    }
825
826    /**
827     * Maps {@code AbstractButton.removeActionListener(ActionListener)}
828     * through queue
829     */
830    public void removeActionListener(final ActionListener actionListener) {
831        runMapping(new MapVoidAction("removeActionListener") {
832            @Override
833            public void map() {
834                ((AbstractButton) getSource()).removeActionListener(actionListener);
835            }
836        });
837    }
838
839    /**
840     * Maps {@code AbstractButton.removeChangeListener(ChangeListener)}
841     * through queue
842     */
843    public void removeChangeListener(final ChangeListener changeListener) {
844        runMapping(new MapVoidAction("removeChangeListener") {
845            @Override
846            public void map() {
847                ((AbstractButton) getSource()).removeChangeListener(changeListener);
848            }
849        });
850    }
851
852    /**
853     * Maps {@code AbstractButton.removeItemListener(ItemListener)} through queue
854     */
855    public void removeItemListener(final ItemListener itemListener) {
856        runMapping(new MapVoidAction("removeItemListener") {
857            @Override
858            public void map() {
859                ((AbstractButton) getSource()).removeItemListener(itemListener);
860            }
861        });
862    }
863
864    /**
865     * Maps {@code AbstractButton.setActionCommand(String)} through queue
866     */
867    public void setActionCommand(final String string) {
868        runMapping(new MapVoidAction("setActionCommand") {
869            @Override
870            public void map() {
871                ((AbstractButton) getSource()).setActionCommand(string);
872            }
873        });
874    }
875
876    /**
877     * Maps {@code AbstractButton.setBorderPainted(boolean)} through queue
878     */
879    public void setBorderPainted(final boolean b) {
880        runMapping(new MapVoidAction("setBorderPainted") {
881            @Override
882            public void map() {
883                ((AbstractButton) getSource()).setBorderPainted(b);
884            }
885        });
886    }
887
888    /**
889     * Maps {@code AbstractButton.setContentAreaFilled(boolean)} through queue
890     */
891    public void setContentAreaFilled(final boolean b) {
892        runMapping(new MapVoidAction("setContentAreaFilled") {
893            @Override
894            public void map() {
895                ((AbstractButton) getSource()).setContentAreaFilled(b);
896            }
897        });
898    }
899
900    /**
901     * Maps {@code AbstractButton.setDisabledIcon(Icon)} through queue
902     */
903    public void setDisabledIcon(final Icon icon) {
904        runMapping(new MapVoidAction("setDisabledIcon") {
905            @Override
906            public void map() {
907                ((AbstractButton) getSource()).setDisabledIcon(icon);
908            }
909        });
910    }
911
912    /**
913     * Maps {@code AbstractButton.setDisabledSelectedIcon(Icon)} through queue
914     */
915    public void setDisabledSelectedIcon(final Icon icon) {
916        runMapping(new MapVoidAction("setDisabledSelectedIcon") {
917            @Override
918            public void map() {
919                ((AbstractButton) getSource()).setDisabledSelectedIcon(icon);
920            }
921        });
922    }
923
924    /**
925     * Maps {@code AbstractButton.setFocusPainted(boolean)} through queue
926     */
927    public void setFocusPainted(final boolean b) {
928        runMapping(new MapVoidAction("setFocusPainted") {
929            @Override
930            public void map() {
931                ((AbstractButton) getSource()).setFocusPainted(b);
932            }
933        });
934    }
935
936    /**
937     * Maps {@code AbstractButton.setHorizontalAlignment(int)} through queue
938     */
939    public void setHorizontalAlignment(final int i) {
940        runMapping(new MapVoidAction("setHorizontalAlignment") {
941            @Override
942            public void map() {
943                ((AbstractButton) getSource()).setHorizontalAlignment(i);
944            }
945        });
946    }
947
948    /**
949     * Maps {@code AbstractButton.setHorizontalTextPosition(int)} through queue
950     */
951    public void setHorizontalTextPosition(final int i) {
952        runMapping(new MapVoidAction("setHorizontalTextPosition") {
953            @Override
954            public void map() {
955                ((AbstractButton) getSource()).setHorizontalTextPosition(i);
956            }
957        });
958    }
959
960    /**
961     * Maps {@code AbstractButton.setIcon(Icon)} through queue
962     */
963    public void setIcon(final Icon icon) {
964        runMapping(new MapVoidAction("setIcon") {
965            @Override
966            public void map() {
967                ((AbstractButton) getSource()).setIcon(icon);
968            }
969        });
970    }
971
972    /**
973     * Maps {@code AbstractButton.setMargin(Insets)} through queue
974     */
975    public void setMargin(final Insets insets) {
976        runMapping(new MapVoidAction("setMargin") {
977            @Override
978            public void map() {
979                ((AbstractButton) getSource()).setMargin(insets);
980            }
981        });
982    }
983
984    /**
985     * Maps {@code AbstractButton.setMnemonic(char)} through queue
986     */
987    public void setMnemonic(final char c) {
988        runMapping(new MapVoidAction("setMnemonic") {
989            @Override
990            public void map() {
991                ((AbstractButton) getSource()).setMnemonic(c);
992            }
993        });
994    }
995
996    /**
997     * Maps {@code AbstractButton.setMnemonic(int)} through queue
998     */
999    public void setMnemonic(final int i) {
1000        runMapping(new MapVoidAction("setMnemonic") {
1001            @Override
1002            public void map() {
1003                ((AbstractButton) getSource()).setMnemonic(i);
1004            }
1005        });
1006    }
1007
1008    /**
1009     * Maps {@code AbstractButton.setModel(ButtonModel)} through queue
1010     */
1011    public void setModel(final ButtonModel buttonModel) {
1012        runMapping(new MapVoidAction("setModel") {
1013            @Override
1014            public void map() {
1015                ((AbstractButton) getSource()).setModel(buttonModel);
1016            }
1017        });
1018    }
1019
1020    /**
1021     * Maps {@code AbstractButton.setPressedIcon(Icon)} through queue
1022     */
1023    public void setPressedIcon(final Icon icon) {
1024        runMapping(new MapVoidAction("setPressedIcon") {
1025            @Override
1026            public void map() {
1027                ((AbstractButton) getSource()).setPressedIcon(icon);
1028            }
1029        });
1030    }
1031
1032    /**
1033     * Maps {@code AbstractButton.setRolloverEnabled(boolean)} through queue
1034     */
1035    public void setRolloverEnabled(final boolean b) {
1036        runMapping(new MapVoidAction("setRolloverEnabled") {
1037            @Override
1038            public void map() {
1039                ((AbstractButton) getSource()).setRolloverEnabled(b);
1040            }
1041        });
1042    }
1043
1044    /**
1045     * Maps {@code AbstractButton.setRolloverIcon(Icon)} through queue
1046     */
1047    public void setRolloverIcon(final Icon icon) {
1048        runMapping(new MapVoidAction("setRolloverIcon") {
1049            @Override
1050            public void map() {
1051                ((AbstractButton) getSource()).setRolloverIcon(icon);
1052            }
1053        });
1054    }
1055
1056    /**
1057     * Maps {@code AbstractButton.setRolloverSelectedIcon(Icon)} through queue
1058     */
1059    public void setRolloverSelectedIcon(final Icon icon) {
1060        runMapping(new MapVoidAction("setRolloverSelectedIcon") {
1061            @Override
1062            public void map() {
1063                ((AbstractButton) getSource()).setRolloverSelectedIcon(icon);
1064            }
1065        });
1066    }
1067
1068    /**
1069     * Maps {@code AbstractButton.setSelected(boolean)} through queue
1070     */
1071    public void setSelected(final boolean b) {
1072        runMapping(new MapVoidAction("setSelected") {
1073            @Override
1074            public void map() {
1075                ((AbstractButton) getSource()).setSelected(b);
1076            }
1077        });
1078    }
1079
1080    /**
1081     * Maps {@code AbstractButton.setSelectedIcon(Icon)} through queue
1082     */
1083    public void setSelectedIcon(final Icon icon) {
1084        runMapping(new MapVoidAction("setSelectedIcon") {
1085            @Override
1086            public void map() {
1087                ((AbstractButton) getSource()).setSelectedIcon(icon);
1088            }
1089        });
1090    }
1091
1092    /**
1093     * Maps {@code AbstractButton.setText(String)} through queue
1094     */
1095    public void setText(final String string) {
1096        runMapping(new MapVoidAction("setText") {
1097            @Override
1098            public void map() {
1099                ((AbstractButton) getSource()).setText(string);
1100            }
1101        });
1102    }
1103
1104    /**
1105     * Maps {@code AbstractButton.setUI(ButtonUI)} through queue
1106     */
1107    public void setUI(final ButtonUI buttonUI) {
1108        runMapping(new MapVoidAction("setUI") {
1109            @Override
1110            public void map() {
1111                ((AbstractButton) getSource()).setUI(buttonUI);
1112            }
1113        });
1114    }
1115
1116    /**
1117     * Maps {@code AbstractButton.setVerticalAlignment(int)} through queue
1118     */
1119    public void setVerticalAlignment(final int i) {
1120        runMapping(new MapVoidAction("setVerticalAlignment") {
1121            @Override
1122            public void map() {
1123                ((AbstractButton) getSource()).setVerticalAlignment(i);
1124            }
1125        });
1126    }
1127
1128    /**
1129     * Maps {@code AbstractButton.setVerticalTextPosition(int)} through queue
1130     */
1131    public void setVerticalTextPosition(final int i) {
1132        runMapping(new MapVoidAction("setVerticalTextPosition") {
1133            @Override
1134            public void map() {
1135                ((AbstractButton) getSource()).setVerticalTextPosition(i);
1136            }
1137        });
1138    }
1139
1140    //End of mapping                                      //
1141    ////////////////////////////////////////////////////////
1142    /**
1143     * Allows to find component by text.
1144     */
1145    public static class AbstractButtonByLabelFinder implements ComponentChooser {
1146
1147        String label;
1148        StringComparator comparator;
1149
1150        /**
1151         * Constructs AbstractButtonByLabelFinder.
1152         *
1153         * @param lb a text pattern
1154         * @param comparator specifies string comparision algorithm.
1155         */
1156        public AbstractButtonByLabelFinder(String lb, StringComparator comparator) {
1157            label = lb;
1158            this.comparator = comparator;
1159        }
1160
1161        /**
1162         * Constructs AbstractButtonByLabelFinder.
1163         *
1164         * @param lb a text pattern
1165         */
1166        public AbstractButtonByLabelFinder(String lb) {
1167            this(lb, Operator.getDefaultStringComparator());
1168        }
1169
1170        @Override
1171        public boolean checkComponent(Component comp) {
1172            if (comp instanceof AbstractButton) {
1173                if (((AbstractButton) comp).getText() != null) {
1174                    return (comparator.equals(((AbstractButton) comp).getText(),
1175                            label));
1176                }
1177            }
1178            return false;
1179        }
1180
1181        @Override
1182        public String getDescription() {
1183            return "AbstractButton with text \"" + label + "\"";
1184        }
1185
1186        @Override
1187        public String toString() {
1188            return "AbstractButtonByLabelFinder{" + "label=" + label + ", comparator=" + comparator + '}';
1189        }
1190    }
1191
1192    /**
1193     * Checks component type.
1194     */
1195    public static class AbstractButtonFinder extends Finder {
1196
1197        /**
1198         * Constructs AbstractButtonFinder.
1199         *
1200         * @param sf other searching criteria.
1201         */
1202        public AbstractButtonFinder(ComponentChooser sf) {
1203            super(AbstractButton.class, sf);
1204        }
1205
1206        /**
1207         * Constructs AbstractButtonFinder.
1208         */
1209        public AbstractButtonFinder() {
1210            super(AbstractButton.class);
1211        }
1212    }
1213}
1214