diff --git a/HMCL/src/main/java/com/jfoenix/controls/JFXSpinner.java b/HMCL/src/main/java/com/jfoenix/controls/JFXSpinner.java index 1118fb69b0..1b50c3cff9 100644 --- a/HMCL/src/main/java/com/jfoenix/controls/JFXSpinner.java +++ b/HMCL/src/main/java/com/jfoenix/controls/JFXSpinner.java @@ -31,6 +31,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.concurrent.ThreadLocalRandom; /// JFXSpinner is the material design implementation of a loading spinner. /// @@ -71,10 +72,10 @@ protected Skin createDefaultSkin() { /// this control. private static final String DEFAULT_STYLE_CLASS = "jfx-spinner"; - private static final double DEFAULT_RADIUS = 12.0; + private static final double DEFAULT_RADIUS = 16.0; /** - * specifies the radius of the spinner node, by default it's set to `12.0` + * specifies the radius of the spinner node, by default it's set to `16.0` */ private StyleableDoubleProperty radius; @@ -96,25 +97,8 @@ public final void setRadius(final double radius) { this.radiusProperty().set(radius); } - /// specifies from which angle the spinner should start spinning - private StyleableDoubleProperty startingAngle; - - public final StyleableDoubleProperty startingAngleProperty() { - if (this.startingAngle == null) { - startingAngle = new SimpleStyleableDoubleProperty(StyleableProperties.STARTING_ANGLE, - JFXSpinner.this, - "startingAngle", - 0.0); - } - return this.startingAngle; - } - - public final double getStartingAngle() { - return startingAngle != null ? startingAngle.get() : 0.0; - } - - public final void setStartingAngle(final double startingAngle) { - this.startingAngleProperty().set(startingAngle); + public double getStartingAngle() { + return 360 - ThreadLocalRandom.current().nextDouble() * 720; } private static final class StyleableProperties { @@ -132,26 +116,12 @@ public StyleableDoubleProperty getStyleableProperty(JFXSpinner control) { } }; - private static final CssMetaData STARTING_ANGLE = - new CssMetaData<>("-jfx-starting-angle", - SizeConverter.getInstance(), 0.0) { - @Override - public boolean isSettable(JFXSpinner control) { - return control.startingAngle == null || !control.startingAngle.isBound(); - } - - @Override - public StyleableDoubleProperty getStyleableProperty(JFXSpinner control) { - return control.startingAngleProperty(); - } - }; - private static final List> CHILD_STYLEABLES; static { final List> styleables = new ArrayList<>(ProgressIndicator.getClassCssMetaData()); - Collections.addAll(styleables, RADIUS, STARTING_ANGLE); + Collections.addAll(styleables, RADIUS); CHILD_STYLEABLES = List.copyOf(styleables); } } diff --git a/HMCL/src/main/java/com/jfoenix/skins/JFXSpinnerSkin.java b/HMCL/src/main/java/com/jfoenix/skins/JFXSpinnerSkin.java index 29b4e0df6b..b4eb4f96bc 100644 --- a/HMCL/src/main/java/com/jfoenix/skins/JFXSpinnerSkin.java +++ b/HMCL/src/main/java/com/jfoenix/skins/JFXSpinnerSkin.java @@ -20,7 +20,6 @@ package com.jfoenix.skins; import com.jfoenix.controls.JFXSpinner; -import com.jfoenix.utils.JFXNodeUtils; import com.jfoenix.utils.TreeShowingProperty; import javafx.animation.Interpolator; import javafx.animation.KeyFrame; @@ -36,8 +35,6 @@ import javafx.scene.shape.Arc; import javafx.scene.shape.Rectangle; import javafx.scene.shape.StrokeLineCap; -import javafx.scene.text.Font; -import javafx.scene.text.Text; import javafx.util.Duration; /// JFXSpinner material design skin @@ -47,6 +44,8 @@ /// @since 2017-09-25 public class JFXSpinnerSkin extends SkinBase { + private static final double DEFAULT_STROKE_WIDTH = 4; + private static final Color GREEN_COLOR = Color.valueOf("#0F9D58"); private static final Color RED_COLOR = Color.valueOf("#db4437"); private static final Color YELLOW_COLOR = Color.valueOf("#f4b400"); @@ -62,13 +61,15 @@ public class JFXSpinnerSkin extends SkinBase { private final StackPane arcPane; private final Rectangle fillRect; private double arcLength = -1; - private final Text text; + + private final double startingAngle; public JFXSpinnerSkin(JFXSpinner control) { super(control); this.control = control; this.treeShowingProperty = new TreeShowingProperty(control); + this.startingAngle = control.getStartingAngle(); arc = new Arc(); arc.setManaged(false); @@ -76,23 +77,20 @@ public JFXSpinnerSkin(JFXSpinner control) { arc.setLength(180); arc.getStyleClass().setAll("arc"); arc.setFill(Color.TRANSPARENT); - arc.setStrokeWidth(3); + arc.setStrokeWidth(DEFAULT_STROKE_WIDTH); arc.setStrokeLineCap(StrokeLineCap.ROUND); track = new Arc(); track.setManaged(false); track.setStartAngle(0); track.setLength(360); - track.setStrokeWidth(3); + track.setStrokeWidth(DEFAULT_STROKE_WIDTH); track.getStyleClass().setAll("track"); track.setFill(Color.TRANSPARENT); fillRect = new Rectangle(); fillRect.setFill(Color.TRANSPARENT); - text = new Text(); - text.setStyle("-fx-font-size:null"); - text.getStyleClass().setAll("text", "percentage"); - final Group group = new Group(fillRect, track, arc, text); + final Group group = new Group(fillRect, track, arc); group.setManaged(false); arcPane = new StackPane(group); arcPane.setPrefSize(50, 50); @@ -109,7 +107,7 @@ private void initialize() { if (getSkinnable().isIndeterminate()) { if (timeline == null) { createTransition(); - if (JFXNodeUtils.isTreeShowing(getSkinnable())) { + if (treeShowingProperty.get()) { timeline.play(); } } @@ -125,22 +123,22 @@ private KeyFrame[] getKeyFrames(double angle, double duration, Paint color) { frames[0] = new KeyFrame(Duration.seconds(duration), new KeyValue(arc.lengthProperty(), 5, Interpolator.LINEAR), new KeyValue(arc.startAngleProperty(), - angle + 45 + control.getStartingAngle(), + angle + 45 + startingAngle, Interpolator.LINEAR)); frames[1] = new KeyFrame(Duration.seconds(duration + 0.4), new KeyValue(arc.lengthProperty(), 250, Interpolator.LINEAR), new KeyValue(arc.startAngleProperty(), - angle + 90 + control.getStartingAngle(), + angle + 90 + startingAngle, Interpolator.LINEAR)); frames[2] = new KeyFrame(Duration.seconds(duration + 0.7), new KeyValue(arc.lengthProperty(), 250, Interpolator.LINEAR), new KeyValue(arc.startAngleProperty(), - angle + 135 + control.getStartingAngle(), + angle + 135 + startingAngle, Interpolator.LINEAR)); frames[3] = new KeyFrame(Duration.seconds(duration + 1.1), new KeyValue(arc.lengthProperty(), 5, Interpolator.LINEAR), new KeyValue(arc.startAngleProperty(), - angle + 435 + control.getStartingAngle(), + angle + 435 + startingAngle, Interpolator.LINEAR), new KeyValue(arc.strokeProperty(), color, Interpolator.EASE_BOTH)); return frames; @@ -230,14 +228,6 @@ protected void layoutChildren(double contentX, double contentY, double contentWi if (!getSkinnable().isIndeterminate()) { arc.setLength(arcLength); - if (text.isVisible()) { - final double progress = control.getProgress(); - int intProgress = (int) Math.round(progress * 100.0); - Font font = text.getFont(); - text.setFont(Font.font(font.getFamily(), radius / 1.7)); - text.setText((progress > 1 ? 100 : intProgress) + "%"); - text.relocate((arcSize - text.getLayoutBounds().getWidth()) / 2, (arcSize - text.getLayoutBounds().getHeight()) / 2); - } } } @@ -281,7 +271,7 @@ private void createTransition() { KeyFrame endingFrame = new KeyFrame(Duration.seconds(5.6), new KeyValue(arc.lengthProperty(), 5, Interpolator.LINEAR), new KeyValue(arc.startAngleProperty(), - 1845 + control.getStartingAngle(), + 1845 + startingAngle, Interpolator.LINEAR)); if (timeline != null) { diff --git a/HMCL/src/main/resources/assets/css/root.css b/HMCL/src/main/resources/assets/css/root.css index bd2c5bb2ca..c429f344cc 100644 --- a/HMCL/src/main/resources/assets/css/root.css +++ b/HMCL/src/main/resources/assets/css/root.css @@ -1452,20 +1452,8 @@ -fx-stroke: -monet-primary-container; } -.jfx-spinner:determinate .percentage { - -fx-fill: -monet-on-surface-variant; -} - -.first-spinner { - -jfx-radius: 20; -} - -.first-spinner .arc { - -fx-stroke-width: 5.0; -} - .small-spinner { - -jfx-radius: 10; + -jfx-radius: 9; } .small-spinner .arc { @@ -1473,59 +1461,7 @@ } .small-spinner-pane .jfx-spinner { - -jfx-radius: 10; -} - -.small-spinner-pane .jfx-spinner .arc { - -fx-stroke-width: 3.0; -} - -.second-spinner { - -jfx-radius: 30; -} - -.second-spinner .arc { - -fx-stroke-width: 5.0; -} - -.third-spinner { - -jfx-radius: 40; -} - -.third-spinner .arc { - -fx-stroke-width: 5.0; -} - -.fourth-spinner { - -jfx-radius: 50; -} - -.fourth-spinner .arc { - -fx-stroke-width: 5.0; -} - -.fifth-spinner { - -jfx-radius: 60; -} - -.fifth-spinner .arc { - -fx-stroke-width: 5.0; -} - -.sixth-spinner { - -jfx-radius: 70; -} - -.sixth-spinner .arc { - -fx-stroke-width: 5.0; -} - -.seventh-spinner { - -jfx-radius: 80; -} - -.seventh-spinner .arc { - -fx-stroke-width: 5.0; + -jfx-radius: 9; } /*******************************************************************************