Exemple #1
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);
    }
  }
Exemple #2
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);
  }