diff --git a/src/Client/src/main/java/greenify/client/Friend.java b/src/Client/src/main/java/greenify/client/Friend.java new file mode 100644 index 0000000..87ec3cd --- /dev/null +++ b/src/Client/src/main/java/greenify/client/Friend.java @@ -0,0 +1,32 @@ +package greenify.client; + +import javafx.beans.property.SimpleFloatProperty; +import javafx.beans.property.SimpleStringProperty; + +public class Friend { + + private SimpleStringProperty friend; + private SimpleFloatProperty friendScore; + + public Friend(String friend, Float friendScore) { + this.friend = new SimpleStringProperty(friend); + this.friendScore = new SimpleFloatProperty(friendScore); + } + + + public String getFriend() { + return friend.get(); + } + + public void setFriend(String name) { + this.friend = new SimpleStringProperty(name); + } + + public Float getFriendScore() { + return friendScore.get(); + } + + public void setScore(Float score) { + this.friendScore = new SimpleFloatProperty(score); + } +} \ No newline at end of file diff --git a/src/Client/src/main/java/greenify/client/controller/DashBoardController.java b/src/Client/src/main/java/greenify/client/controller/DashBoardController.java index b697ff3..514c8ea 100644 --- a/src/Client/src/main/java/greenify/client/controller/DashBoardController.java +++ b/src/Client/src/main/java/greenify/client/controller/DashBoardController.java @@ -2,17 +2,24 @@ package greenify.client.controller; import com.sun.javafx.scene.control.skin.ButtonSkin; import greenify.client.Application; +import greenify.client.Friend; import greenify.client.rest.UserService; import javafx.animation.FadeTransition; import javafx.animation.PathTransition; import javafx.animation.ScaleTransition; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.fxml.FXML; 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.cell.PropertyValueFactory; import javafx.scene.layout.AnchorPane; import javafx.scene.shape.Line; import javafx.stage.Stage; @@ -60,6 +67,18 @@ public class DashBoardController { private Button calculateFootPrintButton; @FXML private Label footprintLabel; + @FXML + private Button addFriendButton; + @FXML + private TableView friendsTable; + @FXML + private TableColumn friendsColumn; + @FXML + private TableColumn scoreColumn; + @FXML + private PieChart pieChart; + @FXML + private Label usernameLabel; /** * Loads the the necessary things before anything else. @@ -74,8 +93,23 @@ public class DashBoardController { activitiesButton.setSkin(new MyButtonSkin(activitiesButton)); userButton.setSkin(new MyButtonSkin(userButton)); friendsButton.setSkin(new MyButtonSkin(friendsButton)); - - + friendsColumn.setCellValueFactory(new PropertyValueFactory<>("Friend")); + scoreColumn.setCellValueFactory(new PropertyValueFactory<>("Score")); + friendsTable.setItems(FriendController.getData()); + if(pieChart != null) { + ObservableList pieChartData = + FXCollections.observableArrayList( + new PieChart.Data("Vegan Meal", 100), + new PieChart.Data("Public Transport", 200), + new PieChart.Data("Home Temperature", 50), + new PieChart.Data("Bike", 75), + new PieChart.Data("Local Product", 110), + new PieChart.Data("Solar Panel", 300) + ); + pieChart.setTitle("FOOTPRINT DISTRIBUTION"); + pieChart.setMaxSize(1000, 1000); + pieChart.setData(pieChartData); + } } /** @@ -126,6 +160,7 @@ public class DashBoardController { System.out.println(userService.currentUser.getName()); System.out.println(userService.getFootprint(userService.currentUser.getName())); footprintLabel.setText("" + userService.getFootprint(userService.currentUser.getName())); + usernameLabel.setText("" + userService.currentUser.getName()); addFadeTransition(userPane); System.out.println("display user"); dashboardPane.setVisible(false); @@ -146,7 +181,6 @@ public class DashBoardController { userPane.setVisible(false); activitiesPane.setVisible(false); friendsPane.setVisible(true); - } //sets the slide in transition for startup @@ -172,6 +206,16 @@ public class DashBoardController { calcStage.show(); } + public void openAddFriend() throws IOException { + Parent calc = Application.load(this.getClass().getClassLoader() + .getResource("fxml/AddFriend.fxml")); + Scene scene = new Scene(calc); + Stage calcStage = new Stage(); + calcStage.setScene(scene); + calcStage.setTitle("Add a new friend - " + userService.currentUser.getName()); + calcStage.show(); + } + //class for the animations on the navigation buttons public class MyButtonSkin extends ButtonSkin { /** @@ -198,4 +242,4 @@ public class DashBoardController { } } -} +} \ No newline at end of file diff --git a/src/Client/src/main/java/greenify/client/controller/FriendController.java b/src/Client/src/main/java/greenify/client/controller/FriendController.java new file mode 100644 index 0000000..e364f4f --- /dev/null +++ b/src/Client/src/main/java/greenify/client/controller/FriendController.java @@ -0,0 +1,56 @@ +package greenify.client.controller; + +import greenify.client.Friend; +import greenify.client.rest.UserService; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.scene.control.*; +import javafx.stage.Stage; +import javafx.stage.Window; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; + +@Controller +public class FriendController { + @Autowired + UserService userService; + + public static ObservableList data = FXCollections.observableArrayList(); + + @FXML + private Button addButton; + @FXML + private TextField userNameText; + + /** + * Signs up the user. + * @param event the click of the sign up button + */ + @FXML + public void addFriend(ActionEvent event) { + //set the window to the current window (for displaying the alerts) + Window owner = addButton.getScene().getWindow(); + //check if the username field is empty + if (userNameText.getText().isEmpty()) { + //if so, display an alert + UserController.AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Username Error!", + "Please enter a username!"); + return; + } + //add friend to the current user + userService.addFriend(userService.currentUser.getName(), userNameText.getText()); + Friend friend = new Friend(userNameText.getText(), + userService.getFootprint(userNameText.getText())); + data.add(friend); + //close the register window after the user has entered all the credentials + Stage current = (Stage) owner; + current.close(); + } + + public static ObservableList getData() { + return data; + } + +} diff --git a/src/Client/src/main/resources/fxml/AddFriend.fxml b/src/Client/src/main/resources/fxml/AddFriend.fxml new file mode 100644 index 0000000..018a0ed --- /dev/null +++ b/src/Client/src/main/resources/fxml/AddFriend.fxml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Client/src/main/resources/fxml/dashboard.fxml b/src/Client/src/main/resources/fxml/dashboard.fxml index 535f498..a47f71a 100644 --- a/src/Client/src/main/resources/fxml/dashboard.fxml +++ b/src/Client/src/main/resources/fxml/dashboard.fxml @@ -1,13 +1,11 @@ - - + - + - @@ -169,38 +167,43 @@ - + - + - - + - + + + + + + - @@ -253,8 +268,11 @@ + + + - + \ No newline at end of file diff --git a/src/Client/src/main/resources/icons/butterfly.png b/src/Client/src/main/resources/icons/butterfly.png new file mode 100644 index 0000000..dfefa65 Binary files /dev/null and b/src/Client/src/main/resources/icons/butterfly.png differ diff --git a/src/Client/src/main/resources/icons/friend.png b/src/Client/src/main/resources/icons/friend.png new file mode 100644 index 0000000..98490e8 Binary files /dev/null and b/src/Client/src/main/resources/icons/friend.png differ diff --git a/src/Client/src/main/resources/icons/friends.png b/src/Client/src/main/resources/icons/friends.png new file mode 100644 index 0000000..516e7e5 Binary files /dev/null and b/src/Client/src/main/resources/icons/friends.png differ diff --git a/src/Client/src/main/resources/icons/grass.png b/src/Client/src/main/resources/icons/grass.png new file mode 100644 index 0000000..5d5ad30 Binary files /dev/null and b/src/Client/src/main/resources/icons/grass.png differ