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.Component; 26 27import javax.swing.JRadioButtonMenuItem; 28 29import org.netbeans.jemmy.ComponentChooser; 30import org.netbeans.jemmy.JemmyProperties; 31 32/** 33 * 34 * <BR><BR>Timeouts used: <BR> 35 * JMenuItemOperator.PushMenuTimeout - 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 JRadioButtonMenuItemOperator extends JMenuItemOperator { 47 48 /** 49 * Constructor. 50 * 51 * @param item a component 52 */ 53 public JRadioButtonMenuItemOperator(JRadioButtonMenuItem item) { 54 super(item); 55 setTimeouts(JemmyProperties.getProperties().getTimeouts()); 56 setOutput(JemmyProperties.getProperties().getOutput()); 57 } 58 59 /** 60 * Constructs a JRadioButtonMenuItemOperator object. 61 * 62 * @param cont a container 63 * @param chooser a component chooser specifying searching criteria. 64 * @param index an index between appropriate ones. 65 */ 66 public JRadioButtonMenuItemOperator(ContainerOperator<?> cont, ComponentChooser chooser, int index) { 67 this((JRadioButtonMenuItem) cont. 68 waitSubComponent(new JRadioButtonMenuItemFinder(chooser), 69 index)); 70 copyEnvironment(cont); 71 } 72 73 /** 74 * Constructs a JRadioButtonMenuItemOperator object. 75 * 76 * @param cont a container 77 * @param chooser a component chooser specifying searching criteria. 78 */ 79 public JRadioButtonMenuItemOperator(ContainerOperator<?> cont, ComponentChooser chooser) { 80 this(cont, chooser, 0); 81 } 82 83 /** 84 * Constructor. Waits component in container first. Uses cont's timeout and 85 * output for waiting and to init operator. 86 * 87 * @param cont a container 88 * @param text Button text. 89 * @param index Ordinal component index. 90 * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean) 91 */ 92 public JRadioButtonMenuItemOperator(ContainerOperator<?> cont, String text, int index) { 93 this((JRadioButtonMenuItem) waitComponent(cont, 94 new JRadioButtonMenuItemByLabelFinder(text, 95 cont.getComparator()), 96 index)); 97 setTimeouts(cont.getTimeouts()); 98 setOutput(cont.getOutput()); 99 } 100 101 /** 102 * Constructor. Waits component in container first. Uses cont's timeout and 103 * output for waiting and to init operator. 104 * 105 * @param cont a container 106 * @param text Button text. 107 * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean) 108 */ 109 public JRadioButtonMenuItemOperator(ContainerOperator<?> cont, String text) { 110 this(cont, text, 0); 111 } 112 113 /** 114 * Constructor. Waits component in container first. Uses cont's timeout and 115 * output for waiting and to init operator. 116 * 117 * @param cont a container 118 * @param index Ordinal component index. 119 */ 120 public JRadioButtonMenuItemOperator(ContainerOperator<?> cont, int index) { 121 this((JRadioButtonMenuItem) waitComponent(cont, 122 new JRadioButtonMenuItemFinder(), 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 */ 133 public JRadioButtonMenuItemOperator(ContainerOperator<?> cont) { 134 this(cont, 0); 135 } 136 137 //////////////////////////////////////////////////////// 138 //Mapping // 139 //End of mapping // 140 //////////////////////////////////////////////////////// 141 /** 142 * Allows to find component by text. 143 */ 144 public static class JRadioButtonMenuItemByLabelFinder implements ComponentChooser { 145 146 String label; 147 StringComparator comparator; 148 149 /** 150 * Constructs JRadioButtonMenuItemByLabelFinder. 151 * 152 * @param lb a text pattern 153 * @param comparator specifies string comparision algorithm. 154 */ 155 public JRadioButtonMenuItemByLabelFinder(String lb, StringComparator comparator) { 156 label = lb; 157 this.comparator = comparator; 158 } 159 160 /** 161 * Constructs JRadioButtonMenuItemByLabelFinder. 162 * 163 * @param lb a text pattern 164 */ 165 public JRadioButtonMenuItemByLabelFinder(String lb) { 166 this(lb, Operator.getDefaultStringComparator()); 167 } 168 169 @Override 170 public boolean checkComponent(Component comp) { 171 if (comp instanceof JRadioButtonMenuItem) { 172 if (((JRadioButtonMenuItem) comp).getText() != null) { 173 return (comparator.equals(((JRadioButtonMenuItem) comp).getText(), 174 label)); 175 } 176 } 177 return false; 178 } 179 180 @Override 181 public String getDescription() { 182 return "JRadioButtonMenuItem with text \"" + label + "\""; 183 } 184 185 @Override 186 public String toString() { 187 return "JRadioButtonMenuItemByLabelFinder{" + "label=" + label + ", comparator=" + comparator + '}'; 188 } 189 } 190 191 /** 192 * Checks component type. 193 */ 194 public static class JRadioButtonMenuItemFinder extends Finder { 195 196 /** 197 * Constructs JRadioButtonMenuItemFinder. 198 * 199 * @param sf other searching criteria. 200 */ 201 public JRadioButtonMenuItemFinder(ComponentChooser sf) { 202 super(JRadioButtonMenuItem.class, sf); 203 } 204 205 /** 206 * Constructs JRadioButtonMenuItemFinder. 207 */ 208 public JRadioButtonMenuItemFinder() { 209 super(JRadioButtonMenuItem.class); 210 } 211 } 212} 213