Chat States. Everybody knows them from Instant Messengers or Facebook Chat. Those tiny notifications, which tell you, if your chat partner is currently composing a message, is (in)active or has paused typing. E.g. "XY is typing..."XMPP defines these states in XEP-0085: Chat State Notifications as:
Each of them - except "gone" - are applicable to a "message input interface". So let's translate them to a JavaFX TextArea!
First we define, that whenever the TextArea receives focus, we want to change the state from 'inactive' (which is the initial default state) to 'active' (if there's no text) or to 'paused' (if there's already text):
Secondly we have to change to 'composing', whenever the text changes. Easy.
The slightly tricky part is to change to the 'paused' state. To achieve this, we can set up a
javafx.animation.PauseTransition and restart it everytime the text or focus has changed. Eventually, when the transition has finished (e.g. after 3 seconds), it will automatically change the state to 'paused':
Lastly, we change to 'inactive' when focus is lost:
And here's my take on a simple implementation. Enjoy!