javafx.animation.Animation Java Examples

The following examples show how to use javafx.animation.Animation. 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: ChartAdvancedStockLine.java    From netbeans with Apache License 2.0 7 votes vote down vote up
private void init(Stage primaryStage) {
    Group root = new Group();
    primaryStage.setScene(new Scene(root));
    root.getChildren().add(createChart());
    // create timeline to add new data every 60th of second
    animation = new Timeline();
    animation.getKeyFrames().add(new KeyFrame(Duration.millis(1000/60), new EventHandler<ActionEvent>() {
        @Override public void handle(ActionEvent actionEvent) {
            // 6 minutes data per frame
            for(int count=0; count < 6; count++) {
                nextTime();
                plotTime();
            }
        }
    }));
    animation.setCycleCount(Animation.INDEFINITE);
}
 
Example #2
Source File: Clock.java    From Quelea with GNU General Public License v3.0 7 votes vote down vote up
private void bindToTime() {
    Timeline timeline = new Timeline(
            new KeyFrame(Duration.seconds(0), (ActionEvent actionEvent) -> {
                Calendar time = Calendar.getInstance();
                String hourString;
                boolean s24h = QueleaProperties.get().getUse24HourClock();
                if (s24h) {
                    hourString = pad(2, '0', time.get(Calendar.HOUR_OF_DAY) + "");
                } else {
                    hourString = pad(2, '0', time.get(Calendar.HOUR) + "");
                }
                String minuteString = pad(2, '0', time.get(Calendar.MINUTE) + "");
                String text1 = hourString + ":" + minuteString;
        if (!s24h) {
            text1 += (time.get(Calendar.AM_PM) == Calendar.AM) ? " AM" : " PM";
        }
        setText(text1);
    }),
            new KeyFrame(Duration.seconds(1))
    );
    timeline.setCycleCount(Animation.INDEFINITE);
    timeline.play();
}
 
Example #3
Source File: SpaceInvadersController.java    From FXGLGames with MIT License 6 votes vote down vote up
private Animation getAnimationLoseLife(Texture texture) {
    texture.setFitWidth(64);
    texture.setFitHeight(64);

    Viewport viewport = gameScene.getViewport();

    TranslateTransition tt = new TranslateTransition(Duration.seconds(0.66), texture);
    tt.setToX(viewport.getWidth() / 2 - texture.getFitWidth() / 2);
    tt.setToY(viewport.getHeight() / 2 - texture.getFitHeight() / 2);

    ScaleTransition st = new ScaleTransition(Duration.seconds(0.66), texture);
    st.setToX(0);
    st.setToY(0);

    return new SequentialTransition(tt, st);
}
 
Example #4
Source File: AnimationDemo.java    From JFoenix with Apache License 2.0 6 votes vote down vote up
@Override
public Animation animateExit() {
    final Integer endValue = 0;
    return new Timeline(
        new KeyFrame(Duration.millis(300),
                     new KeyValue(main.opacityProperty(), endValue, EASE_BOTH)),
        new KeyFrame(Duration.millis(520),
                     new KeyValue(colorPane1.translateXProperty(), endValue, EASE_BOTH),
                     new KeyValue(colorPane1.translateYProperty(), endValue, EASE_BOTH)),
        new KeyFrame(Duration.millis(200),
                     new KeyValue(colorPane1.scaleXProperty(), 1, EASE_BOTH),
                     new KeyValue(colorPane1.scaleYProperty(), 1, EASE_BOTH)),
        new KeyFrame(Duration.millis(1000),
                     new KeyValue(colorPane1.scaleXProperty(), 40, EASE_BOTH),
                     new KeyValue(colorPane1.scaleYProperty(), 40, EASE_BOTH)));
}
 
