diff options
author | Ingo Maier <ingo.maier@epfl.ch> | 2009-04-14 08:24:47 +0000 |
---|---|---|
committer | Ingo Maier <ingo.maier@epfl.ch> | 2009-04-14 08:24:47 +0000 |
commit | 2fd666669012fafdc6acbdbd06a36cd91c3a74e2 (patch) | |
tree | be1d7db9daaef1677d6fdd059f52de8826ce321c /src/swing | |
parent | 8c997bd38cdb07d92e0bee03cd84132ff1918d34 (diff) | |
download | scala-2fd666669012fafdc6acbdbd06a36cd91c3a74e2.tar.gz scala-2fd666669012fafdc6acbdbd06a36cd91c3a74e2.tar.bz2 scala-2fd666669012fafdc6acbdbd06a36cd91c3a74e2.zip |
added painting demo by Frank Teubler
Diffstat (limited to 'src/swing')
-rw-r--r-- | src/swing/scala/swing/test/LinePainting.scala | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/swing/scala/swing/test/LinePainting.scala b/src/swing/scala/swing/test/LinePainting.scala new file mode 100644 index 0000000000..f21b8f6522 --- /dev/null +++ b/src/swing/scala/swing/test/LinePainting.scala @@ -0,0 +1,43 @@ +package scala.swing.test +import scala.swing.Swing._ +import scala.swing.{MainFrame, Panel, SimpleGUIApplication} +import scala.swing.event.{MousePressed, MouseDragged, MouseReleased} +import java.awt.{Color, Dimension, Graphics, Graphics2D, Point, geom} + +/** + * Dragging the mouse draws a simple graph + * + * @author Frank Teubler + */ +object LinePainting extends SimpleGUIApplication { + def top = new MainFrame { + title = "SimpleDraw" + contents = new Panel { + background = Color.white + preferredSize = (200,200) + + listenTo(Mouse.clicks, Mouse.moves) + + reactions += { + case e: MousePressed => moveTo(e.point) + case e: MouseDragged => lineTo(e.point) + case e: MouseReleased => lineTo(e.point) + } + + /* records the dragging */ + val path = new geom.GeneralPath + + def lineTo(p:Point) { path.lineTo(p.x, p.y); repaint() } + def moveTo(p:Point) { path.moveTo(p.x, p.y); repaint() } + + override def paintComponent(g:Graphics) = { + super.paintComponent(g) + /* we need Graphics2D */ + val g2 = g.asInstanceOf[Graphics2D] + g2.draw(path) + } + } + } +} + + |