Fix+enhance motor configuration edit dialog
This commit is contained in:
parent
0725b54061
commit
1fb1e7e512
@ -8,7 +8,7 @@ import java.awt.event.MouseEvent;
|
|||||||
import java.awt.event.WindowAdapter;
|
import java.awt.event.WindowAdapter;
|
||||||
import java.awt.event.WindowEvent;
|
import java.awt.event.WindowEvent;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JDialog;
|
import javax.swing.JDialog;
|
||||||
@ -20,6 +20,8 @@ import javax.swing.JTextField;
|
|||||||
import javax.swing.ListSelectionModel;
|
import javax.swing.ListSelectionModel;
|
||||||
import javax.swing.event.DocumentEvent;
|
import javax.swing.event.DocumentEvent;
|
||||||
import javax.swing.event.DocumentListener;
|
import javax.swing.event.DocumentListener;
|
||||||
|
import javax.swing.event.ListSelectionEvent;
|
||||||
|
import javax.swing.event.ListSelectionListener;
|
||||||
import javax.swing.table.AbstractTableModel;
|
import javax.swing.table.AbstractTableModel;
|
||||||
import javax.swing.table.TableColumn;
|
import javax.swing.table.TableColumn;
|
||||||
import javax.swing.table.TableColumnModel;
|
import javax.swing.table.TableColumnModel;
|
||||||
@ -70,7 +72,7 @@ public class EditMotorConfigurationDialog extends JDialog {
|
|||||||
|
|
||||||
this.rocket = rocket;
|
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 = new JTable(configurationTableModel);
|
||||||
configurationTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
configurationTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||||
configurationTable.setCellSelectionEnabled(true);
|
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() {
|
configurationTable.addMouseListener(new MouseAdapter() {
|
||||||
@Override
|
@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() {
|
private void updateEnabled() {
|
||||||
|
@ -744,7 +744,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
|
|||||||
* @param preset the preset to load from
|
* @param preset the preset to load from
|
||||||
*/
|
*/
|
||||||
protected void loadFromPreset(ComponentPreset preset) {
|
protected void loadFromPreset(ComponentPreset preset) {
|
||||||
if ( preset.has(ComponentPreset.LENGTH) ) {
|
if (preset.has(ComponentPreset.LENGTH)) {
|
||||||
this.length = preset.get(ComponentPreset.LENGTH);
|
this.length = preset.get(ComponentPreset.LENGTH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1668,29 +1668,6 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
|
|||||||
return iterator(true);
|
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
|
* Compare component equality based on the ID of this component. Only the
|
||||||
* ID and class type is used for a basis of comparison.
|
* ID and class type is used for a basis of comparison.
|
||||||
@ -1740,8 +1717,8 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
|
|||||||
ringMass(outerRadius, innerRadius, x2 - x1, density));
|
ringMass(outerRadius, innerRadius, x2 - x1, density));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static final double ringVolume( double outerRadius, double innerRadius, double length ) {
|
protected static final double ringVolume(double outerRadius, double innerRadius, double length) {
|
||||||
return ringMass( outerRadius, innerRadius, length, 1.0 );
|
return ringMass(outerRadius, innerRadius, length, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static final double ringMass(double outerRadius, double innerRadius,
|
protected static final double ringMass(double outerRadius, double innerRadius,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user