Example #5
Source File: SpriteView.java    From training with MIT License 6 votes vote down vote up
public void moveTo(Main.Location loc) {
    walking = new Timeline(Animation.INDEFINITE,
        new KeyFrame(Duration.seconds(.001), new KeyValue(direction, location.getValue().directionTo(loc))),
        new KeyFrame(Duration.seconds(.002), new KeyValue(location, loc)),
        new KeyFrame(Duration.seconds(1), new KeyValue(translateXProperty(), loc.getX() * Main.CELL_SIZE)),
        new KeyFrame(Duration.seconds(1), new KeyValue(translateYProperty(), loc.getY() * Main.CELL_SIZE)),
        new KeyFrame(Duration.seconds(.25), new KeyValue(frame, 0)),
        new KeyFrame(Duration.seconds(.5), new KeyValue(frame, 1)),
        new KeyFrame(Duration.seconds(.75), new KeyValue(frame, 2)),
        new KeyFrame(Duration.seconds(1), new KeyValue(frame, 1))
    );
    walking.setOnFinished(e -> {
        if (arrivalHandler != null) {
            arrivalHandler.handle(e);
        }
    });
    Application.invokeLater(walking::play);
}
 
Example #6
Source File: SpaceInvadersController.java    From FXGLGames with MIT License 6 votes vote down vote up
private Animation getAnimationLoseLife(Texture texture) {
    texture.setFitWidth(64);
    texture.setFitHeight(64);

    Viewport viewport = gameScene.getViewport();

    TranslateTransition tt = new TranslateTransition(Duration.seconds(0.66), texture);
    tt.setToX(viewport.getWidth() / 2 - texture.getFitWidth() / 2);
    tt.setToY(viewport.getHeight() / 2 - texture.getFitHeight() / 2);

    ScaleTransition st = new ScaleTransition(Duration.seconds(0.66), texture);
    st.setToX(0);
    st.setToY(0);

    return new SequentialTransition(tt, st);
}
 
Example #7
Source File: TestCaseListCell.java    From pmd-designer with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private Animation getStatusTransition(TestStatus newStatus) {

        return new Transition() {

            {
                setCycleDuration(Duration.millis(1200));
                setInterpolator(Interpolator.EASE_BOTH);
                setOnFinished(t -> applyCss());
            }


            @Override
            protected void interpolate(double frac) {
                Color vColor = newStatus.getColor().deriveColor(0, 1, 1, clip(map(frac)));
                setBackground(new Background(new BackgroundFill(vColor, CornerRadii.EMPTY, Insets.EMPTY)));
            }

            private double map(double x) {
                return -abs(x - 0.5) + 0.5;
            }

            private double clip(double i) {
                return min(1, max(0, i));
            }
        };
    }
 
Example #8
Source File: SpriteView.java    From quantumjava with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void move(Main.Direction direction) {
    if (walking != null && walking.getStatus().equals(Animation.Status.RUNNING))
        return;
    int lx = location.getValue().getX();
    int ly = location.getValue().getY();
    int dx = direction.getXOffset();
    int dy = direction.getYOffset();
    if (animals.size() < 1) {
        Main.setHelpText("Visit the barn to get a qubitlamb");
    }
    if ((dx < 0 && lx <1) || (dy < 0 && ly <1)) return;
    if ((dx > 0 && lx > Main.HORIZONTAL_CELLS-2) || (dy > 0 && ly > Main.VERTICAL_CELLS-2)) return;
    moveTo(location.getValue().offset(direction.getXOffset(), direction.getYOffset()));
    animals.stream().reduce(location.get(),
        (loc, sprt) -> {
            sprt.moveTo(loc);
            return sprt.location.get();
        }, (loc1, loc2) -> loc1);
}
 
Example #9
Source File: Flyout.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
/**
 * The "do once" configuration
 */
