Misc code beautification
This commit is contained in:
parent
488fc08cd6
commit
d882c1a784
@ -1,6 +1,5 @@
|
|||||||
package org.gerweck.scalafx.akka
|
package org.gerweck.scalafx.akka
|
||||||
|
|
||||||
import scala.collection.mutable
|
|
||||||
import scala.concurrent._
|
import scala.concurrent._
|
||||||
|
|
||||||
import akka.Done
|
import akka.Done
|
||||||
|
@ -15,8 +15,6 @@ import scalafx.application.Platform.runLater
|
|||||||
import scalafx.beans.Observable
|
import scalafx.beans.Observable
|
||||||
import scalafx.beans.property._
|
import scalafx.beans.property._
|
||||||
|
|
||||||
import org.log4s._
|
|
||||||
|
|
||||||
import org.gerweck.scalafx.util.FutureObservable
|
import org.gerweck.scalafx.util.FutureObservable
|
||||||
|
|
||||||
trait AkkaFXCollections extends Any {
|
trait AkkaFXCollections extends Any {
|
||||||
@ -28,7 +26,6 @@ object AkkaFXCollections {
|
|||||||
(buffer: Observable with Growable[A] with Clearable,
|
(buffer: Observable with Growable[A] with Clearable,
|
||||||
clearFirst: Boolean,
|
clearFirst: Boolean,
|
||||||
groupingSize: Int = 50, groupingTimeout: FiniteDuration = 100.milliseconds)
|
groupingSize: Int = 50, groupingTimeout: FiniteDuration = 100.milliseconds)
|
||||||
(implicit ec: ExecutionContext)
|
|
||||||
: Sink[A, Future[Done]] = {
|
: Sink[A, Future[Done]] = {
|
||||||
sealed trait PopulateAction
|
sealed trait PopulateAction
|
||||||
case class InsertRows(data: Seq[A]) extends PopulateAction
|
case class InsertRows(data: Seq[A]) extends PopulateAction
|
||||||
|
@ -1,10 +1,5 @@
|
|||||||
package org.gerweck.scalafx.util
|
package org.gerweck.scalafx.util
|
||||||
|
|
||||||
import language.existentials
|
|
||||||
|
|
||||||
import scalaz._
|
|
||||||
import Scalaz._
|
|
||||||
|
|
||||||
import shapeless._
|
import shapeless._
|
||||||
import shapeless.ops.hlist._
|
import shapeless.ops.hlist._
|
||||||
import shapeless.ops.function._
|
import shapeless.ops.function._
|
||||||
@ -19,18 +14,20 @@ import scalafx.beans.value.ObservableValue
|
|||||||
class ObservableTupler
|
class ObservableTupler
|
||||||
[HLObs <: HList, HLParams <: HList, TParams <: Product] private
|
[HLObs <: HList, HLParams <: HList, TParams <: Product] private
|
||||||
(hlist: HLObs)
|
(hlist: HLObs)
|
||||||
(implicit unwrapper: Mapper.Aux[ObservableUnwrapper.type, HLObs, HLParams],
|
(implicit
|
||||||
tupler: Tupler.Aux[HLParams, TParams],
|
unwrapper: Mapper.Aux[ObservableUnwrapper.type, HLObs, HLParams],
|
||||||
lister: ToList[HLObs, Observable[_]]) {
|
tupler: Tupler.Aux[HLParams, TParams],
|
||||||
|
lister: ToList[HLObs, Observable[_]]) {
|
||||||
|
|
||||||
def |@|[O, P, Appended <: HList, Unwrapped <: HList, Tupled <: Product, ApList]
|
def |@|[O, P, Appended <: HList, Unwrap <: HList, Tupled <: Product, ApList]
|
||||||
(f: ObservableValue[O, P])
|
(f: ObservableValue[O, P])
|
||||||
(implicit prepend: Prepend.Aux[HLObs, ObservableValue[O, P]::HNil, Appended],
|
(implicit
|
||||||
uw: Mapper.Aux[ObservableUnwrapper.type, Appended, Unwrapped],
|
prepend: Prepend.Aux[HLObs, ObservableValue[O, P]::HNil, Appended],
|
||||||
tplr: Tupler.Aux[Unwrapped, Tupled],
|
uw: Mapper.Aux[ObservableUnwrapper.type, Appended, Unwrap],
|
||||||
lst: ToList[Appended, Observable[_]]): ObservableTupler[Appended, Unwrapped, Tupled] = {
|
tplr: Tupler.Aux[Unwrap, Tupled],
|
||||||
|
lst: ToList[Appended, Observable[_]]): ObservableTupler[Appended, Unwrap, Tupled] = {
|
||||||
val newHL: Appended = hlist :+ f
|
val newHL: Appended = hlist :+ f
|
||||||
new ObservableTupler[Appended, Unwrapped, Tupled](newHL)
|
new ObservableTupler[Appended, Unwrap, Tupled](newHL)
|
||||||
}
|
}
|
||||||
|
|
||||||
def hlisted: ObservableValue[HLParams, HLParams] = {
|
def hlisted: ObservableValue[HLParams, HLParams] = {
|
||||||
@ -64,7 +61,10 @@ class ObservableTupler
|
|||||||
prop
|
prop
|
||||||
}
|
}
|
||||||
|
|
||||||
def apply[Func, Result](f: Func)(implicit ffp: FnFromProduct.Aux[HLParams => Result, Func], ftp: FnToProduct.Aux[Func, HLParams => Result]): ObservableValue[Result, Result] = {
|
def apply[Func, Result]
|
||||||
|
(f: Func)
|
||||||
|
(implicit ftp: FnToProduct.Aux[Func, HLParams => Result])
|
||||||
|
: ObservableValue[Result, Result] = {
|
||||||
hlisted map ftp(f)
|
hlisted map ftp(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -172,29 +172,24 @@ final class RichTuple[A <: Product](val self: A) extends AnyVal {
|
|||||||
* Shapeless's `tuple` package, but it can't infer the exact output type,
|
* Shapeless's `tuple` package, but it can't infer the exact output type,
|
||||||
* which is far less useful.
|
* which is far less useful.
|
||||||
*/
|
*/
|
||||||
def observe
|
def observe[L <: HList, Unwrap <: HList, Tupled <: Product]
|
||||||
[L <: HList, Unwrapped <: HList, Tupled <: Product]
|
(implicit tohl: Generic.Aux[A, L],
|
||||||
(implicit tohl: Generic.Aux[A, L],
|
lister: ToTraversable.Aux[L, List, Observable[_]],
|
||||||
lister: ToTraversable.Aux[L, List, Observable[_]],
|
uw: Mapper.Aux[ObservableUnwrapper.type, L, Unwrap],
|
||||||
uw: Mapper.Aux[ObservableUnwrapper.type, L, Unwrapped],
|
tplr: Tupler.Aux[Unwrap, Tupled]): ObservableValue[Tupled, Tupled] = {
|
||||||
tplr: Tupler.Aux[Unwrapped, Tupled]): ObservableValue[Tupled, Tupled] = {
|
|
||||||
val asHList: L = tohl.to(self)
|
val asHList: L = tohl.to(self)
|
||||||
def calculate(): Tupled = uw(asHList).tupled
|
def calculate(): Tupled = uw(asHList).tupled
|
||||||
|
|
||||||
val original = calculate()
|
val original = calculate()
|
||||||
val prop = ObjectProperty[Tupled](original)
|
val prop = ObjectProperty[Tupled](original)
|
||||||
|
|
||||||
for {
|
for (component <- asHList.to[List]) {
|
||||||
component <- asHList.to[List]
|
|
||||||
} {
|
|
||||||
component onChange {
|
component onChange {
|
||||||
prop.value = calculate()
|
prop.value = calculate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
prop
|
prop
|
||||||
}
|
}
|
||||||
|
|
||||||
// def omap[B]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final class RichObservable[A, C](val self: ObservableValue[A, C]) extends AnyVal {
|
final class RichObservable[A, C](val self: ObservableValue[A, C]) extends AnyVal {
|
||||||
@ -247,9 +242,9 @@ final class ObservableOfMapLike[A, B, C](val self: ObservableValue[C, C])(implic
|
|||||||
}
|
}
|
||||||
|
|
||||||
final class RichProperty[A, B](val inner: Property[A, B]) extends AnyVal {
|
final class RichProperty[A, B](val inner: Property[A, B]) extends AnyVal {
|
||||||
def biMap[B <: AnyRef](push: A => B, pull: B => A): ObjectProperty[B] = {
|
def biMap[A1 <: AnyRef](push: A => A1, pull: A1 => A): ObjectProperty[A1] = {
|
||||||
val original = push(inner.value)
|
val original = push(inner.value)
|
||||||
val op = ObjectProperty[B](original)
|
val op = ObjectProperty[A1](original)
|
||||||
inner onChange {
|
inner onChange {
|
||||||
val oldVal = op.value
|
val oldVal = op.value
|
||||||
val newVal = push(inner.value)
|
val newVal = push(inner.value)
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package org.gerweck.scalafx.util
|
package org.gerweck.scalafx.util
|
||||||
|
|
||||||
import language.implicitConversions
|
|
||||||
|
|
||||||
import scala.compat.java8.FunctionConverters._
|
import scala.compat.java8.FunctionConverters._
|
||||||
|
|
||||||
import java.util.function.{ Predicate => JPredicate }
|
import java.util.function.{ Predicate => JPredicate }
|
||||||
|
@ -1,18 +1,12 @@
|
|||||||
package org.gerweck.scalafx
|
package org.gerweck.scalafx
|
||||||
|
|
||||||
import language.implicitConversions
|
|
||||||
import language.existentials
|
|
||||||
|
|
||||||
import scalafx.Includes._
|
|
||||||
import scalafx.beans.property._
|
import scalafx.beans.property._
|
||||||
import scalafx.beans.value._
|
import scalafx.beans.value._
|
||||||
import scalafx.event.subscriptions.Subscription
|
|
||||||
import scalafx.scene.Node
|
import scalafx.scene.Node
|
||||||
import scalafx.scene.control._
|
import scalafx.scene.control._
|
||||||
import scalafx.scene.input._
|
import scalafx.scene.input._
|
||||||
import scalafx.scene.layout.GridPane
|
import scalafx.scene.layout.GridPane
|
||||||
import scalafx.scene.text.Text
|
import scalafx.scene.text.Text
|
||||||
import scalafx.util.StringConverter
|
|
||||||
|
|
||||||
import scalaz._
|
import scalaz._
|
||||||
|
|
||||||
@ -25,8 +19,8 @@ package object util extends ObservableImplicits with LowPriorityImplicits {
|
|||||||
type SimpleProperty[A] = Property[A, _]
|
type SimpleProperty[A] = Property[A, _]
|
||||||
|
|
||||||
object TextDisplay {
|
object TextDisplay {
|
||||||
def apply(text: ObservableValue[String,String]) = {
|
def apply(text: ObservableValue[String,String]): Text = {
|
||||||
val t = new scalafx.scene.text.Text
|
val t = new Text
|
||||||
t.text <== text
|
t.text <== text
|
||||||
t
|
t
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user