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$ $Revision$ $Date$
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.JemmyProperties;
052:
053: import java.awt.Component;
054:
055: import javax.swing.JCheckBoxMenuItem;
056:
057: /**
058: *
059: * <BR><BR>Timeouts used: <BR>
060: * JMenuItemOperator.PushMenuTimeout - time between button pressing and releasing<BR>
061: * ComponentOperator.WaitComponentTimeout - time to wait button displayed <BR>
062: * ComponentOperator.WaitComponentEnabledTimeout - time to wait button enabled <BR>.
063: *
064: * @see org.netbeans.jemmy.Timeouts
065: *
066: * @author Alexandre Iline (alexandre.iline@sun.com)
067: *
068: */
069:
070: public class JCheckBoxMenuItemOperator extends JMenuItemOperator {
071: /**
072: * Constructor.
073: * @param item a component.
074: */
075: public JCheckBoxMenuItemOperator(JCheckBoxMenuItem item) {
076: super (item);
077: setTimeouts(JemmyProperties.getProperties().getTimeouts());
078: setOutput(JemmyProperties.getProperties().getOutput());
079: }
080:
081: /**
082: * Constructs a JCheckBoxMenuItemOperator 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 JCheckBoxMenuItemOperator(ContainerOperator cont,
088: ComponentChooser chooser, int index) {
089: this ((JCheckBoxMenuItem) cont.waitSubComponent(
090: new JCheckBoxMenuItemFinder(chooser), index));
091: copyEnvironment(cont);
092: }
093:
094: /**
095: * Constructs a JCheckBoxMenuItemOperator object.
096: * @param cont a container
097: * @param chooser a component chooser specifying searching criteria.
098: */
099: public JCheckBoxMenuItemOperator(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: */
113: public JCheckBoxMenuItemOperator(ContainerOperator cont,
114: String text, int index) {
115: this ((JCheckBoxMenuItem) waitComponent(cont,
116: new JCheckBoxMenuItemByLabelFinder(text, cont
117: .getComparator()), index));
118: setTimeouts(cont.getTimeouts());
119: setOutput(cont.getOutput());
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: */
130: public JCheckBoxMenuItemOperator(ContainerOperator cont, String text) {
131: this (cont, text, 0);
132: }
133:
134: /**
135: * Constructor.
136: * Waits component in container first.
137: * Uses cont's timeout and output for waiting and to init operator.
138: * @param cont a container
139: * @param index Ordinal component index.
140: */
141: public JCheckBoxMenuItemOperator(ContainerOperator cont, int index) {
142: this ((JCheckBoxMenuItem) waitComponent(cont,
143: new JCheckBoxMenuItemFinder(), index));
144: copyEnvironment(cont);
145: }
146:
147: /**
148: * Constructor.
149: * Waits component in container first.
150: * Uses cont's timeout and output for waiting and to init operator.
151: * @param cont a container
152: */
153: public JCheckBoxMenuItemOperator(ContainerOperator cont) {
154: this (cont, 0);
155: }
156:
157: ////////////////////////////////////////////////////////
158: //Mapping //
159:
160: /**Maps <code>JCheckBoxMenuItem.getState()</code> through queue*/
161: public boolean getState() {
162: return (runMapping(new MapBooleanAction("getState") {
163: public boolean map() {
164: return (((JCheckBoxMenuItem) getSource()).getState());
165: }
166: }));
167: }
168:
169: /**Maps <code>JCheckBoxMenuItem.setState(boolean)</code> through queue*/
170: public void setState(final boolean b) {
171: runMapping(new MapVoidAction("setState") {
172: public void map() {
173: ((JCheckBoxMenuItem) getSource()).setState(b);
174: }
175: });
176: }
177:
178: //End of mapping //
179: ////////////////////////////////////////////////////////
180:
181: /**
182: * Allows to find component by text.
183: */
184: public static class JCheckBoxMenuItemByLabelFinder implements
185: ComponentChooser {
186: String label;
187: StringComparator comparator;
188:
189: /**
190: * Constructs JCheckBoxMenuItemByLabelFinder.
191: * @param lb a text pattern
192: * @param comparator specifies string comparision algorithm.
193: */
194: public JCheckBoxMenuItemByLabelFinder(String lb,
195: StringComparator comparator) {
196: label = lb;
197: this .comparator = comparator;
198: }
199:
200: /**
201: * Constructs JCheckBoxMenuItemByLabelFinder.
202: * @param lb a text pattern
203: */
204: public JCheckBoxMenuItemByLabelFinder(String lb) {
205: this (lb, Operator.getDefaultStringComparator());
206: }
207:
208: public boolean checkComponent(Component comp) {
209: if (comp instanceof JCheckBoxMenuItem) {
210: if (((JCheckBoxMenuItem) comp).getText() != null) {
211: return (comparator
212: .equals(((JCheckBoxMenuItem) comp)
213: .getText(), label));
214: }
215: }
216: return (false);
217: }
218:
219: public String getDescription() {
220: return ("JCheckBoxMenuItem with text \"" + label + "\"");
221: }
222: }
223:
224: /**
225: * Checks component type.
226: */
227: public static class JCheckBoxMenuItemFinder extends Finder {
228: /**
229: * Constructs JCheckBoxMenuItemFinder.
230: * @param sf other searching criteria.
231: */
232: public JCheckBoxMenuItemFinder(ComponentChooser sf) {
233: super (JCheckBoxMenuItem.class, sf);
234: }
235:
236: /**
237: * Constructs JCheckBoxMenuItemFinder.
238: */
239: public JCheckBoxMenuItemFinder() {
240: super (JCheckBoxMenuItem.class);
241: }
242: }
243: }
|