< prev index next >

modules/graphics/src/main/java/javafx/scene/input/KeyEvent.java

Print this page
rev 9773 : 8156809: Remove obsolete com.sun.javafx.robot package
Reviewed-by:


  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 
  26 package javafx.scene.input;
  27 
  28 import com.sun.javafx.tk.Toolkit;
  29 import javafx.beans.NamedArg;
  30 import javafx.event.EventTarget;
  31 import javafx.event.EventType;
  32 
  33 import com.sun.javafx.robot.impl.FXRobotHelper;
  34 import com.sun.javafx.robot.impl.FXRobotHelper.FXRobotInputAccessor;
  35 import com.sun.javafx.scene.input.KeyCodeMap;
  36 import javafx.event.Event;
  37 import javafx.scene.input.ScrollEvent.HorizontalTextScrollUnits;
  38 import javafx.scene.input.ScrollEvent.VerticalTextScrollUnits;
  39 
  40 /**
  41  * An event which indicates that a keystroke occurred in a {@link javafx.scene.Node}.
  42  * <p>
  43  * This event is generated when a key is pressed, released, or typed.
  44  * Depending on the type of the event it is passed
  45  * to {@link javafx.scene.Node#onKeyPressedProperty onKeyPressed}, {@link javafx.scene.Node#onKeyTypedProperty onKeyTyped}
  46  * or {@link javafx.scene.Node#onKeyReleasedProperty onKeyReleased} function.
  47  *
  48  * <p>
  49  * <em>"Key typed" events</em> are higher-level and generally do not depend on
  50  * the platform or keyboard layout.  They are generated when a Unicode character
  51  * is entered, and are the preferred way to find out about character input.
  52  * In the simplest case, a key typed event is produced by a single key press
  53  * (e.g., 'a').  Often, however, characters are produced by series of key
  54  * presses (e.g., SHIFT + 'a'), and the mapping from key pressed events to


  96     /**
  97      * This event occurs when a key has been pressed.
  98      */
  99     public static final EventType<KeyEvent> KEY_PRESSED =
 100             new EventType<KeyEvent>(KeyEvent.ANY, "KEY_PRESSED");
 101 
 102     /**
 103      * This event occurs when a key has been released.
 104      */
 105     public static final EventType<KeyEvent> KEY_RELEASED =
 106             new EventType<KeyEvent>(KeyEvent.ANY, "KEY_RELEASED");
 107 
 108     /**
 109      * This event occurs when a character-generating key was typed
 110      * (pressed and released).  The event contains the {@code character}
 111      * field containing the typed string, the {@code code} and {@code text}
 112      * fields are not used.
 113      */
 114     public static final EventType<KeyEvent> KEY_TYPED =
 115             new EventType<KeyEvent>(KeyEvent.ANY, "KEY_TYPED");
 116 
 117     static {
 118         FXRobotInputAccessor a = new FXRobotInputAccessor() {
 119             @Override public int getCodeForKeyCode(KeyCode keyCode) {
 120                 return keyCode.code;
 121             }
 122             @Override public KeyCode getKeyCodeForCode(int code) {
 123                 return KeyCodeMap.valueOf(code);
 124             }
 125             @Override public KeyEvent createKeyEvent(
 126                 EventType<? extends KeyEvent> eventType,
 127                 KeyCode code, String character, String text,
 128                 boolean shiftDown, boolean controlDown,
 129                 boolean altDown, boolean metaDown)
 130             {
 131                 return new KeyEvent((EventType<KeyEvent>)eventType, character, text, code,
 132                         shiftDown, controlDown, altDown, metaDown);
 133             }
 134             @Override public MouseEvent createMouseEvent(
 135                 EventType<? extends MouseEvent> eventType,
 136                 int x, int y, int screenX, int screenY,
 137                 MouseButton button, int clickCount, boolean shiftDown,
 138                 boolean controlDown, boolean altDown, boolean metaDown,
 139                 boolean popupTrigger, boolean primaryButtonDown,
 140                 boolean middleButtonDown, boolean secondaryButtonDown)
 141             {
 142                 return new MouseEvent(eventType, x, y,
 143                                            screenX, screenY,
 144                                            button, clickCount,
 145                                            shiftDown,
 146                                            controlDown,
 147                                            altDown,
 148                                            metaDown,
 149                                            primaryButtonDown,
 150                                            middleButtonDown,
 151                                            secondaryButtonDown,
 152                                            false,
 153                                            popupTrigger,
 154                                            false,
 155                                            null
 156                                            );
 157             }
 158 
 159             @Override
 160             public ScrollEvent createScrollEvent(
 161                     EventType<? extends ScrollEvent> eventType,
 162                     int scrollX, int scrollY,
 163                     HorizontalTextScrollUnits xTextUnits, int xText,
 164                     VerticalTextScrollUnits yTextUnits, int yText,
 165                     int x, int y, int screenX, int screenY,
 166                     boolean shiftDown, boolean controlDown,
 167                     boolean altDown, boolean metaDown) {
 168                 return new ScrollEvent(ScrollEvent.SCROLL,
 169                         x, y, screenX, screenY,
 170                         shiftDown, controlDown, altDown, metaDown, false, false,
 171                         scrollX, scrollY, 0, 0,
 172                         xTextUnits, xText, yTextUnits, yText,
 173                         0, null);
 174             }
 175         };
 176         FXRobotHelper.setInputAccessor(a);
 177     }
 178 
 179     /**
 180      * Constructs new KeyEvent event with null source and target and KeyCode object directly specified.
 181      * @param source the source of the event. Can be null.
 182      * @param target the target of the event. Can be null.
 183      * @param eventType The type of the event.
 184      * @param character The character or sequence of characters associated with the event
 185      * @param text A String describing the key code
 186      * @param code The integer key code
 187      * @param shiftDown true if shift modifier was pressed.
 188      * @param controlDown true if control modifier was pressed.
 189      * @param altDown true if alt modifier was pressed.
 190      * @param metaDown true if meta modifier was pressed.
 191      * @since JavaFX 8.0
 192      */
 193     public KeyEvent(@NamedArg("source") Object source, @NamedArg("target") EventTarget target, @NamedArg("eventType") EventType<KeyEvent> eventType, @NamedArg("character") String character,
 194             @NamedArg("text") String text, @NamedArg("code") KeyCode code, @NamedArg("shiftDown") boolean shiftDown, @NamedArg("controlDown") boolean controlDown,
 195             @NamedArg("altDown") boolean altDown, @NamedArg("metaDown") boolean metaDown) {
 196         super(source, target, eventType);
 197         boolean isKeyTyped = eventType == KEY_TYPED;




  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 
  26 package javafx.scene.input;
  27 
  28 import com.sun.javafx.tk.Toolkit;
  29 import javafx.beans.NamedArg;
  30 import javafx.event.EventTarget;
  31 import javafx.event.EventType;
  32 


  33 import com.sun.javafx.scene.input.KeyCodeMap;
  34 import javafx.event.Event;
  35 import javafx.scene.input.ScrollEvent.HorizontalTextScrollUnits;
  36 import javafx.scene.input.ScrollEvent.VerticalTextScrollUnits;
  37 
  38 /**
  39  * An event which indicates that a keystroke occurred in a {@link javafx.scene.Node}.
  40  * <p>
  41  * This event is generated when a key is pressed, released, or typed.
  42  * Depending on the type of the event it is passed
  43  * to {@link javafx.scene.Node#onKeyPressedProperty onKeyPressed}, {@link javafx.scene.Node#onKeyTypedProperty onKeyTyped}
  44  * or {@link javafx.scene.Node#onKeyReleasedProperty onKeyReleased} function.
  45  *
  46  * <p>
  47  * <em>"Key typed" events</em> are higher-level and generally do not depend on
  48  * the platform or keyboard layout.  They are generated when a Unicode character
  49  * is entered, and are the preferred way to find out about character input.
  50  * In the simplest case, a key typed event is produced by a single key press
  51  * (e.g., 'a').  Often, however, characters are produced by series of key
  52  * presses (e.g., SHIFT + 'a'), and the mapping from key pressed events to


  94     /**
  95      * This event occurs when a key has been pressed.
  96      */
  97     public static final EventType<KeyEvent> KEY_PRESSED =
  98             new EventType<KeyEvent>(KeyEvent.ANY, "KEY_PRESSED");
  99 
 100     /**
 101      * This event occurs when a key has been released.
 102      */
 103     public static final EventType<KeyEvent> KEY_RELEASED =
 104             new EventType<KeyEvent>(KeyEvent.ANY, "KEY_RELEASED");
 105 
 106     /**
 107      * This event occurs when a character-generating key was typed
 108      * (pressed and released).  The event contains the {@code character}
 109      * field containing the typed string, the {@code code} and {@code text}
 110      * fields are not used.
 111      */
 112     public static final EventType<KeyEvent> KEY_TYPED =
 113             new EventType<KeyEvent>(KeyEvent.ANY, "KEY_TYPED");






























































 114 
 115     /**
 116      * Constructs new KeyEvent event with null source and target and KeyCode object directly specified.
 117      * @param source the source of the event. Can be null.
 118      * @param target the target of the event. Can be null.
 119      * @param eventType The type of the event.
 120      * @param character The character or sequence of characters associated with the event
 121      * @param text A String describing the key code
 122      * @param code The integer key code
 123      * @param shiftDown true if shift modifier was pressed.
 124      * @param controlDown true if control modifier was pressed.
 125      * @param altDown true if alt modifier was pressed.
 126      * @param metaDown true if meta modifier was pressed.
 127      * @since JavaFX 8.0
 128      */
 129     public KeyEvent(@NamedArg("source") Object source, @NamedArg("target") EventTarget target, @NamedArg("eventType") EventType<KeyEvent> eventType, @NamedArg("character") String character,
 130             @NamedArg("text") String text, @NamedArg("code") KeyCode code, @NamedArg("shiftDown") boolean shiftDown, @NamedArg("controlDown") boolean controlDown,
 131             @NamedArg("altDown") boolean altDown, @NamedArg("metaDown") boolean metaDown) {
 132         super(source, target, eventType);
 133         boolean isKeyTyped = eventType == KEY_TYPED;


< prev index next >