20 package net.sf.gridarta.gui.delayedmapmodel;
22 import java.lang.reflect.InvocationTargetException;
23 import java.util.Collection;
24 import java.util.IdentityHashMap;
26 import java.util.Map.Entry;
28 import java.util.concurrent.CopyOnWriteArrayList;
29 import javax.swing.SwingUtilities;
45 import org.apache.log4j.Category;
46 import org.apache.log4j.Logger;
47 import org.jetbrains.annotations.NotNull;
48 import org.jetbrains.annotations.Nullable;
66 private static final long DELAY = 500L;
79 private final Map<MapModel<G, A, R>, MapModelListenerImpl>
mapModelListeners =
new IdentityHashMap<>();
98 private final Object
sync =
new Object();
111 private final Collection<DelayedMapModelListener<G, A, R>>
listeners =
new CopyOnWriteArrayList<>();
126 public void mapCreated(@NotNull
final MapControl<G, A, R> mapControl,
final boolean interactive) {
128 final MapModelListenerImpl mapModelListener =
new MapModelListenerImpl(mapModel);
131 final MapArchObjectListenerImpl mapArchObjectListener =
new MapArchObjectListenerImpl(mapModel);
132 mapModel.
getMapArchObject().addMapArchObjectListener(mapArchObjectListener);
146 if (mapModelListener !=
null) {
150 if (mapArchObjectListener !=
null) {
151 mapModel.
getMapArchObject().removeMapArchObjectListener(mapArchObjectListener);
153 synchronized (
sync) {
163 private final Thread
thread =
new Thread(
new Runnable() {
168 final Map<MapModel<G, A, R>, Void> mapModels =
new IdentityHashMap<>();
169 while (!Thread.currentThread().isInterrupted()) {
171 final long now = System.currentTimeMillis();
172 synchronized (
sync) {
176 final long diff =
timeout - now;
190 SwingUtilities.invokeAndWait(
new Runnable() {
197 listener.mapModelChanged(mapModel);
202 }
catch (
final InvocationTargetException ex) {
203 LOG.error(
"InvocationTargetException: " + ex.getMessage(), ex);
207 }
catch (
final InterruptedException ignored) {
208 Thread.currentThread().interrupt();
226 public void preExitNotify() {
230 }
catch (
final InterruptedException ignored) {
231 Thread.currentThread().interrupt();
232 LOG.warn(
"DelayedMapModelListenerManager was interrupted");
237 public void appExitNotify() {
242 public void waitExitNotify() {
247 exiter.addExiterListener(exiterListener);
265 listener.mapModelChanged(mapControl.getMapModel());
282 final long now = System.currentTimeMillis();
283 synchronized (
sync) {
294 final long now = System.currentTimeMillis();
295 synchronized (
sync) {
335 public void mapObjectsChanged(@NotNull
final Set<G> gameObjects, @NotNull
final Set<G> transientGameObjects) {