package net.sf.openrocket.rocketcomponent;
-import java.util.ArrayList;
import java.util.BitSet;
import java.util.Collection;
import java.util.Collections;
import javax.swing.event.ChangeListener;
import javax.swing.event.EventListenerList;
+import net.sf.openrocket.util.ArrayList;
import net.sf.openrocket.util.BugException;
import net.sf.openrocket.util.ChangeSource;
import net.sf.openrocket.util.Coordinate;
return isStageActive(0);
}
- public boolean isStageActive(RocketComponent stage) {
- if (!(stage instanceof Stage)) {
- throw new IllegalArgumentException("called with component " + stage);
- }
- return stages.get(stage.getParent().getChildPosition(stage));
- }
-
+
+ /**
+ * Check whether the stage specified by the index is active.
+ */
public boolean isStageActive(int stage) {
if (stage >= rocket.getStageCount())
return false;
}
+ /**
+ * Return whether a component is in the currently active stages.
+ */
+ public boolean isComponentActive(final RocketComponent c) {
+ int stage = c.getStageNumber();
+ return isStageActive(stage);
+ }
+
+
/**
* Return the bounds of the current configuration. The bounds are cached.
*
* @return a <code>Collection</code> containing coordinates bouding the rocket.
*/
- @SuppressWarnings("unchecked")
public Collection<Coordinate> getBounds() {
if (rocket.getModID() != boundsModID) {
boundsModID = rocket.getModID();
cachedLength = maxX - minX;
}
}
- return (ArrayList<Coordinate>) cachedBounds.clone();
+ return cachedBounds.clone();
}
/**
* Perform a deep-clone. The object references are also cloned and no
- * listeners are listening on the cloned object.
+ * listeners are listening on the cloned object. The rocket instance remains the same.
*/
@Override
public Configuration clone() {
rocket.addComponentChangeListener(config);
return config;
} catch (CloneNotSupportedException e) {
- throw new BugException("BUG: clone not supported!", e);
+ throw new BugException("clone not supported!", e);
}
}
List<Iterator<RocketComponent>> list = new ArrayList<Iterator<RocketComponent>>();
for (RocketComponent stage : rocket.getChildren()) {
- if (isStageActive(stage)) {
- list.add(stage.deepIterator());
+ if (isComponentActive(stage)) {
+ list.add(stage.iterator(false));
}
}