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$ $Revision$ $Date$
044: *
045: */
046:
047: package org.netbeans.jemmy.drivers;
048:
049: import org.netbeans.jemmy.EventDispatcher;
050: import org.netbeans.jemmy.JemmyException;
051: import org.netbeans.jemmy.JemmyProperties;
052: import org.netbeans.jemmy.Timeout;
053:
054: import org.netbeans.jemmy.drivers.input.KeyEventDriver;
055: import org.netbeans.jemmy.drivers.input.KeyRobotDriver;
056: import org.netbeans.jemmy.drivers.input.MouseEventDriver;
057: import org.netbeans.jemmy.drivers.input.MouseRobotDriver;
058:
059: import org.netbeans.jemmy.operators.ButtonOperator;
060: import org.netbeans.jemmy.operators.CheckboxOperator;
061: import org.netbeans.jemmy.operators.ChoiceOperator;
062: import org.netbeans.jemmy.operators.LabelOperator;
063: import org.netbeans.jemmy.operators.ListOperator;
064: import org.netbeans.jemmy.operators.ScrollPaneOperator;
065: import org.netbeans.jemmy.operators.ScrollbarOperator;
066: import org.netbeans.jemmy.operators.TextAreaOperator;
067: import org.netbeans.jemmy.operators.TextComponentOperator;
068: import org.netbeans.jemmy.operators.TextFieldOperator;
069:
070: /**
071: * Installs drivers for low-level drivers.
072: *
073: * @author Alexandre Iline(alexandre.iline@sun.com)
074: */
075: public class InputDriverInstaller {
076: Timeout robotAutoDelay;
077: boolean useEventDrivers;
078: boolean smooth = false;
079:
080: /**
081: * Constructs an InputDriverInstaller object.
082: * @param useEventDrivers Tells whether to use event drivers, otherwise robot drivers.
083: * @param robotAutoDelay Time for <code>Robot.setAutoDelay(long)</code> method.
084: */
085: public InputDriverInstaller(boolean useEventDrivers,
086: Timeout robotAutoDelay) {
087: this .robotAutoDelay = robotAutoDelay;
088: this .useEventDrivers = useEventDrivers;
089: }
090:
091: /**
092: * Constructs an InputDriverInstaller object. Takes autodelay time
093: * from JemmyProperties' timeouts.
094: * @param useEventDrivers Tells whether to use event drivers, otherwise robot drivers.
095: */
096: public InputDriverInstaller(boolean useEventDrivers) {
097: this (useEventDrivers, JemmyProperties.getCurrentTimeouts()
098: .create("EventDispatcher.RobotAutoDelay"));
099: }
100:
101: /**
102: * Constructs an InputDriverInstaller object. Takes autodelay time
103: * from JemmyProperties' timeouts.
104: * @param useEventDrivers Tells whether to use event drivers, otherwise robot drivers.
105: * @param smooth whether to move mouse smoothly.
106: */
107: public InputDriverInstaller(boolean useEventDrivers, boolean smooth) {
108: this (useEventDrivers);
109: this .smooth = smooth;
110: }
111:
112: /**
113: * Constructs an InputDriverInstaller object. Uses event drivers.
114: * @param robotAutoDelay Time for <code>Robot.setAutoDelay(long)</code> method.
115: */
116: public InputDriverInstaller(Timeout robotAutoDelay) {
117: this (true, robotAutoDelay);
118: }
119:
120: /**
121: * Constructs an InputDriverInstaller object. Takes autodelay time
122: * from JemmyProperties' timeouts. Uses event drivers.
123: */
124: public InputDriverInstaller() {
125: this (true);
126: }
127:
128: static {
129: Class clss = EventDispatcher.class;
130: }
131:
132: /**
133: * Installs input drivers.
134: */
135: public void install() {
136: if (useEventDrivers) {
137: LightDriver keyE = new KeyEventDriver();
138: LightDriver mouseE = new MouseEventDriver();
139: DriverManager.removeDriver(DriverManager.KEY_DRIVER_ID,
140: keyE.getSupported());
141: DriverManager.removeDriver(DriverManager.MOUSE_DRIVER_ID,
142: mouseE.getSupported());
143: DriverManager.setDriver(DriverManager.KEY_DRIVER_ID, keyE);
144: DriverManager.setDriver(DriverManager.MOUSE_DRIVER_ID,
145: mouseE);
146: try {
147: String[] awtOperators = {
148: "org.netbeans.jemmy.operators.ButtonOperator",
149: "org.netbeans.jemmy.operators.CheckboxOperator",
150: "org.netbeans.jemmy.operators.ChoiceOperator",
151: "org.netbeans.jemmy.operators.LabelOperator",
152: "org.netbeans.jemmy.operators.ListOperator",
153: "org.netbeans.jemmy.operators.ScrollPaneOperator",
154: "org.netbeans.jemmy.operators.ScrollbarOperator",
155: "org.netbeans.jemmy.operators.TextAreaOperator",
156: "org.netbeans.jemmy.operators.TextComponentOperator",
157: "org.netbeans.jemmy.operators.TextFieldOperator" };
158: LightDriver keyR = new KeyRobotDriver(robotAutoDelay,
159: awtOperators);
160: LightDriver mouseR = new MouseRobotDriver(
161: robotAutoDelay, awtOperators);
162: DriverManager.removeDriver(DriverManager.KEY_DRIVER_ID,
163: keyR.getSupported());
164: DriverManager.removeDriver(
165: DriverManager.MOUSE_DRIVER_ID, mouseR
166: .getSupported());
167: DriverManager.setDriver(DriverManager.KEY_DRIVER_ID,
168: keyR);
169: DriverManager.setDriver(DriverManager.MOUSE_DRIVER_ID,
170: mouseR);
171: } catch (JemmyException e) {
172: if (!(e.getInnerException() instanceof ClassNotFoundException)) {
173: throw (e);
174: }
175: }
176: } else {
177: LightDriver keyR = new KeyRobotDriver(robotAutoDelay);
178: LightDriver mouseR = new MouseRobotDriver(robotAutoDelay,
179: smooth);
180: DriverManager.removeDriver(DriverManager.KEY_DRIVER_ID,
181: keyR.getSupported());
182: DriverManager.removeDriver(DriverManager.MOUSE_DRIVER_ID,
183: mouseR.getSupported());
184: DriverManager.setDriver(DriverManager.KEY_DRIVER_ID, keyR);
185: DriverManager.setDriver(DriverManager.MOUSE_DRIVER_ID,
186: mouseR);
187: }
188: }
189: }
|