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.
This commit is contained in:
parent
5913fb2533
commit
32817f2cb1
@ -43,9 +43,11 @@ public class MotorConfigurationPanel extends JPanel {
|
|||||||
private final MotorConfigurationTableModel configurationTableModel;
|
private final MotorConfigurationTableModel configurationTableModel;
|
||||||
private final JButton selectMotorButton, removeMotorButton, selectIgnitionButton, resetIgnitionButton;
|
private final JButton selectMotorButton, removeMotorButton, selectIgnitionButton, resetIgnitionButton;
|
||||||
|
|
||||||
|
private final MotorChooserDialog dialog;
|
||||||
|
|
||||||
MotorConfigurationPanel(FlightConfigurationDialog flightConfigurationDialog, Rocket rocket) {
|
MotorConfigurationPanel(FlightConfigurationDialog flightConfigurationDialog, Rocket rocket) {
|
||||||
super(new MigLayout("fill"));
|
super(new MigLayout("fill"));
|
||||||
|
dialog = new MotorChooserDialog(flightConfigurationDialog);
|
||||||
this.flightConfigurationDialog = flightConfigurationDialog;
|
this.flightConfigurationDialog = flightConfigurationDialog;
|
||||||
this.rocket = rocket;
|
this.rocket = rocket;
|
||||||
|
|
||||||
@ -207,7 +209,7 @@ public class MotorConfigurationPanel extends JPanel {
|
|||||||
|
|
||||||
MotorConfiguration config = mount.getMotorConfiguration().get(id);
|
MotorConfiguration config = mount.getMotorConfiguration().get(id);
|
||||||
|
|
||||||
MotorChooserDialog dialog = new MotorChooserDialog(mount, id, flightConfigurationDialog);
|
dialog.setMotorMountAndConfig(mount, id);
|
||||||
dialog.setVisible(true);
|
dialog.setVisible(true);
|
||||||
Motor m = dialog.getSelectedMotor();
|
Motor m = dialog.getSelectedMotor();
|
||||||
double d = dialog.getSelectedDelay();
|
double d = dialog.getSelectedDelay();
|
||||||
|
@ -26,14 +26,18 @@ public class MotorChooserDialog extends JDialog implements CloseableDialog {
|
|||||||
private boolean okClicked = false;
|
private boolean okClicked = false;
|
||||||
private static final Translator trans = Application.getTranslator();
|
private static final Translator trans = Application.getTranslator();
|
||||||
|
|
||||||
|
|
||||||
public MotorChooserDialog(MotorMount mount, String currentConfig, Window owner) {
|
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);
|
super(owner, trans.get("MotorChooserDialog.title"), Dialog.ModalityType.APPLICATION_MODAL);
|
||||||
|
|
||||||
|
|
||||||
JPanel panel = new JPanel(new MigLayout("fill"));
|
JPanel panel = new JPanel(new MigLayout("fill"));
|
||||||
|
|
||||||
selectionPanel = new ThrustCurveMotorSelectionPanel(mount, currentConfig);
|
selectionPanel = new ThrustCurveMotorSelectionPanel();
|
||||||
|
|
||||||
panel.add(selectionPanel, "grow, wrap para");
|
panel.add(selectionPanel, "grow, wrap para");
|
||||||
|
|
||||||
@ -74,6 +78,9 @@ public class MotorChooserDialog extends JDialog implements CloseableDialog {
|
|||||||
selectionPanel.setCloseableDialog(this);
|
selectionPanel.setCloseableDialog(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMotorMountAndConfig( MotorMount mount, String currentConfig ) {
|
||||||
|
selectionPanel.setMotorMountAndConfig(mount, currentConfig);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the motor selected by this chooser dialog, or <code>null</code> if the selection has been aborted.
|
* Return the motor selected by this chooser dialog, or <code>null</code> if the selection has been aborted.
|
||||||
|
@ -30,7 +30,7 @@ class MotorRowFilter extends RowFilter<TableModel, Integer> {
|
|||||||
|
|
||||||
// configuration data used in the filter process
|
// configuration data used in the filter process
|
||||||
private final ThrustCurveMotorDatabaseModel model;
|
private final ThrustCurveMotorDatabaseModel model;
|
||||||
private final Double diameter;
|
private Double diameter;
|
||||||
private List<ThrustCurveMotor> usedMotors = new ArrayList<ThrustCurveMotor>();
|
private List<ThrustCurveMotor> usedMotors = new ArrayList<ThrustCurveMotor>();
|
||||||
|
|
||||||
// things which can be changed to modify filter behavior
|
// things which can be changed to modify filter behavior
|
||||||
@ -50,9 +50,12 @@ class MotorRowFilter extends RowFilter<TableModel, Integer> {
|
|||||||
// List of ImpulseClasses to exclude.
|
// List of ImpulseClasses to exclude.
|
||||||
private List<ImpulseClass> excludedImpulseClass = new ArrayList<ImpulseClass>();
|
private List<ImpulseClass> excludedImpulseClass = new ArrayList<ImpulseClass>();
|
||||||
|
|
||||||
public MotorRowFilter(MotorMount mount, ThrustCurveMotorDatabaseModel model) {
|
public MotorRowFilter(ThrustCurveMotorDatabaseModel model) {
|
||||||
super();
|
super();
|
||||||
this.model = model;
|
this.model = model;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMotorMount( MotorMount mount ) {
|
||||||
if (mount != null) {
|
if (mount != null) {
|
||||||
this.diameter = mount.getMotorMountDiameter();
|
this.diameter = mount.getMotorMountDiameter();
|
||||||
for (MotorConfiguration m : mount.getMotorConfiguration()) {
|
for (MotorConfiguration m : mount.getMotorConfiguration()) {
|
||||||
|
@ -98,20 +98,21 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
|
|||||||
|
|
||||||
private static final ThrustCurveMotorComparator MOTOR_COMPARATOR = new ThrustCurveMotorComparator();
|
private static final ThrustCurveMotorComparator MOTOR_COMPARATOR = new ThrustCurveMotorComparator();
|
||||||
|
|
||||||
private final List<ThrustCurveMotorSet> database;
|
private List<ThrustCurveMotorSet> database;
|
||||||
|
|
||||||
private CloseableDialog dialog = null;
|
private CloseableDialog dialog = null;
|
||||||
|
|
||||||
final ThrustCurveMotorDatabaseModel model;
|
final ThrustCurveMotorDatabaseModel model;
|
||||||
private final JTable table;
|
private final JTable table;
|
||||||
private final TableRowSorter<TableModel> sorter;
|
private final TableRowSorter<TableModel> sorter;
|
||||||
|
private final MotorRowFilter rowFilter;
|
||||||
|
|
||||||
private final JCheckBox hideSimilarBox;
|
private final JCheckBox hideSimilarBox;
|
||||||
|
|
||||||
private final JTextField searchField;
|
private final JTextField searchField;
|
||||||
String[] searchTerms = new String[0];
|
String[] searchTerms = new String[0];
|
||||||
|
|
||||||
|
private final StyledLabel diameterLabel;
|
||||||
private final JLabel curveSelectionLabel;
|
private final JLabel curveSelectionLabel;
|
||||||
private final JComboBox curveSelectionBox;
|
private final JComboBox curveSelectionBox;
|
||||||
private final DefaultComboBoxModel curveSelectionModel;
|
private final DefaultComboBoxModel curveSelectionModel;
|
||||||
@ -140,7 +141,11 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
|
|||||||
private ThrustCurveMotorSet selectedMotorSet;
|
private ThrustCurveMotorSet selectedMotorSet;
|
||||||
private double selectedDelay;
|
private double selectedDelay;
|
||||||
|
|
||||||
|
public ThrustCurveMotorSelectionPanel(MotorMount mount, String currentConfig) {
|
||||||
|
this();
|
||||||
|
setMotorMountAndConfig( mount, currentConfig );
|
||||||
|
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Sole constructor.
|
* Sole constructor.
|
||||||
*
|
*
|
||||||
@ -148,42 +153,17 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
|
|||||||
* @param delay the currently selected ejection charge delay.
|
* @param delay the currently selected ejection charge delay.
|
||||||
* @param diameter the diameter of the motor mount.
|
* @param diameter the diameter of the motor mount.
|
||||||
*/
|
*/
|
||||||
public ThrustCurveMotorSelectionPanel(MotorMount mount, String currentConfig) {
|
public ThrustCurveMotorSelectionPanel() {
|
||||||
super(new MigLayout("fill", "[grow][]"));
|
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)
|
// Construct the database (adding the current motor if not in the db already)
|
||||||
List<ThrustCurveMotorSet> db;
|
List<ThrustCurveMotorSet> db;
|
||||||
db = Application.getThrustCurveMotorSetDatabase().getMotorSets();
|
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<ThrustCurveMotorSet>(db);
|
|
||||||
ThrustCurveMotorSet extra = new ThrustCurveMotorSet();
|
|
||||||
extra.addMotor(selectedMotor);
|
|
||||||
selectedMotorSet = extra;
|
|
||||||
db.add(extra);
|
|
||||||
Collections.sort(db);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
database = db;
|
database = db;
|
||||||
|
|
||||||
model = new ThrustCurveMotorDatabaseModel(database);
|
model = new ThrustCurveMotorDatabaseModel(database);
|
||||||
final MotorRowFilter rowFilter = new MotorRowFilter(mount, model);
|
rowFilter = new MotorRowFilter(model);
|
||||||
|
|
||||||
//// GUI
|
//// GUI
|
||||||
|
|
||||||
@ -369,8 +349,7 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
|
|||||||
|
|
||||||
// Motor mount diameter label
|
// Motor mount diameter label
|
||||||
//// Motor mount diameter:
|
//// Motor mount diameter:
|
||||||
label = new StyledLabel(trans.get("TCMotorSelPan.lbl.Motormountdia") + " " +
|
diameterLabel = new StyledLabel();
|
||||||
UnitGroup.UNITS_MOTOR_DIMENSIONS.getDefaultUnit().toStringUnit(diameter));
|
|
||||||
panel.add(label, "gapright 30lp, spanx, split");
|
panel.add(label, "gapright 30lp, spanx, split");
|
||||||
|
|
||||||
// Vertical split
|
// Vertical split
|
||||||
@ -490,9 +469,6 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
|
|||||||
scrollpane = new JScrollPane(comment);
|
scrollpane = new JScrollPane(comment);
|
||||||
panel.add(scrollpane, "spanx, growx, wrap para");
|
panel.add(scrollpane, "spanx, growx, wrap para");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Thrust curve plot
|
// Thrust curve plot
|
||||||
chart = ChartFactory.createXYLineChart(
|
chart = ChartFactory.createXYLineChart(
|
||||||
null, // title
|
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<ThrustCurveMotorSet>(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
|
@Override
|
||||||
public Motor getSelectedMotor() {
|
public Motor getSelectedMotor() {
|
||||||
return selectedMotor;
|
return selectedMotor;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user