-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSliderPanel.java
73 lines (56 loc) · 2.31 KB
/
SliderPanel.java
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
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import java.awt.Dimension;
import java.awt.Color;
class SliderPanel extends JPanel{
static final int SCREEN_WIDTH = 800;
static final int SCREEN_HEIGHT = 600;
private Slider alignmentMultiplier;
private Slider cohesionMultiplier;
private Slider separationMultiplier;
// TODO:
// to change perception (they all start at Boid.PERCEPTION_DISTANCE)
// private float align_perception_multiplier = 1;
// private float cohesion_perception_multiplier = 1;
// private float separation_perception_multiplier = 1;
SliderPanel() {
this.setPreferredSize(new Dimension(SCREEN_WIDTH, SCREEN_HEIGHT)); // set window size
this.setBackground(Color.black);
this.setDoubleBuffered(true); // all drawing from this component will be done in an offscreen painting buffer -> improves performance
this.requestFocusInWindow();
// this.setFocusable(true); // to use keyAdapter
// this.addKeyListener(new MyKeyAdapter());
this.alignmentMultiplier = new Slider(JSlider.HORIZONTAL, 0, 500, 100, "alignment");
this.add(this.alignmentMultiplier);
this.cohesionMultiplier = new Slider(JSlider.HORIZONTAL, 0, 500, 100, "cohesion");
this.add(this.cohesionMultiplier);
this.separationMultiplier = new Slider(JSlider.HORIZONTAL, 0, 500, 100, "separation");
this.add(this.separationMultiplier);
}
public void reset() {
// set all slider at starting val
alignmentMultiplier.setValue(100);
cohesionMultiplier.setValue(100);
separationMultiplier.setValue(100);
}
public float getAlignmentMult() {
return (float)alignmentMultiplier.getValue() / 100; // in percent
}
public float getCohesionMult() {
return (float)cohesionMultiplier.getValue() / 100;
}
public float getSeparationMult() {
return (float)separationMultiplier.getValue() / 100;
}
}
class Slider extends JSlider {
Slider(int orientation, int min, int max, int startVal, String tooltip) {
super(orientation, min, max, startVal);
setToolTipText(tooltip);
setMajorTickSpacing(100);
setMinorTickSpacing(1);
setPaintTicks(true);
setPaintLabels(true);
}
}