20 package net.sf.gridarta.gui.mapfiles;
23 import java.util.ArrayList;
24 import java.util.Collection;
25 import java.util.Collections;
26 import java.util.Iterator;
27 import java.util.List;
28 import java.util.regex.Pattern;
37 import org.jetbrains.annotations.NotNull;
38 import org.jetbrains.annotations.Nullable;
70 private final Object
sync =
new Object();
93 private final List<PickmapState<G, A, R>>
pickmapStates =
new ArrayList<>();
107 if (parent == null ? !name.isEmpty() : !PATTERN_VALID_MAP_FOLDER_NAME.matcher(name).matches()) {
131 if (parent == null) {
144 return parent != null ?
new File(parent.
getDir(),
name) : baseDir;
157 synchronized (
sync) {
159 pickmapStates.add(pickmapState);
162 listenerMap.pickmapAdded(pickmapState);
173 synchronized (
sync) {
174 final int index = pickmapStates.indexOf(pickmapState);
176 throw new IllegalArgumentException();
179 final File file = pickmapState.getFile();
182 pickmapStates.remove(index);
185 listenerMap.pickmapRemoved(pickmapState);
187 pickmapState.freePickmap();
197 synchronized (
sync) {
198 if (pickmapStates.isEmpty()) {
201 pickmapState = pickmapStates.get(pickmapStates.size() - 1);
213 public Iterator<PickmapState<G, A, R>>
iterator() {
214 return Collections.unmodifiableList(pickmapStates).iterator();
222 return pickmapStates.size();
230 listeners.
add(listenerMap);
238 listeners.
remove(listenerMap);
247 pickmapState.getUnsavedPickmaps(unsavedPickmaps);
258 listenerMap.pickmapReverted(pickmapState, oldPickmap);
final Object sync
The synchronization object for accesses to pickmapStates.
A MapManager manages all opened maps.
final MapViewsManager< G, A, R > mapViewsManager
The MapViewsManager.
Graphical User Interface of Gridarta.
T [] getListeners()
Returns an array of all the listeners.
Reading and writing of maps, handling of paths.
void firePickmapReverted(@NotNull final PickmapState< G, A, R > pickmapState, @NotNull final MapControl< G, A, R > oldPickmap)
Notifies all listeners about a reverted pickmap.
final MapFolder< G, A, R > parent
The parent folder, or.
PickmapState< G, A, R > addPickmap(@NotNull final String name, @NotNull final MapReaderFactory< G, A > mapReaderFactory, @NotNull final MapManager< G, A, R > pickmapManager)
Adds a new PickmapState to this folder.
A factory for creating MapReader instances.
File getDir()
Returns the base directory.
Stores all existing MapViews.
final EventListenerList2< MapFolderListener< G, A, R > > listeners
The registered event listeners.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
void removePickmap(@NotNull final PickmapState< G, A, R > pickmapState, final boolean deleteFile)
Removes a PickmapState from this folder.
void getUnsavedPickmaps(@NotNull final Collection< MapControl< G, A, R >> unsavedPickmaps)
Returns all unsaved MapFiles in this folder.
final File baseDir
The base directory for folder file names.
int getPickmaps()
Returns the number of pickmaps in this folder.
Iterator< PickmapState< G, A, R > > iterator()
Returns an Iterator returning all pickmaps of this folder in arbitrary order.
void remove(@NotNull final T listener)
Removes a listener.
GameObjects are the objects based on Archetypes found on maps.
void add(@NotNull final T listener)
Adds a listener.
final List< PickmapState< G, A, R > > pickmapStates
The pickmaps of this folder.
static final Pattern PATTERN_VALID_MAP_FOLDER_NAME
The Pattern that matches valid map folder names.
MapFolder(@Nullable final MapFolder< G, A, R > parent, @NotNull final String name, @NotNull final File baseDir, @NotNull final MapViewsManager< G, A, R > mapViewsManager)
Creates a new instance.
Base classes for rendering maps.
void removeFolderListener(@NotNull final MapFolderListener< G, A, R > listenerMap)
Removes a MapFolderListener to be notified of events.
final String name
The folder's name.
String getName()
Returns the name.
Type-safe version of EventListenerList.
Currently nothing more than a marker interface for unification.
Interface for listeners interested in events of MapFolders.
void addFolderListener(@NotNull final MapFolderListener< G, A, R > listenerMap)
Adds a MapFolderListener to be notified of events.
void removeAllPickmaps(final boolean deleteFile)
Removes all PickmapState from this folder.
MapFolder< G, A, R > getParent()
Returns the parent folder.
Interface for MapArchObjects.
Indicates that a folder or pickmap name is invalid.
Model class representing a folder of MapFiles.