Fix bug in GeneralOptimizationDialog related to sorting the optimization
parameters. Switched to using a table row sorter instead of manually sorting the array.
This commit is contained in:
parent
1d686c88e5
commit
c9827cd5c1
@ -48,6 +48,7 @@ import javax.swing.event.TreeSelectionListener;
|
|||||||
import javax.swing.table.AbstractTableModel;
|
import javax.swing.table.AbstractTableModel;
|
||||||
import javax.swing.table.DefaultTableCellRenderer;
|
import javax.swing.table.DefaultTableCellRenderer;
|
||||||
import javax.swing.table.TableColumnModel;
|
import javax.swing.table.TableColumnModel;
|
||||||
|
import javax.swing.table.TableRowSorter;
|
||||||
import javax.swing.tree.DefaultMutableTreeNode;
|
import javax.swing.tree.DefaultMutableTreeNode;
|
||||||
import javax.swing.tree.TreePath;
|
import javax.swing.tree.TreePath;
|
||||||
|
|
||||||
@ -96,7 +97,6 @@ import net.sf.openrocket.util.TextUtil;
|
|||||||
|
|
||||||
import com.itextpdf.text.Font;
|
import com.itextpdf.text.Font;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* General rocket optimization dialog.
|
* General rocket optimization dialog.
|
||||||
*
|
*
|
||||||
@ -108,7 +108,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
|
|
||||||
private static final Collator collator = Collator.getInstance();
|
private static final Collator collator = Collator.getInstance();
|
||||||
|
|
||||||
|
|
||||||
private static final String GOAL_MAXIMIZE = trans.get("goal.maximize");
|
private static final String GOAL_MAXIMIZE = trans.get("goal.maximize");
|
||||||
private static final String GOAL_MINIMIZE = trans.get("goal.minimize");
|
private static final String GOAL_MINIMIZE = trans.get("goal.minimize");
|
||||||
private static final String GOAL_SEEK = trans.get("goal.seek");
|
private static final String GOAL_SEEK = trans.get("goal.seek");
|
||||||
@ -116,8 +115,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
private static final String START_TEXT = trans.get("btn.start");
|
private static final String START_TEXT = trans.get("btn.start");
|
||||||
private static final String STOP_TEXT = trans.get("btn.stop");
|
private static final String STOP_TEXT = trans.get("btn.stop");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private final List<OptimizableParameter> optimizationParameters = new ArrayList<OptimizableParameter>();
|
private final List<OptimizableParameter> optimizationParameters = new ArrayList<OptimizableParameter>();
|
||||||
private final Map<Object, List<SimulationModifier>> simulationModifiers =
|
private final Map<Object, List<SimulationModifier>> simulationModifiers =
|
||||||
new HashMap<Object, List<SimulationModifier>>();
|
new HashMap<Object, List<SimulationModifier>>();
|
||||||
@ -126,7 +123,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
private final OpenRocketDocument baseDocument;
|
private final OpenRocketDocument baseDocument;
|
||||||
private OpenRocketDocument documentCopy;
|
private OpenRocketDocument documentCopy;
|
||||||
|
|
||||||
|
|
||||||
private final JButton addButton;
|
private final JButton addButton;
|
||||||
private final JButton removeButton;
|
private final JButton removeButton;
|
||||||
private final JButton removeAllButton;
|
private final JButton removeAllButton;
|
||||||
@ -136,10 +132,10 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
private final DescriptionArea selectedModifierDescription;
|
private final DescriptionArea selectedModifierDescription;
|
||||||
private final SimulationModifierTree availableModifierTree;
|
private final SimulationModifierTree availableModifierTree;
|
||||||
|
|
||||||
private final JComboBox simulationSelectionCombo;
|
private final JComboBox<Object> simulationSelectionCombo;
|
||||||
private final JComboBox optimizationParameterCombo;
|
private final JComboBox<Object> optimizationParameterCombo;
|
||||||
|
|
||||||
private final JComboBox optimizationGoalCombo;
|
private final JComboBox<String> optimizationGoalCombo;
|
||||||
private final JSpinner optimizationGoalSpinner;
|
private final JSpinner optimizationGoalSpinner;
|
||||||
private final UnitSelector optimizationGoalUnitSelector;
|
private final UnitSelector optimizationGoalUnitSelector;
|
||||||
private final DoubleModel optimizationSeekValue;
|
private final DoubleModel optimizationSeekValue;
|
||||||
@ -177,7 +173,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
/** The optimization worker that is running */
|
/** The optimization worker that is running */
|
||||||
private OptimizationWorker worker = null;
|
private OptimizationWorker worker = null;
|
||||||
|
|
||||||
|
|
||||||
private double bestValue = Double.NaN;
|
private double bestValue = Double.NaN;
|
||||||
private Unit bestValueUnit = Unit.NOUNIT;
|
private Unit bestValueUnit = Unit.NOUNIT;
|
||||||
private int stepCount = 0;
|
private int stepCount = 0;
|
||||||
@ -187,10 +182,8 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
private final Map<Point, FunctionEvaluationData> evaluationHistory = new LinkedHashMap<Point, FunctionEvaluationData>();
|
private final Map<Point, FunctionEvaluationData> evaluationHistory = new LinkedHashMap<Point, FunctionEvaluationData>();
|
||||||
private final List<Point> optimizationPath = new LinkedList<Point>();
|
private final List<Point> optimizationPath = new LinkedList<Point>();
|
||||||
|
|
||||||
|
|
||||||
private boolean updating = false;
|
private boolean updating = false;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sole constructor.
|
* Sole constructor.
|
||||||
*
|
*
|
||||||
@ -213,7 +206,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
|
|
||||||
JPanel panel = new JPanel(new MigLayout("fill"));
|
JPanel panel = new JPanel(new MigLayout("fill"));
|
||||||
|
|
||||||
|
|
||||||
ChangeListener clearHistoryChangeListener = new ChangeListener() {
|
ChangeListener clearHistoryChangeListener = new ChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void stateChanged(ChangeEvent e) {
|
public void stateChanged(ChangeEvent e) {
|
||||||
@ -227,8 +219,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// // Selected modifiers table
|
// // Selected modifiers table
|
||||||
|
|
||||||
selectedModifierTableModel = new ParameterSelectionTableModel();
|
selectedModifierTableModel = new ParameterSelectionTableModel();
|
||||||
@ -237,6 +227,9 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
selectedModifierTable.setRowSelectionAllowed(true);
|
selectedModifierTable.setRowSelectionAllowed(true);
|
||||||
selectedModifierTable.setColumnSelectionAllowed(false);
|
selectedModifierTable.setColumnSelectionAllowed(false);
|
||||||
selectedModifierTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
selectedModifierTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||||
|
TableRowSorter<ParameterSelectionTableModel> sorter = new TableRowSorter<ParameterSelectionTableModel>(selectedModifierTableModel);
|
||||||
|
sorter.setComparator(0, new SimulationModifierComparator());
|
||||||
|
selectedModifierTable.setRowSorter( sorter );
|
||||||
|
|
||||||
// Make sure spinner editor fits into the cell height
|
// Make sure spinner editor fits into the cell height
|
||||||
selectedModifierTable.setRowHeight(new JSpinner().getPreferredSize().height - 4);
|
selectedModifierTable.setRowHeight(new JSpinner().getPreferredSize().height - 4);
|
||||||
@ -275,8 +268,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
disableComponents.add(selectedModifierDescription);
|
disableComponents.add(selectedModifierDescription);
|
||||||
panel.add(selectedModifierDescription, "growx");
|
panel.add(selectedModifierDescription, "growx");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// // Add/remove buttons
|
// // Add/remove buttons
|
||||||
sub = new JPanel(new MigLayout("fill"));
|
sub = new JPanel(new MigLayout("fill"));
|
||||||
|
|
||||||
@ -331,8 +322,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
|
|
||||||
panel.add(sub);
|
panel.add(sub);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// // Available modifier tree
|
// // Available modifier tree
|
||||||
availableModifierTree = new SimulationModifierTree(documentCopy.getRocket(), simulationModifiers, selectedModifiers);
|
availableModifierTree = new SimulationModifierTree(documentCopy.getRocket(), simulationModifiers, selectedModifiers);
|
||||||
availableModifierTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
|
availableModifierTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
|
||||||
@ -365,9 +354,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
panel.add(label, "split 2, flowy");
|
panel.add(label, "split 2, flowy");
|
||||||
panel.add(scroll, "width 300lp, height 200lp, grow, wrap para*2");
|
panel.add(scroll, "width 300lp, height 200lp, grow, wrap para*2");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// // Optimization options sub-panel
|
// // Optimization options sub-panel
|
||||||
|
|
||||||
sub = new JPanel(new MigLayout("fill"));
|
sub = new JPanel(new MigLayout("fill"));
|
||||||
@ -376,7 +362,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
sub.setBorder(border);
|
sub.setBorder(border);
|
||||||
disableComponents.add(sub);
|
disableComponents.add(sub);
|
||||||
|
|
||||||
|
|
||||||
// // Simulation to optimize
|
// // Simulation to optimize
|
||||||
|
|
||||||
label = new JLabel(trans.get("lbl.optimizeSim"));
|
label = new JLabel(trans.get("lbl.optimizeSim"));
|
||||||
@ -385,15 +370,13 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
disableComponents.add(label);
|
disableComponents.add(label);
|
||||||
sub.add(label, "");
|
sub.add(label, "");
|
||||||
|
|
||||||
simulationSelectionCombo = new JComboBox();
|
simulationSelectionCombo = new JComboBox<Object>();
|
||||||
simulationSelectionCombo.setToolTipText(tip);
|
simulationSelectionCombo.setToolTipText(tip);
|
||||||
populateSimulations();
|
populateSimulations();
|
||||||
simulationSelectionCombo.addActionListener(clearHistoryActionListener);
|
simulationSelectionCombo.addActionListener(clearHistoryActionListener);
|
||||||
disableComponents.add(simulationSelectionCombo);
|
disableComponents.add(simulationSelectionCombo);
|
||||||
sub.add(simulationSelectionCombo, "growx, wrap unrel");
|
sub.add(simulationSelectionCombo, "growx, wrap unrel");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// // Value to optimize
|
// // Value to optimize
|
||||||
label = new JLabel(trans.get("lbl.optimizeValue"));
|
label = new JLabel(trans.get("lbl.optimizeValue"));
|
||||||
tip = trans.get("lbl.optimizeValue.ttip");
|
tip = trans.get("lbl.optimizeValue.ttip");
|
||||||
@ -401,15 +384,13 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
disableComponents.add(label);
|
disableComponents.add(label);
|
||||||
sub.add(label, "");
|
sub.add(label, "");
|
||||||
|
|
||||||
optimizationParameterCombo = new JComboBox();
|
optimizationParameterCombo = new JComboBox<Object>();
|
||||||
optimizationParameterCombo.setToolTipText(tip);
|
optimizationParameterCombo.setToolTipText(tip);
|
||||||
populateParameters();
|
populateParameters();
|
||||||
optimizationParameterCombo.addActionListener(clearHistoryActionListener);
|
optimizationParameterCombo.addActionListener(clearHistoryActionListener);
|
||||||
disableComponents.add(optimizationParameterCombo);
|
disableComponents.add(optimizationParameterCombo);
|
||||||
sub.add(optimizationParameterCombo, "growx, wrap unrel");
|
sub.add(optimizationParameterCombo, "growx, wrap unrel");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// // Optimization goal
|
// // Optimization goal
|
||||||
label = new JLabel(trans.get("lbl.optimizeGoal"));
|
label = new JLabel(trans.get("lbl.optimizeGoal"));
|
||||||
tip = trans.get("lbl.optimizeGoal");
|
tip = trans.get("lbl.optimizeGoal");
|
||||||
@ -417,14 +398,13 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
disableComponents.add(label);
|
disableComponents.add(label);
|
||||||
sub.add(label, "");
|
sub.add(label, "");
|
||||||
|
|
||||||
optimizationGoalCombo = new JComboBox(new String[] { GOAL_MAXIMIZE, GOAL_MINIMIZE, GOAL_SEEK });
|
optimizationGoalCombo = new JComboBox<String>(new String[] { GOAL_MAXIMIZE, GOAL_MINIMIZE, GOAL_SEEK });
|
||||||
optimizationGoalCombo.setToolTipText(tip);
|
optimizationGoalCombo.setToolTipText(tip);
|
||||||
optimizationGoalCombo.setEditable(false);
|
optimizationGoalCombo.setEditable(false);
|
||||||
optimizationGoalCombo.addActionListener(clearHistoryActionListener);
|
optimizationGoalCombo.addActionListener(clearHistoryActionListener);
|
||||||
disableComponents.add(optimizationGoalCombo);
|
disableComponents.add(optimizationGoalCombo);
|
||||||
sub.add(optimizationGoalCombo, "growx");
|
sub.add(optimizationGoalCombo, "growx");
|
||||||
|
|
||||||
|
|
||||||
// // Optimization custom value
|
// // Optimization custom value
|
||||||
optimizationSeekValue = new DoubleModel(0, UnitGroup.UNITS_NONE);
|
optimizationSeekValue = new DoubleModel(0, UnitGroup.UNITS_NONE);
|
||||||
optimizationSeekValue.addChangeListener(clearHistoryChangeListener);
|
optimizationSeekValue.addChangeListener(clearHistoryChangeListener);
|
||||||
@ -441,11 +421,8 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
disableComponents.add(optimizationGoalUnitSelector);
|
disableComponents.add(optimizationGoalUnitSelector);
|
||||||
sub.add(optimizationGoalUnitSelector, "width 20lp, wrap unrel");
|
sub.add(optimizationGoalUnitSelector, "width 20lp, wrap unrel");
|
||||||
|
|
||||||
|
|
||||||
panel.add(sub, "grow");
|
panel.add(sub, "grow");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// // Required stability sub-panel
|
// // Required stability sub-panel
|
||||||
|
|
||||||
sub = new JPanel(new MigLayout("fill"));
|
sub = new JPanel(new MigLayout("fill"));
|
||||||
@ -454,15 +431,12 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
sub.setBorder(border);
|
sub.setBorder(border);
|
||||||
disableComponents.add(sub);
|
disableComponents.add(sub);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
double ref = CaliberUnit.calculateCaliber(baseDocument.getRocket());
|
double ref = CaliberUnit.calculateCaliber(baseDocument.getRocket());
|
||||||
minimumStability = new DoubleModel(ref, UnitGroup.stabilityUnits(ref));
|
minimumStability = new DoubleModel(ref, UnitGroup.stabilityUnits(ref));
|
||||||
maximumStability = new DoubleModel(5 * ref, UnitGroup.stabilityUnits(ref));
|
maximumStability = new DoubleModel(5 * ref, UnitGroup.stabilityUnits(ref));
|
||||||
minimumStability.addChangeListener(clearHistoryChangeListener);
|
minimumStability.addChangeListener(clearHistoryChangeListener);
|
||||||
maximumStability.addChangeListener(clearHistoryChangeListener);
|
maximumStability.addChangeListener(clearHistoryChangeListener);
|
||||||
|
|
||||||
|
|
||||||
// // Minimum stability
|
// // Minimum stability
|
||||||
tip = trans.get("lbl.requireMinStability.ttip");
|
tip = trans.get("lbl.requireMinStability.ttip");
|
||||||
minimumStabilitySelected = new JCheckBox(trans.get("lbl.requireMinStability"));
|
minimumStabilitySelected = new JCheckBox(trans.get("lbl.requireMinStability"));
|
||||||
@ -488,7 +462,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
disableComponents.add(minimumStabilityUnitSelector);
|
disableComponents.add(minimumStabilityUnitSelector);
|
||||||
sub.add(minimumStabilityUnitSelector, "growx, wrap unrel");
|
sub.add(minimumStabilityUnitSelector, "growx, wrap unrel");
|
||||||
|
|
||||||
|
|
||||||
// // Maximum stability
|
// // Maximum stability
|
||||||
tip = trans.get("lbl.requireMaxStability.ttip");
|
tip = trans.get("lbl.requireMaxStability.ttip");
|
||||||
maximumStabilitySelected = new JCheckBox(trans.get("lbl.requireMaxStability"));
|
maximumStabilitySelected = new JCheckBox(trans.get("lbl.requireMaxStability"));
|
||||||
@ -521,12 +494,8 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
// disableComponents.add(desc);
|
// disableComponents.add(desc);
|
||||||
// sub.add(desc, "span, growx");
|
// sub.add(desc, "span, growx");
|
||||||
|
|
||||||
|
|
||||||
panel.add(sub, "span 2, grow, wrap para*2");
|
panel.add(sub, "span 2, grow, wrap para*2");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// // Rocket figure
|
// // Rocket figure
|
||||||
figure = new RocketFigure(getSelectedSimulation().getConfiguration());
|
figure = new RocketFigure(getSelectedSimulation().getConfiguration());
|
||||||
figure.setBorderPixels(1, 1);
|
figure.setBorderPixels(1, 1);
|
||||||
@ -534,10 +503,8 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
figureScrollPane.setFitting(true);
|
figureScrollPane.setFitting(true);
|
||||||
panel.add(figureScrollPane, "span, split, height 200lp, grow");
|
panel.add(figureScrollPane, "span, split, height 200lp, grow");
|
||||||
|
|
||||||
|
|
||||||
sub = new JPanel(new MigLayout("fill"));
|
sub = new JPanel(new MigLayout("fill"));
|
||||||
|
|
||||||
|
|
||||||
label = new JLabel(trans.get("status.bestValue"));
|
label = new JLabel(trans.get("status.bestValue"));
|
||||||
tip = trans.get("status.bestValue.ttip");
|
tip = trans.get("status.bestValue.ttip");
|
||||||
label.setToolTipText(tip);
|
label.setToolTipText(tip);
|
||||||
@ -547,7 +514,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
bestValueLabel.setToolTipText(tip);
|
bestValueLabel.setToolTipText(tip);
|
||||||
sub.add(bestValueLabel, "wmin 60lp, wrap rel");
|
sub.add(bestValueLabel, "wmin 60lp, wrap rel");
|
||||||
|
|
||||||
|
|
||||||
label = new JLabel(trans.get("status.stepCount"));
|
label = new JLabel(trans.get("status.stepCount"));
|
||||||
tip = trans.get("status.stepCount.ttip");
|
tip = trans.get("status.stepCount.ttip");
|
||||||
label.setToolTipText(tip);
|
label.setToolTipText(tip);
|
||||||
@ -557,7 +523,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
stepCountLabel.setToolTipText(tip);
|
stepCountLabel.setToolTipText(tip);
|
||||||
sub.add(stepCountLabel, "wrap rel");
|
sub.add(stepCountLabel, "wrap rel");
|
||||||
|
|
||||||
|
|
||||||
label = new JLabel(trans.get("status.evalCount"));
|
label = new JLabel(trans.get("status.evalCount"));
|
||||||
tip = trans.get("status.evalCount.ttip");
|
tip = trans.get("status.evalCount.ttip");
|
||||||
label.setToolTipText(tip);
|
label.setToolTipText(tip);
|
||||||
@ -567,7 +532,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
evaluationCountLabel.setToolTipText(tip);
|
evaluationCountLabel.setToolTipText(tip);
|
||||||
sub.add(evaluationCountLabel, "wrap rel");
|
sub.add(evaluationCountLabel, "wrap rel");
|
||||||
|
|
||||||
|
|
||||||
label = new JLabel(trans.get("status.stepSize"));
|
label = new JLabel(trans.get("status.stepSize"));
|
||||||
tip = trans.get("status.stepSize.ttip");
|
tip = trans.get("status.stepSize.ttip");
|
||||||
label.setToolTipText(tip);
|
label.setToolTipText(tip);
|
||||||
@ -577,7 +541,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
stepSizeLabel.setToolTipText(tip);
|
stepSizeLabel.setToolTipText(tip);
|
||||||
sub.add(stepSizeLabel, "wrap para");
|
sub.add(stepSizeLabel, "wrap para");
|
||||||
|
|
||||||
|
|
||||||
// // Start/Stop button
|
// // Start/Stop button
|
||||||
|
|
||||||
startButton = new JToggleButton(START_TEXT);
|
startButton = new JToggleButton(START_TEXT);
|
||||||
@ -599,7 +562,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
});
|
});
|
||||||
sub.add(startButton, "span, growx, wrap para*2");
|
sub.add(startButton, "span, growx, wrap para*2");
|
||||||
|
|
||||||
|
|
||||||
plotButton = new JButton(trans.get("btn.plotPath"));
|
plotButton = new JButton(trans.get("btn.plotPath"));
|
||||||
plotButton.setToolTipText(trans.get("btn.plotPath.ttip"));
|
plotButton.setToolTipText(trans.get("btn.plotPath.ttip"));
|
||||||
plotButton.addActionListener(new ActionListener() {
|
plotButton.addActionListener(new ActionListener() {
|
||||||
@ -619,7 +581,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
disableComponents.add(plotButton);
|
disableComponents.add(plotButton);
|
||||||
sub.add(plotButton, "span, growx, wrap");
|
sub.add(plotButton, "span, growx, wrap");
|
||||||
|
|
||||||
|
|
||||||
saveButton = new JButton(trans.get("btn.save"));
|
saveButton = new JButton(trans.get("btn.save"));
|
||||||
saveButton.setToolTipText(trans.get("btn.save.ttip"));
|
saveButton.setToolTipText(trans.get("btn.save.ttip"));
|
||||||
saveButton.addActionListener(new ActionListener() {
|
saveButton.addActionListener(new ActionListener() {
|
||||||
@ -632,13 +593,8 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
disableComponents.add(saveButton);
|
disableComponents.add(saveButton);
|
||||||
sub.add(saveButton, "span, growx");
|
sub.add(saveButton, "span, growx");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
panel.add(sub, "wrap para*2");
|
panel.add(sub, "wrap para*2");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// // Bottom buttons
|
// // Bottom buttons
|
||||||
|
|
||||||
applyButton = new JButton(trans.get("btn.apply"));
|
applyButton = new JButton(trans.get("btn.apply"));
|
||||||
@ -677,21 +633,18 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
});
|
});
|
||||||
panel.add(closeButton, "right");
|
panel.add(closeButton, "right");
|
||||||
|
|
||||||
|
|
||||||
this.add(panel);
|
this.add(panel);
|
||||||
clearHistory();
|
clearHistory();
|
||||||
updateComponents();
|
updateComponents();
|
||||||
GUIUtil.setDisposableDialogOptions(this, null);
|
GUIUtil.setDisposableDialogOptions(this, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void startOptimization() {
|
private void startOptimization() {
|
||||||
if (running) {
|
if (running) {
|
||||||
log.info("Optimization already running");
|
log.info("Optimization already running");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (selectedModifiers.isEmpty()) {
|
if (selectedModifiers.isEmpty()) {
|
||||||
JOptionPane.showMessageDialog(this, trans.get("error.selectParams.text"),
|
JOptionPane.showMessageDialog(this, trans.get("error.selectParams.text"),
|
||||||
trans.get("error.selectParams.title"), JOptionPane.ERROR_MESSAGE);
|
trans.get("error.selectParams.title"), JOptionPane.ERROR_MESSAGE);
|
||||||
@ -702,7 +655,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
running = true;
|
running = true;
|
||||||
|
|
||||||
// Update the button status
|
// Update the button status
|
||||||
@ -761,7 +713,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
maxAbsolute = true;
|
maxAbsolute = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!minimumStabilitySelected.isSelected()) {
|
if (!minimumStabilitySelected.isSelected()) {
|
||||||
min = Double.NaN;
|
min = Double.NaN;
|
||||||
minAbsolute = maxAbsolute;
|
minAbsolute = maxAbsolute;
|
||||||
@ -862,7 +813,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
};
|
};
|
||||||
worker.start();
|
worker.start();
|
||||||
|
|
||||||
|
|
||||||
clearHistory();
|
clearHistory();
|
||||||
|
|
||||||
updateComponents();
|
updateComponents();
|
||||||
@ -889,13 +839,9 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
startButton.setText(START_TEXT);
|
startButton.setText(START_TEXT);
|
||||||
updating = false;
|
updating = false;
|
||||||
|
|
||||||
|
|
||||||
updateComponents();
|
updateComponents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset the current optimization history and values. This does not reset the design.
|
* Reset the current optimization history and values. This does not reset the design.
|
||||||
*/
|
*/
|
||||||
@ -911,7 +857,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
updateComponents();
|
updateComponents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void applyDesign() {
|
private void applyDesign() {
|
||||||
// TODO: MEDIUM: Apply also potential changes to simulations
|
// TODO: MEDIUM: Apply also potential changes to simulations
|
||||||
Rocket src = getSelectedSimulation().getRocket().copyWithOriginalID();
|
Rocket src = getSelectedSimulation().getRocket().copyWithOriginalID();
|
||||||
@ -938,7 +883,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void resetDesign() {
|
private void resetDesign() {
|
||||||
clearHistory();
|
clearHistory();
|
||||||
|
|
||||||
@ -969,7 +913,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
availableModifierTree.populateTree(documentCopy.getRocket(), simulationModifiers);
|
availableModifierTree.populateTree(documentCopy.getRocket(), simulationModifiers);
|
||||||
availableModifierTree.expandComponents();
|
availableModifierTree.expandComponents();
|
||||||
|
|
||||||
|
|
||||||
// Update selectable simulations
|
// Update selectable simulations
|
||||||
populateSimulations();
|
populateSimulations();
|
||||||
|
|
||||||
@ -978,7 +921,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void populateSimulations() {
|
private void populateSimulations() {
|
||||||
String current = null;
|
String current = null;
|
||||||
Object selection = simulationSelectionCombo.getSelectedItem();
|
Object selection = simulationSelectionCombo.getSelectedItem();
|
||||||
@ -986,7 +928,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
current = selection.toString();
|
current = selection.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
List<Named<Simulation>> simulations = new ArrayList<Named<Simulation>>();
|
List<Named<Simulation>> simulations = new ArrayList<Named<Simulation>>();
|
||||||
Rocket rocket = documentCopy.getRocket();
|
Rocket rocket = documentCopy.getRocket();
|
||||||
|
|
||||||
@ -1006,14 +947,13 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
simulations.add(new Named<Simulation>(sim, name));
|
simulations.add(new Named<Simulation>(sim, name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Simulation sim = new Simulation(rocket);
|
Simulation sim = new Simulation(rocket);
|
||||||
sim.getConfiguration().setFlightConfigurationID(null);
|
sim.getConfiguration().setFlightConfigurationID(null);
|
||||||
String name = createSimulationName(trans.get("noSimulationName"), rocket.getFlightConfigurationNameOrDescription(null));
|
String name = createSimulationName(trans.get("noSimulationName"), rocket.getFlightConfigurationNameOrDescription(null));
|
||||||
simulations.add(new Named<Simulation>(sim, name));
|
simulations.add(new Named<Simulation>(sim, name));
|
||||||
|
|
||||||
|
|
||||||
simulationSelectionCombo.setModel(new DefaultComboBoxModel(simulations.toArray()));
|
simulationSelectionCombo.setModel(new DefaultComboBoxModel<Object>(simulations.toArray()));
|
||||||
simulationSelectionCombo.setSelectedIndex(0);
|
simulationSelectionCombo.setSelectedIndex(0);
|
||||||
if (current != null) {
|
if (current != null) {
|
||||||
for (int i = 0; i < simulations.size(); i++) {
|
for (int i = 0; i < simulations.size(); i++) {
|
||||||
@ -1025,7 +965,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void populateParameters() {
|
private void populateParameters() {
|
||||||
String current = null;
|
String current = null;
|
||||||
Object selection = optimizationParameterCombo.getSelectedItem();
|
Object selection = optimizationParameterCombo.getSelectedItem();
|
||||||
@ -1041,7 +980,7 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
parameters.add(new Named<OptimizableParameter>(p, p.getName()));
|
parameters.add(new Named<OptimizableParameter>(p, p.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
optimizationParameterCombo.setModel(new DefaultComboBoxModel(parameters.toArray()));
|
optimizationParameterCombo.setModel(new DefaultComboBoxModel<Object>(parameters.toArray()));
|
||||||
|
|
||||||
for (int i = 0; i < parameters.size(); i++) {
|
for (int i = 0; i < parameters.size(); i++) {
|
||||||
if (parameters.get(i).toString().equals(current)) {
|
if (parameters.get(i).toString().equals(current)) {
|
||||||
@ -1058,7 +997,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
stepSizeLabel.setText(UnitGroup.UNITS_RELATIVE.toStringUnit(stepSize));
|
stepSizeLabel.setText(UnitGroup.UNITS_RELATIVE.toStringUnit(stepSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void loadOptimizationParameters() {
|
private void loadOptimizationParameters() {
|
||||||
optimizationParameters.clear();
|
optimizationParameters.clear();
|
||||||
optimizationParameters.addAll(OptimizationServiceHelper.getOptimizableParameters(documentCopy));
|
optimizationParameters.addAll(OptimizationServiceHelper.getOptimizableParameters(documentCopy));
|
||||||
@ -1075,7 +1013,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void loadSimulationModifiers() {
|
private void loadSimulationModifiers() {
|
||||||
simulationModifiers.clear();
|
simulationModifiers.clear();
|
||||||
|
|
||||||
@ -1101,13 +1038,10 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void addModifier(SimulationModifier mod) {
|
private void addModifier(SimulationModifier mod) {
|
||||||
if (!selectedModifiers.contains(mod)) {
|
if (!selectedModifiers.contains(mod)) {
|
||||||
log.user(1, "Adding simulation modifier " + mod);
|
log.user(1, "Adding simulation modifier " + mod);
|
||||||
selectedModifiers.add(mod);
|
selectedModifiers.add(mod);
|
||||||
Collections.sort(selectedModifiers, new SimulationModifierComparator());
|
|
||||||
selectedModifierTableModel.fireTableDataChanged();
|
selectedModifierTableModel.fireTableDataChanged();
|
||||||
availableModifierTree.repaint();
|
availableModifierTree.repaint();
|
||||||
} else {
|
} else {
|
||||||
@ -1115,7 +1049,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void removeModifier(SimulationModifier mod) {
|
private void removeModifier(SimulationModifier mod) {
|
||||||
log.user(1, "Removing simulation modifier " + mod);
|
log.user(1, "Removing simulation modifier " + mod);
|
||||||
selectedModifiers.remove(mod);
|
selectedModifiers.remove(mod);
|
||||||
@ -1123,8 +1056,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
availableModifierTree.repaint();
|
availableModifierTree.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the enabled status of all components in the dialog.
|
* Update the enabled status of all components in the dialog.
|
||||||
*/
|
*/
|
||||||
@ -1140,7 +1071,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
|
|
||||||
updating = true;
|
updating = true;
|
||||||
|
|
||||||
|
|
||||||
// First enable all components if optimization not running
|
// First enable all components if optimization not running
|
||||||
if (!running) {
|
if (!running) {
|
||||||
log.debug("Initially enabling all components");
|
log.debug("Initially enabling all components");
|
||||||
@ -1149,7 +1079,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// "Add" button
|
// "Add" button
|
||||||
SimulationModifier mod = getSelectedAvailableModifier();
|
SimulationModifier mod = getSelectedAvailableModifier();
|
||||||
state = (mod != null && !selectedModifiers.contains(mod));
|
state = (mod != null && !selectedModifiers.contains(mod));
|
||||||
@ -1166,7 +1095,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
log.debug("removeAllButton enabled: " + state);
|
log.debug("removeAllButton enabled: " + state);
|
||||||
removeAllButton.setEnabled(state);
|
removeAllButton.setEnabled(state);
|
||||||
|
|
||||||
|
|
||||||
// Optimization goal
|
// Optimization goal
|
||||||
String selected = (String) optimizationGoalCombo.getSelectedItem();
|
String selected = (String) optimizationGoalCombo.getSelectedItem();
|
||||||
state = GOAL_SEEK.equals(selected);
|
state = GOAL_SEEK.equals(selected);
|
||||||
@ -1174,7 +1102,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
optimizationGoalSpinner.setVisible(state);
|
optimizationGoalSpinner.setVisible(state);
|
||||||
optimizationGoalUnitSelector.setVisible(state);
|
optimizationGoalUnitSelector.setVisible(state);
|
||||||
|
|
||||||
|
|
||||||
// Minimum/maximum stability options
|
// Minimum/maximum stability options
|
||||||
state = minimumStabilitySelected.isSelected();
|
state = minimumStabilitySelected.isSelected();
|
||||||
log.debug("minimumStabilitySpinner & UnitSelector enabled: " + state);
|
log.debug("minimumStabilitySpinner & UnitSelector enabled: " + state);
|
||||||
@ -1186,7 +1113,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
maximumStabilitySpinner.setEnabled(state);
|
maximumStabilitySpinner.setEnabled(state);
|
||||||
maximumStabilityUnitSelector.setEnabled(state);
|
maximumStabilityUnitSelector.setEnabled(state);
|
||||||
|
|
||||||
|
|
||||||
// Plot button (enabled if path exists and dimensionality is 1 or 2)
|
// Plot button (enabled if path exists and dimensionality is 1 or 2)
|
||||||
state = (!optimizationPath.isEmpty() && (selectedModifiers.size() == 1 || selectedModifiers.size() == 2));
|
state = (!optimizationPath.isEmpty() && (selectedModifiers.size() == 1 || selectedModifiers.size() == 2));
|
||||||
log.debug("plotButton enabled: " + state + " optimizationPath.isEmpty=" + optimizationPath.isEmpty() +
|
log.debug("plotButton enabled: " + state + " optimizationPath.isEmpty=" + optimizationPath.isEmpty() +
|
||||||
@ -1198,7 +1124,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
log.debug("saveButton enabled: " + state);
|
log.debug("saveButton enabled: " + state);
|
||||||
saveButton.setEnabled(state);
|
saveButton.setEnabled(state);
|
||||||
|
|
||||||
|
|
||||||
// Last disable all components if optimization is running
|
// Last disable all components if optimization is running
|
||||||
if (running) {
|
if (running) {
|
||||||
log.debug("Disabling all components because optimization is running");
|
log.debug("Disabling all components because optimization is running");
|
||||||
@ -1207,7 +1132,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Update description text
|
// Update description text
|
||||||
mod = getSelectedModifier();
|
mod = getSelectedModifier();
|
||||||
if (mod != null) {
|
if (mod != null) {
|
||||||
@ -1216,14 +1140,12 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
selectedModifierDescription.setText("");
|
selectedModifierDescription.setText("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Update the figure
|
// Update the figure
|
||||||
figure.setConfiguration(getSelectedSimulation().getConfiguration());
|
figure.setConfiguration(getSelectedSimulation().getConfiguration());
|
||||||
|
|
||||||
updating = false;
|
updating = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void savePath() {
|
private void savePath() {
|
||||||
|
|
||||||
if (evaluationHistory.isEmpty()) {
|
if (evaluationHistory.isEmpty()) {
|
||||||
@ -1282,7 +1204,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
writer.write("\n");
|
writer.write("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (FunctionEvaluationData data : evaluationHistory.values()) {
|
for (FunctionEvaluationData data : evaluationHistory.values()) {
|
||||||
Value[] state = data.getState();
|
Value[] state = data.getState();
|
||||||
|
|
||||||
@ -1347,7 +1268,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
return ((Named<Simulation>) item).get();
|
return ((Named<Simulation>) item).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the currently selected simulation modifier from the table,
|
* Return the currently selected simulation modifier from the table,
|
||||||
* or <code>null</code> if none selected.
|
* or <code>null</code> if none selected.
|
||||||
@ -1362,7 +1282,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
return selectedModifiers.get(row);
|
return selectedModifiers.get(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the currently selected optimization parameter.
|
* Return the currently selected optimization parameter.
|
||||||
* @return the selected optimization parameter.
|
* @return the selected optimization parameter.
|
||||||
@ -1372,7 +1291,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
return ((Named<OptimizableParameter>) optimizationParameterCombo.getSelectedItem()).get();
|
return ((Named<OptimizableParameter>) optimizationParameterCombo.getSelectedItem()).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Unit getModifierUnit(int index) {
|
private Unit getModifierUnit(int index) {
|
||||||
return selectedModifiers.get(index).getUnitGroup().getDefaultUnit();
|
return selectedModifiers.get(index).getUnitGroup().getDefaultUnit();
|
||||||
}
|
}
|
||||||
@ -1524,7 +1442,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private class DoubleCellRenderer extends DefaultTableCellRenderer {
|
private class DoubleCellRenderer extends DefaultTableCellRenderer {
|
||||||
@Override
|
@Override
|
||||||
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
|
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
|
||||||
@ -1590,6 +1507,4 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user