From: <aki...@us...> - 2013-07-09 08:39:15
|
Revision: 9291 http://sourceforge.net/p/gridarta/code/9291 Author: akirschbaum Date: 2013-07-09 08:39:10 +0000 (Tue, 09 Jul 2013) Log Message: ----------- Extract AddToSelectionAction from MapCursorActions. Modified Paths: -------------- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/mapcursor/MapCursorActions.java trunk/src/gridarta/src/main/java/net/sf/gridarta/maincontrol/GUIMainControl.java Added Paths: ----------- trunk/src/gridarta/src/main/java/net/sf/gridarta/action/AddToSelectionAction.java Added: trunk/src/gridarta/src/main/java/net/sf/gridarta/action/AddToSelectionAction.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/action/AddToSelectionAction.java (rev 0) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/action/AddToSelectionAction.java 2013-07-09 08:39:10 UTC (rev 9291) @@ -0,0 +1,91 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2011 The Gridarta Developers. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.action; + +import javax.swing.Action; +import net.sf.gridarta.gui.map.mapview.MapViewManager; +import net.sf.gridarta.model.archetype.Archetype; +import net.sf.gridarta.model.gameobject.GameObject; +import net.sf.gridarta.model.maparchobject.MapArchObject; +import net.sf.gridarta.model.mapgrid.SelectionMode; +import net.sf.gridarta.utils.EditorAction; +import net.sf.japi.swing.action.ActionMethod; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * An {@link EditorAction} that adds the current pre-selection to the + * selection. + * @author Andreas Kirschbaum + */ +public class AddToSelectionAction<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractSelectionAction<G, A, R> implements EditorAction { + + /** + * The {@link Action} associated with this editor action. Set to {@code + * null} if no action is associated. + */ + @Nullable + private Action action; + + /** + * Creates a new instance. + * @param mapViewManager the map view manager + */ + public AddToSelectionAction(@NotNull final MapViewManager<G, A, R> mapViewManager) { + super(mapViewManager); + } + + /** + * {@inheritDoc} + */ + @Override + public void setAction(@NotNull final Action action, @NotNull final String name) { + this.action = action; + } + + /** + * Adds the current pre-selection to the selection. + */ + @ActionMethod + public void addToSelection() { + doAddToSelection(true); + } + + /** + * Executes the action. + * @param performAction whether the action should be performed + * @return whether the action was or can be performed + */ + private boolean doAddToSelection(final boolean performAction) { + return doSelection(performAction, SelectionMode.ADD); + } + + /** + * {@inheritDoc} + */ + @Override + protected void updateAction() { + if (action != null) { + //noinspection ConstantConditions + action.setEnabled(doAddToSelection(false)); + } + } + +} Property changes on: trunk/src/gridarta/src/main/java/net/sf/gridarta/action/AddToSelectionAction.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +LF \ No newline at end of property Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/mapcursor/MapCursorActions.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/mapcursor/MapCursorActions.java 2013-07-09 07:27:33 UTC (rev 9290) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/mapcursor/MapCursorActions.java 2013-07-09 08:39:10 UTC (rev 9291) @@ -72,18 +72,6 @@ private Action aGoLocation; /** - * Action for "select square". - */ - @Nullable - private Action aSelectSquare; - - /** - * Action for "add to selection". - */ - @Nullable - private Action aAddToSelection; - - /** * The {@link GoLocationDialogManager} to track go location dialog * instances. */ @@ -229,22 +217,6 @@ } /** - * Action method for "select square". - */ - @ActionMethod - public void selectSquare() { - doSelectSquare(true); - } - - /** - * Action method for "add to selection". - */ - @ActionMethod - public void addToSelection() { - doAddToSelection(true); - } - - /** * Return the map cursor of the current map view if it is active. * @return the map cursor, or <code>null</code> if the cursor is not active, * or if no map view exists @@ -281,14 +253,6 @@ //noinspection ConstantConditions aGoLocation.setEnabled(doGoLocation(false)); } - if (aSelectSquare != null) { - //noinspection ConstantConditions - aSelectSquare.setEnabled(doSelectSquare(false)); - } - if (aAddToSelection != null) { - //noinspection ConstantConditions - aAddToSelection.setEnabled(doAddToSelection(false)); - } } private void selectSquare(@NotNull final MapCursor<G, A, R> mapCursor, final SelectionMode mode) { @@ -348,24 +312,6 @@ } /** - * Executes the "select square" action. - * @param performAction whether the action should be performed - * @return whether the action was or can be performed - */ - private boolean doSelectSquare(final boolean performAction) { - return doSelection(performAction, SelectionMode.FLIP); - } - - /** - * Executes the "add to selection" action. - * @param performAction whether the action should be performed - * @return whether the action was or can be performed - */ - private boolean doAddToSelection(final boolean performAction) { - return doSelection(performAction, SelectionMode.ADD); - } - - /** * Executes an action for changing the selection. * @param performAction whether the action should be performed * @param mode the type of action to perform @@ -403,10 +349,6 @@ } } else if (name.equals("goLocation")) { aGoLocation = action; - } else if (name.equals("selectSquare")) { - aSelectSquare = action; - } else if (name.equals("addToSelection")) { - aAddToSelection = action; } else { throw new IllegalArgumentException(); } Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/maincontrol/GUIMainControl.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/maincontrol/GUIMainControl.java 2013-07-09 07:27:33 UTC (rev 9290) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/maincontrol/GUIMainControl.java 2013-07-09 08:39:10 UTC (rev 9291) @@ -34,6 +34,7 @@ import javax.swing.JMenuBar; import javax.swing.filechooser.FileFilter; import net.sf.gridarta.MainControl; +import net.sf.gridarta.action.AddToSelectionAction; import net.sf.gridarta.action.ArchAttributesAction; import net.sf.gridarta.action.CleanCompletelyBlockedSquaresAction; import net.sf.gridarta.action.CollectSpellsAction; @@ -558,7 +559,7 @@ createAction("moveCursorNorthWest", "Map Cursor,Map/Selection", mapCursorActions); createAction("goLocation", "Map Cursor", mapCursorActions); createAction("selectSquare", "Map Cursor,Map/Selection", mapCursorActions); - createAction("addToSelection", "Map Cursor,Map/Selection", mapCursorActions); + createAction("addToSelection", "Map Cursor,Map/Selection", new AddToSelectionAction<G, A, R>(mapViewManager)); createAction("subFromSelection", "Map Cursor,Map/Selection", new SubFromSelectionAction<G, A, R>(mapViewManager)); createAction("startStopDrag", "Map Cursor,Map/Selection", new StartStopDragAction<G, A, R>(mapViewManager)); createAction("releaseDrag", "Map Cursor,Map/Selection", new ReleaseDragAction<G, A, R>(mapViewManager)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |