diff --git a/src/de/t_battermann/dhbw/todolist/Controller.java b/src/de/t_battermann/dhbw/todolist/Controller.java index d6e4193..0f34746 100644 --- a/src/de/t_battermann/dhbw/todolist/Controller.java +++ b/src/de/t_battermann/dhbw/todolist/Controller.java @@ -12,6 +12,7 @@ import javafx.stage.Stage; import java.io.File; import java.io.IOException; +import java.time.LocalDate; import java.time.LocalDateTime; import java.time.ZoneId; import java.util.*; @@ -257,6 +258,16 @@ public class Controller { n.setOnMouseReleased(event -> Platform.exit()); } this.primaryStage.setOnCloseRequest(event -> Platform.exit()); + n = primaryStage.getScene().lookup("#todoDetailSave"); + if ( n != null && n instanceof Button) { + n.setOnMouseClicked(event -> this.saveTodoEntry()); + n.setOnKeyPressed(event -> this.saveTodoEntry()); + } + n = primaryStage.getScene().lookup("#todoDetailDueDate"); + if (n != null && n instanceof CheckBox) { + ((CheckBox) n).setOnAction(event -> this.detailUpdateDueDatePicker()); + } + // TODO } private void updateSelectedTodoList() { @@ -309,12 +320,22 @@ public class Controller { return; if(dueDate) { ((DatePicker) n).setValue( LocalDateTime.ofInstant(this.currentTodo.getDueDate().getTime().toInstant(), ZoneId.systemDefault()).toLocalDate() ); + n.setDisable(false); + }else{ + ((DatePicker) n).setValue(null); + n.setDisable(true); } // time n = primaryStage.getScene().lookup("#todoDetailTime"); if ( n == null || !(n instanceof TextField)) return; - ((TextField) n).setText(this.currentTodo.getTime()); + if ( dueDate ) { + ((TextField) n).setText(this.currentTodo.getTime() ); + n.setDisable(false); + }else{ + n.setDisable(true); + ((TextField) n).setText("00:00"); + } } private void updateStatusLine(String text) { @@ -327,7 +348,6 @@ public class Controller { } private void showSaveAs() { - // TODO Stage save = new Stage(); save.setScene(scenes.get("saveAs")); save.setTitle("Save as ..."); @@ -349,4 +369,76 @@ public class Controller { } }); } + + private void saveTodoEntry() { + Node lv = primaryStage.getScene().lookup("#todos"); + if ( lv == null || !(lv instanceof ListView)) { + this.updateStatusLine("Could’t get todo-ListView!"); + return; + } + // title + Node n = primaryStage.getScene().lookup("#todoDetailTitle"); + if ( n == null || !(n instanceof TextField)) { + this.updateStatusLine("Couldn’t load data from todoDetailTitle"); + return; + } + this.currentTodo.setTitle(((TextField) n).getText()); + // description + n = primaryStage.getScene().lookup("#todoDetailDescription"); + if ( n == null || !(n instanceof TextArea)) { + this.updateStatusLine("Couldn’t load data from todoDetailDescription"); + return; + } + this.currentTodo.setComment(((TextArea) n).getText()); + // date + n = primaryStage.getScene().lookup("#todoDetailDueDate"); + if ( n == null || !(n instanceof CheckBox)) { + this.updateStatusLine("Couldn’t load data from todoDetailDueDate"); + return; + } + if ( !((CheckBox) n).isSelected() ) { + this.currentTodo.setDueDate(null); + this.updateStatusLine("Item updated!"); + this.todos.add(this.currentTodo); + return; + } + n = primaryStage.getScene().lookup("#todoDetailDate"); + if ( n == null || !(n instanceof DatePicker)) { + this.updateStatusLine("Couldn’t load data from todoDetailDate"); + return; + } + LocalDate dd = ((DatePicker) n).getValue(); + // time + n = primaryStage.getScene().lookup("#todoDetailTime"); + if ( n == null || !(n instanceof TextField)) { + this.updateStatusLine("Couldn’t load data from todoDetailDate"); + return; + } + if ( !this.currentTodo.validateTime(((TextField) n).getText())) { + this.updateStatusLine("Invalid time format, use HH:MM!"); + return; + } + this.currentTodo.setDueDate(dd, ((TextField) n).getText()); + this.updateStatusLine("Item updated!"); + } + private void detailUpdateDueDatePicker() { + Node n = primaryStage.getScene().lookup("#todoDetailDueDate"); + if ( n == null || !(n instanceof CheckBox)) { + this.updateStatusLine("Couldn’t load data from todoDetailDueDate"); + return; + } + boolean enable = ((CheckBox) n).isSelected(); + n = primaryStage.getScene().lookup("#todoDetailDate"); + if ( n == null || !(n instanceof DatePicker)) { + this.updateStatusLine("Couldn’t load data from todoDetailDate"); + return; + } + n.setDisable(!enable); + n = primaryStage.getScene().lookup("#todoDetailTime"); + if ( n == null || !(n instanceof TextField)) { + this.updateStatusLine("Couldn’t load data from todoDetailTime"); + return; + } + n.setDisable(!enable); + } } diff --git a/src/de/t_battermann/dhbw/todolist/Todo.java b/src/de/t_battermann/dhbw/todolist/Todo.java index 6a6fdf5..295825c 100644 --- a/src/de/t_battermann/dhbw/todolist/Todo.java +++ b/src/de/t_battermann/dhbw/todolist/Todo.java @@ -1,7 +1,9 @@ package de.t_battermann.dhbw.todolist; import java.text.SimpleDateFormat; +import java.time.LocalDate; import java.util.Calendar; +import java.util.GregorianCalendar; import java.util.UUID; /** @@ -154,10 +156,35 @@ public class Todo { public String getTime() { SimpleDateFormat format = new SimpleDateFormat(); - format.applyPattern("yyyyMMdd'T'HH:mm:ssZ"); + format.applyPattern("HH:mm"); return this.getDueDate() != null ? format.format(this.getDueDate().getTime()) : "00:00"; } + public boolean validateTime(String time) { + //return time.matches("((?\\d{1,2}):(?\\d{1,2})(:\\d{1,2})?|(?

\\d{2})(?\\d{0,2})|(?

)\\d)"); + return time.matches("([0-9]{1,2}:[0-9]{1,2}(:[0-9]{1,2})?|[0-9]{1,4})"); + } + + public void setDueDate(LocalDate date, String time) { + Calendar nd = new GregorianCalendar(); + int hour = 0; + int minute = 0; + if ( time.matches("\\d{1,2}:\\d{1,2}(:\\d{1,2})?") ) { + String t[] = time.split(":", 3); + hour = Integer.parseInt(t[0]); + minute = Integer.parseInt(t[1]); + }else if( time.matches("\\d{1,4}") ) { + if ( time.length() > 2 ) { + hour = Integer.parseInt(time.substring(0, 2)); + minute = Integer.parseInt(time.substring(2, 2)); + }else{ + hour = Integer.parseInt( time ); + } + } + nd.set(date.getYear(), date.getMonthValue(), date.getDayOfMonth(), hour<24?hour:0, minute<60?minute:0); + this.dueDate = nd; + } + @Override public String toString() { return this.getTitle(); diff --git a/src/de/t_battermann/dhbw/todolist/User.java b/src/de/t_battermann/dhbw/todolist/User.java index ebdd5af..5012d69 100644 --- a/src/de/t_battermann/dhbw/todolist/User.java +++ b/src/de/t_battermann/dhbw/todolist/User.java @@ -47,8 +47,6 @@ public class User implements Serializable { this.password = hashedPassword; this.email = email; this.todoLists = new LinkedList<>(); - TodoList tmp = new TodoList("Default", false); - todoLists.add(tmp); } /**