diff --git a/.classpath b/.classpath
index d171cd4..470db96 100644
--- a/.classpath
+++ b/.classpath
@@ -1,6 +1,7 @@
-
-
-
-
-
-
+
+
+
+
+
+
+
diff --git a/.gitattributes b/.gitattributes
index 7351b55..bdb0cab 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1,17 +1,17 @@
-# Auto detect text files and perform LF normalization
-* text=auto
-
-# Custom for Visual Studio
-*.cs diff=csharp
-
-# Standard to msysgit
-*.doc diff=astextplain
-*.DOC diff=astextplain
-*.docx diff=astextplain
-*.DOCX diff=astextplain
-*.dot diff=astextplain
-*.DOT diff=astextplain
-*.pdf diff=astextplain
-*.PDF diff=astextplain
-*.rtf diff=astextplain
-*.RTF diff=astextplain
+# Auto detect text files and perform LF normalization
+* text=auto
+
+# Custom for Visual Studio
+*.cs diff=csharp
+
+# Standard to msysgit
+*.doc diff=astextplain
+*.DOC diff=astextplain
+*.docx diff=astextplain
+*.DOCX diff=astextplain
+*.dot diff=astextplain
+*.DOT diff=astextplain
+*.pdf diff=astextplain
+*.PDF diff=astextplain
+*.rtf diff=astextplain
+*.RTF diff=astextplain
diff --git a/.gitignore b/.gitignore
index ae3c172..2216b25 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,4 @@
/bin/
+.idea
+WorkTimePlanner.eml
+WorkTimePlanner.iml
diff --git a/.project b/.project
index 32aaf72..a481939 100644
--- a/.project
+++ b/.project
@@ -1,17 +1,17 @@
-
-
- WorkTimePlanner
-
-
-
-
-
- org.eclipse.jdt.core.javabuilder
-
-
-
-
-
- org.eclipse.jdt.core.javanature
-
-
+
+
+ WorkTimePlanner
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/lib/pdfbox-app-1.8.10.jar b/lib/pdfbox-app-1.8.10.jar
new file mode 100644
index 0000000..4c6b4f3
Binary files /dev/null and b/lib/pdfbox-app-1.8.10.jar differ
diff --git a/src/wtp/gui/Gui.java b/src/wtp/gui/Gui.java
index 884d7bf..b1ff348 100644
--- a/src/wtp/gui/Gui.java
+++ b/src/wtp/gui/Gui.java
@@ -1,321 +1,343 @@
-package wtp.gui;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.List;
-
-import javafx.application.Application;
-import javafx.event.ActionEvent;
-import javafx.event.EventHandler;
-import javafx.geometry.Insets;
-import javafx.geometry.Orientation;
-import javafx.geometry.Pos;
-import javafx.scene.Node;
-import javafx.scene.Scene;
-import javafx.scene.control.Alert.AlertType;
-import javafx.scene.control.Alert;
-import javafx.scene.control.Button;
-import javafx.scene.control.Label;
-import javafx.scene.control.ProgressBar;
-import javafx.scene.control.Separator;
-import javafx.scene.control.TextField;
-import javafx.scene.layout.Background;
-import javafx.scene.layout.BackgroundFill;
-import javafx.scene.layout.BorderPane;
-import javafx.scene.layout.HBox;
-import javafx.scene.layout.Priority;
-import javafx.scene.layout.Region;
-import javafx.scene.layout.VBox;
-import javafx.scene.paint.Color;
-import javafx.stage.FileChooser;
-import javafx.stage.Popup;
-import javafx.stage.Stage;
-import wtp.io.ProjectReader;
-import wtp.model.Activity;
-import wtp.model.Project;
-
-public class Gui extends Application {
-
- private double height = 600.0;
- private double width = 800.0;
-
- private Stage primaryStage;
-
- private Scene introScene;
- private Scene mainScene;
- private ProgressBar bar;
- private VBox center;
- private VBox activityView;
- private Project p;
-
- public void createIntroScene() {
- VBox vb = new VBox();
- introScene = new Scene(vb, width / 2, height / 2);
- vb.setAlignment(Pos.CENTER);
- Label welcome = new Label("Welcome to WorkTimePlanner!");
- welcome.setStyle("-fx-font-size:20px;");
- Region spacer = new Region();
- Button load = new Button("Load Project");
-
- load.setOnAction(new EventHandler(){
-
- @Override
- public void handle(ActionEvent arg0) {
- FileChooser fc = new FileChooser();
- File f = fc.showOpenDialog(primaryStage);
- try {
- p = ProjectReader.read(f);
- showMainStage();
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- }
-
- });
- Separator line = new Separator(Orientation.HORIZONTAL);
-
- HBox nameBox = new HBox();
- Label nameLabel = new Label("Project Title");
- TextField nameField = new TextField();
- HBox.setHgrow(nameField, Priority.ALWAYS);
- nameBox.getChildren().addAll(nameLabel, nameField);
-
- HBox requiredBox = new HBox();
- Label requiredLabel = new Label("Required Hours");
- TextField requiredField = new TextField();
- HBox.setHgrow(requiredField, Priority.ALWAYS);
- requiredBox.getChildren().addAll(requiredLabel, requiredField);
-
- Button create = new Button("Create Project");
-
- vb.getChildren().addAll(welcome, spacer, load, line, nameBox, requiredBox, create);
- for (Node n : vb.getChildren()) {
- VBox.setMargin(n, new Insets(10));
- }
-
- create.setOnAction(new EventHandler() {
-
- @Override
- public void handle(ActionEvent arg0) {
- try {
- p = new Project(nameField.getText(), Long.parseLong(requiredField.getText()));
- showMainStage();
- } catch (NumberFormatException e) {
- Alert alert = new Alert(AlertType.ERROR);
- alert.setTitle("Error");
- alert.setHeaderText("Creation of Project failed.");
- alert.setContentText("Required Hours needs to be a positive Number");
- alert.showAndWait();
- }
-
- }
-
- });
-
- }
-
- public void createMainScene() {
- BorderPane bp = new BorderPane();
- HBox top = new HBox();
- top.setPadding(new Insets(10, 12, 10, 12));
- top.setSpacing(10);
- Button load = new Button("Load Project");
-
- load.setOnAction(new EventHandler(){
-
- @Override
- public void handle(ActionEvent arg0) {
- FileChooser fc = new FileChooser();
- File f = fc.showOpenDialog(primaryStage);
- try {
- p = ProjectReader.read(f);
- showMainStage();
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- }
-
- });
-
- Button export = new Button("Export Project to Text");
-
- export.setOnAction(new EventHandler(){
-
- @Override
- public void handle(ActionEvent arg0) {
- FileChooser fc = new FileChooser();
- File f = fc.showSaveDialog(primaryStage);
- try {
- PrintWriter fw = new PrintWriter(f);
- String[] s = p.toString().split("\n");
- for(String t : s){
- fw.println(t);
- }
- fw.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- }
-
- });
-
- Button add = new Button("Add Activity");
-
- top.getChildren().addAll(load, export, add);
- bp.setTop(top);
-
- center = new VBox();
- Separator line = new Separator(Orientation.HORIZONTAL);
- center.setFillWidth(true);
-
- bar = new ProgressBar(0.0);
- bar.setPrefWidth(width);
- bar.setPrefHeight(50);
-
- Region spacer = new Region();
- VBox.setVgrow(spacer, Priority.ALWAYS);
- center.getChildren().addAll(line, spacer, bar);
-
- bp.setCenter(center);
- mainScene = new Scene(bp, width, height);
-
- add.setOnAction(new EventHandler() {
-
- @Override
- public void handle(ActionEvent arg0) {
- Popup createActivity = getPopUp();
- createActivity.show(primaryStage);
-
- }
-
- });
- }
-
- public Popup getPopUp() {
- VBox vb = new VBox();
- vb.setFillWidth(true);
- vb.setBackground(new Background(new BackgroundFill(Color.AZURE, null, null)));
- vb.setPadding(new Insets(10));
- Label label = new Label("Create new activity");
- HBox descriptionBox = new HBox();
- Label descriptionLabel = new Label("Description");
- TextField descriptionField = new TextField();
- HBox.setHgrow(descriptionField, Priority.ALWAYS);
- descriptionBox.getChildren().addAll(descriptionLabel, descriptionField);
-
- HBox durationBox = new HBox();
- Label durationLabel = new Label("Duration(min)");
- TextField durationField = new TextField();
- HBox.setHgrow(durationField, Priority.ALWAYS);
- durationBox.getChildren().addAll(durationLabel, durationField);
-
- HBox buttonBox = new HBox();
- Button save = new Button("Save");
- Button cancel = new Button("Cancel");
- buttonBox.getChildren().addAll(save, cancel);
-
- vb.getChildren().addAll(label, descriptionBox, durationBox, buttonBox);
-
- Popup popup = new Popup();
- popup.getContent().add(vb);
- save.setOnAction(new EventHandler() {
-
- @Override
- public void handle(ActionEvent arg0) {
- try {
- Activity a = new Activity(descriptionField.getText(), Long.parseLong(durationField.getText()));
- p.addActivity(a);
- repaintActivities();
- popup.hide();
- } catch (NumberFormatException e) {
- Alert alert = new Alert(AlertType.ERROR);
- alert.setTitle("Error");
- alert.setHeaderText("Creation of Activity failed.");
- alert.setContentText("Duration needs to be a positive Number");
- alert.showAndWait();
- }
-
- }
-
- });
-
- cancel.setOnAction(new EventHandler() {
-
- @Override
- public void handle(ActionEvent arg0) {
- popup.hide();
-
- }
-
- });
-
- return popup;
- }
-
- private void repaintActivities() {
- center.getChildren().remove(activityView);
- activityView = new VBox();
- activityView.setSpacing(10);
- activityView.setPadding(new Insets(10));
- activityView.setBackground(new Background(new BackgroundFill(Color.ANTIQUEWHITE,null,null)));
- HBox tBox = new HBox();
- Label des = new Label("Description");
- Label dur = new Label("Duration(Min)");
- Separator line = new Separator(Orientation.HORIZONTAL);
- tBox.getChildren().addAll(des,dur,line);
- activityView.getChildren().addAll(tBox, line);
- if (p != null) {
- List al = p.getActivities();
- for (Activity a : al) {
- String[] text = a.toString().split(":");
- HBox textBox = new HBox();
- Label name = new Label(text[0]);
- Label minutes = new Label(text[1]);
- textBox.setSpacing(20);
- textBox.getChildren().addAll(name,minutes);
- activityView.getChildren().addAll(textBox);
- }
- }
-
- center.getChildren().add(1, activityView);
-
- }
-
- public static void main(String[] args) {
-
- launch(args);
-
- }
-
- @Override
- public void start(Stage arg0) throws Exception {
- this.primaryStage = arg0;
- createIntroScene();
- createMainScene();
- showIntroStage();
-
- }
-
- public void showIntroStage() {
- primaryStage.setTitle("Welcome");
- primaryStage.setScene(introScene);
- primaryStage.show();
- }
-
- public void showMainStage() {
- bar.progressProperty().bind(p.percentageProperty());
- repaintActivities();
- primaryStage.setTitle("WorkTimePlanner");
- primaryStage.setScene(mainScene);
- primaryStage.show();
-
- }
-
-}
+package wtp.gui;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.time.LocalDate;
+import java.util.ArrayList;
+import java.util.List;
+
+import javafx.application.Application;
+import javafx.event.ActionEvent;
+import javafx.event.EventHandler;
+import javafx.geometry.Insets;
+import javafx.geometry.Orientation;
+import javafx.geometry.Pos;
+import javafx.scene.Node;
+import javafx.scene.Scene;
+import javafx.scene.control.*;
+import javafx.scene.control.Alert.AlertType;
+import javafx.scene.layout.Background;
+import javafx.scene.layout.BackgroundFill;
+import javafx.scene.layout.BorderPane;
+import javafx.scene.layout.HBox;
+import javafx.scene.layout.Priority;
+import javafx.scene.layout.Region;
+import javafx.scene.layout.VBox;
+import javafx.scene.paint.Color;
+import javafx.stage.FileChooser;
+import javafx.stage.Popup;
+import javafx.stage.Stage;
+import wtp.io.PDFWriter;
+import wtp.io.ProjectReader;
+import wtp.model.Activity;
+import wtp.model.Project;
+
+public class Gui extends Application {
+
+ private double height = 600.0;
+ private double width = 800.0;
+
+ private Stage primaryStage;
+
+ private Scene introScene;
+ private Scene mainScene;
+ private ProgressBar bar;
+ private VBox center;
+ private VBox activityView;
+ private Project p;
+
+ public void createIntroScene() {
+ VBox vb = new VBox();
+ introScene = new Scene(vb, width / 2, height / 2);
+ vb.setAlignment(Pos.CENTER);
+ Label welcome = new Label("Welcome to WorkTimePlanner!");
+ welcome.setStyle("-fx-font-size:20px;");
+ Region spacer = new Region();
+ Button load = new Button("Load Project");
+
+ load.setOnAction(new EventHandler(){
+
+ @Override
+ public void handle(ActionEvent arg0) {
+ FileChooser fc = new FileChooser();
+ File f = fc.showOpenDialog(primaryStage);
+ try {
+ p = ProjectReader.read(f);
+ showMainStage();
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+
+ });
+ Separator line = new Separator(Orientation.HORIZONTAL);
+
+ HBox nameBox = new HBox();
+ Label nameLabel = new Label("Project Title");
+ TextField nameField = new TextField();
+ HBox.setHgrow(nameField, Priority.ALWAYS);
+ nameBox.getChildren().addAll(nameLabel, nameField);
+
+ HBox requiredBox = new HBox();
+ Label requiredLabel = new Label("Required Hours");
+ TextField requiredField = new TextField();
+ HBox.setHgrow(requiredField, Priority.ALWAYS);
+ requiredBox.getChildren().addAll(requiredLabel, requiredField);
+
+ Button create = new Button("Create Project");
+
+ vb.getChildren().addAll(welcome, spacer, load, line, nameBox, requiredBox, create);
+ for (Node n : vb.getChildren()) {
+ VBox.setMargin(n, new Insets(10));
+ }
+
+ create.setOnAction(new EventHandler() {
+
+ @Override
+ public void handle(ActionEvent arg0) {
+ try {
+ p = new Project(nameField.getText(), Long.parseLong(requiredField.getText()));
+ showMainStage();
+ } catch (NumberFormatException e) {
+ Alert alert = new Alert(AlertType.ERROR);
+ alert.setTitle("Error");
+ alert.setHeaderText("Creation of Project failed.");
+ alert.setContentText("Required Hours needs to be a positive Number");
+ alert.showAndWait();
+ }
+
+ }
+
+ });
+
+ }
+
+ public void createMainScene() {
+ BorderPane bp = new BorderPane();
+ HBox top = new HBox();
+ top.setPadding(new Insets(10, 12, 10, 12));
+ top.setSpacing(10);
+ Button load = new Button("Load Project");
+
+ load.setOnAction(new EventHandler(){
+
+ @Override
+ public void handle(ActionEvent arg0) {
+ FileChooser fc = new FileChooser();
+ File f = fc.showOpenDialog(primaryStage);
+ try {
+ p = ProjectReader.read(f);
+ showMainStage();
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+
+ });
+
+ Button export = new Button("Save Project to Text");
+
+ export.setOnAction(new EventHandler(){
+
+ @Override
+ public void handle(ActionEvent arg0) {
+ FileChooser fc = new FileChooser();
+ File f = fc.showSaveDialog(primaryStage);
+ try {
+ PrintWriter fw = new PrintWriter(f);
+ String[] s = p.toString().split("\n");
+ for(String t : s){
+ fw.println(t);
+ }
+ fw.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+
+ });
+
+ Button pdf = new Button("Export to PDF File");
+ pdf.setOnAction(new EventHandler() {
+ @Override
+ public void handle(ActionEvent event){
+ FileChooser fc = new FileChooser();
+ fc.getExtensionFilters().add(new FileChooser.ExtensionFilter("PDF File","*.pdf"));
+ try {
+ PDFWriter.write(p, fc.showSaveDialog(primaryStage));
+ } catch (IOException e) {
+ Alert alert = new Alert(AlertType.ERROR);
+ alert.setTitle("Error");
+ alert.setHeaderText("Error writing to PDF File");
+ alert.showAndWait();
+ }
+ }
+ });
+
+ Button add = new Button("Add Activity");
+
+ top.getChildren().addAll(load, export, pdf, add);
+ bp.setTop(top);
+
+ center = new VBox();
+ Separator line = new Separator(Orientation.HORIZONTAL);
+ center.setFillWidth(true);
+
+ bar = new ProgressBar(0.0);
+ bar.setPrefWidth(width);
+ bar.setPrefHeight(50);
+
+ Region spacer = new Region();
+ VBox.setVgrow(spacer, Priority.ALWAYS);
+ center.getChildren().addAll(line, spacer, bar);
+
+ bp.setCenter(center);
+ mainScene = new Scene(bp, width, height);
+
+ add.setOnAction(new EventHandler() {
+
+ @Override
+ public void handle(ActionEvent arg0) {
+ Popup createActivity = getPopUp();
+ createActivity.show(primaryStage);
+
+ }
+
+ });
+ }
+
+ public Popup getPopUp() {
+ VBox vb = new VBox();
+ vb.setFillWidth(true);
+ vb.setBackground(new Background(new BackgroundFill(Color.AZURE, null, null)));
+ vb.setPadding(new Insets(10));
+ Label label = new Label("Create new activity");
+ HBox descriptionBox = new HBox();
+ Label descriptionLabel = new Label("Description");
+ TextField descriptionField = new TextField();
+ HBox.setHgrow(descriptionField, Priority.ALWAYS);
+ descriptionBox.getChildren().addAll(descriptionLabel, descriptionField);
+
+ HBox durationBox = new HBox();
+ Label durationLabel = new Label("Duration(min)");
+ TextField durationField = new TextField();
+ HBox.setHgrow(durationField, Priority.ALWAYS);
+ durationBox.getChildren().addAll(durationLabel, durationField);
+
+ HBox dateBox = new HBox();
+ Label dateLabel = new Label("Date");
+ DatePicker datePicker = new DatePicker(LocalDate.now());
+ dateBox.getChildren().addAll(dateLabel, datePicker);
+
+ HBox buttonBox = new HBox();
+ Button save = new Button("Save");
+ Button cancel = new Button("Cancel");
+ buttonBox.getChildren().addAll(save, cancel);
+
+ vb.getChildren().addAll(label, descriptionBox, dateBox, durationBox, buttonBox);
+
+ Popup popup = new Popup();
+ popup.getContent().add(vb);
+ save.setOnAction(new EventHandler() {
+
+ @Override
+ public void handle(ActionEvent arg0) {
+ try {
+ Activity a = new Activity(descriptionField.getText(), Long.parseLong(durationField.getText()),datePicker.getValue());
+ p.addActivity(a);
+ repaintActivities();
+ popup.hide();
+ } catch (NumberFormatException e) {
+ Alert alert = new Alert(AlertType.ERROR);
+ alert.setTitle("Error");
+ alert.setHeaderText("Creation of Activity failed.");
+ alert.setContentText("Duration needs to be a positive Number");
+ alert.showAndWait();
+ }
+
+ }
+
+ });
+
+ cancel.setOnAction(new EventHandler() {
+
+ @Override
+ public void handle(ActionEvent arg0) {
+ popup.hide();
+
+ }
+
+ });
+
+ return popup;
+ }
+
+ private void repaintActivities() {
+ center.getChildren().remove(activityView);
+ activityView = new VBox();
+ activityView.setSpacing(10);
+ activityView.setPadding(new Insets(10));
+ activityView.setBackground(new Background(new BackgroundFill(Color.ANTIQUEWHITE,null,null)));
+ HBox tBox = new HBox();
+ Label date = new Label ("Date");
+ Label des = new Label("Description");
+ Label dur = new Label("Duration(Min)");
+ Separator line = new Separator(Orientation.HORIZONTAL);
+ tBox.getChildren().addAll(date,des,dur);
+ activityView.getChildren().addAll(tBox, line);
+ if (p != null) {
+ List al = new ArrayList<>(p.getActivities());
+ al.sort((o1, o2) -> o1.getDate().compareTo(o2.getDate()));
+ for (Activity a : al) {
+ HBox textBox = new HBox();
+ Label day = new Label(a.getDate().toString());
+ Label name = new Label(a.getDescription());
+ Label minutes = new Label(a.getDurationInMinutes()+"");
+ textBox.setSpacing(20);
+ textBox.getChildren().addAll(day,name,minutes);
+ activityView.getChildren().addAll(textBox);
+ }
+ }
+
+ center.getChildren().add(1, activityView);
+
+ }
+
+ public static void main(String[] args) {
+
+ launch(args);
+
+ }
+
+ @Override
+ public void start(Stage arg0) throws Exception {
+ this.primaryStage = arg0;
+ createIntroScene();
+ createMainScene();
+ showIntroStage();
+
+ }
+
+ public void showIntroStage() {
+ primaryStage.setTitle("Welcome");
+ primaryStage.setScene(introScene);
+ primaryStage.show();
+ }
+
+ public void showMainStage() {
+ bar.progressProperty().bind(p.percentageProperty());
+ repaintActivities();
+ primaryStage.setTitle("WorkTimePlanner");
+ primaryStage.setScene(mainScene);
+ primaryStage.show();
+
+ }
+
+}
diff --git a/src/wtp/io/PDFWriter.java b/src/wtp/io/PDFWriter.java
new file mode 100644
index 0000000..1e366fd
--- /dev/null
+++ b/src/wtp/io/PDFWriter.java
@@ -0,0 +1,118 @@
+package wtp.io;
+
+
+import org.apache.pdfbox.exceptions.COSVisitorException;
+import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.pdmodel.PDPage;
+import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
+import org.apache.pdfbox.pdmodel.font.PDFont;
+import org.apache.pdfbox.pdmodel.font.PDType1Font;
+import wtp.model.Activity;
+import wtp.model.Project;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Created by David on 29.09.2015.
+ */
+public class PDFWriter {
+
+ static final float pageMargin = PDPage.PAGE_SIZE_A4.getUpperRightX()/10;
+
+ static final float lowerLeftX = PDPage.PAGE_SIZE_A4.getLowerLeftX()+pageMargin;
+ static final float upperRightX = PDPage.PAGE_SIZE_A4.getUpperRightX()-pageMargin;
+ static final float lowerLeftY = PDPage.PAGE_SIZE_A4.getLowerLeftY()+pageMargin;
+ static final float upperRightY = PDPage.PAGE_SIZE_A4.getUpperRightY()-pageMargin;
+
+ static final float width = upperRightX-lowerLeftX;
+ static final float heigth = upperRightY - lowerLeftY;
+
+
+ static final PDFont font = PDType1Font.HELVETICA;
+ static final float textSize = 12;
+ static final float realTextSize=9;
+ static final float textMargin=4;
+ static final float rowHeight =realTextSize+2*textMargin;
+
+ public static void write(Project p, File file) throws IOException {
+ PDDocument doc = new PDDocument();
+ PDPage page = addPage(doc);
+
+ List activityList = new ArrayList(p.getActivities());
+ activityList.sort((o1, o2) -> o1.getDate().compareTo(o2.getDate()));
+
+ float borderTop = upperRightY;
+ for(Activity activity:activityList){
+ borderTop -=rowHeight;
+ if (borderTop < (lowerLeftY+rowHeight)){//neue Seite
+ drawVerticalLines(page, doc,borderTop);
+ page = addPage(doc);
+ borderTop = upperRightY - rowHeight;
+ }
+ drawRow(page,doc,activity,borderTop);
+ }
+ drawVerticalLines(page,doc,borderTop-rowHeight);
+
+ try {
+ doc.save(file);
+ doc.close();
+ } catch (COSVisitorException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private static void drawHeader(PDPage page, PDDocument document) throws IOException {
+ PDPageContentStream cs = new PDPageContentStream(document,page);
+ cs.setNonStrokingColor(0,0,0);
+ cs.setFont(font, textSize);
+
+ cs.beginText();
+ cs.moveTextPositionByAmount(lowerLeftX + textMargin, upperRightY - rowHeight +textMargin);
+ cs.drawString("Date");
+ cs.moveTextPositionByAmount(width / 3, 0);
+ cs.drawString("Description");
+ cs.moveTextPositionByAmount(width/3,0);
+ cs.drawString("Amount (min)");
+ cs.endText();
+ cs.close();
+ }
+
+ private static PDPage addPage(PDDocument document) throws IOException {
+ PDPage page = new PDPage();
+ document.addPage(page);
+ drawHeader(page,document);
+ return page;
+ }
+
+ private static void drawRow(PDPage page,PDDocument document, Activity activity, float borderTop) throws IOException {
+ PDPageContentStream cs = new PDPageContentStream(document,page, true,true);
+ cs.setNonStrokingColor(0,0,0);
+ cs.setFont(font, textSize);
+
+ cs.beginText();
+ cs.moveTextPositionByAmount(lowerLeftX+textMargin, borderTop - rowHeight + textMargin);
+ cs.drawString(activity.getDate().toString());
+ cs.moveTextPositionByAmount(width / 3, 0);
+ cs.drawString(activity.getDescription());
+ cs.moveTextPositionByAmount(width / 3, 0);
+ cs.drawString(activity.getDurationInMinutes()+"");
+ cs.endText();
+ cs.drawLine(lowerLeftX,borderTop,upperRightX,borderTop);
+ cs.close();
+
+ }
+
+ private static void drawVerticalLines(PDPage page, PDDocument document, float lowerEnd) throws IOException {
+ PDPageContentStream cs = new PDPageContentStream(document, page, true, true);
+ cs.setNonStrokingColor(0,0,0);
+ cs.setFont(font, textSize);
+
+ cs.drawLine(lowerLeftX+width/3,lowerEnd,lowerLeftX+width/3,upperRightY);
+ cs.drawLine(lowerLeftX+width*2/3,lowerEnd,lowerLeftX+width*2/3,upperRightY);
+ cs.close();
+ }
+
+}
diff --git a/src/wtp/io/ProjectReader.java b/src/wtp/io/ProjectReader.java
index b54fdc1..19b75a4 100644
--- a/src/wtp/io/ProjectReader.java
+++ b/src/wtp/io/ProjectReader.java
@@ -1,64 +1,65 @@
-package wtp.io;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.LinkedList;
-import java.util.List;
-
-import wtp.model.Activity;
-import wtp.model.Project;
-
-public class ProjectReader {
-
- public static Project read(File f){
- Project p = null;
- try {
- BufferedReader br = new BufferedReader(new FileReader(f));
- String s;
- int state = 0;
- String name = null;
- long required = 0;
- List al = new LinkedList();
- while((s = br.readLine())!=null){
- switch(state){
- case 0:
- name = s;
- state++;
- break;
- case 1:
- try {
- required = Long.parseLong(s.split(":")[1]);
- state++;
- } catch (Exception e) {
- e.printStackTrace();
- state = 3;
- }
- break;
- case 2:
- try {
- String de = s.split(":")[0];
- long d = Long.parseLong(s.split(":")[1]);
- al.add(new Activity(de,d));
- state++;
- } catch (Exception e) {
- e.printStackTrace();
- state = 3;
- }
- }
- }
- p = new Project(name, required);
- for(Activity a : al){
- p.addActivity(a);
- }
- br.close();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return p;
- }
-}
+package wtp.io;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.time.LocalDate;
+import java.util.LinkedList;
+import java.util.List;
+
+import wtp.model.Activity;
+import wtp.model.Project;
+
+public class ProjectReader {
+
+ public static Project read(File f){
+ Project p = null;
+ try {
+ BufferedReader br = new BufferedReader(new FileReader(f));
+ String s;
+ int state = 0;
+ String name = null;
+ long required = 0;
+ List al = new LinkedList();
+ while((s = br.readLine())!=null){
+ switch(state){
+ case 0:
+ name = s;
+ state++;
+ break;
+ case 1:
+ try {
+ required = Long.parseLong(s.split(":")[1]);
+ state++;
+ } catch (Exception e) {
+ e.printStackTrace();
+ state = 3;
+ }
+ break;
+ case 2:
+ try {
+ LocalDate date = LocalDate.parse(s.split(":")[0]);
+ String de = s.split(":")[1];
+ long d = Long.parseLong(s.split(":")[2]);
+ al.add(new Activity(de,d,date));
+ } catch (Exception e) {
+ e.printStackTrace();
+ state = 3;
+ }
+ }
+ }
+ p = new Project(name, required);
+ for(Activity a : al){
+ p.addActivity(a);
+ }
+ br.close();
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return p;
+ }
+}
diff --git a/src/wtp/model/Activity.java b/src/wtp/model/Activity.java
index 99955c6..0ede32d 100644
--- a/src/wtp/model/Activity.java
+++ b/src/wtp/model/Activity.java
@@ -1,30 +1,40 @@
-package wtp.model;
-
-import java.time.Duration;
-
-import javafx.beans.property.ObjectProperty;
-import javafx.beans.property.SimpleObjectProperty;
-
-public class Activity {
-
- private String description;
- private ObjectProperty duration;
-
- public Activity(String description, long minutes){
- this.description = description;
- duration = new SimpleObjectProperty(this,"duration");
- duration.set(Duration.ofMinutes(minutes));
- }
-
- public long getDurationInMinutes(){
- return duration.get().toMinutes();
- }
-
- public ObjectProperty durationProperty(){
- return duration;
- }
-
- public String toString(){
- return this.description+":"+duration.get().toMinutes();
- }
-}
+package wtp.model;
+
+import java.time.Duration;
+import java.time.LocalDate;
+
+import javafx.beans.property.ObjectProperty;
+import javafx.beans.property.SimpleObjectProperty;
+
+public class Activity{
+
+ private String description;
+ private ObjectProperty duration;
+ private LocalDate date;
+
+ public Activity(String description, long minutes, LocalDate date){
+ this.description = description;
+ duration = new SimpleObjectProperty(this,"duration");
+ duration.set(Duration.ofMinutes(minutes));
+ this.date = date;
+ }
+
+ public long getDurationInMinutes(){
+ return duration.get().toMinutes();
+ }
+
+ public ObjectProperty durationProperty(){
+ return duration;
+ }
+
+ public String toString(){
+ return this.date.toString()+":"+this.description+":"+duration.get().toMinutes();
+ }
+ public LocalDate getDate(){
+ return this.date;
+ }
+
+ public String getDescription(){
+ return description;
+ }
+}
diff --git a/src/wtp/model/Project.java b/src/wtp/model/Project.java
index 629884c..4df4d88 100644
--- a/src/wtp/model/Project.java
+++ b/src/wtp/model/Project.java
@@ -1,54 +1,55 @@
-package wtp.model;
-
-import java.time.Duration;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import javafx.beans.property.DoubleProperty;
-import javafx.beans.property.ObjectProperty;
-import javafx.beans.property.SimpleDoubleProperty;
-import javafx.beans.property.SimpleObjectProperty;
-
-public class Project {
- private String name;
- private ObjectProperty required;
- private DoubleProperty percentageDone;
- private List activities;
-
-
- public Project(String name, long hours){
- this.name = name;
- this.percentageDone = new SimpleDoubleProperty();
- this.percentageDone.set(0.0);
- this.required = new SimpleObjectProperty();
- this.required.set(Duration.ofHours(hours));
- this.activities = new ArrayList();
- }
-
- public List getActivities(){
- return Collections.unmodifiableList(activities);
- }
-
- public void addActivity(Activity a){
- double d = percentageDone.get() * required.get().toMinutes()+a.getDurationInMinutes();
- percentageDone.set(d/required.get().toMinutes());
- activities.add(a);
- }
-
- public ObjectProperty requiredProperty(){
- return required;
- }
-
- public DoubleProperty percentageProperty(){
- return percentageDone;
- }
-
- public String toString(){
- String s = this.name + "\nRequired(hrs):"+required.get().toHours();
- for(Activity a : activities){
- s+="\n"+a.toString();
- }
- return s;
- }
-}
+package wtp.model;
+
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import javafx.beans.property.DoubleProperty;
+import javafx.beans.property.ObjectProperty;
+import javafx.beans.property.SimpleDoubleProperty;
+import javafx.beans.property.SimpleObjectProperty;
+
+public class Project {
+ private String name;
+ private ObjectProperty required;
+ private DoubleProperty percentageDone;
+ private List activities;
+
+
+ public Project(String name, long hours){
+ this.name = name;
+ this.percentageDone = new SimpleDoubleProperty();
+ this.percentageDone.set(0.0);
+ this.required = new SimpleObjectProperty();
+ this.required.set(Duration.ofHours(hours));
+ this.activities = new ArrayList();
+ }
+
+ public List getActivities(){
+ return Collections.unmodifiableList(activities);
+ }
+
+
+ public void addActivity(Activity a){
+ double d = percentageDone.get() * required.get().toMinutes()+a.getDurationInMinutes();
+ percentageDone.set(d/required.get().toMinutes());
+ activities.add(a);
+ }
+
+ public ObjectProperty requiredProperty(){
+ return required;
+ }
+
+ public DoubleProperty percentageProperty(){
+ return percentageDone;
+ }
+
+ public String toString(){
+ String s = this.name + "\nRequired(hrs):"+required.get().toHours();
+ for(Activity a : activities){
+ s+="\n"+a.toString();
+ }
+ return s;
+ }
+}