Ejemplo n.º 1
0
  private void redraw() {
    valueFormatString =
        new StringBuilder("%.")
            .append(Integer.toString(getSkinnable().getDecimals()))
            .append("f")
            .toString();
    otherFormatString =
        new StringBuilder("%.")
            .append(Integer.toString(getSkinnable().getTickLabelDecimals()))
            .append("f")
            .toString();

    threshold.setVisible(
        Double.compare(getSkinnable().getCurrentValue(), getSkinnable().getThreshold()) >= 0);

    if (isNoOfDigitsInvalid()) {
      valueText.setText("-E-");
    } else {
      valueText.setText(
          String.format(Locale.US, valueFormatString, getSkinnable().getCurrentValue()));
    }

    updateBackgroundText();

    // Visualize the lcd semitransparent background text
    if (getSkinnable().getUnit().isEmpty()) {
      backgroundText.setX((width - backgroundText.getLayoutBounds().getWidth()) - valueOffsetRight);
    } else {
      backgroundText.setX(
          width - 2 - backgroundText.getLayoutBounds().getWidth() - valueOffsetRight);
    }
    backgroundText.setY(
        height - (backgroundText.getLayoutBounds().getHeight() * digitalFontSizeFactor) * 0.5);

    if (getSkinnable().getUnit().isEmpty()) {
      valueText.setX((width - valueText.getLayoutBounds().getWidth()) - valueOffsetRight);
    } else {
      valueText.setX((width - 2 - valueText.getLayoutBounds().getWidth()) - valueOffsetRight);
    }

    // Update the title
    title.setText(getSkinnable().getTitle());
    title.setX((width - title.getLayoutBounds().getWidth()) * 0.5);

    // Update the upper left text
    upperLeftText.setText(
        String.format(Locale.US, otherFormatString, getSkinnable().getMinMeasuredValue()));
    if (upperLeftText.getX() + upperLeftText.getLayoutBounds().getWidth() > title.getX()) {
      upperLeftText.setText("...");
    }

    // Update the upper right text
    upperRightText.setText(
        String.format(Locale.US, otherFormatString, getSkinnable().getMaxMeasuredValue()));
    upperRightText.setX(
        width - upperRightText.getLayoutBounds().getWidth() - 0.0416666667 * height);
    if (upperRightText.getX() < title.getX() + title.getLayoutBounds().getWidth()) {
      upperRightText.setText("...");
      upperRightText.setX(
          width - upperRightText.getLayoutBounds().getWidth() - 0.0416666667 * height);
    }

    // Update the lower center text
    lowerCenterText.setText(
        String.format(Locale.US, otherFormatString, getSkinnable().getOldValue()));
    lowerCenterText.setX((width - lowerCenterText.getLayoutBounds().getWidth()) * 0.5);

    // Update the lower right text
    lowerRightText.setText(getSkinnable().getSubTitle());
    lowerRightText.setX(
        width - lowerRightText.getLayoutBounds().getWidth() - 0.0416666667 * height);
    lowerRightText.setY(pane.getLayoutBounds().getMinY() + height - 3 - 0.0416666667 * height);
    if (lowerRightText.getX()
        < lowerCenterText.getX() + lowerCenterText.getLayoutBounds().getWidth()) {
      lowerRightText.setText("...");
      lowerRightText.setX(
          width - lowerRightText.getLayoutBounds().getWidth() - 0.0416666667 * height);
    }
  }
