2020package com .jfoenix .skins ;
2121
2222import com .jfoenix .controls .JFXSpinner ;
23- import com .jfoenix .utils .JFXNodeUtils ;
2423import com .jfoenix .utils .TreeShowingProperty ;
2524import javafx .animation .Interpolator ;
2625import javafx .animation .KeyFrame ;
3635import javafx .scene .shape .Arc ;
3736import javafx .scene .shape .Rectangle ;
3837import javafx .scene .shape .StrokeLineCap ;
39- import javafx .scene .text .Font ;
40- import javafx .scene .text .Text ;
4138import javafx .util .Duration ;
4239
4340/// JFXSpinner material design skin
4744/// @since 2017-09-25
4845public class JFXSpinnerSkin extends SkinBase <JFXSpinner > {
4946
47+ private static final double DEFAULT_STROKE_WIDTH = 4 ;
48+
5049 private static final Color GREEN_COLOR = Color .valueOf ("#0F9D58" );
5150 private static final Color RED_COLOR = Color .valueOf ("#db4437" );
5251 private static final Color YELLOW_COLOR = Color .valueOf ("#f4b400" );
@@ -62,37 +61,36 @@ public class JFXSpinnerSkin extends SkinBase<JFXSpinner> {
6261 private final StackPane arcPane ;
6362 private final Rectangle fillRect ;
6463 private double arcLength = -1 ;
65- private final Text text ;
64+
65+ private final double startingAngle ;
6666
6767 public JFXSpinnerSkin (JFXSpinner control ) {
6868 super (control );
6969
7070 this .control = control ;
7171 this .treeShowingProperty = new TreeShowingProperty (control );
72+ this .startingAngle = control .getStartingAngle ();
7273
7374 arc = new Arc ();
7475 arc .setManaged (false );
7576 arc .setStartAngle (0 );
7677 arc .setLength (180 );
7778 arc .getStyleClass ().setAll ("arc" );
7879 arc .setFill (Color .TRANSPARENT );
79- arc .setStrokeWidth (3 );
80+ arc .setStrokeWidth (DEFAULT_STROKE_WIDTH );
8081 arc .setStrokeLineCap (StrokeLineCap .ROUND );
8182
8283 track = new Arc ();
8384 track .setManaged (false );
8485 track .setStartAngle (0 );
8586 track .setLength (360 );
86- track .setStrokeWidth (3 );
87+ track .setStrokeWidth (DEFAULT_STROKE_WIDTH );
8788 track .getStyleClass ().setAll ("track" );
8889 track .setFill (Color .TRANSPARENT );
8990
9091 fillRect = new Rectangle ();
9192 fillRect .setFill (Color .TRANSPARENT );
92- text = new Text ();
93- text .setStyle ("-fx-font-size:null" );
94- text .getStyleClass ().setAll ("text" , "percentage" );
95- final Group group = new Group (fillRect , track , arc , text );
93+ final Group group = new Group (fillRect , track , arc );
9694 group .setManaged (false );
9795 arcPane = new StackPane (group );
9896 arcPane .setPrefSize (50 , 50 );
@@ -109,7 +107,7 @@ private void initialize() {
109107 if (getSkinnable ().isIndeterminate ()) {
110108 if (timeline == null ) {
111109 createTransition ();
112- if (JFXNodeUtils . isTreeShowing ( getSkinnable () )) {
110+ if (treeShowingProperty . get ( )) {
113111 timeline .play ();
114112 }
115113 }
@@ -125,22 +123,22 @@ private KeyFrame[] getKeyFrames(double angle, double duration, Paint color) {
125123 frames [0 ] = new KeyFrame (Duration .seconds (duration ),
126124 new KeyValue (arc .lengthProperty (), 5 , Interpolator .LINEAR ),
127125 new KeyValue (arc .startAngleProperty (),
128- angle + 45 + control . getStartingAngle () ,
126+ angle + 45 + startingAngle ,
129127 Interpolator .LINEAR ));
130128 frames [1 ] = new KeyFrame (Duration .seconds (duration + 0.4 ),
131129 new KeyValue (arc .lengthProperty (), 250 , Interpolator .LINEAR ),
132130 new KeyValue (arc .startAngleProperty (),
133- angle + 90 + control . getStartingAngle () ,
131+ angle + 90 + startingAngle ,
134132 Interpolator .LINEAR ));
135133 frames [2 ] = new KeyFrame (Duration .seconds (duration + 0.7 ),
136134 new KeyValue (arc .lengthProperty (), 250 , Interpolator .LINEAR ),
137135 new KeyValue (arc .startAngleProperty (),
138- angle + 135 + control . getStartingAngle () ,
136+ angle + 135 + startingAngle ,
139137 Interpolator .LINEAR ));
140138 frames [3 ] = new KeyFrame (Duration .seconds (duration + 1.1 ),
141139 new KeyValue (arc .lengthProperty (), 5 , Interpolator .LINEAR ),
142140 new KeyValue (arc .startAngleProperty (),
143- angle + 435 + control . getStartingAngle () ,
141+ angle + 435 + startingAngle ,
144142 Interpolator .LINEAR ),
145143 new KeyValue (arc .strokeProperty (), color , Interpolator .EASE_BOTH ));
146144 return frames ;
@@ -230,14 +228,6 @@ protected void layoutChildren(double contentX, double contentY, double contentWi
230228
231229 if (!getSkinnable ().isIndeterminate ()) {
232230 arc .setLength (arcLength );
233- if (text .isVisible ()) {
234- final double progress = control .getProgress ();
235- int intProgress = (int ) Math .round (progress * 100.0 );
236- Font font = text .getFont ();
237- text .setFont (Font .font (font .getFamily (), radius / 1.7 ));
238- text .setText ((progress > 1 ? 100 : intProgress ) + "%" );
239- text .relocate ((arcSize - text .getLayoutBounds ().getWidth ()) / 2 , (arcSize - text .getLayoutBounds ().getHeight ()) / 2 );
240- }
241231 }
242232 }
243233
@@ -281,7 +271,7 @@ private void createTransition() {
281271 KeyFrame endingFrame = new KeyFrame (Duration .seconds (5.6 ),
282272 new KeyValue (arc .lengthProperty (), 5 , Interpolator .LINEAR ),
283273 new KeyValue (arc .startAngleProperty (),
284- 1845 + control . getStartingAngle () ,
274+ 1845 + startingAngle ,
285275 Interpolator .LINEAR ));
286276
287277 if (timeline != null ) {
0 commit comments