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

View File

@@ -6,8 +6,10 @@ import greenify.client.Friend;
import greenify.client.Hints;
import greenify.client.rest.UserService;
import javafx.animation.FadeTransition;
import javafx.animation.KeyFrame;
import javafx.animation.PathTransition;
import javafx.animation.ScaleTransition;
import javafx.animation.Timeline;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
@@ -16,11 +18,14 @@ import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.chart.PieChart;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.Tooltip;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.effect.ColorAdjust;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.shape.Line;
@@ -31,6 +36,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -187,13 +193,25 @@ public class DashBoardController {
@FXML
private Label loweringTemp;
@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.
* @throws InterruptedException exception if interrupted
*/
public void initialize() throws InterruptedException {
hintText.setWrapText(true);
hintText.setText(hints.randomHint());
//set the dashboardPane to visible
@@ -247,6 +265,52 @@ public class DashBoardController {
addExtraActivityButton.setSkin(new ClickButtonSkin(addExtraActivityButton));
addExtraActivityButton2.setSkin(new ClickButtonSkin(addExtraActivityButton2));
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)
* @throws IOException if the Application doesn't load.
*/
@@ -576,47 +640,55 @@ public class DashBoardController {
*/
public void updateAchievements() {
Map achievements = userService.getAchievements(userService.currentUser.getName());
ColorAdjust desaturate = new ColorAdjust();
desaturate.setSaturation(-0.75);
if ((Boolean)achievements.get("Starting off")) {
achieve1.setOpacity(1);
} else {
achieve1.setEffect(desaturate);
achieve1.setOpacity(0.3);
}
if ((Boolean)achievements.get("Social butterfly")) {
achieve2.setOpacity(1);
} else {
achieve2.setEffect(desaturate);
achieve2.setOpacity(0.3);
}
if ((Boolean)achievements.get("Green saver")) {
achieve3.setOpacity(1);
} else {
achieve3.setEffect(desaturate);
achieve3.setOpacity(0.3);
}
if ((Boolean)achievements.get("Animal friend")) {
achieve4.setOpacity(1);
} else {
achieve4.setEffect(desaturate);
achieve4.setOpacity(0.3);
}
if ((Boolean)achievements.get("Tom Dumoulin")) {
achieve5.setOpacity(1);
} else {
achieve5.setEffect(desaturate);
achieve5.setOpacity(0.3);
}
if ((Boolean)achievements.get("Let it shine")) {
achieve6.setOpacity(1);
} else {
achieve6.setEffect(desaturate);
achieve6.setOpacity(0.3);
}
}
//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.
* the scale transition is for hovering over it so it then scales up
* and scales down when you stop hovering over it.
* @param button the button to add the animation to
*/
public MyButtonSkin(Button button) {
private MyButtonSkin(Button button) {
//inherit the button properties
super(button);
//transition to scale up on hover

View File

@@ -16,6 +16,7 @@
<?import javafx.scene.shape.Line?>
<?import javafx.scene.text.Font?>
<?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">
<children>
@@ -77,7 +78,7 @@
</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">
<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>
<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>
@@ -399,7 +400,7 @@
</children>
</VBox>
</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>
<Label fx:id="welcomebacktext" layoutX="69.0" layoutY="53.0" text="Welcome back user!" AnchorPane.leftAnchor="60.0" AnchorPane.topAnchor="40.0">
<font>
@@ -489,41 +490,65 @@
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Button fx:id="achiev1Tip" mnemonicParsing="false" styleClass="toolTipButton">
<graphic>
<ImageView fx:id="achieve1" fitHeight="101.0" fitWidth="129.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/Clover.png" />
<!-- image from pngall.com - 3548 -->
</image>
</ImageView>
<ImageView fx:id="achieve2" fitHeight="101.0" fitWidth="129.0" pickOnBounds="true" preserveRatio="true" GridPane.rowIndex="1">
</graphic>
</Button>
<Button fx:id="achiev4Tip" mnemonicParsing="false" styleClass="toolTipButton" GridPane.columnIndex="1">
<graphic>
<ImageView fx:id="achieve4" fitHeight="101.0" fitWidth="129.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/alternate_foods.png" />
</image>
</ImageView>
</graphic>
</Button>
<Button fx:id="achiev2Tip" mnemonicParsing="false" styleClass="toolTipButton" GridPane.rowIndex="1">
<graphic>
<ImageView fx:id="achieve2" fitHeight="101.0" fitWidth="129.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/Friendship.png" />
<!-- image from pngall.com - 24498 -->
</image>
</ImageView>
<ImageView fx:id="achieve3" fitHeight="101.0" fitWidth="129.0" pickOnBounds="true" preserveRatio="true" GridPane.rowIndex="2">
</graphic>
</Button>
<Button fx:id="achiev3Tip" mnemonicParsing="false" styleClass="toolTipButton" GridPane.rowIndex="2">
<graphic>
<ImageView fx:id="achieve3" fitHeight="101.0" fitWidth="129.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/co2dev.png" />
<!-- image from exceldryer.com -->
</image>
</ImageView>
<ImageView fx:id="achieve4" fitHeight="101.0" fitWidth="129.0" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="1">
<image>
<Image url="@../icons/alternate_foods.png" />
</image>
</ImageView>
<ImageView fx:id="achieve5" fitHeight="101.0" fitWidth="129.0" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="1" GridPane.rowIndex="1">
</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>
<ImageView fx:id="achieve6" fitHeight="101.0" fitWidth="129.0" pickOnBounds="true" preserveRatio="true" GridPane.columnIndex="1" GridPane.rowIndex="2">
</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>
</GridPane>
</children>

View File

@@ -81,5 +81,16 @@
-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;
}