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();
  }
예제 #2
0
  private void shiftDock() {
    long now = System.currentTimeMillis();
    Rectangle2D cfgBounds = Client.getConfiguredBounds();

    // The bounds to work in
    int boundsSize = cfg.isVertical() ? (int) cfgBounds.getHeight() : (int) cfgBounds.getWidth();

    // Total amount to slide
    int value = cfg.sizeProperty().get() - AUTOHIDE_TAB_OPPOSITE_SIZE;

    // How far along the timeline?
    float fac = Math.min(1f, 1f - ((float) (yEnd - now) / (float) AUTOHIDE_DURATION));

    // The amount of movement so far
    float amt = fac * (float) value;

    // The amount to shrink the width (or height when vertical) of the
    // visible 'bar'
    float barSize = (float) boundsSize * fac;

    // If showing, reverse
    final boolean fhidden = hidden;

    if (!hidden) {
      amt = value - amt;
      barSize = (float) boundsSize - barSize;
      if (!pull.isVisible()) pull.setVisible(true);
    }

    // Reveal or hide the pull tab
    dockContent.setOpacity(hidden ? 1f - fac : fac);
    pull.setOpacity((hidden ? fac : 1f - fac) * 0.5f);

    Stage stage = getStage();
    if (stage != null) {
      if (cfg.topProperty().get()) {
        getScene().getRoot().translateYProperty().set(-amt);
        stage.setHeight(cfg.sizeProperty().get() - amt + Client.DROP_SHADOW_SIZE);
        stage.setWidth(Math.max(AUTOHIDE_TAB_SIZE, cfgBounds.getWidth() - barSize));
        stage.setX(cfgBounds.getMinX() + ((cfgBounds.getWidth() - stage.getWidth()) / 2f));
      } else if (cfg.bottomProperty().get()) {
        stage.setY(cfgBounds.getMaxY() + amt);
        stage.setHeight(cfg.sizeProperty().get() - amt + Client.DROP_SHADOW_SIZE);
        stage.setWidth(Math.max(AUTOHIDE_TAB_SIZE, cfgBounds.getWidth() - barSize));
        stage.setX(cfgBounds.getMinX() + ((cfgBounds.getWidth() - stage.getWidth()) / 2f));
      } else if (cfg.leftProperty().get()) {
        getScene().getRoot().translateXProperty().set(-amt);
        stage.setWidth(cfg.sizeProperty().get() - amt);
        stage.setHeight(Math.max(AUTOHIDE_TAB_SIZE, cfgBounds.getHeight() - barSize));
        stage.setY(cfgBounds.getMinY() + ((cfgBounds.getHeight() - stage.getHeight()) / 2f));
      } else if (cfg.rightProperty().get()) {
        stage.setX(cfgBounds.getMaxX() + amt - cfg.sizeProperty().get());
        stage.setWidth(cfg.sizeProperty().get() - amt);
        stage.setHeight(Math.max(AUTOHIDE_TAB_SIZE, cfgBounds.getHeight() - barSize));
        stage.setY(cfgBounds.getMinY() + ((cfgBounds.getHeight() - stage.getHeight()) / 2f));
      } else {
        throw new UnsupportedOperationException();
      }
    }

    // The update or the sign in dialog may have been popped, so make sure
    // it is position correctly
    if (signInPopup != null && signInPopup.isShowing()) {
      signInPopup.sizeToScene();
    }

    // If not fully hidden / revealed, play again
    if (now < yEnd) {
      dockHider.playFromStart();
    } else {
      // Defer this as events may still be coming in
      Platform.runLater(
          new Runnable() {
            @Override
            public void run() {
              if (!fhidden && stage != null) {
                stage.requestFocus();
                pull.setVisible(false);
              }
              hiding = false;
            }
          });
    }
  }
  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();
  }