Ejemplo 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 (aspectRatio * width > height) {
      width = 1 / (aspectRatio / height);
    } else if (1 / (aspectRatio / height) > width) {
      height = aspectRatio * width;
    }

    if (width > 0 && height > 0) {
      pane.setMaxSize(width, height);
      pane.relocate(
          (getSkinnable().getWidth() - width) * 0.5, (getSkinnable().getHeight() - height) * 0.5);

      updateLcdDesign(height);

      mainInnerShadow0.setRadius(0.0625 * height);
      mainInnerShadow1.setRadius(0.04166667 * height);

      if (crystalOverlay.isVisible()) {
        crystalClip.setWidth(width);
        crystalClip.setHeight(height);
        crystalOverlay.setImage(
            Helper.createNoiseImage(width, height, DARK_NOISE_COLOR, BRIGHT_NOISE_COLOR, 8));
        crystalOverlay.setCache(true);
      }

      double tSize = 0.2 * height;
      threshold.getElements().clear();
      threshold.getElements().add(new MoveTo(0.41666667 * tSize, 0.75 * tSize));
      threshold.getElements().add(new LineTo(0.583333333333333 * tSize, 0.75 * tSize));
      threshold.getElements().add(new LineTo(0.583333333333333 * tSize, 0.916666666666667 * tSize));
      threshold.getElements().add(new LineTo(0.416666666666667 * tSize, 0.916666666666667 * tSize));
      threshold.getElements().add(new LineTo(0.416666666666667 * tSize, 0.75 * tSize));
      threshold.getElements().add(new ClosePath());
      threshold.getElements().add(new MoveTo(0.416666666666667 * tSize, 0.333333333333333 * tSize));
      threshold.getElements().add(new LineTo(0.583333333333333 * tSize, 0.333333333333333 * tSize));
      threshold.getElements().add(new LineTo(0.583333333333333 * tSize, 0.666666666666667 * tSize));
      threshold.getElements().add(new LineTo(0.416666666666667 * tSize, 0.666666666666667 * tSize));
      threshold.getElements().add(new LineTo(0.416666666666667 * tSize, 0.333333333333333 * tSize));
      threshold.getElements().add(new ClosePath());
      threshold.getElements().add(new MoveTo(tSize, tSize));
      threshold.getElements().add(new LineTo(0.5 * tSize, 0));
      threshold.getElements().add(new LineTo(0, tSize));
      threshold.getElements().add(new LineTo(tSize, tSize));
      threshold.getElements().add(new ClosePath());
      threshold.relocate(0.027961994662429348 * width, 0.75 * height - 2);

      updateFonts();

      // Setup the lcd unit
      unitText.setFont(unitFont);
      unitText.setTextOrigin(VPos.BASELINE);
      unitText.setTextAlignment(TextAlignment.RIGHT);

      unitText.setText(getSkinnable().getUnit());
      if (unitText.visibleProperty().isBound()) {
        unitText.visibleProperty().unbind();
      }

      valueOffsetLeft = height * 0.04;

      if (getSkinnable().getUnit().isEmpty()) {
        valueOffsetRight = height * 0.0833333333;
        valueText.setX((width - valueText.getLayoutBounds().getWidth()) - valueOffsetRight);
      } else {
        unitText.setX((width - unitText.getLayoutBounds().getWidth()) - height * 0.04);
        unitText.setY(
            height - (valueText.getLayoutBounds().getHeight() * digitalFontSizeFactor) * 0.5);
        valueOffsetRight =
            (unitText.getLayoutBounds().getWidth()
                + height * 0.0833333333); // distance between value and unit
        valueText.setX(width - 2 - valueText.getLayoutBounds().getWidth() - valueOffsetRight);
      }
      valueText.setY(
          height - (valueText.getLayoutBounds().getHeight() * digitalFontSizeFactor) * 0.5);

      // Visualize the lcd semitransparent background text
      updateBackgroundText();

      if (getSkinnable().getUnit().isEmpty()) {
        backgroundText.setX(
            (width - backgroundText.getLayoutBounds().getWidth()) - valueOffsetRight);
      } else {
        backgroundText.setX(
            width - 2 - backgroundText.getLayoutBounds().getWidth() - valueOffsetRight);
      }
      backgroundText.setY(
          height - (backgroundText.getLayoutBounds().getHeight() * digitalFontSizeFactor) * 0.5);

      // Setup the font for the lcd title, number system, min measured, max measure and former value
      // Title
      title.setFont(titleFont);
      title.setTextOrigin(VPos.BASELINE);
      title.setTextAlignment(TextAlignment.CENTER);
      title.setText(getSkinnable().getTitle());
      title.setX((width - title.getLayoutBounds().getWidth()) * 0.5);
      title.setY(
          pane.getLayoutBounds().getMinY()
              + title.getLayoutBounds().getHeight()
              - 0.04 * height
              + 4);

      // Info Text
      lowerRightText.setFont(smallFont);
      lowerRightText.setTextOrigin(VPos.BASELINE);
      lowerRightText.setTextAlignment(TextAlignment.RIGHT);
      lowerRightText.setText(getSkinnable().getSubTitle());
      lowerRightText.setX(
          pane.getLayoutBounds().getMinX()
              + (pane.getLayoutBounds().getWidth() - lowerRightText.getLayoutBounds().getWidth())
                  * 0.5);
      lowerRightText.setY(pane.getLayoutBounds().getMinY() + height - 4 - 0.0416666667 * height);

      // Min measured value
      upperLeftText.setFont(smallFont);
      upperLeftText.setTextOrigin(VPos.BASELINE);
      upperLeftText.setTextAlignment(TextAlignment.RIGHT);
      upperLeftText.setX(pane.getLayoutBounds().getMinX() + 0.0416666667 * height);
      upperLeftText.setY(
          pane.getLayoutBounds().getMinY()
              + upperLeftText.getLayoutBounds().getHeight()
              - 0.04 * height
              + 4);

      // Max measured value
      upperRightText.setFont(smallFont);
      upperRightText.setTextOrigin(VPos.BASELINE);
      upperRightText.setTextAlignment(TextAlignment.RIGHT);
      upperRightText.setY(
          pane.getLayoutBounds().getMinY()
              + upperRightText.getLayoutBounds().getHeight()
              - 0.04 * height
              + 4);

      // Former value
      lowerCenterText.setFont(smallFont);
      lowerCenterText.setTextOrigin(VPos.BASELINE);
      lowerCenterText.setTextAlignment(TextAlignment.CENTER);
      lowerCenterText.setX((width - lowerCenterText.getLayoutBounds().getWidth()) * 0.5);
      lowerCenterText.setY(pane.getLayoutBounds().getMinY() + height - 4 - 0.0416666667 * height);
    }
  }