PropertyDelegate
Creates a SimpleProperty, where the bean and beanName are automatically set.
V is the value type (Double in the example above).
O is the property type (DoubleProperty) in the example above.
Example usage :
val widthProperty by doubleProperty(1.0)Property is itself a delegate, which returns the property value. So...
val widthProperty by doubleProperty(1.0)
var width by widthPropertyNOTE. The value of beanName is assumed to be the name of the Property, without the Property suffix. In the example above by doubleProperty(1.0) sees the name widthProperty, and reduces it to just width. This is a problem when you have code such as :
private val privateWidthProperty by doubleProperty(1.0)
val widthProperty = privateWidthProperty.asReadOnly()
var width by privateWidthPropertyIn this case, the bean name would be privateWidth, which is wrong. So there are 3 common name prefixes that are tested for :
_ (underscore)
private
mutable
A warning message is issued to Glok's log if the bean is not found.
For any other naming conventions, you'll have to set the bean name manually i.e.
val funnyWidthProperty = SimpleDoubleProperty(1.0, this, "width")
var width by widthPropertyA common mistake is to use PropertyDelegate with non-public fields. Beans must be public. So this is wrong :
private val widthProperty by doubleProperty(1.0)
private var width by widthPropertyUse this instead (without using a PropertyDelegate, and therefore bean and beanName are not set) :
private val widthProperty = SimpleDoubleProperty(1.0)
private var width by widthPropertyBean name will be blank.