25
25
26
26
package javafx .scene .control .skin ;
27
27
28
- import com .sun .javafx .scene .NodeHelper ;
29
- import com .sun .javafx .scene .ParentHelper ;
30
- import com .sun .javafx .scene .control .Properties ;
31
- import com .sun .javafx .scene .control .behavior .BehaviorBase ;
32
- import com .sun .javafx .scene .traversal .ParentTraversalEngine ;
28
+ import static com .sun .javafx .scene .control .skin .Utils .boundedSize ;
29
+
33
30
import javafx .animation .Animation .Status ;
34
31
import javafx .animation .KeyFrame ;
35
32
import javafx .animation .KeyValue ;
46
43
import javafx .event .EventHandler ;
47
44
import javafx .geometry .BoundingBox ;
48
45
import javafx .geometry .Bounds ;
46
+ import javafx .geometry .Insets ;
49
47
import javafx .geometry .Orientation ;
50
48
import javafx .scene .AccessibleAttribute ;
51
49
import javafx .scene .Cursor ;
52
50
import javafx .scene .Node ;
53
- import javafx .scene .control .Button ;
54
51
import javafx .scene .control .Control ;
55
52
import javafx .scene .control .ScrollBar ;
56
53
import javafx .scene .control .ScrollPane ;
62
59
import javafx .scene .layout .StackPane ;
63
60
import javafx .scene .shape .Rectangle ;
64
61
import javafx .util .Duration ;
65
- import com .sun .javafx .util .Utils ;
66
- import com .sun .javafx .scene .control .behavior .ScrollPaneBehavior ;
67
- import static com .sun .javafx .scene .control .skin .Utils .*;
68
- import javafx .geometry .Insets ;
69
62
70
- import java .util .function .Consumer ;
63
+ import com .sun .javafx .scene .NodeHelper ;
64
+ import com .sun .javafx .scene .ParentHelper ;
65
+ import com .sun .javafx .scene .control .ListenerHelper ;
66
+ import com .sun .javafx .scene .control .Properties ;
67
+ import com .sun .javafx .scene .control .behavior .BehaviorBase ;
68
+ import com .sun .javafx .scene .control .behavior .ScrollPaneBehavior ;
69
+ import com .sun .javafx .scene .traversal .ParentTraversalEngine ;
70
+ import com .sun .javafx .util .Utils ;
71
71
72
72
/**
73
73
* Default skin implementation for the {@link ScrollPane} control.
@@ -265,16 +265,13 @@ public ScrollPaneSkin(final ScrollPane control) {
265
265
266
266
// install default input map for the ScrollPane control
267
267
behavior = new ScrollPaneBehavior (control );
268
- // control.setInputMap(behavior.getInputMap());
269
268
270
269
initialize ();
271
270
272
271
// Register listeners
273
- Consumer <ObservableValue <?>> viewportSizeHintConsumer = e -> {
274
- // change affects pref size, so requestLayout on control
275
- getSkinnable ().requestLayout ();
276
- };
277
- registerChangeListener (control .contentProperty (), e -> {
272
+ ListenerHelper lh = ListenerHelper .get (this );
273
+
274
+ lh .addChangeListener (control .contentProperty (), (ev ) -> {
278
275
if (scrollNode != getSkinnable ().getContent ()) {
279
276
if (scrollNode != null ) {
280
277
scrollNode .layoutBoundsProperty ().removeListener (weakNodeListener );
@@ -292,32 +289,35 @@ public ScrollPaneSkin(final ScrollPane control) {
292
289
}
293
290
getSkinnable ().requestLayout ();
294
291
});
295
- registerChangeListener (control .fitToWidthProperty (), e -> {
296
- getSkinnable ().requestLayout ();
297
- viewRect .requestLayout ();
298
- });
299
- registerChangeListener (control .fitToHeightProperty (), e -> {
300
- getSkinnable ().requestLayout ();
301
- viewRect .requestLayout ();
302
- });
303
- registerChangeListener (control .hbarPolicyProperty (), e -> {
304
- // change might affect pref size, so requestLayout on control
305
- getSkinnable ().requestLayout ();
306
- });
307
- registerChangeListener (control .vbarPolicyProperty (), e -> {
308
- // change might affect pref size, so requestLayout on control
309
- getSkinnable ().requestLayout ();
310
- });
311
- registerChangeListener (control .hvalueProperty (), e -> hsb .setValue (getSkinnable ().getHvalue ()));
312
- registerChangeListener (control .hmaxProperty (), e -> hsb .setMax (getSkinnable ().getHmax ()));
313
- registerChangeListener (control .hminProperty (), e -> hsb .setMin (getSkinnable ().getHmin ()));
314
- registerChangeListener (control .vvalueProperty (), e -> vsb .setValue (getSkinnable ().getVvalue ()));
315
- registerChangeListener (control .vmaxProperty (), e -> vsb .setMax (getSkinnable ().getVmax ()));
316
- registerChangeListener (control .vminProperty (), e -> vsb .setMin (getSkinnable ().getVmin ()));
317
- registerChangeListener (control .prefViewportWidthProperty (), viewportSizeHintConsumer );
318
- registerChangeListener (control .prefViewportHeightProperty (), viewportSizeHintConsumer );
319
- registerChangeListener (control .minViewportWidthProperty (), viewportSizeHintConsumer );
320
- registerChangeListener (control .minViewportHeightProperty (), viewportSizeHintConsumer );
292
+
293
+ lh .addChangeListener (
294
+ () -> {
295
+ getSkinnable ().requestLayout ();
296
+ viewRect .requestLayout ();
297
+ },
298
+ control .fitToWidthProperty (),
299
+ control .fitToHeightProperty ()
300
+ );
301
+
302
+ lh .addChangeListener (control .hvalueProperty (), e -> hsb .setValue (getSkinnable ().getHvalue ()));
303
+ lh .addChangeListener (control .hmaxProperty (), e -> hsb .setMax (getSkinnable ().getHmax ()));
304
+ lh .addChangeListener (control .hminProperty (), e -> hsb .setMin (getSkinnable ().getHmin ()));
305
+ lh .addChangeListener (control .vvalueProperty (), e -> vsb .setValue (getSkinnable ().getVvalue ()));
306
+ lh .addChangeListener (control .vmaxProperty (), e -> vsb .setMax (getSkinnable ().getVmax ()));
307
+ lh .addChangeListener (control .vminProperty (), e -> vsb .setMin (getSkinnable ().getVmin ()));
308
+
309
+ lh .addChangeListener (
310
+ () -> {
311
+ // change affects pref size, so requestLayout on control
312
+ getSkinnable ().requestLayout ();
313
+ },
314
+ control .hbarPolicyProperty (),
315
+ control .vbarPolicyProperty (),
316
+ control .prefViewportWidthProperty (),
317
+ control .prefViewportHeightProperty (),
318
+ control .minViewportWidthProperty (),
319
+ control .minViewportHeightProperty ()
320
+ );
321
321
}
322
322
323
323
@@ -387,12 +387,13 @@ public String getName() {
387
387
**************************************************************************/
388
388
389
389
/** {@inheritDoc} */
390
- @ Override public void dispose () {
391
- super .dispose ();
392
-
390
+ @ Override
391
+ public void dispose () {
393
392
if (behavior != null ) {
394
393
behavior .dispose ();
395
394
}
395
+
396
+ super .dispose ();
396
397
}
397
398
398
399
/**
@@ -666,8 +667,10 @@ private void initialize() {
666
667
}
667
668
};
668
669
669
- hsb .addEventFilter (MouseEvent .MOUSE_PRESSED , barHandler );
670
- vsb .addEventFilter (MouseEvent .MOUSE_PRESSED , barHandler );
670
+ ListenerHelper lh = ListenerHelper .get (this );
671
+
672
+ lh .addEventFilter (hsb , MouseEvent .MOUSE_PRESSED , barHandler );
673
+ lh .addEventFilter (vsb , MouseEvent .MOUSE_PRESSED , barHandler );
671
674
672
675
corner = new StackPane ();
673
676
corner .getStyleClass ().setAll ("corner" );
@@ -708,30 +711,27 @@ private void initialize() {
708
711
getChildren ().clear ();
709
712
getChildren ().addAll (viewRect , vsb , hsb , corner );
710
713
711
- /*
712
- ** listeners, and assorted housekeeping
713
- */
714
- InvalidationListener vsbListener = valueModel -> {
714
+ // listeners, and assorted housekeeping
715
+
716
+ lh .addInvalidationListener (vsb .valueProperty (), (valueModel ) -> {
715
717
if (!Properties .IS_TOUCH_SUPPORTED ) {
716
718
posY = Utils .clamp (getSkinnable ().getVmin (), vsb .getValue (), getSkinnable ().getVmax ());
717
719
}
718
720
else {
719
721
posY = vsb .getValue ();
720
722
}
721
723
updatePosY ();
722
- };
723
- vsb .valueProperty ().addListener (vsbListener );
724
+ });
724
725
725
- InvalidationListener hsbListener = valueModel -> {
726
+ lh . addInvalidationListener ( hsb . valueProperty (), ( valueModel ) -> {
726
727
if (!Properties .IS_TOUCH_SUPPORTED ) {
727
728
posX = Utils .clamp (getSkinnable ().getHmin (), hsb .getValue (), getSkinnable ().getHmax ());
728
729
}
729
730
else {
730
731
posX = hsb .getValue ();
731
732
}
732
733
updatePosX ();
733
- };
734
- hsb .valueProperty ().addListener (hsbListener );
734
+ });
735
735
736
736
viewRect .setOnMousePressed (e -> {
737
737
mouseDown = true ;
@@ -744,7 +744,6 @@ private void initialize() {
744
744
ovvalue = vsb .getValue ();
745
745
});
746
746
747
-
748
747
viewRect .setOnDragDetected (e -> {
749
748
if (Properties .IS_TOUCH_SUPPORTED ) {
750
749
startSBReleasedAnimation ();
@@ -782,6 +781,7 @@ posX > getSkinnable().getHmax() || posX < getSkinnable().getHmin()) && !touchDet
782
781
startContentsToViewport ();
783
782
}
784
783
});
784
+
785
785
viewRect .setOnMouseDragged (e -> {
786
786
if (Properties .IS_TOUCH_SUPPORTED ) {
787
787
startSBReleasedAnimation ();
@@ -843,7 +843,6 @@ else if (newVVal < vsb.getMin()) {
843
843
e .consume ();
844
844
});
845
845
846
-
847
846
/*
848
847
** don't allow the ScrollBar to handle the ScrollEvent,
849
848
** In a ScrollPane a vertical scroll should scroll on the vertical only,
@@ -953,13 +952,13 @@ else if (newVVal < vsb.getMin()) {
953
952
** there are certain animations that need to know if the touch is
954
953
** happening.....
955
954
*/
956
- getSkinnable () .addEventHandler (TouchEvent .TOUCH_PRESSED , e -> {
955
+ lh .addEventHandler (getSkinnable (), TouchEvent .TOUCH_PRESSED , e -> {
957
956
touchDetected = true ;
958
957
startSBReleasedAnimation ();
959
958
e .consume ();
960
959
});
961
960
962
- getSkinnable () .addEventHandler (TouchEvent .TOUCH_RELEASED , e -> {
961
+ lh .addEventHandler (getSkinnable (), TouchEvent .TOUCH_RELEASED , e -> {
963
962
touchDetected = false ;
964
963
e .consume ();
965
964
});
0 commit comments