Commits

shemnon committed db5334b

start to get rid of builders

Comments (0)

Files changed (5)

src/main/java/com/github/shemnon/deckcontrol/skin/FadeDeckSkin.java

 package com.github.shemnon.deckcontrol.skin;
 
 import com.github.shemnon.deckcontrol.Deck;
-import javafx.animation.FadeTransitionBuilder;
+import javafx.animation.FadeTransition;
 import javafx.beans.value.ChangeListener;
 import javafx.scene.Node;
 import javafx.util.Duration;
             if (currentNode != null) {
                 currentNode.setOpacity(0.0);
                 currentNode.setVisible(true);
-                FadeTransitionBuilder.create()
-                        .node(currentNode)
-                        .fromValue(0.0)
-                        .toValue(1.0)
-                        .duration(Duration.seconds(1))
-                        .build()
-                        .play();
+                FadeTransition fade = new FadeTransition(Duration.seconds(1), currentNode);
+                fade.setFromValue(0.0);
+                fade.setToValue(1.0);
+                fade.play();
             }
             if (oldNode != null) {
                 // slide last slide to left
-                FadeTransitionBuilder.create()
-                        .node(oldNode)
-                        .toValue(0.0)
-                        .duration(Duration.seconds(1))
-                        .onFinished(actionEvent -> {
-                            oldNode.setVisible(false);
-                            oldNode.setOpacity(1.0);
-                        })
-                        .build()
-                        .play();
+                FadeTransition fade = new FadeTransition(Duration.seconds(1), oldNode);
+                fade.setToValue(0.0);
+                fade.setOnFinished(actionEvent -> {
+                    oldNode.setVisible(false);
+                    oldNode.setOpacity(1.0);}
+                );
+                fade.play();
             }
         }
     }

src/main/java/com/github/shemnon/deckcontrol/skin/PileDeckSkin.java

                 node.setScaleY(4.0);
                 node.setScaleZ(4.0);
                 node.setVisible(true);
-                transitions.add(
-                        new ParallelTransition(
-                                FadeTransitionBuilder.create()
-                                    .toValue(1.0)
-                                    .node(node)
-                                    .duration(duration)
-                                    .build(),
-                                ScaleTransitionBuilder.create()
-                                    .fromX(4.0).fromY(4.0).fromZ(4.0)
-                                    .toX(1.0).toY(1.0).toZ(1.0)
-                                    .node(node)
-                                    .duration(duration)
-                                    .build()
-                        )
-                );
 
+                FadeTransition fade = new FadeTransition(duration, node);
+                fade.setToValue(1.0);
+
+                ScaleTransition scale = new ScaleTransition(duration, node);
+                scale.setFromX(4.0);
+                scale.setFromY(4.0);
+                scale.setFromZ(4.0);
+                scale.setToX(1.0);
+                scale.setToY(1.0);
+                scale.setToZ(1.0);
+
+                transitions.add(new ParallelTransition(fade, scale));
             }
         } else if (lastIndex > shownIndex) {
             // flop cards out
                 node.setScaleY(1.0);
                 node.setScaleZ(1.0);
                 node.setVisible(true);
-                transitions.add(
-                        new ParallelTransition(
-                                FadeTransitionBuilder.create()
-                                        .fromValue(1.0)
-                                        .toValue(0.0)
-                                        .onFinished(actionEvent -> node.setVisible(false))
-                                        .node(node)
-                                        .duration(duration)
-                                        .build(),
-                                ScaleTransitionBuilder.create()
-                                        .fromX(1.0).fromY(1.0).fromZ(1.0)
-                                        .toX(4.0).toY(4.0).toZ(4.0)
-                                        .node(node)
-                                        .duration(duration)
-                                        .build()
-                        )
-                );
+
+                FadeTransition fade = new FadeTransition(duration, node);
+                fade.setFromValue(1.0);
+                fade.setToValue(0.0);
+                fade.setOnFinished(actionEvent -> node.setVisible(false));
+
+                ScaleTransition scale = new ScaleTransition(duration, node);
+                scale.setFromX(1.0);
+                scale.setFromY(1.0);
+                scale.setFromZ(1.0);
+                scale.setToX(4.0);
+                scale.setToY(4.0);
+                scale.setToZ(4.0);
+
+                transitions.add(new ParallelTransition(fade, scale));
             }
         }
 

src/main/java/com/github/shemnon/deckcontrol/skin/ShiftDeckSkin.java

 package com.github.shemnon.deckcontrol.skin;
 
 import com.github.shemnon.deckcontrol.Deck;
