Exemplo 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
  }
Exemplo 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;
 }
Exemplo n.º 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;
  }
Exemplo n.º 4
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);
  }
  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);
  }
Exemplo n.º 6
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);
  }