// Test for RT-13820
  @Test
  public void changingShapeElementsShouldResultInRender() {
    Region r = new Region();
    r.setPrefWidth(640);
    r.setPrefHeight(480);
    LineTo lineTo;
    Path p =
        new Path(
            new MoveTo(0, 0), lineTo = new LineTo(100, 0), new LineTo(50, 100), new ClosePath());
    r.setBackground(new Background(new BackgroundFill(Color.BLUE, null, null)));
    r.setCenterShape(true);
    r.setScaleShape(true);
    r.setShape(p);
    r.impl_syncPeer();

    NGRegion peer = r.impl_getPeer();
    assertFalse(peer.isClean());
    peer.clearDirtyTree();
    assertTrue(peer.isClean());

    lineTo.setX(200);
    p.impl_syncPeer();
    r.impl_syncPeer();
    assertFalse(peer.isClean());
  }
  /** Called to update and layout the content for the plot */
  @Override
  protected void layoutPlotChildren() {
    // we have nothing to layout if no data is present
    if (getData() == null) {
      return;
    }
    // update candle positions
    for (int seriesIndex = 0; seriesIndex < getData().size(); seriesIndex++) {
      Series<String, Number> series = getData().get(seriesIndex);
      Iterator<Data<String, Number>> iter = getDisplayedDataIterator(series);
      Path seriesPath = null;
      if (series.getNode() instanceof Path) {
        seriesPath = (Path) series.getNode();
        seriesPath.getElements().clear();
      }
      while (iter.hasNext()) {
        Data<String, Number> item = iter.next();
        double x = getXAxis().getDisplayPosition(getCurrentDisplayedXValue(item));
        double y = getYAxis().getDisplayPosition(getCurrentDisplayedYValue(item));
        Node itemNode = item.getNode();
        BarData bar = (BarData) item.getExtraValue();
        if (itemNode instanceof Candle && item.getYValue() != null) {
          Candle candle = (Candle) itemNode;

          double close = getYAxis().getDisplayPosition(bar.getClose());
          double high = getYAxis().getDisplayPosition(bar.getHigh());
          double low = getYAxis().getDisplayPosition(bar.getLow());
          double candleWidth = 10;
          // update candle
          candle.update(close - y, high - y, low - y, candleWidth);

          // update tooltip content
          candle.updateTooltip(bar.getOpen(), bar.getClose(), bar.getHigh(), bar.getLow());

          // position the candle
          candle.setLayoutX(x);
          candle.setLayoutY(y);
        }
      }
    }
  }
Пример #3
0
  private Path createEllipsePath(
      double centerX, double centerY, double radiusX, double radiusY, double rotate) {
    ArcTo arcTo = new ArcTo();
    arcTo.setX(centerX - radiusX + 1); // to simulate a full 360 degree celcius circle.
    arcTo.setY(centerY - radiusY);
    arcTo.setSweepFlag(false);
    arcTo.setLargeArcFlag(true);
    arcTo.setRadiusX(radiusX);
    arcTo.setRadiusY(radiusY);
    arcTo.setXAxisRotation(rotate);

    Path path =
        PathBuilder.create()
            .elements(
                new MoveTo(centerX - radiusX, centerY - radiusY),
                arcTo,
                new ClosePath()) // close 1 px gap.
            .build();
    path.setStroke(Color.DODGERBLUE);
    path.getStrokeDashArray().setAll(5d, 5d);
    return path;
  }
