Search in sources :

Example 1 with PathTransition

use of javafx.animation.PathTransition in project CST-135 by psradke.

the class HomePageGUI method drinksCategory.

// Displays the Drinks categories page.
private StackPane drinksCategory() {
    // Set Grid pane settings.
    GridPane pane = new GridPane();
    pane.setVgap(10);
    pane.setHgap(10);
    pane.setMaxSize(575, 293);
    HBox buttonPane = new HBox();
    buttonPane.setSpacing(460);
    buttonPane.setPadding(new Insets(0, 10, 0, 10));
    buttonPane.getChildren().addAll(homeButton, cartButton);
    cartButton.setBackground(Background.EMPTY);
    cartButton.setOnAction(e -> {
        cartButton.getScene().setRoot(shoppingCart());
    });
    homeButton.setBackground(Background.EMPTY);
    homeButton.setOnAction(e -> {
        homeButton.getScene().setRoot(homePage());
    });
    VBox vBox = new VBox();
    vBox.setSpacing(50);
    vBox.setAlignment(Pos.TOP_CENTER);
    vBox.setPadding(new Insets(10, 10, 10, 10));
    vBox.getChildren().addAll(buttonPane, pane);
    // Button[] button = new Button[dispenser.productsForSale.length];
    // Line[] line = new Line[dispenser.productsForSale.length];
    // used to limit how many items are in a row.
    int rowControl = 0;
    // add event handler here for sales page
    for (int i = 0; i < dispenser.productsForSale.length; i++) {
        if (dispenser.getProduct(i) instanceof Drink) {
            StackPane prodPics = new StackPane();
            Drink temp = (Drink) dispenser.getProduct(i);
            Button button = new Button("", new ImageView(temp.image));
            button.setBackground(Background.EMPTY);
            ImageView temp2 = new ImageView(temp.image);
            prodPics.getChildren().addAll(temp2, button);
            Line line = new Line(button.getLayoutX() + temp.image.getWidth() / 2, button.getLayoutY() + temp.image.getHeight() / 2, backgroundPane.getWidth(), 0);
            PathTransition pt = new PathTransition();
            pt.setDuration(Duration.millis(1000));
            pt.setPath(line);
            pt.setNode(button.getGraphic());
            button.setOnMousePressed(e -> {
                // figure out why the items added to cart add multiple instances of item in the table
                if (!shoppingCart.contains(temp)) {
                    shoppingCart.add(new Drink(temp));
                    shoppingCart.get(shoppingCart.indexOf(temp)).setQuantity(1);
                } else {
                    shoppingCart.get(shoppingCart.indexOf(temp)).setQuantity(shoppingCart.get(shoppingCart.indexOf(temp)).quantity + 1);
                }
                // subtract one from the machine inventory.
                temp.quantity--;
                pt.play();
            });
            Text text = new Text(temp.getName() + "\n$" + temp.getPrice());
            text.setFill(Color.WHITE);
            text.setTextAlignment(TextAlignment.CENTER);
            text.setTranslateX(65);
            text.setLayoutX(i);
            if (rowControl < 3) {
                pane.addRow(0, prodPics);
                pane.addRow(1, text);
            } else {
                pane.addRow(2, prodPics);
                pane.addRow(3, text);
            }
            rowControl++;
        }
    }
    backgroundPane.getChildren().addAll(new ImageView(bgImage), vBox);
    return backgroundPane;
}
Also used : Line(javafx.scene.shape.Line) Insets(javafx.geometry.Insets) PathTransition(javafx.animation.PathTransition)

Example 2 with PathTransition

use of javafx.animation.PathTransition in project CST-135 by psradke.

the class HomePageGUI method gumCategory.

