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.Color; 26import java.awt.Component; 27import java.awt.Container; 28import java.awt.Rectangle; 29import java.util.Hashtable; 30 31import javax.swing.Icon; 32import javax.swing.JTabbedPane; 33import javax.swing.SingleSelectionModel; 34import javax.swing.event.ChangeListener; 35import javax.swing.plaf.TabbedPaneUI; 36 37import org.netbeans.jemmy.ComponentChooser; 38import org.netbeans.jemmy.JemmyInputException; 39import org.netbeans.jemmy.Outputable; 40import org.netbeans.jemmy.TestOut; 41import org.netbeans.jemmy.TimeoutExpiredException; 42import org.netbeans.jemmy.drivers.DriverManager; 43import org.netbeans.jemmy.drivers.ListDriver; 44 45/** 46 * <BR><BR>Timeouts used: <BR> 47 * ComponentOperator.WaitComponentTimeout - time to wait component displayed 48 * <BR>. 49 * 50 * @see org.netbeans.jemmy.Timeouts 51 * 52 * @author Alexandre Iline (alexandre.iline@oracle.com) 53 * 54 */ 55public class JTabbedPaneOperator extends JComponentOperator 56 implements Outputable { 57 58 /** 59 * Identifier for a "selected page" property. 60 * 61 * @see #getDump 62 */ 63 public static final String SELECTED_PAGE_DPROP = "Selected"; 64 65 /** 66 * Identifier for a "page" properties. 67 * 68 * @see #getDump 69 */ 70 public static final String PAGE_PREFIX_DPROP = "Page"; 71 72 private TestOut output; 73 private ListDriver driver; 74 75 /** 76 * Constructor. 77 * 78 * @param b a component 79 */ 80 public JTabbedPaneOperator(JTabbedPane b) { 81 super(b); 82 driver = DriverManager.getListDriver(getClass()); 83 } 84 85 /** 86 * Constructs a JTabbedPaneOperator object. 87 * 88 * @param cont a container 89 * @param chooser a component chooser specifying searching criteria. 90 * @param index an index between appropriate ones. 91 */ 92 public JTabbedPaneOperator(ContainerOperator<?> cont, ComponentChooser chooser, int index) { 93 this((JTabbedPane) cont. 94 waitSubComponent(new JTabbedPaneFinder(chooser), 95 index)); 96 copyEnvironment(cont); 97 } 98 99 /** 100 * Constructs a JTabbedPaneOperator object. 101 * 102 * @param cont a container 103 * @param chooser a component chooser specifying searching criteria. 104 */ 105 public JTabbedPaneOperator(ContainerOperator<?> cont, ComponentChooser chooser) { 106 this(cont, chooser, 0); 107 } 108 109 /** 110 * Constructor. Waits component by tab title first. Uses cont's timeout and 111 * output for waiting and to init operator. 112 * 113 * @param cont a container 114 * @param text Tab title. 115 * @param tabIndex a page index to check. if equal to -1, selected page is 116 * checked. 117 * @param index Ordinal component index. 118 * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean) 119 * @throws TimeoutExpiredException 120 */ 121 public JTabbedPaneOperator(ContainerOperator<?> cont, String text, int tabIndex, int index) { 122 this((JTabbedPane) waitComponent(cont, 123 new JTabbedPaneByItemFinder(text, tabIndex, 124 cont.getComparator()), 125 index)); 126 copyEnvironment(cont); 127 } 128 129 /** 130 * Constructor. Waits component by activetab title first. Uses cont's 131 * timeout and output for waiting and to init operator. 132 * 133 * @param cont a container 134 * @param text Title of tab which is currently selected. 135 * @param index Ordinal component index. 136 * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean) 137 * @throws TimeoutExpiredException 138 */ 139 public JTabbedPaneOperator(ContainerOperator<?> cont, String text, int index) { 140 this(cont, text, -1, index); 141 } 142 143 /** 144 * Constructor. Waits component in container first. Uses cont's timeout and 145 * output for waiting and to init operator. 146 * 147 * @param cont a container 148 * @param text Title of tab which is currently selected. 149 * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean) 150 * @throws TimeoutExpiredException 151 */ 152 public JTabbedPaneOperator(ContainerOperator<?> cont, String text) { 153 this(cont, text, 0); 154 } 155 156 /** 157 * Constructor. Waits component in container first. Uses cont's timeout and 158 * output for waiting and to init operator. 159 * 160 * @param cont a container 161 * @param index Ordinal component index. 162 * @throws TimeoutExpiredException 163 */ 164 public JTabbedPaneOperator(ContainerOperator<?> cont, int index) { 165 this((JTabbedPane) waitComponent(cont, 166 new JTabbedPaneFinder(), 167 index)); 168 copyEnvironment(cont); 169 } 170 171 /** 172 * Constructor. Waits component in container first. Uses cont's timeout and 173 * output for waiting and to init operator. 174 * 175 * @param cont a container 176 * @throws TimeoutExpiredException 177 */ 178 public JTabbedPaneOperator(ContainerOperator<?> cont) { 179 this(cont, 0); 180 } 181 182 /** 183 * Searches JTabbedPane in container. 184 * 185 * @param cont Container to search component in. 186 * @param chooser org.netbeans.jemmy.ComponentChooser implementation. 187 * @param index Ordinal component index. 188 * @return JTabbedPane instance or null if component was not found. 189 */ 190 public static JTabbedPane findJTabbedPane(Container cont, ComponentChooser chooser, int index) { 191 return (JTabbedPane) findComponent(cont, new JTabbedPaneFinder(chooser), index); 192 } 193 194 /** 195 * Searches 0'th JTabbedPane in container. 196 * 197 * @param cont Container to search component in. 198 * @param chooser org.netbeans.jemmy.ComponentChooser implementation. 199 * @return JTabbedPane instance or null if component was not found. 200 */ 201 public static JTabbedPane findJTabbedPane(Container cont, ComponentChooser chooser) { 202 return findJTabbedPane(cont, chooser, 0); 203 } 204 205 /** 206 * Searches JTabbedPane by tab title. 207 * 208 * @param cont Container to search component in. 209 * @param text Tooltip text. If null, contents is not checked. 210 * @param ce Compare text exactly. 211 * @param ccs Compare text case sensitively. 212 * @param itemIndex Tab index. if -1 selected one is checked. 213 * @param index Ordinal component index. 214 * @return JTabbedPane instance or null if component was not found. 215 * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean) 216 */ 217 public static JTabbedPane findJTabbedPane(Container cont, String text, boolean ce, boolean ccs, int itemIndex, int index) { 218 return findJTabbedPane(cont, new JTabbedPaneByItemFinder(text, itemIndex, new DefaultStringComparator(ce, ccs)), index); 219 } 220 221 /** 222 * Searches JTabbedPane by tab title. 223 * 224 * @param cont Container to search component in. 225 * @param text Tooltip text. If null, contents is not checked. 226 * @param ce Compare text exactly. 227 * @param ccs Compare text case sensitively. 228 * @param itemIndex Tab index. if -1 selected one is checked. 229 * @return JTabbedPane instance or null if component was not found. 230 * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean) 231 */ 232 public static JTabbedPane findJTabbedPane(Container cont, String text, boolean ce, boolean ccs, int itemIndex) { 233 return findJTabbedPane(cont, text, ce, ccs, itemIndex, 0); 234 } 235 236 /** 237 * Searches JTabbedPane object which component lies on. 238 * 239 * @param comp Component to find JTabbedPane under. 240 * @param chooser org.netbeans.jemmy.ComponentChooser implementation. 241 * @return JTabbedPane instance or null if component was not found. 242 */ 243 public static JTabbedPane findJTabbedPaneUnder(Component comp, ComponentChooser chooser) { 244 return (JTabbedPane) findContainerUnder(comp, new JTabbedPaneFinder(chooser)); 245 } 246 247 /** 248 * Searches JTabbedPane object which component lies on. 249 * 250 * @param comp Component to find JTabbedPane under. 251 * @return JTabbedPane instance or null if component was not found. 252 */ 253 public static JTabbedPane findJTabbedPaneUnder(Component comp) { 254 return findJTabbedPaneUnder(comp, new JTabbedPaneFinder()); 255 } 256 257 /** 258 * Waits JTabbedPane in container. 259 * 260 * @param cont Container to search component in. 261 * @param chooser org.netbeans.jemmy.ComponentChooser implementation. 262 * @param index Ordinal component index. 263 * @return JTabbedPane instance. 264 * @throws TimeoutExpiredException 265 */ 266 public static JTabbedPane waitJTabbedPane(Container cont, ComponentChooser chooser, int index) { 267 return (JTabbedPane) waitComponent(cont, new JTabbedPaneFinder(chooser), index); 268 } 269 270 /** 271 * Waits 0'th JTabbedPane in container. 272 * 273 * @param cont Container to search component in. 274 * @param chooser org.netbeans.jemmy.ComponentChooser implementation. 275 * @return JTabbedPane instance. 276 * @throws TimeoutExpiredException 277 */ 278 public static JTabbedPane waitJTabbedPane(Container cont, ComponentChooser chooser) { 279 return waitJTabbedPane(cont, chooser, 0); 280 } 281 282 /** 283 * Waits JTabbedPane by tab title. 284 * 285 * @param cont Container to search component in. 286 * @param text Tooltip text. If null, contents is not checked. 287 * @param ce Compare text exactly. 288 * @param ccs Compare text case sensitively. 289 * @param itemIndex Tab index. if -1 selected one is checked. 290 * @param index Ordinal component index. 291 * @return JTabbedPane instance. 292 * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean) 293 * @throws TimeoutExpiredException 294 */ 295 public static JTabbedPane waitJTabbedPane(Container cont, String text, boolean ce, boolean ccs, int itemIndex, int index) { 296 return waitJTabbedPane(cont, new JTabbedPaneByItemFinder(text, itemIndex, new DefaultStringComparator(ce, ccs)), index); 297 } 298 299 /** 300 * Waits JTabbedPane by tab title. 301 * 302 * @param cont Container to search component in. 303 * @param text Tooltip text. If null, contents is not checked. 304 * @param ce Compare text exactly. 305 * @param ccs Compare text case sensitively. 306 * @param itemIndex Tab index. if -1 selected one is checked. 307 * @return JTabbedPane instance. 308 * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean) 309 * @throws TimeoutExpiredException 310 */ 311 public static JTabbedPane waitJTabbedPane(Container cont, String text, boolean ce, boolean ccs, int itemIndex) { 312 return waitJTabbedPane(cont, text, ce, ccs, itemIndex, 0); 313 } 314 315 @Override 316 public void setOutput(TestOut output) { 317 super.setOutput(output.createErrorOutput()); 318 this.output = output; 319 } 320 321 @Override 322 public TestOut getOutput() { 323 return output; 324 } 325 326 @Override 327 public void copyEnvironment(Operator anotherOperator) { 328 super.copyEnvironment(anotherOperator); 329 driver 330 = (ListDriver) DriverManager. 331 getDriver(DriverManager.LIST_DRIVER_ID, 332 getClass(), 333 anotherOperator.getProperties()); 334 } 335 336 /** 337 * Searches tab index by tab title. 338 * 339 * @param chooser page searching criteria 340 * @return a page index. 341 * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean) 342 * @deprecated Use findPage(String) or findPage(String, StringComparator) 343 */ 344 @Deprecated 345 public int findPage(TabPageChooser chooser) { 346 for (int i = 0; i < getTabCount(); i++) { 347 if (chooser.checkPage(this, i)) { 348 return i; 349 } 350 } 351 return -1; 352 } 353 354 /** 355 * Searches tab index by tab title. 356 * 357 * @param title a page title. 358 * @param comparator a string comparision algorithm 359 * @return a page index. 360 * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean) 361 * @deprecated Use findPage(String) or findPage(String, StringComparator) 362 */ 363 @Deprecated 364 public int findPage(String title, StringComparator comparator) { 365 return findPage(new BySubStringTabPageChooser(title, comparator)); 366 } 367 368 /** 369 * Searches tab index by tab title. isCaptionEqual method is used to compare 370 * page title with match. 371 * 372 * @param title a page title. 373 * @param ce Compare text exactly. 374 * @param ccs Compare text case sensitively. 375 * @return a page index. 376 * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean) 377 * @deprecated Use findPage(String) or findPage(String, StringComparator) 378 */ 379 @Deprecated 380 public int findPage(String title, boolean ce, boolean ccs) { 381 return findPage(title, new DefaultStringComparator(ce, ccs)); 382 } 383 384 /** 385 * Searches tab index by tab title. isCaptionEqual method is used to compare 386 * page title with match. Uses StringComparator assigned to this object. 387 * 388 * @param title a page title. 389 * @return a page index. 390 */ 391 public int findPage(String title) { 392 return findPage(title, getComparator()); 393 } 394 395 /** 396 * Selects tab. 397 * 398 * @param index a page ordinal index. 399 * @return a root corresponding to the page. 400 */ 401 public Component selectPage(int index) { 402 output.printLine("Selecting " + index + "'th page in tabbed pane\n :" + toStringSource()); 403 makeComponentVisible(); 404 driver.selectItem(this, index); 405 if (getVerification()) { 406 waitSelected(index); 407 } 408 return getComponentAt(index); 409 } 410 411 /** 412 * Selects tab. 413 * 414 * @param chooser page searching criteria 415 * @return a root corresponding to the page. 416 */ 417 public Component selectPage(TabPageChooser chooser) { 418 output.printLine("Selecting \"" + chooser.getDescription() 419 + "\" page in tabbed pane\n :" + toStringSource()); 420 return selectPage(waitPage(chooser)); 421 } 422 423 /** 424 * Selects tab. 425 * 426 * @param title a page title. 427 * @param comparator a string comparision algorithm 428 * @return a root corresponding to the page. 429 */ 430 public Component selectPage(String title, StringComparator comparator) { 431 return selectPage(new BySubStringTabPageChooser(title, comparator)); 432 } 433 434 /** 435 * Selects tab by tab title. 436 * 437 * @param title a page title. 438 * @param ce Compare text exactly. 439 * @param ccs Compare text case sensitively. 440 * @see ComponentOperator#isCaptionEqual(String, String, boolean, boolean) 441 * @deprecated Use selectPage(String) or selectPage(String, 442 * StringComparator) 443 * @return a root corresponding to the page. 444 */ 445 @Deprecated 446 public Component selectPage(String title, boolean ce, boolean ccs) { 447 return selectPage(title, new DefaultStringComparator(ce, ccs)); 448 } 449 450 /** 451 * Selects tab by tab title. Uses StringComparator assigned to this object. 452 * 453 * @param title a page title. 454 * @return a root corresponding to the page. 455 */ 456 public Component selectPage(String title) { 457 return selectPage(title, getComparator()); 458 } 459 460 /** 461 * Wait for a page to exist. 462 * 463 * @param chooser page searching criteria 464 * @return a page index. 465 */ 466 public int waitPage(final TabPageChooser chooser) { 467 waitState(new ComponentChooser() { 468 @Override 469 public boolean checkComponent(Component comp) { 470 return findPage(chooser) > -1; 471 } 472 473 @Override 474 public String getDescription() { 475 return "Tabbed with " + chooser.getDescription() + " page."; 476 } 477 478 @Override 479 public String toString() { 480 return "JTabbedPaneOperator.waitPage.Action{description = " + getDescription() + '}'; 481 } 482 }); 483 return findPage(chooser); 484 } 485 486 /** 487 * Wait for a page to exist. 488 * 489 * @param title a page title. 490 * @param comparator a string comparision algorithm 491 * @return a page index. 492 */ 493 public int waitPage(String title, StringComparator comparator) { 494 return waitPage(new BySubStringTabPageChooser(title, comparator)); 495 } 496 497 /** 498 * Wait for a page to exist. 499 * 500 * @param title a page title. 501 * @return a page index. 502 */ 503 public int waitPage(String title) { 504 return waitPage(title, getComparator()); 505 } 506 507 /** 508 * Waits for a page to be selected. 509 * 510 * @param pageIndex an index of a page to be selected. 511 */ 512 public void waitSelected(final int pageIndex) { 513 getOutput().printLine("Wait " + Integer.toString(pageIndex) + "'th page to be " 514 + " selected in component \n : " 515 + toStringSource()); 516 getOutput().printGolden("Wait " + Integer.toString(pageIndex) + "'th page to be " 517 + " selected"); 518 waitState(new ComponentChooser() { 519 @Override 520 public boolean checkComponent(Component comp) { 521 return getSelectedIndex() == pageIndex; 522 } 523 524 @Override 525 public String getDescription() { 526 return Integer.toString(pageIndex) + "'th page has been selected"; 527 } 528 529 @Override 530 public String toString() { 531 return "JTabbedPaneOperator.waitSelected.ComponentChooser{description = " + getDescription() + '}'; 532 } 533 }); 534 } 535 536 /** 537 * Waits for a page to be selected. 538 * 539 * @param pageTitle a title of a page to be selected. 540 */ 541 public void waitSelected(final String pageTitle) { 542 waitSelected(findPage(pageTitle)); 543 } 544 545 @Override 546 public Hashtable<String, Object> getDump() { 547 Hashtable<String, Object> result = super.getDump(); 548 if (((JTabbedPane) getSource()).getSelectedIndex() != -1) { 549 result.put(SELECTED_PAGE_DPROP, ((JTabbedPane) getSource()). 550 getTitleAt(((JTabbedPane) getSource()).getSelectedIndex())); 551 } 552 String[] pages = new String[((JTabbedPane) getSource()).getTabCount()]; 553 for (int i = 0; i < ((JTabbedPane) getSource()).getTabCount(); i++) { 554 pages[i] = ((JTabbedPane) getSource()).getTitleAt(i); 555 } 556 addToDump(result, PAGE_PREFIX_DPROP, pages); 557 return result; 558 } 559 560 //////////////////////////////////////////////////////// 561 //Mapping // 562 /** 563 * Maps {@code JTabbedPane.addChangeListener(ChangeListener)} through queue 564 */ 565 public void addChangeListener(final ChangeListener changeListener) { 566 runMapping(new MapVoidAction("addChangeListener") { 567 @Override 568 public void map() { 569 ((JTabbedPane) getSource()).addChangeListener(changeListener); 570 } 571 }); 572 } 573 574 /** 575 * Maps {@code JTabbedPane.addTab(String, Component)} through queue 576 */ 577 public void addTab(final String string, final Component component) { 578 runMapping(new MapVoidAction("addTab") { 579 @Override 580 public void map() { 581 ((JTabbedPane) getSource()).addTab(string, component); 582 } 583 }); 584 } 585 586 /** 587 * Maps {@code JTabbedPane.addTab(String, Icon, Component)} through queue 588 */ 589 public void addTab(final String string, final Icon icon, final Component component) { 590 runMapping(new MapVoidAction("addTab") { 591 @Override 592 public void map() { 593 ((JTabbedPane) getSource()).addTab(string, icon, component); 594 } 595 }); 596 } 597 598 /** 599 * Maps {@code JTabbedPane.addTab(String, Icon, Component, String)} 600 * through queue 601 */ 602 public void addTab(final String string, final Icon icon, final Component component, final String string1) { 603 runMapping(new MapVoidAction("addTab") { 604 @Override 605 public void map() { 606 ((JTabbedPane) getSource()).addTab(string, icon, component, string1); 607 } 608 }); 609 } 610 611 /** 612 * Maps {@code JTabbedPane.getBackgroundAt(int)} through queue 613 */ 614 public Color getBackgroundAt(final int i) { 615 return (runMapping(new MapAction<Color>("getBackgroundAt") { 616 @Override 617 public Color map() { 618 return ((JTabbedPane) getSource()).getBackgroundAt(i); 619 } 620 })); 621 } 622 623 /** 624 * Maps {@code JTabbedPane.getBoundsAt(int)} through queue 625 */ 626 public Rectangle getBoundsAt(final int i) { 627 return (runMapping(new MapAction<Rectangle>("getBoundsAt") { 628 @Override 629 public Rectangle map() { 630 return ((JTabbedPane) getSource()).getBoundsAt(i); 631 } 632 })); 633 } 634 635 /** 636 * Maps {@code JTabbedPane.getComponentAt(int)} through queue 637 */ 638 public Component getComponentAt(final int i) { 639 return (runMapping(new MapAction<Component>("getComponentAt") { 640 @Override 641 public Component map() { 642 return ((JTabbedPane) getSource()).getComponentAt(i); 643 } 644 })); 645 } 646 647 /** 648 * Maps {@code JTabbedPane.getDisabledIconAt(int)} through queue 649 */ 650 public Icon getDisabledIconAt(final int i) { 651 return (runMapping(new MapAction<Icon>("getDisabledIconAt") { 652 @Override 653 public Icon map() { 654 return ((JTabbedPane) getSource()).getDisabledIconAt(i); 655 } 656 })); 657 } 658 659 /** 660 * Maps {@code JTabbedPane.getForegroundAt(int)} through queue 661 */ 662 public Color getForegroundAt(final int i) { 663 return (runMapping(new MapAction<Color>("getForegroundAt") { 664 @Override 665 public Color map() { 666 return ((JTabbedPane) getSource()).getForegroundAt(i); 667 } 668 })); 669 } 670 671 /** 672 * Maps {@code JTabbedPane.getIconAt(int)} through queue 673 */ 674 public Icon getIconAt(final int i) { 675 return (runMapping(new MapAction<Icon>("getIconAt") { 676 @Override 677 public Icon map() { 678 return ((JTabbedPane) getSource()).getIconAt(i); 679 } 680 })); 681 } 682 683 /** 684 * Maps {@code JTabbedPane.getModel()} through queue 685 */ 686 public SingleSelectionModel getModel() { 687 return (runMapping(new MapAction<SingleSelectionModel>("getModel") { 688 @Override 689 public SingleSelectionModel map() { 690 return ((JTabbedPane) getSource()).getModel(); 691 } 692 })); 693 } 694 695 /** 696 * Maps {@code JTabbedPane.getSelectedComponent()} through queue 697 */ 698 public Component getSelectedComponent() { 699 return (runMapping(new MapAction<Component>("getSelectedComponent") { 700 @Override 701 public Component map() { 702 return ((JTabbedPane) getSource()).getSelectedComponent(); 703 } 704 })); 705 } 706 707 /** 708 * Maps {@code JTabbedPane.getSelectedIndex()} through queue 709 */ 710 public int getSelectedIndex() { 711 return (runMapping(new MapIntegerAction("getSelectedIndex") { 712 @Override 713 public int map() { 714 return ((JTabbedPane) getSource()).getSelectedIndex(); 715 } 716 })); 717 } 718 719 /** 720 * Maps {@code JTabbedPane.getTabCount()} through queue 721 */ 722 public int getTabCount() { 723 return (runMapping(new MapIntegerAction("getTabCount") { 724 @Override 725 public int map() { 726 return ((JTabbedPane) getSource()).getTabCount(); 727 } 728 })); 729 } 730 731 /** 732 * Maps {@code JTabbedPane.getTabPlacement()} through queue 733 */ 734 public int getTabPlacement() { 735 return (runMapping(new MapIntegerAction("getTabPlacement") { 736 @Override 737 public int map() { 738 return ((JTabbedPane) getSource()).getTabPlacement(); 739 } 740 })); 741 } 742 743 /** 744 * Maps {@code JTabbedPane.getTabRunCount()} through queue 745 */ 746 public int getTabRunCount() { 747 return (runMapping(new MapIntegerAction("getTabRunCount") { 748 @Override 749 public int map() { 750 return ((JTabbedPane) getSource()).getTabRunCount(); 751 } 752 })); 753 } 754 755 /** 756 * Maps {@code JTabbedPane.getTitleAt(int)} through queue 757 */ 758 public String getTitleAt(final int i) { 759 return (runMapping(new MapAction<String>("getTitleAt") { 760 @Override 761 public String map() { 762 return ((JTabbedPane) getSource()).getTitleAt(i); 763 } 764 })); 765 } 766 767 /** 768 * Maps {@code JTabbedPane.getUI()} through queue 769 */ 770 public TabbedPaneUI getUI() { 771 return (runMapping(new MapAction<TabbedPaneUI>("getUI") { 772 @Override 773 public TabbedPaneUI map() { 774 return ((JTabbedPane) getSource()).getUI(); 775 } 776 })); 777 } 778 779 /** 780 * Maps {@code JTabbedPane.indexOfComponent(Component)} through queue 781 */ 782 public int indexOfComponent(final Component component) { 783 return (runMapping(new MapIntegerAction("indexOfComponent") { 784 @Override 785 public int map() { 786 return ((JTabbedPane) getSource()).indexOfComponent(component); 787 } 788 })); 789 } 790 791 /** 792 * Maps {@code JTabbedPane.indexOfTab(String)} through queue 793 */ 794 public int indexOfTab(final String string) { 795 return (runMapping(new MapIntegerAction("indexOfTab") { 796 @Override 797 public int map() { 798 return ((JTabbedPane) getSource()).indexOfTab(string); 799 } 800 })); 801 } 802 803 /** 804 * Maps {@code JTabbedPane.indexOfTab(Icon)} through queue 805 */ 806 public int indexOfTab(final Icon icon) { 807 return (runMapping(new MapIntegerAction("indexOfTab") { 808 @Override 809 public int map() { 810 return ((JTabbedPane) getSource()).indexOfTab(icon); 811 } 812 })); 813 } 814 815 /** 816 * Maps 817 * {@code JTabbedPane.insertTab(String, Icon, Component, String, int)} 818 * through queue 819 */ 820 public void insertTab(final String string, final Icon icon, final Component component, final String string1, final int i) { 821 runMapping(new MapVoidAction("insertTab") { 822 @Override 823 public void map() { 824 ((JTabbedPane) getSource()).insertTab(string, icon, component, string1, i); 825 } 826 }); 827 } 828 829 /** 830 * Maps {@code JTabbedPane.isEnabledAt(int)} through queue 831 */ 832 public boolean isEnabledAt(final int i) { 833 return (runMapping(new MapBooleanAction("isEnabledAt") { 834 @Override 835 public boolean map() { 836 return ((JTabbedPane) getSource()).isEnabledAt(i); 837 } 838 })); 839 } 840 841 /** 842 * Maps {@code JTabbedPane.removeChangeListener(ChangeListener)} 843 * through queue 844 */ 845 public void removeChangeListener(final ChangeListener changeListener) { 846 runMapping(new MapVoidAction("removeChangeListener") { 847 @Override 848 public void map() { 849 ((JTabbedPane) getSource()).removeChangeListener(changeListener); 850 } 851 }); 852 } 853 854 /** 855 * Maps {@code JTabbedPane.removeTabAt(int)} through queue 856 */ 857 public void removeTabAt(final int i) { 858 runMapping(new MapVoidAction("removeTabAt") { 859 @Override 860 public void map() { 861 ((JTabbedPane) getSource()).removeTabAt(i); 862 } 863 }); 864 } 865 866 /** 867 * Maps {@code JTabbedPane.setBackgroundAt(int, Color)} through queue 868 */ 869 public void setBackgroundAt(final int i, final Color color) { 870 runMapping(new MapVoidAction("setBackgroundAt") { 871 @Override 872 public void map() { 873 ((JTabbedPane) getSource()).setBackgroundAt(i, color); 874 } 875 }); 876 } 877 878 /** 879 * Maps {@code JTabbedPane.setComponentAt(int, Component)} through queue 880 */ 881 public void setComponentAt(final int i, final Component component) { 882 runMapping(new MapVoidAction("setComponentAt") { 883 @Override 884 public void map() { 885 ((JTabbedPane) getSource()).setComponentAt(i, component); 886 } 887 }); 888 } 889 890 /** 891 * Maps {@code JTabbedPane.setDisabledIconAt(int, Icon)} through queue 892 */ 893 public void setDisabledIconAt(final int i, final Icon icon) { 894 runMapping(new MapVoidAction("setDisabledIconAt") { 895 @Override 896 public void map() { 897 ((JTabbedPane) getSource()).setDisabledIconAt(i, icon); 898 } 899 }); 900 } 901 902 /** 903 * Maps {@code JTabbedPane.setEnabledAt(int, boolean)} through queue 904 */ 905 public void setEnabledAt(final int i, final boolean b) { 906 runMapping(new MapVoidAction("setEnabledAt") { 907 @Override 908 public void map() { 909 ((JTabbedPane) getSource()).setEnabledAt(i, b); 910 } 911 }); 912 } 913 914 /** 915 * Maps {@code JTabbedPane.setForegroundAt(int, Color)} through queue 916 */ 917 public void setForegroundAt(final int i, final Color color) { 918 runMapping(new MapVoidAction("setForegroundAt") { 919 @Override 920 public void map() { 921 ((JTabbedPane) getSource()).setForegroundAt(i, color); 922 } 923 }); 924 } 925 926 /** 927 * Maps {@code JTabbedPane.setIconAt(int, Icon)} through queue 928 */ 929 public void setIconAt(final int i, final Icon icon) { 930 runMapping(new MapVoidAction("setIconAt") { 931 @Override 932 public void map() { 933 ((JTabbedPane) getSource()).setIconAt(i, icon); 934 } 935 }); 936 } 937 938 /** 939 * Maps {@code JTabbedPane.setModel(SingleSelectionModel)} through queue 940 */ 941 public void setModel(final SingleSelectionModel singleSelectionModel) { 942 runMapping(new MapVoidAction("setModel") { 943 @Override 944 public void map() { 945 ((JTabbedPane) getSource()).setModel(singleSelectionModel); 946 } 947 }); 948 } 949 950 /** 951 * Maps {@code JTabbedPane.setSelectedComponent(Component)} through queue 952 */ 953 public void setSelectedComponent(final Component component) { 954 runMapping(new MapVoidAction("setSelectedComponent") { 955 @Override 956 public void map() { 957 ((JTabbedPane) getSource()).setSelectedComponent(component); 958 } 959 }); 960 } 961 962 /** 963 * Maps {@code JTabbedPane.setSelectedIndex(int)} through queue 964 */ 965 public void setSelectedIndex(final int i) { 966 runMapping(new MapVoidAction("setSelectedIndex") { 967 @Override 968 public void map() { 969 ((JTabbedPane) getSource()).setSelectedIndex(i); 970 } 971 }); 972 } 973 974 /** 975 * Maps {@code JTabbedPane.setTabPlacement(int)} through queue 976 */ 977 public void setTabPlacement(final int i) { 978 runMapping(new MapVoidAction("setTabPlacement") { 979 @Override 980 public void map() { 981 ((JTabbedPane) getSource()).setTabPlacement(i); 982 } 983 }); 984 } 985 986 /** 987 * Maps {@code JTabbedPane.setTitleAt(int, String)} through queue 988 */ 989 public void setTitleAt(final int i, final String string) { 990 runMapping(new MapVoidAction("setTitleAt") { 991 @Override 992 public void map() { 993 ((JTabbedPane) getSource()).setTitleAt(i, string); 994 } 995 }); 996 } 997 998 /** 999 * Maps {@code JTabbedPane.setUI(TabbedPaneUI)} through queue 1000 */ 1001 public void setUI(final TabbedPaneUI tabbedPaneUI) { 1002 runMapping(new MapVoidAction("setUI") { 1003 @Override 1004 public void map() { 1005 ((JTabbedPane) getSource()).setUI(tabbedPaneUI); 1006 } 1007 }); 1008 } 1009 1010 //End of mapping // 1011 //////////////////////////////////////////////////////// 1012 /** 1013 * Specifies criteria for a tab page searching. 1014 */ 1015 public interface TabPageChooser { 1016 1017 /** 1018 * Should be true if a page is good. 1019 * 1020 * @param oper Operator used to search item. 1021 * @param index Index of a page be checked. 1022 * @return true if a page fits the criteria. 1023 */ 1024 public boolean checkPage(JTabbedPaneOperator oper, int index); 1025 1026 /** 1027 * Page description. 1028 * 1029 * @return a description. 1030 */ 1031 public String getDescription(); 1032 } 1033 1034 /** 1035 * Exception is thrown if a nonexistent page is trying to be selected. 1036 */ 1037 public class NoSuchPageException extends JemmyInputException { 1038 1039 private static final long serialVersionUID = 42L; 1040 1041 /** 1042 * Constructor. 1043 * 1044 * @param item nonexistent page title. 1045 */ 1046 public NoSuchPageException(String item) { 1047 super("No such page as \"" + item + "\"", getSource()); 1048 } 1049 } 1050 1051 /** 1052 * Allows to find component by page title. 1053 */ 1054 public static class JTabbedPaneByItemFinder implements ComponentChooser { 1055 1056 String title; 1057 int itemIndex; 1058 StringComparator comparator; 1059 1060 /** 1061 * Constructs JTabbedPaneByItemFinder. 1062 * 1063 * @param lb a text pattern 1064 * @param ii page index to check. If equal to -1, selected page is 1065 * checked. 1066 * @param comparator specifies string comparision algorithm. 1067 */ 1068 public JTabbedPaneByItemFinder(String lb, int ii, StringComparator comparator) { 1069 title = lb; 1070 itemIndex = ii; 1071 this.comparator = comparator; 1072 } 1073 1074 /** 1075 * Constructs JTabbedPaneByItemFinder. 1076 * 1077 * @param lb a text pattern 1078 * @param ii page index to check. If equal to -1, selected page is 1079 * checked. 1080 */ 1081 public JTabbedPaneByItemFinder(String lb, int ii) { 1082 this(lb, ii, Operator.getDefaultStringComparator()); 1083 } 1084 1085 @Override 1086 public boolean checkComponent(Component comp) { 1087 if (comp instanceof JTabbedPane) { 1088 if (title == null) { 1089 return true; 1090 } 1091 JTabbedPaneOperator tpo = new JTabbedPaneOperator((JTabbedPane) comp); 1092 if (tpo.getTabCount() > itemIndex) { 1093 int ii = itemIndex; 1094 if (ii == -1) { 1095 ii = tpo.getSelectedIndex(); 1096 if (ii == -1) { 1097 return false; 1098 } 1099 } 1100 return (comparator.equals(tpo.getTitleAt(ii), 1101 title)); 1102 } 1103 } 1104 return false; 1105 } 1106 1107 @Override 1108 public String getDescription() { 1109 return ("JTabbedPane with text \"" + title + "\" in " 1110 + itemIndex + "'th item"); 1111 } 1112 1113 @Override 1114 public String toString() { 1115 return "JTabbedPaneByItemFinder{" + "title=" + title + ", itemIndex=" + itemIndex + ", comparator=" + comparator + '}'; 1116 } 1117 } 1118 1119 /** 1120 * Checks component type. 1121 */ 1122 public static class JTabbedPaneFinder extends Finder { 1123 1124 /** 1125 * Constructs JTabbedPaneFinder. 1126 * 1127 * @param sf other searching criteria. 1128 */ 1129 public JTabbedPaneFinder(ComponentChooser sf) { 1130 super(JTabbedPane.class, sf); 1131 } 1132 1133 /** 1134 * Constructs JTabbedPaneFinder. 1135 */ 1136 public JTabbedPaneFinder() { 1137 super(JTabbedPane.class); 1138 } 1139 } 1140 1141 private static class BySubStringTabPageChooser implements TabPageChooser { 1142 1143 String title; 1144 StringComparator comparator; 1145 1146 public BySubStringTabPageChooser(String title, StringComparator comparator) { 1147 this.title = title; 1148 this.comparator = comparator; 1149 } 1150 1151 @Override 1152 public boolean checkPage(JTabbedPaneOperator oper, int index) { 1153 return (comparator.equals(oper.getTitleAt(index), 1154 title)); 1155 } 1156 1157 @Override 1158 public String getDescription() { 1159 return "Page having \"" + title + "\" title."; 1160 } 1161 1162 @Override 1163 public String toString() { 1164 return "BySubStringTabPageChooser{" + "title=" + title + ", comparator=" + comparator + '}'; 1165 } 1166 } 1167 1168} 1169