public MaterialToolbar() {
    getStyleClass().add("material-toolbar");
    mainIcon = new AnimatedIcon();
    mainIcon.setIconFill(Color.WHITE);

    changeViewAnimationCircle = new Circle();
    changeViewAnimationCircle.setOpacity(0);
    changeViewAnimationCircle.setManaged(false);

    currentTitle = new Label("Main");
    currentTitle.getStyleClass().add("material-toolbar-text");

    changeViewAnimationTitle = new Label();
    changeViewAnimationTitle.setOpacity(0);
    changeViewAnimationTitle.getStyleClass().add("material-toolbar-text");

    background = new Rectangle();
    background.setManaged(false);
    background.setFill(Color.DARKSLATEBLUE);

    backgroundClip = new Rectangle();
    backgroundClip.setFill(Color.BLACK);
    backgroundClip.xProperty().bind(background.xProperty());
    backgroundClip.yProperty().bind(background.yProperty());
    backgroundClip.widthProperty().bind(background.widthProperty());
    backgroundClip.heightProperty().bind(background.heightProperty());
    changeViewAnimationCircle.setClip(backgroundClip);

    actionBox = new HBox();
    actionBox.setSpacing(6);

    getChildren()
        .addAll(
            mainIcon,
            changeViewAnimationCircle,
            currentTitle,
            changeViewAnimationTitle,
            background,
            actionBox);

    background.toBack();
    changeViewAnimationCircle.toFront();
    changeViewAnimationTitle.toFront();
    currentTitle.toFront();
    mainIcon.toFront();
    actionBox.toFront();
  }
  public void animateTo(Color color, String title, IconType iconType, ToolbarAction... actions) {
    changeViewAnimationCircle.setOpacity(0);
    changeViewAnimationCircle.setFill(color);

    changeViewAnimationTitle.setOpacity(0);
    changeViewAnimationTitle.setText(title);

    Transition circleTransition =
        new Transition() {

          {
            setCycleDuration(Duration.millis(480));
          }

          @Override
          protected void interpolate(double frac) {
            changeViewAnimationCircle.setRadius((getWidth() + 32) * frac);
            changeViewAnimationCircle.setOpacity(0.2 + frac);

            currentTitle.setTranslateY(-currentTitle.getLayoutBounds().getHeight() * frac);
            currentTitle.setOpacity(1 - frac * 1.5);

            changeViewAnimationTitle.setTranslateY(
                currentTitle.getLayoutBounds().getHeight()
                    - currentTitle.getLayoutBounds().getHeight() * frac);
            changeViewAnimationTitle.setOpacity(frac);

            for (Node n : actionBox.getChildren()) {
              n.setScaleX(1 - frac);
              n.setScaleY(1 - frac);
              n.setOpacity(1 - frac);
            }
          }
        };

    circleTransition.setOnFinished(
        e -> {
          background.setFill(color);
          changeViewAnimationCircle.setOpacity(0);
          currentTitle.setTranslateY(0);
          currentTitle.setText(title);
          currentTitle.setOpacity(1);
          changeViewAnimationTitle.setOpacity(0);
          actionBox.getChildren().clear();
          actionBox.setOpacity(0);

          for (ToolbarAction action : actions) {
            Button actionButton = new Button(action.getIconText());
            actionButton.setOnAction(action.getOnAction());
            actionButton.getStyleClass().add("material-toolbar-action");
            actionBox.getChildren().add(actionButton);
          }

          Transition actionTransition =
              new Transition() {

                {
                  setCycleDuration(Duration.millis(360));
                }

                @Override
                protected void interpolate(double frac) {
                  for (Node n : actionBox.getChildren()) {
                    n.setScaleX(frac);
                    n.setScaleY(frac);
                  }
                  actionBox.setOpacity(frac);
                }
              };
          actionTransition.play();
        });

    if (iconType.equals(IconType.ARROW)) {
      mainIcon.toArrow();
    } else if (iconType.equals(IconType.BACK)) {
      mainIcon.toBack();
    } else if (iconType.equals(IconType.CLOSE)) {
      mainIcon.toClose();
    } else if (iconType.equals(IconType.MENU)) {
      mainIcon.toMenu();
    } else if (iconType.equals(IconType.PAUSE)) {
      mainIcon.toPause();
    } else if (iconType.equals(IconType.PLAY)) {
      mainIcon.toPlay();
    }

    circleTransition.play();
  }
