Пример #1
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());
  }
Пример #2
0
  private void updateLcdDesign(final double HEIGHT) {
    LcdDesign lcdDesign = getSkinnable().getLcdDesign();
    Color[] lcdColors = lcdDesign.getColors();

    if (LcdDesign.SECTIONS == lcdDesign) {
      double currentValue = getSkinnable().getCurrentValue();
      int listSize = sections.size();
      for (int i = 0; i < listSize; i++) {
        Section section = sections.get(i);
        if (section.contains(currentValue)) {
          lcdColors = sectionColorMap.get(section);
          break;
        }
      }
    }

    lcdPaint =
        new LinearGradient(
            0,
            1,
            0,
            HEIGHT - 1,
            false,
            CycleMethod.NO_CYCLE,
            new Stop(0, lcdColors[0]),
            new Stop(0.03, lcdColors[1]),
            new Stop(0.5, lcdColors[2]),
            new Stop(0.5, lcdColors[3]),
            new Stop(1.0, lcdColors[4]));
    if (lcdDesign.name().startsWith("FLAT")) {
      lcdFramePaint = getSkinnable().getBorderPaint();

      lcdPaint = getSkinnable().getBackgroundPaint();

      Color lcdForegroundColor = (Color) getSkinnable().getForegroundPaint();
      backgroundText.setFill(
          Color.color(
              lcdForegroundColor.getRed(),
              lcdForegroundColor.getGreen(),
              lcdForegroundColor.getBlue(),
              0.1));
      valueText.setFill(lcdForegroundColor);
      upperLeftText.setFill(lcdForegroundColor);
      title.setFill(lcdForegroundColor);
      upperRightText.setFill(lcdForegroundColor);
      unitText.setFill(lcdForegroundColor);
      lowerRightText.setFill(lcdForegroundColor);
      lowerCenterText.setFill(lcdForegroundColor);
      threshold.setFill(lcdForegroundColor);
    } else {
      lcdFramePaint =
          new LinearGradient(
              0,
              0.02083333 * height,
              0,
              HEIGHT - 0.02083333 * HEIGHT,
              false,
              CycleMethod.NO_CYCLE,
              new Stop(0.0, Color.rgb(26, 26, 26)),
              new Stop(0.015, Color.rgb(77, 77, 77)),
              new Stop(0.985, Color.rgb(77, 77, 77)),
              new Stop(1.0, Color.rgb(221, 221, 221)));

      lcdPaint =
          new LinearGradient(
              0,
              1,
              0,
              HEIGHT - 1,
              false,
              CycleMethod.NO_CYCLE,
              new Stop(0, lcdColors[0]),
              new Stop(0.03, lcdColors[1]),
              new Stop(0.5, lcdColors[2]),
              new Stop(0.5, lcdColors[3]),
              new Stop(1.0, lcdColors[4]));

      backgroundText.setFill(lcdDesign.lcdBackgroundColor);
      valueText.setFill(lcdDesign.lcdForegroundColor);
      upperLeftText.setFill(lcdDesign.lcdForegroundColor);
      title.setFill(lcdDesign.lcdForegroundColor);
      upperRightText.setFill(lcdDesign.lcdForegroundColor);
      unitText.setFill(lcdDesign.lcdForegroundColor);
      lowerRightText.setFill(lcdDesign.lcdForegroundColor);
      lowerCenterText.setFill(lcdDesign.lcdForegroundColor);
      threshold.setFill(lcdDesign.lcdForegroundColor);
    }

    pane.setBackground(
        new Background(
            new BackgroundFill(lcdPaint, new CornerRadii(0.10416667 * HEIGHT), Insets.EMPTY)));
    pane.setBorder(
        new Border(
            new BorderStroke(
                lcdFramePaint,
                BorderStrokeStyle.SOLID,
                new CornerRadii(0.05 * HEIGHT),
                new BorderWidths(0.02083333 * HEIGHT))));
  }
