Gridarta Editor
ShrinkMapSizeDialogManager.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.dialog.shrinkmapsize;
21 
22 import java.util.HashMap;
23 import java.util.Map;
30 import org.jetbrains.annotations.NotNull;
31 import org.jetbrains.annotations.Nullable;
32 
38 public class ShrinkMapSizeDialogManager<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> {
39 
43  @NotNull
44  private final Map<MapView<G, A, R>, ShrinkMapSizeDialog<G, A, R>> dialogs = new HashMap<>();
45 
49  @NotNull
51 
52  @Override
53  public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) {
54  // ignore
55  }
56 
57  @Override
58  public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) {
59  // ignore
60  }
61 
62  @Override
63  public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) {
64  disposeDialog(mapView);
65  }
66 
67  };
68 
73  public ShrinkMapSizeDialogManager(@NotNull final MapViewManager<G, A, R> mapViewManager) {
74  mapViewManager.addMapViewManagerListener(mapViewManagerListener);
75  }
76 
81  public void showDialog(@NotNull final MapView<G, A, R> mapView) {
82  synchronized (dialogs) {
83  final ShrinkMapSizeDialog<G, A, R> oldDialog = dialogs.get(mapView);
84  if (oldDialog != null) {
85  oldDialog.getDialog().toFront();
86  return;
87  }
88 
89  final ShrinkMapSizeDialog<G, A, R> pane = new ShrinkMapSizeDialog<>(this, mapView);
90  dialogs.put(mapView, pane);
91  }
92  }
93 
99  public void disposeDialog(@NotNull final MapView<G, A, R> mapView) {
100  final ShrinkMapSizeDialog<G, A, R> dialog;
101  synchronized (dialogs) {
102  dialog = dialogs.remove(mapView);
103  if (dialog == null) {
104  return;
105  }
106  }
107 
108  dialog.getDialog().dispose();
109  }
110 
111 }
Graphical User Interface of Gridarta.
void showDialog(@NotNull final MapView< G, A, R > mapView)
Shows a dialog to shrink the map size.
final Map< MapView< G, A, R >, ShrinkMapSizeDialog< G, A, R > > dialogs
Dialog for each map view.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
Definition: GameObject.java:36
Dialog to ask which empty borders to remove from a map.
void disposeDialog(@NotNull final MapView< G, A, R > mapView)
Disposes a dialog.
GameObjects are the objects based on Archetypes found on maps.
Interface for listeners interested in events related to MapViewManager instances. ...
Base classes for rendering maps.
Window getDialog()
Returns the JDialog for this instance.
ShrinkMapSizeDialogManager(@NotNull final MapViewManager< G, A, R > mapViewManager)
Creates a new instance.
A map view consists of a map grid and a map cursor, and is attached to a map control.
Definition: MapView.java:43
final MapViewManagerListener< G, A, R > mapViewManagerListener
The map view manager listener to detect closed map views.