From b3c1c5fac1e23175e6a949c72dbe524364ee86eb Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Mon, 12 Oct 2015 12:20:45 -0400 Subject: [PATCH] [Bugfix] Cleaning up FlightConfigurationID handling. Multiple Fixes. -Fixed Motor Choosing UI Function -Fixed Motor Remove UI Function -Fixed UI display bug: pass FlightConfigIDs instead of naked Strings. -FlightConfigurationIDs now filter out keytext only. (spurious "key: " appended) -Fixed extra de-select when navigating MotorSelection / FlightConfig selection tables - code no longer sets selected cell / config as the default item --- .../file/openrocket/OpenRocketSaver.java | 2 +- .../openrocket/importt/MotorMountHandler.java | 17 +++ .../openrocket/savers/AxialStageSaver.java | 2 +- .../savers/RecoveryDeviceSaver.java | 2 +- .../savers/RocketComponentSaver.java | 14 ++- .../file/openrocket/savers/RocketSaver.java | 2 +- .../openrocket/masscalc/MassCalculator.java | 4 +- .../sf/openrocket/motor/MotorInstance.java | 46 ++++---- .../motor/MotorInstanceConfiguration.java | 32 +++--- .../sf/openrocket/motor/MotorInstanceId.java | 5 +- .../motor/ThrustCurveMotorInstance.java | 17 +++ .../openrocket/rocketcomponent/BodyTube.java | 32 ++++-- .../rocketcomponent/ComponentChangeEvent.java | 4 +- .../rocketcomponent/FlightConfigurable.java | 10 ++ .../rocketcomponent/FlightConfiguration.java | 4 +- .../FlightConfigurationID.java | 14 ++- .../FlightConfigurationSet.java | 19 +++- .../openrocket/rocketcomponent/InnerTube.java | 20 +++- .../sf/openrocket/rocketcomponent/Rocket.java | 14 ++- .../BasicEventSimulationEngine.java | 2 +- .../simulation/SimulationConditions.java | 9 +- .../simulation/SimulationOptions.java | 2 +- .../adaptors/FlightConfigurationModel.java | 7 +- .../IgnitionSelectionDialog.java | 43 ++++--- .../SeparationSelectionDialog.java | 7 +- .../gui/dialogs/motor/MotorChooserDialog.java | 8 +- .../motor/thrustcurve/MotorRowFilter.java | 4 +- .../ThrustCurveMotorSelectionPanel.java | 51 ++++++--- .../FlightConfigurablePanel.java | 48 ++++---- .../FlightConfigurableTableModel.java | 24 ++-- .../FlightConfigurationPanel.java | 3 +- .../MotorConfigurationPanel.java | 105 ++++++++++-------- 32 files changed, 362 insertions(+), 211 deletions(-) diff --git a/core/src/net/sf/openrocket/file/openrocket/OpenRocketSaver.java b/core/src/net/sf/openrocket/file/openrocket/OpenRocketSaver.java index 6390fa3f1..27a4361fb 100644 --- a/core/src/net/sf/openrocket/file/openrocket/OpenRocketSaver.java +++ b/core/src/net/sf/openrocket/file/openrocket/OpenRocketSaver.java @@ -502,7 +502,7 @@ public class OpenRocketSaver extends RocketSaver { writeln(""); indent++; - writeElement("configid", cond.getConfigID()); + writeElement("configid", cond.getConfigID().key); writeElement("launchrodlength", cond.getLaunchRodLength()); writeElement("launchrodangle", cond.getLaunchRodAngle() * 180.0 / Math.PI); writeElement("launchroddirection", cond.getLaunchRodDirection() * 360.0 / (2.0 * Math.PI)); diff --git a/core/src/net/sf/openrocket/file/openrocket/importt/MotorMountHandler.java b/core/src/net/sf/openrocket/file/openrocket/importt/MotorMountHandler.java index 2c367307e..1a7681ca6 100644 --- a/core/src/net/sf/openrocket/file/openrocket/importt/MotorMountHandler.java +++ b/core/src/net/sf/openrocket/file/openrocket/importt/MotorMountHandler.java @@ -57,8 +57,11 @@ class MotorMountHandler extends AbstractElementHandler { @Override public void closeElement(String element, HashMap attributes, String content, WarningSet warnings) throws SAXException { + // DEBUG ONLY + // System.err.println("closing MotorMount element: "+ element); if (element.equals("motor")) { + // yes, this is confirmed to be the FLIGHT config id, instead of the motor inastance id. FlightConfigurationID fcid = new FlightConfigurationID(attributes.get("configid")); if (!fcid.isValid()) { warnings.add(Warning.fromString("Illegal motor specification, ignoring.")); @@ -69,6 +72,20 @@ class MotorMountHandler extends AbstractElementHandler { MotorInstance motorInstance = motor.getNewInstance(); motorInstance.setEjectionDelay(motorHandler.getDelay(warnings)); mount.setMotorInstance(fcid, motorInstance); +// // vvvvvvv DEBUG vvvvvvv +// System.err.println(" processing element:"+fcid.key); +// MotorInstance justSet = mount.getMotorInstance(fcid); +// System.err.println(" just set Motor: "+motor.getDesignation()+" to Mount: "+((RocketComponent)mount).getName()+"."); +// String contains; +// if( justSet.isEmpty()){ +// contains = "empty"; +// }else{ +// contains = justSet.getMotor().getDesignation(); +// } +// System.err.println(" to Motor: "+justSet.getMotorID()+ " containing: "+contains); +// System.err.println(" mount now contains "+mount.getMotorCount()+" motors."); +// // ... well, we know it's at least 2 configurations now.... +// // ^^^^^^^ DEBUG ^^^^^^^^ return; } diff --git a/core/src/net/sf/openrocket/file/openrocket/savers/AxialStageSaver.java b/core/src/net/sf/openrocket/file/openrocket/savers/AxialStageSaver.java index 04b5b14b2..66a5c3da1 100644 --- a/core/src/net/sf/openrocket/file/openrocket/savers/AxialStageSaver.java +++ b/core/src/net/sf/openrocket/file/openrocket/savers/AxialStageSaver.java @@ -64,7 +64,7 @@ public class AxialStageSaver extends ComponentAssemblySaver { } StageSeparationConfiguration separationConfig = stage.getSeparationConfigurations().get(fcid); - elements.add(""); + elements.add(""); elements.addAll(separationConfig(separationConfig, true)); elements.add(""); diff --git a/core/src/net/sf/openrocket/file/openrocket/savers/RecoveryDeviceSaver.java b/core/src/net/sf/openrocket/file/openrocket/savers/RecoveryDeviceSaver.java index c37541ed1..c6effb9ad 100644 --- a/core/src/net/sf/openrocket/file/openrocket/savers/RecoveryDeviceSaver.java +++ b/core/src/net/sf/openrocket/file/openrocket/savers/RecoveryDeviceSaver.java @@ -47,7 +47,7 @@ public class RecoveryDeviceSaver extends MassObjectSaver { } DeploymentConfiguration deployConfig = dev.getDeploymentConfigurations().get(fcid); - elements.add(""); + elements.add(""); elements.addAll(deploymentConfiguration(deployConfig, true)); elements.add(""); } diff --git a/core/src/net/sf/openrocket/file/openrocket/savers/RocketComponentSaver.java b/core/src/net/sf/openrocket/file/openrocket/savers/RocketComponentSaver.java index a3c556ead..f75eccaab 100644 --- a/core/src/net/sf/openrocket/file/openrocket/savers/RocketComponentSaver.java +++ b/core/src/net/sf/openrocket/file/openrocket/savers/RocketComponentSaver.java @@ -164,13 +164,15 @@ public class RocketComponentSaver { for (FlightConfiguration curConfig : configs) { FlightConfigurationID fcid = curConfig.getFlightConfigurationID(); - MotorInstance motorInstance = mount.getMotorInstance(fcid); - Motor motor = motorInstance.getMotor(); - // Nothing is stored if no motor loaded - if (motor == null) - continue; - elements.add(" "); + MotorInstance motorInstance = mount.getMotorInstance(fcid); + // Nothing is stored if no motor loaded + if( motorInstance.isEmpty()){ + continue; + } + Motor motor = motorInstance.getMotor(); + + elements.add(" "); if (motor.getMotorType() != Motor.Type.UNKNOWN) { elements.add(" " + motor.getMotorType().name().toLowerCase(Locale.ENGLISH) + ""); } diff --git a/core/src/net/sf/openrocket/file/openrocket/savers/RocketSaver.java b/core/src/net/sf/openrocket/file/openrocket/savers/RocketSaver.java index 1d6198ab9..4fe6007e0 100644 --- a/core/src/net/sf/openrocket/file/openrocket/savers/RocketSaver.java +++ b/core/src/net/sf/openrocket/file/openrocket/savers/RocketSaver.java @@ -48,7 +48,7 @@ public class RocketSaver extends RocketComponentSaver { if (fcid == null) continue; - String str = ".getActiveMotors()"); } MotorMount mount = inst.getMount(); if( null == mount ){ diff --git a/core/src/net/sf/openrocket/motor/MotorInstance.java b/core/src/net/sf/openrocket/motor/MotorInstance.java index a18b3f98d..33e0ef854 100644 --- a/core/src/net/sf/openrocket/motor/MotorInstance.java +++ b/core/src/net/sf/openrocket/motor/MotorInstance.java @@ -17,9 +17,10 @@ import net.sf.openrocket.util.StateChangeListener; */ public class MotorInstance implements FlightConfigurableParameter { - protected MotorInstanceId id = null; - protected MotorMount mount = null; - //protected Motor motor = null; // deferred to subclasses + protected MotorInstanceId id = null; + // deferred to subclasses + //protected MotorMount mount = null; + //protected Motor motor = null; protected double ejectionDelay = 0.0; protected double ignitionDelay = 0.0; protected IgnitionEvent ignitionEvent = IgnitionEvent.NEVER; @@ -27,7 +28,7 @@ public class MotorInstance implements FlightConfigurableParameter protected double ignitionTime = 0.0; // comparison threshold - private static final double EPSILON = 0.01; + //private static final double EPSILON = 0.01; protected int modID = 0; private final List listeners = new ArrayList(); @@ -40,7 +41,7 @@ public class MotorInstance implements FlightConfigurableParameter modID++; } - public MotorInstanceId getID() { + public MotorInstanceId getMotorID() { return this.id; } @@ -65,11 +66,11 @@ public class MotorInstance implements FlightConfigurableParameter }; public MotorMount getMount() { - return this.mount; + throw new UnsupportedOperationException("Retrieve a mount from an immutable no-motors instance"); } public void setMount(final MotorMount _mount) { - this.mount = _mount; + throw new UnsupportedOperationException("Retrieve a mount from an immutable no-motors instance"); } public Coordinate getPosition() { @@ -165,7 +166,11 @@ public class MotorInstance implements FlightConfigurableParameter } public boolean isEmpty(){ - return this == MotorInstance.EMPTY_INSTANCE; + return true; + } + + public boolean hasMotor(){ + return ! this.isEmpty(); } @Override @@ -176,19 +181,20 @@ public class MotorInstance implements FlightConfigurableParameter MotorInstance omi = (MotorInstance)other; if( this.id.equals( omi.id)){ return true; - }else if( this.mount != omi.mount ){ - return false; - }else if( this.ignitionEvent == omi.ignitionEvent ){ - return false; - }else if( EPSILON < Math.abs(this.ignitionDelay - omi.ignitionDelay )){ - return false; - }else if( EPSILON < Math.abs( this.ejectionDelay - omi.ejectionDelay )){ - return false; - }else if( ! this.position.equals( omi.position )){ - return false; - }else if( EPSILON < Math.abs( this.ignitionTime - omi.ignitionTime )){ - return false; } +// }else if( this.mount != omi.mount ){ +// return false; +// }else if( this.ignitionEvent == omi.ignitionEvent ){ +// return false; +// }else if( EPSILON < Math.abs(this.ignitionDelay - omi.ignitionDelay )){ +// return false; +// }else if( EPSILON < Math.abs( this.ejectionDelay - omi.ejectionDelay )){ +// return false; +// }else if( ! this.position.equals( omi.position )){ +// return false; +// }else if( EPSILON < Math.abs( this.ignitionTime - omi.ignitionTime )){ +// return false; +// } return true; } diff --git a/core/src/net/sf/openrocket/motor/MotorInstanceConfiguration.java b/core/src/net/sf/openrocket/motor/MotorInstanceConfiguration.java index acb08c7df..0982927d3 100644 --- a/core/src/net/sf/openrocket/motor/MotorInstanceConfiguration.java +++ b/core/src/net/sf/openrocket/motor/MotorInstanceConfiguration.java @@ -7,9 +7,6 @@ import java.util.Set; import net.sf.openrocket.models.atmosphere.AtmosphericConditions; import net.sf.openrocket.rocketcomponent.FlightConfiguration; -import net.sf.openrocket.rocketcomponent.FlightConfigurationID; -import net.sf.openrocket.rocketcomponent.MotorMount; -import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.util.Monitorable; /** @@ -34,16 +31,16 @@ public class MotorInstanceConfiguration implements Cloneable, Iterable iterator = configuration.getRocket().iterator(false); - while (iterator.hasNext()) { - RocketComponent component = iterator.next(); - if (component instanceof MotorMount) { - MotorMount mount = (MotorMount) component; - - // MotorInstance motorInst = mount.getMotorInstance(flightConfigId); - // IgnitionConfiguration ignitionConfig = mount.getIgnitionConfiguration().get(flightConfigId); +// Iterator iterator = configuration.getRocket().iterator(false); +// while (iterator.hasNext()) { +// RocketComponent component = iterator.next(); +// if (component instanceof MotorMount) { +// MotorMount mount = (MotorMount) component; +// +// // MotorInstance motorInst = mount.getMotorInstance(flightConfigId); +// // IgnitionConfiguration ignitionConfig = mount.getIgnitionConfiguration().get(flightConfigId); // // Iterator iter = mount.getMotorIterator(); // @@ -65,10 +62,9 @@ public class MotorInstanceConfiguration implements Cloneable, Iterable getMotorIterator(){ return this.motors.iterator(); @@ -399,15 +409,15 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial @Override public void setMotorMount(boolean _active){ - if (this.isActing == _active) + if (this.isActingMount == _active) return; - this.isActing = _active; + this.isActingMount = _active; fireComponentChangeEvent(ComponentChangeEvent.MOTOR_CHANGE); } @Override public boolean isMotorMount(){ - return this.isActing; + return this.isActingMount; } @Override diff --git a/core/src/net/sf/openrocket/rocketcomponent/ComponentChangeEvent.java b/core/src/net/sf/openrocket/rocketcomponent/ComponentChangeEvent.java index ff5d6c8b1..e41a2cac0 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/ComponentChangeEvent.java +++ b/core/src/net/sf/openrocket/rocketcomponent/ComponentChangeEvent.java @@ -26,8 +26,8 @@ public class ComponentChangeEvent extends EventObject { /** A change to the 3D texture assigned to a component*/ public static final int TEXTURE_CHANGE = 128; - /** A bit-field that contains all possible change types. */ - public static final int ALL_CHANGE = 0xFFFFFFFF; + /** A bit-field that contains all possible change types. Will output as -1 */ + public static final int ALL_CHANGE = 0xFFFFFFFF; // =-1; // because int is a signed type. private final int type; diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurable.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurable.java index a2b042ac9..a0349d071 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurable.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurable.java @@ -41,6 +41,16 @@ public interface FlightConfigurable extends FlightConfig */ 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. diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java index 2f7e5f77e..e796be135 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java @@ -205,9 +205,9 @@ public class FlightConfiguration implements FlightConfigurableParameter instanceList = mount.getMotorInstance(this.fcid); MotorInstance inst = mount.getMotorInstance(this.fcid); - if( MotorInstance.EMPTY_INSTANCE == inst){ + if(( mount.isMotorMount()) && ( MotorInstance.EMPTY_INSTANCE == inst)){ // DEVEL - log.error("Detected 'Empty' Motor Instance in configuration: "+this.getName()+" / "+comp.getName()+" / (#)"); + log.error("Detected 'Empty' Motor Instance on Activated MotorMount: "+this.getName()+" / "+comp.getName()+" / (#)"); continue; } diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurationID.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurationID.java index 4b2e15d70..b629d9b14 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurationID.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurationID.java @@ -26,7 +26,17 @@ public final class FlightConfigurationID implements Comparable_val.length()){ this.key = FlightConfigurationID.ERROR_CONFIGURATION_KEY; } else { - this.key = _val; + // vv temp vv + String temp_val = _val; + final String extra = "key: "; + if( _val.contains(extra)){ + int index = temp_val.lastIndexOf(extra); + temp_val = _val.substring(index+extra.length()); + System.err.println(" correcting FCID from \""+_val+"\" to \""+temp_val+"\"."); + } + // ^^ temp ^^ + + this.key = temp_val; } } @@ -63,7 +73,7 @@ public final class FlightConfigurationID implements Comparable> im return map.size(); } - + @Override + public FlightConfigurationID get(E testValue) { + if( null == testValue ){ + return null; + } + for( Entry curEntry : this.map.entrySet()){ + FlightConfigurationID curKey = curEntry.getKey(); + E curValue = curEntry.getValue(); + + if( testValue.equals(curValue)){ + return curKey; + } + } + + return null; + } + @Override public E get(FlightConfigurationID id) { E toReturn; diff --git a/core/src/net/sf/openrocket/rocketcomponent/InnerTube.java b/core/src/net/sf/openrocket/rocketcomponent/InnerTube.java index 50962fcc9..784b41537 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/InnerTube.java +++ b/core/src/net/sf/openrocket/rocketcomponent/InnerTube.java @@ -10,7 +10,6 @@ import org.slf4j.LoggerFactory; import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.motor.Motor; import net.sf.openrocket.motor.MotorInstance; -import net.sf.openrocket.motor.MotorInstanceId; import net.sf.openrocket.preset.ComponentPreset; import net.sf.openrocket.startup.Application; import net.sf.openrocket.util.BugException; @@ -259,12 +258,21 @@ public class InnerTube extends ThicknessRingComponent implements Clusterable, Ra @Override public void setMotorInstance(final FlightConfigurationID fcid, final MotorInstance newMotorInstance){ + if( null == fcid){ + throw new NullPointerException(" null FCID passed passed to 'setMotorInstance(...)': bug "); + } + if( null == newMotorInstance){ + throw new NullPointerException(" null passed as MotorInstance to add to MotorSet ... bug "); + } + this.motors.set(fcid,newMotorInstance); - if( null != newMotorInstance ){ - newMotorInstance.setMount( this); - if( MotorInstanceId.EMPTY_ID != newMotorInstance.getID()){ - this.setMotorMount(true); - } + + if( newMotorInstance.isEmpty() ){ + return; + }else if( null == newMotorInstance.getMount()){ + newMotorInstance.setMount(this); + }else if( !this.equals( newMotorInstance.getMount())){ + throw new BugException(" adding a MotorInstance to a mount that it isn't owned by... "); } } diff --git a/core/src/net/sf/openrocket/rocketcomponent/Rocket.java b/core/src/net/sf/openrocket/rocketcomponent/Rocket.java index 6f0c87e9b..10a7af932 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/Rocket.java +++ b/core/src/net/sf/openrocket/rocketcomponent/Rocket.java @@ -401,6 +401,9 @@ public class Rocket extends RocketComponent { return; } + if( -1 == e.getType()){ + log.debug(">>fireComponentChangeEvent()>> . . ."); + } // Notify all components first Iterator iterator = this.iterator(true); while (iterator.hasNext()) { @@ -513,14 +516,23 @@ public class Rocket extends RocketComponent { } this.setFlightConfiguration( fcid, nextConfig ); - fireComponentChangeEvent(ComponentChangeEvent.MOTOR_CHANGE); + fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); return nextConfig; } + public int getConfigurationCount(){ + return this.configurations.size(); + } + public FlightConfigurationSet getConfigurationSet(){ checkState(); return this.configurations; } + + public FlightConfiguration getFlightConfig( final FlightConfigurationID fcid ){ + checkState(); + return this.configurations.get(fcid); + } public Vector getSortedConfigurationIDs(){ // if the configuration list has changed, refresh it. diff --git a/core/src/net/sf/openrocket/simulation/BasicEventSimulationEngine.java b/core/src/net/sf/openrocket/simulation/BasicEventSimulationEngine.java index 67081d649..0b3c2bdeb 100644 --- a/core/src/net/sf/openrocket/simulation/BasicEventSimulationEngine.java +++ b/core/src/net/sf/openrocket/simulation/BasicEventSimulationEngine.java @@ -448,7 +448,7 @@ public class BasicEventSimulationEngine implements SimulationEngine { // Check whether any motor in the active stages is active anymore List activeMotors = status.getConfiguration().getActiveMotors(); for (MotorInstance curInstance : activeMotors) { - MotorInstanceId curID = curInstance.getID(); + MotorInstanceId curID = curInstance.getMotorID(); RocketComponent comp = ((RocketComponent) curInstance.getMount()); int stage = comp.getStageNumber(); if (!status.getConfiguration().isStageActive(stage)) diff --git a/core/src/net/sf/openrocket/simulation/SimulationConditions.java b/core/src/net/sf/openrocket/simulation/SimulationConditions.java index b01ab8d73..64c5e7153 100644 --- a/core/src/net/sf/openrocket/simulation/SimulationConditions.java +++ b/core/src/net/sf/openrocket/simulation/SimulationConditions.java @@ -28,7 +28,7 @@ import net.sf.openrocket.util.WorldCoordinate; public class SimulationConditions implements Monitorable, Cloneable { private Rocket rocket; - private FlightConfigurationID motorID = null; + private FlightConfigurationID configID= null; private Simulation simulation; // The parent simulation @@ -116,12 +116,11 @@ public class SimulationConditions implements Monitorable, Cloneable { public FlightConfigurationID getMotorConfigurationID() { - return motorID; + return configID; } - - public void setMotorConfigurationID(FlightConfigurationID motorID) { - this.motorID = motorID; + public void setFlightConfigurationID(FlightConfigurationID _fcid) { + this.configID = _fcid; this.modID++; } diff --git a/core/src/net/sf/openrocket/simulation/SimulationOptions.java b/core/src/net/sf/openrocket/simulation/SimulationOptions.java index b1e14f42f..8ec326baa 100644 --- a/core/src/net/sf/openrocket/simulation/SimulationOptions.java +++ b/core/src/net/sf/openrocket/simulation/SimulationOptions.java @@ -621,7 +621,7 @@ public class SimulationOptions implements ChangeSource, Cloneable { SimulationConditions conditions = new SimulationConditions(); conditions.setRocket((Rocket) getRocket().copy()); - conditions.setMotorConfigurationID(this.getConfigID()); + conditions.setFlightConfigurationID(this.getConfigID()); conditions.setLaunchRodLength(getLaunchRodLength()); conditions.setLaunchRodAngle(getLaunchRodAngle()); conditions.setLaunchRodDirection(getLaunchRodDirection()); diff --git a/swing/src/net/sf/openrocket/gui/adaptors/FlightConfigurationModel.java b/swing/src/net/sf/openrocket/gui/adaptors/FlightConfigurationModel.java index fc45cf47a..cb584ebc5 100644 --- a/swing/src/net/sf/openrocket/gui/adaptors/FlightConfigurationModel.java +++ b/swing/src/net/sf/openrocket/gui/adaptors/FlightConfigurationModel.java @@ -72,10 +72,9 @@ public class FlightConfigurationModel implements ComboBoxModel configs= rocket.getConfigurationSet(); - - configs.setDefault( configs.get(fcid)); - this.config = rocket.getDefaultConfiguration(); + FlightConfigurationSet configSet = rocket.getConfigurationSet(); + + this.config = configSet.get(fcid); } diff --git a/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/IgnitionSelectionDialog.java b/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/IgnitionSelectionDialog.java index a339bc252..24f987bb0 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/IgnitionSelectionDialog.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/IgnitionSelectionDialog.java @@ -15,7 +15,6 @@ import javax.swing.JRadioButton; import javax.swing.JSpinner; import net.miginfocom.swing.MigLayout; -import net.sf.openrocket.formatting.RocketDescriptor; import net.sf.openrocket.gui.SpinnerEditor; import net.sf.openrocket.gui.adaptors.DoubleModel; import net.sf.openrocket.gui.util.GUIUtil; @@ -24,35 +23,39 @@ import net.sf.openrocket.motor.MotorInstance; import net.sf.openrocket.rocketcomponent.FlightConfigurationID; import net.sf.openrocket.rocketcomponent.IgnitionEvent; import net.sf.openrocket.rocketcomponent.MotorMount; -import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.startup.Application; import net.sf.openrocket.unit.UnitGroup; public class IgnitionSelectionDialog extends JDialog { - + private static final long serialVersionUID = -3399966098520607837L; + private static final Translator trans = Application.getTranslator(); - private RocketDescriptor descriptor = Application.getInjector().getInstance(RocketDescriptor.class); + //private RocketDescriptor descriptor = Application.getInjector().getInstance(RocketDescriptor.class); - private MotorInstance curMotor; - //private IgnitionConfiguration newConfiguration; + private MotorMount curMount; + private MotorInstance destMotorInstance; - public IgnitionSelectionDialog(Window parent, final Rocket rocket, final MotorMount component) { + private IgnitionEvent startIgnEvent; + private double ignitionDelay; + + public IgnitionSelectionDialog(Window parent, final FlightConfigurationID curFCID, MotorMount _mount) { super(parent, trans.get("edtmotorconfdlg.title.Selectignitionconf"), Dialog.ModalityType.APPLICATION_MODAL); - final FlightConfigurationID id = rocket.getDefaultConfiguration().getFlightConfigurationID(); - - curMotor = component.getMotorInstance(id); - MotorInstance defMotor = component.getDefaultMotorInstance(); + curMount = _mount; + destMotorInstance = curMount.getMotorInstance(curFCID); + startIgnEvent = destMotorInstance.getIgnitionEvent(); + ignitionDelay = destMotorInstance.getIgnitionDelay(); + final MotorInstance defaultMotorInstance = curMount.getDefaultMotorInstance(); JPanel panel = new JPanel(new MigLayout("fill")); // Edit default or override option - boolean isDefault = (defMotor.equals( curMotor)); + boolean isDefault = curMount.isDefaultMotorInstance( destMotorInstance ); panel.add(new JLabel(trans.get("IgnitionSelectionDialog.opt.title")), "span, wrap rel"); final JRadioButton defaultButton = new JRadioButton(trans.get("IgnitionSelectionDialog.opt.default"), isDefault); panel.add(defaultButton, "span, gapleft para, wrap rel"); String str = trans.get("IgnitionSelectionDialog.opt.override"); - str = str.replace("{0}", descriptor.format(rocket, id)); + //str = str.replace("{0}", descriptor.format(rocket, id)); final JRadioButton overrideButton = new JRadioButton(str, !isDefault); panel.add(overrideButton, "span, gapleft para, wrap para"); @@ -79,7 +82,7 @@ public class IgnitionSelectionDialog extends JDialog { //// plus panel.add(new JLabel(trans.get("MotorCfg.lbl.plus")), "gap indent, skip 1, span, split"); - DoubleModel delay = new DoubleModel(curMotor, "IgnitionDelay", UnitGroup.UNITS_SHORT_TIME, 0); + DoubleModel delay = new DoubleModel(destMotorInstance, "IgnitionDelay", UnitGroup.UNITS_SHORT_TIME, 0); JSpinner spin = new JSpinner(delay.getSpinnerModel()); spin.setEditor(new SpinnerEditor(spin, 3)); panel.add(spin, "gap rel rel"); @@ -93,12 +96,15 @@ public class IgnitionSelectionDialog extends JDialog { okButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - MotorInstance defMotor = component.getDefaultMotorInstance(); if (defaultButton.isSelected()) { - component.setMotorInstance(id, defMotor); + System.err.println("setting motor ignition to.... default values"); + + destMotorInstance.setIgnitionDelay( defaultMotorInstance.getIgnitionDelay()); + destMotorInstance.setIgnitionEvent( defaultMotorInstance.getIgnitionEvent()); } else { - component.setMotorInstance(id, curMotor); + System.err.println("setting motor ignition to.... new values: "); + System.err.println(" "+destMotorInstance.getIgnitionEvent()+" w/ "+destMotorInstance.getIgnitionDelay()); } IgnitionSelectionDialog.this.setVisible(false); } @@ -112,6 +118,9 @@ public class IgnitionSelectionDialog extends JDialog { @Override public void actionPerformed(ActionEvent e) { IgnitionSelectionDialog.this.setVisible(false); + // if cancelled, reset to starting values + destMotorInstance.setIgnitionEvent( startIgnEvent ); + destMotorInstance.setIgnitionDelay( ignitionDelay ); } }); diff --git a/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/SeparationSelectionDialog.java b/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/SeparationSelectionDialog.java index c33f93881..b488bb959 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/SeparationSelectionDialog.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/SeparationSelectionDialog.java @@ -23,7 +23,6 @@ import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.rocketcomponent.AxialStage; import net.sf.openrocket.rocketcomponent.FlightConfigurationID; -import net.sf.openrocket.rocketcomponent.FlightConfigurationSet; import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.StageSeparationConfiguration; import net.sf.openrocket.rocketcomponent.StageSeparationConfiguration.SeparationEvent; @@ -94,9 +93,9 @@ public class SeparationSelectionDialog extends JDialog { @Override public void actionPerformed(ActionEvent e) { if (defaultButton.isSelected()) { - FlightConfigurationSet sepConfigSet = component.getSeparationConfigurations(); - StageSeparationConfiguration sepConfig = sepConfigSet.get(FlightConfigurationID.DEFAULT_CONFIGURATION_ID); - component.getSeparationConfigurations().setDefault( sepConfig); +// FlightConfigurationSet sepConfigSet = component.getSeparationConfigurations(); +// StageSeparationConfiguration sepConfig = sepConfigSet.get(FlightConfigurationID.DEFAULT_CONFIGURATION_ID); +// component.getSeparationConfigurations().setDefault( sepConfig); // old version //component.getSeparationConfigurations().setDefault( fcid?, newConfiguration); } else { diff --git a/swing/src/net/sf/openrocket/gui/dialogs/motor/MotorChooserDialog.java b/swing/src/net/sf/openrocket/gui/dialogs/motor/MotorChooserDialog.java index 63a97570e..30400543c 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/motor/MotorChooserDialog.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/motor/MotorChooserDialog.java @@ -23,6 +23,8 @@ import net.sf.openrocket.startup.Application; public class MotorChooserDialog extends JDialog implements CloseableDialog { + private static final long serialVersionUID = 6903386330489783515L; + private final ThrustCurveMotorSelectionPanel selectionPanel; private boolean okClicked = false; @@ -30,7 +32,7 @@ public class MotorChooserDialog extends JDialog implements CloseableDialog { public MotorChooserDialog(MotorMount mount, FlightConfigurationID currentConfigID, Window owner) { this(owner); - setMotorMountAndConfig(mount, currentConfigID); + setMotorMountAndConfig( currentConfigID, mount); } public MotorChooserDialog(Window owner) { @@ -82,8 +84,8 @@ public class MotorChooserDialog extends JDialog implements CloseableDialog { selectionPanel.setCloseableDialog(this); } - public void setMotorMountAndConfig( MotorMount mount, FlightConfigurationID currentConfig ) { - selectionPanel.setMotorMountAndConfig(mount, currentConfig); + public void setMotorMountAndConfig( FlightConfigurationID _fcid, MotorMount _mount ) { + selectionPanel.setMotorMountAndConfig( _fcid, _mount ); } /** diff --git a/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/MotorRowFilter.java b/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/MotorRowFilter.java index cca4beacf..c8cdbef43 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/MotorRowFilter.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/MotorRowFilter.java @@ -67,7 +67,9 @@ public class MotorRowFilter extends RowFilter implements Ch Iterator iter = mount.getMotorIterator(); while( iter.hasNext()){ MotorInstance mi = iter.next(); - this.usedMotors.add((ThrustCurveMotor) mi.getMotor()); + if( !mi.isEmpty()){ + this.usedMotors.add((ThrustCurveMotor) mi.getMotor()); + } } } } diff --git a/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/ThrustCurveMotorSelectionPanel.java b/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/ThrustCurveMotorSelectionPanel.java index 7c0956f9a..9aea6df0d 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/ThrustCurveMotorSelectionPanel.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/ThrustCurveMotorSelectionPanel.java @@ -98,11 +98,12 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec private ThrustCurveMotorSet selectedMotorSet; private double selectedDelay; - public ThrustCurveMotorSelectionPanel(MotorMount mount, FlightConfigurationID currentConfig) { + public ThrustCurveMotorSelectionPanel( final FlightConfigurationID fcid, MotorMount mount ) { this(); - setMotorMountAndConfig( mount, currentConfig ); + setMotorMountAndConfig( fcid, mount ); } + /** * Sole constructor. * @@ -310,18 +311,39 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec } - public void setMotorMountAndConfig( MotorMount mount, FlightConfigurationID currentConfigId ) { + public void setMotorMountAndConfig( final FlightConfigurationID _fcid, MotorMount _mount ) { + if ( null == _fcid ){ + throw new NullPointerException(" attempted to set mount with a null FCID. bug. "); + }else if ( null == _mount ){ + throw new NullPointerException(" attempted to set mount with a null mount. bug. "); + } + + // DEBUG + MotorInstance curMotorInstance = _mount.getMotorInstance(_fcid); + System.err.println("(A) motor ID: "+ curMotorInstance.getMotorID().hashCode()); + if( curMotorInstance.isEmpty()){ + System.err.println("(B) MotorInstance: Motor: Empty."); + System.err.println("(C) MotorInstance: mount: Empty."); + }else{ + System.err.println("(B) MotorInstance: has motor: "+curMotorInstance.getMotor() ); + System.err.println("(C) MotorInstance: set mount: "+curMotorInstance.getMount()); + } + System.err.println("(D) MotorInstance: parent mount: "+_mount); + System.err.println("(F) FCID: "+ _fcid.key); + + System.err.println("(K) MotorInstance: IgnitionEvent: "+curMotorInstance.getIgnitionEvent().name); + System.err.println("(I) MotorInstance: Ign delay: "+curMotorInstance.getIgnitionDelay()); + // DEBUG + selectedMotor = null; selectedMotorSet = null; selectedDelay = 0; - ThrustCurveMotor motorToSelect = null; - if (currentConfigId != null && mount != null) { - MotorInstance motorConf = mount.getMotorInstance( currentConfigId); - motorToSelect = (ThrustCurveMotor) motorConf.getMotor(); - selectedDelay = motorConf.getEjectionDelay(); + if ( curMotorInstance.hasMotor()){ + motorToSelect = (ThrustCurveMotor) curMotorInstance.getMotor(); + selectedDelay = curMotorInstance.getEjectionDelay(); } - + // If current motor is not found in db, add a new ThrustCurveMotorSet containing it if (motorToSelect != null) { ThrustCurveMotorSet motorSetToSelect = null; @@ -333,13 +355,14 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec database.add(extra); Collections.sort(database); } + + select(motorToSelect); + MotorMount mount = curMotorInstance.getMount(); + + //? have we added this motor to the given mount? + motorFilterPanel.setMotorMount(mount); } - - select(motorToSelect); - - motorFilterPanel.setMotorMount(mount); scrollSelectionVisible(); - } @Override diff --git a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurablePanel.java b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurablePanel.java index e2e7d5344..7b5e54a37 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurablePanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurablePanel.java @@ -10,7 +10,6 @@ import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTable; -import javax.swing.ListSelectionModel; import javax.swing.UIManager; import javax.swing.border.Border; import javax.swing.border.EmptyBorder; @@ -24,7 +23,6 @@ import net.sf.openrocket.formatting.RocketDescriptor; import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.rocketcomponent.FlightConfigurableComponent; -import net.sf.openrocket.rocketcomponent.FlightConfiguration; import net.sf.openrocket.rocketcomponent.FlightConfigurationID; import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.startup.Application; @@ -58,7 +56,7 @@ public abstract class FlightConfigurablePanel ids = rocket.getSortedConfigurationIDs(); for( int rowNum = 0; rowNum < table.getRowCount(); rowNum++ ) { FlightConfigurationID rowFCID = ids.get(rowNum ); - if ( rowFCID.equals(selectedFCID) ) { table.changeSelection(rowNum, col, true, false); break; @@ -114,17 +109,16 @@ public abstract class FlightConfigurablePanel selectedComponent = (Pair) tableValue; - return new FlightConfigurationID( selectedComponent.getU() ); + Pair selectedComponent = (Pair) tableValue; + return selectedComponent.getU(); } else if ( tableValue instanceof String ){ - return new FlightConfigurationID((String) tableValue); + // DEPRECATED + System.err.println(" found String instance where expected a Pair....Bug!"); + throw new IllegalStateException("!!Found String instance where expected a Pair....Bug!"); + // this really should be un-implemented. + //return new FlightConfigurationID((String) tableValue); } - return null; + return FlightConfigurationID.ERROR_CONFIGURATION_ID; } protected abstract class FlightConfigurableCellRenderer extends DefaultTableCellRenderer { @@ -183,9 +181,11 @@ public abstract class FlightConfigurablePanel v = (Pair) value; + @SuppressWarnings("unchecked") + Pair v = (Pair) value; + if(v!=null){ - FlightConfigurationID fcid = new FlightConfigurationID (v.getU()); + FlightConfigurationID fcid = v.getU(); T component = v.getV(); label = format(component, fcid, label ); } diff --git a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurableTableModel.java b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurableTableModel.java index edc8548ff..5a581af40 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurableTableModel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurableTableModel.java @@ -17,7 +17,7 @@ import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.startup.Application; import net.sf.openrocket.util.Pair; -public class FlightConfigurableTableModel extends AbstractTableModel implements ComponentChangeListener{ +public class FlightConfigurableTableModel extends AbstractTableModel implements ComponentChangeListener{ private static final long serialVersionUID = 3168465083803936363L; private static final Translator trans = Application.getTranslator(); @@ -37,8 +37,8 @@ public class FlightConfigurableTableModel } @Override - public void componentChanged(ComponentChangeEvent e) { - if ( e.isMotorChange() || e.isTreeChange() ) { + public void componentChanged(ComponentChangeEvent cce) { + if ( cce.isMotorChange() || cce.isTreeChange() ) { initialize(); fireTableStructureChanged(); } @@ -66,7 +66,7 @@ public class FlightConfigurableTableModel @Override public int getRowCount() { - return rocket.getConfigurationSet().size() - 1; + return rocket.getConfigurationSet().size(); } @Override @@ -76,15 +76,16 @@ public class FlightConfigurableTableModel @Override public Object getValueAt(int row, int column) { - FlightConfigurationID id = getConfiguration(row); + FlightConfigurationID fcid = getConfigurationID(row); + switch (column) { case 0: { - return id; + return fcid; } default: { int index = column - 1; T d = components.get(index); - return new Pair(id.toString(), d); + return new Pair(fcid, d); } } } @@ -104,11 +105,12 @@ public class FlightConfigurableTableModel } } - private FlightConfigurationID getConfiguration(int rowNum) { - this.ids = rocket.getSortedConfigurationIDs(); + private FlightConfigurationID getConfigurationID(int rowNum) { + if( rocket.getConfigurationCount() != ids.size()){ + this.ids = rocket.getSortedConfigurationIDs(); + } - FlightConfigurationID id = this.ids.get(rowNum + 1); - return id; + return this.ids.get(rowNum); } } \ No newline at end of file diff --git a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurationPanel.java b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurationPanel.java index 73dcf1dfe..4958a3845 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurationPanel.java @@ -146,8 +146,7 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe ((FlightConfigurableComponent) c).cloneFlightConfiguration(oldId, newId); } } - newConfig.setName( oldName); - rocket.getConfigurationSet().setDefault(newConfig); + newConfig.setName( oldName+"2"); // Create a new simulation for this configuration. createSimulationForNewConfiguration(); diff --git a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java index 3b415abf0..4b3b8e054 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java @@ -66,7 +66,6 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel @Override public void onDataChanged() { MotorConfigurationPanel.this.fireTableDataChanged(); - } }; subpanel.add(mountConfigPanel, "grow"); @@ -147,18 +146,19 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel protected boolean includeComponent(MotorMount component) { return component.isMotorMount(); } - }; + // Listen to changes to the table so we can disable the help text when a // motor mount is added through the edit body tube dialog. configurationTableModel.addTableModelListener( new TableModelListener() { @Override - public void tableChanged(TableModelEvent e) { + public void tableChanged(TableModelEvent tme) { MotorConfigurationPanel.this.updateButtonState(); } }); + JTable configurationTable = new JTable(configurationTableModel); configurationTable.getTableHeader().setReorderingAllowed(false); configurationTable.setCellSelectionEnabled(true); @@ -168,7 +168,7 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel configurationTable.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { - updateButtonState(); + MotorConfigurationPanel.this.updateButtonState(); int selectedColumn = table.getSelectedColumn(); if (e.getClickCount() == 2) { if (selectedColumn > 0) { @@ -184,12 +184,12 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel protected void updateButtonState() { if( configurationTableModel.getColumnCount() > 1 ) { showContent(); - FlightConfigurationID currentID = rocket.getDefaultConfiguration().getFlightConfigurationID(); - MotorMount currentMount = getSelectedComponent(); - selectMotorButton.setEnabled(currentMount != null && currentID != null); - removeMotorButton.setEnabled(currentMount != null && currentID != null); - selectIgnitionButton.setEnabled(currentMount != null && currentID != null); - resetIgnitionButton.setEnabled(currentMount != null && currentID != null); + + boolean haveSelection = (null != getSelectedComponent()); + selectMotorButton.setEnabled( haveSelection ); + removeMotorButton.setEnabled( haveSelection ); + selectIgnitionButton.setEnabled( haveSelection ); + resetIgnitionButton.setEnabled( haveSelection ); } else { showEmptyText(); selectMotorButton.setEnabled(false); @@ -201,65 +201,71 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel private void selectMotor() { - FlightConfigurationID id = rocket.getDefaultConfiguration().getFlightConfigurationID(); - MotorMount mount = getSelectedComponent(); - if (id == null || mount == null) - return; - MotorInstance inst = mount.getMotorInstance(id); - if( inst.isEmpty() ) - return; - - motorChooserDialog.setMotorMountAndConfig(mount, id); - + MotorMount curMount = getSelectedComponent(); + FlightConfigurationID fcid= getSelectedConfigurationId(); + if ( (null == fcid )||( null == curMount )){ + return; + } + System.err.println("?? selected FCID: "+ fcid.key); + + motorChooserDialog.setMotorMountAndConfig( fcid, curMount ); motorChooserDialog.setVisible(true); Motor m = motorChooserDialog.getSelectedMotor(); double d = motorChooserDialog.getSelectedDelay(); + MotorInstance curInstance = curMount.getMotorInstance(fcid); if (m != null) { - inst = m.getNewInstance(); - inst.setEjectionDelay(d); - mount.setMotorInstance(id, inst); + curInstance = m.getNewInstance(); + curInstance.setEjectionDelay(d); + curMount.setMotorInstance( fcid, curInstance); } fireTableDataChanged(); } private void removeMotor() { - FlightConfigurationID id = rocket.getDefaultConfiguration().getFlightConfigurationID(); - MotorMount mount = getSelectedComponent(); - if (id == null || mount == null) - return; - - mount.setMotorInstance( id, null); - + MotorMount curMount = getSelectedComponent(); + FlightConfigurationID fcid= getSelectedConfigurationId(); + if ( (null == fcid )||( null == curMount )){ + return; + } + + + MotorInstance curInstance = MotorInstance.EMPTY_INSTANCE; + curMount.setMotorInstance( fcid, curInstance); + fireTableDataChanged(); } private void selectIgnition() { - FlightConfigurationID currentID = rocket.getDefaultConfiguration().getFlightConfigurationID(); - MotorMount currentMount = getSelectedComponent(); - if (currentID == null || currentMount == null) - return; - - IgnitionSelectionDialog dialog = new IgnitionSelectionDialog( + MotorMount curMount = getSelectedComponent(); + FlightConfigurationID fcid= getSelectedConfigurationId(); + if ( (null == fcid )||( null == curMount )){ + return; + } + + IgnitionSelectionDialog ignitionDialog = new IgnitionSelectionDialog( SwingUtilities.getWindowAncestor(this.flightConfigurationPanel), - rocket, - currentMount); - dialog.setVisible(true); - + fcid, + curMount); + ignitionDialog.setVisible(true); + + // changes performed automatically within "new IgnitionSelectionDialog(...)" + fireTableDataChanged(); } private void resetIgnition() { - FlightConfigurationID currentID = rocket.getDefaultConfiguration().getFlightConfigurationID(); - MotorMount currentMount = getSelectedComponent(); - if (currentID == null || currentMount == null) - return; - - MotorInstance curInstance = currentMount.getMotorInstance(currentID); - MotorInstance defInstance = currentMount.getDefaultMotorInstance(); + MotorMount curMount = getSelectedComponent(); + FlightConfigurationID fcid= getSelectedConfigurationId(); + if ( (null == fcid )||( null == curMount )){ + return; + } + MotorInstance curInstance = curMount.getMotorInstance(fcid); + + MotorInstance defInstance = curInstance.getMount().getDefaultMotorInstance(); curInstance.setIgnitionDelay( defInstance.getIgnitionDelay()); curInstance.setIgnitionEvent( defInstance.getIgnitionEvent()); @@ -271,7 +277,7 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel private static final long serialVersionUID = -7462331042920067984L; @Override - protected JLabel format( MotorMount mount, FlightConfigurationID configId, JLabel l ) { + protected JLabel format( MotorMount mount, FlightConfigurationID configId, JLabel l ) { JLabel label = new JLabel(); label.setLayout(new BoxLayout(label, BoxLayout.X_AXIS)); MotorInstance curMotor = mount.getMotorInstance( configId); @@ -292,6 +298,9 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel MotorMount mount = curMotorInstance.getMount(); Motor motor = curMotorInstance.getMotor(); + if( null == mount){ + throw new NullPointerException("Motor has a null mount... this should never happen: "+curMotorInstance.getMotorID()); + } String str = motor.getDesignation(curMotorInstance.getEjectionDelay()); int count = mount.getInstanceCount();