diff --git a/src/Client/src/main/java/greenify/client/Application.java b/src/Client/src/main/java/greenify/client/Application.java index 40c41f3..127b49f 100644 --- a/src/Client/src/main/java/greenify/client/Application.java +++ b/src/Client/src/main/java/greenify/client/Application.java @@ -16,7 +16,7 @@ import java.io.IOException; @SpringBootApplication public class Application extends javafx.application.Application { private static ConfigurableApplicationContext springContext; -// private static final Logger log = LoggerFactory.getLogger(Application.class); + //private static final Logger log = LoggerFactory.getLogger(Application.class); /** * This (main) method starts launch. @@ -53,7 +53,8 @@ public class Application extends javafx.application.Application { */ @Override public void start(Stage primaryStage) throws Exception { - Parent rootNode = load(this.getClass().getClassLoader().getResource("fxml/LoginWindow.fxml")); + Parent rootNode = load(this.getClass().getClassLoader() + .getResource("fxml/LoginWindow.fxml")); primaryStage.setTitle("Greenify"); Scene scene = new Scene(rootNode); primaryStage.setScene(scene); 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 80918bd..e9d2466 100644 --- a/src/Client/src/main/java/greenify/client/controller/DashBoardController.java +++ b/src/Client/src/main/java/greenify/client/controller/DashBoardController.java @@ -22,18 +22,14 @@ import org.springframework.stereotype.Controller; import java.io.IOException; -//Class that controls the dashboard fxml file (the GUI Screen) - - +/** + * Class that controls the dashboard fxml file (the GUI Screen). + */ @Controller public class DashBoardController { @Autowired UserService userService; - private FadeTransition fadeTrans; //transition for switching between the different panels - private int net; - private int count = 0; - @FXML private AnchorPane dashboardPane; @FXML @@ -43,11 +39,9 @@ public class DashBoardController { @FXML private AnchorPane friendsPane; @FXML - private Label veganMealCounter; - @FXML private Label totalVeganMealCounter; @FXML - private Label welcomebacktext; + private Label welcomeBackText; @FXML private Button dashboardButton; @FXML @@ -60,20 +54,18 @@ public class DashBoardController { private Line pathLine; @FXML private AnchorPane menuBar; + @FXML private Button addNewActivityButton; @FXML private Button calculateFootPrintButton; - - - /** - * loads the the necessary things 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() + "!"); + welcomeBackText.setText("Welcome back, " + userService.currentUser.getName() + "!"); //adds the slide transition to the menu bar addSlideTransition(menuBar, pathLine); //adds animations to the navigation buttons @@ -90,20 +82,22 @@ public class DashBoardController { } /** - * adds a fade transition for switching between the different panes. + * Adds a fade transition for switching between the different panes. * @param node the node on which the transition needs to act */ - public void addFadeTransition(Node node) { + private void addFadeTransition(Node node) { - fadeTrans = new FadeTransition(Duration.millis(400), node); + // FadeTransition is now a local variable + // net is now a local variable + //transition for switching between the different panels + FadeTransition fadeTrans = new FadeTransition(Duration.millis(400), node); fadeTrans.setFromValue(0); fadeTrans.setToValue(1.0); fadeTrans.play(); } - /** - * displays the dashboard pane. + * Displays the dashboard pane. * @param event the event (clicking the button) */ public void displayDashboard(ActionEvent event) { @@ -113,15 +107,15 @@ public class DashBoardController { userPane.setVisible(false); activitiesPane.setVisible(false); friendsPane.setVisible(false); - } /** - * displays the activities pane. + * Displays the activities pane. * @param event the event (clicking the button) */ public void displayActivities(ActionEvent event) { addFadeTransition(activitiesPane); + int net = 0; totalVeganMealCounter.setText("" + net); System.out.println("display activities"); dashboardPane.setVisible(false); @@ -131,7 +125,7 @@ public class DashBoardController { } /** - * displays the user profile pane. + * Displays the user profile pane. * @param event the event (clicking the button) */ public void displayUser(ActionEvent event) { @@ -141,9 +135,12 @@ public class DashBoardController { userPane.setVisible(true); activitiesPane.setVisible(false); friendsPane.setVisible(false); - } + /** + * Displays the friends pane. + * @param event the event (clicking the button) + */ public void displayFriends(ActionEvent event) { addFadeTransition(friendsPane); System.out.println("display friends"); @@ -154,7 +151,7 @@ public class DashBoardController { } //sets the slide in transition for startup - public void addSlideTransition(Node node, Line path1) { + private void addSlideTransition(Node node, Line path1) { PathTransition pathTrans = new PathTransition(Duration.millis(1100), path1, node); pathTrans.play(); } @@ -179,7 +176,7 @@ public class DashBoardController { * and scales down when you stop hovering over it. * @param button the button to add the animation to */ - public MyButtonSkin(Button button) { + MyButtonSkin(Button button) { //inherit the button properties super(button); //transition to scale up on hover diff --git a/src/Client/src/main/java/greenify/client/controller/RegisterWindowController.java b/src/Client/src/main/java/greenify/client/controller/RegisterWindowController.java index c44b668..62ac1ce 100644 --- a/src/Client/src/main/java/greenify/client/controller/RegisterWindowController.java +++ b/src/Client/src/main/java/greenify/client/controller/RegisterWindowController.java @@ -9,7 +9,7 @@ import javafx.scene.control.Alert; import javafx.scene.control.Button; import javafx.scene.control.PasswordField; import javafx.scene.control.TextField; -import javafx.scene.shape.Line; +//import javafx.scene.shape.Line; import javafx.stage.Stage; import javafx.stage.Window; import javafx.util.Duration; @@ -18,7 +18,9 @@ import org.springframework.stereotype.Controller; import java.util.concurrent.TimeUnit; -//class that controls the actions for the register window +/** + * Class that controls the actions for the register window. + */ @Controller public class RegisterWindowController { @@ -32,12 +34,17 @@ public class RegisterWindowController { @FXML private PasswordField passwordField2; @FXML - private Button signupButton; - @FXML - private Line uNamePathLine; + private Button signUpButton; + //@FXML + //private Line uNamePathLine; + /** + * Initializes the animation. + * @throws InterruptedException exception when interrupted + */ public void initialize() throws InterruptedException { - // PathTransition pathTransUName = new PathTransition(Duration.millis(1100), uNamePathLine, userNameText); + // PathTransition pathTransUName = new PathTransition(Duration.millis(1100), + // uNamePathLine, userNameText); // pathTransUName.play(); addSlideAnimation(1100, userNameText, -300); addSlideAnimation(1100, passwordField, 300); @@ -46,7 +53,13 @@ public class RegisterWindowController { } - public void addSlideAnimation(int duration, Node node, int from) { + /** + * Adds the slide animation. + * @param duration the duration + * @param node the node + * @param from from where + */ + private void addSlideAnimation(int duration, Node node, int from) { TranslateTransition slideIn = new TranslateTransition(Duration.millis(duration), node); slideIn.setFromX(from); slideIn.setToX(0); @@ -54,13 +67,13 @@ public class RegisterWindowController { } /** - * signs the user up. + * Signs up the user. * @param event the click of the sign up button */ @FXML public void handleSignUpButton(ActionEvent event) { //set the window to the current window (for displaying the alerts) - Window owner = signupButton.getScene().getWindow(); + Window owner = signUpButton.getScene().getWindow(); //check if the username field is empty if (userNameText.getText().isEmpty()) { //if so, display an alert diff --git a/src/Client/src/main/java/greenify/client/controller/UserController.java b/src/Client/src/main/java/greenify/client/controller/UserController.java index fc0f097..9c3e238 100644 --- a/src/Client/src/main/java/greenify/client/controller/UserController.java +++ b/src/Client/src/main/java/greenify/client/controller/UserController.java @@ -16,8 +16,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import java.io.IOException; +import java.util.Objects; -//class that controls the actions for the login screen +/** + * Class that controls the actions for the login screen. + */ @Controller public class UserController { @Autowired @@ -33,10 +36,10 @@ public class UserController { private Button loginButton; @FXML - private Button signupButton; + private Button signUpButton; /** - * handles when the user clicks on the login button. + * Handles when the user clicks on the login button. * it checks if the username and password fields are filled * and gives alerts if they aren't filled in. * @param event the click of the login button @@ -75,18 +78,18 @@ public class UserController { } /** - * opens the dashboard stage. + * Opens the dashboard stage. * @throws IOException exception if fxml file can't be found * @author sem */ - public void openDashboard() throws IOException { + private void openDashboard() throws IOException { //load the fxml file Parent dash = Application.load(this.getClass().getClassLoader() .getResource("fxml/dashboard.fxml")); Scene scene = new Scene(dash); //add the stylesheet for the CSS - scene.getStylesheets().add(getClass().getClassLoader() - .getResource("stylesheets/dashboardStyle.css").toExternalForm()); + scene.getStylesheets().add(Objects.requireNonNull(getClass().getClassLoader() + .getResource("stylesheets/dashboardStyle.css")).toExternalForm()); Stage appStage = new Stage(); appStage.setScene(scene); //set the title @@ -94,8 +97,10 @@ public class UserController { appStage.show(); } - //class for showing the alerts - public static class AlertHelper { + /** + * Class for showing the alerts. + */ + static class AlertHelper { /** * alerts for the login screen. * @param alertType the type of alert @@ -103,10 +108,10 @@ public class UserController { * @param title the title given to the displayed alert * @param message the message displayed in the alert */ - public static void showAlert(Alert.AlertType alertType, - Window owner, - String title, - String message) { + static void showAlert(Alert.AlertType alertType, + Window owner, + String title, + String message) { Alert alert = new Alert(alertType); alert.setTitle(title); alert.setHeaderText(null); diff --git a/src/Client/src/main/java/greenify/client/rest/UserService.java b/src/Client/src/main/java/greenify/client/rest/UserService.java index ba726e5..c52250e 100644 --- a/src/Client/src/main/java/greenify/client/rest/UserService.java +++ b/src/Client/src/main/java/greenify/client/rest/UserService.java @@ -8,25 +8,23 @@ import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.stereotype.Service; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; @Service public class UserService { + public UserDto currentUser; + @Autowired RestTemplate restTemplate; - public UserDto currentUser; - @Bean RestTemplate restTemplate(RestTemplateBuilder builder) { return builder.build(); } /** - * registers the user. + * Registers the user. * @param name the username of the user * @param password the password of the user * @return a userDTO @@ -37,7 +35,7 @@ public class UserService { public UserDto registerUser(String name, String password) { //headers for http HttpHeaders headers = new HttpHeaders(); - //set the accept header in JSÖN value + //set the accept header in JSON value headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); //connect to the server with the needed url UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/registerUser") @@ -47,7 +45,7 @@ public class UserService { //getting the password from the database //create a http entity to be sent - HttpEntity entity = new HttpEntity<>(headers); + new HttpEntity<>(headers); System.out.println(builder.build().encode().toUri()); //the result to be sent is a userDto @@ -59,7 +57,7 @@ public class UserService { } /** - * sign ins the user. + * Signs in the user. * @param name the username of the user * @param password the password of the user * @return a userDTO @@ -72,7 +70,7 @@ public class UserService { UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/loginUser") .queryParam("name", name) .queryParam("password", password); - HttpEntity entity = new HttpEntity<>(headers); + new HttpEntity<>(headers); System.out.println(builder.build().encode().toUri()); UserDto result = this.restTemplate.getForObject(builder.build() .encode().toUri(), UserDto.class); @@ -80,6 +78,13 @@ public class UserService { return result; } + /** + * Updates the input of the user. + * @param name name of the user + * @param inputName name of the input + * @param value value of the input + * @return returns the result + */ @SuppressWarnings("Duplicates") public String updateInput(String name, String inputName, String value) { HttpHeaders headers = new HttpHeaders(); @@ -88,11 +93,10 @@ public class UserService { .queryParam("name", name) .queryParam("inputName", inputName) .queryParam("value",value); - HttpEntity entity = new HttpEntity<>(headers); + new HttpEntity<>(headers); System.out.println(builder.build().encode().toUri()); - String result = this.restTemplate.getForObject(builder.build() + return this.restTemplate.getForObject(builder.build() .encode().toUri(), String.class); - return result; } @SuppressWarnings("Duplicates") diff --git a/src/Client/src/main/resources/fxml/LoginWindow.fxml b/src/Client/src/main/resources/fxml/LoginWindow.fxml index 03a3902..03b8014 100644 --- a/src/Client/src/main/resources/fxml/LoginWindow.fxml +++ b/src/Client/src/main/resources/fxml/LoginWindow.fxml @@ -17,7 +17,7 @@