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;
134
135 this.character = isKeyTyped ? character : KeyEvent.CHAR_UNDEFINED;
136 this.text = isKeyTyped ? "" : text;
137 this.code = isKeyTyped ? KeyCode.UNDEFINED : code;
138 this.shiftDown = shiftDown;
139 this.controlDown = controlDown;
140 this.altDown = altDown;
141 this.metaDown = metaDown;
142 }
143
144 /**
145 * Constructs new KeyEvent event with null source and target and KeyCode object directly specified.
146 * @param eventType The type of the event.
147 * @param character The character or sequence of characters associated with the event
148 * @param text A String describing the key code
149 * @param code The integer key code
150 * @param shiftDown true if shift modifier was pressed.
151 * @param controlDown true if control modifier was pressed.
152 * @param altDown true if alt modifier was pressed.
153 * @param metaDown true if meta modifier was pressed.
154 * @since JavaFX 8.0
155 */
156 public KeyEvent(@NamedArg("eventType") EventType<KeyEvent> eventType, @NamedArg("character") String character,
157 @NamedArg("text") String text, @NamedArg("code") KeyCode code, @NamedArg("shiftDown") boolean shiftDown, @NamedArg("controlDown") boolean controlDown,
158 @NamedArg("altDown") boolean altDown, @NamedArg("metaDown") boolean metaDown) {
159 super(eventType);
160 boolean isKeyTyped = eventType == KEY_TYPED;
161
162 this.character = isKeyTyped ? character : KeyEvent.CHAR_UNDEFINED;
163 this.text = isKeyTyped ? "" : text;
164 this.code = isKeyTyped ? KeyCode.UNDEFINED : code;
165 this.shiftDown = shiftDown;
|
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 a new {@code KeyEvent} event from the specified parameters.
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;
134
135 this.character = isKeyTyped ? character : KeyEvent.CHAR_UNDEFINED;
136 this.text = isKeyTyped ? "" : text;
137 this.code = isKeyTyped ? KeyCode.UNDEFINED : code;
138 this.shiftDown = shiftDown;
139 this.controlDown = controlDown;
140 this.altDown = altDown;
141 this.metaDown = metaDown;
142 }
143
144 /**
145 * Constructs a new {@code KeyEvent} event from the specified parameters,
146 * with a {@code null} source and target.
147 * @param eventType The type of the event.
148 * @param character The character or sequence of characters associated with the event
149 * @param text A String describing the key code
150 * @param code The integer key code
151 * @param shiftDown true if shift modifier was pressed.
152 * @param controlDown true if control modifier was pressed.
153 * @param altDown true if alt modifier was pressed.
154 * @param metaDown true if meta modifier was pressed.
155 * @since JavaFX 8.0
156 */
157 public KeyEvent(@NamedArg("eventType") EventType<KeyEvent> eventType, @NamedArg("character") String character,
158 @NamedArg("text") String text, @NamedArg("code") KeyCode code, @NamedArg("shiftDown") boolean shiftDown, @NamedArg("controlDown") boolean controlDown,
159 @NamedArg("altDown") boolean altDown, @NamedArg("metaDown") boolean metaDown) {
160 super(eventType);
161 boolean isKeyTyped = eventType == KEY_TYPED;
162
163 this.character = isKeyTyped ? character : KeyEvent.CHAR_UNDEFINED;
164 this.text = isKeyTyped ? "" : text;
165 this.code = isKeyTyped ? KeyCode.UNDEFINED : code;
166 this.shiftDown = shiftDown;
|