Add methods for calculator and fix checktsyle errors
This commit is contained in:
@@ -54,7 +54,8 @@ public class Application extends javafx.application.Application {
|
|||||||
.getResource("fxml/LoginWindow.fxml"));
|
.getResource("fxml/LoginWindow.fxml"));
|
||||||
primaryStage.setTitle("Greenify");
|
primaryStage.setTitle("Greenify");
|
||||||
Scene scene = new Scene(rootNode);
|
Scene scene = new Scene(rootNode);
|
||||||
scene.getStylesheets().add(getClass().getClassLoader().getResource("stylesheets/LoginWindowStyle.css").toExternalForm());
|
scene.getStylesheets().add(getClass().getClassLoader().getResource(
|
||||||
|
"stylesheets/LoginWindowStyle.css").toExternalForm());
|
||||||
primaryStage.setScene(scene);
|
primaryStage.setScene(scene);
|
||||||
primaryStage.show();
|
primaryStage.show();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,8 +48,6 @@ public class CalculatorController {
|
|||||||
private Label annualIncomeLabel;
|
private Label annualIncomeLabel;
|
||||||
@FXML
|
@FXML
|
||||||
private Button saveButton;
|
private Button saveButton;
|
||||||
// @FXML
|
|
||||||
// private Button getStartedNextButton;
|
|
||||||
@FXML
|
@FXML
|
||||||
private TextField publicTransitField;
|
private TextField publicTransitField;
|
||||||
@FXML
|
@FXML
|
||||||
@@ -148,11 +146,28 @@ public class CalculatorController {
|
|||||||
shoppingPane.setVisible(true);
|
shoppingPane.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The method saves the calculation.
|
||||||
|
* @param event user clicks to button
|
||||||
|
*/
|
||||||
|
public void saveCalculation(ActionEvent event) {
|
||||||
|
getStartedPane.setVisible(false);
|
||||||
|
travelPane.setVisible(false);
|
||||||
|
homePane.setVisible(false);
|
||||||
|
foodPane.setVisible(false);
|
||||||
|
shoppingPane.setVisible(false);
|
||||||
|
if (!annualIncomeLabel.getText().equals(null)) {
|
||||||
|
userService.updateInput(userService.currentUser.getName(), "input_income",
|
||||||
|
annualIncomeLabel.getText());
|
||||||
}
|
}
|
||||||
|
if (!peopleInHouseHoldLabel.getText().equals(null)) {
|
||||||
|
userService.updateInput(userService.currentUser.getName(), "input_population",
|
||||||
|
peopleInHouseHoldLabel.getText());
|
||||||
|
}
|
||||||
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
|
"input_footprint_housing_naturalgas_cuft", "0");
|
||||||
|
userService.updateInput(userService.currentUser.getName(),
|
||||||
|
"input_footprint_transportation_miles1", "0");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ public class DashBoardController {
|
|||||||
UserService userService;
|
UserService userService;
|
||||||
|
|
||||||
private FadeTransition fadeTrans; //transition for switching between the different panels
|
private FadeTransition fadeTrans; //transition for switching between the different panels
|
||||||
private int net;
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private AnchorPane dashboardPane;
|
private AnchorPane dashboardPane;
|
||||||
@@ -42,8 +41,6 @@ public class DashBoardController {
|
|||||||
@FXML
|
@FXML
|
||||||
private AnchorPane friendsPane;
|
private AnchorPane friendsPane;
|
||||||
@FXML
|
@FXML
|
||||||
private Label totalVeganMealCounter;
|
|
||||||
@FXML
|
|
||||||
private Label welcomebacktext;
|
private Label welcomebacktext;
|
||||||
@FXML
|
@FXML
|
||||||
private Button dashboardButton;
|
private Button dashboardButton;
|
||||||
@@ -62,7 +59,7 @@ public class DashBoardController {
|
|||||||
@FXML
|
@FXML
|
||||||
private Button calculateFootPrintButton;
|
private Button calculateFootPrintButton;
|
||||||
@FXML
|
@FXML
|
||||||
private Label footPrintLabel;
|
private Label footprintLabel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the the necessary things before anything else.
|
* Loads the the necessary things before anything else.
|
||||||
@@ -81,10 +78,6 @@ public class DashBoardController {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserService getUserService() {
|
|
||||||
return userService;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
@@ -118,7 +111,6 @@ public class DashBoardController {
|
|||||||
*/
|
*/
|
||||||
public void displayActivities(ActionEvent event) {
|
public void displayActivities(ActionEvent event) {
|
||||||
addFadeTransition(activitiesPane);
|
addFadeTransition(activitiesPane);
|
||||||
totalVeganMealCounter.setText("" + net);
|
|
||||||
System.out.println("display activities");
|
System.out.println("display activities");
|
||||||
dashboardPane.setVisible(false);
|
dashboardPane.setVisible(false);
|
||||||
userPane.setVisible(false);
|
userPane.setVisible(false);
|
||||||
@@ -131,6 +123,9 @@ public class DashBoardController {
|
|||||||
* @param event the event (clicking the button)
|
* @param event the event (clicking the button)
|
||||||
*/
|
*/
|
||||||
public void displayUser(ActionEvent event) {
|
public void displayUser(ActionEvent event) {
|
||||||
|
System.out.println(userService.currentUser.getName());
|
||||||
|
System.out.println(userService.getFootprint(userService.currentUser.getName()));
|
||||||
|
footprintLabel.setText("" + userService.getFootprint(userService.currentUser.getName()));
|
||||||
addFadeTransition(userPane);
|
addFadeTransition(userPane);
|
||||||
System.out.println("display user");
|
System.out.println("display user");
|
||||||
dashboardPane.setVisible(false);
|
dashboardPane.setVisible(false);
|
||||||
|
|||||||
@@ -28,13 +28,10 @@ public class UserController {
|
|||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private TextField usernameField;
|
private TextField usernameField;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private PasswordField passwordField;
|
private PasswordField passwordField;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Button loginButton;
|
private Button loginButton;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Button signUpButton;
|
private Button signUpButton;
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import org.springframework.context.annotation.Bean;
|
|||||||
import org.springframework.http.HttpEntity;
|
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.http.ResponseEntity;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
import org.springframework.web.util.UriComponentsBuilder;
|
import org.springframework.web.util.UriComponentsBuilder;
|
||||||
@@ -83,10 +84,9 @@ public class UserService {
|
|||||||
* @param name name of the user
|
* @param name name of the user
|
||||||
* @param inputName name of the input
|
* @param inputName name of the input
|
||||||
* @param value value 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 void updateInput(String name, String inputName, String value) {
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/setInput")
|
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/setInput")
|
||||||
@@ -95,18 +95,35 @@ public class UserService {
|
|||||||
.queryParam("value",value);
|
.queryParam("value",value);
|
||||||
new HttpEntity<>(headers);
|
new HttpEntity<>(headers);
|
||||||
System.out.println(builder.build().encode().toUri());
|
System.out.println(builder.build().encode().toUri());
|
||||||
return this.restTemplate.getForObject(builder.build()
|
ResponseEntity<String> authenticateResponse = this.restTemplate.getForEntity(builder.build()
|
||||||
.encode().toUri(), String.class);
|
.encode().toUri(), String.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the footprint of the user.
|
||||||
|
* @param name name of the user
|
||||||
|
* @return returns the footprint score
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("Duplicates")
|
||||||
|
public Float getFootprint(String name) {
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||||
|
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getFootprint")
|
||||||
|
.queryParam("name", name);
|
||||||
|
new HttpEntity<>(headers);
|
||||||
|
System.out.println(builder.build().encode().toUri());
|
||||||
|
Float result = this.restTemplate.getForObject(builder
|
||||||
|
.build().encode().toUri(), Float.class);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a friend to the user.
|
* Adds a friend to the user.
|
||||||
* @param name the username of the current user.
|
* @param name the username of the current user.
|
||||||
* @param friend the username of the friend you want to add.
|
* @param friend the username of the friend you want to add.
|
||||||
* @return a userDTO
|
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("Duplicates")
|
@SuppressWarnings("Duplicates")
|
||||||
public String addFriend(String name, String friend) {
|
public void addFriend(String name, String friend) {
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/addFriend")
|
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/addFriend")
|
||||||
@@ -114,8 +131,7 @@ public class UserService {
|
|||||||
.queryParam("friend",friend);
|
.queryParam("friend",friend);
|
||||||
HttpEntity<?> entity = new HttpEntity<>(headers);
|
HttpEntity<?> entity = new HttpEntity<>(headers);
|
||||||
System.out.println(builder.build().encode().toUri());
|
System.out.println(builder.build().encode().toUri());
|
||||||
String result = this.restTemplate.getForObject(builder.build()
|
ResponseEntity<String> authenticateResponse = this.restTemplate.getForEntity(builder.build()
|
||||||
.encode().toUri(), String.class);
|
.encode().toUri(), String.class);
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<?import javafx.geometry.*?>
|
<?import javafx.geometry.Insets?>
|
||||||
<?import com.jfoenix.controls.*?>
|
|
||||||
<?import javafx.scene.image.*?>
|
|
||||||
<?import javafx.scene.text.*?>
|
|
||||||
<?import java.lang.*?>
|
|
||||||
<?import java.util.*?>
|
|
||||||
<?import javafx.scene.*?>
|
|
||||||
<?import javafx.scene.control.*?>
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import javafx.scene.image.*?>
|
||||||
<?import javafx.scene.layout.*?>
|
<?import javafx.scene.layout.*?>
|
||||||
|
<?import javafx.scene.text.*?>
|
||||||
|
|
||||||
<AnchorPane prefHeight="703.0" prefWidth="820.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.CalculatorController">
|
<AnchorPane prefHeight="703.0" prefWidth="820.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.CalculatorController">
|
||||||
<children>
|
<children>
|
||||||
@@ -98,7 +94,7 @@
|
|||||||
</ImageView>
|
</ImageView>
|
||||||
</graphic>
|
</graphic>
|
||||||
</Button>
|
</Button>
|
||||||
<Button fx:id="saveButton" layoutX="702.0" layoutY="24.0" mnemonicParsing="false" text="Save">
|
<Button fx:id="saveButton" layoutX="702.0" layoutY="24.0" onAction="#saveCalculation" mnemonicParsing="false" text="Save">
|
||||||
<font>
|
<font>
|
||||||
<Font size="17.0" />
|
<Font size="17.0" />
|
||||||
</font></Button>
|
</font></Button>
|
||||||
@@ -190,3 +186,4 @@
|
|||||||
<AnchorPane fx:id="shoppingPane" layoutY="85.0" prefHeight="618.0" prefWidth="820.0" visible="false" />
|
<AnchorPane fx:id="shoppingPane" layoutY="85.0" prefHeight="618.0" prefWidth="820.0" visible="false" />
|
||||||
</children>
|
</children>
|
||||||
</AnchorPane>
|
</AnchorPane>
|
||||||
|
|
||||||
|
|||||||
@@ -190,7 +190,7 @@
|
|||||||
<Font size="24.0" />
|
<Font size="24.0" />
|
||||||
</font>
|
</font>
|
||||||
</Text>
|
</Text>
|
||||||
<Label fx:id="footPrintLabel" alignment="CENTER" contentDisplay="CENTER" prefHeight="27.0" prefWidth="134.0" text="co2 footprint" textAlignment="CENTER">
|
<Label fx:id="footprintLabel" alignment="CENTER" contentDisplay="CENTER" prefHeight="27.0" prefWidth="134.0" text="co2 footprint" textAlignment="CENTER">
|
||||||
<font>
|
<font>
|
||||||
<Font size="18.0" />
|
<Font size="18.0" />
|
||||||
</font>
|
</font>
|
||||||
|
|||||||
Reference in New Issue
Block a user