Java Code Examples for javafx.animation.Timeline#setAutoReverse()
The following examples show how to use
javafx.animation.Timeline#setAutoReverse() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GlobalTransformManager.java From paintera with GNU General Public License v2.0 | 7 votes |
public synchronized void setTransform(final AffineTransform3D affine, final Duration duration) { if (duration.toMillis() == 0.0) { setTransform(affine); return; } final Timeline timeline = new Timeline(60.0); timeline.setCycleCount(1); timeline.setAutoReverse(false); final AffineTransform3D currentState = this.affine.copy(); final DoubleProperty progressProperty = new SimpleDoubleProperty(0.0); final SimilarityTransformInterpolator interpolator = new SimilarityTransformInterpolator(currentState, affine.copy()); progressProperty.addListener((obs, oldv, newv) -> setTransform(interpolator.interpolateAt(newv.doubleValue()))); final KeyValue kv = new KeyValue(progressProperty, 1.0, Interpolator.EASE_BOTH); timeline.getKeyFrames().add(new KeyFrame(duration, kv)); timeline.play(); }
Example 2
Source File: ChartLayoutAnimator.java From chart-fx with Apache License 2.0 | 6 votes |
/** * Play a animation containing the given keyframes. * * @param keyFrames The keyframes to animate * @return A id reference to the animation that can be used to stop the animation if needed */ public Object animate(KeyFrame... keyFrames) { Timeline t = new Timeline(); t.setAutoReverse(false); t.setCycleCount(1); t.getKeyFrames().addAll(keyFrames); t.setOnFinished(this); // start animation timer if needed if (activeTimeLines.isEmpty()) start(); // get id and add to map activeTimeLines.put(t, t); // play animation t.play(); return t; }
Example 3
Source File: Viewer3DFX.java From paintera with GNU General Public License v2.0 | 6 votes |
public void setAffine(final Affine affine, final Duration duration) { if (duration.toMillis() == 0.0) { setAffine(affine); return; } final Timeline timeline = new Timeline(60.0); timeline.setCycleCount(1); timeline.setAutoReverse(false); final Affine currentState = new Affine(); getAffine(currentState); final DoubleProperty progressProperty = new SimpleDoubleProperty(0.0); final SimilarityTransformInterpolator interpolator = new SimilarityTransformInterpolator( Transforms.fromTransformFX(currentState), Transforms.fromTransformFX(affine) ); progressProperty.addListener((obs, oldv, newv) -> setAffine(Transforms.toTransformFX(interpolator.interpolateAt(newv.doubleValue())))); final KeyValue kv = new KeyValue(progressProperty, 1.0, Interpolator.EASE_BOTH); timeline.getKeyFrames().add(new KeyFrame(duration, kv)); timeline.play(); }
Example 4
Source File: WoodlandController.java From examples-javafx-repos1 with Apache License 2.0 | 6 votes |
private void snap(Optional<Rectangle> onSquare) { if( onSquare.isPresent() ) { Point2D onSquarePt = new Point2D(onSquare.get().getLayoutX(), onSquare.get().getLayoutY()); final Timeline timeline = new Timeline(); timeline.setCycleCount(1); timeline.setAutoReverse(false); timeline.getKeyFrames() .add(new KeyFrame(Duration.millis(200), new KeyValue(gamePiece.layoutXProperty(), onSquarePt.getX()+gpCenteringX), new KeyValue(gamePiece.layoutYProperty(), onSquarePt.getY()+gpCenteringY)) ); timeline.play(); } }
Example 5
Source File: TimelineSample.java From marathonv5 with Apache License 2.0 | 5 votes |
public TimelineSample() { super(280,120); //create a circle final Circle circle = new Circle(25,25, 20, Color.web("1c89f4")); circle.setEffect(new Lighting()); //create a timeline for moving the circle timeline = new Timeline(); timeline.setCycleCount(Timeline.INDEFINITE); timeline.setAutoReverse(true); //one can start/pause/stop/play animation by //timeline.play(); //timeline.pause(); //timeline.stop(); //timeline.playFromStart(); //add the following keyframes to the timeline timeline.getKeyFrames().addAll (new KeyFrame(Duration.ZERO, new KeyValue(circle.translateXProperty(), 0)), new KeyFrame(new Duration(4000), new KeyValue(circle.translateXProperty(), 205))); getChildren().add(createNavigation()); getChildren().add(circle); // REMOVE ME setControls( new SimplePropertySheet.PropDesc("Timeline rate", timeline.rateProperty(), -4d, 4d) //TODO it is possible to do it for integer? ); // END REMOVE ME }
Example 6
Source File: TimelineSample.java From marathonv5 with Apache License 2.0 | 5 votes |
public TimelineSample() { super(280,120); //create a circle final Circle circle = new Circle(25,25, 20, Color.web("1c89f4")); circle.setEffect(new Lighting()); //create a timeline for moving the circle timeline = new Timeline(); timeline.setCycleCount(Timeline.INDEFINITE); timeline.setAutoReverse(true); //one can start/pause/stop/play animation by //timeline.play(); //timeline.pause(); //timeline.stop(); //timeline.playFromStart(); //add the following keyframes to the timeline timeline.getKeyFrames().addAll (new KeyFrame(Duration.ZERO, new KeyValue(circle.translateXProperty(), 0)), new KeyFrame(new Duration(4000), new KeyValue(circle.translateXProperty(), 205))); getChildren().add(createNavigation()); getChildren().add(circle); // REMOVE ME setControls( new SimplePropertySheet.PropDesc("Timeline rate", timeline.rateProperty(), -4d, 4d) //TODO it is possible to do it for integer? ); // END REMOVE ME }
Example 7
Source File: AnimationHelper.java From ApkToolPlus with Apache License 2.0 | 5 votes |
/** * 抖动窗口 * * @param window 窗口对象 * @param count 抖动次数 */ public static void shake(Window window, int count) { final Delta detla = new Delta(); detla.x = 0; detla.y = 0; Timeline timelineX = new Timeline(new KeyFrame(Duration.seconds(0.1), event -> { if (detla.x == 0) { window.setX(window.getX() + 10); detla.x = 1; } else { window.setX(window.getX() - 10); detla.x = 0; } })); //timelineX.setCycleCount(Timeline.INDEFINITE); timelineX.setCycleCount(count); timelineX.setAutoReverse(false); timelineX.play(); // Timeline timelineY = new Timeline(new KeyFrame(Duration.seconds(0.1), event -> { // if (detla.y == 0) { // stage.setY(stage.getY() + 10); // detla.y = 1; // } else { // stage.setY(stage.getY() - 10); // detla.y = 0; // } // })); // // timelineY.setCycleCount(count); // timelineY.setAutoReverse(false); // timelineY.play(); }
Example 8
Source File: ColorAnimationUtils.java From graph-editor with Eclipse Public License 1.0 | 5 votes |
/** * Adds animated color properties to the given node that can be accessed from CSS. * * @param node the node to be styled with animated colors * @param data a {@link AnimatedColor} object storing the animation parameters */ public static void animateColor(final Node node, final AnimatedColor data) { removeAnimation(node); final ObjectProperty<Color> baseColor = new SimpleObjectProperty<>(); final KeyValue firstkeyValue = new KeyValue(baseColor, data.getFirstColor()); final KeyValue secondKeyValue = new KeyValue(baseColor, data.getSecondColor()); final KeyFrame firstKeyFrame = new KeyFrame(Duration.ZERO, firstkeyValue); final KeyFrame secondKeyFrame = new KeyFrame(data.getInterval(), secondKeyValue); final Timeline timeline = new Timeline(firstKeyFrame, secondKeyFrame); baseColor.addListener((v, o, n) -> { final int redValue = (int) (n.getRed() * 255); final int greenValue = (int) (n.getGreen() * 255); final int blueValue = (int) (n.getBlue() * 255); final String format = data.getProperty() + ": " + COLOR_FORMAT + ";"; node.setStyle(String.format(format, redValue, greenValue, blueValue)); }); node.getProperties().put(TIMELINE_KEY, timeline); timeline.setAutoReverse(true); timeline.setCycleCount(Animation.INDEFINITE); timeline.play(); }
Example 9
Source File: TimelineEventsSample.java From marathonv5 with Apache License 2.0 | 4 votes |
public TimelineEventsSample() { super(70,70); //create a circle with effect final Circle circle = new Circle(20, Color.rgb(156,216,255)); circle.setEffect(new Lighting()); //create a text inside a circle final Text text = new Text (i.toString()); text.setStroke(Color.BLACK); //create a layout for circle with text inside final StackPane stack = new StackPane(); stack.getChildren().addAll(circle, text); stack.setLayoutX(30); stack.setLayoutY(30); //create a timeline for moving the circle timeline = new Timeline(); timeline.setCycleCount(Timeline.INDEFINITE); timeline.setAutoReverse(true); //one can add a specific action when each frame is started. There are one or more frames during // executing one KeyFrame depending on set Interpolator. timer = new AnimationTimer() { @Override public void handle(long l) { text.setText(i.toString()); i++; } }; //create a keyValue with factory: scaling the circle 2times KeyValue keyValueX = new KeyValue(stack.scaleXProperty(), 2); KeyValue keyValueY = new KeyValue(stack.scaleYProperty(), 2); //create a keyFrame, the keyValue is reached at time 2s Duration duration = Duration.seconds(2); //one can add a specific action when the keyframe is reached EventHandler<ActionEvent> onFinished = new EventHandler<ActionEvent>() { public void handle(ActionEvent t) { stack.setTranslateX(java.lang.Math.random()*200-100); //reset counter i = 0; } }; KeyFrame keyFrame = new KeyFrame(duration, onFinished , keyValueX, keyValueY); //add the keyframe to the timeline timeline.getKeyFrames().add(keyFrame); getChildren().add(stack); }
Example 10
Source File: TimelineEventsSample.java From marathonv5 with Apache License 2.0 | 4 votes |
public TimelineEventsSample() { super(70,70); //create a circle with effect final Circle circle = new Circle(20, Color.rgb(156,216,255)); circle.setEffect(new Lighting()); //create a text inside a circle final Text text = new Text (i.toString()); text.setStroke(Color.BLACK); //create a layout for circle with text inside final StackPane stack = new StackPane(); stack.getChildren().addAll(circle, text); stack.setLayoutX(30); stack.setLayoutY(30); //create a timeline for moving the circle timeline = new Timeline(); timeline.setCycleCount(Timeline.INDEFINITE); timeline.setAutoReverse(true); //one can add a specific action when each frame is started. There are one or more frames during // executing one KeyFrame depending on set Interpolator. timer = new AnimationTimer() { @Override public void handle(long l) { text.setText(i.toString()); i++; } }; //create a keyValue with factory: scaling the circle 2times KeyValue keyValueX = new KeyValue(stack.scaleXProperty(), 2); KeyValue keyValueY = new KeyValue(stack.scaleYProperty(), 2); //create a keyFrame, the keyValue is reached at time 2s Duration duration = Duration.seconds(2); //one can add a specific action when the keyframe is reached EventHandler<ActionEvent> onFinished = new EventHandler<ActionEvent>() { public void handle(ActionEvent t) { stack.setTranslateX(java.lang.Math.random()*200-100); //reset counter i = 0; } }; KeyFrame keyFrame = new KeyFrame(duration, onFinished , keyValueX, keyValueY); //add the keyframe to the timeline timeline.getKeyFrames().add(keyFrame); getChildren().add(stack); }
Example 11
Source File: TimelineEvents.java From netbeans with Apache License 2.0 | 4 votes |
private void init(Stage primaryStage) { Group root = new Group(); primaryStage.setResizable(false); primaryStage.setScene(new Scene(root, 260,100)); //create a circle with effect final Circle circle = new Circle(20, Color.rgb(156,216,255)); circle.setEffect(new Lighting()); //create a text inside a circle final Text text = new Text (i.toString()); text.setStroke(Color.BLACK); //create a layout for circle with text inside final StackPane stack = new StackPane(); stack.getChildren().addAll(circle, text); stack.setLayoutX(30); stack.setLayoutY(30); //create a timeline for moving the circle timeline = new Timeline(); timeline.setCycleCount(Timeline.INDEFINITE); timeline.setAutoReverse(true); //one can add a specific action when each frame is started. There are one or more frames during // executing one KeyFrame depending on set Interpolator. timer = new AnimationTimer() { @Override public void handle(long l) { text.setText(i.toString()); i++; } }; //create a keyValue with factory: scaling the circle 2times KeyValue keyValueX = new KeyValue(stack.scaleXProperty(), 2); KeyValue keyValueY = new KeyValue(stack.scaleYProperty(), 2); //create a keyFrame, the keyValue is reached at time 2s Duration duration = Duration.seconds(2); //one can add a specific action when the keyframe is reached EventHandler<ActionEvent> onFinished = new EventHandler<ActionEvent>() { public void handle(ActionEvent t) { stack.setTranslateX(java.lang.Math.random()*200); //reset counter i = 0; } }; KeyFrame keyFrame = new KeyFrame(duration, onFinished , keyValueX, keyValueY); //add the keyframe to the timeline timeline.getKeyFrames().add(keyFrame); root.getChildren().add(stack); }
Example 12
Source File: JiaGuActivity.java From ApkToolPlus with Apache License 2.0 | 4 votes |
private void iteratorEncryptApkList(Iterator<Parent> iterator){ if(!iterator.hasNext()){ Platform.runLater(() -> { btnAddApk.setDisable(false); btnStartEncrypt.setDisable(false); isWorking = false; }); return; } Parent node = iterator.next(); ApkItemView apkItemView = (ApkItemView) node.getUserData(); KeystoreConfig keystoreConfig = SettingHelper.getKeystoreConfig(); if(!apkItemView.isWaiting()){ iteratorEncryptApkList(iterator); return; } // 进度动画 progressAnimation = new Timeline( new KeyFrame( Duration.ZERO, new KeyValue(apkItemView.progressBar.progressProperty(), 0) ), /** 正在反编译 **/ new KeyFrame(Duration.seconds(8), event -> progressAnimation.pause(), new KeyValue(apkItemView.progressBar.progressProperty(), 0.6)), /** 正在加固 **/ new KeyFrame(Duration.seconds(10), event -> progressAnimation.pause(), new KeyValue(apkItemView.progressBar.progressProperty(),0.75)), /** 正在回编译 **/ new KeyFrame(Duration.seconds(13), event -> { if(keystoreConfig != null){ progressAnimation.pause(); } }, new KeyValue(apkItemView.progressBar.progressProperty(),1)), /** 正在签名 **/ new KeyFrame(Duration.seconds(15), event -> { apkItemView.setSigning(); }, new KeyValue(apkItemView.progressBar.progressProperty(),1)) ); progressAnimation.setAutoReverse(false); // 指定从哪里开始播放 //progressAnimation.playFrom(Duration.millis(1000)); // 从开头播放 //progressAnimation.playFromStart(); apkItemView.setEncrypting(); TaskManager.get().queue(() -> { encryptApk(apkItemView.getApk(), keystoreConfig); apkItemView.setFinished(); // 加固下一个 iteratorEncryptApkList(iterator); }); }
Example 13
Source File: DockZones.java From AnchorFX with GNU Lesser General Public License v3.0 | 3 votes |
private void createRectangleForPreview() { rectanglePreview = new Rectangle(0, 0, 50, 50); rectanglePreview.getStyleClass().add("dockzone-rectangle-preview"); rectanglePreview.setOpacity(0); opacityAnimationPreview = new Timeline(new KeyFrame(Duration.seconds(0.5), new KeyValue(rectanglePreview.opacityProperty(), 0.5, Interpolator.LINEAR))); opacityAnimationPreview.setAutoReverse(true); opacityAnimationPreview.setCycleCount(-1); mainRoot.getChildren().add(rectanglePreview); }
Example 14
Source File: FarCry4Loading.java From FXTutorials with MIT License | 2 votes |
public LoadingArc() { Arc arc = new Arc(); arc.setCenterX(25); arc.setCenterY(25); arc.setRadiusX(25.0f); arc.setRadiusY(25.0f); arc.setLength(30.0f); arc.setStrokeWidth(5); Stop[] stops = new Stop[] { new Stop(0, Color.WHITE), new Stop(1, Color.BLUE)}; LinearGradient lg1 = new LinearGradient(0, 0, 1, 0, true, CycleMethod.NO_CYCLE, stops); arc.setStroke(lg1); Rectangle rect = new Rectangle(50, 50); rect.setFill(null); rect.setStroke(Color.RED); getChildren().addAll(rect, arc); double time = 0.75; Rotate r = new Rotate(0, 25, 25); arc.getTransforms().add(r); //arc.getTransforms().add(new Scale(-1, 1, 25, 25)); Timeline timeline = new Timeline(); KeyFrame kf2 = new KeyFrame(Duration.seconds(time), new KeyValue(r.angleProperty(), 270)); timeline.getKeyFrames().addAll(kf2); Timeline timeline3 = new Timeline(new KeyFrame(Duration.seconds(time), new KeyValue(r.angleProperty(), 360))); SequentialTransition st = new SequentialTransition(timeline, timeline3); st.setCycleCount(Timeline.INDEFINITE); st.setInterpolator(Interpolator.EASE_BOTH); st.play(); ////////// Timeline timeline2 = new Timeline(); timeline2.setAutoReverse(true); timeline2.setCycleCount(Timeline.INDEFINITE); KeyFrame kf = new KeyFrame(Duration.seconds(time), new KeyValue(arc.lengthProperty(), 270, Interpolator.EASE_BOTH)); timeline2.getKeyFrames().add(kf); timeline2.play(); }