bug fixes
[debian/openrocket] / src / net / sf / openrocket / rocketcomponent / Configuration.java
index 837e9fea7803f468cc9bdd302e596ff7048c4745..404e84c326657df89d3669e0ae33ef2e1e8d120c 100644 (file)
@@ -1,6 +1,5 @@
 package net.sf.openrocket.rocketcomponent;
 
-import java.util.ArrayList;
 import java.util.BitSet;
 import java.util.Collection;
 import java.util.Collections;
@@ -12,6 +11,7 @@ import javax.swing.event.ChangeEvent;
 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;
@@ -98,14 +98,11 @@ public class Configuration implements Cloneable, ChangeSource, ComponentChangeLi
                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;
@@ -255,12 +252,20 @@ public class Configuration implements Cloneable, ChangeSource, ComponentChangeLi
        }
        
        
+       /**
+        * 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();
@@ -285,7 +290,7 @@ public class Configuration implements Cloneable, ChangeSource, ComponentChangeLi
                                cachedLength = maxX - minX;
                        }
                }
-               return (ArrayList<Coordinate>) cachedBounds.clone();
+               return cachedBounds.clone();
        }
        
        
@@ -329,7 +334,7 @@ public class Configuration implements Cloneable, ChangeSource, ComponentChangeLi
        
        /**
         * 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() {
@@ -343,7 +348,7 @@ public class Configuration implements Cloneable, ChangeSource, ComponentChangeLi
                        rocket.addComponentChangeListener(config);
                        return config;
                } catch (CloneNotSupportedException e) {
-                       throw new BugException("BUG: clone not supported!", e);
+                       throw new BugException("clone not supported!", e);
                }
        }
        
@@ -367,8 +372,8 @@ public class Configuration implements Cloneable, ChangeSource, ComponentChangeLi
                        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));
                                }
                        }