update unified style classes

This commit is contained in:
goeranh 2025-06-19 19:43:44 +02:00
parent f9325824cb
commit 0987a965c8
No known key found for this signature in database
6 changed files with 101 additions and 2 deletions

View File

@ -0,0 +1,10 @@
<component name="ArtifactManager">
<artifact type="jar" name="todo:jar">
<output-path>$PROJECT_DIR$/out/artifacts/todo_jar</output-path>
<root id="archive" name="todo.jar">
<element id="module-output" name="todo" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/com/google/errorprone/error_prone_annotations/2.38.0/error_prone_annotations-2.38.0.jar" path-in-jar="/" />
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/com/google/code/gson/gson/2.13.1/gson-2.13.1.jar" path-in-jar="/" />
</root>
</artifact>
</component>

View File

@ -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<TodoList> listen = new ArrayList<>();
// try t ope nthe file and read json data if successful
try(JsonReader reader = new JsonReader(new FileReader("./test.json"))) {

View File

@ -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<TodoList> 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<List<TodoList>>(){}.getType();
Gson g = new Gson();
List<TodoList> 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);
}
}

View File

@ -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<TodoList> 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<TodoList> 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);

View File

@ -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();
}

View File

@ -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