Esempio n. 1
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
  }
Esempio n. 2
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;
 }
Esempio n. 3
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);
  }