예제 #1
0
  public Parent createContent() {
    Pane root = new Pane();
    root.setPrefSize(140, 140);
    root.setMinSize(Pane.USE_PREF_SIZE, Pane.USE_PREF_SIZE);
    root.setMaxSize(Pane.USE_PREF_SIZE, Pane.USE_PREF_SIZE);
    // create rectangle
    Rectangle rect = new Rectangle(20, 20, 100, 100);
    rect.setArcHeight(20);
    rect.setArcWidth(20);
    rect.setFill(Color.ORANGE);
    root.getChildren().add(rect);

    rotateTransition = new RotateTransition(Duration.seconds(4), rect);
    rotateTransition.setFromAngle(0);
    rotateTransition.setToAngle(720);
    rotateTransition.setCycleCount(Timeline.INDEFINITE);
    rotateTransition.setAutoReverse(true);

    return root;
  }
예제 #2
0
파일: LcdSkin.java 프로젝트: jforge/Medusa
  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);
    }
  }
예제 #3
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();
    }
  }
예제 #4
0
  @Override
  protected Group createVisual() {
    // container set-up
    final Group group =
        new Group() {
          @Override
          public boolean isResizable() {
            // every node is resizable when it contains a graph
            return isNesting();
          }

          @Override
          public void resize(double w, double h) {
            if (!isResizable()) {
              return;
            }

            // compute new size, based on layout bounds
            Bounds layoutBounds = getLayoutBounds();
            Bounds vboxBounds = vbox.getLayoutBounds();
            double vw = vboxBounds.getWidth() + w - layoutBounds.getWidth();
            double vh = vboxBounds.getHeight() + h - layoutBounds.getHeight();
            vbox.setPrefSize(vw, vh);
            vbox.resize(vw, vh);
          }
        };

    // create box for border and background
    rect = new Rectangle();
    rect.setFill(
        new LinearGradient(
            0,
            0,
            1,
            1,
            true,
            CycleMethod.REFLECT,
            Arrays.asList(new Stop(0, new Color(1, 1, 1, 1)))));
    rect.setStroke(new Color(0, 0, 0, 1));
    rect.getStyleClass().add(CSS_CLASS_SHAPE);

    nestedChildrenPane = createNestedContentPane();
    nestedContentStackPane = createNestedContentStackPane(nestedChildrenPane);
    nestedChildrenPane.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
    nestedContentStackPane.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);

    // initialize image view
    iconImageView = new ImageView();
    iconImageView.setImage(null);
    iconImageView.getStyleClass().add(CSS_CLASS_ICON);

    // initialize text
    labelText = new Text();
    labelText.setTextOrigin(VPos.TOP);
    labelText.setText(NODE_LABEL_EMPTY);
    labelText.getStyleClass().add(CSS_CLASS_LABEL);

    // build node visual
    createNodeVisual(group, rect, iconImageView, labelText, nestedContentStackPane);

    return group;
  }
예제 #5
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();
    }
  }