Menu proper implementation
This commit is contained in:
		
							parent
							
								
									4b47ea8d59
								
							
						
					
					
						commit
						81e22d094b
					
				
					 9 changed files with 46 additions and 15 deletions
				
			
		| 
						 | 
					@ -4,14 +4,18 @@ import java.awt.event.ActionEvent;
 | 
				
			||||||
import java.awt.event.ActionListener;
 | 
					import java.awt.event.ActionListener;
 | 
				
			||||||
import javax.swing.JMenuItem;
 | 
					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");
 | 
					        super("Clear all");
 | 
				
			||||||
 | 
					        this.xlModel = xlModel;
 | 
				
			||||||
        addActionListener(this);
 | 
					        addActionListener(this);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void actionPerformed(ActionEvent e) {
 | 
					    public void actionPerformed(ActionEvent e) {
 | 
				
			||||||
        // TODO
 | 
					        xlModel.clearAll();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,15 +3,23 @@ package xl.gui.menu;
 | 
				
			||||||
import java.awt.event.ActionEvent;
 | 
					import java.awt.event.ActionEvent;
 | 
				
			||||||
import java.awt.event.ActionListener;
 | 
					import java.awt.event.ActionListener;
 | 
				
			||||||
import javax.swing.JMenuItem;
 | 
					import javax.swing.JMenuItem;
 | 
				
			||||||
 | 
					import xl.model.XLModel;
 | 
				
			||||||
 | 
					import xl.gui.StatusLabel;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class ClearMenuItem extends JMenuItem implements ActionListener {
 | 
					class ClearMenuItem extends JMenuItem implements ActionListener {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public ClearMenuItem() {
 | 
					    private XLModel xlModel;
 | 
				
			||||||
 | 
					    private StatusLabel statusLabel;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    public ClearMenuItem(XLModel xlModel, StatusLabel statusLabel) {
 | 
				
			||||||
        super("Clear");
 | 
					        super("Clear");
 | 
				
			||||||
 | 
					        this.xlModel = xlModel;
 | 
				
			||||||
 | 
					        this.statusLabel = statusLabel;
 | 
				
			||||||
        addActionListener(this);
 | 
					        addActionListener(this);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void actionPerformed(ActionEvent e) {
 | 
					    public void actionPerformed(ActionEvent e) {
 | 
				
			||||||
        // TODO
 | 
					        xlModel.clearCell();
 | 
				
			||||||
 | 
					        statusLabel.setText(xlModel.getStatus());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,6 +3,7 @@ package xl.gui.menu;
 | 
				
			||||||
import java.awt.event.ActionEvent;
 | 
					import java.awt.event.ActionEvent;
 | 
				
			||||||
import java.awt.event.ActionListener;
 | 
					import java.awt.event.ActionListener;
 | 
				
			||||||
import javax.swing.JMenuItem;
 | 
					import javax.swing.JMenuItem;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import xl.gui.XL;
 | 
					import xl.gui.XL;
 | 
				
			||||||
import xl.gui.XLList;
 | 
					import xl.gui.XLList;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,17 +2,22 @@ package xl.gui.menu;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.io.FileNotFoundException;
 | 
					import java.io.FileNotFoundException;
 | 
				
			||||||
import javax.swing.JFileChooser;
 | 
					import javax.swing.JFileChooser;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import xl.model.XLModel;
 | 
				
			||||||
import xl.gui.StatusLabel;
 | 
					import xl.gui.StatusLabel;
 | 
				
			||||||
import xl.gui.XL;
 | 
					import xl.gui.XL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class LoadMenuItem extends OpenMenuItem {
 | 
					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");
 | 
					        super(xl, statusLabel, "Load");
 | 
				
			||||||
 | 
					        this.xlModel = xlModel;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected void action(String path) throws FileNotFoundException {
 | 
					    protected void action(String path) throws FileNotFoundException {
 | 
				
			||||||
        // TODO
 | 
					        xlModel.load(path);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected int openDialog(JFileChooser fileChooser) {
 | 
					    protected int openDialog(JFileChooser fileChooser) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,19 +3,23 @@ package xl.gui.menu;
 | 
				
			||||||
import java.awt.event.ActionEvent;
 | 
					import java.awt.event.ActionEvent;
 | 
				
			||||||
import java.awt.event.ActionListener;
 | 
					import java.awt.event.ActionListener;
 | 
				
			||||||
import javax.swing.JMenuItem;
 | 
					import javax.swing.JMenuItem;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import xl.model.XLModel;
 | 
				
			||||||
import xl.gui.XL;
 | 
					import xl.gui.XL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class NewMenuItem extends JMenuItem implements ActionListener {
 | 
					class NewMenuItem extends JMenuItem implements ActionListener {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private XL xl;
 | 
					    private XL xl;
 | 
				
			||||||
 | 
					    private XLModel model;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public NewMenuItem(XL xl) {
 | 
					    public NewMenuItem(XL xl) {
 | 
				
			||||||
        super("New");
 | 
					        super("New");
 | 
				
			||||||
        this.xl = xl;
 | 
					        this.xl = xl;
 | 
				
			||||||
 | 
					        model = new XLModel();
 | 
				
			||||||
        addActionListener(this);
 | 
					        addActionListener(this);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void actionPerformed(ActionEvent event) {
 | 
					    public void actionPerformed(ActionEvent event) {
 | 
				
			||||||
        new XL(xl);
 | 
					        new XL(xl, model);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,6 +8,7 @@ import javax.swing.JFileChooser;
 | 
				
			||||||
import javax.swing.JMenuItem;
 | 
					import javax.swing.JMenuItem;
 | 
				
			||||||
import javax.swing.filechooser.FileFilter;
 | 
					import javax.swing.filechooser.FileFilter;
 | 
				
			||||||
import javax.swing.filechooser.FileNameExtensionFilter;
 | 
					import javax.swing.filechooser.FileNameExtensionFilter;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import xl.gui.StatusLabel;
 | 
					import xl.gui.StatusLabel;
 | 
				
			||||||
import xl.gui.XL;
 | 
					import xl.gui.XL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,17 +2,22 @@ package xl.gui.menu;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.io.FileNotFoundException;
 | 
					import java.io.FileNotFoundException;
 | 
				
			||||||
import javax.swing.JFileChooser;
 | 
					import javax.swing.JFileChooser;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import xl.model.XLModel;
 | 
				
			||||||
import xl.gui.StatusLabel;
 | 
					import xl.gui.StatusLabel;
 | 
				
			||||||
import xl.gui.XL;
 | 
					import xl.gui.XL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class SaveMenuItem extends OpenMenuItem {
 | 
					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");
 | 
					        super(xl, statusLabel, "Save");
 | 
				
			||||||
 | 
					        this.xlModel = xlModel;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected void action(String path) throws FileNotFoundException {
 | 
					    protected void action(String path) throws FileNotFoundException {
 | 
				
			||||||
        // TODO
 | 
					        xlModel.save(path);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected int openDialog(JFileChooser fileChooser) {
 | 
					    protected int openDialog(JFileChooser fileChooser) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,6 +3,7 @@ package xl.gui.menu;
 | 
				
			||||||
import java.awt.event.ActionEvent;
 | 
					import java.awt.event.ActionEvent;
 | 
				
			||||||
import java.awt.event.ActionListener;
 | 
					import java.awt.event.ActionListener;
 | 
				
			||||||
import javax.swing.JMenuItem;
 | 
					import javax.swing.JMenuItem;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import xl.gui.XL;
 | 
					import xl.gui.XL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class WindowMenuItem extends JMenuItem implements ActionListener {
 | 
					class WindowMenuItem extends JMenuItem implements ActionListener {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,21 +2,23 @@ package xl.gui.menu;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import javax.swing.JMenu;
 | 
					import javax.swing.JMenu;
 | 
				
			||||||
import javax.swing.JMenuBar;
 | 
					import javax.swing.JMenuBar;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import xl.model.XLModel;
 | 
				
			||||||
import xl.gui.StatusLabel;
 | 
					import xl.gui.StatusLabel;
 | 
				
			||||||
import xl.gui.XL;
 | 
					import xl.gui.XL;
 | 
				
			||||||
import xl.gui.XLList;
 | 
					import xl.gui.XLList;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class XLMenuBar extends JMenuBar {
 | 
					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 file = new JMenu("File");
 | 
				
			||||||
        JMenu edit = new JMenu("Edit");
 | 
					        JMenu edit = new JMenu("Edit");
 | 
				
			||||||
        file.add(new SaveMenuItem(xl, statusLabel));
 | 
					        file.add(new SaveMenuItem(xl, statusLabel, xlModel)); 
 | 
				
			||||||
        file.add(new LoadMenuItem(xl, statusLabel));
 | 
					        file.add(new LoadMenuItem(xl, statusLabel, xlModel));
 | 
				
			||||||
        file.add(new NewMenuItem(xl));
 | 
					        file.add(new NewMenuItem(xl));
 | 
				
			||||||
        file.add(new CloseMenuItem(xl, xlList));
 | 
					        file.add(new CloseMenuItem(xl, xlList));
 | 
				
			||||||
        edit.add(new ClearMenuItem());
 | 
					        edit.add(new ClearMenuItem(xlModel, statusLabel));
 | 
				
			||||||
        edit.add(new ClearAllMenuItem());
 | 
					        edit.add(new ClearAllMenuItem(xlModel));
 | 
				
			||||||
        add(file);
 | 
					        add(file);
 | 
				
			||||||
        add(edit);
 | 
					        add(edit);
 | 
				
			||||||
        add(new WindowMenu(xlList));
 | 
					        add(new WindowMenu(xlList));
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue