1 19 20 25 package org.netbeans.jellytools.modules.editor; 26 27 import java.awt.Robot ; 28 import java.awt.event.InputEvent ; 29 import java.awt.event.KeyEvent ; 30 import org.netbeans.jemmy.operators.*; 31 32 33 38 public class Find extends JDialogOperator { 39 40 42 public Find() { 43 super(java.util.ResourceBundle.getBundle("org.netbeans.editor.Bundle").getString("find-title")); 44 } 45 46 private JLabelOperator _lblFindWhat; 47 private JComboBoxOperator _cboFindWhat; 48 private JCheckBoxOperator _cbHighlightSearch; 49 private JCheckBoxOperator _cbIncrementalSearch; 50 private JCheckBoxOperator _cbMatchCase; 51 private JCheckBoxOperator _cbMatchWholeWordsOnly; 53 private JCheckBoxOperator _cbBackwardSearch; 54 private JCheckBoxOperator _cbWrapSearch; 55 private JCheckBoxOperator _cbRegularExpressions; 56 private JCheckBoxOperator _cbBlockSearch; 57 private JButtonOperator _btFind; 58 private JButtonOperator _btClose; 59 private JButtonOperator _btHelp; 60 61 62 66 69 public JLabelOperator lblFindWhat() { 70 if (_lblFindWhat==null) { 71 _lblFindWhat = new JLabelOperator(this, java.util.ResourceBundle.getBundle("org.netbeans.editor.Bundle").getString("find-what")); 72 } 73 return _lblFindWhat; 74 } 75 76 79 public JComboBoxOperator cboFindWhat() { 80 if (_cboFindWhat==null) { 81 _cboFindWhat = new JComboBoxOperator(this); 82 } 83 return _cboFindWhat; 84 } 85 86 89 public JCheckBoxOperator cbHighlightSearch() { 90 if (_cbHighlightSearch==null) { 91 _cbHighlightSearch = new JCheckBoxOperator(this, java.util.ResourceBundle.getBundle("org.netbeans.editor.Bundle").getString("find-highlight-search")); 92 } 93 return _cbHighlightSearch; 94 } 95 96 99 public JCheckBoxOperator cbIncrementalSearch() { 100 if (_cbIncrementalSearch==null) { 101 _cbIncrementalSearch = new JCheckBoxOperator(this, java.util.ResourceBundle.getBundle("org.netbeans.editor.Bundle").getString("find-inc-search")); 102 } 103 return _cbIncrementalSearch; 104 } 105 106 109 public JCheckBoxOperator cbMatchCase() { 110 if (_cbMatchCase==null) { 111 _cbMatchCase = new JCheckBoxOperator(this, java.util.ResourceBundle.getBundle("org.netbeans.editor.Bundle").getString("find-match-case")); 112 } 113 return _cbMatchCase; 114 } 115 116 119 125 126 129 public JCheckBoxOperator cbMatchWholeWordsOnly() { 130 if (_cbMatchWholeWordsOnly==null) { 131 _cbMatchWholeWordsOnly = new JCheckBoxOperator(this, java.util.ResourceBundle.getBundle("org.netbeans.editor.Bundle").getString("find-whole-words")); 132 } 133 return _cbMatchWholeWordsOnly; 134 } 135 136 139 public JCheckBoxOperator cbBackwardSearch() { 140 if (_cbBackwardSearch==null) { 141 _cbBackwardSearch = new JCheckBoxOperator(this, java.util.ResourceBundle.getBundle("org.netbeans.editor.Bundle").getString("find-backward-search")); 142 } 143 return _cbBackwardSearch; 144 } 145 146 149 public JCheckBoxOperator cbWrapSearch() { 150 if (_cbWrapSearch==null) { 151 _cbWrapSearch = new JCheckBoxOperator(this, java.util.ResourceBundle.getBundle("org.netbeans.editor.Bundle").getString("find-wrap-search")); 152 } 153 return _cbWrapSearch; 154 } 155 156 159 public JCheckBoxOperator cbRegularExpressions() { 160 if (_cbRegularExpressions==null) { 161 _cbRegularExpressions = new JCheckBoxOperator(this, java.util.ResourceBundle.getBundle("org.netbeans.editor.Bundle").getString("find-reg-exp")); 162 } 163 return _cbRegularExpressions; 164 } 165 166 169 public JCheckBoxOperator cbBlockSearch() { 170 if (_cbBlockSearch==null) { 171 _cbBlockSearch = new JCheckBoxOperator(this, java.util.ResourceBundle.getBundle("org.netbeans.editor.Bundle").getString("find-block-search")); 172 } 173 return _cbBlockSearch; 174 } 175 176 179 public JButtonOperator btFind() { 180 if (_btFind==null) { 181 _btFind = new JButtonOperator(this, java.util.ResourceBundle.getBundle("org.netbeans.editor.Bundle").getString("find-button-find")); 182 } 183 return _btFind; 184 } 185 186 189 public JButtonOperator btClose() { 190 if (_btClose==null) { 191 _btClose = new JButtonOperator(this, java.util.ResourceBundle.getBundle("org.netbeans.editor.Bundle").getString("find-button-cancel")); 192 } 193 return _btClose; 194 } 195 196 199 public JButtonOperator btHelp() { 200 if (_btHelp==null) { 201 _btHelp = new JButtonOperator(this, java.util.ResourceBundle.getBundle("org.openide.explorer.propertysheet.Bundle").getString("CTL_Help")); 202 } 203 return _btHelp; 204 } 205 206 207 211 214 public String getSelectedFindWhat() { 215 return cboFindWhat().getSelectedItem().toString(); 216 } 217 218 221 public void selectFindWhat(String item) { 222 cboFindWhat().selectItem(item); 223 } 224 225 228 public void typeFindWhat(String text) { 229 cboFindWhat().typeText(text); 230 } 231 232 235 public void checkHighlightSearch(boolean state) { 236 if (cbHighlightSearch().isSelected()!=state) { 237 cbHighlightSearch().push(); 238 } 239 } 240 241 244 public void checkIncrementalSearch(boolean state) { 245 if (cbIncrementalSearch().isSelected()!=state) { 246 cbIncrementalSearch().push(); 247 } 248 } 249 250 253 public void checkMatchCase(boolean state) { 254 if (cbMatchCase().isSelected()!=state) { 255 cbMatchCase().push(); 256 } 257 } 258 259 262 267 268 271 public void checkMatchWholeWordsOnly(boolean state) { 272 if (cbMatchWholeWordsOnly().isSelected()!=state) { 273 cbMatchWholeWordsOnly().push(); 274 } 275 } 276 277 280 public void checkBackwardSearch(boolean state) { 281 if (cbBackwardSearch().isSelected()!=state) { 282 cbBackwardSearch().push(); 283 } 284 } 285 286 289 public void checkWrapSearch(boolean state) { 290 if (cbWrapSearch().isSelected()!=state) { 291 cbWrapSearch().push(); 292 } 293 } 294 295 298 public void checkRegularExpressions(boolean state) { 299 if (cbRegularExpressions().isSelected()!=state) { 300 cbRegularExpressions().push(); 301 } 302 } 303 304 307 public void checkBlockSearch(boolean state) { 308 if (cbBlockSearch().isSelected()!=state) { 309 cbBlockSearch().push(); 310 } 311 } 312 313 315 public void find() { 316 btFind().push(); 317 } 318 319 321 public void close() { 322 btClose().push(); 323 } 324 325 327 public void help() { 328 btHelp().push(); 329 } 330 331 332 336 338 public void verify() { 339 lblFindWhat(); 340 cboFindWhat(); 341 cbHighlightSearch(); 342 cbIncrementalSearch(); 343 cbMatchCase(); 344 cbMatchWholeWordsOnly(); 346 cbBackwardSearch(); 347 cbWrapSearch(); 348 cbRegularExpressions(); 349 cbBlockSearch(); 350 btFind(); 351 btClose(); 352 btHelp(); 353 } 354 355 public static void find(String text) { 356 Find op=new Find(); 357 op.typeFindWhat(text); 358 op.find(); 359 } 360 361 public static void find(String text,Robot robot) { 362 Find op=new Find(); 363 robot.waitForIdle(); 364 java.awt.Point p=op.cboFindWhat().getLocationOnScreen(); 365 int x=p.x+op.cboFindWhat().getWidth()/2; 366 int y=p.y+op.cboFindWhat().getHeight()/2; 367 robot.mouseMove(x,y); 368 robot.mousePress(InputEvent.BUTTON1_MASK); 369 robot.delay(50); 370 robot.mouseRelease(InputEvent.BUTTON1_MASK); 371 char c; 372 boolean upper; 373 for (int i=0;i < text.length();i++) { 374 c=text.charAt(i); 375 if (Character.isUpperCase(c)) { 376 upper=true; 377 } else { 378 upper=false; 379 c=(char)(Character.toUpperCase((char)c)); 380 } 381 if (upper) { 382 robot.keyPress(KeyEvent.VK_SHIFT); 383 } 384 robot.keyPress((int)c); 385 robot.delay(5); 386 robot.keyRelease((int)c); 387 robot.delay(5); 388 if (upper) { 389 robot.keyRelease(KeyEvent.VK_SHIFT); 390 } 391 } 392 p=op.btFind().getLocationOnScreen(); 393 x=p.x+op.btFind().getWidth()/2; 394 y=p.y+op.btFind().getHeight()/2; 395 robot.mouseMove(x,y); 396 robot.mousePress(InputEvent.BUTTON1_MASK); 397 robot.delay(50); 398 robot.mouseRelease(InputEvent.BUTTON1_MASK); 399 robot.delay(50); 400 robot.waitForIdle(); 401 } 402 403 404 407 public static void main(String args[]) { 408 new Find().verify(); 409 System.out.println("Find verification finished."); 410 try { 411 Robot robot=new Robot (); 412 System.out.println("Start delay."); 413 robot.delay(2000); 414 System.out.println("Delayed"); 415 robot.waitForIdle(); 416 robot.keyPress(KeyEvent.VK_CONTROL); 417 robot.delay(1); 418 robot.keyPress(KeyEvent.VK_F); 419 robot.delay(20); 420 robot.keyRelease(KeyEvent.VK_F); 421 robot.delay(1); 422 robot.keyRelease(KeyEvent.VK_CONTROL); 423 System.out.println("1"); 424 robot.waitForIdle(); 425 System.out.println("2"); 426 Find.find("aaa",robot); 427 System.out.println("3"); 428 429 } catch (Exception ex) { 430 ex.printStackTrace(); 431 } 432 } 433 } 434 435 | Popular Tags |