[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
This commit is contained in:
Daniel_M_Williams 2015-10-23 17:49:38 -04:00
parent 64417ca93c
commit d977733cf5
8 changed files with 44 additions and 47 deletions

View File

@ -236,6 +236,10 @@ public class MotorInstance implements FlightConfigurableParameter<MotorInstance>
} }
} }
@Override
public String toString(){
return MotorInstanceId.EMPTY_ID.getComponentId();
}
public int getModID() { public int getModID() {
return modID; return modID;

View File

@ -366,11 +366,6 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial
return this.motors.getDefault(); return this.motors.getDefault();
} }
@Override
public boolean isDefaultMotorInstance( final MotorInstance testInstance){
return this.motors.getDefault() == testInstance;
}
@Override @Override
public MotorInstance getMotorInstance( final FlightConfigurationID fcid){ public MotorInstance getMotorInstance( final FlightConfigurationID fcid){
return this.motors.get(fcid); return this.motors.get(fcid);

View File

@ -259,12 +259,7 @@ public class InnerTube extends ThicknessRingComponent implements Clusterable, Ra
public MotorInstance getDefaultMotorInstance(){ public MotorInstance getDefaultMotorInstance(){
return this.motors.getDefault(); return this.motors.getDefault();
} }
@Override
public boolean isDefaultMotorInstance( final MotorInstance testInstance){
return this.motors.isDefault( testInstance);
}
@Override @Override
public MotorInstance getMotorInstance( final FlightConfigurationID fcid){ public MotorInstance getMotorInstance( final FlightConfigurationID fcid){
return this.motors.get(fcid); return this.motors.get(fcid);
@ -376,9 +371,10 @@ public class InnerTube extends ThicknessRingComponent implements Clusterable, Ra
copy.setName(splitName); copy.setName(splitName);
return copy; return copy;
} }
public void printMotorDebug( FlightConfigurationID fcid ){ @Override
System.err.println(this.motors.toDebug()); public String toMotorDebug( ){
return this.motors.toDebug();
} }
@Override @Override

View File

@ -34,8 +34,10 @@ public class MotorConfigurationSet extends ParameterSet<MotorInstance> {
@Override @Override
public String toDebug(){ public String toDebug(){
StringBuilder buffer = new StringBuilder(); StringBuilder buffer = new StringBuilder();
buffer.append("====== Dumping MotorConfigurationSet for mount '"+this.component.getName()+"' of type: "+this.component.getClass().getSimpleName()+" ======"); buffer.append("====== Dumping MotorConfigurationSet for mount '"+this.component.getName()+"' of type: "+this.component.getClass().getSimpleName()+" ======\n");
buffer.append(" >> motorSet ("+this.size()+ " motors)"); 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()){ for( FlightConfigurationID loopFCID : this.map.keySet()){
String shortKey = loopFCID.getShortKey(); String shortKey = loopFCID.getShortKey();
@ -47,7 +49,12 @@ public class MotorConfigurationSet extends ParameterSet<MotorInstance> {
}else{ }else{
designation = curInstance.getMotor().getDesignation(curInstance.getEjectionDelay()); 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(); return buffer.toString();
} }

View File

@ -53,15 +53,7 @@ public interface MotorMount extends ChangeSource, FlightConfigurableComponent {
* @return number of times this component is instanced * @return number of times this component is instanced
*/ */
public int getInstanceCount(); 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) * @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); public Coordinate getMotorPosition(FlightConfigurationID id);
/**
* Development / Debug method.
*
* @return table describing all the motors configured for this mount.
*/
public String toMotorDebug( );
} }

View File

@ -82,6 +82,7 @@ public class EnumModel<T extends Enum<T>> extends AbstractListModel
return currentValue; return currentValue;
} }
@Override @Override
public void setSelectedItem(Object item) { public void setSelectedItem(Object item) {
if (item == null) { if (item == null) {
@ -101,6 +102,8 @@ public class EnumModel<T extends Enum<T>> extends AbstractListModel
// Comparison with == ok, since both are enums // Comparison with == ok, since both are enums
if (currentValue == item) if (currentValue == item)
return; return;
// @SuppressWarnings("unchecked")
this.currentValue = (Enum<T>) item;
setMethod.invoke(source, item); setMethod.invoke(source, item);
} }

View File

@ -53,7 +53,7 @@ public class IgnitionSelectionDialog extends JDialog {
JPanel panel = new JPanel(new MigLayout("fill")); JPanel panel = new JPanel(new MigLayout("fill"));
// Edit default or override option // 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"); panel.add(new JLabel(trans.get("IgnitionSelectionDialog.opt.title")), "span, wrap rel");
final JRadioButton defaultButton = new JRadioButton(trans.get("IgnitionSelectionDialog.opt.default"), isDefault); final JRadioButton defaultButton = new JRadioButton(trans.get("IgnitionSelectionDialog.opt.default"), isDefault);
panel.add(defaultButton, "span, gapleft para, wrap rel"); panel.add(defaultButton, "span, gapleft para, wrap rel");
@ -101,11 +101,16 @@ public class IgnitionSelectionDialog extends JDialog {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if (defaultButton.isSelected()) { if (defaultButton.isSelected()) {
// change the default... // retrieve our just-set values
IgnitionEvent cie = curMotorInstance.getIgnitionEvent();
double cid = curMotorInstance.getIgnitionDelay(); 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) // this seems like odd behavior to me, but it matches the text on the UI dialog popup. -teyrana (equipoise@gmail.com)
Iterator<MotorInstance> iter = curMount.getMotorIterator(); Iterator<MotorInstance> iter = curMount.getMotorIterator();
while( iter.hasNext() ){ while( iter.hasNext() ){
@ -114,16 +119,13 @@ public class IgnitionSelectionDialog extends JDialog {
next.setIgnitionEvent( cie); next.setIgnitionEvent( cie);
} }
final MotorInstance defaultMotorInstance = curMount.getDefaultMotorInstance(); // System.err.println("setting default motor ignition ("+defaultMotorInstance.getMotorID().toString()+") to: ");
System.err.println("setting default motor ignition ("+defaultMotorInstance.getMotorID().toString()+") to: "); // System.err.println(" event: "+defaultMotorInstance.getIgnitionEvent().name+" w/delay: "+defaultMotorInstance.getIgnitionDelay());
System.err.println(" event: "+defaultMotorInstance.getIgnitionEvent()+" w/delay: "+defaultMotorInstance.getIgnitionDelay()); // }else {
}
// else {
// System.err.println("setting motor ignition to.... new values: "); // System.err.println("setting motor ignition to.... new values: ");
// //destMotorInstance.setIgnitionEvent((IgnitionEvent)eventBox.getSelectedItem()); // //destMotorInstance.setIgnitionEvent((IgnitionEvent)eventBox.getSelectedItem());
// System.err.println(" "+curMotorInstance.getIgnitionEvent()+" w/ "+curMotorInstance.getIgnitionDelay()); // System.err.println(" "+curMotorInstance.getIgnitionEvent()+" w/ "+curMotorInstance.getIgnitionDelay());
// } }
IgnitionSelectionDialog.this.setVisible(false); IgnitionSelectionDialog.this.setVisible(false);
} }
}); });

