Search in sources :

Example 1 with PauseTransition

use of javafx.animation.PauseTransition in project tray by qzind.

the class WebApp method capture.

/**
 * Sets up capture to run on JavaFX thread and returns snapshot of rendered page
 *
 * @param model Data about the html to be rendered for capture
 * @return BufferedImage of the rendered html
 */
public static synchronized BufferedImage capture(final WebAppModel model) throws Throwable {
    final AtomicReference<BufferedImage> capture = new AtomicReference<>();
    complete.set(false);
    thrown.set(null);
    // ensure JavaFX has started before we run
    if (webView == null) {
        throw new IOException("JavaFX has not been started");
    }
    // run these actions on the JavaFX thread
    Platform.runLater(new Thread() {

        public void run() {
            try {
                pageWidth = model.getWebWidth();
                pageHeight = model.getWebHeight();
                pageZoom = model.getZoom();
                webView.setMinSize(100, 100);
                webView.setPrefSize(100, 100);
                webView.autosize();
                // FIXME - will not capture without showing stage
                stage.show();
                stage.toBack();
                // ran when engine reaches SUCCEEDED state, takes snapshot of loaded html
                snap = new PauseTransition(Duration.millis(100));
                snap.setOnFinished(new EventHandler<ActionEvent>() {

                    @Override
                    public void handle(ActionEvent actionEvent) {
                        try {
                            log.debug("Attempting image capture");
                            WritableImage snapshot = webView.snapshot(new SnapshotParameters(), null);
                            capture.set(SwingFXUtils.fromFXImage(snapshot, null));
                            complete.set(true);
                        } catch (Throwable t) {
                            thrown.set(t);
                        } finally {
                            // hide stage so users won't have to manually close it
                            stage.hide();
                        }
                    }
                });
                // actually begin loading the html
                if (model.isPlainText()) {
                    webView.getEngine().loadContent(model.getSource(), "text/html");
                } else {
                    webView.getEngine().load(model.getSource());
                }
            } catch (Throwable t) {
                thrown.set(t);
            }
        }
    });
    Throwable t = null;
    while (!complete.get() && (t = thrown.get()) == null) {
        log.trace("Waiting on capture..");
        try {
            Thread.sleep(1000);
        } catch (Exception ignore) {
        }
    }
    if (t != null) {
        throw t;
    }
    return capture.get();
}
Also used : WritableImage(javafx.scene.image.WritableImage) SnapshotParameters(javafx.scene.SnapshotParameters) ActionEvent(javafx.event.ActionEvent) EventHandler(javafx.event.EventHandler) AtomicReference(java.util.concurrent.atomic.AtomicReference) PauseTransition(javafx.animation.PauseTransition) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) ReflectException(org.joor.ReflectException) IOException(java.io.IOException)

Example 2 with PauseTransition

use of javafx.animation.PauseTransition in project Board-Instrumentation-Framework by intel.

the class RadialBargraphSkin method fadeBackToInteractive.

private void fadeBackToInteractive() {
    FadeTransition fadeUnitOut = new FadeTransition(Duration.millis(425), unit);
    fadeUnitOut.setFromValue(1.0);
    fadeUnitOut.setToValue(0.0);
    FadeTransition fadeValueOut = new FadeTransition(Duration.millis(425), value);
    fadeValueOut.setFromValue(1.0);
    fadeValueOut.setToValue(0.0);
    PauseTransition pause = new PauseTransition(Duration.millis(50));
    FadeTransition fadeUnitIn = new FadeTransition(Duration.millis(425), unit);
    fadeUnitIn.setFromValue(0.0);
    fadeUnitIn.setToValue(1.0);
    FadeTransition fadeValueIn = new FadeTransition(Duration.millis(425), value);
    fadeValueIn.setFromValue(0.0);
    fadeValueIn.setToValue(1.0);
    ParallelTransition parallelIn = new ParallelTransition(fadeUnitIn, fadeValueIn);
    ParallelTransition parallelOut = new ParallelTransition(fadeUnitOut, fadeValueOut);
    parallelOut.setOnFinished(event -> {
        unit.setText("Interactive");
        value.setText("");
        resizeText();
    });
    SequentialTransition sequence = new SequentialTransition(parallelOut, pause, parallelIn);
    sequence.play();
}
Also used : SequentialTransition(javafx.animation.SequentialTransition) FadeTransition(javafx.animation.FadeTransition) PauseTransition(javafx.animation.PauseTransition) ParallelTransition(javafx.animation.ParallelTransition)

Example 3 with PauseTransition

use of javafx.animation.PauseTransition in project Board-Instrumentation-Framework by intel.

the class HeatControlSkin method fadeBack.

private void fadeBack() {
    FadeTransition fadeInfoTextOut = new FadeTransition(Duration.millis(425), infoText);
    fadeInfoTextOut.setFromValue(1.0);
    fadeInfoTextOut.setToValue(0.0);
    FadeTransition fadeValueOut = new FadeTransition(Duration.millis(425), value);
    fadeValueOut.setFromValue(1.0);
    fadeValueOut.setToValue(0.0);
    PauseTransition pause = new PauseTransition(Duration.millis(50));
    FadeTransition fadeInfoTextIn = new FadeTransition(Duration.millis(425), infoText);
    fadeInfoTextIn.setFromValue(0.0);
    fadeInfoTextIn.setToValue(1.0);
    FadeTransition fadeValueIn = new FadeTransition(Duration.millis(425), value);
    fadeValueIn.setFromValue(0.0);
    fadeValueIn.setToValue(1.0);
    ParallelTransition parallelIn = new ParallelTransition(fadeInfoTextIn, fadeValueIn);
    ParallelTransition parallelOut = new ParallelTransition(fadeInfoTextOut, fadeValueOut);
    parallelOut.setOnFinished(event -> {
        double currentValue = (valueIndicatorRotate.getAngle() + getSkinnable().getStartAngle() - 180) / angleStep + getSkinnable().getMinValue();
        value.setText(String.format(Locale.US, "%." + getSkinnable().getDecimals() + "f", currentValue));
        value.setTranslateX((size - value.getLayoutBounds().getWidth()) * 0.5);
        if (getSkinnable().getTarget() < getSkinnable().getValue()) {
            getSkinnable().setInfoText("COOLING");
        } else if (getSkinnable().getTarget() > getSkinnable().getValue()) {
            getSkinnable().setInfoText("HEATING");
        }
        resizeText();
        drawTickMarks(ticks);
        userAction = false;
    });
    SequentialTransition sequence = new SequentialTransition(parallelOut, pause, parallelIn);
    sequence.play();
}
Also used : SequentialTransition(javafx.animation.SequentialTransition) FadeTransition(javafx.animation.FadeTransition) PauseTransition(javafx.animation.PauseTransition) ParallelTransition(javafx.animation.ParallelTransition)

