1 /*
2 * Copyright (c) 2014, 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
172 // move fake focus in to the textfield if the spinner is editable
173 control.focusedProperty().addListener((ov, t, hasFocus) -> {
174 // Fix for the regression noted in a comment in RT-29885.
175 ((FakeFocusTextField)textField).setFakeFocus(hasFocus);
176 });
177
178 control.addEventFilter(KeyEvent.ANY, ke -> {
179 if (control.isEditable()) {
180 // This prevents a stack overflow from our rebroadcasting of the
181 // event to the textfield that occurs in the final else statement
182 // of the conditions below.
183 if (ke.getTarget().equals(textField)) return;
184
185 // Fix for RT-38527 which led to a stack overflow
186 if (ke.getCode() == KeyCode.ESCAPE) return;
187
188 // Fix for the regression noted in a comment in RT-29885.
189 // This forwards the event down into the TextField when
190 // the key event is actually received by the Spinner.
191 textField.fireEvent(ke.copyFor(textField, textField));
192 ke.consume();
193 }
194 });
195
196 // This event filter is to enable keyboard events being delivered to the
197 // spinner when the user has mouse clicked into the TextField area of the
198 // Spinner control. Without this the up/down/left/right arrow keys don't
199 // work when you click inside the TextField area (but they do in the case
200 // of tabbing in).
201 textField.addEventFilter(KeyEvent.ANY, ke -> {
202 if (! control.isEditable()) {
203 control.fireEvent(ke.copyFor(control, control));
204 ke.consume();
205 }
206 });
207
208 textField.focusedProperty().addListener((ov, t, hasFocus) -> {
209 // Fix for RT-29885
210 control.getProperties().put("FOCUSED", hasFocus);
211 // --- end of RT-29885
|
1 /*
2 * Copyright (c) 2014, 2018, 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
172 // move fake focus in to the textfield if the spinner is editable
173 control.focusedProperty().addListener((ov, t, hasFocus) -> {
174 // Fix for the regression noted in a comment in RT-29885.
175 ((FakeFocusTextField)textField).setFakeFocus(hasFocus);
176 });
177
178 control.addEventFilter(KeyEvent.ANY, ke -> {
179 if (control.isEditable()) {
180 // This prevents a stack overflow from our rebroadcasting of the
181 // event to the textfield that occurs in the final else statement
182 // of the conditions below.
183 if (ke.getTarget().equals(textField)) return;
184
185 // Fix for RT-38527 which led to a stack overflow
186 if (ke.getCode() == KeyCode.ESCAPE) return;
187
188 // Fix for the regression noted in a comment in RT-29885.
189 // This forwards the event down into the TextField when
190 // the key event is actually received by the Spinner.
191 textField.fireEvent(ke.copyFor(textField, textField));
192
193 if (ke.getCode() == KeyCode.ENTER) return;
194
195 ke.consume();
196 }
197 });
198
199 // This event filter is to enable keyboard events being delivered to the
200 // spinner when the user has mouse clicked into the TextField area of the
201 // Spinner control. Without this the up/down/left/right arrow keys don't
202 // work when you click inside the TextField area (but they do in the case
203 // of tabbing in).
204 textField.addEventFilter(KeyEvent.ANY, ke -> {
205 if (! control.isEditable()) {
206 control.fireEvent(ke.copyFor(control, control));
207 ke.consume();
208 }
209 });
210
211 textField.focusedProperty().addListener((ov, t, hasFocus) -> {
212 // Fix for RT-29885
213 control.getProperties().put("FOCUSED", hasFocus);
214 // --- end of RT-29885
|