View File

@ -288,15 +288,6 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
MotorInstance curMotor = mount.getMotorInstance( configId); MotorInstance curMotor = mount.getMotorInstance( configId);
String motorString = getMotorSpecification( curMotor ); 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); JLabel motorDescriptionLabel = new JLabel(motorString);
label.add(motorDescriptionLabel); label.add(motorDescriptionLabel);
@ -327,11 +318,12 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
} }
private JLabel getIgnitionEventString(FlightConfigurationID id, MotorMount mount) { private JLabel getIgnitionEventString(FlightConfigurationID id, MotorMount mount) {
MotorInstance defInstance = mount.getDefaultMotorInstance();
MotorInstance curInstance = mount.getMotorInstance(id); MotorInstance curInstance = mount.getMotorInstance(id);
IgnitionEvent ignitionEvent = curInstance.getIgnitionEvent(); IgnitionEvent ignitionEvent = curInstance.getIgnitionEvent();
Double ignitionDelay = curInstance.getIgnitionDelay(); Double ignitionDelay = curInstance.getIgnitionDelay();
boolean isDefault = mount.isDefaultMotorInstance(curInstance); boolean isDefault = (defInstance.getIgnitionEvent() == curInstance.getIgnitionEvent());
JLabel label = new JLabel(); JLabel label = new JLabel();
String str = trans.get("MotorMount.IgnitionEvent.short." + ignitionEvent.name()); String str = trans.get("MotorMount.IgnitionEvent.short." + ignitionEvent.name());