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: JPasswordFieldOperator.java,v 1.6 2007/10/05 11:35:19 jskrivanek Exp $ $Revision: 1.6 $ $Date: 2007/10/05 11:35:19 $
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 java.util.Hashtable;
057:
058: import javax.swing.JPasswordField;
059:
060: /**
061: * <BR><BR>Timeouts used: <BR>
062: * JTextComponentOperator.PushKeyTimeout - time between key pressing and releasing during text typing <BR>
063: * JTextComponentOperator.BetweenKeysTimeout - time to sleep between two chars typing <BR>
064: * JTextComponentOperator.ChangeCaretPositionTimeout - maximum time to chenge caret position <BR>
065: * JTextComponentOperator.TypeTextTimeout - maximum time to type text <BR>
066: * ComponentOperator.WaitComponentTimeout - time to wait component displayed <BR>
067: * ComponentOperator.WaitFocusTimeout - time to wait component focus <BR>
068: * JScrollBarOperator.OneScrollClickTimeout - time for one scroll click <BR>
069: * JScrollBarOperator.WholeScrollTimeout - time for the whole scrolling <BR>.
070: *
071: * @see org.netbeans.jemmy.Timeouts
072: *
073: * @author Alexandre Iline (alexandre.iline@sun.com)
074: *
075: */
076:
077: public class JPasswordFieldOperator extends JTextFieldOperator {
078:
079: /**
080: * Identifier for a "echo char" property.
081: * @see #getDump
082: */
083: public static final String ECHO_CHAR_DPROP = "Echo char";
084:
085: /**
086: * Constructor.
087: * @param b a component
088: */
089: public JPasswordFieldOperator(JPasswordField b) {
090: super (b);
091: }
092:
093: /**
094: * Constructs a JPasswordFieldOperator object.
095: * @param cont a container
096: * @param chooser a component chooser specifying searching criteria.
097: * @param index an index between appropriate ones.
098: */
099: public JPasswordFieldOperator(ContainerOperator cont,
100: ComponentChooser chooser, int index) {
101: this ((JPasswordField) cont.waitSubComponent(
102: new JPasswordFieldFinder(chooser), index));
103: copyEnvironment(cont);
104: }
105:
106: /**
107: * Constructs a JPasswordFieldOperator object.
108: * @param cont a container
109: * @param chooser a component chooser specifying searching criteria.
110: */
111: public JPasswordFieldOperator(ContainerOperator cont,
112: ComponentChooser chooser) {
113: this (cont, chooser, 0);
114: }
115:
116: /**
117: * Constructor.
118: * Waits component in container first.
119: * Uses cont's timeout and output for waiting and to init operator.
120: * @param cont a container
121: * @param text Button text.
122: * @param index Ordinal component index.
123: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
124: * @throws TimeoutExpiredException
125: */
126: public JPasswordFieldOperator(ContainerOperator cont, String text,
127: int index) {
128: this (
129: (JPasswordField) waitComponent(
130: cont,
131: new JPasswordFieldFinder(
132: new JTextComponentOperator.JTextComponentByTextFinder(
133: text, cont.getComparator())),
134: index));
135: copyEnvironment(cont);
136: }
137:
138: /**
139: * Constructor.
140: * Waits component in container first.
141: * Uses cont's timeout and output for waiting and to init operator.
142: * @param cont a container
143: * @param text Button text.
144: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
145: * @throws TimeoutExpiredException
146: */
147: public JPasswordFieldOperator(ContainerOperator cont, String text) {
148: this (cont, text, 0);
149: }
150:
151: /**
152: * Constructor.
153: * Waits component in container first.
154: * Uses cont's timeout and output for waiting and to init operator.
155: * @param cont a container
156: * @param index Ordinal component index.
157: * @throws TimeoutExpiredException
158: */
159: public JPasswordFieldOperator(ContainerOperator cont, int index) {
160: this ((JPasswordField) waitComponent(cont,
161: new JPasswordFieldFinder(), index));
162: copyEnvironment(cont);
163: }
164:
165: /**
166: * Constructor.
167: * Waits component in container first.
168: * Uses cont's timeout and output for waiting and to init operator.
169: * @param cont a container
170: * @throws TimeoutExpiredException
171: */
172: public JPasswordFieldOperator(ContainerOperator cont) {
173: this (cont, 0);
174: }
175:
176: /**
177: * Searches JPasswordField in container.
178: * @param cont Container to search component in.
179: * @param chooser a component chooser specifying searching criteria.
180: * @param index Ordinal component index.
181: * @return JPasswordField instance or null if component was not found.
182: */
183: public static JPasswordField findJPasswordField(Container cont,
184: ComponentChooser chooser, int index) {
185: return ((JPasswordField) findJTextComponent(cont,
186: new JPasswordFieldFinder(chooser), index));
187: }
188:
189: /**
190: * Searches JPasswordField in container.
191: * @param cont Container to search component in.
192: * @param chooser a component chooser specifying searching criteria.
193: * @return JPasswordField instance or null if component was not found.
194: */
195: public static JPasswordField findJPasswordField(Container cont,
196: ComponentChooser chooser) {
197: return (findJPasswordField(cont, chooser, 0));
198: }
199:
200: /**
201: * Searches JPasswordField by text.
202: * @param cont Container to search component in.
203: * @param text Component text.
204: * @param ce Compare text exactly.
205: * @param ccs Compare text case sensitively.
206: * @param index Ordinal component index.
207: * @return JPasswordField instance or null if component was not found.
208: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
209: */
210: public static JPasswordField findJPasswordField(Container cont,
211: String text, boolean ce, boolean ccs, int index) {
212: return (findJPasswordField(cont, new JPasswordFieldFinder(
213: new JTextComponentOperator.JTextComponentByTextFinder(
214: text, new DefaultStringComparator(ce, ccs))),
215: index));
216: }
217:
218: /**
219: * Searches JPasswordField by text.
220: * @param cont Container to search component in.
221: * @param text Component text.
222: * @param ce Compare text exactly.
223: * @param ccs Compare text case sensitively.
224: * @return JPasswordField instance or null if component was not found.
225: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
226: */
227: public static JPasswordField findJPasswordField(Container cont,
228: String text, boolean ce, boolean ccs) {
229: return (findJPasswordField(cont, text, ce, ccs, 0));
230: }
231:
232: /**
233: * Waits JPasswordField in container.
234: * @param cont Container to search component in.
235: * @param chooser a component chooser specifying searching criteria.
236: * @param index Ordinal component index.
237: * @return JPasswordField instance.
238: * @throws TimeoutExpiredException
239: */
240: public static JPasswordField waitJPasswordField(Container cont,
241: ComponentChooser chooser, int index) {
242: return ((JPasswordField) waitJTextComponent(cont,
243: new JPasswordFieldFinder(chooser), index));
244: }
245:
246: /**
247: * Waits JPasswordField in container.
248: * @param cont Container to search component in.
249: * @param chooser a component chooser specifying searching criteria.
250: * @return JPasswordField instance.
251: * @throws TimeoutExpiredException
252: */
253: public static JPasswordField waitJPasswordField(Container cont,
254: ComponentChooser chooser) {
255: return (waitJPasswordField(cont, chooser, 0));
256: }
257:
258: /**
259: * Waits JPasswordField by text.
260: * @param cont Container to search component in.
261: * @param text Component text.
262: * @param ce Compare text exactly.
263: * @param ccs Compare text case sensitively.
264: * @param index Ordinal component index.
265: * @return JPasswordField instance.
266: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
267: * @throws TimeoutExpiredException
268: */
269: public static JPasswordField waitJPasswordField(Container cont,
270: String text, boolean ce, boolean ccs, int index) {
271: return (waitJPasswordField(cont, new JPasswordFieldFinder(
272: new JTextComponentOperator.JTextComponentByTextFinder(
273: text, new DefaultStringComparator(ce, ccs))),
274: index));
275: }
276:
277: /**
278: * Waits JPasswordField by text.
279: * @param cont Container to search component in.
280: * @param text Component text.
281: * @param ce Compare text exactly.
282: * @param ccs Compare text case sensitively.
283: * @return JPasswordField instance.
284: * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean)
285: * @throws TimeoutExpiredException
286: */
287: public static JPasswordField waitJPasswordField(Container cont,
288: String text, boolean ce, boolean ccs) {
289: return (waitJPasswordField(cont, text, ce, ccs, 0));
290: }
291:
292: public Hashtable getDump() {
293: Hashtable result = super .getDump();
294: result.put(ECHO_CHAR_DPROP, new Character(
295: ((JPasswordField) getSource()).getEchoChar())
296: .toString());
297: return (result);
298: }
299:
300: ////////////////////////////////////////////////////////
301: //Mapping //
302:
303: /**Maps <code>JPasswordField.echoCharIsSet()</code> through queue*/
304: public boolean echoCharIsSet() {
305: return (runMapping(new MapBooleanAction("echoCharIsSet") {
306: public boolean map() {
307: return (((JPasswordField) getSource()).echoCharIsSet());
308: }
309: }));
310: }
311:
312: /**Maps <code>JPasswordField.getEchoChar()</code> through queue*/
313: public char getEchoChar() {
314: return (runMapping(new MapCharacterAction("getEchoChar") {
315: public char map() {
316: return (((JPasswordField) getSource()).getEchoChar());
317: }
318: }));
319: }
320:
321: /**Maps <code>JPasswordField.getPassword()</code> through queue*/
322: public char[] getPassword() {
323: return ((char[]) runMapping(new MapAction("getPassword") {
324: public Object map() {
325: return (((JPasswordField) getSource()).getPassword());
326: }
327: }));
328: }
329:
330: /**Maps <code>JPasswordField.setEchoChar(char)</code> through queue*/
331: public void setEchoChar(final char c) {
332: runMapping(new MapVoidAction("setEchoChar") {
333: public void map() {
334: ((JPasswordField) getSource()).setEchoChar(c);
335: }
336: });
337: }
338:
339: //End of mapping //
340: ////////////////////////////////////////////////////////
341:
342: /**
343: * Checks component type.
344: */
345: public static class JPasswordFieldFinder extends Finder {
346: /**
347: * Constructs JPasswordFieldFinder.
348: * @param sf other searching criteria.
349: */
350: public JPasswordFieldFinder(ComponentChooser sf) {
351: super (JPasswordField.class, sf);
352: }
353:
354: /**
355: * Constructs JPasswordFieldFinder.
356: */
357: public JPasswordFieldFinder() {
358: super (JPasswordField.class);
359: }
360: }
361: }
|