@SuppressWarnings("deprecation") private void initialize() { ConfidenceProgressIndicator control = getSkinnable(); boolean isIndeterminate = control.isIndeterminate(); if (isIndeterminate) { // clean up determinateIndicator determinateIndicator = null; // create spinner spinner = new IndeterminateSpinner(control, this, spinEnabled.get(), progressColor.get()); getChildren().clear(); getChildren().add(spinner); if (getSkinnable().impl_isTreeVisible()) {} } else { // clean up after spinner if (spinner != null) { spinner = null; } // create determinateIndicator determinateIndicator = new ConfidenceProgressIndicatorSkin.DeterminateIndicator( control, this, progressColor.get()); getChildren().clear(); getChildren().add(determinateIndicator); } }
private void updateProgress() { intProgress = (int) Math.round(control.getProgress() * 100.0); // text.setText((control.getProgress() >= 1) ? (DONE) : ("" + intProgress + "%")); degProgress = (int) (360 * control.getProgress()); arcShape.setLength(-degProgress); indicator.setOpacity(control.getProgress() == 0 ? 0 : 1); requestLayout(); }
@Override public boolean isSettable(ConfidenceProgressIndicator n) { final ConfidenceProgressIndicatorSkin skin = (ConfidenceProgressIndicatorSkin) n.getSkin(); return skin.indeterminateSegmentCount == null || !skin.indeterminateSegmentCount.isBound(); }
@Override protected void layoutChildren() { Insets controlInsets = control.getInsets(); final double w = control.getWidth() - controlInsets.getLeft() - controlInsets.getRight(); final double h = control.getHeight() - controlInsets.getTop() - controlInsets.getBottom(); final double prefW = pathsG.prefWidth(-1); final double prefH = pathsG.prefHeight(-1); double scaleX = w / prefW; double scale = scaleX; if ((scaleX * prefH) > h) { scale = h / prefH; } double indicatorW = prefW * scale - 3; double indicatorH = prefH * scale - 3; pathsG.resizeRelocate((w - indicatorW) / 2, (h - indicatorH) / 2, indicatorW, indicatorH); }
@Override protected double computePrefHeight(double width) { final Insets controlInsets = control.getInsets(); final double top = snapSize(controlInsets.getTop()); final double bottom = snapSize(controlInsets.getBottom()); final Insets indicatorInsets = indicator.getInsets(); final double iLeft = snapSize(indicatorInsets.getLeft()); final double iRight = snapSize(indicatorInsets.getRight()); final double iTop = snapSize(indicatorInsets.getTop()); final double iBottom = snapSize(indicatorInsets.getBottom()); final double indicatorMax = snapSize(Math.max(Math.max(iLeft, iRight), Math.max(iTop, iBottom))); final Insets progressInsets = progress.getInsets(); final double pLeft = snapSize(progressInsets.getLeft()); final double pRight = snapSize(progressInsets.getRight()); final double pTop = snapSize(progressInsets.getTop()); final double pBottom = snapSize(progressInsets.getBottom()); final double progressMax = snapSize(Math.max(Math.max(pLeft, pRight), Math.max(pTop, pBottom))); final Insets tickInsets = tick.getInsets(); final double tTop = snapSize(tickInsets.getTop()); final double tBottom = snapSize(tickInsets.getBottom()); final double indicatorHeight = indicatorMax + progressMax + tTop + tBottom + progressMax + indicatorMax; return top + indicatorHeight /*+ textGap + doneText.getLayoutBounds().getHeight()*/ + bottom; }
@Override protected double computePrefWidth(double height) { final Insets controlInsets = control.getInsets(); final double left = snapSize(controlInsets.getLeft()); final double right = snapSize(controlInsets.getRight()); final Insets indicatorInsets = indicator.getInsets(); final double iLeft = snapSize(indicatorInsets.getLeft()); final double iRight = snapSize(indicatorInsets.getRight()); final double iTop = snapSize(indicatorInsets.getTop()); final double iBottom = snapSize(indicatorInsets.getBottom()); final double indicatorMax = snapSize(Math.max(Math.max(iLeft, iRight), Math.max(iTop, iBottom))); final Insets progressInsets = progress.getInsets(); final double pLeft = snapSize(progressInsets.getLeft()); final double pRight = snapSize(progressInsets.getRight()); final double pTop = snapSize(progressInsets.getTop()); final double pBottom = snapSize(progressInsets.getBottom()); final double progressMax = snapSize(Math.max(Math.max(pLeft, pRight), Math.max(pTop, pBottom))); final Insets tickInsets = tick.getInsets(); final double tLeft = snapSize(tickInsets.getLeft()); final double tRight = snapSize(tickInsets.getRight()); final double indicatorWidth = indicatorMax + progressMax + tLeft + tRight + progressMax + indicatorMax; return left + indicatorWidth + /*Math.max(indicatorWidth, doneText.getLayoutBounds().getWidth()) + */ right; }
public DeterminateIndicator( ConfidenceProgressIndicator control, ConfidenceProgressIndicatorSkin s, Paint fillOverride) { this.control = control; getStyleClass().add("determinate-indicator"); intProgress = (int) Math.round(control.getProgress() * 100.0); degProgress = (int) (360 * control.getProgress()); InvalidationListener progressListener = valueModel -> updateProgress(); control.progressProperty().addListener(progressListener); getChildren().clear(); // The circular background for the progress pie piece indicator = new StackPane(); indicator.setScaleShape(false); indicator.setCenterShape(false); indicator.getStyleClass().setAll("indicator"); indicatorCircle = new Circle(); indicator.setShape(indicatorCircle); // The shape for our progress pie piece arcShape = new Arc(); arcShape.setType(ArcType.ROUND); arcShape.setStartAngle(90.0F); // Our progress pie piece progress = new StackPane(); progress.getStyleClass().setAll("progress"); progress.setScaleShape(false); progress.setCenterShape(false); progress.setShape(arcShape); progress.getChildren().clear(); setFillOverride(fillOverride); // The check mark that's drawn at 100% tick = new StackPane(); tick.getStyleClass().setAll("tick"); getChildren().setAll(indicator, progress, /*text,*/ tick); updateProgress(); }
@Override public StyleableProperty<Boolean> getStyleableProperty(ConfidenceProgressIndicator node) { final ConfidenceProgressIndicatorSkin skin = (ConfidenceProgressIndicatorSkin) node.getSkin(); return (StyleableProperty<Boolean>) skin.spinEnabled; }
@Override public boolean isSettable(ConfidenceProgressIndicator node) { final ConfidenceProgressIndicatorSkin skin = (ConfidenceProgressIndicatorSkin) node.getSkin(); return skin.spinEnabled == null || !skin.spinEnabled.isBound(); }
@Override public StyleableProperty<Number> getStyleableProperty(ConfidenceProgressIndicator n) { final ConfidenceProgressIndicatorSkin skin = (ConfidenceProgressIndicatorSkin) n.getSkin(); return (StyleableProperty<Number>) skin.indeterminateSegmentCount; }
@Override public StyleableProperty<Paint> getStyleableProperty(ConfidenceProgressIndicator n) { final ConfidenceProgressIndicatorSkin skin = (ConfidenceProgressIndicatorSkin) n.getSkin(); return (StyleableProperty<Paint>) skin.progressColor; }
@Override public boolean isSettable(ConfidenceProgressIndicator n) { final ConfidenceProgressIndicatorSkin skin = (ConfidenceProgressIndicatorSkin) n.getSkin(); return skin.progressColor == null || !skin.progressColor.isBound(); }
@Override protected void layoutChildren() { // Position and size the circular background // double doneTextHeight = doneText.getLayoutBounds().getHeight(); final Insets controlInsets = control.getInsets(); final double left = snapSize(controlInsets.getLeft()); final double right = snapSize(controlInsets.getRight()); final double top = snapSize(controlInsets.getTop()); final double bottom = snapSize(controlInsets.getBottom()); /* ** use the min of width, or height, keep it a circle */ final double areaW = control.getWidth() - left - right; final double areaH = control.getHeight() - top - bottom /*- textGap - doneTextHeight*/; final double radiusW = areaW / 2; final double radiusH = areaH / 2; final double radius = Math.round(Math.min(radiusW, radiusH)); // use round instead of floor final double centerX = snapPosition(left + radiusW); final double centerY = snapPosition(top + radius); // find radius that fits inside radius - insetsPadding final Insets indicatorInsets = indicator.getInsets(); final double iLeft = snapSize(indicatorInsets.getLeft()); final double iRight = snapSize(indicatorInsets.getRight()); final double iTop = snapSize(indicatorInsets.getTop()); final double iBottom = snapSize(indicatorInsets.getBottom()); final double progressRadius = snapSize( Math.min( Math.min(radius - iLeft, radius - iRight), Math.min(radius - iTop, radius - iBottom))); indicatorCircle.setRadius(radius); indicator.setLayoutX(centerX); indicator.setLayoutY(centerY); arcShape.setRadiusX(progressRadius); arcShape.setRadiusY(progressRadius); progress.setLayoutX(centerX); progress.setLayoutY(centerY); // find radius that fits inside progressRadius - progressInsets final Insets progressInsets = progress.getInsets(); final double pLeft = snapSize(progressInsets.getLeft()); final double pRight = snapSize(progressInsets.getRight()); final double pTop = snapSize(progressInsets.getTop()); final double pBottom = snapSize(progressInsets.getBottom()); final double indicatorRadius = snapSize( Math.min( Math.min(progressRadius - pLeft, progressRadius - pRight), Math.min(progressRadius - pTop, progressRadius - pBottom))); // find size of spare box that fits inside indicator radius double squareBoxHalfWidth = Math.ceil(Math.sqrt((indicatorRadius * indicatorRadius) / 2)); // double squareBoxHalfWidth2 = indicatorRadius * (Math.sqrt(2) / 2); tick.setLayoutX(centerX - squareBoxHalfWidth); tick.setLayoutY(centerY - squareBoxHalfWidth); tick.resize(squareBoxHalfWidth + squareBoxHalfWidth, squareBoxHalfWidth + squareBoxHalfWidth); tick.setVisible(control.getProgress() >= 1); }
/** * ************************************************************************ * Constructors * * * ************************************************************************ */ @SuppressWarnings("deprecation") public ConfidenceProgressIndicatorSkin(ConfidenceProgressIndicator control) { super(control, new ConfidenceProgressIndicatorBehavior<>(control)); InvalidationListener indeterminateListener = valueModel -> initialize(); control.indeterminateProperty().addListener(indeterminateListener); InvalidationListener visibilityListener = new InvalidationListener() { @Override public void invalidated(Observable valueModel) { if (getSkinnable().isIndeterminate() && timelineNulled && spinner == null) { timelineNulled = false; spinner = new IndeterminateSpinner( getSkinnable(), ConfidenceProgressIndicatorSkin.this, spinEnabled.get(), progressColor.get()); getChildren().add(spinner); } if (spinner != null) { if (getSkinnable().impl_isTreeVisible() && getSkinnable().getScene() != null) { } else { getChildren().remove(spinner); spinner = null; timelineNulled = true; } } } }; control.visibleProperty().addListener(visibilityListener); control.parentProperty().addListener(visibilityListener); InvalidationListener sceneListener = new InvalidationListener() { @Override public void invalidated(Observable valueModel) { if (spinner != null) { if (getSkinnable().getScene() == null) { getChildren().remove(spinner); spinner = null; timelineNulled = true; } } else { if (getSkinnable().getScene() != null && getSkinnable().isIndeterminate()) { timelineNulled = false; spinner = new IndeterminateSpinner( getSkinnable(), ConfidenceProgressIndicatorSkin.this, spinEnabled.get(), progressColor.get()); getChildren().add(spinner); getSkinnable().requestLayout(); } } } }; control.sceneProperty().addListener(sceneListener); initialize(); getSkinnable().requestLayout(); }