From 32817f2cb1c2f302f092de3c9735ff5403d2d876 Mon Sep 17 00:00:00 2001 From: kruland2607 Date: Thu, 3 Oct 2013 21:00:50 -0500 Subject: [PATCH] Reworked the ThrustCurveMotorSelectionPanel so a single instance can be reused for different searches. This means the MotorRowFilter has an easier time remembering its settings on a per rocket basis. --- .../MotorConfigurationPanel.java | 4 +- .../gui/dialogs/motor/MotorChooserDialog.java | 11 ++- .../motor/thrustcurve/MotorRowFilter.java | 7 +- .../ThrustCurveMotorSelectionPanel.java | 85 +++++++++++-------- 4 files changed, 67 insertions(+), 40 deletions(-) diff --git a/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/MotorConfigurationPanel.java b/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/MotorConfigurationPanel.java index 1cb7178f6..b47d910f7 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/MotorConfigurationPanel.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/flightconfiguration/MotorConfigurationPanel.java @@ -43,9 +43,11 @@ public class MotorConfigurationPanel extends JPanel { private final MotorConfigurationTableModel configurationTableModel; private final JButton selectMotorButton, removeMotorButton, selectIgnitionButton, resetIgnitionButton; + private final MotorChooserDialog dialog; MotorConfigurationPanel(FlightConfigurationDialog flightConfigurationDialog, Rocket rocket) { super(new MigLayout("fill")); + dialog = new MotorChooserDialog(flightConfigurationDialog); this.flightConfigurationDialog = flightConfigurationDialog; this.rocket = rocket; @@ -207,7 +209,7 @@ public class MotorConfigurationPanel extends JPanel { MotorConfiguration config = mount.getMotorConfiguration().get(id); - MotorChooserDialog dialog = new MotorChooserDialog(mount, id, flightConfigurationDialog); + dialog.setMotorMountAndConfig(mount, id); dialog.setVisible(true); Motor m = dialog.getSelectedMotor(); double d = dialog.getSelectedDelay(); diff --git a/swing/src/net/sf/openrocket/gui/dialogs/motor/MotorChooserDialog.java b/swing/src/net/sf/openrocket/gui/dialogs/motor/MotorChooserDialog.java index 898964af0..a6718116f 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/motor/MotorChooserDialog.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/motor/MotorChooserDialog.java @@ -26,14 +26,18 @@ public class MotorChooserDialog extends JDialog implements CloseableDialog { private boolean okClicked = false; private static final Translator trans = Application.getTranslator(); - public MotorChooserDialog(MotorMount mount, String currentConfig, Window owner) { + this(owner); + setMotorMountAndConfig(mount, currentConfig); + } + + public MotorChooserDialog(Window owner) { super(owner, trans.get("MotorChooserDialog.title"), Dialog.ModalityType.APPLICATION_MODAL); JPanel panel = new JPanel(new MigLayout("fill")); - selectionPanel = new ThrustCurveMotorSelectionPanel(mount, currentConfig); + selectionPanel = new ThrustCurveMotorSelectionPanel(); panel.add(selectionPanel, "grow, wrap para"); @@ -74,6 +78,9 @@ public class MotorChooserDialog extends JDialog implements CloseableDialog { selectionPanel.setCloseableDialog(this); } + public void setMotorMountAndConfig( MotorMount mount, String currentConfig ) { + selectionPanel.setMotorMountAndConfig(mount, currentConfig); + } /** * Return the motor selected by this chooser dialog, or null if the selection has been aborted. diff --git a/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/MotorRowFilter.java b/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/MotorRowFilter.java index 82d7483c9..a7961ec1d 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/MotorRowFilter.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/MotorRowFilter.java @@ -30,7 +30,7 @@ class MotorRowFilter extends RowFilter { // configuration data used in the filter process private final ThrustCurveMotorDatabaseModel model; - private final Double diameter; + private Double diameter; private List usedMotors = new ArrayList(); // things which can be changed to modify filter behavior @@ -50,9 +50,12 @@ class MotorRowFilter extends RowFilter { // List of ImpulseClasses to exclude. private List excludedImpulseClass = new ArrayList(); - public MotorRowFilter(MotorMount mount, ThrustCurveMotorDatabaseModel model) { + public MotorRowFilter(ThrustCurveMotorDatabaseModel model) { super(); this.model = model; + } + + public void setMotorMount( MotorMount mount ) { if (mount != null) { this.diameter = mount.getMotorMountDiameter(); for (MotorConfiguration m : mount.getMotorConfiguration()) { diff --git a/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/ThrustCurveMotorSelectionPanel.java b/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/ThrustCurveMotorSelectionPanel.java index 555c49a38..07d2ccc54 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/ThrustCurveMotorSelectionPanel.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/motor/thrustcurve/ThrustCurveMotorSelectionPanel.java @@ -98,20 +98,21 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec private static final ThrustCurveMotorComparator MOTOR_COMPARATOR = new ThrustCurveMotorComparator(); - private final List database; + private List database; private CloseableDialog dialog = null; final ThrustCurveMotorDatabaseModel model; private final JTable table; private final TableRowSorter sorter; + private final MotorRowFilter rowFilter; private final JCheckBox hideSimilarBox; private final JTextField searchField; String[] searchTerms = new String[0]; - + private final StyledLabel diameterLabel; private final JLabel curveSelectionLabel; private final JComboBox curveSelectionBox; private final DefaultComboBoxModel curveSelectionModel; @@ -140,7 +141,11 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec private ThrustCurveMotorSet selectedMotorSet; private double selectedDelay; - + public ThrustCurveMotorSelectionPanel(MotorMount mount, String currentConfig) { + this(); + setMotorMountAndConfig( mount, currentConfig ); + + } /** * Sole constructor. * @@ -148,42 +153,17 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec * @param delay the currently selected ejection charge delay. * @param diameter the diameter of the motor mount. */ - public ThrustCurveMotorSelectionPanel(MotorMount mount, String currentConfig) { + public ThrustCurveMotorSelectionPanel() { super(new MigLayout("fill", "[grow][]")); - double diameter = 0; - if (currentConfig != null && mount != null) { - MotorConfiguration motorConf = mount.getMotorConfiguration().get(currentConfig); - selectedMotor = (ThrustCurveMotor) motorConf.getMotor(); - selectedDelay = motorConf.getEjectionDelay(); - diameter = mount.getMotorMountDiameter(); - } - // Construct the database (adding the current motor if not in the db already) List db; db = Application.getThrustCurveMotorSetDatabase().getMotorSets(); - // If current motor is not found in db, add a new ThrustCurveMotorSet containing it - if (selectedMotor != null) { - for (ThrustCurveMotorSet motorSet : db) { - if (motorSet.getMotors().contains(selectedMotor)) { - selectedMotorSet = motorSet; - break; - } - } - if (selectedMotorSet == null) { - db = new ArrayList(db); - ThrustCurveMotorSet extra = new ThrustCurveMotorSet(); - extra.addMotor(selectedMotor); - selectedMotorSet = extra; - db.add(extra); - Collections.sort(db); - } - } database = db; model = new ThrustCurveMotorDatabaseModel(database); - final MotorRowFilter rowFilter = new MotorRowFilter(mount, model); + rowFilter = new MotorRowFilter(model); //// GUI @@ -369,8 +349,7 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec // Motor mount diameter label //// Motor mount diameter: - label = new StyledLabel(trans.get("TCMotorSelPan.lbl.Motormountdia") + " " + - UnitGroup.UNITS_MOTOR_DIMENSIONS.getDefaultUnit().toStringUnit(diameter)); + diameterLabel = new StyledLabel(); panel.add(label, "gapright 30lp, spanx, split"); // Vertical split @@ -490,9 +469,6 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec scrollpane = new JScrollPane(comment); panel.add(scrollpane, "spanx, growx, wrap para"); - - - // Thrust curve plot chart = ChartFactory.createXYLineChart( null, // title @@ -569,6 +545,45 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec } + public void setMotorMountAndConfig( MotorMount mount, String currentConfig ) { + double diameter = 0; + + if (currentConfig != null && mount != null) { + MotorConfiguration motorConf = mount.getMotorConfiguration().get(currentConfig); + selectedMotor = (ThrustCurveMotor) motorConf.getMotor(); + selectedDelay = motorConf.getEjectionDelay(); + diameter = mount.getMotorMountDiameter(); + } + + // If current motor is not found in db, add a new ThrustCurveMotorSet containing it + if (selectedMotor != null) { + for (ThrustCurveMotorSet motorSet : database) { + if (motorSet.getMotors().contains(selectedMotor)) { + selectedMotorSet = motorSet; + break; + } + } + if (selectedMotorSet == null) { + database = new ArrayList(database); + ThrustCurveMotorSet extra = new ThrustCurveMotorSet(); + extra.addMotor(selectedMotor); + selectedMotorSet = extra; + database.add(extra); + Collections.sort(database); + } + } + + updateData(); + setDelays(true); + + diameterLabel.setText(trans.get("TCMotorSelPan.lbl.Motormountdia") + " " + + UnitGroup.UNITS_MOTOR_DIMENSIONS.getDefaultUnit().toStringUnit(0)); + + rowFilter.setMotorMount(mount); + scrollSelectionVisible(); + + } + @Override public Motor getSelectedMotor() { return selectedMotor;