Esempio n. 1
0
  private void initialize() {
    this.setVisible(false);
    this.getStyleClass().add(DEFAULT_STYLE_CLASS);

    contentHolder = new StackPane();
    contentHolder.setBackground(
        new Background(new BackgroundFill(Color.WHITE, new CornerRadii(2), null)));
    JFXDepthManager.setDepth(contentHolder, 4);
    contentHolder.setPickOnBounds(false);
    // ensure stackpane is never resized beyond it's preferred size
    contentHolder.setMaxSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
    overlayPane = new StackPane();
    overlayPane.getChildren().add(contentHolder);
    overlayPane.getStyleClass().add("jfx-dialog-overlay-pane");
    StackPane.setAlignment(contentHolder, Pos.CENTER);
    overlayPane.setVisible(false);
    overlayPane.setBackground(
        new Background(new BackgroundFill(Color.rgb(0, 0, 0, 0.1), null, null)));
    // close the dialog if clicked on the overlay pane
    if (overlayClose.get()) overlayPane.addEventHandler(MouseEvent.MOUSE_PRESSED, closeHandler);
    // prevent propagating the events to overlay pane
    contentHolder.addEventHandler(MouseEvent.ANY, (e) -> e.consume());
  }
Esempio n. 2
0
  public JFXButtonSkin(JFXButton button) {
    super(button);

    buttonRippler =
        new JFXRippler(new StackPane()) {
          @Override
          protected Node getMask() {
            StackPane mask = new StackPane();
            mask.shapeProperty().bind(buttonContainer.shapeProperty());
            mask.backgroundProperty()
                .bind(
                    Bindings.createObjectBinding(
                        () -> {
                          return new Background(
                              new BackgroundFill(
                                  Color.WHITE,
                                  buttonContainer.backgroundProperty().get() != null
                                      ? buttonContainer.getBackground().getFills().get(0).getRadii()
                                      : defaultRadii,
                                  buttonContainer.backgroundProperty().get() != null
                                      ? buttonContainer
                                          .getBackground()
                                          .getFills()
                                          .get(0)
                                          .getInsets()
                                      : Insets.EMPTY));
                        },
                        buttonContainer.backgroundProperty()));
            mask.resize(buttonContainer.getWidth(), buttonContainer.getHeight());
            return mask;
          }

          @Override
          protected void initListeners() {
            ripplerPane.setOnMousePressed(
                (event) -> {
                  createRipple(event.getX(), event.getY());
                });
          }
        };
    buttonContainer.getChildren().add(buttonRippler);

    // add listeners to the button and bind properties
    button.buttonTypeProperty().addListener((o, oldVal, newVal) -> updateButtonType(newVal));
    button.setOnMousePressed(
        (e) -> {
          if (clickedAnimation != null) {
            clickedAnimation.setRate(1);
            clickedAnimation.play();
          }
        });
    button.setOnMouseReleased(
        (e) -> {
          if (clickedAnimation != null) {
            clickedAnimation.setRate(-1);
            clickedAnimation.play();
          }
        });

    /*
     * disable action when clicking on the button shadow
     */
    button.setPickOnBounds(false);
    buttonContainer.setPickOnBounds(false);

    buttonContainer.borderProperty().bind(getSkinnable().borderProperty());
    buttonContainer
        .backgroundProperty()
        .bind(
            Bindings.createObjectBinding(
                () -> {
                  // reset button background to transparent if its set to java default values
                  if (button.getBackground() == null
                      || isJavaDefaultBackground(button.getBackground())
                      || isJavaDefaultClickedBackground(button.getBackground()))
                    button.setBackground(
                        new Background(new BackgroundFill(Color.TRANSPARENT, defaultRadii, null)));

                  // Insets always Empty
                  if (getSkinnable().getBackground() != null
                      && getSkinnable()
                          .getBackground()
                          .getFills()
                          .get(0)
                          .getInsets()
                          .equals(new Insets(-0.2, -0.2, -0.2, -0.2))) {
                    return new Background(
                        new BackgroundFill(
                            getSkinnable().getBackground() != null
                                ? getSkinnable().getBackground().getFills().get(0).getFill()
                                : Color.TRANSPARENT,
                            getSkinnable().backgroundProperty().get() != null
                                ? getSkinnable().getBackground().getFills().get(0).getRadii()
                                : defaultRadii,
                            Insets.EMPTY /*new Insets(0,0,-1.0,0)*/));
                  } else {
                    return new Background(
                        new BackgroundFill(
                            getSkinnable().getBackground() != null
                                ? getSkinnable().getBackground().getFills().get(0).getFill()
                                : Color.TRANSPARENT,
                            getSkinnable().getBackground() != null
                                ? getSkinnable().getBackground().getFills().get(0).getRadii()
                                : defaultRadii,
                            Insets
                                .EMPTY /*getSkinnable().backgroundProperty().get()!=null?getSkinnable().getBackground().getFills().get(0).getInsets() : Insets.EMPTY*/));
                  }
                },
                getSkinnable().backgroundProperty()));

    button
        .ripplerFillProperty()
        .addListener((o, oldVal, newVal) -> buttonRippler.setRipplerFill(newVal));

    // set default background to transparent
    if (button.getBackground() == null || isJavaDefaultBackground(button.getBackground()))
      button.setBackground(
          new Background(new BackgroundFill(Color.TRANSPARENT, defaultRadii, null)));

    updateButtonType(button.getButtonType());
    updateChildren();
  }