Example usage for javafx.util Duration ZERO

List of usage examples for javafx.util Duration ZERO

Introduction

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

Prototype

Duration ZERO

To view the source code for javafx.util Duration ZERO.

Click Source Link

Document

A Duration of 0 (no time).

Usage

From source file:Main.java

@Override
public void start(Stage stage) {
    Text msg = new Text("java2s.com");
    msg.setTextOrigin(VPos.TOP);/*  w  w w.ja v  a2  s.  c o m*/
    msg.setFont(Font.font(24));

    Pane root = new Pane(msg);
    root.setPrefSize(500, 70);
    Scene scene = new Scene(root);

    stage.setScene(scene);
    stage.setTitle("Scrolling Text");
    stage.show();

    double sceneWidth = scene.getWidth();
    double msgWidth = msg.getLayoutBounds().getWidth();

    KeyValue initKeyValue = new KeyValue(msg.translateXProperty(), sceneWidth);
    KeyFrame initFrame = new KeyFrame(Duration.ZERO, initKeyValue);

    KeyValue endKeyValue = new KeyValue(msg.translateXProperty(), -1.0 * msgWidth);
    KeyFrame endFrame = new KeyFrame(Duration.seconds(3), endKeyValue);

    Timeline timeline = new Timeline(initFrame, endFrame);

    timeline.setCycleCount(Timeline.INDEFINITE);
    timeline.play();
}

From source file:ninja.eivind.hotsreplayuploader.services.AccountService.java

public AccountService() {
    setDelay(Duration.ZERO);
    setPeriod(Duration.minutes(10));
}

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/*from   ww w . j a  v a  2s.  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:projavafx.videoplayer3.VideoPlayer3.java

@Override
public void start(Stage primaryStage) {
    final Label message = new Label("I \u2764 Robots");
    message.setVisible(false);//  ww  w.jav a2s .c om

    String workingDir = System.getProperty("user.dir");
    final File f = new File(workingDir, "../media/omgrobots.flv");

    final Media m = new Media(f.toURI().toString());
    m.getMarkers().put("Split", Duration.millis(3000));
    m.getMarkers().put("Join", Duration.millis(9000));

    final MediaPlayer mp = new MediaPlayer(m);

    final MediaView mv1 = new MediaView(mp);
    mv1.setViewport(new Rectangle2D(0, 0, 960 / 2, 540));
    StackPane.setAlignment(mv1, Pos.CENTER_LEFT);

    final MediaView mv2 = new MediaView(mp);
    mv2.setViewport(new Rectangle2D(960 / 2, 0, 960 / 2, 540));
    StackPane.setAlignment(mv2, Pos.CENTER_RIGHT);

    StackPane root = new StackPane();
    root.getChildren().addAll(message, mv1, mv2);
    root.setOnMouseClicked(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent event) {
            mp.seek(Duration.ZERO);
            message.setVisible(false);
        }
    });

    final Scene scene = new Scene(root, 960, 540);
    final URL stylesheet = getClass().getResource("media.css");
    scene.getStylesheets().add(stylesheet.toString());

    primaryStage.setScene(scene);
    primaryStage.setTitle("Video Player 3");
    primaryStage.show();

    mp.setOnMarker(new EventHandler<MediaMarkerEvent>() {

        @Override
        public void handle(final MediaMarkerEvent event) {
            Platform.runLater(new Runnable() {

                @Override
                public void run() {
                    if (event.getMarker().getKey().equals("Split")) {
                        message.setVisible(true);
                        buildSplitTransition(mv1, mv2).play();
                    } else {
                        buildJoinTransition(mv1, mv2).play();
                    }
                }

            });
        }
    });
    mp.play();
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    final Label markerText = new Label();
    StackPane.setAlignment(markerText, Pos.TOP_CENTER);

    String workingDir = System.getProperty("user.dir");
    final File f = new File(workingDir, "../media/omgrobots.flv");

    final Media m = new Media(f.toURI().toString());

    final ObservableMap<String, Duration> markers = m.getMarkers();
    markers.put("Robot Finds Wall", Duration.millis(3100));
    markers.put("Then Finds the Green Line", Duration.millis(5600));
    markers.put("Robot Grabs Sled", Duration.millis(8000));
    markers.put("And Heads for Home", Duration.millis(11500));

    final MediaPlayer mp = new MediaPlayer(m);
    mp.setOnMarker(new EventHandler<MediaMarkerEvent>() {
        @Override/*from w  w w  . ja va  2 s . c o m*/
        public void handle(final MediaMarkerEvent event) {
            Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    markerText.setText(event.getMarker().getKey());
                }
            });
        }
    });

    final MediaView mv = new MediaView(mp);

    final StackPane root = new StackPane();
    root.getChildren().addAll(mv, markerText);
    root.setOnMouseClicked(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent event) {
            mp.seek(Duration.ZERO);
            markerText.setText("");
        }
    });

    final Scene scene = new Scene(root, 960, 540);
    final URL stylesheet = getClass().getResource("media.css");
    scene.getStylesheets().add(stylesheet.toString());

    primaryStage.setScene(scene);
    primaryStage.setTitle("Video Player 2");
    primaryStage.show();

    mp.play();
}

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);/*w  ww  .ja  v a  2 s . com*/
    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:MediaControl.java

