DefaultWindowDriver.java revision 13978:1993af50385d
1232633Smp/*
259243Sobrien * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
359243Sobrien * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
459243Sobrien *
559243Sobrien * This code is free software; you can redistribute it and/or modify it
6232633Smp * under the terms of the GNU General Public License version 2 only, as
759243Sobrien * published by the Free Software Foundation.
8232633Smp *
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.drivers.windows;
24
25import java.awt.Window;
26import java.awt.event.ComponentEvent;
27import java.awt.event.FocusEvent;
28import java.awt.event.WindowEvent;
29
30import org.netbeans.jemmy.drivers.LightSupportiveDriver;
31import org.netbeans.jemmy.drivers.WindowDriver;
32import org.netbeans.jemmy.drivers.input.EventDriver;
33import org.netbeans.jemmy.operators.ComponentOperator;
34import org.netbeans.jemmy.operators.WindowOperator;
35
36public 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}
94