-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path116.java
More file actions
153 lines (135 loc) · 4.83 KB
/
Copy path116.java
File metadata and controls
153 lines (135 loc) · 4.83 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package org.newdawn.slick.tools.peditor;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.HashMap;
import javax.swing.BorderFactory;
import javax.swing.JCheckBox;
import org.newdawn.slick.particles.ConfigurableEmitter;
import org.newdawn.slick.particles.ConfigurableEmitter.LinearInterpolator;
/**
* A panel to display the whiskas controls within pedigree GUI
*
* @author void
*/
public class WhiskasPanel extends ControlPanel {
/** The window used to configure the linear interpolation graphs */
private GraphEditorWindow editor;
/** The offset into the panel */
private int offset = 25;
/** key: control, value: name of value */
private HashMap controlToValueName = new HashMap();
/** key: value name, value: control */
private HashMap valueNameToControl = new HashMap();
/** key: name, value: emitter value */
private HashMap valueMap = new HashMap();
/**
* Create a new panel for limiting controls
*
* @param l The list to be notified when the name changes
* @param colorPanel The panel controlling the colours that needs to be controlled based on the enablement here
* @param emissionControls The panel controlling the emissions that needs to be controlled based on the enablement here
*/
public WhiskasPanel(EmitterList l, final ColorPanel colorPanel,
final EmissionControls emissionControls) {
setLayout(null);
setBorder(BorderFactory
.createTitledBorder("Particle Life Time Gradients"));
// add checkbox controls for all linear values
addEnableControl("Alpha", new ItemListener() {
public void itemStateChanged(ItemEvent e) {
colorPanel.getStartAlpha().setEnabled(
e.getStateChange() != ItemEvent.SELECTED);
colorPanel.getEndAlpha().setEnabled(
e.getStateChange() != ItemEvent.SELECTED);
itemStateChangedHandler(e);
}
});
addEnableControl("Size", new ItemListener() {
public void itemStateChanged(ItemEvent e) {
emissionControls.getInitialSize().setEnabledForced(
e.getStateChange() != ItemEvent.SELECTED);
itemStateChangedHandler(e);
}
});
addEnableControl("Velocity", new ItemListener() {
public void itemStateChanged(ItemEvent e) {
itemStateChangedHandler(e);
}
});
addEnableControl("ScaleY", new ItemListener() {
public void itemStateChanged(ItemEvent e) {
itemStateChangedHandler(e);
}
});
}
/**
* Add a control for enablement
*
* @param text The label to be associated with the check box
* @param listener The listener to be notified of updates to the new control
*/
private void addEnableControl(String text, ItemListener listener) {
JCheckBox enableControl = new JCheckBox("Enable " + text);
enableControl.setBounds(10, offset, 200, 20);
enableControl.addItemListener(listener);
add(enableControl);
controlToValueName.put(enableControl, text);
valueNameToControl.put(text, enableControl);
offset += 25;
}
/**
* Notificaiton that one of the configuration option has changed state
*
* @param e The event describing the change of state
*/
public void itemStateChangedHandler(ItemEvent e) {
String valueName = (String) controlToValueName.get(e.getSource());
LinearInterpolator value = (LinearInterpolator) valueMap.get(valueName);
if (e.getStateChange() == ItemEvent.SELECTED) {
value.setActive(true);
editor.registerValue(value, valueName);
} else {
value.setActive(false);
editor.removeValue(valueName);
}
}
/**
* Links this whiskas panel to the given editor
*
* @param editor The particle editor in use
*/
public void setEditor(GraphEditorWindow editor) {
this.editor = editor;
}
/**
* @see org.newdawn.slick.tools.peditor.ControlPanel#linkEmitterToFields(org.newdawn.slick.particles.ConfigurableEmitter)
*/
protected void linkEmitterToFields(ConfigurableEmitter emitter) {
this.emitter = emitter;
// register the new emitter
editor.setLinkedEmitter(emitter);
valueMap.clear();
linkToEmitter("Alpha", emitter.alpha);
linkToEmitter("Size", emitter.size);
linkToEmitter("Velocity", emitter.velocity);
linkToEmitter("ScaleY", emitter.scaleY);
editor.setFirstProperty();
}
/**
* Link this set of controls to a linear interpolater within the particle emitter
*
* @param name The name of the article emitter being linked
* @param interpol The interpolator being configured
*/
private void linkToEmitter(String name, LinearInterpolator interpol) {
// put to value map
valueMap.put(name, interpol);
// now update the checkbox to represent the state of the given
// interpolator
boolean checked = interpol.isActive();
JCheckBox enableControl = (JCheckBox) valueNameToControl.get(name);
enableControl.setSelected(false);
if (checked)
enableControl.setSelected(checked);
}
}