Merge pull request #967 from jlassahn/fix-954

More improvements for Bug #954
This commit is contained in:
Billy Olsen 2021-07-11 19:19:48 -07:00 committed by GitHub
commit 53e1454173
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 15 deletions

View File

@ -615,6 +615,7 @@ public class OpenRocketDocument implements ComponentChangeListener {
} }
fireUndoRedoChangeEvent(); fireUndoRedoChangeEvent();
fireDocumentChangeEvent(new DocumentChangeEvent(e.getSource()));
} }
/** /**

View File

@ -9,6 +9,8 @@ import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -72,6 +74,17 @@ public class PhotoFrame extends JFrame {
setJMenuBar(getMenu(app)); setJMenuBar(getMenu(app));
setContentPane(photoPanel); setContentPane(photoPanel);
if (!app)
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
closeAction();
}
});
GUIUtil.rememberWindowSize(this); GUIUtil.rememberWindowSize(this);
this.setLocationByPlatform(true); this.setLocationByPlatform(true);
GUIUtil.rememberWindowPosition(this); 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 { public static void main(String args[]) throws Exception {
LoggingSystemSetup.setupLoggingAppender(); LoggingSystemSetup.setupLoggingAppender();

View File

@ -46,6 +46,7 @@ import net.sf.openrocket.gui.figure3d.photo.exhaust.FlameRenderer;
import net.sf.openrocket.gui.main.Splash; import net.sf.openrocket.gui.main.Splash;
import net.sf.openrocket.motor.Motor; import net.sf.openrocket.motor.Motor;
import net.sf.openrocket.motor.MotorConfiguration; import net.sf.openrocket.motor.MotorConfiguration;
import net.sf.openrocket.rocketcomponent.AxialStage;
import net.sf.openrocket.rocketcomponent.FlightConfiguration; import net.sf.openrocket.rocketcomponent.FlightConfiguration;
import net.sf.openrocket.rocketcomponent.FlightConfigurationId; import net.sf.openrocket.rocketcomponent.FlightConfigurationId;
import net.sf.openrocket.rocketcomponent.MotorMount; import net.sf.openrocket.rocketcomponent.MotorMount;
@ -75,6 +76,11 @@ public class PhotoPanel extends JPanel implements GLEventListener {
private List<ImageCallback> imageCallbacks = new java.util.Vector<PhotoPanel.ImageCallback>(); private List<ImageCallback> imageCallbacks = new java.util.Vector<PhotoPanel.ImageCallback>();
private RocketRenderer rr;
private PhotoSettings p;
private OpenRocketDocument document;
private DocumentChangeListener changeListener;
interface ImageCallback { interface ImageCallback {
public void performAction(BufferedImage i); public void performAction(BufferedImage i);
} }
@ -84,32 +90,38 @@ public class PhotoPanel extends JPanel implements GLEventListener {
repaint(); repaint();
} }
private RocketRenderer rr;
private PhotoSettings p;
void setDoc(final OpenRocketDocument doc) { 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() { ((GLAutoDrawable) canvas).invoke(false, new GLRunnable() {
@Override @Override
public boolean run(final GLAutoDrawable drawable) { public boolean run(final GLAutoDrawable drawable) {
PhotoPanel.this.configuration = doc.getSelectedConfiguration();
cachedBounds = null;
rr = new RealisticRenderer(doc); rr = new RealisticRenderer(doc);
rr.init(drawable); 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; return false;
} }
}); });
} }
void clearDoc() {
document.removeDocumentChangeListener(changeListener);
changeListener = null;
document = null;
}
PhotoSettings getSettings() { PhotoSettings getSettings() {
return p; return p;
} }
@ -406,7 +418,11 @@ public class PhotoPanel extends JPanel implements GLEventListener {
rr.render(drawable, configuration, new HashSet<RocketComponent>()); rr.render(drawable, configuration, new HashSet<RocketComponent>());
//Figure out the lowest stage shown //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 int currentStageNumber = configuration.getActiveStages()[configuration.getActiveStages().length-1];
//final AxialStage currentStage = (AxialStage)configuration.getRocket().getChild( bottomStageNumber); //final AxialStage currentStage = (AxialStage)configuration.getRocket().getChild( bottomStageNumber);