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. Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 package org.netbeans.jemmy.drivers.input;
26 
27 import org.netbeans.jemmy.Timeout;
28 import org.netbeans.jemmy.drivers.KeyDriver;
29 import org.netbeans.jemmy.operators.ComponentOperator;
30 
31 /**
32  * KeyDriver using robot operations.
33  *
34  * @author Alexandre Iline(alexandre.iline@oracle.com)
35  */
36 public class KeyRobotDriver extends RobotDriver implements KeyDriver {
37 
38     /**
39      * Constructs a KeyRobotDriver object.
40      *
41      * @param autoDelay Time for {@code Robot.setAutoDelay(long)} method.
42      */
KeyRobotDriver(Timeout autoDelay)43     public KeyRobotDriver(Timeout autoDelay) {
44         super(autoDelay);
45     }
46 
47     /**
48      * Constructs a KeyRobotDriver object.
49      *
50      * @param autoDelay Time for {@code Robot.setAutoDelay(long)} method.
51      * @param supported an array of supported class names
52      */
KeyRobotDriver(Timeout autoDelay, String[] supported)53     public KeyRobotDriver(Timeout autoDelay, String[] supported) {
54         super(autoDelay, supported);
55     }
56 
57     @Override
pushKey(ComponentOperator oper, int keyCode, int modifiers, Timeout pushTime)58     public void pushKey(ComponentOperator oper, int keyCode, int modifiers, Timeout pushTime) {
59         pressKey(oper, keyCode, modifiers);
60         pushTime.sleep();
61         releaseKey(oper, keyCode, modifiers);
62     }
63 
64     @Override
typeKey(ComponentOperator oper, int keyCode, char keyChar, int modifiers, Timeout pushTime)65     public void typeKey(ComponentOperator oper, int keyCode, char keyChar, int modifiers, Timeout pushTime) {
66         pushKey(oper, keyCode, modifiers, pushTime);
67     }
68 
69     /**
70      * Presses a key.
71      *
72      * @param oper Operator to press a key on.
73      * @param keyCode Key code ({@code KeyEventVK_*} field.
74      * @param modifiers a combination of {@code InputEvent.*_MASK} fields.
75      */
76     @Override
pressKey(ComponentOperator oper, int keyCode, int modifiers)77     public void pressKey(ComponentOperator oper, int keyCode, int modifiers) {
78         pressKey(keyCode, modifiers);
79     }
80 
81     @Override
typedKey(ComponentOperator oper, int keyCode, char keyChar, int modifiers)82     public void typedKey(ComponentOperator oper, int keyCode, char keyChar, int modifiers) {
83         releaseKey(oper, keyCode, modifiers);
84     }
85 
86     /**
87      * Releases a key.
88      *
89      * @param oper Operator to release a key on.
90      * @param keyCode Key code ({@code KeyEventVK_*} field.
91      * @param modifiers a combination of {@code InputEvent.*_MASK} fields.
92      */
93     @Override
releaseKey(ComponentOperator oper, int keyCode, int modifiers)94     public void releaseKey(ComponentOperator oper, int keyCode, int modifiers) {
95         releaseKey(keyCode, modifiers);
96     }
97 }
98