Java Code Examples for javafx.animation.SequentialTransition#setOnFinished()

The following examples show how to use javafx.animation.SequentialTransition#setOnFinished() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChartLayoutAnimator.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
/**
 * Play a animation containing the given keyframes.
 *
 * @param animation The animation to play
 * @return A id reference to the animation that can be used to stop the animation if needed
 */
public Object animate(Animation animation) {
    SequentialTransition t = new SequentialTransition();
    t.getChildren().add(animation);
    t.setOnFinished(this);
    // start animation timer if needed
    if (activeTimeLines.isEmpty())
        start();
    // get id and add to map
    activeTimeLines.put(t, t);
    // play animation
    t.play();
    return t;

}
 
Example 2
Source File: Splash.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
/** Close the splash screen */
public void close()
{
    // Keep the splash for another 3 seconds
    // (so in case of fast startup it's at least shown 3 secs),
    // then fade out.
    final PauseTransition pause = new PauseTransition(Duration.seconds(3));
    final FadeTransition fade = new FadeTransition(Duration.seconds(1.5), stage.getScene().getRoot());
    fade.setFromValue(1.0);
    fade.setToValue(0);

    final SequentialTransition animation = new SequentialTransition(pause, fade);
    animation.setOnFinished(event -> stage.close());
    animation.play();
}
 
Example 3
Source File: RippleEffect.java    From pmd-designer with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public RippleEffect(ReadOnlyDoubleProperty containerWidth,
                    ReadOnlyDoubleProperty containerHeight,
                    Supplier<Background> containerBackground) {
    circleRipple = new Circle(0.1, rippleColor);
    circleRipple.setOpacity(0.0);
    // Optional box blur on ripple - smoother ripple effect
    //circleRipple.setEffect(new BoxBlur(3, 3, 2));
    // Fade effect bit longer to show edges on the end of animation
    final FadeTransition fadeTransition = new FadeTransition(rippleDuration, circleRipple);
    fadeTransition.setInterpolator(Interpolator.EASE_OUT);
    fadeTransition.setFromValue(1.0);
    fadeTransition.setToValue(0.0);
    final Timeline scaleRippleTimeline = new Timeline();
    final SequentialTransition parallelTransition = new SequentialTransition();
    parallelTransition.getChildren().addAll(
        scaleRippleTimeline,
        fadeTransition
    );
    // When ripple transition is finished then reset circleRipple to starting point
    parallelTransition.setOnFinished(event -> {
        circleRipple.setOpacity(0.0);
        circleRipple.setRadius(0.1);
    });
    this.handler = event -> {
        parallelTransition.stop();
        // Manually fire finish event
        parallelTransition.getOnFinished().handle(null);
        circleRipple.setCenterX(event.getX());
        circleRipple.setCenterY(event.getY());
        // Recalculate ripple size if size of button from last time was changed
        if (containerWidth.get() != lastRippleWidth || containerHeight.get() != lastRippleHeight) {
            lastRippleWidth = containerWidth.get();
            lastRippleHeight = containerHeight.get();
            rippleClip.setWidth(lastRippleWidth);
            rippleClip.setHeight(lastRippleHeight);
            try {
                rippleClip.setArcHeight(containerBackground.get().getFills().get(0).getRadii().getTopLeftHorizontalRadius());
                rippleClip.setArcWidth(containerBackground.get().getFills().get(0).getRadii().getTopLeftHorizontalRadius());
                circleRipple.setClip(rippleClip);
            } catch (Exception ignored) {
                // try block because of possible null of Background, fills ...
            }
            // Getting 45% of longest button's length, because we want edge of ripple effect always visible
            double circleRippleRadius = Math.max(containerHeight.get(), containerWidth.get()) * 0.45;
            final KeyValue keyValue = new KeyValue(circleRipple.radiusProperty(), circleRippleRadius, Interpolator.EASE_OUT);
            final KeyFrame keyFrame = new KeyFrame(rippleDuration, keyValue);
            scaleRippleTimeline.getKeyFrames().clear();
            scaleRippleTimeline.getKeyFrames().add(keyFrame);
        }
        parallelTransition.playFromStart();
    };
}
 
