ADD::Added slide-in transition for the menu bar

it gets played on load, right now it sometimes is a bit laggy but not sure if that is JavaFX or just everything getting loaded
This commit is contained in:
Sem van der Hoeven
2019-03-20 08:08:32 +01:00
parent 292035498c
commit 8345b6c06f
2 changed files with 48 additions and 7 deletions

View File

@@ -1,12 +1,17 @@
package greenify.client.controller;
import com.sun.javafx.scene.control.skin.ButtonSkin;
import greenify.client.rest.UserService;
import javafx.animation.FadeTransition;
import javafx.animation.PathTransition;
import javafx.animation.ScaleTransition;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.AnchorPane;
import javafx.scene.shape.Line;
import javafx.util.Duration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
@@ -39,13 +44,29 @@ public class DashBoardController {
@FXML
private Label welcomebacktext;
@FXML
public Button dashboardButton;
public Button activitiesButton;
public Button userButton;
public Line pathLine;
public AnchorPane menuBar;
FadeTransition fadeTrans; //transition for switching between the different panels
/**
* loads the 'welcome back' text before anything else.
* loads the the necessary things before anything else.
*/
public void initialize() {
//sets the text of the 'welcome back' text to include the username
welcomebacktext.setText("Welcome back, " + userService.currentUser.getName() + "!");
//adds the slide transition to the menu bar
addSlideTransition(menuBar, pathLine);
//adds animations to the navigation buttons
dashboardButton.setSkin(new MyButtonSkin(dashboardButton));
activitiesButton.setSkin(new MyButtonSkin(activitiesButton));
userButton.setSkin(new MyButtonSkin(userButton));
}
/**
@@ -109,7 +130,6 @@ public class DashBoardController {
* @param event the event (clicking the button)
*/
public void addVeganMeal(ActionEvent event) {
FadeTransition updateTrans = new FadeTransition(Duration.millis(200), totalVeganMealCounter);
count++;
int net = userService.currentUser.getVeganMeal() + count;
@@ -120,4 +140,25 @@ public class DashBoardController {
userService.currentUser.getName());
System.out.println("Vegetarian meal is added");
}
public void addSlideTransition(Node node, Line path1) {
PathTransition pathTrans = new PathTransition(Duration.millis(1500), path1, node);
pathTrans.play();
}
//class for the animations on the navigation buttons
public class MyButtonSkin extends ButtonSkin {
public MyButtonSkin(Button button) {
super(button);
final ScaleTransition scaleUp = new ScaleTransition(Duration.millis(100));
scaleUp.setNode(button);
scaleUp.setToX(1.1);
button.setOnMouseEntered(e -> scaleUp.playFromStart());
final ScaleTransition scaleDown = new ScaleTransition(Duration.millis(100));
scaleDown.setNode(button);
scaleDown.setToX(1.0);
button.setOnMouseExited(e -> scaleDown.playFromStart());
}
}
}

View File

@@ -44,8 +44,9 @@
</Button>
<Line endX="104.0" layoutX="102.0" layoutY="133.0" scaleY="0.7" startX="-100.0" stroke="#e3ffe8" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" />
<Line endX="104.0" layoutX="105.0" layoutY="178.0" scaleY="0.7" startX="-100.0" stroke="#e3ffe8" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" />
<Line fx:id="pathLine" endX="100.0" endY="28.0" fill="#1b9736" layoutX="5.0" layoutY="273.0" startX="-100.0" startY="28.0" stroke="#5a635c" />
</children></AnchorPane>
<AnchorPane fx:id="activitiesPane" layoutX="214.0" prefHeight="603.0" prefWidth="711.0" visible="false">
<AnchorPane fx:id="activitiesPane" layoutX="214.0" prefHeight="603.0" prefWidth="720.0" visible="false">
<children>
<Text fill="#002c0c" layoutX="101.0" layoutY="74.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Available Activities" AnchorPane.leftAnchor="60.0" AnchorPane.topAnchor="40.0">
<font>
@@ -88,7 +89,7 @@
</Pane>
<Pane layoutX="310.0" layoutY="93.0" prefHeight="471.0" prefWidth="150.0" style="-fx-background-color: #f4fff4;">
<children>
<Text layoutX="21.0" layoutY="37.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Done today" textAlignment="CENTER">
<Text layoutX="11.0" layoutY="37.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Done recently" textAlignment="CENTER">
<font>
<Font size="21.0" />
</font>
@@ -195,9 +196,9 @@
<Font size="30.0" />
</font>
</Label>
<Button layoutX="567.0" layoutY="26.0" mnemonicParsing="false" onAction="#displayActivities" prefHeight="74.0" prefWidth="62.0" style="-fx-border-radius: 20px; -fx-padding: 0px 0px 0px 0px; -fx-background-color: transparent;" textFill="#e0fcdb">
<Button contentDisplay="RIGHT" layoutX="496.0" layoutY="26.0" mnemonicParsing="false" onAction="#displayActivities" prefHeight="74.0" prefWidth="200.0" style="-fx-border-radius: 20px; -fx-padding: 0px 0px 0px 0px; -fx-background-color: transparent;" text="Add a new activity" textFill="#29721a">
<font>
<Font name="Eras Bold ITC" size="28.0" />
<Font name="Corbel Bold" size="14.0" />
</font>
<graphic>
<ImageView fitHeight="81.0" fitWidth="74.0" pickOnBounds="true" preserveRatio="true">
@@ -216,4 +217,3 @@
</AnchorPane>
</children>
</AnchorPane>