private static String formatTime(Duration elapsed, Duration duration) {
    int intElapsed = (int) Math.floor(elapsed.toSeconds());
    int elapsedHours = intElapsed / (60 * 60);
    if (elapsedHours > 0) {
        intElapsed -= elapsedHours * 60 * 60;
    }/*w  w w . j a  va  2  s .  co  m*/
    int elapsedMinutes = intElapsed / 60;
    int elapsedSeconds = intElapsed - elapsedHours * 60 * 60 - elapsedMinutes * 60;

    if (duration.greaterThan(Duration.ZERO)) {
        int intDuration = (int) Math.floor(duration.toSeconds());
        int durationHours = intDuration / (60 * 60);
        if (durationHours > 0) {
            intDuration -= durationHours * 60 * 60;
        }
        int durationMinutes = intDuration / 60;
        int durationSeconds = intDuration - durationHours * 60 * 60 - durationMinutes * 60;
        if (durationHours > 0) {
            return String.format("%d:%02d:%02d/%d:%02d:%02d", elapsedHours, elapsedMinutes, elapsedSeconds,
                    durationHours, durationMinutes, durationSeconds);
        } else {
            return String.format("%02d:%02d/%02d:%02d", elapsedMinutes, elapsedSeconds, durationMinutes,
                    durationSeconds);
        }
    } else {
        if (elapsedHours > 0) {
            return String.format("%d:%02d:%02d", elapsedHours, elapsedMinutes, elapsedSeconds);
        } else {
            return String.format("%02d:%02d", elapsedMinutes, elapsedSeconds);
        }
    }
}

From source file:MediaControl.java

protected void updateValues() {
    if (playTime != null && timeSlider != null && volumeSlider != null) {
        Platform.runLater(new Runnable() {
            public void run() {
                Duration currentTime = mp.getCurrentTime();
                playTime.setText(formatTime(currentTime, duration));
                timeSlider.setDisable(duration.isUnknown());
                if (!timeSlider.isDisabled() && duration.greaterThan(Duration.ZERO)
                        && !timeSlider.isValueChanging()) {
                    timeSlider.setValue(currentTime.divide(duration).toMillis() * 100.0);
                }//from  w w  w. j  av  a  2s .com
                if (!volumeSlider.isValueChanging()) {
                    volumeSlider.setValue((int) Math.round(mp.getVolume() * 100));
                }
            }
        });
    }
}

From source file:AudioPlayer3.java

private Node createControlPanel() {
    final HBox hbox = new HBox();
    hbox.setAlignment(Pos.CENTER);//from w  ww .  ja  v a  2  s  .  com
    hbox.setFillHeight(false);

    final Button playPauseButton = createPlayPauseButton();

    final Button seekStartButton = new Button();
    seekStartButton.setId("seekStartButton");
    seekStartButton.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            seekAndUpdatePosition(Duration.ZERO);
        }
    });

    final Button seekEndButton = new Button();
    seekEndButton.setId("seekEndButton");
    seekEndButton.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            final MediaPlayer mediaPlayer = songModel.getMediaPlayer();
            final Duration totalDuration = mediaPlayer.getTotalDuration();
            final Duration oneSecond = Duration.seconds(1);
            seekAndUpdatePosition(totalDuration.subtract(oneSecond));
        }
    });

    hbox.getChildren().addAll(seekStartButton, playPauseButton, seekEndButton);
    return hbox;
}

From source file:com.bdb.weather.display.current.WindGauge.java

/**
 * Load the wind data into the gauge./*from w w  w  .j  a  va2 s  . com*/
 * 
 * @param wind The prevailing wind data
 * @param gust The wind gust data
 * @param maxWindSpeed The maximum wind speed so far this day
 * @param maxWindGust The maximum wind gust so far this day
 * @param avgWindSpeed The average wind speed so far this day
 * @param windDirs The extra wind directions
 */
public void loadData(Wind wind, Wind gust, Speed maxWindSpeed, Speed maxWindGust, Speed avgWindSpeed,
        List<Heading> windDirs) {
    if (wind == null)
        return;

    currentHeading = wind.getDirection().get();
    headingInterval = (currentHeading - lastHeading) / 10.0;
    if (headingInterval > 18.0)
        headingInterval -= 36.0;
    else if (headingInterval < -18.0)
        headingInterval += 36.0;

    lastHeading += headingInterval;
    datasets[0].setValue(lastHeading);

    for (int i = 1; i < datasets.length; i++) {
        if (windDirs.size() >= i)
            datasets[i].setValue(windDirs.get(i - 1).get());
        else
            datasets[i].setValue(wind.getDirection().get());
    }

    currentSpeed = wind.getSpeed().get();
    speedInterval = (currentSpeed - lastSpeed) / 10.0;
    lastSpeed += speedInterval;

    speedDataset.setValue(lastSpeed);

    String gustValue = DisplayConstants.UNKNOWN_VALUE_STRING;
    if (gust != null) {
        Speed gustSpeed = gust.getSpeed();

        if (gustSpeed != null) {
            gustValue = Speed.getDefaultFormatter().format(gustSpeed.get());
            gustDataset.setValue(gustSpeed.get());
            plot.setDataset(WIND_GUST_DATASET_INDEX, gustDataset);
        } else
            plot.setDataset(WIND_GUST_DATASET_INDEX, null);
    }

    if (maxWindSpeed != null)
        maxSpeedDataset.setValue(maxWindSpeed.get());
    else
        maxSpeedDataset.setValue(null);

    if (maxWindGust != null)
        maxGustDataset.setValue(maxWindGust.get());
    else
        maxGustDataset.setValue(null);

    String sustainedValue = Speed.getDefaultFormatter().format(wind.getSpeed().get());
    String s = sustainedValue + "/" + gustValue + " " + Speed.getDefaultUnit();
    speedAnnotation.setLabel(s);

    if (avgWindSpeed != null)
        avgAnnotation.setLabel("Avg: " + avgWindSpeed);
    else
        avgAnnotation.setLabel("");

    timeline.jumpTo(Duration.ZERO);
    timeline.play();
}