blob: bdf52455fe2a451ce14a495267b0627760dff0d4 (
plain) (
blame)
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
|
/*
* Graphyx
* copyright (c) 2009 Jakob Odersky
* made available under the MIT License
*/
package graphyx.gui
import scala.swing._
import scala.swing.event._
import scala.swing.GridBagPanel._
import sims.geometry._
class GravityPanel(container: Container) extends GridBagPanel{
val c = new Constraints
c.fill = Fill.Both
this.border = Swing.EmptyBorder(3,3,3,3)
val sldX = new Slider {max = 500; min = -500; preferredSize = minimumSize}
val lblX = new Label("0.0")
val sldY = new Slider {max = 500; min = -500; preferredSize = minimumSize}
val lblY = new Label("-9.81")
c.gridx = 0
c.gridy = 0
c.weightx = 1.0
c.weighty = 0.0
super.add(new Label("Gravity"), c)
c.gridx = 0
c.gridy = 1
c.weightx = 1.0
c.weighty = 0.0
super.add(new Label("X: "), c)
c.gridx = 1
c.gridy = 1
c.weightx = 1.0
c.weighty = 0.0
super.add(sldX, c)
c.gridx = 2
c.gridy = 1
c.weightx = 0.0
c.weighty = 0.0
super.add(lblX, c)
c.gridx = 0
c.gridy = 2
c.weightx = 1.0
c.weighty = 0.0
super.add(new Label("Y: "), c)
c.gridx = 1
c.gridy = 2
c.weightx = 1.0
c.weighty = 0.0
super.add(sldY, c)
c.gridx = 2
c.gridy = 2
c.weightx = 0.0
c.weighty = 0.0
super.add(lblY, c)
listenTo(sldX, sldY)
reactions += {
case ValueChanged(s) if (s == sldX || s == sldY) =>
container.scene.real.gravity = Vector2D(sldX.value / 10.0, sldY.value / 10.0)
}
def update() = {
val g = container.scene.world.gravity
sldX.value = (g.x * 10).toInt
lblX.text = ((g.x * 10).toInt / 10.0).toString
sldY.value = (g.y * 10).toInt
lblY.text = ((g.y * 10).toInt / 10.0).toString
}
}
|