tag:blogger.com,1999:blog-429571914585035568.post6155201190837367227..comments2023-10-15T11:19:18.998+02:00Comments on Babbler - an XMPP library for Java: Bringing XMPP Chat States to JavaFXChristian Schudthttp://www.blogger.com/profile/05150185502293392614noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-429571914585035568.post-63505674356129781892015-02-14T20:29:13.353+01:002015-02-14T20:29:13.353+01:00Christian,
no need for the on finished handler wi...Christian,<br /><br />no need for the on finished handler with key frame: The key frame can set a boolean property to which you can bind a "When". Also, possibly it makes sense to bind more properties to one KeyValue instead of simply "timeUp" (have not deeper checked that).<br /><br />If it doesn't work as you expected it, either your expectation or your code was simply wrong. It actually works like a charm in my apps. ;-)<br /><br />Actually I would use fluent API (static Bindings.when) and static imports, as it is simple to read (like English):<br /><br />chatState.bind(when(focused).then(when(isEmpty()).then(ACTIVE).otherwise.(when(timeUp).then(PAUSED).otherwise(COMPOSING)).otherwise(INACTIVE)));<br /><br />(BTW, the fact that this is hard to read in Java is why I asked Oracle to finish FXML expression. There it would read something like ...text="${focused ? isEmpty ? ACTIVE : timeUp ? PAUSED : COMPOSITING : INACTIVE}")<br /><br />The trick with the binding (instead of listener) is (a) it is reactive, so the invariant is guaranteed to be true always without to make up a mind about the when-then implied by listeners, and the invariant keeps the complete definition of the state engine in one single place (even in one single Java statement) and does not scatter it all over the code, (b) it's shorter than old-school Java, (c) once Oracle fixes FXML expressions, you can omit Java at all and let the designer do the bindings. :-)<br /><br />Regards<br />-MarkusUnknownhttps://www.blogger.com/profile/16730512154181587633noreply@blogger.comtag:blogger.com,1999:blog-429571914585035568.post-51673268664842696622015-02-13T22:48:10.765+01:002015-02-13T22:48:10.765+01:00Ah I now know what you mean. I've ended up wit...Ah I now know what you mean. I've ended up with something like the following, but it doesn't even work as expected and imo is hard to maintain/debug/read. The rest of the code isn't much cleaner either. Do you meant it to be like that?<br /><br /> chatState.bind(new When(timeIsUp)<br /> .then(new When(focusedProperty())<br /> .then(new When(textProperty().isEmpty())<br /> .then(ChatState.ACTIVE)<br /> .otherwise(ChatState.PAUSED))<br /> .otherwise(ChatState.INACTIVE))<br /> .otherwise(new When(focusedProperty())<br /> .then(new When(textProperty().isEmpty())<br /> .then(ChatState.ACTIVE)<br /> .otherwise(ChatState.COMPOSING))<br /> .otherwise(ChatState.INACTIVE)));Christian Schudthttps://www.blogger.com/profile/05150185502293392614noreply@blogger.comtag:blogger.com,1999:blog-429571914585035568.post-45095097477211706432015-02-13T20:55:18.882+01:002015-02-13T20:55:18.882+01:00Thanks for your proposal, but what is the "Wh...Thanks for your proposal, but what is the "When" expression? I can use a Timeline/Keyframe, but the onFinished EventHandler would still be there.Christian Schudthttps://www.blogger.com/profile/05150185502293392614noreply@blogger.comtag:blogger.com,1999:blog-429571914585035568.post-56174374818139349092015-02-13T20:10:25.735+01:002015-02-13T20:10:25.735+01:00A great example how animation can be used beyond v...A great example how animation can be used beyond visual animation. If you replace Transition by Timeline, you can get rid of the event handler and the "if": The key frame can directly modify a property, and the "When" expression does the rest. :-)Unknownhttps://www.blogger.com/profile/16730512154181587633noreply@blogger.com