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.rocketcomponent.Motor;
+import net.sf.openrocket.l10n.Translator;
+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.startup.Application;
+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;
// Positive when user is modifying configuration name
private int configurationNameModification = 0;
-
+ private static final Translator trans = Application.getTranslator();
+
public EditMotorConfigurationDialog(final Rocket rocket, Window parent) {
- super(parent, "Edit motor configurations");
+ //// Edit motor configurations
+ super(parent, trans.get("edtmotorconfdlg.title.Editmotorconf"));
if (parent != null)
this.setModalityType(ModalityType.DOCUMENT_MODAL);
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>");
+ //// <html><b>Motor mounts:</b>
+ JLabel label = new JLabel(trans.get("edtmotorconfdlg.lbl.Motormounts"));
panel.add(label, "gapbottom para");
- label = new JLabel("<html>Select which components function as motor mounts:");
- panel.add(label,"ay 100%, w 1px, growx");
-
+ //// <html>Select which components function as motor mounts:
+ label = new JLabel(trans.get("edtmotorconfdlg.selectcomp"));
+ 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>");
+ //// <html><b>Motor configurations:</b>
+ label = new JLabel(trans.get("edtmotorconfdlg.lbl.Motorconfig"));
panel.add(label, "spanx, gapbottom para");
-
- label = new JLabel("Configuration name:");
- String tip = "Leave name empty for default.";
+ //// Configuration name:
+ label = new JLabel(trans.get("edtmotorconfdlg.lbl.Configname"));
+ //// Leave name empty for default.
+ String tip = trans.get("edtmotorconfdlg.lbl.Leavenamedefault");
label.setToolTipText(tip);
panel.add(label, "");
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(configurationNameField, "cell 2 1, gapright para");
- newConfButton = new JButton("New configuration");
+ //// New configuration
+ newConfButton = new JButton(trans.get("edtmotorconfdlg.but.Newconfiguration"));
newConfButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
});
panel.add(newConfButton, "cell 3 1");
- removeConfButton = new JButton("Remove configuration");
+ //// Remove configuration
+ removeConfButton = new JButton(trans.get("edtmotorconfdlg.but.Removeconfiguration"));
removeConfButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
});
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");
+ //// Select motor
+ selectMotorButton = new JButton(trans.get("edtmotorconfdlg.but.Selectmotor"));
selectMotorButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
});
panel.add(selectMotorButton, "spanx, flowx, split 2, ax 50%");
-
- removeMotorButton = new JButton("Remove motor");
+ //// Remove motor button
+ removeMotorButton = new JButton(trans.get("edtmotorconfdlg.but.removemotor"));
removeMotorButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
});
panel.add(removeMotorButton, "ax 50%");
-
-
+
+
//// Close button
-
- JButton close = new JButton("Close");
+ JButton close = new JButton(trans.get("dlg.but.close"));
close.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
updateEnabled();
- GUIUtil.installEscapeCloseOperation(this);
- GUIUtil.setDefaultButton(close);
this.setLocationByPlatform(true);
+ GUIUtil.setDisposableDialogOptions(this, close);
// Undo description
final OpenRocketDocument document = BasicFrame.findDocument(rocket);
if (document != null) {
- document.startUndo("Edit motor configurations");
+ //// Edit motor configurations
+ document.startUndo(trans.get("edtmotorconfdlg.title.Editmotorconf"));
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
});
}
}
-
-
+
+
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(),
- this);
+ 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);
}
MotorMount mount = findMount(column);
Motor motor = mount.getMotor(id);
if (motor == null)
+ //// None
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) {
- return "Configuration name";
+ //// Configuration name
+ return trans.get("edtmotorconfdlg.lbl.Configname");
}
MotorMount mount = findMount(column);
String name = mount.toString();
int count = mount.getMotorCount();
if (count > 1) {
- name = name + " (\u00d7" + count + ")";
+ name = name + " (" + Chars.TIMES + count + ")";
}
return name;
}
-
}
-
-
-
}