From 040c451a3d099ee42ac3c645837ca9af5660e7cf Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Tue, 1 Dec 2015 18:43:21 -0500 Subject: [PATCH] [Bugfix] Improves FlightConfiguration selection, readability -ParameterSetModel fixed - controlled configuration in the main window. et al. - now implements a generic ComboBoxModel, instead of just a FlightConfigurationId. --- .../document/OpenRocketDocument.java | 13 ++++++- .../sf/openrocket/document/Simulation.java | 6 +-- .../file/openrocket/OpenRocketSaver.java | 2 +- .../importt/SimulationConditionsHandler.java | 4 +- .../rocketcomponent/FlightConfiguration.java | 6 +-- .../simulation/SimulationOptions.java | 37 ++++++++++-------- .../net/sf/openrocket/util/TestRockets.java | 3 +- .../gui/adaptors/ParameterSetModel.java | 39 ++++++++----------- .../gui/dialogs/ComponentAnalysisDialog.java | 3 +- .../GeneralOptimizationDialog.java | 2 +- .../openrocket/gui/main/SimulationPanel.java | 11 +++--- .../sf/openrocket/gui/print/DesignReport.java | 2 +- .../gui/scalefigure/RocketPanel.java | 7 ++-- .../gui/simulation/SimulationEditDialog.java | 7 ++-- 14 files changed, 72 insertions(+), 70 deletions(-) diff --git a/core/src/net/sf/openrocket/document/OpenRocketDocument.java b/core/src/net/sf/openrocket/document/OpenRocketDocument.java index 8729c39d0..d7155bba8 100644 --- a/core/src/net/sf/openrocket/document/OpenRocketDocument.java +++ b/core/src/net/sf/openrocket/document/OpenRocketDocument.java @@ -277,7 +277,7 @@ public class OpenRocketDocument implements ComponentChangeListener { } for (Simulation s : getSimulations()) { // Assumes modifiable collection - which it is - if (configId.equals(s.getOptions().getConfigID())) { + if (configId.equals(s.getOptions().getId())) { removeSimulation(s); } } @@ -628,6 +628,17 @@ public class OpenRocketDocument implements ComponentChangeListener { } } + public String getSimulationDetail(){ + StringBuilder str = new StringBuilder(); + str.append(">> Dumping simulation list:\n"); + int simNum = 0; + for( Simulation s : this.simulations ){ + str.append(String.format(" [%d] %s \n", simNum, s.getName(), s.getOptions().getId().toShortKey() )); + simNum++; + } + + return str.toString(); + } diff --git a/core/src/net/sf/openrocket/document/Simulation.java b/core/src/net/sf/openrocket/document/Simulation.java index 5137f42b0..7bb32abdb 100644 --- a/core/src/net/sf/openrocket/document/Simulation.java +++ b/core/src/net/sf/openrocket/document/Simulation.java @@ -114,7 +114,7 @@ public class Simulation implements ChangeSource, Cloneable { DefaultSimulationOptionFactory f = Application.getInjector().getInstance(DefaultSimulationOptionFactory.class); options.copyConditionsFrom(f.getDefault()); - options.setMotorConfigurationID(rocket.getDefaultConfiguration().getFlightConfigurationID()); + options.setFlightConfigurationId(rocket.getDefaultConfiguration().getFlightConfigurationID()); options.addChangeListener(new ConditionListener()); } @@ -275,7 +275,7 @@ public class Simulation implements ChangeSource, Cloneable { } } - FlightConfiguration config = rocket.getFlightConfiguration(options.getConfigID()); + FlightConfiguration config = rocket.getFlightConfiguration(options.getId()); List motorList = config.getActiveMotors(); //Make sure this simulation has motors. @@ -332,7 +332,7 @@ public class Simulation implements ChangeSource, Cloneable { // Set simulated info after simulation, will not be set in case of exception simulatedConditions = options.clone(); - final FlightConfiguration configuration = new FlightConfiguration(options.getConfigID(), this.rocket); + final FlightConfiguration configuration = this.rocket.getFlightConfiguration( options.getId()); simulatedConfigurationDescription = descriptor.format(configuration.getRocket(), configuration.getFlightConfigurationID()); simulatedRocketID = rocket.getFunctionalModID(); diff --git a/core/src/net/sf/openrocket/file/openrocket/OpenRocketSaver.java b/core/src/net/sf/openrocket/file/openrocket/OpenRocketSaver.java index 8f7403a84..4acde1906 100644 --- a/core/src/net/sf/openrocket/file/openrocket/OpenRocketSaver.java +++ b/core/src/net/sf/openrocket/file/openrocket/OpenRocketSaver.java @@ -504,7 +504,7 @@ public class OpenRocketSaver extends RocketSaver { writeln(""); indent++; - writeElement("configid", cond.getConfigID().key); + writeElement("configid", cond.getId().key); writeElement("launchrodlength", cond.getLaunchRodLength()); writeElement("launchrodangle", cond.getLaunchRodAngle() * 180.0 / Math.PI); writeElement("launchroddirection", cond.getLaunchRodDirection() * 360.0 / (2.0 * Math.PI)); diff --git a/core/src/net/sf/openrocket/file/openrocket/importt/SimulationConditionsHandler.java b/core/src/net/sf/openrocket/file/openrocket/importt/SimulationConditionsHandler.java index 78f97928b..0ce6b87b0 100644 --- a/core/src/net/sf/openrocket/file/openrocket/importt/SimulationConditionsHandler.java +++ b/core/src/net/sf/openrocket/file/openrocket/importt/SimulationConditionsHandler.java @@ -51,9 +51,9 @@ class SimulationConditionsHandler extends AbstractElementHandler { if (element.equals("configid")) { if (content.equals("")) { - conditions.setMotorConfigurationID(null); + conditions.setFlightConfigurationId(null); } else { - conditions.setMotorConfigurationID(new FlightConfigurationID(content)); + conditions.setFlightConfigurationId(new FlightConfigurationID(content)); } } else if (element.equals("launchrodlength")) { if (Double.isNaN(d)) { diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java index 692489e9a..c3f57a092 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java @@ -382,11 +382,7 @@ public class FlightConfiguration implements FlightConfigurableParameter> implements ComboBoxModel, StateChangeListener { +public class ParameterSetModel> implements ComboBoxModel, StateChangeListener { //private static final Translator trans = Application.getTranslator(); - private static final Logger log = LoggerFactory.getLogger(ParameterSetModel.class); + //private static final Logger log = LoggerFactory.getLogger(ParameterSetModel.class); //private RocketDescriptor descriptor = Application.getInjector().getInstance(RocketDescriptor.class); private EventListenerList listenerList = new EventListenerList(); - private T selected; + private Object selected; private final ParameterSet sourceSet; List idList= new Vector(); @@ -40,17 +37,12 @@ public class ParameterSetModel> impleme } @Override - public FlightConfigurationID getElementAt(int index) { - - this.idList = this.sourceSet.getSortedConfigurationIDs(); - - if (index < 0){ - return FlightConfigurationID.ERROR_CONFIGURATION_FCID; - }else if ( index >= this.idList.size()){ - return FlightConfigurationID.ERROR_CONFIGURATION_FCID; + public T getElementAt(int index) { + if((index < 0)||( index >= this.idList.size())){ + return sourceSet.getDefault(); } - - return this.idList.get(index); + FlightConfigurationID fcid = this.idList.get(index); + return this.sourceSet.get( fcid); } @Override @@ -61,7 +53,7 @@ public class ParameterSetModel> impleme @Override public Object getSelectedItem() { - return selected; + return this.selected; } @Override @@ -71,13 +63,13 @@ public class ParameterSetModel> impleme return; } - if (!(item instanceof FlightConfigurationID)) { - - throw new IllegalArgumentException("MotorConfigurationModel item=" + item); + if( item.getClass().isAssignableFrom(this.selected.getClass())){ + this.selected = item; + return; + }else{ + throw new IllegalArgumentException("attempted to set selected item (oftype "+item.getClass().getSimpleName() + +") when this generic contains a type: "+this.selected.getClass().getSimpleName()); } - FlightConfigurationID fcid= (FlightConfigurationID) item; - - this.selected = sourceSet.get(fcid); } @@ -117,6 +109,7 @@ public class ParameterSetModel> impleme return; } fireListDataEvent(); + this.idList = this.sourceSet.getSortedConfigurationIDs(); } } diff --git a/swing/src/net/sf/openrocket/gui/dialogs/ComponentAnalysisDialog.java b/swing/src/net/sf/openrocket/gui/dialogs/ComponentAnalysisDialog.java index 0684392b5..8df8fff9d 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/ComponentAnalysisDialog.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/ComponentAnalysisDialog.java @@ -58,7 +58,6 @@ import net.sf.openrocket.masscalc.MassCalculator; import net.sf.openrocket.masscalc.MassCalculator.MassCalcType; import net.sf.openrocket.rocketcomponent.FinSet; import net.sf.openrocket.rocketcomponent.FlightConfiguration; -import net.sf.openrocket.rocketcomponent.FlightConfigurationID; import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.startup.Application; @@ -179,7 +178,7 @@ public class ComponentAnalysisDialog extends JDialog implements StateChangeListe panel.add(label, "growx, right"); ParameterSetModel psm = new ParameterSetModel( configuration.getRocket().getConfigurationSet()); - JComboBox combo = new JComboBox(psm); + JComboBox combo = new JComboBox(psm); panel.add(combo, "wrap"); 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 4d4c93507..5e9a1da1d 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/optimization/GeneralOptimizationDialog.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/optimization/GeneralOptimizationDialog.java @@ -1164,7 +1164,7 @@ public class GeneralOptimizationDialog extends JDialog { } // Update the active configuration - FlightConfigurationID fcid = getSelectedSimulation().getOptions().getConfigID(); + FlightConfigurationID fcid = getSelectedSimulation().getOptions().getId(); getSelectedSimulation().getRocket().setDefaultConfiguration(fcid); updating = false; diff --git a/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java b/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java index de4fbd73e..2c23d75c6 100644 --- a/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java +++ b/swing/src/net/sf/openrocket/gui/main/SimulationPanel.java @@ -58,6 +58,7 @@ import net.sf.openrocket.unit.UnitGroup; import net.sf.openrocket.util.AlphanumComparator; public class SimulationPanel extends JPanel { + private static final long serialVersionUID = 1390060162192576924L; private static final Logger log = LoggerFactory.getLogger(SimulationPanel.class); private static final Translator trans = Application.getTranslator(); @@ -323,7 +324,7 @@ public class SimulationPanel extends JPanel { } @Override - public Comparator getComparator() { + public Comparator getComparator() { return new AlphanumComparator(); } }, @@ -660,11 +661,8 @@ public class SimulationPanel extends JPanel { } } - private enum SimulationTableColumns { - - } - private class JLabelRenderer extends DefaultTableCellRenderer { + private static final long serialVersionUID = 5487619660216145843L; @Override public Component getTableCellRendererComponent(JTable table, @@ -706,6 +704,9 @@ public class SimulationPanel extends JPanel { tip = "" + sim.getName() + "
"; switch (sim.getStatus()) { + case CANT_RUN: + tip += trans.get("simpanel.ttip.noData")+"
"; + break; case UPTODATE: tip += trans.get("simpanel.ttip.uptodate") + "
"; break; diff --git a/swing/src/net/sf/openrocket/gui/print/DesignReport.java b/swing/src/net/sf/openrocket/gui/print/DesignReport.java index ed99dba1a..8d387de9d 100644 --- a/swing/src/net/sf/openrocket/gui/print/DesignReport.java +++ b/swing/src/net/sf/openrocket/gui/print/DesignReport.java @@ -515,7 +515,7 @@ public class DesignReport { try { for (int i = 0; i < simulations.size(); i++) { Simulation simulation = simulations.get(i); - if (Utils.equals(simulation.getOptions().getConfigID(), motorId)) { + if (Utils.equals(simulation.getOptions().getId(), motorId)) { simulation = simulation.copy(); simulation.simulate(); flight = simulation.getSimulatedData(); diff --git a/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java b/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java index 5d92e3c9f..179c40c97 100644 --- a/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java +++ b/swing/src/net/sf/openrocket/gui/scalefigure/RocketPanel.java @@ -307,13 +307,14 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change add(label, "growx, right"); ParameterSetModel psm = new ParameterSetModel( configuration.getRocket().getConfigurationSet()); - JComboBox flightConfigurationComboBox = new JComboBox(psm); - add(flightConfigurationComboBox, "wrap"); + JComboBox flightConfigurationComboBox = new JComboBox(psm); + add(flightConfigurationComboBox, "wrap, width 16%, wmin 100"); flightConfigurationComboBox.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent ae) { Object source = ae.getSource(); if( source instanceof JComboBox ){ + @SuppressWarnings("unchecked") JComboBox box = (JComboBox) source; FlightConfiguration newConfig = (FlightConfiguration)box.getSelectedItem(); document.getRocket().getConfigurationSet().setDefault( newConfig); @@ -695,7 +696,7 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change Rocket duplicate = (Rocket) document.getRocket().copy(); Simulation simulation = ((SwingPreferences) Application.getPreferences()).getBackgroundSimulation(duplicate); - simulation.getOptions().setMotorConfigurationID( + simulation.getOptions().setFlightConfigurationId( document.getDefaultConfiguration().getFlightConfigurationID()); backgroundSimulationWorker = new BackgroundSimulationWorker(document, simulation); diff --git a/swing/src/net/sf/openrocket/gui/simulation/SimulationEditDialog.java b/swing/src/net/sf/openrocket/gui/simulation/SimulationEditDialog.java index b24545c86..4184b1e3e 100644 --- a/swing/src/net/sf/openrocket/gui/simulation/SimulationEditDialog.java +++ b/swing/src/net/sf/openrocket/gui/simulation/SimulationEditDialog.java @@ -25,14 +25,13 @@ import net.sf.openrocket.gui.adaptors.ParameterSetModel; 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.simulation.SimulationOptions; import net.sf.openrocket.simulation.extension.SimulationExtension; import net.sf.openrocket.startup.Application; public class SimulationEditDialog extends JDialog { - + private static final long serialVersionUID = -4468157685542912715L; private final Window parentWindow; private final Simulation[] simulation; private final OpenRocketDocument document; @@ -152,14 +151,14 @@ public class SimulationEditDialog extends JDialog { panel.add(label, "growx 0, gapright para"); ParameterSetModel psm = new ParameterSetModel( configuration.getRocket().getConfigurationSet()); - JComboBox combo = new JComboBox(psm); + JComboBox combo = new JComboBox(psm); //// Select the motor configuration to use. combo.setToolTipText(trans.get("simedtdlg.combo.ttip.Flightcfg")); combo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - conditions.setMotorConfigurationID(configuration.getFlightConfigurationID()); + conditions.setFlightConfigurationId(configuration.getFlightConfigurationID()); } }); panel.add(combo, "span");