JComponentOperator.java revision 13978:1993af50385d
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; 26import java.awt.Container; 27import java.awt.Dimension; 28import java.awt.Insets; 29import java.awt.Point; 30import java.awt.Rectangle; 31import java.awt.Window; 32import java.awt.event.ActionListener; 33import java.awt.event.MouseEvent; 34import java.beans.VetoableChangeListener; 35import java.util.Hashtable; 36 37import javax.accessibility.AccessibleContext; 38import javax.swing.JComponent; 39import javax.swing.JInternalFrame; 40import javax.swing.JRootPane; 41import javax.swing.JToolTip; 42import javax.swing.KeyStroke; 43import javax.swing.border.Border; 44import javax.swing.event.AncestorListener; 45 46import org.netbeans.jemmy.ComponentChooser; 47import org.netbeans.jemmy.ComponentSearcher; 48import org.netbeans.jemmy.JemmyProperties; 49import org.netbeans.jemmy.Outputable; 50import org.netbeans.jemmy.TestOut; 51import org.netbeans.jemmy.TimeoutExpiredException; 52import org.netbeans.jemmy.Timeoutable; 53import org.netbeans.jemmy.Timeouts; 54 55/** 56 * <BR><BR>Timeouts used: <BR> 57 * JComponentOperator.WaitToolTipTimeout - time to wait tool tip displayed <BR> 58 * JComponentOperator.ShowToolTipTimeout - time to show tool tip <BR> 59 * ComponentOperator.WaitComponentTimeout - time to wait component displayed 60 * <BR>. 61 * 62 * @see org.netbeans.jemmy.Timeouts 63 * 64 * @author Alexandre Iline (alexandre.iline@oracle.com) 65 * 66 */ 67public class JComponentOperator extends ContainerOperator<Container> 68 implements Timeoutable, Outputable { 69 70 /** 71 * Identifier for a "tooltip text" property. 72 * 73 * @see #getDump 74 */ 75 public static final String TOOLTIP_TEXT_DPROP = "Tooltip text"; 76 public static final String A11Y_DATA = "Accessible data (yes/no)"; 77 public static final String A11Y_NAME_DPROP = "Accessible name"; 78 public static final String A11Y_DESCRIPTION_DPROP = "Accessible decription"; 79 80 private final static long WAIT_TOOL_TIP_TIMEOUT = 10000; 81 private final static long SHOW_TOOL_TIP_TIMEOUT = 0; 82 83 private Timeouts timeouts; 84 private TestOut output; 85 86 /** 87 * Constructor. 88 * 89 * @param b a component 90 */ 91 public JComponentOperator(JComponent b) { 92 super(b); 93 } 94 95 /** 96 * Constructs a JComponentOperator object. 97 * 98 * @param cont a container 99 * @param chooser a component chooser specifying searching criteria. 100 * @param index an index between appropriate ones. 101 */ 102 public JComponentOperator(ContainerOperator<?> cont, ComponentChooser chooser, int index) { 103 this((JComponent) cont. 104 waitSubComponent(new JComponentFinder(chooser), 105 index)); 106 copyEnvironment(cont); 107 } 108 109 /** 110 * Constructs a JComponentOperator object. 111 * 112 * @param cont a container 113 * @param chooser a component chooser specifying searching criteria. 114 */ 115 public JComponentOperator(ContainerOperator<?> cont, ComponentChooser chooser) { 116 this(cont, chooser, 0); 117 } 118 119 /** 120 * Constructor. Waits component in container first. Uses cont's timeout and 121 * output for waiting and to init operator. 122 * 123 * @param cont Operator pointing a container to search component in. 124 * @param index Ordinal component index. 125 * @throws TimeoutExpiredException 126 */ 127 public JComponentOperator(ContainerOperator<?> cont, int index) { 128 this((JComponent) waitComponent(cont, 129 new JComponentFinder(ComponentSearcher.getTrueChooser("Any JComponent")), 130 index)); 131 copyEnvironment(cont); 132 } 133 134 /** 135 * Constructor. Waits component in container first. Uses cont's timeout and 136 * output for waiting and to init operator. 137 * 138 * @param cont Operator pointing a container to search component in. 139 * @throws TimeoutExpiredException 140 */ 141 public JComponentOperator(ContainerOperator<?> cont) { 142 this(cont, 0); 143 } 144 145 /** 146 * Searches JComponent in container. 147 * 148 * @param cont Container to search component in. 149 * @param chooser org.netbeans.jemmy.ComponentChooser implementation. 150 * @param index Ordinal component index. 151 * @return JComponent instance or null if component was not found. 152 */ 153 public static JComponent findJComponent(Container cont, ComponentChooser chooser, int index) { 154 return (JComponent) findComponent(cont, new JComponentFinder(chooser), index); 155 } 156 157 /** 158 * Searches 0'th JComponent in container. 159 * 160 * @param cont Container to search component in. 161 * @param chooser org.netbeans.jemmy.ComponentChooser implementation. 162 * @return JComponent instance or null if component was not found. 163 */ 164 public static JComponent findJComponent(Container cont, ComponentChooser chooser) { 165 return findJComponent(cont, chooser, 0); 166 } 167 168 /** 169 * Searches JComponent by tooltip text. 170 * 171 * @param cont Container to search component in. 172 * @param toolTipText Tooltip text. If null, contents is not checked. 173 * @param ce Compare text exactly. 174 * @param ccs Compare text case sensitively. 175 * @param index Ordinal component index. 176 * @return JComponent instance or null if component was not found. 177 * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean) 178 */ 179 public static JComponent findJComponent(Container cont, String toolTipText, boolean ce, boolean ccs, int index) { 180 return findJComponent(cont, new JComponentByTipFinder(toolTipText, new DefaultStringComparator(ce, ccs)), index); 181 } 182 183 /** 184 * Searches JComponent by tooltip text. 185 * 186 * @param cont Container to search component in. 187 * @param toolTipText Tooltip text. If null, contents is not checked. 188 * @param ce Compare text exactly. 189 * @param ccs Compare text case sensitively. 190 * @return JComponent instance or null if component was not found. 191 * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean) 192 */ 193 public static JComponent findJComponent(Container cont, String toolTipText, boolean ce, boolean ccs) { 194 return findJComponent(cont, toolTipText, ce, ccs, 0); 195 } 196 197 /** 198 * Waits JComponent in container. 199 * 200 * @param cont Container to search component in. 201 * @param chooser org.netbeans.jemmy.ComponentChooser implementation. 202 * @param index Ordinal component index. 203 * @return JComponent instance or null if component was not found. 204 * @throws TimeoutExpiredException 205 */ 206 public static JComponent waitJComponent(Container cont, ComponentChooser chooser, final int index) { 207 return (JComponent) waitComponent(cont, new JComponentFinder(chooser), index); 208 } 209 210 /** 211 * Waits 0'th JComponent in container. 212 * 213 * @param cont Container to search component in. 214 * @param chooser org.netbeans.jemmy.ComponentChooser implementation. 215 * @return JComponent instance or null if component was not found. 216 * @throws TimeoutExpiredException 217 */ 218 public static JComponent waitJComponent(Container cont, ComponentChooser chooser) { 219 return waitJComponent(cont, chooser, 0); 220 } 221 222 /** 223 * Waits JComponent by tooltip text. 224 * 225 * @param cont Container to search component in. 226 * @param toolTipText Tooltip text. If null, contents is not checked. 227 * @param ce Compare text exactly. 228 * @param ccs Compare text case sensitively. 229 * @param index Ordinal component index. 230 * @return JComponent instance or null if component was not found. 231 * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean) 232 * @throws TimeoutExpiredException 233 */ 234 public static JComponent waitJComponent(Container cont, String toolTipText, boolean ce, boolean ccs, int index) { 235 return waitJComponent(cont, new JComponentByTipFinder(toolTipText, new DefaultStringComparator(ce, ccs)), index); 236 } 237 238 /** 239 * Waits JComponent by tooltip text. 240 * 241 * @param cont Container to search component in. 242 * @param toolTipText Tooltip text. If null, contents is not checked. 243 * @param ce Compare text exactly. 244 * @param ccs Compare text case sensitively. 245 * @return JComponent instance or null if component was not found. 246 * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean) 247 * @throws TimeoutExpiredException 248 */ 249 public static JComponent waitJComponent(Container cont, String toolTipText, boolean ce, boolean ccs) { 250 return waitJComponent(cont, toolTipText, ce, ccs, 0); 251 } 252 253 static { 254 Timeouts.initDefault("JComponentOperator.WaitToolTipTimeout", WAIT_TOOL_TIP_TIMEOUT); 255 Timeouts.initDefault("JComponentOperator.ShowToolTipTimeout", SHOW_TOOL_TIP_TIMEOUT); 256 } 257 258 @Override 259 public void setTimeouts(Timeouts timeouts) { 260 super.setTimeouts(timeouts); 261 this.timeouts = timeouts; 262 } 263 264 @Override 265 public Timeouts getTimeouts() { 266 return timeouts; 267 } 268 269 @Override 270 public void setOutput(TestOut out) { 271 output = out; 272 super.setOutput(output.createErrorOutput()); 273 } 274 275 @Override 276 public TestOut getOutput() { 277 return output; 278 } 279 280 @Override 281 public int getCenterXForClick() { 282 Rectangle rect = getVisibleRect(); 283 return ((int) rect.getX() 284 + (int) rect.getWidth() / 2); 285 } 286 287 @Override 288 public int getCenterYForClick() { 289 Rectangle rect = getVisibleRect(); 290 return ((int) rect.getY() 291 + (int) rect.getHeight() / 2); 292 } 293 294 /** 295 * Showes tool tip. 296 * 297 * @return JToolTip component. 298 * @throws TimeoutExpiredException 299 */ 300 public JToolTip showToolTip() { 301 enterMouse(); 302 moveMouse(getCenterXForClick(), 303 getCenterYForClick()); 304 return waitToolTip(); 305 } 306 307 public JToolTip waitToolTip() { 308 return ((JToolTip) waitComponent(WindowOperator. 309 waitWindow(new JToolTipWindowFinder(), 310 0, 311 getTimeouts(), 312 getOutput()), 313 new JToolTipFinder(), 314 0, 315 getTimeouts(), 316 getOutput())); 317 } 318 319 /** 320 * Looks for a first window-like container. 321 * 322 * @return either WindowOperator of JInternalFrameOperator 323 */ 324 public ContainerOperator<?> getWindowContainerOperator() { 325 Component resultComp; 326 if (getSource() instanceof Window) { 327 resultComp = getSource(); 328 } else { 329 resultComp = getContainer(new ComponentChooser() { 330 @Override 331 public boolean checkComponent(Component comp) { 332 return (comp instanceof Window 333 || comp instanceof JInternalFrame); 334 } 335 336 @Override 337 public String getDescription() { 338 return ""; 339 } 340 }); 341 } 342 ContainerOperator<?> result; 343 if (resultComp instanceof Window) { 344 result = new WindowOperator((Window) resultComp); 345 } else { 346 result = new ContainerOperator<>((Container) resultComp); 347 } 348 result.copyEnvironment(this); 349 return result; 350 } 351 352 @Override 353 public Hashtable<String, Object> getDump() { 354 Hashtable<String, Object> result = super.getDump(); 355 if (getToolTipText() != null) { 356 result.put(TOOLTIP_TEXT_DPROP, getToolTipText()); 357 } 358 //System.out.println("Dump a11y = " + System.getProperty("jemmy.dump.a11y")); 359 if (System.getProperty("jemmy.dump.a11y") != null 360 && System.getProperty("jemmy.dump.a11y").equals("on")) { 361 AccessibleContext a11y = getSource().getAccessibleContext(); 362 if (a11y != null) { 363 result.put(A11Y_DATA, "yes"); 364 String accName = (a11y.getAccessibleName() == null) ? "null" : a11y.getAccessibleName(); 365 String accDesc = (a11y.getAccessibleDescription() == null) ? "null" : a11y.getAccessibleDescription(); 366 result.put(A11Y_NAME_DPROP, accName); 367 result.put(A11Y_DESCRIPTION_DPROP, accDesc); 368 } else { 369 result.put(A11Y_DATA, "no"); 370 } 371 } 372 return result; 373 } 374 375 //////////////////////////////////////////////////////// 376 //Mapping // 377 /** 378 * Maps {@code JComponent.addAncestorListener(AncestorListener)} 379 * through queue 380 */ 381 public void addAncestorListener(final AncestorListener ancestorListener) { 382 runMapping(new MapVoidAction("addAncestorListener") { 383 @Override 384 public void map() { 385 ((JComponent) getSource()).addAncestorListener(ancestorListener); 386 } 387 }); 388 } 389 390 /** 391 * Maps 392 * {@code JComponent.addVetoableChangeListener(VetoableChangeListener)} 393 * through queue 394 */ 395 public void addVetoableChangeListener(final VetoableChangeListener vetoableChangeListener) { 396 runMapping(new MapVoidAction("addVetoableChangeListener") { 397 @Override 398 public void map() { 399 ((JComponent) getSource()).addVetoableChangeListener(vetoableChangeListener); 400 } 401 }); 402 } 403 404 /** 405 * Maps {@code JComponent.computeVisibleRect(Rectangle)} through queue 406 */ 407 public void computeVisibleRect(final Rectangle rectangle) { 408 runMapping(new MapVoidAction("computeVisibleRect") { 409 @Override 410 public void map() { 411 ((JComponent) getSource()).computeVisibleRect(rectangle); 412 } 413 }); 414 } 415 416 /** 417 * Maps {@code JComponent.createToolTip()} through queue 418 */ 419 public JToolTip createToolTip() { 420 return (runMapping(new MapAction<JToolTip>("createToolTip") { 421 @Override 422 public JToolTip map() { 423 return ((JComponent) getSource()).createToolTip(); 424 } 425 })); 426 } 427 428 /** 429 * Maps {@code JComponent.firePropertyChange(String, byte, byte)} 430 * through queue 431 */ 432 public void firePropertyChange(final String string, final byte b, final byte b1) { 433 runMapping(new MapVoidAction("firePropertyChange") { 434 @Override 435 public void map() { 436 getSource().firePropertyChange(string, b, b1); 437 } 438 }); 439 } 440 441 /** 442 * Maps {@code JComponent.firePropertyChange(String, char, char)} 443 * through queue 444 */ 445 public void firePropertyChange(final String string, final char c, final char c1) { 446 runMapping(new MapVoidAction("firePropertyChange") { 447 @Override 448 public void map() { 449 getSource().firePropertyChange(string, c, c1); 450 } 451 }); 452 } 453 454 /** 455 * Maps {@code JComponent.firePropertyChange(String, double, double)} 456 * through queue 457 */ 458 public void firePropertyChange(final String string, final double d, final double d1) { 459 runMapping(new MapVoidAction("firePropertyChange") { 460 @Override 461 public void map() { 462 getSource().firePropertyChange(string, d, d1); 463 } 464 }); 465 } 466 467 /** 468 * Maps {@code JComponent.firePropertyChange(String, float, float)} 469 * through queue 470 */ 471 public void firePropertyChange(final String string, final float f, final float f1) { 472 runMapping(new MapVoidAction("firePropertyChange") { 473 @Override 474 public void map() { 475 getSource().firePropertyChange(string, f, f1); 476 } 477 }); 478 } 479 480 /** 481 * Maps {@code JComponent.firePropertyChange(String, int, int)} through queue 482 */ 483 public void firePropertyChange(final String string, final int i, final int i1) { 484 runMapping(new MapVoidAction("firePropertyChange") { 485 @Override 486 public void map() { 487 ((JComponent) getSource()).firePropertyChange(string, i, i1); 488 } 489 }); 490 } 491 492 /** 493 * Maps {@code JComponent.firePropertyChange(String, long, long)} 494 * through queue 495 */ 496 public void firePropertyChange(final String string, final long l, final long l1) { 497 runMapping(new MapVoidAction("firePropertyChange") { 498 @Override 499 public void map() { 500 getSource().firePropertyChange(string, l, l1); 501 } 502 }); 503 } 504 505 /** 506 * Maps {@code JComponent.firePropertyChange(String, short, short)} 507 * through queue 508 */ 509 public void firePropertyChange(final String string, final short s, final short s1) { 510 runMapping(new MapVoidAction("firePropertyChange") { 511 @Override 512 public void map() { 513 getSource().firePropertyChange(string, s, s1); 514 } 515 }); 516 } 517 518 /** 519 * Maps {@code JComponent.firePropertyChange(String, boolean, boolean)} 520 * through queue 521 */ 522 public void firePropertyChange(final String string, final boolean b, final boolean b1) { 523 runMapping(new MapVoidAction("firePropertyChange") { 524 @Override 525 public void map() { 526 ((JComponent) getSource()).firePropertyChange(string, b, b1); 527 } 528 }); 529 } 530 531 /** 532 * Maps {@code JComponent.getAccessibleContext()} through queue 533 */ 534 public AccessibleContext getAccessibleContext() { 535 return (runMapping(new MapAction<AccessibleContext>("getAccessibleContext") { 536 @Override 537 public AccessibleContext map() { 538 return getSource().getAccessibleContext(); 539 } 540 })); 541 } 542 543 /** 544 * Maps {@code JComponent.getActionForKeyStroke(KeyStroke)} through queue 545 */ 546 public ActionListener getActionForKeyStroke(final KeyStroke keyStroke) { 547 return (runMapping(new MapAction<ActionListener>("getActionForKeyStroke") { 548 @Override 549 public ActionListener map() { 550 return ((JComponent) getSource()).getActionForKeyStroke(keyStroke); 551 } 552 })); 553 } 554 555 /** 556 * Maps {@code JComponent.getAutoscrolls()} through queue 557 */ 558 public boolean getAutoscrolls() { 559 return (runMapping(new MapBooleanAction("getAutoscrolls") { 560 @Override 561 public boolean map() { 562 return ((JComponent) getSource()).getAutoscrolls(); 563 } 564 })); 565 } 566 567 /** 568 * Maps {@code JComponent.getBorder()} through queue 569 */ 570 public Border getBorder() { 571 return (runMapping(new MapAction<Border>("getBorder") { 572 @Override 573 public Border map() { 574 return ((JComponent) getSource()).getBorder(); 575 } 576 })); 577 } 578 579 /** 580 * Maps {@code JComponent.getClientProperty(Object)} through queue 581 */ 582 public Object getClientProperty(final Object object) { 583 return (runMapping(new MapAction<Object>("getClientProperty") { 584 @Override 585 public Object map() { 586 return ((JComponent) getSource()).getClientProperty(object); 587 } 588 })); 589 } 590 591 /** 592 * Maps {@code JComponent.getConditionForKeyStroke(KeyStroke)} through queue 593 */ 594 public int getConditionForKeyStroke(final KeyStroke keyStroke) { 595 return (runMapping(new MapIntegerAction("getConditionForKeyStroke") { 596 @Override 597 public int map() { 598 return ((JComponent) getSource()).getConditionForKeyStroke(keyStroke); 599 } 600 })); 601 } 602 603 /** 604 * Maps {@code JComponent.getDebugGraphicsOptions()} through queue 605 */ 606 public int getDebugGraphicsOptions() { 607 return (runMapping(new MapIntegerAction("getDebugGraphicsOptions") { 608 @Override 609 public int map() { 610 return ((JComponent) getSource()).getDebugGraphicsOptions(); 611 } 612 })); 613 } 614 615 /** 616 * Maps {@code JComponent.getInsets(Insets)} through queue 617 */ 618 public Insets getInsets(final Insets insets) { 619 return (runMapping(new MapAction<Insets>("getInsets") { 620 @Override 621 public Insets map() { 622 return ((JComponent) getSource()).getInsets(insets); 623 } 624 })); 625 } 626 627 /** 628 * Maps {@code JComponent.getNextFocusableComponent()} through queue 629 */ 630 @Deprecated 631 public Component getNextFocusableComponent() { 632 return (runMapping(new MapAction<Component>("getNextFocusableComponent") { 633 @Override 634 public Component map() { 635 return ((JComponent) getSource()).getNextFocusableComponent(); 636 } 637 })); 638 } 639 640 /** 641 * Maps {@code JComponent.getRegisteredKeyStrokes()} through queue 642 */ 643 public KeyStroke[] getRegisteredKeyStrokes() { 644 return ((KeyStroke[]) runMapping(new MapAction<Object>("getRegisteredKeyStrokes") { 645 @Override 646 public Object map() { 647 return ((JComponent) getSource()).getRegisteredKeyStrokes(); 648 } 649 })); 650 } 651 652 /** 653 * Maps {@code JComponent.getRootPane()} through queue 654 */ 655 public JRootPane getRootPane() { 656 return (runMapping(new MapAction<JRootPane>("getRootPane") { 657 @Override 658 public JRootPane map() { 659 return ((JComponent) getSource()).getRootPane(); 660 } 661 })); 662 } 663 664 /** 665 * Maps {@code JComponent.getToolTipLocation(MouseEvent)} through queue 666 */ 667 public Point getToolTipLocation(final MouseEvent mouseEvent) { 668 return (runMapping(new MapAction<Point>("getToolTipLocation") { 669 @Override 670 public Point map() { 671 return ((JComponent) getSource()).getToolTipLocation(mouseEvent); 672 } 673 })); 674 } 675 676 /** 677 * Maps {@code JComponent.getToolTipText()} through queue 678 */ 679 public String getToolTipText() { 680 return (runMapping(new MapAction<String>("getToolTipText") { 681 @Override 682 public String map() { 683 return ((JComponent) getSource()).getToolTipText(); 684 } 685 })); 686 } 687 688 /** 689 * Maps {@code JComponent.getToolTipText(MouseEvent)} through queue 690 */ 691 public String getToolTipText(final MouseEvent mouseEvent) { 692 return (runMapping(new MapAction<String>("getToolTipText") { 693 @Override 694 public String map() { 695 return ((JComponent) getSource()).getToolTipText(mouseEvent); 696 } 697 })); 698 } 699 700 /** 701 * Maps {@code JComponent.getTopLevelAncestor()} through queue 702 */ 703 public Container getTopLevelAncestor() { 704 return (runMapping(new MapAction<Container>("getTopLevelAncestor") { 705 @Override 706 public Container map() { 707 return ((JComponent) getSource()).getTopLevelAncestor(); 708 } 709 })); 710 } 711 712 /** 713 * Maps {@code JComponent.getUIClassID()} through queue 714 */ 715 public String getUIClassID() { 716 return (runMapping(new MapAction<String>("getUIClassID") { 717 @Override 718 public String map() { 719 return ((JComponent) getSource()).getUIClassID(); 720 } 721 })); 722 } 723 724 /** 725 * Maps {@code JComponent.getVisibleRect()} through queue 726 */ 727 public Rectangle getVisibleRect() { 728 return (runMapping(new MapAction<Rectangle>("getVisibleRect") { 729 @Override 730 public Rectangle map() { 731 return ((JComponent) getSource()).getVisibleRect(); 732 } 733 })); 734 } 735 736 /** 737 * Maps {@code JComponent.grabFocus()} through queue 738 */ 739 public void grabFocus() { 740 runMapping(new MapVoidAction("grabFocus") { 741 @Override 742 public void map() { 743 ((JComponent) getSource()).grabFocus(); 744 } 745 }); 746 } 747 748 /** 749 * Maps {@code JComponent.isFocusCycleRoot()} through queue 750 */ 751 public boolean isFocusCycleRoot() { 752 return (runMapping(new MapBooleanAction("isFocusCycleRoot") { 753 @Override 754 public boolean map() { 755 return ((JComponent) getSource()).isFocusCycleRoot(); 756 } 757 })); 758 } 759 760 /** 761 * Maps {@code JComponent.isManagingFocus()} through queue 762 */ 763 @Deprecated 764 public boolean isManagingFocus() { 765 return (runMapping(new MapBooleanAction("isManagingFocus") { 766 @Override 767 public boolean map() { 768 return ((JComponent) getSource()).isManagingFocus(); 769 } 770 })); 771 } 772 773 /** 774 * Maps {@code JComponent.isOptimizedDrawingEnabled()} through queue 775 */ 776 public boolean isOptimizedDrawingEnabled() { 777 return (runMapping(new MapBooleanAction("isOptimizedDrawingEnabled") { 778 @Override 779 public boolean map() { 780 return ((JComponent) getSource()).isOptimizedDrawingEnabled(); 781 } 782 })); 783 } 784 785 /** 786 * Maps {@code JComponent.isPaintingTile()} through queue 787 */ 788 public boolean isPaintingTile() { 789 return (runMapping(new MapBooleanAction("isPaintingTile") { 790 @Override 791 public boolean map() { 792 return ((JComponent) getSource()).isPaintingTile(); 793 } 794 })); 795 } 796 797 /** 798 * Maps {@code JComponent.isRequestFocusEnabled()} through queue 799 */ 800 public boolean isRequestFocusEnabled() { 801 return (runMapping(new MapBooleanAction("isRequestFocusEnabled") { 802 @Override 803 public boolean map() { 804 return ((JComponent) getSource()).isRequestFocusEnabled(); 805 } 806 })); 807 } 808 809 /** 810 * Maps {@code JComponent.isValidateRoot()} through queue 811 */ 812 public boolean isValidateRoot() { 813 return (runMapping(new MapBooleanAction("isValidateRoot") { 814 @Override 815 public boolean map() { 816 return ((JComponent) getSource()).isValidateRoot(); 817 } 818 })); 819 } 820 821 /** 822 * Maps {@code JComponent.paintImmediately(int, int, int, int)} through queue 823 */ 824 public void paintImmediately(final int i, final int i1, final int i2, final int i3) { 825 runMapping(new MapVoidAction("paintImmediately") { 826 @Override 827 public void map() { 828 ((JComponent) getSource()).paintImmediately(i, i1, i2, i3); 829 } 830 }); 831 } 832 833 /** 834 * Maps {@code JComponent.paintImmediately(Rectangle)} through queue 835 */ 836 public void paintImmediately(final Rectangle rectangle) { 837 runMapping(new MapVoidAction("paintImmediately") { 838 @Override 839 public void map() { 840 ((JComponent) getSource()).paintImmediately(rectangle); 841 } 842 }); 843 } 844 845 /** 846 * Maps {@code JComponent.putClientProperty(Object, Object)} through queue 847 */ 848 public void putClientProperty(final Object object, final Object object1) { 849 runMapping(new MapVoidAction("putClientProperty") { 850 @Override 851 public void map() { 852 ((JComponent) getSource()).putClientProperty(object, object1); 853 } 854 }); 855 } 856 857 /** 858 * Maps 859 * {@code JComponent.registerKeyboardAction(ActionListener, String, KeyStroke, int)} 860 * through queue 861 */ 862 public void registerKeyboardAction(final ActionListener actionListener, final String string, final KeyStroke keyStroke, final int i) { 863 runMapping(new MapVoidAction("registerKeyboardAction") { 864 @Override 865 public void map() { 866 ((JComponent) getSource()).registerKeyboardAction(actionListener, string, keyStroke, i); 867 } 868 }); 869 } 870 871 /** 872 * Maps 873 * {@code JComponent.registerKeyboardAction(ActionListener, KeyStroke, int)} 874 * through queue 875 */ 876 public void registerKeyboardAction(final ActionListener actionListener, final KeyStroke keyStroke, final int i) { 877 runMapping(new MapVoidAction("registerKeyboardAction") { 878 @Override 879 public void map() { 880 ((JComponent) getSource()).registerKeyboardAction(actionListener, keyStroke, i); 881 } 882 }); 883 } 884 885 /** 886 * Maps {@code JComponent.removeAncestorListener(AncestorListener)} 887 * through queue 888 */ 889 public void removeAncestorListener(final AncestorListener ancestorListener) { 890 runMapping(new MapVoidAction("removeAncestorListener") { 891 @Override 892 public void map() { 893 ((JComponent) getSource()).removeAncestorListener(ancestorListener); 894 } 895 }); 896 } 897 898 /** 899 * Maps 900 * {@code JComponent.removeVetoableChangeListener(VetoableChangeListener)} 901 * through queue 902 */ 903 public void removeVetoableChangeListener(final VetoableChangeListener vetoableChangeListener) { 904 runMapping(new MapVoidAction("removeVetoableChangeListener") { 905 @Override 906 public void map() { 907 ((JComponent) getSource()).removeVetoableChangeListener(vetoableChangeListener); 908 } 909 }); 910 } 911 912 /** 913 * Maps {@code JComponent.repaint(Rectangle)} through queue 914 */ 915 public void repaint(final Rectangle rectangle) { 916 runMapping(new MapVoidAction("repaint") { 917 @Override 918 public void map() { 919 ((JComponent) getSource()).repaint(rectangle); 920 } 921 }); 922 } 923 924 /** 925 * Maps {@code JComponent.requestDefaultFocus()} through queue 926 */ 927 @Deprecated 928 public boolean requestDefaultFocus() { 929 return (runMapping(new MapBooleanAction("requestDefaultFocus") { 930 @Override 931 public boolean map() { 932 return ((JComponent) getSource()).requestDefaultFocus(); 933 } 934 })); 935 } 936 937 /** 938 * Maps {@code JComponent.resetKeyboardActions()} through queue 939 */ 940 public void resetKeyboardActions() { 941 runMapping(new MapVoidAction("resetKeyboardActions") { 942 @Override 943 public void map() { 944 ((JComponent) getSource()).resetKeyboardActions(); 945 } 946 }); 947 } 948 949 /** 950 * Maps {@code JComponent.revalidate()} through queue 951 */ 952 public void revalidate() { 953 runMapping(new MapVoidAction("revalidate") { 954 @Override 955 public void map() { 956 getSource().revalidate(); 957 } 958 }); 959 } 960 961 /** 962 * Maps {@code JComponent.scrollRectToVisible(Rectangle)} through queue 963 */ 964 public void scrollRectToVisible(final Rectangle rectangle) { 965 runMapping(new MapVoidAction("scrollRectToVisible") { 966 @Override 967 public void map() { 968 ((JComponent) getSource()).scrollRectToVisible(rectangle); 969 } 970 }); 971 } 972 973 /** 974 * Maps {@code JComponent.setAlignmentX(float)} through queue 975 */ 976 public void setAlignmentX(final float f) { 977 runMapping(new MapVoidAction("setAlignmentX") { 978 @Override 979 public void map() { 980 ((JComponent) getSource()).setAlignmentX(f); 981 } 982 }); 983 } 984 985 /** 986 * Maps {@code JComponent.setAlignmentY(float)} through queue 987 */ 988 public void setAlignmentY(final float f) { 989 runMapping(new MapVoidAction("setAlignmentY") { 990 @Override 991 public void map() { 992 ((JComponent) getSource()).setAlignmentY(f); 993 } 994 }); 995 } 996 997 /** 998 * Maps {@code JComponent.setAutoscrolls(boolean)} through queue 999 */ 1000 public void setAutoscrolls(final boolean b) { 1001 runMapping(new MapVoidAction("setAutoscrolls") { 1002 @Override 1003 public void map() { 1004 ((JComponent) getSource()).setAutoscrolls(b); 1005 } 1006 }); 1007 } 1008 1009 /** 1010 * Maps {@code JComponent.setBorder(Border)} through queue 1011 */ 1012 public void setBorder(final Border border) { 1013 runMapping(new MapVoidAction("setBorder") { 1014 @Override 1015 public void map() { 1016 ((JComponent) getSource()).setBorder(border); 1017 } 1018 }); 1019 } 1020 1021 /** 1022 * Maps {@code JComponent.setDebugGraphicsOptions(int)} through queue 1023 */ 1024 public void setDebugGraphicsOptions(final int i) { 1025 runMapping(new MapVoidAction("setDebugGraphicsOptions") { 1026 @Override 1027 public void map() { 1028 ((JComponent) getSource()).setDebugGraphicsOptions(i); 1029 } 1030 }); 1031 } 1032 1033 /** 1034 * Maps {@code JComponent.setDoubleBuffered(boolean)} through queue 1035 */ 1036 public void setDoubleBuffered(final boolean b) { 1037 runMapping(new MapVoidAction("setDoubleBuffered") { 1038 @Override 1039 public void map() { 1040 ((JComponent) getSource()).setDoubleBuffered(b); 1041 } 1042 }); 1043 } 1044 1045 /** 1046 * Maps {@code JComponent.setMaximumSize(Dimension)} through queue 1047 */ 1048 public void setMaximumSize(final Dimension dimension) { 1049 runMapping(new MapVoidAction("setMaximumSize") { 1050 @Override 1051 public void map() { 1052 getSource().setMaximumSize(dimension); 1053 } 1054 }); 1055 } 1056 1057 /** 1058 * Maps {@code JComponent.setMinimumSize(Dimension)} through queue 1059 */ 1060 public void setMinimumSize(final Dimension dimension) { 1061 runMapping(new MapVoidAction("setMinimumSize") { 1062 @Override 1063 public void map() { 1064 getSource().setMinimumSize(dimension); 1065 } 1066 }); 1067 } 1068 1069 /** 1070 * Maps {@code JComponent.setNextFocusableComponent(Component)} through queue 1071 */ 1072 @Deprecated 1073 public void setNextFocusableComponent(final Component component) { 1074 runMapping(new MapVoidAction("setNextFocusableComponent") { 1075 @Override 1076 public void map() { 1077 ((JComponent) getSource()).setNextFocusableComponent(component); 1078 } 1079 }); 1080 } 1081 1082 /** 1083 * Maps {@code JComponent.setOpaque(boolean)} through queue 1084 */ 1085 public void setOpaque(final boolean b) { 1086 runMapping(new MapVoidAction("setOpaque") { 1087 @Override 1088 public void map() { 1089 ((JComponent) getSource()).setOpaque(b); 1090 } 1091 }); 1092 } 1093 1094 /** 1095 * Maps {@code JComponent.setPreferredSize(Dimension)} through queue 1096 */ 1097 public void setPreferredSize(final Dimension dimension) { 1098 runMapping(new MapVoidAction("setPreferredSize") { 1099 @Override 1100 public void map() { 1101 getSource().setPreferredSize(dimension); 1102 } 1103 }); 1104 } 1105 1106 /** 1107 * Maps {@code JComponent.setRequestFocusEnabled(boolean)} through queue 1108 */ 1109 public void setRequestFocusEnabled(final boolean b) { 1110 runMapping(new MapVoidAction("setRequestFocusEnabled") { 1111 @Override 1112 public void map() { 1113 ((JComponent) getSource()).setRequestFocusEnabled(b); 1114 } 1115 }); 1116 } 1117 1118 /** 1119 * Maps {@code JComponent.setToolTipText(String)} through queue 1120 */ 1121 public void setToolTipText(final String string) { 1122 runMapping(new MapVoidAction("setToolTipText") { 1123 @Override 1124 public void map() { 1125 ((JComponent) getSource()).setToolTipText(string); 1126 } 1127 }); 1128 } 1129 1130 /** 1131 * Maps {@code JComponent.unregisterKeyboardAction(KeyStroke)} through queue 1132 */ 1133 public void unregisterKeyboardAction(final KeyStroke keyStroke) { 1134 runMapping(new MapVoidAction("unregisterKeyboardAction") { 1135 @Override 1136 public void map() { 1137 ((JComponent) getSource()).unregisterKeyboardAction(keyStroke); 1138 } 1139 }); 1140 } 1141 1142 /** 1143 * Maps {@code JComponent.updateUI()} through queue 1144 */ 1145 public void updateUI() { 1146 runMapping(new MapVoidAction("updateUI") { 1147 @Override 1148 public void map() { 1149 ((JComponent) getSource()).updateUI(); 1150 } 1151 }); 1152 } 1153 1154 //End of mapping // 1155 //////////////////////////////////////////////////////// 1156 /** 1157 * Allows to find component by tooltip. 1158 */ 1159 public static class JComponentByTipFinder implements ComponentChooser { 1160 1161 String label; 1162 1163 StringComparator comparator; 1164 1165 /** 1166 * Constructs JComponentByTipFinder. 1167 * 1168 * @param lb a text pattern 1169 * @param comparator specifies string comparision algorithm. 1170 */ 1171 public JComponentByTipFinder(String lb, StringComparator comparator) { 1172 label = lb; 1173 this.comparator = comparator; 1174 } 1175 1176 /** 1177 * Constructs JComponentByTipFinder. 1178 * 1179 * @param lb a text pattern 1180 */ 1181 public JComponentByTipFinder(String lb) { 1182 this(lb, Operator.getDefaultStringComparator()); 1183 } 1184 1185 @Override 1186 public boolean checkComponent(Component comp) { 1187 if (comp instanceof JComponent) { 1188 if (((JComponent) comp).getToolTipText() != null) { 1189 return (comparator.equals(((JComponent) comp).getToolTipText(), 1190 label)); 1191 } 1192 } 1193 return false; 1194 } 1195 1196 @Override 1197 public String getDescription() { 1198 return "JComponent with tool tip \"" + label + "\""; 1199 } 1200 1201 @Override 1202 public String toString() { 1203 return "JComponentByTipFinder{" + "label=" + label + ", comparator=" + comparator + '}'; 1204 } 1205 } 1206 1207 /** 1208 * Checks component type. 1209 */ 1210 public static class JComponentFinder extends Finder { 1211 1212 /** 1213 * Constructs JComponentFinder. 1214 * 1215 * @param sf other searching criteria. 1216 */ 1217 public JComponentFinder(ComponentChooser sf) { 1218 super(JComponent.class, sf); 1219 } 1220 1221 /** 1222 * Constructs JComponentFinder. 1223 */ 1224 public JComponentFinder() { 1225 super(JComponent.class); 1226 } 1227 } 1228 1229 static class JToolTipWindowFinder implements ComponentChooser { 1230 1231 ComponentChooser ppFinder; 1232 1233 public JToolTipWindowFinder() { 1234 ppFinder = new ComponentChooser() { 1235 @Override 1236 public boolean checkComponent(Component comp) { 1237 return (comp.isShowing() 1238 && comp.isVisible() 1239 && comp instanceof JToolTip); 1240 } 1241 1242 @Override 1243 public String getDescription() { 1244 return "A tool tip"; 1245 } 1246 1247 @Override 1248 public String toString() { 1249 return "JComponentOperator.JToolTipWindowFinder.ComponentChooser{description = " + getDescription() + '}'; 1250 } 1251 }; 1252 } 1253 1254 @Override 1255 public boolean checkComponent(Component comp) { 1256 if (comp.isShowing() && comp instanceof Window) { 1257 ComponentSearcher cs = new ComponentSearcher((Container) comp); 1258 cs.setOutput(JemmyProperties.getCurrentOutput().createErrorOutput()); 1259 return (cs.findComponent(ppFinder) 1260 != null); 1261 } 1262 return false; 1263 } 1264 1265 @Override 1266 public String getDescription() { 1267 return "A tool tip window"; 1268 } 1269 1270 @Override 1271 public String toString() { 1272 return "JToolTipWindowFinder{" + "ppFinder=" + ppFinder + '}'; 1273 } 1274 } 1275 1276 class JToolTipFinder extends Finder { 1277 1278 public JToolTipFinder(ComponentChooser sf) { 1279 super(JToolTip.class, sf); 1280 } 1281 1282 public JToolTipFinder() { 1283 super(JToolTip.class); 1284 } 1285 } 1286} 1287