ADD:added nodes and methods to display random hints to on the GUI

ADD::added refresh button to get a new hint

EDIT::edited hints to work with the GUI
This commit is contained in:
Sem van der Hoeven
2019-04-05 13:11:17 +02:00
parent 06daa4776f
commit 75faf4ae8c
5 changed files with 77 additions and 27 deletions

View File

@@ -15,44 +15,51 @@ public class Hints {
* This method adds all the Strings to the arraylist.
*/
private void initHints() {
hints.add("Buying local produce will not only decrease your carbon "
this.hints.add("Buying local produce will not only decrease your carbon "
+ "footprint, but also help your local economy: A win-win!");
hints.add("Did you know that a gas oven only uses 6% of its energy "
this.hints.add("Did you know that a gas oven only uses 6% of its energy "
+ "to cook? And an electric oven is not much better at 12%.");
hints.add("70% of the deforestation of the Amazon is to provide land for cattle ranches.");
hints.add("Research shows that reducing meat consumption can increase"
this.hints.add("70% of the deforestation of the Amazon is to provide land for cattle ranches.");
this.hints.add("Research shows that reducing meat consumption can increase"
+ " your life span by 3.6 years");
hints.add("Vegetarians have a lower risk of getting heart disease, high blood pressure, "
this.hints.add("Vegetarians have a lower risk of getting heart disease, high blood pressure, "
+ "diabetes and cancer than meat eaters.");
hints.add("Did you know? The carbon footprint of a vegetarian diet is about half "
this.hints.add("Did you know? The carbon footprint of a vegetarian diet is about half "
+ "that of a meat-lovers diet!");
hints.add("Cycling is good for the environment AND for your body, "
this.hints.add("Cycling is good for the environment AND for your body, "
+ "so why not grab your bike instead of your car?");
hints.add("If we could capture all of the suns energy shining on the Earth for just one "
this.hints.add("If we could capture all of the suns energy shining on the Earth for just one "
+ "hour, we could power the entire world for one year!");
hints.add("27,000 trees are cut down each day so we can have toilet paper.");
hints.add("A glass bottle made in our time will take more than 4,000 years to decompose.");
hints.add("Don't forget to turn off the lights and heating in rooms"
this.hints.add("27,000 trees are cut down each day so we can have toilet paper.");
this.hints.add("A glass bottle made in our time will take more than 4,000 years to decompose.");
this.hints.add("Don't forget to turn off the lights and heating in rooms"
+ " you're not using at the moment!");
hints.add("Did you know that about 4.5% of the Dutch population does not eat meat");
hints.add("Reuse your bags when you go grocery shopping. You will save plastic bags.");
hints.add("An estimated 250 million trees can be save each year "
+ "if every published newspaper is recycled.");
hints.add("About 88,000 jobs were created in 2015 through the wind power sector.");
hints.add("You can use LED lights in your home to safe energy!");
hints.add("If you isolate your home well, it will be warmer "
this.hints.add("Did you know that about 4.5% of the Dutch population does not eat meat?");
this.hints.add("Reuse your bags when you go grocery shopping. You will save plastic bags!");
this.hints.add("An estimated 250 million trees can be saved each year "
+ "if every published newspaper would be recycled.");
this.hints.add("About 88,000 jobs were created in 2015 through the wind power sector.");
this.hints.add("You can use LED lights in your home to save energy!");
this.hints.add("If you isolate your home well, it will be warmer, "
+ "and you'll save energy as well!");
hints.add("Do you have leftovers? Donate them to food kitchens. This way you won't waste "
+ "food and help people at the same time.");
hints.add("A lot of coffee places give you a discount if you bring your own cup. "
this.hints.add("Do you have leftovers? Donate them to food kitchens."
+ " This way you won't waste"
+ " food, and you'll help people at the same time!");
this.hints.add("A lot of coffee places give you a discount if you bring your own cup. "
+ "Get rid of those disposable cups!");
hints.add("When shopping, look for products with minimal to no packaging, "
this.hints.add("When shopping, look for products with minimal to no packaging, "
+ "or at least packaging made from recycled items. ");
hints.add("If you order food, you can ask the restaurant to not include "
this.hints.add("If you order food, you can ask the restaurant to not include "
+ "utensils and napkins, it saves plastic and paper.");
hints.add("It takes about 66 days to form a new habit, keep going!");
hints.add("Get yourself a nice reusable water bottle! It's cheaper and better for "
this.hints.add("It takes about 66 days to form a new habit, keep going!");
this.hints.add("Get yourself a nice reusable water bottle! It's cheaper and better for "
+ "the environment to refill than to buy a new one every time it's empty.");
this.hints.add("Recycle glass bottles!"
+ " A glass bottle made in our time will take more than 4,000 years"
+ " to decompose.");
this.hints.add("Only 1% of our planets water supply can be used."
+ " 97% is ocean water and 2% is frozen solid in the Arctic, for now.");
this.hints.add("Plastic bad");
}
/**
@@ -61,8 +68,8 @@ public class Hints {
*/
public String randomHint() {
Random rand = new Random();
int index = rand.nextInt(hints.size());
return hints.get(index);
int index = rand.nextInt(this.hints.size());
return this.hints.get(index);
}
}

View File

@@ -3,6 +3,7 @@ package greenify.client.controller;
import com.sun.javafx.scene.control.skin.ButtonSkin;
import greenify.client.Application;
import greenify.client.Friend;
import greenify.client.Hints;
import greenify.client.rest.UserService;
import javafx.animation.FadeTransition;
import javafx.animation.PathTransition;
@@ -46,6 +47,8 @@ public class DashBoardController {
@Autowired
UserService userService;
Hints hints = new Hints();
private FadeTransition fadeTrans; //transition for switching between the different panels
@FXML
@@ -168,12 +171,18 @@ public class DashBoardController {
private CheckBox bike;
@FXML
private CheckBox solarPanels;
@FXML
private Label hintText;
@FXML
private Button refreshHintsButton;
/**
* Loads the the necessary things before anything else.
* @throws InterruptedException exception if interrupted
*/
public void initialize() throws InterruptedException {
hintText.setWrapText(true);
hintText.setText(hints.randomHint());
//set the dashboardPane to visible
dashboardPane.setVisible(true);
userPane.setVisible(false);
@@ -225,6 +234,8 @@ public class DashBoardController {
addFriendButton.setSkin(new ClickButtonSkin(addFriendButton));
addExtraActivityButton.setSkin(new ClickButtonSkin(addExtraActivityButton));
addExtraActivityButton2.setSkin(new ClickButtonSkin(addExtraActivityButton2));
addRandomHints();
}
/**
@@ -415,6 +426,19 @@ public class DashBoardController {
calcStage.show();
}
public void addRandomHints() {
FadeTransition fadeOut = new FadeTransition(Duration.millis(400), hintText);
fadeOut.setFromValue(1.0);
fadeOut.setToValue(0.0);
fadeOut.play();
hintText.setWrapText(true);
hintText.setText(hints.randomHint());
FadeTransition fadeIn = new FadeTransition(Duration.millis(400), hintText);
fadeIn.setFromValue(0.0);
fadeIn.setToValue(1.0);
fadeIn.play();
}
/**
* Opens extra activities.
* @param event the event (clicking the button)

View File

@@ -48,6 +48,25 @@
<Line endX="104.0" layoutX="105.0" layoutY="178.0" scaleY="0.7" startX="-100.0" stroke="#e3ffe8" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" />
<Line endX="104.0" layoutX="109.0" layoutY="223.0" startX="-100.0" stroke="#e3ffe8" strokeWidth="0.7" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" />
<Line fx:id="pathLine" endX="100.0" endY="28.0" fill="#1b9736" layoutX="8.0" layoutY="323.0" startX="-100.0" startY="28.0" stroke="#5a635c" />
<Label fx:id="hintText" alignment="TOP_LEFT" layoutX="14.0" layoutY="420.0" prefHeight="218.0" prefWidth="187.0" text="Hints" textFill="#c2cdc4">
<font>
<Font size="15.0" />
</font>
</Label>
<Text fill="#002c0c" layoutX="14.0" layoutY="415.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Random hint!">
<font>
<Font size="18.0" />
</font>
</Text>
<Button fx:id="refreshHintsButton" layoutX="157.0" layoutY="390.0" mnemonicParsing="false" onAction="#addRandomHints" style="-fx-background-color: transparent;">
<graphic>
<ImageView fitHeight="26.0" fitWidth="24.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/refresh2.png" />
</image>
</ImageView>
</graphic>
</Button>
</children></AnchorPane>
<AnchorPane fx:id="activitiesPane" layoutX="214.0" prefHeight="703.0" prefWidth="820.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="214.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB