001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s): Alexandre Iline.
025: *
026: * The Original Software is the Jemmy library.
027: * The Initial Developer of the Original Software is Alexandre Iline.
028: * All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: *
041: *
042: *
043: * $Id: DefaultWindowDriver.java,v 1.7 2007/10/05 11:37:32 jskrivanek Exp $ $Revision: 1.7 $ $Date: 2007/10/05 11:37:32 $
044: *
045: */
046:
047: package org.netbeans.jemmy.drivers.windows;
048:
049: import java.awt.Dimension;
050: import java.awt.Toolkit;
051: import java.awt.Window;
052:
053: import java.awt.event.ComponentEvent;
054: import java.awt.event.FocusEvent;
055: import java.awt.event.WindowEvent;
056:
057: import org.netbeans.jemmy.operators.ComponentOperator;
058: import org.netbeans.jemmy.operators.WindowOperator;
059:
060: import org.netbeans.jemmy.drivers.LightSupportiveDriver;
061: import org.netbeans.jemmy.drivers.WindowDriver;
062:
063: import org.netbeans.jemmy.drivers.input.EventDriver;
064:
065: public class DefaultWindowDriver extends LightSupportiveDriver
066: implements WindowDriver {
067: EventDriver eDriver;
068:
069: public DefaultWindowDriver() {
070: super (
071: new String[] { "org.netbeans.jemmy.operators.WindowOperator" });
072: eDriver = new EventDriver();
073: }
074:
075: public void activate(ComponentOperator oper) {
076: checkSupported(oper);
077: if (((WindowOperator) oper).getFocusOwner() == null) {
078: ((WindowOperator) oper).toFront();
079: }
080: eDriver.dispatchEvent(oper.getSource(),
081: new WindowEvent((Window) oper.getSource(),
082: WindowEvent.WINDOW_ACTIVATED));
083: eDriver.dispatchEvent(oper.getSource(), new FocusEvent(
084: (Window) oper.getSource(), FocusEvent.FOCUS_GAINED));
085: }
086:
087: public void close(ComponentOperator oper) {
088: checkSupported(oper);
089: eDriver.dispatchEvent(oper.getSource(), new WindowEvent(
090: (Window) oper.getSource(), WindowEvent.WINDOW_CLOSING));
091: ((WindowOperator) oper).setVisible(false);
092: }
093:
094: public void move(ComponentOperator oper, int x, int y) {
095: checkSupported(oper);
096: ((WindowOperator) oper).setLocation(x, y);
097: }
098:
099: public void resize(ComponentOperator oper, int width, int height) {
100: checkSupported(oper);
101: ((WindowOperator) oper).setSize(width, height);
102: eDriver.dispatchEvent(oper.getSource(), new ComponentEvent(
103: (Window) oper.getSource(),
104: ComponentEvent.COMPONENT_RESIZED));
105: }
106: }
|