public StackPane gumCategory() {
    // Set Grid pane settings.
    GridPane pane = new GridPane();
    pane.setVgap(10);
    pane.setHgap(10);
    pane.setMaxSize(575, 293);
    HBox buttonPane = new HBox();
    buttonPane.setSpacing(460);
    buttonPane.setPadding(new Insets(0, 10, 0, 10));
    buttonPane.getChildren().addAll(homeButton, cartButton);
    cartButton.setBackground(Background.EMPTY);
    cartButton.setOnAction(e -> {
        cartButton.getScene().setRoot(shoppingCart());
    });
    homeButton.setBackground(Background.EMPTY);
    homeButton.setOnAction(e -> {
        homeButton.getScene().setRoot(homePage());
    });
    // add event handler here for sales page
    for (int i = 0; i < dispenser.productsForSale.length; i++) {
        if (dispenser.getProduct(i) instanceof Gum) {
            Gum temp = (Gum) dispenser.getProduct(i);
            Button button = new Button("", new ImageView(temp.image));
            button.setBackground(Background.EMPTY);
            StackPane prodPics = new StackPane();
            ImageView temp2 = new ImageView(temp.image);
            prodPics.getChildren().addAll(temp2, button);
            Line line = new Line(button.getLayoutX() + temp.image.getWidth() / 2, button.getLayoutY() + temp.image.getHeight() / 2, backgroundPane.getWidth(), 0);
            PathTransition pt = new PathTransition();
            pt.setDuration(Duration.millis(1000));
            pt.setPath(line);
            pt.setNode(button.getGraphic());
            button.setOnMouseReleased(e -> {
                // cart to 1, otherwise add 1 to the existing item
                if (!shoppingCart.contains(temp)) {
                    shoppingCart.add(new Gum(temp));
                    System.out.println("Not Found");
                    shoppingCart.get(shoppingCart.indexOf(temp)).setQuantity(1);
                } else {
                    shoppingCart.get(shoppingCart.indexOf(temp)).setQuantity(shoppingCart.get(shoppingCart.indexOf(temp)).quantity + 1);
                }
                // subtract one from the machine inventory.
                temp.quantity--;
                pt.play();
            });
            Text text = new Text(temp.getName() + "\n" + temp.getFlavor() + "\n$" + temp.getPrice());
            text.setFill(Color.WHITE);
            text.setTextAlignment(TextAlignment.CENTER);
            text.setTranslateX(65);
            text.setLayoutX(i);
            pane.addRow(0, prodPics);
            pane.addRow(1, text);
        }
    }
    VBox vBox = new VBox();
    vBox.setSpacing(200);
    vBox.setAlignment(Pos.TOP_CENTER);
    vBox.setPadding(new Insets(10, 10, 10, 10));
    vBox.getChildren().addAll(buttonPane, pane);
    // if (inventory.getItems().indexOf(vBox) <= 3) {
    // System.out.println("Please restock");
    // }
    backgroundPane.getChildren().addAll(new ImageView(bgImage), vBox);
    return backgroundPane;
}
Also used : Line(javafx.scene.shape.Line) Insets(javafx.geometry.Insets) PathTransition(javafx.animation.PathTransition)

Example 3 with PathTransition

use of javafx.animation.PathTransition in project CST-135 by psradke.

the class HomePageGUI method sweetsCategory.

