Merge branch 'add/activity_tooltips' into 'master'

Add/activity tooltips

See merge request cse1105/2018-2019/oopp-group-43/template!75
This commit is contained in:
Sem van der Hoeven
2019-04-08 12:36:45 +00:00
4 changed files with 156 additions and 45 deletions

View File

@@ -403,16 +403,17 @@ public class CalculatorController {
Window owner = saveButton.getScene().getWindow(); Window owner = saveButton.getScene().getWindow();
controller.updateLeaderboard(); controller.updateLeaderboard();
controller.updateAchievements(); controller.updateAchievements();
Stage current = (Stage) owner;
UserController.AlertHelper.showAlert(Alert.AlertType.CONFIRMATION, UserController.AlertHelper.showAlert(Alert.AlertType.CONFIRMATION,
owner, "Footprint saved!", "Your footprint is saved!"); owner, "Footprint saved!", "Your footprint is saved!");
Stage current = (Stage) owner;
current.close(); current.close();
} }
/** /**
* Checks the food labels. * Checks the food labels.
*/ */
public void checkFoodLabels() { @SuppressWarnings("Duplicates")
private void checkFoodLabels() {
if (!meatFishEggsLabel.getText().replace(" daily servings per person", "").equals("2.6")) { if (!meatFishEggsLabel.getText().replace(" daily servings per person", "").equals("2.6")) {
userService.updateInput(userService.currentUser.getName(), userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_food_meatfisheggs", "input_footprint_shopping_food_meatfisheggs",
@@ -445,7 +446,8 @@ public class CalculatorController {
/** /**
* Checks the house labels. * Checks the house labels.
*/ */
public void checkHousingLabels() { @SuppressWarnings("Duplicates")
private void checkHousingLabels() {
if (!electricityField.getText().equals("0")) { if (!electricityField.getText().equals("0")) {
userService.updateInput(userService.currentUser.getName(), userService.updateInput(userService.currentUser.getName(),
"input_footprint_housing_electricity_dollars", "input_footprint_housing_electricity_dollars",
@@ -481,7 +483,8 @@ public class CalculatorController {
/** /**
* Checks the transport labels. * Checks the transport labels.
*/ */
public void checkTransportLabels() { @SuppressWarnings("Duplicates")
private void checkTransportLabels() {
if (!publicTransitField.getText().equals("0")) { if (!publicTransitField.getText().equals("0")) {
userService.updateInput(userService.currentUser.getName(), userService.updateInput(userService.currentUser.getName(),
"input_footprint_transportation_publictrans", "input_footprint_transportation_publictrans",

View File

@@ -6,8 +6,10 @@ import greenify.client.Friend;
import greenify.client.Hints; import greenify.client.Hints;
import greenify.client.rest.UserService; import greenify.client.rest.UserService;
import javafx.animation.FadeTransition; import javafx.animation.FadeTransition;
import javafx.animation.KeyFrame;
import javafx.animation.PathTransition; import javafx.animation.PathTransition;
import javafx.animation.ScaleTransition; import javafx.animation.ScaleTransition;
import javafx.animation.Timeline;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
@@ -16,11 +18,14 @@ import javafx.scene.Node;
import javafx.scene.Parent; import javafx.scene.Parent;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.chart.PieChart; import javafx.scene.chart.PieChart;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.TableColumn; import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView; import javafx.scene.control.TableView;
import javafx.scene.control.Tooltip;
import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.effect.ColorAdjust;
import javafx.scene.image.ImageView; import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import javafx.scene.shape.Line; import javafx.scene.shape.Line;
@@ -31,6 +36,7 @@ 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.lang.reflect.Field;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@@ -187,13 +193,25 @@ public class DashBoardController {
@FXML @FXML
private Label loweringTemp; private Label loweringTemp;
@FXML @FXML
private Button refreshHintsButton; private Button achiev1Tip;
@FXML
private Button achiev2Tip;
@FXML
private Button achiev3Tip;
@FXML
private Button achiev4Tip;
@FXML
private Button achiev5Tip;
@FXML
private Button achiev6Tip;
/** /**
* Loads the the necessary things before anything else. * Loads the the necessary things before anything else.
* @throws InterruptedException exception if interrupted * @throws InterruptedException exception if interrupted
*/ */
public void initialize() throws InterruptedException { public void initialize() throws InterruptedException {
hintText.setWrapText(true); hintText.setWrapText(true);
hintText.setText(hints.randomHint()); hintText.setText(hints.randomHint());
//set the dashboardPane to visible //set the dashboardPane to visible
@@ -247,6 +265,52 @@ public class DashBoardController {
addExtraActivityButton.setSkin(new ClickButtonSkin(addExtraActivityButton)); addExtraActivityButton.setSkin(new ClickButtonSkin(addExtraActivityButton));
addExtraActivityButton2.setSkin(new ClickButtonSkin(addExtraActivityButton2)); addExtraActivityButton2.setSkin(new ClickButtonSkin(addExtraActivityButton2));
addRandomHints(); addRandomHints();
Tooltip tooltip = new Tooltip("tip");
hackTooltipStartTiming(tooltip);
addToolTip(achiev1Tip, "Starting off \n You did your first green activity!");
addToolTip(achiev2Tip, "Social Butterfly \n You added three friends");
addToolTip(achiev3Tip, "Green Saver \n You saved * of CO2");
addToolTip(achiev4Tip, "Animal Friend \n You have eaten 10 vegetarian meals");
addToolTip(achiev5Tip, "Tom Dumoulin \n You have biked * km");
addToolTip(achiev6Tip, "Let it shine \n You installed solar panels");
}
/**
* adds a tooltip to the button.
* @param button the button to add the tooltip to.
* @param message the message to be displayed in the tooltip.
*/
private void addToolTip(Button button, String message) {
button.setTooltip(new Tooltip(message));
}
/**
* changes the delay time between hovering over something with a tooltip and when the
* tooltip is displayed.
* @param tooltip the tooltip to change the delay of
*/
private static void hackTooltipStartTiming(Tooltip tooltip) {
try {
Field fieldBehavior = tooltip.getClass().getDeclaredField("BEHAVIOR");
fieldBehavior.setAccessible(true);
Object objBehavior = fieldBehavior.get(tooltip);
Field fieldTimer = objBehavior.getClass().getDeclaredField("activationTimer");
fieldTimer.setAccessible(true);
Timeline objTimer = (Timeline) fieldTimer.get(objBehavior);
objTimer.getKeyFrames().clear();
objTimer.getKeyFrames().add(new KeyFrame(new Duration(150)));
} catch (NoSuchFieldException e) {
e.printStackTrace();
e.getMessage();
} catch (IllegalAccessException e) {
e.getMessage();
e.printStackTrace();
}
} }
/** /**
@@ -410,7 +474,7 @@ public class DashBoardController {
} }
/** /**
* Logs out the user * Logs out the user.
* @param event the event (clicking the button) * @param event the event (clicking the button)
* @throws IOException if the Application doesn't load. * @throws IOException if the Application doesn't load.
*/ */
@@ -576,47 +640,55 @@ public class DashBoardController {
*/ */
public void updateAchievements() { public void updateAchievements() {
Map achievements = userService.getAchievements(userService.currentUser.getName()); Map achievements = userService.getAchievements(userService.currentUser.getName());
ColorAdjust desaturate = new ColorAdjust();
desaturate.setSaturation(-0.75);
if ((Boolean)achievements.get("Starting off")) { if ((Boolean)achievements.get("Starting off")) {
achieve1.setOpacity(1); achieve1.setOpacity(1);
} else { } else {
achieve1.setEffect(desaturate);
achieve1.setOpacity(0.3); achieve1.setOpacity(0.3);
} }
if ((Boolean)achievements.get("Social butterfly")) { if ((Boolean)achievements.get("Social butterfly")) {
achieve2.setOpacity(1); achieve2.setOpacity(1);
} else { } else {
achieve2.setEffect(desaturate);
achieve2.setOpacity(0.3); achieve2.setOpacity(0.3);
} }
if ((Boolean)achievements.get("Green saver")) { if ((Boolean)achievements.get("Green saver")) {
achieve3.setOpacity(1); achieve3.setOpacity(1);
} else { } else {
achieve3.setEffect(desaturate);
achieve3.setOpacity(0.3); achieve3.setOpacity(0.3);
} }
if ((Boolean)achievements.get("Animal friend")) { if ((Boolean)achievements.get("Animal friend")) {
achieve4.setOpacity(1); achieve4.setOpacity(1);
} else { } else {
achieve4.setEffect(desaturate);
achieve4.setOpacity(0.3); achieve4.setOpacity(0.3);
} }
if ((Boolean)achievements.get("Tom Dumoulin")) { if ((Boolean)achievements.get("Tom Dumoulin")) {
achieve5.setOpacity(1); achieve5.setOpacity(1);
} else { } else {
achieve5.setEffect(desaturate);
achieve5.setOpacity(0.3); achieve5.setOpacity(0.3);
} }
if ((Boolean)achievements.get("Let it shine")) { if ((Boolean)achievements.get("Let it shine")) {
achieve6.setOpacity(1); achieve6.setOpacity(1);
} else { } else {
achieve6.setEffect(desaturate);
achieve6.setOpacity(0.3); achieve6.setOpacity(0.3);
} }
} }
//class for the animations on the navigation buttons //class for the animations on the navigation buttons
public class MyButtonSkin extends ButtonSkin { private class MyButtonSkin extends ButtonSkin {
/** /**
* adds a skin and scale animation to a button. * adds a skin and scale animation to a button.
* the scale transition is for hovering over it so it then scales up * the scale transition is for hovering over it so it then scales up
* 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) { private 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

@@ -16,6 +16,7 @@
<?import javafx.scene.shape.Line?> <?import javafx.scene.shape.Line?>
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?> <?import javafx.scene.text.Text?>
<?import javafx.scene.control.Tooltip?>
<AnchorPane prefHeight="702.0" prefWidth="1032.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.DashBoardController"> <AnchorPane prefHeight="702.0" prefWidth="1032.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.DashBoardController">
<children> <children>
@@ -77,7 +78,7 @@
</graphic> </graphic>
</Button> </Button>
</children></AnchorPane> </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"> <AnchorPane fx:id="activitiesPane" layoutX="214.0" prefHeight="703.0" prefWidth="820.0" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="214.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children> <children>
<Text fill="#002c0c" layoutX="101.0" layoutY="74.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Activity Summary" AnchorPane.leftAnchor="60.0" AnchorPane.topAnchor="40.0"> <Text fill="#002c0c" layoutX="101.0" layoutY="74.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Activity Summary" AnchorPane.leftAnchor="60.0" AnchorPane.topAnchor="40.0">
<font> <font>
@@ -399,7 +400,7 @@
</children> </children>
</VBox> </VBox>
</children></AnchorPane> </children></AnchorPane>
<AnchorPane fx:id="dashboardPane" layoutX="215.0" prefHeight="703.0" prefWidth="820.0" visible="false" 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>
<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>
@@ -489,41 +490,65 @@
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints> </rowConstraints>
<children> <children>
<ImageView fx:id="achieve1" fitHeight="101.0" fitWidth="129.0" pickOnBounds="true" preserveRatio="true"> <Button fx:id="achiev1Tip" mnemonicParsing="false" styleClass="toolTipButton">
<image> <graphic>
<Image url="@../icons/Clover.png" /> <ImageView fx:id="achieve1" fitHeight="101.0" fitWidth="129.0" pickOnBounds="true" preserveRatio="true">
<!-- image from pngall.com - 3548 --> <image>
</image> <Image url="@../icons/Clover.png" />
</ImageView> <!-- image from pngall.com - 3548 -->
<ImageView fx:id="achieve2" fitHeight="101.0" fitWidth="129.0" pickOnBounds="true" preserveRatio="true" GridPane.rowIndex="1"> </image>
<image> </ImageView>
<Image url="@../icons/Friendship.png" /> </graphic>
<!-- image from pngall.com - 24498 --> </Button>
</image> <Button fx:id="achiev4Tip" mnemonicParsing="false" styleClass="toolTipButton" GridPane.columnIndex="1">
</ImageView> <graphic>
<ImageView fx:id="achieve3" fitHeight="101.0" fitWidth="129.0" pickOnBounds="true" preserveRatio="true" GridPane.rowIndex="2"> <ImageView fx:id="achieve4" fitHeight="101.0" fitWidth="129.0" pickOnBounds="true" preserveRatio="true">
<image> <image>
<Image url="@../icons/co2dev.png" /> <Image url="@../icons/alternate_foods.png" />
<!-- image from exceldryer.com --> </image>
</image> </ImageView>
</ImageView> </graphic>
<ImageView fx:id="achieve4" fitHeight="101.0" fitWidth="129.0" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="1"> </Button>
<image> <Button fx:id="achiev2Tip" mnemonicParsing="false" styleClass="toolTipButton" GridPane.rowIndex="1">
<Image url="@../icons/alternate_foods.png" /> <graphic>
</image> <ImageView fx:id="achieve2" fitHeight="101.0" fitWidth="129.0" pickOnBounds="true" preserveRatio="true">
</ImageView> <image>
<ImageView fx:id="achieve5" fitHeight="101.0" fitWidth="129.0" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="1" GridPane.rowIndex="1"> <Image url="@../icons/Friendship.png" />
<image> <!-- image from pngall.com - 24498 -->
<Image url="@../icons/achiev1pic.jpg" /> </image>
<!-- image from shutterstock.com - 1038138760 --> </ImageView>
</image> </graphic>
</ImageView> </Button>
<ImageView fx:id="achieve6" fitHeight="101.0" fitWidth="129.0" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="1" GridPane.rowIndex="2"> <Button fx:id="achiev3Tip" mnemonicParsing="false" styleClass="toolTipButton" GridPane.rowIndex="2">
<image> <graphic>
<Image url="@../icons/solar_panels.jpeg" /> <ImageView fx:id="achieve3" fitHeight="101.0" fitWidth="129.0" pickOnBounds="true" preserveRatio="true">
<!-- image from moregreenenergy.com --> <image>
</image> <Image url="@../icons/co2dev.png" />
</ImageView> <!-- image from exceldryer.com -->
</image>
</ImageView>
</graphic>
</Button>
<Button fx:id="achiev5Tip" mnemonicParsing="false" styleClass="toolTipButton" GridPane.columnIndex="1" GridPane.rowIndex="1">
<graphic>
<ImageView fx:id="achieve5" fitHeight="101.0" fitWidth="129.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/achiev1pic.jpg" />
<!-- image from shutterstock.com - 1038138760 -->
</image>
</ImageView>
</graphic>
</Button>
<Button fx:id="achiev6Tip" mnemonicParsing="false" styleClass="toolTipButton" GridPane.columnIndex="1" GridPane.rowIndex="2">
<graphic>
<ImageView fx:id="achieve6" fitHeight="101.0" fitWidth="129.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/solar_panels.jpeg" />
<!-- image from moregreenenergy.com -->
</image>
</ImageView>
</graphic>
</Button>
</children> </children>
</GridPane> </GridPane>
</children> </children>

View File

@@ -81,5 +81,16 @@
-fx-font-size: 14px; -fx-font-size: 14px;
} }
.toolTipButton {
-fx-background-color: transparent;
-fx-padding: 0 0 0 0;
}
.tooltip {
-fx-background-color: #d0f2d3;
-fx-text-fill: #364c38;
-fx-font-size: 14px;
}