From 581ec324d9421fbeffebe349be75d1e61c3aaf1a Mon Sep 17 00:00:00 2001 From: kruland2607 Date: Tue, 25 Mar 2014 12:12:30 -0500 Subject: [PATCH] Fix selection bug in motor selection panel. The app threw NPE when trying to reuse the dialog. --- .../ThrustCurveMotorSelectionPanel.java | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) 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 ff9de619f..7ea640b54 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 @@ -310,6 +310,10 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec } public void setMotorMountAndConfig( MotorMount mount, String currentConfig ) { + selectedMotor = null; + selectedMotorSet = null; + selectedDelay = 0; + ThrustCurveMotor motorToSelect = null; if (currentConfig != null && mount != null) { MotorConfiguration motorConf = mount.getMotorConfiguration().get(currentConfig); @@ -317,21 +321,14 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec selectedDelay = motorConf.getEjectionDelay(); } - selectedMotorSet = null; - // If current motor is not found in db, add a new ThrustCurveMotorSet containing it if (motorToSelect != null) { - for (ThrustCurveMotorSet motorSet : database) { - if (motorSet.getMotors().contains(motorToSelect)) { - selectedMotorSet = motorSet; - break; - } - } - if (selectedMotorSet == null) { + ThrustCurveMotorSet motorSetToSelect = null; + motorSetToSelect = findMotorSet(motorToSelect); + if (motorSetToSelect == null) { database = new ArrayList(database); ThrustCurveMotorSet extra = new ThrustCurveMotorSet(); extra.addMotor(motorToSelect); - selectedMotorSet = extra; database.add(extra); Collections.sort(database); }