Example 4 with PauseTransition

use of javafx.animation.PauseTransition in project JFoenix by jfoenixadmin.

the class JFXNodeUtils method addDelayedEventHandler.

public static <T extends Event> EventHandler<? super T> addDelayedEventHandler(Node control, Duration delayTime, final EventType<T> eventType, final EventHandler<? super T> eventHandler) {
    Wrapper<T> eventWrapper = new Wrapper<>();
    PauseTransition holdTimer = new PauseTransition(delayTime);
    holdTimer.setOnFinished(finish -> eventHandler.handle(eventWrapper.content));
    final EventHandler<? super T> eventEventHandler = event -> {
        eventWrapper.content = event;
        holdTimer.playFromStart();
    };
    control.addEventHandler(eventType, eventEventHandler);
    return eventEventHandler;
}
Also used : EventHandler(javafx.event.EventHandler) MouseEvent(javafx.scene.input.MouseEvent) UnmodifiableListSet(com.sun.javafx.collections.UnmodifiableListSet) InvalidationListener(javafx.beans.InvalidationListener) ArrayList(java.util.ArrayList) BackgroundFill(javafx.scene.layout.BackgroundFill) Locale(java.util.Locale) BiConsumer(java.util.function.BiConsumer) Direction(com.sun.javafx.scene.traversal.Direction) KeyCode(javafx.scene.input.KeyCode) Color(javafx.scene.paint.Color) Node(javafx.scene.Node) Event(javafx.event.Event) Set(java.util.Set) KeyEvent(javafx.scene.input.KeyEvent) Background(javafx.scene.layout.Background) EventType(javafx.event.EventType) Consumer(java.util.function.Consumer) Duration(javafx.util.Duration) List(java.util.List) Region(javafx.scene.layout.Region) PauseTransition(javafx.animation.PauseTransition) Paint(javafx.scene.paint.Paint) ObservableValue(javafx.beans.value.ObservableValue) Queue(java.util.Queue) ArrayDeque(java.util.ArrayDeque) PauseTransition(javafx.animation.PauseTransition)

Example 5 with PauseTransition

use of javafx.animation.PauseTransition in project JFoenix by jfoenixadmin.

the class JFXSnackbar method getTimeline.

private Timeline getTimeline(Duration timeout) {
    Timeline animation;
    animation = new Timeline(new KeyFrame(Duration.ZERO, e -> this.toBack(), new KeyValue(this.visibleProperty(), false, Interpolator.EASE_BOTH), new KeyValue(this.translateYProperty(), this.getLayoutBounds().getHeight(), easeInterpolator), new KeyValue(this.opacityProperty(), 0, easeInterpolator)), new KeyFrame(Duration.millis(10), e -> this.toFront(), new KeyValue(this.visibleProperty(), true, Interpolator.EASE_BOTH)), new KeyFrame(Duration.millis(300), new KeyValue(this.opacityProperty(), 1, easeInterpolator), new KeyValue(this.translateYProperty(), 0, easeInterpolator)));
    animation.setCycleCount(1);
    pauseTransition = Duration.INDEFINITE.equals(timeout) ? null : new PauseTransition(timeout);
    if (pauseTransition != null) {
        animation.setOnFinished(finish -> {
            if (pauseTransition != null) {
                pauseTransition.setOnFinished(done -> {
                    pauseTransition = null;
                    eventsSet.remove(currentEvent);
                    currentEvent = eventQueue.peek();
                    close();
                });
                pauseTransition.play();
            }
        });
    }
    return animation;
}
Also used : Timeline(javafx.animation.Timeline) KeyValue(javafx.animation.KeyValue) KeyFrame(javafx.animation.KeyFrame) PauseTransition(javafx.animation.PauseTransition)

Aggregations

PauseTransition (javafx.animation.PauseTransition)17 MouseEvent (javafx.scene.input.MouseEvent)7 SequentialTransition (javafx.animation.SequentialTransition)6 EventHandler (javafx.event.EventHandler)6 Duration (javafx.util.Duration)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 FadeTransition (javafx.animation.FadeTransition)5 ActionEvent (javafx.event.ActionEvent)5 Node (javafx.scene.Node)5 Color (javafx.scene.paint.Color)5 Locale (java.util.Locale)4 ParallelTransition (javafx.animation.ParallelTransition)4 Event (javafx.event.Event)4 EventType (javafx.event.EventType)4 Background (javafx.scene.layout.Background)4 BackgroundFill (javafx.scene.layout.BackgroundFill)4 Region (javafx.scene.layout.Region)4 Paint (javafx.scene.paint.Paint)4 UnmodifiableListSet (com.sun.javafx.collections.UnmodifiableListSet)3