 |
Gridarta Editor
|
Go to the documentation of this file.
20 package net.sf.gridarta.gui.panel.pickmapchooser;
22 import java.awt.Component;
24 import java.io.IOException;
25 import java.util.Collection;
26 import java.util.Collections;
27 import java.util.HashSet;
28 import java.util.List;
30 import javax.swing.Action;
31 import javax.swing.JOptionPane;
32 import javax.swing.JPopupMenu;
33 import javax.swing.event.ChangeEvent;
34 import javax.swing.event.ChangeListener;
59 import net.
sf.japi.swing.action.ActionBuilder;
60 import net.
sf.japi.swing.action.ActionBuilderFactory;
61 import net.
sf.japi.swing.action.ActionMethod;
62 import org.apache.log4j.Category;
63 import org.apache.log4j.Logger;
64 import org.jetbrains.annotations.NotNull;
65 import org.jetbrains.annotations.Nullable;
85 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
191 reloadPickmap(mapControl.getMapModel().getMapFile().getFile());
202 public void mapSizeChanged(@NotNull
final Size2D newSize) {
212 public void mapObjectsChanged(@NotNull
final Set<G> gameObjects, @NotNull
final Set<G> transientGameObjects) {
222 public void mapFileChanged(@Nullable
final MapFile oldMapFile) {
227 public void modifiedChanged() {
250 public void pickmapModifiedChanged(
final int index, @NotNull
final PickmapState<G, A, R> pickmapState) {
263 public void stateChanged(
final ChangeEvent e) {
266 if (mapControl !=
null) {
286 public void mapCreated(@NotNull
final MapControl<G, A, R> mapControl,
final boolean interactive) {
287 if (!mapControl.isPickmap()) {
299 if (!mapControl.isPickmap()) {
325 public PickmapChooserControl(@NotNull
final PickmapChooserModel<G, A, R> pickmapChooserModel, @NotNull
final PickmapSettings pickmapSettings, @NotNull
final NewMapDialogFactory<G, A, R> newMapDialogFactory, @NotNull
final MapFolderTree<G, A, R> mapFolderTree, @NotNull
final MapManager<G, A, R> mapManager, @NotNull
final Component
parent, @NotNull
final MapViewsManager<G, A, R> mapViewsManager, @NotNull
final FileControl<G, A, R> fileControl, @NotNull
final PickmapChooserView<G, A, R> pickmapChooserView) {
335 view = pickmapChooserView;
355 if (pickmapState !=
null) {
358 }
catch (
final IOException ex) {
359 LOG.warn(
"cannot reload pickmap " + pickmapState.
getFile() +
": " + ex.getMessage());
377 if (pickmap ==
null) {
390 final Collection<MapControl<G, A, R>> unsavedPickmaps =
new HashSet<>();
393 final int result =
ACTION_BUILDER.showConfirmDialog(
parent, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE,
"pickmapConfirmSaveChanges", pickmap.getMapModel().getMapArchObject().getMapName());
394 if (result == JOptionPane.YES_OPTION) {
397 }
catch (
final IOException e) {
398 ACTION_BUILDER.showMessageDialog(
parent,
"encodeMapFile", pickmap.getMapModel().getMapFile(), e.getMessage());
401 if (pickmap.getMapModel().isModified()) {
404 }
else if (result == JOptionPane.CANCEL_OPTION || result == JOptionPane.CLOSED_OPTION) {
418 if (selectedIndex == -1) {
423 }
catch (
final IndexOutOfBoundsException ignored) {
436 if (this.active ==
active) {
447 if (gameObject.isEqual(selection)) {
458 if (pickmap ==
null) {
459 return Collections.emptyList();
603 if (pickmapState ==
null) {
608 final File file = pickmapState.
getFile();
611 }
catch (
final IOException ex) {
631 if (pickmapState ==
null) {
640 pickmapState.
remove(
true);
661 if (pickmapState ==
null) {
668 }
catch (
final IOException e) {
688 if (pickmapState ==
null) {
692 final File mapFileFile = pickmapState.
getFile();
698 if (mapControl ==
null) {
704 if (mapControlMapFile ==
null) {
709 if (!mapControlMapFile.
getFile().exists()) {
720 }
catch (
final IOException ex) {
721 ACTION_BUILDER.showMessageDialog(
null,
"pickmapIOError", mapFileFile.getName(), ex.getMessage());
730 public void setAction(@NotNull
final Action action, @NotNull
final String
name) {
732 case "addNewPickmap":
736 case "openPickmapMap":
740 case "deletePickmap":
748 case "revertPickmap":
753 throw new IllegalArgumentException(
"unsupported action name: " +
name);
A MapModel reflects the data of a map.
PickmapChooserControl(@NotNull final PickmapChooserModel< G, A, R > pickmapChooserModel, @NotNull final PickmapSettings pickmapSettings, @NotNull final NewMapDialogFactory< G, A, R > newMapDialogFactory, @NotNull final MapFolderTree< G, A, R > mapFolderTree, @NotNull final MapManager< G, A, R > mapManager, @NotNull final Component parent, @NotNull final MapViewsManager< G, A, R > mapViewsManager, @NotNull final FileControl< G, A, R > fileControl, @NotNull final PickmapChooserView< G, A, R > pickmapChooserView)
Creates a new instance.
List< G > getSelectedGameObjects()
Return all selected game objects.
File getFile()
Returns the underlying map file.
PickmapState< G, A, R > getOpenPickmapMap()
Determines if "open pickmap as map" is enabled.
A MapManager manages all opened maps.
List< G > getSelections()
Returns the selected game objects.
Action aRevertPickmap
Action called for "revert active pickmap".
PickmapState< G, A, R > get(final int index)
Returns a map file by index.
void setPopupMenu(@NotNull final JPopupMenu popupMenu)
Sets the popup menu to show.
void setActive(final boolean active)
Called whenever this tab becomes active or inactive.
Base package of all Gridarta classes.
final void deactivate()
Cursor gets deactivated.
Interface for classes being part of the object chooser.
void revert()
Reverts this pickmap to its underlying map file.
PickmapState< G, A, R > getPickmap(@NotNull final File file)
Returns the pickmap by file name.
Stores all known MapFiles.
Interface for event listeners that are interested in changes on {}.
final Component parent
The parent component for error messages.
final MapViewsManager< G, A, R > mapViewsManager
The MapViewsManager.
Interface for listeners listening to MapManager changes.
final PickmapChooserView< G, A, R > view
The view for this control.
final PickmapChooserModelListener< G, A, R > pickmapChooserModelListener
The pickmap chooser listener used to track the currently active pickmap.
boolean doOpenPickmapMap(final boolean performAction)
Performs or checks availability of the "open pickmap map" action.
void fireActivePickmapChanged(@Nullable final PickmapState< G, A, R > pickmapState)
Notifies all listeners that the active pickmap has changes.
final ChangeListener changeListener
The ChangeListener attached to {link view}.
void remove(final boolean deleteFile)
Removes this pickmap from its folder.
void addNewPickmap()
Invoked when user wants to open a new pickmap.
G getSelectedGameObject()
Return one selected game object.
void reportLoadError(@Nullable File file, @NotNull String message)
Reflects a game object (object on a map).
void setLockAllPickmaps(final boolean lockAllPickmaps)
Sets whether all pickmaps are locked.
static final Category LOG
The Logger for printing log messages.
void savePickmap()
Saves the current active pickmap.
void addMapModelListener(@NotNull MapModelListener< G, A, R > listener)
Register a map listener.
boolean doAddNewPickmap(final boolean performAction)
Performs or checks availability of the "add new pickmap" action.
boolean isModified()
Return whether the map has been modified from the on-disk state.
final MapControlListener< G, A, R > mapControlListener
The map control listener which is registered to the selected pickmap.
Graphical User Interface of Gridarta.
MapCursor< G, A, R > getMapCursor()
Returns the MapCursor of this view.
boolean doSavePickmap(final boolean performAction)
Performs or checks availability of the "save pickmap" action.
void save()
Saves this pickmap.
void setLocked(boolean locked)
Sets whether pickmaps are immutable.
GameObjects are the objects based on Archetypes found on maps.
void showNewPickmapDialog()
Shows a dialog for creating a new pickmap.
boolean doDeletePickmap(final boolean performAction)
Performs or checks availability of the "delete pickmap" action.
String getTitle()
Returns the title to display in the object chooser.
Action aAddNewPickmap
Action called for "add new pickmap".
final MapFolderTree< G, A, R > mapFolderTree
The model.
PickmapState< G, A, R > currentPickmapState
The current active pickmap on top.
boolean canExit()
Invoked when the user wants to exit the application.
void removeMapModelListener(@NotNull MapModelListener< G, A, R > listener)
Unregister a map listener.
Interface for MapArchObjects.
File getFile()
Returns a File for this map file.
PickmapState< G, A, R > getSelectedPickmap()
Returns the selected pickmap.
An interface for classes that collect errors.
Utility class to create NewMapDialog instances.
A map view consists of a map grid and a map cursor, and is attached to a map control.
boolean isLocked()
Returns whether pickmaps are immutable.
MapControl< G, A, R > currentPickmapControl
The current active pickmap on top.
void revertPickmap()
Invoked when user wants to revert the current pickmap to previously saved state.
int getSelectedIndex()
Returns the selected index.
void refresh()
Updates the actions' states.
boolean doRevertPickmap(final boolean performAction)
Performs or checks availability of the "revert pickmap" action.
This package contains the framework for validating maps.
boolean isMatching(@NotNull final G gameObject)
Returns whether the current selection matches the given game object.
static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final String defaultValue)
Returns the value of a key.
Action aOpenPickmapMap
Action called for "open active pickmap as map".
Action aSavePickmap
Action called for "save active pickmap".
The location of a map file with a map directory.
Component getPickmapPanel()
Returns the JTabbedPane with all pickmaps.
void setPopupMenu(@NotNull final JPopupMenu popupMenu)
Sets the popup menu to show.
Maintains the state of a pickmap file.
final MapModelListener< G, A, R > mapModelListener
The MapModelListener which is registered to the selected pickmap.
Action aDeletePickmap
Action called for "delete active pickmap".
Interface for listeners listening on MapModel events.
void addPickmapChooserListener(@NotNull final PickmapChooserModelListener< G, A, R > pickmapChooserModelListener)
Adds a PickmapChooserModelListener to be notified.
void addMapControlListener(@NotNull MapControlListener< G, A, R > listener)
Registers a MapControlListener.
final PickmapChooserModel< G, A, R > pickmapChooserModel
The PickmapChooserModel to control.
final NewMapDialogFactory< G, A, R > newMapDialogFactory
The factory for creating new pickmaps.
void addPickmapSettingsListener(@NotNull PickmapSettingsListener listener)
Adds a PickmapSettingsListener to be notified about changes.
void getUnsavedPickmaps(@NotNull final Collection< MapControl< G, A, R >> unsavedMaps)
Returns all unsaved map controls of this model.
Component getComponent()
Returns the component to show in the object chooser.
Base classes for rendering maps.
final PickmapSettingsListener pickmapSettingsListener
The PickmapSettingsListener attached to {}.
void addChangeListener(@NotNull final ChangeListener changeListener)
Adds a ChangeListener to be notified when the selected pickmap tab changes.
void reloadPickmap(@NotNull final File file)
Reloads a pickmap.
boolean active
Set if the pickmap panel is active.
Currently nothing more than a marker interface for unification.
Interface for listeners listening on changes in MapControl instances.
boolean isLockAllPickmaps()
Returns whether all pickmaps are locked.
void removeMapControlListener(@NotNull MapControlListener< G, A, R > listener)
Unregisters a MapControlListener.
Utility class for ActionBuilder related functions.
MapModel< G, A, R > getMapModel()
Returns the map model.
void openPickmapMap()
Opens the active pickmap as a normal map for extensive editing.
void deletePickmap()
Invoked when the user wants to delete the active pickmap.
G getSelection()
Returns the selected game object.
final FileControl< G, A, R > fileControl
The FileControl to use.
void setAction(@NotNull final Action action, @NotNull final String name)
Sets the Action instance for this editor action.
MapView< G, A, R > openMapFileWithView(@NotNull final MapFile mapFile, @Nullable final Point viewPosition)
Loads a map file and creates a map view.
MapFile getMapFile()
Returns the map file.
Manages the pickmap panel and most pickmap-related code in general.
Stores all existing MapViews.
The class Size2D represents a 2d rectangular area.
final MapManagerListener< G, A, R > mapManagerListener
The MapManagerListener to track existing pickmaps.
void setCurrentPickmap(@Nullable final PickmapState< G, A, R > currentPickmapState)
Sets the currently active pickmap.
Container for settings that affect pickmaps.
static final ActionBuilder ACTION_BUILDER
Action Builder.
MapView< G, A, R > getMapViewFrame(@NotNull final MapControl< G, A, R > mapControl)
Returns the last used view of a MapControl.
MapControl< G, A, R > getPickmap()
Returns the MapControl representing this pickmap.
final PickmapSettings pickmapSettings
The PickmapSettings to use.