comments and fixups
This commit is contained in:
parent
6031d69c8b
commit
851e1a4b41
@ -16,7 +16,7 @@ public class Main {
|
||||
//initialize the state empty
|
||||
List<TodoList> listen = new ArrayList<>();
|
||||
// try t ope nthe file and read json data if successful
|
||||
try(JsonReader reader = new JsonReader(new FileReader(new File("./test.json")))) {
|
||||
try(JsonReader reader = new JsonReader(new FileReader("./test.json"))) {
|
||||
Type listType = new TypeToken<List<TodoList>>(){}.getType();
|
||||
Gson g = new Gson();
|
||||
List<TodoList> temp = g.fromJson(reader, listType);
|
||||
@ -26,8 +26,8 @@ public class Main {
|
||||
// ignore file not found --> probably first start and no file present
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} ;
|
||||
}
|
||||
//open the window with the data
|
||||
MainWindow mw = new MainWindow(listen);
|
||||
new MainWindow(listen);
|
||||
}
|
||||
}
|
@ -1,8 +1,5 @@
|
||||
package de.dhsn.oop.data;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public abstract class TodoItem{
|
||||
public boolean done = false;
|
||||
public String title;
|
||||
|
@ -4,7 +4,6 @@ import de.dhsn.oop.data.TodoList;
|
||||
import de.dhsn.oop.ui.helpers.TodoListListModel;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ListDataListener;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
import java.awt.*;
|
||||
@ -17,7 +16,6 @@ import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class MainWindow extends JFrame implements ActionListener, ListSelectionListener {
|
||||
private JButton addNewList;
|
||||
@ -83,7 +81,7 @@ public class MainWindow extends JFrame implements ActionListener, ListSelectionL
|
||||
* callback function to be called with a title for a new list
|
||||
* this is called from NewListDialog when the user presses the save button
|
||||
*
|
||||
* @param title
|
||||
* @param title title to use for the new todolist
|
||||
* @return
|
||||
*/
|
||||
public void nldCallback(String title) {
|
||||
|
@ -1,12 +1,9 @@
|
||||
package de.dhsn.oop.ui;
|
||||
|
||||
import de.dhsn.oop.data.TodoList;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.List;
|
||||
|
||||
public class NewListDialog extends JFrame implements ActionListener {
|
||||
private JTextField input = new JTextField("TODO");
|
||||
@ -28,6 +25,10 @@ public class NewListDialog extends JFrame implements ActionListener {
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* save futton handler calling parent view update function and then closing window
|
||||
* @param e the event to be processed
|
||||
*/
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
mw.nldCallback(input.getText().strip());
|
||||
|
@ -12,6 +12,7 @@ public class TodoItemPanel extends JPanel implements ActionListener {
|
||||
private TodoItem item;
|
||||
private TodoList list;
|
||||
private TodoListView view;
|
||||
|
||||
public TodoItemPanel(TodoItem i, TodoList l, TodoListView v){
|
||||
item = i;
|
||||
list = l;
|
||||
@ -33,11 +34,20 @@ public class TodoItemPanel extends JPanel implements ActionListener {
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* checkbox action listener for done state of item
|
||||
* @param e the event to be processed
|
||||
*/
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
item.setDone(((JCheckBox)(e.getSource())).isSelected());
|
||||
}
|
||||
|
||||
/**
|
||||
* delete item button callback function
|
||||
* the current item has to be rmeoved from the list
|
||||
* @param e
|
||||
*/
|
||||
public void deletePressed(ActionEvent e) {
|
||||
list.getList().remove(item);
|
||||
view.forceRerender();
|
||||
|
@ -84,7 +84,8 @@ public class TodoListView extends JFrame {
|
||||
|
||||
public void deleteButtonClicked(ActionEvent e){
|
||||
mainWindow.deleteList(list);
|
||||
forceRerender();
|
||||
setVisible(false);
|
||||
dispose();
|
||||
}
|
||||
|
||||
public void addCallback(TextTodoItem item){
|
||||
|
Loading…
Reference in New Issue
Block a user