Route change events through OpenRocketDocument so Photo Studio can
receive notifications of changes to the rocket. Dispose PhotoStudio windows on close, and add a close event to remove event handlers, to avoid leaking resources.
This commit is contained in:
parent
dcc3c43bc3
commit
51c1c78988
@ -594,6 +594,7 @@ public class OpenRocketDocument implements ComponentChangeListener {
|
||||
}
|
||||
|
||||
fireUndoRedoChangeEvent();
|
||||
fireDocumentChangeEvent(new DocumentChangeEvent(e.getSource()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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();
|
||||
|
@ -75,6 +75,11 @@ public class PhotoPanel extends JPanel implements GLEventListener {
|
||||
|
||||
private List<ImageCallback> imageCallbacks = new java.util.Vector<PhotoPanel.ImageCallback>();
|
||||
|
||||
private RocketRenderer rr;
|
||||
private PhotoSettings p;
|
||||
private OpenRocketDocument document;
|
||||
private DocumentChangeListener changeListener;
|
||||
|
||||
interface ImageCallback {
|
||||
public void performAction(BufferedImage i);
|
||||
}
|
||||
@ -84,32 +89,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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user