Esempio n. 1
0
 private void setBarColor(final double VALUE) {
   if (!sectionsVisible && !colorGradientEnabled) {
     bar.setStroke(barColor);
   } else if (colorGradientEnabled && noOfGradientStops > 1) {
     bar.setStroke(getSkinnable().getGradientLookup().getColorAt((VALUE - minValue) / range));
   } else {
     bar.setStroke(barColor);
     for (Section section : sections) {
       if (section.contains(VALUE)) {
         bar.setStroke(section.getColor());
         break;
       }
     }
   }
 }
Esempio n. 2
0
  private void redraw() {
    pane.setBorder(
        new Border(
            new BorderStroke(
                getSkinnable().getBorderPaint(),
                BorderStrokeStyle.SOLID,
                CornerRadii.EMPTY,
                new BorderWidths(getSkinnable().getBorderWidth() / PREFERRED_HEIGHT * height))));
    pane.setBackground(
        new Background(
            new BackgroundFill(
                getSkinnable().getBackgroundPaint(), CornerRadii.EMPTY, Insets.EMPTY)));

    barColor = getSkinnable().getBarColor();

    locale = getSkinnable().getLocale();
    formatString =
        new StringBuilder("%.")
            .append(Integer.toString(getSkinnable().getDecimals()))
            .append("f")
            .toString();
    colorGradientEnabled = getSkinnable().isGradientBarEnabled();
    noOfGradientStops = getSkinnable().getGradientBarStops().size();
    sectionsVisible = getSkinnable().getSectionsVisible();

    minValueText.setText(
        String.format(
            locale,
            "%." + getSkinnable().getTickLabelDecimals() + "f",
            getSkinnable().getMinValue()));
    maxValueText.setText(
        String.format(
            locale,
            "%." + getSkinnable().getTickLabelDecimals() + "f",
            getSkinnable().getMaxValue()));
    resizeStaticText();

    barBackground.setStroke(getSkinnable().getBarBackgroundColor());
    bar.setStroke(getSkinnable().getBarColor());
    needle.setFill(getSkinnable().getNeedleColor());

    minValueText.setVisible(getSkinnable().getTickLabelsVisible());
    maxValueText.setVisible(getSkinnable().getTickLabelsVisible());

    minValueText.setFill(getSkinnable().getTitleColor());
    maxValueText.setFill(getSkinnable().getTitleColor());
    titleText.setFill(getSkinnable().getTitleColor());
  }
Esempio n. 3
0
 private void rotateNeedle(final double VALUE) {
   double needleStartAngle = angleRange * 0.5;
   double targetAngle = (VALUE - minValue) * angleStep - needleStartAngle;
   targetAngle = Helper.clamp(-needleStartAngle, -needleStartAngle + angleRange, targetAngle);
   needleRotate.setAngle(targetAngle);
   bar.setLength(-(getSkinnable().getCurrentValue() - minValue) * angleStep);
   setBarColor(VALUE);
 }
    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();
    }
    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();
    }
Esempio n. 6
0
 private void registerListeners() {
   getSkinnable().widthProperty().addListener(o -> handleEvents("RESIZE"));
   getSkinnable().heightProperty().addListener(o -> handleEvents("RESIZE"));
   getSkinnable().setOnUpdate(e -> handleEvents(e.eventType.name()));
   getSkinnable()
       .currentValueProperty()
       .addListener(o -> rotateNeedle(getSkinnable().getCurrentValue()));
   getSkinnable()
       .sectionsAlwaysVisibleProperty()
       .addListener(o -> bar.setVisible(!getSkinnable().getSectionsAlwaysVisible()));
 }
  @Override
  public void start(Stage primaryStage) throws Exception {

    Pane pane = new Pane();
    int x = RADIUS + GAP;
    int y = RADIUS + GAP;

    for (int i = 0; i < 2; i++) {

      // drawing a 2 Circles in each row
      for (int j = 0; j < 2; j++) {
        // create circle
        Circle c = new Circle(RADIUS);
        c.setCenterX(x);
        c.setCenterY(y);
        c.setStroke(Color.BLACK);
        c.setFill(Color.WHITE);
        pane.getChildren().add(c);

        // create 4 arcs in each circle with 90 degree increment
        for (int k = 30; k < 360; k += 90) {
          Arc arc = new Arc(x, y, RADIUS - 15, RADIUS - 15, k, 30);
          arc.setFill(Color.BLACK);
          arc.setType(ArcType.ROUND);
          pane.getChildren().add(arc);
        }

        x += RADIUS * 2 + GAP;
      }
      // reset center for the next row
      x = RADIUS + GAP;
      y += RADIUS * 2 + GAP;
    }

    Scene scene = new Scene(pane, 425, 425);
    primaryStage.setScene(scene);
    primaryStage.setTitle("Fans");
    primaryStage.show();
  }
