Add methods for calculator and fix checktsyle errors

This commit is contained in:
cugurlu
2019-03-27 13:40:52 +01:00
parent 1d10d1d54b
commit 07f5eb0449
7 changed files with 83 additions and 62 deletions

View File

@@ -54,7 +54,8 @@ public class Application extends javafx.application.Application {
.getResource("fxml/LoginWindow.fxml"));
primaryStage.setTitle("Greenify");
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.show();
}

View File

@@ -48,8 +48,6 @@ public class CalculatorController {
private Label annualIncomeLabel;
@FXML
private Button saveButton;
// @FXML
// private Button getStartedNextButton;
@FXML
private TextField publicTransitField;
@FXML
@@ -148,11 +146,28 @@ public class CalculatorController {
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");
}
}

View File

@@ -31,7 +31,6 @@ public class DashBoardController {
UserService userService;
private FadeTransition fadeTrans; //transition for switching between the different panels
private int net;
@FXML
private AnchorPane dashboardPane;
@@ -42,8 +41,6 @@ public class DashBoardController {
@FXML
private AnchorPane friendsPane;
@FXML
private Label totalVeganMealCounter;
@FXML
private Label welcomebacktext;
@FXML
private Button dashboardButton;
@@ -62,7 +59,7 @@ public class DashBoardController {
@FXML
private Button calculateFootPrintButton;
@FXML
private Label footPrintLabel;
private Label footprintLabel;
/**
* 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.
* @param node the node on which the transition needs to act
@@ -118,7 +111,6 @@ public class DashBoardController {
*/
public void displayActivities(ActionEvent event) {
addFadeTransition(activitiesPane);
totalVeganMealCounter.setText("" + net);
System.out.println("display activities");
dashboardPane.setVisible(false);
userPane.setVisible(false);
@@ -131,6 +123,9 @@ public class DashBoardController {
* @param event the event (clicking the button)
*/
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);
System.out.println("display user");
dashboardPane.setVisible(false);

View File

@@ -28,13 +28,10 @@ public class UserController {
@FXML
private TextField usernameField;
@FXML
private PasswordField passwordField;
@FXML
private Button loginButton;
@FXML
private Button signUpButton;

View File

@@ -7,6 +7,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
@@ -83,10 +84,9 @@ public class UserService {
* @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) {
public void updateInput(String name, String inputName, String value) {
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/setInput")
@@ -95,18 +95,35 @@ public class UserService {
.queryParam("value",value);
new HttpEntity<>(headers);
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);
}
/**
* 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.
* @param name the username of the current user.
* @param friend the username of the friend you want to add.
* @return a userDTO
*/
@SuppressWarnings("Duplicates")
public String addFriend(String name, String friend) {
public void addFriend(String name, String friend) {
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/addFriend")
@@ -114,8 +131,7 @@ public class UserService {
.queryParam("friend",friend);
HttpEntity<?> entity = new HttpEntity<>(headers);
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);
return result;
}
}

View File

@@ -1,14 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import com.jfoenix.controls.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.text.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?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">
<children>
@@ -22,10 +18,10 @@
<ImageView fitHeight="60.0" fitWidth="52.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/cloud.png" />
<!--image credits:-->
<!--image made by Smashicons https://www.flaticon.com/authors/smashicons-->
<!--from https://www.flaticon.com/
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0-->
<!--image credits:-->
<!--image made by Smashicons https://www.flaticon.com/authors/smashicons-->
<!--from https://www.flaticon.com/
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0-->
</image>
</ImageView>
</graphic>
@@ -38,11 +34,11 @@
<ImageView fitHeight="60.0" fitWidth="52.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/world.png" />
<!--image credits:
made by prettycons https://www.flaticon.com/authors/prettycons
from https://www.flaticon.com/
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
-->
<!--image credits:
made by prettycons https://www.flaticon.com/authors/prettycons
from https://www.flaticon.com/
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
-->
</image>
</ImageView>
</graphic>
@@ -55,11 +51,11 @@
<ImageView fitHeight="60.0" fitWidth="52.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/home.png" />
<!--image credits:
made by Smashicons https://www.flaticon.com/authors/smashicons
from https://www.flaticon.com/
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
-->
<!--image credits:
made by Smashicons https://www.flaticon.com/authors/smashicons
from https://www.flaticon.com/
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
-->
</image>
</ImageView>
</graphic>
@@ -72,11 +68,11 @@
<ImageView fitHeight="60.0" fitWidth="52.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/coffee-cup.png" />
<!--image credits:
made by pixel-perfect https://www.flaticon.com/authors/pixel-perfect
from https://www.flaticon.com/
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
-->
<!--image credits:
made by pixel-perfect https://www.flaticon.com/authors/pixel-perfect
from https://www.flaticon.com/
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
-->
</image>
</ImageView>
</graphic>
@@ -89,16 +85,16 @@
<ImageView fitHeight="60.0" fitWidth="52.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/shopping-cart.png" />
<!--image credits:
made by Gregor Cresnar https://www.flaticon.com/authors/gregor-cresnar
from https://www.flaticon.com/
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
-->
<!--image credits:
made by Gregor Cresnar https://www.flaticon.com/authors/gregor-cresnar
from https://www.flaticon.com/
flaticon is licenced by http://creativecommons.org/licenses/by/3.0/ Creative Commons BY 3.0
-->
</image>
</ImageView>
</graphic>
</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 size="17.0" />
</font></Button>
@@ -190,3 +186,4 @@
<AnchorPane fx:id="shoppingPane" layoutY="85.0" prefHeight="618.0" prefWidth="820.0" visible="false" />
</children>
</AnchorPane>

View File

@@ -190,7 +190,7 @@
<Font size="24.0" />
</font>
</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 size="18.0" />
</font>