private void defineFlyout() {
    tl.setCycleCount(1);
    loc.addListener((obs, oldY, newY) -> {
        if(flyoutSide == Side.TOP || flyoutSide == Side.TOP_RIGHT 
        		|| flyoutSide == Side.BOTTOM || flyoutSide == Side.BOTTOM_LEFT) {
            userNodeContainer.setLayoutY(newY.doubleValue());
        }else{
            userNodeContainer.setLayoutX(newY.doubleValue());
        }

    });
    tl.statusProperty().addListener((v, o, n) -> {
        if(n == Animation.Status.STOPPED) {
            if(!flyoutShowing) {
                popup.hide();
            } 
            flyOutStatus.setValue(Flyout.Status.COMPLETE);
        }else{
            flyOutStatus.setValue(Flyout.Status.RUNNING);
        }
    });
}
 
Example #10
Source File: ConnectorUtils.java    From scenic-view with GNU General Public License v3.0 6 votes vote down vote up
public static List<Animation> getAnimations() {
        final List<Animation> animationList = new ArrayList<>();
        
        // FIXME disabled as JavaFX 8.0 has removed the AnimationPulseReceiver class
        
//        final AbstractMasterTimer timer = ToolkitAccessor.getMasterTimer();
//        try {
//            final Field field = AbstractMasterTimer.class.getDeclaredField("receivers");
//            field.setAccessible(true);
//            @SuppressWarnings("unchecked") final PulseReceiver[] object = (PulseReceiver[]) field.get(timer);
//            for (PulseReceiver pulseReceiver : object) {
//                if (pulseReceiver instanceof AnimationPulseReceiver) {
//                    final Field field2 = AnimationPulseReceiver.class.getDeclaredField("animation");
//                    field2.setAccessible(true);
//                    final Animation animation = (Animation) field2.get(pulseReceiver);
//                    animationList.add(animation);
//                }
//            }
//        } catch (final Exception e) {
//            ScenicViewExceptionLogger.submitException(e);
//        }
        return animationList;
    }
 
Example #11
Source File: ViewNumberChart.java    From helloiot with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void construct(IoTApp app) {
    super.construct(app);
    
    if (glyph != null) {
        glyphnode = new StackPane(IconBuilder.create(glyph, 36.0).styleClass("unitinputicon").build());
        glyphnode.setPadding(new Insets(0, 0, 0, 6));
        boxview.getChildren().add(0, glyphnode);
    }        
    
    device.subscribeStatus(messageHandler);

    serie = new ChartSerie();
    serie.setDevice(device);
    serie.construct();
    areachart.addShapeChart(new ShapeChartArea(serie));
           
    timeline = new Timeline(new KeyFrame(duration.divide(ChartSerie.SIZE), ae -> {
        serie.tick();
    }));  
    timeline.setCycleCount(Animation.INDEFINITE);        
    timeline.play();   
    // Do not update status all values come from messages
}
 
Example #12
Source File: RubikView.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public RubikView() {
    
    rubik = new Rubik();
    setCenter(rubik.getSubScene());
    
    timer = new Timeline(
        new KeyFrame(Duration.ZERO, 
            e -> clock.set(LocalTime.now().minusNanos(time.toNanoOfDay()).format(fmt))),
        new KeyFrame(Duration.seconds(1)));
    
    timer.setCycleCount(Animation.INDEFINITE);
    timeLabel = new Label();
    timeLabel.setStyle("-fx-text-fill: white; -fx-font-size: 0.9em;");
    timeLabel.textProperty().bind(clock);
    
    rubik.isSolved().addListener((ov,b,b1)->{
        if(b1){
            timer.stop();
            MobileApplication.getInstance().showMessage("Solved in " + (rubik.getCount().get() + 1) + " movements!");
        }
    });
    
    getStylesheets().add(RubikView.class.getResource("rubik.css").toExternalForm());
    addEventHandler(MouseEvent.ANY, rubik.eventHandler);
}
 
