import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Arrays;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
+import javax.swing.KeyStroke;
+import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableCellRenderer;
import net.sf.openrocket.aerodynamics.WarningSet;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.document.Simulation;
-import net.sf.openrocket.gui.ResizeLabel;
+import net.sf.openrocket.document.events.DocumentChangeEvent;
+import net.sf.openrocket.document.events.DocumentChangeListener;
+import net.sf.openrocket.document.events.SimulationChangeEvent;
import net.sf.openrocket.gui.adaptors.Column;
import net.sf.openrocket.gui.adaptors.ColumnTableModel;
+import net.sf.openrocket.gui.components.ResizeLabel;
import net.sf.openrocket.rocketcomponent.ComponentChangeEvent;
import net.sf.openrocket.rocketcomponent.ComponentChangeListener;
import net.sf.openrocket.simulation.FlightData;
private static final Color OK_COLOR = new Color(60,150,0);
private static final String OK_TEXT = "\u2714"; // Heavy check mark
- private static final String NAME_PREFIX = "Simulation ";
-
private final OpenRocketDocument document;
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
-
- // Generate unique name for the simulation
- int maxValue = 0;
- for (Simulation s: document.getSimulations()) {
- String name = s.getName();
- if (name.startsWith(NAME_PREFIX)) {
- try {
- maxValue = Math.max(maxValue,
- Integer.parseInt(name.substring(NAME_PREFIX.length())));
- } catch (NumberFormatException ignore) { }
- }
- }
-
Simulation sim = new Simulation(document.getRocket());
- sim.setName(NAME_PREFIX + (maxValue+1));
+ sim.setName(document.getNextSimulationName());
int n = document.getSimulationCount();
document.addSimulation(sim);
this.add(button,"gapright para");
-// button = new JButton("Plot / export");
- button = new JButton("Plot flight");
+ button = new JButton("Plot / export");
+// button = new JButton("Plot flight");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// Set simulation status icon
Simulation.Status status = document.getSimulation(row).getStatus();
+ System.out.println("status=" + status);
label.setIcon(Icons.SIMULATION_STATUS_ICON_MAP.get(status));
}
};
- simulationTable = new JTable(simulationTableModel);
+ // Override processKeyBinding so that the JTable does not catch
+ // key bindings used in menu accelerators
+ simulationTable = new JTable(simulationTableModel) {
+ @Override
+ protected boolean processKeyBinding(KeyStroke ks,
+ KeyEvent e,
+ int condition,
+ boolean pressed) {
+ return false;
+ }
+ };
simulationTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
simulationTable.setDefaultRenderer(Object.class, new JLabelRenderer());
simulationTableModel.setColumnWidths(simulationTable.getColumnModel());
+
// Mouse listener to act on double-clicks
simulationTable.addMouseListener(new MouseAdapter() {
@Override
}
}
});
+
+ document.addDocumentChangeListener(new DocumentChangeListener() {
+ @Override
+ public void documentChanged(DocumentChangeEvent event) {
+ if (!(event instanceof SimulationChangeEvent))
+ return;
+ simulationTableModel.fireTableDataChanged();
+ }
+ });
}
+ public ListSelectionModel getSimulationListSelectionModel() {
+ return simulationTable.getSelectionModel();
+ }
+
private void openDialog(final Simulation sim, int position) {
new SimulationEditDialog(SwingUtilities.getWindowAncestor(this), sim, position)
.setVisible(true);
int[] selection = simulationTable.getSelectedRows();
simulationTableModel.fireTableDataChanged();
for (int row: selection) {
+ if (row >= simulationTableModel.getRowCount())
+ break;
simulationTable.addRowSelectionInterval(row, row);
}
}