 |
Gridarta Editor
|
Go to the documentation of this file.
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;
30 import javax.swing.Action;
31 import javax.swing.filechooser.FileFilter;
62 import net.
sf.japi.swing.action.ActionBuilder;
63 import net.
sf.japi.swing.action.ActionBuilderFactory;
64 import net.
sf.japi.swing.action.ActionMethod;
65 import net.
sf.japi.swing.action.ToggleAction;
66 import org.jetbrains.annotations.NotNull;
67 import org.jetbrains.annotations.Nullable;
73 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> {
79 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
85 private final String @NotNull []
directionsMap = {
"North",
"East",
"South",
"West",
"NorthEast",
"SouthEast",
"SouthWest",
"NorthWest",
"Up",
"Down" };
262 public void gridVisibleChanged(
final boolean gridVisible) {
267 public void lightVisibleChanged(
final boolean lightVisible) {
272 public void smoothingChanged(
final boolean smoothing) {
277 public void tileStretchingChanged(
final boolean tileStretchingChanged) {
282 public void doubleFacesChanged(
final boolean doubleFaces) {
287 public void alphaTypeChanged(
final int alphaType) {
292 public void editTypeChanged(
final int editType) {
297 public void autojoinChanged(
final boolean autojoin) {
316 public void mapCreated(@NotNull
final MapControl<G, A, R> mapControl,
final boolean interactive) {
339 public void mapMetaChanged() {
344 public void mapSizeChanged(@NotNull
final Size2D mapSize) {
357 public void mapSizeChanged(@NotNull
final Size2D newSize) {
367 public void mapObjectsChanged(@NotNull
final Set<G> gameObjects, @NotNull
final Set<G> transientGameObjects) {
377 public void mapFileChanged(@Nullable
final MapFile oldMapFile) {
382 public void modifiedChanged() {
404 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) {
597 if (exitIterator.hasNext()) {
598 mapView.setCursorLocation(exitIterator.next().getMapSquare().getMapLocation());
776 public void enterMap(@NotNull
final MapFile mapFile, @Nullable
final Point destinationPoint) {
849 private boolean doGridVisible(
final boolean performAction,
final boolean gridVisible) {
864 private boolean doSmoothing(
final boolean performAction,
final boolean smoothing) {
879 private boolean doTileStretching(
final boolean performAction,
final boolean tileStretching) {
895 private boolean doDoubleFaces(
final boolean performAction,
final boolean doubleFaces) {
911 private boolean doTileShow(
final boolean performAction,
final boolean tileShow) {
922 if (mapView ==
null) {
940 if (mapView ==
null) {
959 private boolean doAutoJoin(
final boolean performAction,
final boolean autoJoin) {
974 if (mapView ==
null) {
980 if (selectedExit ==
null) {
982 if (cursorExit ==
null) {
1007 if (mapView ==
null) {
1011 if (performAction) {
1025 if (mapView ==
null) {
1029 if (performAction) {
1043 if (mapView ==
null) {
1047 if (performAction) {
1050 final Collection<G> gameObjectsToDelete =
new ArrayList<>();
1051 for (
final Iterable<G> mapSquare : mapModel) {
1052 for (
final G gameObject : mapSquare) {
1053 if (gameObject.isHead() && gameObject.hasUndefinedArchetype()) {
1054 gameObjectsToDelete.add(gameObject);
1058 if (!gameObjectsToDelete.isEmpty()) {
1059 mapModel.beginTransaction(
"delete undefined objects");
1061 for (
final G gameObject : gameObjectsToDelete) {
1062 mapModel.removeGameObject(gameObject,
false);
1065 mapModel.endTransaction();
1081 if (mapView ==
null) {
1086 if (path.isEmpty()) {
1090 if (performAction) {
1107 if (mapView ==
null) {
1113 final String path = currentMapArchObj.getTilePath(direction);
1114 if (!path.isEmpty()) {
1122 final String newPath = currentMapArchObj.calculateTilePath(direction, currentMapModel.
getMapFile());
1125 if (mapFile.
getFile().isDirectory()) {
1128 if (mapFile.
getFile().exists()) {
1132 if (performAction) {
1133 final File dir = mapFile.
getFile().getParentFile();
1134 if (!dir.exists()) {
1135 if (!dir.mkdirs()) {
1141 final A mapArchObject = currentMapArchObj.createClone();
1146 mapArchObject.setTilePath(direction2,
"");
1152 }
catch (
final IOException ex) {
1172 if (mapView ==
null) {
1176 if (performAction) {
1184 public void setAction(@NotNull
final Action action, @NotNull
final String
name) {
1186 case "mapCreateView":
1190 case "mapProperties":
1198 case "shrinkMapSize":
1214 case "deleteUnknownObjects":
1234 case "tileStretching":
1252 throw new IllegalArgumentException(
"unsupported action name: " +
name);
void activeMapViewChanged(@Nullable final MapView< G, A, R > mapView)
This event handler is called when the current map view has changed.
void setTileStretching(final boolean tileStretching)
Sets whether tile-stretching of the current map is active.
Manager for ShrinkMapSizeDialog instances.
final FileFilter mapFileFilter
The Swing file filter to use.
void setTileStretching(boolean tileStretching)
Sets the tile-stretching setting.
A MapModel reflects the data of a map.
boolean doTileShow(final boolean performAction, final boolean tileShow)
Executes the "tile show" action.
boolean isSmoothing()
Action method for "smoothing".
void shrinkMapSize()
Action method for "shrink map size".
A getMapArchObject()
Returns the Map Arch Object with the meta information about the map.
boolean isSmoothing()
Returns the smoothing setting.
A MapManager manages all opened maps.
void setGridVisible(final boolean gridVisible)
Sets whether the grid of the current map should be visible.
void enterDownMap()
Action method for entering the down map.
final Action[] aCreateTiles
Action for "create tile xxx".
final MapModelListener< G, A, R > mapModelListener
The MapModelListener attached to currentMapView.
void enterNorthWestMap()
Action method for entering the north west map.
MapControl< G, A, R > getMapControl()
Return the controller of this view.
void enterSouthMap()
Action method for entering the south map.
final Frame helpParent
The parent frame for help windows.
Base package of all Gridarta classes.
void setDoubleFaces(boolean doubleFaces)
Sets whether double faces should be drawn double height.
void setTileShow(final boolean tileShow)
Action method for "tile show".
boolean doDeleteUnknownObjects(final boolean performAction)
Executes the "delete unknown objects" action.
boolean isGridVisible()
Get the visibility of the grid.
void enterNorthMap()
Action method for entering the north map.
boolean isTileStretching()
Returns the tile-stretching setting.
Component getComponent()
Returns the component associated with this MapView that can be used as parent for dialogs.
void addMapViewSettingsListener(@NotNull MapViewSettingsListener listener)
Register a MapViewSettingsListener.
void createTileNorthWest()
Action method for creating northwest tiled map.
Interface for listeners listening on map arch object changes.
final MapManager< G, A, R > mapManager
The MapManager.
void setGridVisible(boolean gridVisible)
Set the visibility of the grid.
Iterator for iterating over top-level game object of a map model.
boolean isAutojoin()
Returns whether "autojoin" is enabled.
Interface for listeners listening to MapManager changes.
boolean isAutoJoin()
Action method for "autojoin".
void createTileSouthWest()
Action method for creating southwest tiled map.
void enterMap(@NotNull final MapFile mapFile, @Nullable final Point destinationPoint)
Enters a map.
Interface for listeners interested in events related to {} instances.
ToggleAction aTileShow
Action for "tile show".
MapControl< G, A, R > newMap(@Nullable List< G > objects, @NotNull A mapArchObject, @Nullable MapFile mapFile, boolean interactive)
Creates a new map control without view.
final MapViewSettings mapViewSettings
The MapViewSettings instance to use.
void setSmoothing(final boolean smoothing)
Sets whether smoothing of the current map is active.
Action aMapProperties
Action for "map properties".
void addMapManagerListener(@NotNull MapManagerListener< G, A, R > listener)
Adds a MapManagerListener to be notified.
Action aEnterExit
Action for "enter exit".
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.
static MapPath newMapPath(@NotNull final String string)
Creates a MapPath instance from string representation.
void setDoubleFaces(final boolean doubleFaces)
Sets whether double faces on the current map should be shown.
void mapViewClosing(@NotNull final MapView< G, A, R > mapView)
This event handler is called when a map view is to be closed.
boolean doDoubleFaces(final boolean performAction, final boolean doubleFaces)
Executes the "double faces" action.
Reflects a game object (object on a map).
Utility class for MapPath related functions.
final EnterMap< G, A, R > enterMap
The EnterMap instance to use.
Container for settings that affect the rendering of maps.
final MapPropertiesDialogFactory< G, A, R > mapPropertiesDialogFactory
The MapPropertiesDialogFactory to use.
Selects valid exit game objects from maps.
final MapViewsManager< G, A, R > mapViewsManager
The MapViewsManager.
void createTileDown()
Action method for creating down tiled map.
void addMapModelListener(@NotNull MapModelListener< G, A, R > listener)
Register a map listener.
void mapCreateView()
Action method for "create view".
Interface for listeners listening to MapCursor related events.
void mapCursorChangedMode()
This event handler is called when MapCursor changes mode (drag, select).
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)
Creates a new instance.
boolean doNextExit(final boolean performAction)
Executes the "next exit" action.
void prevExit()
Selects the previous exit.
Graphical User Interface of Gridarta.
boolean doEnterMap(final boolean performAction, @NotNull final Direction direction)
Executes the "enter map" action.
void enterUpMap()
Action method for entering the up map.
MapCursor< G, A, R > getMapCursor()
Returns the MapCursor of this view.
MapView< G, A, R > currentMapView
The current map view, or.
void setAutojoin(boolean autojoin)
Sets the "autojoin" state.
ToggleAction aSmoothing
Action for "smoothing".
void enterSouthEastMap()
Action method for entering the south east map.
Action aDeleteUnknownObjects
Action for "delete unknown objects".
GameObjects are the objects based on Archetypes found on maps.
void createTileNorthEast()
Action method for creating northeast tiled map.
static final ActionBuilder ACTION_BUILDER
Action Builder.
boolean isGridVisible()
Action method for "grid visible".
Action aShrinkMapSize
Action for "shrink map size".
boolean doPrevExit(final boolean performAction)
Executes the "prev exit" action.
final String[] directionsMap
Possible directions for "enter xxx map".
void createTileSouthEast()
Action method for creating southeast tiled map.
boolean isDoubleFaces()
Action method for "double faces".
ToggleAction aGridVisible
Action for "grid visible".
void removeMapModelListener(@NotNull MapModelListener< G, A, R > listener)
Unregister a map listener.
void setAction(@NotNull final Action action, @NotNull final String name)
Sets the Action instance for this editor action.
Interface for MapArchObjects.
ToggleAction aTileStretching
Action for "tile-stretching visible".
File getFile()
Returns a File for this map file.
The model component of the selected square control.
void createTileUp()
Action method for creating up tiled map.
void mapCursorChangedGameObject(@Nullable final MapSquare< G, A, R > mapSquare, @Nullable final G gameObject)
Called whenever the selected game object has changed.
boolean isTileStretching()
Action method for "tile-stretching".
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.
An interface for classes that collect errors.
Point getLocation()
Get position of cursor.
A map view consists of a map grid and a map cursor, and is attached to a map control.
boolean doAutoJoin(final boolean performAction, final boolean autoJoin)
Executes the "auto join" action.
final ExitMatcher< G, A, R > exitMatcher
The ExitMatcher for selecting exit game objects.
Action aPrevExit
Action for "previous exit".
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.
This package contains the framework for validating maps.
boolean doGridVisible(final boolean performAction, final boolean gridVisible)
Executes the "grid visible" action.
boolean doEnterExit(final boolean performAction)
Executes the "enter exit" action.
JScrollPane getScrollPane()
Returns the JScrollPane of this map view.
void createTileSouth()
Action method for creating south tiled map.
final ProjectSettings projectSettings
The ProjectSettings.
Manages actions in the "map" menu.
final boolean allowRandomMapParameters
Whether exit paths may point to random maps.
boolean doCreateTile(final boolean performAction, @NotNull final Direction direction)
Executes the "create tile" action.
void save()
Saves the map to a file.
boolean doSmoothing(final boolean performAction, final boolean smoothing)
Executes the "smoothing" action.
The location of a map file with a map directory.
MapView< G, A, R > newMapView(@NotNull final MapControl< G, A, R > mapControl, @Nullable final Point viewPosition)
Creates a new map view.
Settings that apply to a project.
void release(@NotNull MapControl< G, A, R > mapControl)
Releases a MapControl instance.
Interface for listeners listening on MapModel events.
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.
final MapManagerListener< G, A, R > mapManagerListener
The map manager listener which is attached to the current map if the current map is tracked.
void setAutoJoin(final boolean autoJoin)
Action method for "autoJoin".
void setSmoothing(boolean smoothing)
Sets the smoothing setting.
boolean doTileStretching(final boolean performAction, final boolean tileStretching)
Executes the "tile-stretching" action.
void deleteUnknownObjects()
Deletes all game objects referencing unknown archetypes.
void createTileEast()
Action method for creating east tiled map.
boolean isDoubleFaces()
Get whether double faces are drawn double height.
final SelectedSquareModel< G, A, R > selectedSquareModel
The SelectedSquareModel to use.
void showDialog(@NotNull final MapView< G, A, R > mapView)
Shows a dialog to shrink the map size.
void mapProperties()
Action method for "map properties".
void enterExit()
Tries to load the map where the selected map-exit points to.
Base classes for rendering maps.
void selectExit(@NotNull final MapView< G, A, R > mapView, final int direction)
Selects an exit square.
Interface for event listeners that are interested in changes on {}.
void createTileWest()
Action method for creating west tiled map.
An Iterator that filters another iterator according to a {}.
Action aNextExit
Action for "next exit".
ToggleAction aDoubleFaces
Action for "draw double faces".
void enterEastMap()
Action method for entering the east map.
boolean doMapProperties(final boolean performAction)
Executes the "map properties" action.
void mapCursorChangedPos(@NotNull final Point location)
This event handler is called when MapCursor has moved.
final MapArchObjectListener mapArchObjectListener
The MapArchObjectListener attached to currentMapView.
boolean doShrinkMapSize(final boolean performAction)
Executes the "shrink map size" action.
void mapViewCreated(@NotNull final MapView< G, A, R > mapView)
This event handler is called when a map view was created.
Currently nothing more than a marker interface for unification.
final Action[] aDirections
Action for "enter xxx map".
MapModel< G, A, R > getMapModel()
Returns the map model.
G getSelectedGameObject()
Returns the currently selected GameObject within this list (currently selected MapSquare).
final ShrinkMapSizeDialogManager< G, A, R > shrinkMapSizeDialogManager
The ShrinkMapSizeDialogManager instance.
final MapViewSettingsListener mapViewSettingsListener
The MapViewSettingsListener attached to {}.
void enterWestMap()
Action method for entering the west map.
File getMapsDirectory()
Returns the default maps directory.
void nextExit()
Selects the next exit.
ToggleAction aAutoJoin
Action for "autojoin".
boolean doMapCreateView(final boolean performAction)
Executes the "map create view" action.
void mapCursorChangedSize()
Called whenever the map cursor's map grid size has changed.
boolean isTileShow()
Action method for "tile show".
MapFile getMapFile()
Returns the map file.
Displays the contents of the currently selected map square.
Stores all existing MapViews.
The class Size2D represents a 2d rectangular area.
void enterNorthEastMap()
Action method for entering the north east map.
Factory for creating map property dialog instances.
void updateActions()
Updates the actions' state.
Action aMapCreateView
Action for "create view".
void createTileNorth()
Action method for creating north tiled map.
void enterSouthWestMap()
Action method for entering the south west map.