Пример #4
0
  /**
   * Sets colors for path gradient. Values are used on next update().
   *
   * @param pathColor Path Color
   * @param bendStartColor Starting path color
   * @param bendEndColor Ending path color
   */
  public void setColors(Color pathColor, Color bendStartColor, Color bendEndColor) {
    this.pathColor = pathColor;
    this.bendEndColor = bendEndColor;
    this.bendStartColor = bendStartColor;

    Paint fill = p.getFill();
    if (fill instanceof LinearGradient) {
      LinearGradient lg = (LinearGradient) fill;
      if (lg.getStops().size() >= 3) {
        p.setFill(
            new LinearGradient(
                lg.getStartX(),
                lg.getStartY(),
                lg.getEndX(),
                lg.getEndY(),
                false,
                CycleMethod.NO_CYCLE,
                new Stop(lg.getStops().get(0).getOffset(), pathColor),
                new Stop(lg.getStops().get(1).getOffset(), bendStartColor),
                new Stop(lg.getStops().get(2).getOffset(), bendEndColor)));
      }
    }
  }
 @Override
 protected void seriesAdded(Series<String, Number> series, int seriesIndex) {
   // handle any data already in series
   for (int j = 0; j < series.getData().size(); j++) {
     Data item = series.getData().get(j);
     Node candle = createCandle(seriesIndex, item, j);
     if (shouldAnimate()) {
       candle.setOpacity(0);
       getPlotChildren().add(candle);
       // fade in new candle
       FadeTransition ft = new FadeTransition(Duration.millis(500), candle);
       ft.setToValue(1);
       ft.play();
     } else {
       getPlotChildren().add(candle);
     }
   }
   // create series path
   Path seriesPath = new Path();
   seriesPath.getStyleClass().setAll("candlestick-average-line", "series" + seriesIndex);
   series.setNode(seriesPath);
   getPlotChildren().add(seriesPath);
 }
Пример #6
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());
  }
Пример #7
0
  public static Path getFXShape(LinkedList swingShapeList) {

    Path sfx = new Path();

    for (Object s : swingShapeList) {
      java.awt.Shape ss = (java.awt.Shape) s;
      if (ss instanceof java.awt.Shape) {
        double[] coords = new double[6];
        ArrayList<double[]> areaPoints = new ArrayList<double[]>();

        for (PathIterator pi = ss.getPathIterator(null); !pi.isDone(); pi.next()) {
          int type = pi.currentSegment(coords);

          double[] pathIteratorCoords = {
            type, coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]
          };
          areaPoints.add(pathIteratorCoords);
        }

        for (double[] d : areaPoints) {
          if (d[0] == PathIterator.SEG_MOVETO) {

            MoveTo moveTo = new MoveTo();
            moveTo.setX(d[1]);
            moveTo.setY(d[2]);
            sfx.getElements().add(moveTo);

          } else if (d[0] == PathIterator.SEG_LINETO) {

            LineTo lineTo = new LineTo();
            lineTo.setX(d[1]);
            lineTo.setY(d[2]);
            sfx.getElements().add(lineTo);

          } else if (d[0] == PathIterator.SEG_CUBICTO) {

            CubicCurveTo ccTo = new CubicCurveTo(d[1], d[2], d[3], d[4], d[5], d[6]);
            sfx.getElements().add(ccTo);

          } else if (d[0] == PathIterator.SEG_QUADTO) {

            QuadCurveTo qcTo = new QuadCurveTo(d[1], d[2], d[3], d[4]);
            sfx.getElements().add(qcTo);

          } else if (d[0] == PathIterator.SEG_CLOSE) {

            ClosePath cp = new ClosePath();
            sfx.getElements().add(cp);
          }
        }
      }
    }
    return sfx;
  }
Пример #8
0
 // REMOVE ME
 public static Node createIconContent() {
   Path path = new Path();
   path.getElements()
       .addAll(new MoveTo(25, 25), new HLineTo(45), new ArcTo(20, 20, 0, 80, 25, true, true));
   path.setStroke(Color.web("#b9c0c5"));
   path.setStrokeWidth(5);
   path.getStrokeDashArray().addAll(15d, 15d);
   path.setFill(null);
   javafx.scene.effect.InnerShadow effect = new javafx.scene.effect.InnerShadow();
   effect.setOffsetX(1);
   effect.setOffsetY(1);
   effect.setRadius(3);
   effect.setColor(Color.rgb(0, 0, 0, 0.6));
   path.setEffect(effect);
   return path;
 }
Пример #9
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);
    }
  }
Пример #10
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);
    }
  }
Пример #11
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))));
  }
Пример #12
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);
  }
