import net.sf.openrocket.document.Simulation;
import net.sf.openrocket.gui.components.DescriptionArea;
import net.sf.openrocket.gui.components.UnitSelector;
+import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.simulation.FlightDataBranch;
+import net.sf.openrocket.simulation.FlightDataType;
import net.sf.openrocket.simulation.FlightEvent;
-import net.sf.openrocket.simulation.FlightDataBranch.Type;
+import net.sf.openrocket.startup.Application;
import net.sf.openrocket.unit.Unit;
import net.sf.openrocket.util.GUIUtil;
import net.sf.openrocket.util.Icons;
-import net.sf.openrocket.util.Pair;
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;
/** The array of presets for the combo box. */
private static final PlotConfiguration[] PRESET_ARRAY;
static {
- PRESET_ARRAY = Arrays.copyOf(PlotConfiguration.DEFAULT_CONFIGURATIONS,
+ PRESET_ARRAY = Arrays.copyOf(PlotConfiguration.DEFAULT_CONFIGURATIONS,
PlotConfiguration.DEFAULT_CONFIGURATIONS.length + 1);
- PRESET_ARRAY[PRESET_ARRAY.length-1] = CUSTOM_CONFIGURATION;
+ PRESET_ARRAY[PRESET_ARRAY.length - 1] = CUSTOM_CONFIGURATION;
}
-
-
+
+
/** The current default configuration, set each time a plot is made. */
private static PlotConfiguration defaultConfiguration =
- PlotConfiguration.DEFAULT_CONFIGURATIONS[0].resetUnits();
-
+ PlotConfiguration.DEFAULT_CONFIGURATIONS[0].resetUnits();
+
private final Simulation simulation;
- private final FlightDataBranch.Type[] types;
+ private final FlightDataType[] types;
private PlotConfiguration configuration;
private JPanel typeSelectorPanel;
private FlightEventTableModel eventTableModel;
-
+
private int modifying = 0;
-
+
public SimulationPlotPanel(final Simulation simulation) {
super(new MigLayout("fill"));
this.simulation = simulation;
- if (simulation.getSimulatedData() == null ||
- simulation.getSimulatedData().getBranchCount()==0) {
+ if (simulation.getSimulatedData() == null ||
+ simulation.getSimulatedData().getBranchCount() == 0) {
throw new IllegalArgumentException("Simulation contains no data.");
}
FlightDataBranch branch = simulation.getSimulatedData().getBranch(0);
// TODO: LOW: Revert to custom if data type is not available.
configuration = defaultConfiguration.clone();
-
+
//// Configuration selector
// Setup the combo box
configurationSelector = new JComboBox(PRESET_ARRAY);
- for (PlotConfiguration config: PRESET_ARRAY) {
+ for (PlotConfiguration config : PRESET_ARRAY) {
if (config.getName().equals(configuration.getName())) {
configurationSelector.setSelectedItem(config);
}
public void itemStateChanged(ItemEvent e) {
if (modifying > 0)
return;
- PlotConfiguration conf = (PlotConfiguration)configurationSelector.getSelectedItem();
+ PlotConfiguration conf = (PlotConfiguration) configurationSelector.getSelectedItem();
if (conf == CUSTOM_CONFIGURATION)
return;
modifying++;
modifying--;
}
});
- this.add(new JLabel("Preset plot configurations: "), "spanx, split");
- this.add(configurationSelector,"growx, wrap 20lp");
-
-
+ //// Preset plot configurations:
+ this.add(new JLabel(trans.get("simplotpanel.lbl.Presetplotconf")), "spanx, split");
+ this.add(configurationSelector, "growx, wrap 20lp");
+
+
//// X axis
-
- this.add(new JLabel("X axis type:"), "spanx, split");
+ //// X axis type:
+ this.add(new JLabel(trans.get("simplotpanel.lbl.Xaxistype")), "spanx, split");
domainTypeSelector = new JComboBox(types);
domainTypeSelector.setSelectedItem(configuration.getDomainAxisType());
domainTypeSelector.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if (modifying > 0)
return;
- FlightDataBranch.Type type = (Type) domainTypeSelector.getSelectedItem();
+ FlightDataType type = (FlightDataType) domainTypeSelector.getSelectedItem();
configuration.setDomainAxisType(type);
domainUnitSelector.setUnitGroup(type.getUnitGroup());
domainUnitSelector.setSelectedUnit(configuration.getDomainAxisUnit());
}
});
this.add(domainTypeSelector, "gapright para");
-
- this.add(new JLabel("Unit:"));
+ //// Unit:
+ this.add(new JLabel(trans.get("simplotpanel.lbl.Unit")));
domainUnitSelector = new UnitSelector(configuration.getDomainAxisType().getUnitGroup());
domainUnitSelector.setSelectedUnit(configuration.getDomainAxisUnit());
domainUnitSelector.addItemListener(new ItemListener() {
});
this.add(domainUnitSelector, "width 40lp, gapright para");
-
- DescriptionArea desc = new DescriptionArea("The data will be plotted in time order " +
- "even if the X axis type is not time.", 2, -2f);
+ //// The data will be plotted in time order even if the X axis type is not time.
+ DescriptionArea desc = new DescriptionArea(trans.get("simplotpanel.Desc"), 2, -2f);
desc.setViewportBorder(BorderFactory.createEmptyBorder());
this.add(desc, "width 1px, growx 1, wrap unrel");
-
-
+
+
//// Y axis selector panel
-
- this.add(new JLabel("Y axis types:"));
-
- this.add(new JLabel("Flight events:"), "wrap rel");
+ //// Y axis types:
+ this.add(new JLabel(trans.get("simplotpanel.lbl.Yaxistypes")));
+ //// Flight events:
+ this.add(new JLabel(trans.get("simplotpanel.lbl.Flightevents")), "wrap rel");
typeSelectorPanel = new JPanel(new MigLayout("gapy rel"));
JScrollPane scroll = new JScrollPane(typeSelectorPanel);
this.add(scroll, "spany 2, height 10px, grow 100, gapright para");
-
+
//// Flight events
eventTableModel = new FlightEventTableModel();
JTable table = new JTable(eventTableModel);
table.addMouseListener(new GUIUtil.BooleanTableClickListener(table));
this.add(new JScrollPane(table), "height 10px, width 200lp, grow 1, wrap rel");
-
+
//// All + None buttons
- JButton button = new JButton("All");
+ JButton button = new JButton(trans.get("simplotpanel.but.All"));
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
- for (FlightEvent.Type t: FlightEvent.Type.values())
+ for (FlightEvent.Type t : FlightEvent.Type.values())
configuration.setEvent(t, true);
eventTableModel.fireTableDataChanged();
}
});
this.add(button, "split 2, gapleft para, gapright para, growx, sizegroup buttons");
- button = new JButton("None");
+ //// None
+ button = new JButton(trans.get("simplotpanel.but.None"));
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
- for (FlightEvent.Type t: FlightEvent.Type.values())
+ for (FlightEvent.Type t : FlightEvent.Type.values())
configuration.setEvent(t, false);
eventTableModel.fireTableDataChanged();
}
});
this.add(button, "gapleft para, gapright para, growx, sizegroup buttons, wrap para");
-
-
-
- button = new JButton("New Y axis plot type");
+
+
+ //// New Y axis plot type
+ button = new JButton(trans.get("simplotpanel.but.NewYaxisplottype"));
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (configuration.getTypeCount() >= 15) {
- JOptionPane.showMessageDialog(SimulationPlotPanel.this,
- "A maximum of 15 plots is allowed.", "Cannot add plot",
+ JOptionPane.showMessageDialog(SimulationPlotPanel.this,
+ //// A maximum of 15 plots is allowed.
+ //// Cannot add plot
+ trans.get("simplotpanel.OptionPane.lbl1"),
+ trans.get("simplotpanel.OptionPane.lbl2"),
JOptionPane.ERROR_MESSAGE);
return;
}
-
+
// Select new type smartly
- FlightDataBranch.Type type = null;
- for (FlightDataBranch.Type t:
+ FlightDataType type = null;
+ for (FlightDataType t :
simulation.getSimulatedData().getBranch(0).getTypes()) {
-
- boolean used = false;
- if (configuration.getDomainAxisType().equals(t)) {
- used = true;
- } else {
- for (int i=0; i < configuration.getTypeCount(); i++) {
- if (configuration.getType(i).equals(t)) {
- used = true;
- break;
+
+ boolean used = false;
+ if (configuration.getDomainAxisType().equals(t)) {
+ used = true;
+ } else {
+ for (int i = 0; i < configuration.getTypeCount(); i++) {
+ if (configuration.getType(i).equals(t)) {
+ used = true;
+ break;
+ }
}
}
+
+ if (!used) {
+ type = t;
+ break;
+ }
}
-
- if (!used) {
- type = t;
- break;
+ if (type == null) {
+ type = simulation.getSimulatedData().getBranch(0).getTypes()[0];
}
+
+ // Add new type
+ configuration.addPlotDataType(type);
+ setToCustom();
+ updatePlots();
}
- if (type == null) {
- type = simulation.getSimulatedData().getBranch(0).getTypes()[0];
- }
-
- // Add new type
- configuration.addPlotDataType(type);
- setToCustom();
- updatePlots();
- }
});
this.add(button, "spanx, split");
-
+
this.add(new JPanel(), "growx");
- button = new JButton("Plot flight");
+ //// Plot flight
+ button = new JButton(trans.get("simplotpanel.but.Plotflight"));
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
defaultConfiguration = configuration.clone();
- PlotDialog.showPlot(SwingUtilities.getWindowAncestor(SimulationPlotPanel.this),
+ PlotDialog.showPlot(SwingUtilities.getWindowAncestor(SimulationPlotPanel.this),
simulation, configuration);
}
});
this.add(button, "right");
-
+
updatePlots();
}
domainUnitSelector.setSelectedUnit(configuration.getDomainAxisUnit());
typeSelectorPanel.removeAll();
- for (int i=0; i < configuration.getTypeCount(); i++) {
- FlightDataBranch.Type type = configuration.getType(i);
+ for (int i = 0; i < configuration.getTypeCount(); i++) {
+ FlightDataType type = configuration.getType(i);
Unit unit = configuration.getUnit(i);
int axis = configuration.getAxis(i);
}
-
-
+
+
/**
* A JPanel which configures a single plot of a PlotConfiguration.
*/
private JComboBox axisSelector;
- public PlotTypeSelector(int index, FlightDataBranch.Type type) {
- this (index, type, null, -1);
+ public PlotTypeSelector(int index, FlightDataType type) {
+ this(index, type, null, -1);
}
- public PlotTypeSelector(int plotIndex, FlightDataBranch.Type type, Unit unit, int position) {
+ public PlotTypeSelector(int plotIndex, FlightDataType type, Unit unit, int position) {
super(new MigLayout("ins 0"));
this.index = plotIndex;
public void itemStateChanged(ItemEvent e) {
if (modifying > 0)
return;
- FlightDataBranch.Type type = (Type) typeSelector.getSelectedItem();
+ FlightDataType type = (FlightDataType) typeSelector.getSelectedItem();
configuration.setPlotDataType(index, type);
unitSelector.setUnitGroup(type.getUnitGroup());
unitSelector.setSelectedUnit(configuration.getUnit(index));
});
this.add(typeSelector, "gapright para");
- this.add(new JLabel("Unit:"));
+ //// Unit:
+ this.add(new JLabel(trans.get("simplotpanel.lbl.Unit")));
unitSelector = new UnitSelector(type.getUnitGroup());
if (unit != null)
unitSelector.setSelectedUnit(unit);
});
this.add(unitSelector, "width 40lp, gapright para");
- this.add(new JLabel("Axis:"));
+ //// Axis:
+ this.add(new JLabel(trans.get("simplotpanel.lbl.Axis")));
axisSelector = new JComboBox(POSITIONS);
if (position == LEFT)
axisSelector.setSelectedIndex(1);
});
this.add(axisSelector);
-
+
JButton button = new JButton(Icons.DELETE);
- button.setToolTipText("Remove this plot");
+ //// Remove this plot
+ button.setToolTipText(trans.get("simplotpanel.but.ttip.Removethisplot"));
button.setBorderPainted(false);
button.addActionListener(new ActionListener() {
@Override
}
-
+
private class FlightEventTableModel extends AbstractTableModel {
private final FlightEvent.Type[] eventTypes;
public FlightEventTableModel() {
EnumSet<FlightEvent.Type> set = EnumSet.noneOf(FlightEvent.Type.class);
- for (int i=0; i < simulation.getSimulatedData().getBranchCount(); i++) {
- for (Pair<Double,FlightEvent> e:
- simulation.getSimulatedData().getBranch(i).getEvents()) {
- set.add(e.getV().getType());
+ for (int i = 0; i < simulation.getSimulatedData().getBranchCount(); i++) {
+ for (FlightEvent e : simulation.getSimulatedData().getBranch(i).getEvents()) {
+ set.add(e.getType());
}
}
set.remove(FlightEvent.Type.ALTITUDE);
eventTypes = new FlightEvent.Type[count];
int pos = 0;
- for (FlightEvent.Type t: FlightEvent.Type.values()) {
+ for (FlightEvent.Type t : FlightEvent.Type.values()) {
if (set.contains(t)) {
eventTypes[pos] = t;
pos++;
public int getColumnCount() {
return 2;
}
-
+
@Override
public int getRowCount() {
return eventTypes.length;
return String.class;
default:
- throw new IndexOutOfBoundsException("column="+column);
+ throw new IndexOutOfBoundsException("column=" + column);
}
}
-
+
@Override
public Object getValueAt(int row, int column) {
switch (column) {
return eventTypes[row].toString();
default:
- throw new IndexOutOfBoundsException("column="+column);
+ throw new IndexOutOfBoundsException("column=" + column);
}
}
@Override
public void setValueAt(Object value, int row, int column) {
if (column != 0 || !(value instanceof Boolean)) {
- throw new IllegalArgumentException("column="+column+", value="+value);
+ throw new IllegalArgumentException("column=" + column + ", value=" + value);
}
- configuration.setEvent(eventTypes[row], (Boolean)value);
+ configuration.setEvent(eventTypes[row], (Boolean) value);
this.fireTableCellUpdated(row, column);
}
}