Merge branch 'unstable' into issue-1204

This commit is contained in:
SiboVG 2022-03-04 04:27:40 +01:00
commit ff00ace5e4
2 changed files with 30 additions and 4 deletions

View File

@ -1588,7 +1588,11 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
this.checkComponentStructure();
return children.get(n);
}
/**
* Returns all the direct children of this component. The result is a clone of the children list and may be edited.
* @return direct children of this component.
*/
public final List<RocketComponent> getChildren() {
checkState();
this.checkComponentStructure();
@ -1683,10 +1687,29 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
while ( null != curComponent ) {
if( ComponentAssembly.class.isAssignableFrom( curComponent.getClass()))
return (ComponentAssembly) curComponent;
curComponent = curComponent.parent;
}
throw new IllegalStateException("getAssembly() called on hierarchy without a ComponentAssembly.");
}
/**
* Return all the component assemblies that are a child of this component
* @return list of ComponentAssembly components that are a child of this component
*/
public final List<RocketComponent> getChildAssemblies() {
checkState();
Iterator<RocketComponent> children = iterator(false);
List<RocketComponent> result = new ArrayList<>();
while (children.hasNext()) {
RocketComponent child = children.next();
if (child instanceof ComponentAssembly) {
result.add(child);
}
}
return result;
}
/**

View File

@ -12,6 +12,7 @@ import javax.swing.JToggleButton;
import net.miginfocom.swing.MigLayout;
import net.sf.openrocket.gui.widgets.SelectColorToggleButton;
import net.sf.openrocket.rocketcomponent.AxialStage;
import net.sf.openrocket.rocketcomponent.BodyTube;
import net.sf.openrocket.rocketcomponent.ComponentChangeEvent;
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
import net.sf.openrocket.rocketcomponent.Rocket;
@ -36,7 +37,9 @@ public class StageSelector extends JPanel implements StateChangeListener {
private void updateButtons( final FlightConfiguration configuration ) {
buttons.clear();
this.removeAll();
for(RocketComponent stage : configuration.getRocket().getChildren()){
List<RocketComponent> assemblies = configuration.getRocket().getChildAssemblies();
for (RocketComponent stage : assemblies) {
if (!(stage instanceof AxialStage)) continue;
JToggleButton button = new SelectColorToggleButton(new StageAction((AxialStage) stage));
button.setSelected(configuration.isStageActive(stage.getStageNumber()));
@ -50,7 +53,7 @@ public class StageSelector extends JPanel implements StateChangeListener {
@Override
public void stateChanged(EventObject eo) {
Object source = eo.getSource();
if ((source instanceof Rocket) || (source instanceof AxialStage)) {
if ((source instanceof Rocket) || (source instanceof AxialStage) || (source instanceof BodyTube)) {
Rocket rkt = (Rocket) ((RocketComponent) source).getRoot();
updateButtons( rkt.getSelectedConfiguration() );
}