From ecee676e2e35876e7213d1b9630e74a57dbdf489 Mon Sep 17 00:00:00 2001 From: Thomas Battermann Date: Sun, 21 Jun 2015 10:38:59 +0200 Subject: [PATCH] Highlight item past due, with prio and item done --- README.md | 3 +- .../dhbw/todolist/Controller.java | 24 ++++++ src/de/t_battermann/dhbw/todolist/Todo.java | 13 +++ src/de/t_battermann/dhbw/todolist/star.png | Bin 0 -> 654 bytes src/de/t_battermann/dhbw/todolist/star.svg | 76 ++++++++++++++++++ 5 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 src/de/t_battermann/dhbw/todolist/star.png create mode 100644 src/de/t_battermann/dhbw/todolist/star.svg diff --git a/README.md b/README.md index 52e760a..aebe1c6 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,7 @@ A project for class "programming 2" at Baden-Wuerttemberg Cooperative State Univ ## Todo -- Highlight items with priority -- Highlight items past due (and TodoList!) +- Highlight TodoLists with items past due - filter items (include/exclude done items) ## Dependencies diff --git a/src/de/t_battermann/dhbw/todolist/Controller.java b/src/de/t_battermann/dhbw/todolist/Controller.java index 5eda88e..db33cf7 100644 --- a/src/de/t_battermann/dhbw/todolist/Controller.java +++ b/src/de/t_battermann/dhbw/todolist/Controller.java @@ -8,6 +8,7 @@ import javafx.fxml.FXMLLoader; import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.control.*; +import javafx.scene.paint.Paint; import javafx.stage.Stage; import java.io.File; @@ -32,6 +33,26 @@ public class Controller { showLoadFileDialog(); } + static class TodoListCell extends ListCell { + @Override + public void updateItem(Todo item, boolean empty) { + super.updateItem(item, empty); + if ( !empty && item != null ) { + if ( item.isPrio() && !item.isDone() ) { + this.setStyle("-fx-graphic:url(/de/t_battermann/dhbw/todolist/star.png);"); + }else{ + this.setStyle("-fx-graphic:null;"); + } + this.setTextFill(Paint.valueOf(item.isDone() ? "#999999" : (item.pastDue() ? "#aa0000" :"#000000") )); + this.setText(item.getTitle() + (item.getDueDate() != null ? " (due: "+item.getDateTime()+")" : "")); + }else{ + this.setStyle("-fx-graphic:null;"); + this.setTextFill(Paint.valueOf("#000000")); + this.setText(""); + } + } + } + /** * Initialize new empty */ @@ -264,6 +285,7 @@ public class Controller { lv.getSelectionModel().selectedIndexProperty().addListener(event -> { this.updateSelectedTodo(); }); + lv.setCellFactory(param -> new TodoListCell()); }else{ ErrorPrinter.printWarning("showMainWindow > Couldn’t find element '#todos'"); } @@ -720,6 +742,7 @@ public class Controller { } this.currentTodo.setDone(!this.currentTodo.isDone()); ((ToggleButton) n).setSelected(this.currentTodo.isDone()); + this.notifyList(todos,currentTodo); } private void toggleStar() { @@ -732,6 +755,7 @@ public class Controller { } this.currentTodo.setPrio(!this.currentTodo.isPrio()); ((ToggleButton) n).setSelected(this.currentTodo.isPrio()); + this.notifyList(todos,currentTodo); } private void newTodoItem() { diff --git a/src/de/t_battermann/dhbw/todolist/Todo.java b/src/de/t_battermann/dhbw/todolist/Todo.java index 2b7ce9a..5bed469 100644 --- a/src/de/t_battermann/dhbw/todolist/Todo.java +++ b/src/de/t_battermann/dhbw/todolist/Todo.java @@ -160,6 +160,12 @@ public class Todo { return this.getDueDate() != null ? format.format(this.getDueDate().getTime()) : "00:00"; } + public String getDateTime() { + SimpleDateFormat format = new SimpleDateFormat(); + format.applyPattern("yyyy-MM-dd HH:mm"); + return this.getDueDate() != null ? format.format(this.getDueDate().getTime()) : "0000-00-00 00:00"; + } + public boolean validateTime(String time) { return time.matches("([0-9]{1,2}:[0-9]{1,2}(:[0-9]{1,2})?|[0-9]{1,4})"); } @@ -184,6 +190,13 @@ public class Todo { this.dueDate = nd; } + public boolean pastDue() { + if ( this.dueDate == null ) + return false; + Calendar today = new GregorianCalendar(); + return today.after(this.dueDate); + } + @Override public String toString() { return this.getTitle(); diff --git a/src/de/t_battermann/dhbw/todolist/star.png b/src/de/t_battermann/dhbw/todolist/star.png new file mode 100644 index 0000000000000000000000000000000000000000..65c0a065569ecf60458be5fa00c99682cb3cc748 GIT binary patch literal 654 zcmV;90&)F`P)J94x*IE@EJSZ@>B#6ouQpy;OE~E)Odd5VlQOQMmJ`8y-fZ zRCBrDu#F8wBtlhDcyNBx$vig<>dVXiu$2`=M+Y@k<>^JgEGY`FLm}L1wLR?c5TR*! zvdk+#>j~Fo-EpWHM*FO$35f)!p2vC+FAt_t{`N|xnp$6AILy^liqP-9>%zhUWV7IT zE#2fKMpqXjzE+9Hd6&;O-zuL+jE!+3%QPg3#>50CTU*V$%}s=5k@E${Vie0|#Oy4` zp%AB<#v(8RTu~G + + + + + + + + + image/svg+xml + + + + + + + + +