 |
Gridarta Editor
|
Go to the documentation of this file.
20 package net.sf.gridarta.mainactions;
22 import java.awt.Point;
23 import java.awt.Rectangle;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.IdentityHashMap;
27 import java.util.List;
30 import javax.swing.Action;
31 import javax.swing.JFrame;
65 import net.
sf.japi.swing.action.ActionMethod;
66 import org.jetbrains.annotations.NotNull;
67 import org.jetbrains.annotations.Nullable;
346 public void mapGridChanged(@NotNull
final MapGridEvent e) {
351 public void mapGridResized(@NotNull
final MapGridEvent e) {
369 public MainActions(@NotNull
final FindDialogManager<G, A, R> findDialogManager, @NotNull
final ReplaceDialogManager<G, A, R> replaceDialogManager, @NotNull
final JFrame
parent, @NotNull
final MapViewSettings mapViewSettings, @NotNull
final ArchetypeSet<G, A, R> archetypeSet, @NotNull
final CopyBuffer<G, A, R> copyBuffer, @NotNull
final ObjectChooser<G, A, R> objectChooser, @NotNull
final MapManager<G, A, R> mapManager, @NotNull
final InsertionModeSet<G, A, R> insertionModeSet) {
381 archetypeSet.addArchetypeSetListener(this::refreshMenus);
401 public void mapCreated(@NotNull
final MapControl<G, A, R> mapControl,
final boolean interactive) {
428 public void mapSizeChanged(@NotNull
final Size2D newSize) {
438 public void mapObjectsChanged(@NotNull
final Set<G> gameObjects, @NotNull
final Set<G> transientGameObjects) {
448 public void mapFileChanged(@Nullable
final MapFile oldMapFile) {
453 public void modifiedChanged() {
837 private boolean doFind(
final boolean performAction) {
839 if (mapView ==
null) {
875 private boolean doReplace(
final boolean performAction) {
877 if (mapView ==
null) {
893 private boolean doClear(
final boolean performAction) {
895 if (mapView ==
null) {
899 final Rectangle selectedRec = mapView.
getMapGrid().getSelectedRec();
900 if (selectedRec ==
null) {
916 private boolean doCut(
final boolean performAction) {
918 if (mapView ==
null) {
922 final Rectangle selectedRec = mapView.
getMapGrid().getSelectedRec();
923 if (selectedRec ==
null) {
939 private boolean doCopy(
final boolean performAction) {
941 if (mapView ==
null) {
945 final Rectangle selectedRec = mapView.
getMapGrid().getSelectedRec();
946 if (selectedRec ==
null) {
962 private boolean doPaste(
final boolean performAction) {
964 if (mapView ==
null) {
987 if (mapView ==
null) {
996 if (selectedSquares.isEmpty()) {
1002 if (selectedRec ==
null) {
1006 if (performAction) {
1022 if (mapControl ==
null) {
1027 if (mapView ==
null) {
1032 if (!shiftProcessor.
canShift(direction)) {
1036 if (performAction) {
1037 shiftProcessor.
shift(direction);
1050 if (mapView ==
null) {
1054 if (performAction) {
1068 if (mapView ==
null) {
1072 if (performAction) {
1086 if (mapView ==
null) {
1090 if (performAction) {
1104 if (mapView ==
null) {
1108 if (performAction) {
1122 if (mapView ==
null) {
1126 if (performAction) {
1140 if (mapView ==
null) {
1144 if (performAction) {
1158 if (mapView ==
null) {
1163 if (performAction) {
1177 if (mapView ==
null) {
1181 if (performAction) {
1192 final Collection<MatchCriteria<G, A, R>> matchCriteriaArch =
new ArrayList<>(archNames.length);
1193 for (
final String archName : archNames) {
1197 final Collection<MatchCriteria<G, A, R>> matchCriteriaName =
new ArrayList<>(names.length);
1198 for (
final String
name : names) {
1208 boolean doModify =
false;
1210 if (matchCriteriaArch.isEmpty() && matchCriteriaName.isEmpty()) {
1215 if (matchCriteria.matches(gameObject.getHead())) {
1222 if (!matchCriteria.matches(gameObject.getHead())) {
1232 gameObject.applyMassChange(layers, subLayers, changes);
1253 if (performAction) {
1270 if (performAction) {
1284 if (mapView ==
null) {
1288 boolean foundEmptySelectedSquare =
false;
1291 if (selectedSquare.isEmpty()) {
1292 foundEmptySelectedSquare =
true;
1296 if (!foundEmptySelectedSquare) {
1300 if (performAction) {
1301 final Map<MapSquare<G, A, R>, Void> newSelection =
new IdentityHashMap<>();
1302 Map<MapSquare<G, A, R>, Void> todo =
new IdentityHashMap<>();
1304 todo.put(mapSquare,
null);
1305 newSelection.put(mapSquare,
null);
1309 final Point point =
new Point();
1310 while (!todo.isEmpty()) {
1311 final Map<MapSquare<G, A, R>, Void> tmp =
new IdentityHashMap<>();
1313 for (
int dy = -1; dy <= 1; dy++) {
1314 for (
int dx = -1; dx <= 1; dx++) {
1315 if (dx != 0 || dy != 0) {
1316 mapSquare.getMapLocation(point, dx, dy);
1319 if (newMapSquare.
isEmpty() && !newSelection.containsKey(newMapSquare)) {
1320 tmp.put(newMapSquare,
null);
1321 newSelection.put(newMapSquare,
null);
1335 mapSquare.getMapLocation(point);
1353 if (mapView ==
null) {
1357 if (performAction) {
1380 if (mapView ==
null) {
1384 if (performAction) {
1423 private void tileStretching(@NotNull
final MapView<G, A, R> mapView,
final int heightValue,
final boolean isAbsolute, @NotNull
final Integer @Nullable [] subLayers) {
1430 gameObject.updateTileStretch(heightValue, isAbsolute, subLayers);
1439 public void setAction(@NotNull
final Action action, @NotNull
final String
name) {
1465 case "shiftNorthEast":
1473 case "shiftSouthEast":
1481 case "shiftSouthWest":
1489 case "shiftNorthWest":
1521 case "randFillAuto":
1525 case "randFillAbove":
1529 case "randFillBelow":
1545 case "invertSelection":
1549 case "expandEmptySelection":
1553 case "tileStretchingSet":
1557 case "tileStretchingClear":
1561 case "tileStretchingIncrease":
1565 case "tileStretchingDecrease":
1570 throw new IllegalArgumentException(
"unsupported action name: " +
name);
InsertionMode getTopmostInsertionMode()
Returns the "topmost" insertion mode.
boolean doFindNext(final boolean performAction)
Executes the "find next" action.
A MapModel reflects the data of a map.
boolean doFind(final boolean performAction)
Executes the "find" action.
void refreshMenus()
Enables/disables menu entries based on the current state.
void endTransaction()
Ends a transaction.
MapGrid getMapGrid()
Returns the MapGrid of this view.
boolean doFillAbove(final boolean performAction)
Executes the "fill above" action.
A getMapArchObject()
Returns the Map Arch Object with the meta information about the map.
Action aPasteTiled
Action called for "paste tiled".
A MapManager manages all opened maps.
void invertSelection()
Inverts all selected squares.
boolean isEmpty()
Returns whether this copy buffer contains any game objects.
final InsertionModeSet< G, A, R > insertionModeSet
The InsertionModeSet to use.
MapManagerListener< G, A, R > newMapManagerListener()
Creates a new MapManagerListener that refreshes the actions when the current map changes.
Criteria for game object matchers.
void fillAbove()
"Fill above" was selected from the Edit menu.
MapControl< G, A, R > getMapControl()
Return the controller of this view.
Base package of all Gridarta classes.
final MapViewSettings mapViewSettings
The map view settings instance.
boolean doClear(final boolean performAction)
Executes the "clear" action.
void paste()
"Paste" was selected from the Edit menu.
void tileStretching(@NotNull final MapView< G, A, R > mapView, final int heightValue, final boolean isAbsolute, @NotNull final Integer @Nullable[] subLayers)
Performs one of the "tile stretching" actions.
void endTransaction()
End a transaction.
void massChange()
"Mass change" was selected from the Edit menu.
Displays a dialog asking for parameters for the "random fill" function.
boolean showTileStretchingDialog(@NotNull final Component parent)
Displays the tile stretching dialog.
void findNext()
"Find next" was selected from the Edit menu.
Action aCopy
Action called for "copy".
boolean isPointValid(@Nullable Point pos)
Checks whether the given coordinate is within map bounds.
void find()
"Find" was selected from the Edit menu.
void shiftSouthWest()
"Shift South West" was selected from the Edit menu.
Action aShiftNorth
Action called for "shift north".
void activeMapViewChanged(@Nullable final MapView< G, A, R > mapView)
This event handler is called when the current map view has changed.
boolean doExpandEmptySelection(final boolean performAction)
Executes the "expand empty selection" action.
void beginTransaction(@NotNull String name)
Starts a new transaction.
Interface for listeners listening to MapManager changes.
A MatchCriteria that matches by archetype name.
Creates and displays the replace dialog.
Interface for listeners interested in events related to {} instances.
void fillAuto()
"Fill" was selected from the Edit menu.
boolean findPrev(@NotNull final MapView< G, A, R > mapView, final boolean performAction)
Executes the "find next" action.
Action aFillBelow
Action called for "fill below".
Rectangle getSelectedRec()
Returns the smallest rectangle containing selection.
boolean doRandFillAuto(final boolean performAction)
Executes the "rand fill auto" action.
Action aFindNext
Action called for "find next".
boolean findNext(@NotNull final MapView< G, A, R > mapView, final boolean performAction)
Executes the "find next" action.
Reflects a game object (object on a map).
Container for settings that affect the rendering of maps.
Integer[] getSubLayers()
Returns the sub-layers to affect.
Encapsulates actions and related functions.
void floodFill()
"Flood fill" was selected from the Edit menu.
Action aShiftWest
Action called for "shift west".
Action aShiftSouthEast
Action called for "shift south east".
final MapGridListener mapGridListener
The map grid listener used to detect map grid changes.
Graphical User Interface of Gridarta.
InsertionMode getAutoInsertionMode()
Returns the "auto" insertion mode.
void beginTransaction()
Starts a new transaction.
boolean doPaste(final boolean performAction)
Executes the "paste" action.
final RandomFillDialog randomFillDialog
The RandomFillDialog instance.
MapCursor< G, A, R > getMapCursor()
Returns the MapCursor of this view.
void randFillBelow()
"Random fill below" was selected from the Edit menu.
void fillRandom(@NotNull final MapView< G, A, R > mapView, @NotNull final InsertionMode insertionMode)
"RandomFill" was selected from the Edit menu.
boolean doCopy(final boolean performAction)
Executes the "copy" action.
Action aFloodFill
Action called for "flood fill".
int getFillDensity()
Returns the fill density.
static< G extends GameObject< G, A, R > A extends R extends Archetype< G, A, R > void floodFill(@NotNull final MapModel< G, A, R > mapModel, @NotNull final Point start, @NotNull final List<? extends BaseObject< G, A, R, ?>> gameObjects, @NotNull final InsertionModeSet< G, A, R > insertionModeSet)
void tileStretchingIncrease()
Invoked when the user wants to increase tile stretching on the selected map squares.
void shiftEast()
"Shift East" was selected from the Edit menu.
MapView< G, A, R > currentMapView
The last known active map view, or.
boolean doTileStretchingChange(final boolean performAction, final int heightValue, final boolean isAbsolute)
Executes one of the "tile stretching clear/increase/decrease" actions.
void selectAll()
Invoked when the user wants to select all squares from a map.
void selectAll()
Marks all squares as selected.
GameObjects are the objects based on Archetypes found on maps.
void addMapModelListener(@NotNull final MapModelListener< G, A, R > listener)
Adds a MapModelListener to be notified about changes of the cut/copied game objects.
List<? extends BaseObject< G, A, R, ?> > getSelections()
Returns the selected arches in the left-side panel.
Action aRandFillAbove
Action called for "random fill above".
void shiftSouth()
"Shift South" was selected from the Edit menu.
boolean doPasteTiled(final boolean performAction)
Executes the "paste tiled" action.
void showDialog(@NotNull final MapView< G, A, R > mapView)
Displays the replace dialog.
boolean doShift(final boolean performAction, @NotNull final Direction direction)
Executes the "shift" action.
Action aExpandEmptySelection
Action called for "grow empty selection".
The Replace dialog: replaces game objects in a map.
void fillBelow()
"Fill below" was selected from the Edit menu.
void mapViewClosing(@NotNull final MapView< G, A, R > mapView)
This event handler is called when a map view is to be closed.
void shift(@NotNull final Direction dir)
Shifts the map contents by one square.
void fill(@NotNull final MapView< G, A, R > mapView, @NotNull final InsertionMode insertionMode)
"Fill" was selected from the Edit menu.
boolean doRandFillAbove(final boolean performAction)
Executes the "rand fill above" action.
final CopyBuffer< G, A, R > copyBuffer
The copy buffer instance.
Integer[] getLayers()
Returns the layers to affect.
void cut()
"Cut" was selected from the Edit menu.
Action aFillAuto
Action called for "fill".
Integer[] getSubLayers()
Returns the sub-layers to affect.
Action aRandFillAuto
Action called for "random fill".
Displays a dialog asking for parameters for the "mass change" function.
Interface for MapArchObjects.
int getHeightValue()
Returns the height value.
void copy(@NotNull final MapView< G, A, R > mapView, @NotNull final Rectangle selectedRec)
Executes the Copy command.
Action aPaste
Action called for "paste".
boolean doFillAuto(final boolean performAction)
Executes the "fill auto" action.
Action aTileStretchingDecrease
Action called for "tile stretching -> decrease Z".
MapView< G, A, R > getSelection()
Determine if the current map has a selection.
Action aMassChange
Action called for "mass change".
Action aInvertSelection
Action called for "invert selection".
boolean isTileStretchingAbsolute()
Action method for "absolute" action.
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.
Modes that describe how squares get selected.
String[] getArchNames()
Returns the arch names to affect.
void copy()
"Copy" was selected from the Edit menu.
Interface that captures similarities between different ArchetypeSet implementations.
final ObjectChooser< G, A, R > objectChooser
The ObjectChooser instance to use.
Creates and displays the find dialog.
This package contains the framework for validating maps.
void tileStretchingDecrease()
Invoked when the user wants to decrease tile stretching on the selected map squares.
InsertionMode getBottommostInsertionMode()
Returns the "bottommost" insertion mode.
void select(@NotNull final Point pos, @NotNull final SelectionMode selectionMode)
Selects or deselects a single square.
Common base implementation of CopyBuffer.
boolean isRandomFillSkipAdjacentSquares()
Action method for "skip adjacent squares" action.
void shiftSouthEast()
"Shift South East" was selected from the Edit menu.
MapControl< G, A, R > currentMapControl
The last known active map, or.
boolean doMassChange(final boolean performAction)
Executes the "mass change" actions.
The location of a map file with a map directory.
Action aTileStretchingSet
Action called for "tile stretching -> set Z".
boolean showMassChangeDialog(@NotNull final Component parent)
Displays the mass change dialog.
Common base interface for ObjectChoosers.
void cut(@NotNull final MapView< G, A, R > mapView, @NotNull final Rectangle selectedRec)
Executes the Cut command.
Displays a dialog asking for parameters for the "tile stretching set" function.
void shiftNorthEast()
"Shift North East" was selected from the Edit menu.
String[] getNames()
Returns the object names to affect.
void tileStretchingSet()
Invoked when the user wants to set tile stretching on the selected map squares.
Action aTileStretchingClear
Action called for "tile stretching -> clear Z".
Action aRandFillBelow
Action called for "random fill below".
void pasteTiled()
"Paste Tiled" was selected from the Edit menu.
Interface for listeners listening on MapModel events.
2D-Grid containing flags for selection, pre-selection, cursor, warnings and errors.
ADD
All squares that are preselected get selected.
MapSquare< G, A, R > getMapSquare(@NotNull Point pos)
Get the square at a specified location.
void shiftNorth()
"Shift North" was selected from the Edit menu.
void paste(@NotNull final MapView< G, A, R > mapView, @NotNull final Point startLocation)
Executes the Paste command.
String getChanges()
Returns the actual changes to apply.
void expandEmptySelection()
Invoked when the user wants to expand the selection of empty map squares to surrounding empty map squ...
void shiftNorthWest()
"Shift North West" was selected from the Edit menu.
Action aCut
Action called for "cut".
Action aFind
Action called for "find".
void invertSelection()
Invoked when the user wants to invert all selected squares from a map.
Utility class implementing fill operations on map instances.
Action aSelectAll
Action called for "select all".
MapModelListener< G, A, R > newMapModelListener()
Creates a new MapModelListener that refreshes the actions when the map contents change.
void showDialog(@NotNull final MapView< G, A, R > mapView)
Displays the replace dialog.
Base classes for rendering maps.
A MatchCriteria that matches by object name.
boolean isEmpty()
Check whether this square is empty.
boolean doTileStretchingChangeSet(final boolean performAction)
Executes one of the "tile stretching" actions.
void randFillAbove()
"Random fill above" was selected from the Edit menu.
final FindDialogManager< G, A, R > findDialogManager
The find dialog manager to use.
boolean doSelectAll(final boolean performAction)
Executes the "select all" action.
Action aClear
Action called for "clear".
void findPrev()
"Find previous" was selected from the Edit menu.
Currently nothing more than a marker interface for unification.
Interface for listeners listening to MapGridEvents.
MapModel< G, A, R > getMapModel()
Returns the map model.
boolean doFillBelow(final boolean performAction)
Executes the "fill below" action.
final ReplaceDialogManager< G, A, R > replaceDialogManager
The replace dialog manager to use.
Action aShiftSouthWest
Action called for "shift south west".
boolean doFindPrev(final boolean performAction)
Executes the "find prev" action.
Performs a "shift" operation in a map: shift all selected squares into the given direction.
Action aShiftEast
Action called for "shift east".
List< MapSquare< G, A, R > > getSelectedSquares()
Returns the selected squares.
Action aShiftNorthEast
Action called for "shift north east".
boolean doFloodFill(final boolean performAction)
Executes the "flood fill" action.
void shiftWest()
"Shift West" was selected from the Edit menu.
void randFillAuto()
"Random fill" was selected from the Edit menu.
Action aFillAbove
Action called for "fill above".
This event is created by MapGrid.
final MassChangeDialog massChangeDialog
The MassChangeDialog instance.
boolean doRandFillBelow(final boolean performAction)
Executes the "rand fill below" action.
boolean doCut(final boolean performAction)
Executes the "cut" action.
void setAction(@NotNull final Action action, @NotNull final String name)
Sets the Action instance for this editor action.
void tileStretchingClear()
Invoked when the user wants to clear tile stretching on the selected map squares.
Action aFindPrev
Action called for "find prev".
Action aShiftNorthWest
Action called for "shift north west".
void replace()
"Replace" was selected from the Edit menu.
Action aShiftSouth
Action called for "shift south".
final TileStretchingDialog tileStretchingDialog
The TileStretchingDialog instance.
Action aTileStretchingIncrease
Action called for "tile stretching -> increase Z".
boolean canShift(@NotNull final Direction dir)
Checks whether shifting is possible.
The class Size2D represents a 2d rectangular area.
void unSelect()
Clears all selection and pre-selection flags from the grid.
boolean doReplace(final boolean performAction)
Executes the "replace" action.
boolean doInvertSelection(final boolean performAction)
Executes the "invert selection" action.
MainActions(@NotNull final FindDialogManager< G, A, R > findDialogManager, @NotNull final ReplaceDialogManager< G, A, R > replaceDialogManager, @NotNull final JFrame parent, @NotNull final MapViewSettings mapViewSettings, @NotNull final ArchetypeSet< G, A, R > archetypeSet, @NotNull final CopyBuffer< G, A, R > copyBuffer, @NotNull final ObjectChooser< G, A, R > objectChooser, @NotNull final MapManager< G, A, R > mapManager, @NotNull final InsertionModeSet< G, A, R > insertionModeSet)
Creates a new instance.
static< G extends GameObject< G, A, R > A extends R extends Archetype< G, A, R > void fill(@NotNull final MapModel< G, A, R > mapModel, @NotNull final Collection< MapSquare< G, A, R >> selection, @NotNull final InsertionMode insertionMode, @NotNull final List<? extends BaseObject< G, A, R, ?>> gameObjects, final int density, final boolean noAdjacent)
void pasteTiled(@NotNull final MapView< G, A, R > mapView, @NotNull final Iterable< MapSquare< G, A, R >> selectedSquares, @NotNull final Point origin)
Executes the Paste Tiled command.
boolean showRandomFillDialog(@NotNull final Component parent)
Displays the random fill dialog.
final JFrame parent
The parent component for dialog windows.
Action aReplace
Action called for "replace".
void clear()
"Clear" was selected from the Edit menu.
void clear(@NotNull final MapView< G, A, R > mapView, @NotNull final Rectangle selectedRec)
Executes the Clear command.
void mapViewCreated(@NotNull final MapView< G, A, R > mapView)
This event handler is called when a map view was created.