Пример #3
0
  private void redraw() {
    formatString =
        new StringBuilder("%.")
            .append(Integer.toString(getSkinnable().getDecimals()))
            .append("f")
            .toString();
    tickLabelFormatString =
        new StringBuilder("%.")
            .append(Integer.toString(getSkinnable().getTickLabelDecimals()))
            .append("f")
            .toString();

    // Background stroke and fill
    pane.setBorder(
        new Border(
            new BorderStroke(
                getSkinnable().getBorderPaint(),
                BorderStrokeStyle.SOLID,
                CornerRadii.EMPTY,
                new BorderWidths(
                    Orientation.HORIZONTAL == orientation
                        ? getSkinnable().getBorderWidth() / preferredHeight * height
                        : getSkinnable().getBorderWidth() / preferredWidth * width))));
    pane.setBackground(
        new Background(
            new BackgroundFill(
                getSkinnable().getBackgroundPaint(), CornerRadii.EMPTY, Insets.EMPTY)));

    Color barColor = getSkinnable().getBarColor();
    bar.setFill(barColor);
    if (Orientation.VERTICAL == orientation) {
      barHighlight.setFill(
          new LinearGradient(
              barHighlight.getLayoutX(),
              0,
              barHighlight.getLayoutX() + barHighlight.getWidth(),
              0,
              false,
              CycleMethod.NO_CYCLE,
              new Stop(0.0, Color.rgb(255, 255, 255, 0.65)),
              new Stop(0.92, Color.TRANSPARENT),
              new Stop(1.0, Color.rgb(0, 0, 0, 0.2))));
    } else {
      barHighlight.setFill(
          new LinearGradient(
              0,
              barHighlight.getLayoutY(),
              0,
              barHighlight.getLayoutY() + barHighlight.getHeight(),
              false,
              CycleMethod.NO_CYCLE,
              new Stop(0.0, Color.rgb(255, 255, 255, 0.65)),
              new Stop(0.92, Color.TRANSPARENT),
              new Stop(1.0, Color.rgb(0, 0, 0, 0.2))));
    }

    // LED
    if (getSkinnable().isLedVisible()) {
      final Color LED_COLOR = getSkinnable().getLedColor();
      switch (getSkinnable().getLedType()) {
        case FLAT:
          ledFramePaint = Color.WHITE;
          ledOnPaint =
              new LinearGradient(
                  0,
                  0.25 * ledSize,
                  0,
                  0.74 * ledSize,
                  false,
                  CycleMethod.NO_CYCLE,
                  new Stop(0.0, LED_COLOR),
                  new Stop(1.0, LED_COLOR.deriveColor(0d, 1d, 0.5, 1d)));
          ledOffPaint =
              new LinearGradient(
                  0,
                  0.25 * ledSize,
                  0,
                  0.74 * ledSize,
                  false,
                  CycleMethod.NO_CYCLE,
                  new Stop(0.0, LED_COLOR.deriveColor(0d, 1d, 0.5, 1d)),
                  new Stop(1.0, LED_COLOR.deriveColor(0d, 1d, 0.13, 1d)));
          ledHighlightPaint = Color.TRANSPARENT;
          break;
        case STANDARD:
        default:
          ledFramePaint =
              new LinearGradient(
                  0.14 * ledSize,
                  0.14 * ledSize,
                  0.84 * ledSize,
                  0.84 * ledSize,
                  false,
                  CycleMethod.NO_CYCLE,
                  new Stop(0.0, Color.rgb(20, 20, 20, 0.65)),
                  new Stop(0.15, Color.rgb(20, 20, 20, 0.65)),
                  new Stop(0.26, Color.rgb(41, 41, 41, 0.65)),
                  new Stop(0.26, Color.rgb(41, 41, 41, 0.64)),
                  new Stop(0.85, Color.rgb(200, 200, 200, 0.41)),
                  new Stop(1.0, Color.rgb(200, 200, 200, 0.35)));
          ledOnPaint =
              new LinearGradient(
                  0.25 * ledSize,
                  0.25 * ledSize,
                  0.74 * ledSize,
                  0.74 * ledSize,
                  false,
                  CycleMethod.NO_CYCLE,
                  new Stop(0.0, LED_COLOR.deriveColor(0d, 1d, 0.77, 1d)),
                  new Stop(0.49, LED_COLOR.deriveColor(0d, 1d, 0.5, 1d)),
                  new Stop(1.0, LED_COLOR));
          ledOffPaint =
              new LinearGradient(
                  0.25 * ledSize,
                  0.25 * ledSize,
                  0.74 * ledSize,
                  0.74 * ledSize,
                  false,
                  CycleMethod.NO_CYCLE,
                  new Stop(0.0, LED_COLOR.deriveColor(0d, 1d, 0.20, 1d)),
                  new Stop(0.49, LED_COLOR.deriveColor(0d, 1d, 0.13, 1d)),
                  new Stop(1.0, LED_COLOR.deriveColor(0d, 1d, 0.2, 1d)));
          ledHighlightPaint =
              new RadialGradient(
                  0,
                  0,
                  0.3 * ledSize,
                  0.3 * ledSize,
                  0.29 * ledSize,
                  false,
                  CycleMethod.NO_CYCLE,
                  new Stop(0.0, Color.WHITE),
                  new Stop(1.0, Color.TRANSPARENT));
          break;
      }
      drawLed();
    }

    // LCD
    LcdDesign lcdDesign = getSkinnable().getLcdDesign();
    Color[] lcdColors = lcdDesign.getColors();
    if (getSkinnable().isLcdVisible() && getSkinnable().isValueVisible()) {
      LinearGradient lcdGradient =
          new LinearGradient(
              0,
              1,
              0,
              lcd.getHeight() - 1,
              false,
              CycleMethod.NO_CYCLE,
              new Stop(0, lcdColors[0]),
              new Stop(0.03, lcdColors[1]),
              new Stop(0.5, lcdColors[2]),
              new Stop(0.5, lcdColors[3]),
              new Stop(1.0, lcdColors[4]));
      Paint lcdFramePaint;
      if (LcdDesign.FLAT_CUSTOM == lcdDesign) {
        lcdFramePaint = lcdDesign.lcdForegroundColor;
      } else {
        lcdFramePaint =
            new LinearGradient(
                0,
                0,
                0,
                lcd.getHeight(),
                false,
                CycleMethod.NO_CYCLE,
                new Stop(0.0, Color.rgb(26, 26, 26)),
                new Stop(0.01, Color.rgb(77, 77, 77)),
                new Stop(0.99, Color.rgb(77, 77, 77)),
                new Stop(1.0, Color.rgb(221, 221, 221)));
      }
      lcd.setFill(lcdGradient);
      lcd.setStroke(lcdFramePaint);
    }

    // Text
    titleText.setText(getSkinnable().getTitle());
    titleText.setFill(getSkinnable().getTitleColor());
    unitText.setFill(getSkinnable().getUnitColor());
    unitText.setText(getSkinnable().getUnit());
    valueText.setFill(
        getSkinnable().isLcdVisible() ? lcdColors[5] : getSkinnable().getValueColor());
    resizeText();
  }
