@Override protected double computePrefHeight(double width) { double h = 0; for (Node child : getChildren()) { if (child instanceof Region) { Region region = (Region) child; if (region.getShape() != null) { h = Math.max(h, region.getShape().getLayoutBounds().getMaxY()); } else { h = Math.max(h, region.prefHeight(width)); } } } return h; }
@Override protected double computePrefWidth(double height) { double w = 0; for (Node child : getChildren()) { if (child instanceof Region) { Region region = (Region) child; if (region.getShape() != null) { w = Math.max(w, region.getShape().getLayoutBounds().getMaxX()); } else { w = Math.max(w, region.prefWidth(height)); } } } return w; }
private void rebuild() { // update indeterminate indicator final int segments = skin.indeterminateSegmentCount.get(); opacities.clear(); pathsG.getChildren().clear(); final double step = 0.8 / (segments - 1); for (int i = 0; i < segments; i++) { Region region = new Region(); region.setScaleShape(false); region.setCenterShape(false); region.getStyleClass().addAll("segment", "segment" + i); if (fillOverride instanceof Color) { Color c = (Color) fillOverride; region.setStyle( "-fx-background-color: rgba(" + ((int) (255 * c.getRed())) + "," + "" + ((int) (255 * c.getGreen())) + "," + ((int) (255 * c.getBlue())) + "," + "" + c.getOpacity() + ");"); } else { region.setStyle(null); } double opacity = Math.min(1, i * step); opacities.add(opacity); region.setOpacity(opacity); pathsG.getChildren().add(region); } }
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 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 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); }