Ejemplo n.º 3
0
  @Override
  public void initialize(URL location, ResourceBundle resources) {
    Circle cuser = new Circle(10, Color.DODGERBLUE);
    Circle cpass = new Circle(10, Color.DODGERBLUE);
    cuser.setOpacity(0);
    cpass.setOpacity(0);
    ButtonSkin users = new ButtonSkin(login);
    users.getChildren().add(0, cuser);
    login.setSkin(users);
    ButtonSkin passs = new ButtonSkin(hify);
    passs.getChildren().add(0, cpass);
    hify.setSkin(passs);
    login.setOnMousePressed(
        new EventHandler<MouseEvent>() {
          @Override
          public void handle(MouseEvent event) {
            // .println("pressed");
            cuser.setOpacity(0.5);
            cuser.setRadius(10);
            cuser.setCenterX(event.getX());
            cuser.setCenterY(event.getY());
            Rectangle r = new Rectangle();
            r.setArcHeight(
                login.getBackground().getFills().get(0).getRadii().getTopLeftVerticalRadius());
            r.setArcWidth(
                login.getBackground().getFills().get(0).getRadii().getTopLeftHorizontalRadius());
            // .println(login.getPrefWidth()+"  "+login.getPrefHeight());
            r.setWidth(login.getPrefWidth());
            r.setHeight(login.getPrefHeight());
            cuser.setClip(r);
            Timeline tl = new Timeline();
            KeyValue kv =
                new KeyValue(
                    cuser.radiusProperty(), 1.5 * login.getPrefWidth(), Interpolator.EASE_OUT);
            KeyFrame kf = new KeyFrame(Duration.millis(1500), kv);
            tl.getKeyFrames().clear();
            tl.getKeyFrames().add(kf);
            tl.play();
            await.countDown();
          }
        });
    login.setOnMouseReleased(
        new EventHandler<MouseEvent>() {
          @Override
          public void handle(MouseEvent event) {
            try {
              await.await();
            } catch (InterruptedException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }

            awaitu.countDown();
            FadeTransition fd = new FadeTransition(Duration.millis(1500), cuser);
            fd.setFromValue(0.5);
            fd.setToValue(0);
            fd.setInterpolator(Interpolator.EASE_OUT);
            fd.play();
          }
        });
    hify.setOnMousePressed(
        new EventHandler<MouseEvent>() {
          @Override
          public void handle(MouseEvent event) {
            // .println("pressed");
            cpass.setOpacity(0.5);
            cpass.setRadius(10);
            cpass.setCenterX(event.getX());
            cpass.setCenterY(event.getY());
            Rectangle r = new Rectangle();
            r.setArcHeight(
                hify.getBackground().getFills().get(0).getRadii().getTopLeftVerticalRadius());
            r.setArcWidth(
                hify.getBackground().getFills().get(0).getRadii().getTopLeftHorizontalRadius());
            r.setWidth(hify.getPrefWidth());
            r.setHeight(hify.getPrefHeight());
            cpass.setClip(r);
            Timeline tl = new Timeline();
            KeyValue kv =
                new KeyValue(
                    cpass.radiusProperty(), 1.5 * hify.getPrefWidth(), Interpolator.EASE_OUT);
            KeyFrame kf = new KeyFrame(Duration.millis(1500), kv);
            tl.getKeyFrames().clear();
            tl.getKeyFrames().add(kf);
            tl.play();
            awaitp.countDown();
          }
        });
    hify.setOnMouseReleased(
        new EventHandler<MouseEvent>() {
          @Override
          public void handle(MouseEvent event) {
            try {
              awaitp.await();
            } catch (InterruptedException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
            }
            awaitpa.countDown();
            FadeTransition fd = new FadeTransition(Duration.millis(1500), cpass);
            fd.setFromValue(0.5);
            fd.setToValue(0);
            fd.setInterpolator(Interpolator.EASE_OUT);
            fd.play();
          }
        });
    user.focusedProperty()
        .addListener(
            new ChangeListener<Boolean>() {
              @Override
              public void changed(
                  ObservableValue<? extends Boolean> observable,
                  Boolean oldValue,
                  Boolean newValue) {
                if (newValue) {
                  TranslateTransition fd = new TranslateTransition(Duration.millis(500), userlabel);
                  FadeTransition ff = new FadeTransition(Duration.millis(500), userlabel);
                  fd.setInterpolator(Interpolator.EASE_BOTH);
                  ff.setInterpolator(Interpolator.EASE_BOTH);
                  ff.setToValue(1.0);
                  ff.setFromValue(0.0);
                  fd.setByY(-3);
                  ParallelTransition pt = new ParallelTransition();
                  pt.getChildren().addAll(fd, ff);
                  pt.play();

                } else {
                  userlabel.setTranslateY(3);
                  userlabel.setOpacity(0);
                }
              }
            });
    pass.focusedProperty()
        .addListener(
            new ChangeListener<Boolean>() {

              @Override
              public void changed(
                  ObservableValue<? extends Boolean> observable,
                  Boolean oldValue,
                  Boolean newValue) {
                if (newValue) {
                  TranslateTransition fd = new TranslateTransition(Duration.millis(500), passlabel);
                  FadeTransition ff = new FadeTransition(Duration.millis(500), passlabel);
                  fd.setInterpolator(Interpolator.EASE_BOTH);
                  ff.setInterpolator(Interpolator.EASE_BOTH);
                  ff.setToValue(1.0);
                  ff.setFromValue(0.0);
                  fd.setByY(-3);
                  ParallelTransition pt = new ParallelTransition();
                  pt.getChildren().addAll(fd, ff);
                  pt.play();

                } else {
                  passlabel.setTranslateY(3);
                  passlabel.setOpacity(0);
                }
              }
            });
    p1.setEffect(new DropShadow());
  }