Files
TpMazeJava/src/ui/QuitMenuItem.java
T
regar42 29f0c69fa4 Open app on empty maze and improve load/save
model:
* Add a filename attribute to MazeAppModel to keep track of the file
  currently being used by the app
* Add saveToFile(filename) to save the maze into a specific file
* Rewrite saveToFile() to use the stored filename attribute to know into
  which file is to be used to save the maze, instead of the
  hardcoded path
* Remove unused models
* MazeAppModel is now initialized with an empty maze, instead of a
  maze read from a hardcoded path
* Add a MazeAppModelMessage class to pass proper messages to observers
* Replace setMaze(maze) by loadMaze(filename) for now
* Move paintMaze into ui/MazeApp

ui:
* Add a Save As button (just a new name for the previous Save button)
  and implement an actual Save button (which saves into the file
  currently being used), disabled when no file is currently in use.
  (see #16)
* Create the FileBox class to handle file choices for the load, save,
  save as buttons
* Add keystrokes to trigger Load, Save or Save As actions from the menu

maze:
* Add a method to Maze to perform a deep copy of a matrix of boxes
* Add a static method to generate an empty maze of a fixed size (10*10)
  This behavior might change in the future
* Add a constructor to make a Maze from a matrix of boxes
2017-12-23 16:30:01 +01:00

49 lines
1.1 KiB
Java

package ui;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.KeyStroke;
import model.MazeAppModel;
public class QuitMenuItem extends JMenuItem
implements ActionListener {
private final MazeApp mazeApp;
public QuitMenuItem(MazeApp mazeApp) {
super("Quit");
this.mazeApp = mazeApp;
this.setAccelerator(KeyStroke.getKeyStroke("control Q"));
addActionListener(this);
}
public void actionPerformed(ActionEvent evt) {
MazeAppModel mazeAppModel = mazeApp.getMazeAppModel();
if (mazeAppModel.isModified()) {
int response = JOptionPane.showInternalOptionDialog(this,
"Maze not saved. Save it ?",
"Quit application",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.WARNING_MESSAGE,
null, null, null);
switch (response) {
case JOptionPane.CANCEL_OPTION:
return;
case JOptionPane.OK_OPTION:
mazeAppModel.saveToFile();
break;
case JOptionPane.NO_OPTION:
break;
}
}
System.exit(0);
}
}