From 9af14e60153576f1e22c4d9c2012023e62ca511c Mon Sep 17 00:00:00 2001 From: mlwauben Date: Sat, 6 Apr 2019 09:00:20 +0200 Subject: [PATCH] ADD:: logout button --- .../controller/DashBoardController.java | 33 ++++++++++++++++++- .../src/main/resources/fxml/dashboard.fxml | 5 +++ .../resources/stylesheets/dashboardStyle.css | 9 +++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/Client/src/main/java/greenify/client/controller/DashBoardController.java b/src/Client/src/main/java/greenify/client/controller/DashBoardController.java index 6ce8230..c1915f9 100644 --- a/src/Client/src/main/java/greenify/client/controller/DashBoardController.java +++ b/src/Client/src/main/java/greenify/client/controller/DashBoardController.java @@ -26,6 +26,7 @@ import javafx.scene.image.ImageView; import javafx.scene.layout.AnchorPane; import javafx.scene.shape.Line; import javafx.stage.Stage; +import javafx.stage.Window; import javafx.util.Duration; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; @@ -33,6 +34,7 @@ import org.springframework.stereotype.Controller; import java.io.IOException; import java.util.List; import java.util.Map; +import java.util.Objects; /** * Class that controls the dashboard fxml file (the GUI Screen). @@ -70,6 +72,8 @@ public class DashBoardController { @FXML private Button friendsButton; @FXML + private Button logOutButton; + @FXML private Line pathLine; @FXML private AnchorPane menuBar; @@ -197,7 +201,7 @@ public class DashBoardController { activitiesButton.setSkin(new MyButtonSkin(activitiesButton)); userButton.setSkin(new MyButtonSkin(userButton)); friendsButton.setSkin(new MyButtonSkin(friendsButton)); - + logOutButton.setSkin(new MyButtonSkin(logOutButton)); friendsColumn.setCellValueFactory(new PropertyValueFactory<>("Friend")); scoreColumn.setCellValueFactory(new PropertyValueFactory<>("Score")); globalUser.setCellValueFactory(new PropertyValueFactory<>("Friend")); @@ -403,6 +407,33 @@ public class DashBoardController { updateFriends(); } + /** + * Logs out the user + * @param event the event (clicking the button) + * @throws IOException if the Application doesn't load. + */ + public void logOut(ActionEvent event) throws IOException { + //get the current window + Window owner = logOutButton.getScene().getWindow(); + Stage current = (Stage) owner; + //close current window (log out) + current.close(); + System.out.println("User is logged out"); + + //load the fxml file + Parent dash = Application.load(this.getClass().getClassLoader() + .getResource("fxml/LoginWindow.fxml")); + Scene scene = new Scene(dash); + //add the stylesheet for the CSS + scene.getStylesheets().add(Objects.requireNonNull(getClass().getClassLoader() + .getResource("stylesheets/LoginWindowStyle.css")).toExternalForm()); + Stage appStage = new Stage(); + appStage.setScene(scene); + //set the title + appStage.setTitle("Greenify"); + appStage.show(); + } + //sets the slide in transition for startup public void addSlideTransition(Node node, Line path1) { PathTransition pathTrans = new PathTransition(Duration.millis(1100), path1, node); diff --git a/src/Client/src/main/resources/fxml/dashboard.fxml b/src/Client/src/main/resources/fxml/dashboard.fxml index 614d721..ff36756 100644 --- a/src/Client/src/main/resources/fxml/dashboard.fxml +++ b/src/Client/src/main/resources/fxml/dashboard.fxml @@ -44,6 +44,11 @@ + diff --git a/src/Client/src/main/resources/stylesheets/dashboardStyle.css b/src/Client/src/main/resources/stylesheets/dashboardStyle.css index a7eefaa..7b1a3c8 100644 --- a/src/Client/src/main/resources/stylesheets/dashboardStyle.css +++ b/src/Client/src/main/resources/stylesheets/dashboardStyle.css @@ -47,6 +47,15 @@ #friendsButton:pressed { -fx-background-color: #b7e2c2; } +#logOutButton { + -fx-background-color: #5a635c; +} +#logOutButton:hover { + -fx-background-color: #677069; +} +#logOutButton:pressed { + -fx-background-color: #b7e2c2; +} #addNewActivityButton:pressed {