Merge branch 'connect_friends_GUI' into 'master'

Edit GUI for friend property

See merge request cse1105/2018-2019/oopp-group-43/template!49
This commit is contained in:
Ceren Ugurlu
2019-03-30 10:58:18 +00:00
9 changed files with 205 additions and 16 deletions

View File

@@ -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);
}
}

View File

@@ -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<Friend> friendsTable;
@FXML
private TableColumn<Friend, String> friendsColumn;
@FXML
private TableColumn<Friend, Float> 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<PieChart.Data> 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 {
}
}
}
}

View File

@@ -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<Friend> 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<Friend> getData() {
return data;
}
}

View File

@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<AnchorPane prefHeight="287.0" prefWidth="187.0" style="-fx-background-color: #e2f0c8;" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.FriendController">
<children>
<Text fill="#00650d" layoutX="114.0" layoutY="64.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Add Friend" textAlignment="CENTER" wrappingWidth="234.96600341796875">
<font>
<Font size="36.0" />
</font>
</Text>
<TextField fx:id="userNameText" layoutX="140.0" layoutY="100.0" prefHeight="35.0" prefWidth="183.0" promptText="Username">
<font>
<Font size="13.0" />
</font>
</TextField>
<Button fx:id="addButton" layoutX="206.0" layoutY="154.0" mnemonicParsing="false" onAction="#addFriend" style="-fx-background-color: #005e07;" text="Add!" textFill="#c4eec9">
<font>
<Font name="Corbel Bold" size="14.0" />
</font>
</Button>
<ImageView fitHeight="80.0" fitWidth="349.0" layoutY="211.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/grass.png"/>
</image>
</ImageView>
<ImageView fitHeight="150.0" fitWidth="200.0" layoutY="43.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/friends.png" />
</image>
</ImageView>
</children>
</AnchorPane>

View File

@@ -1,13 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import java.lang.*?>
<?import javafx.scene.chart.PieChart?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.shape.*?>
<?import javafx.scene.shape.Line?>
<?import javafx.scene.text.*?>
<AnchorPane prefHeight="702.0" prefWidth="1032.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.DashBoardController">
<children>
<AnchorPane fx:id="menuBar" prefHeight="703.0" prefWidth="216.0" style="-fx-background-color: #5a635c;">
@@ -169,38 +167,43 @@
<Font size="30.0" />
</font>
</Text>
<VBox layoutX="517.0" layoutY="28.0" prefHeight="53.0" prefWidth="100.0" style="-fx-background-color: #daefdf; -fx-border-radius: 20%;">
<VBox layoutX="80.0" layoutY="150.0" prefHeight="59.0" prefWidth="266.0" style="-fx-background-color: #daefdf; -fx-border-radius: 20%;">
<children>
<Text fill="#004d11" strokeType="OUTSIDE" strokeWidth="0.0" text="Score" textAlignment="CENTER" wrappingWidth="100.79296875">
<Text fill="#004d11" strokeType="OUTSIDE" strokeWidth="0.0" text="Username" textAlignment="CENTER" wrappingWidth="267.1929016113281">
<font>
<Font size="24.0" />
</font>
</Text>
<Label fx:id="scoreField" alignment="CENTER" contentDisplay="CENTER" prefHeight="17.0" prefWidth="101.0" text="score" textAlignment="CENTER">
<Label fx:id="usernameLabel" alignment="CENTER" contentDisplay="CENTER" layoutX="50.0" prefHeight="27.0" prefWidth="267.0" text="username" textAlignment="CENTER">
<font>
<Font size="18.0" />
</font>
</Label>
</children>
</VBox>
<VBox alignment="CENTER" layoutX="517.0" layoutY="121.0" prefHeight="53.0" prefWidth="100.0" style="-fx-background-color: #daefdf; -fx-border-radius: 20%;">
<VBox alignment="CENTER" layoutX="80.0" layoutY="250.0" prefHeight="59.0" prefWidth="266.0" style="-fx-background-color: #daefdf; -fx-border-radius: 20%;">
<children>
<Text fill="#004d11" strokeType="OUTSIDE" strokeWidth="0.0" text="CO2 footprint" textAlignment="CENTER" wrappingWidth="161.79296875">
<font>
<Font size="24.0" />
</font>
</Text>
<Label fx:id="footprintLabel" alignment="CENTER" contentDisplay="CENTER" prefHeight="27.0" prefWidth="134.0" text="co2 footprint" textAlignment="CENTER">
<Label fx:id="footprintLabel" alignment="CENTER" contentDisplay="CENTER" prefHeight="27.0" prefWidth="162.0" text="co2 footprint" textAlignment="CENTER">
<font>
<Font size="18.0" />
</font>
</Label>
</children>
</VBox>
<PieChart fx:id="pieChart" layoutX="441.0" layoutY="300.0" prefHeight="352.0" prefWidth="363.0" />
<ImageView fitHeight="163.0" fitWidth="200.0" layoutX="550.0" layoutY="47.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/butterfly.png" />
</image>
</ImageView>
</children></AnchorPane>
<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>
<HBox layoutX="97.0" layoutY="124.0" prefHeight="100.0" prefWidth="200.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 size="30.0" />
@@ -223,7 +226,7 @@
<Font size="15.0" />
</font>
</Text>
<Button fx:id="calculateFootPrintButton" contentDisplay="RIGHT" layoutX="572.0" layoutY="124.0" mnemonicParsing="false" onAction="#openCalculator" prefHeight="74.0" prefWidth="205.0" style="-fx-border-radius: 20px; -fx-padding: 0px 0px 0px 0px; -fx-background-color: transparent;" text="Calculate your &#10;CO2 footprint" textFill="#29721a">
<Button fx:id="calculateFootPrintButton" contentDisplay="RIGHT" layoutX="577.0" layoutY="126.0" mnemonicParsing="false" onAction="#openCalculator" prefHeight="74.0" prefWidth="205.0" style="-fx-border-radius: 20px; -fx-padding: 0px 0px 0px 0px; -fx-background-color: transparent;" text="Calculate your &#10;CO2 footprint" textFill="#29721a">
<font>
<Font name="Corbel Bold" size="14.0" />
</font>
@@ -239,6 +242,18 @@
</ImageView>
</graphic>
</Button>
<Button fx:id="addFriendButton" contentDisplay="RIGHT" layoutX="596.0" layoutY="220.0" mnemonicParsing="false" onAction="#openAddFriend" prefHeight="74.0" prefWidth="200.0" style="-fx-border-radius: 20px; -fx-padding: 0px 0px 0px 0px; -fx-background-color: transparent;" text="Add friend" textFill="#29721a">
<font>
<Font name="Corbel Bold" size="14.0" />
</font>
<graphic>
<ImageView fitHeight="74.0" fitWidth="64.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../icons/friend.png" />
</image>
</ImageView>
</graphic>
</Button>
</children>
</AnchorPane>
<AnchorPane fx:id="friendsPane" layoutX="216.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">
@@ -253,8 +268,11 @@
<TableColumn fx:id="friendsColumn" prefWidth="107.0" text="Friend" />
<TableColumn fx:id="scoreColumn" prefWidth="108.0" text="Score" />
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
</TableView>
</children>
</AnchorPane>
</children>
</AnchorPane>
</AnchorPane>

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB