|
@ -2,6 +2,8 @@ package nova.monadic_sfx.implicits |
|
|
|
|
|
|
|
|
import javafx.beans.property.ObjectProperty |
|
|
import javafx.beans.property.ObjectProperty |
|
|
import javafx.collections.ObservableList |
|
|
import javafx.collections.ObservableList |
|
|
|
|
|
import javafx.event.ActionEvent |
|
|
|
|
|
import javafx.event.EventHandler |
|
|
import javafx.scene.{input => jfxsi} |
|
|
import javafx.scene.{input => jfxsi} |
|
|
import javafx.{event => jfxe} |
|
|
import javafx.{event => jfxe} |
|
|
import monix.bio.Task |
|
|
import monix.bio.Task |
|
@ -13,18 +15,15 @@ import monix.reactive.Observer |
|
|
import monix.reactive.OverflowStrategy |
|
|
import monix.reactive.OverflowStrategy |
|
|
import monix.tail.Iterant |
|
|
import monix.tail.Iterant |
|
|
import monix.{eval => me} |
|
|
import monix.{eval => me} |
|
|
|
|
|
import org.gerweck.scalafx.util._ |
|
|
import scalafx.Includes._ |
|
|
import scalafx.Includes._ |
|
|
import scalafx.beans.property.Property |
|
|
import scalafx.beans.property.Property |
|
|
|
|
|
import scalafx.beans.property.ReadOnlyProperty |
|
|
import scalafx.beans.value.ObservableValue |
|
|
import scalafx.beans.value.ObservableValue |
|
|
import scalafx.collections.ObservableBuffer |
|
|
import scalafx.collections.ObservableBuffer |
|
|
import scalafx.scene.Scene |
|
|
import scalafx.scene.Scene |
|
|
import scalafx.scene.control.ButtonBase |
|
|
import scalafx.scene.control.ButtonBase |
|
|
import scalafx.beans.property.ReadOnlyProperty |
|
|
|
|
|
import javafx.event.ActionEvent |
|
|
|
|
|
import javafx.event.EventHandler |
|
|
|
|
|
import javafx.scene.{control => jfxsc} |
|
|
|
|
|
import scalafx.scene.control.MenuItem |
|
|
import scalafx.scene.control.MenuItem |
|
|
import org.gerweck.scalafx.util._ |
|
|
|
|
|
|
|
|
|
|
|
object JavaFXMonixObservables { |
|
|
object JavaFXMonixObservables { |
|
|
|
|
|
|
|
@ -80,8 +79,8 @@ object JavaFXMonixObservables { |
|
|
op.onNext(prop.value) |
|
|
op.onNext(prop.value) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
def -->(op: Property[T, J]) = { |
|
|
|
|
|
op() = prop.value |
|
|
|
|
|
|
|
|
def ==>(op: Property[T, J]) = { |
|
|
|
|
|
op <== prop |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
def <--(obs: Observable[T])(implicit s: Scheduler) = { |
|
|
def <--(obs: Observable[T])(implicit s: Scheduler) = { |
|
@ -90,13 +89,12 @@ object JavaFXMonixObservables { |
|
|
|
|
|
|
|
|
def asOption = prop.map(Option(_)) |
|
|
def asOption = prop.map(Option(_)) |
|
|
|
|
|
|
|
|
def observableChange[J1 >: J]() |
|
|
|
|
|
: Observable[(ObservableValue[T, J], J1, J1)] = { |
|
|
|
|
|
|
|
|
def observableChange[J1 >: J](): Observable[J1] = { |
|
|
import monix.execution.cancelables.SingleAssignCancelable |
|
|
import monix.execution.cancelables.SingleAssignCancelable |
|
|
Observable.create(OverflowStrategy.Unbounded) { sub => |
|
|
Observable.create(OverflowStrategy.Unbounded) { sub => |
|
|
val c = SingleAssignCancelable() |
|
|
val c = SingleAssignCancelable() |
|
|
|
|
|
|
|
|
val canc = prop.onChange((a, b, c) => sub.onNext((a, b, c))) |
|
|
|
|
|
|
|
|
val canc = prop.onChange((a, b, c) => sub.onNext(c)) |
|
|
|
|
|
|
|
|
c := Cancelable(() => canc.cancel()) |
|
|
c := Cancelable(() => canc.cancel()) |
|
|
c |
|
|
c |
|
@ -107,18 +105,9 @@ object JavaFXMonixObservables { |
|
|
implicit final class BindObs2[A](private val prop: ObjectProperty[A]) |
|
|
implicit final class BindObs2[A](private val prop: ObjectProperty[A]) |
|
|
extends AnyVal { |
|
|
extends AnyVal { |
|
|
|
|
|
|
|
|
// def -->(sub: Var[A]) = |
|
|
|
|
|
// prop.onChange((a, b, c) => sub := c) |
|
|
|
|
|
|
|
|
|
|
|
def -->(sub: Observer[A]) = |
|
|
def -->(sub: Observer[A]) = |
|
|
prop.onChange((a, b, c) => if (c != null) sub.onNext(c)) |
|
|
prop.onChange((a, b, c) => if (c != null) sub.onNext(c)) |
|
|
|
|
|
|
|
|
// def -->[J1 >: A, T]( |
|
|
|
|
|
// op: Observable[J1] => me.Task[T] |
|
|
|
|
|
// )(implicit s: Scheduler) = { |
|
|
|
|
|
// op(prop.observableChange().map(_._3)).runToFuture |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
def -->(op: Property[A, A]) = { |
|
|
def -->(op: Property[A, A]) = { |
|
|
prop.onChange((a, b, c) => if (c != null) op() = c) |
|
|
prop.onChange((a, b, c) => if (c != null) op() = c) |
|
|
} |
|
|
} |
|
@ -147,21 +136,16 @@ object JavaFXMonixObservables { |
|
|
op.onNext(prop.value) |
|
|
op.onNext(prop.value) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
def -->(op: Property[T, J]) = { |
|
|
|
|
|
|
|
|
def ==>(op: Property[T, J]) = { |
|
|
op <== prop |
|
|
op <== prop |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// def <--(obs: Observable[T])(implicit s: Scheduler) = { |
|
|
|
|
|
// obs.doOnNext(v => me.Task(prop.value = v)).subscribe() |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
def observableChange[J1 >: J]() |
|
|
|
|
|
: Observable[(ObservableValue[T, J], J1, J1)] = { |
|
|
|
|
|
|
|
|
def observableChange[J1 >: J](): Observable[J1] = { |
|
|
import monix.execution.cancelables.SingleAssignCancelable |
|
|
import monix.execution.cancelables.SingleAssignCancelable |
|
|
Observable.create(OverflowStrategy.Unbounded) { sub => |
|
|
Observable.create(OverflowStrategy.Unbounded) { sub => |
|
|
val c = SingleAssignCancelable() |
|
|
val c = SingleAssignCancelable() |
|
|
|
|
|
|
|
|
val canc = prop.onChange((a, b, c) => sub.onNext((a, b, c))) |
|
|
|
|
|
|
|
|
val canc = prop.onChange((a, b, c) => sub.onNext(c)) |
|
|
|
|
|
|
|
|
c := Cancelable(() => canc.cancel()) |
|
|
c := Cancelable(() => canc.cancel()) |
|
|
c |
|
|
c |
|
@ -227,17 +211,6 @@ object JavaFXMonixObservables { |
|
|
implicit final class OnActionObservable( |
|
|
implicit final class OnActionObservable( |
|
|
private val button: ButtonBase |
|
|
private val button: ButtonBase |
|
|
) extends AnyVal { |
|
|
) extends AnyVal { |
|
|
// def -->[T]( |
|
|
|
|
|
// op: Observable[jfxe.ActionEvent] => me.Task[T] |
|
|
|
|
|
// )(implicit s: Scheduler) = { |
|
|
|
|
|
// op(button.observableAction()).runToFuture |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
// def -->( |
|
|
|
|
|
// sub: ConcurrentSubject[jfxe.ActionEvent, jfxe.ActionEvent] |
|
|
|
|
|
// ) = { |
|
|
|
|
|
// button.onAction = value => sub.onNext(value) |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
def observableAction(): Observable[jfxe.ActionEvent] = { |
|
|
def observableAction(): Observable[jfxe.ActionEvent] = { |
|
|
import monix.execution.cancelables.SingleAssignCancelable |
|
|
import monix.execution.cancelables.SingleAssignCancelable |
|
@ -262,19 +235,8 @@ object JavaFXMonixObservables { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
implicit final class MenuItemActionObservable( |
|
|
implicit final class MenuItemActionObservable( |
|
|
private val et: MenuItem |
|
|
|
|
|
|
|
|
private val item: MenuItem |
|
|
) extends AnyVal { |
|
|
) extends AnyVal { |
|
|
// def -->[T]( |
|
|
|
|
|
// op: Observable[jfxe.ActionEvent] => me.Task[T] |
|
|
|
|
|
// )(implicit s: Scheduler) = { |
|
|
|
|
|
// op(button.observableAction()).runToFuture |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
// def -->( |
|
|
|
|
|
// sub: ConcurrentSubject[jfxe.ActionEvent, jfxe.ActionEvent] |
|
|
|
|
|
// ) = { |
|
|
|
|
|
// button.onAction = value => sub.onNext(value) |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
def observableAction(): Observable[jfxe.ActionEvent] = { |
|
|
def observableAction(): Observable[jfxe.ActionEvent] = { |
|
|
import monix.execution.cancelables.SingleAssignCancelable |
|
|
import monix.execution.cancelables.SingleAssignCancelable |
|
@ -286,9 +248,9 @@ object JavaFXMonixObservables { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
et.onAction = l |
|
|
|
|
|
|
|
|
item.onAction = l |
|
|
c := Cancelable(() => |
|
|
c := Cancelable(() => |
|
|
et.removeEventHandler( |
|
|
|
|
|
|
|
|
item.removeEventHandler( |
|
|
jfxe.ActionEvent.ACTION, |
|
|
jfxe.ActionEvent.ACTION, |
|
|
l |
|
|
l |
|
|
) |
|
|
) |
|
|