Skip to content
42 changes: 6 additions & 36 deletions HMCL/src/main/java/com/jfoenix/controls/JFXSpinner.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -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;

Expand All @@ -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 {
Comment on lines 102 to 104
Expand All @@ -132,26 +116,12 @@ public StyleableDoubleProperty getStyleableProperty(JFXSpinner control) {
}
};

private static final CssMetaData<JFXSpinner, Number> 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<CssMetaData<? extends Styleable, ?>> CHILD_STYLEABLES;

static {
final List<CssMetaData<? extends Styleable, ?>> styleables =
new ArrayList<>(ProgressIndicator.getClassCssMetaData());
Collections.addAll(styleables, RADIUS, STARTING_ANGLE);
Collections.addAll(styleables, RADIUS);
CHILD_STYLEABLES = List.copyOf(styleables);
}
}
Expand Down
38 changes: 14 additions & 24 deletions HMCL/src/main/java/com/jfoenix/skins/JFXSpinnerSkin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -47,6 +44,8 @@
/// @since 2017-09-25
public class JFXSpinnerSkin extends SkinBase<JFXSpinner> {

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");
Expand All @@ -62,37 +61,36 @@ public class JFXSpinnerSkin extends SkinBase<JFXSpinner> {
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);
arc.setStartAngle(0);
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);
Expand All @@ -109,7 +107,7 @@ private void initialize() {
if (getSkinnable().isIndeterminate()) {
if (timeline == null) {
createTransition();
if (JFXNodeUtils.isTreeShowing(getSkinnable())) {
if (treeShowingProperty.get()) {
timeline.play();
}
}
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}
}

Expand Down Expand Up @@ -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) {
Expand Down
68 changes: 2 additions & 66 deletions HMCL/src/main/resources/assets/css/root.css
Original file line number Diff line number Diff line change
Expand Up @@ -1452,80 +1452,16 @@
-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 {
-fx-stroke-width: 3.0;
}

.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;
}

/*******************************************************************************
Expand Down