Gridarta Editor
MapUserListenerManager.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2015 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.gui.mapuserlistener;
21 
22 import java.util.IdentityHashMap;
23 import java.util.Map;
34 import org.jetbrains.annotations.NotNull;
35 import org.jetbrains.annotations.Nullable;
36 
41 public class MapUserListenerManager<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> {
42 
46  @NotNull
48 
52  @NotNull
54 
58  @NotNull
59  private final Map<MapView<G, A, R>, MapMouseListener<G, A, R>> mapUserListeners = new IdentityHashMap<>();
60 
65  @NotNull
67 
68  @Override
69  public void currentMapChanged(@Nullable final MapControl<G, A, R> mapControl) {
70  // ignore
71  }
72 
73  @Override
74  public void mapCreated(@NotNull final MapControl<G, A, R> mapControl, final boolean interactive) {
75  mapViewsManager.addMapViewsListener(mapControl, mapViewsListener);
76  }
77 
78  @Override
79  public void mapClosing(@NotNull final MapControl<G, A, R> mapControl) {
80  // ignore
81  }
82 
83  @Override
84  public void mapClosed(@NotNull final MapControl<G, A, R> mapControl) {
85  mapViewsManager.removeMapViewsListener(mapControl, mapViewsListener);
86  }
87 
88  };
89 
94  @NotNull
96 
97  @Override
98  public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) {
99  final MapMouseListener<G, A, R> mapMouseListener = new MapMouseListener<>(mapView.getRenderer(), toolPalette, mapView);
100  mapUserListeners.put(mapView, mapMouseListener);
101  }
102 
103  @Override
104  public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) {
105  final MapMouseListener<G, A, R> mapMouseListener = mapUserListeners.remove(mapView);
106  assert mapMouseListener != null;
107  mapMouseListener.closeNotify();
108  }
109 
110  };
111 
117  public MapUserListenerManager(@NotNull final ToolPalette<G, A, R> toolPalette, @NotNull final MapViewsManager<G, A, R> mapViewsManager) {
118  this.toolPalette = toolPalette;
119  this.mapViewsManager = mapViewsManager;
120  }
121 
126  public void addMapManager(@NotNull final MapManager<G, A, R> mapManager) {
127  mapManager.addMapManagerListener(mapManagerListener);
128  }
129 
130 }
void addMapViewsListener(@NotNull final MapControl< G, A, R > mapControl, @NotNull final MapViewsListener< G, A, R > listener)
Adds a MapViewsListener to be notified of events.
void removeMapViewsListener(@NotNull final MapControl< G, A, R > mapControl, @NotNull final MapViewsListener< G, A, R > listener)
Removes a MapViewsListener to be notified of events.
A MapManager manages all opened maps.
Definition: MapManager.java:37
final MapManagerListener< G, A, R > mapManagerListener
The MapManagerListener for tracking MapControl instances.
Graphical User Interface of Gridarta.
final Map< MapView< G, A, R >, MapMouseListener< G, A, R > > mapUserListeners
Maps MapView instance to attached MapMouseListener.
Tracks map views and attaches/detaches MapMouseListener instances.
This package handles tools for manipulating maps.
void closeNotify()
Must be called when this object is freed.
Base package of all Gridarta classes.
final ToolPalette< G, A, R > toolPalette
The ToolPalette to attach to.
void addMapManager(@NotNull final MapManager< G, A, R > mapManager)
Registers a MapManager to track.
Reflects a game object (object on a map).
Definition: GameObject.java:36
Interface for listeners listening to MapManager changes.
GameObjects are the objects based on Archetypes found on maps.
Tracks mouse actions and calls the appropriate MouseOpListeners.
final MapViewsListener< G, A, R > mapViewsListener
The MapViewsListener attached to all MapControl instances.
Base classes for rendering maps.
Pane for controlling which mouse to select and configure tools for.
Interface for listeners interested in MapViewsManager related events.
Currently nothing more than a marker interface for unification.
Definition: MapControl.java:35
A map view consists of a map grid and a map cursor, and is attached to a map control.
Definition: MapView.java:43
MapUserListenerManager(@NotNull final ToolPalette< G, A, R > toolPalette, @NotNull final MapViewsManager< G, A, R > mapViewsManager)
Creates a new instance.
final MapViewsManager< G, A, R > mapViewsManager
The MapViewsManager.