Пример #13
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();
    }
  }
  public ColorPickerPopover() {

    getStyleClass().add("color-picker-popover");
    popup.setAutoHide(true);

    // add this to popup
    popup.getContent().add(this);

    // load stylesheet
    getStylesheets().add(ColorPicker.class.getResource("ColorPicker.css").toString());

    // create popover path for main shape
    final Path p = new Path();
    p.getElements()
        .addAll(
            new MoveTo(PICKER_PADDING, PICKER_PADDING + ARROW_SIZE + RADIUS),
            new ArcTo(
                RADIUS,
                RADIUS,
                90,
                PICKER_PADDING + RADIUS,
                PICKER_PADDING + ARROW_SIZE,
                false,
                true),
            new LineTo(PICKER_PADDING + ARROW_X - (ARROW_SIZE * 0.8), PICKER_PADDING + ARROW_SIZE),
            new LineTo(PICKER_PADDING + ARROW_X, PICKER_PADDING),
            new LineTo(PICKER_PADDING + ARROW_X + (ARROW_SIZE * 0.8), PICKER_PADDING + ARROW_SIZE),
            new LineTo(PICKER_PADDING + PICKER_WIDTH - RADIUS, PICKER_PADDING + ARROW_SIZE),
            new ArcTo(
                RADIUS,
                RADIUS,
                90,
                PICKER_PADDING + PICKER_WIDTH,
                PICKER_PADDING + ARROW_SIZE + RADIUS,
                false,
                true),
            new LineTo(
                PICKER_PADDING + PICKER_WIDTH,
                PICKER_PADDING + ARROW_SIZE + PICKER_HEIGHT - RADIUS),
            new ArcTo(
                RADIUS,
                RADIUS,
                90,
                PICKER_PADDING + PICKER_WIDTH - RADIUS,
                PICKER_PADDING + ARROW_SIZE + PICKER_HEIGHT,
                false,
                true),
            new LineTo(PICKER_PADDING + RADIUS, PICKER_PADDING + ARROW_SIZE + PICKER_HEIGHT),
            new ArcTo(
                RADIUS,
                RADIUS,
                90,
                PICKER_PADDING,
                PICKER_PADDING + ARROW_SIZE + PICKER_HEIGHT - RADIUS,
                false,
                true),
            new ClosePath());
    p.setFill(
        new LinearGradient(
            0,
            0,
            0,
            1,
            true,
            CycleMethod.NO_CYCLE,
            new Stop(0, Color.web("#313131")),
            new Stop(0.5, Color.web("#5f5f5f")),
            new Stop(1, Color.web("#313131"))));
    p.setStroke(null);
    p.setEffect(new DropShadow(15, 0, 1, Color.gray(0, 0.6)));
    p.setCache(true);

    // create rectangle to capture mouse events to hide
    Rectangle windowClickRect =
        RectangleBuilder.create()
            .width(PICKER_PADDING + PICKER_WIDTH + PICKER_PADDING)
            .height(PICKER_PADDING + PICKER_HEIGHT + PICKER_PADDING)
            .fill(Color.TRANSPARENT)
            .onMouseClicked(
                new EventHandler<MouseEvent>() {

                  @Override
                  public void handle(MouseEvent event) {

                    System.out.println("x= " + event.getX());
                    System.out.println(
                        "p.contains(event.getX(), event.getY()) = "
                            + p.contains(event.getX(), event.getY()));
                    if (!p.contains(event.getX(), event.getY())) {
                      hide();
                    }
                  }
                })
            .build();

    final Circle colorRectIndicator =
        CircleBuilder.create()
            .centerX(60)
            .centerY(60)
            .radius(5)
            .stroke(Color.WHITE)
            .fill(null)
            .effect(new DropShadow(2, 0, 1, Color.BLACK))
            .build();

    colorRectIndicator
        .centerXProperty()
        .bind(
            new DoubleBinding() {

              {
                bind(sat);
              }

              @Override
              protected double computeValue() {

                return (PICKER_PADDING + 10) + (RECT_SIZE * (sat.get() / 100));
              }
            });

    colorRectIndicator
        .centerYProperty()
        .bind(
            new DoubleBinding() {

              {
                bind(bright);
              }

              @Override
              protected double computeValue() {

                return (PICKER_PADDING + ARROW_SIZE + 10)
                    + (RECT_SIZE * (1 - (bright.get() / 100)));
              }
            });

    final Rectangle colorRect =
        RectangleBuilder.create()
            .x(PICKER_PADDING + 10)
            .y(PICKER_PADDING + ARROW_SIZE + 10)
            .width(RECT_SIZE)
            .height(RECT_SIZE)
            .build();
    colorRect
        .fillProperty()
        .bind(
            new ObjectBinding<Paint>() {

              {
                bind(color);
              }

              @Override
              protected Paint computeValue() {

                return Color.hsb(hue.getValue(), 1, 1);
              }
            });

    Rectangle colorRectOverlayOne =
        RectangleBuilder.create()
            .x(PICKER_PADDING + 10)
            .y(PICKER_PADDING + ARROW_SIZE + 10)
            .width(RECT_SIZE)
            .height(RECT_SIZE)
            .fill(
                new LinearGradient(
                    0,
                    0,
                    1,
                    0,
                    true,
                    CycleMethod.NO_CYCLE,
                    new Stop(0, Color.rgb(255, 255, 255, 1)),
                    new Stop(1, Color.rgb(255, 255, 255, 0))))
            .build();

    EventHandler<MouseEvent> rectMouseHandler =
        new EventHandler<MouseEvent>() {

          @Override
          public void handle(MouseEvent event) {

            final double x = event.getX() - colorRect.getX();
            final double y = event.getY() - colorRect.getY();
            sat.set(clamp(x / RECT_SIZE) * 100);
            bright.set(100 - (clamp(y / RECT_SIZE) * 100));
          }
        };

    Rectangle colorRectOverlayTwo =
        RectangleBuilder.create()
            .x(PICKER_PADDING + 10)
            .y(PICKER_PADDING + ARROW_SIZE + 10)
            .width(RECT_SIZE)
            .height(RECT_SIZE)
            .fill(
                new LinearGradient(
                    0,
                    0,
                    0,
                    1,
                    true,
                    CycleMethod.NO_CYCLE,
                    new Stop(0, Color.rgb(0, 0, 0, 0)),
                    new Stop(1, Color.rgb(0, 0, 0, 1))))
            .onMouseDragged(rectMouseHandler)
            .onMouseClicked(rectMouseHandler)
            .build();
    final Rectangle colorBar =
        RectangleBuilder.create()
            .x(PICKER_PADDING + PICKER_WIDTH - 30)
            .y(PICKER_PADDING + ARROW_SIZE + 10)
            .width(20)
            .height(RECT_SIZE)
            .fill(createHueGradient())
            .build();
    final Rectangle colorBarIndicator =
        RectangleBuilder.create()
            .x(PICKER_PADDING + PICKER_WIDTH - 32)
            .y(PICKER_PADDING + ARROW_SIZE + 15)
            .width(24)
            .height(10)
            .arcWidth(4)
            .arcHeight(4)
            .stroke(Color.WHITE)
            .fill(null)
            .effect(new DropShadow(2, 0, 1, Color.BLACK))
            .build();

    colorBarIndicator
        .yProperty()
        .bind(
            new DoubleBinding() {

              {
                bind(hue);
              }

              @Override
              protected double computeValue() {

                return (PICKER_PADDING + ARROW_SIZE + 5) + (RECT_SIZE * (hue.get() / 360));
              }
            });
    EventHandler<MouseEvent> barMouseHandler =
        new EventHandler<MouseEvent>() {

          @Override
          public void handle(MouseEvent event) {

            final double y = event.getY() - colorBar.getY();
            hue.set(clamp(y / RECT_SIZE) * 360);
          }
        };
    colorBar.setOnMouseDragged(barMouseHandler);
    colorBar.setOnMouseClicked(barMouseHandler);

    Label brightnessLabel = new Label("Brightness:");
    brightnessLabel.setMinWidth(Control.USE_PREF_SIZE);
    GridPane.setConstraints(brightnessLabel, 0, 0);

    Slider brightnessSlider = SliderBuilder.create().min(0).max(100).id("BrightnessSlider").build();
    brightnessSlider.valueProperty().bindBidirectional(bright);
    GridPane.setConstraints(brightnessSlider, 1, 0);

    IntegerField brightnessField = new IntegerField();
    brightnessField.valueProperty().bindBidirectional(bright);
    brightnessField.setPrefColumnCount(7);
    GridPane.setConstraints(brightnessField, 2, 0);

    Label saturationLabel = new Label("Saturation:");
    saturationLabel.setMinWidth(Control.USE_PREF_SIZE);
    GridPane.setConstraints(saturationLabel, 0, 1);

    Slider saturationSlider = SliderBuilder.create().min(0).max(100).id("SaturationSlider").build();
    saturationSlider.valueProperty().bindBidirectional(sat);
    GridPane.setConstraints(saturationSlider, 1, 1);

    saturationSlider
        .styleProperty()
        .bind(
            new StringBinding() {

              {
                bind(color);
              }

              @Override
              protected String computeValue() {

                return "picker-color: hsb(" + hue.get() + ",100%,100%);";
              }
            });

    IntegerField saturationField = new IntegerField();
    saturationField.valueProperty().bindBidirectional(sat);
    saturationField.setPrefColumnCount(7);
    GridPane.setConstraints(saturationField, 2, 1);

    Label webLabel = new Label("Web:");
    webLabel.setMinWidth(Control.USE_PREF_SIZE);
    GridPane.setConstraints(webLabel, 0, 2);

    WebColorField webField = new WebColorField();
    webField.valueProperty().bindBidirectional(color);
    GridPane.setConstraints(webField, 1, 2, 2, 1);

    GridPane controls = new GridPane();
    controls.setVgap(5);
    controls.setHgap(5);
    controls
        .getChildren()
        .addAll(
            brightnessLabel,
            brightnessSlider,
            brightnessField,
            saturationLabel,
            saturationSlider,
            saturationField,
            webLabel,
            webField);
    controls.setManaged(false);
    controls.resizeRelocate(
        PICKER_PADDING + 10,
        PICKER_PADDING + ARROW_SIZE + 10 + 170 + 10,
        PICKER_WIDTH - 20,
        controls.getPrefHeight());

    getChildren()
        .addAll(
            windowClickRect,
            p,
            colorRect,
            colorRectOverlayOne,
            colorRectOverlayTwo,
            colorBar,
            colorRectIndicator,
            colorBarIndicator,
            controls);
  }
Пример #15
0
 public void rotator(double angle, Path path) {
   ObservableList<PathElement> elements = path.getElements();
   elements = pathChanger(elements, 1);
   path = new javafx.scene.shape.Path(elements);
 }
Пример #16
0
  /** Updates DisplacementMap and path for current coordinates. */
  public void update() {
    setUpdateNeeded(false);

    if (newWidth == map.getWidth()
        && newHeight == map.getHeight()
        && targetX == oldTargetX
        && targetY == oldTargetY) {
      return;
    }
    oldTargetX = targetX;
    oldTargetY = targetY;
    if (newWidth != map.getWidth() || newHeight != map.getHeight()) {
      map.setWidth(newWidth);
      map.setHeight(newHeight);
    }

    final double W = node.getLayoutBounds().getWidth();
    final double H = node.getLayoutBounds().getHeight();

    // target point F for folded corner
    final double xF = Math.min(targetX, W - 1);
    final double yF = Math.min(targetY, H - 1);

    final Point2D F = new Point2D(xF, yF);

    // corner point O
    final double xO = W;
    final double yO = H;

    // distance between them
    final double FO = Math.hypot(xF - xO, yF - yO);
    final double AF = FO / 2;

    final double AC = Math.min(AF * 0.5, 200);

    // radius of the fold as seen along the l2 line
    final double R = AC / Math.PI * 1.5;
    final double BC = R;
    final double flat_R = AC;

    // Gradient for the line from target point to corner point
    final double K = (yO - yF) / (xO - xF);

    // angle of a line l1
    final double ANGLE = Math.atan(1 / K);

    // point A (on line l1 - the mirror line of target and corner points)
    final double xA = (xO + xF) / 2;
    final double yA = (yO + yF) / 2;

    // end points of line l1
    final double bottomX = xA - (H - yA) * K;
    final double bottomY = H;
    final double rightX = W;
    final double rightY = yA - (W - xA) / K;

    final Point2D RL1 = new Point2D(rightX, rightY);
    final Point2D BL1 = new Point2D(bottomX, bottomY);

    // point C (on line l2 - the line when distortion begins)
    final double kC = AC / AF;
    final double xC = xA - (xA - xF) * kC;
    final double yC = yA - (yA - yF) * kC;

    final Point2D C = new Point2D(xC, yC);

    final Point2D RL2 = new Point2D(W, yC - (W - xC) / K);
    final Point2D BL2 = new Point2D(xC - (H - yC) * K, H);

    // point B (on line l3 - the line where distortion ends)
    final double kB = BC / AC;
    final double xB = xC + (xA - xC) * kB;
    final double yB = yC + (yA - yC) * kB;

    // Bottom ellipse calculations
    final Point2D BP1 = calcIntersection(F, BL1, BL2, C);
    final Point2D BP3 = BL2;
    final Point2D BP2 = middle(BP1, BP3, 0.5);
    final Point2D BP4 = new Point2D(xB + BP2.getX() - xC, yB + BP2.getY() - yC);

    final double bE_x1 = hypot(BP2, BP3);
    final double bE_y2 = -hypot(BP2, BP4);
    final double bE_yc = -hypot(BP2, BL1);
    final double bE_y0 = bE_y2 * bE_y2 / (2 * bE_y2 - bE_yc);
    final double bE_b = bE_y0 - bE_y2;
    final double bE_a = Math.sqrt(-bE_x1 * bE_x1 / bE_y0 * bE_b * bE_b / bE_yc);

    // Right ellipse calculations
    final Point2D RP1 = calcIntersection(F, RL1, RL2, C);
    final Point2D RP3 = RL2;
    final Point2D RP2 = middle(RP1, RP3, 0.5);
    final Point2D RP4 = new Point2D(xB + RP2.getX() - xC, yB + RP2.getY() - yC);

    final double rE_x1 = hypot(RP2, RP3);
    final double rE_y2 = -hypot(RP2, RP4);
    final double rE_yc = -hypot(RP2, RL1);
    final double rE_y0 = rE_y2 * rE_y2 / (2 * rE_y2 - rE_yc);
    final double rE_b = rE_y0 - rE_y2;
    final double rE_a = Math.sqrt(-rE_x1 * rE_x1 / rE_y0 * rE_b * rE_b / rE_yc);

    p.setFill(
        new LinearGradient(
            xF,
            yF,
            xO,
            yO,
            false,
            CycleMethod.NO_CYCLE,
            new Stop(0, pathColor),
            new Stop((xC - xF) / (xO - xF), bendStartColor),
            new Stop((xB - xF) / (xO - xF), bendEndColor)));

    p.getElements()
        .setAll(
            new MoveTo(BP4.getX(), BP4.getY()),
            ArcToBuilder.create()
                .XAxisRotation(Math.toDegrees(-ANGLE))
                .radiusX(bE_a)
                .radiusY(bE_b)
                .x(BP1.getX())
                .y(BP1.getY())
                .build(),
            new LineTo(xF, yF),
            new LineTo(RP1.getX(), RP1.getY()),
            ArcToBuilder.create()
                .XAxisRotation(Math.toDegrees(-ANGLE))
                .radiusX(rE_a)
                .radiusY(rE_b)
                .x(RP4.getX())
                .y(RP4.getY())
                .build(),
            new ClosePath());

    if (shadow != null) {
      double level0 = (xB - xF) / (xO - xF) - R / FO * 0.5;
      double level1 = (xB - xF) / (xO - xF) + (0.3 + (200 - AC) / 200) * R / FO;
      shadow.setFill(
          new LinearGradient(
              xF,
              yF,
              xO,
              yO,
              false,
              CycleMethod.NO_CYCLE,
              new Stop(level0, Color.rgb(0, 0, 0, 0.7)),
              new Stop(level0 * 0.3 + level1 * 0.7, Color.rgb(0, 0, 0, 0.25)),
              new Stop(level1, Color.rgb(0, 0, 0, 0.0)),
              new Stop(1, Color.rgb(0, 0, 0, 0))));

      shadow
          .getElements()
          .setAll(
              new MoveTo(RP3.getX(), RP3.getY()),
              ArcToBuilder.create()
                  .XAxisRotation(Math.toDegrees(-ANGLE))
                  .radiusX(rE_a)
                  .radiusY(rE_b)
                  .x(RP4.getX())
                  .y(RP4.getY())
                  .sweepFlag(true)
                  .build(),
              new LineTo(BP4.getX(), BP4.getY()),
              ArcToBuilder.create()
                  .XAxisRotation(Math.toDegrees(-ANGLE))
                  .radiusX(bE_a)
                  .radiusY(bE_b)
                  .x(BP3.getX())
                  .y(BP3.getY())
                  .sweepFlag(true)
                  .build(),
              new LineTo(xO, yO),
              new ClosePath());
    }

    if (clip != null) {
      final Point2D RL3 = new Point2D(W, yB - (W - xB) / K);
      final Point2D BL3 = new Point2D(xB - (H - yB) * K, H);

      clip.getElements()
          .setAll(
              new MoveTo(0, 0),
              RL3.getY() > 0 ? new LineTo(W, 0) : new LineTo(0, 0),
              RL3.getY() >= 0
                  ? new LineTo(RL3.getX(), RL3.getY())
                  : new LineTo(xB - (0 - yB) * K, 0),
              BL3.getX() >= 0
                  ? new LineTo(BL3.getX(), BL3.getY())
                  : new LineTo(0, yB - (0 - xB) / K),
              BL3.getX() > 0 ? new LineTo(0, H) : new LineTo(0, 0),
              new ClosePath());
    }

    final double K2 = -K;
    final double C2 = BP3.getX() - K2 * H;

    final double K3 = -K;
    final double C3 = xB - K3 * yB;

    final double STEP = Math.max(0.1, R / (buffer.length - 1));
    final double HYPOT = Math.hypot(1, K);
    final double yR = 1.5 * R;
    double x_1 = 0, y_1 = 0, cur_len = 0;
    for (double len = 0; len <= R; len += STEP) {
      final int index = (int) Math.round(len / STEP);
      final double angle = Math.asin(len / R);
      final double y = yR * Math.cos(angle);
      if (len > 0) {
        cur_len += Math.hypot(y - y_1, len - x_1);
      }
      buffer[index][0] = (float) angle;
      buffer[index][1] = (float) (cur_len * flat_R);
      x_1 = len;
      y_1 = y;
    }
    double total_len = cur_len;
    for (double len = 0; len <= R; len += STEP) {
      final int index = (int) Math.round(len / STEP);
      final double flat_len = buffer[index][1] / total_len;
      final double delta_len = flat_len - len;
      final double xs = delta_len / HYPOT;
      final double ys = K * delta_len / HYPOT;
      buffer[index][0] = (float) (xs / W);
      buffer[index][1] = (float) (ys / H);
    }

    for (int y = 0; y < map.getHeight(); y++) {
      final double lx2 = K2 * (y + 0.5) + C2;
      final double lx3 = K3 * (y + 0.5) + C3;
      for (int x = 0; x < map.getWidth(); x++) {
        if (x + 0.5 < lx2) {
          map.setSamples(x, y, 0, 0);
        } else if (x + 0.5 >= lx3 - 1) {
          map.setSamples(x, y, 1, 0);
        } else {
          final double len = Math.abs((x + 0.5) - K2 * (y + 0.5) - C2) / HYPOT;
          final int index = (int) Math.round(len / STEP);
          map.setSamples(x, y, buffer[index][0], buffer[index][1]);
        }
      }
    }
  }
Пример #17
0
  public PathSample() {
    super(180, 90);
    // Create path shape - square
    Path path1 = new Path();
    path1
        .getElements()
        .addAll(
            new MoveTo(25, 25),
            new HLineTo(65),
            new VLineTo(65),
            new LineTo(25, 65),
            new ClosePath());
    path1.setFill(null);
    path1.setStroke(Color.RED);
    path1.setStrokeWidth(2);

    // Create path shape - curves
    Path path2 = new Path();
    path2
        .getElements()
        .addAll(
            new MoveTo(100, 45),
            new CubicCurveTo(120, 20, 130, 80, 140, 45),
            new QuadCurveTo(150, 0, 160, 45),
            new ArcTo(20, 40, 0, 180, 45, true, true));
    path2.setFill(null);
    path2.setStroke(Color.DODGERBLUE);
    path2.setStrokeWidth(2);

    // show the path shapes;
    getChildren().add(new Group(path1, path2));
    // REMOVE ME
    setControls(
        new SimplePropertySheet.PropDesc("Path 1 Stroke", path1.strokeProperty()),
        new SimplePropertySheet.PropDesc("Path 2 Stroke", path2.strokeProperty()));
    // END REMOVE ME
  }
Пример #18
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);
  }