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: JRadioButtonMenuItemOperator.java,v 1.5 2007/10/05 11:35:56 jskrivanek Exp $ $Revision: 1.5 $ $Date: 2007/10/05 11:35:56 $
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.JRadioButtonMenuItem;
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 JRadioButtonMenuItemOperator extends JMenuItemOperator {
071: /**
072: * Constructor.
073: * @param item a component
074: */
075: public JRadioButtonMenuItemOperator(JRadioButtonMenuItem item) {
076: super (item);
077: setTimeouts(JemmyProperties.getProperties().getTimeouts());
078: setOutput(JemmyProperties.getProperties().getOutput());
079: }
080:
081: /**
082: * Constructs a JRadioButtonMenuItemOperator 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 JRadioButtonMenuItemOperator(ContainerOperator cont,
088: ComponentChooser chooser, int index) {
089: this ((JRadioButtonMenuItem) cont.waitSubComponent(
090: new JRadioButtonMenuItemFinder(chooser), index));
091: copyEnvironment(cont);
092: }
093:
094: /**
095: * Constructs a JRadioButtonMenuItemOperator object.
096: * @param cont a container
097: * @param chooser a component chooser specifying searching criteria.
098: */
099: public JRadioButtonMenuItemOperator(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 JRadioButtonMenuItemOperator(ContainerOperator cont,
114: String text, int index) {
115: this ((JRadioButtonMenuItem) waitComponent(cont,
116: new JRadioButtonMenuItemByLabelFinder(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 JRadioButtonMenuItemOperator(ContainerOperator cont,
131: 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: */
142: public JRadioButtonMenuItemOperator(ContainerOperator cont,
143: int index) {
144: this ((JRadioButtonMenuItem) waitComponent(cont,
145: new JRadioButtonMenuItemFinder(), 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: */
155: public JRadioButtonMenuItemOperator(ContainerOperator cont) {
156: this (cont, 0);
157: }
158:
159: ////////////////////////////////////////////////////////
160: //Mapping //
161: //End of mapping //
162: ////////////////////////////////////////////////////////
163:
164: /**
165: * Allows to find component by text.
166: */
167: public static class JRadioButtonMenuItemByLabelFinder implements
168: ComponentChooser {
169: String label;
170: StringComparator comparator;
171:
172: /**
173: * Constructs JRadioButtonMenuItemByLabelFinder.
174: * @param lb a text pattern
175: * @param comparator specifies string comparision algorithm.
176: */
177: public JRadioButtonMenuItemByLabelFinder(String lb,
178: StringComparator comparator) {
179: label = lb;
180: this .comparator = comparator;
181: }
182:
183: /**
184: * Constructs JRadioButtonMenuItemByLabelFinder.
185: * @param lb a text pattern
186: */
187: public JRadioButtonMenuItemByLabelFinder(String lb) {
188: this (lb, Operator.getDefaultStringComparator());
189: }
190:
191: public boolean checkComponent(Component comp) {
192: if (comp instanceof JRadioButtonMenuItem) {
193: if (((JRadioButtonMenuItem) comp).getText() != null) {
194: return (comparator.equals(
195: ((JRadioButtonMenuItem) comp).getText(),
196: label));
197: }
198: }
199: return (false);
200: }
201:
202: public String getDescription() {
203: return ("JRadioButtonMenuItem with text \"" + label + "\"");
204: }
205: }
206:
207: /**
208: * Checks component type.
209: */
210: public static class JRadioButtonMenuItemFinder extends Finder {
211: /**
212: * Constructs JRadioButtonMenuItemFinder.
213: * @param sf other searching criteria.
214: */
215: public JRadioButtonMenuItemFinder(ComponentChooser sf) {
216: super (JRadioButtonMenuItem.class, sf);
217: }
218:
219: /**
220: * Constructs JRadioButtonMenuItemFinder.
221: */
222: public JRadioButtonMenuItemFinder() {
223: super (JRadioButtonMenuItem.class);
224: }
225: }
226: }
|