Fix AppearanceBuilder change listener removal

This commit is contained in:
SiboVG 2022-06-15 19:22:39 +02:00
parent 05a033dee4
commit ab8fe16b62
3 changed files with 16 additions and 28 deletions

View File

@ -3,9 +3,6 @@ package net.sf.openrocket.gui.configdialog;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.lang.reflect.Method;
import java.util.EventObject;
@ -61,7 +58,7 @@ import net.sf.openrocket.util.LineStyle;
import net.sf.openrocket.util.StateChangeListener;
import net.sf.openrocket.gui.widgets.SelectColorButton;
public class AppearancePanel extends JPanel implements WindowListener {
public class AppearancePanel extends JPanel {
private static final long serialVersionUID = 2709187552673202019L;
private static final Translator trans = Application.getTranslator();
@ -110,14 +107,7 @@ public class AppearancePanel extends JPanel implements WindowListener {
private static final JColorChooser colorChooser = new JColorChooser();
@Override
public void windowOpened(WindowEvent e) {}
@Override
public void windowClosing(WindowEvent e) {}
@Override
public void windowClosed(WindowEvent e) {
public void clearConfigListeners() {
if (ab != null) {
ab.clearConfigListeners();
}
@ -126,18 +116,6 @@ public class AppearancePanel extends JPanel implements WindowListener {
}
}
@Override
public void windowIconified(WindowEvent e) {}
@Override
public void windowDeiconified(WindowEvent e) {}
@Override
public void windowActivated(WindowEvent e) {}
@Override
public void windowDeactivated(WindowEvent e) {}
private class ColorActionListener implements ActionListener {
private final String valueName;
private final Object o;

View File

@ -17,6 +17,7 @@ import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.rocketcomponent.AxialStage;
import net.sf.openrocket.rocketcomponent.ComponentChangeEvent;
import net.sf.openrocket.rocketcomponent.ComponentChangeListener;
import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.startup.Application;
import net.sf.openrocket.util.BugException;
@ -64,6 +65,7 @@ public class ComponentConfigDialog extends JDialog implements ComponentChangeLis
* In fact, it should trigger for any method of closing the dialog.
*/
public void windowClosed(WindowEvent e){
configurator.clearConfigListeners();
configurator.invalidate();
document.getRocket().removeComponentChangeListener(ComponentConfigDialog.this);
ComponentConfigDialog.this.dispose();
@ -231,9 +233,10 @@ public class ComponentConfigDialog extends JDialog implements ComponentChangeLis
*/
public static void showDialog(Window parent, OpenRocketDocument document, RocketComponent component, boolean rememberPreviousTab) {
if (dialog != null) {
// Don't remember the previous tab for stages, because this will leave you in the override tab for
// Don't remember the previous tab for rockets or stages, because this will leave you in the override tab for
// the next component, which is generally not what you want.
if (dialog.getComponent() instanceof AxialStage && !(component instanceof AxialStage)) {
if (dialog.getComponent() instanceof Rocket ||
(dialog.getComponent() instanceof AxialStage && !(component instanceof AxialStage))) {
previousSelectedTab = null;
} else {
previousSelectedTab = dialog.getSelectedTabName();

View File

@ -66,6 +66,7 @@ public class RocketComponentConfig extends JPanel {
private final TextFieldListener textFieldListener;
private JPanel buttonPanel;
private AppearancePanel appearancePanel = null;
private JLabel infoLabel;
private StyledLabel multiCompEditLabel;
@ -125,7 +126,8 @@ public class RocketComponentConfig extends JPanel {
trans.get("RocketCompCfg.tab.MassandCGoverride"));
if (allMassive) {
//// Appearance options
tabbedPane.addTab(trans.get("RocketCompCfg.tab.Appearance"), null, new AppearancePanel(document, component),
appearancePanel = new AppearancePanel(document, component);
tabbedPane.addTab(trans.get("RocketCompCfg.tab.Appearance"), null, appearancePanel,
"Appearance Tool Tip");
}
@ -237,7 +239,12 @@ public class RocketComponentConfig extends JPanel {
multiCompEditLabel.setText("");
}
}
public void clearConfigListeners() {
if (appearancePanel != null) {
appearancePanel.clearConfigListeners();
}
}
protected JPanel materialPanel(Material.Type type) {
////Component material: and Component finish: