[bugfix] Flight Configuration management bugs fixed

Removed "Rename Configuration" Button => "Reset to Default" (is now obsolete)
Re-implemented 'create new configuration' button
This commit is contained in:
Daniel_M_Williams 2015-10-09 17:56:30 -04:00
parent 0a55f59548
commit 059c9cf0db
7 changed files with 62 additions and 35 deletions

View File

@ -164,6 +164,10 @@ public class MotorInstance implements FlightConfigurableParameter<MotorInstance>
return false;
}
public boolean isEmpty(){
return this == MotorInstance.EMPTY_INSTANCE;
}
@Override
public boolean equals( Object other ){
if( other == null )

View File

@ -29,9 +29,9 @@ import net.sf.openrocket.util.StateChangeListener;
public class FlightConfiguration implements FlightConfigurableParameter<FlightConfiguration>, ChangeSource, ComponentChangeListener, Monitorable {
private static final Logger log = LoggerFactory.getLogger(FlightConfiguration.class);
public final static String DEFAULT_CONFIGURATION_NAME = "default configuration";
public final static String DEFAULT_CONFIGURATION_NAME = "Default Configuration";
protected String configurationName = FlightConfiguration.DEFAULT_CONFIGURATION_NAME;
protected String configurationName ;
protected final Rocket rocket;
protected final FlightConfigurationID fcid;
@ -62,6 +62,12 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
private int modID = 0;
public FlightConfiguration( ){
this.fcid = FlightConfigurationID.ERROR_CONFIGURATION_ID;
this.rocket = new Rocket();
this.configurationName = "<ERROR: FlightConfiguration created without an id or rocket instance. ERROR!> ";
}
/**
* Create a new configuration with the specified <code>Rocket</code>.
*
@ -75,6 +81,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
this.fcid = _fcid;
}
this.rocket = rocket;
this.setName( fcid.key);
updateStageMap();
rocket.addComponentChangeListener(this);
@ -450,6 +457,11 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
return;
}else if( "".equals(newName)){
return;
}else if( this.getFlightConfigurationID().equals( FlightConfigurationID.DEFAULT_CONFIGURATION_ID)){
this.configurationName = FlightConfiguration.DEFAULT_CONFIGURATION_NAME;
return;
}else if( ! this.getFlightConfigurationID().isValid()){
return;
}else if( newName.equals(this.configurationName)){
return;
}

View File

@ -47,6 +47,14 @@ public interface MotorMount extends ChangeSource, FlightConfigurableComponent {
*/
public MotorInstance getDefaultMotorInstance();
/**
* Default implementatino supplied by RocketComponent (returns 1);
*
* @return number of times this component is instanced
*/
public int getInstanceCount();
/**
*
* @param testInstance instance to test

View File

@ -84,9 +84,9 @@ public class Rocket extends RocketComponent {
aeroModID = modID;
treeModID = modID;
functionalModID = modID;
FlightConfiguration defaultConfiguration = new FlightConfiguration(null, this);
//FlightConfigurationID defaultFCID = defaultConfiguration.getFlightConfigurationID();
defaultConfiguration.setName( "Default Configuration" );
FlightConfigurationID defaultFCID = FlightConfigurationID.DEFAULT_CONFIGURATION_ID;
FlightConfiguration defaultConfiguration = new FlightConfiguration( defaultFCID, this);
this.configurations = new FlightConfigurationSet<FlightConfiguration>(this, ComponentChangeEvent.ALL_CHANGE, defaultConfiguration);
}

View File

@ -47,17 +47,17 @@ public class RenameConfigDialog extends JDialog {
});
panel.add(okButton);
JButton defaultButton = new JButton(trans.get("RenameConfigDialog.but.reset")+" (NYI)- what do I do? ");
defaultButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// why would I bother setting to null?
System.err.println(" NYI: defaultButton (ln:55) in RenameConfigDialog... not sure what it's for...");
//rocket.getFlightConfiguration(configId).setName(null);
RenameConfigDialog.this.setVisible(false);
}
});
panel.add(defaultButton);
// JButton renameToDefaultButton = new JButton(trans.get("RenameConfigDialog.but.reset")+" (in Devel: is this fixed yet?)");
// renameToDefaultButton.addActionListener(new ActionListener() {
// @Override
// public void actionPerformed(ActionEvent e) {
// // why would I bother setting to null?
// System.err.println(" NYI: defaultButton (ln:55) in RenameConfigDialog... not sure what it's for...");
// //rocket.getFlightConfiguration(configId).setName(null);
// RenameConfigDialog.this.setVisible(false);
// }
// });
// panel.add(renameToDefaultButton);
JButton cancel = new JButton(trans.get("button.cancel"));
cancel.addActionListener(new ActionListener() {

View File

@ -27,7 +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();
@ -124,9 +123,10 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
}
private void addConfiguration() {
FlightConfigurationID newFCID = new FlightConfigurationID();
FlightConfiguration newConfig = new FlightConfiguration( newFCID, rocket );
//FlightConfiguration newConfig = new FlightConfiguration( rocket );
//FlightConfigurationID newFCID = newConfig.getFlightConfigurationID();
rocket.setFlightConfiguration(newFCID, newConfig);
// Create a new simulation for this configuration.
createSimulationForNewConfiguration();

View File

@ -31,13 +31,13 @@ import net.sf.openrocket.rocketcomponent.FlightConfigurationID;
import net.sf.openrocket.rocketcomponent.IgnitionEvent;
import net.sf.openrocket.rocketcomponent.MotorMount;
import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.unit.UnitGroup;
import net.sf.openrocket.util.Chars;
import net.sf.openrocket.util.Coordinate;
public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount> {
private static final long serialVersionUID = -5046535300435793744L;
private static final String NONE = trans.get("edtmotorconfdlg.tbl.None");
private final JButton selectMotorButton, removeMotorButton, selectIgnitionButton, resetIgnitionButton;
@ -61,6 +61,8 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
subpanel.add(label, "wrap");
MotorMountConfigurationPanel mountConfigPanel = new MotorMountConfigurationPanel(this,rocket) {
private static final long serialVersionUID = -238261338962282816L;
@Override
public void onDataChanged() {
MotorConfigurationPanel.this.fireTableDataChanged();
@ -139,6 +141,8 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
//// Motor selection table.
configurationTableModel = new FlightConfigurableTableModel<MotorMount>(MotorMount.class,rocket) {
private static final long serialVersionUID = -1210899988369000567L;
@Override
protected boolean includeComponent(MotorMount component) {
return component.isMotorMount();
@ -201,8 +205,9 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
MotorMount mount = getSelectedComponent();
if (id == null || mount == null)
return;
MotorInstance inst = mount.getMotorInstance(id);
if( inst.isEmpty() )
return;
motorChooserDialog.setMotorMountAndConfig(mount, id);
@ -263,13 +268,14 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
private class MotorTableCellRenderer extends FlightConfigurablePanel<MotorMount>.FlightConfigurableCellRenderer {
private static final long serialVersionUID = -7462331042920067984L;
@Override
protected JLabel format( MotorMount mount, FlightConfigurationID configId, JLabel l ) {
JLabel label = new JLabel();
label.setLayout(new BoxLayout(label, BoxLayout.X_AXIS));
MotorInstance motorConfig = mount.getMotorInstance( configId);
String motorString = getMotorSpecification(mount, motorConfig);
MotorInstance curMotor = mount.getMotorInstance( configId);
String motorString = getMotorSpecification( curMotor );
JLabel motorDescriptionLabel = new JLabel(motorString);
label.add(motorDescriptionLabel);
label.add( Box.createRigidArea(new Dimension(10,0)));
@ -279,25 +285,22 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
return label;
}
private String getMotorSpecification(MotorMount mount, MotorInstance motorConfig) {
Motor motor = motorConfig.getMotor();
if (motor == null)
private String getMotorSpecification(MotorInstance curMotorInstance ) {
if( curMotorInstance.isEmpty()){
return NONE;
}
String str = motor.getDesignation(motorConfig.getEjectionDelay());
int count = getMountMultiplicity(mount);
MotorMount mount = curMotorInstance.getMount();
Motor motor = curMotorInstance.getMotor();
String str = motor.getDesignation(curMotorInstance.getEjectionDelay());
int count = mount.getInstanceCount();
if (count > 1) {
str = "" + count + Chars.TIMES + " " + str;
}
return str;
}
private int getMountMultiplicity(MotorMount mount) {
RocketComponent c = (RocketComponent) mount;
return c.toAbsolute(Coordinate.NUL).length;
}
private JLabel getIgnitionEventString(FlightConfigurationID id, MotorMount mount) {
MotorInstance curInstance = mount.getMotorInstance(id);