commit
abce7097cc
@ -4,6 +4,8 @@ import java.util.List;
|
|||||||
|
|
||||||
import javax.swing.table.AbstractTableModel;
|
import javax.swing.table.AbstractTableModel;
|
||||||
|
|
||||||
|
import net.sf.openrocket.rocketcomponent.ComponentChangeEvent;
|
||||||
|
import net.sf.openrocket.rocketcomponent.ComponentChangeListener;
|
||||||
import net.sf.openrocket.rocketcomponent.MotorMount;
|
import net.sf.openrocket.rocketcomponent.MotorMount;
|
||||||
import net.sf.openrocket.rocketcomponent.Rocket;
|
import net.sf.openrocket.rocketcomponent.Rocket;
|
||||||
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||||
@ -12,25 +14,42 @@ import net.sf.openrocket.util.ArrayList;
|
|||||||
/**
|
/**
|
||||||
* The table model for selecting whether components are motor mounts or not.
|
* The table model for selecting whether components are motor mounts or not.
|
||||||
*/
|
*/
|
||||||
class MotorMountTableModel extends AbstractTableModel {
|
class MotorMountTableModel extends AbstractTableModel implements ComponentChangeListener {
|
||||||
|
|
||||||
private final MotorMountConfigurationPanel motorConfigurationPanel;
|
private final MotorMountConfigurationPanel motorConfigurationPanel;
|
||||||
|
|
||||||
private final List<MotorMount> potentialMounts = new ArrayList<MotorMount>();
|
private final List<MotorMount> potentialMounts = new ArrayList<MotorMount>();
|
||||||
|
|
||||||
|
private final Rocket rocket;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param motorConfigurationPanel
|
* @param motorConfigurationPanel
|
||||||
*/
|
*/
|
||||||
MotorMountTableModel(MotorMountConfigurationPanel motorConfigurationPanel, Rocket rocket) {
|
MotorMountTableModel(MotorMountConfigurationPanel motorConfigurationPanel, Rocket rocket) {
|
||||||
this.motorConfigurationPanel = motorConfigurationPanel;
|
this.motorConfigurationPanel = motorConfigurationPanel;
|
||||||
|
this.rocket = rocket;
|
||||||
|
|
||||||
|
initialize();
|
||||||
|
rocket.addComponentChangeListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initialize() {
|
||||||
|
potentialMounts.clear();
|
||||||
for (RocketComponent c : rocket) {
|
for (RocketComponent c : rocket) {
|
||||||
if (c instanceof MotorMount) {
|
if (c instanceof MotorMount) {
|
||||||
potentialMounts.add((MotorMount) c);
|
potentialMounts.add((MotorMount) c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void componentChanged(ComponentChangeEvent e) {
|
||||||
|
if ( e.isMotorChange() || e.isTreeChange() ) {
|
||||||
|
initialize();
|
||||||
|
fireTableStructureChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getColumnCount() {
|
public int getColumnCount() {
|
||||||
return 2;
|
return 2;
|
||||||
|
@ -117,9 +117,9 @@ public class SimulationPanel extends JPanel {
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
int[] selection = simulationTable.getSelectedRows();
|
int[] selection = simulationTable.getSelectedRows();
|
||||||
if (selection.length == 0)
|
if (selection.length == 0) {
|
||||||
return; // TODO: LOW: "None selected" dialog
|
return;
|
||||||
|
}
|
||||||
Simulation[] sims = new Simulation[selection.length];
|
Simulation[] sims = new Simulation[selection.length];
|
||||||
for (int i = 0; i < selection.length; i++) {
|
for (int i = 0; i < selection.length; i++) {
|
||||||
selection[i] = simulationTable.convertRowIndexToModel(selection[i]);
|
selection[i] = simulationTable.convertRowIndexToModel(selection[i]);
|
||||||
@ -138,9 +138,9 @@ public class SimulationPanel extends JPanel {
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
int[] selection = simulationTable.getSelectedRows();
|
int[] selection = simulationTable.getSelectedRows();
|
||||||
if (selection.length == 0)
|
if (selection.length == 0) {
|
||||||
return; // TODO: LOW: "None selected" dialog
|
return;
|
||||||
|
}
|
||||||
Simulation[] sims = new Simulation[selection.length];
|
Simulation[] sims = new Simulation[selection.length];
|
||||||
for (int i = 0; i < selection.length; i++) {
|
for (int i = 0; i < selection.length; i++) {
|
||||||
selection[i] = simulationTable.convertRowIndexToModel(selection[i]);
|
selection[i] = simulationTable.convertRowIndexToModel(selection[i]);
|
||||||
@ -164,9 +164,9 @@ public class SimulationPanel extends JPanel {
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
int[] selection = simulationTable.getSelectedRows();
|
int[] selection = simulationTable.getSelectedRows();
|
||||||
if (selection.length == 0)
|
if (selection.length == 0) {
|
||||||
return; // TODO: LOW: "None selected" dialog
|
return;
|
||||||
|
}
|
||||||
// Verify deletion
|
// Verify deletion
|
||||||
boolean verify = Application.getPreferences().getBoolean(Preferences.CONFIRM_DELETE_SIMULATION, true);
|
boolean verify = Application.getPreferences().getBoolean(Preferences.CONFIRM_DELETE_SIMULATION, true);
|
||||||
if (verify) {
|
if (verify) {
|
||||||
@ -218,9 +218,9 @@ public class SimulationPanel extends JPanel {
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
int selected = simulationTable.getSelectedRow();
|
int selected = simulationTable.getSelectedRow();
|
||||||
if (selected < 0)
|
if (selected < 0) {
|
||||||
return; // TODO: MEDIUM: "None selected" dialog
|
return;
|
||||||
|
}
|
||||||
selected = simulationTable.convertRowIndexToModel(selected);
|
selected = simulationTable.convertRowIndexToModel(selected);
|
||||||
simulationTable.clearSelection();
|
simulationTable.clearSelection();
|
||||||
simulationTable.addRowSelectionInterval(selected, selected);
|
simulationTable.addRowSelectionInterval(selected, selected);
|
||||||
@ -480,6 +480,7 @@ public class SimulationPanel extends JPanel {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
simulationTable.setAutoCreateRowSorter(true);
|
||||||
simulationTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
simulationTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
||||||
simulationTable.setDefaultRenderer(Object.class, new JLabelRenderer());
|
simulationTable.setDefaultRenderer(Object.class, new JLabelRenderer());
|
||||||
simulationTableModel.setColumnWidths(simulationTable.getColumnModel());
|
simulationTableModel.setColumnWidths(simulationTable.getColumnModel());
|
||||||
@ -490,17 +491,19 @@ public class SimulationPanel extends JPanel {
|
|||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
|
if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
|
||||||
int selected = simulationTable.getSelectedRow();
|
int selectedRow = simulationTable.getSelectedRow();
|
||||||
if (selected < 0)
|
if (selectedRow < 0) {
|
||||||
return;
|
return;
|
||||||
selected = simulationTable.convertRowIndexToModel(selected);
|
}
|
||||||
|
int selected = simulationTable.convertRowIndexToModel(selectedRow);
|
||||||
|
|
||||||
int column = simulationTable.columnAtPoint(e.getPoint());
|
int column = simulationTable.columnAtPoint(e.getPoint());
|
||||||
if (column == 0) {
|
if (column == 0) {
|
||||||
SimulationWarningDialog.showWarningDialog(SimulationPanel.this, document.getSimulations().get(selected));
|
SimulationWarningDialog.showWarningDialog(SimulationPanel.this, document.getSimulations().get(selected));
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
simulationTable.clearSelection();
|
simulationTable.clearSelection();
|
||||||
simulationTable.addRowSelectionInterval(selected, selected);
|
simulationTable.addRowSelectionInterval(selectedRow, selectedRow);
|
||||||
|
|
||||||
openDialog(document.getSimulations().get(selected));
|
openDialog(document.getSimulations().get(selected));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user