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;
60 import net.
sf.japi.swing.action.ActionBuilder;
61 import net.
sf.japi.swing.action.ActionBuilderFactory;
62 import net.
sf.japi.swing.action.ActionMethod;
63 import org.apache.log4j.Category;
64 import org.apache.log4j.Logger;
65 import org.jetbrains.annotations.NotNull;
66 import org.jetbrains.annotations.Nullable;
86 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
195 reloadPickmap(mapControl.getMapModel().getMapFile().getFile());
208 public void mapSizeChanged(@NotNull
final Size2D newSize) {
218 public void mapObjectsChanged(@NotNull
final Set<G> gameObjects, @NotNull
final Set<G> transientGameObjects) {
228 public void mapFileChanged(@Nullable
final MapFile oldMapFile) {
233 public void modifiedChanged() {
256 public void pickmapModifiedChanged(
final int index, @NotNull
final PickmapState<G, A, R> pickmapState) {
269 public void stateChanged(
final ChangeEvent e) {
272 if (mapControl != null) {
292 public void mapCreated(@NotNull
final MapControl<G, A, R> mapControl,
final boolean interactive) {
293 if (!mapControl.isPickmap()) {
294 mapControl.addMapControlListener(mapControlListener);
305 if (!mapControl.isPickmap()) {
306 mapControl.removeMapControlListener(mapControlListener);
320 public void lockedChanged(
final boolean locked) {
338 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) {
346 ACTION_BUILDER.createToggles(
true,
this,
"lockAllPickmaps");
347 pickmapChooserModel.addPickmapChooserListener(pickmapChooserModelListener);
348 view = pickmapChooserView;
351 mapManager.addMapManagerListener(mapManagerListener);
352 pickmapSettings.addPickmapSettingsListener(pickmapSettingsListener);
369 if (pickmapState != null) {
372 }
catch (
final IOException ex) {
373 LOG.warn(
"cannot reload pickmap " + pickmapState.
getFile() +
": " + ex.getMessage());
391 if (pickmap == null) {
404 final Collection<MapControl<G, A, R>> unsavedPickmaps =
new HashSet<>();
407 final int result = ACTION_BUILDER.showConfirmDialog(parent, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE,
"pickmapConfirmSaveChanges", pickmap.getMapModel().getMapArchObject().getMapName());
408 if (result == JOptionPane.YES_OPTION) {
411 }
catch (
final IOException e) {
412 ACTION_BUILDER.showMessageDialog(parent,
"encodeMapFile", pickmap.getMapModel().getMapFile(), e.getMessage());
415 if (pickmap.getMapModel().isModified()) {
418 }
else if (result == JOptionPane.CANCEL_OPTION || result == JOptionPane.CLOSED_OPTION) {
432 if (selectedIndex == -1) {
436 return pickmapChooserModel.
get(selectedIndex);
437 }
catch (
final IndexOutOfBoundsException ignored) {
450 if (this.active == active) {
461 if (gameObject.isEqual(selection)) {
472 if (pickmap == null) {
473 return Collections.emptyList();
545 final MapControl<G, A, R> pickmapControl = currentPickmapState == null ? null : currentPickmapState.getPickmap();
546 if (this.currentPickmapState == currentPickmapState && currentPickmapControl == pickmapControl) {
550 if (currentPickmapControl != null) {
556 currentPickmapControl = pickmapControl;
558 if (currentPickmapControl != null) {
572 pickmapSettings.
setLocked(lockAllPickmaps);
579 if (aAddNewPickmap != null) {
583 if (aOpenPickmapMap != null) {
587 if (aDeletePickmap != null) {
591 if (aSavePickmap != null) {
595 if (aRevertPickmap != null) {
625 if (pickmapState == null) {
630 final File file = pickmapState.
getFile();
633 }
catch (
final IOException ex) {
653 if (pickmapState == null) {
658 if (!ACTION_BUILDER.showQuestionDialog(parent,
"confirmDeletePickmap", pickmapState.
getFile().getName())) {
662 pickmapState.
remove(
true);
678 if (currentPickmapState == null || currentPickmapControl == null || !currentPickmapControl.
getMapModel().
isModified()) {
683 if (pickmapState == null) {
690 }
catch (
final IOException e) {
691 ACTION_BUILDER.showMessageDialog(parent,
"encodeMapFile", pickmapState, e.getMessage());
710 if (pickmapState == null) {
714 final File mapFileFile = pickmapState.
getFile();
715 if (currentPickmapControl == null || !currentPickmapControl.
getMapModel().
isModified() || !mapFileFile.exists()) {
720 if (mapControl == null) {
726 if (mapControlMapFile == null) {
731 if (!mapControlMapFile.
getFile().exists()) {
732 ACTION_BUILDER.showMessageDialog(parent,
"revertPickmapGone", mapControlMapFile);
736 if (mapModel.
isModified() && !ACTION_BUILDER.showQuestionDialog(parent,
"confirmRevertPickmap", mapFileFile.getName())) {
742 }
catch (
final IOException ex) {
743 ACTION_BUILDER.showMessageDialog(null,
"pickmapIOError", mapFileFile.getName(), ex.getMessage());
752 public void setAction(@NotNull
final Action action, @NotNull
final String name) {
753 if (name.equals(
"addNewPickmap")) {
754 aAddNewPickmap = action;
755 }
else if (name.equals(
"openPickmapMap")) {
756 aOpenPickmapMap = action;
757 }
else if (name.equals(
"deletePickmap")) {
758 aDeletePickmap = action;
759 }
else if (name.equals(
"savePickmap")) {
760 aSavePickmap = action;
761 }
else if (name.equals(
"revertPickmap")) {
762 aRevertPickmap = action;
764 throw new IllegalArgumentException();
boolean doSavePickmap(final boolean performAction)
Performs or checks availability of the "save pickmap" action.
final PickmapSettings pickmapSettings
The PickmapSettings to use.
void setLockAllPickmaps(final boolean lockAllPickmaps)
Set whether all pickmaps are locked.
Component getPickmapPanel()
Returns the JTabbedPane with all pickmaps.
Interface for event listeners that are interested in changes on PickmapSettings.
List< G > getSelections()
Returns the selected game objects.
A MapModel reflects the data of a map.
A MapManager manages all opened maps.
PickmapState< G, A, R > getPickmap(@NotNull final File file)
Returns the pickmap by file name.
void getUnsavedPickmaps(@NotNull final Collection< MapControl< G, A, R >> unsavedMaps)
Returns all unsaved map controls of this model.
Graphical User Interface of Gridarta.
boolean doRevertPickmap(final boolean performAction)
Performs or checks availability of the "revert pickmap" action.
Maintains the state of a pickmap file.
This package contains the framework for validating maps.
final PickmapChooserView< G, A, R > view
The view for this control.
boolean active
Set if the pickmap panel is active.
void revert()
Reverts this pickmap to its underlying map file.
Interface for listeners listening on MapModel events.
void setAction(@NotNull final Action action, @NotNull final String name)
Sets the Action instance for this editor action.
boolean isModified()
Return whether the map has been modified from the on-disk state.
Action aDeletePickmap
Action called for "delete active pickmap".
Stores all existing MapViews.
void addChangeListener(@NotNull final ChangeListener changeListener)
Adds a ChangeListener to be notified when the selected pickmap tab changes.
void addNewPickmap()
Invoked when user wants to open a new pickmap.
void save()
Saves this pickmap.
void addMapModelListener(@NotNull MapModelListener< G, A, R > listener)
Register a map listener.
final Component parent
The parent component for error messages.
void deletePickmap()
Invoked when the user wants to delete the active pickmap.
void openPickmapMap()
Open active pickmap as normal map for extensive editing.
MapModel< G, A, R > getMapModel()
Returns the map model.
boolean canExit()
Invoked when the user wants to exit the application.
PickmapState< G, A, R > getSelectedPickmap()
Returns the selected pickmap.
void savePickmap()
Save current active pickmap.
static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final String defaultValue)
Returns the value of a key.
final MapManagerListener< G, A, R > mapManagerListener
The MapManagerListener to track existing pickmaps.
PickmapState< G, A, R > get(final int index)
Returns a map file by index.
void showNewPickmapDialog()
Shows a dialog for creating a new pickmap.
Base package of all Gridarta classes.
void revertPickmap()
Invoked when user wants to revert the current pickmap to previously saved state.
Reflects a game object (object on a map).
void reportLoadError(@Nullable File file, @NotNull String message)
MapView< G, A, R > openMapFileWithView(@NotNull final MapFile mapFile, @Nullable final Point viewPosition, @Nullable final Point centerSquare)
Load a map file and create a map view.
PickmapState< G, A, R > currentPickmapState
The current active pickmap on top.
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)
Create a PickmapChooserControl.
void setActive(final boolean active)
Called whenever this tab becomes active or inactive.
MapControl< G, A, R > getPickmap()
Returns the MapControl representing this pickmap.
Interface for listeners listening to MapManager changes.
Component getComponent()
Returns the component to show in the object chooser.
int getSelectedIndex()
Returns the selected index.
Interface for listeners listening on changes in MapControl instances.
void reloadPickmap(@NotNull final File file)
Reload a pickmap.
GameObjects are the objects based on Archetypes found on maps.
void addMapControlListener(@NotNull MapControlListener< G, A, R > listener)
Registers a MapControlListener.
Stores all known MapFiles.
void remove(final boolean deleteFile)
Removes this pickmap from its folder.
void setPopupMenu(@NotNull final JPopupMenu popupMenu)
Sets the popup menu to show.
Base classes for rendering maps.
void setLocked(boolean locked)
Sets whether pickmaps are immutable.
List< G > getSelectedGameObjects()
Return all selected game objects.
boolean doOpenPickmapMap(final boolean performAction)
Performs or checks availability of the "open pickmap map" action.
void removeMapModelListener(@NotNull MapModelListener< G, A, R > listener)
Unregister a map listener.
File getFile()
Returns the underlying map file.
final PickmapChooserModelListener< G, A, R > pickmapChooserModelListener
The pickmap chooser listener used to track the currently active pickmap.
Utility class to create NewMapDialog instances.
Utility class for ActionBuilder related functions.
MapView< G, A, R > getMapViewFrame(@NotNull final MapControl< G, A, R > mapControl)
Returns the last used view of a MapControl.
Action aAddNewPickmap
Action called for "add new pickmap".
void fireActivePickmapChanged(@Nullable final PickmapState< G, A, R > pickmapState)
Notifies all listeners that the active pickmap has changes.
Action aSavePickmap
Action called for "save active pickmap".
Manages the pickmap panel and most pickmap-related code in general.
MapCursor< G, A, R > getMapCursor()
Returns the MapCursor of this view.
Currently nothing more than a marker interface for unification.
A map view consists of a map grid and a map cursor, and is attached to a map control.
MapFile getMapFile()
Returns the map file.
boolean isLockAllPickmaps()
Return whether all pickmaps are locked.
File getFile()
Returns a File for this map file.
boolean isMatching(@NotNull final G gameObject)
Returns whether the current selection matches the given game object.
boolean isLocked()
Returns whether pickmaps are immutable.
An interface for classes that collect errors.
final MapViewsManager< G, A, R > mapViewsManager
The MapViewsManager.
void refresh()
Update the actions' states.
final FileControl< G, A, R > fileControl
The FileControl to use.
final ChangeListener changeListener
The ChangeListener attached to {link view}.
final MapControlListener< G, A, R > mapControlListener
The map control listener which is registered to the selected pickmap.
final PickmapChooserModel< G, A, R > pickmapChooserModel
The PickmapChooserModel to control.
void setCurrentPickmap(@Nullable final PickmapState< G, A, R > currentPickmapState)
Set the currently active pickmap.
G getSelection()
Returns the selected game object.
G getSelectedGameObject()
Return one selected game object.
static final ActionBuilder ACTION_BUILDER
Action Builder.
Action aOpenPickmapMap
Action called for "open active pickmap as map".
String getTitle()
Returns the title to display in the object chooser.
final NewMapDialogFactory< G, A, R > newMapDialogFactory
The factory for creating new pickmaps.
void setPopupMenu(@NotNull final JPopupMenu popupMenu)
Sets the popup menu to show.
final PickmapSettingsListener pickmapSettingsListener
The PickmapSettingsListener attached to pickmapSettings.
final void deactivate()
Cursor gets deactivated.
PickmapState< G, A, R > getOpenPickmapMap()
Determine if "open pickmap as map" is enabled.
final MapFolderTree< G, A, R > mapFolderTree
The model.
boolean doDeletePickmap(final boolean performAction)
Performs or checks availability of the "delete pickmap" action.
Action aRevertPickmap
Action called for "revert active pickmap".
The location of a map file with a map directory.
static final Category LOG
The Logger for printing log messages.
MapControl< G, A, R > currentPickmapControl
The current active pickmap on top.
Interface for MapArchObjects.
Interface for classes being part of the object chooser.
Container for settings that affect pickmaps.
boolean doAddNewPickmap(final boolean performAction)
Performs or checks availability of the "add new pickmap" action.
The class Size2D represents a 2d rectangular area.
final MapModelListener< G, A, R > mapModelListener
The MapModelListener which is registered to the selected pickmap.
void removeMapControlListener(@NotNull MapControlListener< G, A, R > listener)
Unregisters a MapControlListener.