-import javafx.animation.Animation;
-import javafx.animation.ParallelTransition;
-import javafx.animation.SequentialTransition;
-import javafx.animation.TranslateTransitionBuilder;
+import javafx.animation.*;
 import javafx.beans.value.ChangeListener;
 import javafx.event.ActionEvent;
 import javafx.event.EventHandler;
         } else if (lastIndex < shownIndex) {
             if (oldNode != null) {
                 // slide last slide to left
-                transition.getChildren().add(
-                        TranslateTransitionBuilder.create()
-                                .node(oldNode)
-                                .fromX(0)
-                                .toX(-deck.getWidth())
-                                .duration(Duration.seconds(1))
-                                .onFinished(hideOldNode)
-                                .build());
+                TranslateTransition translate = new TranslateTransition(Duration.seconds(1), oldNode);
+                translate.setFromX(0);
+                translate.setToX(-deck.getWidth());
+                translate.setOnFinished(hideOldNode);
+
+                transition.getChildren().add(translate);
             }
             if (currentNode != null) {
                 // slide next slide from right
                 currentNode.setTranslateX(deck.getWidth());
                 currentNode.setVisible(true);
-                transition.getChildren().add(
-                        TranslateTransitionBuilder.create()
-                            .node(currentNode)
-                            .fromX(deck.getWidth())
-                            .toX(0)
-                            .duration(Duration.seconds(1))
-                            .build());
+
+                TranslateTransition translate = new TranslateTransition(Duration.seconds(1), currentNode);
+                translate.setFromX(deck.getWidth());
+                translate.setToX(0);
+
+                transition.getChildren().add(translate);
             }
         } else {
             if (oldNode != null) {
                 // slide last slide to right
-                transition.getChildren().add(
-                        TranslateTransitionBuilder.create()
-                            .node(oldNode)
-                            .fromX(0)
-                            .toX(deck.getWidth())
-                            .duration(Duration.seconds(1))
-                            .onFinished(hideOldNode)
-                            .build());
+                TranslateTransition translate = new TranslateTransition(Duration.seconds(1), oldNode);
+                translate.setFromX(0);
+                translate.setToX(deck.getWidth());
+                translate.setOnFinished(hideOldNode);
+
+                transition.getChildren().add(translate);
             }
             if (currentNode != null) {
                 // slide next slide from left
                 currentNode.setTranslateX(-deck.getWidth());
                 currentNode.setVisible(true);
-                transition.getChildren().add(
-                        TranslateTransitionBuilder.create()
-                            .node(currentNode)
-                            .fromX(-deck.getWidth())
-                            .toX(0)
-                            .duration(Duration.seconds(1))
-                            .build());
+
+                TranslateTransition translate = new TranslateTransition(Duration.seconds(1), currentNode);
+                translate.setFromX(-deck.getWidth());
+                translate.setToX(0);
+
+                transition.getChildren().add(translate);
             }
         }
         if (sequentialTransition.getStatus() == Animation.Status.RUNNING) {

src/main/java/com/github/shemnon/deckcontrol/skin/SlideDeckSkin.java

 package com.github.shemnon.deckcontrol.skin;
 
 import com.github.shemnon.deckcontrol.Deck;
-import javafx.animation.TranslateTransitionBuilder;
+import javafx.animation.TranslateTransition;
 import javafx.beans.value.ChangeListener;
 import javafx.event.ActionEvent;
 import javafx.event.EventHandler;
                 // slide next slide from right
                 currentNode.setTranslateX(deck.getWidth());
                 currentNode.setVisible(true);
-                TranslateTransitionBuilder.create()
-                        .node(currentNode)
-                        .fromX(deck.getWidth())
-                        .toX(0)
-                        .duration(Duration.seconds(1))
-                        .onFinished(hideOldNode)
-                        .build()
-                        .play();
+
+                TranslateTransition translate = new TranslateTransition(Duration.seconds(1), currentNode);
+                translate.setFromX(deck.getWidth());
+                translate.setToX(0);
+                translate.setOnFinished(hideOldNode);
+
+                translate.play();
             } else {
                 // slide last slide to left
-                TranslateTransitionBuilder.create()
-                        .node(hideNode)
-                        .fromX(0)
-                        .toX(-deck.getWidth())
-                        .duration(Duration.seconds(1))
-                        .onFinished(hideOldNode)
-                        .build()
-                        .play();
+                TranslateTransition translate = new TranslateTransition(Duration.seconds(1), hideNode);
+                translate.setFromX(0);
+                translate.setToX(-deck.getWidth());
+                translate.setOnFinished(hideOldNode);
+
+                translate.play();
             }
         } else {
             if (hideNode != null) {
                     currentNode.setTranslateX(0);
                     currentNode.setVisible(true);
                 }
-                TranslateTransitionBuilder.create()
-                        .node(hideNode)
-                        .fromX(0)
-                        .toX(deck.getWidth())
-                        .duration(Duration.seconds(1))
-                        .onFinished(hideOldNode)
-                        .build()
-                        .play();
+                TranslateTransition translate = new TranslateTransition(Duration.seconds(1), hideNode);
+                translate.setFromX(0);
+                translate.setToX(deck.getWidth());
+                translate.setOnFinished(hideOldNode);
+
+                translate.play();
             } else {
                 // slide current slide from left
                 currentNode.setTranslateX(-deck.getWidth());
                 currentNode.setVisible(true);
-                TranslateTransitionBuilder.create()
-                        .node(currentNode)
-                        .fromX(-deck.getWidth())
-                        .toX(0)
-                        .duration(Duration.seconds(1))
-                        .onFinished(hideOldNode)
-                        .build()
-                        .play();
+
+                TranslateTransition translate = new TranslateTransition(Duration.seconds(1), currentNode);
+                translate.setFromX(-deck.getWidth());
+                translate.setToX(0);
+                translate.setOnFinished(hideOldNode);
+
+                translate.play();
             }
         }
     }

