From e18b0812733e5fc1b56169f19318c67460247322 Mon Sep 17 00:00:00 2001 From: kruland2607 Date: Tue, 16 Oct 2012 12:53:37 -0500 Subject: [PATCH] Added some l10n strings to the motor table. Tightened up access to package scope member variables. --- core/resources/l10n/messages.properties | 6 ++- .../FlightConfigurationDialog.java | 50 +++++++++++++++---- .../FlightConfigurationModel.java | 7 ++- .../MotorConfigurationTableModel.java | 38 ++++++-------- .../MotorMountTableModel.java | 4 +- 5 files changed, 66 insertions(+), 39 deletions(-) diff --git a/core/resources/l10n/messages.properties b/core/resources/l10n/messages.properties index 175b90de8..380ad6c98 100644 --- a/core/resources/l10n/messages.properties +++ b/core/resources/l10n/messages.properties @@ -185,7 +185,11 @@ edtmotorconfdlg.selectcomp = Select which components function as motor mou edtmotorconfdlg.lbl.Motorconfig = Motor configurations: edtmotorconfdlg.lbl.Configname = Configuration name: edtmotorconfdlg.lbl.Motortab = Motors -edtmotorconfdlg.lbl.Advancemode = Advanced mode +edtmotorconfdlg.tbl.None = None +edtmotorconfdlg.tbl.Motorheader = Motor +edtmotorconfdlg.tbl.Mountheader = Motor Mount +edtmotorconfdlg.tbl.Ignitionheader = Ignition + ! Example design dialog exdesigndlg.but.open = Open exdesigndlg.lbl.Selectexample = Select example designs to open: diff --git a/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/FlightConfigurationDialog.java b/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/FlightConfigurationDialog.java index 5c879c240..ad99b06b4 100644 --- a/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/FlightConfigurationDialog.java +++ b/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/FlightConfigurationDialog.java @@ -33,21 +33,23 @@ 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.rocketcomponent.MotorMount.IgnitionEvent; import net.sf.openrocket.startup.Application; +import net.sf.openrocket.util.Chars; public class FlightConfigurationDialog extends JDialog { - final Rocket rocket; + private final Rocket rocket; final MotorMount[] mounts; - MotorConfigurationTableModel configurationTableModel; - FlightConfigurationModel flightConfigurationModel; + private MotorConfigurationTableModel configurationTableModel; + private FlightConfigurationModel flightConfigurationModel; private final JButton renameConfButton, removeConfButton, copyConfButton; private JButton selectMotorButton, removeMotorButton; - String currentID = null; + private String currentID = null; private MotorMount currentMount = null; static final Translator trans = Application.getTranslator(); @@ -72,7 +74,7 @@ public class FlightConfigurationDialog extends JDialog { JLabel label = new JLabel("Selected Configuration: "); panel.add(label); - flightConfigurationModel = new FlightConfigurationModel(rocket.getDefaultConfiguration()); + flightConfigurationModel = new FlightConfigurationModel(this, rocket.getDefaultConfiguration()); JComboBox configSelector = new JComboBox(flightConfigurationModel); panel.add(configSelector,"gapright para"); @@ -200,7 +202,7 @@ public class FlightConfigurationDialog extends JDialog { updateButtonState(); } - void updateButtonState() { + private void updateButtonState() { removeConfButton.setEnabled(currentID != null); renameConfButton.setEnabled(currentID != null); selectMotorButton.setEnabled(currentMount != null && currentID != null); @@ -237,12 +239,12 @@ public class FlightConfigurationDialog extends JDialog { updateButtonState(); } - - String findID(int row) { - return rocket.getMotorConfigurationIDs()[row + 1]; + void makeMotorMount( MotorMount mount, boolean isMotorMount ) { + mount.setMotorMount( isMotorMount ); + configurationTableModel.fireTableStructureChanged(); + updateButtonState(); } - - + MotorMount findMount(int column) { MotorMount mount = null; @@ -262,6 +264,32 @@ public class FlightConfigurationDialog extends JDialog { return mount; } + String findMotorForDisplay( int column ) { + String id = currentID; + MotorMount mount = findMount(column); + Motor motor = mount.getMotor(id); + if (motor == null) + return null; + + String str = motor.getDesignation(mount.getMotorDelay(id)); + int count = mount.getMotorCount(); + if (count > 1) { + str = "" + count + Chars.TIMES + " " + str; + } + return str; + } + + String findIgnitionForDisplay( int column ) { + String id = currentID; + MotorMount mount = findMount(column); + Motor motor = mount.getMotor(id); + if (motor == null) + //// None + return null; + IgnitionEvent ignition = mount.getIgnitionEvent(); + return ignition.toString(); + } + private JComponent makeMotorTab( ) { JPanel panel = new JPanel(new MigLayout("fill")); diff --git a/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/FlightConfigurationModel.java b/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/FlightConfigurationModel.java index c2a00fbb6..96c013834 100644 --- a/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/FlightConfigurationModel.java +++ b/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/FlightConfigurationModel.java @@ -15,7 +15,10 @@ public class FlightConfigurationModel extends DefaultComboBoxModel { private Map map = new HashMap(); - public FlightConfigurationModel(Configuration config) { + private final FlightConfigurationDialog flightConfigurationDialog; + + public FlightConfigurationModel(FlightConfigurationDialog flightConfigurationDialog, Configuration config) { + this.flightConfigurationDialog = flightConfigurationDialog; this.config = config; this.rocket = config.getRocket(); } @@ -54,7 +57,7 @@ public class FlightConfigurationModel extends DefaultComboBoxModel { } ID idObject = (ID) item; - config.setMotorConfigurationID(idObject.getID()); + flightConfigurationDialog.selectConfiguration(idObject.getID()); } /* diff --git a/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/MotorConfigurationTableModel.java b/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/MotorConfigurationTableModel.java index ccfcf4e5e..7cae5b80a 100644 --- a/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/MotorConfigurationTableModel.java +++ b/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/MotorConfigurationTableModel.java @@ -2,9 +2,7 @@ package net.sf.openrocket.gui.dialogs.flightconfiguration; import javax.swing.table.AbstractTableModel; -import net.sf.openrocket.motor.Motor; import net.sf.openrocket.rocketcomponent.MotorMount; -import net.sf.openrocket.rocketcomponent.MotorMount.IgnitionEvent; import net.sf.openrocket.util.Chars; /** @@ -12,6 +10,11 @@ import net.sf.openrocket.util.Chars; */ class MotorConfigurationTableModel extends AbstractTableModel { + private final static String NONE = FlightConfigurationDialog.trans.get("edtmotorconfdlg.tbl.None"); + private final static String MOTOR_MOUNT = FlightConfigurationDialog.trans.get("edtmotorconfdlg.tbl.Mountheader"); + private final static String MOTOR = FlightConfigurationDialog.trans.get("edtmotorconfdlg.tbl.Motorheader"); + private final static String IGNITION = FlightConfigurationDialog.trans.get("edtmotorconfdlg.tbl.Ignitionheader"); + /** * */ @@ -46,8 +49,6 @@ class MotorConfigurationTableModel extends AbstractTableModel { @Override public Object getValueAt(int row, int column) { - String id = this.flightConfigurationDialog.currentID; - switch( column ) { case 0: { @@ -61,28 +62,21 @@ class MotorConfigurationTableModel extends AbstractTableModel { } case 1: { - MotorMount mount = this.flightConfigurationDialog.findMount(row); - Motor motor = mount.getMotor(id); - if (motor == null) + String str = this.flightConfigurationDialog.findMotorForDisplay(row); + if (str == null) //// None - return "None"; + return NONE; - String str = motor.getDesignation(mount.getMotorDelay(id)); - int count = mount.getMotorCount(); - if (count > 1) { - str = "" + count + Chars.TIMES + " " + str; - } return str; } case 2: { - MotorMount mount = this.flightConfigurationDialog.findMount(row); - Motor motor = mount.getMotor(id); - if (motor == null) + String str = this.flightConfigurationDialog.findIgnitionForDisplay(row); + if (str == null) //// None - return "None"; - IgnitionEvent ignition = mount.getIgnitionEvent(); - return ignition.toString(); + return NONE; + + return str; } default: return ""; @@ -94,11 +88,11 @@ class MotorConfigurationTableModel extends AbstractTableModel { public String getColumnName(int column) { switch (column ) { case 0: - return "Motor Mount"; + return MOTOR_MOUNT; case 1: - return "Motor"; + return MOTOR; case 2: - return "Ignition"; + return IGNITION; default: return ""; } diff --git a/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/MotorMountTableModel.java b/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/MotorMountTableModel.java index b89878bd6..7b4f56778 100644 --- a/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/MotorMountTableModel.java +++ b/core/src/net/sf/openrocket/gui/dialogs/flightconfiguration/MotorMountTableModel.java @@ -68,8 +68,6 @@ class MotorMountTableModel extends AbstractTableModel { throw new IllegalArgumentException("column=" + column + ", value=" + value); } - this.flightConfigurationDialog.mounts[row].setMotorMount((Boolean) value); - this.flightConfigurationDialog.configurationTableModel.fireTableStructureChanged(); - this.flightConfigurationDialog.updateButtonState(); + this.flightConfigurationDialog.makeMotorMount( this.flightConfigurationDialog.mounts[row], (Boolean) value); } } \ No newline at end of file