[fixes #358] Fix some issues

This commit is contained in:
SiboVG 2022-02-17 16:38:51 +01:00
parent d82c541464
commit 161120855c
4 changed files with 67 additions and 23 deletions

View File

@ -109,17 +109,17 @@ public abstract class ExternalComponent extends RocketComponent {
" type=" + mat.getType()); " type=" + mat.getType());
} }
if (material.equals(mat))
return;
material = mat;
clearPreset();
fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
for (RocketComponent listener : configListeners) { for (RocketComponent listener : configListeners) {
if (listener instanceof ExternalComponent) { if (listener instanceof ExternalComponent) {
((ExternalComponent) listener).setMaterial(mat); ((ExternalComponent) listener).setMaterial(mat);
} }
} }
if (material.equals(mat))
return;
material = mat;
clearPreset();
fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE);
} }
public Finish getFinish() { public Finish getFinish() {

View File

@ -6,6 +6,7 @@ import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.List;
import javax.swing.JDialog; import javax.swing.JDialog;
@ -42,7 +43,8 @@ public class ComponentConfigDialog extends JDialog implements ComponentChangeLis
private final Window parent; private final Window parent;
private static final Translator trans = Application.getTranslator(); private static final Translator trans = Application.getTranslator();
private ComponentConfigDialog(Window parent, OpenRocketDocument document, RocketComponent component) { private ComponentConfigDialog(Window parent, OpenRocketDocument document, RocketComponent component,
List<RocketComponent> listeners) {
super(parent); super(parent);
this.parent = parent; this.parent = parent;
@ -61,9 +63,22 @@ public class ComponentConfigDialog extends JDialog implements ComponentChangeLis
configurator.invalidate(); configurator.invalidate();
document.getRocket().removeComponentChangeListener(ComponentConfigDialog.this); document.getRocket().removeComponentChangeListener(ComponentConfigDialog.this);
ComponentConfigDialog.this.dispose(); ComponentConfigDialog.this.dispose();
component.clearConfigListeners();
} }
public void windowClosing(WindowEvent e){} public void windowClosing(WindowEvent e){}
@Override
public void windowOpened(WindowEvent e) {
super.windowOpened(e);
// Add config listeners
component.clearConfigListeners();
if (listeners != null) {
for (RocketComponent listener : listeners) {
component.addConfigListener(listener);
}
}
}
}); });
} }
@ -188,23 +203,41 @@ public class ComponentConfigDialog extends JDialog implements ComponentChangeLis
* *
* @param document the document to configure. * @param document the document to configure.
* @param component the component to configure. * @param component the component to configure.
* @param listeners config listeners for the component
*/ */
public static void showDialog(Window parent, OpenRocketDocument document, public static void showDialog(Window parent, OpenRocketDocument document,
RocketComponent component) { RocketComponent component, List<RocketComponent> listeners) {
if (dialog != null) if (dialog != null)
dialog.dispose(); dialog.dispose();
dialog = new ComponentConfigDialog(parent, document, component); dialog = new ComponentConfigDialog(parent, document, component, listeners);
dialog.setVisible(true); dialog.setVisible(true);
////Modify ////Modify
document.addUndoPosition(trans.get("ComponentCfgDlg.Modify") + " " + component.getComponentName()); document.addUndoPosition(trans.get("ComponentCfgDlg.Modify") + " " + component.getComponentName());
} }
/**
* A singleton configuration dialog. Will create and show a new dialog if one has not
* previously been used, or update the dialog and show it if a previous one exists.
*
* @param document the document to configure.
* @param component the component to configure.
*/
public static void showDialog(Window parent, OpenRocketDocument document,
RocketComponent component) {
ComponentConfigDialog.showDialog(parent, document, component, null);
}
/* package */
static void showDialog(RocketComponent component, List<RocketComponent> listeners) {
showDialog(dialog.parent, dialog.document, component, listeners);
}
/* package */ /* package */
static void showDialog(RocketComponent component) { static void showDialog(RocketComponent component) {
showDialog(dialog.parent, dialog.document, component); ComponentConfigDialog.showDialog(component, null);
} }
/** /**
@ -213,9 +246,6 @@ public class ComponentConfigDialog extends JDialog implements ComponentChangeLis
public static void hideDialog() { public static void hideDialog() {
if (dialog != null) { if (dialog != null) {
dialog.setVisible(false); dialog.setVisible(false);
if (dialog.component != null) {
dialog.component.clearConfigListeners();
}
} }
} }

View File

@ -335,16 +335,26 @@ public class BasicFrame extends JFrame {
@Override @Override
public void valueChanged(TreeSelectionEvent e) { public void valueChanged(TreeSelectionEvent e) {
// Scroll tree to the selected item // Scroll tree to the selected item
TreePath path = componentSelectionModel.getSelectionPath(); TreePath[] paths = componentSelectionModel.getSelectionPaths();
if (path == null) if (paths == null || paths.length == 0)
return; return;
tree.scrollPathToVisible(path);
for (TreePath path : paths) {
tree.scrollPathToVisible(path);
}
if (!ComponentConfigDialog.isDialogVisible()) if (!ComponentConfigDialog.isDialogVisible())
return; return;
RocketComponent c = (RocketComponent) path.getLastPathComponent(); RocketComponent c = (RocketComponent) paths[0].getLastPathComponent();
List<RocketComponent> listeners = new ArrayList<>();
for (int i = 1; i < paths.length; i++) {
RocketComponent listener = (RocketComponent) paths[i].getLastPathComponent();
if (listener.getClass().equals(c.getClass())) {
listeners.add((RocketComponent) paths[i].getLastPathComponent());
}
}
ComponentConfigDialog.showDialog(BasicFrame.this, ComponentConfigDialog.showDialog(BasicFrame.this,
BasicFrame.this.document, c); BasicFrame.this.document, c, listeners);
} }
}); });

View File

@ -790,11 +790,15 @@ public class RocketActions {
if (!checkAllClassesEqual(components)) if (!checkAllClassesEqual(components))
return; return;
for (int i = 1; i < components.size(); i++) { // Do nothing if the config dialog is already visible
components.get(0).addConfigListener(components.get(i)); if (ComponentConfigDialog.isDialogVisible())
} return;
ComponentConfigDialog.showDialog(parentFrame, document, components.get(0)); List<RocketComponent> listeners = null;
if (components.size() > 1) {
listeners = components.subList(1, components.size());
}
ComponentConfigDialog.showDialog(parentFrame, document, components.get(0), listeners);
} }
@Override @Override