示例#1
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;
  }
示例#2
0
  public void update(Point2D center, Dimension2D dim) {
    moveTo1.setX(center.getX() - 10);
    moveTo1.setY(center.getY());

    lineTo1.setX(center.getX() + 10);
    lineTo1.setY(center.getY());

    moveTo2.setX(center.getX());
    moveTo2.setY(center.getY() - 10);

    lineTo2.setX(center.getX());
    lineTo2.setY(center.getY() + 10);
  }
示例#3
0
  public ObservableList<PathElement> pathChanger(
      ObservableList<PathElement> elements, double angle) {
    MoveTo moveTo = (MoveTo) elements.get(0);
    LineTo lineToSecond = (LineTo) elements.get(1);
    LineTo lineToThird = (LineTo) elements.get(2);
    LineTo lineToFourth = (LineTo) elements.get(3);
    LineTo lineToFifth = (LineTo) elements.get(4);
    LineTo lineToSixth = (LineTo) elements.get(5);
    LineTo lineToSeventh = (LineTo) elements.get(6);
    LineTo lineToEighth = (LineTo) elements.get(7);

    double x = moveTo.getX();
    double y = moveTo.getY();
    double[] res = rotationCoordinates(new double[] {x, y}, angle);

    moveTo.setX(res[0]);
    moveTo.setY(res[1]);

    x = lineToSecond.getX();
    y = lineToSecond.getY();

    res = rotationCoordinates(new double[] {x, y}, angle);

    lineToSecond.setX(res[0]);
    lineToSecond.setY(res[1]);

    x = lineToThird.getX();
    y = lineToThird.getY();
    res = rotationCoordinates(new double[] {x, y}, angle);

    lineToThird.setX(res[0]);
    lineToThird.setY(res[1]);

    x = lineToFourth.getX();
    y = lineToFourth.getY();
    res = rotationCoordinates(new double[] {x, y}, angle);

    lineToFourth.setX(res[0]);
    lineToFourth.setY(res[1]);

    x = lineToFifth.getX();
    y = lineToFifth.getY();
    res = rotationCoordinates(new double[] {x, y}, angle);

    lineToFifth.setX(res[0]);
    lineToFifth.setY(res[1]);

    x = lineToSixth.getX();
    y = lineToSixth.getY();
    res = rotationCoordinates(new double[] {x, y}, angle);

    lineToSixth.setX(res[0]);
    lineToSixth.setY(res[1]);

    x = lineToSeventh.getX();
    y = lineToSeventh.getY();
    res = rotationCoordinates(new double[] {x, y}, angle);

    lineToSeventh.setX(res[0]);
    lineToSeventh.setY(res[1]);

    x = lineToEighth.getX();
    y = lineToEighth.getY();
    res = rotationCoordinates(new double[] {x, y}, angle);

    lineToEighth.setX(res[0]);
    lineToEighth.setY(res[1]);

    elements.remove(0, 8);
    elements.add(0, moveTo);
    elements.add(1, lineToSecond);
    elements.add(2, lineToThird);
    elements.add(3, lineToFourth);
    elements.add(4, lineToFifth);
    elements.add(5, lineToSixth);
    elements.add(6, lineToSeventh);
    elements.add(7, lineToEighth);
    return elements;
  }
示例#4
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();
    }
  }