20 package net.sf.gridarta.gui.map.mapactions;
22 import java.awt.Frame;
23 import java.awt.Point;
25 import java.io.IOException;
26 import java.util.ArrayList;
27 import java.util.Collection;
28 import java.util.Iterator;
29 import javax.swing.Action;
30 import javax.swing.filechooser.FileFilter;
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 net.
sf.japi.swing.action.ToggleAction;
63 import org.jetbrains.annotations.NotNull;
64 import org.jetbrains.annotations.Nullable;
70 public class MapActions<G
extends GameObject<G, A, R>, A extends
MapArchObject<A>, R extends
Archetype<G, A, R>> implements
EditorAction,
MapCursorListener<G, A, R>,
MapViewManagerListener<G, A, R> {
76 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
82 private final String[]
directionsMap = {
"North",
"East",
"South",
"West",
"NorthEast",
"SouthEast",
"SouthWest",
"NorthWest",
"Up",
"Down" };
166 private final Action[]
aDirections =
new Action[directionsMap.length];
172 private final Action[]
aCreateTiles =
new Action[directionsMap.length];
259 public void gridVisibleChanged(
final boolean gridVisible) {
264 public void lightVisibleChanged(
final boolean lightVisible) {
269 public void smoothingChanged(
final boolean smoothing) {
274 public void tileStretchingChanged(
final boolean tileStretchingChanged) {
279 public void doubleFacesChanged(
final boolean doubleFaces) {
284 public void alphaTypeChanged(
final int alphaType) {
289 public void editTypeChanged(
final int editType) {
294 public void autojoinChanged(
final boolean autojoin) {
313 public void mapCreated(@NotNull
final MapControl<G, A, R> mapControl,
final boolean interactive) {
336 public void mapMetaChanged() {
341 public void mapSizeChanged(@NotNull
final Size2D mapSize) {
363 public MapActions(@NotNull
final Frame helpParent, @NotNull
final MapManager<G, A, R> mapManager, @NotNull
final MapViewManager<G, A, R> mapViewManager, @NotNull
final ExitMatcher<G, A, R> exitMatcher, @NotNull
final FileFilter mapFileFilter, @NotNull
final SelectedSquareModel<G, A, R> selectedSquareModel,
final boolean allowRandomMapParameters, @NotNull
final MapPropertiesDialogFactory<G, A, R> mapPropertiesDialogFactory, @NotNull
final MapViewSettings mapViewSettings, @NotNull
final MapViewsManager<G, A, R> mapViewsManager, @NotNull
final EnterMap<G, A, R> enterMap, @NotNull
final ProjectSettings projectSettings) {
376 mapViewSettings.addMapViewSettingsListener(mapViewSettingsListener);
377 mapManager.addMapManagerListener(mapManagerListener);
557 final G exit = exitIterator.
next();
559 assert mapSquare != null;
738 public void enterMap(@NotNull
final MapFile mapFile, @Nullable
final Point destinationPoint) {
746 if (aGridVisible != null) {
752 if (aSmoothing != null) {
758 if (aDoubleFaces != null) {
764 if (aTileShow != null) {
766 aTileShow.setEnabled(
doTileShow(
false,
false));
770 if (aTileStretching != null) {
776 if (aMapCreateView != null) {
780 if (aMapProperties != null) {
784 if (aAutoJoin != null) {
786 aAutoJoin.setEnabled(
doAutoJoin(
false,
false));
790 if (aEnterExit != null) {
794 if (aNextExit != null) {
798 if (aPrevExit != null) {
802 if (aDeleteUnknownObjects != null) {
807 if (aDirections[direction.ordinal()] != null) {
808 aDirections[direction.ordinal()].setEnabled(
doEnterMap(
false, direction));
812 if (aCreateTiles[direction.ordinal()] != null) {
813 aCreateTiles[direction.ordinal()].setEnabled(
doCreateTile(
false, direction));
816 if (aShrinkMapSize != null) {
830 private boolean doGridVisible(
final boolean performAction,
final boolean gridVisible) {
845 private boolean doSmoothing(
final boolean performAction,
final boolean smoothing) {
860 private boolean doTileStretching(
final boolean performAction,
final boolean tileStretching) {
876 private boolean doDoubleFaces(
final boolean performAction,
final boolean doubleFaces) {
892 private boolean doTileShow(
final boolean performAction,
final boolean tileShow) {
903 if (mapView == null) {
921 if (mapView == null) {
940 private boolean doAutoJoin(
final boolean performAction,
final boolean autoJoin) {
955 if (mapView == null) {
961 if (selectedExit == null) {
963 if (cursorExit == null) {
973 if (!enterMap.
enterExit(mapView, exit, allowRandomMapParameters)) {
988 if (mapView == null) {
1006 if (mapView == null) {
1010 if (performAction) {
1024 if (mapView == null) {
1028 if (performAction) {
1031 final Collection<G> gameObjectsToDelete =
new ArrayList<>();
1032 for (
final Iterable<G> mapSquare : mapModel) {
1033 for (
final G gameObject : mapSquare) {
1034 if (gameObject.isHead() && gameObject.hasUndefinedArchetype()) {
1035 gameObjectsToDelete.add(gameObject);
1039 if (!gameObjectsToDelete.isEmpty()) {
1042 for (
final G gameObject : gameObjectsToDelete) {
1043 mapModel.removeGameObject(gameObject,
false);
1046 mapModel.endTransaction();
1062 if (mapView == null) {
1067 if (path.isEmpty()) {
1071 if (performAction) {
1088 if (mapView == null) {
1094 final String path = currentMapArchObj.getTilePath(direction);
1095 if (!path.isEmpty()) {
1103 final String newPath = currentMapArchObj.calculateTilePath(direction, currentMapModel.
getMapFile());
1106 if (mapFile.
getFile().isDirectory()) {
1109 if (mapFile.
getFile().exists()) {
1113 if (performAction) {
1114 final File dir = mapFile.
getFile().getParentFile();
1115 if (!dir.exists()) {
1116 if (!dir.mkdirs()) {
1117 ACTION_BUILDER.showMessageDialog(mapView.
getComponent(),
"createTileErrorMakeDirectories", dir.toString());
1122 final A mapArchObject = currentMapArchObj.createClone();
1127 mapArchObject.setTilePath(direction2,
"");
1133 }
catch (
final IOException ex) {
1136 mapManager.
release(mapControl);
1153 if (mapView == null) {
1157 if (performAction) {
1158 shrinkMapSizeDialogManager.
showDialog(mapView);
1165 public void setAction(@NotNull
final Action action, @NotNull
final String name) {
1166 if (name.equals(
"mapCreateView")) {
1167 aMapCreateView = action;
1168 }
else if (name.equals(
"mapProperties")) {
1169 aMapProperties = action;
1170 }
else if (name.equals(
"autoJoin")) {
1171 aAutoJoin = (ToggleAction) action;
1172 }
else if (name.equals(
"shrinkMapSize")) {
1173 aShrinkMapSize = action;
1174 }
else if (name.equals(
"enterExit")) {
1175 aEnterExit = action;
1176 }
else if (name.equals(
"nextExit")) {
1178 }
else if (name.equals(
"prevExit")) {
1180 }
else if (name.equals(
"deleteUnknownObjects")) {
1181 aDeleteUnknownObjects = action;
1182 }
else if (name.equals(
"gridVisible")) {
1183 aGridVisible = (ToggleAction) action;
1184 }
else if (name.equals(
"smoothing")) {
1185 aSmoothing = (ToggleAction) action;
1186 }
else if (name.equals(
"doubleFaces")) {
1187 aDoubleFaces = (ToggleAction) action;
1188 }
else if (name.equals(
"tileShow")) {
1189 aTileShow = (ToggleAction) action;
1190 }
else if (name.equals(
"tileStretching")) {
1191 aTileStretching = (ToggleAction) action;
1194 for (i = 0; i < directionsMap.length; i++) {
1195 if (name.equals(
"enter" + directionsMap[i] +
"Map")) {
1196 aDirections[i] = action;
1200 if (name.equals(
"createTile" + directionsMap[i])) {
1201 aCreateTiles[i] = action;
1205 if (i >= directionsMap.length) {
1206 throw new IllegalArgumentException();
1214 if (currentMapView != null) {
1217 currentMapView = mapView;
1218 if (currentMapView != null) {
void setAction(@NotNull final Action action, @NotNull final String name)
Sets the Action instance for this editor action.
void save()
Saves the map to a file.
void enterExit()
Try to load the map where the selected map-exit points to.
G getSelectedGameObject()
Returns the currently selected GameObject within this list (currently selected MapSquare).
JScrollPane getScrollPane()
Returns the JScrollPane of this map view.
final Frame helpParent
The parent frame for help windows.
boolean doPrevExit(final boolean performAction)
Executes the "prev exit" action.
Interface for listeners listening on map arch object changes.
ToggleAction aTileShow
Action for "tile show".
final ExitMatcher< G, A, R > exitMatcher
The ExitMatcher for selecting exit game objects.
boolean isGridVisible()
Action method for "grid visible".
Manager for ShrinkMapSizeDialog instances.
static MapPath newMapPath(@NotNull final String string)
Creates a MapPath instance from string representation.
final MapViewSettings mapViewSettings
The MapViewSettings instance to use.
void mapCreateView()
Action method for "create view".
MapSquare< G, A, R > getMapSquare()
A MapModel reflects the data of a map.
A MapManager manages all opened maps.
void release(@NotNull MapControl< G, A, R > mapControl)
Releases a MapControl instance.
boolean isAutojoin()
Returns whether "autojoin" is enabled.
Graphical User Interface of Gridarta.
boolean isTileStretching()
Action method for "tile-stretching".
MapControl< G, A, R > newMap(@Nullable List< G > objects, @NotNull A mapArchObject, @Nullable MapFile mapFile, boolean interactive)
Creates a new map control without view.
void enterEastMap()
Action method for entering the east map.
Settings that apply to a project.
Iterator for iterating over top-level game object of a map model.
ToggleAction aDoubleFaces
Action for "draw double faces".
void showDialog(@NotNull final MapView< G, A, R > mapView)
Shows a dialog to shrink the map size.
void setAutoJoin(final boolean autoJoin)
Action method for "autoJoin".
void setTileStretching(boolean tileStretching)
Sets the tile-stretching setting.
MapView< G, A, R > newMapView(@NotNull final MapControl< G, A, R > mapControl, @Nullable final Point viewPosition, @Nullable final Point centerSquare)
Creates a new map view.
boolean doEnterMap(final boolean performAction, @NotNull final Direction direction)
Executes the "enter map" action.
void setAutojoin(boolean autojoin)
Sets the "autojoin" state.
void setTileStretching(final boolean tileStretching)
Sets whether tile-stretching of the current map is active.
void enterDownMap()
Action method for entering the down map.
boolean isAutoJoin()
Action method for "autojoin".
void showDialog(@NotNull Component parent, @NotNull Frame helpParent, @NotNull MapModel< G, A, R > mapModel, @NotNull FileFilter mapFileFilter)
Show a dialog querying the user for map properties.
final MapArchObjectListener mapArchObjectListener
The MapArchObjectListener attached to currentMapView.
void enterSouthWestMap()
Action method for entering the south west map.
MapView< G, A, R > currentMapView
The current map view, or.
Stores all existing MapViews.
final FileFilter mapFileFilter
The Swing file filter to use.
void createTileDown()
Action method for creating down tiled map.
Action aNextExit
Action for "next exit".
void deleteUnknownObjects()
Deletes all game objects referencing unknown archetypes.
void mapProperties()
Action method for "map properties".
ToggleAction aTileStretching
Action for "tile-stretching visible".
boolean doAutoJoin(final boolean performAction, final boolean autoJoin)
Executes the "auto join" action.
final MapManagerListener< G, A, R > mapManagerListener
The map manager listener which is attached to the current map if the current map is tracked...
MapControl< G, A, R > getMapControl()
Return the controller of this view.
final Action [] aDirections
Action for "enter xxx map".
boolean isSmoothing()
Returns the smoothing setting.
void enterNorthMap()
Action method for entering the north map.
void mapViewClosing(@NotNull final MapView< G, A, R > mapView)
This event handler is called when a map view is to be closed.
MapActions(@NotNull final Frame helpParent, @NotNull final MapManager< G, A, R > mapManager, @NotNull final MapViewManager< G, A, R > mapViewManager, @NotNull final ExitMatcher< G, A, R > exitMatcher, @NotNull final FileFilter mapFileFilter, @NotNull final SelectedSquareModel< G, A, R > selectedSquareModel, final boolean allowRandomMapParameters, @NotNull final MapPropertiesDialogFactory< G, A, R > mapPropertiesDialogFactory, @NotNull final MapViewSettings mapViewSettings, @NotNull final MapViewsManager< G, A, R > mapViewsManager, @NotNull final EnterMap< G, A, R > enterMap, @NotNull final ProjectSettings projectSettings)
Create a new instance.
Point getLocation()
Get position of cursor.
MapModel< G, A, R > getMapModel()
Returns the map model.
final MapPropertiesDialogFactory< G, A, R > mapPropertiesDialogFactory
The MapPropertiesDialogFactory to use.
Base package of all Gridarta classes.
boolean doCreateTile(final boolean performAction, @NotNull final Direction direction)
Executes the "create tile" action.
boolean isTileShow()
Action method for "tile show".
final Action [] aCreateTiles
Action for "create tile xxx".
void setDoubleFaces(boolean doubleFaces)
Sets whether double faces should be drawn double height.
void mapCursorChangedSize()
Called whenever the map cursor's map grid size has changed.
Reflects a game object (object on a map).
boolean enterExit(@NotNull final MapView< G, A, R > mapView, @NotNull final GameObject< G, A, R > exit, final boolean allowRandomMapParameters)
Opens the map an exit game object points to.
An Iterator that filters another iterator according to a GameObjectMatcher.
ToggleAction aAutoJoin
Action for "autojoin".
boolean isGridVisible()
Get the visibility of the grid.
boolean doTileStretching(final boolean performAction, final boolean tileStretching)
Executes the "tile-stretching" action.
void setGridVisible(final boolean gridVisible)
Sets whether the grid of the current map should be visible.
void createTileNorthEast()
Action method for creating northeast tiled map.
Interface for listeners listening to MapManager changes.
void enterMap(@NotNull final MapFile mapFile, @Nullable final Point destinationPoint)
Enters a map.
Selects valid exit game objects from maps.
void nextExit()
Select the next exit.
void createTileWest()
Action method for creating west tiled map.
Action aEnterExit
Action for "enter exit".
void createTileSouth()
Action method for creating south tiled map.
final ProjectSettings projectSettings
The ProjectSettings.
Interface for event listeners that are interested in changes on MapViewSettings.
void updateActions()
Update the actions' state.
void enterNorthWestMap()
Action method for entering the north west map.
Container for settings that affect the rendering of maps.
void mapViewCreated(@NotNull final MapView< G, A, R > mapView)
This event handler is called when a map view was created.
GameObjects are the objects based on Archetypes found on maps.
void enterUpMap()
Action method for entering the up map.
void mapCursorChangedMode()
This event handler is called when MapCursor changes mode (drag, select).
Action aMapProperties
Action for "map properties".
final SelectedSquareModel< G, A, R > selectedSquareModel
The SelectedSquareModel to use.
G getValidExit(@NotNull final MapModel< G, A, R > mapModel, @NotNull final Point point)
Returns an exit game object on a given map square having exit information.
void createTileSouthEast()
Action method for creating southeast tiled map.
final boolean allowRandomMapParameters
Whether exit paths may point to random maps.
Point getMapLocation()
Returns the coordinate on the map.
Interface for listeners interested in events related to MapViewManager instances. ...
void setSmoothing(boolean smoothing)
Sets the smoothing setting.
Utility class for MapPath related functions.
Displays the contents of the currently selected map square.
Manages actions in the "map" menu.
boolean isSmoothing()
Action method for "smoothing".
ToggleAction aGridVisible
Action for "grid visible".
void createTileNorthWest()
Action method for creating northwest tiled map.
final MapViewSettingsListener mapViewSettingsListener
The MapViewSettingsListener attached to mapViewSettings.
Base classes for rendering maps.
void createTileUp()
Action method for creating up tiled map.
boolean doGridVisible(final boolean performAction, final boolean gridVisible)
Executes the "grid visible" action.
void enterSouthEastMap()
Action method for entering the south east map.
void createTileNorth()
Action method for creating north tiled map.
void mapCursorChangedGameObject(@Nullable final MapSquare< G, A, R > mapSquare, @Nullable final G gameObject)
Called whenever the selected game object has changed.
void setDoubleFaces(final boolean doubleFaces)
Sets whether double faces on the current map should be shown.
final MapManager< G, A, R > mapManager
The MapManager.
Action aDeleteUnknownObjects
Action for "delete unknown objects".
void activeMapViewChanged(@Nullable final MapView< G, A, R > mapView)
This event handler is called when the current map view has changed.
A getMapArchObject()
Returns the Map Arch Object with the meta information about the map.
void mapCursorChangedPos(@NotNull final Point location)
This event handler is called when MapCursor has moved.
MapCursor< G, A, R > getMapCursor()
Returns the MapCursor of this view.
boolean doMapCreateView(final boolean performAction)
Executes the "map create view" action.
void enterSouthMap()
Action method for entering the south map.
Currently nothing more than a marker interface for unification.
Action aMapCreateView
Action for "create view".
boolean doDeleteUnknownObjects(final boolean performAction)
Executes the "delete unknown objects" action.
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 doSmoothing(final boolean performAction, final boolean smoothing)
Executes the "smoothing" action.
File getFile()
Returns a File for this map file.
void prevExit()
Select the previous exit.
void enterNorthEastMap()
Action method for entering the north east map.
Action aPrevExit
Action for "previous exit".
boolean doEnterExit(final boolean performAction)
Executes the "enter exit" action.
void shrinkMapSize()
Action method for "shrink map size".
final String [] directionsMap
Possible directions for "enter xxx map".
Factory for creating map property dialog instances.
final EnterMap< G, A, R > enterMap
The EnterMap instance to use.
File getMapsDirectory()
Returns the default maps directory.
static final ActionBuilder ACTION_BUILDER
Action Builder.
void beginTransaction(@NotNull String name)
Starts a new transaction.
The model component of the selected square control.
boolean doTileShow(final boolean performAction, final boolean tileShow)
Executes the "tile show" action.
boolean doDoubleFaces(final boolean performAction, final boolean doubleFaces)
Executes the "double faces" action.
Component getComponent()
Returns the component associated with this MapView that can be used as parent for dialogs...
boolean doNextExit(final boolean performAction)
Executes the "next exit" action.
final ShrinkMapSizeDialogManager< G, A, R > shrinkMapSizeDialogManager
The ShrinkMapSizeDialogManager instance.
Interface for listeners listening to MapCursor related events.
boolean isDoubleFaces()
Action method for "double faces".
boolean doMapProperties(final boolean performAction)
Executes the "map properties" action.
void setSmoothing(final boolean smoothing)
Sets whether smoothing of the current map is active.
ToggleAction aSmoothing
Action for "smoothing".
void createTileEast()
Action method for creating east tiled map.
boolean isTileStretching()
Returns the tile-stretching setting.
void createTileSouthWest()
Action method for creating southwest tiled map.
Action aShrinkMapSize
Action for "shrink map size".
final MapViewsManager< G, A, R > mapViewsManager
The MapViewsManager.
void setGridVisible(boolean gridVisible)
Set the visibility of the grid.
boolean doShrinkMapSize(final boolean performAction)
Executes the "shrink map size" action.
The location of a map file with a map directory.
void enterWestMap()
Action method for entering the west map.
void selectExit(@NotNull final MapView< G, A, R > mapView, final int direction)
Selects an exit square.
Interface for MapArchObjects.
void setTileShow(final boolean tileShow)
Action method for "tile show".
boolean isDoubleFaces()
Get whether double faces are drawn double height.
The class Size2D represents a 2d rectangular area.
boolean enterMap(@NotNull final MapView< G, A, R > mapView, @NotNull final MapPath mapPath, @NotNull final Direction direction, @Nullable final Point destinationPoint)
Enters a map wanted.