/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package test; import javafx.beans.value.ObservableValue; import javafx.scene.*; import java.util.*; import javafx.scene.Group; import javafx.scene.shape.*; import javafx.scene.paint.Color; import javafx.animation.*; import javafx.beans.binding.Bindings; import javafx.beans.property.*; import javafx.beans.value.ChangeListener; import javafx.event.EventHandler; import javafx.scene.control.ScrollPane; import javafx.scene.control.ScrollPane.ScrollBarPolicy; import javafx.scene.input.MouseEvent; import javafx.util.Duration; public class Loop extends Parent { private Line playbackHead; private double width; private Timeline headTrans; public Loop(int width, int height) { super(); this.width = width; Rectangle borderRect = new Rectangle(width,height); borderRect.setFill(Color.TRANSPARENT); borderRect.setStroke(Color.BLACK); getChildren().add(borderRect); Group loopAreaGroup = new Group(); getChildren().add(loopAreaGroup); playbackHead = new Line(); playbackHead.setStrokeWidth(2); playbackHead.setEndY(height); loopAreaGroup.getChildren().add(playbackHead); playbackHead.translateXProperty().addListener(new ChangeListener() { public void changed(ObservableValue observable, Number oldValue, Number newValue) { System.out.println("x: " + playbackHead.getTranslateX()); } }); } public void startScrolling() { headTrans = new Timeline(); KeyValue kv = new KeyValue(playbackHead.translateXProperty(),0); KeyFrame kf = new KeyFrame(Duration.ZERO,kv); headTrans.getKeyFrames().add(kf); KeyValue kv2 = new KeyValue(playbackHead.translateXProperty(),width); KeyFrame kf2 = new KeyFrame( Duration.millis(3000), kv2); headTrans.getKeyFrames().add(kf2); headTrans.setCycleCount(Timeline.INDEFINITE); headTrans.playFromStart(); } public void stopScrolling() { if (headTrans != null) headTrans.stop(); } }