Java Code Examples for javafx.animation.Animation#play()

The following examples show how to use javafx.animation.Animation#play() . 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: MainProgramSceneController.java    From Hostel-Management-System with MIT License 6 votes vote down vote up
@FXML
private void shirnkDetailsAction(ActionEvent event)
{
    if ("Cancel".equals(StudentDetailController.editCancelButton.getText()))
    {
        StudentDetailController.editCancelButtonAction(event);
    }

    final Animation animation = new Transition()
    {
        
        {
            setCycleDuration(Duration.millis(800));
        }

        @Override
        protected void interpolate(double frac)
        {
            SplitPaneMain.setDividerPosition(0, SplitPaneMain.getDividerPositions()[0]-frac);
        }
    };
    animation.play();
}
 
Example 2
Source File: AnimatedTableRow.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
private void moveDataWithAnimation(final TableView<Person> sourceTable,
		final TableView<Person> destinationTable,
		final Pane commonTableAncestor, final TableRow<Person> row) {
	// Create imageview to display snapshot of row:
	final ImageView imageView = createImageView(row);
	// Start animation at current row:
	final Point2D animationStartPoint = row.localToScene(new Point2D(0, 0)); // relative to Scene
	final Point2D animationEndPoint = computeAnimationEndPoint(destinationTable); // relative to Scene
	// Set start location
	final Point2D startInRoot = commonTableAncestor.sceneToLocal(animationStartPoint); // relative to commonTableAncestor
	imageView.relocate(startInRoot.getX(), startInRoot.getY());
	// Create animation
	final Animation transition = createAndConfigureAnimation(
			sourceTable, destinationTable, commonTableAncestor, row,
			imageView, animationStartPoint, animationEndPoint);
	// add animated image to display
	commonTableAncestor.getChildren().add(imageView);
	// start animation
	transition.play();
}
 
Example 3
Source File: JFXAlert.java    From JFoenix with Apache License 2.0 6 votes vote down vote up
/**
 * play the hide animation for the dialog, as the java hide method is set to final
 * so it can not be overridden
 */
public void hideWithAnimation() {
    if (transition == null || transition.getStatus().equals(Animation.Status.STOPPED)) {
        JFXAlertAnimation currentAnimation = getCurrentAnimation();
        Animation animation = currentAnimation.createHidingAnimation(getDialogPane().getContent(), getDialogPane());
        if (animation != null) {
            transition = animation;
            animation.setOnFinished(finish -> {
                animateClosing = false;
                hide();
                transition = null;
            });
            animation.play();
        } else {
            animateClosing = false;
            transition = null;
            Platform.runLater(this::hide);
        }
    }
}
 
Example 4
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 5
Source File: ArtistsMainController.java    From MusicPlayer with MIT License 5 votes vote down vote up
@Override
public void scroll(char letter) {
	
	ObservableList<Artist> artistListItems = artistList.getItems();
	
	int selectedCell = 0;

    for (Artist artist : artistListItems) {
        // Removes article from artist title and compares it to selected letter.
        String artistTitle = artist.getTitle();
        char firstLetter = removeArticle(artistTitle).charAt(0);
        if (firstLetter < letter) {
            selectedCell++;
        }
    }
	
	double startVvalue = artistListScrollPane.getVvalue();
	double finalVvalue = (double) (selectedCell * 50) / (Library.getArtists().size() * 50 - artistListScrollPane.getHeight());
	
	Animation scrollAnimation = new Transition() {
        {
            setCycleDuration(Duration.millis(500));
        }
        protected void interpolate(double frac) {
            double vValue = startVvalue + ((finalVvalue - startVvalue) * frac);
            artistListScrollPane.setVvalue(vValue);
        }
    };
    scrollAnimation.play();
}
 
Example 6
Source File: AlbumsController.java    From MusicPlayer with MIT License 5 votes vote down vote up
private void populateSongTable(VBox cell, Album selectedAlbum) { 	
	// Retrieves albums songs and stores them as an observable list.
	ObservableList<Song> albumSongs = FXCollections.observableArrayList(selectedAlbum.getSongs());
	
    playingColumn.setCellFactory(x -> new PlayingTableCell<Song, Boolean>());
    titleColumn.setCellFactory(x -> new ControlPanelTableCell<Song, String>());
    lengthColumn.setCellFactory(x -> new ClippedTableCell<Song, String>());
    playsColumn.setCellFactory(x -> new ClippedTableCell<Song, Integer>());

    // Sets each column item.
    playingColumn.setCellValueFactory(new PropertyValueFactory<Song, Boolean>("playing"));
    titleColumn.setCellValueFactory(new PropertyValueFactory<Song, String>("title"));
    lengthColumn.setCellValueFactory(new PropertyValueFactory<Song, String>("length"));
    playsColumn.setCellValueFactory(new PropertyValueFactory<Song, Integer>("playCount"));
    
    // Adds songs to table.
    songTable.setItems(albumSongs);
    double height = (albumSongs.size() + 1) * 50 + 2;
    Animation songTableLoadAnimation = new Transition() {
    	{
    		setCycleDuration(Duration.millis(250));
            setInterpolator(Interpolator.EASE_BOTH);
    	}
    	
    	protected void interpolate(double frac) {
    		songTable.setMinHeight(frac * height);
            songTable.setPrefHeight(frac * height);
    	}
    };
    songTableLoadAnimation.play();
}
 
