Merge Menubar features into mvc #17

Manually merged
regar42 merged 4 commits from menuBar into mvc 2017-12-16 17:03:56 +00:00
3 changed files with 56 additions and 15 deletions
Showing only changes of commit a6783e4a0d - Show all commits

No files matched your search

+2
View File
@@ -6,6 +6,7 @@ public class FileMenu extends JMenu {
private final MazeApp mazeApp; private final MazeApp mazeApp;
private final QuitMenuItem quitMenuItem; private final QuitMenuItem quitMenuItem;
private final LoadMazeMenuItem loadMazeMenuItem;
public FileMenu(MazeApp mazeApp) { public FileMenu(MazeApp mazeApp) {
@@ -13,6 +14,7 @@ public class FileMenu extends JMenu {
this.mazeApp = mazeApp; this.mazeApp = mazeApp;
add(quitMenuItem = new QuitMenuItem(mazeApp)); add(quitMenuItem = new QuitMenuItem(mazeApp));
add(loadMazeMenuItem = new LoadMazeMenuItem(mazeApp));
} }
+40
View File
@@ -0,0 +1,40 @@
package ui;
import javax.swing.JFileChooser;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileNameExtensionFilter;
import model.MazeAppModel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class LoadMazeMenuItem extends JMenuItem
implements ActionListener {
private final MazeApp mazeApp;
public LoadMazeMenuItem(MazeApp mazeApp) {
super("Load maze");
this.mazeApp = mazeApp;
addActionListener(this);
}
public void actionPerformed(ActionEvent evt) {
MazeAppModel mazeAppModel = mazeApp.getMazeAppModel();
JFileChooser fileChooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter(
"Text files", "txt");
fileChooser.setFileFilter(filter);
int returnVal = fileChooser.showOpenDialog(mazeApp);
if(returnVal == JFileChooser.APPROVE_OPTION) {
System.out.println("You chose to open this file: " +
fileChooser.getSelectedFile().getName());
String filename = fileChooser.getSelectedFile().getName();
}
mazeApp.getMazeAppModel().setMaze(model.Maze.);
}
}
+14 -15
View File
@@ -25,23 +25,22 @@ public class QuitMenuItem extends JMenuItem
MazeAppModel mazeAppModel = mazeApp.getMazeAppModel(); MazeAppModel mazeAppModel = mazeApp.getMazeAppModel();
if (mazeAppModel.isModified()) { if (mazeAppModel.isModified()) {
int response = JOptionPane.showInternalOptionDialog(this, int response = JOptionPane.showInternalOptionDialog(this,
"Maze not saved. Save it ?", "Maze not saved. Save it ?",
"Quit application", "Quit application",
JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.WARNING_MESSAGE, JOptionPane.WARNING_MESSAGE,
null,null,null) ; null,null,null);
switch (response) { switch (response) {
case JOptionPane.CANCEL_OPTION: case JOptionPane.CANCEL_OPTION:
return; return;
case JOptionPane.OK_OPTION: case JOptionPane.OK_OPTION:
mazeAppModel.saveToFile(); mazeAppModel.saveToFile();
break; break;
case JOptionPane.NO_OPTION: case JOptionPane.NO_OPTION:
break; break;
} }
} }
System.exit(0) ; System.exit(0) ;
} }
} }