blob: 29f8e1f9e7aaa5a8c09d3108b99cb2460909de02 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
package jcgp.gui.settings.parameters;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Control;
import jcgp.backend.parameters.BooleanParameter;
import jcgp.backend.parameters.ParameterStatus;
import jcgp.gui.settings.SettingsPane;
/**
* This extension of @code{GUIParameter} uses a @code{CheckBox} to display
* the value of a @code{BooleanParameter}. It cannot be constructed
* directly - instead, use @code{GUIParameter.create()}.
* <br><br>
* See {@link GUIParameter} for more information.
*
* @author Eduardo Pedroni
*/
public class GUIBooleanParameter extends GUIParameter<Boolean> {
private CheckBox checkBox;
/**
* This default-visibility constructor is intended for use
* by the factory method only.
*
*/
GUIBooleanParameter(final BooleanParameter parameter, final SettingsPane sp) {
super(parameter, sp);
}
@Override
protected Control makeControl() {
checkBox = new CheckBox();
checkBox.setSelected(parameter.get());
return checkBox;
}
@Override
protected void setControlListeners() {
/* pass the CheckBox value back to the parameter whenever it gets
* modified, provided the experiment isn't running */
checkBox.selectedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(
ObservableValue<? extends Boolean> observable,
Boolean oldValue, Boolean newValue) {
if (!settingsPane.isExperimentRunning()) {
parameter.set(newValue);
settingsPane.revalidateParameters();
}
}
});
}
@Override
protected void setValidityStyle() {
// update the Control's style and tooltip based on the status of the parameter
if (parameter.getStatus() == ParameterStatus.INVALID) {
checkBox.setStyle(BASE_CHECKBOX_STYLE + INVALID_PARAMETER_STYLE);
checkBox.setTooltip(tooltip);
tooltip.setText(parameter.getStatus().getDetails());
} else if (parameter.getStatus() == ParameterStatus.WARNING
|| parameter.getStatus() == ParameterStatus.WARNING_RESET) {
checkBox.setStyle(BASE_CHECKBOX_STYLE + WARNING_PARAMETER_STYLE);
checkBox.setTooltip(tooltip);
tooltip.setText(parameter.getStatus().getDetails());
} else {
checkBox.setStyle(BASE_CHECKBOX_STYLE + VALID_PARAMETER_STYLE);
checkBox.setTooltip(null);
}
}
@Override
public void refreshValue() {
checkBox.setSelected(parameter.get());
}
}
|