Menu proper implementation

This commit is contained in:
Imbus 2024-06-03 19:31:27 +02:00
parent 4b47ea8d59
commit 81e22d094b
9 changed files with 46 additions and 15 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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