Пример #4
0
  private void initGraphics() {
    barBorder1 = new Line();
    barBorder2 = new Line();

    barBackground = new Rectangle();

    ticksAndSectionsCanvas = new Canvas(preferredWidth, preferredHeight);
    ticksAndSections = ticksAndSectionsCanvas.getGraphicsContext2D();

    ledCanvas = new Canvas();
    led = ledCanvas.getGraphicsContext2D();

    lcd = new Rectangle(0.3 * preferredWidth, 0.014 * preferredHeight);
    lcd.setArcWidth(0.0125 * preferredHeight);
    lcd.setArcHeight(0.0125 * preferredHeight);
    lcd.relocate((preferredWidth - lcd.getWidth()) * 0.5, 0.44 * preferredHeight);
    lcd.setManaged(getSkinnable().isLcdVisible());
    lcd.setVisible(getSkinnable().isLcdVisible());

    bar = new Rectangle();
    bar.setStroke(null);

    barHighlight = new Rectangle();
    barHighlight.setStroke(null);
    boolean barEffectEnabled = getSkinnable().isBarEffectEnabled();
    barHighlight.setVisible(barEffectEnabled);
    barHighlight.setManaged(barEffectEnabled);

    titleText = new Text(getSkinnable().getTitle());

    unitText = new Text(getSkinnable().getUnit());

    valueText = new Text(String.format(Locale.US, formatString, getSkinnable().getCurrentValue()));

    pane =
        new Pane(
            barBorder1,
            barBorder2,
            barBackground,
            ticksAndSectionsCanvas,
            titleText,
            unitText,
            ledCanvas,
            lcd,
            valueText,
            bar,
            barHighlight);
    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);
  }
Пример #5
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);
  }