|
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.drivers.windows; |
|
24 |
|
25 import java.awt.Component; |
|
26 import java.awt.Container; |
|
27 |
|
28 import javax.swing.plaf.basic.BasicInternalFrameTitlePane; |
|
29 |
|
30 import org.netbeans.jemmy.ComponentChooser; |
|
31 import org.netbeans.jemmy.ComponentSearcher; |
|
32 import org.netbeans.jemmy.drivers.FrameDriver; |
|
33 import org.netbeans.jemmy.drivers.InternalFrameDriver; |
|
34 import org.netbeans.jemmy.drivers.LightSupportiveDriver; |
|
35 import org.netbeans.jemmy.drivers.WindowDriver; |
|
36 import org.netbeans.jemmy.operators.ComponentOperator; |
|
37 import org.netbeans.jemmy.operators.JInternalFrameOperator; |
|
38 |
|
39 public class DefaultInternalFrameDriver extends LightSupportiveDriver |
|
40 implements WindowDriver, FrameDriver, InternalFrameDriver { |
|
41 |
|
42 public DefaultInternalFrameDriver() { |
|
43 super(new String[]{"org.netbeans.jemmy.operators.JInternalFrameOperator"}); |
|
44 } |
|
45 |
|
46 @Override |
|
47 public void activate(ComponentOperator oper) { |
|
48 checkSupported(oper); |
|
49 ((JInternalFrameOperator) oper).moveToFront(); |
|
50 ((JInternalFrameOperator) oper).getTitleOperator().clickMouse(); |
|
51 } |
|
52 |
|
53 @Override |
|
54 public void requestClose(ComponentOperator oper) { |
|
55 checkSupported(oper); |
|
56 ((JInternalFrameOperator) oper).moveToFront(); |
|
57 ((JInternalFrameOperator) oper).getCloseButton().push(); |
|
58 } |
|
59 |
|
60 @Override |
|
61 public void requestCloseAndThenHide(ComponentOperator oper) { |
|
62 throw new UnsupportedOperationException(); |
|
63 } |
|
64 |
|
65 @Override |
|
66 @Deprecated |
|
67 public void close(ComponentOperator oper) { |
|
68 requestClose(oper); |
|
69 } |
|
70 |
|
71 @Override |
|
72 public void move(ComponentOperator oper, int x, int y) { |
|
73 checkSupported(oper); |
|
74 ComponentOperator titleOperator = ((JInternalFrameOperator) oper).getTitleOperator(); |
|
75 titleOperator.dragNDrop(titleOperator.getCenterY(), |
|
76 titleOperator.getCenterY(), |
|
77 x - oper.getX() + titleOperator.getCenterY(), |
|
78 y - oper.getY() + titleOperator.getCenterY()); |
|
79 } |
|
80 |
|
81 @Override |
|
82 public void resize(ComponentOperator oper, int width, int height) { |
|
83 checkSupported(oper); |
|
84 oper. |
|
85 dragNDrop(oper.getWidth() - 1, |
|
86 oper.getHeight() - 1, |
|
87 width - 1, |
|
88 height - 1); |
|
89 } |
|
90 |
|
91 @Override |
|
92 public void iconify(ComponentOperator oper) { |
|
93 checkSupported(oper); |
|
94 ((JInternalFrameOperator) oper).getMinimizeButton().clickMouse(); |
|
95 } |
|
96 |
|
97 @Override |
|
98 public void deiconify(ComponentOperator oper) { |
|
99 checkSupported(oper); |
|
100 ((JInternalFrameOperator) oper).getIconOperator().pushButton(); |
|
101 } |
|
102 |
|
103 @Override |
|
104 public void maximize(ComponentOperator oper) { |
|
105 checkSupported(oper); |
|
106 if (!((JInternalFrameOperator) oper).isMaximum()) { |
|
107 if (!((JInternalFrameOperator) oper).isSelected()) { |
|
108 activate(oper); |
|
109 } |
|
110 ((JInternalFrameOperator) oper).getMaximizeButton().push(); |
|
111 } |
|
112 } |
|
113 |
|
114 @Override |
|
115 public void demaximize(ComponentOperator oper) { |
|
116 checkSupported(oper); |
|
117 if (((JInternalFrameOperator) oper).isMaximum()) { |
|
118 if (!((JInternalFrameOperator) oper).isSelected()) { |
|
119 activate(oper); |
|
120 } |
|
121 ((JInternalFrameOperator) oper).getMaximizeButton().push(); |
|
122 } |
|
123 } |
|
124 |
|
125 @Override |
|
126 public Component getTitlePane(ComponentOperator operator) { |
|
127 ComponentSearcher cs = new ComponentSearcher((Container) operator.getSource()); |
|
128 cs.setOutput(operator.getOutput().createErrorOutput()); |
|
129 return (cs.findComponent(new ComponentChooser() { |
|
130 @Override |
|
131 public boolean checkComponent(Component comp) { |
|
132 if (System.getProperty("java.version").startsWith("1.2")) { |
|
133 return comp.getClass().getName().endsWith("InternalFrameTitlePane"); |
|
134 } else { |
|
135 return comp instanceof BasicInternalFrameTitlePane; |
|
136 } |
|
137 } |
|
138 |
|
139 @Override |
|
140 public String getDescription() { |
|
141 return "Title pane"; |
|
142 } |
|
143 |
|
144 @Override |
|
145 public String toString() { |
|
146 return "getTitlePane.ComponentChooser{description = " + getDescription() + '}'; |
|
147 } |
|
148 })); |
|
149 } |
|
150 } |