Skip to content

Commit 935b9e2

Browse files
committed
App theme changed, code is optimized and bugs are removed
Signed-off-by: cankush625 <[email protected]>
1 parent 3d899b9 commit 935b9e2

File tree

10 files changed

+87
-24
lines changed

10 files changed

+87
-24
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

TodoList.iml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<content url="file://$MODULE_DIR$">
66
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
77
</content>
8-
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
8+
<orderEntry type="inheritedJdk" />
99
<orderEntry type="sourceFolder" forTests="false" />
1010
<orderEntry type="module-library" exported="">
1111
<library>

TodoListItems.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ Flutter Interact Google's Flutter Interact conference 11-12-2019
88
Google Cloud Community Day, Mumbai Event organized by GDG Mumbai. 10-12-2019
99
Learn Dart Start learning dart programming language 11-12-2019
1010
Flutter Interact San Francisco The GDG San Francisco organising the Flutter Interact Viewing Pary from 9:30 AM PST onwards. 17-12-2019
11+
Todays Todo Todays Todo 22-12-2019
Binary file not shown.
Binary file not shown.

out/production/TodoList/com/cankush/todolist/mainwindow.fxml

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,21 @@
44
<?import javafx.scene.layout.*?>
55
<?import javafx.scene.text.Font?>
66
<BorderPane fx:id="mainBorderPane" fx:controller="com.cankush.todolist.Controller"
7-
xmlns:fx="http://javafx.com/fxml">
7+
xmlns:fx="http://javafx.com/fxml"
8+
stylesheets="@style.css">
89
<!-- Adding a Menu bar for our application-->
910
<top>
1011
<VBox>
1112
<MenuBar>
1213
<Menu text="File">
13-
<items>
14-
<MenuItem text="New..." onAction="#showNewItemDialog"/>
15-
<!-- <SeparatorMenuItem/> &lt;!&ndash; Adding the separating line between the two menu items&ndash;&gt;-->
16-
<MenuItem text="Exit"/>
17-
</items>
14+
<MenuItem text="New..." onAction="#showNewItemDialog"/>
15+
<!-- <SeparatorMenuItem/> &lt;!&ndash; Adding the separating line between the two menu items&ndash;&gt;-->
16+
<MenuItem text="Exit" onAction="#handleExit"/>
1817
</Menu>
1918
</MenuBar>
2019
<ToolBar>
2120
<HBox>
22-
<Button onAction="#showNewItemDialog">
21+
<Button onAction="#showNewItemDialog" id="newItemButton">
2322
<!-- tooltip displays the description of the item when hovered on it-->
2423
<tooltip>
2524
<Tooltip text="Add new Todo Item"/>
@@ -30,14 +29,11 @@
3029
</ImageView>
3130
</graphic>
3231
</Button>
33-
<<<<<<< HEAD
34-
<ToggleButton fx:id="filterToggleButton" text="Today's Items" onAction="#handleFilterButton">
32+
<ToggleButton fx:id="filterToggleButton" id="filterButton" text="Today's Items" onAction="#handleFilterButton">
3533
<tooltip>
3634
<Tooltip text="Button Down: Show today's items only. Button Up: Show all items"/>
3735
</tooltip>
3836
</ToggleButton>
39-
=======
40-
>>>>>>> 5e6314cb8c48209cb76b93fa05f19042456f41c7
4137
</HBox>
4238
</ToolBar>
4339
</VBox>
@@ -53,7 +49,7 @@
5349
<!-- We have to use all the remaining space if the window. So, we are adding the center tag-->
5450
<center>
5551
<VBox style="-fx-background-color: white">
56-
<TextArea fx:id="itemDetailsTextArea" VBox.vgrow="ALWAYS" wrapText="true"/> <!-- VBox.vgrow tells the VBox to always give room as much as
52+
<TextArea fx:id="itemDetailsTextArea" VBox.vgrow="ALWAYS" wrapText="true" editable="false"/> <!-- VBox.vgrow tells the VBox to always give room as much as
5753
possible to the TextArea. It give as much as possible space to the TextArea and minimum space to the
5854
its child that is, in this case HBox which display Due date--><!-- wrapText will add the text to the new
5955
line when the current line of the box size is full-->

