diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..74806f7 Binary files /dev/null and b/.DS_Store differ 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 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +