From 81e22d094ba04cf60bb937a38a623c513249aeb2 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Mon, 3 Jun 2024 19:31:27 +0200 Subject: [PATCH] Menu proper implementation --- app/src/main/java/xl/gui/menu/ClearAllMenuItem.java | 10 +++++++--- app/src/main/java/xl/gui/menu/ClearMenuItem.java | 12 ++++++++++-- app/src/main/java/xl/gui/menu/CloseMenuItem.java | 1 + app/src/main/java/xl/gui/menu/LoadMenuItem.java | 9 +++++++-- app/src/main/java/xl/gui/menu/NewMenuItem.java | 6 +++++- app/src/main/java/xl/gui/menu/OpenMenuItem.java | 1 + app/src/main/java/xl/gui/menu/SaveMenuItem.java | 9 +++++++-- app/src/main/java/xl/gui/menu/WindowMenuItem.java | 1 + app/src/main/java/xl/gui/menu/XLMenuBar.java | 12 +++++++----- 9 files changed, 46 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/xl/gui/menu/ClearAllMenuItem.java b/app/src/main/java/xl/gui/menu/ClearAllMenuItem.java index dce2215..10d3738 100644 --- a/app/src/main/java/xl/gui/menu/ClearAllMenuItem.java +++ b/app/src/main/java/xl/gui/menu/ClearAllMenuItem.java @@ -4,14 +4,18 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JMenuItem; -class ClearAllMenuItem extends JMenuItem implements ActionListener { +import xl.model.XLModel; - public ClearAllMenuItem() { +class ClearAllMenuItem extends JMenuItem implements ActionListener { + private XLModel xlModel; + + public ClearAllMenuItem(XLModel xlModel) { super("Clear all"); + this.xlModel = xlModel; addActionListener(this); } public void actionPerformed(ActionEvent e) { - // TODO + xlModel.clearAll(); } } diff --git a/app/src/main/java/xl/gui/menu/ClearMenuItem.java b/app/src/main/java/xl/gui/menu/ClearMenuItem.java index c1954f9..0351e09 100644 --- a/app/src/main/java/xl/gui/menu/ClearMenuItem.java +++ b/app/src/main/java/xl/gui/menu/ClearMenuItem.java @@ -3,15 +3,23 @@ package xl.gui.menu; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JMenuItem; +import xl.model.XLModel; +import xl.gui.StatusLabel; class ClearMenuItem extends JMenuItem implements ActionListener { - public ClearMenuItem() { + private XLModel xlModel; + private StatusLabel statusLabel; + + public ClearMenuItem(XLModel xlModel, StatusLabel statusLabel) { super("Clear"); + this.xlModel = xlModel; + this.statusLabel = statusLabel; addActionListener(this); } public void actionPerformed(ActionEvent e) { - // TODO + xlModel.clearCell(); + statusLabel.setText(xlModel.getStatus()); } } diff --git a/app/src/main/java/xl/gui/menu/CloseMenuItem.java b/app/src/main/java/xl/gui/menu/CloseMenuItem.java index 4373217..5126b0e 100644 --- a/app/src/main/java/xl/gui/menu/CloseMenuItem.java +++ b/app/src/main/java/xl/gui/menu/CloseMenuItem.java @@ -3,6 +3,7 @@ package xl.gui.menu; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JMenuItem; + import xl.gui.XL; import xl.gui.XLList; diff --git a/app/src/main/java/xl/gui/menu/LoadMenuItem.java b/app/src/main/java/xl/gui/menu/LoadMenuItem.java index c833104..453c52f 100644 --- a/app/src/main/java/xl/gui/menu/LoadMenuItem.java +++ b/app/src/main/java/xl/gui/menu/LoadMenuItem.java @@ -2,17 +2,22 @@ package xl.gui.menu; import java.io.FileNotFoundException; import javax.swing.JFileChooser; + +import xl.model.XLModel; import xl.gui.StatusLabel; import xl.gui.XL; class LoadMenuItem extends OpenMenuItem { - public LoadMenuItem(XL xl, StatusLabel statusLabel) { + private XLModel xlModel; + + public LoadMenuItem(XL xl, StatusLabel statusLabel, XLModel xlModel) { super(xl, statusLabel, "Load"); + this.xlModel = xlModel; } protected void action(String path) throws FileNotFoundException { - // TODO + xlModel.load(path); } protected int openDialog(JFileChooser fileChooser) { diff --git a/app/src/main/java/xl/gui/menu/NewMenuItem.java b/app/src/main/java/xl/gui/menu/NewMenuItem.java index ae2aeb9..e808916 100644 --- a/app/src/main/java/xl/gui/menu/NewMenuItem.java +++ b/app/src/main/java/xl/gui/menu/NewMenuItem.java @@ -3,19 +3,23 @@ package xl.gui.menu; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JMenuItem; + +import xl.model.XLModel; import xl.gui.XL; class NewMenuItem extends JMenuItem implements ActionListener { private XL xl; + private XLModel model; public NewMenuItem(XL xl) { super("New"); this.xl = xl; + model = new XLModel(); addActionListener(this); } public void actionPerformed(ActionEvent event) { - new XL(xl); + new XL(xl, model); } } diff --git a/app/src/main/java/xl/gui/menu/OpenMenuItem.java b/app/src/main/java/xl/gui/menu/OpenMenuItem.java index 39c3f88..fca8951 100644 --- a/app/src/main/java/xl/gui/menu/OpenMenuItem.java +++ b/app/src/main/java/xl/gui/menu/OpenMenuItem.java @@ -8,6 +8,7 @@ import javax.swing.JFileChooser; import javax.swing.JMenuItem; import javax.swing.filechooser.FileFilter; import javax.swing.filechooser.FileNameExtensionFilter; + import xl.gui.StatusLabel; import xl.gui.XL; diff --git a/app/src/main/java/xl/gui/menu/SaveMenuItem.java b/app/src/main/java/xl/gui/menu/SaveMenuItem.java index 84b5807..ea10dd8 100644 --- a/app/src/main/java/xl/gui/menu/SaveMenuItem.java +++ b/app/src/main/java/xl/gui/menu/SaveMenuItem.java @@ -2,17 +2,22 @@ package xl.gui.menu; import java.io.FileNotFoundException; import javax.swing.JFileChooser; + +import xl.model.XLModel; import xl.gui.StatusLabel; import xl.gui.XL; class SaveMenuItem extends OpenMenuItem { - public SaveMenuItem(XL xl, StatusLabel statusLabel) { + private XLModel xlModel; + + public SaveMenuItem(XL xl, StatusLabel statusLabel, XLModel xlModel) { super(xl, statusLabel, "Save"); + this.xlModel = xlModel; } protected void action(String path) throws FileNotFoundException { - // TODO + xlModel.save(path); } protected int openDialog(JFileChooser fileChooser) { diff --git a/app/src/main/java/xl/gui/menu/WindowMenuItem.java b/app/src/main/java/xl/gui/menu/WindowMenuItem.java index afa6d29..a560ac1 100644 --- a/app/src/main/java/xl/gui/menu/WindowMenuItem.java +++ b/app/src/main/java/xl/gui/menu/WindowMenuItem.java @@ -3,6 +3,7 @@ package xl.gui.menu; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JMenuItem; + import xl.gui.XL; class WindowMenuItem extends JMenuItem implements ActionListener { diff --git a/app/src/main/java/xl/gui/menu/XLMenuBar.java b/app/src/main/java/xl/gui/menu/XLMenuBar.java index cbbf837..1191e19 100644 --- a/app/src/main/java/xl/gui/menu/XLMenuBar.java +++ b/app/src/main/java/xl/gui/menu/XLMenuBar.java @@ -2,21 +2,23 @@ package xl.gui.menu; import javax.swing.JMenu; import javax.swing.JMenuBar; + +import xl.model.XLModel; import xl.gui.StatusLabel; import xl.gui.XL; import xl.gui.XLList; public class XLMenuBar extends JMenuBar { - public XLMenuBar(XL xl, XLList xlList, StatusLabel statusLabel) { + public XLMenuBar(XL xl, XLList xlList, StatusLabel statusLabel, XLModel xlModel) { JMenu file = new JMenu("File"); JMenu edit = new JMenu("Edit"); - file.add(new SaveMenuItem(xl, statusLabel)); - file.add(new LoadMenuItem(xl, statusLabel)); + file.add(new SaveMenuItem(xl, statusLabel, xlModel)); + file.add(new LoadMenuItem(xl, statusLabel, xlModel)); file.add(new NewMenuItem(xl)); file.add(new CloseMenuItem(xl, xlList)); - edit.add(new ClearMenuItem()); - edit.add(new ClearAllMenuItem()); + edit.add(new ClearMenuItem(xlModel, statusLabel)); + edit.add(new ClearAllMenuItem(xlModel)); add(file); add(edit); add(new WindowMenu(xlList));