Esempio n. 8
0
  private void drawSections() {
    if (sections.isEmpty()) return;
    sectionLayer.getChildren().clear();

    double centerX = width * 0.5;
    double centerY = height * 0.85;
    double barRadius = height * 0.54210526;
    double barWidth = width * 0.28472222;

    for (Section section : sections) {
      Arc sectionBar =
          new Arc(
              centerX,
              centerY,
              barRadius,
              barRadius,
              angleRange * 0.5 + 90 - (section.getStart() * angleStep),
              -((section.getStop() - section.getStart()) - minValue) * angleStep);
      sectionBar.setType(ArcType.OPEN);
      sectionBar.setStroke(section.getColor());
      sectionBar.setStrokeWidth(barWidth);
      sectionBar.setStrokeLineCap(StrokeLineCap.BUTT);
      sectionBar.setFill(null);
      Tooltip sectionTooltip =
          new Tooltip(
              new StringBuilder(section.getText())
                  .append("\n")
                  .append(String.format(Locale.US, "%.2f", section.getStart()))
                  .append(" - ")
                  .append(String.format(Locale.US, "%.2f", section.getStop()))
                  .toString());
      sectionTooltip.setTextAlignment(TextAlignment.CENTER);
      Tooltip.install(sectionBar, sectionTooltip);
      sectionLayer.getChildren().add(sectionBar);
    }
  }
    @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);
    }
