From d977733cf5cde8564044ab8d954720d8635faabb Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Fri, 23 Oct 2015 17:49:38 -0400 Subject: [PATCH] [Bugfix] More Motor Ignition UI issues - Selecting an option in the Ignition Chooser dialog updates itself - When updating all motor ignition events, the default is also updated. - removed isDefaultMotorInstance from MotorMounts - default is always the Empty Instance, which has a built in test: 'isEmpty' - in MotorConfigurationPanel: ignition events are gray out, if they match the default ignition event --- .../sf/openrocket/motor/MotorInstance.java | 4 ++++ .../openrocket/rocketcomponent/BodyTube.java | 5 ---- .../openrocket/rocketcomponent/InnerTube.java | 14 ++++------- .../MotorConfigurationSet.java | 13 +++++++--- .../rocketcomponent/MotorMount.java | 16 ++++++------- .../sf/openrocket/gui/adaptors/EnumModel.java | 3 +++ .../IgnitionSelectionDialog.java | 24 ++++++++++--------- .../MotorConfigurationPanel.java | 12 ++-------- 8 files changed, 44 insertions(+), 47 deletions(-) diff --git a/core/src/net/sf/openrocket/motor/MotorInstance.java b/core/src/net/sf/openrocket/motor/MotorInstance.java index 86678195d..a8ccae999 100644 --- a/core/src/net/sf/openrocket/motor/MotorInstance.java +++ b/core/src/net/sf/openrocket/motor/MotorInstance.java @@ -236,6 +236,10 @@ public class MotorInstance implements FlightConfigurableParameter } } + @Override + public String toString(){ + return MotorInstanceId.EMPTY_ID.getComponentId(); + } public int getModID() { return modID; diff --git a/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java b/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java index 9e6966775..e924a5f68 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java +++ b/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java @@ -366,11 +366,6 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial return this.motors.getDefault(); } - @Override - public boolean isDefaultMotorInstance( final MotorInstance testInstance){ - return this.motors.getDefault() == testInstance; - } - @Override public MotorInstance getMotorInstance( final FlightConfigurationID fcid){ return this.motors.get(fcid); diff --git a/core/src/net/sf/openrocket/rocketcomponent/InnerTube.java b/core/src/net/sf/openrocket/rocketcomponent/InnerTube.java index 45cf34bf9..294446945 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/InnerTube.java +++ b/core/src/net/sf/openrocket/rocketcomponent/InnerTube.java @@ -259,12 +259,7 @@ public class InnerTube extends ThicknessRingComponent implements Clusterable, Ra public MotorInstance getDefaultMotorInstance(){ return this.motors.getDefault(); } - - @Override - public boolean isDefaultMotorInstance( final MotorInstance testInstance){ - return this.motors.isDefault( testInstance); - } - + @Override public MotorInstance getMotorInstance( final FlightConfigurationID fcid){ return this.motors.get(fcid); @@ -376,9 +371,10 @@ public class InnerTube extends ThicknessRingComponent implements Clusterable, Ra copy.setName(splitName); return copy; } - - public void printMotorDebug( FlightConfigurationID fcid ){ - System.err.println(this.motors.toDebug()); + + @Override + public String toMotorDebug( ){ + return this.motors.toDebug(); } @Override diff --git a/core/src/net/sf/openrocket/rocketcomponent/MotorConfigurationSet.java b/core/src/net/sf/openrocket/rocketcomponent/MotorConfigurationSet.java index 8764268ae..3d12176e4 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/MotorConfigurationSet.java +++ b/core/src/net/sf/openrocket/rocketcomponent/MotorConfigurationSet.java @@ -34,8 +34,10 @@ public class MotorConfigurationSet extends ParameterSet { @Override public String toDebug(){ StringBuilder buffer = new StringBuilder(); - buffer.append("====== Dumping MotorConfigurationSet for mount '"+this.component.getName()+"' of type: "+this.component.getClass().getSimpleName()+" ======"); - buffer.append(" >> motorSet ("+this.size()+ " motors)"); + buffer.append("====== Dumping MotorConfigurationSet for mount '"+this.component.getName()+"' of type: "+this.component.getClass().getSimpleName()+" ======\n"); + buffer.append(" >> motorSet ("+this.size()+ " motors)\n"); + MotorInstance emptyInstance = this.getDefault(); + buffer.append(" >> (["+emptyInstance.toString()+"]= @ "+ emptyInstance.getIgnitionEvent().name +" +"+emptyInstance.getIgnitionDelay()+"sec )\n"); for( FlightConfigurationID loopFCID : this.map.keySet()){ String shortKey = loopFCID.getShortKey(); @@ -47,7 +49,12 @@ public class MotorConfigurationSet extends ParameterSet { }else{ designation = curInstance.getMotor().getDesignation(curInstance.getEjectionDelay()); } - buffer.append(" >> ["+shortKey+"]= "+designation); + String ignition = curInstance.getIgnitionEvent().name; + double delay = curInstance.getIgnitionDelay(); + if( 0 != delay ){ + ignition += " +"+delay; + } + buffer.append(" >> ["+shortKey+"]= "+designation+" @ "+ignition+"\n"); } return buffer.toString(); } diff --git a/core/src/net/sf/openrocket/rocketcomponent/MotorMount.java b/core/src/net/sf/openrocket/rocketcomponent/MotorMount.java index e1d6daddc..47f247612 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/MotorMount.java +++ b/core/src/net/sf/openrocket/rocketcomponent/MotorMount.java @@ -53,15 +53,7 @@ public interface MotorMount extends ChangeSource, FlightConfigurableComponent { * @return number of times this component is instanced */ public int getInstanceCount(); - - - /** - * - * @param testInstance instance to test - * @return if this motor is the default instance - */ - public boolean isDefaultMotorInstance( final MotorInstance testInstance); - + /** * * @param fcid id for which to return the motor (null retrieves the default) @@ -116,4 +108,10 @@ public interface MotorMount extends ChangeSource, FlightConfigurableComponent { */ public Coordinate getMotorPosition(FlightConfigurationID id); + /** + * Development / Debug method. + * + * @return table describing all the motors configured for this mount. + */ + public String toMotorDebug( ); } diff --git a/swing/src/net/sf/openrocket/gui/adaptors/EnumModel.java b/swing/src/net/sf/openrocket/gui/adaptors/EnumModel.java index 0dee97fef..df8ba1f25 100644 --- a/swing/src/net/sf/openrocket/gui/adaptors/EnumModel.java +++ b/swing/src/net/sf/openrocket/gui/adaptors/EnumModel.java @@ -82,6 +82,7 @@ public class EnumModel> extends AbstractListModel return currentValue; } + @Override public void setSelectedItem(Object item) { if (item == null) { @@ -101,6 +102,8 @@ public class EnumModel> extends AbstractListModel // Comparison with == ok, since both are enums if (currentValue == item) return; + // @SuppressWarnings("unchecked") + this.currentValue = (Enum) item; setMethod.invoke(source, item); } diff --git a/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/IgnitionSelectionDialog.java b/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/IgnitionSelectionDialog.java index 3361d7eae..d11bcd73e 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/IgnitionSelectionDialog.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/IgnitionSelectionDialog.java @@ -53,7 +53,7 @@ public class IgnitionSelectionDialog extends JDialog { JPanel panel = new JPanel(new MigLayout("fill")); // Edit default or override option - boolean isDefault = curMount.isDefaultMotorInstance( curMotorInstance ); + boolean isDefault = curMotorInstance.isEmpty(); panel.add(new JLabel(trans.get("IgnitionSelectionDialog.opt.title")), "span, wrap rel"); final JRadioButton defaultButton = new JRadioButton(trans.get("IgnitionSelectionDialog.opt.default"), isDefault); panel.add(defaultButton, "span, gapleft para, wrap rel"); @@ -101,11 +101,16 @@ public class IgnitionSelectionDialog extends JDialog { public void actionPerformed(ActionEvent e) { if (defaultButton.isSelected()) { - // change the default... - IgnitionEvent cie = curMotorInstance.getIgnitionEvent(); + // retrieve our just-set values double cid = curMotorInstance.getIgnitionDelay(); + IgnitionEvent cie = curMotorInstance.getIgnitionEvent(); - // and change all remaining configs? + // update the default instance + final MotorInstance defaultMotorInstance = curMount.getDefaultMotorInstance(); + defaultMotorInstance.setIgnitionDelay( cid); + defaultMotorInstance.setIgnitionEvent( cie); + + // and change all remaining configs // this seems like odd behavior to me, but it matches the text on the UI dialog popup. -teyrana (equipoise@gmail.com) Iterator iter = curMount.getMotorIterator(); while( iter.hasNext() ){ @@ -114,16 +119,13 @@ public class IgnitionSelectionDialog extends JDialog { next.setIgnitionEvent( cie); } - final MotorInstance defaultMotorInstance = curMount.getDefaultMotorInstance(); - System.err.println("setting default motor ignition ("+defaultMotorInstance.getMotorID().toString()+") to: "); - System.err.println(" event: "+defaultMotorInstance.getIgnitionEvent()+" w/delay: "+defaultMotorInstance.getIgnitionDelay()); - - } -// else { +// System.err.println("setting default motor ignition ("+defaultMotorInstance.getMotorID().toString()+") to: "); +// System.err.println(" event: "+defaultMotorInstance.getIgnitionEvent().name+" w/delay: "+defaultMotorInstance.getIgnitionDelay()); +// }else { // System.err.println("setting motor ignition to.... new values: "); // //destMotorInstance.setIgnitionEvent((IgnitionEvent)eventBox.getSelectedItem()); // System.err.println(" "+curMotorInstance.getIgnitionEvent()+" w/ "+curMotorInstance.getIgnitionDelay()); -// } + } IgnitionSelectionDialog.this.setVisible(false); } }); 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 fd523e4a1..15e1c3b5f 100644 --- a/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/flightconfigpanel/MotorConfigurationPanel.java @@ -288,15 +288,6 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel MotorInstance curMotor = mount.getMotorInstance( configId); String motorString = getMotorSpecification( curMotor ); -// if( mount instanceof InnerTube ){ -// System.err.println("Formatting Cell: fcid="+configId.key.substring(0, 8)); -// System.err.println( ((InnerTube) mount).toDebugString() ); -// } -// System.err.println("rendering "+configId.getShortKey()+" cell: " ); -// if( rocket.getConfigurationSet().isDefault( configId) ){ -// String newText = label.getText() + " (default)"; -// System.err.println(" "+label.getText()+" >> "+newText); -// } JLabel motorDescriptionLabel = new JLabel(motorString); label.add(motorDescriptionLabel); @@ -327,11 +318,12 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel } private JLabel getIgnitionEventString(FlightConfigurationID id, MotorMount mount) { + MotorInstance defInstance = mount.getDefaultMotorInstance(); MotorInstance curInstance = mount.getMotorInstance(id); IgnitionEvent ignitionEvent = curInstance.getIgnitionEvent(); Double ignitionDelay = curInstance.getIgnitionDelay(); - boolean isDefault = mount.isDefaultMotorInstance(curInstance); + boolean isDefault = (defInstance.getIgnitionEvent() == curInstance.getIgnitionEvent()); JLabel label = new JLabel(); String str = trans.get("MotorMount.IgnitionEvent.short." + ignitionEvent.name());