diff --git a/core/src/net/sf/openrocket/file/openrocket/importt/DoubleSetter.java b/core/src/net/sf/openrocket/file/openrocket/importt/DoubleSetter.java index 7e8dceaa2..5d553b57b 100644 --- a/core/src/net/sf/openrocket/file/openrocket/importt/DoubleSetter.java +++ b/core/src/net/sf/openrocket/file/openrocket/importt/DoubleSetter.java @@ -4,7 +4,7 @@ import java.util.HashMap; import net.sf.openrocket.aerodynamics.Warning; import net.sf.openrocket.aerodynamics.WarningSet; -import net.sf.openrocket.rocketcomponent.FlightConfigurable; +import net.sf.openrocket.rocketcomponent.FlightConfigurableParameterSet; import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.util.Reflection; import net.sf.openrocket.util.Reflection.Method; @@ -94,7 +94,7 @@ class DoubleSetter implements Setter { if (configGetter == null) { setMethod.invoke(c, d * multiplier); } else { - FlightConfigurable config = (FlightConfigurable) configGetter.invoke(c); + FlightConfigurableParameterSet config = (FlightConfigurableParameterSet) configGetter.invoke(c); Object obj = config.getDefault(); setMethod.invoke(obj, d * multiplier); } diff --git a/core/src/net/sf/openrocket/file/openrocket/importt/EnumSetter.java b/core/src/net/sf/openrocket/file/openrocket/importt/EnumSetter.java index fda5362c2..3156c1dd2 100644 --- a/core/src/net/sf/openrocket/file/openrocket/importt/EnumSetter.java +++ b/core/src/net/sf/openrocket/file/openrocket/importt/EnumSetter.java @@ -4,7 +4,7 @@ import java.util.HashMap; import net.sf.openrocket.aerodynamics.Warning; import net.sf.openrocket.aerodynamics.WarningSet; -import net.sf.openrocket.rocketcomponent.FlightConfigurable; +import net.sf.openrocket.rocketcomponent.FlightConfigurableParameterSet; import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.util.Reflection; import net.sf.openrocket.util.Reflection.Method; @@ -38,7 +38,7 @@ class EnumSetter> implements Setter { if (configurationGetter == null) { setter.invoke(c, setEnum); } else { - FlightConfigurable config = (FlightConfigurable) configurationGetter.invoke(c); + FlightConfigurableParameterSet config = (FlightConfigurableParameterSet) configurationGetter.invoke(c); Object obj = config.getDefault(); setter.invoke(obj, setEnum); } diff --git a/core/src/net/sf/openrocket/masscalc/MassCalculator.java b/core/src/net/sf/openrocket/masscalc/MassCalculator.java index f1ed4b5d4..914460d35 100644 --- a/core/src/net/sf/openrocket/masscalc/MassCalculator.java +++ b/core/src/net/sf/openrocket/masscalc/MassCalculator.java @@ -298,7 +298,7 @@ public class MassCalculator implements Monitorable { private void calculateStageCache(FlightConfiguration config) { int stageCount = config.getActiveStageCount(); if(debug){ - System.err.println(">> Calculating massData cache for config: "+config.toShort()+" with "+stageCount+" stages"); + System.err.println(">> Calculating massData cache for config: "+config.toDebug()+" with "+stageCount+" stages"); } if( 0 < stageCount ){ for( AxialStage curStage : config.getActiveStages()){ diff --git a/core/src/net/sf/openrocket/motor/MotorConfiguration.java b/core/src/net/sf/openrocket/motor/MotorConfiguration.java index 14780d09e..2bee2f72e 100644 --- a/core/src/net/sf/openrocket/motor/MotorConfiguration.java +++ b/core/src/net/sf/openrocket/motor/MotorConfiguration.java @@ -32,7 +32,6 @@ public class MotorConfiguration implements FlightConfigurableParameter listeners = new ArrayList(); public MotorConfiguration( Motor motor ) { this(); @@ -231,24 +230,20 @@ public class MotorConfiguration implements FlightConfigurableParameter configs = (FlightConfigurable) configGetter.invoke(c); + FlightConfigurableParameterSet configs = (FlightConfigurableParameterSet) configGetter.invoke(c); return configs.get(simulation.getRocket().getDefaultConfiguration().getFlightConfigurationID()); } diff --git a/core/src/net/sf/openrocket/rocketcomponent/DeploymentConfiguration.java b/core/src/net/sf/openrocket/rocketcomponent/DeploymentConfiguration.java index 24a0f9913..9803fe921 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/DeploymentConfiguration.java +++ b/core/src/net/sf/openrocket/rocketcomponent/DeploymentConfiguration.java @@ -180,5 +180,8 @@ public class DeploymentConfiguration implements FlightConfigurableParameter - * The parameter value is always defined, and null is not a valid - * parameter value. - * - * @param the parameter type - */ -public interface FlightConfigurable extends FlightConfigurableComponent, Iterable { - - /** - * Return the default parameter value for this FlightConfiguration. - * This is used in case a per-flight configuration override - * has not been defined. - * - * @return the default parameter value (never null) - */ - public E getDefault(); - - /** - * Set the default parameter value for this FlightConfiguration. - *This is used in case a per-flight configuration override - * has not been defined. - * - * @param value the parameter value (null not allowed) - */ - public void setDefault(E value); - - /** - * Return the parameter value for the provided flight configuration ID. - * This returns either the value specified for this flight config ID, - * or the default value. - * - * @param id the flight configuration ID - * @return the parameter to use (never null) - */ - public E get(FlightConfigurationId id); - - /** - * Return the parameter value for the provided flight configuration ID. - * This returns either the value specified for this flight config ID, - * or the default value. - * - * @param value the parameter to find - * @return the flight configuration ID - */ - public FlightConfigurationId get(E value); - - /** - * Set the parameter value for the provided flight configuration ID. - * This sets the override for this flight configuration ID. - * - * @param id the flight configuration ID - * @param value the parameter value (null not allowed) - */ - public void set(FlightConfigurationId id, E value); - - /** - * - * @return a sorted list of all the contained FlightConfigurationIDs - */ - public List getSortedConfigurationIDs(); - - /** - * Return whether a specific flight configuration ID is using the - * default value. - * - * @param id the flight configuration ID - * @return whether the default is being used - */ - public boolean isDefault(FlightConfigurationId id); - - /** - * Reset a specific flight configuration ID to use the default parameter value. - * - * @param id the flight configuration ID - */ - public void reset(FlightConfigurationId id); - - /** - * Return the number of specific flight configurations other than the default. - * @return - */ - public int size(); -} diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurableParameter.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurableParameter.java index f6e32efe7..d8616731f 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurableParameter.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurableParameter.java @@ -16,4 +16,6 @@ public interface FlightConfigurableParameter extends ChangeSource { */ public E clone(); + public void update(); + } diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurableParameterSet.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurableParameterSet.java index 39bf42308..b7efd5286 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurableParameterSet.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurableParameterSet.java @@ -12,12 +12,15 @@ import net.sf.openrocket.util.StateChangeListener; import net.sf.openrocket.util.Utils; /** - * An implementation of FlightConfiguration that fires off events - * to the rocket components when the parameter value is changed. + * Represents a value or parameter that can vary based on the + * flight configuration ID. + *

+ * The parameter value is always defined, and null is not a valid + * parameter value. * * @param the parameter type */ -public class FlightConfigurableParameterSet> implements FlightConfigurable { +public class FlightConfigurableParameterSet> implements Iterable { //private static final Logger log = LoggerFactory.getLogger(ParameterSet.class); protected final HashMap map = new HashMap(); @@ -66,12 +69,24 @@ public class FlightConfigurableParameterSet getSortedConfigurationIDs(){ ArrayList toReturn = new ArrayList(); @@ -156,7 +191,13 @@ public class FlightConfigurableParameterSet + * @author Daniel Williams */ public class FlightConfiguration implements FlightConfigurableParameter, ChangeSource, ComponentChangeListener, Monitorable { private static final Logger log = LoggerFactory.getLogger(FlightConfiguration.class); @@ -42,8 +41,6 @@ public class FlightConfiguration implements FlightConfigurableParameter listenerList = new ArrayList(); - protected class StageFlags implements Cloneable { public boolean active = true; public int prev = -1; @@ -99,7 +96,6 @@ public class FlightConfiguration implements FlightConfigurableParameter(); } //////////////// Listeners //////////////// @Override public void addChangeListener(StateChangeListener listener) { - listenerList.add(listener); } @Override public void removeChangeListener(StateChangeListener listener) { - listenerList.remove(listener); } // for outgoing events only protected void fireChangeEvent() { - EventObject e = new EventObject(this); - this.modID++; boundsModID = -1; refLengthModID = -1; - // Copy the list before iterating to prevent concurrent modification exceptions. - EventListener[] listeners = listenerList.toArray(new EventListener[0]); - for (EventListener l : listeners) { - if (l instanceof StateChangeListener) { - ((StateChangeListener) l).stateChanged(e); - } - } - updateStages(); updateMotors(); } @@ -344,18 +321,14 @@ public class FlightConfiguration implements FlightConfigurableParameter(); for( StageFlags flags : this.stages.values()){ clone.stages.put( flags.stage.getStageNumber(), flags.clone()); } @@ -596,4 +573,63 @@ public class FlightConfiguration implements FlightConfigurableParameter