src/com/cankush/todolist/Controller.java

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import com.cankush.todolist.datamodel.TodoData;
44
import com.cankush.todolist.datamodel.TodoItem;
5+
import javafx.application.Platform;
56
import javafx.beans.value.ChangeListener;
67
import javafx.beans.value.ObservableValue;
8+
import javafx.collections.transformation.FilteredList;
79
import javafx.collections.transformation.SortedList;
810
import javafx.event.ActionEvent;
911
import javafx.event.EventHandler;
@@ -22,6 +24,7 @@
2224
import java.util.Comparator;
2325
import java.util.List;
2426
import java.util.Optional;
27+
import java.util.function.Predicate;
2528

2629
public class Controller {
2730
private List<TodoItem> todoItems; // Making todoItems generic
@@ -38,6 +41,13 @@ public class Controller {
3841
@FXML
3942
private ToggleButton filterToggleButton;
4043

44+
// Adding filtered list to show the item by applying some criteria
45+
private FilteredList<TodoItem> filteredList;
46+
47+
// Adding predicate instances;
48+
private Predicate<TodoItem> wantAllItems;
49+
private Predicate<TodoItem> wantTodaysItems;
50+
4151
/**
4252
* Initializing with some data
4353
*/
@@ -71,8 +81,28 @@ public void changed(ObservableValue<? extends TodoItem> observable, TodoItem old
7181
}
7282
});
7383

