Ejemplo n.º 1
0
  /**
   * Add EventHandler to handlers list & search through the EventHandlers EventTypes, placing it in
   * the correct lists, so Events can be filtered correctly.
   */
  public final void addEventHandler(final EventHandler _handler) {
    if (exists(_handler) == true) {
      Logger.println(_handler.getName() + "already exists within " + name, Logger.Verbosity.MAJOR);
      return;
    }

    handlers.add(_handler);

    final ArrayList<EventType> types = _handler.getWantedEventTypes();
    if (types.isEmpty() == true || types.contains(Event.ALL_EVENT_TYPES) == true) {
      // Due to legacy we must assumme that a types size of 0,
      // represents a developer wishing to recieve all Events.
      // If the types contains ALL_EVENT_TYPES then only add it
      // to the ALL_EVENT_TYPES EventQueue.
      eventQueues.get(Event.ALL_EVENT_TYPES).addEventHandler(_handler);
      return;
    }

    for (final EventType type : types) {
      if (eventQueues.containsKey(type) == false) {
        addEventQueue(type, new EventQueue(type));
      }

      eventQueues.get(type).addEventHandler(_handler);
    }
  }
Ejemplo n.º 2
0
  private void remove(final EventHandler _handler) {
    final ArrayList<EventType> types = _handler.getWantedEventTypes();
    if (types.isEmpty() == true) {
      // Due to legacy we must assumme that a types size of 0,
      // represents Event.ALL_EVENT_TYPES, must be specially removed.
      eventQueues.get(Event.ALL_EVENT_TYPES).removeEventHandler(_handler);
    }

    for (final EventType type : types) {
      if (eventQueues.containsKey(type) == true) {
        eventQueues.get(type).removeEventHandler(_handler);
      }
    }

    handlers.remove(_handler);
    _handler.reset(); // Should clear any
  }