Add new automatic conversion to BooleanProperty

There are a number of signatures in ScalaFX that won't accept an
observable of a Scala Boolean and that require you to convert it to a
Java Boolean. This adds an automatic conversion to resolve that.
This commit is contained in:
Sarah Gerweck 2016-07-30 15:26:18 -07:00
parent e50159b82e
commit 5b6ad07a08
2 changed files with 17 additions and 1 deletions

View File

@ -0,0 +1,15 @@
package org.gerweck.scalafx.util
import scala.language.implicitConversions
import scalafx.beans.property._
trait LowPriorityImplicits {
implicit def scalaBooleanToBooleanProperty(ob: ReadOnlyObjectProperty[Boolean]): ReadOnlyBooleanProperty = {
val b = BooleanProperty(ob.value)
ob onChange { (_, oldV, newV) =>
b.value = newV
}
b
}
}

View File

@ -3,6 +3,7 @@ package org.gerweck.scalafx
import language.implicitConversions
import language.existentials
import scalafx.Includes._
import scalafx.beans.property._
import scalafx.beans.value._
import scalafx.event.subscriptions.Subscription
@ -19,7 +20,7 @@ import scalaz._
*
* @author Sarah Gerweck <sarah@atscale.com>
*/
package object util extends ObservableImplicits {
package object util extends ObservableImplicits with LowPriorityImplicits {
type Observable[A] = ObservableValue[A, _]
type SimpleProperty[A] = Property[A, _]