diff --git a/core/src/net/sf/openrocket/document/OpenRocketDocument.java b/core/src/net/sf/openrocket/document/OpenRocketDocument.java index 022ad0902..168702894 100644 --- a/core/src/net/sf/openrocket/document/OpenRocketDocument.java +++ b/core/src/net/sf/openrocket/document/OpenRocketDocument.java @@ -615,6 +615,7 @@ public class OpenRocketDocument implements ComponentChangeListener { } fireUndoRedoChangeEvent(); + fireDocumentChangeEvent(new DocumentChangeEvent(e.getSource())); } /** diff --git a/swing/src/net/sf/openrocket/gui/figure3d/photo/PhotoFrame.java b/swing/src/net/sf/openrocket/gui/figure3d/photo/PhotoFrame.java index 7cc1caacd..a6f571644 100644 --- a/swing/src/net/sf/openrocket/gui/figure3d/photo/PhotoFrame.java +++ b/swing/src/net/sf/openrocket/gui/figure3d/photo/PhotoFrame.java @@ -9,6 +9,8 @@ import java.awt.datatransfer.UnsupportedFlavorException; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; @@ -72,6 +74,17 @@ public class PhotoFrame extends JFrame { setJMenuBar(getMenu(app)); setContentPane(photoPanel); + if (!app) + setDefaultCloseOperation(DISPOSE_ON_CLOSE); + + addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + closeAction(); + } + }); + + GUIUtil.rememberWindowSize(this); this.setLocationByPlatform(true); GUIUtil.rememberWindowPosition(this); @@ -305,6 +318,11 @@ public class PhotoFrame extends JFrame { } + private boolean closeAction() { + photoPanel.clearDoc(); + return true; + } + public static void main(String args[]) throws Exception { LoggingSystemSetup.setupLoggingAppender(); diff --git a/swing/src/net/sf/openrocket/gui/figure3d/photo/PhotoPanel.java b/swing/src/net/sf/openrocket/gui/figure3d/photo/PhotoPanel.java index 78cf58dc0..3521ad373 100644 --- a/swing/src/net/sf/openrocket/gui/figure3d/photo/PhotoPanel.java +++ b/swing/src/net/sf/openrocket/gui/figure3d/photo/PhotoPanel.java @@ -46,6 +46,7 @@ import net.sf.openrocket.gui.figure3d.photo.exhaust.FlameRenderer; import net.sf.openrocket.gui.main.Splash; import net.sf.openrocket.motor.Motor; import net.sf.openrocket.motor.MotorConfiguration; +import net.sf.openrocket.rocketcomponent.AxialStage; import net.sf.openrocket.rocketcomponent.FlightConfiguration; import net.sf.openrocket.rocketcomponent.FlightConfigurationId; import net.sf.openrocket.rocketcomponent.MotorMount; @@ -75,6 +76,11 @@ public class PhotoPanel extends JPanel implements GLEventListener { private List imageCallbacks = new java.util.Vector(); + private RocketRenderer rr; + private PhotoSettings p; + private OpenRocketDocument document; + private DocumentChangeListener changeListener; + interface ImageCallback { public void performAction(BufferedImage i); } @@ -84,32 +90,38 @@ public class PhotoPanel extends JPanel implements GLEventListener { repaint(); } - private RocketRenderer rr; - private PhotoSettings p; - void setDoc(final OpenRocketDocument doc) { + document = doc; + cachedBounds = null; + this.configuration = doc.getSelectedConfiguration(); + + changeListener = new DocumentChangeListener() { + @Override + public void documentChanged(DocumentChangeEvent event) { + log.debug("Repainting on document change"); + needUpdate = true; + PhotoPanel.this.repaint(); + } + }; + document.addDocumentChangeListener(changeListener); + ((GLAutoDrawable) canvas).invoke(false, new GLRunnable() { @Override public boolean run(final GLAutoDrawable drawable) { - PhotoPanel.this.configuration = doc.getSelectedConfiguration(); - cachedBounds = null; rr = new RealisticRenderer(doc); rr.init(drawable); - doc.addDocumentChangeListener(new DocumentChangeListener() { - @Override - public void documentChanged(DocumentChangeEvent event) { - log.debug("Repainting on document change"); - needUpdate = true; - PhotoPanel.this.repaint(); - } - }); - return false; } }); } + void clearDoc() { + document.removeDocumentChangeListener(changeListener); + changeListener = null; + document = null; + } + PhotoSettings getSettings() { return p; } @@ -406,7 +418,11 @@ public class PhotoPanel extends JPanel implements GLEventListener { rr.render(drawable, configuration, new HashSet()); //Figure out the lowest stage shown - final int bottomStageNumber = configuration.getBottomStage().getStageNumber(); + + AxialStage bottomStage = configuration.getBottomStage(); + int bottomStageNumber = 0; + if (bottomStage != null) + bottomStage.getStageNumber(); //final int currentStageNumber = configuration.getActiveStages()[configuration.getActiveStages().length-1]; //final AxialStage currentStage = (AxialStage)configuration.getRocket().getChild( bottomStageNumber);