Java Code Examples for javafx.animation.Transition#play()

The following examples show how to use javafx.animation.Transition#play() . 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: CustomSliderSkin.java    From MusicPlayer with MIT License 5 votes vote down vote up
/**
 * Called when ever either min, max or value changes, so thumb's layoutX, Y is recomputed.
 */
private void positionThumb(final boolean animate) {
    Slider s = getSkinnable();
    if (s.getValue() > s.getMax()) return;// this can happen if we are bound to something 
    boolean horizontal = s.getOrientation() == Orientation.HORIZONTAL;
    final double endX = (horizontal) ? trackStart + (((trackLength * ((s.getValue() - s.getMin()) /
            (s.getMax() - s.getMin()))) - thumbWidth/2)) : thumbLeft;
    final double endY = (horizontal) ? thumbTop :
        snappedTopInset() + trackLength - (trackLength * ((s.getValue() - s.getMin()) /
            (s.getMax() - s.getMin()))); //  - thumbHeight/2
    
    if (animate) {
        // lets animate the thumb transition
        final double startX = thumb.getLayoutX();
        final double startY = thumb.getLayoutY();
        Transition transition = new Transition() {
            {
                setCycleDuration(Duration.millis(200));
            }

            @Override protected void interpolate(double frac) {
                if (!Double.isNaN(startX)) {
                    thumb.setLayoutX(startX + frac * (endX - startX));
                }
                if (!Double.isNaN(startY)) {
                    thumb.setLayoutY(startY + frac * (endY - startY));
                }
            }
        };
        transition.play();
    } else {
        thumb.setLayoutX(endX);
        thumb.setLayoutY(endY);
    }
}
 
Example 2
Source File: ImageMosaicStep.java    From TweetwallFX with MIT License 5 votes vote down vote up
@Override
public void doStep(final MachineContext context) {
    WordleSkin wordleSkin = (WordleSkin) context.get("WordleSkin");
    ImageMosaicDataProvider dataProvider = context.getDataProvider(ImageMosaicDataProvider.class);
    pane = wordleSkin.getPane();
    if (dataProvider.getImages().size() < 35) {
        context.proceed();
    } else {
        Transition createMosaicTransition = createMosaicTransition(dataProvider.getImages());
        createMosaicTransition.setOnFinished(event
                -> executeAnimations(context));

        createMosaicTransition.play();
    }
}