Skip to content

Commit

Permalink
Add dynamic start angle functionality to CircleProgressIndicator
Browse files Browse the repository at this point in the history
The update made to the CircleProgressIndicator and CircleProgressIndicatorSkin allows the start angle of the progress arc to be dynamically changed. This is done by binding a new startAngle property to the existing progressArc's startAngle property. The start angle of the progress arc can be customized using the setStartAngle method, which will update the visually displayed progress.
  • Loading branch information
leewyatt committed May 21, 2024
1 parent 37c0ea3 commit a450904
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
26 changes: 26 additions & 0 deletions gemsfx/src/main/java/com/dlsc/gemsfx/CircleProgressIndicator.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.dlsc.gemsfx;

import com.dlsc.gemsfx.skins.CircleProgressIndicatorSkin;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.css.CssMetaData;
import javafx.css.Styleable;
Expand Down Expand Up @@ -55,6 +57,7 @@
public class CircleProgressIndicator extends ProgressIndicator {

private static final String DEFAULT_STYLE_CLASS = "circle-progress-indicator";
private static final double DEFAULT_START_ANGLE = 90.0;
private static final ArcType DEFAULT_ARC_TYPE = ArcType.OPEN;
private static final StringConverter<Double> DEFAULT_CONVERTER = new StringConverter<>() {
@Override
Expand Down Expand Up @@ -135,6 +138,29 @@ public final void setGraphic(Node graphic) {
graphicProperty().set(graphic);
}

private DoubleProperty startAngle;

/**
* The start angle property defines the starting angle of the arc that is used to display the progress.
* The default value is 90 degrees, which corresponds to the top of the circle.
*
* @return the start angle property
*/
public final DoubleProperty startAngleProperty() {
if (startAngle == null) {
startAngle = new SimpleDoubleProperty(this, "startAngle", DEFAULT_START_ANGLE);
}
return startAngle;
}

public final double getStartAngle() {
return startAngle == null ? DEFAULT_START_ANGLE : startAngle.get();
}

public final void setStartAngle(double startAngle) {
startAngleProperty().set(startAngle);
}

private ObjectProperty<ArcType> arcType;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public CircleProgressIndicatorSkin(CircleProgressIndicator control) {
// init the progress arc
progressArc.getStyleClass().add("progress-arc");
progressArc.setManaged(false);
progressArc.setStartAngle(90);
progressArc.startAngleProperty().bind(control.startAngleProperty());
progressArc.setLength(360);
progressArc.radiusXProperty().bind(radiusBinding);
progressArc.radiusYProperty().bind(radiusBinding);
Expand Down

0 comments on commit a450904

Please sign in to comment.