import net.sf.openrocket.unit.Unit;
import net.sf.openrocket.util.GUIUtil;
import net.sf.openrocket.util.Icons;
+import net.sf.openrocket.util.Utils;
+/**
+ * Panel that displays the simulation plot options to the user.
+ *
+ * @author Sampo Niskanen <sampo.niskanen@iki.fi>
+ */
public class SimulationPlotPanel extends JPanel {
private static final Translator trans = Application.getTranslator();
-
+
// TODO: LOW: Should these be somewhere else?
public static final int AUTO = -1;
public static final int LEFT = 0;
public static final int RIGHT = 1;
- public static final String AUTO_NAME = "Auto";
- public static final String LEFT_NAME = "Left";
- public static final String RIGHT_NAME = "Right";
+ //// Auto
+ public static final String AUTO_NAME = trans.get("simplotpanel.AUTO_NAME");
+ //// Left
+ public static final String LEFT_NAME = trans.get("simplotpanel.LEFT_NAME");
+ //// Right
+ public static final String RIGHT_NAME = trans.get("simplotpanel.RIGHT_NAME");
- private static final String CUSTOM = "Custom";
+ //// Custom
+ private static final String CUSTOM = trans.get("simplotpanel.CUSTOM");
/** The "Custom" configuration - not to be used for anything other than the title. */
private static final PlotConfiguration CUSTOM_CONFIGURATION;
FlightDataBranch branch = simulation.getSimulatedData().getBranch(0);
types = branch.getTypes();
- // TODO: LOW: Revert to custom if data type is not available.
- configuration = defaultConfiguration.clone();
+ setConfiguration(defaultConfiguration);
-
//// Configuration selector
// Setup the combo box
configurationSelector.setSelectedItem(config);
}
}
+
+ // FIXME: Bugs when expected branch is not present
+
configurationSelector.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (conf == CUSTOM_CONFIGURATION)
return;
modifying++;
- configuration = conf.clone().resetUnits();
+ setConfiguration(conf.clone().resetUnits());
updatePlots();
modifying--;
}
JOptionPane.showMessageDialog(SimulationPlotPanel.this,
//// A maximum of 15 plots is allowed.
//// Cannot add plot
- trans.get("simplotpanel.OptionPane.lbl1"),
+ trans.get("simplotpanel.OptionPane.lbl1"),
trans.get("simplotpanel.OptionPane.lbl2"),
JOptionPane.ERROR_MESSAGE);
return;
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
+ if (configuration.getTypeCount() == 0) {
+ JOptionPane.showMessageDialog(SimulationPlotPanel.this,
+ trans.get("error.noPlotSelected"),
+ trans.get("error.noPlotSelected.title"),
+ JOptionPane.ERROR_MESSAGE);
+ return;
+ }
defaultConfiguration = configuration.clone();
- PlotDialog.showPlot(SwingUtilities.getWindowAncestor(SimulationPlotPanel.this),
+ SimulationPlotDialog.showPlot(SwingUtilities.getWindowAncestor(SimulationPlotPanel.this),
simulation, configuration);
}
});
}
+ private void setConfiguration(PlotConfiguration conf) {
+
+ boolean modified = false;
+
+ configuration = conf.clone();
+ if (!Utils.contains(types, configuration.getDomainAxisType())) {
+ configuration.setDomainAxisType(types[0]);
+ modified = true;
+ }
+
+ for (int i = 0; i < configuration.getTypeCount(); i++) {
+ if (!Utils.contains(types, configuration.getType(i))) {
+ configuration.removePlotDataType(i);
+ i--;
+ modified = true;
+ }
+ }
+
+ if (modified) {
+ configuration.setName(CUSTOM);
+ }
+
+ }
+
+
private void setToCustom() {
modifying++;
configuration.setName(CUSTOM);
public void itemStateChanged(ItemEvent e) {
if (modifying > 0)
return;
- Unit unit = (Unit) unitSelector.getSelectedUnit();
+ Unit unit = unitSelector.getSelectedUnit();
configuration.setPlotDataUnit(index, unit);
}
});