-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui_parameter_ParameterControl.pde
65 lines (57 loc) · 2.12 KB
/
gui_parameter_ParameterControl.pde
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
/**
* Base class for a dynamically generated GUI control.
*/
public abstract class ParameterControl {
private String labelText;
private Object obj;
private Field updateField;
private GLabel label;
/**
* Creates a ParameterControl.
* @param labelText the text displayed beside the control.
* @param obj the object that contains the field to be controlled.
* @param fieldName the name of the field on the object that this should control.
*/
ParameterControl(String labelText, Object obj, String fieldName) {
this.labelText = labelText;
this.obj = obj;
try {
// Tries to find the Field specified by fieldName.
this.updateField = obj.getClass().getField(fieldName);
}
catch (ReflectiveOperationException e) {
System.err.println(e.getClass().getSimpleName() + ": " + e.getMessage());
}
}
/** Sets the field on the object specified at creation to a new value. */
public void updateValue(Object value) {
try {
this.updateField.set(this.obj, value);
}
catch (ReflectiveOperationException e) {
System.err.println(e.getClass().getSimpleName() + ": " + e.getMessage());
}
// (Delayed) re-render the scene.
tweaker.update();
}
protected void createLabel(GWindow window, int x, int y) {
createLabel(window, x, y, 100);
}
protected void createLabel(GWindow window, int x, int y, int labelWidth) {
this.label = new GLabel(window, x, y, labelWidth, 20);
this.label.setTextAlign(GAlign.LEFT, GAlign.MIDDLE);
this.label.setText(this.labelText);
this.label.setOpaque(false);
}
public void setVisible(boolean visible) {
this.label.setVisible(visible);
}
/**
* Creates and draws the G4P GUI elements on the window.
* @param window the window to draw the GUI elements on.
* @param x the x position within the window for the left edge of the GUI elements.
* @param y the y position within the window for the top edge of the GUI elements.
* @return the vertical height of the GUI elements drawn, in number of pixels.
*/
abstract int createGUIControls(GWindow window, int x, int y);
}