Esempio n. 10
0
  private void resize() {
    width =
        getSkinnable().getWidth()
            - getSkinnable().getInsets().getLeft()
            - getSkinnable().getInsets().getRight();
    height =
        getSkinnable().getHeight()
            - getSkinnable().getInsets().getTop()
            - getSkinnable().getInsets().getBottom();

    if (ASPECT_RATIO * width > height) {
      width = 1 / (ASPECT_RATIO / height);
    } else if (1 / (ASPECT_RATIO / height) > width) {
      height = ASPECT_RATIO * width;
    }

    if (width > 0 && height > 0) {
      double centerX = width * 0.5;
      double centerY = height * 0.85;
      double barRadius = height * 0.54210526;
      double barWidth = width * 0.28472222;

      pane.setMaxSize(width, height);
      pane.relocate(
          (getSkinnable().getWidth() - width) * 0.5, (getSkinnable().getHeight() - height) * 0.5);

      barBackground.setCenterX(centerX);
      barBackground.setCenterY(centerY);
      barBackground.setRadiusX(barRadius);
      barBackground.setRadiusY(barRadius);
      barBackground.setStrokeWidth(barWidth);
      barBackground.setStartAngle(angleRange * 0.5 + 90);
      barBackground.setLength(-angleRange);

      if (sectionsVisible && sectionsAlwaysVisible) {
        sectionLayer.setPrefSize(width, height);
        drawSections();
      }

      bar.setCenterX(centerX);
      bar.setCenterY(centerY);
      bar.setRadiusX(barRadius);
      bar.setRadiusY(barRadius);
      bar.setStrokeWidth(barWidth);
      bar.setStartAngle(angleRange * 0.5 + 90);
      bar.setLength(-(getSkinnable().getCurrentValue() - minValue) * angleStep);

      double needleWidth = height * 0.13157895;
      double needleHeight = height * 0.91315789;

      needle.setCache(true);

      needleMoveTo1.setX(0.0);
      needleMoveTo1.setY(0.927953890489914 * needleHeight);

      needleCubicCurveTo2.setControlX1(0);
      needleCubicCurveTo2.setControlY1(0.968299711815562 * needleHeight);
      needleCubicCurveTo2.setControlX2(0.22 * needleWidth);
      needleCubicCurveTo2.setControlY2(needleHeight);
      needleCubicCurveTo2.setX(0.5 * needleWidth);
      needleCubicCurveTo2.setY(needleHeight);

      needleCubicCurveTo3.setControlX1(0.78 * needleWidth);
      needleCubicCurveTo3.setControlY1(needleHeight);
      needleCubicCurveTo3.setControlX2(needleWidth);
      needleCubicCurveTo3.setControlY2(0.968299711815562 * needleHeight);
      needleCubicCurveTo3.setX(needleWidth);
      needleCubicCurveTo3.setY(0.927953890489914 * needleHeight);

      needleCubicCurveTo4.setControlX1(needleWidth);
      needleCubicCurveTo4.setControlY1(0.92507204610951 * needleHeight);
      needleCubicCurveTo4.setControlX2(0.6 * needleWidth);
      needleCubicCurveTo4.setControlY2(0.0144092219020173 * needleHeight);
      needleCubicCurveTo4.setX(0.6 * needleWidth);
      needleCubicCurveTo4.setY(0.0144092219020173 * needleHeight);

      needleCubicCurveTo5.setControlX1(0.6 * needleWidth);
      needleCubicCurveTo5.setControlY1(0.0144092219020173 * needleHeight);
      needleCubicCurveTo5.setControlX2(0.58 * needleWidth);
      needleCubicCurveTo5.setControlY2(0);
      needleCubicCurveTo5.setX(0.5 * needleWidth);
      needleCubicCurveTo5.setY(0);

      needleCubicCurveTo6.setControlX1(0.42 * needleWidth);
      needleCubicCurveTo6.setControlY1(0);
      needleCubicCurveTo6.setControlX2(0.4 * needleWidth);
      needleCubicCurveTo6.setControlY2(0.0144092219020173 * needleHeight);
      needleCubicCurveTo6.setX(0.4 * needleWidth);
      needleCubicCurveTo6.setY(0.0144092219020173 * needleHeight);

      needleCubicCurveTo7.setControlX1(0.4 * needleWidth);
      needleCubicCurveTo7.setControlY1(0.0144092219020173 * needleHeight);
      needleCubicCurveTo7.setControlX2(0);
      needleCubicCurveTo7.setControlY2(0.92507204610951 * needleHeight);
      needleCubicCurveTo7.setX(0);
      needleCubicCurveTo7.setY(0.927953890489914 * needleHeight);

      needle.setCache(true);
      needle.setCacheHint(CacheHint.ROTATE);

      needle.relocate(
          (width - needle.getLayoutBounds().getWidth()) * 0.5,
          centerY
              - needle.getLayoutBounds().getHeight()
              + needle.getLayoutBounds().getWidth() * 0.5);
      needleRotate.setPivotX(needle.getLayoutBounds().getWidth() * 0.5);
      needleRotate.setPivotY(
          needle.getLayoutBounds().getHeight() - needle.getLayoutBounds().getWidth() * 0.5);

      resizeStaticText();
    }
  }
