|
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.Window; |
|
26 import java.awt.event.ComponentEvent; |
|
27 import java.awt.event.FocusEvent; |
|
28 import java.awt.event.WindowEvent; |
|
29 |
|
30 import org.netbeans.jemmy.drivers.LightSupportiveDriver; |
|
31 import org.netbeans.jemmy.drivers.WindowDriver; |
|
32 import org.netbeans.jemmy.drivers.input.EventDriver; |
|
33 import org.netbeans.jemmy.operators.ComponentOperator; |
|
34 import org.netbeans.jemmy.operators.WindowOperator; |
|
35 |
|
36 public class DefaultWindowDriver extends LightSupportiveDriver implements WindowDriver { |
|
37 |
|
38 EventDriver eDriver; |
|
39 |
|
40 public DefaultWindowDriver() { |
|
41 super(new String[]{"org.netbeans.jemmy.operators.WindowOperator"}); |
|
42 eDriver = new EventDriver(); |
|
43 } |
|
44 |
|
45 @Override |
|
46 public void activate(ComponentOperator oper) { |
|
47 checkSupported(oper); |
|
48 if (((WindowOperator) oper).getFocusOwner() == null) { |
|
49 ((WindowOperator) oper).toFront(); |
|
50 } |
|
51 eDriver.dispatchEvent(oper.getSource(), |
|
52 new WindowEvent((Window) oper.getSource(), |
|
53 WindowEvent.WINDOW_ACTIVATED)); |
|
54 eDriver.dispatchEvent(oper.getSource(), |
|
55 new FocusEvent(oper.getSource(), |
|
56 FocusEvent.FOCUS_GAINED)); |
|
57 } |
|
58 |
|
59 @Override |
|
60 public void requestClose(ComponentOperator oper) { |
|
61 checkSupported(oper); |
|
62 eDriver.dispatchEvent(oper.getSource(), |
|
63 new WindowEvent((Window) oper.getSource(), |
|
64 WindowEvent.WINDOW_CLOSING)); |
|
65 } |
|
66 |
|
67 @Override |
|
68 public void requestCloseAndThenHide(ComponentOperator oper) { |
|
69 requestClose(oper); |
|
70 oper.setVisible(false); |
|
71 } |
|
72 |
|
73 @Override |
|
74 @Deprecated |
|
75 public void close(ComponentOperator oper) { |
|
76 requestClose(oper); |
|
77 } |
|
78 |
|
79 @Override |
|
80 public void move(ComponentOperator oper, int x, int y) { |
|
81 checkSupported(oper); |
|
82 oper.setLocation(x, y); |
|
83 } |
|
84 |
|
85 @Override |
|
86 public void resize(ComponentOperator oper, int width, int height) { |
|
87 checkSupported(oper); |
|
88 oper.setSize(width, height); |
|
89 eDriver.dispatchEvent(oper.getSource(), |
|
90 new ComponentEvent(oper.getSource(), |
|
91 ComponentEvent.COMPONENT_RESIZED)); |
|
92 } |
|
93 } |