Commit fba54458 authored by h2b's avatar h2b

Close operation added to screen driver.

parent 683aa515
......@@ -18,8 +18,8 @@
package de.h2b.scala.lib.simgraf.driver
import java.awt.{ Color => AwtColor, Dimension, FileDialog, Frame, Graphics,
GraphicsEnvironment, Rectangle, RenderingHints }
import java.awt.event.{ ActionEvent, ActionListener, KeyListener, MouseListener }
GraphicsEnvironment, Rectangle, RenderingHints }
import java.awt.event.{ ActionEvent, ActionListener, WindowEvent }
import java.awt.image.BufferedImage
import java.io.{ File, IOException }
......@@ -29,7 +29,8 @@ import de.h2b.scala.lib.simgraf.{ Color, Pixel }
import de.h2b.scala.lib.util.{ Level, Logger }
import de.h2b.scala.lib.util.config.BundleConfig
import javax.imageio.ImageIO
import javax.swing.{ JFrame, JMenu, JMenuBar, JMenuItem, JPanel, WindowConstants }
import javax.swing.{ JFrame, JMenu, JMenuBar, JMenuItem, JPanel,
WindowConstants }
/**
* Screen-driver implementation trait based on AWT (and some Swing).
......@@ -176,6 +177,11 @@ trait AwtScreenDriver extends ScreenDriver {
panel.repaint()
}
def close (): Unit = {
val closing = new WindowEvent(frame, WindowEvent.WINDOW_CLOSING)
frame.dispatchEvent(closing)
}
//bonus functionality, not required by super class
private class FileMenu (val parent: Frame) extends ActionListener {
......
......@@ -156,6 +156,16 @@ abstract class ScreenDriver protected (val p0: Pixel, val width: Int, val height
*/
def drawText (p0: Pixel, text: String): Unit
/**
* Closes the screen this driver is associated to.
*
* @note Might not have an effect if the underlying implementation does not
* support such an operation.
*
* @since 1.3.0
*/
def close (): Unit
/**
* Helper function for systems with origin at upper-left corner.
*
......
......@@ -17,10 +17,8 @@
*/
package de.h2b.scala.lib.simgraf.demo
import scala.util.Random
import de.h2b.scala.lib.simgraf.{ Color, Point, World }
import de.h2b.scala.lib.simgraf.event.{ Event, Subscriber }
import de.h2b.scala.lib.simgraf.event.{ Event, KeyEvent, Subscriber, system }
import de.h2b.scala.lib.simgraf.layout.GridLayout
import de.h2b.scala.lib.simgraf.shapes.{ Coloring, Rectangle }
......@@ -38,7 +36,11 @@ object EventEchoDemo extends App {
case _ Color.Red
}))
Subscriber.ref {
case e: Event println(e)
case KeyEvent(k) if k=='q'
world.screen.close()
system.terminate()
case e: Event
println(e)
}
}
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