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();
}
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();
}
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();
}
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;
}
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;
}
Aggregations