[#1781] Support multi-component parameter additions
This commit is contained in:
parent
be0457e980
commit
1702a28d62
@ -17,6 +17,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -264,9 +265,9 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
addButton = new SelectColorButton(Chars.LEFT_ARROW + " " + trans.get("btn.add") + " ");
|
addButton = new SelectColorButton(Chars.LEFT_ARROW + " " + trans.get("btn.add") + " ");
|
||||||
addButton.setToolTipText(trans.get("btn.add.ttip"));
|
addButton.setToolTipText(trans.get("btn.add.ttip"));
|
||||||
addButton.addActionListener(e -> {
|
addButton.addActionListener(e -> {
|
||||||
SimulationModifier mod = getSelectedAvailableModifier();
|
List<SimulationModifier> mods = getSelectedAvailableModifiers();
|
||||||
if (mod != null) {
|
if (mods.size() > 0) {
|
||||||
addModifier(mod);
|
addModifiers(mods);
|
||||||
clearHistory();
|
clearHistory();
|
||||||
} else {
|
} else {
|
||||||
log.error("Attempting to add simulation modifier when none is selected");
|
log.error("Attempting to add simulation modifier when none is selected");
|
||||||
@ -328,9 +329,9 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
@Override
|
@Override
|
||||||
public void mousePressed(MouseEvent e) {
|
public void mousePressed(MouseEvent e) {
|
||||||
if (e.getClickCount() == 2) {
|
if (e.getClickCount() == 2) {
|
||||||
SimulationModifier mod = getSelectedAvailableModifier();
|
List<SimulationModifier> mods = getSelectedAvailableModifiers();
|
||||||
if (mod != null) {
|
if (mods.size() == 1) {
|
||||||
addModifier(mod);
|
addModifiers(mods);
|
||||||
clearHistory();
|
clearHistory();
|
||||||
} else {
|
} else {
|
||||||
log.info(Markers.USER_MARKER, "Double-clicked non-available option");
|
log.info(Markers.USER_MARKER, "Double-clicked non-available option");
|
||||||
@ -1027,15 +1028,20 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addModifier(SimulationModifier mod) {
|
private void addModifiers(List<SimulationModifier> mods) {
|
||||||
if (!selectedModifiers.contains(mod)) {
|
if (mods == null || mods.size() == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (SimulationModifier mod : mods) {
|
||||||
|
if (selectedModifiers.contains(mod)) {
|
||||||
|
log.info(Markers.USER_MARKER, "Attempting to add an already existing simulation modifier " + mod);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
log.info(Markers.USER_MARKER, "Adding simulation modifier " + mod);
|
log.info(Markers.USER_MARKER, "Adding simulation modifier " + mod);
|
||||||
selectedModifiers.add(mod);
|
selectedModifiers.add(mod);
|
||||||
selectedModifierTableModel.fireTableDataChanged();
|
|
||||||
availableModifierTree.repaint();
|
|
||||||
} else {
|
|
||||||
log.info(Markers.USER_MARKER, "Attempting to add an already existing simulation modifier " + mod);
|
|
||||||
}
|
}
|
||||||
|
selectedModifierTableModel.fireTableDataChanged();
|
||||||
|
availableModifierTree.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeModifier(SimulationModifier mod) {
|
private void removeModifier(SimulationModifier mod) {
|
||||||
@ -1069,8 +1075,8 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// "Add" button
|
// "Add" button
|
||||||
SimulationModifier mod = getSelectedAvailableModifier();
|
List<SimulationModifier> mods = getSelectedAvailableModifiers();
|
||||||
state = (mod != null && !selectedModifiers.contains(mod));
|
state = (mods.size() > 0 && !new HashSet<>(selectedModifiers).containsAll(mods));
|
||||||
log.debug("addButton enabled: " + state);
|
log.debug("addButton enabled: " + state);
|
||||||
addButton.setEnabled(state);
|
addButton.setEnabled(state);
|
||||||
|
|
||||||
@ -1122,9 +1128,9 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update description text
|
// Update description text
|
||||||
mod = getSelectedModifier();
|
SimulationModifier selectedMod = getSelectedModifier();
|
||||||
if (mod != null) {
|
if (selectedMod != null) {
|
||||||
selectedModifierDescription.setText(mod.getDescription());
|
selectedModifierDescription.setText(selectedMod.getDescription());
|
||||||
} else {
|
} else {
|
||||||
selectedModifierDescription.setText("");
|
selectedModifierDescription.setText("");
|
||||||
}
|
}
|
||||||
@ -1221,18 +1227,20 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the currently selected available simulation modifier from the modifier tree,
|
* Return the currently selected available simulation modifier from the modifier tree.
|
||||||
* or <code>null</code> if none selected.
|
|
||||||
*/
|
*/
|
||||||
private SimulationModifier getSelectedAvailableModifier() {
|
private List<SimulationModifier> getSelectedAvailableModifiers() {
|
||||||
TreePath treepath = availableModifierTree.getSelectionPath();
|
List<SimulationModifier> result = new ArrayList<>();
|
||||||
if (treepath != null) {
|
TreePath[] treepaths = availableModifierTree.getSelectionPaths();
|
||||||
Object o = ((DefaultMutableTreeNode) treepath.getLastPathComponent()).getUserObject();
|
if (treepaths != null) {
|
||||||
if (o instanceof SimulationModifier) {
|
for (TreePath treepath : treepaths) {
|
||||||
return (SimulationModifier) o;
|
Object obj = ((DefaultMutableTreeNode) treepath.getLastPathComponent()).getUserObject();
|
||||||
|
if (obj instanceof SimulationModifier) {
|
||||||
|
result.add((SimulationModifier) obj);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user