FIX:: checkstyle 'client'

This commit is contained in:
mlwauben
2019-03-26 11:34:53 +01:00
committed by Merel Steenbergen
parent 81f58c86f9
commit 37d3e6c4a7
8 changed files with 85 additions and 65 deletions

View File

@@ -16,7 +16,7 @@ import java.io.IOException;
@SpringBootApplication @SpringBootApplication
public class Application extends javafx.application.Application { public class Application extends javafx.application.Application {
private static ConfigurableApplicationContext springContext; 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. * This (main) method starts launch.
@@ -53,7 +53,8 @@ public class Application extends javafx.application.Application {
*/ */
@Override @Override
public void start(Stage primaryStage) throws Exception { 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"); primaryStage.setTitle("Greenify");
Scene scene = new Scene(rootNode); Scene scene = new Scene(rootNode);
primaryStage.setScene(scene); primaryStage.setScene(scene);

View File

@@ -22,18 +22,14 @@ import org.springframework.stereotype.Controller;
import java.io.IOException; 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 @Controller
public class DashBoardController { public class DashBoardController {
@Autowired @Autowired
UserService userService; UserService userService;
private FadeTransition fadeTrans; //transition for switching between the different panels
private int net;
private int count = 0;
@FXML @FXML
private AnchorPane dashboardPane; private AnchorPane dashboardPane;
@FXML @FXML
@@ -43,11 +39,9 @@ public class DashBoardController {
@FXML @FXML
private AnchorPane friendsPane; private AnchorPane friendsPane;
@FXML @FXML
private Label veganMealCounter;
@FXML
private Label totalVeganMealCounter; private Label totalVeganMealCounter;
@FXML @FXML
private Label welcomebacktext; private Label welcomeBackText;
@FXML @FXML
private Button dashboardButton; private Button dashboardButton;
@FXML @FXML
@@ -60,20 +54,18 @@ public class DashBoardController {
private Line pathLine; private Line pathLine;
@FXML @FXML
private AnchorPane menuBar; private AnchorPane menuBar;
@FXML @FXML
private Button addNewActivityButton; private Button addNewActivityButton;
@FXML @FXML
private Button calculateFootPrintButton; private Button calculateFootPrintButton;
/** /**
* loads the the necessary things before anything else. * Loads the the necessary things before anything else.
*/ */
public void initialize() { public void initialize() {
//sets the text of the 'welcome back' text to include the username //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 //adds the slide transition to the menu bar
addSlideTransition(menuBar, pathLine); addSlideTransition(menuBar, pathLine);
//adds animations to the navigation buttons //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 * @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.setFromValue(0);
fadeTrans.setToValue(1.0); fadeTrans.setToValue(1.0);
fadeTrans.play(); fadeTrans.play();
} }
/** /**
* displays the dashboard pane. * Displays the dashboard pane.
* @param event the event (clicking the button) * @param event the event (clicking the button)
*/ */
public void displayDashboard(ActionEvent event) { public void displayDashboard(ActionEvent event) {
@@ -113,15 +107,15 @@ public class DashBoardController {
userPane.setVisible(false); userPane.setVisible(false);
activitiesPane.setVisible(false); activitiesPane.setVisible(false);
friendsPane.setVisible(false); friendsPane.setVisible(false);
} }
/** /**
* displays the activities pane. * Displays the activities pane.
* @param event the event (clicking the button) * @param event the event (clicking the button)
*/ */
public void displayActivities(ActionEvent event) { public void displayActivities(ActionEvent event) {
addFadeTransition(activitiesPane); addFadeTransition(activitiesPane);
int net = 0;
totalVeganMealCounter.setText("" + net); totalVeganMealCounter.setText("" + net);
System.out.println("display activities"); System.out.println("display activities");
dashboardPane.setVisible(false); 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) * @param event the event (clicking the button)
*/ */
public void displayUser(ActionEvent event) { public void displayUser(ActionEvent event) {
@@ -141,9 +135,12 @@ public class DashBoardController {
userPane.setVisible(true); userPane.setVisible(true);
activitiesPane.setVisible(false); activitiesPane.setVisible(false);
friendsPane.setVisible(false); friendsPane.setVisible(false);
} }
/**
* Displays the friends pane.
* @param event the event (clicking the button)
*/
public void displayFriends(ActionEvent event) { public void displayFriends(ActionEvent event) {
addFadeTransition(friendsPane); addFadeTransition(friendsPane);
System.out.println("display friends"); System.out.println("display friends");
@@ -154,7 +151,7 @@ public class DashBoardController {
} }
//sets the slide in transition for startup //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); PathTransition pathTrans = new PathTransition(Duration.millis(1100), path1, node);
pathTrans.play(); pathTrans.play();
} }
@@ -179,7 +176,7 @@ public class DashBoardController {
* and scales down when you stop hovering over it. * and scales down when you stop hovering over it.
* @param button the button to add the animation to * @param button the button to add the animation to
*/ */
public MyButtonSkin(Button button) { MyButtonSkin(Button button) {
//inherit the button properties //inherit the button properties
super(button); super(button);
//transition to scale up on hover //transition to scale up on hover

View File

@@ -9,7 +9,7 @@ import javafx.scene.control.Alert;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.PasswordField; import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
import javafx.scene.shape.Line; //import javafx.scene.shape.Line;
import javafx.stage.Stage; import javafx.stage.Stage;
import javafx.stage.Window; import javafx.stage.Window;
import javafx.util.Duration; import javafx.util.Duration;
@@ -18,7 +18,9 @@ import org.springframework.stereotype.Controller;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
//class that controls the actions for the register window /**
* Class that controls the actions for the register window.
*/
@Controller @Controller
public class RegisterWindowController { public class RegisterWindowController {
@@ -32,12 +34,17 @@ public class RegisterWindowController {
@FXML @FXML
private PasswordField passwordField2; private PasswordField passwordField2;
@FXML @FXML
private Button signupButton; private Button signUpButton;
@FXML //@FXML
private Line uNamePathLine; //private Line uNamePathLine;
/**
* Initializes the animation.
* @throws InterruptedException exception when interrupted
*/
public void initialize() throws InterruptedException { 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(); // pathTransUName.play();
addSlideAnimation(1100, userNameText, -300); addSlideAnimation(1100, userNameText, -300);
addSlideAnimation(1100, passwordField, 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); TranslateTransition slideIn = new TranslateTransition(Duration.millis(duration), node);
slideIn.setFromX(from); slideIn.setFromX(from);
slideIn.setToX(0); 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 * @param event the click of the sign up button
*/ */
@FXML @FXML
public void handleSignUpButton(ActionEvent event) { public void handleSignUpButton(ActionEvent event) {
//set the window to the current window (for displaying the alerts) //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 //check if the username field is empty
if (userNameText.getText().isEmpty()) { if (userNameText.getText().isEmpty()) {
//if so, display an alert //if so, display an alert

View File

@@ -16,8 +16,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import java.io.IOException; 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 @Controller
public class UserController { public class UserController {
@Autowired @Autowired
@@ -33,10 +36,10 @@ public class UserController {
private Button loginButton; private Button loginButton;
@FXML @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 * it checks if the username and password fields are filled
* and gives alerts if they aren't filled in. * and gives alerts if they aren't filled in.
* @param event the click of the login button * @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 * @throws IOException exception if fxml file can't be found
* @author sem * @author sem
*/ */
public void openDashboard() throws IOException { private void openDashboard() throws IOException {
//load the fxml file //load the fxml file
Parent dash = Application.load(this.getClass().getClassLoader() Parent dash = Application.load(this.getClass().getClassLoader()
.getResource("fxml/dashboard.fxml")); .getResource("fxml/dashboard.fxml"));
Scene scene = new Scene(dash); Scene scene = new Scene(dash);
//add the stylesheet for the CSS //add the stylesheet for the CSS
scene.getStylesheets().add(getClass().getClassLoader() scene.getStylesheets().add(Objects.requireNonNull(getClass().getClassLoader()
.getResource("stylesheets/dashboardStyle.css").toExternalForm()); .getResource("stylesheets/dashboardStyle.css")).toExternalForm());
Stage appStage = new Stage(); Stage appStage = new Stage();
appStage.setScene(scene); appStage.setScene(scene);
//set the title //set the title
@@ -94,8 +97,10 @@ public class UserController {
appStage.show(); appStage.show();
} }
//class for showing the alerts /**
public static class AlertHelper { * Class for showing the alerts.
*/
static class AlertHelper {
/** /**
* alerts for the login screen. * alerts for the login screen.
* @param alertType the type of alert * @param alertType the type of alert
@@ -103,10 +108,10 @@ public class UserController {
* @param title the title given to the displayed alert * @param title the title given to the displayed alert
* @param message the message displayed in the alert * @param message the message displayed in the alert
*/ */
public static void showAlert(Alert.AlertType alertType, static void showAlert(Alert.AlertType alertType,
Window owner, Window owner,
String title, String title,
String message) { String message) {
Alert alert = new Alert(alertType); Alert alert = new Alert(alertType);
alert.setTitle(title); alert.setTitle(title);
alert.setHeaderText(null); alert.setHeaderText(null);

View File

@@ -8,25 +8,23 @@ import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.stereotype.Service; 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.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder; import org.springframework.web.util.UriComponentsBuilder;
@Service @Service
public class UserService { public class UserService {
public UserDto currentUser;
@Autowired @Autowired
RestTemplate restTemplate; RestTemplate restTemplate;
public UserDto currentUser;
@Bean @Bean
RestTemplate restTemplate(RestTemplateBuilder builder) { RestTemplate restTemplate(RestTemplateBuilder builder) {
return builder.build(); return builder.build();
} }
/** /**
* registers the user. * Registers the user.
* @param name the username of the user * @param name the username of the user
* @param password the password of the user * @param password the password of the user
* @return a userDTO * @return a userDTO
@@ -37,7 +35,7 @@ public class UserService {
public UserDto registerUser(String name, String password) { public UserDto registerUser(String name, String password) {
//headers for http //headers for http
HttpHeaders headers = new HttpHeaders(); 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); headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
//connect to the server with the needed url //connect to the server with the needed url
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/registerUser") UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/registerUser")
@@ -47,7 +45,7 @@ public class UserService {
//getting the password from the database //getting the password from the database
//create a http entity to be sent //create a http entity to be sent
HttpEntity<?> entity = new HttpEntity<>(headers); new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri()); System.out.println(builder.build().encode().toUri());
//the result to be sent is a userDto //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 name the username of the user
* @param password the password of the user * @param password the password of the user
* @return a userDTO * @return a userDTO
@@ -72,7 +70,7 @@ public class UserService {
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/loginUser") UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/loginUser")
.queryParam("name", name) .queryParam("name", name)
.queryParam("password", password); .queryParam("password", password);
HttpEntity<?> entity = new HttpEntity<>(headers); new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri()); System.out.println(builder.build().encode().toUri());
UserDto result = this.restTemplate.getForObject(builder.build() UserDto result = this.restTemplate.getForObject(builder.build()
.encode().toUri(), UserDto.class); .encode().toUri(), UserDto.class);
@@ -80,6 +78,13 @@ public class UserService {
return result; 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") @SuppressWarnings("Duplicates")
public String updateInput(String name, String inputName, String value) { public String updateInput(String name, String inputName, String value) {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
@@ -88,11 +93,10 @@ public class UserService {
.queryParam("name", name) .queryParam("name", name)
.queryParam("inputName", inputName) .queryParam("inputName", inputName)
.queryParam("value",value); .queryParam("value",value);
HttpEntity<?> entity = new HttpEntity<>(headers); new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri()); System.out.println(builder.build().encode().toUri());
String result = this.restTemplate.getForObject(builder.build() return this.restTemplate.getForObject(builder.build()
.encode().toUri(), String.class); .encode().toUri(), String.class);
return result;
} }
@SuppressWarnings("Duplicates") @SuppressWarnings("Duplicates")

View File

@@ -17,7 +17,7 @@
</font> </font>
</Text> </Text>
<Button fx:id="loginButton" layoutX="419.0" layoutY="274.0" mnemonicParsing="false" onAction="#handleLoginButtonAction" prefHeight="26.0" prefWidth="96.0" text="Login" textAlignment="CENTER" /> <Button fx:id="loginButton" layoutX="419.0" layoutY="274.0" mnemonicParsing="false" onAction="#handleLoginButtonAction" prefHeight="26.0" prefWidth="96.0" text="Login" textAlignment="CENTER" />
<Button fx:id="signupButton" layoutX="42.0" layoutY="52.0" mnemonicParsing="false" onAction="#handleRegisterButtonAction" prefHeight="10.0" prefWidth="96.0" text="Sign up!" /> <Button fx:id="signUpButton" layoutX="42.0" layoutY="52.0" mnemonicParsing="false" onAction="#handleRegisterButtonAction" prefHeight="10.0" prefWidth="96.0" text="Sign up!" />
<PasswordField fx:id="passwordField" layoutX="318.0" layoutY="210.0" prefHeight="42.0" prefWidth="303.0" promptText="Password" /> <PasswordField fx:id="passwordField" layoutX="318.0" layoutY="210.0" prefHeight="42.0" prefWidth="303.0" promptText="Password" />
<Hyperlink alignment="CENTER" layoutX="384.0" layoutY="301.0" prefHeight="42.0" prefWidth="173.0" text="Forgot Password?" textAlignment="CENTER" textFill="#3db25a" textOverrun="LEADING_WORD_ELLIPSIS"> <Hyperlink alignment="CENTER" layoutX="384.0" layoutY="301.0" prefHeight="42.0" prefWidth="173.0" text="Forgot Password?" textAlignment="CENTER" textFill="#3db25a" textOverrun="LEADING_WORD_ELLIPSIS">
<font> <font>

View File

@@ -24,7 +24,7 @@
<Font size="13.0" /> <Font size="13.0" />
</font> </font>
</TextField> </TextField>
<Button fx:id="signupButton" layoutX="115.0" layoutY="229.0" mnemonicParsing="false" onAction="#handleSignUpButton" style="-fx-background-color: #005e07;" text="Sign up!" textFill="#c4eec9"> <Button fx:id="signUpButton" layoutX="115.0" layoutY="229.0" mnemonicParsing="false" onAction="#handleSignUpButton" style="-fx-background-color: #005e07;" text="Sign up!" textFill="#c4eec9">
<font> <font>
<Font name="Corbel Bold" size="14.0" /> <Font name="Corbel Bold" size="14.0" />
</font> </font>

View File

@@ -201,7 +201,7 @@
<AnchorPane fx:id="dashboardPane" layoutX="215.0" prefHeight="703.0" prefWidth="820.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="214.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> <AnchorPane fx:id="dashboardPane" layoutX="215.0" prefHeight="703.0" prefWidth="820.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="214.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children> <children>
<HBox layoutX="97.0" layoutY="124.0" prefHeight="100.0" prefWidth="200.0" /> <HBox layoutX="97.0" layoutY="124.0" prefHeight="100.0" prefWidth="200.0" />
<Label fx:id="welcomebacktext" layoutX="69.0" layoutY="53.0" text="Welcome back user!" AnchorPane.leftAnchor="60.0" AnchorPane.topAnchor="40.0"> <Label fx:id="welcomeBacktext" layoutX="69.0" layoutY="53.0" text="Welcome back user!" AnchorPane.leftAnchor="60.0" AnchorPane.topAnchor="40.0">
<font> <font>
<Font size="30.0" /> <Font size="30.0" />
</font> </font>