import net.miginfocom.swing.MigLayout;
import net.sf.openrocket.document.OpenRocketDocument;
+import net.sf.openrocket.gui.dialogs.motor.MotorChooserDialog;
import net.sf.openrocket.gui.main.BasicFrame;
-import net.sf.openrocket.gui.main.MotorChooserDialog;
-import net.sf.openrocket.rocketcomponent.Motor;
+import net.sf.openrocket.motor.Motor;
import net.sf.openrocket.rocketcomponent.MotorMount;
import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.rocketcomponent.RocketComponent;
+import net.sf.openrocket.util.Chars;
import net.sf.openrocket.util.GUIUtil;
public class EditMotorConfigurationDialog extends JDialog {
private final Rocket rocket;
private final MotorMount[] mounts;
-
+
private final JTable configurationTable;
private final MotorConfigurationTableModel configurationTableModel;
-
+
private final JButton newConfButton, removeConfButton;
private final JButton selectMotorButton, removeMotorButton;
private final JTextField configurationNameField;
-
+
private String currentID = null;
private MotorMount currentMount = null;
this.rocket = rocket;
ArrayList<MotorMount> mountList = new ArrayList<MotorMount>();
- Iterator<RocketComponent> iterator = rocket.deepIterator();
+ Iterator<RocketComponent> iterator = rocket.iterator();
while (iterator.hasNext()) {
RocketComponent c = iterator.next();
if (c instanceof MotorMount) {
- mountList.add((MotorMount)c);
+ mountList.add((MotorMount) c);
}
}
mounts = mountList.toArray(new MotorMount[0]);
-
-
+
+
JPanel panel = new JPanel(new MigLayout("fill, flowy"));
-
+
//// Motor mount selection
JLabel label = new JLabel("<html><b>Motor mounts:</b>");
panel.add(label, "gapbottom para");
label = new JLabel("<html>Select which components function as motor mounts:");
- panel.add(label,"ay 100%, w 1px, growx");
-
+ panel.add(label, "ay 100%, w 1px, growx");
+
JTable table = new JTable(new MotorMountTableModel());
table.setTableHeader(null);
table.setShowVerticalLines(false);
col0.setPreferredWidth(w);
col0.setMaxWidth(w);
+ table.addMouseListener(new GUIUtil.BooleanTableClickListener(table));
+
JScrollPane scroll = new JScrollPane(table);
panel.add(scroll, "w 200lp, h 150lp, grow, wrap 20lp");
-
-
-
+
+
+
//// Motor selection
label = new JLabel("<html><b>Motor configurations:</b>");
panel.add(label, "spanx, gapbottom para");
-
+
label = new JLabel("Configuration name:");
String tip = "Leave name empty for default.";
label.setToolTipText(tip);
public void changedUpdate(DocumentEvent e) {
update();
}
+
@Override
public void insertUpdate(DocumentEvent e) {
update();
}
+
@Override
public void removeUpdate(DocumentEvent e) {
update();
}
+
private void update() {
if (configurationNameModification != 0)
return;
-
+
String text = configurationNameField.getText();
if (currentID != null) {
configurationNameModification++;
});
panel.add(removeConfButton, "cell 4 1");
-
-
+
+
configurationTableModel = new MotorConfigurationTableModel();
configurationTable = new JTable(configurationTableModel);
configurationTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
scroll = new JScrollPane(configurationTable);
panel.add(scroll, "cell 1 2, spanx, w 500lp, h 150lp, grow");
-
+
selectMotorButton = new JButton("Select motor");
selectMotorButton.addActionListener(new ActionListener() {
@Override
});
panel.add(selectMotorButton, "spanx, flowx, split 2, ax 50%");
-
+
removeMotorButton = new JButton("Remove motor");
removeMotorButton.addActionListener(new ActionListener() {
@Override
});
panel.add(removeMotorButton, "ax 50%");
-
-
+
+
//// Close button
JButton close = new JButton("Close");
updateEnabled();
- GUIUtil.installEscapeCloseOperation(this);
- GUIUtil.setDefaultButton(close);
+ this.setLocationByPlatform(true);
+ GUIUtil.setDisposableDialogOptions(this, close);
// Undo description
final OpenRocketDocument document = BasicFrame.findDocument(rocket);
});
}
}
-
-
+
+
private void updateEnabled() {
int column = configurationTable.getSelectedColumn();
int row = configurationTable.getSelectedRow();
rocket.getDefaultConfiguration().setMotorConfigurationID(currentID);
}
-
+
if (configurationNameModification == 0) {
// Don't update name field when user is modifying it
configurationNameModification++;
removeMotorButton.setEnabled(currentMount != null && currentID != null);
}
-
-
+
+
private void selectMotor() {
if (currentID == null || currentMount == null)
return;
MotorChooserDialog dialog = new MotorChooserDialog(currentMount.getMotor(currentID),
- currentMount.getMotorDelay(currentID), currentMount.getMotorMountDiameter());
+ currentMount.getMotorDelay(currentID), currentMount.getMotorMountDiameter(), this);
dialog.setVisible(true);
Motor m = dialog.getSelectedMotor();
double d = dialog.getSelectedDelay();
currentMount.setMotor(currentID, m);
currentMount.setMotorDelay(currentID, d);
}
-
+
int row = configurationTable.getSelectedRow();
configurationTableModel.fireTableRowsUpdated(row, row);
updateEnabled();
private String findID(int row) {
- return rocket.getMotorConfigurationIDs()[row+1];
+ return rocket.getMotorConfigurationIDs()[row + 1];
}
-
+
private MotorMount findMount(int column) {
MotorMount mount = null;
-
+
int count = column;
- for (MotorMount m: mounts) {
+ for (MotorMount m : mounts) {
if (m.isMotorMount())
count--;
if (count <= 0) {
}
if (mount == null) {
- throw new IndexOutOfBoundsException("motor mount not found, column="+column);
+ throw new IndexOutOfBoundsException("motor mount not found, column=" + column);
}
return mount;
}
-
+
/**
* The table model for selecting whether components are motor mounts or not.
*/
private class MotorMountTableModel extends AbstractTableModel {
-
+
@Override
public int getColumnCount() {
return 2;
}
-
+
@Override
public int getRowCount() {
return mounts.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 mounts[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);
}
- mounts[row].setMotorMount((Boolean)value);
+ mounts[row].setMotorMount((Boolean) value);
configurationTableModel.fireTableStructureChanged();
updateEnabled();
}
}
-
+
/**
* The table model for selecting and editing the motor configurations.
*/
@Override
public int getColumnCount() {
int count = 1;
- for (MotorMount m: mounts) {
+ for (MotorMount m : mounts) {
if (m.isMotorMount())
count++;
}
return count;
}
-
+
@Override
public int getRowCount() {
- return rocket.getMotorConfigurationIDs().length-1;
+ return rocket.getMotorConfigurationIDs().length - 1;
}
-
+
@Override
public Object getValueAt(int row, int column) {
String id = findID(row);
-
+
if (column == 0) {
return rocket.getMotorConfigurationNameOrDescription(id);
}
if (motor == null)
return "None";
- String str = motor.getDesignation(mount.getMotorDelay(id));
+ String str = motor.getDesignation(mount.getMotorDelay(id));
int count = mount.getMotorCount();
if (count > 1) {
- str = "" + count + "\u00d7 " + str;
+ str = "" + count + Chars.TIMES + " " + str;
}
return str;
}
-
-
+
+
@Override
public String getColumnName(int column) {
if (column == 0) {
String name = mount.toString();
int count = mount.getMotorCount();
if (count > 1) {
- name = name + " (\u00d7" + count + ")";
+ name = name + " (" + Chars.TIMES + count + ")";
}
return name;
}
-
}
-
-
-
}