Java 类javafx.animation.StrokeTransition 实例源码

项目:LivroJavaComoProgramar10Edicao    文件:TransitionAnimationsController.java   
@FXML
private void startButtonPressed(ActionEvent event) 
{
   // transition that changes a shape's fill   
   FillTransition fillTransition = 
      new FillTransition(Duration.seconds(1));
   fillTransition.setToValue(Color.CYAN);
   fillTransition.setCycleCount(2);

   // each even cycle plays transition in reverse to restore original
   fillTransition.setAutoReverse(true); 

   // transition that changes a shape's stroke over time  
   StrokeTransition strokeTransition = 
      new StrokeTransition(Duration.seconds(1));
   strokeTransition.setToValue(Color.BLUE);
   strokeTransition.setCycleCount(2);
   strokeTransition.setAutoReverse(true);

   // parallelizes multiple transitions  
   ParallelTransition parallelTransition = 
      new ParallelTransition(fillTransition, strokeTransition);

   // transition that changes a node's opacity over time
   FadeTransition fadeTransition = 
      new FadeTransition(Duration.seconds(1));
   fadeTransition.setFromValue(1.0); // opaque
   fadeTransition.setToValue(0.0); // transparent
   fadeTransition.setCycleCount(2);
   fadeTransition.setAutoReverse(true);

   // transition that rotates a node 
   RotateTransition rotateTransition = 
      new RotateTransition(Duration.seconds(1));
   rotateTransition.setByAngle(360.0);
   rotateTransition.setCycleCount(2);
   rotateTransition.setInterpolator(Interpolator.EASE_BOTH);
   rotateTransition.setAutoReverse(true);

   // transition that moves a node along a Path  
   Path path = new Path(new MoveTo(45, 45), new LineTo(45, 0), 
      new LineTo(90, 0), new LineTo(90, 90), new LineTo(0, 90));
   PathTransition translateTransition = 
      new PathTransition(Duration.seconds(2), path);
   translateTransition.setCycleCount(2);
   translateTransition.setInterpolator(Interpolator.EASE_IN);
   translateTransition.setAutoReverse(true);

   // transition that scales a shape to make it larger or smaller
   ScaleTransition scaleTransition =
      new ScaleTransition(Duration.seconds(1));
   scaleTransition.setByX(0.75);
   scaleTransition.setByY(0.75);
   scaleTransition.setCycleCount(2);
   scaleTransition.setInterpolator(Interpolator.EASE_OUT);
   scaleTransition.setAutoReverse(true);

   // transition that applies a sequence of transitions to a node
   SequentialTransition sequentialTransition = 
      new SequentialTransition (rectangle, parallelTransition, 
         fadeTransition, rotateTransition, translateTransition, 
         scaleTransition);
   sequentialTransition.play(); // play the transition
}