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: JCheckBoxOperator.java,v 1.5 2007/10/05 11:35:45 jskrivanek Exp $ $Revision: 1.5 $ $Date: 2007/10/05 11:35:45 $
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.JCheckBox;
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 JCheckBoxOperator extends JToggleButtonOperator {
072:
073: /**
074: * Constructor.
075: * @param b a component
076: */
077: public JCheckBoxOperator(JCheckBox b) {
078: super (b);
079: }
080:
081: /**
082: * Constructs a JCheckBoxOperator 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 JCheckBoxOperator(ContainerOperator cont,
088: ComponentChooser chooser, int index) {
089: this ((JCheckBox) cont.waitSubComponent(new JCheckBoxFinder(
090: chooser), index));
091: copyEnvironment(cont);
092: }
093:
094: /**
095: * Constructs a JCheckBoxOperator object.
096: * @param cont a container
097: * @param chooser a component chooser specifying searching criteria.
098: */
099: public JCheckBoxOperator(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 JCheckBoxOperator(ContainerOperator cont, String text,
115: int index) {
116: this ((JCheckBox) waitComponent(cont, new JCheckBoxFinder(
117: new AbstractButtonOperator.AbstractButtonByLabelFinder(
118: text, cont.getComparator())), index));
119: copyEnvironment(cont);
120: }
121:
122: /**
123: * Constructor.
124: * Waits component in container first.
125: * Uses cont's timeout and output for waiting and to init operator.
126: * @param cont a container
127: * @param text Button text.
128: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
129: * @throws TimeoutExpiredException
130: */
131: public JCheckBoxOperator(ContainerOperator cont, String text) {
132: this (cont, text, 0);
133: }
134:
135: /**
136: * Constructor.
137: * Waits component in container first.
138: * Uses cont's timeout and output for waiting and to init operator.
139: * @param cont a container
140: * @param index Ordinal component index.
141: * @throws TimeoutExpiredException
142: */
143: public JCheckBoxOperator(ContainerOperator cont, int index) {
144: this ((JCheckBox) waitComponent(cont, new JCheckBoxFinder(),
145: index));
146: copyEnvironment(cont);
147: }
148:
149: /**
150: * Constructor.
151: * Waits component in container first.
152: * Uses cont's timeout and output for waiting and to init operator.
153: * @param cont a container
154: * @throws TimeoutExpiredException
155: */
156: public JCheckBoxOperator(ContainerOperator cont) {
157: this (cont, 0);
158: }
159:
160: /**
161: * Searches JCheckBox in container.
162: * @param cont Container to search component in.
163: * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
164: * @param index Ordinal component index.
165: * @return JCheckBox instance or null if component was not found.
166: */
167: public static JCheckBox findJCheckBox(Container cont,
168: ComponentChooser chooser, int index) {
169: return ((JCheckBox) findJToggleButton(cont,
170: new JCheckBoxFinder(chooser), index));
171: }
172:
173: /**
174: * Searches 0'th JCheckBox in container.
175: * @param cont Container to search component in.
176: * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
177: * @return JCheckBox instance or null if component was not found.
178: */
179: public static JCheckBox findJCheckBox(Container cont,
180: ComponentChooser chooser) {
181: return (findJCheckBox(cont, chooser, 0));
182: }
183:
184: /**
185: * Searches JCheckBox by text.
186: * @param cont Container to search component in.
187: * @param text Button text. If null, contents is not checked.
188: * @param ce Compare text exactly.
189: * @param ccs Compare text case sensitively.
190: * @param index Ordinal component index.
191: * @return JCheckBox instance or null if component was not found.
192: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
193: */
194: public static JCheckBox findJCheckBox(Container cont, String text,
195: boolean ce, boolean ccs, int index) {
196: return (findJCheckBox(cont, new JCheckBoxFinder(
197: new AbstractButtonOperator.AbstractButtonByLabelFinder(
198: text, new DefaultStringComparator(ce, ccs))),
199: index));
200: }
201:
202: /**
203: * Searches JCheckBox by text.
204: * @param cont Container to search component in.
205: * @param text Button text. If null, contents is not checked.
206: * @param ce Compare text exactly.
207: * @param ccs Compare text case sensitively.
208: * @return JCheckBox instance or null if component was not found.
209: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
210: */
211: public static JCheckBox findJCheckBox(Container cont, String text,
212: boolean ce, boolean ccs) {
213: return (findJCheckBox(cont, text, ce, ccs, 0));
214: }
215:
216: /**
217: * Waits JCheckBox in container.
218: * @param cont Container to search component in.
219: * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
220: * @param index Ordinal component index.
221: * @return JCheckBox instance.
222: * @throws TimeoutExpiredException
223: */
224: public static JCheckBox waitJCheckBox(Container cont,
225: ComponentChooser chooser, int index) {
226: return ((JCheckBox) waitJToggleButton(cont,
227: new JCheckBoxFinder(chooser), index));
228: }
229:
230: /**
231: * Waits 0'th JCheckBox in container.
232: * @param cont Container to search component in.
233: * @param chooser org.netbeans.jemmy.ComponentChooser implementation.
234: * @return JCheckBox instance.
235: * @throws TimeoutExpiredException
236: */
237: public static JCheckBox waitJCheckBox(Container cont,
238: ComponentChooser chooser) {
239: return (waitJCheckBox(cont, chooser, 0));
240: }
241:
242: /**
243: * Waits JCheckBox by text.
244: * @param cont Container to search component in.
245: * @param text Button text. If null, contents is not checked.
246: * @param ce Compare text exactly.
247: * @param ccs Compare text case sensitively.
248: * @param index Ordinal component index.
249: * @return JCheckBox instance.
250: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
251: * @throws TimeoutExpiredException
252: */
253: public static JCheckBox waitJCheckBox(Container cont, String text,
254: boolean ce, boolean ccs, int index) {
255: return (waitJCheckBox(cont, new JCheckBoxFinder(
256: new AbstractButtonOperator.AbstractButtonByLabelFinder(
257: text, new DefaultStringComparator(ce, ccs))),
258: index));
259: }
260:
261: /**
262: * Waits JCheckBox by text.
263: * @param cont Container to search component in.
264: * @param text Button text. If null, contents is not checked.
265: * @param ce Compare text exactly.
266: * @param ccs Compare text case sensitively.
267: * @return JCheckBox instance.
268: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
269: * @throws TimeoutExpiredException
270: */
271: public static JCheckBox waitJCheckBox(Container cont, String text,
272: boolean ce, boolean ccs) {
273: return (waitJCheckBox(cont, text, ce, ccs, 0));
274: }
275:
276: /**
277: * Checks component type.
278: */
279: public static class JCheckBoxFinder extends Finder {
280: /**
281: * Constructs JCheckBoxFinder.
282: * @param sf other searching criteria.
283: */
284: public JCheckBoxFinder(ComponentChooser sf) {
285: super (JCheckBox.class, sf);
286: }
287:
288: /**
289: * Constructs JCheckBoxFinder.
290: */
291: public JCheckBoxFinder() {
292: super (JCheckBox.class);
293: }
294: }
295: }
|