From 1f2d0c32a0c38ef954e319b9946ddc133f362cec Mon Sep 17 00:00:00 2001 From: Frikk Hald Andersen Date: Sat, 7 Apr 2018 13:07:39 +0200 Subject: [PATCH] #95 Made UI for adding sleepdata. Also made a Add Sleepdata button in the menu. --- .DS_Store | Bin 0 -> 8196 bytes .../java/tdt4140/gr1802/app/core/Athlete.java | 2 +- .../tdt4140/gr1802/app/core/CSVsleep.java | 8 +- .../gr1802/app/ui/AddSleepdataController.java | 151 ++++++++++++++++++ .../gr1802/app/ui/AddWorkoutController.java | 10 ++ .../app/ui/AthleteWorkoutController.java | 11 ++ .../app/ui/CoachRequestsController.java | 10 ++ .../app/ui/HomeScreenAthleteController.java | 10 ++ .../gr1802/app/ui/SeeCoachesController.java | 12 ++ .../gr1802/app/ui/SeeWorkoutsController.java | 10 ++ .../java/tdt4140/gr1802/app/ui/Styles.css | 3 + .../tdt4140/gr1802/app/ui/AddSleepdata.fxml | 66 ++++++++ .../tdt4140/gr1802/app/ui/AddWorkout.fxml | 1 + .../tdt4140/gr1802/app/ui/AthleteWorkout.fxml | 1 + .../tdt4140/gr1802/app/ui/CoachRequests.fxml | 1 + .../gr1802/app/ui/HomeScreenAthlete.fxml | 1 + .../tdt4140/gr1802/app/ui/SeeCoaches.fxml | 1 + .../tdt4140/gr1802/app/ui/SeeWorkouts.fxml | 1 + 18 files changed, 292 insertions(+), 7 deletions(-) create mode 100644 .DS_Store create mode 100644 tdt4140-gr1802/app.ui/src/main/java/tdt4140/gr1802/app/ui/AddSleepdataController.java create mode 100644 tdt4140-gr1802/app.ui/src/main/java/tdt4140/gr1802/app/ui/Styles.css create mode 100644 tdt4140-gr1802/app.ui/src/main/resources/tdt4140/gr1802/app/ui/AddSleepdata.fxml diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..74806f75ca88865477f6104feb7e8cb48a4cc4eb GIT binary patch literal 8196 zcmeHMTWlLe6us9?(|yon+*guPS|gW|s!p)e&_r!R9j8f^KGcGpC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V7~F>J*S>?A(!z%J~=J=l+XiIW3(7>Do(4ihJJkCP9egD#e_Lfm{9AHm1) zaeQKdo3G%RMNI6ka!^P-dp#zW(?!d)t#PueviZ^>g4PWnuteB2^7y~^>firwV5Gn# zKp;Ti|B3+C>`w1a(dw^umhxCTLireFp19qdke&+_+=Tag;W){KKMbiJ@pVaG&Iw5x XO8@wW04=!x|N2E5-2Wa4Z^GhFC^{M| literal 0 HcmV?d00001 diff --git a/tdt4140-gr1802/app.core/src/main/java/tdt4140/gr1802/app/core/Athlete.java b/tdt4140-gr1802/app.core/src/main/java/tdt4140/gr1802/app/core/Athlete.java index 2bd32f3..8c13cb6 100644 --- a/tdt4140-gr1802/app.core/src/main/java/tdt4140/gr1802/app/core/Athlete.java +++ b/tdt4140-gr1802/app.core/src/main/java/tdt4140/gr1802/app/core/Athlete.java @@ -145,6 +145,6 @@ public int getNrOfWorkouts(String activity) { public void addSleepData (URL path) { CSVsleep csvSleep = new CSVsleep (path); - sleepdata = csvSleep.getSleepData(); + sleepdata = csvSleep.getSleepData(); } } diff --git a/tdt4140-gr1802/app.core/src/main/java/tdt4140/gr1802/app/core/CSVsleep.java b/tdt4140-gr1802/app.core/src/main/java/tdt4140/gr1802/app/core/CSVsleep.java index 02be26e..75be203 100644 --- a/tdt4140-gr1802/app.core/src/main/java/tdt4140/gr1802/app/core/CSVsleep.java +++ b/tdt4140-gr1802/app.core/src/main/java/tdt4140/gr1802/app/core/CSVsleep.java @@ -35,21 +35,15 @@ public List> getSleepData() { br = new BufferedReader(new InputStreamReader(filePath.openStream())); while ((line = br.readLine()) != null) { if (line.isEmpty() || i == 0 || i == 1) { - System.out.println("Empty"); } else { // use comma as separator String[] linje = line.split(cvsSplitBy); String date = linje[1].substring(0,10); List day = Arrays.asList(date, linje[2], linje[3]); sleepdata.add(day); - /*for (String e: day) { - System.out.println(e); - }*/ } - //System.out.println("kommer hit"); i++; } - //returns array return sleepdata; @@ -57,6 +51,8 @@ public List> getSleepData() { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); + } catch (ArrayIndexOutOfBoundsException e) { + e.printStackTrace(); } finally { if (br != null) { try { diff --git a/tdt4140-gr1802/app.ui/src/main/java/tdt4140/gr1802/app/ui/AddSleepdataController.java b/tdt4140-gr1802/app.ui/src/main/java/tdt4140/gr1802/app/ui/AddSleepdataController.java new file mode 100644 index 0000000..810dd91 --- /dev/null +++ b/tdt4140-gr1802/app.ui/src/main/java/tdt4140/gr1802/app/ui/AddSleepdataController.java @@ -0,0 +1,151 @@ +package tdt4140.gr1802.app.ui; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; + +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.fxml.LoadException; +import javafx.scene.Node; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.scene.control.Button; +import javafx.scene.control.CheckBox; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; +import javafx.stage.Stage; +import tdt4140.gr1802.app.core.App; +import tdt4140.gr1802.app.core.Athlete; +import tdt4140.gr1802.app.core.Database; +import tdt4140.gr1802.app.core.Workout; + +public class AddSleepdataController { + + // Making variables for every element in the fxml-file + + @FXML + private Button btAddSleepdata ; + + @FXML + private Button btAddWorkout; + + @FXML + private Button btSeeWorkouts; + + @FXML + private Button btSeeCoaches; + + @FXML + private Button btCoachRequests; + + @FXML + private TextField filepathTextField; + + @FXML + private Button addButton; + + @FXML + private Label txtLabelUsername; + + @FXML + private CheckBox checkBox; + + @FXML + private TextField gpxField; + + private Button homeScreenButton; + + private Database db; + + private static App app; + + private static Athlete athlete; + + private boolean visibility; + + + + // Initialization method + public void initialize() { + athlete = app.getAthlete(); + this.db = app.getDb(); + + // Set username label + this.txtLabelUsername.setText(athlete.getUsername()); + } + + + // Method called when "Add" button clicked + public void clickAddButton (ActionEvent event) throws IOException { + // The text in the application is used as a filepath, adds workout to the DB + String path = filepathTextField.getText(); + URL filePath = new File(path).toURI().toURL(); + athlete.addSleepData(filePath); + db.addSleepData(athlete); + } + + + // Side-menu buttons + public void clickAddWorkout (ActionEvent event) throws IOException, LoadException{ + // Open new window + Parent root = FXMLLoader.load(getClass().getResource("AddWorkout.fxml")); + Scene scene = new Scene(root,1280,720); + Stage window = (Stage) ((Node)event.getSource()).getScene().getWindow(); + + window.setScene(scene); + window.show(); + + } + + public void clickSeeWorkouts (ActionEvent event) throws IOException{ + Parent root = FXMLLoader.load(getClass().getResource("SeeWorkouts.fxml")); + Scene scene = new Scene(root,1280,720); + Stage window = (Stage) ((Node)event.getSource()).getScene().getWindow(); + window.setScene(scene); + window.show(); + } + + public void clickSeeCoaches (ActionEvent event) throws IOException{ + Parent root = FXMLLoader.load(getClass().getResource("SeeCoaches.fxml")); + Scene scene = new Scene(root,1280,720); + Stage window = (Stage) ((Node)event.getSource()).getScene().getWindow(); + + window.setScene(scene); + window.show(); + } + + public void clickCoachRequest (ActionEvent event) throws IOException{ + Parent root = FXMLLoader.load(getClass().getResource("CoachRequests.fxml")); + Scene scene = new Scene(root,1280,720); + Stage window = (Stage) ((Node)event.getSource()).getScene().getWindow(); + + window.setScene(scene); + window.show(); + } + + + public void backToHomeScreen(ActionEvent event) throws IOException{ + Parent root = FXMLLoader.load(getClass().getResource("HomeScreenAthlete.fxml")); + Scene scene = new Scene(root,1280,720); + Stage window = (Stage) ((Node)event.getSource()).getScene().getWindow(); + + window.setScene(scene); + window.show(); + } + + public void clickAddSleepdata (ActionEvent event) throws IOException, LoadException{ + // Open new window + Parent root = FXMLLoader.load(getClass().getResource("AddSleepdata.fxml")); + Scene scene = new Scene(root,1280,720); + Stage window = (Stage) ((Node)event.getSource()).getScene().getWindow(); + + window.setScene(scene); + window.show(); + } + +} + diff --git a/tdt4140-gr1802/app.ui/src/main/java/tdt4140/gr1802/app/ui/AddWorkoutController.java b/tdt4140-gr1802/app.ui/src/main/java/tdt4140/gr1802/app/ui/AddWorkoutController.java index 1f479ae..324247b 100644 --- a/tdt4140-gr1802/app.ui/src/main/java/tdt4140/gr1802/app/ui/AddWorkoutController.java +++ b/tdt4140-gr1802/app.ui/src/main/java/tdt4140/gr1802/app/ui/AddWorkoutController.java @@ -166,5 +166,15 @@ public void backToHomeScreen(ActionEvent event) throws IOException{ window.setScene(scene); window.show(); } + + public void clickAddSleepdata (ActionEvent event) throws IOException, LoadException{ + // Open new window + Parent root = FXMLLoader.load(getClass().getResource("AddSleepdata.fxml")); + Scene scene = new Scene(root,1280,720); + Stage window = (Stage) ((Node)event.getSource()).getScene().getWindow(); + + window.setScene(scene); + window.show(); + } } diff --git a/tdt4140-gr1802/app.ui/src/main/java/tdt4140/gr1802/app/ui/AthleteWorkoutController.java b/tdt4140-gr1802/app.ui/src/main/java/tdt4140/gr1802/app/ui/AthleteWorkoutController.java index b4996e9..b1dde4f 100644 --- a/tdt4140-gr1802/app.ui/src/main/java/tdt4140/gr1802/app/ui/AthleteWorkoutController.java +++ b/tdt4140-gr1802/app.ui/src/main/java/tdt4140/gr1802/app/ui/AthleteWorkoutController.java @@ -8,6 +8,7 @@ import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; +import javafx.fxml.LoadException; import javafx.scene.Node; import javafx.scene.Parent; import javafx.scene.Scene; @@ -183,5 +184,15 @@ public void backToHomeScreen(ActionEvent event) throws IOException{ window.setScene(scene); window.show(); } + + public void clickAddSleepdata (ActionEvent event) throws IOException, LoadException{ + // Open new window + Parent root = FXMLLoader.load(getClass().getResource("AddSleepdata.fxml")); + Scene scene = new Scene(root,1280,720); + Stage window = (Stage) ((Node)event.getSource()).getScene().getWindow(); + + window.setScene(scene); + window.show(); + } } diff --git a/tdt4140-gr1802/app.ui/src/main/java/tdt4140/gr1802/app/ui/CoachRequestsController.java b/tdt4140-gr1802/app.ui/src/main/java/tdt4140/gr1802/app/ui/CoachRequestsController.java index b6f909c..07d002f 100644 --- a/tdt4140-gr1802/app.ui/src/main/java/tdt4140/gr1802/app/ui/CoachRequestsController.java +++ b/tdt4140-gr1802/app.ui/src/main/java/tdt4140/gr1802/app/ui/CoachRequestsController.java @@ -166,5 +166,15 @@ public void backToHomeScreen(ActionEvent event) throws IOException{ window.setScene(scene); window.show(); } + + public void clickAddSleepdata (ActionEvent event) throws IOException, LoadException{ + // Open new window + Parent root = FXMLLoader.load(getClass().getResource("AddSleepdata.fxml")); + Scene scene = new Scene(root,1280,720); + Stage window = (Stage) ((Node)event.getSource()).getScene().getWindow(); + + window.setScene(scene); + window.show(); + } } diff --git a/tdt4140-gr1802/app.ui/src/main/java/tdt4140/gr1802/app/ui/HomeScreenAthleteController.java b/tdt4140-gr1802/app.ui/src/main/java/tdt4140/gr1802/app/ui/HomeScreenAthleteController.java index 222ea18..35943bd 100644 --- a/tdt4140-gr1802/app.ui/src/main/java/tdt4140/gr1802/app/ui/HomeScreenAthleteController.java +++ b/tdt4140-gr1802/app.ui/src/main/java/tdt4140/gr1802/app/ui/HomeScreenAthleteController.java @@ -146,4 +146,14 @@ public void clickCoachRequest (ActionEvent event) throws IOException{ window.setScene(scene); window.show(); } + + public void clickAddSleepdata (ActionEvent event) throws IOException, LoadException{ + // Open new window + Parent root = FXMLLoader.load(getClass().getResource("AddSleepdata.fxml")); + Scene scene = new Scene(root,1280,720); + Stage window = (Stage) ((Node)event.getSource()).getScene().getWindow(); + + window.setScene(scene); + window.show(); + } } diff --git a/tdt4140-gr1802/app.ui/src/main/java/tdt4140/gr1802/app/ui/SeeCoachesController.java b/tdt4140-gr1802/app.ui/src/main/java/tdt4140/gr1802/app/ui/SeeCoachesController.java index 4704fe4..c484548 100644 --- a/tdt4140-gr1802/app.ui/src/main/java/tdt4140/gr1802/app/ui/SeeCoachesController.java +++ b/tdt4140-gr1802/app.ui/src/main/java/tdt4140/gr1802/app/ui/SeeCoachesController.java @@ -179,4 +179,16 @@ public void backToHomeScreen(ActionEvent event) throws IOException{ window.setScene(scene); window.show(); } + + public void clickAddSleepdata (ActionEvent event) throws IOException, LoadException{ + // Open new window + Parent root = FXMLLoader.load(getClass().getResource("AddSleepdata.fxml")); + Scene scene = new Scene(root,1280,720); + Stage window = (Stage) ((Node)event.getSource()).getScene().getWindow(); + + window.setScene(scene); + window.show(); + } + + } diff --git a/tdt4140-gr1802/app.ui/src/main/java/tdt4140/gr1802/app/ui/SeeWorkoutsController.java b/tdt4140-gr1802/app.ui/src/main/java/tdt4140/gr1802/app/ui/SeeWorkoutsController.java index b46675e..2a34c7a 100644 --- a/tdt4140-gr1802/app.ui/src/main/java/tdt4140/gr1802/app/ui/SeeWorkoutsController.java +++ b/tdt4140-gr1802/app.ui/src/main/java/tdt4140/gr1802/app/ui/SeeWorkoutsController.java @@ -12,6 +12,7 @@ import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; +import javafx.fxml.LoadException; import javafx.scene.Node; import javafx.scene.Parent; import javafx.scene.Scene; @@ -184,4 +185,13 @@ public void backToHomeScreen(ActionEvent event) throws IOException{ window.show(); } + public void clickAddSleepdata (ActionEvent event) throws IOException, LoadException{ + // Open new window + Parent root = FXMLLoader.load(getClass().getResource("AddSleepdata.fxml")); + Scene scene = new Scene(root,1280,720); + Stage window = (Stage) ((Node)event.getSource()).getScene().getWindow(); + + window.setScene(scene); + window.show(); + } } diff --git a/tdt4140-gr1802/app.ui/src/main/java/tdt4140/gr1802/app/ui/Styles.css b/tdt4140-gr1802/app.ui/src/main/java/tdt4140/gr1802/app/ui/Styles.css new file mode 100644 index 0000000..a86e057 --- /dev/null +++ b/tdt4140-gr1802/app.ui/src/main/java/tdt4140/gr1802/app/ui/Styles.css @@ -0,0 +1,3 @@ +.button { + -fx-font-weight: bold; +} diff --git a/tdt4140-gr1802/app.ui/src/main/resources/tdt4140/gr1802/app/ui/AddSleepdata.fxml b/tdt4140-gr1802/app.ui/src/main/resources/tdt4140/gr1802/app/ui/AddSleepdata.fxml new file mode 100644 index 0000000..b90c8fe --- /dev/null +++ b/tdt4140-gr1802/app.ui/src/main/resources/tdt4140/gr1802/app/ui/AddSleepdata.fxml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +