ADD::added calculator window to GUI

ADD::added button to open calculator to main window
This commit is contained in:
Sem van der Hoeven
2019-03-25 14:51:25 +01:00
parent d5319fc973
commit 987acbad71
15 changed files with 364 additions and 10 deletions

View File

@@ -0,0 +1,121 @@
package greenify.client.controller;
import greenify.client.rest.UserService;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Slider;
import javafx.scene.layout.AnchorPane;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
@Controller
public class CalculatorController {
@Autowired
UserService userService;
@FXML
public Button calculatorGetStartedButton;
@FXML
private Button calculatorTravelButton;
@FXML
private Button calculatorHomeButton;
@FXML
private Button calculatorFoodButton;
@FXML
private Button calculatorShoppingButton;
@FXML
private AnchorPane getStartedPane;
@FXML
private AnchorPane travelPane;
@FXML
private AnchorPane homePane;
@FXML
private AnchorPane foodPane;
@FXML
private AnchorPane shoppingPane;
@FXML
private Slider peopleInHouseholdSLider;
@FXML
private Label peopleInHouseHoldLabel;
@FXML
private Slider annualIncomeSlider;
@FXML
private Label annualIncomeLabel;
@FXML
private Button saveButton;
public void initialize() {
peopleInHouseholdSLider.setSnapToTicks(true);
annualIncomeSlider.setSnapToTicks(true);
//add listener to slider for amount of people in household
peopleInHouseholdSLider.valueProperty().addListener(new ChangeListener<Number>() {
public void changed(ObservableValue<? extends Number> observable,
Number oldValue, Number newValue) {
peopleInHouseHoldLabel.setText("" + newValue.intValue());
}
});
//add listener to slider for annual income
annualIncomeSlider.valueProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observable,
Number oldValue, Number newValue) {
annualIncomeLabel.setText("" + (newValue.intValue() * 1000));
}
});
}
public void displayGetStarted(ActionEvent event) {
getStartedPane.setVisible(true);
travelPane.setVisible(false);
homePane.setVisible(false);
foodPane.setVisible(false);
shoppingPane.setVisible(false);
}
public void displayTravel(ActionEvent event) {
getStartedPane.setVisible(false);
travelPane.setVisible(true);
homePane.setVisible(false);
foodPane.setVisible(false);
shoppingPane.setVisible(false);
}
public void displayHome(ActionEvent event) {
getStartedPane.setVisible(false);
travelPane.setVisible(false);
homePane.setVisible(true);
foodPane.setVisible(false);
shoppingPane.setVisible(false);
}
public void displayFood(ActionEvent event) {
getStartedPane.setVisible(false);
travelPane.setVisible(false);
homePane.setVisible(false);
foodPane.setVisible(true);
shoppingPane.setVisible(false);
}
public void displayShopping(ActionEvent event) {
getStartedPane.setVisible(false);
travelPane.setVisible(false);
homePane.setVisible(false);
foodPane.setVisible(false);
shoppingPane.setVisible(true);
}
}

View File

@@ -1,6 +1,7 @@
package greenify.client.controller;
import com.sun.javafx.scene.control.skin.ButtonSkin;
import greenify.client.Application;
import greenify.client.rest.UserService;
import javafx.animation.FadeTransition;
import javafx.animation.PathTransition;
@@ -8,14 +9,19 @@ import javafx.animation.ScaleTransition;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.AnchorPane;
import javafx.scene.shape.Line;
import javafx.stage.Stage;
import javafx.util.Duration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import java.io.IOException;
//Class that controls the dashboard fxml file (the GUI Screen)
@@ -56,6 +62,9 @@ public class DashBoardController {
private AnchorPane menuBar;
@FXML
private Button addNewActivityButton;
@FXML
private Button calculateFootPrintButton;
@@ -74,7 +83,10 @@ public class DashBoardController {
friendsButton.setSkin(new MyButtonSkin(friendsButton));
}
public UserService getUserService() {
return userService;
}
/**
@@ -143,7 +155,6 @@ public class DashBoardController {
userPane.setVisible(false);
activitiesPane.setVisible(false);
friendsPane.setVisible(true);
}
@@ -169,6 +180,18 @@ public class DashBoardController {
pathTrans.play();
}
public void openCalculator() throws IOException {
Parent calc = Application.load(this.getClass().getClassLoader()
.getResource("fxml/calculator.fxml"));
Scene scene = new Scene(calc);
scene.getStylesheets().add(getClass().getClassLoader().getResource("stylesheets/calculatorStyle.css").toExternalForm());
Stage calcStage = new Stage();
calcStage.setScene(scene);
calcStage.setTitle("Calculate CO2 footprint - " + userService.currentUser.getName());
calcStage.show();
}
//class for the animations on the navigation buttons
public class MyButtonSkin extends ButtonSkin {
/**
@@ -193,5 +216,6 @@ public class DashBoardController {
scaleDown.setToX(1.0);
button.setOnMouseExited(e -> scaleDown.playFromStart());
}
}
}