[#1631] Show subcomponent overridden icon

When a component's parent has the subcomponent overridden icon enabled, that component will now also have a dedicated icon, indicating that it's mass has been overridden
This commit is contained in:
SiboVG 2022-11-08 16:51:15 +01:00
parent de15bdd79b
commit 4e1c0f15fb
5 changed files with 41 additions and 14 deletions

View File

@ -930,6 +930,12 @@ RocketCompCfg.checkbox.OverrideSubcomponents = Override for all subcomponents
RocketCompCfg.checkbox.OverrideSubcomponents.Mass.ttip = <html>Overrides the aggregate mass of this component<br>and its subcomponents with the mass of this component.</html> RocketCompCfg.checkbox.OverrideSubcomponents.Mass.ttip = <html>Overrides the aggregate mass of this component<br>and its subcomponents with the mass of this component.</html>
RocketCompCfg.checkbox.OverrideSubcomponents.CG.ttip = <html>Overrides the center of gravity (CG) of this component<br>and its subcomponents with the CG of this component.</html> RocketCompCfg.checkbox.OverrideSubcomponents.CG.ttip = <html>Overrides the center of gravity (CG) of this component<br>and its subcomponents with the CG of this component.</html>
RocketCompCfg.checkbox.OverrideSubcomponents.CD.ttip = <html>Overrides the coefficient of drag (C<sub>D</sub>) of this component<br>and its subcomponents with the C<sub>D</sub> of this component.</html> RocketCompCfg.checkbox.OverrideSubcomponents.CD.ttip = <html>Overrides the coefficient of drag (C<sub>D</sub>) of this component<br>and its subcomponents with the C<sub>D</sub> of this component.</html>
RocketCompCfg.lbl.MassOverriddenBy = Mass overridden by %s
RocketCompCfg.lbl.CGOverriddenBy = CG overridden by %s
RocketCompCfg.lbl.CDOverriddenBy = <html>C<sub>D</sub> overridden by %s</html>
RocketCompCfg.lbl.MassOverriddenBy.ttip = The mass of this component is determined by the mass override value of %s
RocketCompCfg.lbl.CGOverriddenBy.ttip = The CG of this component is determined by the CG override value of %s
RocketCompCfg.lbl.CDOverriddenBy.ttip = <html>The C<sub>D</sub> of this component is determined by the C<sub>D</sub> override value of %s</html>
RocketCompCfg.lbl.longB1 = <html>The overridden mass and center of gravity does not include motors.<br> RocketCompCfg.lbl.longB1 = <html>The overridden mass and center of gravity does not include motors.<br>
RocketCompCfg.lbl.longB2 = The center of gravity is measured from the front end of the RocketCompCfg.lbl.longB2 = The center of gravity is measured from the front end of the
RocketCompCfg.lbl.Commentsonthe = Comments on the RocketCompCfg.lbl.Commentsonthe = Comments on the

View File

@ -14,8 +14,9 @@ public class ComponentChangeEvent extends EventObject {
UNDO( 16, "UNDO"), UNDO( 16, "UNDO"),
MOTOR( 32, "Motor"), MOTOR( 32, "Motor"),
EVENT( 64, "Event"), EVENT( 64, "Event"),
TEXTURE ( 128, "Texture") TEXTURE ( 128, "Texture"),
, GRAPHIC( 256, "Configuration") GRAPHIC( 256, "Configuration"),
TREE_CHILDREN( 512, "TREE_CHILDREN"),
; ;
protected int value; protected int value;
@ -45,6 +46,8 @@ public class ComponentChangeEvent extends EventObject {
/** A change that affects the rocket tree structure */ /** A change that affects the rocket tree structure */
public static final int TREE_CHANGE = TYPE.TREE.value; public static final int TREE_CHANGE = TYPE.TREE.value;
/** A change that affects the children's tree structure */
public static final int TREE_CHANGE_CHILDREN = TYPE.TREE_CHILDREN.value;
/** A change caused by undo/redo. */ /** A change caused by undo/redo. */
public static final int UNDO_CHANGE = TYPE.UNDO.value; public static final int UNDO_CHANGE = TYPE.UNDO.value;
/** A change in the motor configurations or names */ /** A change in the motor configurations or names */
@ -124,6 +127,9 @@ public class ComponentChangeEvent extends EventObject {
public boolean isTreeChange() { public boolean isTreeChange() {
return TYPE.TREE.matches(this.type); return TYPE.TREE.matches(this.type);
} }
public boolean isTreeChildrenChange() {
return TYPE.TREE_CHILDREN.matches(this.type);
}
public boolean isUndoChange() { public boolean isUndoChange() {
return TYPE.UNDO.matches(this.type); return TYPE.UNDO.matches(this.type);
@ -150,6 +156,8 @@ public class ComponentChangeEvent extends EventObject {
s += ",aero"; s += ",aero";
if (isTreeChange()) if (isTreeChange())
s += ",tree"; s += ",tree";
if (isTreeChildrenChange())
s += ",treechild";
if (isUndoChange()) if (isUndoChange())
s += ",undo"; s += ",undo";
if (isMotorChange()) if (isMotorChange())

View File

@ -819,7 +819,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
updateChildrenMassOverriddenBy(); updateChildrenMassOverriddenBy();
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE | ComponentChangeEvent.TREE_CHANGE_CHILDREN);
} }
/** /**
@ -857,7 +857,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
updateChildrenCGOverriddenBy(); updateChildrenCGOverriddenBy();
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE | ComponentChangeEvent.TREE_CHANGE_CHILDREN);
} }
/** /**
@ -897,7 +897,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
overrideSubcomponentsCD(override); overrideSubcomponentsCD(override);
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE | ComponentChangeEvent.TREE_CHANGE_CHILDREN);
} }
/** /**

View File

@ -90,9 +90,9 @@ public class ComponentTreeModel implements TreeModel, ComponentChangeListener {
private void fireTreeNodeChanged(RocketComponent node) { private void fireTreeNodeChanged(RocketComponent node) {
TreeModelEvent e = new TreeModelEvent(this, makeTreePath(node), null, null); TreeModelEvent e = new TreeModelEvent(this, makeTreePath(node), null, null);
Object[] l = listeners.toArray(); for (TreeModelListener listener : listeners) {
for (int i = 0; i < l.length; i++) listener.treeNodesChanged(e);
((TreeModelListener) l[i]).treeNodesChanged(e); }
} }
@ -147,7 +147,12 @@ public class ComponentTreeModel implements TreeModel, ComponentChangeListener {
// TODO: LOW: Could this be performed better? // TODO: LOW: Could this be performed better?
expandAll(); expandAll();
} }
} else { } else if (e.isTreeChildrenChange()) {
for (RocketComponent c : e.getSource().getAllChildren()) {
fireTreeNodeChanged(c);
}
}
else {
fireTreeNodeChanged(e.getSource()); fireTreeNodeChanged(e.getSource());
} }
} }

View File

@ -49,23 +49,31 @@ public class ComponentTreeRenderer extends DefaultTreeCellRenderer {
} else { } else {
setIcon(ComponentIcons.getSmallIcon(value.getClass())); setIcon(ComponentIcons.getSmallIcon(value.getClass()));
} }
if (c.isMassOverridden() || c.isCGOverridden() || c.isCDOverridden()) { if (c.isMassOverridden() || c.getMassOverriddenBy() != null ||
c.isCGOverridden() || c.getCGOverriddenBy() != null ||
c.isCDOverridden() || c.getCDOverriddenBy() != null) {
JPanel p = new JPanel(); JPanel p = new JPanel();
p.setLayout(new FlowLayout(FlowLayout.LEFT, 1, 1)); p.setLayout(new FlowLayout(FlowLayout.LEFT, 1, 1));
p.setBackground(UIManager.getColor("Tree.textBackground")); p.setBackground(UIManager.getColor("Tree.textBackground"));
p.setForeground(UIManager.getColor("Tree.textForeground")); p.setForeground(UIManager.getColor("Tree.textForeground"));
p.add(comp/* , BorderLayout.WEST */); p.add(comp/* , BorderLayout.WEST */);
if (c.isMassOverridden()) { if (c.getMassOverriddenBy() != null) {
p.add(new JLabel(Icons.MASS_OVERRIDE_SUBCOMPONENT));
} else if (c.isMassOverridden()) {
p.add(new JLabel(Icons.MASS_OVERRIDE)); p.add(new JLabel(Icons.MASS_OVERRIDE));
} }
if (c.isCGOverridden()) { if (c.getCGOverriddenBy() != null) {
p.add(new JLabel(Icons.CG_OVERRIDE_SUBCOMPONENT));
} else if (c.isCGOverridden()) {
p.add(new JLabel(Icons.CG_OVERRIDE)); p.add(new JLabel(Icons.CG_OVERRIDE));
} }
if (c.isCDOverridden()) { if (c.getCDOverriddenBy() != null) {
p.add(new JLabel(Icons.CD_OVERRIDE_SUBCOMPONENT));
} else if (c.isCDOverridden()) {
p.add(new JLabel(Icons.CD_OVERRIDE)); p.add(new JLabel(Icons.CD_OVERRIDE));
} }
// Make sure the tooltip also works on the override icons
if (components != null && components.size() > 1 && components.contains(c)) { if (components != null && components.size() > 1 && components.contains(c)) {
p.setToolTipText(getToolTipMultipleComponents(components)); p.setToolTipText(getToolTipMultipleComponents(components));
} else { } else {