public void initialise ( MenuTree menuTree , RemoteMenuController remoteControl ) { this . menuTree = menuTree ; this . remoteControl = remoteControl ; // we spin up a monitor that counts down changed fields resetting the background colour after a few seconds. executor . scheduleAtFixedRate ( this :: updatedFieldChecker , 1000 , 100 , TimeUnit . MILLISECONDS ) ; // // register a listener that will handle all the connectivity and change events. Take careful note of the // Platform.runLater calls, these are very important, you must not update UI controls directly in the comms // call back. // remoteControl . addListener ( new RemoteControllerListener ( ) { /** * This is called whenever a menu item value changes. If value only is true only the value has changed, and * the item is unaffected. * @param item the item that has changed * @param valueOnly true if only the current value has changed, false if the MenuItem has changed too */ @ Override public void menuItemChanged ( MenuItem item , boolean valueOnly ) { Platform . runLater ( ( ) -> renderItemValue ( item ) ) ; } /** * When the tree is fully populated, and therefore the menuTree has all items in it, we get this callback * so we can do whatever we need to do with the information. */ @ Override public void treeFullyPopulated ( ) { Platform . runLater ( ( ) -> { menuLoadLabel . setText ( "YES" ) ; itemGrid . getChildren ( ) . clear ( ) ; buildGrid ( MenuTree . ROOT , 10 , 0 ) ; } ) ; } /** * When the connection state changes, we redraw the UI to show the remote information on the right. * Notice we don't do so immediately, rather we call Platform.runLater to make the changes. * @param remoteInformation the new connection information * @param con the new connection state. */ @ Override public void connectionState ( RemoteInformation remoteInformation , boolean con ) { remoteInfo = Optional . ofNullable ( remoteInformation ) ; connected = con ; Platform . runLater ( MainWindowController . this :: updateConnectionDetails ) ; } } ) ; // // start the comms // remoteControl . start ( ) ; }
initialise is called by the App to start the application up . In here we register a listener for communication events and start the comms .