Esempio n. 1
0
  private void initGraphics() {
    mainInnerShadow0 = new InnerShadow();
    mainInnerShadow0.setOffsetX(0.0);
    mainInnerShadow0.setOffsetY(0.0);
    mainInnerShadow0.setRadius(0.0625 * PREFERRED_HEIGHT);
    mainInnerShadow0.setColor(Color.rgb(255, 255, 255, 0.5));
    mainInnerShadow0.setBlurType(BlurType.TWO_PASS_BOX);

    mainInnerShadow1 = new InnerShadow();
    mainInnerShadow1.setOffsetX(0.0);
    mainInnerShadow1.setOffsetY(1.0);
    mainInnerShadow1.setRadius(0.04166667 * PREFERRED_HEIGHT);
    mainInnerShadow1.setColor(Color.rgb(0, 0, 0, 0.65));
    mainInnerShadow1.setBlurType(BlurType.TWO_PASS_BOX);
    mainInnerShadow1.setInput(mainInnerShadow0);

    crystalClip = new Rectangle(0, 0, width, height);
    crystalClip.setArcWidth(5);
    crystalClip.setArcHeight(5);

    crystalImage =
        Helper.createNoiseImage(
            PREFERRED_WIDTH, PREFERRED_HEIGHT, DARK_NOISE_COLOR, BRIGHT_NOISE_COLOR, 8);
    crystalOverlay = new ImageView(crystalImage);
    crystalOverlay.setClip(crystalClip);
    boolean crystalEnabled = getSkinnable().isLcdCrystalEnabled();
    crystalOverlay.setManaged(crystalEnabled);
    crystalOverlay.setVisible(crystalEnabled);

    threshold = new Path();
    threshold.setManaged(getSkinnable().isThresholdVisible());
    threshold.setVisible(getSkinnable().isThresholdVisible());
    threshold.setStroke(null);

    backgroundText =
        new Text(String.format(Locale.US, valueFormatString, getSkinnable().getCurrentValue()));
    backgroundText.setFill(getSkinnable().getLcdDesign().lcdBackgroundColor);
    backgroundText.setOpacity(
        (LcdFont.LCD == getSkinnable().getLcdFont()
                || LcdFont.ELEKTRA == getSkinnable().getLcdFont())
            ? 1
            : 0);

    valueText =
        new Text(String.format(Locale.US, valueFormatString, getSkinnable().getCurrentValue()));
    valueText.setFill(getSkinnable().getLcdDesign().lcdForegroundColor);

    unitText = new Text(getSkinnable().getUnit());
    unitText.setFill(getSkinnable().getLcdDesign().lcdForegroundColor);
    unitText.setManaged(!getSkinnable().getUnit().isEmpty());
    unitText.setVisible(!getSkinnable().getUnit().isEmpty());

    title = new Text(getSkinnable().getTitle());
    title.setFill(getSkinnable().getLcdDesign().lcdForegroundColor);
    title.setManaged(!getSkinnable().getTitle().isEmpty());
    title.setVisible(!getSkinnable().getTitle().isEmpty());

    lowerRightText = new Text(getSkinnable().getSubTitle());
    lowerRightText.setFill(getSkinnable().getLcdDesign().lcdForegroundColor);
    lowerRightText.setManaged(!getSkinnable().getSubTitle().isEmpty());
    lowerRightText.setVisible(!getSkinnable().getSubTitle().isEmpty());

    upperLeftText =
        new Text(String.format(Locale.US, otherFormatString, getSkinnable().getMinMeasuredValue()));
    upperLeftText.setFill(getSkinnable().getLcdDesign().lcdForegroundColor);
    upperLeftText.setManaged(getSkinnable().isMinMeasuredValueVisible());
    upperLeftText.setVisible(getSkinnable().isMinMeasuredValueVisible());

    upperRightText =
        new Text(String.format(Locale.US, otherFormatString, getSkinnable().getMaxMeasuredValue()));
    upperRightText.setFill(getSkinnable().getLcdDesign().lcdForegroundColor);
    upperRightText.setManaged(getSkinnable().isMaxMeasuredValueVisible());
    upperRightText.setVisible(getSkinnable().isMaxMeasuredValueVisible());

    lowerCenterText =
        new Text(String.format(Locale.US, otherFormatString, getSkinnable().getOldValue()));
    lowerCenterText.setFill(getSkinnable().getLcdDesign().lcdForegroundColor);
    lowerCenterText.setManaged(getSkinnable().isOldValueVisible());
    lowerCenterText.setVisible(getSkinnable().isOldValueVisible());

    shadowGroup = new Group();
    shadowGroup.setEffect(getSkinnable().isShadowsEnabled() ? FOREGROUND_SHADOW : null);
    shadowGroup
        .getChildren()
        .setAll(
            threshold,
            valueText,
            unitText,
            title,
            lowerRightText,
            upperLeftText,
            upperRightText,
            lowerCenterText);

    pane = new Pane(crystalOverlay, backgroundText, shadowGroup);
    pane.setEffect(getSkinnable().isShadowsEnabled() ? mainInnerShadow1 : null);
    getChildren().setAll(pane);
  }
