diff options
Diffstat (limited to 'src/main/scala/graphyx/gui/GravityPanel.scala')
-rw-r--r-- | src/main/scala/graphyx/gui/GravityPanel.scala | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/main/scala/graphyx/gui/GravityPanel.scala b/src/main/scala/graphyx/gui/GravityPanel.scala new file mode 100644 index 0000000..bdf5245 --- /dev/null +++ b/src/main/scala/graphyx/gui/GravityPanel.scala @@ -0,0 +1,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 + } + +} |