20 package net.sf.gridarta.gui.panel.pickmapchooser;
22 import java.awt.Component;
24 import java.io.IOException;
25 import javax.swing.BorderFactory;
26 import javax.swing.JPopupMenu;
27 import javax.swing.JTabbedPane;
28 import javax.swing.SwingConstants;
29 import javax.swing.event.ChangeListener;
49 import org.apache.log4j.Category;
50 import org.apache.log4j.Logger;
51 import org.jetbrains.annotations.NotNull;
52 import org.jetbrains.annotations.Nullable;
100 private final JTabbedPane
pickmapPanel =
new JTabbedPane(SwingConstants.TOP);
116 if (activeMapFolder != null) {
119 activeMapFolder = mapFolder;
120 if (activeMapFolder != null) {
125 pickmapChooserModel.
clear();
126 pickmapPanel.removeAll();
127 if (activeMapFolder != null) {
186 public void pickmapModifiedChanged(
final int index, @NotNull
final PickmapState<G, A, R> pickmapState) {
187 pickmapPanel.setTitleAt(index,
getTitle(pickmapState));
200 public PickmapChooserView(@NotNull
final PickmapChooserModel<G, A, R> pickmapChooserModel, @NotNull
final MapFolderTree<G, A, R> mapFolderTree, @NotNull
final MapArchObjectFactory<A> mapArchObjectFactory, @NotNull
final MapReaderFactory<G, A> mapReaderFactory, @NotNull
final MapManager<G, A, R> pickmapManager) {
206 pickmapChooserModel.addPickmapChooserListener(pickmapChooserModelListener);
208 mapFolderTree.addModelListener(mapFolderTreeListener);
220 pickmapPanel.setComponentPopupMenu(popupMenu);
229 pickmapPanel.addChangeListener(changeListener);
238 pickmapState.loadPickmap();
239 }
catch (
final IOException ex) {
240 LOG.warn(
"cannot load pickmap " + pickmapState.getFile() +
": " + ex.getMessage());
244 final int index = pickmapChooserModel.
addMapFile(pickmapState);
246 pickmapPanel.insertTab(
getTitle(pickmapState), null, mapView == null ? null : mapView.
getScrollPane(), null, index);
254 final int index = pickmapChooserModel.
removeMapFile(pickmapState);
256 pickmapPanel.remove(index);
266 final int index = pickmapChooserModel.
revertMapFile(oldPickmap, pickmapState);
270 pickmapPanel.setTitleAt(index,
getTitle(pickmapState));
272 pickmapPanel.setComponentAt(index, mapView == null ? null : mapView.
getScrollPane());
280 final int index = pickmapChooserModel.
indexOf(pickmapState);
284 pickmapPanel.setSelectedIndex(index);
294 final String name = pickmapState.getFile().getName();
297 return modified ? name +
" *" : name;
314 return pickmapPanel.getSelectedIndex();
326 if (activeMapFolder == null) {
331 throw new IOException(
"invalid pickmap name: " + pickmapName);
335 if (pickmapName.equals(pickmapState.getFile().getName())) {
336 throw new DuplicatePickmapException(pickmapName);
341 if (mapFile2.
getFile().isDirectory()) {
342 throw new IOException(
"pickmap file is a directory: " + mapFile2);
344 if (mapFile2.
getFile().exists()) {
345 throw new IOException(
"pickmap file exists: " + mapFile2);
348 final File dir = mapFile2.
getFile().getParentFile();
351 throw new IOException(
"cannot create directory: " + dir);
356 mapArchObject.setMapSize(mapSize);
357 mapArchObject.setMapName(pickmapName);
362 pickmapManager.
release(mapControl);
367 pickmapState = activeMapFolder.addPickmap(pickmapName, mapReaderFactory, pickmapManager);
369 throw new AssertionError(ex);
Interface for listeners interested in events of MapFolderTrees.
void save()
Saves the map to a file.
Component getPickmapPanel()
Returns the JTabbedPane with all pickmaps.
JScrollPane getScrollPane()
Returns the JScrollPane of this map view.
int removeMapFile(@NotNull final PickmapState< G, A, R > pickmapState)
Removes a map file.
static MapPath newMapPath(@NotNull final String string)
Creates a MapPath instance from string representation.
A MapManager manages all opened maps.
void release(@NotNull MapControl< G, A, R > mapControl)
Releases a MapControl instance.
Graphical User Interface of Gridarta.
Reading and writing of maps, handling of paths.
MapControl< G, A, R > newMap(@Nullable List< G > objects, @NotNull A mapArchObject, @Nullable MapFile mapFile, boolean interactive)
Creates a new map control without view.
Maintains the state of a pickmap file.
A factory for creating MapReader instances.
Factory for creating MapArchObject instances.
int indexOf(@NotNull final PickmapState< G, A, R > pickmapState)
Returns the index of a map file.
boolean isModified()
Return whether the map has been modified from the on-disk state.
void addChangeListener(@NotNull final ChangeListener changeListener)
Adds a ChangeListener to be notified when the selected pickmap tab changes.
static boolean isValidPickmapName(@NotNull final CharSequence name)
Returns whether a pickmap name is valid.
Class with constants used in Gridarta and derivates.
void clear()
Removes all map files.
final MapFolderTreeListener< G, A, R > mapFolderTreeListener
The listener attached to mapFolderTree.
A newMapArchObject(boolean addDefaultAttributes)
Creates a new MapArchObject instance.
MapModel< G, A, R > getMapModel()
Returns the map model.
Base package of all Gridarta classes.
A View for choosing pickmaps.
void activeMapFolderChanged(@Nullable MapFolder< G, A, R > mapFolder)
The active folder has changed.
Reflects a game object (object on a map).
void removePickmap(@NotNull final PickmapState< G, A, R > pickmapState)
Called when a pickmap has been removed from the model.
final JTabbedPane pickmapPanel
Panel with pickmaps.
int getSelectedIndex()
Returns the selected index.
void addPickmap(@NotNull final PickmapState< G, A, R > pickmapState)
Called when a new pickmap has been added to the model.
void revertPickmap(@NotNull final PickmapState< G, A, R > pickmapState, @NotNull final MapControl< G, A, R > oldPickmap)
Called when a pickmap in the model has been reverted.
Indicates that a pickmap name is not unique within its folder.
GameObjects are the objects based on Archetypes found on maps.
void newPickmap(@NotNull final Size2D mapSize, @NotNull final String pickmapName)
Add a new pickmap.
static final Category LOG
The Logger for printing log messages.
Stores all known MapFiles.
Utility class for MapPath related functions.
final MapArchObjectFactory< A > mapArchObjectFactory
The MapArchObjectFactory instance.
final MapFolderListener< G, A, R > mapFolderListener
The listener attached to activeMapFolder.
void setPopupMenu(@NotNull final JPopupMenu popupMenu)
Sets the popup menu to show.
MapFolder< G, A, R > activeMapFolder
The last known active folder.
Base classes for rendering maps.
void removeFolderListener(@NotNull final MapFolderListener< G, A, R > listenerMap)
Removes a MapFolderListener to be notified of events.
static final int SPACE_PICKMAP_ARCHETYPE_TOP
The height of rigid area between the two tab-panes on the pickmap- and archetype-panel.
final MapReaderFactory< G, A > mapReaderFactory
The map reader factory instance.
void setActivePickmap(@NotNull final PickmapState< G, A, R > pickmapState)
Sets the active pickmap.
final PickmapChooserModelListener< G, A, R > pickmapChooserModelListener
The PickmapChooserModelListener attached to pickmapChooserModel to detect modified pickmaps...
final MapFolderTree< G, A, R > mapFolderTree
The model to display.
String getTitle(@NotNull final PickmapState< G, A, R > pickmapState)
Returns the title of a pickmap to use as the tab name.
Currently nothing more than a marker interface for unification.
Interface for listeners interested in events of MapFolders.
final PickmapChooserModel< G, A, R > pickmapChooserModel
The attached PickmapChooserModel.
A map view consists of a map grid and a map cursor, and is attached to a map control.
File getFile()
Returns a File for this map file.
void addFolderListener(@NotNull final MapFolderListener< G, A, R > listenerMap)
Adds a MapFolderListener to be notified of events.
int addMapFile(@NotNull final PickmapState< G, A, R > pickmapState)
Adds a map file.
final MapManager< G, A, R > pickmapManager
The MapManager instance for loading pickmaps.
PickmapChooserView(@NotNull final PickmapChooserModel< G, A, R > pickmapChooserModel, @NotNull final MapFolderTree< G, A, R > mapFolderTree, @NotNull final MapArchObjectFactory< A > mapArchObjectFactory, @NotNull final MapReaderFactory< G, A > mapReaderFactory, @NotNull final MapManager< G, A, R > pickmapManager)
Creates a new instance.
The location of a map file with a map directory.
int revertMapFile(@NotNull final MapControl< G, A, R > oldPickmap, @NotNull final PickmapState< G, A, R > pickmapState)
Reverts a map file.
Interface for MapArchObjects.
Indicates that a folder or pickmap name is invalid.
Model class representing a folder of MapFiles.
The class Size2D represents a 2d rectangular area.