From: <aki...@us...> - 2013-07-09 07:04:50
|
Revision: 9284 http://sourceforge.net/p/gridarta/code/9284 Author: akirschbaum Date: 2013-07-09 07:04:39 +0000 (Tue, 09 Jul 2013) Log Message: ----------- Extract InsertArchAction 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/InsertArchAction.java Added: trunk/src/gridarta/src/main/java/net/sf/gridarta/action/InsertArchAction.java =================================================================== --- trunk/src/gridarta/src/main/java/net/sf/gridarta/action/InsertArchAction.java (rev 0) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/action/InsertArchAction.java 2013-07-09 07:04:39 UTC (rev 9284) @@ -0,0 +1,102 @@ +/* + * 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.gui.panel.objectchooser.ObjectChooser; +import net.sf.gridarta.model.archetype.Archetype; +import net.sf.gridarta.model.baseobject.BaseObject; +import net.sf.gridarta.model.gameobject.GameObject; +import net.sf.gridarta.model.maparchobject.MapArchObject; +import net.sf.gridarta.model.mapcursor.MapCursor; +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 inserts a new game object into the current map. + * @author Andreas Kirschbaum + */ +public class InsertArchAction<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractMapCursorAction<G, A, R> implements EditorAction { + + /** + * The object chooser. + */ + @NotNull + private final ObjectChooser<G, A, R> objectChooser; + + /** + * 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 + * @param objectChooser the object chooser + */ + public InsertArchAction(@NotNull final MapViewManager<G, A, R> mapViewManager, @NotNull final ObjectChooser<G, A, R> objectChooser) { + super(mapViewManager); + this.objectChooser = objectChooser; + } + + /** + * {@inheritDoc} + */ + @Override + public void setAction(@NotNull final Action action, @NotNull final String name) { + this.action = action; + } + + /** + * Action method for "insert arch". + */ + @ActionMethod + public void insertArch() { + doInsertArch(true); + } + + /** + * Executes the "insert arch" action. + * @param performAction whether the action should be performed + * @return whether the action was or can be performed + */ + private boolean doInsertArch(final boolean performAction) { + final MapCursor<G, A, R> mapCursor = getActiveMapCursor(); + final BaseObject<G, A, R, ?> gameObject = objectChooser.getSelection(); + return mapCursor != null && gameObject != null && mapCursor.insertGameObject(performAction, gameObject, false, true); + } + + /** + * {@inheritDoc} + */ + @Override + protected void updateAction() { + if (action != null) { + //noinspection ConstantConditions + action.setEnabled(doInsertArch(false)); + } + } + +} Property changes on: trunk/src/gridarta/src/main/java/net/sf/gridarta/action/InsertArchAction.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 05:22:40 UTC (rev 9283) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/mapcursor/MapCursorActions.java 2013-07-09 07:04:39 UTC (rev 9284) @@ -28,9 +28,7 @@ import net.sf.gridarta.gui.map.mapview.MapViewManager; import net.sf.gridarta.gui.map.mapview.MapViewManagerListener; import net.sf.gridarta.gui.map.renderer.MapRenderer; -import net.sf.gridarta.gui.panel.objectchooser.ObjectChooser; import net.sf.gridarta.model.archetype.Archetype; -import net.sf.gridarta.model.baseobject.BaseObject; import net.sf.gridarta.model.direction.Direction; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; @@ -56,12 +54,6 @@ private static final int BORDER = 3; /** - * The object chooser. - */ - @NotNull - private final ObjectChooser<G, A, R> objectChooser; - - /** * All {@link Direction Directions}. */ @NotNull @@ -110,12 +102,6 @@ private Action aReleaseDrag; /** - * Action for "insert arch". - */ - @Nullable - private Action aInsertArch; - - /** * The {@link GoLocationDialogManager} to track go location dialog * instances. */ @@ -178,11 +164,9 @@ /** * Create a new instance. - * @param objectChooser the object chooser * @param mapViewManager the map view manager */ - public MapCursorActions(@NotNull final ObjectChooser<G, A, R> objectChooser, @NotNull final MapViewManager<G, A, R> mapViewManager) { - this.objectChooser = objectChooser; + public MapCursorActions(@NotNull final MapViewManager<G, A, R> mapViewManager) { goLocationDialogManager = new GoLocationDialogManager<G, A, R>(mapViewManager); aMoveCursor = new Action[directions.length]; mapViewManager.addMapViewManagerListener(mapViewManagerListener); @@ -303,14 +287,6 @@ } /** - * Action method for "insert arch". - */ - @ActionMethod - public void insertArch() { - doInsertArch(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 @@ -367,10 +343,6 @@ //noinspection ConstantConditions aReleaseDrag.setEnabled(doReleaseDrag(false)); } - if (aInsertArch != null) { - //noinspection ConstantConditions - aInsertArch.setEnabled(doInsertArch(false)); - } } private void selectSquare(@NotNull final MapCursor<G, A, R> mapCursor, final SelectionMode mode) { @@ -522,17 +494,6 @@ } /** - * Executes the "insert arch" action. - * @param performAction whether the action should be performed - * @return whether the action was or can be performed - */ - private boolean doInsertArch(final boolean performAction) { - final MapCursor<G, A, R> mapCursor = getActiveMapCursor(); - final BaseObject<G, A, R, ?> gameObject = objectChooser.getSelection(); - return mapCursor != null && gameObject != null && mapCursor.insertGameObject(performAction, gameObject, false, true); - } - - /** * {@inheritDoc} */ @Override @@ -561,8 +522,6 @@ aStartStopDrag = action; } else if (name.equals("releaseDrag")) { aReleaseDrag = action; - } else if (name.equals("insertArch")) { - aInsertArch = 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 05:22:40 UTC (rev 9283) +++ trunk/src/gridarta/src/main/java/net/sf/gridarta/maincontrol/GUIMainControl.java 2013-07-09 07:04:39 UTC (rev 9284) @@ -45,6 +45,7 @@ import net.sf.gridarta.action.DisplayIconsOnlyAction; import net.sf.gridarta.action.ExitAction; import net.sf.gridarta.action.GcAction; +import net.sf.gridarta.action.InsertArchAction; import net.sf.gridarta.action.LightVisibleAction; import net.sf.gridarta.action.MoveSquareBottomAction; import net.sf.gridarta.action.MoveSquareDownAction; @@ -444,7 +445,7 @@ //noinspection ResultOfObjectAllocationIgnored new FindArchetypesDialogManager<G, A, R>(parent, archetypeChooserControl, objectChooser, archetypeTypeSet); final EditorAction mainActions = new MainActions<G, A, R>(findDialogManager, replaceDialogManager, mainViewFrame, globalSettings, mapViewSettings, archetypeSet, copyBuffer, objectChooser, mapManager, mapViewManager, resources, insertionModeSet, exiter); - final EditorAction mapCursorActions = new MapCursorActions<G, A, R>(objectChooser, mapViewManager); + final EditorAction mapCursorActions = new MapCursorActions<G, A, R>(mapViewManager); final Action moveSquareDownAction = createAction("moveSquareDown", "Selected Square View", new MoveSquareDownAction<G, A, R>(selectedSquareModel, mapManager)); final Action moveSquareUpAction = createAction("moveSquareUp", "Selected Square View", new MoveSquareUpAction<G, A, R>(selectedSquareModel, mapManager)); final Action moveSquareBottomAction = createAction("moveSquareBottom", "Selected Square View", new MoveSquareBottomAction<G, A, R>(selectedSquareModel, mapManager)); @@ -558,7 +559,7 @@ createAction("subFromSelection", "Map Cursor,Map/Selection", mapCursorActions); createAction("startStopDrag", "Map Cursor,Map/Selection", mapCursorActions); createAction("releaseDrag", "Map Cursor,Map/Selection", mapCursorActions); - createAction("insertArch", "Map Cursor,Map", mapCursorActions); + createAction("insertArch", "Map Cursor,Map", new InsertArchAction<G, A, R>(mapViewManager, objectChooser)); createAction("deleteArch", "Map Cursor,Map", new DeleteArchAction<G, A, R>(mapViewManager)); createAction("selectArchAbove", "Map Cursor,Selected Square View", new SelectArchBelowAction<G, A, R>(mapViewManager)); createAction("selectArchBelow", "Map Cursor,Selected Square View", new SelectArchAboveAction<G, A, R>(mapViewManager)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |