예제 #1
0
  /*
   * Show a dialog window with the given node as the root node, and perform
   * the given action when the dialog is shown.
   */
  private static void showDialog(Parent root, final OnShownAction onShown) {

    // Create an undecorated modal stage, with the main window as its owner,
    // and the given root as its content

    final Stage dialog = new Stage(StageStyle.UNDECORATED);
    dialog.initModality(Modality.WINDOW_MODAL);

    final Window owner = Model.getInstance().getMainWindow();
    dialog.initOwner(owner);

    dialog.setScene(new Scene(root));

    dialog.setOnShown(
        new EventHandler<WindowEvent>() {
          @Override
          public void handle(WindowEvent t) {

            // Center the dialog within the main window.
            dialog.setX(owner.getX() + owner.getWidth() / 2 - dialog.getWidth() / 2);
            dialog.setY(owner.getY() + owner.getHeight() / 2 - dialog.getHeight() / 2);

            // Perform the optional callback.
            if (onShown != null) {
              onShown.perform();
            }
          }
        });

    // Fade out the main window, show the dialog, wait for it the closed,
    // then fade the main window back in.

    FadeTransitionBuilder.create().node(owner.getScene().getRoot()).toValue(0.25).build().play();

    dialog.showAndWait();

    FadeTransitionBuilder.create().node(owner.getScene().getRoot()).toValue(1).build().play();
  }
예제 #2
0
  public Animations(
      Node toAnimate,
      boolean initiallyVisible,
      Duration slideDown,
      Duration slideUp,
      Duration fadeIn,
      Duration fadeAway) {
    this.toAnimate = toAnimate;
    toAnimate.setVisible(initiallyVisible);
    state = initiallyVisible ? State.VISIBLE : State.HIDDEN;

    SLIDE_DOWN =
        TranslateTransitionBuilder.create()
            .fromY(-200)
            .toY(0)
            .node(toAnimate)
            .duration(slideDown)
            .onFinished(
                new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent arg0) {
                    toVisibleState();
                  }
                })
            .build();

    SLIDE_UP =
        TranslateTransitionBuilder.create()
            .fromY(0)
            .toY(-200)
            .node(toAnimate)
            .duration(slideUp)
            .onFinished(
                new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent arg0) {
                    toHiddenState();
                  }
                })
            .build();

    FADE_AWAY =
        FadeTransitionBuilder.create()
            .node(toAnimate)
            .fromValue(1)
            .toValue(0)
            .duration(fadeAway)
            .onFinished(
                new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent arg0) {
                    toHiddenState();
                  }
                })
            .build();
    FADE_IN =
        FadeTransitionBuilder.create()
            .node(toAnimate)
            .fromValue(0)
            .toValue(1)
            .duration(fadeIn)
            .onFinished(
                new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent arg0) {
                    toVisibleState();
                  }
                })
            .build();
  }