1/* 2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23package org.netbeans.jemmy.operators; 24 25import java.awt.Container; 26 27import javax.swing.JCheckBox; 28 29import org.netbeans.jemmy.ComponentChooser; 30import org.netbeans.jemmy.TimeoutExpiredException; 31 32/** 33 * 34 * <BR><BR>Timeouts used: <BR> 35 * AbstractButtonOperator.PushButtonTimeout - time between button pressing and 36 * releasing<BR> 37 * ComponentOperator.WaitComponentTimeout - time to wait button displayed <BR> 38 * ComponentOperator.WaitComponentEnabledTimeout - time to wait button enabled 39 * <BR>. 40 * 41 * @see org.netbeans.jemmy.Timeouts 42 * 43 * @author Alexandre Iline (alexandre.iline@oracle.com) 44 * 45 */ 46public class JCheckBoxOperator extends JToggleButtonOperator { 47 48 /** 49 * Constructor. 50 * 51 * @param b a component 52 */ 53 public JCheckBoxOperator(JCheckBox b) { 54 super(b); 55 } 56 57 /** 58 * Constructs a JCheckBoxOperator object. 59 * 60 * @param cont a container 61 * @param chooser a component chooser specifying searching criteria. 62 * @param index an index between appropriate ones. 63 */ 64 public JCheckBoxOperator(ContainerOperator<?> cont, ComponentChooser chooser, int index) { 65 this((JCheckBox) cont. 66 waitSubComponent(new JCheckBoxFinder(chooser), 67 index)); 68 copyEnvironment(cont); 69 } 70 71 /** 72 * Constructs a JCheckBoxOperator object. 73 * 74 * @param cont a container 75 * @param chooser a component chooser specifying searching criteria. 76 */ 77 public JCheckBoxOperator(ContainerOperator<?> cont, ComponentChooser chooser) { 78 this(cont, chooser, 0); 79 } 80 81 /** 82 * Constructor. Waits component in container first. Uses cont's timeout and 83 * output for waiting and to init operator. 84 * 85 * @param cont a container 86 * @param text Button text. 87 * @param index Ordinal component index. 88 * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean) 89 * @throws TimeoutExpiredException 90 */ 91 public JCheckBoxOperator(ContainerOperator<?> cont, String text, int index) { 92 this((JCheckBox) waitComponent(cont, 93 new JCheckBoxFinder(new AbstractButtonOperator.AbstractButtonByLabelFinder(text, 94 cont.getComparator())), 95 index)); 96 copyEnvironment(cont); 97 } 98 99 /** 100 * Constructor. Waits component in container first. Uses cont's timeout and 101 * output for waiting and to init operator. 102 * 103 * @param cont a container 104 * @param text Button text. 105 * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean) 106 * @throws TimeoutExpiredException 107 */ 108 public JCheckBoxOperator(ContainerOperator<?> cont, String text) { 109 this(cont, text, 0); 110 } 111 112 /** 113 * Constructor. Waits component in container first. Uses cont's timeout and 114 * output for waiting and to init operator. 115 * 116 * @param cont a container 117 * @param index Ordinal component index. 118 * @throws TimeoutExpiredException 119 */ 120 public JCheckBoxOperator(ContainerOperator<?> cont, int index) { 121 this((JCheckBox) waitComponent(cont, 122 new JCheckBoxFinder(), 123 index)); 124 copyEnvironment(cont); 125 } 126 127 /** 128 * Constructor. Waits component in container first. Uses cont's timeout and 129 * output for waiting and to init operator. 130 * 131 * @param cont a container 132 * @throws TimeoutExpiredException 133 */ 134 public JCheckBoxOperator(ContainerOperator<?> cont) { 135 this(cont, 0); 136 } 137 138 /** 139 * Searches JCheckBox in container. 140 * 141 * @param cont Container to search component in. 142 * @param chooser org.netbeans.jemmy.ComponentChooser implementation. 143 * @param index Ordinal component index. 144 * @return JCheckBox instance or null if component was not found. 145 */ 146 public static JCheckBox findJCheckBox(Container cont, ComponentChooser chooser, int index) { 147 return (JCheckBox) findJToggleButton(cont, new JCheckBoxFinder(chooser), index); 148 } 149 150 /** 151 * Searches 0'th JCheckBox in container. 152 * 153 * @param cont Container to search component in. 154 * @param chooser org.netbeans.jemmy.ComponentChooser implementation. 155 * @return JCheckBox instance or null if component was not found. 156 */ 157 public static JCheckBox findJCheckBox(Container cont, ComponentChooser chooser) { 158 return findJCheckBox(cont, chooser, 0); 159 } 160 161 /** 162 * Searches JCheckBox by text. 163 * 164 * @param cont Container to search component in. 165 * @param text Button text. If null, contents is not checked. 166 * @param ce Compare text exactly. 167 * @param ccs Compare text case sensitively. 168 * @param index Ordinal component index. 169 * @return JCheckBox instance or null if component was not found. 170 * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean) 171 */ 172 public static JCheckBox findJCheckBox(Container cont, String text, boolean ce, boolean ccs, int index) { 173 return (findJCheckBox(cont, 174 new JCheckBoxFinder(new AbstractButtonOperator.AbstractButtonByLabelFinder(text, 175 new DefaultStringComparator(ce, ccs))), 176 index)); 177 } 178 179 /** 180 * Searches JCheckBox by text. 181 * 182 * @param cont Container to search component in. 183 * @param text Button text. If null, contents is not checked. 184 * @param ce Compare text exactly. 185 * @param ccs Compare text case sensitively. 186 * @return JCheckBox instance or null if component was not found. 187 * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean) 188 */ 189 public static JCheckBox findJCheckBox(Container cont, String text, boolean ce, boolean ccs) { 190 return findJCheckBox(cont, text, ce, ccs, 0); 191 } 192 193 /** 194 * Waits JCheckBox in container. 195 * 196 * @param cont Container to search component in. 197 * @param chooser org.netbeans.jemmy.ComponentChooser implementation. 198 * @param index Ordinal component index. 199 * @return JCheckBox instance. 200 * @throws TimeoutExpiredException 201 */ 202 public static JCheckBox waitJCheckBox(Container cont, ComponentChooser chooser, int index) { 203 return (JCheckBox) waitJToggleButton(cont, new JCheckBoxFinder(chooser), index); 204 } 205 206 /** 207 * Waits 0'th JCheckBox in container. 208 * 209 * @param cont Container to search component in. 210 * @param chooser org.netbeans.jemmy.ComponentChooser implementation. 211 * @return JCheckBox instance. 212 * @throws TimeoutExpiredException 213 */ 214 public static JCheckBox waitJCheckBox(Container cont, ComponentChooser chooser) { 215 return waitJCheckBox(cont, chooser, 0); 216 } 217 218 /** 219 * Waits JCheckBox by text. 220 * 221 * @param cont Container to search component in. 222 * @param text Button text. If null, contents is not checked. 223 * @param ce Compare text exactly. 224 * @param ccs Compare text case sensitively. 225 * @param index Ordinal component index. 226 * @return JCheckBox instance. 227 * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean) 228 * @throws TimeoutExpiredException 229 */ 230 public static JCheckBox waitJCheckBox(Container cont, String text, boolean ce, boolean ccs, int index) { 231 return (waitJCheckBox(cont, 232 new JCheckBoxFinder(new AbstractButtonOperator.AbstractButtonByLabelFinder(text, 233 new DefaultStringComparator(ce, ccs))), 234 index)); 235 } 236 237 /** 238 * Waits JCheckBox by text. 239 * 240 * @param cont Container to search component in. 241 * @param text Button text. If null, contents is not checked. 242 * @param ce Compare text exactly. 243 * @param ccs Compare text case sensitively. 244 * @return JCheckBox instance. 245 * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean) 246 * @throws TimeoutExpiredException 247 */ 248 public static JCheckBox waitJCheckBox(Container cont, String text, boolean ce, boolean ccs) { 249 return waitJCheckBox(cont, text, ce, ccs, 0); 250 } 251 252 /** 253 * Checks component type. 254 */ 255 public static class JCheckBoxFinder extends Finder { 256 257 /** 258 * Constructs JCheckBoxFinder. 259 * 260 * @param sf other searching criteria. 261 */ 262 public JCheckBoxFinder(ComponentChooser sf) { 263 super(JCheckBox.class, sf); 264 } 265 266 /** 267 * Constructs JCheckBoxFinder. 268 */ 269 public JCheckBoxFinder() { 270 super(JCheckBox.class); 271 } 272 } 273} 274