24
24
*/
25
25
package javafx .scene .control .skin ;
26
26
27
- import com .sun .javafx .scene .ParentHelper ;
28
- import com .sun .javafx .scene .traversal .Algorithm ;
29
- import com .sun .javafx .scene .control .FakeFocusTextField ;
30
- import com .sun .javafx .scene .traversal .Direction ;
31
- import com .sun .javafx .scene .traversal .ParentTraversalEngine ;
32
- import javafx .scene .control .Control ;
33
- import javafx .scene .control .SkinBase ;
34
- import com .sun .javafx .scene .control .behavior .SpinnerBehavior ;
35
- import com .sun .javafx .scene .traversal .TraversalContext ;
36
- import javafx .collections .ListChangeListener ;
27
+ import java .util .List ;
28
+
37
29
import javafx .css .PseudoClass ;
38
30
import javafx .geometry .HPos ;
39
31
import javafx .geometry .VPos ;
40
32
import javafx .scene .AccessibleAction ;
41
33
import javafx .scene .AccessibleRole ;
42
34
import javafx .scene .Node ;
35
+ import javafx .scene .control .Control ;
36
+ import javafx .scene .control .SkinBase ;
43
37
import javafx .scene .control .Spinner ;
44
38
import javafx .scene .control .TextField ;
45
39
import javafx .scene .input .KeyCode ;
46
40
import javafx .scene .input .KeyEvent ;
47
41
import javafx .scene .layout .Region ;
48
42
import javafx .scene .layout .StackPane ;
49
43
50
- import java .util .List ;
44
+ import com .sun .javafx .scene .ParentHelper ;
45
+ import com .sun .javafx .scene .control .FakeFocusTextField ;
46
+ import com .sun .javafx .scene .control .ListenerHelper ;
47
+ import com .sun .javafx .scene .control .behavior .SpinnerBehavior ;
48
+ import com .sun .javafx .scene .traversal .Algorithm ;
49
+ import com .sun .javafx .scene .traversal .Direction ;
50
+ import com .sun .javafx .scene .traversal .ParentTraversalEngine ;
51
+ import com .sun .javafx .scene .traversal .TraversalContext ;
51
52
52
53
/**
53
54
* Default skin implementation for the {@link Spinner} control.
@@ -80,11 +81,9 @@ public class SpinnerSkin<T> extends SkinBase<Spinner<T>> {
80
81
private static final int SPLIT_ARROWS_HORIZONTAL = 5 ;
81
82
82
83
private int layoutMode = 0 ;
83
-
84
84
private final SpinnerBehavior behavior ;
85
85
86
86
87
-
88
87
/* *************************************************************************
89
88
* *
90
89
* Constructors *
@@ -103,13 +102,15 @@ public SpinnerSkin(Spinner<T> control) {
103
102
104
103
// install default input map for the Button control
105
104
behavior = new SpinnerBehavior <>(control );
106
- // control.setInputMap(behavior.getInputMap());
107
105
108
106
textField = control .getEditor ();
109
- getChildren ().add (textField );
107
+
108
+ ListenerHelper lh = ListenerHelper .get (this );
110
109
111
110
updateStyleClass ();
112
- control .getStyleClass ().addListener ((ListChangeListener <String >) c -> updateStyleClass ());
111
+ lh .addListChangeListener (control .getStyleClass (), (ch ) -> {
112
+ updateStyleClass ();
113
+ });
113
114
114
115
// increment / decrement arrows
115
116
incrementArrow = new Region ();
@@ -169,12 +170,12 @@ public void executeAccessibleAction(AccessibleAction action, Object... parameter
169
170
// Fixes in the same vein as ComboBoxListViewSkin
170
171
171
172
// move fake focus in to the textfield if the spinner is editable
172
- control .focusedProperty (). addListener (( ov , t , hasFocus ) -> {
173
+ lh . addChangeListener ( control .focusedProperty (), ( op ) -> {
173
174
// Fix for the regression noted in a comment in RT-29885.
174
- ((FakeFocusTextField )textField ).setFakeFocus (hasFocus );
175
+ ((FakeFocusTextField )textField ).setFakeFocus (control . isFocused () );
175
176
});
176
177
177
- control .addEventFilter (KeyEvent .ANY , ke -> {
178
+ lh .addEventFilter (control , KeyEvent .ANY , ( ke ) -> {
178
179
if (control .isEditable ()) {
179
180
// This prevents a stack overflow from our rebroadcasting of the
180
181
// event to the textfield that occurs in the final else statement
@@ -204,14 +205,15 @@ public void executeAccessibleAction(AccessibleAction action, Object... parameter
204
205
// Spinner control. Without this the up/down/left/right arrow keys don't
205
206
// work when you click inside the TextField area (but they do in the case
206
207
// of tabbing in).
207
- textField .addEventFilter (KeyEvent .ANY , ke -> {
208
+ lh .addEventFilter (textField , KeyEvent .ANY , ( ke ) -> {
208
209
if (! control .isEditable () || isIncDecKeyEvent (ke )) {
209
210
control .fireEvent (ke .copyFor (control , control ));
210
211
ke .consume ();
211
212
}
212
213
});
213
214
214
- textField .focusedProperty ().addListener ((ov , t , hasFocus ) -> {
215
+ lh .addChangeListener (textField .focusedProperty (), (op ) -> {
216
+ boolean hasFocus = textField .isFocused ();
215
217
// Fix for RT-29885
216
218
control .getProperties ().put ("FOCUSED" , hasFocus );
217
219
// --- end of RT-29885
@@ -229,7 +231,6 @@ public void executeAccessibleAction(AccessibleAction action, Object... parameter
229
231
230
232
textField .focusTraversableProperty ().bind (control .editableProperty ());
231
233
232
-
233
234
// Following code borrowed from ComboBoxPopupControl, to resolve the
234
235
// issue initially identified in RT-36902, but specifically (for Spinner)
235
236
// identified in RT-40625
@@ -261,13 +262,27 @@ private boolean isIncDecKeyEvent(KeyEvent ke) {
261
262
* *
262
263
**************************************************************************/
263
264
265
+ @ Override
266
+ public void install () {
267
+ // when replacing the skin, the textField (which comes from the control), must first be uninstalled
268
+ // by the old skin in its dispose(), followed by (re-)adding it here.
269
+ getChildren ().add (textField );
270
+ }
271
+
264
272
/** {@inheritDoc} */
265
- @ Override public void dispose () {
266
- super .dispose ();
273
+ @ Override
274
+ public void dispose () {
275
+ if (getSkinnable () == null ) {
276
+ return ;
277
+ }
278
+
279
+ getChildren ().removeAll (textField , incrementArrowButton , decrementArrowButton );
267
280
268
281
if (behavior != null ) {
269
282
behavior .dispose ();
270
283
}
284
+
285
+ super .dispose ();
271
286
}
272
287
273
288
/** {@inheritDoc} */
0 commit comments