diff --git a/project/Build.scala b/project/Build.scala index 0a4e566..9806741 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -198,6 +198,15 @@ object Eclipse { } object Dependencies { + /* ********************************************************************** */ + /* Akka */ + /* ********************************************************************** */ + final val akkaVersion = "2.4.4" + + val akkaActor = "com.typesafe.akka" %% "akka-actor" % akkaVersion + val akkaAgent = "com.typesafe.akka" %% "akka-agent" % akkaVersion + val akkaStream = "com.typesafe.akka" %% "akka-stream" % akkaVersion + /* ********************************************************************** */ /* Utility Dependencies */ /* ********************************************************************** */ @@ -319,6 +328,13 @@ object UtilsBuild extends Build { shapeless ), + /* Akka dependencies */ + libraryDependencies ++= Seq ( + akkaActor % "optional", + akkaStream % "optional", + akkaAgent % "optional" + ), + unmanagedJars in Compile += Attributed.blank(file(System.getenv("JAVA_HOME") + "/jre/lib/ext/jfxrt.jar")) ) } diff --git a/src/main/scala/org/gerweck/scalafx/akka/AkkaFX.scala b/src/main/scala/org/gerweck/scalafx/akka/AkkaFX.scala new file mode 100644 index 0000000..8d48979 --- /dev/null +++ b/src/main/scala/org/gerweck/scalafx/akka/AkkaFX.scala @@ -0,0 +1,31 @@ +package org.gerweck.scalafx.akka + +import scala.concurrent.Future + +import akka.Done +import akka.stream.scaladsl._ + +import scalafx.application.Platform.runLater +import scalafx.beans.property.Property + +/** A master object that exposes all the Akka-ScalaFX bridges. + * + * @author Sarah Gerweck + */ +object AkkaFX extends AkkaStreamFX + +trait AkkaStreamFX { + /** A [[akka.stream.scaladsl.Sink]] that sends all values to a + * [[scalafx.beans.property.Property]]. + * + * Each event that's written into the `Sink` will trigger an update of the + * `Property` with the streamed value. + */ + def observableSink[A](prop: Property[A, _]): Sink[A, Future[Done]] = { + Sink.foreach[A] { a => + runLater { + prop.value = a + } + } + } +}