Merged l10n branch to trunk
[debian/openrocket] / src / net / sf / openrocket / gui / dialogs / EditMotorConfigurationDialog.java
index bb80d92b629caeef20ad3ac70a8b42bd0e462cfa..b1ef4a9c60e528c7e67324be7829fef0efff2ce6 100644 (file)
@@ -26,11 +26,15 @@ import javax.swing.table.TableColumnModel;
 
 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 {
@@ -38,24 +42,26 @@ 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);
@@ -65,29 +71,30 @@ public class EditMotorConfigurationDialog extends JDialog {
                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);
@@ -101,21 +108,24 @@ public class EditMotorConfigurationDialog extends JDialog {
                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, "");
                
@@ -126,18 +136,21 @@ public class EditMotorConfigurationDialog extends JDialog {
                        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++;
@@ -151,7 +164,8 @@ public class EditMotorConfigurationDialog extends JDialog {
                });
                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) {
@@ -163,7 +177,8 @@ public class EditMotorConfigurationDialog extends JDialog {
                });
                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) {
@@ -177,9 +192,9 @@ public class EditMotorConfigurationDialog extends JDialog {
                });
                panel.add(removeConfButton, "cell 4 1");
                
-               
 
-               
+
+
                configurationTableModel = new MotorConfigurationTableModel();
                configurationTable = new JTable(configurationTableModel);
                configurationTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
@@ -208,8 +223,8 @@ public class EditMotorConfigurationDialog extends JDialog {
                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) {
@@ -218,8 +233,8 @@ public class EditMotorConfigurationDialog extends JDialog {
                });
                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) {
@@ -228,11 +243,10 @@ public class EditMotorConfigurationDialog extends JDialog {
                });
                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) {
@@ -247,14 +261,14 @@ public class EditMotorConfigurationDialog extends JDialog {
                
                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) {
@@ -263,10 +277,10 @@ public class EditMotorConfigurationDialog extends JDialog {
                        });
                }
        }
-
-       
        
        
+
+
        private void updateEnabled() {
                int column = configurationTable.getSelectedColumn();
                int row = configurationTable.getSelectedRow();
@@ -285,7 +299,7 @@ public class EditMotorConfigurationDialog extends JDialog {
                        rocket.getDefaultConfiguration().setMotorConfigurationID(currentID);
                        
                }
-
+               
                if (configurationNameModification == 0) {
                        // Don't update name field when user is modifying it
                        configurationNameModification++;
@@ -304,16 +318,15 @@ public class EditMotorConfigurationDialog extends JDialog {
                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();
@@ -322,7 +335,7 @@ public class EditMotorConfigurationDialog extends JDialog {
                        currentMount.setMotor(currentID, m);
                        currentMount.setMotorDelay(currentID, d);
                }
-
+               
                int row = configurationTable.getSelectedRow();
                configurationTableModel.fireTableRowsUpdated(row, row);
                updateEnabled();
@@ -342,15 +355,15 @@ public class EditMotorConfigurationDialog extends JDialog {
        
        
        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) {
@@ -360,22 +373,22 @@ public class EditMotorConfigurationDialog extends JDialog {
                }
                
                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;
@@ -391,10 +404,10 @@ public class EditMotorConfigurationDialog extends JDialog {
                                return String.class;
                                
                        default:
-                               throw new IndexOutOfBoundsException("column="+column);
+                               throw new IndexOutOfBoundsException("column=" + column);
                        }
                }
-
+               
                @Override
                public Object getValueAt(int row, int column) {
                        switch (column) {
@@ -405,7 +418,7 @@ public class EditMotorConfigurationDialog extends JDialog {
                                return mounts[row].toString();
                                
                        default:
-                               throw new IndexOutOfBoundsException("column="+column);
+                               throw new IndexOutOfBoundsException("column=" + column);
                        }
                }
                
@@ -417,17 +430,17 @@ public class EditMotorConfigurationDialog extends JDialog {
                @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.
         */
@@ -436,23 +449,23 @@ public class EditMotorConfigurationDialog extends JDialog {
                @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);
                        }
@@ -460,36 +473,34 @@ public class EditMotorConfigurationDialog extends JDialog {
                        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;
                }
                
-               
        }
-
-       
-       
        
 }