algCheckBoxes = new EnumMap<SolverAlgorithm, JCheckBox>(SolverAlgorithm.class);
algTolerances = new EnumMap<SolverAlgorithm, JTextField>(SolverAlgorithm.class);
algToleranceLabels = new EnumMap<SolverAlgorithm, JLabel>(SolverAlgorithm.class);
int noOfExactAlgs = SolverAlgorithm.noOfExactAlgs();
for (int i = 0; i < SolverAlgorithm.closedValues().length; i++) {
SolverAlgorithm algo = SolverAlgorithm.closedValues()[i];
if (i == 0) {
JLabel label = new JLabel("--------- Exact ---------");
label.setMinimumSize(new Dimension(250, 0));
algPanel.add(label, BorderLayout.CENTER);
label.setForeground(Color.DARK_GRAY);
label.setFocusable(false);
JPanel placeholder = new JPanel();
placeholder.setFocusable(false);
algPanel.add(placeholder);
} else if (i == noOfExactAlgs) {
JLabel label = new JLabel("----- Approximate -----");
label.setMinimumSize(new Dimension(250, 0));
algPanel.add(label, BorderLayout.CENTER);
label.setForeground(Color.DARK_GRAY);
label.setFocusable(false);
JPanel placeholder = new JPanel();
placeholder.setFocusable(false);
algPanel.add(placeholder);
}
JCheckBox checkBox = new JCheckBox (algo.toString());
checkBox.setName(algo.toString());
final int index = i;
checkBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
AbstractButton abstractButton = (AbstractButton) e.getSource();
boolean selected = abstractButton.getModel().isSelected();
SolverAlgorithm algorithm = SolverAlgorithm.fromString(abstractButton.getName());
data.setWhatifAlgorithm(algorithm, selected);
}
});
algPanel.add(checkBox);
algCheckBoxes.put(algo,checkBox);
if (!algo.isExact()) {
Dimension d = new Dimension(70,30);
JLabel tolLabel = new JLabel("Tolerance: ");
tolLabel.setMaximumSize(d);
tolLabel.setFocusable(false);
d = new Dimension(90,30);
JTextField tolerance = new JTextField(30);
tolerance.setText(numFormat.format(SolverMultiClosedAMVA.DEFAULT_TOLERANCE));
tolerance.setMaximumSize(d);
tolerance.setName(algo.toString());
tolerance.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
JTextField textField = (JTextField) e.getSource();
Double tol = SolverMultiClosedAMVA.validateTolerance(textField.getText());
SolverAlgorithm algorithm = SolverAlgorithm.fromString(textField.getName());
if (tol != null) {
data.setWhatifAlgorithmTolerance(algorithm, tol);
}
else {
JOptionPane.showMessageDialog(WhatIfPanel.this, "Error: Invalid tolerance value. Using last valid value.", "Input data error", JOptionPane.ERROR_MESSAGE);
}
}
@Override
public void focusGained(FocusEvent e) {
}
});
tolerance.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
JTextField textField = (JTextField) e.getSource();
SolverAlgorithm algorithm = SolverAlgorithm.fromString(textField.getName());
Double tol = SolverMultiClosedAMVA.validateTolerance(textField.getText());
if (tol != null) {
data.setWhatifAlgorithmTolerance(algorithm, tol);
}
else {