Example 7
Source File: AlbumsController.java    From MusicPlayer with MIT License 5 votes vote down vote up
@Override
public void scroll(char letter) {
	
 int index = 0;
	double cellHeight = 0;
	ObservableList<Node> children = grid.getChildren();
	
	for (int i = 0; i < children.size(); i++) {
		
		VBox cell = (VBox) children.get(i);
		cellHeight = cell.getHeight();
		if (cell.getChildren().size() > 1) {
			Label label = (Label) cell.getChildren().get(1);
    		char firstLetter = removeArticle(label.getText()).charAt(0);
    		if (firstLetter < letter) {
    			index++;
    		}	
		}
	}
	
	double row = (index / 5) * cellHeight;
	double finalVvalue = row / (grid.getHeight() - gridBox.getHeight());
	double startVvalue = gridBox.getVvalue();
	
	Animation scrollAnimation = new Transition() {
        {
            setCycleDuration(Duration.millis(500));
        }
        protected void interpolate(double frac) {
            double vValue = startVvalue + ((finalVvalue - startVvalue) * frac);
            gridBox.setVvalue(vValue);
        }
    };
    
    scrollAnimation.play();
}
 
Example 8
Source File: ArtistsController.java    From MusicPlayer with MIT License 5 votes vote down vote up
@Override
public void scroll(char letter) {
	
	int index = 0;
	double cellHeight = 0;
	ObservableList<Node> children = grid.getChildren();

    for (Node node : children) {

        VBox cell = (VBox) node;
        cellHeight = cell.getHeight();
        Label label = (Label) cell.getChildren().get(1);
        char firstLetter = removeArticle(label.getText()).charAt(0);
        if (firstLetter < letter) {
            index++;
        }
    }
	
	ScrollPane scrollpane = MusicPlayer.getMainController().getScrollPane();
	
	double row = (index / 5) * cellHeight;
	double finalVvalue = row / (grid.getHeight() - scrollpane.getHeight());
	double startVvalue = scrollpane.getVvalue();
	
	Animation scrollAnimation = new Transition() {
        {
            setCycleDuration(Duration.millis(500));
        }
        protected void interpolate(double frac) {
            double vValue = startVvalue + ((finalVvalue - startVvalue) * frac);
            scrollpane.setVvalue(vValue);
        }
    };
    
    scrollAnimation.play();
}
 
Example 9
Source File: SpaceInvadersController.java    From FXGLGames with MIT License 4 votes vote down vote up
public void loseLife() {
    Texture t = lives.get(lives.size() - 1);

    lives.remove(t);

    Animation animation = getAnimationLoseLife(t);
    animation.setOnFinished(e -> gameScene.removeUINode(t));
    animation.play();

    Viewport viewport = gameScene.getViewport();

    Node flash = new Rectangle(viewport.getWidth(), viewport.getHeight(), Color.rgb(190, 10, 15, 0.5));

    gameScene.addUINode(flash);

    runOnce(() -> gameScene.removeUINode(flash), Duration.seconds(1));
}
 
Example 10
Source File: SpaceInvadersController.java    From FXGLGames with MIT License 4 votes vote down vote up
public void loseLife() {
    Texture t = lives.get(lives.size() - 1);

    lives.remove(t);

    Animation animation = getAnimationLoseLife(t);
    animation.setOnFinished(e -> gameScene.removeUINode(t));
    animation.play();

    Viewport viewport = gameScene.getViewport();

    Node flash = new Rectangle(viewport.getWidth(), viewport.getHeight(), Color.rgb(190, 10, 15, 0.5));

    gameScene.addUINode(flash);

    runOnce(() -> gameScene.removeUINode(flash), Duration.seconds(1));
}
 
Example 11
Source File: LogLine.java    From LogFX with GNU General Public License v3.0 4 votes vote down vote up
@MustCallOnJavaFXThread
void animate( Color color ) {
    Animation animation = new BackgroundTransition( color );
    animation.play();
}