| /* |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| */ |
| package transitionpath; |
| |
| import javafx.animation.PathTransition; |
| import javafx.animation.PathTransition.OrientationType; |
| import javafx.animation.PathTransitionBuilder; |
| import javafx.animation.Timeline; |
| import javafx.application.Application; |
| import javafx.scene.Group; |
| import javafx.scene.Scene; |
| import javafx.scene.paint.Color; |
| import javafx.scene.shape.CubicCurveTo; |
| import javafx.scene.shape.MoveTo; |
| import javafx.scene.shape.Path; |
| import javafx.scene.shape.PathBuilder; |
| import javafx.scene.shape.Rectangle; |
| import javafx.stage.Stage; |
| import javafx.util.Duration; |
| |
| /** |
| * A sample in which a node moves along a path from end to end over a given time. |
| * |
| * @related animation/transitions/FadeTransition |
| * @related animation/transitions/FillTransition |
| * @related animation/transitions/ParallelTransition |
| * @related animation/transitions/PauseTransition |
| * @related animation/transitions/RotateTransition |
| * @related animation/transitions/ScaleTransition |
| * @related animation/transitions/SequentialTransition |
| * @related animation/transitions/StrokeTransition |
| * @related animation/transitions/TranslateTransition |
| * @see javafx.animation.PathTransition |
| * @see javafx.animation.PathTransitionBuilder |
| * @see javafx.animation.Transition |
| */ |
| public class TransitionPath extends Application { |
| |
| private PathTransition pathTransition; |
| |
| private void init(Stage primaryStage) { |
| Group root = new Group(); |
| primaryStage.setResizable(false); |
| primaryStage.setScene(new Scene(root, 400,260)); |
| Rectangle rect = new Rectangle (0, 0, 40, 40); |
| rect.setArcHeight(10); |
| rect.setArcWidth(10); |
| rect.setFill(Color.ORANGE); |
| root.getChildren().add(rect); |
| Path path = PathBuilder.create() |
| .elements( |
| new MoveTo(20,20), |
| new CubicCurveTo(380, 0, 380, 120, 200, 120), |
| new CubicCurveTo(0, 120, 0, 240, 380, 240) |
| ) |
| .build(); |
| path.setStroke(Color.DODGERBLUE); |
| path.getStrokeDashArray().setAll(5d,5d); |
| root.getChildren().add(path); |
| |
| pathTransition = PathTransitionBuilder.create() |
| .duration(Duration.seconds(4)) |
| .path(path) |
| .node(rect) |
| .orientation(OrientationType.ORTHOGONAL_TO_TANGENT) |
| .cycleCount(Timeline.INDEFINITE) |
| .autoReverse(true) |
| .build(); |
| } |
| |
| public void play() { |
| pathTransition.play(); |
| } |
| |
| @Override public void stop() { |
| pathTransition.stop(); |
| } |
| |
| @Override public void start(Stage primaryStage) throws Exception { |
| init(primaryStage); |
| primaryStage.show(); |
| play(); |
| } |
| |
| /** |
| * The main() method is ignored in correctly deployed JavaFX |
| * application. main() serves only as fallback in case the |
| * application can not be launched through deployment artifacts, |
| * e.g., in IDEs with limited FX support. NetBeans ignores main(). |
| * @param args the command line arguments |
| */ |
| public static void main(String[] args) { |
| launch(args); |
| } |
| } |