Esempio n. 2
0
  private void resize() {
    width =
        getSkinnable().getWidth()
            - getSkinnable().getInsets().getLeft()
            - getSkinnable().getInsets().getRight();
    height =
        getSkinnable().getHeight()
            - getSkinnable().getInsets().getTop()
            - getSkinnable().getInsets().getBottom();

    if (width > 0 && height > 0) {
      orientation = getSkinnable().getOrientation();

      double currentValue = getSkinnable().getCurrentValue();
      Color tickMarkColor = getSkinnable().getTickMarkColor();
      Color barBorderColor =
          Color.color(
              tickMarkColor.getRed(), tickMarkColor.getGreen(), tickMarkColor.getBlue(), 0.5);
      boolean isFlatLed = LedType.FLAT == getSkinnable().getLedType();

      if (Orientation.VERTICAL == orientation) {
        width = height / aspectRatio;
        size = width < height ? width : height;
        stepSize = Math.abs((0.66793 * height) / getSkinnable().getRange());

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

        barBackground.setWidth(0.14286 * width);
        barBackground.setHeight(0.67143 * height);
        barBackground.relocate(
            (width - barBackground.getWidth()) * 0.5, (height - barBackground.getHeight()) * 0.5);
        barBackground.setStroke(null);
        barBackground.setFill(
            new LinearGradient(
                0,
                barBackground.getLayoutBounds().getMinY(),
                0,
                barBackground.getLayoutBounds().getMaxY(),
                false,
                CycleMethod.NO_CYCLE,
                new Stop(0.0, Color.rgb(255, 255, 255, 0.05)),
                new Stop(0.5, Color.rgb(255, 255, 255, 0.15)),
                new Stop(1.0, Color.rgb(255, 255, 255, 0.05))));

        minValuePosition = barBackground.getLayoutY() + barBackground.getLayoutBounds().getHeight();
        maxValuePosition = barBackground.getLayoutY();
        zeroPosition = minValuePosition + getSkinnable().getMinValue() * stepSize;
        zeroPosition = zeroPosition > minValuePosition ? minValuePosition : zeroPosition;

        barBorder1.setStartX(barBackground.getLayoutX() - 1);
        barBorder1.setStartY(maxValuePosition);
        barBorder1.setEndX(barBackground.getLayoutX() - 1);
        barBorder1.setEndY(minValuePosition);
        barBorder2.setStartX(
            barBackground.getLayoutX() + barBackground.getLayoutBounds().getWidth() + 1);
        barBorder2.setStartY(maxValuePosition);
        barBorder2.setEndX(
            barBackground.getLayoutX() + barBackground.getLayoutBounds().getWidth() + 1);
        barBorder2.setEndY(minValuePosition);

        barBorder1.setStroke(barBorderColor);
        barBorder2.setStroke(barBorderColor);

        bar.setWidth(0.14286 * width);
        bar.setTranslateX((width - bar.getWidth()) * 0.5);
        bar.setTranslateY(getSkinnable().isStartFromZero() ? zeroPosition : minValuePosition);

        barHighlight.setWidth(bar.getWidth());
        barHighlight.setTranslateX(bar.getTranslateX());
        barHighlight.setTranslateY(bar.getTranslateY());

        setBar(currentValue);

        ticksAndSectionsCanvas.setCache(false);
        ticksAndSectionsCanvas.setWidth(height / aspectRatio);
        ticksAndSectionsCanvas.setHeight(height);
        ticksAndSections.clearRect(
            0, 0, ticksAndSectionsCanvas.getWidth(), ticksAndSectionsCanvas.getHeight());
        drawTickMarks(ticksAndSections);
        ticksAndSectionsCanvas.setCache(true);
        ticksAndSectionsCanvas.setCacheHint(CacheHint.QUALITY);

        ledSize = isFlatLed ? 0.08 * width : 0.09 * width;
        ledCanvas.setWidth(ledSize);
        ledCanvas.setHeight(ledSize);
        ledCanvas.relocate((width - ledSize) * 0.5, 0.12 * height);
        ledOffShadow =
            isFlatLed
                ? null
                : new InnerShadow(
                    BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.65), 0.07 * ledSize, 0, 0, 0);
        ledOnShadow =
            isFlatLed
                ? null
                : new InnerShadow(
                    BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.65), 0.07 * ledSize, 0, 0, 0);
        if (!isFlatLed)
          ledOnShadow.setInput(
              new DropShadow(
                  BlurType.TWO_PASS_BOX, getSkinnable().getLedColor(), 0.36 * ledSize, 0, 0, 0));

        lcd.setWidth(0.8 * width);
        lcd.setHeight(0.22 * width);
        lcd.setArcWidth(0.0125 * size);
        lcd.setArcHeight(0.0125 * size);
        lcd.relocate((width - lcd.getWidth()) * 0.5, 0.87 * height);
      } else {
        height = width / aspectRatio;
        size = width < height ? width : height;
        stepSize = Math.abs(0.9 * width / getSkinnable().getRange());

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

        barBackground.setWidth(0.9 * width);
        barBackground.setHeight(0.14286 * height);
        barBackground.relocate(
            (width - barBackground.getWidth()) * 0.5, (height - barBackground.getHeight()) * 0.5);
        barBackground.setStroke(null);
        barBackground.setFill(
            new LinearGradient(
                barBackground.getLayoutBounds().getMinX(),
                0,
                barBackground.getLayoutBounds().getMaxX(),
                0,
                false,
                CycleMethod.NO_CYCLE,
                new Stop(0.0, Color.rgb(255, 255, 255, 0.05)),
                new Stop(0.5, Color.rgb(255, 255, 255, 0.15)),
                new Stop(1.0, Color.rgb(255, 255, 255, 0.05))));

        minValuePosition = barBackground.getLayoutX();
        maxValuePosition = barBackground.getLayoutX() + barBackground.getLayoutBounds().getWidth();
        zeroPosition = minValuePosition - getSkinnable().getMinValue() * stepSize;
        zeroPosition = zeroPosition < minValuePosition ? minValuePosition : zeroPosition;

        barBorder1.setStartX(minValuePosition);
        barBorder1.setStartY(barBackground.getLayoutY() - 1);
        barBorder1.setEndX(maxValuePosition);
        barBorder1.setEndY(barBackground.getLayoutY() - 1);
        barBorder2.setStartX(minValuePosition);
        barBorder2.setStartY(
            barBackground.getLayoutY() + barBackground.getLayoutBounds().getHeight() + 1);
        barBorder2.setEndX(maxValuePosition);
        barBorder2.setEndY(
            barBackground.getLayoutY() + barBackground.getLayoutBounds().getHeight() + 1);

        barBorder1.setStroke(barBorderColor);
        barBorder2.setStroke(barBorderColor);

        bar.setHeight(0.14286 * height);
        bar.setTranslateX(getSkinnable().isStartFromZero() ? zeroPosition : minValuePosition);
        bar.setTranslateY((height - bar.getHeight()) * 0.5);

        barHighlight.setHeight(bar.getHeight());
        barHighlight.setTranslateX(bar.getTranslateX());
        barHighlight.setTranslateY(bar.getTranslateY());

        setBar(currentValue);

        ticksAndSectionsCanvas.setCache(false);
        ticksAndSectionsCanvas.setWidth(width);
        ticksAndSectionsCanvas.setHeight(height);
        ticksAndSections.clearRect(
            0, 0, ticksAndSectionsCanvas.getWidth(), ticksAndSectionsCanvas.getHeight());
        drawTickMarks(ticksAndSections);
        ticksAndSectionsCanvas.setCache(true);
        ticksAndSectionsCanvas.setCacheHint(CacheHint.QUALITY);

        ledSize = isFlatLed ? 0.08 * height : 0.09 * height;
        ledCanvas.setWidth(ledSize);
        ledCanvas.setHeight(ledSize);
        ledCanvas.relocate(0.955 * width, (height - ledSize) * 0.5);
        ledOffShadow =
            isFlatLed
                ? null
                : new InnerShadow(
                    BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.65), 0.07 * ledSize, 0, 0, 0);
        ledOnShadow =
            isFlatLed
                ? null
                : new InnerShadow(
                    BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.65), 0.07 * ledSize, 0, 0, 0);
        if (!isFlatLed)
          ledOnShadow.setInput(
              new DropShadow(
                  BlurType.TWO_PASS_BOX, getSkinnable().getLedColor(), 0.36 * ledSize, 0, 0, 0));

        lcd.setWidth(0.3 * width);
        lcd.setHeight(0.22 * height);
        lcd.setArcWidth(0.0125 * size);
        lcd.setArcHeight(0.0125 * size);
        lcd.relocate((width - lcd.getWidth()) - 0.03571429 * height, 0.03571429 * height);
      }

      resizeText();
    }
  }