From 9c49b6336a663bf53a7b64c68251e02f7949239f Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Mon, 4 Apr 2016 23:08:20 -0400 Subject: [PATCH 01/12] [bugfix] Added back in the default no-motor configuration. --- .../FlightConfigurableParameterSet.java | 18 ++-- .../sf/openrocket/rocketcomponent/Rocket.java | 85 ++++++++++--------- 2 files changed, 56 insertions(+), 47 deletions(-) diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurableParameterSet.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurableParameterSet.java index 07f0dc033..504d9752a 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurableParameterSet.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurableParameterSet.java @@ -75,6 +75,11 @@ public class FlightConfigurableParameterSet iterator() { return map.values().iterator(); @@ -135,9 +140,6 @@ public class FlightConfigurableParameterSet configSet = new HashMap(); + private FlightConfigurableParameterSet configSet; private HashMap stageMap = new HashMap(); // Does the rocket have a perfect finish (a notable amount of laminar flow) @@ -86,9 +86,10 @@ public class Rocket extends RocketComponent { functionalModID = modID; - // must be after the hashmaps :P - this.selectedConfiguration = new FlightConfiguration( this, null); + + configSet = new FlightConfigurableParameterSet( new FlightConfiguration(this, FlightConfigurationId.DEFAULT_VALUE_FCID) ); + this.selectedConfiguration = configSet.getDefault(); } public String getDesigner() { @@ -311,7 +312,8 @@ public class Rocket extends RocketComponent { // Rocket copy is cloned, so non-trivial members must be cloned as well: copy.stageMap = new HashMap(); - copy.configSet = new HashMap(); + copy.configSet = new FlightConfigurableParameterSet( this.configSet ); + new HashMap(); if( 0 < this.configSet.size() ){ Rocket.cloneConfigs( this, copy); } @@ -324,8 +326,8 @@ public class Rocket extends RocketComponent { source.checkState(); dest.checkState(); dest.selectedConfiguration = source.selectedConfiguration.clone(); - for( final FlightConfiguration config : source.configSet.values() ){ - dest.configSet.put( config.getId(), config.clone() ); + for( final FlightConfiguration config : source.configSet ){ + dest.configSet.set( config.getId(), config.clone() ); } } @@ -473,7 +475,7 @@ public class Rocket extends RocketComponent { private void updateConfigurations(){ this.selectedConfiguration.update(); - for( FlightConfiguration config : configSet.values() ){ + for( FlightConfiguration config : configSet ){ config.update(); } } @@ -570,37 +572,12 @@ public class Rocket extends RocketComponent { return this.selectedConfiguration; } - public FlightConfiguration createFlightConfiguration( final FlightConfigurationId fcid) { - checkState(); - if( null == fcid ){ - throw new NullPointerException("Attempted to create a flightConfiguration from a null key!"); - }else if( fcid.hasError() ){ - throw new NullPointerException("Attempted to create a flightConfiguration from an error key!"); - }else if( configSet.containsKey(fcid)){ - return this.configSet.get(fcid); - }else{ - FlightConfiguration nextConfig = new FlightConfiguration(this, fcid); - this.configSet.put(fcid, nextConfig); - this.selectedConfiguration = nextConfig; - fireComponentChangeEvent(ComponentChangeEvent.TREE_CHANGE); - return nextConfig; - } - } - public int getConfigurationCount(){ return this.configSet.size(); } public List getIds(){ - ArrayList toReturn = new ArrayList(this.configSet.keySet()); - - // Java 1.8: - //toReturn.sort( null ); - - // Java 1.7: - Collections.sort(toReturn); - - return toReturn; + return configSet.getSortedConfigurationIDs(); } @@ -610,7 +587,7 @@ public class Rocket extends RocketComponent { * @return list of attached flight configurations (unordered) */ public FlightConfiguration[] toConfigArray(){ - return this.configSet.values().toArray( new FlightConfiguration[0]); + return this.configSet.toArray(); } /** @@ -626,7 +603,7 @@ public class Rocket extends RocketComponent { } // Get current configuration: - this.configSet.remove( fcid); + this.configSet.reset( fcid); fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); } @@ -637,12 +614,12 @@ public class Rocket extends RocketComponent { * @param id the configuration ID. * @return whether a motor configuration with that ID exists. */ - public boolean containsFlightConfigurationID(FlightConfigurationId id) { + public boolean containsFlightConfigurationID(final FlightConfigurationId id) { checkState(); if( id.hasError() ){ return false; } - return configSet.containsKey( id); + return configSet.containsId( id); } @@ -675,6 +652,29 @@ public class Rocket extends RocketComponent { } + /** + * Return a flight configuration. If the supplied id does not have a specific instance, the default is returned. + * + * @param id the flight configuration id + * @return FlightConfiguration instance + */ + public FlightConfiguration createFlightConfiguration(final FlightConfigurationId fcid) { + checkState(); + if( null == fcid ){ + return configSet.getDefault(); + }else if( fcid.hasError() ){ + return configSet.getDefault(); + }else if( configSet.containsId(fcid)){ + return this.getFlightConfiguration(fcid); + }else{ + FlightConfiguration nextConfig = new FlightConfiguration(this, fcid); + this.configSet.set(fcid, nextConfig); + fireComponentChangeEvent(ComponentChangeEvent.TREE_CHANGE); + return nextConfig; + } + } + + /** * Return a flight configuration. If the supplied id does not have a specific instance, the default is returned. * @@ -683,7 +683,7 @@ public class Rocket extends RocketComponent { */ public FlightConfiguration getFlightConfiguration(final FlightConfigurationId fcid) { checkState(); - return this.createFlightConfiguration(fcid); + return this.configSet.get(fcid); } /** @@ -713,7 +713,7 @@ public class Rocket extends RocketComponent { if( fcid.hasError() ){ log.error("attempt to set a 'fcid = config' with a error fcid. Ignored.", new IllegalArgumentException("error id:"+fcid)); return; - }else if( this.configSet.containsKey(fcid)){ + }else if( this.configSet.containsId(fcid)){ this.selectedConfiguration = configSet.get(fcid); fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE); } @@ -734,9 +734,10 @@ public class Rocket extends RocketComponent { } if (null == newConfig){ - newConfig = createFlightConfiguration(fcid); + configSet.reset( fcid); + }else{ + configSet.set(fcid, newConfig); } - configSet.put(fcid, newConfig); fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE); } @@ -822,7 +823,7 @@ public class Rocket extends RocketComponent { StringBuilder buf = new StringBuilder(); buf.append(String.format("====== Dumping %d Configurations from rocket: \n", this.getConfigurationCount(), this.getName())); final String fmt = " [%12s]: %s\n"; - for( FlightConfiguration config : this.configSet.values() ){ + for( FlightConfiguration config : this.configSet ){ String shortKey = config.getId().toShortKey(); if( this.selectedConfiguration.equals( config)){ shortKey = "=>" + shortKey; From 5b687b5bccabedbf04c3bb0fea2db1c51a3ad08b Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Tue, 5 Apr 2016 22:56:06 -0400 Subject: [PATCH 02/12] [Bugfix] Fixes a few configuration bugs. - Fixes out-of-date javadoc comments - Fixes FlightConfigurationTest -- fixes TestRocket instantiation. - Simplified FlightConfiguration class function API - --- .../FlightConfigurableParameterSet.java | 89 +++++++++---------- .../sf/openrocket/rocketcomponent/Rocket.java | 16 ++-- .../net/sf/openrocket/util/TestRockets.java | 2 +- .../rocketcomponent/ParameterSetTest.java | 2 +- 4 files changed, 51 insertions(+), 58 deletions(-) diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurableParameterSet.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurableParameterSet.java index 504d9752a..57002c737 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurableParameterSet.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurableParameterSet.java @@ -22,23 +22,20 @@ public class FlightConfigurableParameterSet map = new HashMap(); - protected static final FlightConfigurationId defaultValueId = FlightConfigurationId.DEFAULT_VALUE_FCID; - + /** * Construct a FlightConfiguration that has no overrides. * - * @param component the rocket component on which events are fired when the parameter values are changed - * @param eventType the event type that will be fired on changes + * @param _defaultValue the first default value */ public FlightConfigurableParameterSet(E _defaultValue) { - this.map.put( defaultValueId, _defaultValue); + this.map.put( FlightConfigurationId.DEFAULT_VALUE_FCID, _defaultValue); } /** * Construct a copy of an existing FlightConfigurationImpl. * - * @param component the rocket component on which events are fired when the parameter values are changed - * @param eventType the event type that will be fired on changes + * @param configSet the FlightConfigurableParameterSet to copy */ public FlightConfigurableParameterSet(FlightConfigurableParameterSet configSet ){ for (FlightConfigurationId key : configSet.map.keySet()) { @@ -55,7 +52,7 @@ public class FlightConfigurableParameterSet ids = this.getSortedConfigurationIDs(); + List ids = this.getIds(); FlightConfigurationId selectedId = ids.get(index); return this.map.get(selectedId); } @@ -149,38 +146,38 @@ public class FlightConfigurableParameterSet getSortedConfigurationIDs(){ - ArrayList toReturn = new ArrayList(); - - toReturn.addAll( this.map.keySet() ); - toReturn.remove( defaultValueId ); - // Java 1.8: - //toReturn.sort( null ); - - // Java 1.7: - Collections.sort(toReturn); - - return toReturn; - } - - public List getIds(){ - return this.getSortedConfigurationIDs(); + + /** + * @return a sorted list of all the contained FlightConfigurationIDs + */ + public List getIds(){ + ArrayList toReturn = new ArrayList(); + + toReturn.addAll( this.map.keySet() ); + toReturn.remove( FlightConfigurationId.DEFAULT_VALUE_FCID ); + // Java 1.8: + //toReturn.sort( null ); + + // Java 1.7: + Collections.sort(toReturn); + + return toReturn; } /** * 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) + * @param fcid the flight configuration ID + * @param nextValue the parameter value (null not allowed) */ - public void set(FlightConfigurationId fcid, E nextValue) { + public void set( final FlightConfigurationId fcid, E nextValue) { if ( nextValue == null) { - // null value means to delete this fcid - this.map.remove(fcid); + // null value means to delete this fcid + this.map.remove(fcid); + }else if( FlightConfigurationId.DEFAULT_VALUE_FCID == fcid ){ + // if a user wants to set the default value, make them do it explicitly with .setDefaultValue(...) + return; }else{ this.map.put(fcid, nextValue); } @@ -189,7 +186,7 @@ public class FlightConfigurableParameterSet (%d configurations)\n", this.getDefault().getClass().getSimpleName(), this.size() )); final String fmt = " [%-12s]: %s\n"; - for( FlightConfigurationId loopFCID : this.getSortedConfigurationIDs()){ + for( FlightConfigurationId loopFCID : getIds()){ String shortKey = loopFCID.toShortKey(); E inst = this.map.get(loopFCID); if( this.isDefault(inst)){ diff --git a/core/src/net/sf/openrocket/rocketcomponent/Rocket.java b/core/src/net/sf/openrocket/rocketcomponent/Rocket.java index 605647764..31f3b41fb 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/Rocket.java +++ b/core/src/net/sf/openrocket/rocketcomponent/Rocket.java @@ -577,7 +577,7 @@ public class Rocket extends RocketComponent { } public List getIds(){ - return configSet.getSortedConfigurationIDs(); + return configSet.getIds(); } @@ -594,7 +594,7 @@ public class Rocket extends RocketComponent { * Remove a flight configuration ID from the configuration IDs. The null * ID cannot be removed, and an attempt to remove it will be silently ignored. * - * @param id the flight configuration ID to remove + * @param fcid the flight configuration ID to remove */ public void removeFlightConfigurationID(FlightConfigurationId fcid) { checkState(); @@ -626,7 +626,7 @@ public class Rocket extends RocketComponent { /** * Check whether the given motor configuration ID has motors defined for it. * - * @param id the FlightConfigurationID containing the motor (may be invalid). + * @param fcid the FlightConfigurationID containing the motor (may be invalid). * @return whether any motors are defined for it. */ public boolean hasMotors(FlightConfigurationId fcid) { @@ -655,7 +655,7 @@ public class Rocket extends RocketComponent { /** * Return a flight configuration. If the supplied id does not have a specific instance, the default is returned. * - * @param id the flight configuration id + * @param fcid the flight configuration id * @return FlightConfiguration instance */ public FlightConfiguration createFlightConfiguration(final FlightConfigurationId fcid) { @@ -678,7 +678,7 @@ public class Rocket extends RocketComponent { /** * Return a flight configuration. If the supplied id does not have a specific instance, the default is returned. * - * @param id the flight configuration id + * @param fcid the flight configuration id * @return a FlightConfiguration instance */ public FlightConfiguration getFlightConfiguration(final FlightConfigurationId fcid) { @@ -689,7 +689,7 @@ public class Rocket extends RocketComponent { /** * Return a flight configuration. If the supplied index is out of bounds, an exception is thrown. * - * @param id the flight configuration index number + * @param configIndex the flight configuration index number * @return a FlightConfiguration instance */ public FlightConfiguration getFlightConfiguration(final int configIndex) { @@ -723,8 +723,8 @@ public class Rocket extends RocketComponent { * Associate the given ID and flight configuration. * null or an empty string. * - * @param id the flight configuration id - * @param name the name for the flight configuration + * @param fcid the flight configuration id + * @param newConfig new FlightConfiguration to store */ public void setFlightConfiguration(final FlightConfigurationId fcid, FlightConfiguration newConfig) { checkState(); diff --git a/core/src/net/sf/openrocket/util/TestRockets.java b/core/src/net/sf/openrocket/util/TestRockets.java index 42ed39af6..9e3896bad 100644 --- a/core/src/net/sf/openrocket/util/TestRockets.java +++ b/core/src/net/sf/openrocket/util/TestRockets.java @@ -384,7 +384,7 @@ public class TestRockets { public static final Rocket makeEstesAlphaIII(){ Rocket rocket = new Rocket(); FlightConfigurationId fcid[] = new FlightConfigurationId[5]; - fcid[0] = rocket.getSelectedConfiguration().getFlightConfigurationID(); + fcid[0] = new FlightConfigurationId(); rocket.createFlightConfiguration(fcid[0]); fcid[1] = new FlightConfigurationId(); rocket.createFlightConfiguration(fcid[1]); diff --git a/core/test/net/sf/openrocket/rocketcomponent/ParameterSetTest.java b/core/test/net/sf/openrocket/rocketcomponent/ParameterSetTest.java index cafd84817..763c4a9c1 100644 --- a/core/test/net/sf/openrocket/rocketcomponent/ParameterSetTest.java +++ b/core/test/net/sf/openrocket/rocketcomponent/ParameterSetTest.java @@ -138,7 +138,7 @@ public class ParameterSetTest extends BaseTestCase { // testSet.getSortedConfigurationIDs() // >> this function should ONLY return ids for the overrides assertThat("getIds() broken!\n"+testSet.toDebug(), testSet.getIds().size(), equalTo( testSet.size())); - assertThat("getIds() broken!\n"+testSet.toDebug(), testSet.getSortedConfigurationIDs().size(), equalTo( testSet.getIds().size() ) ); + assertThat("getIds() broken!\n"+testSet.toDebug(), testSet.getIds().size(), equalTo( testSet.getIds().size() ) ); } @Test From d7faf0d273a412b0c8abe3bd31aa5959b48f8048 Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Sun, 10 Apr 2016 13:08:47 -0400 Subject: [PATCH 03/12] [Refine] Refining Configuration Fixes - Rocket.getSelectedConfiguration will now create a new configuration if only the default config exists -- added additional unit tests for this behavior in: FLightConfigurationTest - added test for saving ver 1.08 files to OpenRocketSaverTest - Converted : "private static final long serialVersionUID ..." declarations to: "@SuppressWarnings("serial")" - cleaned up some other random errors: -- tightened excessive permission modifiers -- public -> -- change some methods from 'public' to '/*package-local*/' --- .../rocketcomponent/FlightConfiguration.java | 71 +++++++++---------- .../sf/openrocket/rocketcomponent/Rocket.java | 55 +++++++------- .../net/sf/openrocket/util/TestRockets.java | 27 ++++--- .../file/openrocket/OpenRocketSaverTest.java | 1 + .../FlightConfigurationTest.java | 58 ++++++++++++--- .../rocketcomponent/RocketTest.java | 1 - .../gui/adaptors/ParameterSetModel.java | 4 +- .../MotorConfigurationPanel.java | 6 +- .../gui/scalefigure/RocketFigure.java | 4 +- .../gui/scalefigure/RocketPanel.java | 2 +- 10 files changed, 129 insertions(+), 100 deletions(-) diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java index 0d2328691..175a349a8 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java @@ -29,18 +29,19 @@ import net.sf.openrocket.util.Monitorable; public class FlightConfiguration implements FlightConfigurableParameter, Monitorable { private static final Logger log = LoggerFactory.getLogger(FlightConfiguration.class); - public final static String DEFAULT_CONFIGURATION_NAME = "Default Configuration".intern(); - public final static String NO_MOTORS_TEXT = "[No Motors Defined]".intern(); - - protected String configurationName=null; + private final static String NO_MOTORS_NAME = "[No Motors Defined]"; + private final static String DEFAULT_CONFIGURATION_NAME = NO_MOTORS_NAME; + + private String configurationName=null; protected final Rocket rocket; protected final FlightConfigurationId fcid; - protected static int instanceCount=0; + private static int instanceCount=0; + // made public for testing.... there is probably a better way public final int instanceNumber; - protected class StageFlags implements Cloneable { + private class StageFlags implements Cloneable { public boolean active = true; public int prev = -1; public AxialStage stage = null; @@ -59,7 +60,6 @@ public class FlightConfiguration implements FlightConfigurableParameter getActiveComponents() { Queue toProcess = new ArrayDeque(this.getActiveStages()); - ArrayList toReturn = new ArrayList(); + ArrayList toReturn = new ArrayList<>(); while (!toProcess.isEmpty()) { RocketComponent comp = toProcess.poll(); toReturn.add(comp); for (RocketComponent child : comp.getChildren()) { - if (child instanceof AxialStage) { - continue; - } else { + if (!(child instanceof AxialStage)) { toProcess.offer(child); } } @@ -194,7 +192,7 @@ public class FlightConfiguration implements FlightConfigurableParameter getActiveStages() { - List activeStages = new ArrayList(); + List activeStages = new ArrayList<>(); for (StageFlags flags : this.stages.values()) { if (flags.active) { @@ -215,9 +213,8 @@ public class FlightConfiguration implements FlightConfigurableParameter iter = rocket.iterator(false); @@ -471,15 +461,22 @@ public class FlightConfiguration implements FlightConfigurableParameter> Why am I being cloned!?", new IllegalStateException(this.toDebug()+" >to> "+clone.toDebug())); - - - // DO NOT UPDATE this.stages or this.motors; - // these are are updated correctly on their own. - + + // Note the stages are updated in the constructor call. + FlightConfiguration clone = new FlightConfiguration( this.rocket, this.fcid ); + clone.setName("clone[#"+clone.instanceNumber+"]"+clone.fcid.toShortKey()); + //FlightConfigurationId cloneId = clone.getFlightConfigurationID(); + + System.err.println(" cloning from: "+this.toDebug()); + System.err.println(" cloning to: "+clone.toDebug()); + +// // clone motor instances. +// for( MotorConfiguration motor : motors.values() ){ +// MotorConfiguration cloneMotor = new MotorConfiguration( motor, cloneId); +// clone.addMotor( cloneMotor); +// cloneMotor.getMount().setMotorConfig(cloneMotor, cloneId); +// } + clone.cachedBounds = this.cachedBounds.clone(); clone.modID = this.modID; clone.boundsModID = -1; diff --git a/core/src/net/sf/openrocket/rocketcomponent/Rocket.java b/core/src/net/sf/openrocket/rocketcomponent/Rocket.java index 31f3b41fb..2fcecc70e 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/Rocket.java +++ b/core/src/net/sf/openrocket/rocketcomponent/Rocket.java @@ -34,14 +34,12 @@ public class Rocket extends RocketComponent { private static final Logger log = LoggerFactory.getLogger(Rocket.class); private static final Translator trans = Application.getTranslator(); - public static final String DEFAULT_NAME = "[{motors}]"; - public static final double DEFAULT_REFERENCE_LENGTH = 0.01; - - + protected static final double DEFAULT_REFERENCE_LENGTH = 0.01; + /** * List of component change listeners. */ - private List listenerList = new ArrayList(); + private List listenerList = new ArrayList<>(); /** * When freezeList != null, events are not dispatched but stored in the list. @@ -69,7 +67,7 @@ public class Rocket extends RocketComponent { // Flight configuration list private FlightConfiguration selectedConfiguration; private FlightConfigurableParameterSet configSet; - private HashMap stageMap = new HashMap(); + private HashMap stageMap = new HashMap<>(); // Does the rocket have a perfect finish (a notable amount of laminar flow) private boolean perfectFinish = false; @@ -84,12 +82,11 @@ public class Rocket extends RocketComponent { aeroModID = modID; treeModID = modID; functionalModID = modID; - // must be after the hashmaps :P - - configSet = new FlightConfigurableParameterSet( new FlightConfiguration(this, FlightConfigurationId.DEFAULT_VALUE_FCID) ); - this.selectedConfiguration = configSet.getDefault(); + FlightConfiguration defaultConfig = new FlightConfiguration(this, FlightConfigurationId.DEFAULT_VALUE_FCID); + configSet = new FlightConfigurableParameterSet<>( defaultConfig ); + this.selectedConfiguration = defaultConfig; } public String getDesigner() { @@ -211,7 +208,7 @@ public class Rocket extends RocketComponent { * * @Return a reference to the topmost stage */ - public AxialStage getBottomCoreStage(){ + /*package-local*/ AxialStage getBottomCoreStage(){ // get last stage that's a direct child of the rocket. return (AxialStage) children.get( children.size()-1 ); } @@ -223,8 +220,8 @@ public class Rocket extends RocketComponent { } return guess; } - - public void trackStage(final AxialStage newStage) { + + /*package-local*/ void trackStage(final AxialStage newStage) { int stageNumber = newStage.getStageNumber(); AxialStage value = stageMap.get(stageNumber); @@ -236,8 +233,8 @@ public class Rocket extends RocketComponent { this.stageMap.put(stageNumber, newStage); } } - - public void forgetStage(final AxialStage oldStage) { + + /*package-local*/ void forgetStage(final AxialStage oldStage) { this.stageMap.remove(oldStage.getStageNumber()); } @@ -569,7 +566,10 @@ public class Rocket extends RocketComponent { */ public FlightConfiguration getSelectedConfiguration() { checkState(); - return this.selectedConfiguration; + if( this.selectedConfiguration == this.configSet.getDefault() ){ + selectedConfiguration = createFlightConfiguration(null); + } + return selectedConfiguration; } public int getConfigurationCount(){ @@ -650,28 +650,29 @@ public class Rocket extends RocketComponent { } return false; } - - + + /** * Return a flight configuration. If the supplied id does not have a specific instance, the default is returned. * * @param fcid the flight configuration id * @return FlightConfiguration instance */ - public FlightConfiguration createFlightConfiguration(final FlightConfigurationId fcid) { + public FlightConfiguration createFlightConfiguration( final FlightConfigurationId fcid) { checkState(); - if( null == fcid ){ - return configSet.getDefault(); + + if( null == fcid ){ + // fall-through to the default case... + // creating a FlightConfiguration( null ) just allocates a fresh new FCID }else if( fcid.hasError() ){ return configSet.getDefault(); }else if( configSet.containsId(fcid)){ return this.getFlightConfiguration(fcid); - }else{ - FlightConfiguration nextConfig = new FlightConfiguration(this, fcid); - this.configSet.set(fcid, nextConfig); - fireComponentChangeEvent(ComponentChangeEvent.TREE_CHANGE); - return nextConfig; } + FlightConfiguration nextConfig = new FlightConfiguration(this, fcid); + this.configSet.set(nextConfig.getFlightConfigurationID(), nextConfig); + fireComponentChangeEvent(ComponentChangeEvent.TREE_CHANGE); + return nextConfig; } @@ -697,7 +698,7 @@ public class Rocket extends RocketComponent { } public FlightConfigurationId getId( final int configIndex) { - List idList = this.getIds(); + List idList = configSet.getIds(); return idList.get(configIndex); } diff --git a/core/src/net/sf/openrocket/util/TestRockets.java b/core/src/net/sf/openrocket/util/TestRockets.java index 9e3896bad..580dd5600 100644 --- a/core/src/net/sf/openrocket/util/TestRockets.java +++ b/core/src/net/sf/openrocket/util/TestRockets.java @@ -101,14 +101,13 @@ public class TestRockets { // Motor.Type type, double[] delays, double diameter, double length, // double[] time, double[] thrust, // Coordinate[] cg, String digest); - ThrustCurveMotor mtr = new ThrustCurveMotor( - Manufacturer.getManufacturer("Estes"),"A8", " SU Black Powder", + return new ThrustCurveMotor( + Manufacturer.getManufacturer("Estes"),"A8", " SU Black Powder", Motor.Type.SINGLE, new double[] {0,3,5}, 0.018, 0.070, new double[] { 0, 1, 2 }, new double[] { 0, 9, 0 }, new Coordinate[] { - new Coordinate(0.035, 0, 0, 0.0164),new Coordinate(.035, 0, 0, 0.0145),new Coordinate(.035, 0, 0, 0.0131)}, + new Coordinate(0.035, 0, 0, 0.0164),new Coordinate(.035, 0, 0, 0.0145),new Coordinate(.035, 0, 0, 0.0131)}, "digest A8 test"); - return mtr; } // This function is used for unit, integration tests, DO NOT CHANGE (without updating tests). @@ -117,14 +116,13 @@ public class TestRockets { // Motor.Type type, double[] delays, double diameter, double length, // double[] time, double[] thrust, // Coordinate[] cg, String digest); - ThrustCurveMotor mtr = new ThrustCurveMotor( + return new ThrustCurveMotor( Manufacturer.getManufacturer("Estes"),"B4", " SU Black Powder", Motor.Type.SINGLE, new double[] {0,3,5}, 0.018, 0.070, new double[] { 0, 1, 2 }, new double[] { 0, 11.4, 0 }, new Coordinate[] { new Coordinate(0.035, 0, 0, 0.0195),new Coordinate(.035, 0, 0, 0.0155),new Coordinate(.035, 0, 0, 0.013)}, "digest B4 test"); - return mtr; } // This function is used for unit, integration tests, DO NOT CHANGE (without updating tests). @@ -133,26 +131,24 @@ public class TestRockets { // Motor.Type type, double[] delays, double diameter, double length, // double[] time, double[] thrust, // Coordinate[] cg, String digest); - ThrustCurveMotor mtr = new ThrustCurveMotor( + return new ThrustCurveMotor( Manufacturer.getManufacturer("Estes"),"C6", " SU Black Powder", Motor.Type.SINGLE, new double[] {0,3,5,7}, 0.018, 0.070, new double[] { 0, 1, 2 }, new double[] { 0, 6, 0 }, new Coordinate[] { new Coordinate(0.035, 0, 0, 0.0227),new Coordinate(.035, 0, 0, 0.0165),new Coordinate(.035, 0, 0, 0.012)}, "digest C6 test"); - return mtr; } // This function is used for unit, integration tests, DO NOT CHANGE (without updating tests). private static Motor generateMotor_D21_18mm(){ - ThrustCurveMotor mtr = new ThrustCurveMotor( + return new ThrustCurveMotor( Manufacturer.getManufacturer("AeroTech"),"D21", "Desc", Motor.Type.SINGLE, new double[] {}, 0.018, 0.07, new double[] { 0, 1, 2 }, new double[] { 0, 32, 0 }, new Coordinate[] { new Coordinate(.035, 0, 0, 0.025),new Coordinate(.035, 0, 0, .020),new Coordinate(.035, 0, 0, 0.0154)}, "digest D21 test"); - return mtr; } // This function is used for unit, integration tests, DO NOT CHANGE (without updating tests). @@ -161,14 +157,13 @@ public class TestRockets { // Motor.Type type, double[] delays, double diameter, double length, // double[] time, double[] thrust, // Coordinate[] cg, String digest); - ThrustCurveMotor mtr = new ThrustCurveMotor( + return new ThrustCurveMotor( Manufacturer.getManufacturer("AeroTech"),"M1350", "Desc", Motor.Type.SINGLE, new double[] {}, 0.075, 0.622, new double[] { 0, 1, 2 }, new double[] { 0, 1357, 0 }, new Coordinate[] { new Coordinate(.311, 0, 0, 4.808),new Coordinate(.311, 0, 0, 3.389),new Coordinate(.311, 0, 0, 1.970)}, "digest M1350 test"); - return mtr; } // This function is used for unit, integration tests, DO NOT CHANGE (without updating tests). @@ -177,14 +172,13 @@ public class TestRockets { // Motor.Type type, double[] delays, double diameter, double length, // double[] time, double[] thrust, // Coordinate[] cg, String digest); - ThrustCurveMotor mtr = new ThrustCurveMotor( + return new ThrustCurveMotor( Manufacturer.getManufacturer("AeroTech"),"G77", "Desc", Motor.Type.SINGLE, new double[] {4,7,10},0.029, 0.124, new double[] { 0, 1, 2 }, new double[] { 0, 1, 0 }, new Coordinate[] { new Coordinate(.062, 0, 0, 0.123),new Coordinate(.062, 0, 0, .0935),new Coordinate(.062, 0, 0, 0.064)}, "digest G77 test"); - return mtr; } // @@ -1029,7 +1023,10 @@ public class TestRockets { public static Rocket makeFalcon9Heavy() { Rocket rocket = new Rocket(); rocket.setName("Falcon9H Scale Rocket"); - FlightConfiguration selConfig = rocket.getSelectedConfiguration(); + + + FlightConfiguration selConfig = rocket.createFlightConfiguration(null); + rocket.setSelectedConfiguration(selConfig); FlightConfigurationId selFCID = selConfig.getFlightConfigurationID(); // ====== Payload Stage ====== diff --git a/core/test/net/sf/openrocket/file/openrocket/OpenRocketSaverTest.java b/core/test/net/sf/openrocket/file/openrocket/OpenRocketSaverTest.java index 819935805..362d2c8a1 100644 --- a/core/test/net/sf/openrocket/file/openrocket/OpenRocketSaverTest.java +++ b/core/test/net/sf/openrocket/file/openrocket/OpenRocketSaverTest.java @@ -131,6 +131,7 @@ public class OpenRocketSaverTest { rocketDocs.add(TestRockets.makeTestRocket_v106_withRecoveryDeviceDeploymentConfig()); rocketDocs.add(TestRockets.makeTestRocket_v106_withStageSeparationConfig()); rocketDocs.add(TestRockets.makeTestRocket_v107_withSimulationExtension(SIMULATION_EXTENSION_SCRIPT)); + rocketDocs.add(TestRockets.makeTestRocket_v108_withBoosters()); rocketDocs.add(TestRockets.makeTestRocket_for_estimateFileSize()); StorageOptions options = new StorageOptions(); diff --git a/core/test/net/sf/openrocket/rocketcomponent/FlightConfigurationTest.java b/core/test/net/sf/openrocket/rocketcomponent/FlightConfigurationTest.java index c8beaa563..8740ad46a 100644 --- a/core/test/net/sf/openrocket/rocketcomponent/FlightConfigurationTest.java +++ b/core/test/net/sf/openrocket/rocketcomponent/FlightConfigurationTest.java @@ -142,12 +142,43 @@ public class FlightConfigurationTest extends BaseTestCase { config.setAllStages(); } - - /** - * Single stage rocket specific configuration tests - */ - @Test - public void testConfigurationSwitching() { + + @Test + public void testCreateConfigurationNullId() { + /* Setup */ + Rocket rkt = TestRockets.makeEstesAlphaIII(); + + // PRE-CONDITION: + // test that all configurations correctly loaded: + int expectedConfigCount = 5; + int actualConfigCount = rkt.getConfigurationCount(); + assertThat("number of loaded configuration counts doesn't actually match.", actualConfigCount, equalTo(expectedConfigCount)); + + // create with + rkt.createFlightConfiguration(null); + expectedConfigCount = 6; + actualConfigCount = rkt.getConfigurationCount(); + assertThat("createFlightConfiguration with null: doesn't actually work.", actualConfigCount, equalTo(expectedConfigCount)); + } + + @Test + public void testGetNullSelectedConfiguration(){ + Rocket rkt = new Rocket(); + + // PRE-CONDITION: + // test that all configurations correctly loaded: + int expectedConfigCount = 0; + int actualConfigCount = rkt.getConfigurationCount(); + assertThat("number of loaded configuration counts doesn't actually match.", actualConfigCount, equalTo(expectedConfigCount)); + + rkt.getSelectedConfiguration(); + expectedConfigCount = 1; + actualConfigCount = rkt.getConfigurationCount(); + assertThat("createFlightConfiguration with null: doesn't actually work.", actualConfigCount, equalTo(expectedConfigCount)); + } + + @Test + public void testConfigurationSpecific() { /* Setup */ Rocket rkt = TestRockets.makeEstesAlphaIII(); @@ -156,14 +187,21 @@ public class FlightConfigurationTest extends BaseTestCase { int expectedMotorCount = 5; int actualMotorCount = smmt.getMotorCount(); assertThat("number of motor configurations doesn't match.", actualMotorCount, equalTo(expectedMotorCount)); - + // test that all configurations correctly loaded: int expectedConfigCount = 5; int actualConfigCount = rkt.getConfigurationCount(); assertThat("number of loaded configuration counts doesn't actually match.", actualConfigCount, equalTo(expectedConfigCount)); - - - } + + actualConfigCount = rkt.getIds().size(); + assertThat("number of configuration array ids doesn't actually match.", + actualConfigCount, equalTo(expectedConfigCount)); + + int expectedConfigArraySize = 6; + int actualConfigArraySize = rkt.toConfigArray().length; + assertThat("Size of configuration arrays doesn't actually match.", + actualConfigArraySize, equalTo(expectedConfigArraySize)); + } /** * Multi stage rocket specific configuration tests diff --git a/core/test/net/sf/openrocket/rocketcomponent/RocketTest.java b/core/test/net/sf/openrocket/rocketcomponent/RocketTest.java index ea2c50f9e..8807e7a5b 100644 --- a/core/test/net/sf/openrocket/rocketcomponent/RocketTest.java +++ b/core/test/net/sf/openrocket/rocketcomponent/RocketTest.java @@ -39,7 +39,6 @@ public class RocketTest extends BaseTestCase { FlightConfigurationId fcid5 = config5.getId(); assertThat("fcids should match: ", config2.getId(), equalTo(fcid5)); assertThat("Configurations should bef different match: "+config2.toDebug()+"=?="+config5.toDebug(), config2.instanceNumber, not( config5.instanceNumber)); - } diff --git a/swing/src/net/sf/openrocket/gui/adaptors/ParameterSetModel.java b/swing/src/net/sf/openrocket/gui/adaptors/ParameterSetModel.java index e581e6fbf..d417b853c 100644 --- a/swing/src/net/sf/openrocket/gui/adaptors/ParameterSetModel.java +++ b/swing/src/net/sf/openrocket/gui/adaptors/ParameterSetModel.java @@ -47,7 +47,7 @@ public class ParameterSetModel> impleme @Override public int getSize() { - this.idList = this.sourceSet.getSortedConfigurationIDs(); + this.idList = this.sourceSet.getIds(); return this.idList.size(); } @@ -109,7 +109,7 @@ public class ParameterSetModel> impleme return; } fireListDataEvent(); - this.idList = this.sourceSet.getSortedConfigurationIDs(); + this.idList = this.sourceSet.getIds(); } } 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 dd115452a..a77e7d92a 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java @@ -34,8 +34,8 @@ import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.unit.UnitGroup; import net.sf.openrocket.util.Chars; +@SuppressWarnings("serial") public class MotorConfigurationPanel extends FlightConfigurablePanel { - private static final long serialVersionUID = -5046535300435793744L; private static final String NONE = trans.get("edtmotorconfdlg.tbl.None"); @@ -60,7 +60,6 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel subpanel.add(label, "wrap"); MotorMountConfigurationPanel mountConfigPanel = new MotorMountConfigurationPanel(this,rocket) { - private static final long serialVersionUID = -238261338962282816L; @Override public void onDataChanged() { @@ -138,8 +137,6 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel protected JTable initializeTable() { //// Motor selection table. configurationTableModel = new FlightConfigurableTableModel(MotorMount.class,rocket) { - private static final long serialVersionUID = -1210899988369000567L; - @Override protected boolean includeComponent(MotorMount component) { return component.isMotorMount(); @@ -270,7 +267,6 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel private class MotorTableCellRenderer extends FlightConfigurablePanel.FlightConfigurableCellRenderer { - private static final long serialVersionUID = -7462331042920067984L; @Override protected JLabel format( MotorMount mount, FlightConfigurationId configId, JLabel l ) { diff --git a/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java b/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java index 56d4c7168..12439066c 100644 --- a/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java +++ b/swing/src/net/sf/openrocket/gui/scalefigure/RocketFigure.java @@ -49,9 +49,9 @@ import net.sf.openrocket.util.Transformation; * * @author Sampo Niskanen */ +@SuppressWarnings("serial") public class RocketFigure extends AbstractScaleFigure { - private static final long serialVersionUID = 45884403769043138L; - + private static final Logger log = LoggerFactory.getLogger(BasicEventSimulationEngine.class); private static final String ROCKET_FIGURE_PACKAGE = "net.sf.openrocket.gui.rocketfigure"; diff --git a/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java b/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java index ad2dcac3b..988cfed62 100644 --- a/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java +++ b/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java @@ -81,8 +81,8 @@ import net.sf.openrocket.util.StateChangeListener; * @author Sampo Niskanen * @author Bill Kuker */ +@SuppressWarnings("serial") public class RocketPanel extends JPanel implements TreeSelectionListener, ChangeSource { - private static final long serialVersionUID = 1L; private static final Translator trans = Application.getTranslator(); From 345d5952c6184dc63d881412de2f49d8c7ee58eb Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Sun, 10 Apr 2016 16:40:20 -0400 Subject: [PATCH 04/12] [Refine] Copying a FlightConfiguration in the UI now updates correctly. - involved adjusting clone() -> copy(...) in FlightConfigurableParameters --- .../openrocket/motor/MotorConfiguration.java | 47 ++++++++++++------- .../motor/MotorConfigurationId.java | 10 +--- .../rocketcomponent/AxialStage.java | 4 +- .../openrocket/rocketcomponent/BodyTube.java | 4 +- .../DeploymentConfiguration.java | 3 ++ .../FlightConfigurableComponent.java | 2 +- .../FlightConfigurableParameter.java | 17 +++++-- .../FlightConfigurableParameterSet.java | 5 +- .../rocketcomponent/FlightConfiguration.java | 47 ++++++++++++------- .../FlightConfigurationId.java | 6 +-- .../IgnitionConfiguration.java | 9 ++-- .../openrocket/rocketcomponent/InnerTube.java | 4 +- .../rocketcomponent/ParallelStage.java | 4 +- .../rocketcomponent/RecoveryDevice.java | 4 +- .../StageSeparationConfiguration.java | 4 ++ .../CopyFlightConfigurationVisitor.java | 31 ------------ .../rocketcomponent/ParameterSetTest.java | 17 ++++--- .../FlightConfigurationPanel.java | 24 +++++----- 18 files changed, 125 insertions(+), 117 deletions(-) delete mode 100644 core/src/net/sf/openrocket/rocketvisitors/CopyFlightConfigurationVisitor.java diff --git a/core/src/net/sf/openrocket/motor/MotorConfiguration.java b/core/src/net/sf/openrocket/motor/MotorConfiguration.java index 7148cd479..115e35350 100644 --- a/core/src/net/sf/openrocket/motor/MotorConfiguration.java +++ b/core/src/net/sf/openrocket/motor/MotorConfiguration.java @@ -186,23 +186,36 @@ public class MotorConfiguration implements FlightConfigurableParameter { /** - * Return a copy of this object. The listeners must not be copied - * to the new object. + * return an exact copy of this object */ - public E clone(); - - public void update(); + E clone(); + + /** + * return a copy of this object, corresponding to the specified Id + * + * @param fcid id to attach the new object to + * @return the desired copy + */ + E copy( final FlightConfigurationId fcid ); + + void update(); } diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurableParameterSet.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurableParameterSet.java index 57002c737..cc4ef365b 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurableParameterSet.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurableParameterSet.java @@ -221,10 +221,11 @@ public class FlightConfigurableParameterSet { - - private final FlightConfigurationId oldConfigId; - private final FlightConfigurationId newConfigId; - - public CopyFlightConfigurationVisitor(FlightConfigurationId oldConfigId, FlightConfigurationId newConfigId) { - super(); - this.oldConfigId = oldConfigId; - this.newConfigId = newConfigId; - } - - @Override - public void doAction(RocketComponent visitable) { - - if (visitable instanceof FlightConfigurableComponent) { - ((FlightConfigurableComponent) visitable).cloneFlightConfiguration(oldConfigId, newConfigId); - } - } - - @Override - public Void getResult() { - return null; - } - -} diff --git a/core/test/net/sf/openrocket/rocketcomponent/ParameterSetTest.java b/core/test/net/sf/openrocket/rocketcomponent/ParameterSetTest.java index 763c4a9c1..2039ebd28 100644 --- a/core/test/net/sf/openrocket/rocketcomponent/ParameterSetTest.java +++ b/core/test/net/sf/openrocket/rocketcomponent/ParameterSetTest.java @@ -51,11 +51,16 @@ public class ParameterSetTest extends BaseTestCase { public String toString(){ return "tp#:"+id; } - - @Override - public TestParameter clone(){ - return new TestParameter(); - } + + @Override + public TestParameter clone(){ + return new TestParameter(); + } + + @Override + public TestParameter copy( final FlightConfigurationId copyId){ + return new TestParameter(); + } }; @Before @@ -230,7 +235,7 @@ public class ParameterSetTest extends BaseTestCase { assertThat("set stores default value correctly: ", testSet.get(fcid2), equalTo( tp2 )); FlightConfigurationId fcid3 = new FlightConfigurationId(); - testSet.cloneFlightConfiguration(fcid2, fcid3); + testSet.copyFlightConfiguration(fcid2, fcid3); // fcid <=> tp2 should be stored.... assertThat("set should contain zero overrides: ", testSet.size(), equalTo( 2 )); assertThat("set stores default value correctly: ", testSet.get(fcid3), not( testSet.getDefault() )); 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 6412f4910..223256343 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurationPanel.java @@ -27,8 +27,6 @@ import net.sf.openrocket.startup.Application; import net.sf.openrocket.util.StateChangeListener; public class FlightConfigurationPanel extends JPanel implements StateChangeListener { - private static final long serialVersionUID = -5467500312467789009L; - //private static final Logger log = LoggerFactory.getLogger(FlightConfigurationPanel.class); private static final Translator trans = Application.getTranslator(); private final OpenRocketDocument document; @@ -123,7 +121,6 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe private void addConfiguration() { FlightConfigurationId newFCID = new FlightConfigurationId(); FlightConfiguration newConfig = new FlightConfiguration( rocket, newFCID ); - rocket.setFlightConfiguration(newFCID, newConfig); // Create a new simulation for this configuration. @@ -133,14 +130,15 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe } private void copyConfiguration() { - FlightConfiguration oldConfig = rocket.getSelectedConfiguration(); - FlightConfiguration newConfig = oldConfig.clone(); - FlightConfigurationId oldId = oldConfig.getFlightConfigurationID(); - FlightConfigurationId newId = newConfig.getFlightConfigurationID(); - + FlightConfiguration oldConfig = rocket.getSelectedConfiguration(); + FlightConfigurationId oldId = oldConfig.getFlightConfigurationID(); + + FlightConfigurationId newId = new FlightConfigurationId(); + FlightConfiguration newConfig = oldConfig.copy( newId); + for (RocketComponent c : rocket) { if (c instanceof FlightConfigurableComponent) { - ((FlightConfigurableComponent) c).cloneFlightConfiguration(oldId, newId); + ((FlightConfigurableComponent) c).copyFlightConfiguration(oldId, newId); } } rocket.setFlightConfiguration(newId, newConfig); @@ -170,8 +168,10 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe private void createSimulationForNewConfiguration() { Simulation newSim = new Simulation(rocket); OpenRocketDocument doc = BasicFrame.findDocument(rocket); - newSim.setName(doc.getNextSimulationName()); - doc.addSimulation(newSim); + if (doc != null) { + newSim.setName(doc.getNextSimulationName()); + doc.addSimulation(newSim); + } } private void configurationChanged() { @@ -192,7 +192,7 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe int motorMountCount = rocket.accept(new ListMotorMounts()).size(); // Count the number of recovery devices - int recoveryDeviceCount = rocket.accept(new ListComponents(RecoveryDevice.class)).size(); + int recoveryDeviceCount = rocket.accept(new ListComponents<>(RecoveryDevice.class)).size(); // Count the number of stages int stageCount = rocket.getStageCount(); From fedda3278ed08d5090aca5def765992678fc4ca0 Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Sun, 10 Apr 2016 23:30:18 -0400 Subject: [PATCH 05/12] [Refine] Refining the FlightConfiguration UI behavior - the selected configuration in a rocket is now specified by id instead of instance - tighted up Configuration UI behavior - operations should now start from selected configuration row --- .../importt/MotorConfigurationHandler.java | 4 +-- .../rocketcomponent/FlightConfiguration.java | 10 +------ .../sf/openrocket/rocketcomponent/Rocket.java | 20 +++----------- .../net/sf/openrocket/util/TestRockets.java | 16 +++++------- .../GeneralOptimizationDialog.java | 6 +---- .../FlightConfigurationPanel.java | 26 +++++++++---------- .../gui/scalefigure/RocketPanel.java | 2 +- 7 files changed, 28 insertions(+), 56 deletions(-) diff --git a/core/src/net/sf/openrocket/file/openrocket/importt/MotorConfigurationHandler.java b/core/src/net/sf/openrocket/file/openrocket/importt/MotorConfigurationHandler.java index 890c85af0..5aaa42cc3 100644 --- a/core/src/net/sf/openrocket/file/openrocket/importt/MotorConfigurationHandler.java +++ b/core/src/net/sf/openrocket/file/openrocket/importt/MotorConfigurationHandler.java @@ -62,9 +62,7 @@ class MotorConfigurationHandler extends AbstractElementHandler { } if ("true".equals(attributes.remove("default"))) { - // also associate this configuration with the default. - FlightConfiguration fc = rocket.getFlightConfiguration(fcid); - rocket.setSelectedConfiguration( fc); + rocket.setSelectedConfiguration( fcid); } super.closeElement(element, attributes, content, warnings); diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java index e86aa4b4c..fc562d5e2 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java @@ -343,15 +343,7 @@ public class FlightConfiguration implements FlightConfigurableParameter getMotorIDs() { - return motors.keySet(); - } - - public MotorConfiguration getMotorInstance(MotorConfigurationId id) { - return motors.get(id); - } - + public boolean hasMotors() { return (0 < motors.size()); } diff --git a/core/src/net/sf/openrocket/rocketcomponent/Rocket.java b/core/src/net/sf/openrocket/rocketcomponent/Rocket.java index 2fcecc70e..bcd9b3fb7 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/Rocket.java +++ b/core/src/net/sf/openrocket/rocketcomponent/Rocket.java @@ -511,7 +511,7 @@ public class Rocket extends RocketComponent { public void freeze() { checkState(); if (freezeList == null) { - freezeList = new LinkedList(); + freezeList = new LinkedList<>(); log.debug("Freezing Rocket"); } else { Application.getExceptionHandler().handleErrorCondition("Attempting to freeze Rocket when it is already frozen, " + @@ -702,24 +702,12 @@ public class Rocket extends RocketComponent { return idList.get(configIndex); } - public void setSelectedConfiguration(final FlightConfiguration config) { + public void setSelectedConfiguration(final FlightConfigurationId selectId) { checkState(); - this.selectedConfiguration = config; + this.selectedConfiguration = this.configSet.get( selectId ); fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE); } - - public void setDefaultConfiguration(final FlightConfigurationId fcid) { - checkState(); - - if( fcid.hasError() ){ - log.error("attempt to set a 'fcid = config' with a error fcid. Ignored.", new IllegalArgumentException("error id:"+fcid)); - return; - }else if( this.configSet.containsId(fcid)){ - this.selectedConfiguration = configSet.get(fcid); - fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE); - } - } - + /** * Associate the given ID and flight configuration. * null or an empty string. diff --git a/core/src/net/sf/openrocket/util/TestRockets.java b/core/src/net/sf/openrocket/util/TestRockets.java index 580dd5600..9c5ed9b77 100644 --- a/core/src/net/sf/openrocket/util/TestRockets.java +++ b/core/src/net/sf/openrocket/util/TestRockets.java @@ -515,7 +515,7 @@ public class TestRockets { bodytube.setMaterial(material); finset.setMaterial(material); - rocket.setSelectedConfiguration( rocket.getFlightConfiguration( fcid[0])); + rocket.setSelectedConfiguration( fcid[0] ); rocket.getSelectedConfiguration().setAllStages(); rocket.enableEvents(); return rocket; @@ -535,8 +535,7 @@ public class TestRockets { fcid[i] = new FlightConfigurationId(); rocket.createFlightConfiguration(fcid[i]); } - FlightConfiguration selectedConfiguration = rocket.getFlightConfiguration(fcid[0]); - + double noseconeLength = 0.07; double noseconeRadius = 0.012; NoseCone nosecone = new NoseCone(Transition.Shape.OGIVE, noseconeLength, noseconeRadius); @@ -708,7 +707,7 @@ public class TestRockets { } rocket.getSelectedConfiguration().setAllStages(); - rocket.setSelectedConfiguration( selectedConfiguration ); + rocket.setSelectedConfiguration( fcid[0] ); rocket.enableEvents(); return rocket; } @@ -1024,11 +1023,10 @@ public class TestRockets { Rocket rocket = new Rocket(); rocket.setName("Falcon9H Scale Rocket"); + FlightConfiguration selConfig = rocket.createFlightConfiguration(null); + FlightConfigurationId selFCID = selConfig.getFlightConfigurationID(); + rocket.setSelectedConfiguration(selFCID); - FlightConfiguration selConfig = rocket.createFlightConfiguration(null); - rocket.setSelectedConfiguration(selConfig); - FlightConfigurationId selFCID = selConfig.getFlightConfigurationID(); - // ====== Payload Stage ====== // ====== ====== ====== ====== AxialStage payloadStage = new AxialStage(); @@ -1175,7 +1173,7 @@ public class TestRockets { } rocket.enableEvents(); - rocket.setSelectedConfiguration(selConfig); + rocket.setSelectedConfiguration( selFCID); selConfig.setAllStages(); return rocket; diff --git a/swing/src/net/sf/openrocket/gui/dialogs/optimization/GeneralOptimizationDialog.java b/swing/src/net/sf/openrocket/gui/dialogs/optimization/GeneralOptimizationDialog.java index e8c42a5cd..33ec67823 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/optimization/GeneralOptimizationDialog.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/optimization/GeneralOptimizationDialog.java @@ -1165,11 +1165,7 @@ public class GeneralOptimizationDialog extends JDialog { } else { selectedModifierDescription.setText(""); } - - // Update the active configuration - FlightConfigurationId fcid = getSelectedSimulation().getId(); - getSelectedSimulation().getRocket().setDefaultConfiguration(fcid); - + updating = false; } 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 223256343..724ed3b95 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurationPanel.java @@ -115,23 +115,22 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe updateButtonState(); this.add(tabs, "spanx, grow, wrap rel"); - } private void addConfiguration() { - FlightConfigurationId newFCID = new FlightConfigurationId(); - FlightConfiguration newConfig = new FlightConfiguration( rocket, newFCID ); - rocket.setFlightConfiguration(newFCID, newConfig); - + FlightConfigurationId newId = new FlightConfigurationId(); + FlightConfiguration newConfig = new FlightConfiguration( rocket, newId ); + rocket.setFlightConfiguration( newId, newConfig); + // Create a new simulation for this configuration. - createSimulationForNewConfiguration(); + createSimulationForNewConfiguration( newId ); configurationChanged(); } private void copyConfiguration() { - FlightConfiguration oldConfig = rocket.getSelectedConfiguration(); - FlightConfigurationId oldId = oldConfig.getFlightConfigurationID(); + FlightConfigurationId oldId = this.motorConfigurationPanel.getSelectedConfigurationId(); + FlightConfiguration oldConfig = rocket.getFlightConfiguration(oldId); FlightConfigurationId newId = new FlightConfigurationId(); FlightConfiguration newConfig = oldConfig.copy( newId); @@ -141,10 +140,11 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe ((FlightConfigurableComponent) c).copyFlightConfiguration(oldId, newId); } } - rocket.setFlightConfiguration(newId, newConfig); - - // Create a new simulation for this configuration. - createSimulationForNewConfiguration(); + rocket.setFlightConfiguration( newId, newConfig); + + + // Create a new simulation for this configuration. + createSimulationForNewConfiguration( newId); configurationChanged(); } @@ -165,7 +165,7 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe /** * prereq - assumes that the new configuration has been set as the default configuration. */ - private void createSimulationForNewConfiguration() { + private void createSimulationForNewConfiguration( final FlightConfigurationId fcid ) { Simulation newSim = new Simulation(rocket); OpenRocketDocument doc = BasicFrame.findDocument(rocket); if (doc != null) { diff --git a/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java b/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java index 988cfed62..a843a00e8 100644 --- a/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java +++ b/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java @@ -320,7 +320,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change @Override public void actionPerformed(ActionEvent ae) { FlightConfiguration newConfig = (FlightConfiguration)configComboBox.getSelectedItem(); - document.getRocket().setSelectedConfiguration( newConfig); + document.getRocket().setSelectedConfiguration( newConfig.getId()); updateExtras(); updateFigures(); } From df328c15559068a63055c0fd8598405cef75ff55 Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Fri, 15 Apr 2016 23:21:19 -0400 Subject: [PATCH 06/12] [Bugfix] Rolled back the selected=default => new config 'feature' --- core/src/net/sf/openrocket/rocketcomponent/Rocket.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/core/src/net/sf/openrocket/rocketcomponent/Rocket.java b/core/src/net/sf/openrocket/rocketcomponent/Rocket.java index bcd9b3fb7..1f09b3aac 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/Rocket.java +++ b/core/src/net/sf/openrocket/rocketcomponent/Rocket.java @@ -566,9 +566,6 @@ public class Rocket extends RocketComponent { */ public FlightConfiguration getSelectedConfiguration() { checkState(); - if( this.selectedConfiguration == this.configSet.getDefault() ){ - selectedConfiguration = createFlightConfiguration(null); - } return selectedConfiguration; } @@ -591,8 +588,9 @@ public class Rocket extends RocketComponent { } /** - * Remove a flight configuration ID from the configuration IDs. The null - * ID cannot be removed, and an attempt to remove it will be silently ignored. + * Remove a flight configuration ID from the configuration IDs. The + * FlightConfigurationId.DEFAULT_VALUE_FCID ID cannot be removed, + * and an attempt to remove it will be silently ignored. * * @param fcid the flight configuration ID to remove */ @@ -604,7 +602,7 @@ public class Rocket extends RocketComponent { // Get current configuration: this.configSet.reset( fcid); - fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); + fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE); } From b02e164bce96e6f7bb46af0485cc2345ae7abf8a Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Sat, 16 Apr 2016 11:10:33 -0400 Subject: [PATCH 07/12] [bugfix] RocketPanel configuration list now updates changes - Pulled JComboBoxModel into its own class: ConfigurationModel -- removed Rocket.toConfigArray() --> getFlightConfigurationByIndex(int,bool) -Refactored document.getDefaultConfiguration -> getSelected... -- because that's what it does. Default is a different thing. -minor: minor spelling errors and unused fields/functions --- .../document/OpenRocketDocument.java | 2 +- .../openrocket/importt/OpenRocketLoader.java | 2 +- .../rocketcomponent/FlightConfiguration.java | 28 ++++---- .../sf/openrocket/rocketcomponent/Rocket.java | 42 ++++++----- .../FlightConfigurationTest.java | 47 ++++++------ .../gui/components/ConfigurationModel.java | 71 +++++++++++++++++++ .../gui/dialogs/ComponentAnalysisDialog.java | 21 +++--- .../gui/figure3d/photo/PhotoPanel.java | 2 +- .../FlightConfigurationPanel.java | 1 + .../gui/scalefigure/RocketPanel.java | 57 ++++++++------- .../gui/simulation/SimulationEditDialog.java | 8 ++- 11 files changed, 182 insertions(+), 99 deletions(-) create mode 100644 swing/src/net/sf/openrocket/gui/components/ConfigurationModel.java diff --git a/core/src/net/sf/openrocket/document/OpenRocketDocument.java b/core/src/net/sf/openrocket/document/OpenRocketDocument.java index 15d63c32c..376728c21 100644 --- a/core/src/net/sf/openrocket/document/OpenRocketDocument.java +++ b/core/src/net/sf/openrocket/document/OpenRocketDocument.java @@ -164,7 +164,7 @@ public class OpenRocketDocument implements ComponentChangeListener { } - public FlightConfiguration getDefaultConfiguration() { + public FlightConfiguration getSelectedConfiguration() { return rocket.getSelectedConfiguration(); } diff --git a/core/src/net/sf/openrocket/file/openrocket/importt/OpenRocketLoader.java b/core/src/net/sf/openrocket/file/openrocket/importt/OpenRocketLoader.java index 8bfba9ae7..7662c80ad 100644 --- a/core/src/net/sf/openrocket/file/openrocket/importt/OpenRocketLoader.java +++ b/core/src/net/sf/openrocket/file/openrocket/importt/OpenRocketLoader.java @@ -53,7 +53,7 @@ public class OpenRocketLoader extends AbstractRocketLoader { throw new RocketLoadException("Malformed XML in input.", e); } - doc.getDefaultConfiguration().setAllStages(); + doc.getSelectedConfiguration().setAllStages(); // Deduce suitable time skip double timeSkip = StorageOptions.SIMULATION_DATA_NONE; diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java index fc562d5e2..a8d48be8e 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java @@ -6,7 +6,6 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Queue; -import java.util.Set; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -52,10 +51,6 @@ public class FlightConfiguration implements FlightConfigurableParameterFlightConfigurationId.DEFAULT_VALUE_FCID ID cannot be removed, @@ -668,7 +663,7 @@ public class Rocket extends RocketComponent { return this.getFlightConfiguration(fcid); } FlightConfiguration nextConfig = new FlightConfiguration(this, fcid); - this.configSet.set(nextConfig.getFlightConfigurationID(), nextConfig); + this.configSet.set(nextConfig.getId(), nextConfig); fireComponentChangeEvent(ComponentChangeEvent.TREE_CHANGE); return nextConfig; } @@ -685,13 +680,25 @@ public class Rocket extends RocketComponent { return this.configSet.get(fcid); } + public FlightConfiguration getFlightConfigurationByIndex(final int configIndex) { + return getFlightConfigurationByIndex( configIndex, false); + } + /** - * Return a flight configuration. If the supplied index is out of bounds, an exception is thrown. + * Return a flight configuration. If the supplied index is out of bounds, an exception is thrown. + * If the default instance is allowed, the default will be at index 0. * - * @param configIndex the flight configuration index number - * @return a FlightConfiguration instance + * @param includeDefault Whether to allow returning the default instance + * @param configIndex The flight configuration index number + * @return a FlightConfiguration instance */ - public FlightConfiguration getFlightConfiguration(final int configIndex) { + public FlightConfiguration getFlightConfigurationByIndex( int configIndex, final boolean allowDefault ) { + if( allowDefault ){ + if( 0 == configIndex ){ + return configSet.getDefault(); + } + --configIndex; + } return this.configSet.get( this.getId(configIndex)); } @@ -704,7 +711,7 @@ public class Rocket extends RocketComponent { checkState(); this.selectedConfiguration = this.configSet.get( selectId ); fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE); - } + } /** * Associate the given ID and flight configuration. @@ -728,7 +735,6 @@ public class Rocket extends RocketComponent { fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE); } - //////// Obligatory component information @Override public String getComponentName() { diff --git a/core/test/net/sf/openrocket/rocketcomponent/FlightConfigurationTest.java b/core/test/net/sf/openrocket/rocketcomponent/FlightConfigurationTest.java index 8740ad46a..47bcfb3e1 100644 --- a/core/test/net/sf/openrocket/rocketcomponent/FlightConfigurationTest.java +++ b/core/test/net/sf/openrocket/rocketcomponent/FlightConfigurationTest.java @@ -162,23 +162,7 @@ public class FlightConfigurationTest extends BaseTestCase { } @Test - public void testGetNullSelectedConfiguration(){ - Rocket rkt = new Rocket(); - - // PRE-CONDITION: - // test that all configurations correctly loaded: - int expectedConfigCount = 0; - int actualConfigCount = rkt.getConfigurationCount(); - assertThat("number of loaded configuration counts doesn't actually match.", actualConfigCount, equalTo(expectedConfigCount)); - - rkt.getSelectedConfiguration(); - expectedConfigCount = 1; - actualConfigCount = rkt.getConfigurationCount(); - assertThat("createFlightConfiguration with null: doesn't actually work.", actualConfigCount, equalTo(expectedConfigCount)); - } - - @Test - public void testConfigurationSpecific() { + public void testMotorConfigurations() { /* Setup */ Rocket rkt = TestRockets.makeEstesAlphaIII(); @@ -188,6 +172,12 @@ public class FlightConfigurationTest extends BaseTestCase { int actualMotorCount = smmt.getMotorCount(); assertThat("number of motor configurations doesn't match.", actualMotorCount, equalTo(expectedMotorCount)); + } + + @Test + public void testFlightConfigurationGetters(){ + Rocket rkt = TestRockets.makeEstesAlphaIII(); + // test that all configurations correctly loaded: int expectedConfigCount = 5; int actualConfigCount = rkt.getConfigurationCount(); @@ -197,10 +187,25 @@ public class FlightConfigurationTest extends BaseTestCase { assertThat("number of configuration array ids doesn't actually match.", actualConfigCount, equalTo(expectedConfigCount)); - int expectedConfigArraySize = 6; - int actualConfigArraySize = rkt.toConfigArray().length; - assertThat("Size of configuration arrays doesn't actually match.", - actualConfigArraySize, equalTo(expectedConfigArraySize)); + // upon success, these silently complete. + // upon failure, they'll throw exceptions: + rkt.getFlightConfigurationByIndex(4); + rkt.getFlightConfigurationByIndex(5, true); + } + + + @Test(expected=java.lang.IndexOutOfBoundsException.class) + public void testGetFlightConfigurationOutOfBounds(){ + Rocket rkt = TestRockets.makeEstesAlphaIII(); + + // test that all configurations correctly loaded: + int expectedConfigCount = 5; + int actualConfigCount = rkt.getConfigurationCount(); + assertThat("number of loaded configuration counts doesn't actually match.", actualConfigCount, equalTo(expectedConfigCount)); + + // this SHOULD throw an exception -- + // it's out of bounds on, and no configuration exists at index 5. + rkt.getFlightConfigurationByIndex(5); } /** diff --git a/swing/src/net/sf/openrocket/gui/components/ConfigurationModel.java b/swing/src/net/sf/openrocket/gui/components/ConfigurationModel.java new file mode 100644 index 000000000..a7d1219f3 --- /dev/null +++ b/swing/src/net/sf/openrocket/gui/components/ConfigurationModel.java @@ -0,0 +1,71 @@ +package net.sf.openrocket.gui.components; + +import net.sf.openrocket.rocketcomponent.FlightConfigurationId; +import net.sf.openrocket.rocketcomponent.Rocket; +import net.sf.openrocket.rocketcomponent.FlightConfiguration; +import net.sf.openrocket.util.StateChangeListener; + +import javax.swing.*; +import javax.swing.event.ListDataListener; + +import java.util.EventObject; + +public class ConfigurationModel implements ComboBoxModel, StateChangeListener { + + private final Rocket rkt; + + //private FlightConfigurationSelector(){} + + public ConfigurationModel( final Rocket _rkt) { + rkt = _rkt; + } + + + @Override + public void stateChanged(EventObject e) { +// FlightConfiguration newConfig = (FlightConfiguration)this.getSelectedItem(); +// rkt.setSelectedConfiguration( newConfig.getId()); + } + + + @Override + public Object getSelectedItem() { + return rkt.getSelectedConfiguration(); + } + + + @Override + public void setSelectedItem(Object nextItem) { + if( nextItem instanceof FlightConfiguration ){ + FlightConfigurationId selectedId = ((FlightConfiguration)nextItem).getId(); + rkt.setSelectedConfiguration(selectedId); + } + } + + @Override + public void addListDataListener(ListDataListener l) { + // let the rocket send events, if necessary + // ignore any listen requests here... + } + + + public FlightConfiguration getElementAt( final int configIndex) { + return rkt.getFlightConfigurationByIndex(configIndex, true); + } + + + @Override + public int getSize() { + // plus the default config + return rkt.getConfigurationCount()+1; + } + + + @Override + public void removeListDataListener(ListDataListener l) { + // delegate event handling to the rocket + // ignore any listen requests here... + } + + +} diff --git a/swing/src/net/sf/openrocket/gui/dialogs/ComponentAnalysisDialog.java b/swing/src/net/sf/openrocket/gui/dialogs/ComponentAnalysisDialog.java index 8d7133a88..860f5cdbf 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/ComponentAnalysisDialog.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/ComponentAnalysisDialog.java @@ -47,6 +47,7 @@ import net.sf.openrocket.gui.adaptors.ColumnTable; import net.sf.openrocket.gui.adaptors.ColumnTableModel; import net.sf.openrocket.gui.adaptors.DoubleModel; import net.sf.openrocket.gui.components.BasicSlider; +import net.sf.openrocket.gui.components.ConfigurationModel; import net.sf.openrocket.gui.components.StageSelector; import net.sf.openrocket.gui.components.StyledLabel; import net.sf.openrocket.gui.components.UnitSelector; @@ -75,7 +76,7 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe private final FlightConditions conditions; - private final FlightConfiguration configuration; + private final Rocket rkt; private final DoubleModel theta, aoa, mach, roll; private final JToggleButton worstToggle; private boolean fakeChange = false; @@ -105,11 +106,11 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe JPanel panel = new JPanel(new MigLayout("fill")); add(panel); - this.configuration = rocketPanel.getConfiguration(); + rkt = rocketPanel.getDocument().getRocket(); this.aerodynamicCalculator = rocketPanel.getAerodynamicCalculator().newInstance(); - conditions = new FlightConditions(configuration); + conditions = new FlightConditions(rkt.getSelectedConfiguration()); rocketPanel.setCPAOA(0); aoa = new DoubleModel(rocketPanel, "CPAOA", UnitGroup.UNITS_ANGLE, 0, Math.PI); @@ -169,7 +170,6 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe // Stage and motor selection: //// Active stages: panel.add(new JLabel(trans.get("componentanalysisdlg.lbl.activestages")), "spanx, split, gapafter rel"); - Rocket rkt = rocketPanel.getDocument().getRocket(); panel.add(new StageSelector( rkt), "gapafter paragraph"); //// Motor configuration: @@ -177,9 +177,9 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe label.setHorizontalAlignment(JLabel.RIGHT); panel.add(label, "growx, right"); - JComboBox combo = new JComboBox( configuration.getRocket().toConfigArray()); - - panel.add(combo, "wrap"); + final ConfigurationModel configModel = new ConfigurationModel(rkt); + final JComboBox configComboBox = new JComboBox<>(configModel); + panel.add( configComboBox, "wrap"); // Tabbed pane @@ -517,6 +517,7 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe */ @Override public void stateChanged(EventObject e) { + final FlightConfiguration configuration = rkt.getSelectedConfiguration(); AerodynamicForces forces; WarningSet set = new WarningSet(); conditions.setAOA(aoa.getValue()); @@ -580,12 +581,12 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe data[1] = MassCalcType.LAUNCH_MASS.getCG(motorConfig); } - forces = aeroData.get(configuration.getRocket()); + forces = aeroData.get(rkt); if (forces != null) { Object[] data = new Object[3]; cgData.add(data); - data[0] = configuration.getRocket(); - data[1] = massData.get(configuration.getRocket()); + data[0] = rkt; + data[1] = massData.get(rkt); data[2] = forces; dragData.add(forces); rollData.add(forces); diff --git a/swing/src/net/sf/openrocket/gui/figure3d/photo/PhotoPanel.java b/swing/src/net/sf/openrocket/gui/figure3d/photo/PhotoPanel.java index 5ddcec25a..7e92db8b4 100644 --- a/swing/src/net/sf/openrocket/gui/figure3d/photo/PhotoPanel.java +++ b/swing/src/net/sf/openrocket/gui/figure3d/photo/PhotoPanel.java @@ -91,7 +91,7 @@ public class PhotoPanel extends JPanel implements GLEventListener { ((GLAutoDrawable) canvas).invoke(false, new GLRunnable() { @Override public boolean run(final GLAutoDrawable drawable) { - PhotoPanel.this.configuration = doc.getDefaultConfiguration(); + PhotoPanel.this.configuration = doc.getSelectedConfiguration(); cachedBounds = null; rr = new RealisticRenderer(doc); rr.init(drawable); 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 724ed3b95..607e978fe 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurationPanel.java @@ -26,6 +26,7 @@ import net.sf.openrocket.rocketvisitors.ListMotorMounts; import net.sf.openrocket.startup.Application; import net.sf.openrocket.util.StateChangeListener; +@SuppressWarnings("serial") public class FlightConfigurationPanel extends JPanel implements StateChangeListener { private static final Translator trans = Application.getTranslator(); diff --git a/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java b/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java index a843a00e8..f61bc3a63 100644 --- a/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java +++ b/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java @@ -5,8 +5,6 @@ import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.Font; import java.awt.Point; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.awt.event.InputEvent; import java.awt.event.MouseEvent; import java.util.ArrayList; @@ -42,6 +40,7 @@ import net.sf.openrocket.gui.adaptors.DoubleModel; import net.sf.openrocket.gui.components.BasicSlider; import net.sf.openrocket.gui.components.StageSelector; import net.sf.openrocket.gui.components.UnitSelector; +import net.sf.openrocket.gui.components.ConfigurationModel; import net.sf.openrocket.gui.configdialog.ComponentConfigDialog; import net.sf.openrocket.gui.figure3d.RocketFigure3d; import net.sf.openrocket.gui.figureelements.CGCaret; @@ -75,6 +74,7 @@ import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.MathUtil; import net.sf.openrocket.util.StateChangeListener; + /** * A JPanel that contains a RocketFigure and buttons to manipulate the figure. * @@ -86,7 +86,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change private static final Translator trans = Application.getTranslator(); - public static enum VIEW_TYPE { + public enum VIEW_TYPE { SideView(false, RocketFigure.VIEW_SIDE), BackView(false, RocketFigure.VIEW_BACK), Figure3D(true, RocketFigure3d.TYPE_FIGURE), @@ -96,7 +96,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change public final boolean is3d; private final int type; - private VIEW_TYPE(final boolean is3d, final int type) { + VIEW_TYPE(final boolean is3d, final int type) { this.is3d = is3d; this.type = type; }; @@ -140,7 +140,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change // The functional ID of the rocket that was simulated private int flightDataFunctionalID = -1; - private FlightConfigurationId flightDataMotorID = null; + private FlightConfigurationId flightDataMotorID = null; private SimulationWorker backgroundSimulationWorker = null; @@ -271,12 +271,21 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change * Creates the layout and components of the panel. */ private void createPanel() { + final Rocket rkt = document.getRocket(); + + rkt.addChangeListener(new StateChangeListener(){ + @Override + public void stateChanged(EventObject eo) { + updateExtras(); + updateFigures(); + } + }); + setLayout(new MigLayout("", "[shrink][grow]", "[shrink][shrink][grow][shrink]")); setPreferredSize(new Dimension(800, 300)); - // View Type Dropdown - @SuppressWarnings("serial") // because java throws a warning without this. + // View Type drop-down ComboBoxModel cm = new DefaultComboBoxModel(VIEW_TYPE.values()) { @Override @@ -301,7 +310,6 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change add(scaleSelector); // Stage selector - final Rocket rkt = document.getRocket(); StageSelector stageSelector = new StageSelector( rkt ); rkt.addChangeListener(stageSelector); add(stageSelector); @@ -311,21 +319,12 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change JLabel label = new JLabel(trans.get("RocketPanel.lbl.Flightcfg")); label.setHorizontalAlignment(JLabel.RIGHT); add(label, "growx, right"); - - final JComboBox configComboBox = new JComboBox( document.getRocket().toConfigArray()); - + + final ConfigurationModel configModel = new ConfigurationModel(rkt); + final JComboBox configComboBox = new JComboBox<>(configModel); + rkt.addChangeListener( configModel ); add(configComboBox, "wrap, width 16%, wmin 100"); - configComboBox.addActionListener(new ActionListener(){ - @Override - public void actionPerformed(ActionEvent ae) { - FlightConfiguration newConfig = (FlightConfiguration)configComboBox.getSelectedItem(); - document.getRocket().setSelectedConfiguration( newConfig.getId()); - updateExtras(); - updateFigures(); - } - }); - // Create slider and scroll pane DoubleModel theta = new DoubleModel(figure, "Rotation", @@ -361,8 +360,8 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change return aerodynamicCalculator; } - public FlightConfiguration getConfiguration() { - return document.getDefaultConfiguration(); + public FlightConfiguration getSelectedConfiguration() { + return document.getSelectedConfiguration(); } /** @@ -565,7 +564,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change Coordinate cp, cg; double cpx, cgx; - FlightConfiguration curConfig = document.getDefaultConfiguration(); + FlightConfiguration curConfig = document.getSelectedConfiguration(); // TODO: MEDIUM: User-definable conditions FlightConditions conditions = new FlightConditions(curConfig); warnings.clear(); @@ -644,7 +643,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change extraText.setLength(length); extraText.setDiameter(diameter); extraText.setMass(cg.weight); - extraText.setMassWithoutMotors( massCalculator.getCG( getConfiguration(), MassCalcType.NO_MOTORS ).weight ); + extraText.setMassWithoutMotors( massCalculator.getCG( getSelectedConfiguration(), MassCalcType.NO_MOTORS ).weight ); extraText.setWarnings(warnings); if (figure.getType() == RocketPanel.VIEW_TYPE.SideView && length > 0) { @@ -672,12 +671,12 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change // Check whether data is already up to date if (flightDataFunctionalID == curConfig.getRocket().getFunctionalModID() && - flightDataMotorID == curConfig.getFlightConfigurationID()) { + flightDataMotorID == curConfig.getId()) { return; } flightDataFunctionalID = curConfig.getRocket().getFunctionalModID(); - flightDataMotorID = curConfig.getFlightConfigurationID(); + flightDataMotorID = curConfig.getId(); // Stop previous computation (if any) stopBackgroundSimulation(); @@ -695,7 +694,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change Rocket duplicate = (Rocket) document.getRocket().copy(); Simulation simulation = ((SwingPreferences) Application.getPreferences()).getBackgroundSimulation(duplicate); - simulation.setFlightConfigurationId( document.getDefaultConfiguration().getFlightConfigurationID()); + simulation.setFlightConfigurationId( document.getSelectedConfiguration().getId()); backgroundSimulationWorker = new BackgroundSimulationWorker(document, simulation); backgroundSimulationExecutor.execute(backgroundSimulationWorker); @@ -781,7 +780,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change * Adds the extra data to the figure. Currently this includes the CP and CG carets. */ private void addExtras() { - FlightConfiguration curConfig = document.getDefaultConfiguration(); + FlightConfiguration curConfig = document.getSelectedConfiguration(); extraCG = new CGCaret(0, 0); extraCP = new CPCaret(0, 0); extraText = new RocketInfo(curConfig); diff --git a/swing/src/net/sf/openrocket/gui/simulation/SimulationEditDialog.java b/swing/src/net/sf/openrocket/gui/simulation/SimulationEditDialog.java index 18dad4a30..05c6c587d 100644 --- a/swing/src/net/sf/openrocket/gui/simulation/SimulationEditDialog.java +++ b/swing/src/net/sf/openrocket/gui/simulation/SimulationEditDialog.java @@ -21,10 +21,12 @@ import javax.swing.event.DocumentListener; import net.miginfocom.swing.MigLayout; import net.sf.openrocket.document.OpenRocketDocument; import net.sf.openrocket.document.Simulation; +import net.sf.openrocket.gui.components.ConfigurationModel; import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.rocketcomponent.FlightConfiguration; import net.sf.openrocket.rocketcomponent.FlightConfigurationId; +import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.simulation.extension.SimulationExtension; import net.sf.openrocket.startup.Application; @@ -145,8 +147,10 @@ public class SimulationEditDialog extends JDialog { label.setToolTipText(trans.get("simedtdlg.lbl.ttip.Flightcfg")); panel.add(label, "growx 0, gapright para"); - final JComboBox configComboBox = new JComboBox( document.getRocket().toConfigArray()); - configComboBox.setSelectedItem( document.getRocket().getSelectedConfiguration().getId() ); + final Rocket rkt = document.getRocket(); + final ConfigurationModel configModel = new ConfigurationModel( rkt); + final JComboBox configComboBox = new JComboBox<>(configModel); + configComboBox.setSelectedItem( rkt.getSelectedConfiguration().getId() ); //// Select the motor configuration to use. configComboBox.setToolTipText(trans.get("simedtdlg.combo.ttip.Flightcfg")); From f7090afd7923d44be92d1323e74dbea4708c03d8 Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Sun, 17 Apr 2016 11:00:48 -0400 Subject: [PATCH 08/12] [bugfix] Removing the selected configuration selects the default --- core/src/net/sf/openrocket/rocketcomponent/Rocket.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/src/net/sf/openrocket/rocketcomponent/Rocket.java b/core/src/net/sf/openrocket/rocketcomponent/Rocket.java index a0c8cad04..7dd192ecf 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/Rocket.java +++ b/core/src/net/sf/openrocket/rocketcomponent/Rocket.java @@ -595,6 +595,10 @@ public class Rocket extends RocketComponent { return; } + if( selectedConfiguration.getId().equals( fcid)){ + selectedConfiguration = configSet.getDefault(); + } + // Get current configuration: this.configSet.reset( fcid); fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE); From 3362c032796a8fcf321b00bbf469f934a3ec9317 Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Sat, 23 Apr 2016 18:36:31 -0400 Subject: [PATCH 09/12] [bugfix] Fixed several FlightConfiguration bugs - adjusted some class member names to be more descriptive - When a component lacks an entry for the currently selected FC -- Code would sometimes fail to create a new motor entry - removing a flight configuration from a rocket -- removes all component configurations tied to that configuration Id --- .../document/OpenRocketDocument.java | 2 +- .../openrocket/motor/MotorConfiguration.java | 40 +++++++++++-------- .../motor/MotorConfigurationId.java | 20 ++++++++-- .../motor/MotorConfigurationSet.java | 24 ++++++++--- .../rocketcomponent/AxialStage.java | 5 +++ .../openrocket/rocketcomponent/BodyTube.java | 6 ++- .../FlightConfigurableComponent.java | 7 ++++ .../rocketcomponent/FlightConfiguration.java | 2 +- .../openrocket/rocketcomponent/InnerTube.java | 4 ++ .../rocketcomponent/RecoveryDevice.java | 4 ++ .../sf/openrocket/rocketcomponent/Rocket.java | 13 +++++- .../FlightConfigurablePanel.java | 4 +- .../MotorConfigurationPanel.java | 24 +++++------ 13 files changed, 112 insertions(+), 43 deletions(-) diff --git a/core/src/net/sf/openrocket/document/OpenRocketDocument.java b/core/src/net/sf/openrocket/document/OpenRocketDocument.java index 376728c21..101d2e34a 100644 --- a/core/src/net/sf/openrocket/document/OpenRocketDocument.java +++ b/core/src/net/sf/openrocket/document/OpenRocketDocument.java @@ -286,7 +286,7 @@ public class OpenRocketDocument implements ComponentChangeListener { removeSimulation(s); } } - rocket.removeFlightConfigurationID(configId); + rocket.removeFlightConfiguration(configId); } diff --git a/core/src/net/sf/openrocket/motor/MotorConfiguration.java b/core/src/net/sf/openrocket/motor/MotorConfiguration.java index 115e35350..6da292a50 100644 --- a/core/src/net/sf/openrocket/motor/MotorConfiguration.java +++ b/core/src/net/sf/openrocket/motor/MotorConfiguration.java @@ -16,19 +16,18 @@ public class MotorConfiguration implements FlightConfigurableParameter> in: %28s::%10s %8s ign@: %12s ", + buf.append(String.format("[in: %28s][fcid %10s][mid %10s][ %8s ign@: %12s]", mount.getDebugName(), fcid.toShortKey(), + mid.toDebug(), toMotorDescription(), toIgnitionDescription() )); return buf.toString(); } - + } diff --git a/core/src/net/sf/openrocket/motor/MotorConfigurationId.java b/core/src/net/sf/openrocket/motor/MotorConfigurationId.java index d77d5467e..dc9c69362 100644 --- a/core/src/net/sf/openrocket/motor/MotorConfigurationId.java +++ b/core/src/net/sf/openrocket/motor/MotorConfigurationId.java @@ -33,10 +33,9 @@ public final class MotorConfigurationId { throw new NullPointerException("Provided FlightConfigurationId was null"); } - // Use intern so comparison can be done using == instead of equals() - final long upper = ((long)_mount.getID().hashCode()) << 32; - final long lower = _fcid.key.getLeastSignificantBits(); - this.key = new UUID( upper, lower); + final long mountHash= ((long)_mount.getID().hashCode()) << 32; + final long fcidLower = _fcid.key.getMostSignificantBits(); + this.key = new UUID( mountHash, fcidLower); } @Override @@ -56,6 +55,10 @@ public final class MotorConfigurationId { return key.hashCode(); } + public String toDebug(){ + return toShortKey(); + } + @Override public String toString(){ if( this.key == MotorConfigurationId.ERROR_KEY){ @@ -64,4 +67,13 @@ public final class MotorConfigurationId { return key.toString(); } } + + public String toShortKey() { + final String keyString = key.toString(); + final int lastIndex = -1 + keyString.length(); + final int chunkLen = 4; + + // return the head + tail of the full 64-character id + return (keyString.substring(0,chunkLen)+"/"+keyString.substring(lastIndex - chunkLen,lastIndex)); + } } diff --git a/core/src/net/sf/openrocket/motor/MotorConfigurationSet.java b/core/src/net/sf/openrocket/motor/MotorConfigurationSet.java index 16bf1cf2e..c986f06cb 100644 --- a/core/src/net/sf/openrocket/motor/MotorConfigurationSet.java +++ b/core/src/net/sf/openrocket/motor/MotorConfigurationSet.java @@ -4,7 +4,6 @@ import net.sf.openrocket.rocketcomponent.ComponentChangeEvent; import net.sf.openrocket.rocketcomponent.FlightConfigurableParameterSet; import net.sf.openrocket.rocketcomponent.FlightConfigurationId; import net.sf.openrocket.rocketcomponent.MotorMount; -import net.sf.openrocket.rocketcomponent.RocketComponent; /** * FlightConfigurationSet for motors. @@ -24,8 +23,15 @@ public class MotorConfigurationSet extends FlightConfigurableParameterSet configSet, RocketComponent component) { - super(configSet); + public MotorConfigurationSet(FlightConfigurableParameterSet sourceSet, final MotorMount newMount) { + // creates a new empty config w/ default value + super( new MotorConfiguration( newMount, FlightConfigurationId.DEFAULT_VALUE_FCID )); + + for( MotorConfiguration sourceConfig : sourceSet ){ + FlightConfigurationId nextFCID = sourceConfig.getFCID(); + MotorConfiguration nextValue = new MotorConfiguration( newMount, nextFCID, sourceConfig); + set( nextFCID, nextValue ); + } } @Override @@ -42,10 +48,18 @@ public class MotorConfigurationSet extends FlightConfigurableParameterSet getComponentBounds() { diff --git a/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java b/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java index b1f976b6d..734a96a4b 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java +++ b/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java @@ -92,7 +92,6 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial return outerRadius; } - /** * Set the outer radius of the body tube. If the radius is less than the wall thickness, * the wall thickness is decreased accordingly of the value of the radius. @@ -395,6 +394,11 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial public Iterator getMotorIterator(){ return this.motors.iterator(); } + + @Override + public void reset( final FlightConfigurationId fcid){ + this.motors.reset(fcid); + } @Override public void copyFlightConfiguration(FlightConfigurationId oldConfigId, FlightConfigurationId newConfigId) { diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurableComponent.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurableComponent.java index 53434956f..187f276a2 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurableComponent.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfigurableComponent.java @@ -16,4 +16,11 @@ public interface FlightConfigurableComponent { */ void copyFlightConfiguration(FlightConfigurationId oldConfigId, FlightConfigurationId newConfigId); + /** + * Reset a specific flight configuration ID to use the default parameter value. + * + * @param fcid the flight configuration ID + */ + void reset( final FlightConfigurationId fcid); + } diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java index a8d48be8e..135f84c10 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java @@ -371,7 +371,7 @@ public class FlightConfiguration implements FlightConfigurableParameter iterator = this.iterator(); + while (iterator.hasNext()) { + RocketComponent comp = iterator.next(); + + if (comp instanceof FlightConfigurableComponent){ + FlightConfigurableComponent confbl = (FlightConfigurableComponent)comp; + confbl.reset( fcid); + } + } + // Get current configuration: this.configSet.reset( fcid); fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE); 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 ddae1784b..8f3521489 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurablePanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurablePanel.java @@ -29,9 +29,10 @@ import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.startup.Application; import net.sf.openrocket.util.Pair; + +@SuppressWarnings("serial") public abstract class FlightConfigurablePanel extends JPanel { - private static final long serialVersionUID = 3359871704879603700L; protected static final Translator trans = Application.getTranslator(); private static final Logger log = LoggerFactory.getLogger(FlightConfigurablePanel.class); protected RocketDescriptor descriptor = Application.getInjector().getInstance(RocketDescriptor.class); @@ -160,7 +161,6 @@ public abstract class FlightConfigurablePanel if ( (null == fcid )||( null == curMount )){ return; } - - //MotorInstance curInstance = curMount.getMotorInstance( fcid ); - // curInstance may be empty here... - //String mountName = ((RocketComponent)curMount).getName(); - //System.err.println("?? Selecting motor "+curInstance+" for mount: "+mountName+" for config: "+fcid.toShortKey()); - + + if( fcid.equals( FlightConfigurationId.DEFAULT_VALUE_FCID)){ + throw new IllegalStateException("Attempting to set a motor on the default FCID."); + } + motorChooserDialog.setMotorMountAndConfig( fcid, curMount ); motorChooserDialog.setVisible(true); - Motor mtr = motorChooserDialog.getSelectedMotor(); + Motor mtr = motorChooserDialog.getSelectedMotor(); double d = motorChooserDialog.getSelectedDelay(); if (mtr != null) { - MotorConfiguration curConfig = curMount.getMotorConfig(fcid); - curConfig.setMotor(mtr); - curConfig.setEjectionDelay(d); - curConfig.setIgnitionEvent( IgnitionEvent.NEVER); - curMount.setMotorConfig( curConfig, fcid); + final MotorConfiguration templateConfig = curMount.getMotorConfig(fcid); + final MotorConfiguration newConfig = new MotorConfiguration( curMount, fcid, templateConfig); + newConfig.setMotor(mtr); + newConfig.setEjectionDelay(d); + curMount.setMotorConfig( newConfig, fcid); } fireTableDataChanged(); From 915d401370458cc2775d2aef2513a751f2ad5f27 Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Sun, 24 Apr 2016 10:15:48 -0400 Subject: [PATCH 10/12] [Bugfix] Configuration Selection ComboBox now correctly updates - adjusted some type cast warnings - Added 'ignore if new==current' paths in rocket configuration functions -- These if paths break potential infinite loops - added update code for the main-window selected configuration dropdown -- now updates when the currently-selected configuration is removed. --- .../openrocket/motor/MotorConfigurationSet.java | 3 ++- .../net/sf/openrocket/rocketcomponent/Rocket.java | 14 ++++++++++++-- .../gui/adaptors/ColumnTableRowSorter.java | 8 ++++---- .../gui/components/ConfigurationModel.java | 15 +++++++-------- .../sf/openrocket/gui/components/FlatButton.java | 1 + .../sf/openrocket/gui/components/HtmlLabel.java | 1 + .../gui/dialogs/ComponentAnalysisDialog.java | 5 +++-- .../openrocket/gui/dialogs/EditDecalDialog.java | 1 + .../FlightConfigurablePanel.java | 2 ++ .../FlightConfigurationPanel.java | 1 + .../openrocket/gui/scalefigure/RocketPanel.java | 5 +++-- .../gui/simulation/SimulationEditDialog.java | 6 +++--- 12 files changed, 40 insertions(+), 22 deletions(-) diff --git a/core/src/net/sf/openrocket/motor/MotorConfigurationSet.java b/core/src/net/sf/openrocket/motor/MotorConfigurationSet.java index c986f06cb..69b92d70d 100644 --- a/core/src/net/sf/openrocket/motor/MotorConfigurationSet.java +++ b/core/src/net/sf/openrocket/motor/MotorConfigurationSet.java @@ -43,7 +43,8 @@ public class MotorConfigurationSet extends FlightConfigurableParameterSet { private final ColumnTableModel columnTableModel; @@ -14,8 +14,8 @@ public class ColumnTableRowSorter extends TableRowSorter { } @Override - public Comparator getComparator(int column) { - Comparator c = columnTableModel.getColumn(column).getComparator(); + public Comparator getComparator(int column) { + Comparator c = columnTableModel.getColumn(column).getComparator(); return (c!= null) ? c : super.getComparator(column); } @@ -30,7 +30,7 @@ public class ColumnTableRowSorter extends TableRowSorter { */ @Override protected boolean useToString(int column) { - Comparator c = columnTableModel.getColumn(column).getComparator(); + Comparator c = columnTableModel.getColumn(column).getComparator(); return ( c != null ) ? false : super.useToString(column); } diff --git a/swing/src/net/sf/openrocket/gui/components/ConfigurationModel.java b/swing/src/net/sf/openrocket/gui/components/ConfigurationModel.java index a7d1219f3..2f8f57111 100644 --- a/swing/src/net/sf/openrocket/gui/components/ConfigurationModel.java +++ b/swing/src/net/sf/openrocket/gui/components/ConfigurationModel.java @@ -13,18 +13,17 @@ import java.util.EventObject; public class ConfigurationModel implements ComboBoxModel, StateChangeListener { private final Rocket rkt; + private final JComboBox combo; - //private FlightConfigurationSelector(){} - - public ConfigurationModel( final Rocket _rkt) { - rkt = _rkt; + public ConfigurationModel( final Rocket _rkt, final JComboBox _combo) { + this.rkt = _rkt; + this.combo = _combo; } - @Override - public void stateChanged(EventObject e) { -// FlightConfiguration newConfig = (FlightConfiguration)this.getSelectedItem(); -// rkt.setSelectedConfiguration( newConfig.getId()); + public void stateChanged(EventObject eo) { + combo.revalidate(); + combo.repaint(); } diff --git a/swing/src/net/sf/openrocket/gui/components/FlatButton.java b/swing/src/net/sf/openrocket/gui/components/FlatButton.java index d4c39ef40..e4ee35642 100644 --- a/swing/src/net/sf/openrocket/gui/components/FlatButton.java +++ b/swing/src/net/sf/openrocket/gui/components/FlatButton.java @@ -12,6 +12,7 @@ import javax.swing.JButton; * * @author Sampo Niskanen */ +@SuppressWarnings("serial") public class FlatButton extends JButton { public FlatButton() { diff --git a/swing/src/net/sf/openrocket/gui/components/HtmlLabel.java b/swing/src/net/sf/openrocket/gui/components/HtmlLabel.java index 59fdbfa72..d4c48f592 100644 --- a/swing/src/net/sf/openrocket/gui/components/HtmlLabel.java +++ b/swing/src/net/sf/openrocket/gui/components/HtmlLabel.java @@ -11,6 +11,7 @@ import javax.swing.JLabel; * * @author Sampo Niskanen */ +@SuppressWarnings("serial") public class HtmlLabel extends JLabel { public HtmlLabel() { diff --git a/swing/src/net/sf/openrocket/gui/dialogs/ComponentAnalysisDialog.java b/swing/src/net/sf/openrocket/gui/dialogs/ComponentAnalysisDialog.java index 860f5cdbf..4dd50d50d 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/ComponentAnalysisDialog.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/ComponentAnalysisDialog.java @@ -177,8 +177,9 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe label.setHorizontalAlignment(JLabel.RIGHT); panel.add(label, "growx, right"); - final ConfigurationModel configModel = new ConfigurationModel(rkt); - final JComboBox configComboBox = new JComboBox<>(configModel); + final JComboBox configComboBox = new JComboBox<>(); + final ConfigurationModel configModel = new ConfigurationModel(rkt, configComboBox); + configComboBox.setModel( configModel); panel.add( configComboBox, "wrap"); diff --git a/swing/src/net/sf/openrocket/gui/dialogs/EditDecalDialog.java b/swing/src/net/sf/openrocket/gui/dialogs/EditDecalDialog.java index 8a2214410..63bf9ac7e 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/EditDecalDialog.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/EditDecalDialog.java @@ -23,6 +23,7 @@ import net.sf.openrocket.gui.util.GUIUtil; import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.startup.Application; +@SuppressWarnings("serial") public class EditDecalDialog extends JDialog { private static final Translator trans = Application.getTranslator(); 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 8f3521489..39a3ed36c 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurablePanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurablePanel.java @@ -137,6 +137,7 @@ public abstract class FlightConfigurablePanel selectedComponent = (Pair) tableValue; return selectedComponent.getV(); } @@ -151,6 +152,7 @@ public abstract class FlightConfigurablePanel selectedComponent = (Pair) tableValue; FlightConfigurationId fcid = selectedComponent.getU(); return fcid; 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 607e978fe..2384b2120 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/FlightConfigurationPanel.java @@ -159,6 +159,7 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe FlightConfigurationId currentId = this.motorConfigurationPanel.getSelectedConfigurationId(); if (currentId == null) return; + System.err.println(this.rocket.toDebugConfigs()); document.removeFlightConfigurationAndSimulations(currentId); configurationChanged(); } diff --git a/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java b/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java index f61bc3a63..275c88523 100644 --- a/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java +++ b/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java @@ -320,9 +320,10 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change label.setHorizontalAlignment(JLabel.RIGHT); add(label, "growx, right"); - final ConfigurationModel configModel = new ConfigurationModel(rkt); - final JComboBox configComboBox = new JComboBox<>(configModel); + final JComboBox configComboBox = new JComboBox<>(); + final ConfigurationModel configModel = new ConfigurationModel(rkt, configComboBox); rkt.addChangeListener( configModel ); + configComboBox.setModel(configModel); add(configComboBox, "wrap, width 16%, wmin 100"); diff --git a/swing/src/net/sf/openrocket/gui/simulation/SimulationEditDialog.java b/swing/src/net/sf/openrocket/gui/simulation/SimulationEditDialog.java index 05c6c587d..cd98327c6 100644 --- a/swing/src/net/sf/openrocket/gui/simulation/SimulationEditDialog.java +++ b/swing/src/net/sf/openrocket/gui/simulation/SimulationEditDialog.java @@ -148,9 +148,9 @@ public class SimulationEditDialog extends JDialog { panel.add(label, "growx 0, gapright para"); final Rocket rkt = document.getRocket(); - final ConfigurationModel configModel = new ConfigurationModel( rkt); - final JComboBox configComboBox = new JComboBox<>(configModel); - configComboBox.setSelectedItem( rkt.getSelectedConfiguration().getId() ); + final JComboBox configComboBox = new JComboBox<>(); + final ConfigurationModel configModel = new ConfigurationModel(rkt, configComboBox); + configComboBox.setModel( configModel); //// Select the motor configuration to use. configComboBox.setToolTipText(trans.get("simedtdlg.combo.ttip.Flightcfg")); From a94e14c2a6082cf47248b3632f595972068874b6 Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Sun, 24 Apr 2016 11:31:40 -0400 Subject: [PATCH 11/12] [Bugfix] Main Window Config chooser now updates for new Configurations - --- .../gui/components/ConfigurationModel.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/swing/src/net/sf/openrocket/gui/components/ConfigurationModel.java b/swing/src/net/sf/openrocket/gui/components/ConfigurationModel.java index 2f8f57111..ebec09ac6 100644 --- a/swing/src/net/sf/openrocket/gui/components/ConfigurationModel.java +++ b/swing/src/net/sf/openrocket/gui/components/ConfigurationModel.java @@ -10,7 +10,7 @@ import javax.swing.event.ListDataListener; import java.util.EventObject; -public class ConfigurationModel implements ComboBoxModel, StateChangeListener { +public class ConfigurationModel implements MutableComboBoxModel, StateChangeListener { private final Rocket rkt; private final JComboBox combo; @@ -66,5 +66,21 @@ public class ConfigurationModel implements ComboBoxModel, S // ignore any listen requests here... } + // ====== MutableComboBoxModel Functions ====== + // these functions don't need to do anything, just being a 'mutable' version of the combo box + // is enough to allow updating the UI + + @Override + public void addElement(FlightConfiguration arg0) {} + + @Override + public void insertElementAt(FlightConfiguration arg0, int arg1) {} + + @Override + public void removeElement(Object arg0) {} + + @Override + public void removeElementAt(int arg0) {} + } From 5f9eb87fdee4999b9e050f899e41aad2b9a160a6 Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Sun, 24 Apr 2016 13:33:43 -0400 Subject: [PATCH 12/12] [Bugfix] resolved classpath errors in Eclipse --- core/.classpath | 2 ++ swing/.classpath | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/core/.classpath b/core/.classpath index 81fec6f9a..419476b88 100644 --- a/core/.classpath +++ b/core/.classpath @@ -25,5 +25,7 @@ + + diff --git a/swing/.classpath b/swing/.classpath index 8305c734c..4eb2bf8e2 100644 --- a/swing/.classpath +++ b/swing/.classpath @@ -1,6 +1,7 @@ + @@ -22,5 +23,12 @@ + + + + + + +