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 */
23 package org.netbeans.jemmy.operators;
24
25 import java.awt.Component;
26 import java.awt.Container;
27 import java.awt.Rectangle;
28 import java.beans.PropertyVetoException;
29 import java.util.Hashtable;
30
31 import javax.swing.Icon;
32 import javax.swing.JDesktopPane;
33 import javax.swing.JInternalFrame;
34 import javax.swing.JLayeredPane;
35 import javax.swing.JMenuBar;
36 import javax.swing.JScrollPane;
37 import javax.swing.JInternalFrame.JDesktopIcon;
38 import javax.swing.event.InternalFrameListener;
39 import javax.swing.plaf.InternalFrameUI;
40
41 import org.netbeans.jemmy.ComponentChooser;
42 import org.netbeans.jemmy.ComponentSearcher;
43 import org.netbeans.jemmy.JemmyInputException;
44 import org.netbeans.jemmy.JemmyProperties;
45 import org.netbeans.jemmy.Outputable;
46 import org.netbeans.jemmy.TestOut;
488 /**
489 * Moves frame to new location. Note: frame should not be iconified.
490 *
491 * @param x X coordinate of a new frame location.
492 * @param y Y coordinate of a new frame location.
493 * @throws WrongInternalFrameStateException
494 */
495 public void move(int x, int y) {
496 checkIconified(false);
497 output.printLine("Move JInternalFrame to ("
498 + Integer.toString(x) + ","
499 + Integer.toString(y) + ")"
500 + " position\n : " + toStringSource());
501 output.printGolden("Move " + getTitle()
502 + " JInternalFrame to ("
503 + Integer.toString(x) + ","
504 + Integer.toString(y) + ")"
505 + " position");
506 checkIconified(false);
507 wDriver.move(this, x, y);
508 }
509
510 /**
511 * Resizes frame. Note: frame should not be iconified.
512 *
513 * @param width New frame width.
514 * @param height New frame height.
515 * @throws WrongInternalFrameStateException
516 */
517 public void resize(int width, int height) {
518 output.printLine("Resize JInternalFrame to ("
519 + Integer.toString(width) + ","
520 + Integer.toString(height) + ")"
521 + " size\n : " + toStringSource());
522 output.printGolden("Resize " + getTitle()
523 + " JInternalFrame to ("
524 + Integer.toString(width) + ","
525 + Integer.toString(height) + ")"
526 + " size");
527 checkIconified(false);
528 wDriver.resize(this, width, height);
529 }
530
531 /**
532 * Activates frame. Note: frame should not be iconified.
533 *
534 * @throws WrongInternalFrameStateException
535 */
536 public void activate() {
537 checkIconified(false);
538 wDriver.activate(this);
539 }
540
541 /**
542 * Closes the frame.
543 */
544 public void close() {
545 checkIconified(false);
546 wDriver.requestClose(this);
547 }
548
549 /**
550 * Scrolls to internal frame's rectangle.
551 *
552 * @param x Horizontal rectangle coordinate
553 * @param y Vertical rectangle coordinate
554 * @param width rectangle width
555 * @param height rectangle height
556 *
557 */
558 public void scrollToRectangle(int x, int y, int width, int height) {
559 output.printTrace("Scroll desktop pane to make \"" + getTitle() + "\" internal frame visible");
560 output.printGolden("Scroll desktop pane to make \"" + getTitle() + "\" internal frame visible");
561 makeComponentVisible();
562 //try to find JScrollPane under.
563 JScrollPane scroll;
564 if (isIcon()) {
565 scroll
566 = (JScrollPane) iconOperator.getContainer(new JScrollPaneOperator.JScrollPaneFinder(ComponentSearcher.
637 * @return a button operator
638 */
639 public ContainerOperator<?> getTitleOperator() {
640 initOperators();
641 return titleOperator;
642 }
643
644 /**
645 * Creates an operator for an desktop icon.
646 *
647 * @return an icon operator.
648 */
649 public JDesktopIconOperator getIconOperator() {
650 initOperators();
651 return iconOperator;
652 }
653
654 /**
655 * Waits for the frame to be iconified or deiconified.
656 *
657 * @param icon whether the frame needs to be iconified.
658 */
659 public void waitIcon(final boolean icon) {
660 waitState(new ComponentChooser() {
661 @Override
662 public boolean checkComponent(Component comp) {
663 return ((JInternalFrame) comp).isIcon() == icon;
664 }
665
666 @Override
667 public String getDescription() {
668 return "Iconified JInternalFrame";
669 }
670
671 @Override
672 public String toString() {
673 return "JInternalFrameOperator.waitIcon.ComponentChooser{description = " + getDescription() + '}';
674 }
675 });
676 }
677
678 /**
679 * Waits for the frame to be maximized or demaximized.
680 *
681 * @param maximum whether the frame needs to be maximized.
682 */
683 public void waitMaximum(final boolean maximum) {
684 waitState(new ComponentChooser() {
685 @Override
686 public boolean checkComponent(Component comp) {
687 return ((JInternalFrame) comp).isMaximum() == maximum;
688 }
689
690 @Override
691 public String getDescription() {
692 return "Maximizied JInternalFrame";
693 }
694
695 @Override
696 public String toString() {
697 return "JInternalFrameOperator.waitMaximum.ComponentChooser{description = " + getDescription() + '}';
698 }
699 });
700 }
701
702 /**
703 * Returns information about component.
704 */
705 @Override
706 public Hashtable<String, Object> getDump() {
707 Hashtable<String, Object> result = super.getDump();
708 result.put(TITLE_DPROP, ((JInternalFrame) getSource()).getTitle());
709 String state = STATE_NORMAL_DPROP_VALUE;
710 if (((JInternalFrame) getSource()).isClosed()) {
711 state = STATE_CLOSED_DPROP_VALUE;
712 } else if (((JInternalFrame) getSource()).isIcon()) {
|
1 /*
2 * Copyright (c) 1997, 2018, 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 */
23 package org.netbeans.jemmy.operators;
24
25 import java.awt.Component;
26 import java.awt.Container;
27 import java.awt.Dimension;
28 import java.awt.Point;
29 import java.awt.Rectangle;
30 import java.beans.PropertyVetoException;
31 import java.util.Hashtable;
32
33 import javax.swing.Icon;
34 import javax.swing.JDesktopPane;
35 import javax.swing.JInternalFrame;
36 import javax.swing.JLayeredPane;
37 import javax.swing.JMenuBar;
38 import javax.swing.JScrollPane;
39 import javax.swing.JInternalFrame.JDesktopIcon;
40 import javax.swing.event.InternalFrameListener;
41 import javax.swing.plaf.InternalFrameUI;
42
43 import org.netbeans.jemmy.ComponentChooser;
44 import org.netbeans.jemmy.ComponentSearcher;
45 import org.netbeans.jemmy.JemmyInputException;
46 import org.netbeans.jemmy.JemmyProperties;
47 import org.netbeans.jemmy.Outputable;
48 import org.netbeans.jemmy.TestOut;
490 /**
491 * Moves frame to new location. Note: frame should not be iconified.
492 *
493 * @param x X coordinate of a new frame location.
494 * @param y Y coordinate of a new frame location.
495 * @throws WrongInternalFrameStateException
496 */
497 public void move(int x, int y) {
498 checkIconified(false);
499 output.printLine("Move JInternalFrame to ("
500 + Integer.toString(x) + ","
501 + Integer.toString(y) + ")"
502 + " position\n : " + toStringSource());
503 output.printGolden("Move " + getTitle()
504 + " JInternalFrame to ("
505 + Integer.toString(x) + ","
506 + Integer.toString(y) + ")"
507 + " position");
508 checkIconified(false);
509 wDriver.move(this, x, y);
510 if (getVerification()) {
511 waitComponentLocation(new Point(x, y));
512 }
513 }
514
515 /**
516 * Resizes frame. Note: frame should not be iconified.
517 *
518 * @param width New frame width.
519 * @param height New frame height.
520 * @throws WrongInternalFrameStateException
521 */
522 public void resize(int width, int height) {
523 output.printLine("Resize JInternalFrame to ("
524 + Integer.toString(width) + ","
525 + Integer.toString(height) + ")"
526 + " size\n : " + toStringSource());
527 output.printGolden("Resize " + getTitle()
528 + " JInternalFrame to ("
529 + Integer.toString(width) + ","
530 + Integer.toString(height) + ")"
531 + " size");
532 checkIconified(false);
533 wDriver.resize(this, width, height);
534 if (getVerification()) {
535 waitComponentSize(new Dimension(width, height));
536 }
537 }
538
539 /**
540 * Activates frame. Note: frame should not be iconified.
541 *
542 * @throws WrongInternalFrameStateException
543 */
544 public void activate() {
545 checkIconified(false);
546 wDriver.activate(this);
547 if (getVerification()) {
548 waitActivate(true);
549 }
550 }
551
552 /**
553 * Closes the frame.
554 */
555 public void close() {
556 checkIconified(false);
557 wDriver.requestClose(this);
558 if (getVerification()) {
559 waitClosed();
560 }
561 }
562
563 /**
564 * Scrolls to internal frame's rectangle.
565 *
566 * @param x Horizontal rectangle coordinate
567 * @param y Vertical rectangle coordinate
568 * @param width rectangle width
569 * @param height rectangle height
570 *
571 */
572 public void scrollToRectangle(int x, int y, int width, int height) {
573 output.printTrace("Scroll desktop pane to make \"" + getTitle() + "\" internal frame visible");
574 output.printGolden("Scroll desktop pane to make \"" + getTitle() + "\" internal frame visible");
575 makeComponentVisible();
576 //try to find JScrollPane under.
577 JScrollPane scroll;
578 if (isIcon()) {
579 scroll
580 = (JScrollPane) iconOperator.getContainer(new JScrollPaneOperator.JScrollPaneFinder(ComponentSearcher.
651 * @return a button operator
652 */
653 public ContainerOperator<?> getTitleOperator() {
654 initOperators();
655 return titleOperator;
656 }
657
658 /**
659 * Creates an operator for an desktop icon.
660 *
661 * @return an icon operator.
662 */
663 public JDesktopIconOperator getIconOperator() {
664 initOperators();
665 return iconOperator;
666 }
667
668 /**
669 * Waits for the frame to be iconified or deiconified.
670 *
671 * @param isIconified whether the frame needs to be iconified or deiconified.
672 */
673 public void waitIcon(final boolean isIconified) {
674 waitStateOnQueue(new ComponentChooser() {
675 @Override
676 public boolean checkComponent(Component comp) {
677 return isIcon() == isIconified;
678 }
679
680 @Override
681 public String getDescription() {
682 return "Internal Frame is " + (isIconified ? "iconified" : "deiconified");
683 }
684
685 @Override
686 public String toString() {
687 return "JInternalFrameOperator.waitIcon.ComponentChooser{description = " + getDescription() + '}';
688 }
689 });
690 }
691
692 /**
693 * Waits for the frame to be activated or deactivated.
694 *
695 * @param isActivate whether the frame needs to be activated or deactivated.
696 */
697 public void waitActivate(final boolean isActivate) {
698 waitStateOnQueue(new ComponentChooser() {
699 @Override
700 public boolean checkComponent(Component comp) {
701 return isSelected() == isActivate;
702 }
703
704 @Override
705 public String getDescription() {
706 return "Internal Frame is " + (isActivate ? "activated" : "deactivated");
707 }
708
709 @Override
710 public String toString() {
711 return "JInternalFrameOperator.waitActivate.ComponentChooser{description = " + getDescription() + '}';
712 }
713 });
714 }
715
716 /**
717 * Waits for the frame to be closed.
718 */
719 public void waitClosed() {
720 waitStateOnQueue(new ComponentChooser() {
721 @Override
722 public boolean checkComponent(Component comp) {
723 return isClosed();
724 }
725
726 @Override
727 public String getDescription() {
728 return "Internal Frame is closed";
729 }
730
731 @Override
732 public String toString() {
733 return "JInternalFrameOperator.waitClosed.ComponentChooser{description = " + getDescription() + '}';
734 }
735 });
736 }
737
738 /**
739 * Waits for the frame to be maximized or demaximized.
740 *
741 * @param isMaximum whether the frame needs to be maximized or demaximized.
742 */
743 public void waitMaximum(final boolean isMaximum) {
744 waitStateOnQueue(new ComponentChooser() {
745 @Override
746 public boolean checkComponent(Component comp) {
747 return isMaximum() == isMaximum;
748 }
749
750 @Override
751 public String getDescription() {
752 return "Internal Frame is " + (isMaximum ? "maximizied" : "demaximizied");
753 }
754
755 @Override
756 public String toString() {
757 return "JInternalFrameOperator.waitMaximum.ComponentChooser{description = " + getDescription() + '}';
758 }
759 });
760 }
761
762 /**
763 * Returns information about component.
764 */
765 @Override
766 public Hashtable<String, Object> getDump() {
767 Hashtable<String, Object> result = super.getDump();
768 result.put(TITLE_DPROP, ((JInternalFrame) getSource()).getTitle());
769 String state = STATE_NORMAL_DPROP_VALUE;
770 if (((JInternalFrame) getSource()).isClosed()) {
771 state = STATE_CLOSED_DPROP_VALUE;
772 } else if (((JInternalFrame) getSource()).isIcon()) {
|