Example #1
0
  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);
    }
  }
Example #2
0
 private static List<Map.Entry<EventType<?>, EventHandler<?>>> getHandlers(Node node) {
   return (List<Entry<EventType<?>, EventHandler<?>>>) node.getProperties().get(P_HANDLERS);
 }
Example #3
0
 private static void setInputMap(Node node, InputMap<?> im) {
   node.getProperties().put(P_INPUTMAP, im);
 }
Example #4
0
 static InputMap<?> getInputMap(Node node) {
   init(node);
   return (InputMap<?>) node.getProperties().get(P_INPUTMAP);
 }