Skip to content

Commit

Permalink
#95 Made UI for adding sleepdata. Also made a Add Sleepdata button in…
Browse files Browse the repository at this point in the history
… the menu.
  • Loading branch information
Frikk Hald Andersen committed Apr 7, 2018
1 parent 31dac00 commit 1f2d0c3
Show file tree
Hide file tree
Showing 18 changed files with 292 additions and 7 deletions.
Binary file added .DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,24 @@ public List<List<String>> 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 <String> 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;

} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ArrayIndexOutOfBoundsException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.button {
-fx-font-weight: bold;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.effect.DropShadow?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.shape.Line?>
<?import javafx.scene.text.Font?>

<AnchorPane prefHeight="720.0" prefWidth="1280.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="tdt4140.gr1802.app.ui.AddSleepdataController">
<children>
<ImageView fitHeight="75.0" fitWidth="181.0" layoutY="3.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@Images/homescreen_pink.png" />
</image>
<effect>
<DropShadow />
</effect>
</ImageView>
<AnchorPane fx:id="logo" prefHeight="720.0" prefWidth="1280.0">
<children>
<SplitPane layoutY="71.0" prefHeight="655.0" prefWidth="1280.0">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="575.0" prefWidth="1280.0">
<children>
<VBox layoutX="22.0" layoutY="64.0" prefHeight="104.0" prefWidth="107.0">
<children>
<Button fx:id="btAddWorkout" mnemonicParsing="false" onAction="#clickAddWorkout" prefHeight="25.0" prefWidth="106.0" text="Add Workout" />
<Button fx:id="btSeeWorkouts" mnemonicParsing="false" onAction="#clickSeeWorkouts" prefHeight="25.0" prefWidth="106.0" text="See Workouts" />
<Button fx:id="btSeeCoaches" mnemonicParsing="false" onAction="#clickSeeCoaches" prefHeight="25.0" prefWidth="106.0" text="See Coaches" />
<Button fx:id="btCoachRequests" mnemonicParsing="false" onAction="#clickCoachRequest" prefHeight="25.0" prefWidth="106.0" text="Coach Requests" />
<Button fx:id="btAddSleepdata" mnemonicParsing="false" onAction="#clickAddSleepdata" prefHeight="25.0" prefWidth="106.0" text="Add Sleepdata" />
</children>
</VBox>
<Pane layoutX="159.0" prefHeight="655.0" prefWidth="1127.0">
<children>
<TextField fx:id="filepathTextField" layoutX="29.0" layoutY="65.0" prefHeight="27.0" prefWidth="501.0" promptText="Enter CSV Filepath" />
<Button fx:id="addButton" layoutX="29.0" layoutY="188.0" mnemonicParsing="false" onAction="#clickAddButton" prefHeight="27.0" prefWidth="107.0" text="Add" />
</children></Pane>
</children>
</AnchorPane>
</items>
</SplitPane>
<Label fx:id="txtLabelUsername" alignment="CENTER_RIGHT" contentDisplay="RIGHT" layoutX="1050.0" layoutY="30.0" prefHeight="18.0" prefWidth="175.0" textAlignment="RIGHT">
<font>
<Font size="14.0" />
</font>
</Label>
</children></AnchorPane>
<Line endX="1183.0" layoutX="97.0" layoutY="71.0" startX="-100.0" />
<Line endX="751.0" layoutX="-261.0" layoutY="402.0" rotate="270.0" startX="89.0" />
<Label layoutX="26.0" layoutY="17.0" prefHeight="42.0" prefWidth="143.0" text="It's Training" textFill="WHITE">
<font>
<Font name="Century Gothic" size="23.0" />
</font>
</Label>
<Button fx:id="homeScreenButton" layoutX="23.0" layoutY="25.0" mnemonicParsing="false" onAction="#backToHomeScreen" opacity="0.0" prefHeight="27.0" prefWidth="136.0" text="Button" />
</children>
</AnchorPane>
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<VBox layoutX="22.0" layoutY="64.0" prefHeight="104.0" prefWidth="107.0">
<children>
<Button fx:id="btAddWorkout" mnemonicParsing="false" onAction="#clickAddWorkout" prefHeight="25.0" prefWidth="106.0" text="Add Workout" />
<Button fx:id="btAddSleepdata" mnemonicParsing="false" onAction="#clickAddSleepdata" prefHeight="25.0" prefWidth="106.0" text="Add Sleepdata" />
<Button fx:id="btSeeWorkouts" mnemonicParsing="false" onAction="#clickSeeWorkouts" prefHeight="25.0" prefWidth="106.0" text="See Workouts" />
<Button fx:id="btSeeCoaches" mnemonicParsing="false" onAction="#clickSeeCoaches" prefHeight="25.0" prefWidth="106.0" text="See Coaches" />
<Button fx:id="btCoachRequests" mnemonicParsing="false" onAction="#clickCoachRequest" prefHeight="25.0" prefWidth="106.0" text="Coach Requests" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<VBox layoutX="22.0" layoutY="64.0" prefHeight="104.0" prefWidth="107.0">
<children>
<Button fx:id="btAddWorkout" mnemonicParsing="false" onAction="#clickAddWorkout" prefHeight="25.0" prefWidth="106.0" text="Add Workout" />
<Button fx:id="btAddSleepdata" mnemonicParsing="false" onAction="#clickAddSleepdata" prefHeight="25.0" prefWidth="106.0" text="Add Sleepdata" />
<Button fx:id="btSeeWorkouts" mnemonicParsing="false" onAction="#clickSeeWorkouts" prefHeight="25.0" prefWidth="106.0" text="See Workouts" />
<Button fx:id="btSeeCoaches" mnemonicParsing="false" onAction="#clickSeeCoaches" prefHeight="25.0" prefWidth="106.0" text="See Coaches" />
<Button fx:id="btCoachRequests" mnemonicParsing="false" onAction="#clickCoachRequest" prefHeight="25.0" prefWidth="106.0" text="Coach Requests" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<VBox layoutX="22.0" layoutY="64.0" prefHeight="104.0" prefWidth="107.0">
<children>
<Button fx:id="btAddWorkout" mnemonicParsing="false" onAction="#clickAddWorkout" prefHeight="25.0" prefWidth="106.0" text="Add Workout" />
<Button fx:id="btAddSleepdata" mnemonicParsing="false" onAction="#clickAddSleepdata" prefHeight="25.0" prefWidth="106.0" text="Add Sleepdata" />
<Button fx:id="btSeeWorkouts" mnemonicParsing="false" onAction="#clickSeeWorkouts" prefHeight="25.0" prefWidth="106.0" text="See Workouts" />
<Button fx:id="btSeeCoaches" mnemonicParsing="false" onAction="#clickSeeCoaches" prefHeight="25.0" prefWidth="106.0" text="See Coaches" />
<Button fx:id="btCoachRequests" mnemonicParsing="false" onAction="#clickCoachRequest" prefHeight="25.0" prefWidth="106.0" text="Coach Requests" />
Expand Down
Loading

0 comments on commit 1f2d0c3

Please sign in to comment.