84+
// Predicate for all items
85+
wantAllItems = new Predicate<TodoItem>() {
86+
@Override
87+
public boolean test(TodoItem item) {
88+
return true;
89+
}
90+
};
91+
92+
// Predicate for today's items
93+
wantTodaysItems = new Predicate<TodoItem>() {
94+
@Override
95+
public boolean test(TodoItem item) {
96+
return (item.getDeadline().equals(LocalDate.now()));
97+
}
98+
};
99+
100+
// Adding code for filteredList
101+
filteredList = new FilteredList<TodoItem>(TodoData.getInstance().getTodoItems(), wantAllItems);
102+
74103
// Sorting the TodoItems list according to the date
75-
SortedList<TodoItem> sortedList = new SortedList<TodoItem>(TodoData.getInstance().getTodoItems(),
104+
// filteredList can be replaced by TodoData.getInstance().getTodoItems() if we are not implementing filteredList
105+
SortedList<TodoItem> sortedList = new SortedList<TodoItem>(filteredList,
76106
new Comparator<TodoItem>() {
77107
@Override
78108
public int compare(TodoItem o1, TodoItem o2) {
@@ -219,8 +249,36 @@ public void deleteItem(TodoItem item) {
219249
}
220250
}
221251

252+
/**
253+
* Method to handle the filter button on main window
254+
*/
255+
@FXML
222256
public void handleFilterButton() {
257+
TodoItem selectedItem = todoListView.getSelectionModel().getSelectedItem();
258+
if (filterToggleButton.isSelected()) {
259+
// If the deadline for todoItem is today then the todoItem is displayed once button is selected
260+
filteredList.setPredicate(wantTodaysItems);
261+
if (filteredList.isEmpty()) {
262+
itemDetailsTextArea.clear();
263+
deadLineLabel.setText("");
264+
} else if (filteredList.contains(selectedItem)) {
265+
todoListView.getSelectionModel().select(selectedItem);
266+
} else {
267+
todoListView.getSelectionModel().selectFirst();
268+
}
269+
} else {
270+
// If the button is not selected then showing all the items
271+
filteredList.setPredicate(wantAllItems);
272+
todoListView.getSelectionModel().select(selectedItem);
273+
}
274+
}
223275

276+
/**
277+
* Event handler for exit option in file menu
278+
*/
279+
@FXML
280+
public void handleExit() {
281+
Platform.exit();
224282
}
225283
}
226284

src/com/cankush/todolist/Main.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class Main extends Application {
1414
@Override
1515
public void start(Stage primaryStage) throws Exception{
1616
Parent root = FXMLLoader.load(getClass().getResource("mainwindow.fxml"));
17+
setUserAgentStylesheet(STYLESHEET_CASPIAN);
1718
primaryStage.setTitle("Todo List");
1819
primaryStage.setScene(new Scene(root, 900, 500));
1920
primaryStage.show();

src/com/cankush/todolist/mainwindow.fxml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,21 @@
44
<?import javafx.scene.layout.*?>
55
<?import javafx.scene.text.Font?>
66
<BorderPane fx:id="mainBorderPane" fx:controller="com.cankush.todolist.Controller"
7-
xmlns:fx="http://javafx.com/fxml">
7+
xmlns:fx="http://javafx.com/fxml"
8+
stylesheets="@style.css">
89
<!-- Adding a Menu bar for our application-->
910
<top>
1011
<VBox>
1112
<MenuBar>
1213
<Menu text="File">
13-
<items>
14-
<MenuItem text="New..." onAction="#showNewItemDialog"/>
15-
<!-- <SeparatorMenuItem/> &lt;!&ndash; Adding the separating line between the two menu items&ndash;&gt;-->
16-
<MenuItem text="Exit"/>
17-
</items>
14+
<MenuItem text="New..." onAction="#showNewItemDialog"/>
15+
<!-- <SeparatorMenuItem/> &lt;!&ndash; Adding the separating line between the two menu items&ndash;&gt;-->
16+
<MenuItem text="Exit" onAction="#handleExit"/>
1817
</Menu>
1918
</MenuBar>
2019
<ToolBar>
2120
<HBox>
22-
<Button onAction="#showNewItemDialog">
21+
<Button onAction="#showNewItemDialog" id="newItemButton">
2322
<!-- tooltip displays the description of the item when hovered on it-->
2423
<tooltip>
2524
<Tooltip text="Add new Todo Item"/>
@@ -30,7 +29,7 @@
3029
</ImageView>
3130
</graphic>
3231
</Button>
33-
<ToggleButton fx:id="filterToggleButton" text="Today's Items" onAction="#handleFilterButton">
32+
<ToggleButton fx:id="filterToggleButton" id="filterButton" text="Today's Items" onAction="#handleFilterButton">
3433
<tooltip>
3534
<Tooltip text="Button Down: Show today's items only. Button Up: Show all items"/>
3635
</tooltip>
@@ -50,7 +49,7 @@
5049
<!-- We have to use all the remaining space if the window. So, we are adding the center tag-->
5150
<center>
5251
<VBox style="-fx-background-color: white">
53-
<TextArea fx:id="itemDetailsTextArea" VBox.vgrow="ALWAYS" wrapText="true"/> <!-- VBox.vgrow tells the VBox to always give room as much as
52+
<TextArea fx:id="itemDetailsTextArea" VBox.vgrow="ALWAYS" wrapText="true" editable="false"/> <!-- VBox.vgrow tells the VBox to always give room as much as
5453
possible to the TextArea. It give as much as possible space to the TextArea and minimum space to the
5554
its child that is, in this case HBox which display Due date--><!-- wrapText will add the text to the new
5655
line when the current line of the box size is full-->

src/com/cankush/todolist/style.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#filterButton {
2+
-fx-background-color: SkyBlue;
3+
-fx-start-margin: 2px;
4+
}
5+
6+
#newItemButton {
7+
/*-fx-padding: 5vw;*/
8+
}

0 commit comments

Comments
 (0)