Esempio n. 11
0
  // ******************** Initialization ************************************
  private void initGraphics() {
    // Set initial size
    if (Double.compare(getSkinnable().getPrefWidth(), 0.0) <= 0
        || Double.compare(getSkinnable().getPrefHeight(), 0.0) <= 0
        || Double.compare(getSkinnable().getWidth(), 0.0) <= 0
        || Double.compare(getSkinnable().getHeight(), 0.0) <= 0) {
      if (getSkinnable().getPrefWidth() > 0 && getSkinnable().getPrefHeight() > 0) {
        getSkinnable().setPrefSize(getSkinnable().getPrefWidth(), getSkinnable().getPrefHeight());
      } else {
        getSkinnable().setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
      }
    }

    barBackground =
        new Arc(
            PREFERRED_WIDTH * 0.5,
            PREFERRED_HEIGHT * 0.696,
            PREFERRED_WIDTH * 0.275,
            PREFERRED_WIDTH * 0.275,
            angleRange * 0.5 + 90,
            -angleRange);
    barBackground.setType(ArcType.OPEN);
    barBackground.setStroke(getSkinnable().getBarBackgroundColor());
    barBackground.setStrokeWidth(PREFERRED_WIDTH * 0.02819549 * 2);
    barBackground.setStrokeLineCap(StrokeLineCap.BUTT);
    barBackground.setFill(null);

    sectionLayer = new Pane();
    sectionLayer.setBackground(
        new Background(new BackgroundFill(Color.TRANSPARENT, CornerRadii.EMPTY, Insets.EMPTY)));

    bar =
        new Arc(
            PREFERRED_WIDTH * 0.5,
            PREFERRED_HEIGHT * 0.696,
            PREFERRED_WIDTH * 0.275,
            PREFERRED_WIDTH * 0.275,
            angleRange * 0.5 + 90,
            0);
    bar.setType(ArcType.OPEN);
    bar.setStroke(getSkinnable().getBarColor());
    bar.setStrokeWidth(PREFERRED_WIDTH * 0.02819549 * 2);
    bar.setStrokeLineCap(StrokeLineCap.BUTT);
    bar.setFill(null);
    // bar.setMouseTransparent(sectionsAlwaysVisible ? true : false);
    bar.setVisible(!sectionsAlwaysVisible);

    needleRotate = new Rotate((getSkinnable().getValue() - oldValue - minValue) * angleStep);

    needleMoveTo1 = new MoveTo();
    needleCubicCurveTo2 = new CubicCurveTo();
    needleCubicCurveTo3 = new CubicCurveTo();
    needleCubicCurveTo4 = new CubicCurveTo();
    needleCubicCurveTo5 = new CubicCurveTo();
    needleCubicCurveTo6 = new CubicCurveTo();
    needleCubicCurveTo7 = new CubicCurveTo();
    needleClosePath8 = new ClosePath();
    needle =
        new Path(
            needleMoveTo1,
            needleCubicCurveTo2,
            needleCubicCurveTo3,
            needleCubicCurveTo4,
            needleCubicCurveTo5,
            needleCubicCurveTo6,
            needleCubicCurveTo7,
            needleClosePath8);
    needle.setFillRule(FillRule.EVEN_ODD);
    needle.getTransforms().setAll(needleRotate);
    needle.setFill(getSkinnable().getNeedleColor());
    needle.setPickOnBounds(false);
    needle.setStrokeType(StrokeType.INSIDE);
    needle.setStrokeWidth(1);
    needle.setStroke(getSkinnable().getBackgroundPaint());

    needleTooltip = new Tooltip(String.format(locale, formatString, getSkinnable().getValue()));
    needleTooltip.setTextAlignment(TextAlignment.CENTER);
    Tooltip.install(needle, needleTooltip);

    minValueText =
        new Text(
            String.format(
                locale,
                "%." + getSkinnable().getTickLabelDecimals() + "f",
                getSkinnable().getMinValue()));
    minValueText.setFill(getSkinnable().getTitleColor());
    Helper.enableNode(minValueText, getSkinnable().getTickLabelsVisible());

    maxValueText =
        new Text(
            String.format(
                locale,
                "%." + getSkinnable().getTickLabelDecimals() + "f",
                getSkinnable().getMaxValue()));
    maxValueText.setFill(getSkinnable().getTitleColor());
    Helper.enableNode(maxValueText, getSkinnable().getTickLabelsVisible());

    titleText = new Text(getSkinnable().getTitle());
    titleText.setFill(getSkinnable().getTitleColor());
    Helper.enableNode(titleText, !getSkinnable().getTitle().isEmpty());

    if (!sections.isEmpty() && sectionsVisible && !sectionsAlwaysVisible) {
      barTooltip = new Tooltip();
      barTooltip.setTextAlignment(TextAlignment.CENTER);
      Tooltip.install(bar, barTooltip);
    }

    pane =
        new Pane(barBackground, sectionLayer, bar, needle, minValueText, maxValueText, titleText);
    pane.setBorder(
        new Border(
            new BorderStroke(
                getSkinnable().getBorderPaint(),
                BorderStrokeStyle.SOLID,
                CornerRadii.EMPTY,
                new BorderWidths(getSkinnable().getBorderWidth()))));
    pane.setBackground(
        new Background(
            new BackgroundFill(
                getSkinnable().getBackgroundPaint(), CornerRadii.EMPTY, Insets.EMPTY)));

    getChildren().setAll(pane);
  }