diff --git a/Programmierung2/src/TodoListApp/Domain/ProgrammSystem.java b/Programmierung2/src/TodoListApp/Domain/ProgrammSystem.java index 86eb69e..e3ae76e 100644 --- a/Programmierung2/src/TodoListApp/Domain/ProgrammSystem.java +++ b/Programmierung2/src/TodoListApp/Domain/ProgrammSystem.java @@ -18,6 +18,12 @@ public class ProgrammSystem { return tasks.printAllTask(); } - + public boolean removeTask(String title) { + return tasks.removeTask(title); + } + + public boolean markTaskAsDone(String title) { + return tasks.markTaskAsDone(title); + } } diff --git a/Programmierung2/src/TodoListApp/Domain/Task.java b/Programmierung2/src/TodoListApp/Domain/Task.java index 8918e6e..4ef9228 100644 --- a/Programmierung2/src/TodoListApp/Domain/Task.java +++ b/Programmierung2/src/TodoListApp/Domain/Task.java @@ -50,8 +50,8 @@ public class Task { @Override public String toString() { - return "title=" + title + ", beschreibung=" + beschreibung + ((istGemacht == false) ? ", istGemacht = Nein" : ", istGemacht = Ja") - + ", taskprioritaet=" + taskprioritaet; + return "Title= " + title + ", Beschreibung= " + beschreibung + ((istGemacht == false) ? ", istGemacht = Nein" : ", istGemacht = Ja") + + ", Priorität= " + taskprioritaet; } } diff --git a/Programmierung2/src/TodoListApp/Domain/TaskList.java b/Programmierung2/src/TodoListApp/Domain/TaskList.java index 1f3223f..da68610 100644 --- a/Programmierung2/src/TodoListApp/Domain/TaskList.java +++ b/Programmierung2/src/TodoListApp/Domain/TaskList.java @@ -5,56 +5,56 @@ import TodoListApp.Domain.*; import TodoListApp.Domain.KlassenException.*; public class TaskList { - + private ArrayList alleTasks; + public TaskList() { this.alleTasks = new ArrayList<>(); } - + public boolean addTaskZuList(String title, String beschreibung, String eingabeTaskprioritaet) { - Prioritaet taskPrioritaet = null; - switch (eingabeTaskprioritaet) { - case "niedrig": - taskPrioritaet = taskPrioritaet.Niedrig; - break; + Prioritaet taskPrioritaet = null; + switch (eingabeTaskprioritaet) { + case "niedrig": + taskPrioritaet = taskPrioritaet.Niedrig; + break; - case "mittel": - taskPrioritaet = taskPrioritaet.Mittel; - break; + case "mittel": + taskPrioritaet = taskPrioritaet.Mittel; + break; - case "hoch": - taskPrioritaet = taskPrioritaet.Hoch; - break; - default: - taskPrioritaet = taskPrioritaet.Niedrig; - } - - alleTasks.add(new Task(title,beschreibung,taskPrioritaet)); - return true; + case "hoch": + taskPrioritaet = taskPrioritaet.Hoch; + break; + default: + taskPrioritaet = taskPrioritaet.Niedrig; } - - - public boolean removeTask(Task task) { - + + alleTasks.add(new Task(title, beschreibung, taskPrioritaet)); + return true; + } + + public boolean removeTask(String title) { + for (Task t : alleTasks) { - if (t.getTitle().equalsIgnoreCase(task.getTitle())) { - alleTasks.remove(task); + if (t.getTitle().equalsIgnoreCase(title)) { + alleTasks.remove(t); return true; } } return false; } - + public String findeTaskByTitle(String title) throws TaskNichtGefundenException { - + for (Task t : alleTasks) { if (t.getTitle() == title) return t.toString(); } - throw new TaskNichtGefundenException("Task wurde nicht gefunden" ); + throw new TaskNichtGefundenException("Task wurde nicht gefunden"); } - + public ArrayList printAlleGemachteTasks() { ArrayList alleGemachteTasks = new ArrayList<>(); for (Task t : alleTasks) { @@ -63,7 +63,7 @@ public class TaskList { } return alleGemachteTasks; } - + public ArrayList printAllTask() { ArrayList printallTasks = new ArrayList<>(); int index = 1; @@ -73,4 +73,13 @@ public class TaskList { return printallTasks; } + public boolean markTaskAsDone(String title) { + for (Task t : alleTasks) + if (t.getTitle().equalsIgnoreCase(title)) { + t.setIstGemacht(true); + return t.isIstGemacht(); + } + return false; + } + } diff --git a/Programmierung2/src/TodoListApp/GUI_UserInterface/GUI_UserInterface.java b/Programmierung2/src/TodoListApp/GUI_UserInterface/GUI_UserInterface.java index d827e38..a781d43 100644 --- a/Programmierung2/src/TodoListApp/GUI_UserInterface/GUI_UserInterface.java +++ b/Programmierung2/src/TodoListApp/GUI_UserInterface/GUI_UserInterface.java @@ -14,6 +14,8 @@ public class GUI_UserInterface extends JFrame { private JButton zeigeAlleTasks; private JTextArea AllTasksArea; private JButton clear; + private JButton removeTask; + private JButton taskDone; public GUI_UserInterface() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE ); @@ -43,7 +45,6 @@ public class GUI_UserInterface extends JFrame { panel_1.setLayout(null); AllTasksArea = new JTextArea(); - AllTasksArea.setEnabled(false); AllTasksArea.setEditable(false); AllTasksArea.setForeground(new Color(0, 0, 0)); AllTasksArea.setFont(new Font("Arial", Font.BOLD, 14)); @@ -61,6 +62,14 @@ public class GUI_UserInterface extends JFrame { clear = new JButton("Clear TextArea"); clear.setBounds(384, 506, 159, 29); panel.add(clear); + + removeTask = new JButton("Task Löschen"); + removeTask.setBounds(10, 547, 159, 27); + panel.add(removeTask); + + taskDone = new JButton("Gemacht!"); + taskDone.setBounds(193, 549, 159, 25); + panel.add(taskDone); setLocationRelativeTo(null); this.setVisible(true); @@ -88,7 +97,14 @@ public class GUI_UserInterface extends JFrame { public JButton getClear() { return clear; } + + public JButton getRemoveTask() { + return removeTask; + } + + public JButton getTaskDone() { + return taskDone; + } - -} +} \ No newline at end of file diff --git a/Programmierung2/src/TodoListApp/GUI_UserInterface/MarkTask.java b/Programmierung2/src/TodoListApp/GUI_UserInterface/MarkTask.java new file mode 100644 index 0000000..9139a3b --- /dev/null +++ b/Programmierung2/src/TodoListApp/GUI_UserInterface/MarkTask.java @@ -0,0 +1,84 @@ +package TodoListApp.GUI_UserInterface; + +import java.awt.Color; +import java.awt.Font; + +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.SwingConstants; +import javax.swing.border.EmptyBorder; + +public class MarkTask extends JFrame { + private static final long serialVersionUID = 1L; + private JPanel contentPane; + private JTextField markTaskEingabe; + private JButton markTaskButton; + + public MarkTask() { + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setBounds(100, 100, 417, 424); + contentPane = new JPanel(); + contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); + + setContentPane(contentPane); + contentPane.setLayout(null); + + JPanel panel = new JPanel(); + panel.setBackground(new Color(0, 128, 192)); + panel.setBounds(40, 48, 333, 263); + contentPane.add(panel); + panel.setLayout(null); + + JLabel lblNewLabel = new JLabel("Task markieren"); + lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 14)); + lblNewLabel.setForeground(new Color(255, 255, 255)); + lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER); + lblNewLabel.setBounds(28, 11, 256, 29); + panel.add(lblNewLabel); + + JLabel lblNewLabel_1 = new JLabel("Title: "); + lblNewLabel_1.setFont(new Font("Tahoma", Font.BOLD, 12)); + lblNewLabel_1.setForeground(new Color(255, 255, 255)); + lblNewLabel_1.setBounds(65, 69, 77, 17); + panel.add(lblNewLabel_1); + + markTaskEingabe = new JTextField(); + markTaskEingabe.setBounds(128, 67, 114, 21); + panel.add(markTaskEingabe); + markTaskEingabe.setColumns(10); + + markTaskButton = new JButton("Submit"); + markTaskButton.setBounds(65, 121, 105, 27); + panel.add(markTaskButton); + setLocationRelativeTo(null); + } + + public void zeigeFenster() { + this.setVisible(true); + } + + + + public JTextField getMarkTaskEingabe() { + return markTaskEingabe; + } + + public void setMarkTaskEingabe(JTextField markTaskEingabe) { + this.markTaskEingabe = markTaskEingabe; + } + + public JButton getMarkTaskButton() { + return markTaskButton; + } + + public void showInfo(String message) { + JOptionPane.showMessageDialog(null, message, "Task gelöscht", JOptionPane.INFORMATION_MESSAGE); + } + public void showError(String message) { + JOptionPane.showMessageDialog(null, message, "Task gelöscht", JOptionPane.ERROR_MESSAGE); + } +} diff --git a/Programmierung2/src/TodoListApp/GUI_UserInterface/RemoveTask.java b/Programmierung2/src/TodoListApp/GUI_UserInterface/RemoveTask.java new file mode 100644 index 0000000..129660b --- /dev/null +++ b/Programmierung2/src/TodoListApp/GUI_UserInterface/RemoveTask.java @@ -0,0 +1,85 @@ +package TodoListApp.GUI_UserInterface; + +import java.awt.EventQueue; + +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.border.EmptyBorder; +import java.awt.Color; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.SwingConstants; +import javax.swing.JTextField; +import javax.swing.JButton; +import java.awt.Font; + +public class RemoveTask extends JFrame { + + private static final long serialVersionUID = 1L; + private JPanel contentPane; + private JTextField removeTaskEingabe; + private JButton removeTaskButton; + + public RemoveTask() { + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setBounds(100, 100, 417, 424); + contentPane = new JPanel(); + contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); + + setContentPane(contentPane); + contentPane.setLayout(null); + + JPanel panel = new JPanel(); + panel.setBackground(new Color(0, 128, 192)); + panel.setBounds(40, 48, 333, 263); + contentPane.add(panel); + panel.setLayout(null); + + JLabel lblNewLabel = new JLabel("Task Löschen"); + lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 14)); + lblNewLabel.setForeground(new Color(255, 255, 255)); + lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER); + lblNewLabel.setBounds(28, 11, 256, 29); + panel.add(lblNewLabel); + + JLabel lblNewLabel_1 = new JLabel("Title: "); + lblNewLabel_1.setFont(new Font("Tahoma", Font.BOLD, 12)); + lblNewLabel_1.setForeground(new Color(255, 255, 255)); + lblNewLabel_1.setBounds(65, 69, 77, 17); + panel.add(lblNewLabel_1); + + removeTaskEingabe = new JTextField(); + removeTaskEingabe.setBounds(128, 67, 114, 21); + panel.add(removeTaskEingabe); + removeTaskEingabe.setColumns(10); + + removeTaskButton = new JButton("Submit"); + removeTaskButton.setBounds(65, 121, 105, 27); + panel.add(removeTaskButton); + setLocationRelativeTo(null); + } + + public void zeigeFenster() { + this.setVisible(true); + } + + public JTextField getRemoveTaskEingabe() { + return removeTaskEingabe; + } + + public void setRemoveTaskEingabe(JTextField removeTaskEingabe) { + this.removeTaskEingabe = removeTaskEingabe; + } + + public JButton getRemoveTaskButton() { + return removeTaskButton; + } + + public void showInfo(String message) { + JOptionPane.showMessageDialog(null, message, "Task gelöscht", JOptionPane.INFORMATION_MESSAGE); + } + public void showError(String message) { + JOptionPane.showMessageDialog(null, message, "Task gelöscht", JOptionPane.ERROR_MESSAGE); + } + +} \ No newline at end of file diff --git a/Programmierung2/src/TodoListApp/GUI_UserInterface/Userverwalter.java b/Programmierung2/src/TodoListApp/GUI_UserInterface/Userverwalter.java index 7bee54a..d969c46 100644 --- a/Programmierung2/src/TodoListApp/GUI_UserInterface/Userverwalter.java +++ b/Programmierung2/src/TodoListApp/GUI_UserInterface/Userverwalter.java @@ -8,17 +8,21 @@ public class Userverwalter { private ProgrammSystem system; private GUI_UserInterface user; private GUI_addTask taskHinziFuegenFenster; + private RemoveTask taskLöschenFenster; + private MarkTask markTaskFenster; private int index = 0; public Userverwalter() { this.system = new ProgrammSystem(); this.user = new GUI_UserInterface(); this.taskHinziFuegenFenster = new GUI_addTask(); + this.taskLöschenFenster = new RemoveTask(); + this.markTaskFenster = new MarkTask(); // Buttons User: user.getAddTask().addActionListener(e -> { try { - zeigeFenster(); + taskAddFenster(); } catch (FalscheEinagebException e1) { // TODO Auto-generated catch block e1.printStackTrace(); @@ -34,13 +38,18 @@ public class Userverwalter { e1.printStackTrace(); } }); - + + markTaskFenster.getMarkTaskButton().addActionListener(e -> markTaskAsDone()); + taskLöschenFenster.getRemoveTaskButton().addActionListener(e-> removeTask()); + user.getTaskDone().addActionListener(e ->zeigeMarkTaskFenster()); + user.getZeigeAlleTasks().addActionListener(e -> showAllTasks()); user.getClear().addActionListener(e -> clearTextArea()); + user.getRemoveTask().addActionListener(e -> removeTaskFenster()); } - public void zeigeFenster() throws FalscheEinagebException { + public void taskAddFenster() throws FalscheEinagebException { taskHinziFuegenFenster.zeigeFensterAddTask(); } @@ -80,8 +89,43 @@ public class Userverwalter { } + public void removeTaskFenster() { + taskLöschenFenster.zeigeFenster(); + } + + public void removeTask() { + String title = taskLöschenFenster.getRemoveTaskEingabe().getText(); + if (system.removeTask(title)) { + taskLöschenFenster.showInfo("Task erfolgreich gelöscht"); + clearTextArea(); + showAllTasks(); + } + else + taskLöschenFenster.showError("Task ist nicht auf der Liste"); + } + public void clearTextArea() { + if (user.getAllTasksArea().getText().isEmpty()) + user.showInfo("Ist bereits leer!"); + user.getAllTasksArea().setText(""); index = 0; } + + public void zeigeMarkTaskFenster() { + markTaskFenster.zeigeFenster(); + } + + public void markTaskAsDone() { + String title = markTaskFenster.getMarkTaskEingabe().getText(); + + if (title.isEmpty()) + markTaskFenster.showError("Sie müssen Title eingeben"); + else if (system.markTaskAsDone(title)) { + markTaskFenster.showInfo("Task ist als Gemacht makiert"); + clearTextArea(); + showAllTasks(); + } + } } +