Commit c646d62a authored by h2b's avatar h2b

Documentation added. API refined.

parent 2c8c2263
......@@ -66,6 +66,14 @@ It contains a `Cell` (a rectangular area) and a `GridLayout` of cells organized
Various factory methods are provided that construct grid layouts from a sample cell, within a cell or on the whole screen.
## Events
Since version 1.2.0 an event package is available that constitutes a high-level abstraction of input (e.g., keyboard or mouse) events.
Such events, if triggered by the drivers, are published to the global event stream of that package and can be retrieved by subscribing to its `stream` object.
To get the triggering enabled, the `withEvents` factory methods of `World` or `Screen` have to be used.
## API
See [Scaladoc](http://hans-hermann-bode.de/sites/default/files/sites/simgraf/scaladocs/de/h2b/scala/lib/simgraf/index.html).
......
......@@ -25,6 +25,9 @@ import de.h2b.scala.lib.simgraf.Pixel
import javax.swing.SwingUtilities
/**
* Provides key and mouse listeners publishing key and mouse events to the
* event-package publisher.
*
* @since 1.2.0
* @author h2b
*/
......
......@@ -34,6 +34,11 @@ import javax.swing.{ JFrame, JMenu, JMenuBar, JMenuItem, JPanel, WindowConstants
/**
* Screen-driver implementation trait based on AWT (and some Swing).
*
* Provides hooks for key and mouse listeners that can be overridden by
* implementations. By default, no such listeners are enabled.
*
* Also provides a file menu with save item as bonus functionality.
*
* @author h2b
*/
trait AwtScreenDriver extends ScreenDriver {
......
......@@ -18,6 +18,8 @@
package de.h2b.scala.lib.simgraf.event
/**
* Sealed trait of mouse buttons.
*
* @since 1.2.0
* @author h2b
*/
......
......@@ -20,6 +20,8 @@ package de.h2b.scala.lib.simgraf.event
import de.h2b.scala.lib.simgraf.Pixel
/**
* Sealed trait of input events.
*
* @since 1.2.0
* @author h2b
*/
......@@ -27,5 +29,11 @@ sealed trait Event
case class KeyEvent (char: Char) extends Event
/**
* @constructor
*
* @param position the position of this mouse event in coordinates of the
* related screen
*/
case class MouseEvent (button: Button, modifiers: Set[Modifier], clickCount: Int,
position: Pixel) extends Event
......@@ -18,6 +18,8 @@
package de.h2b.scala.lib.simgraf.event
/**
* Sealed trait of keyboard-modifier keys.
*
* @since 1.2.0
* @author h2b
*/
......
......@@ -18,15 +18,22 @@
package de.h2b.scala.lib.simgraf.event
import akka.actor.Actor
import de.h2b.scala.lib.util.Logger
/**
* Provides an actor publishing `Event`s to the package object's global event
* stream.
*
* @since 1.2.0
* @author h2b
*/
class Publisher extends Actor {
private val log = Logger(getClass)
def receive = {
case e: Event context.system.eventStream.publish(e)
case e: Event stream.publish(e)
case unknown log.warn(s"unknown message received: $unknown")
}
}
......@@ -18,15 +18,33 @@
package de.h2b.scala.lib.simgraf
import akka.actor.{ ActorSystem, Props }
import de.h2b.scala.lib.simgraf.event.Publisher
/**
* This package constitutes a high-level abstraction of input (e.g., keyboard
* or mouse) events.
*
* Such events, if triggered by the drivers, are published to the global
* event stream of this package and can be retrieved by subscribing to the
* `stream` object.
*
* @since 1.2.0
* @author h2b
*/
package object event {
private val system = ActorSystem("SimGraf")
/**
* The actor publishing all events to the global event stream that are
* triggered by drivers.
*/
private[simgraf] val publisher = system.actorOf(Props[Publisher])
/**
* The event stream global to this package.
*
* Subscribe to this stream to retrieve triggered events.
*/
val stream = system.eventStream
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment