When New GUI exits, tuning entities are told of pending exit which gives them time close things down and exit gracefully.

git-svn-id: http://svn.3splooges.com/romraider-arch/trunk@762 d2e2e1cd-ba16-0410-be16-b7c4453c7c2d
This commit is contained in:
Tgui 2007-08-06 04:22:13 +00:00
parent adc334dfb1
commit 0cb2205708
4 changed files with 38 additions and 2 deletions

View File

@ -28,6 +28,8 @@ import java.awt.Image;
import java.awt.Toolkit; import java.awt.Toolkit;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Iterator; import java.util.Iterator;
import java.util.Vector; import java.util.Vector;
@ -92,8 +94,22 @@ public class NewGUI extends JFrame implements ActionListener, TreeSelectionListe
// Define window closed operation // Define window closed operation
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
LOGGER.info("Preparing Enginuity for exit.");
TuningEntity currentTuningEntity = ApplicationStateManager.getCurrentTuningEntity();
if(currentTuningEntity == null){
LOGGER.debug("No Tuning Entity ever selected.");
LOGGER.info("Enginuity exiting.");
System.exit(0);
}else{
LOGGER.debug("Notify current tuning entity of pending exit.");
currentTuningEntity.notifySystemExit();
}
}
});
// Setup JMenu // Setup JMenu
Iterator tuningEntities = ApplicationStateManager.getTuningEntities().iterator(); Iterator tuningEntities = ApplicationStateManager.getTuningEntities().iterator();
@ -131,6 +147,7 @@ public class NewGUI extends JFrame implements ActionListener, TreeSelectionListe
} }
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if(e.getActionCommand().equalsIgnoreCase("UTEC Tuning Entity")){ if(e.getActionCommand().equalsIgnoreCase("UTEC Tuning Entity")){
String theCommand = e.getActionCommand(); String theCommand = e.getActionCommand();
@ -279,4 +296,9 @@ public class NewGUI extends JFrame implements ActionListener, TreeSelectionListe
return engninuityVersionTitle; return engninuityVersionTitle;
} }
public void readyForExit() {
LOGGER.info("Enginuity is now exiting.");
System.exit(0);
}
} }

View File

@ -28,4 +28,8 @@ public interface TuningEntity extends ActionListener{
// Control methods // Control methods
public void init(TuningEntityListener listener); public void init(TuningEntityListener listener);
// Notify of system exit. Tuning entity must reply to parent GUI that they are in fac
// ready for shutdown
public void notifySystemExit();
} }

View File

@ -50,4 +50,9 @@ public interface TuningEntityListener {
* *
*/ */
public void saveMaps(); public void saveMaps();
/**
* Tuning entity calls back to main gui when its prepared for exit.
*/
public void readyForExit();
} }

View File

@ -438,4 +438,9 @@ public class UtecTuningEntityImpl implements TuningEntity{
return newData; return newData;
} }
public void notifySystemExit() {
this.theTEL.readyForExit();
}
} }