Fix+enhance motor configuration edit dialog

This commit is contained in:
Sampo Niskanen 2012-09-25 13:03:11 +00:00
parent 0725b54061
commit 1fb1e7e512
2 changed files with 365 additions and 365 deletions

View File

@ -8,7 +8,7 @@ import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JDialog;
@ -20,6 +20,8 @@ import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
@ -70,7 +72,7 @@ public class EditMotorConfigurationDialog extends JDialog {
this.rocket = rocket;
mounts = rocket.getMotorMounts().toArray( new MotorMount[0]) ;
mounts = getPotentialMotorMounts();
@ -191,6 +193,16 @@ public class EditMotorConfigurationDialog extends JDialog {
configurationTable = new JTable(configurationTableModel);
configurationTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
configurationTable.setCellSelectionEnabled(true);
configurationTable.getColumnModel().getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
int column = configurationTable.getSelectedColumn();
System.err.println("column=" + column);
if (column == 0 && configurationTable.getColumnCount() > 1) {
configurationTable.setColumnSelectionInterval(1, 1);
}
}
});
configurationTable.addMouseListener(new MouseAdapter() {
@Override
@ -271,6 +283,17 @@ public class EditMotorConfigurationDialog extends JDialog {
}
private MotorMount[] getPotentialMotorMounts() {
List<MotorMount> list = new ArrayList<MotorMount>();
for (RocketComponent c : rocket) {
if (c instanceof MotorMount) {
list.add((MotorMount) c);
}
}
return list.toArray(new MotorMount[0]);
}
private void updateEnabled() {

View File

@ -1668,29 +1668,6 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
return iterator(true);
}
/**
* Retrieve the List of MotorMounts in the Rocket.
*
* Each element returned will a RocketComponent which implements MotorMount. Further isMotorMount()
* returns true.
*
* @return List<MotorMount>
*/
public final List<MotorMount> getMotorMounts() {
Iterator<RocketComponent> it = iterator();
List<MotorMount> mmts = new ArrayList<MotorMount>();
while (it.hasNext()) {
RocketComponent c = it.next();
if (c instanceof MotorMount) {
if ( ((MotorMount)c).isMotorMount() ) {
mmts.add((MotorMount) c);
}
}
}
return mmts;
}
/**
* Compare component equality based on the ID of this component. Only the
* ID and class type is used for a basis of comparison.