@Override public void start(final Stage stage) throws Exception { StackPane pane = new StackPane(); JFXSpinner root = new JFXSpinner(); pane.getChildren().add(root); final Scene scene = new Scene(pane, 300, 300); scene.getStylesheets().add(MainDemo.class.getResource("/css/jfoenix-components.css").toExternalForm()); stage.setScene(scene); stage.setTitle("JFX Spinner Demo"); stage.show(); }
@Override public List<CssMetaData<? extends Styleable, ?>> getControlCssMetaData() { return getClassCssMetaData(); }
@Override protected double computeMaxHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) { if (Region.USE_COMPUTED_SIZE == control.getRadius()) { return super.computeMaxHeight(width, topInset, rightInset, bottomInset, leftInset); } else { return control.getRadius() * 2 + arc.getStrokeWidth() * 2; } }
private void initialize() { if (getSkinnable().isIndeterminate()) { if (timeline == null) { createTransition(); if (getSkinnable().impl_isTreeVisible()) { timeline.play(); } } } else { clearAnimation(); arc.setStartAngle(90); updateProgress(); } }
registerChangeListener(control.indeterminateProperty(), "INDETERMINATE"); registerChangeListener(control.progressProperty(), "PROGRESS"); registerChangeListener(control.visibleProperty(), "VISIBLE"); registerChangeListener(control.parentProperty(), "PARENT"); registerChangeListener(control.sceneProperty(), "SCENE");
/** * {@inheritDoc} */ @Override protected void layoutChildren(double contentX, double contentY, double contentWidth, double contentHeight) { final double strokeWidth = arc.getStrokeWidth(); final double radius = Math.min(contentWidth, contentHeight) / 2 - strokeWidth / 2; final double arcSize = snapSize(radius * 2 + strokeWidth); arcPane.resizeRelocate((contentWidth - arcSize) / 2 + 1, (contentHeight - arcSize) / 2 + 1, arcSize, arcSize); updateArcLayout(radius, arcSize); fillRect.setWidth(arcSize); fillRect.setHeight(arcSize); if (!isValid) { initialize(); isValid = true; } 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); } } }
private void createTransition() { if(!getSkinnable().isIndeterminate()) return; final Paint initialColor = arc.getStroke(); if (initialColor == null) { new KeyValue(arc.lengthProperty(), 5, Interpolator.LINEAR), new KeyValue(arc.startAngleProperty(), 1845 + control.getStartingAngle(), Interpolator.LINEAR));
@PostConstruct public void init() { Timeline timeline = new Timeline( new KeyFrame( Duration.ZERO, new KeyValue(blueSpinner.progressProperty(), 0), new KeyValue(greenSpinner.progressProperty(), 0) ), new KeyFrame( Duration.seconds(0.5), new KeyValue(greenSpinner.progressProperty(), 0.5) ), new KeyFrame( Duration.seconds(2), new KeyValue(blueSpinner.progressProperty(), 1), new KeyValue(greenSpinner.progressProperty(), 1) ) ); timeline.setCycleCount(Timeline.INDEFINITE); timeline.play(); }
private void pauseTimeline(boolean pause) { if (getSkinnable().isIndeterminate()) { if (timeline == null) { createTransition(); } if (pause) { timeline.pause(); } else { timeline.play(); } } }
/** * Generates a processing indicator */ public static Node getProcessingIndicator() { final StackPane pane = new StackPane(); final JFXSpinner indicator = new JFXSpinner(); indicator.setStyle("-fx-max-width:16;-fx-max-height:16;"); pane.getChildren().add(indicator); pane.setAlignment(Pos.CENTER); NodeHelper.setHgrow(pane); return pane; }
public JFXSpinner(double progress) { super(progress); init(); }
private void init(){ getStyleClass().add(DEFAULT_STYLE_CLASS); }
private KeyFrame[] getKeyFrames(double angle, double duration, Paint color) { KeyFrame[] frames = new KeyFrame[4]; frames[0] = new KeyFrame(Duration.seconds(duration), new KeyValue(arc.lengthProperty(), 5, Interpolator.LINEAR), new KeyValue(arc.startAngleProperty(), angle + 45 + control.getStartingAngle(), 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(), 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(), 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(), Interpolator.LINEAR), new KeyValue(arc.strokeProperty(), color, Interpolator.EASE_BOTH)); return frames; }
registerChangeListener(control.indeterminateProperty(), obs -> initialize()); registerChangeListener(control.progressProperty(), obs -> updateProgress()); registerChangeListener(control.visibleProperty(), obs->updateAnimation()); registerChangeListener(control.parentProperty(), obs->updateAnimation()); registerChangeListener(control.sceneProperty(), obs->updateAnimation());
/** * {@inheritDoc} */ @Override protected void layoutChildren(double contentX, double contentY, double contentWidth, double contentHeight) { final double strokeWidth = arc.getStrokeWidth(); final double radius = Math.min(contentWidth, contentHeight) / 2 - strokeWidth / 2; final double arcSize = snapSize(radius * 2 + strokeWidth); arcPane.resizeRelocate((contentWidth - arcSize) / 2 + 1, (contentHeight - arcSize) / 2 + 1, arcSize, arcSize); updateArcLayout(radius, arcSize); fillRect.setWidth(arcSize); fillRect.setHeight(arcSize); if (!isValid) { initialize(); isValid = true; } 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); } } }
private void createTransition() { if(!getSkinnable().isIndeterminate()) return; final Paint initialColor = arc.getStroke(); if (initialColor == null) { new KeyValue(arc.lengthProperty(), 5, Interpolator.LINEAR), new KeyValue(arc.startAngleProperty(), 1845 + control.getStartingAngle(), Interpolator.LINEAR));
private void pauseTimeline(boolean pause) { if (getSkinnable().isIndeterminate()) { if (timeline == null) { createTransition(); } if (pause) { timeline.pause(); } else { timeline.play(); } } }
public JFXSpinner(double progress) { super(progress); init(); }
private void init(){ getStyleClass().add(DEFAULT_STYLE_CLASS); }
private KeyFrame[] getKeyFrames(double angle, double duration, Paint color) { KeyFrame[] frames = new KeyFrame[4]; frames[0] = new KeyFrame(Duration.seconds(duration), new KeyValue(arc.lengthProperty(), 5, Interpolator.LINEAR), new KeyValue(arc.startAngleProperty(), angle + 45 + control.getStartingAngle(), 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(), 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(), 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(), Interpolator.LINEAR), new KeyValue(arc.strokeProperty(), color, Interpolator.EASE_BOTH)); return frames; }