Example #13
Source File: MonitorController.java    From arcgis-runtime-demo-java with Apache License 2.0 5 votes vote down vote up
private void dispatchHelicopter() {
  // create an animation timer
  Timeline animator = new Timeline();
  animator.setCycleCount(Animation.INDEFINITE);

  // specify units
  LinearUnit meters = new LinearUnit(LinearUnitId.METERS);
  AngularUnit degrees = new AngularUnit(AngularUnitId.DEGREES);

  animator.getKeyFrames().add(new KeyFrame(Duration.millis(100), actionEvent -> {
    // get the geodesic distance
    GeodesicDistanceResult distance = GeometryEngine.distanceGeodesic((Point) helicopter.getGeometry(), fireLocation,
        meters, degrees, GeodeticCurveType.GEODESIC);

    if (distance.getDistance() > 40) {
      // move helicopter 10 meters towards target
      Point newPosition = GeometryEngine.moveGeodesic((Point) helicopter.getGeometry(), 40, meters, distance
          .getAzimuth1(), degrees, GeodeticCurveType.GEODESIC);
      helicopter.setGeometry(newPosition);
    } else {
      animator.stop();
      helicopterButton.setDisable(true);
      flagButton.setDisable(false);
    }
  }));
  animator.play();
}
 
Example #14
Source File: AnimatedSprite.java    From DeskChan with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void addAnimation(AnimationData data){
    if (data == null) return;
    queue.add(data);
    if (mainSprite == null){
        setCurrentAnimation();
    }

    if (timeline.getStatus() != Animation.Status.RUNNING){
        timeline.play();
    }
}
 
Example #15
Source File: MainController.java    From MusicPlayer with MIT License 5 votes vote down vote up
private void collapseSideBar() {
    if (expandAnimation.statusProperty().get() == Animation.Status.STOPPED
        && collapseAnimation.statusProperty().get() == Animation.Status.STOPPED) {

        collapseAnimation.play();
    }
}
 
Example #16
Source File: ImprovedBackgroundController.java    From examples-javafx-repos1 with Apache License 2.0 5 votes vote down vote up
@FXML
public void controlPressed() {
	if( log.isDebugEnabled() ) {
		log.debug("[CONTROL PRESSED]");
	}
	if( parallelTransition.getStatus() == Animation.Status.RUNNING ) {
		pauseAnimation();
	} else {
		startAmination();
	}
}
 
Example #17
Source File: MainController.java    From MusicPlayer with MIT License 5 votes vote down vote up
private void expandSideBar() {
    if (expandAnimation.statusProperty().get() == Animation.Status.STOPPED
        && collapseAnimation.statusProperty().get() == Animation.Status.STOPPED) {

    	expandAnimation.play();
    }
}
 
Example #18
Source File: SpriteView.java    From training with MIT License 5 votes vote down vote up
public void startAnimation() {
    Timeline timeline = new Timeline(Animation.INDEFINITE,
        new KeyFrame(Duration.seconds(.25), new KeyValue(frame, 0)),
        new KeyFrame(Duration.seconds(.5), new KeyValue(frame, 1)),
        new KeyFrame(Duration.seconds(.75), new KeyValue(frame, 2)),
        new KeyFrame(Duration.seconds(1), new KeyValue(frame, 1))
    );
    timeline.onFinishedProperty().setValue(e -> timeline.play());
    timeline.play();
}
 
Example #19
Source File: Clock.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
public Clock(Duration tickInterval, boolean start) {
    time = new ReadOnlyObjectWrapper<>(LocalDateTime.now());
    clockwork = new Timeline(new KeyFrame(tickInterval, event -> time.set(LocalDateTime.now())));
    clockwork.setCycleCount(Animation.INDEFINITE);
    if (start) {
        clockwork.play();
    }
}
 
Example #20
Source File: Beeper.java    From helloiot with GNU General Public License v3.0 5 votes vote down vote up
public Beeper(ClipFactory factory, Node alert, Animation alertanimation) {

        this.alert = alert;
        this.alertanimation = alertanimation;
        // http://www.soundjay.com/tos.html
        beep = factory.createClip(getClass().getResource("/com/adr/helloiot/sounds/beep-01a.wav").toExternalForm(), AudioClip.INDEFINITE);
    }
 
