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: JToggleButtonOperator.java,v 1.5 2007/10/05 11:35:13 jskrivanek Exp $ $Revision: 1.5 $ $Date: 2007/10/05 11:35:13 $
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 javax.swing.JToggleButton;
057:
058: /**
059: *
060: * <BR><BR>Timeouts used: <BR>
061: * AbstractButtonOperator.PushButtonTimeout - time between button pressing and releasing<BR>
062: * ComponentOperator.WaitComponentTimeout - time to wait button displayed <BR>
063: * ComponentOperator.WaitComponentEnabledTimeout - time to wait button enabled <BR>.
064: *
065: * @see org.netbeans.jemmy.Timeouts
066: *
067: * @author Alexandre Iline (alexandre.iline@sun.com)
068: *
069: */
070:
071: public class JToggleButtonOperator extends AbstractButtonOperator {
072:
073: /**
074: * Constructor.
075: * @param b a component
076: */
077: public JToggleButtonOperator(JToggleButton b) {
078: super (b);
079: }
080:
081: /**
082: * Constructs a JToggleButtonOperator object.
083: * @param cont a container
084: * @param chooser a component chooser specifying searching criteria.
085: * @param index an index between appropriate ones.
086: */
087: public JToggleButtonOperator(ContainerOperator cont,
088: ComponentChooser chooser, int index) {
089: this ((JToggleButton) cont.waitSubComponent(
090: new JToggleButtonFinder(chooser), index));
091: copyEnvironment(cont);
092: }
093:
094: /**
095: * Constructs a JToggleButtonOperator object.
096: * @param cont a container
097: * @param chooser a component chooser specifying searching criteria.
098: */
099: public JToggleButtonOperator(ContainerOperator cont,
100: ComponentChooser chooser) {
101: this (cont, chooser, 0);
102: }
103:
104: /**
105: * Constructor.
106: * Waits component in container first.
107: * Uses cont's timeout and output for waiting and to init operator.
108: * @param cont a container
109: * @param text Button text.
110: * @param index Ordinal component index.
111: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
112: * @throws TimeoutExpiredException
113: */
114: public JToggleButtonOperator(ContainerOperator cont, String text,
115: int index) {
116: this (
117: (JToggleButton) waitComponent(
118: cont,
119: new JToggleButtonFinder(
120: new AbstractButtonOperator.AbstractButtonByLabelFinder(
121: text, cont.getComparator())),
122: index));
123: copyEnvironment(cont);
124: }
125:
126: /**
127: * Constructor.
128: * Waits component in container first.
129: * Uses cont's timeout and output for waiting and to init operator.
130: * @param cont a container
131: * @param text Button text.
132: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
133: * @throws TimeoutExpiredException
134: */
135: public JToggleButtonOperator(ContainerOperator cont, String text) {
136: this (cont, text, 0);
137: }
138:
139: /**
140: * Constructor.
141: * Waits component in container first.
142: * Uses cont's timeout and output for waiting and to init operator.
143: * @param cont a container
144: * @param index Ordinal component index.
145: * @throws TimeoutExpiredException
146: */
147: public JToggleButtonOperator(ContainerOperator cont, int index) {
148: this ((JToggleButton) waitComponent(cont,
149: new JToggleButtonFinder(), index));
150: copyEnvironment(cont);
151: }
152:
153: /**
154: * Constructor.
155: * Waits component in container first.
156: * Uses cont's timeout and output for waiting and to init operator.
157: * @param cont a container
158: * @throws TimeoutExpiredException
159: */
160: public JToggleButtonOperator(ContainerOperator cont) {
161: this (cont, 0);
162: }
163:
164: /**
165: * Searches JToggleButton in container.
166: * @param cont Container to search component in.
167: * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
168: * @param index Ordinal component index.
169: * @return JToggleButton instance or null if component was not found.
170: */
171: public static JToggleButton findJToggleButton(Container cont,
172: ComponentChooser chooser, int index) {
173: return ((JToggleButton) findAbstractButton(cont,
174: new JToggleButtonFinder(chooser), index));
175: }
176:
177: /**
178: * Searches 0'th JToggleButton in container.
179: * @param cont Container to search component in.
180: * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
181: * @return JToggleButton instance or null if component was not found.
182: */
183: public static JToggleButton findJToggleButton(Container cont,
184: ComponentChooser chooser) {
185: return (findJToggleButton(cont, chooser, 0));
186: }
187:
188: /**
189: * Searches JToggleButton by text.
190: * @param cont Container to search component in.
191: * @param text Button text. If null, contents is not checked.
192: * @param ce Compare text exactly.
193: * @param ccs Compare text case sensitively.
194: * @param index Ordinal component index.
195: * @return JToggleButton instance or null if component was not found.
196: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
197: */
198: public static JToggleButton findJToggleButton(Container cont,
199: String text, boolean ce, boolean ccs, int index) {
200: return (findJToggleButton(cont, new JToggleButtonFinder(
201: new AbstractButtonOperator.AbstractButtonByLabelFinder(
202: text, new DefaultStringComparator(ce, ccs))),
203: index));
204: }
205:
206: /**
207: * Searches JToggleButton by text.
208: * @param cont Container to search component in.
209: * @param text Button text. If null, contents is not checked.
210: * @param ce Compare text exactly.
211: * @param ccs Compare text case sensitively.
212: * @return JToggleButton instance or null if component was not found.
213: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
214: */
215: public static JToggleButton findJToggleButton(Container cont,
216: String text, boolean ce, boolean ccs) {
217: return (findJToggleButton(cont, text, ce, ccs, 0));
218: }
219:
220: /**
221: * Waits JToggleButton in container.
222: * @param cont Container to search component in.
223: * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
224: * @param index Ordinal component index.
225: * @return JToggleButton instance.
226: * @throws TimeoutExpiredException
227: */
228: public static JToggleButton waitJToggleButton(Container cont,
229: ComponentChooser chooser, int index) {
230: return ((JToggleButton) waitAbstractButton(cont,
231: new JToggleButtonFinder(chooser), index));
232: }
233:
234: /**
235: * Waits 0'th JToggleButton in container.
236: * @param cont Container to search component in.
237: * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
238: * @return JToggleButton instance.
239: * @throws TimeoutExpiredException
240: */
241: public static JToggleButton waitJToggleButton(Container cont,
242: ComponentChooser chooser) {
243: return (waitJToggleButton(cont, chooser, 0));
244: }
245:
246: /**
247: * Waits JToggleButton by text.
248: * @param cont Container to search component in.
249: * @param text Button text. If null, contents is not checked.
250: * @param ce Compare text exactly.
251: * @param ccs Compare text case sensitively.
252: * @param index Ordinal component index.
253: * @return JToggleButton instance.
254: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
255: * @throws TimeoutExpiredException
256: */
257: public static JToggleButton waitJToggleButton(Container cont,
258: String text, boolean ce, boolean ccs, int index) {
259: return (waitJToggleButton(cont, new JToggleButtonFinder(
260: new AbstractButtonOperator.AbstractButtonByLabelFinder(
261: text, new DefaultStringComparator(ce, ccs))),
262: index));
263: }
264:
265: /**
266: * Waits JToggleButton by text.
267: * @param cont Container to search component in.
268: * @param text Button text. If null, contents is not checked.
269: * @param ce Compare text exactly.
270: * @param ccs Compare text case sensitively.
271: * @return JToggleButton instance.
272: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
273: * @throws TimeoutExpiredException
274: */
275: public static JToggleButton waitJToggleButton(Container cont,
276: String text, boolean ce, boolean ccs) {
277: return (waitJToggleButton(cont, text, ce, ccs, 0));
278: }
279:
280: /**
281: * Prepares the button to click.
282: */
283: protected void prepareToClick() {
284: makeComponentVisible();
285: }
286:
287: /**
288: * Checks component type.
289: */
290: public static class JToggleButtonFinder extends Finder {
291: /**
292: * Constructs JToggleButtonFinder.
293: * @param sf other searching criteria.
294: */
295: public JToggleButtonFinder(ComponentChooser sf) {
296: super (JToggleButton.class, sf);
297: }
298:
299: /**
300: * Constructs JToggleButtonFinder.
301: */
302: public JToggleButtonFinder() {
303: super (JToggleButton.class);
304: }
305: }
306: }
|