trait SFXDelegateCompanion[D <: java.lang.Object] {
/**
* Converts a ScalaFX object to its JavaFX equivalent. Given a SFXDelegate, this method returns
* its delegate. If the argument was `null` it returns also `null`.
*
* @param s SFXDelegate object to be converted.
* @return Wrapped JavaFX object or `null` if argument is `null`.
*/
implicit def sfxObject2jfx[S <: SFXDelegate[D]](s: S): D =
if (s == null) null.asInstanceOf[D]
else s.delegate
}
object Styleable {
implicit def sfxStyleable2jfx(s: Styleable): jfxcss.Styleable = if (s != null) s.delegate else null
}
object Styleable
extends SFXDelegateCompanion[jfxcss.Styleable]
object Styleable
extends SFXDelegateCompanion[jfxe.EventType[_]] // No type specified--
You received this message because you are subscribed to the Google Groups "ScalaFX Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalafx-dev...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to scalafx-dev+unsubscribe@googlegroups.com.
1) Add a type member in SFXDelegate:
trait SFXDelegate[+D <: Object] extends AnyRef {
type Delegate = D // !!
/**
* JavaFX object to be wrapped.
*/
def delegate: Delegate
// ...
}
Companion
trait SFXCompanion {
implicit def sfx2jfx[D <: SFXDelegate[_]](s: D): s.Delegate =
if (s == null) null.asInstanceOf[s.Delegate]
else s.delegate
}
And then the companions:
object TreeTableView extends SFXCompanion {
// ...
I didn't run the tests, but playing around with simplified cases in REPL seems to be working.
Sorry if this is stupid: I'm way to young, Scala-wise :P
M.
--
You received this message because you are subscribed to the Google Groups "ScalaFX Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalafx-dev...@googlegroups.com.
Hmmm.
The
trait SFXDelegate[+D <: Object] extends AnyRef {
type Delegate = D
statement compiles fine in 2.10 but fails in 2.11. Something with covariance and invariance :’(
So it would become something like
trait SFXDelegate[+D <: Object] extends AnyRef {
type Delegate <: D
// ...
but then also we must define Delegate
class TreeTableView [T](override val delegate: jfxsc.TreeTableView [T]) extends SFXDelegate[jfxsc.TreeTableView [T]] {
type Delegate = jfxsc.TreeTableView [T] // new
// ...
}
which is becoming quite tiresome to write (and I still get some errors).
I’ll try some more: I have little idea what I am doing, but it’s a great way to learn some Scala :P
M