private StackPane sweetsCategory() {
    // Set Grid pane settings.
    GridPane pane = new GridPane();
    pane.setVgap(10);
    pane.setHgap(10);
    pane.setMaxSize(575, 293);
    HBox buttonPane = new HBox();
    buttonPane.setSpacing(460);
    buttonPane.setPadding(new Insets(0, 10, 0, 10));
    buttonPane.getChildren().addAll(homeButton, cartButton);
    cartButton.setBackground(Background.EMPTY);
    cartButton.setOnAction(e -> {
        cartButton.getScene().setRoot(shoppingCart());
    });
    homeButton.setBackground(Background.EMPTY);
    homeButton.setOnAction(e -> {
        homeButton.getScene().setRoot(homePage());
    });
    // used to limit how many items are in a row.
    int rowControl = 0;
    // add event handler here for sales page
    for (int i = 0; i < dispenser.productsForSale.length; i++) {
        if (dispenser.getProduct(i) instanceof Snack) {
            Snack temp = (Snack) dispenser.getProduct(i);
            StackPane prodPics = new StackPane();
            Button button = new Button("", new ImageView(temp.image));
            button.setBackground(Background.EMPTY);
            ImageView temp2 = new ImageView(temp.image);
            prodPics.getChildren().addAll(temp2, button);
            Line line = new Line(button.getLayoutX() + temp.image.getWidth() / 2, button.getLayoutY() + temp.image.getHeight() / 2, backgroundPane.getWidth(), 0);
            PathTransition pt = new PathTransition();
            pt.setDuration(Duration.millis(1000));
            pt.setPath(line);
            pt.setNode(button.getGraphic());
            button.setOnMouseReleased(e -> {
                // cart to 1, otherwise add 1 to the existing item
                if (!shoppingCart.contains(temp)) {
                    shoppingCart.add(temp instanceof Chips ? new Chips((Chips) temp) : new Candy((Candy) temp));
                    shoppingCart.get(shoppingCart.indexOf(temp)).setQuantity(1);
                } else {
                    shoppingCart.get(shoppingCart.indexOf(temp)).setQuantity(shoppingCart.get(shoppingCart.indexOf(temp)).quantity + 1);
                }
                // subtract one from the machine inventory.
                temp.quantity--;
                System.out.println(temp.quantity);
                pt.play();
            });
            Text text = new Text(temp.getName() + "\n$" + temp.getPrice());
            text.setFill(Color.WHITE);
            text.setTextAlignment(TextAlignment.CENTER);
            text.setTranslateX(65);
            text.setLayoutX(i);
            if (rowControl < 3) {
                pane.addRow(0, prodPics);
                pane.addRow(1, text);
            } else if (rowControl >= 3 && rowControl < 6) {
                pane.addRow(2, prodPics);
                pane.addRow(3, text);
            } else if (rowControl >= 6 && rowControl < 9) {
                pane.addRow(4, prodPics);
                pane.addRow(5, text);
            }
            rowControl++;
        }
    }
    VBox vBox = new VBox();
    vBox.setSpacing(50);
    vBox.setAlignment(Pos.TOP_CENTER);
    vBox.setPadding(new Insets(10, 10, 10, 10));
    vBox.getChildren().addAll(buttonPane, pane);
    backgroundPane.getChildren().addAll(new ImageView(bgImage), vBox);
    return backgroundPane;
}
Also used : Insets(javafx.geometry.Insets) Line(javafx.scene.shape.Line) PathTransition(javafx.animation.PathTransition)

Example 4 with PathTransition

use of javafx.animation.PathTransition in project CST-135 by psradke.

the class Animation method moveImage.

protected void moveImage() {
    PathTransition pt = new PathTransition();
    pt.setDuration(Duration.millis(4000));
    pt.setPath(line);
    pt.setNode(new ImageView(img));
    pt.setOrientation(PathTransition.OrientationType.ORTHOGONAL_TO_TANGENT);
    pt.setCycleCount(Timeline.INDEFINITE);
    pt.setAutoReverse(false);
    pt.play();
    FadeTransition ft = new FadeTransition();
    ft.setDuration(Duration.seconds(3));
    ft.setNode(new ImageView(img));
    ft.setFromValue(1.0);
    ft.setToValue(0.0);
    ft.setCycleCount(0);
    ft.setAutoReverse(false);
    ft.play();
}
Also used : PathTransition(javafx.animation.PathTransition) FadeTransition(javafx.animation.FadeTransition) ImageView(javafx.scene.image.ImageView)

Aggregations

PathTransition (javafx.animation.PathTransition)4 Insets (javafx.geometry.Insets)3 Line (javafx.scene.shape.Line)3 FadeTransition (javafx.animation.FadeTransition)1 ImageView (javafx.scene.image.ImageView)1