[fix] reworks / fixes the way ComponentConfigDialogs are closed

- Close hooks are now called for all methods of closing a dialog ('close', 'X', and escape)
- Adds a rocket.removeComponentChangeListener to close hook
- removes redundant / buggy methods
This commit is contained in:
Daniel_M_Williams 2020-04-05 10:40:34 -04:00
parent 24ae797959
commit 336b899a06
2 changed files with 27 additions and 25 deletions

View File

@ -2,6 +2,8 @@ package net.sf.openrocket.gui.configdialog;
import java.awt.Window;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
@ -30,10 +32,9 @@ public class ComponentConfigDialog extends JDialog implements ComponentChangeLis
private static final String CONFIGDIALOGPACKAGE = "net.sf.openrocket.gui.configdialog";
private static final String CONFIGDIALOGPOSTFIX = "Config";
// Static Value -- This is a singleton value, and we should only have zero or one active at any time
private static ComponentConfigDialog dialog = null;
private OpenRocketDocument document = null;
private RocketComponent component = null;
private RocketComponentConfig configurator = null;
@ -41,8 +42,7 @@ public class ComponentConfigDialog extends JDialog implements ComponentChangeLis
private final Window parent;
private static final Translator trans = Application.getTranslator();
private ComponentConfigDialog(Window parent, OpenRocketDocument document,
RocketComponent component) {
private ComponentConfigDialog(Window parent, OpenRocketDocument document, RocketComponent component) {
super(parent);
this.parent = parent;
@ -50,6 +50,22 @@ public class ComponentConfigDialog extends JDialog implements ComponentChangeLis
GUIUtil.setDisposableDialogOptions(this, null);
GUIUtil.rememberWindowPosition(this);
// overrides common defaults in 'GUIUTIL.setDisposableDialogOptions', above
setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
/**
* Triggered by the 'Close' Button on the ConfigDialogs. AND Esc. AND the [x] button (on Windows)
* In fact, it should trigger for any method of closing the dialog.
*/
public void windowClosed(WindowEvent e){
configurator.invalidate();
document.getRocket().removeComponentChangeListener(ComponentConfigDialog.this);
ComponentConfigDialog.this.dispose();
}
public void windowClosing(WindowEvent e){}
});
}
@ -102,14 +118,6 @@ public class ComponentConfigDialog extends JDialog implements ComponentChangeLis
throw new BugException("Unable to find any configurator for " + component);
}
private void closeDialog() {
this.setVisible(false);
this.dispose();
this.configurator.invalidateModels();
}
@Override
public void componentChanged(ComponentChangeEvent e) {
if (e.isTreeChange() || e.isUndoChange()) {
@ -200,7 +208,7 @@ public class ComponentConfigDialog extends JDialog implements ComponentChangeLis
*/
public static void hideDialog() {
if (dialog != null) {
dialog.closeDialog();
dialog.setVisible(false);
}
}

View File

@ -3,10 +3,7 @@ package net.sf.openrocket.gui.configdialog;
import java.awt.Component;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@ -43,11 +40,8 @@ import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.material.Material;
import net.sf.openrocket.preset.ComponentPreset;
import net.sf.openrocket.rocketcomponent.ComponentAssembly;
import net.sf.openrocket.rocketcomponent.ExternalComponent;
import net.sf.openrocket.rocketcomponent.*;
import net.sf.openrocket.rocketcomponent.ExternalComponent.Finish;
import net.sf.openrocket.rocketcomponent.Instanceable;
import net.sf.openrocket.rocketcomponent.NoseCone;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.rocketcomponent.position.AxialMethod;
import net.sf.openrocket.startup.Application;
import net.sf.openrocket.unit.UnitGroup;
@ -111,11 +105,11 @@ public class RocketComponentConfig extends JPanel {
//// Override and Mass and CG override options
tabbedPane.addTab(trans.get("RocketCompCfg.tab.Override"), null, overrideTab(),
trans.get("RocketCompCfg.tab.MassandCGoverride"));
if (component.isMassive())
if (component.isMassive()) {
//// Appearance options
tabbedPane.addTab(trans.get("RocketCompCfg.tab.Appearance"), null, new AppearancePanel(document, component),
"Appearance Tool Tip");
}
//// Comment and Specify a comment for the component
tabbedPane.addTab(trans.get("RocketCompCfg.tab.Comment"), null, commentTab(),
@ -622,12 +616,12 @@ public class RocketComponentConfig extends JPanel {
this.invalidatables.add(model);
}
public void invalidateModels() {
public void invalidate() {
super.invalidate();
for (Invalidatable i : invalidatables) {
i.invalidate();
}
((ComponentPresetDatabase) Application.getComponentPresetDao()).removeChangeListener(presetModel);
}