Gridarta Editor
GoMapDialogManager.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.gomap;
21 
22 import java.awt.Window;
23 import javax.swing.Action;
33 import net.sf.gridarta.utils.Exiter;
35 import net.sf.japi.swing.action.ActionMethod;
36 import org.apache.log4j.Category;
37 import org.apache.log4j.Logger;
38 import org.jetbrains.annotations.NotNull;
39 
44 public class GoMapDialogManager<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction {
45 
49  @NotNull
50  private static final Category LOG = Logger.getLogger(GoMapDialogManager.class);
51 
55  @NotNull
56  private final Window parent;
57 
61  @NotNull
63 
67  @NotNull
68  private final MapsIndex mapsIndex = new MapsIndex();
69 
73  @NotNull
75 
84  public GoMapDialogManager(@NotNull final Window parent, @NotNull final MapManager<G, A, R> mapManager, @NotNull final MapViewsManager<G, A, R> mapViewsManager, @NotNull final ProjectSettings projectSettings, @NotNull final Exiter exiter) {
85  this.parent = parent;
86  this.mapViewsManager = mapViewsManager;
87  mapsIndexer = new MapsIndexer<>(mapsIndex, mapManager, projectSettings);
88  mapsIndexer.start();
89  exiter.addExiterListener(new ExiterListener() {
90 
91  @Override
92  public void preExitNotify() {
93  // ignore
94  }
95 
96  @Override
97  public void appExitNotify() {
98  try {
99  mapsIndexer.stop();
100  } catch (final InterruptedException ignored) {
101  Thread.currentThread().interrupt();
102  LOG.warn("Waiting for MapsIndexer to terminate was interrupted");
103  }
104  }
105 
106  @Override
107  public void waitExitNotify() {
108  // ignore
109  }
110 
111  });
112  }
113 
117  @ActionMethod
118  public void goMap() {
119  new GoMapDialog<>(parent, mapsIndex, mapViewsManager).showDialog();
120  }
121 
122  @Override
123  public void setAction(@NotNull final Action action, @NotNull final String name) {
124  }
125 
126 }
Indexes maps by map name.
Definition: MapsIndex.java:29
final Window parent
The parent Window for go map dialogs.
GoMapDialogManager(@NotNull final Window parent, @NotNull final MapManager< G, A, R > mapManager, @NotNull final MapViewsManager< G, A, R > mapViewsManager, @NotNull final ProjectSettings projectSettings, @NotNull final Exiter exiter)
Creates a new instance.
A MapManager manages all opened maps.
Definition: MapManager.java:37
Graphical User Interface of Gridarta.
static final Category LOG
The Logger for printing log messages.
Settings that apply to a project.
Maintains a MapsIndex for the maps directory.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
Definition: GameObject.java:36
Exits the application.
Definition: Exiter.java:28
A global editor action.
Interface for listeners interested in Exiter related events.
GameObjects are the objects based on Archetypes found on maps.
Base classes for rendering maps.
final MapsIndexer< G, A, R > mapsIndexer
The MapsIndexer indexing mapsIndex.
A dialog to ask the user for a map to open.
void setAction(@NotNull final Action action, @NotNull final String name)
Sets the Action instance for this editor action.
final MapsIndex mapsIndex
The MapsIndex indexing all maps.
void goMap()
Action method to open the "go map" dialog.
final MapViewsManager< G, A, R > mapViewsManager
The MapViewsManager for opening maps.