Example 4
Source File: MaterialDesignToggleButton.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
private void createRippleEffect() {
        circleRipple = new Circle(0.1, rippleColor);
        circleRipple.setOpacity(0.0);
        // Optional box blur on ripple - smoother ripple effect
//        circleRipple.setEffect(new BoxBlur(3, 3, 2));

        // Fade effect bit longer to show edges on the end
        final FadeTransition fadeTransition = new FadeTransition(rippleDuration, circleRipple);
        fadeTransition.setInterpolator(Interpolator.EASE_OUT);
        fadeTransition.setFromValue(1.0);
        fadeTransition.setToValue(0.0);

        final Timeline scaleRippleTimeline = new Timeline();

        final SequentialTransition parallelTransition = new SequentialTransition();
        parallelTransition.getChildren().addAll(
                scaleRippleTimeline,
                fadeTransition
        );

        parallelTransition.setOnFinished(event1 -> {
            circleRipple.setOpacity(0.0);
            circleRipple.setRadius(0.1);
        });

        this.addEventHandler(MouseEvent.MOUSE_EXITED, event -> {
        	this.setCursor(Cursor.DEFAULT);
        });

        this.addEventHandler(MouseEvent.MOUSE_ENTERED, event -> {
        	this.setCursor(Cursor.HAND);
        });


        this.addEventHandler(MouseEvent.MOUSE_PRESSED, event -> {
            parallelTransition.stop();
            parallelTransition.getOnFinished().handle(null);

            circleRipple.setCenterX(event.getX());
            circleRipple.setCenterY(event.getY());

            // Recalculate ripple size if size of button from last time was changed
            if (getWidth() != lastRippleWidth || getHeight() != lastRippleHeight)
            {
                lastRippleWidth = getWidth();
                lastRippleHeight = getHeight();

                rippleClip.setWidth(lastRippleWidth);
                rippleClip.setHeight(lastRippleHeight);

                try {
                    rippleClip.setArcHeight(this.getBackground().getFills().get(0).getRadii().getTopLeftHorizontalRadius());
                    rippleClip.setArcWidth(this.getBackground().getFills().get(0).getRadii().getTopLeftHorizontalRadius());
                    circleRipple.setClip(rippleClip);
                } catch (Exception e) {

                }

                // Getting 45% of longest button's length, because we want edge of ripple effect always visible
                double circleRippleRadius = Math.max(getHeight(), getWidth()) * 0.45;
                final KeyValue keyValue = new KeyValue(circleRipple.radiusProperty(), circleRippleRadius, Interpolator.EASE_OUT);
                final KeyFrame keyFrame = new KeyFrame(rippleDuration, keyValue);
                scaleRippleTimeline.getKeyFrames().clear();
                scaleRippleTimeline.getKeyFrames().add(keyFrame);
            }

            parallelTransition.playFromStart();
        });
    }
 
Example 5
Source File: MaterialDesignButton.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
private void createRippleEffect() {
        circleRipple = new Circle(0.1, rippleColor);
        circleRipple.setOpacity(0.0);
        // Optional box blur on ripple - smoother ripple effect
//        circleRipple.setEffect(new BoxBlur(3, 3, 2));

        // Fade effect bit longer to show edges on the end
        final FadeTransition fadeTransition = new FadeTransition(rippleDuration, circleRipple);
        fadeTransition.setInterpolator(Interpolator.EASE_OUT);
        fadeTransition.setFromValue(1.0);
        fadeTransition.setToValue(0.0);

        final Timeline scaleRippleTimeline = new Timeline();

        final SequentialTransition parallelTransition = new SequentialTransition();
        parallelTransition.getChildren().addAll(
                scaleRippleTimeline,
                fadeTransition
        );

        parallelTransition.setOnFinished(event1 -> {
            circleRipple.setOpacity(0.0);
            circleRipple.setRadius(0.1);
        });

        this.addEventHandler(MouseEvent.MOUSE_PRESSED, event -> {
            parallelTransition.stop();
            parallelTransition.getOnFinished().handle(null);

            circleRipple.setCenterX(event.getX());
            circleRipple.setCenterY(event.getY());

            // Recalculate ripple size if size of button from last time was changed
            if (getWidth() != lastRippleWidth || getHeight() != lastRippleHeight)
            {
                lastRippleWidth = getWidth();
                lastRippleHeight = getHeight();

                rippleClip.setWidth(lastRippleWidth);
                rippleClip.setHeight(lastRippleHeight);

                try {
                    rippleClip.setArcHeight(this.getBackground().getFills().get(0).getRadii().getTopLeftHorizontalRadius());
                    rippleClip.setArcWidth(this.getBackground().getFills().get(0).getRadii().getTopLeftHorizontalRadius());
                    circleRipple.setClip(rippleClip);
                } catch (Exception e) {

                }

                // Getting 45% of longest button's length, because we want edge of ripple effect always visible
                double circleRippleRadius = Math.max(getHeight(), getWidth()) * 0.45;
                final KeyValue keyValue = new KeyValue(circleRipple.radiusProperty(), circleRippleRadius, Interpolator.EASE_OUT);
                final KeyFrame keyFrame = new KeyFrame(rippleDuration, keyValue);
                scaleRippleTimeline.getKeyFrames().clear();
                scaleRippleTimeline.getKeyFrames().add(keyFrame);
            }

            parallelTransition.playFromStart();
        });
    }
 