src/test/java/com/github/shemnon/deckcontrol/DemoOne.java

 
 import javafx.application.Application;
 import javafx.scene.Node;
-import javafx.scene.SceneBuilder;
-import javafx.scene.control.ButtonBuilder;
-import javafx.scene.layout.HBoxBuilder;
+import javafx.scene.Scene;
+import javafx.scene.control.Button;
+import javafx.scene.layout.HBox;
 import javafx.scene.layout.Pane;
 import javafx.scene.layout.StackPane;
-import javafx.scene.layout.VBoxBuilder;
+import javafx.scene.layout.VBox;
 import javafx.scene.text.Text;
 import javafx.stage.Stage;
 
     public void start(Stage stage) throws Exception {
         final Deck deck = createDeck();
 
-        stage.setScene(SceneBuilder.create()
-                .root(
-                        VBoxBuilder.create()
-                                .fillWidth(false)
-                                .children(
-                                        deck,
-                                        HBoxBuilder.create().children(
-                                                ButtonBuilder.create()
-                                                        .text("<<")
-                                                        .onAction(actionEvent -> deck.previousNode()).build(),
-                                                ButtonBuilder.create()
-                                                        .text(">>")
-                                                        .onAction(actionEvent -> deck.nextNode()).build()
-                                        ).build(),
-                                        HBoxBuilder.create().children(
-                                                ButtonBuilder.create()
-                                                        .text("Slide")
-                                                        .onAction(actionEvent -> deck.setStyle("-fx-skin: 'com.github.shemnon.deckcontrol.skin.SlideDeckSkin'")).build(),
-                                                ButtonBuilder.create()
-                                                        .text("Fade")
-                                                        .onAction(actionEvent -> deck.setStyle("-fx-skin: 'com.github.shemnon.deckcontrol.skin.FadeDeckSkin'")).build(),
-                                                ButtonBuilder.create()
-                                                        .text("Shift")
-                                                        .onAction(actionEvent -> deck.setStyle("-fx-skin: 'com.github.shemnon.deckcontrol.skin.ShiftDeckSkin'")).build(),
-                                                ButtonBuilder.create()
-                                                        .text("Shelf")
-                                                        .onAction(actionEvent -> deck.setStyle("-fx-skin: 'com.github.shemnon.deckcontrol.skin.ShelfDeckSkin'")).build()
-                                        ).build()
-                                ).build())
-                .width(300)
-                .height(300)
-                .build());
+        Button left = new Button("<<");
+        left.setOnAction(actionEvent -> deck.previousNode());
+        Button right = new Button("<<");
+        right.setOnAction(actionEvent -> deck.nextNode());
 
+        Button slide = new Button("Slide");
+        slide.setOnAction(actionEvent -> deck.setStyle("-fx-skin: 'com.github.shemnon.deckcontrol.skin.SlideDeckSkin'"));
+        Button fade = new Button("Fade");
+        fade.setOnAction(actionEvent -> deck.setStyle("-fx-skin: 'com.github.shemnon.deckcontrol.skin.FadeDeckSkin'"));
+        Button shift = new Button("Shift");
+        shift.setOnAction(actionEvent -> deck.setStyle("-fx-skin: 'com.github.shemnon.deckcontrol.skin.ShiftDeckSkin'"));
+        Button shelf = new Button("Shelf");
+        shelf.setOnAction(actionEvent -> deck.setStyle("-fx-skin: 'com.github.shemnon.deckcontrol.skin.ShelfDeckSkin'"));
 
-        stage.setWidth(300);
-        stage.setHeight(300);
+        VBox box = new VBox(
+                deck,
+                new HBox(left, right),
+                new HBox(slide, fade, shift, shelf)
+        );
+        box.setFillWidth(false);
+        box.setPrefWidth(300);
+        box.setPrefHeight(300);
+
+        Scene scene = new Scene(box);
+        stage.setScene(scene);
 
         stage.show();
     }