private static void init(Node node) { if (node.getProperties().get(P_INPUTMAP) == null) { node.getProperties().put(P_INPUTMAP, InputMap.empty()); node.getProperties().put(P_HANDLERS, new ArrayList<Map.Entry<?, ?>>()); MapChangeListener<Object, Object> listener = ch -> { if (!P_INPUTMAP.equals(ch.getKey())) { return; } getHandlers(node) .forEach( entry -> { node.removeEventHandler( (EventType<Event>) entry.getKey(), (EventHandler<Event>) entry.getValue()); }); getHandlers(node).clear(); InputMap<?> inputMap = (InputMap<?>) ch.getValueAdded(); inputMap.forEachEventType( new HandlerConsumer<Event>() { @Override public <E extends Event> void accept( EventType<? extends E> t, InputHandler<? super E> h) { node.addEventHandler(t, h); getHandlers(node).add(new SimpleEntry<>(t, h)); } }); }; node.getProperties().addListener(listener); } }
private static List<Map.Entry<EventType<?>, EventHandler<?>>> getHandlers(Node node) { return (List<Entry<EventType<?>, EventHandler<?>>>) node.getProperties().get(P_HANDLERS); }
private static void setInputMap(Node node, InputMap<?> im) { node.getProperties().put(P_INPUTMAP, im); }
static InputMap<?> getInputMap(Node node) { init(node); return (InputMap<?>) node.getProperties().get(P_INPUTMAP); }