Example #21
Source File: Curbstone3D.java    From SmartCity-ParkingManagement with Apache License 2.0 5 votes vote down vote up
@Override
public void start(final Stage s) throws Exception {
	s.setTitle("Curbstone 3D");
	final Curbstone c = new Curbstone(50, Color.web("#DC143C"), 1);
	c.setTranslateX(0);
	c.rx.setAngle(25);
	c.ry.setAngle(45);

	final Timeline animation = new Timeline();
	animation.getKeyFrames().addAll(new KeyFrame(Duration.ZERO, new KeyValue(c.ry.angleProperty(), 0d)),
			new KeyFrame(Duration.valueOf("20000ms"), new KeyValue(c.ry.angleProperty(), 360d)));
	animation.setCycleCount(Animation.INDEFINITE);
	// create root group
	final Parent root = c;
	// translate and rotate group so that origin is center and +Y is up
	root.setTranslateX(200);
	root.setTranslateY(75);
	final Line line = new Line(200, 200, 200, 200);
	final Rotate rotation = new Rotate(1, Rotate.Y_AXIS);
	rotation.pivotXProperty().bind(line.startXProperty());
	rotation.pivotYProperty().bind(line.startYProperty());
	root.getTransforms().add(rotation);
	// create scene
	final Scene scene = new Scene(root, 400, 150);
	scene.setCamera(new PerspectiveCamera());
	s.setScene(scene);
	s.show();
	// start spining animation
	animation.play();
}
 
Example #22
Source File: KeyboardEventNotificator.java    From DeskChan with GNU Lesser General Public License v3.0 5 votes vote down vote up
synchronized void start(){
    Platform.runLater(() -> {
        if (timeline == null)
            handle(null);
        else if (timeline.getStatus() != Animation.Status.RUNNING) {
            timeline.play();
            timeline.setCycleCount(Timeline.INDEFINITE);
        }
    });
}
 
Example #23
Source File: DaoLaunchWindow.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
private void startAutoSectionChange() {
    autoPlayTimeline = new Timeline(new KeyFrame(
            Duration.seconds(10),
            ae -> goToNextSection()
    ));
    autoPlayTimeline.setCycleCount(Animation.INDEFINITE);

    autoPlayTimeline.play();
}
 
Example #24
Source File: CutTextEventHandler.java    From jfxvnc with Apache License 2.0 5 votes vote down vote up
public CutTextEventHandler() {

    Platform.runLater(() -> {
      clipboard = Clipboard.getSystemClipboard();
      clipTask = new Timeline(new KeyFrame(Duration.millis(500), (event) -> {
        if (clipboard.hasString()) {
          String newString = clipboard.getString();
          if (newString == null) {
            return;
          }
          if (clipTextProperty.get() == null) {
            clipTextProperty.set(newString);
            return;
          }
          if (newString != null && !clipTextProperty.get().equals(newString)) {
            fire(new ClientCutText(newString.replace("\r\n", "\n")));
            clipTextProperty.set(newString);
          }
        }
      }));
      clipTask.setCycleCount(Animation.INDEFINITE);
    });

    enabled.addListener((l, o, n) -> Platform.runLater(() -> {
      if (n) {
        clipTask.play();
      } else {
        clipTask.stop();
        clipTextProperty.set(null);
      }
    }));
  }
 
Example #25
Source File: SequentialAnimationFX.java    From AnimateFX with Apache License 2.0 5 votes vote down vote up
/**
 * Stop the animations
 */
public void stop() {
    status = Animation.Status.STOPPED;
    for (AnimationFX animationFX : animations) {
        animationFX.stop();
    }
}
 
Example #26
Source File: JFXNodesAnimation.java    From JFoenix with Apache License 2.0 5 votes vote down vote up
public void animate() {
    init();
    Animation exitAnimation = animateExit();
    Animation sharedAnimation = animateSharedNodes();
    Animation entranceAnimation = animateEntrance();
    exitAnimation.setOnFinished(finish -> sharedAnimation.play());
    sharedAnimation.setOnFinished(finish -> entranceAnimation.play());
    entranceAnimation.setOnFinished(finish -> end());
    exitAnimation.play();
}
 
