/** * ************************************************************************* * Transitions * * * ************************************************************************ */ private Transition getShowAnimation(DialogTransition transitionType) { Transition animation = null; if (contentHolder != null) { switch (transitionType) { case LEFT: contentHolder.setTranslateX(-offsetX); animation = new LeftTransition(); break; case RIGHT: contentHolder.setTranslateX(offsetX); animation = new RightTransition(); break; case TOP: contentHolder.setTranslateY(-offsetY); animation = new TopTransition(); break; case BOTTOM: contentHolder.setTranslateY(offsetY); animation = new BottomTransition(); break; default: contentHolder.setScaleX(0); contentHolder.setScaleY(0); animation = new CenterTransition(); break; } } if (animation != null) animation.setOnFinished( (finish) -> onDialogOpenedProperty.get().handle(new JFXDialogEvent(JFXDialogEvent.OPENED))); return animation; }
public Then then(final Runnable action) { if (listener == null) { listener = new FinishedListener(); prevHandler = transition.getOnFinished(); transition.setOnFinished(listener); } runnables.add(action); return this; }
/** 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); }); }
public com.zenjava.jfxflow.actvity.Transition createTransition( final Pane container, final Activity fromActivity, Activity toActivity) { Transition transition = createMainTransition(fromActivity, toActivity); ViewTransition exit = null; if (fromActivity != null) { if (fromActivity instanceof HasExitTransition) { exit = ((HasExitTransition) fromActivity).getExitTransition(); } else { exit = getDefaultExitTransition(fromActivity.getView().toNode()); } exit.setupBeforeAnimation(container.getBoundsInParent()); addAnimation(transition, exit.getAnimation()); } ViewTransition entry = null; if (toActivity != null) { if (toActivity instanceof HasEntryTransition) { entry = ((HasEntryTransition) toActivity).getEntryTransition(); } else { entry = getDefaultEntryTransition(toActivity.getView().toNode()); } entry.setupBeforeAnimation(container.getBoundsInParent()); addAnimation(transition, entry.getAnimation()); addView(container, toActivity.getView().toNode()); } final ViewTransition finalExit = exit; final ViewTransition finalEntry = entry; transition.setOnFinished( new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { if (fromActivity != null) { removeView(container, fromActivity.getView().toNode()); } if (finalEntry != null) { finalEntry.cleanupAfterAnimation(); } if (finalExit != null) { finalExit.cleanupAfterAnimation(); } } }); return new FxAnimation(transition); }
/** show the dialog inside its parent container */ public void show() { this.setDialogContainer(dialogContainer); // animation = getShowAnimation(transitionType.get()); animation.play(); }
/** * it will show the dialog in the specified container * * @param dialogContainer */ public void show(StackPane dialogContainer) { this.setDialogContainer(dialogContainer); animation.play(); }
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(); }
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(); }
public void animate(Tkey key) { Transition transition = new SpriteTransition(key); transition.play(); }