i have simpleintegerproperty
, want derive simpleobjectproperty<color>
it.
for imagine mechanism streams , optionals:
simpleintegerproperty intprop; objectproperty<color> colorprop = intprop.map(i -> convertinttocolor(i), c -> convertcolortoint(c));
is there built-in or need roll out on own?
it seems odd if there no such thing because looking @ power of bindings
gives strong feeling feature should there.
thanks!
unsure if best way, seems work using bindings.createobjectbinding
:
@test public void test() { simpleintegerproperty simpleintegerproperty = new simpleintegerproperty(1); objectbinding<color> binding = bindings .createobjectbinding(() -> convertocolor(simpleintegerproperty.get()), simpleintegerproperty); system.out.println(binding.get()); binding.addlistener(new changelistener<color>() { @override public void changed(observablevalue<? extends color> observable, color oldvalue, color newvalue) { system.out.println(newvalue); } }); simpleintegerproperty.set(2); } private color convertocolor(int i) { switch (i) { case 1: return color.red; case 2: return color.blue; } return null; }
Comments
Post a Comment