Example #27
Source File: CubeSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@Override public Node create3dContent() {
    Cube c = new Cube(50,Color.RED,1);
    c.rx.setAngle(45);
    c.ry.setAngle(45);
    Cube c2 = new Cube(50,Color.GREEN,1);
    c2.setTranslateX(100);
    c2.rx.setAngle(45);
    c2.ry.setAngle(45);
    Cube c3 = new Cube(50,Color.ORANGE,1);
    c3.setTranslateX(-100);
    c3.rx.setAngle(45);
    c3.ry.setAngle(45);

    animation = new Timeline();
    animation.getKeyFrames().addAll(
            new KeyFrame(Duration.ZERO,
                    new KeyValue(c.ry.angleProperty(), 0d),
                    new KeyValue(c2.rx.angleProperty(), 0d),
                    new KeyValue(c3.rz.angleProperty(), 0d)
            ),
            new KeyFrame(Duration.seconds(1),
                    new KeyValue(c.ry.angleProperty(), 360d),
                    new KeyValue(c2.rx.angleProperty(), 360d),
                    new KeyValue(c3.rz.angleProperty(), 360d)
            ));
    animation.setCycleCount(Animation.INDEFINITE);

    return new Group(c,c2,c3);
}
 
Example #28
Source File: AdvancedStockLineChartSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public AdvancedStockLineChartSample() {
    getChildren().add(createChart());
    // create timeline to add new data every 60th of second
    animation = new Timeline();
    animation.getKeyFrames().add(new KeyFrame(Duration.millis(1000/60), new EventHandler<ActionEvent>() {
        @Override public void handle(ActionEvent actionEvent) {
            // 6 minutes data per frame
            for(int count=0; count < 6; count++) {
                nextTime();
                plotTime();
            }
        }
    }));
    animation.setCycleCount(Animation.INDEFINITE);
}
 
Example #29
Source File: JFXAlertAnimation.java    From JFoenix with Apache License 2.0 5 votes vote down vote up
@Override
public Animation createShowingAnimation(Node contentContainer, Node overlay) {
    return new CachedTransition(contentContainer, new Timeline(
        new KeyFrame(Duration.millis(1000),
            new KeyValue(contentContainer.scaleXProperty(), 1, Interpolator.EASE_OUT),
            new KeyValue(contentContainer.scaleYProperty(), 1, Interpolator.EASE_OUT),
            new KeyValue(overlay.opacityProperty(), 1, Interpolator.EASE_BOTH)
        ))) {
        {
            setCycleDuration(Duration.millis(160));
            setDelay(Duration.seconds(0));
        }
    };
}
 
Example #30
Source File: CubeSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@Override public Node create3dContent() {
    Cube c = new Cube(50,Color.RED,1);
    c.rx.setAngle(45);
    c.ry.setAngle(45);
    Cube c2 = new Cube(50,Color.GREEN,1);
    c2.setTranslateX(100);
    c2.rx.setAngle(45);
    c2.ry.setAngle(45);
    Cube c3 = new Cube(50,Color.ORANGE,1);
    c3.setTranslateX(-100);
    c3.rx.setAngle(45);
    c3.ry.setAngle(45);

    animation = new Timeline();
    animation.getKeyFrames().addAll(
            new KeyFrame(Duration.ZERO,
                    new KeyValue(c.ry.angleProperty(), 0d),
                    new KeyValue(c2.rx.angleProperty(), 0d),
                    new KeyValue(c3.rz.angleProperty(), 0d)
            ),
            new KeyFrame(Duration.seconds(1),
                    new KeyValue(c.ry.angleProperty(), 360d),
                    new KeyValue(c2.rx.angleProperty(), 360d),
                    new KeyValue(c3.rz.angleProperty(), 360d)
            ));
    animation.setCycleCount(Animation.INDEFINITE);

    return new Group(c,c2,c3);
}