Example 6
Source File: FadeInCloudStep.java    From TweetwallFX with MIT License 4 votes vote down vote up
@Override
public void doStep(final MachineContext context) {
    List<Word> sortedWords = context.getDataProvider(TagCloudDataProvider.class).getWords();

    if (sortedWords.isEmpty()) {
        return;
    }

    WordleSkin wordleSkin = (WordleSkin) context.get("WordleSkin");
    List<Word> limitedWords = sortedWords.stream().limit(wordleSkin.getDisplayCloudTags()).collect(Collectors.toList());
    limitedWords.sort(Comparator.reverseOrder());

    Bounds layoutBounds = wordleSkin.getPane().getLayoutBounds();

    WordleLayout.Configuration configuration = new WordleLayout.Configuration(limitedWords, wordleSkin.getFont(), wordleSkin.getFontSizeMax(), layoutBounds);
    if (null != wordleSkin.getLogo()) {
        configuration.setBlockedAreaBounds(wordleSkin.getLogo().getBoundsInParent());
    }
    if (null != wordleSkin.getSecondLogo()) {
        configuration.setBlockedAreaBounds(wordleSkin.getSecondLogo().getBoundsInParent());
    }
    WordleLayout cloudWordleLayout = WordleLayout.createWordleLayout(configuration);
    Duration defaultDuration = Duration.seconds(1.5);

    List<Transition> fadeOutTransitions = new ArrayList<>();
    List<Transition> moveTransitions = new ArrayList<>();
    List<Transition> fadeInTransitions = new ArrayList<>();

    cloudWordleLayout.getWordLayoutInfo().entrySet().stream().forEach(entry -> {
        Word word = entry.getKey();
        Bounds bounds = entry.getValue();
        Text textNode = cloudWordleLayout.createTextNode(word);
        wordleSkin.word2TextMap.put(word, textNode);
        textNode.setLayoutX(bounds.getMinX() + layoutBounds.getWidth() / 2d);
        textNode.setLayoutY(bounds.getMinY() + layoutBounds.getHeight() / 2d + bounds.getHeight() / 2d);
        textNode.setOpacity(0);
        wordleSkin.getPane().getChildren().add(textNode);
        FadeTransition ft = new FadeTransition(defaultDuration, textNode);
        ft.setToValue(1);
        fadeInTransitions.add(ft);
    });

    ParallelTransition fadeOuts = new ParallelTransition();
    fadeOuts.getChildren().addAll(fadeOutTransitions);
    ParallelTransition moves = new ParallelTransition();
    moves.getChildren().addAll(moveTransitions);
    ParallelTransition fadeIns = new ParallelTransition();
    fadeIns.getChildren().addAll(fadeInTransitions);
    SequentialTransition morph = new SequentialTransition(fadeOuts, moves, fadeIns);

    morph.setOnFinished(e -> context.proceed());
    morph.play();
}