diff --git a/.idea/artifacts/todo_jar.xml b/.idea/artifacts/todo_jar.xml
new file mode 100644
index 0000000..de6cbc6
--- /dev/null
+++ b/.idea/artifacts/todo_jar.xml
@@ -0,0 +1,10 @@
+
+
+ $PROJECT_DIR$/out/artifacts/todo_jar
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/de/dhsn/oop/Main.java b/src/main/java/de/dhsn/oop/Main.java
index a7d5554..fe70f7c 100644
--- a/src/main/java/de/dhsn/oop/Main.java
+++ b/src/main/java/de/dhsn/oop/Main.java
@@ -6,6 +6,7 @@ import com.google.gson.stream.JsonReader;
import de.dhsn.oop.data.TodoList;
import de.dhsn.oop.ui.MainWindow;
+import javax.swing.*;
import java.io.*;
import java.lang.reflect.Type;
import java.util.ArrayList;
@@ -14,6 +15,13 @@ import java.util.List;
public class Main {
public static void main(String[] args) {
//initialize the state empty
+ /*
+ JFileChooser jfs = new JFileChooser();
+ JFrame fileFrame = new JFrame("Open File");
+ fileFrame.getContentPane().add(jfs);
+ fileFrame.setVisible(true);
+
+ */
List listen = new ArrayList<>();
// try t ope nthe file and read json data if successful
try(JsonReader reader = new JsonReader(new FileReader("./test.json"))) {
diff --git a/src/main/java/de/dhsn/oop/todo.java b/src/main/java/de/dhsn/oop/todo.java
new file mode 100644
index 0000000..1ec3708
--- /dev/null
+++ b/src/main/java/de/dhsn/oop/todo.java
@@ -0,0 +1,35 @@
+package de.dhsn.oop;
+
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
+import com.google.gson.stream.JsonReader;
+import de.dhsn.oop.data.TodoList;
+import de.dhsn.oop.ui.MainWindow;
+
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
+
+public class todo {
+ public static void main(String[] args){
+ List listen = new ArrayList<>();
+ // try t ope nthe file and read json data if successful
+ try(JsonReader reader = new JsonReader(new FileReader("./test.json"))) {
+ Type listType = new TypeToken>(){}.getType();
+ Gson g = new Gson();
+ List temp = g.fromJson(reader, listType);
+ //insert all data from json int o state list
+ listen.addAll(temp);
+ } catch (FileNotFoundException ignored) {
+ // ignore file not found --> probably first start and no file present
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ //open the window with the data
+ new MainWindow(listen);
+
+ }
+}
diff --git a/src/main/java/de/dhsn/oop/ui/MainWindow.java b/src/main/java/de/dhsn/oop/ui/MainWindow.java
index 4af15b8..ab3ba9e 100644
--- a/src/main/java/de/dhsn/oop/ui/MainWindow.java
+++ b/src/main/java/de/dhsn/oop/ui/MainWindow.java
@@ -18,6 +18,9 @@ import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
+/**
+ * MainWindow is the main Class started by the static void main function after initializing the datastructure
+ */
public class MainWindow extends JFrame implements ActionListener, ListSelectionListener {
private FlatButton addNewList;
private List lists;
@@ -27,7 +30,7 @@ public class MainWindow extends JFrame implements ActionListener, ListSelectionL
* Main window constructor, takes a (potentially empty) list of TodoList
* this list of lists is supposed to keep all application state for easy file save and open operations
*
- * @param lists
+ * @param lists A list of TodoList
* @throws HeadlessException
*/
public MainWindow(List lists) throws HeadlessException {
@@ -48,6 +51,7 @@ public class MainWindow extends JFrame implements ActionListener, ListSelectionL
addNewList = new FlatButton("Neue Liste Anlegen");
addNewList.addActionListener(this);
+ addNewList.setBackground(Color.WHITE);
cp.add(addNewList, BorderLayout.SOUTH);
cp.setBackground(Color.WHITE);
diff --git a/src/main/java/de/dhsn/oop/ui/NewTodoItemView.java b/src/main/java/de/dhsn/oop/ui/NewTodoItemView.java
index 82bed2c..fa791ab 100644
--- a/src/main/java/de/dhsn/oop/ui/NewTodoItemView.java
+++ b/src/main/java/de/dhsn/oop/ui/NewTodoItemView.java
@@ -8,11 +8,19 @@ import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+/**
+ * This class will present a for with a input field for the name of a new TodoItem to create
+ */
public class NewTodoItemView extends JFrame implements ActionListener {
JTextField input = new JTextField();
FlatButton submit = new FlatButton("OK");
TodoListView view;
+ /**
+ * Constructor to initialize the new todoitem window
+ * the calling class, TodoListView has to be passed to allow for a callback on save
+ * @param view TodoListView instance to call the callback on
+ */
public NewTodoItemView(TodoListView view){
this.view = view;
this.setMaximumSize(new Dimension(200,70));
@@ -25,11 +33,16 @@ public class NewTodoItemView extends JFrame implements ActionListener {
setVisible(true);
}
+ /**
+ * this function gets called when the OK button gets clicked
+ * it will take the text from the input, create a new todoitem and pass it to the TodoListView passed to the constructor
+ * @param e the event to be processed
+ */
@Override
public void actionPerformed(ActionEvent e) {
//hand data back to parent windwo
view.addCallback(new TextTodoItem(input.getText().trim()));
- //close and gc this window
+ //close and remove this window
setVisible(false);
dispose();
}
diff --git a/src/main/java/de/dhsn/oop/ui/TodoListView.java b/src/main/java/de/dhsn/oop/ui/TodoListView.java
index 0f642f8..9f8a299 100644
--- a/src/main/java/de/dhsn/oop/ui/TodoListView.java
+++ b/src/main/java/de/dhsn/oop/ui/TodoListView.java
@@ -11,6 +11,9 @@ import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
+/**
+ * TodoListView displays the contents of a single todolist and buttons for actions to apply to the list
+ */
public class TodoListView extends JFrame {
private FlatLabel title;
private FlatButton addButton;
@@ -20,6 +23,11 @@ public class TodoListView extends JFrame {
private JScrollPane scrolPane;
MainWindow mainWindow;
+ /**
+ * the constructor of the TodoListView class needs a todolist to display and the MainWindow to call the "redraw" function
+ * @param list
+ * @param mw
+ */
public TodoListView(TodoList list, MainWindow mw) {
super();
mainWindow = mw;
@@ -63,6 +71,9 @@ public class TodoListView extends JFrame {
setVisible(true);
}
+ /**
+ * build the contents of the scollpanel and add them to the window
+ */
public void buildScrollPanel(){
scrollContent = new FlatPanel();
scrollContent.removeAll();
@@ -75,22 +86,40 @@ public class TodoListView extends JFrame {
repaint();
}
+ /**
+ * function to tell teh parent Window to reopen this list view because repaint does not work on the scroll pane
+ */
public void forceRerender(){
mainWindow.restartList(list);
setVisible(false);
dispose();
}
+ /**
+ * add todoitem button click function
+ * this will open the newTodoItemView window and pass itself as an argument to allow for a callback to add the new item
+ * @param e
+ */
public void addTodoClicked(ActionEvent e){
new NewTodoItemView(this);
}
+ /**
+ * function called when the delete todolist button is pressed
+ * calls the deleteList function on the main window to delete the list from global state
+ * @param e Event information
+ */
public void deleteButtonClicked(ActionEvent e){
mainWindow.deleteList(list);
setVisible(false);
dispose();
}
+ /**
+ * callback function for the newTodoItem class
+ * accepts a new todoitem to append to the list
+ * @param item
+ */
public void addCallback(TextTodoItem item){
list.addTodo(item);
// todo fühlt sich nach nem reudigen hack an