java - JavaFX Property for a BitSet -
i need javafx property
bitset
in order create tablecolumn
toggle button each bit in bitset
. have implemented property<bitset>
oracle documentation meaning , usage of of interface methods still eludes me, me looks superfluous boilerplate. please tell me if on right track implementation , can improve. didn't implement bindings yet because don't expect need them use case.
import java.util.*; import javafx.beans.invalidationlistener; import javafx.beans.property.property; import javafx.beans.value.changelistener; import javafx.beans.value.observablevalue; public class bitsetproperty implements property<bitset> { private bitset value; private final set<changelistener<? super bitset>> changelisteners = new hashset<>(); private final set<invalidationlistener> invalidationlisteners = new hashset<>(); @override public object getbean() {return value;} @override public string getname() {return "what shall return here?";} @override public void addlistener(changelistener<? super bitset> listener) {changelisteners.add(listener);} @override public void removelistener(changelistener<? super bitset> listener) {changelisteners.remove(listener);} @override public bitset getvalue() { return (bitset)value.clone(); } @override public void addlistener(invalidationlistener listener) {invalidationlisteners.add(listener);} @override public void removelistener(invalidationlistener listener) {invalidationlisteners.remove(listener);} @override public void setvalue(bitset value) { if(!value.equals(this.value)) { changelisteners.stream().foreach(cl->cl.changed(this, this.value, (bitset)value.clone())); invalidationlisteners.stream().foreach(il->il.invalidated(this)); } this.value=value; } @override public void bind(observablevalue<? extends bitset> observable) { throw new unsupportedoperationexception(); } @override public void unbind() { throw new unsupportedoperationexception(); } @override public boolean isbound() { // todo auto-generated method stub return false; } @override public void bindbidirectional(property<bitset> other) { throw new unsupportedoperationexception(); } @override public void unbindbidirectional(property<bitset> other) { throw new unsupportedoperationexception(); } }
answering own question turns out misunderstood how properties work. thought trigger change events when internal state changes know treat content black box (i guess assuming content immutable) , trigger when content replaced, easier problem. question can solved using:
objectproperty<bitset> property = new simpleobjectproperty<>();
Comments
Post a Comment