Gabriel95 / scalafx

Automatically exported from code.google.com/p/scalafx
Other
0 stars 0 forks source link

ObjectProperty holding a ScalaFX wrapper cannot bind to ScalaFX control's properties #14

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
For instance, if an `ObjectProperty` has parameter type 
`scalafx.scene.paint.Color` it cannot be bound to `fill` property in 
`scalafx.scene.shape.Rectangle`.

You will get compilation error:
  error: overloaded method value <== with alternatives:
  (v: scalafx.beans.value.ObservableValue[_ <: javafx.scene.paint.Paint, _ <: javafx.scene.paint.Paint])Unit <and>
  (v: javafx.beans.value.ObservableValue[_ <: javafx.scene.paint.Paint])Unit
  cannot be applied to (scalafx.beans.property.ObjectProperty[scalafx.scene.paint.Paint])
  fill <== fillPaint

Example code illustrating that is here:
https://github.com/jsacha/ProScalaFX/blob/master/test/src/misc/ChangeFillExample
.scala
(also attached)

Also, if you look at implementation of `scalafx.scene.Node` you can see that 
ObjectProperty types there, they use JavaFX types for value.
http://code.google.com/p/scalafx/source/browse/src/scalafx/scene/Node.scala#65
I think this is because of the same binding problem. 

Original issue reported on code.google.com by galic...@gmail.com on 14 Dec 2012 at 4:23

Attachments:

GoogleCodeExporter commented 8 years ago

Original comment by jpsacha on 1 Feb 2013 at 5:13

GoogleCodeExporter commented 8 years ago
This issue could not be easily and completely fixed without significant changes 
to ScalaFX code base. To make it easier to deal with it I implemented factory 
methods for ObjectProperty that simplify the work around (using ObjectProperty 
with JavaFX value type)
https://code.google.com/p/scalafx/source/detail?r=bb04f99df3c7ebf13779bc7c3ce4f5
f2a102da5d

The work around is to use a factory method, rather than constructor. The 
factory method with create ObjectProperty with correct value type. When using 
it, do not specify type of created instance, let the Scala compiler infer it. 
For instance, instead of using constructor:

val fillPaint = new ObjectProperty[jfxsp.Paint](Color.LIGHTGRAY)

use factory method:

val fillPaint = ObjectProperty(Color.LIGHTGRAY)

Original comment by jpsacha on 8 Mar 2013 at 3:15