Example usage for javafx.util Duration Duration

List of usage examples for javafx.util Duration Duration

Introduction

In this page you can find the example usage for javafx.util Duration Duration.

Prototype

public Duration(@NamedArg("millis") double millis) 

Source Link

Document

Creates a new Duration with potentially fractional millisecond resolution.

Usage

From source file:com.sunkur.springjavafxcontroller.screen.ScreensContoller.java

private boolean swapScreen(final Parent root) {
    final Group rootGroup = getScreenRoot();
    final DoubleProperty opacity = rootGroup.opacityProperty();
    if (!isScreenEmpty()) {

        Timeline fade = new Timeline(new KeyFrame(Duration.ZERO, new KeyValue(opacity, 1.0)),
                new KeyFrame(new Duration(250), new EventHandler<ActionEvent>() {
                    @Override//w  w  w .j  a v  a2 s.c o m
                    public void handle(ActionEvent t) {
                        rootGroup.getChildren().remove(0);

                        rootGroup.getChildren().add(0, root);
                        Timeline fadeIn = new Timeline(new KeyFrame(Duration.ZERO, new KeyValue(opacity, 0.0)),
                                new KeyFrame(new Duration(350), new KeyValue(opacity, 1.0)));
                        fadeIn.play();
                    }
                }, new KeyValue(opacity, 0.0)));
        fade.play();
        return true;
    } else {
        opacity.set(0.0);
        rootGroup.getChildren().add(0, root);
        Timeline fadeIn = new Timeline(new KeyFrame(Duration.ZERO, new KeyValue(opacity, 0.0)),
                new KeyFrame(new Duration(350), new KeyValue(opacity, 1.0)));
        fadeIn.play();
    }

    if (!this.stage.isShowing()) {
        this.stage.show();
    }
    return true;
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    Group root = new Group();
    Scene scene = new Scene(root, 800, 600, Color.BLACK);
    primaryStage.setScene(scene);//from   ww  w .  j a va 2s  .c om
    Group circles = new Group();
    for (int i = 0; i < 30; i++) {
        Circle circle = new Circle(150, Color.web("white", 0.05));
        circle.setStrokeType(StrokeType.OUTSIDE);
        circle.setStroke(Color.web("white", 0.16));
        circle.setStrokeWidth(4);
        circles.getChildren().add(circle);
    }
    Rectangle colors = new Rectangle(scene.getWidth(), scene.getHeight(),
            new LinearGradient(0f, 1f, 1f, 0f, true, CycleMethod.NO_CYCLE,
                    new Stop[] { new Stop(0, Color.web("#f8bd55")), new Stop(0.14, Color.web("#c0fe56")),
                            new Stop(0.28, Color.web("#5dfbc1")), new Stop(0.43, Color.web("#64c2f8")),
                            new Stop(0.57, Color.web("#be4af7")), new Stop(0.71, Color.web("#ed5fc2")),
                            new Stop(0.85, Color.web("#ef504c")), new Stop(1, Color.web("#f2660f")), }));
    Group blendModeGroup = new Group(
            new Group(new Rectangle(scene.getWidth(), scene.getHeight(), Color.BLACK), circles), colors);
    colors.setBlendMode(BlendMode.OVERLAY);
    root.getChildren().add(blendModeGroup);
    circles.setEffect(new BoxBlur(10, 10, 3));
    Timeline timeline = new Timeline();
    for (Node circle : circles.getChildren()) {
        timeline.getKeyFrames().addAll(new KeyFrame(Duration.ZERO, // set start position at 0
                new KeyValue(circle.translateXProperty(), random() * 800),
                new KeyValue(circle.translateYProperty(), random() * 600)),
                new KeyFrame(new Duration(40000), // set end position at 40s
                        new KeyValue(circle.translateXProperty(), random() * 800),
                        new KeyValue(circle.translateYProperty(), random() * 600)));
    }
    // play 40s of animation
    timeline.play();

    primaryStage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {

    String message = "Earthrise at Christmas: " + "[Forty] years ago this Christmas, a turbulent world "
            + "looked to the heavens for a unique view of our home "
            + "planet. This photo of Earthrise over the lunar horizon "
            + "was taken by the Apollo 8 crew in December 1968, showing "
            + "Earth for the first time as it appears from deep space. "
            + "Astronauts Frank Borman, Jim Lovell and William Anders "
            + "had become the first humans to leave Earth orbit, "
            + "entering lunar orbit on Christmas Eve. In a historic live "
            + "broadcast that night, the crew took turns reading from "
            + "the Book of Genesis, closing with a holiday wish from "
            + "Commander Borman: \"We close with good night, good luck, "
            + "a Merry Christmas, and God bless all of you -- all of " + "you on the good Earth.\"";

    // Reference to the Text
    Text textRef = TextBuilder.create().layoutY(100).textOrigin(VPos.TOP).textAlignment(TextAlignment.JUSTIFY)
            .wrappingWidth(400).text(message).fill(Color.rgb(187, 195, 107))
            .font(Font.font("SansSerif", FontWeight.BOLD, 24)).build();

    // Provides the animated scrolling behavior for the text
    TranslateTransition transTransition = TranslateTransitionBuilder.create().duration(new Duration(75000))
            .node(textRef).toY(-820).interpolator(Interpolator.LINEAR).cycleCount(Timeline.INDEFINITE).build();

    Scene scene = SceneBuilder//  w ww . j  a  v  a  2  s.  co m
            .create().width(516).height(
                    387)
            .root(GroupBuilder.create().children(
                    ImageViewBuilder.create().image(new Image("http://projavafx.com/images/earthrise.jpg"))
                            .build(),
                    ScrollPaneBuilder.create().layoutX(50).layoutY(180).prefWidth(440).prefHeight(85)
                            .hbarPolicy(ScrollBarPolicy.NEVER).vbarPolicy(ScrollBarPolicy.NEVER).pannable(true)
                            .content(textRef).style("-fx-background-color: transparent;").build())
                    .build())
            .build();

    stage.setScene(scene);
    stage.setTitle("Hello Earthrise");
    stage.show();

    // Start the text animation
    transTransition.play();
}

From source file:com.loyalty.controllers.DashboardController.java

private void animate() {
    Toolkit tk = Toolkit.getDefaultToolkit();
    Dimension screenDimension = tk.getScreenSize();
    TranslateTransition transition = new TranslateTransition(new Duration(30000), lbl_promotion);
    transition.setInterpolator(Interpolator.LINEAR);
    transition.setCycleCount(Timeline.INDEFINITE);
    transition.setFromX(screenDimension.getWidth());
    transition.setToX(-screenDimension.getWidth());
    transition.play();//from   w w  w .  j av a2  s  . c  o  m
}

From source file:jp.co.heppokoact.autocapture.FXMLDocumentController.java

@Override
public void initialize(URL url, ResourceBundle rb) {
    // ???/*from w w w .  java  2 s. c o  m*/
    prop = new Properties();
    if (CONFIG_FILE.exists()) {
        try (InputStream in = new FileInputStream(CONFIG_FILE)) {
            prop.loadFromXML(in);
        } catch (IOException e) {
            throw new RuntimeException("????????", e);
        }
    }

    // ????????
    String saveDirectoryPath = prop.getProperty("saveDirectoryPath");
    if (saveDirectoryPath != null) {
        File tempSaveDirectory = new File(saveDirectoryPath);
        if (tempSaveDirectory.exists()) {
            saveDirectory.set(tempSaveDirectory);
        }
    }

    // ???
    saveDirectoryLabel.textProperty().bind(Bindings.createStringBinding(() -> {
        File sd = saveDirectory.get();
        return (sd == null) ? "" : sd.getName();
    }, saveDirectory));
    areaStartXLabel.textProperty().bind(Bindings.convert(areaStartX));
    areaStartYLabel.textProperty().bind(Bindings.convert(areaStartY));
    areaEndXLabel.textProperty().bind(Bindings.convert(areaEndX));
    areaEndYLabel.textProperty().bind(Bindings.convert(areaEndY));
    nextPointXLabel.textProperty().bind(Bindings.convert(nextPointX));
    nextPointYLabel.textProperty().bind(Bindings.convert(nextPointY));
    prevPointXLabel.textProperty().bind(Bindings.convert(prevPointX));
    prevPointYLabel.textProperty().bind(Bindings.convert(prevPointY));

    // ???
    stopButton.setDisable(true);

    // ????
    captureService = new CaptureService();
    captureTimeline = new Timeline(new KeyFrame(new Duration(CAPTURE_INTERVAL), e -> {
        captureService.restart();
    }));
    captureTimeline.setCycleCount(Timeline.INDEFINITE);
    try {
        robot = new Robot();
    } catch (AWTException e) {
        throw new RuntimeException("???????", e);
    }

    // ??
    clip = new AudioClip(ClassLoader.getSystemResource("ayashi.wav").toString());
}

From source file:utybo.branchingstorytree.swing.impl.SSBClient.java

@Override
public void play(final String name) {
    resources.get(name).seek(new Duration(0));
    resources.get(name).play();
}