add calculating methods to bind
Tom Eugelink
tbee at tbee.org
Wed May 21 19:36:37 UTC 2014
Found it! Slightly different DoubleBinding was required (copied it from negate).
private DoubleBinding snap(final ObservableNumberValue value, final Observable... dependencies) {
return new DoubleBinding() {
{
super.bind(value);
}
@Override
public void dispose() {
super.unbind(value);
}
@Override
protected double computeValue() {
return NodeUtil.snapXY(value.doubleValue());
}
@Override
public ObservableList<?> getDependencies() {
return FXCollections.singletonObservableList(value);
}
};
}
On 2014-5-21 21:34, Tomas Mikula wrote:
> Hi Tom,
>
> it seems to me that in your custom DoubleBinding implementation
> `other` is not its dependency, thus it does not react to it's
> invalidations.
>
> Tomas
>
> On Wed, May 21, 2014 at 9:25 PM, Tom Eugelink <tbee at tbee.org> wrote:
>> I came up with this:
>>
>> startXProperty().bind( *snap(*heightProperty().multiply(0.2)) )
>>
>>
>> And then:
>>
>> private DoubleBinding snap(final ObservableNumberValue other, final
>> Observable... dependencies) {
>> return new DoubleBinding() {
>> {
>> super.bind(dependencies);
>> }
>>
>> @Override
>> public void dispose() {
>> super.unbind(dependencies);
>> }
>>
>> @Override
>> protected double computeValue() {
>> return NodeUtil.snap(other.doubleValue());
>> }
>>
>> @Override
>> public ObservableList<?> getDependencies() {
>> return new
>> ImmutableObservableList<Observable>(dependencies);
>> }
>> };
>> }
>>
>> But that always returns 0... I feel this should have worked.
>>
>> Tom
More information about the openjfx-dev
mailing list