예제 #1
0
 /** close the dialog */
 public void close() {
   animation.setRate(-1);
   animation.play();
   animation.setOnFinished(
       (e) -> {
         resetProperties();
         onDialogClosedProperty.get().handle(new JFXDialogEvent(JFXDialogEvent.CLOSED));
         dialogContainer.getChildren().remove(this);
       });
 }
예제 #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();
  }