Пример #1
0
 public void keyPressed() {
   if (key == ' ') {
     log.debug("programmed: fire panTo + zoomTo");
     PanMapEvent panMapEvent = new PanMapEvent(this, maps.get(0).getId());
     Location location = new Location(52.4115f, 13.0516f);
     panMapEvent.setLocation(location);
     eventDispatcher.fireMapEvent(panMapEvent);
     ZoomMapEvent zoomMapEvent = new ZoomMapEvent(this, maps.get(0).getId());
     zoomMapEvent.setSubType("zoomTo");
     zoomMapEvent.setZoomLevel(14);
     eventDispatcher.fireMapEvent(zoomMapEvent);
   }
 }
Пример #2
0
  /**
   * Initializes default events, i.e. all given maps handle mouse and keyboard interactions. No
   * cross-listening between maps.
   *
   * @param p The PApplet needed for mouse and key user interactions.
   * @param maps One or many maps.
   * @return The EventDispatcher to use for additional event handling.
   */
  public static EventDispatcher createDefaultEventDispatcher(PApplet p, UnfoldingMap... maps) {
    EventDispatcher eventDispatcher = new EventDispatcher();

    MouseHandler mouseHandler = new MouseHandler(p, maps);
    KeyboardHandler keyboardHandler = new KeyboardHandler(p, maps);

    eventDispatcher.addBroadcaster(mouseHandler);
    eventDispatcher.addBroadcaster(keyboardHandler);

    for (UnfoldingMap map : maps) {
      eventDispatcher.register(map, PanMapEvent.TYPE_PAN, map.getId());
      eventDispatcher.register(map, ZoomMapEvent.TYPE_ZOOM, map.getId());
    }

    return eventDispatcher;
  }
Пример #3
0
  public void setup() {
    size(1200, 600, GLConstants.GLGRAPHICS);
    smooth();

    // Creates non-default dispatcher to register own broadcasters and listeners.
    eventDispatcher = new EventDispatcher();

    // Creates default mapDisplay
    Map map1 = new Map(this, "map1", 10, 10, 400, 400);
    maps.add(map1);
    Map map2 = new Map(this, "map2", 420, 10, 400, 400);
    maps.add(map2);
    Map map3 = new Map(this, "map3", 830, 10, 400, 400);
    maps.add(map3);

    debugDisplay = new DebugDisplay(this, map1.mapDisplay, 10, 390, 250, 150);

    MouseHandler mouseHandler = new MouseHandler(this, maps);
    eventDispatcher.addBroadcaster(mouseHandler);
    KeyboardHandler keyboardHandler = new KeyboardHandler(this, maps);
    eventDispatcher.addBroadcaster(keyboardHandler);

    // See class description for detailed explanation of these registrations.
    eventDispatcher.register(map1, "pan");
    eventDispatcher.register(map1, "zoom");
    eventDispatcher.register(map2, "pan", map1.getId(), map2.getId());
    eventDispatcher.register(map2, "zoom", map1.getId(), map2.getId());
    map2.setActive(true); // only map2 gets keyboard (non hit test) events
    eventDispatcher.register(map3, "pan", map1.getId(), map2.getId());
    eventDispatcher.register(map3, "zoom", map2.getId());

    // Prints all listeners
    log.debug("pan=" + eventDispatcher.typedScopedListeners.size());
    List<ScopedListeners> scopedListenersList = eventDispatcher.typedScopedListeners.get("pan");
    log.debug("pan-scopes=" + scopedListenersList.size());
    for (ScopedListeners scopedListeners : scopedListenersList) {
      log.debug(
          scopedListeners.scopeIds + " has + " + scopedListeners.listeners.size() + " listeners");
    }
  }