KeyRobotDriver.java revision 13978:1993af50385d
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 */
23package org.netbeans.jemmy.drivers.input;
24
25import org.netbeans.jemmy.Timeout;
26import org.netbeans.jemmy.drivers.KeyDriver;
27import org.netbeans.jemmy.operators.ComponentOperator;
28
29/**
30 * KeyDriver using robot operations.
31 *
32 * @author Alexandre Iline(alexandre.iline@oracle.com)
33 */
34public class KeyRobotDriver extends RobotDriver implements KeyDriver {
35
36    /**
37     * Constructs a KeyRobotDriver object.
38     *
39     * @param autoDelay Time for {@code Robot.setAutoDelay(long)} method.
40     */
41    public KeyRobotDriver(Timeout autoDelay) {
42        super(autoDelay);
43    }
44
45    /**
46     * Constructs a KeyRobotDriver object.
47     *
48     * @param autoDelay Time for {@code Robot.setAutoDelay(long)} method.
49     * @param supported an array of supported class names
50     */
51    public KeyRobotDriver(Timeout autoDelay, String[] supported) {
52        super(autoDelay, supported);
53    }
54
55    @Override
56    public void pushKey(ComponentOperator oper, int keyCode, int modifiers, Timeout pushTime) {
57        pressKey(oper, keyCode, modifiers);
58        pushTime.sleep();
59        releaseKey(oper, keyCode, modifiers);
60    }
61
62    @Override
63    public void typeKey(ComponentOperator oper, int keyCode, char keyChar, int modifiers, Timeout pushTime) {
64        pushKey(oper, keyCode, modifiers, pushTime);
65    }
66
67    /**
68     * Presses a key.
69     *
70     * @param oper Operator to press a key on.
71     * @param keyCode Key code ({@code KeyEventVK_*} field.
72     * @param modifiers a combination of {@code InputEvent.*_MASK} fields.
73     */
74    @Override
75    public void pressKey(ComponentOperator oper, int keyCode, int modifiers) {
76        pressKey(keyCode, modifiers);
77    }
78
79    @Override
80    public void typedKey(ComponentOperator oper, int keyCode, char keyChar, int modifiers) {
81        releaseKey(oper, keyCode, modifiers);
82    }
83
84    /**
85     * Releases a key.
86     *
87     * @param oper Operator to release a key on.
88     * @param keyCode Key code ({@code KeyEventVK_*} field.
89     * @param modifiers a combination of {@code InputEvent.*_MASK} fields.
90     */
91    @Override
92    public void releaseKey(ComponentOperator oper, int keyCode, int modifiers) {
93        releaseKey(keyCode, modifiers);
94    }
95}
96