save simulation before exit

This commit is contained in:
Fredrik Osterlind 2012-06-01 16:04:39 +02:00
parent b9f1b9b205
commit 2e8ede93cf

View file

@ -2622,8 +2622,7 @@ public class GUI extends Observable {
/** /**
* Quit program * Quit program
* *
* @param askForConfirmation * @param askForConfirmation Should we ask for confirmation before quitting?
* Should we ask for confirmation before quitting?
*/ */
public void doQuit(boolean askForConfirmation) { public void doQuit(boolean askForConfirmation) {
if (isVisualizedInApplet()) { if (isVisualizedInApplet()) {
@ -2631,15 +2630,25 @@ public class GUI extends Observable {
} }
if (askForConfirmation) { if (askForConfirmation) {
String s1 = "Quit"; if (getSimulation() != null) {
String s2 = "Cancel"; /* Save? */
Object[] options = { s1, s2 }; String s1 = "Yes";
int n = JOptionPane.showOptionDialog(GUI.getTopParentContainer(), String s2 = "No";
"Sure you want to quit?", String s3 = "Cancel";
"Quit", JOptionPane.YES_NO_OPTION, Object[] options = { s1, s2, s3 };
JOptionPane.QUESTION_MESSAGE, null, options, s1); int n = JOptionPane.showOptionDialog(GUI.getTopParentContainer(),
if (n != JOptionPane.YES_OPTION) { "Do you want to save the current simulation?",
return; WINDOW_TITLE, JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.WARNING_MESSAGE, null, options, s1);
if (n == JOptionPane.YES_OPTION) {
if (myGUI.doSaveConfig(true) == null) {
return;
}
} else if (n == JOptionPane.CANCEL_OPTION) {
return;
} else if (n != JOptionPane.NO_OPTION) {
return;
}
} }
} }