From: <aki...@us...> - 2011-10-30 17:28:33
|
Revision: 9073 http://gridarta.svn.sourceforge.net/gridarta/?rev=9073&view=rev Author: akirschbaum Date: 2011-10-30 17:28:23 +0000 (Sun, 30 Oct 2011) Log Message: ----------- Remove MapSquareSelection and MapSquareSelectionCache; maintain the selected game object in MapCursor. Modified Paths: -------------- trunk/model/src/app/net/sf/gridarta/model/gameobject/AbstractGameObject.java trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursorListener.java trunk/model/src/test/net/sf/gridarta/model/mapcursor/MapCursorTest.java trunk/src/app/net/sf/gridarta/gui/exitconnector/ExitConnectorController.java trunk/src/app/net/sf/gridarta/gui/mainwindow/GameObjectTextEditorTab.java trunk/src/app/net/sf/gridarta/gui/map/event/MouseOpEvent.java trunk/src/app/net/sf/gridarta/gui/map/mapactions/MapActions.java trunk/src/app/net/sf/gridarta/gui/map/mapview/AbstractMapView.java trunk/src/app/net/sf/gridarta/gui/map/mapview/DefaultMapView.java trunk/src/app/net/sf/gridarta/gui/map/mapview/DefaultMapViewFactory.java trunk/src/app/net/sf/gridarta/gui/map/mapview/MapCursorTracker.java trunk/src/app/net/sf/gridarta/gui/map/mapview/MapView.java trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java trunk/src/app/net/sf/gridarta/gui/misc/StatusBar.java trunk/src/app/net/sf/gridarta/gui/panel/gameobjectattributes/GameObjectAttributesControl.java trunk/src/app/net/sf/gridarta/gui/panel/objectchooser/DefaultObjectChooser.java trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/ModelUpdater.java trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareActions.java trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareModel.java trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareModelListener.java trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareView.java trunk/src/app/net/sf/gridarta/gui/panel/tools/DeletionTool.java trunk/src/app/net/sf/gridarta/gui/panel/tools/InsertionTool.java trunk/src/app/net/sf/gridarta/gui/panel/tools/SelectionTool.java trunk/src/app/net/sf/gridarta/mainactions/MainActions.java trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java trunk/src/test/net/sf/gridarta/gui/map/mapview/TestMapView.java trunk/src/test/net/sf/gridarta/gui/map/mapview/TestMapViewFactory.java trunk/src/test/net/sf/gridarta/gui/map/test/TestMapControlCreatorUtils.java trunk/src/test/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareActionsTest.java Removed Paths: ------------- trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/MapSquareSelection.java trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/MapSquareSelectionCache.java trunk/src/test/net/sf/gridarta/gui/panel/selectedsquare/MapSquareSelectionTest.java Modified: trunk/model/src/app/net/sf/gridarta/model/gameobject/AbstractGameObject.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/gameobject/AbstractGameObject.java 2011-10-29 20:24:50 UTC (rev 9072) +++ trunk/model/src/app/net/sf/gridarta/model/gameobject/AbstractGameObject.java 2011-10-30 17:28:23 UTC (rev 9073) @@ -204,11 +204,8 @@ */ @Override public boolean isTop() { - if (container == null) { - throw new NotInsideContainerException(getThis()); - } //noinspection ConstantConditions - return container.isTop(getThis()); + return container == null || container.isTop(getThis()); } /** @@ -216,11 +213,8 @@ */ @Override public boolean isBottom() { - if (container == null) { - throw new NotInsideContainerException(getThis()); - } //noinspection ConstantConditions - return container.isBottom(getThis()); + return container == null || container.isBottom(getThis()); } /** @@ -228,11 +222,10 @@ */ @Override public void moveTop() { - if (container == null) { - throw new NotInsideContainerException(getThis()); + if (container != null) { + //noinspection ConstantConditions + container.moveTop(getThis()); } - //noinspection ConstantConditions - container.moveTop(getThis()); } /** @@ -240,11 +233,10 @@ */ @Override public void moveUp() { - if (container == null) { - throw new NotInsideContainerException(getThis()); + if (container != null) { + //noinspection ConstantConditions + container.moveUp(getThis()); } - //noinspection ConstantConditions - container.moveUp(getThis()); } /** @@ -252,11 +244,10 @@ */ @Override public void moveDown() { - if (container == null) { - throw new NotInsideContainerException(getThis()); + if (container != null) { + //noinspection ConstantConditions + container.moveDown(getThis()); } - //noinspection ConstantConditions - container.moveDown(getThis()); } /** @@ -264,11 +255,10 @@ */ @Override public void moveBottom() { - if (container == null) { - throw new NotInsideContainerException(getThis()); + if (container != null) { + //noinspection ConstantConditions + container.moveBottom(getThis()); } - //noinspection ConstantConditions - container.moveBottom(getThis()); } /** Modified: trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java 2011-10-29 20:24:50 UTC (rev 9072) +++ trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java 2011-10-30 17:28:23 UTC (rev 9073) @@ -22,11 +22,16 @@ import java.awt.Dimension; import java.awt.Point; import java.awt.Rectangle; +import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.direction.Direction; +import net.sf.gridarta.model.gameobject.GameObject; +import net.sf.gridarta.model.maparchobject.MapArchObject; import net.sf.gridarta.model.mapgrid.MapGrid; import net.sf.gridarta.model.mapgrid.MapGridEvent; import net.sf.gridarta.model.mapgrid.MapGridListener; import net.sf.gridarta.model.mapgrid.SelectionMode; +import net.sf.gridarta.model.mapmodel.MapModel; +import net.sf.gridarta.model.mapmodel.MapSquare; import net.sf.gridarta.utils.EventListenerList2; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -38,8 +43,9 @@ * <li>Deactivated</li> <li>On the map</li> <li>Dragging</li> </ul> When * coordinates or state of MapCursor changes an event is fired. * @author <a href="mailto:dlv...@gm...">Daniel Viegas</a> + * @author Andreas Kirschbaum */ -public class MapCursor { +public class MapCursor<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> { /** * Current cursor position. When cursor is active it is highlighted on the @@ -77,6 +83,12 @@ private final MapGrid mapGrid; /** + * The {@link MapModel} of this cursor. + */ + @NotNull + private final MapModel<G, A, R> mapModel; + + /** * Used to test if coordinates are on the map. Created by MapGrid. */ @NotNull @@ -90,18 +102,32 @@ private final Point tmpPoint = new Point(); /** + * The selected {@link MapSquare}. + */ + @Nullable + private MapSquare<G, A, R> mapSquare; + + /** + * The selected {@link GameObject}. + */ + @Nullable + private G gameObject; + + /** * The MapCursorListeners to inform of changes. */ @NotNull - private final EventListenerList2<MapCursorListener> listenerList = new EventListenerList2<MapCursorListener>(MapCursorListener.class); + private final EventListenerList2<MapCursorListener<G, A, R>> listenerList = new EventListenerList2<MapCursorListener<G, A, R>>(MapCursorListener.class); /** * Construct a MapCursor. The cursor will be deactivated after * construction. * @param mapGrid Cursor is bound to this grid + * @param mapModel the map model of this cursor */ - public MapCursor(@NotNull final MapGrid mapGrid) { + public MapCursor(@NotNull final MapGrid mapGrid, @NotNull final MapModel<G, A, R> mapModel) { this.mapGrid = mapGrid; + this.mapModel = mapModel; mapRec = mapGrid.getMapRec(); final MapGridListener mapGridListener = new MapGridListener() { @@ -121,6 +147,7 @@ if (onMap && !mapRec.contains(pos)) { pos.x = Math.min(pos.x, mapRec.width - 1); pos.y = Math.min(pos.y, mapRec.height - 1); + selectLastGameObject(); mapGrid.setCursor(pos); fireMapCursorChangedPosEvent(); } @@ -159,12 +186,14 @@ } else { mapGrid.unSetCursor(pos); pos.setLocation(p); + selectLastGameObject(); mapGrid.setCursor(pos); fireMapCursorChangedPosEvent(); hasChanged = true; } } else { pos.setLocation(p); + selectLastGameObject(); mapGrid.setCursor(pos); onMap = true; fireMapCursorChangedModeEvent(); @@ -200,11 +229,13 @@ } else { mapGrid.unSetCursor(pos); pos.setLocation(p); + selectLastGameObject(); mapGrid.setCursor(pos); hasChanged = true; } } else { pos.setLocation(p); + selectLastGameObject(); onMap = true; fireMapCursorChangedModeEvent(); hasChanged = true; @@ -252,6 +283,7 @@ final Point oldPos = new Point(pos); mapGrid.unSetCursor(pos); pos.setLocation(p); + selectLastGameObject(); mapGrid.updatePreSelect(dragStart, oldPos, pos); mapGrid.setCursor(pos); dragOffset.setSize(pos.x - dragStart.x, pos.y - dragStart.y); @@ -302,18 +334,23 @@ */ public final void deactivate() { final boolean hasChanged = onMap; + final boolean hasChangedGameObject = mapSquare != null || gameObject != null; mapGrid.beginTransaction(); try { onMap = false; dragging = false; mapGrid.unSetCursor(pos); mapGrid.unSelect(); + mapSquare = null; + gameObject = null; } finally { mapGrid.endTransaction(); } if (hasChanged) { fireMapCursorChangedModeEvent(); fireMapCursorChangedPosEvent(); + } else if (hasChangedGameObject) { + fireGameObjectChangedEvent(); } } @@ -374,7 +411,7 @@ * Register a MapCursorListener. * @param listener MapCursorListener to register */ - public void addMapCursorListener(@NotNull final MapCursorListener listener) { + public void addMapCursorListener(@NotNull final MapCursorListener<G, A, R> listener) { listenerList.add(listener); } @@ -382,7 +419,7 @@ * Remove a MapCursorListener. * @param listener MapCursorListener to remove */ - public void removeMapCursorListener(@NotNull final MapCursorListener listener) { + public void removeMapCursorListener(@NotNull final MapCursorListener<G, A, R> listener) { listenerList.remove(listener); } @@ -390,7 +427,7 @@ * Inform all registered listeners that the MapCursor's mode has changed. */ private void fireMapCursorChangedModeEvent() { - for (final MapCursorListener listener : listenerList.getListeners()) { + for (final MapCursorListener<G, A, R> listener : listenerList.getListeners()) { listener.mapCursorChangedMode(); } } @@ -400,12 +437,61 @@ * changed. */ private void fireMapCursorChangedPosEvent() { - for (final MapCursorListener listener : listenerList.getListeners()) { + for (final MapCursorListener<G, A, R> listener : listenerList.getListeners()) { listener.mapCursorChangedPos(getLocation()); } } /** + * Notifies all listeners that the selected game object has changed. + */ + private void fireGameObjectChangedEvent() { + for (final MapCursorListener<G, A, R> listener : listenerList.getListeners()) { + listener.mapCursorChangedGameObject(mapSquare, gameObject); + } + } + + /** + * Returns the selected {@link GameObject}. + * @return the selected game object or <code>null</code> if the map cursor + * is not active or if the selected map square is empty + */ + @Nullable + public G getGameObject() { + return gameObject; + } + + /** + * Sets the selected {@link GameObject}. If the game object is not on a map + * or not on the map this cursor is attached to, the cursor is deactivated. + * @param gameObject the selected game object or <code>null</code> to + * deactivate the cursor + */ + public void setGameObject(@Nullable final G gameObject) { + if (gameObject == null) { + if (this.gameObject != null) { + this.gameObject = null; + fireGameObjectChangedEvent(); + } + return; + } + + final MapSquare<G, A, R> mapSquare = gameObject.getMapSquare(); + if (mapSquare == null || mapSquare.getMapModel() != mapModel) { + if (onMap) { + deactivate(); + } + return; + } + + if (this.mapSquare != mapSquare || this.gameObject != gameObject) { + this.mapSquare = mapSquare; + this.gameObject = gameObject; + fireGameObjectChangedEvent(); + } + } + + /** * Start a new transaction. Transactions may be nested. Transactions serve * the purpose of firing events to the views when more changes are known to * come before the view is really required to update. Each invocation of @@ -423,4 +509,26 @@ mapGrid.endTransaction(); } + /** + * Selects the last (top-most) {@link GameObject} on the current map + * location. + */ + private void selectLastGameObject() { + @Nullable MapSquare<G, A, R> newMapSquare; + @Nullable G newGameObject; + try { + newMapSquare = mapModel.getMapSquare(pos); + newGameObject = newMapSquare.getLast(); + } catch (final IndexOutOfBoundsException ignored) { + newMapSquare = null; + newGameObject = null; + } + if (mapSquare == newMapSquare && gameObject == newGameObject) { + return; + } + mapSquare = newMapSquare; + gameObject = newGameObject; + fireGameObjectChangedEvent(); + } + } // class MapCursor Modified: trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursorListener.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursorListener.java 2011-10-29 20:24:50 UTC (rev 9072) +++ trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursorListener.java 2011-10-30 17:28:23 UTC (rev 9073) @@ -21,13 +21,18 @@ import java.awt.Point; import java.util.EventListener; +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.mapmodel.MapSquare; import org.jetbrains.annotations.Nullable; /** * Interface for listeners listening to {@link MapCursor} related events. * @author <a href="mailto:dlv...@gm...">Daniel Viegas</a> + * @author Andreas Kirschbaum */ -public interface MapCursorListener extends EventListener { +public interface MapCursorListener<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends EventListener { /** * This event handler is called when {@link MapCursor} has moved, appeared @@ -43,4 +48,15 @@ */ void mapCursorChangedMode(); + /** + * Called whenever the selected game object has changed. This function is + * <em>not</em> called if {@link #mapCursorChangedPos(Point)} occurs + * concurrently. + * @param mapSquare the newly selected map square or <code>null</code> if no + * map square is selected + * @param gameObject the newly selected game object or <code>null</code> if + * no game object is selected + */ + void mapCursorChangedGameObject(@Nullable MapSquare<G, A, R> mapSquare, @Nullable G gameObject); + } // interface MapCursorListener Modified: trunk/model/src/test/net/sf/gridarta/model/mapcursor/MapCursorTest.java =================================================================== --- trunk/model/src/test/net/sf/gridarta/model/mapcursor/MapCursorTest.java 2011-10-29 20:24:50 UTC (rev 9072) +++ trunk/model/src/test/net/sf/gridarta/model/mapcursor/MapCursorTest.java 2011-10-30 17:28:23 UTC (rev 9073) @@ -22,9 +22,14 @@ import java.awt.Dimension; import java.awt.Point; import junit.framework.JUnit4TestAdapter; +import net.sf.gridarta.model.archetype.TestArchetype; import net.sf.gridarta.model.direction.Direction; +import net.sf.gridarta.model.gameobject.TestGameObject; +import net.sf.gridarta.model.maparchobject.TestMapArchObject; import net.sf.gridarta.model.mapgrid.MapGrid; import net.sf.gridarta.model.mapgrid.SelectionMode; +import net.sf.gridarta.model.mapmodel.MapSquare; +import net.sf.gridarta.model.mapmodel.TestMapModelCreator; import net.sf.gridarta.utils.Size2D; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -58,8 +63,10 @@ * @return the new map cursor instance */ @NotNull - public static MapCursor createCursor(@NotNull final MapGrid grid) { - final MapCursor cursor = new MapCursor(grid); + public static MapCursor<TestGameObject, TestMapArchObject, TestArchetype> createCursor(@NotNull final MapGrid grid) { + final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false); + final Size2D gridSize = grid.getSize(); + final MapCursor<TestGameObject, TestMapArchObject, TestArchetype> cursor = new MapCursor<TestGameObject, TestMapArchObject, TestArchetype>(grid, mapModelCreator.newMapModel(gridSize.getWidth(), gridSize.getHeight())); cursor.addMapCursorListener(listener); Assert.assertFalse("MapCursor has to be disabled when created.", cursor.isActive()); listener.changedPosCounter = 0; @@ -73,7 +80,7 @@ @Test public void setOutside() { final MapGrid grid = new MapGrid(gridSize); - final MapCursor cursor = createCursor(grid); + final MapCursor<TestGameObject, TestMapArchObject, TestArchetype> cursor = createCursor(grid); final Point p = new Point(); for (int i = -2; i < gridSize.getWidth() + 2; i++) { p.setLocation(i, -1); @@ -115,7 +122,7 @@ @Test public void setInside() { final MapGrid grid = new MapGrid(gridSize); - final MapCursor cursor = createCursor(grid); + final MapCursor<TestGameObject, TestMapArchObject, TestArchetype> cursor = createCursor(grid); boolean first = true; final Point p = new Point(); for (int j = 0; j < gridSize.getHeight(); j++) { @@ -145,7 +152,7 @@ @Test public void setSameLocation() { final MapGrid grid = new MapGrid(gridSize); - final MapCursor cursor = createCursor(grid); + final MapCursor<TestGameObject, TestMapArchObject, TestArchetype> cursor = createCursor(grid); final Point p = new Point(-1, -1); Assert.assertFalse("setLocation(null) should return false", cursor.setLocation(null)); testEvents(0, 0); @@ -177,7 +184,7 @@ @Test public void setLocationSafe() { final MapGrid grid = new MapGrid(gridSize); - final MapCursor cursor = createCursor(grid); + final MapCursor<TestGameObject, TestMapArchObject, TestArchetype> cursor = createCursor(grid); final Point p = new Point(-1, -1); Assert.assertFalse("setLocationSafe(null) should return false", cursor.setLocationSafe(null)); testEvents(0, 0); @@ -213,7 +220,7 @@ @Test public void testIsOnGrid() { final MapGrid grid = new MapGrid(gridSize); - final MapCursor cursor = createCursor(grid); + final MapCursor<TestGameObject, TestMapArchObject, TestArchetype> cursor = createCursor(grid); final Point p = new Point(); for (int j = -2; j < gridSize.getHeight() + 2; j++) { for (int i = -2; i < gridSize.getWidth() + 2; i++) { @@ -234,7 +241,7 @@ @Test public void testGoTo() { final MapGrid grid = new MapGrid(gridSize); - final MapCursor cursor = createCursor(grid); + final MapCursor<TestGameObject, TestMapArchObject, TestArchetype> cursor = createCursor(grid); for (final Direction dir : Direction.values()) { Assert.assertFalse("go(" + dir + ") should return false.", cursor.goTo(dir)); testEvents(0, 0); @@ -259,7 +266,7 @@ @Test public void dragging() { final MapGrid grid = new MapGrid(gridSize); - final MapCursor cursor = createCursor(grid); + final MapCursor<TestGameObject, TestMapArchObject, TestArchetype> cursor = createCursor(grid); Assert.assertFalse("MapCursor should not drag while deactivated.", cursor.isDragging()); cursor.dragStart(); testEvents(0, 0); @@ -302,7 +309,7 @@ * @param p the destination location * @param offset the expected dragging offset */ - private static void dragTo(@NotNull final MapCursor cursor, @NotNull final MapGrid grid, @NotNull final Direction dir, @NotNull final Point start, @NotNull final Point p, @NotNull final Dimension offset) { + private static void dragTo(@NotNull final MapCursor<TestGameObject, TestMapArchObject, TestArchetype> cursor, @NotNull final MapGrid grid, @NotNull final Direction dir, @NotNull final Point start, @NotNull final Point p, @NotNull final Dimension offset) { final Point d = new Point(dir.getDx(), dir.getDy()); p.x += d.x; p.y += d.y; @@ -372,7 +379,7 @@ @Test public void selecting() { final MapGrid grid = new MapGrid(gridSize); - final MapCursor cursor = createCursor(grid); + final MapCursor<TestGameObject, TestMapArchObject, TestArchetype> cursor = createCursor(grid); final Point start = new Point(2, 3); final Point end = new Point(4, 5); final Point gridMaxIndex = new Point(gridSize.getWidth() - 1, gridSize.getHeight() - 1); @@ -471,7 +478,7 @@ /** * A {@link MapCursorListener} that counts the number of event callbacks. */ - private static class TestMapCursorListener implements MapCursorListener { + private static class TestMapCursorListener implements MapCursorListener<TestGameObject, TestMapArchObject, TestArchetype> { /** * The number of calls to {@link #mapCursorChangedPos(Point)}. @@ -499,6 +506,11 @@ changedModeCounter++; } + @Override + public void mapCursorChangedGameObject(@Nullable final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquare, @Nullable final TestGameObject gameObject) { + // ignore + } + } // class TestMapCursorListener } // class MapCursorTest Modified: trunk/src/app/net/sf/gridarta/gui/exitconnector/ExitConnectorController.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/exitconnector/ExitConnectorController.java 2011-10-29 20:24:50 UTC (rev 9072) +++ trunk/src/app/net/sf/gridarta/gui/exitconnector/ExitConnectorController.java 2011-10-30 17:28:23 UTC (rev 9073) @@ -32,6 +32,7 @@ import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; import net.sf.gridarta.model.mapcursor.MapCursorListener; +import net.sf.gridarta.model.mapmodel.MapSquare; import net.sf.gridarta.utils.ActionUtils; import net.sf.japi.swing.action.ActionBuilder; import net.sf.japi.swing.action.ActionBuilderFactory; @@ -144,7 +145,7 @@ * {@link #currentMapView}. */ @NotNull - private final MapCursorListener mapCursorListener = new MapCursorListener() { + private final MapCursorListener<G, A, R> mapCursorListener = new MapCursorListener<G, A, R>() { /** {@inheritDoc} */ @Override @@ -158,6 +159,11 @@ refreshActions(); } + @Override + public void mapCursorChangedGameObject(@Nullable final MapSquare<G, A, R> mapSquare, @Nullable final G gameObject) { + //ignore + } + }; /** Modified: trunk/src/app/net/sf/gridarta/gui/mainwindow/GameObjectTextEditorTab.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/mainwindow/GameObjectTextEditorTab.java 2011-10-29 20:24:50 UTC (rev 9072) +++ trunk/src/app/net/sf/gridarta/gui/mainwindow/GameObjectTextEditorTab.java 2011-10-30 17:28:23 UTC (rev 9073) @@ -24,7 +24,6 @@ import java.io.File; import java.util.Set; import net.sf.gridarta.gui.panel.gameobjecttexteditor.GameObjectTextEditor; -import net.sf.gridarta.gui.panel.selectedsquare.MapSquareSelection; import net.sf.gridarta.gui.panel.selectedsquare.SelectedSquareModel; import net.sf.gridarta.gui.panel.selectedsquare.SelectedSquareModelListener; import net.sf.gridarta.gui.utils.borderpanel.Location; @@ -234,17 +233,12 @@ selectedSquareModel.addSelectedSquareListener(new SelectedSquareModelListener<G, A, R>() { @Override - public void selectedGameObjectChanged(@Nullable final G gameObject) { + public void selectionChanged(@Nullable final MapSquare<G, A, R> mapSquare, @Nullable final G gameObject) { autoApplyArchPanelChanges(); selectedGameObject = gameObject; refreshDisplay(); } - @Override - public void selectedMapSquareSelectionChanged(@Nullable final MapSquareSelection<G, A, R> mapSquareSelection) { - // ignore - } - }); currentMapControl = mapManager.getCurrentMap(); if (currentMapControl != null) { Modified: trunk/src/app/net/sf/gridarta/gui/map/event/MouseOpEvent.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/event/MouseOpEvent.java 2011-10-29 20:24:50 UTC (rev 9072) +++ trunk/src/app/net/sf/gridarta/gui/map/event/MouseOpEvent.java 2011-10-30 17:28:23 UTC (rev 9073) @@ -51,7 +51,7 @@ * The cursor to use for this event. */ @NotNull - private final MapCursor mapCursor; + private final MapCursor<G, A, R> mapCursor; /** * The map control for this event. @@ -115,7 +115,7 @@ } @NotNull - public MapCursor getMapCursor() { + public MapCursor<G, A, R> getMapCursor() { return mapCursor; } Modified: trunk/src/app/net/sf/gridarta/gui/map/mapactions/MapActions.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/mapactions/MapActions.java 2011-10-29 20:24:50 UTC (rev 9072) +++ trunk/src/app/net/sf/gridarta/gui/map/mapactions/MapActions.java 2011-10-30 17:28:23 UTC (rev 9073) @@ -345,7 +345,7 @@ * The map cursor listener which is attached to {@link #currentMapView}. */ @NotNull - private final MapCursorListener mapCursorListener = new MapCursorListener() { + private final MapCursorListener<G, A, R> mapCursorListener = new MapCursorListener<G, A, R>() { /** {@inheritDoc} */ @Override @@ -359,6 +359,11 @@ // ignore } + @Override + public void mapCursorChangedGameObject(@Nullable final MapSquare<G, A, R> mapSquare, @Nullable final G gameObject) { + // ignore + } + }; /** Modified: trunk/src/app/net/sf/gridarta/gui/map/mapview/AbstractMapView.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/mapview/AbstractMapView.java 2011-10-29 20:24:50 UTC (rev 9072) +++ trunk/src/app/net/sf/gridarta/gui/map/mapview/AbstractMapView.java 2011-10-30 17:28:23 UTC (rev 9073) @@ -57,7 +57,7 @@ * The {@link MapCursor} of this map view. */ @NotNull - private final MapCursor mapCursor; + private final MapCursor<G, A, R> mapCursor; /** * Creates a new instance. @@ -65,7 +65,7 @@ * @param mapGrid the map grid of this map view * @param mapCursor the map cursor of this map view */ - protected AbstractMapView(@NotNull final MapModel<G, A, R> mapModel, @NotNull final MapGrid mapGrid, @NotNull final MapCursor mapCursor) { + protected AbstractMapView(@NotNull final MapModel<G, A, R> mapModel, @NotNull final MapGrid mapGrid, @NotNull final MapCursor<G, A, R> mapCursor) { this.mapModel = mapModel; this.mapGrid = mapGrid; this.mapCursor = mapCursor; @@ -136,7 +136,7 @@ */ @NotNull @Override - public MapCursor getMapCursor() { + public MapCursor<G, A, R> getMapCursor() { return mapCursor; } Modified: trunk/src/app/net/sf/gridarta/gui/map/mapview/DefaultMapView.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/mapview/DefaultMapView.java 2011-10-29 20:24:50 UTC (rev 9072) +++ trunk/src/app/net/sf/gridarta/gui/map/mapview/DefaultMapView.java 2011-10-30 17:28:23 UTC (rev 9073) @@ -196,7 +196,7 @@ * @param xScrollDistance the x distance when scrolling * @param yScrollDistance the y distance when scrolling */ - public DefaultMapView(@NotNull final MapControl<G, A, R> mapControl, final int number, @NotNull final PathManager pathManager, @NotNull final MapGrid mapGrid, @NotNull final MapCursor mapCursor, final AbstractMapRenderer<G, A, R> renderer, @Nullable final Point viewPosition, final int xScrollDistance, final int yScrollDistance) { + public DefaultMapView(@NotNull final MapControl<G, A, R> mapControl, final int number, @NotNull final PathManager pathManager, @NotNull final MapGrid mapGrid, @NotNull final MapCursor<G, A, R> mapCursor, final AbstractMapRenderer<G, A, R> renderer, @Nullable final Point viewPosition, final int xScrollDistance, final int yScrollDistance) { super(mapControl.getMapModel(), mapGrid, mapCursor); internalFrame = new JInternalFrame(getWindowTitle(mapControl, number, pathManager), true, true, true, true); this.mapControl = mapControl; Modified: trunk/src/app/net/sf/gridarta/gui/map/mapview/DefaultMapViewFactory.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/mapview/DefaultMapViewFactory.java 2011-10-29 20:24:50 UTC (rev 9072) +++ trunk/src/app/net/sf/gridarta/gui/map/mapview/DefaultMapViewFactory.java 2011-10-30 17:28:23 UTC (rev 9073) @@ -92,7 +92,7 @@ final MapGrid mapGrid = new MapGrid(mapModel.getMapArchObject().getMapSize()); final AbstractMapRenderer<G, A, R> renderer = mapControl.isPickmap() ? rendererFactory.newPickmapRenderer(mapModel, mapGrid) : rendererFactory.newMapRenderer(mapModel, mapGrid); renderer.setFocusable(true); - final MapView<G, A, R> mapView = new DefaultMapView<G, A, R>(mapControl, viewCounter, pathManager, mapGrid, new MapCursor(mapGrid), renderer, viewPosition, xScrollDistance, yScrollDistance); + final MapView<G, A, R> mapView = new DefaultMapView<G, A, R>(mapControl, viewCounter, pathManager, mapGrid, new MapCursor<G, A, R>(mapGrid, mapModel), renderer, viewPosition, xScrollDistance, yScrollDistance); mapView.getInternalFrame().setJMenuBar(ACTION_BUILDER.createMenuBar(false, "mapwindow")); return mapView; } Modified: trunk/src/app/net/sf/gridarta/gui/map/mapview/MapCursorTracker.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/mapview/MapCursorTracker.java 2011-10-29 20:24:50 UTC (rev 9072) +++ trunk/src/app/net/sf/gridarta/gui/map/mapview/MapCursorTracker.java 2011-10-30 17:28:23 UTC (rev 9073) @@ -29,6 +29,7 @@ import net.sf.gridarta.model.maparchobject.MapArchObject; import net.sf.gridarta.model.mapcursor.MapCursor; import net.sf.gridarta.model.mapcursor.MapCursorListener; +import net.sf.gridarta.model.mapmodel.MapSquare; import net.sf.gridarta.utils.CommonConstants; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -45,7 +46,7 @@ * The {@link MapCursor} to track. */ @NotNull - private final MapCursor mapCursor; + private final MapCursor<G, A, R> mapCursor; /** * The {@link AbstractMapRenderer} to update. @@ -63,7 +64,7 @@ * The {@link MapCursorListener} attached to {@link #mapCursor}. */ @NotNull - private final MapCursorListener mapCursorListener = new MapCursorListener() { + private final MapCursorListener<G, A, R> mapCursorListener = new MapCursorListener<G, A, R>() { /** {@inheritDoc} */ @Override @@ -77,6 +78,11 @@ // Ignore mode change events } + @Override + public void mapCursorChangedGameObject(@Nullable final MapSquare<G, A, R> mapSquare, @Nullable final G gameObject) { + // ignore + } + }; /** @@ -89,7 +95,7 @@ * @param mapCursor the map cursor to track * @param renderer the map renderer to update */ - public MapCursorTracker(final boolean isPickmap, @Nullable final Point viewPosition, final int xScrollDistance, final int yScrollDistance, @NotNull final MapCursor mapCursor, @NotNull final AbstractMapRenderer<G, A, R> renderer) { + public MapCursorTracker(final boolean isPickmap, @Nullable final Point viewPosition, final int xScrollDistance, final int yScrollDistance, @NotNull final MapCursor<G, A, R> mapCursor, @NotNull final AbstractMapRenderer<G, A, R> renderer) { this.mapCursor = mapCursor; this.renderer = renderer; this.mapCursor.addMapCursorListener(mapCursorListener); Modified: trunk/src/app/net/sf/gridarta/gui/map/mapview/MapView.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/mapview/MapView.java 2011-10-29 20:24:50 UTC (rev 9072) +++ trunk/src/app/net/sf/gridarta/gui/map/mapview/MapView.java 2011-10-30 17:28:23 UTC (rev 9073) @@ -118,7 +118,7 @@ * @return the map cursor of this view */ @NotNull - MapCursor getMapCursor(); + MapCursor<G, A, R> getMapCursor(); /** * Returns the {@link MapRenderer} for this view. Modified: trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java 2011-10-29 20:24:50 UTC (rev 9072) +++ trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java 2011-10-30 17:28:23 UTC (rev 9073) @@ -37,6 +37,8 @@ import net.sf.gridarta.model.mapcursor.MapCursor; import net.sf.gridarta.model.mapcursor.MapCursorListener; import net.sf.gridarta.model.mapgrid.SelectionMode; +import net.sf.gridarta.model.mapmodel.MapModel; +import net.sf.gridarta.model.mapmodel.MapSquare; import net.sf.gridarta.utils.ActionUtils; import net.sf.japi.swing.action.ActionBuilder; import net.sf.japi.swing.action.ActionBuilderFactory; @@ -186,7 +188,7 @@ * #currentMapView}. */ @NotNull - private final MapCursorListener mapCursorListener = new MapCursorListener() { + private final MapCursorListener<G, A, R> mapCursorListener = new MapCursorListener<G, A, R>() { /** {@inheritDoc} */ @Override @@ -200,6 +202,11 @@ refreshActions(); } + @Override + public void mapCursorChangedGameObject(@Nullable final MapSquare<G, A, R> mapSquare, @Nullable final G gameObject) { + // ignore + } + }; /** @@ -395,7 +402,7 @@ * or if no map view exists */ @Nullable - private MapCursor getActiveMapCursor() { + private MapCursor<G, A, R> getActiveMapCursor() { final MapView<G, A, R> mapView = currentMapView; return mapView == null ? null : getActiveMapCursor(mapView); } @@ -407,8 +414,8 @@ * or if no map view exists */ @Nullable - private MapCursor getActiveMapCursor(@NotNull final MapView<G, A, R> mapView) { - final MapCursor mapCursor = mapView.getMapCursor(); + private MapCursor<G, A, R> getActiveMapCursor(@NotNull final MapView<G, A, R> mapView) { + final MapCursor<G, A, R> mapCursor = mapView.getMapCursor(); return mapCursor.isActive() ? mapCursor : null; } @@ -433,7 +440,7 @@ aArchAttributes.setEnabled(doArchAttributes(false)); } - private static void selectSquare(@NotNull final MapCursor mapCursor, final SelectionMode mode) { + private void selectSquare(@NotNull final MapCursor<G, A, R> mapCursor, final SelectionMode mode) { mapCursor.dragStart(); mapCursor.dragSelect(mode); } @@ -445,7 +452,7 @@ * @return whether the action was or can be performed */ private boolean doGo(final boolean performAction, @NotNull final Direction direction) { - final MapCursor mapCursor = getActiveMapCursor(); + final MapCursor<G, A, R> mapCursor = getActiveMapCursor(); if (mapCursor == null) { return false; } @@ -509,7 +516,7 @@ * @return whether the action was or can be performed */ private boolean doSelection(final boolean performAction, @NotNull final SelectionMode mode) { - final MapCursor mapCursor = getActiveMapCursor(); + final MapCursor<G, A, R> mapCursor = getActiveMapCursor(); if (mapCursor == null) { return false; } @@ -527,7 +534,7 @@ * @return whether the action was or can be performed */ private boolean doStartStopDrag(final boolean performAction) { - final MapCursor mapCursor = getActiveMapCursor(); + final MapCursor<G, A, R> mapCursor = getActiveMapCursor(); if (mapCursor == null) { return false; } @@ -549,7 +556,7 @@ * @return whether the action was or can be performed */ private boolean doReleaseDrag(final boolean performAction) { - final MapCursor mapCursor = getActiveMapCursor(); + final MapCursor<G, A, R> mapCursor = getActiveMapCursor(); if (mapCursor == null) { return false; } @@ -583,7 +590,7 @@ } if (performAction) { - selectedSquareView.insertGameObjectFromObjectChooser(mapView); + selectedSquareView.insertGameObjectFromObjectChooser(mapView.getMapControl().getMapModel()); } return true; @@ -600,12 +607,29 @@ return false; } - if (getActiveMapCursor(mapView) == null) { // XXX: should pass to function + final MapCursor<G, A, R> mapCursor = getActiveMapCursor(mapView); + if (mapCursor == null) { return false; } + final G gameObject = mapCursor.getGameObject(); + if (gameObject == null) { + return false; + } + + final MapSquare<G, A, R> mapSquare = gameObject.getMapSquare(); + if (mapSquare == null) { + return false; + } + if (performAction) { - selectedSquareView.deleteSelection(mapView); + final MapModel<G, A, R> mapModel = mapSquare.getMapModel(); + mapModel.beginTransaction("Delete"); // TODO; I18N/L10N + try { + mapModel.removeGameObject(gameObject, true); + } finally { + mapModel.endTransaction(); + } } return true; @@ -617,7 +641,7 @@ * @return whether the action was or can be performed */ private boolean doSelectArchAbove(final boolean performAction) { - final MapCursor mapCursor = getActiveMapCursor(); + final MapCursor<G, A, R> mapCursor = getActiveMapCursor(); if (mapCursor == null) { return false; } @@ -635,7 +659,7 @@ * @return whether the action was or can be performed */ private boolean doSelectArchBelow(final boolean performAction) { - final MapCursor mapCursor = getActiveMapCursor(); + final MapCursor<G, A, R> mapCursor = getActiveMapCursor(); if (mapCursor == null) { return false; } @@ -653,7 +677,7 @@ * @return whether the action was or can be performed */ private boolean doArchAttributes(final boolean performAction) { - final MapCursor mapCursor = getActiveMapCursor(); + final MapCursor<G, A, R> mapCursor = getActiveMapCursor(); if (mapCursor == null) { return false; } Modified: trunk/src/app/net/sf/gridarta/gui/misc/StatusBar.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/misc/StatusBar.java 2011-10-29 20:24:50 UTC (rev 9072) +++ trunk/src/app/net/sf/gridarta/gui/misc/StatusBar.java 2011-10-30 17:28:23 UTC (rev 9073) @@ -49,6 +49,7 @@ import net.sf.gridarta.model.mapcursor.MapCursorListener; import net.sf.gridarta.model.mapmanager.MapManager; import net.sf.gridarta.model.mapmanager.MapManagerListener; +import net.sf.gridarta.model.mapmodel.MapSquare; import net.sf.japi.swing.action.ActionBuilder; import net.sf.japi.swing.action.ActionBuilderFactory; import org.jetbrains.annotations.NotNull; @@ -129,7 +130,7 @@ /** * The map cursor listener to detect map cursor changes. */ - private final MapCursorListener mapCursorListener = new MapCursorListener() { + private final MapCursorListener<G, A, R> mapCursorListener = new MapCursorListener<G, A, R>() { /** {@inheritDoc} */ @Override @@ -143,6 +144,11 @@ mapCursorChanged(mapView == null ? null : mapView.getMapCursor()); } + @Override + public void mapCursorChangedGameObject(@Nullable final MapSquare<G, A, R> mapSquare, @Nullable final G gameObject) { + // ignore + } + }; /** @@ -351,7 +357,7 @@ * offset when in drag mode. * @param mapCursor the map cursor to set coordinates from */ - private void mapCursorChanged(@Nullable final MapCursor mapCursor) { + private void mapCursorChanged(@Nullable final MapCursor<G, A, R> mapCursor) { final String formatCursor; if (mapCursor == null) { formatCursor = ""; Modified: trunk/src/app/net/sf/gridarta/gui/panel/gameobjectattributes/GameObjectAttributesControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/panel/gameobjectattributes/GameObjectAttributesControl.java 2011-10-29 20:24:50 UTC (rev 9072) +++ trunk/src/app/net/sf/gridarta/gui/panel/gameobjectattributes/GameObjectAttributesControl.java 2011-10-30 17:28:23 UTC (rev 9073) @@ -36,7 +36,6 @@ import javax.swing.SwingConstants; import net.sf.gridarta.gui.dialog.gameobjectattributes.GameObjectAttributesDialogFactory; import net.sf.gridarta.gui.panel.objectchooser.ObjectChooser; -import net.sf.gridarta.gui.panel.selectedsquare.MapSquareSelection; import net.sf.gridarta.gui.panel.selectedsquare.SelectedSquareModel; import net.sf.gridarta.gui.panel.selectedsquare.SelectedSquareModelListener; import net.sf.gridarta.gui.panel.selectedsquare.SelectedSquareView; @@ -334,16 +333,10 @@ /** {@inheritDoc} */ @Override - public void selectedGameObjectChanged(@Nullable final G gameObject) { + public void selectionChanged(@Nullable final MapSquare<G, A, R> mapSquare, @Nullable final G gameObject) { gameObjectAttributesModel.setSelectedGameObject(gameObject); } - /** {@inheritDoc} */ - @Override - public void selectedMapSquareSelectionChanged(@Nullable final MapSquareSelection<G, A, R> mapSquareSelection) { - // ignore - } - }; /** Modified: trunk/src/app/net/sf/gridarta/gui/panel/objectchooser/DefaultObjectChooser.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/panel/objectchooser/DefaultObjectChooser.java 2011-10-29 20:24:50 UTC (rev 9072) +++ trunk/src/app/net/sf/gridarta/gui/panel/objectchooser/DefaultObjectChooser.java 2011-10-30 17:28:23 UTC (rev 9073) @@ -48,6 +48,7 @@ import net.sf.gridarta.model.mapcursor.MapCursor; import net.sf.gridarta.model.mapcursor.MapCursorListener; import net.sf.gridarta.model.mapmodel.MapModel; +import net.sf.gridarta.model.mapmodel.MapSquare; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -128,7 +129,7 @@ * The map cursor listener attached to {@link #activePickmapView}. */ @NotNull - private final MapCursorListener mapCursorListener = new MapCursorListener() { + private final MapCursorListener<G, A, R> mapCursorListener = new MapCursorListener<G, A, R>() { /** {@inheritDoc} */ @Override @@ -142,6 +143,11 @@ updatePickmapInfo(activePickmapView == null ? null : activePickmapView.getMapCursor()); } + @Override + public void mapCursorChangedGameObject(@Nullable final MapSquare<G, A, R> mapSquare, @Nullable final G gameObject) { + // ignore + } + }; /** @@ -396,7 +402,7 @@ * Updates the display information for the active pickmap. * @param mapCursor the map cursor or <code>null</code> */ - private void updatePickmapInfo(@Nullable final MapCursor mapCursor) { + private void updatePickmapInfo(@Nullable final MapCursor<G, A, R> mapCursor) { if (isPickmapActive()) { @Nullable final BaseObject<G, A, R, ?> gameObject; if (mapCursor == null) { Deleted: trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/MapSquareSelection.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/MapSquareSelection.java 2011-10-29 20:24:50 UTC (rev 9072) +++ trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/MapSquareSelection.java 2011-10-30 17:28:23 UTC (rev 9073) @@ -1,244 +0,0 @@ -/* - * 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.gui.panel.selectedsquare; - -import net.sf.gridarta.gui.map.mapview.MapView; -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.mapmodel.MapSquare; -import net.sf.gridarta.utils.EventListenerList2; -import org.apache.log4j.Category; -import org.apache.log4j.Logger; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * Holds the selection state for one {@link net.sf.gridarta.model.mapcontrol.MapControl}. - * It consists of a {@link MapSquare}, a {@link GameObject} in this map square, - * and a selection index (relative to the map square). <p/> The game object and - * the selection index are redundant. This redundancy is used to retain the - * selection when the map square changes. - * @author Andreas Kirschbaum - */ -public class MapSquareSelection<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> { - - /** - * The {@link Logger} for printing log messages. - */ - @NotNull - private static final Category log = Logger.getLogger(MapSquareSelection.class); - - /** - * The {@link MapSquareSelectionListener MapSquareSelectionListeners} to - * inform of changes. - */ - @NotNull - private final EventListenerList2<MapSquareSelectionListener<G, A, R>> listenerList = new EventListenerList2<MapSquareSelectionListener<G, A, R>>(MapSquareSelectionListener.class); - - /** - * The corresponding map view. - */ - @NotNull - private final MapView<G, A, R> mapView; - - /** - * The currently selected map square. It is set to <code>null</code> if no - * map square is selected. - */ - @Nullable - private MapSquare<G, A, R> mapSquare = null; - - /** - * The currently selected game object. It is part of {@link #mapSquare}. It - * is set to <code>null</code> if not game object is selected (or if - * <code>mapSquare</code> is <code>null</code>). - */ - @Nullable - private GameObject<G, A, R> gameObject = null; - - /** - * The index in the map square list that corresponds to {@link #gameObject}. - * It is set to zero if <code>gameObject</code> is <code>null</code>. - */ - private int index = 0; - - /** - * Creates a new instance. - * @param mapView the corresponding map view - */ - public MapSquareSelection(@NotNull final MapView<G, A, R> mapView) { - this.mapView = mapView; - } - - /** - * Selects a map square. If it is different from the previously selected map - * square, the state ({@link #gameObject} and {@link #index}) is reset. - * @param mapSquare the selected map square - * @param gameObject the selected game object, or <code>null</code> to - * deselect it - * @param index the selected index - * @return <code>true</code> if the state has changed - */ - public boolean setMapSquare(@Nullable final MapSquare<G, A, R> mapSquare, @Nullable final G gameObject, final int index) { - if (this.mapSquare == mapSquare && this.gameObject == gameObject && this.index == index) { - return false; - } - - this.mapSquare = mapSquare; - this.gameObject = gameObject; - this.index = index; - fireSelectionChangedEvent(mapSquare, gameObject, index); - return true; - } - - /** - * Validates that the selected map square is still valid. - * @return <code>true</code> if the state has changed - */ - public boolean validateMapSquare() { - final MapSquare<G, A, R> currentMapSquare = mapSquare; // copy for concurrency reasons - return currentMapSquare != null && !mapView.getMapControl().getMapModel().getMapArchObject().isPointValid(currentMapSquare.getMapLocation()) && setMapSquare(null, null, 0); - } - - /** - * Checks if the currently selected map square is affected by a change in - * the given map square. - * @param changedMapSquare the map square that has changed - * @return <code>true</code> if the state was updated - */ - public boolean checkForChangedMapSquare(@NotNull final MapSquare<G, A, R> changedMapSquare) { - final MapSquare<G, A, R> currentMapSquare = mapSquare; // copy for concurrency reasons - if (currentMapSquare == null || currentMapSquare.getMapModel() != changedMapSquare.getMapModel() || currentMapSquare.getMapX() != changedMapSquare.getMapX() || currentMapSquare.getMapY() != changedMapSquare.getMapY()) { - return false; - } - - mapSquare = changedMapSquare; - return true; - } - - /** - * Returns the associated map view. - * @return the associated map view - */ - @NotNull - public MapView<G, A, R> getMapView() { - return mapView; - } - - /** - * Returns the selected map square. - * @return the selected map square if any - */ - @Nullable - public MapSquare<G, A, R> getMapSquare() { - return mapSquare; - } - - /** - * Returns the selected game object. - * @return the selected game object if any - */ - @Nullable - public GameObject<G, A, R> getGameObject() { - return gameObject; - } - - /** - * Sets the selected game object. - * @param gameObject the selected game object, or <code>null</code> to - * deselect it - * @param index the selected index - * @return whether the selected game object was changed - */ - public boolean setGameObject(@Nullable final G gameObject, final int index) { - if (this.gameObject == gameObject) { - this.index = index; - return false; - } - - this.gameObject = gameObject; - this.index = index; - fireSelectionChangedEvent(mapSquare, gameObject, index); - return true; - } - - /** - * Returns the selected index. - * @return the selected index - */ - public int getIndex() { - return index; - } - - public boolean setSelectedGameObject(@Nullable final G gameObject) { - if (gameObject == null) { - return setGameObject(null, 0); - } - - final MapSquare<G, A, R> gameObjectMapSquare = gameObject.getTopContainer().getMapSquare(); - if (gameObjectMapSquare == null) { - log.warn("setSelectedGameObject: gameObject " + gameObject + " is not part of a map"); - return false; - } - if (mapView.getMapControl().getMapModel() != gameObjectMapSquare.getMapModel()) { - return false; - } - - final MapSquare<G, A, R> effectiveMapSquare; - if (gameObject == this.gameObject) { - effectiveMapSquare = mapSquare; - } else if (gameObject.isInContainer() && this.gameObject != null && this.gameObject.getHead().getTopContainer() == gameObject.getTopContainer()) { - effectiveMapSquare = mapSquare; - } else { - effectiveMapSquare = gameObjectMapSquare; - } - return setMapSquare(effectiveMapSquare, gameObject, 0); - } - - /** - * Adds a map square selection listener. - * @param mapSquareSelectionListener the listener to add - */ - public void addMapSquareSelectionListener(@NotNull final MapSquareSelectionListener<G, A, R> mapSquareSelectionListener) { - listenerList.add(mapSquareSelectionListener); - } - - /** - * Removes a map square selection listener. - * @param mapSquareSelectionListener the listener to remove - */ - public void removeMapSquareSelectionListener(@NotNull final MapSquareSelectionListener<G, A, R> mapSquareSelectionListener) { - listenerList.remove(mapSquareSelectionListener); - } - - /** - * Notifies all listeners that the current selection has changed. - * @param mapSquare the new selected map square - * @param gameObject the new selected game object - * @param index the new selected index - */ - private void fireSelectionChangedEvent(@Nullable final MapSquare<G, A, R> mapSquare, @Nullable final G gameObject, final int index) { - for (final MapSquareSelectionListener<G, A, R> mapSquareSelectionListener : listenerList.getListeners()) { - mapSquareSelectionListener.selectionChanged(mapSquare, gameObject, index); - } - } - -} // class MapSquareSelection Deleted: trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/MapSquareSelectionCache.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/MapSquareSelectionCache.java 2011-10-29 20:24:50 UTC (rev 9072) +++ trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/MapSquareSelectionCache.java 2011-10-30 17:28:23 UTC (rev 9073) @@ -1,121 +0,0 @@ -/* - * 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.gui.panel.selectedsquare; - -import java.util.IdentityHashMap; -import java.util.Map; -import net.sf.gridarta.gui.map.mapview.MapView; -import net.sf.gridarta.gui.map.mapview.MapViewManager; -import net.sf.gridarta.gui.map.mapview.MapViewManagerListener; -import net.sf.gridarta.model.archetype.Archetype; -import net.sf.gridarta.model.gameobject.GameObject; -import net.sf.gridarta.model.maparchobject.MapArchObject; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * The class <code>MapSquareSelectionCache</code> manages a cache that contains - * one {@link MapSquareSelection} instance for each {@link MapView} instance. - * @author unknown - * @author Andreas Kirschbaum - */ -public class MapSquareSelectionCache<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> { - - /** - * The cache to map {@link MapView} instances to {@link MapSquareSelection} - * instances. - */ - @NotNull - private final Map<MapView<G, A, R>, MapSquareSelection<G, A, R>> cache = new IdentityHashMap<MapView<G, A, R>, MapSquareSelection<G, A, R>>(); - - /** - * The map control listener used to remove closed maps from {@link #cache}. - */ - private final MapViewManagerListener<G, A, R> mapViewManagerListener = new MapViewManagerListener<G, A, R>() { - - /** {@inheritDoc} */ - @Override - public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) { - // ignore - } - - /** {@inheritDoc} */ - @Override - public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) { - // ignore - } - - /** {@inheritDoc} */ - @Override - public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) { - cache.remove(mapView); - } - - }; - - /** - * Creates a new instance. - * @param mapViewManager the map view manager - */ - public MapSquareSelectionCache(@NotNull final MapViewManager<G, A, R> mapViewManager) { - mapViewManager.addMapViewManagerListener(mapViewManagerListener); - } - - /** - * Return the {@link MapSquareSelection} instance associated to a {@link - * net.sf.gridarta.model.mapcontrol.MapControl} instance. If no instance - * exists, a new one is created. - ... [truncated message content] |
From: <aki...@us...> - 2011-10-30 17:31:48
|
Revision: 9074 http://gridarta.svn.sourceforge.net/gridarta/?rev=9074&view=rev Author: akirschbaum Date: 2011-10-30 17:31:42 +0000 (Sun, 30 Oct 2011) Log Message: ----------- Retain the selection when deactivating the map cursor. Modified Paths: -------------- trunk/atrinik/ChangeLog trunk/crossfire/ChangeLog trunk/daimonin/ChangeLog trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java Modified: trunk/atrinik/ChangeLog =================================================================== --- trunk/atrinik/ChangeLog 2011-10-30 17:28:23 UTC (rev 9073) +++ trunk/atrinik/ChangeLog 2011-10-30 17:31:42 UTC (rev 9074) @@ -1,3 +1,7 @@ +2011-10-30 Andreas Kirschbaum + + * Retain the selection when deactivating the map cursor. + 2011-10-18 Andreas Kirschbaum * Fix Next Exit not finding all exits. Modified: trunk/crossfire/ChangeLog =================================================================== --- trunk/crossfire/ChangeLog 2011-10-30 17:28:23 UTC (rev 9073) +++ trunk/crossfire/ChangeLog 2011-10-30 17:31:42 UTC (rev 9074) @@ -1,3 +1,7 @@ +2011-10-30 Andreas Kirschbaum + + * Retain the selection when deactivating the map cursor. + 2011-10-18 Andreas Kirschbaum * Fix Next Exit not finding all exits. Modified: trunk/daimonin/ChangeLog =================================================================== --- trunk/daimonin/ChangeLog 2011-10-30 17:28:23 UTC (rev 9073) +++ trunk/daimonin/ChangeLog 2011-10-30 17:31:42 UTC (rev 9074) @@ -1,3 +1,7 @@ +2011-10-30 Andreas Kirschbaum + + * Retain the selection when deactivating the map cursor. + 2011-10-18 Andreas Kirschbaum * Fix Next Exit not finding all exits. Modified: trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java 2011-10-30 17:28:23 UTC (rev 9073) +++ trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java 2011-10-30 17:31:42 UTC (rev 9074) @@ -330,7 +330,7 @@ } /** - * Cursor gets deactivated. All selections get lost. + * Cursor gets deactivated. */ public final void deactivate() { final boolean hasChanged = onMap; @@ -340,7 +340,6 @@ onMap = false; dragging = false; mapGrid.unSetCursor(pos); - mapGrid.unSelect(); mapSquare = null; gameObject = null; } finally { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2011-10-30 17:47:38
|
Revision: 9075 http://gridarta.svn.sourceforge.net/gridarta/?rev=9075&view=rev Author: akirschbaum Date: 2011-10-30 17:47:32 +0000 (Sun, 30 Oct 2011) Log Message: ----------- Move SelectedSquareView.selectArch() to MapCursor.selectAbove()/selectBelow(). Modified Paths: -------------- trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareView.java Modified: trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java 2011-10-30 17:31:42 UTC (rev 9074) +++ trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java 2011-10-30 17:47:32 UTC (rev 9075) @@ -530,4 +530,46 @@ fireGameObjectChangedEvent(); } + /** + * Moves the selected {@link GameObject}. Does nothing if no game object is + * selected. + * @param performAction whether the action should be performed + * @return whether the action was or can be performed + */ + public boolean selectAbove(final boolean performAction) { + if (mapSquare == null || gameObject == null) { + return false; + } + + final G newGameObject = mapSquare.getPrev(gameObject); + if (newGameObject == null) { + return false; + } + + gameObject = newGameObject; + fireGameObjectChangedEvent(); + return true; + } + + /** + * Moves the selected {@link GameObject}. Does nothing if no game object is + * selected. + * @param performAction whether the action should be performed + * @return whether the action was or can be performed + */ + public boolean selectBelow(final boolean performAction) { + if (mapSquare == null || gameObject == null) { + return false; + } + + final G newGameObject = mapSquare.getNext(gameObject); + if (newGameObject == null) { + return false; + } + + gameObject = newGameObject; + fireGameObjectChangedEvent(); + return true; + } + } // class MapCursor Modified: trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java 2011-10-30 17:31:42 UTC (rev 9074) +++ trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java 2011-10-30 17:47:32 UTC (rev 9075) @@ -642,15 +642,7 @@ */ private boolean doSelectArchAbove(final boolean performAction) { final MapCursor<G, A, R> mapCursor = getActiveMapCursor(); - if (mapCursor == null) { - return false; - } - - if (performAction) { - selectedSquareView.selectArch(true); - } - - return true; + return mapCursor != null && mapCursor.selectAbove(performAction); } /** @@ -660,15 +652,7 @@ */ private boolean doSelectArchBelow(final boolean performAction) { final MapCursor<G, A, R> mapCursor = getActiveMapCursor(); - if (mapCursor == null) { - return false; - } - - if (performAction) { - selectedSquareView.selectArch(false); - } - - return true; + return mapCursor != null && mapCursor.selectBelow(performAction); } /** Modified: trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareView.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareView.java 2011-10-30 17:31:42 UTC (rev 9074) +++ trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareView.java 2011-10-30 17:47:32 UTC (rev 9075) @@ -677,10 +677,6 @@ } } - public void selectArch(final boolean above) { - setSelectedIndex(list.getSelectedIndex() + (above ? 1 : -1)); - } - /** * Determines if "select" was selected. * @param e the mouse event to check for "select" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2011-10-30 18:14:17
|
Revision: 9076 http://gridarta.svn.sourceforge.net/gridarta/?rev=9076&view=rev Author: akirschbaum Date: 2011-10-30 18:14:11 +0000 (Sun, 30 Oct 2011) Log Message: ----------- Revert r9074. Revision Links: -------------- http://gridarta.svn.sourceforge.net/gridarta/?rev=9074&view=rev Modified Paths: -------------- trunk/atrinik/ChangeLog trunk/crossfire/ChangeLog trunk/daimonin/ChangeLog trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java Modified: trunk/atrinik/ChangeLog =================================================================== --- trunk/atrinik/ChangeLog 2011-10-30 17:47:32 UTC (rev 9075) +++ trunk/atrinik/ChangeLog 2011-10-30 18:14:11 UTC (rev 9076) @@ -1,7 +1,3 @@ -2011-10-30 Andreas Kirschbaum - - * Retain the selection when deactivating the map cursor. - 2011-10-18 Andreas Kirschbaum * Fix Next Exit not finding all exits. Modified: trunk/crossfire/ChangeLog =================================================================== --- trunk/crossfire/ChangeLog 2011-10-30 17:47:32 UTC (rev 9075) +++ trunk/crossfire/ChangeLog 2011-10-30 18:14:11 UTC (rev 9076) @@ -1,7 +1,3 @@ -2011-10-30 Andreas Kirschbaum - - * Retain the selection when deactivating the map cursor. - 2011-10-18 Andreas Kirschbaum * Fix Next Exit not finding all exits. Modified: trunk/daimonin/ChangeLog =================================================================== --- trunk/daimonin/ChangeLog 2011-10-30 17:47:32 UTC (rev 9075) +++ trunk/daimonin/ChangeLog 2011-10-30 18:14:11 UTC (rev 9076) @@ -1,7 +1,3 @@ -2011-10-30 Andreas Kirschbaum - - * Retain the selection when deactivating the map cursor. - 2011-10-18 Andreas Kirschbaum * Fix Next Exit not finding all exits. Modified: trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java 2011-10-30 17:47:32 UTC (rev 9075) +++ trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java 2011-10-30 18:14:11 UTC (rev 9076) @@ -330,7 +330,7 @@ } /** - * Cursor gets deactivated. + * Cursor gets deactivated. All selections get lost. */ public final void deactivate() { final boolean hasChanged = onMap; @@ -340,6 +340,7 @@ onMap = false; dragging = false; mapGrid.unSetCursor(pos); + mapGrid.unSelect(); mapSquare = null; gameObject = null; } finally { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2011-10-30 19:20:14
|
Revision: 9077 http://gridarta.svn.sourceforge.net/gridarta/?rev=9077&view=rev Author: akirschbaum Date: 2011-10-30 19:20:07 +0000 (Sun, 30 Oct 2011) Log Message: ----------- Simplify ErrorListView. Modified Paths: -------------- trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java trunk/src/app/net/sf/gridarta/gui/panel/gameobjectattributes/ErrorListView.java trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java Modified: trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java 2011-10-30 18:14:11 UTC (rev 9076) +++ trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java 2011-10-30 19:20:07 UTC (rev 9077) @@ -236,6 +236,7 @@ } else { pos.setLocation(p); selectLastGameObject(); + mapGrid.setCursor(pos); onMap = true; fireMapCursorChangedModeEvent(); hasChanged = true; @@ -492,6 +493,26 @@ } /** + * Sets the selected {@link MapSquare}. If the map square does not belong to + * the map this cursor is attached to, the cursor is deactivated. + * @param mapSquare the selected map square or <code>null</code> to + * deactivate the cursor + */ + public void setMapSquare(@Nullable final MapSquare<G, A, R> mapSquare) { + if (mapSquare == null || mapSquare.getMapModel() != mapModel) { + if (onMap) { + deactivate(); + } + return; + } + + if (this.mapSquare != mapSquare) { + this.mapSquare = mapSquare; + fireGameObjectChangedEvent(); + } + } + + /** * Start a new transaction. Transactions may be nested. Transactions serve * the purpose of firing events to the views when more changes are known to * come before the view is really required to update. Each invocation of Modified: trunk/src/app/net/sf/gridarta/gui/panel/gameobjectattributes/ErrorListView.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/panel/gameobjectattributes/ErrorListView.java 2011-10-30 18:14:11 UTC (rev 9076) +++ trunk/src/app/net/sf/gridarta/gui/panel/gameobjectattributes/ErrorListView.java 2011-10-30 19:20:07 UTC (rev 9077) @@ -20,7 +20,6 @@ package net.sf.gridarta.gui.panel.gameobjectattributes; import java.awt.BorderLayout; -import java.awt.Point; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.io.File; @@ -38,15 +37,11 @@ import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import net.sf.gridarta.gui.map.mapview.MapView; -import net.sf.gridarta.gui.map.mapview.MapViewsManager; -import net.sf.gridarta.gui.panel.selectedsquare.SelectedSquareView; +import net.sf.gridarta.gui.map.mapview.MapViewManager; +import net.sf.gridarta.gui.map.mapview.MapViewManagerListener; 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.mapcontrol.MapControl; -import net.sf.gridarta.model.mapmanager.MapManager; -import net.sf.gridarta.model.mapmanager.MapManagerListener; import net.sf.gridarta.model.mapmodel.MapModel; import net.sf.gridarta.model.mapmodel.MapModelListener; import net.sf.gridarta.model.mapmodel.MapSquare; @@ -100,18 +95,6 @@ private Vector<ValidationError<G, A, R>> errors = null; /** - * The selected square view to update. - */ - @NotNull - private final SelectedSquareView<G, A, R> selectedSquareView; - - /** - * The {@link MapViewsManager}. - */ - @NotNull - private final MapViewsManager<G, A, R> mapViewsManager; - - /** * The {@link MapView} for displaying map errors. Set to <code>null</code> * if no map is active. */ @@ -135,84 +118,73 @@ }; /** - * The {@link MapManagerListener} for tracking the current map. + * The {@link MapModelListener} which is attached to {@link + * #currentMapModel}. */ - @NotNull - private final MapManagerListener<G, A, R> mapManagerListener = new MapManagerListener<G, A, R>() { + private final MapModelListener<G, A, R> mapModelListener = new MapModelListener<G, A, R>() { /** {@inheritDoc} */ @Override - public void currentMapChanged(@Nullable final MapControl<G, A, R> mapControl) { - if (currentMapModel != null) { - currentMapModel.removeMapModelListener(mapModelListener); - } - currentMapModel = mapControl == null ? null : mapControl.getMapModel(); - if (currentMapModel != null) { - currentMapModel.addMapModelListener(mapModelListener); - } - - setErrors(mapControl); - } - - /** {@inheritDoc} */ - @Override - public void mapCreated(@NotNull final MapControl<G, A, R> mapControl, final boolean interactive) { + public void mapSizeChanged(@NotNull final Size2D newSize) { // ignore } /** {@inheritDoc} */ @Override - public void mapClosing(@NotNull final MapControl<G, A, R> mapControl) { + public void mapSquaresChanged(@NotNull final Set<MapSquare<G, A, R>> mapSquares) { // ignore } /** {@inheritDoc} */ @Override - public void mapClosed(@NotNull final MapControl<G, A, R> mapControl) { + public void mapObjectsChanged(@NotNull final Set<G> gameObjects, @NotNull final Set<G> transientGameObjects) { // ignore } - }; - - /** - * The {@link MapModelListener} which is attached to {@link - * #currentMapModel}. - */ - private final MapModelListener<G, A, R> mapModelListener = new MapModelListener<G, A, R>() { - /** {@inheritDoc} */ @Override - public void mapSizeChanged(@NotNull final Size2D newSize) { - // ignore + public void errorsChanged(@NotNull final ErrorCollector<G, A, R> errors) { + updateErrors(errors); } /** {@inheritDoc} */ @Override - public void mapSquaresChanged(@NotNull final Set<MapSquare<G, A, R>> mapSquares) { + public void mapFileChanged(@Nullable final File oldMapFile) { // ignore } /** {@inheritDoc} */ @Override - public void mapObjectsChanged(@NotNull final Set<G> gameObjects, @NotNull final Set<G> transientGameObjects) { + public void modifiedChanged() { // ignore } - /** {@inheritDoc} */ + }; + + @NotNull + private final MapViewManagerListener<G, A, R> mapViewManagerListener = new MapViewManagerListener<G, A, R>() { + @Override - public void errorsChanged(@NotNull final ErrorCollector<G, A, R> errors) { - updateErrors(errors); + public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) { + if (currentMapModel != null) { + currentMapModel.removeMapModelListener(mapModelListener); + } + currentMapModel = mapView == null ? null : mapView.getMapControl().getMapModel(); + if (currentMapModel != null) { + currentMapModel.addMapModelListener(mapModelListener); + } + + ErrorListView.this.mapView = mapView; + updateErrors(); } - /** {@inheritDoc} */ @Override - public void mapFileChanged(@Nullable final File oldMapFile) { + public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) { // ignore } - /** {@inheritDoc} */ @Override - public void modifiedChanged() { + public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) { // ignore } @@ -220,14 +192,10 @@ /** * Create a ConnectionPanel. - * @param selectedSquareView the selected square view to update - * @param mapViewsManager the map views manager - * @param mapManager the map manager to use + * @param mapViewManager the map view manager to track */ - public ErrorListView(@NotNull final SelectedSquareView<G, A, R> selectedSquareView, @NotNull final MapViewsManager<G, A, R> mapViewsManager, @NotNull final MapManager<G, A, R> mapManager) { + public ErrorListView(@NotNull final MapViewManager<G, A, R> mapViewManager) { setLayout(new BorderLayout()); - this.selectedSquareView = selectedSquareView; - this.mapViewsManager = mapViewsManager; final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(errorList), new JScrollPane(errorMsg)); splitPane.setOneTouchExpandable(true); add(splitPane, BorderLayout.CENTER); @@ -244,13 +212,10 @@ highlightEntries(errorList.getSelectedIndex()); } }); - final MapControl<G, A, R> mapControl = mapManager.getCurrentMap(); - currentMapModel = mapControl == null ? null : mapControl.getMapModel(); - if (currentMapModel != null) { - currentMapModel.addMapModelListener(mapModelListener); - } - mapManager.addMapManagerListener(mapManagerListener); - setErrors(mapControl); + mapViewManager.addMapViewManagerListener(mapViewManagerListener); + mapView = mapViewManager.getActiveMapView(); + mapViewManagerListener.activeMapViewChanged(mapView); + updateErrors(); } /** @@ -270,41 +235,6 @@ } /** - * Set the error for a map. - * @param mapView the map view or <code>null</code> - * @param errors the errors - */ - public void setErrors(@NotNull final MapView<G, A, R> mapView, @NotNull final ErrorCollector<G, A, R> errors) { - this.mapView = mapView; - updateErrors(errors); - } - - /** - * Clears the displayed errors. - */ - public void unsetErrors() { - mapView = null; - errors = null; - errorList.setModel(new DefaultListModel()); - fireErrorsUpdated(false); - } - - /** - * Updates the errors for the current map. - * @param errors the errors - */ - public void updateErrors(@NotNull final ErrorCollector<G, A, R> errors) { - final List<ValidationError<G, A, R>> errorVector = new ArrayList<ValidationError<G, A, R>>(); - for (final ValidationError<G, A, R> validationError : errors.getErrors()) { - errorVector.add(validationError); - } - this.errors = new Vector<ValidationError<G, A, R>>(errorVector); - errorList.setListData(this.errors); - - fireErrorsUpdated(hasWarnings()); - } - - /** * Returns whether any warnings are shown. * @return whether any warnings are shown */ @@ -333,35 +263,24 @@ } errorMsg.setText(error.getMessage()); - final Iterator<G> gameObjectIterator = error.getGameObjects().iterator(); - if (gameObjectIterator.hasNext()) { - final G gameObject = gameObjectIterator.next(); - final BaseObject<G, A, R, ?> topContainer = gameObject.getTopContainer(); - setMapCursorLocation(topContainer.getMapLocation()); - selectedSquareView.setSelectedGameObject(gameObject); - } else { - final Iterator<MapSquare<G, A, R>> mapSquareIterator = error.getMapSquares().iterator(); - if (mapSquareIterator.hasNext()) { - final MapSquare<G, A, R> mapSquare = mapSquareIterator.next(); - setMapCursorLocation(mapSquare == null ? null : mapSquare.getMapLocation()); + final MapView<G, A, R> tmpMapView = mapView; + if (tmpMapView != null) { + final Iterator<G> gameObjectIterator = error.getGameObjects().iterator(); + if (gameObjectIterator.hasNext()) { + final G gameObject = gameObjectIterator.next(); + tmpMapView.getMapCursor().setGameObject(gameObject); + } else { + final Iterator<MapSquare<G, A, R>> mapSquareIterator = error.getMapSquares().iterator(); + if (mapSquareIterator.hasNext()) { + final MapSquare<G, A, R> mapSquare = mapSquareIterator.next(); + tmpMapView.getMapCursor().setMapSquare(mapSquare); + } } } errorMsg.setCaretPosition(0); } /** - * Updates the {@link #mapView}'s location. Does nothing if no map cursor - * is active. - * @param point the location to set - */ - private void setMapCursorLocation(@Nullable final Point point) { - final MapView<G, A, R> tmp = mapView; - if (tmp != null) { - tmp.setCursorLocation(point); - } - } - - /** * Notifies all listeners that the warnings may have changed. * @param hasWarnings whether any warnings are shown */ @@ -373,19 +292,32 @@ /** * Updates the displayed errors. - * @param mapControl the map control of which the errors have changed */ - private void setErrors(@Nullable final MapControl<G, A, R> mapControl) { - if (mapControl != null) { - final MapView<G, A, R> mapView = mapViewsManager.getMapViewFrame(mapControl); - if (mapView != null) { - final ErrorCollector<G, A, R> errorCollector = mapControl.getMapModel().getErrors(); - setErrors(mapView, errorCollector); - return; - } + private void updateErrors() { + if (mapView != null) { + updateErrors(mapView.getMapControl().getMapModel().getErrors()); + return; } - unsetErrors(); + errors = null; + errorList.setModel(new DefaultListModel()); + fireErrorsUpdated(false); } + /** + * Updates the errors for the current map. + * @param errors the errors + */ + public void updateErrors(@NotNull final ErrorCollector<G, A, R> errors) { + assert mapView != null; + final List<ValidationError<G, A, R>> errorVector = new ArrayList<ValidationError<G, A, R>>(); + for (final ValidationError<G, A, R> validationError : errors.getErrors()) { + errorVector.add(validationError); + } + this.errors = new Vector<ValidationError<G, A, R>>(errorVector); + errorList.setListData(this.errors); + + fireErrorsUpdated(hasWarnings()); + } + } // class ErrorPanel Modified: trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java 2011-10-30 18:14:11 UTC (rev 9076) +++ trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java 2011-10-30 19:20:07 UTC (rev 9077) @@ -581,7 +581,7 @@ } else { pluginControl.getView().setMenu(pluginsMenu); } - final ErrorListView<G, A, R> errorListView = new ErrorListView<G, A, R>(selectedSquareView, mapViewsManager, mapManager); + final ErrorListView<G, A, R> errorListView = new ErrorListView<G, A, R>(mapViewManager); gameObjectAttributesControl.addTab(new ArchTab<G, A, R>(archetypeTypeSet, gameObjectAttributesModel)); gameObjectAttributesControl.addTab(new MsgTextTab<G, A, R>(gameObjectAttributesModel)); gameObjectAttributesControl.addTab(new EventsTab<G, A, R>(mainViewFrame, mapManager, gameObjectAttributesModel, scriptArchEditor, scriptArchData, scriptArchDataUtils, scriptArchUtils)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2011-10-30 20:19:36
|
Revision: 9078 http://gridarta.svn.sourceforge.net/gridarta/?rev=9078&view=rev Author: akirschbaum Date: 2011-10-30 20:19:28 +0000 (Sun, 30 Oct 2011) Log Message: ----------- Set the map cursor and select the affected game object for selected entries in the Warnings tab; By default select the top-most game object in the selected square view. Modified Paths: -------------- trunk/atrinik/ChangeLog trunk/crossfire/ChangeLog trunk/daimonin/ChangeLog trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java trunk/model/src/test/net/sf/gridarta/model/mapcursor/MapCursorTest.java Modified: trunk/atrinik/ChangeLog =================================================================== --- trunk/atrinik/ChangeLog 2011-10-30 19:20:07 UTC (rev 9077) +++ trunk/atrinik/ChangeLog 2011-10-30 20:19:28 UTC (rev 9078) @@ -1,3 +1,11 @@ +2011-10-30 Andreas Kirschbaum + + * Set the map cursor and select the affected game object for + selected entries in the Warnings tab. + + * By default select the top-most game object in the selected + square view. + 2011-10-18 Andreas Kirschbaum * Fix Next Exit not finding all exits. Modified: trunk/crossfire/ChangeLog =================================================================== --- trunk/crossfire/ChangeLog 2011-10-30 19:20:07 UTC (rev 9077) +++ trunk/crossfire/ChangeLog 2011-10-30 20:19:28 UTC (rev 9078) @@ -1,3 +1,11 @@ +2011-10-30 Andreas Kirschbaum + + * Set the map cursor and select the affected game object for + selected entries in the Warnings tab. + + * By default select the top-most game object in the selected + square view. + 2011-10-18 Andreas Kirschbaum * Fix Next Exit not finding all exits. Modified: trunk/daimonin/ChangeLog =================================================================== --- trunk/daimonin/ChangeLog 2011-10-30 19:20:07 UTC (rev 9077) +++ trunk/daimonin/ChangeLog 2011-10-30 20:19:28 UTC (rev 9078) @@ -1,3 +1,11 @@ +2011-10-30 Andreas Kirschbaum + + * Set the map cursor and select the affected game object for + selected entries in the Warnings tab. + + * By default select the top-most game object in the selected + square view. + 2011-10-18 Andreas Kirschbaum * Fix Next Exit not finding all exits. Modified: trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java 2011-10-30 19:20:07 UTC (rev 9077) +++ trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java 2011-10-30 20:19:28 UTC (rev 9078) @@ -114,6 +114,45 @@ private G gameObject; /** + * The nesting level of map cursor transactions. Change events are delivered + * when all nested transactions are finished. + */ + private int transactionDepth; + + /** + * The value of {@link #pos} at the start of the outermost map cursor + * transaction. + */ + @NotNull + private final Point transactionPos = new Point(); + + /** + * The value of {@link #onMap} at the start of the outermost map cursor + * transaction. + */ + private boolean transactionOnMap; + + /** + * The value of {@link #dragging} at the start of the outermost map cursor + * transaction. + */ + private boolean transactionDragging; + + /** + * The value of {@link #mapSquare} at the start of the outermost map cursor + * transaction. + */ + @Nullable + private MapSquare<G, A, R> transactionMapSquare; + + /** + * The value of {@link #gameObject} at the start of the outermost map cursor + * transaction. + */ + @Nullable + private G transactionGameObject; + + /** * The MapCursorListeners to inform of changes. */ @NotNull @@ -145,17 +184,19 @@ } // Test if cursor position is outside map -> move inside if (onMap && !mapRec.contains(pos)) { - pos.x = Math.min(pos.x, mapRec.width - 1); - pos.y = Math.min(pos.y, mapRec.height - 1); - selectLastGameObject(); - mapGrid.setCursor(pos); - fireMapCursorChangedPosEvent(); + beginTransaction(); + try { + pos.x = Math.min(pos.x, mapRec.width - 1); + pos.y = Math.min(pos.y, mapRec.height - 1); + selectMapSquare(); + } finally { + endTransaction(); + } } } }; mapGrid.addMapGridListener(mapGridListener); - deactivate(); } /** @@ -172,43 +213,26 @@ * Move cursor to a new location. If new location is not on map, cursor gets * disabled. * @param p New location. If <code>p == null</code> cursor gets disabled - * @return <code>true</code> if cursor position changed or if it gets - * disabled */ - public boolean setLocation(@Nullable final Point p) { - mapGrid.beginTransaction(); + public void setLocation(@Nullable final Point p) { + beginTransaction(); try { - final boolean hasChanged; if (p != null && mapRec.contains(p)) { if (onMap) { - if (pos.equals(p)) { - hasChanged = false; - } else { - mapGrid.unSetCursor(pos); + if (!pos.equals(p)) { pos.setLocation(p); - selectLastGameObject(); - mapGrid.setCursor(pos); - fireMapCursorChangedPosEvent(); - hasChanged = true; + selectMapSquare(); } } else { pos.setLocation(p); - selectLastGameObject(); - mapGrid.setCursor(pos); + selectMapSquare(); onMap = true; - fireMapCursorChangedModeEvent(); - fireMapCursorChangedPosEvent(); - hasChanged = true; } - } else if (onMap) { - deactivate(); - hasChanged = true; } else { - hasChanged = false; + onMap = false; } - return hasChanged; } finally { - mapGrid.endTransaction(); + endTransaction(); } } @@ -219,7 +243,7 @@ * @return <code>true</code> if cursor position changed */ public boolean setLocationSafe(@Nullable final Point p) { - mapGrid.beginTransaction(); + beginTransaction(); final boolean hasChanged; try { if (p != null && mapRec.contains(p)) { @@ -227,29 +251,22 @@ if (pos.equals(p)) { hasChanged = false; } else { - mapGrid.unSetCursor(pos); pos.setLocation(p); - selectLastGameObject(); - mapGrid.setCursor(pos); + selectMapSquare(); hasChanged = true; } } else { pos.setLocation(p); - selectLastGameObject(); - mapGrid.setCursor(pos); + selectMapSquare(); onMap = true; - fireMapCursorChangedModeEvent(); hasChanged = true; } } else { hasChanged = false; } } finally { - mapGrid.endTransaction(); + endTransaction(); } - if (hasChanged) { - fireMapCursorChangedPosEvent(); - } return hasChanged; } @@ -258,16 +275,15 @@ */ public void dragStart() { if (onMap && !dragging) { - mapGrid.beginTransaction(); + beginTransaction(); try { dragStart.setLocation(pos); mapGrid.preSelect(dragStart, pos); dragging = true; dragOffset.setSize(0, 0); } finally { - mapGrid.endTransaction(); + endTransaction(); } - fireMapCursorChangedModeEvent(); } } @@ -279,19 +295,16 @@ */ public boolean dragTo(@Nullable final Point p) { if (p != null && mapRec.contains(p) && dragging && !pos.equals(p)) { - mapGrid.beginTransaction(); + beginTransaction(); try { final Point oldPos = new Point(pos); - mapGrid.unSetCursor(pos); pos.setLocation(p); - selectLastGameObject(); + selectMapSquare(); mapGrid.updatePreSelect(dragStart, oldPos, pos); - mapGrid.setCursor(pos); dragOffset.setSize(pos.x - dragStart.x, pos.y - dragStart.y); } finally { - mapGrid.endTransaction(); + endTransaction(); } - fireMapCursorChangedPosEvent(); return true; } return false; @@ -302,14 +315,13 @@ */ public void dragRelease() { if (dragging) { - mapGrid.beginTransaction(); + beginTransaction(); try { mapGrid.unPreSelect(dragStart, pos); dragging = false; } finally { - mapGrid.endTransaction(); + endTransaction(); } - fireMapCursorChangedModeEvent(); } } @@ -320,12 +332,12 @@ */ public void dragSelect(@NotNull final SelectionMode selectionMode) { if (dragging) { - mapGrid.beginTransaction(); + beginTransaction(); try { dragRelease(); mapGrid.selectArea(dragStart, pos, selectionMode); } finally { - mapGrid.endTransaction(); + endTransaction(); } } } @@ -334,25 +346,13 @@ * Cursor gets deactivated. All selections get lost. */ public final void deactivate() { - final boolean hasChanged = onMap; - final boolean hasChangedGameObject = mapSquare != null || gameObject != null; - mapGrid.beginTransaction(); + beginTransaction(); try { onMap = false; - dragging = false; - mapGrid.unSetCursor(pos); mapGrid.unSelect(); - mapSquare = null; - gameObject = null; } finally { - mapGrid.endTransaction(); + endTransaction(); } - if (hasChanged) { - fireMapCursorChangedModeEvent(); - fireMapCursorChangedPosEvent(); - } else if (hasChangedGameObject) { - fireGameObjectChangedEvent(); - } } /** @@ -425,34 +425,6 @@ } /** - * Inform all registered listeners that the MapCursor's mode has changed. - */ - private void fireMapCursorChangedModeEvent() { - for (final MapCursorListener<G, A, R> listener : listenerList.getListeners()) { - listener.mapCursorChangedMode(); - } - } - - /** - * Inform all registered listeners that the MapCursor's position has - * changed. - */ - private void fireMapCursorChangedPosEvent() { - for (final MapCursorListener<G, A, R> listener : listenerList.getListeners()) { - listener.mapCursorChangedPos(getLocation()); - } - } - - /** - * Notifies all listeners that the selected game object has changed. - */ - private void fireGameObjectChangedEvent() { - for (final MapCursorListener<G, A, R> listener : listenerList.getListeners()) { - listener.mapCursorChangedGameObject(mapSquare, gameObject); - } - } - - /** * Returns the selected {@link GameObject}. * @return the selected game object or <code>null</code> if the map cursor * is not active or if the selected map square is empty @@ -469,27 +441,24 @@ * deactivate the cursor */ public void setGameObject(@Nullable final G gameObject) { - if (gameObject == null) { - if (this.gameObject != null) { + beginTransaction(); + try { + if (gameObject == null) { this.gameObject = null; - fireGameObjectChangedEvent(); + } else { + final MapSquare<G, A, R> mapSquare = gameObject.getMapSquare(); + if (mapSquare == null || mapSquare.getMapModel() != mapModel) { + onMap = false; + } else { + onMap = true; + pos.setLocation(mapSquare.getMapX(), mapSquare.getMapY()); + this.mapSquare = mapSquare; + this.gameObject = gameObject; + } } - return; + } finally { + endTransaction(); } - - final MapSquare<G, A, R> mapSquare = gameObject.getMapSquare(); - if (mapSquare == null || mapSquare.getMapModel() != mapModel) { - if (onMap) { - deactivate(); - } - return; - } - - if (this.mapSquare != mapSquare || this.gameObject != gameObject) { - this.mapSquare = mapSquare; - this.gameObject = gameObject; - fireGameObjectChangedEvent(); - } } /** @@ -499,17 +468,19 @@ * deactivate the cursor */ public void setMapSquare(@Nullable final MapSquare<G, A, R> mapSquare) { - if (mapSquare == null || mapSquare.getMapModel() != mapModel) { - if (onMap) { - deactivate(); + beginTransaction(); + try { + if (mapSquare == null || mapSquare.getMapModel() != mapModel) { + onMap = false; + } else { + onMap = true; + pos.setLocation(mapSquare.getMapX(), mapSquare.getMapY()); + this.mapSquare = mapSquare; + selectTopmostGameObject(); } - return; + } finally { + endTransaction(); } - - if (this.mapSquare != mapSquare) { - this.mapSquare = mapSquare; - fireGameObjectChangedEvent(); - } } /** @@ -519,6 +490,14 @@ * this function requires its own invocation of {@link #endTransaction()}. */ public void beginTransaction() { + if (transactionDepth == 0) { + transactionPos.setLocation(pos); + transactionOnMap = onMap; + transactionDragging = dragging; + transactionMapSquare = mapSquare; + transactionGameObject = gameObject; + } + transactionDepth++; mapGrid.beginTransaction(); } @@ -527,32 +506,72 @@ * by 1. <p/> If the last transaction is ended, the changes are committed. */ public void endTransaction() { + assert transactionDepth > 0; + transactionDepth--; + + if (!onMap) { + dragging = false; + mapSquare = null; + gameObject = null; + } + + if (transactionDepth == 0) { + final boolean changedPos = !pos.equals(transactionPos) || mapSquare != transactionMapSquare; + final boolean changedMode = onMap != transactionOnMap || dragging != transactionDragging; + final boolean changedGameObject = gameObject != transactionGameObject; + if (!onMap) { + mapGrid.unSelect(); + } + if (transactionOnMap && (!onMap || !pos.equals(transactionPos))) { + mapGrid.unSetCursor(transactionPos); + } + if (onMap && (!transactionOnMap || !pos.equals(transactionPos))) { + mapGrid.setCursor(pos); + } + if (changedMode) { + for (final MapCursorListener<G, A, R> listener : listenerList.getListeners()) { + listener.mapCursorChangedMode(); + } + } + if (changedPos) { + for (final MapCursorListener<G, A, R> listener : listenerList.getListeners()) { + listener.mapCursorChangedPos(getLocation()); + } + } + if (changedGameObject) { + for (final MapCursorListener<G, A, R> listener : listenerList.getListeners()) { + listener.mapCursorChangedGameObject(mapSquare, gameObject); + } + } + } + mapGrid.endTransaction(); } /** - * Selects the last (top-most) {@link GameObject} on the current map - * location. + * Selects the map square on the current map location. Must be called from + * within a map cursor transaction. */ - private void selectLastGameObject() { - @Nullable MapSquare<G, A, R> newMapSquare; - @Nullable G newGameObject; + private void selectMapSquare() { + assert transactionDepth > 0; try { - newMapSquare = mapModel.getMapSquare(pos); - newGameObject = newMapSquare.getLast(); + mapSquare = mapModel.getMapSquare(pos); } catch (final IndexOutOfBoundsException ignored) { - newMapSquare = null; - newGameObject = null; + mapSquare = null; } - if (mapSquare == newMapSquare && gameObject == newGameObject) { - return; - } - mapSquare = newMapSquare; - gameObject = newGameObject; - fireGameObjectChangedEvent(); + selectTopmostGameObject(); } /** + * Selects the last (top-most) {@link GameObject} on the current map square. + * Must be called from within a map cursor transaction. + */ + private void selectTopmostGameObject() { + assert transactionDepth > 0; + gameObject = mapSquare == null ? null : mapSquare.getLast(); + } + + /** * Moves the selected {@link GameObject}. Does nothing if no game object is * selected. * @param performAction whether the action should be performed @@ -568,8 +587,14 @@ return false; } - gameObject = newGameObject; - fireGameObjectChangedEvent(); + if (performAction) { + beginTransaction(); + try { + gameObject = newGameObject; + } finally { + endTransaction(); + } + } return true; } @@ -589,8 +614,14 @@ return false; } - gameObject = newGameObject; - fireGameObjectChangedEvent(); + if (performAction) { + beginTransaction(); + try { + gameObject = newGameObject; + } finally { + endTransaction(); + } + } return true; } Modified: trunk/model/src/test/net/sf/gridarta/model/mapcursor/MapCursorTest.java =================================================================== --- trunk/model/src/test/net/sf/gridarta/model/mapcursor/MapCursorTest.java 2011-10-30 19:20:07 UTC (rev 9077) +++ trunk/model/src/test/net/sf/gridarta/model/mapcursor/MapCursorTest.java 2011-10-30 20:19:28 UTC (rev 9078) @@ -84,14 +84,14 @@ final Point p = new Point(); for (int i = -2; i < gridSize.getWidth() + 2; i++) { p.setLocation(i, -1); - Assert.assertFalse("setLocation(" + p + ") should return false", cursor.setLocation(p)); + cursor.setLocation(p); testEvents(0, 0); Assert.assertFalse("MapCursor should be disabled after setLocation(" + p + ")", cursor.isActive()); testEvents(0, 0); Assert.assertNull("getLocation() should return null after setLocation(" + p + ")", cursor.getLocation()); testEvents(0, 0); p.setLocation(i, gridSize.getHeight()); - Assert.assertFalse("setLocation(" + p + ") should return false", cursor.setLocation(p)); + cursor.setLocation(p); testEvents(0, 0); Assert.assertFalse("MapCursor should be disabled after setLocation(" + p + ")", cursor.isActive()); testEvents(0, 0); @@ -100,14 +100,14 @@ } for (int i = -2; i < gridSize.getHeight() + 2; i++) { p.setLocation(-1, i); - Assert.assertFalse("setLocation(" + p + ") should return false", cursor.setLocation(p)); + cursor.setLocation(p); testEvents(0, 0); Assert.assertFalse("MapCursor should be disabled after setLocation(" + p + ")", cursor.isActive()); testEvents(0, 0); Assert.assertNull("getLocation() should return null after setLocation(" + p + ")", cursor.getLocation()); testEvents(0, 0); p.setLocation(gridSize.getWidth(), i); - Assert.assertFalse("setLocation(" + p + ") should return false", cursor.setLocation(p)); + cursor.setLocation(p); testEvents(0, 0); Assert.assertFalse("MapCursor should be disabled after setLocation(" + p + ")", cursor.isActive()); testEvents(0, 0); @@ -128,7 +128,7 @@ for (int j = 0; j < gridSize.getHeight(); j++) { for (int i = 0; i < gridSize.getWidth(); i++) { p.setLocation(i, j); - Assert.assertTrue("setLocation(" + p + ") should return true", cursor.setLocation(p)); + cursor.setLocation(p); if (first) { // Only the first after activation should fire a change mode event testEvents(1, 1); @@ -154,25 +154,25 @@ final MapGrid grid = new MapGrid(gridSize); final MapCursor<TestGameObject, TestMapArchObject, TestArchetype> cursor = createCursor(grid); final Point p = new Point(-1, -1); - Assert.assertFalse("setLocation(null) should return false", cursor.setLocation(null)); + cursor.setLocation(null); testEvents(0, 0); Assert.assertFalse("MapCursor should be deactivated", cursor.isActive()); testEvents(0, 0); - Assert.assertFalse("setLocation(" + p + ") should return false", cursor.setLocation(p)); + cursor.setLocation(p); testEvents(0, 0); Assert.assertFalse("MapCursor should be deactivated", cursor.isActive()); testEvents(0, 0); p.setLocation(3, 4); - Assert.assertTrue("setLocation(" + p + ") should return true", cursor.setLocation(p)); + cursor.setLocation(p); testEvents(1, 1); Assert.assertTrue("MapCursor should be active", cursor.isActive()); testEvents(0, 0); - Assert.assertFalse("setLocation(" + p + ") should return false", cursor.setLocation(p)); + cursor.setLocation(p); testEvents(0, 0); Assert.assertTrue("MapCursor should be active", cursor.isActive()); testEvents(0, 0); p.setLocation(-1, -1); - Assert.assertTrue("setLocation(" + p + ") should return true", cursor.setLocation(p)); + cursor.setLocation(p); testEvents(1, 1); Assert.assertFalse("MapCursor should be deactivated", cursor.isActive()); testEvents(0, 0); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2011-10-30 21:39:07
|
Revision: 9079 http://gridarta.svn.sourceforge.net/gridarta/?rev=9079&view=rev Author: akirschbaum Date: 2011-10-30 21:39:01 +0000 (Sun, 30 Oct 2011) Log Message: ----------- Remove dependency MapCursorActions -> SelectedSquareView. Modified Paths: -------------- trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareView.java trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java Modified: trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java 2011-10-30 20:19:28 UTC (rev 9078) +++ trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java 2011-10-30 21:39:01 UTC (rev 9079) @@ -23,6 +23,7 @@ import java.awt.Point; import java.awt.Rectangle; 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; @@ -625,4 +626,31 @@ return true; } + /** + * Inserts a {@link GameObject} before the selected game object. Does + * nothing if no game object is selected. + * @param gameObject the game object to insert + * @param join if set, auto-joining is supported + */ + public void insertGameObject(final BaseObject<G, A, R, ?> gameObject, final boolean join) { + if (!onMap) { + return; + } + + mapModel.beginTransaction("Insert"); // TODO; I18N/L10N + try { + final G insertedGameObject = mapModel.insertArchToMap(gameObject, this.gameObject, pos, true); + if (insertedGameObject != null) { + beginTransaction(); + try { + this.gameObject = insertedGameObject; + } finally { + endTransaction(); + } + } + } finally { + mapModel.endTransaction(); + } + } + } // class MapCursor Modified: trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java 2011-10-30 20:19:28 UTC (rev 9078) +++ trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java 2011-10-30 21:39:01 UTC (rev 9079) @@ -28,9 +28,10 @@ import net.sf.gridarta.gui.map.mapview.MapView; import net.sf.gridarta.gui.map.mapview.MapViewManager; import net.sf.gridarta.gui.map.mapview.MapViewManagerListener; +import net.sf.gridarta.gui.panel.objectchooser.ObjectChooser; import net.sf.gridarta.gui.panel.selectedsquare.SelectedSquareModel; -import net.sf.gridarta.gui.panel.selectedsquare.SelectedSquareView; 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; @@ -53,6 +54,12 @@ public class MapCursorActions<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> { /** + * The object chooser. + */ + @NotNull + private final ObjectChooser<G, A, R> objectChooser; + + /** * Actions for "go". */ @NotNull @@ -132,12 +139,6 @@ private final GameObjectAttributesDialogFactory<G, A, R> gameObjectAttributesDialogFactory; /** - * The selected square view. - */ - @NotNull - private final SelectedSquareView<G, A, R> selectedSquareView; - - /** * The selected square model. */ @NotNull @@ -211,15 +212,15 @@ /** * Create a new instance. + * @param objectChooser the object chooser * @param gameObjectAttributesDialogFactory the factory for creating game * object attributes dialog instances * @param mapViewManager the map view manager - * @param selectedSquareView the selected square view * @param selectedSquareModel the selected square model */ - public MapCursorActions(@NotNull final GameObjectAttributesDialogFactory<G, A, R> gameObjectAttributesDialogFactory, @NotNull final MapViewManager<G, A, R> mapViewManager, @NotNull final SelectedSquareView<G, A, R> selectedSquareView, @NotNull final SelectedSquareModel<G, A, R> selectedSquareModel) { + public MapCursorActions(@NotNull final ObjectChooser<G, A, R> objectChooser, @NotNull final GameObjectAttributesDialogFactory<G, A, R> gameObjectAttributesDialogFactory, @NotNull final MapViewManager<G, A, R> mapViewManager, @NotNull final SelectedSquareModel<G, A, R> selectedSquareModel) { + this.objectChooser = objectChooser; this.gameObjectAttributesDialogFactory = gameObjectAttributesDialogFactory; - this.selectedSquareView = selectedSquareView; this.selectedSquareModel = selectedSquareModel; goLocationDialogManager = new GoLocationDialogManager<G, A, R>(mapViewManager); final String[] directionsGo = { "goNorth", "goEast", "goSouth", "goWest", "goNorthEast", "goSouthEast", "goSouthWest", "goNorthWest" }; @@ -585,12 +586,23 @@ return false; } - if (getActiveMapCursor(mapView) == null) { // XXX: should pass to function + final MapCursor<G, A, R> mapCursor = getActiveMapCursor(mapView); + if (mapCursor == null) { // XXX: should pass to function return false; } if (performAction) { - selectedSquareView.insertGameObjectFromObjectChooser(mapView.getMapControl().getMapModel()); + final BaseObject<G, A, R, ?> gameObject = objectChooser.getSelection(); + if (gameObject == null) { + return false; + } + + final Point location = mapCursor.getLocation(); + if (location == null) { + return false; + } + + mapCursor.insertGameObject(gameObject, true); } return true; Modified: trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareView.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareView.java 2011-10-30 20:19:28 UTC (rev 9078) +++ trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareView.java 2011-10-30 21:39:01 UTC (rev 9079) @@ -629,10 +629,6 @@ } } - public void insertGameObjectFromObjectChooser(@NotNull final MapModel<G, A, R> mapModel) { - insertGameObjectFromObjectChooser(mapModel, list.getSelectedIndex()); - } - /** * Inserts a new game object. * @param index the list index to insert at @@ -650,8 +646,8 @@ * @param index the list index to insert at */ private void insertGameObjectFromObjectChooser(@NotNull final MapModel<G, A, R> mapModel, final int index) { - final BaseObject<G, A, R, ?> baseObject = objectChooser.getSelection(); - if (baseObject == null) { + final BaseObject<G, A, R, ?> gameObject = objectChooser.getSelection(); + if (gameObject == null) { return; } @@ -660,21 +656,7 @@ return; } - final Point location = mapCursor.getLocation(); - if (location == null) { - return; - } - - final G prevGameObject = index >= model.getSize() ? null : getListGameObject(index); - mapModel.beginTransaction("Insert"); // TODO; I18N/L10N - try { - final G insertedGameObject = mapModel.insertArchToMap(baseObject, prevGameObject, location, true); - if (insertedGameObject != null) { - setSelectedGameObject(insertedGameObject); - } - } finally { - mapModel.endTransaction(); - } + mapCursor.insertGameObject(gameObject, true); } /** Modified: trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java 2011-10-30 20:19:28 UTC (rev 9078) +++ trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java 2011-10-30 21:39:01 UTC (rev 9079) @@ -528,7 +528,7 @@ ActionUtils.newActions(ACTION_BUILDER, "Map Navigation", goExitDialogManager, "goExit"); ActionUtils.newActions(ACTION_BUILDER, "Tool", this, "cleanCompletelyBlockedSquares", "collectSpells", "controlClient", "controlServer", "gc", "options", "shortcuts", "zoom"); //noinspection ResultOfObjectAllocationIgnored - new MapCursorActions<G, A, R>(gameObjectAttributesDialogFactory, mapViewManager, selectedSquareView, selectedSquareModel); + new MapCursorActions<G, A, R>(objectChooser, gameObjectAttributesDialogFactory, mapViewManager, selectedSquareModel); ActionUtils.newAction(ACTION_BUILDER, "Script", scriptEditControl, "newScript"); ActionUtils.newAction(ACTION_BUILDER, "Script", fileControl, "editScript"); ActionUtils.newActions(ACTION_BUILDER, "Map", fileControl, "openFile", "saveAllMaps"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2011-10-30 22:07:26
|
Revision: 9080 http://gridarta.svn.sourceforge.net/gridarta/?rev=9080&view=rev Author: akirschbaum Date: 2011-10-30 22:07:19 +0000 (Sun, 30 Oct 2011) Log Message: ----------- Fix selected square view to allow insertion at the bottom. Modified Paths: -------------- trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareView.java Modified: trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java 2011-10-30 21:39:01 UTC (rev 9079) +++ trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java 2011-10-30 22:07:19 UTC (rev 9080) @@ -630,16 +630,18 @@ * Inserts a {@link GameObject} before the selected game object. Does * nothing if no game object is selected. * @param gameObject the game object to insert + * @param insertAtEnd whether to ignore the selected game object and insert + * at the end * @param join if set, auto-joining is supported */ - public void insertGameObject(final BaseObject<G, A, R, ?> gameObject, final boolean join) { + public void insertGameObject(@NotNull final BaseObject<G, A, R, ?> gameObject, final boolean insertAtEnd, final boolean join) { if (!onMap) { return; } mapModel.beginTransaction("Insert"); // TODO; I18N/L10N try { - final G insertedGameObject = mapModel.insertArchToMap(gameObject, this.gameObject, pos, true); + final G insertedGameObject = mapModel.insertArchToMap(gameObject, insertAtEnd ? null : this.gameObject, pos, join); if (insertedGameObject != null) { beginTransaction(); try { Modified: trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java 2011-10-30 21:39:01 UTC (rev 9079) +++ trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java 2011-10-30 22:07:19 UTC (rev 9080) @@ -602,7 +602,7 @@ return false; } - mapCursor.insertGameObject(gameObject, true); + mapCursor.insertGameObject(gameObject, false, true); } return true; Modified: trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareView.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareView.java 2011-10-30 21:39:01 UTC (rev 9079) +++ trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareView.java 2011-10-30 22:07:19 UTC (rev 9080) @@ -355,7 +355,10 @@ } } } else if (isInsert(e)) { - insertGameObjectFromObjectChooser(getListIndex(e)); + final int index = getListIndex(e); + setSelectedIndex(index); + insertGameObjectFromObjectChooser(index >= model.getSize()); + setSelectedIndex(index); } else if (isDelete(e)) { deleteIndex(getListIndex(e)); } @@ -529,7 +532,7 @@ } //JList does not use type parameters @SuppressWarnings("unchecked") - final G gameObject = (G) list.getSelectedValue(); + final G gameObject = index >= model.getSize() ? null : (G) list.getSelectedValue(); if (mapCursor != null) { mapCursor.setGameObject(gameObject); } @@ -631,21 +634,8 @@ /** * Inserts a new game object. - * @param index the list index to insert at */ - private void insertGameObjectFromObjectChooser(final int index) { - final MapModel<G, A, R> mapModel = this.mapModel; - if (mapModel != null) { - insertGameObjectFromObjectChooser(mapModel, index); - } - } - - /** - * Inserts a new game object. - * @param mapModel the map to insert into - * @param index the list index to insert at - */ - private void insertGameObjectFromObjectChooser(@NotNull final MapModel<G, A, R> mapModel, final int index) { + private void insertGameObjectFromObjectChooser(final boolean insertAtEnd) { final BaseObject<G, A, R, ?> gameObject = objectChooser.getSelection(); if (gameObject == null) { return; @@ -656,7 +646,7 @@ return; } - mapCursor.insertGameObject(gameObject, true); + mapCursor.insertGameObject(gameObject, insertAtEnd, true); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2011-10-30 23:22:55
|
Revision: 9084 http://gridarta.svn.sourceforge.net/gridarta/?rev=9084&view=rev Author: akirschbaum Date: 2011-10-30 23:22:48 +0000 (Sun, 30 Oct 2011) Log Message: ----------- Merge duplicated code. Modified Paths: -------------- trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareView.java Modified: trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java 2011-10-30 22:46:08 UTC (rev 9083) +++ trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java 2011-10-30 23:22:48 UTC (rev 9084) @@ -655,4 +655,56 @@ } } + /** + * Deletes the selected game object. Does nothing if no game object is + * selected. + * @param performAction whether the action should be performed + * @return whether the action was or can be performed + */ + public boolean deleteSelectedGameObject(final boolean performAction) { + if (!onMap) { + return false; + } + + final G gameObject = this.gameObject; + if (gameObject == null) { + return false; + } + + final MapSquare<G, A, R> mapSquare = this.mapSquare; + if (mapSquare == null) { + return false; + } + + if (performAction) { + mapModel.beginTransaction("Delete"); // TODO; I18N/L10N + try { + G nextGameObject = mapSquare.getNext(gameObject); + mapModel.removeGameObject(gameObject, true); + if (nextGameObject == null) { + nextGameObject = mapSquare.getFirst(); + } + if (nextGameObject != null) { + while (true) { + final G invGameObject = nextGameObject.getFirst(); + if (invGameObject == null) { + break; + } + nextGameObject = invGameObject; + } + } + beginTransaction(); + try { + this.gameObject = nextGameObject; + } finally { + endTransaction(); + } + } finally { + mapModel.endTransaction(); + } + } + + return true; + } + } // class MapCursor Modified: trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java 2011-10-30 22:46:08 UTC (rev 9083) +++ trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java 2011-10-30 23:22:48 UTC (rev 9084) @@ -37,7 +37,6 @@ import net.sf.gridarta.model.mapcursor.MapCursor; import net.sf.gridarta.model.mapcursor.MapCursorListener; import net.sf.gridarta.model.mapgrid.SelectionMode; -import net.sf.gridarta.model.mapmodel.MapModel; import net.sf.gridarta.model.mapmodel.MapSquare; import net.sf.gridarta.utils.ActionUtils; import net.sf.japi.swing.action.ActionBuilder; @@ -605,37 +604,8 @@ * @return whether the action was or can be performed */ private boolean doDeleteArch(final boolean performAction) { - final MapView<G, A, R> mapView = currentMapView; - if (mapView == null) { - return false; - } - - final MapCursor<G, A, R> mapCursor = getActiveMapCursor(mapView); - if (mapCursor == null) { - return false; - } - - final G gameObject = mapCursor.getGameObject(); - if (gameObject == null) { - return false; - } - - final MapSquare<G, A, R> mapSquare = gameObject.getMapSquare(); - if (mapSquare == null) { - return false; - } - - if (performAction) { - final MapModel<G, A, R> mapModel = mapSquare.getMapModel(); - mapModel.beginTransaction("Delete"); // TODO; I18N/L10N - try { - mapModel.removeGameObject(gameObject, true); - } finally { - mapModel.endTransaction(); - } - } - - return true; + final MapCursor<G, A, R> mapCursor = getActiveMapCursor(); + return mapCursor != null && mapCursor.deleteSelectedGameObject(performAction); } /** Modified: trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareView.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareView.java 2011-10-30 22:46:08 UTC (rev 9083) +++ trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareView.java 2011-10-30 23:22:48 UTC (rev 9084) @@ -605,32 +605,13 @@ * @param index the list index of the game object to delete */ private void deleteIndex(final int index) { - final MapModel<G, A, R> mapModel = this.mapModel; - if (mapModel != null) { - deleteIndex(mapModel, index); + final MapCursor<G, A, R> mapCursor = this.mapCursor; + if (mapCursor != null && index < model.getSize()) { + setSelectedIndex(index); + mapCursor.deleteSelectedGameObject(true); } } - private void deleteIndex(@NotNull final MapModel<G, A, R> mapModel, final int index) { - if (index < 0 || index >= model.getSize()) { - return; - } - - final G gameObject = getListGameObject(index); - if (gameObject == null) { - return; - } - - mapModel.beginTransaction("Delete"); // TODO; I18N/L10N - try { - mapModel.removeGameObject(gameObject, true); - } finally { - mapModel.endTransaction(); - } - - setSelectedIndex(index); - } - /** * Inserts a new game object. * @param index the list index to insert at This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2011-10-30 23:26:26
|
Revision: 9085 http://gridarta.svn.sourceforge.net/gridarta/?rev=9085&view=rev Author: akirschbaum Date: 2011-10-30 23:26:19 +0000 (Sun, 30 Oct 2011) Log Message: ----------- Merge duplicated code. Modified Paths: -------------- trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareView.java Modified: trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java 2011-10-30 23:22:48 UTC (rev 9084) +++ trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java 2011-10-30 23:26:19 UTC (rev 9085) @@ -629,30 +629,35 @@ /** * Inserts a {@link GameObject} before the selected game object. Does * nothing if no game object is selected. + * @param performAction whether the action should be performed * @param gameObject the game object to insert * @param insertAtEnd whether to ignore the selected game object and insert * at the end * @param join if set, auto-joining is supported + * @return whether the action was or can be performed */ - public void insertGameObject(@NotNull final BaseObject<G, A, R, ?> gameObject, final boolean insertAtEnd, final boolean join) { + public boolean insertGameObject(final boolean performAction, @NotNull final BaseObject<G, A, R, ?> gameObject, final boolean insertAtEnd, final boolean join) { if (!onMap) { - return; + return false; } - mapModel.beginTransaction("Insert"); // TODO; I18N/L10N - try { - final G insertedGameObject = mapModel.insertArchToMap(gameObject, insertAtEnd ? null : this.gameObject, pos, join); - if (insertedGameObject != null) { - beginTransaction(); - try { - this.gameObject = insertedGameObject; - } finally { - endTransaction(); + if (performAction) { + mapModel.beginTransaction("Insert"); // TODO; I18N/L10N + try { + final G insertedGameObject = mapModel.insertArchToMap(gameObject, insertAtEnd ? null : this.gameObject, pos, join); + if (insertedGameObject != null) { + beginTransaction(); + try { + this.gameObject = insertedGameObject; + } finally { + endTransaction(); + } } + } finally { + mapModel.endTransaction(); } - } finally { - mapModel.endTransaction(); } + return true; } /** Modified: trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java 2011-10-30 23:22:48 UTC (rev 9084) +++ trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java 2011-10-30 23:26:19 UTC (rev 9085) @@ -571,31 +571,9 @@ * @return whether the action was or can be performed */ private boolean doInsertArch(final boolean performAction) { - final MapView<G, A, R> mapView = currentMapView; - if (mapView == null) { - return false; - } - - final MapCursor<G, A, R> mapCursor = getActiveMapCursor(mapView); - if (mapCursor == null) { // XXX: should pass to function - return false; - } - - if (performAction) { - final BaseObject<G, A, R, ?> gameObject = objectChooser.getSelection(); - if (gameObject == null) { - return false; - } - - final Point location = mapCursor.getLocation(); - if (location == null) { - return false; - } - - mapCursor.insertGameObject(gameObject, false, true); - } - - return true; + 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); } /** Modified: trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareView.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareView.java 2011-10-30 23:22:48 UTC (rev 9084) +++ trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareView.java 2011-10-30 23:26:19 UTC (rev 9085) @@ -621,7 +621,7 @@ if (gameObject != null) { final MapCursor<G, A, R> mapCursor = this.mapCursor; if (mapCursor != null) { - mapCursor.insertGameObject(gameObject, index >= model.getSize(), true); + mapCursor.insertGameObject(true, gameObject, index >= model.getSize(), true); } } setSelectedIndex(index); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2011-10-31 19:56:50
|
Revision: 9088 http://gridarta.svn.sourceforge.net/gridarta/?rev=9088&view=rev Author: akirschbaum Date: 2011-10-31 19:56:43 +0000 (Mon, 31 Oct 2011) Log Message: ----------- Rename action names. Modified Paths: -------------- trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/action.properties trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/messages.properties trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/action.properties trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/messages.properties trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/action.properties trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/messages.properties trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java trunk/src/app/net/sf/gridarta/messages.properties trunk/src/app/net/sf/gridarta/messages_de.properties trunk/src/app/net/sf/gridarta/messages_fr.properties trunk/src/app/net/sf/gridarta/messages_sv.properties Modified: trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/action.properties =================================================================== --- trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/action.properties 2011-10-31 07:54:27 UTC (rev 9087) +++ trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/action.properties 2011-10-31 19:56:43 UTC (rev 9088) @@ -50,7 +50,7 @@ main.toolbar=newMap openFile saveMap saveMapAs - prevWindow nextWindow - undo redo -moveCursor.menu=goNorth goEast goSouth goWest goNorthEast goSouthEast goSouthWest goNorthWest - goLocation +moveCursor.menu=moveCursorNorth moveCursorEast moveCursorSouth moveCursorWest moveCursorNorthEast moveCursorSouthEast moveCursorSouthWest moveCursorNorthWest - goLocation exitConnector.menu=exitCopy exitPaste exitConnect Modified: trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/messages.properties =================================================================== --- trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/messages.properties 2011-10-31 07:54:27 UTC (rev 9087) +++ trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/messages.properties 2011-10-31 19:56:43 UTC (rev 9088) @@ -127,14 +127,14 @@ ####### # Cursor -goNorth.accel=NUMPAD9 -goNorthEast.accel=NUMPAD6 -goEast.accel=NUMPAD3 -goSouthEast.accel=NUMPAD2 -goSouth.accel=NUMPAD1 -goSouthWest.accel=NUMPAD4 -goWest.accel=NUMPAD7 -goNorthWest.accel=NUMPAD8 +moveCursorNorth.accel=NUMPAD9 +moveCursorNorthEast.accel=NUMPAD6 +moveCursorEast.accel=NUMPAD3 +moveCursorSouthEast.accel=NUMPAD2 +moveCursorSouth.accel=NUMPAD1 +moveCursorSouthWest.accel=NUMPAD4 +moveCursorWest.accel=NUMPAD7 +moveCursorNorthWest.accel=NUMPAD8 ####### Modified: trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/action.properties =================================================================== --- trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/action.properties 2011-10-31 07:54:27 UTC (rev 9087) +++ trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/action.properties 2011-10-31 19:56:43 UTC (rev 9088) @@ -50,7 +50,7 @@ main.toolbar=newMap openFile saveMap saveMapAs - prevWindow nextWindow - undo redo -moveCursor.menu=goNorth goEast goSouth goWest goNorthEast goSouthEast goSouthWest goNorthWest - goLocation +moveCursor.menu=moveCursorNorth moveCursorEast moveCursorSouth moveCursorWest moveCursorNorthEast moveCursorSouthEast moveCursorSouthWest moveCursorNorthWest - goLocation exitConnector.menu=exitCopy exitPaste exitConnect Modified: trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/messages.properties =================================================================== --- trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/messages.properties 2011-10-31 07:54:27 UTC (rev 9087) +++ trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/messages.properties 2011-10-31 19:56:43 UTC (rev 9088) @@ -118,14 +118,14 @@ ####### # Cursor -goNorth.accel=NUMPAD8 -goNorthEast.accel=NUMPAD9 -goEast.accel=NUMPAD6 -goSouthEast.accel=NUMPAD3 -goSouth.accel=NUMPAD2 -goSouthWest.accel=NUMPAD1 -goWest.accel=NUMPAD4 -goNorthWest.accel=NUMPAD7 +moveCursorNorth.accel=NUMPAD8 +moveCursorNorthEast.accel=NUMPAD9 +moveCursorEast.accel=NUMPAD6 +moveCursorSouthEast.accel=NUMPAD3 +moveCursorSouth.accel=NUMPAD2 +moveCursorSouthWest.accel=NUMPAD1 +moveCursorWest.accel=NUMPAD4 +moveCursorNorthWest.accel=NUMPAD7 about.title=About Gridarta for Crossfire Modified: trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/action.properties =================================================================== --- trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/action.properties 2011-10-31 07:54:27 UTC (rev 9087) +++ trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/action.properties 2011-10-31 19:56:43 UTC (rev 9088) @@ -50,7 +50,7 @@ main.toolbar=newMap openFile saveMap saveMapAs - prevWindow nextWindow - undo redo -moveCursor.menu=goNorth goEast goSouth goWest goNorthEast goSouthEast goSouthWest goNorthWest - goLocation +moveCursor.menu=moveCursorNorth moveCursorEast moveCursorSouth moveCursorWest moveCursorNorthEast moveCursorSouthEast moveCursorSouthWest moveCursorNorthWest - goLocation exitConnector.menu=exitCopy exitPaste exitConnect Modified: trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/messages.properties =================================================================== --- trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/messages.properties 2011-10-31 07:54:27 UTC (rev 9087) +++ trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/messages.properties 2011-10-31 19:56:43 UTC (rev 9088) @@ -127,14 +127,14 @@ ####### # Cursor -goNorth.accel=NUMPAD9 -goNorthEast.accel=NUMPAD6 -goEast.accel=NUMPAD3 -goSouthEast.accel=NUMPAD2 -goSouth.accel=NUMPAD1 -goSouthWest.accel=NUMPAD4 -goWest.accel=NUMPAD7 -goNorthWest.accel=NUMPAD8 +moveCursorNorth.accel=NUMPAD9 +moveCursorNorthEast.accel=NUMPAD6 +moveCursorEast.accel=NUMPAD3 +moveCursorSouthEast.accel=NUMPAD2 +moveCursorSouth.accel=NUMPAD1 +moveCursorSouthWest.accel=NUMPAD4 +moveCursorWest.accel=NUMPAD7 +moveCursorNorthWest.accel=NUMPAD8 ####### Modified: trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java 2011-10-31 07:54:27 UTC (rev 9087) +++ trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java 2011-10-31 19:56:43 UTC (rev 9088) @@ -213,7 +213,7 @@ this.objectChooser = objectChooser; this.gameObjectAttributesDialogFactory = gameObjectAttributesDialogFactory; goLocationDialogManager = new GoLocationDialogManager<G, A, R>(mapViewManager); - final String[] directionsGo = { "goNorth", "goEast", "goSouth", "goWest", "goNorthEast", "goSouthEast", "goSouthWest", "goNorthWest" }; + final String[] directionsGo = { "moveCursorNorth", "moveCursorEast", "moveCursorSouth", "moveCursorWest", "moveCursorNorthEast", "moveCursorSouthEast", "moveCursorSouthWest", "moveCursorNorthWest" }; aGo = new Action[directionsGo.length]; final ActionBuilder actionBuilder = ActionBuilderFactory.getInstance().getActionBuilder("net.sf.gridarta"); for (int i = 0; i < directionsGo.length; i++) { @@ -236,66 +236,66 @@ } /** - * Action method for "cursor north". + * Action method for "move cursor north". */ @ActionMethod - public void goNorth() { + public void moveCursorNorth() { doGo(true, Direction.NORTH); } /** - * Action method for "cursor south". + * Action method for "move cursor south". */ @ActionMethod - public void goSouth() { + public void moveCursorSouth() { doGo(true, Direction.SOUTH); } /** - * Action method for "cursor east". + * Action method for "move cursor east". */ @ActionMethod - public void goEast() { + public void moveEast() { doGo(true, Direction.EAST); } /** - * Action method for "cursor west". + * Action method for "move cursor west". */ @ActionMethod - public void goWest() { + public void moveCursorWest() { doGo(true, Direction.WEST); } /** - * Action method for "cursor north east". + * Action method for "move cursor north east". */ @ActionMethod - public void goNorthEast() { + public void moveNorthEast() { doGo(true, Direction.NORTH_EAST); } /** - * Action method for "cursor north west". + * Action method for "move cursor north west". */ @ActionMethod - public void goNorthWest() { + public void moveNorthWest() { doGo(true, Direction.NORTH_WEST); } /** - * Action method for "cursor south east". + * Action method for "move cursor south east". */ @ActionMethod - public void goSouthEast() { + public void moveSouthEast() { doGo(true, Direction.SOUTH_EAST); } /** - * Action method for "cursor south west". + * Action method for "move cursor south west". */ @ActionMethod - public void goSouthWest() { + public void moveSouthWest() { doGo(true, Direction.SOUTH_WEST); } Modified: trunk/src/app/net/sf/gridarta/messages.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages.properties 2011-10-31 07:54:27 UTC (rev 9087) +++ trunk/src/app/net/sf/gridarta/messages.properties 2011-10-31 19:56:43 UTC (rev 9088) @@ -43,29 +43,29 @@ moveCursor.text=Move Cursor moveCursor.shortdescription=Moves the map cursor. -goNorth.text=Move Cursor North -goNorth.shortdescription=Moves the map cursor north. +moveCursorNorth.text=Move Cursor North +moveCursorNorth.shortdescription=Moves the map cursor north. -goNorthEast.text=Move Cursor Northeast -goNorthEast.shortdescription=Moves the map cursor north east. +moveCursorNorthEast.text=Move Cursor Northeast +moveCursorNorthEast.shortdescription=Moves the map cursor north east. -goEast.text=Move Cursor East -goEast.shortdescription=Moves the map cursor east. +moveCursorEast.text=Move Cursor East +moveCursorEast.shortdescription=Moves the map cursor east. -goSouthEast.text=Move Cursor Southeast -goSouthEast.shortdescription=Moves the map cursor south east. +moveCursorSouthEast.text=Move Cursor Southeast +moveCursorSouthEast.shortdescription=Moves the map cursor south east. -goSouth.text=Move Cursor South -goSouth.shortdescription=Moves the map cursor south. +moveCursorSouth.text=Move Cursor South +moveCursorSouth.shortdescription=Moves the map cursor south. -goSouthWest.text=Move Cursor Southwest -goSouthWest.shortdescription=Moves the map cursor south west. +moveCursorSouthWest.text=Move Cursor Southwest +moveCursorSouthWest.shortdescription=Moves the map cursor south west. -goWest.text=Move Cursor West -goWest.shortdescription=Moves the map cursor west. +moveCursorWest.text=Move Cursor West +moveCursorWest.shortdescription=Moves the map cursor west. -goNorthWest.text=Move Cursor Northwest -goNorthWest.shortdescription=Moves the map cursor north west. +moveCursorNorthWest.text=Move Cursor Northwest +moveCursorNorthWest.shortdescription=Moves the map cursor north west. goMap.text=Goto Map... goMap.mnemonic=M Modified: trunk/src/app/net/sf/gridarta/messages_de.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages_de.properties 2011-10-31 07:54:27 UTC (rev 9087) +++ trunk/src/app/net/sf/gridarta/messages_de.properties 2011-10-31 19:56:43 UTC (rev 9088) @@ -43,29 +43,29 @@ moveCursor.text=Cursor bewegen moveCursor.shortdescription=Bewegt den Cursor. -goNorth.text=Cursor nach Nord -goNorth.shortdescription=Bewegt den Cursor nach Norden. +moveCursorNorth.text=Cursor nach Nord +moveCursorNorth.shortdescription=Bewegt den Cursor nach Norden. -goNorthEast.text=Cursor nach Nordost -goNorthEast.shortdescription=Bewegt den Cursor nach Nordosten. +moveCursorNorthEast.text=Cursor nach Nordost +moveCursorNorthEast.shortdescription=Bewegt den Cursor nach Nordosten. -goEast.text=Cursor nach Ost -goEast.shortdescription=Bewegt den Cursor nach Osten. +moveCursorEast.text=Cursor nach Ost +moveCursorEast.shortdescription=Bewegt den Cursor nach Osten. -goSouthEast.text=Cursor nach S\u00fcdost -goSouthEast.shortdescription=Bewegt den Cursor nach S\u00fcdosten. +moveCursorSouthEast.text=Cursor nach S\u00fcdost +moveCursorSouthEast.shortdescription=Bewegt den Cursor nach S\u00fcdosten. -goSouth.text=Cursor nach S\u00fcd -goSouth.shortdescription=Bewegt den Cursor nach S\u00fcden. +moveCursorSouth.text=Cursor nach S\u00fcd +moveCursorSouth.shortdescription=Bewegt den Cursor nach S\u00fcden. -goSouthWest.text=Cursor nach S\u00fcdwest -goSouthWest.shortdescription=Bewegt den Cursor nach S\u00fcdwesten. +moveCursorSouthWest.text=Cursor nach S\u00fcdwest +moveCursorSouthWest.shortdescription=Bewegt den Cursor nach S\u00fcdwesten. -goWest.text=Cursor nach West -goWest.shortdescription=Bewegt den Cursor nach Westen. +moveCursorWest.text=Cursor nach West +moveCursorWest.shortdescription=Bewegt den Cursor nach Westen. -goNorthWest.text=Cursor nach Nordwest -goNorthWest.shortdescription=Bewegt den Cursor nach Nordwesten. +moveCursorNorthWest.text=Cursor nach Nordwest +moveCursorNorthWest.shortdescription=Bewegt den Cursor nach Nordwesten. ####### # Map Modified: trunk/src/app/net/sf/gridarta/messages_fr.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages_fr.properties 2011-10-31 07:54:27 UTC (rev 9087) +++ trunk/src/app/net/sf/gridarta/messages_fr.properties 2011-10-31 19:56:43 UTC (rev 9088) @@ -43,29 +43,29 @@ #moveCursor.text= #moveCursor.shortdescription= -#goNorth.text= -#goNorth.shortdescription= +#moveCursorNorth.text= +#moveCursorNorth.shortdescription= -#goNorthEast.text= -#goNorthEast.shortdescription= +#moveCursorNorthEast.text= +#moveCursorNorthEast.shortdescription= -#goEast.text= -#goEast.shortdescription= +#moveCursorEast.text= +#moveCursorEast.shortdescription= -#goSouthEast.text= -#goSouthEast.shortdescription= +#moveCursorSouthEast.text= +#moveCursorSouthEast.shortdescription= -#goSouth.text= -#goSouth.shortdescription= +#moveCursorSouth.text= +#moveCursorSouth.shortdescription= -#goSouthWest.text= -#goSouthWest.shortdescription= +#moveCursorSouthWest.text= +#moveCursorSouthWest.shortdescription= -#goWest.text= -#goWest.shortdescription= +#moveCursorWest.text= +#moveCursorWest.shortdescription= -#goNorthWest.text= -#goNorthWest.shortdescription= +#moveCursorNorthWest.text= +#moveCursorNorthWest.shortdescription= goMap.text=Aller \u00e0 une carte... goMap.mnemonic=A Modified: trunk/src/app/net/sf/gridarta/messages_sv.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages_sv.properties 2011-10-31 07:54:27 UTC (rev 9087) +++ trunk/src/app/net/sf/gridarta/messages_sv.properties 2011-10-31 19:56:43 UTC (rev 9088) @@ -43,29 +43,29 @@ moveCursor.text=Flytta mark\u00f6r #moveCursor.shortdescription= -goNorth.text=Flytta mark\u00f6r norrut -#goNorth.shortdescription= +moveCursorNorth.text=Flytta mark\u00f6r norrut +#moveCursorNorth.shortdescription= -goNorthEast.text=Flytta mark\u00f6r nord\u00f6st -#goNorthEast.shortdescription= +moveCursorNorthEast.text=Flytta mark\u00f6r nord\u00f6st +#moveCursorNorthEast.shortdescription= -goEast.text=Flytta mark\u00f6r \u00f6sterut -#goEast.shortdescription= +moveCursorEast.text=Flytta mark\u00f6r \u00f6sterut +#moveCursorEast.shortdescription= -goSouthEast.text=Flytta mark\u00f6r syd\u00f6st -#goSouthEast.shortdescription= +moveCursorSouthEast.text=Flytta mark\u00f6r syd\u00f6st +#moveCursorSouthEast.shortdescription= -goSouth.text=Flytta mark\u00f6r s\u00f6derut -#goSouth.shortdescription= +moveCursorSouth.text=Flytta mark\u00f6r s\u00f6derut +#moveCursorSouth.shortdescription= -goSouthWest.text=Flytta mark\u00f6r sydv\u00e4st -#goSouthWest.shortdescription= +moveCursorSouthWest.text=Flytta mark\u00f6r sydv\u00e4st +#moveCursorSouthWest.shortdescription= -goWest.text=Flytta mark\u00f6r v\u00e4sterut -#goWest.shortdescription= +moveCursorWest.text=Flytta mark\u00f6r v\u00e4sterut +#moveCursorWest.shortdescription= -goNorthWest.text=Flytta mark\u00f6r nordv\u00e4st -#goNorthWest.shortdescription= +moveCursorNorthWest.text=Flytta mark\u00f6r nordv\u00e4st +#moveCursorNorthWest.shortdescription= ####### # Map This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2011-10-31 22:31:26
|
Revision: 9093 http://gridarta.svn.sourceforge.net/gridarta/?rev=9093&view=rev Author: akirschbaum Date: 2011-10-31 22:31:19 +0000 (Mon, 31 Oct 2011) Log Message: ----------- Properly enable or disable 'Move Cursor' menu entries. Modified Paths: -------------- trunk/model/src/app/net/sf/gridarta/model/direction/Direction.java trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java trunk/model/src/test/net/sf/gridarta/model/mapcursor/MapCursorTest.java trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java Modified: trunk/model/src/app/net/sf/gridarta/model/direction/Direction.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/direction/Direction.java 2011-10-31 22:08:56 UTC (rev 9092) +++ trunk/model/src/app/net/sf/gridarta/model/direction/Direction.java 2011-10-31 22:31:19 UTC (rev 9093) @@ -19,6 +19,8 @@ package net.sf.gridarta.model.direction; +import org.jetbrains.annotations.NotNull; + /** * A direction. * @author Andreas Kirschbaum @@ -28,42 +30,42 @@ /** * North. */ - NORTH(0, -1), + NORTH(0, -1, "North"), /** * East. */ - EAST(1, 0), + EAST(1, 0, "East"), /** * South. */ - SOUTH(0, 1), + SOUTH(0, 1, "South"), /** * West. */ - WEST(-1, 0), + WEST(-1, 0, "West"), /** * North east. */ - NORTH_EAST(1, -1), + NORTH_EAST(1, -1, "NorthEast"), /** * South east. */ - SOUTH_EAST(1, 1), + SOUTH_EAST(1, 1, "SouthEast"), /** * South west. */ - SOUTH_WEST(-1, 1), + SOUTH_WEST(-1, 1, "SouthWest"), /** * North west. */ - NORTH_WEST(-1, -1); + NORTH_WEST(-1, -1, "NorthWest"); /** * The relative x direction. @@ -76,13 +78,21 @@ private final int dy; /** + * The identification string. + */ + @NotNull + private final String id; + + /** * Creates a new instance. * @param dx the relative x direction * @param dy the relative y direction + * @param id the identification string */ - Direction(final int dx, final int dy) { + Direction(final int dx, final int dy, @NotNull final String id) { this.dx = dx; this.dy = dy; + this.id = id; } /** @@ -101,4 +111,13 @@ return dy; } + /** + * Returns the identification string. + * @return the identification string + */ + @NotNull + public String getId() { + return id; + } + } // enum Direction Modified: trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java 2011-10-31 22:08:56 UTC (rev 9092) +++ trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java 2011-10-31 22:31:19 UTC (rev 9093) @@ -385,17 +385,24 @@ /** * Moves the cursor one square relative to current position. + * @param performAction whether the action should be performed * @param dir the direction * @return <code>true</code> if cursor really moved */ - public boolean goTo(@NotNull final Direction dir) { + public boolean goTo(final boolean performAction, @NotNull final Direction dir) { if (onMap) { tmpPoint.setLocation(pos.x + dir.getDx(), pos.y + dir.getDy()); - if (dragging) { - return dragTo(tmpPoint); - } else { - return setLocationSafe(tmpPoint); + if (!mapRec.contains(tmpPoint)) { + return false; } + if (performAction) { + if (dragging) { + dragTo(tmpPoint); + } else { + setLocationSafe(tmpPoint); + } + } + return true; } return false; } Modified: trunk/model/src/test/net/sf/gridarta/model/mapcursor/MapCursorTest.java =================================================================== --- trunk/model/src/test/net/sf/gridarta/model/mapcursor/MapCursorTest.java 2011-10-31 22:08:56 UTC (rev 9092) +++ trunk/model/src/test/net/sf/gridarta/model/mapcursor/MapCursorTest.java 2011-10-31 22:31:19 UTC (rev 9093) @@ -236,14 +236,14 @@ } /** - * Checks {@link MapCursor#goTo(Direction)}. + * Checks {@link MapCursor#goTo(boolean, Direction)}. */ @Test public void testGoTo() { final MapGrid grid = new MapGrid(gridSize); final MapCursor<TestGameObject, TestMapArchObject, TestArchetype> cursor = createCursor(grid); for (final Direction dir : Direction.values()) { - Assert.assertFalse("go(" + dir + ") should return false.", cursor.goTo(dir)); + Assert.assertFalse("go(" + dir + ") should return false.", cursor.goTo(true, dir)); testEvents(0, 0); } final Point pStart = new Point(2, 3); @@ -251,7 +251,7 @@ cursor.setLocation(p); testEvents(1, 1); for (final Direction dir : Direction.values()) { - Assert.assertTrue("go(" + dir + ") should return true. (Maybe the grid was too small.)", cursor.goTo(dir)); + Assert.assertTrue("go(" + dir + ") should return true. (Maybe the grid was too small.)", cursor.goTo(true, dir)); testEvents(1, 0); p.x += dir.getDx(); p.y += dir.getDy(); Modified: trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java 2011-10-31 22:08:56 UTC (rev 9092) +++ trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java 2011-10-31 22:31:19 UTC (rev 9093) @@ -58,6 +58,12 @@ private final ObjectChooser<G, A, R> objectChooser; /** + * All {@link Direction Directions}. + */ + @NotNull + private static final Direction[] directions = Direction.values(); + + /** * Actions for "move cursor". */ @NotNull @@ -186,7 +192,7 @@ /** {@inheritDoc} */ @Override public void mapCursorChangedPos(@Nullable final Point location) { - // ignore + refreshActions(); } /** {@inheritDoc} */ @@ -213,11 +219,10 @@ this.objectChooser = objectChooser; this.gameObjectAttributesDialogFactory = gameObjectAttributesDialogFactory; goLocationDialogManager = new GoLocationDialogManager<G, A, R>(mapViewManager); - final String[] moveCursorDirections = { "moveCursorNorth", "moveCursorEast", "moveCursorSouth", "moveCursorWest", "moveCursorNorthEast", "moveCursorSouthEast", "moveCursorSouthWest", "moveCursorNorthWest" }; - aMoveCursor = new Action[moveCursorDirections.length]; + aMoveCursor = new Action[directions.length]; final ActionBuilder actionBuilder = ActionBuilderFactory.getInstance().getActionBuilder("net.sf.gridarta"); - for (int i = 0; i < moveCursorDirections.length; i++) { - aMoveCursor[i] = ActionUtils.newAction(actionBuilder, "Map Cursor,Map/Selection", this, moveCursorDirections[i]); + for (final Direction direction : directions) { + aMoveCursor[direction.ordinal()] = ActionUtils.newAction(actionBuilder, "Map Cursor,Map/Selection", this, "moveCursor" + direction.getId()); } aGoLocation = ActionUtils.newAction(actionBuilder, "Map Cursor", this, "goLocation"); aSelectSquare = ActionUtils.newAction(actionBuilder, "Map Cursor,Map/Selection", this, "selectSquare"); @@ -414,9 +419,8 @@ * Enable/disable menu entries based on the current cursor state. */ private void refreshActions() { - final boolean goEnabled = doMoveCursor(false, Direction.NORTH); - for (final Action action : aMoveCursor) { - action.setEnabled(goEnabled); + for (final Direction direction : directions) { + aMoveCursor[direction.ordinal()].setEnabled(doMoveCursor(false, direction)); } aGoLocation.setEnabled(doGoLocation(false)); aSelectSquare.setEnabled(doSelectSquare(false)); @@ -444,15 +448,7 @@ */ private boolean doMoveCursor(final boolean performAction, @NotNull final Direction direction) { final MapCursor<G, A, R> mapCursor = getActiveMapCursor(); - if (mapCursor == null) { - return false; - } - - if (performAction) { - mapCursor.goTo(direction); - } - - return true; + return mapCursor != null && mapCursor.goTo(performAction, direction); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2011-11-03 17:33:16
|
Revision: 9097 http://gridarta.svn.sourceforge.net/gridarta/?rev=9097&view=rev Author: akirschbaum Date: 2011-11-03 17:33:08 +0000 (Thu, 03 Nov 2011) Log Message: ----------- Add actions moveSquarePrev and moveSquareNext for selecting the previous or next game object in the selected square view. Modified Paths: -------------- trunk/model/src/app/net/sf/gridarta/model/gameobject/GameObject.java trunk/src/app/net/sf/gridarta/action.properties trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareActions.java trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareView.java trunk/src/app/net/sf/gridarta/messages.properties trunk/src/app/net/sf/gridarta/messages_de.properties trunk/src/app/net/sf/gridarta/messages_fr.properties trunk/src/app/net/sf/gridarta/messages_sv.properties Modified: trunk/model/src/app/net/sf/gridarta/model/gameobject/GameObject.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/gameobject/GameObject.java 2011-11-03 16:57:07 UTC (rev 9096) +++ trunk/model/src/app/net/sf/gridarta/model/gameobject/GameObject.java 2011-11-03 17:33:08 UTC (rev 9097) @@ -59,6 +59,14 @@ void addLast(@NotNull G gameObject); /** + * Return the last GameObject contained in this container. + * @return first GameObject contained or <code>null</code> if {@link + * #isEmpty()} returns <code>true</code> + */ + @Nullable + G getLast(); + + /** * Add the given GameObject at the beginning of this Container. * @param gameObject the free yet unlinked <code>GameObject</code> to be * placed in the inventory Modified: trunk/src/app/net/sf/gridarta/action.properties =================================================================== --- trunk/src/app/net/sf/gridarta/action.properties 2011-11-03 16:57:07 UTC (rev 9096) +++ trunk/src/app/net/sf/gridarta/action.properties 2011-11-03 17:33:08 UTC (rev 9097) @@ -160,6 +160,8 @@ update.icon=general/Search16 +moveSquarePrev.icon=navigation/Up16 +moveSquareNext.icon=navigation/Down16 moveSquareTop.icon=navigation/Top16 moveSquareUp.icon=navigation/Up16 moveSquareDown.icon=navigation/Down16 Modified: trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareActions.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareActions.java 2011-11-03 16:57:07 UTC (rev 9096) +++ trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareActions.java 2011-11-03 17:33:08 UTC (rev 9097) @@ -49,6 +49,74 @@ } /** + * Executes the "move square prev" action. + * @param performAction whether the action should be performed + * @return whether the action was or can be performed + */ + public boolean doMoveSquarePrev(final boolean performAction) { + final GameObject<G, A, R> gameObject = selectedSquareModel.getSelectedGameObject(); + if (gameObject == null || !gameObject.isHead()) { + return false; + } + + G prevGameObject = gameObject.getPrev(); + if (prevGameObject == null) { + prevGameObject = gameObject.getContainerGameObject(); + if (prevGameObject == null) { + return false; + } + } else if (performAction) { + while (true) { + final G tmp = prevGameObject.getFirst(); + if (tmp == null) { + break; + } + prevGameObject = tmp; + } + } + + if (performAction) { + selectedSquareModel.setSelectedGameObject(prevGameObject); + } + + return true; + } + + /** + * Executes the "move square next" action. + * @param performAction whether the action should be performed + * @return whether the action was or can be performed + */ + public boolean doMoveSquareNext(final boolean performAction) { + final G gameObject = selectedSquareModel.getSelectedGameObject(); + if (gameObject == null || !gameObject.isHead()) { + return false; + } + + G nextGameObject = gameObject.getLast(); + if (nextGameObject == null) { + nextGameObject = gameObject; + while (true) { + final G tmp = nextGameObject.getNext(); + if (tmp != null) { + nextGameObject = tmp; + break; + } + nextGameObject = nextGameObject.getContainerGameObject(); + if (nextGameObject == null) { + return false; + } + } + } + + if (performAction) { + selectedSquareModel.setSelectedGameObject(nextGameObject); + } + + return true; + } + + /** * Executes the "move square top" action. * @param performAction whether the action should be performed * @return whether the action was or can be performed Modified: trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareView.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareView.java 2011-11-03 16:57:07 UTC (rev 9096) +++ trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareView.java 2011-11-03 17:33:08 UTC (rev 9097) @@ -159,6 +159,18 @@ private MapCursor<G, A, R> mapCursor; /** + * The action for "move square prev". + */ + @NotNull + private final Action aMoveSquarePrev = ActionUtils.newAction(ACTION_BUILDER, "Selected Square View", this, "moveSquarePrev"); + + /** + * The action for "move square next". + */ + @NotNull + private final Action aMoveSquareNext = ActionUtils.newAction(ACTION_BUILDER, "Selected Square View", this, "moveSquareNext"); + + /** * The action for "move square top". */ @NotNull @@ -397,7 +409,7 @@ updateArrows(false); final Collection<Action> actions = new ArrayList<Action>(); - actions.add(aMoveSquareTop); + actions.add(aMoveSquareDown); actions.add(aMoveSquareUp); actions.add(aMoveSquareDown); actions.add(aMoveSquareBottom); @@ -467,6 +479,8 @@ * Updates the enabled state of all actions. */ private void updateActions() { + aMoveSquarePrev.setEnabled(selectedSquareActions.doMoveSquarePrev(false)); + aMoveSquareNext.setEnabled(selectedSquareActions.doMoveSquareNext(false)); aMoveSquareTop.setEnabled(selectedSquareActions.doMoveSquareTop(false)); aMoveSquareUp.setEnabled(selectedSquareActions.doMoveSquareUp(false)); aMoveSquareDown.setEnabled(selectedSquareActions.doMoveSquareDown(false)); @@ -552,6 +566,22 @@ } /** + * Action method for selecting the previous game object. + */ + @ActionMethod + public void moveSquarePrev() { + selectedSquareActions.doMoveSquarePrev(true); + } + + /** + * Action method for selecting the next game object. + */ + @ActionMethod + public void moveSquareNext() { + selectedSquareActions.doMoveSquareNext(true); + } + + /** * Action method for moving an arch topmost within its square. */ @ActionMethod Modified: trunk/src/app/net/sf/gridarta/messages.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages.properties 2011-11-03 16:57:07 UTC (rev 9096) +++ trunk/src/app/net/sf/gridarta/messages.properties 2011-11-03 17:33:08 UTC (rev 9097) @@ -1567,6 +1567,12 @@ ################## # Selected Square +moveSquarePrev.text= +moveSquarePrev.shortdescription=Selects the previous game object in map square. +moveSquarePrev.accel=alt pressed UP +moveSquareNext.text= +moveSquareNext.shortdescription=Selects the next game object in map square. +moveSquareNext.accel=alt pressed DOWN moveSquareTop.text= moveSquareTop.shortdescription=Moves the selected game object to top of map square. moveSquareUp.text= Modified: trunk/src/app/net/sf/gridarta/messages_de.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages_de.properties 2011-11-03 16:57:07 UTC (rev 9096) +++ trunk/src/app/net/sf/gridarta/messages_de.properties 2011-11-03 17:33:08 UTC (rev 9097) @@ -1332,7 +1332,10 @@ ################## # Selected Square - +moveSquarePrev.text= +moveSquarePrev.shortdescription=Selektiert das n\u00e4chste Objekt. +moveSquareNext.text= +moveSquareNext.shortdescription=Selektiert das vorherige Objekt. moveSquareTop.text= moveSquareTop.shortdescription=Verschiebt das aktive Objekt an den Anfang. moveSquareUp.text= Modified: trunk/src/app/net/sf/gridarta/messages_fr.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages_fr.properties 2011-11-03 16:57:07 UTC (rev 9096) +++ trunk/src/app/net/sf/gridarta/messages_fr.properties 2011-11-03 17:33:08 UTC (rev 9097) @@ -1323,7 +1323,10 @@ ################## # Selected Square - +moveSquarePrev.text= +#moveSquarePrev.shortdescription= +moveSquareNext.text= +#moveSquareNext.shortdescription= moveSquareTop.text= #moveSquareTop.shortdescription= moveSquareUp.text= Modified: trunk/src/app/net/sf/gridarta/messages_sv.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages_sv.properties 2011-11-03 16:57:07 UTC (rev 9096) +++ trunk/src/app/net/sf/gridarta/messages_sv.properties 2011-11-03 17:33:08 UTC (rev 9097) @@ -1323,6 +1323,10 @@ ################## # Selected Square +moveSquarePrev.text= +#moveSquarePrev.shortdescription= +moveSquareNext.text= +#moveSquareNext.shortdescription= moveSquareTop.text= #moveSquareTop.shortdescription= moveSquareUp.text= This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2011-11-05 15:38:10
|
Revision: 9101 http://gridarta.svn.sourceforge.net/gridarta/?rev=9101&view=rev Author: akirschbaum Date: 2011-11-05 15:38:03 +0000 (Sat, 05 Nov 2011) Log Message: ----------- Replace "Revert Map" with "Reload Map". Modified Paths: -------------- trunk/atrinik/ChangeLog trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/action.properties trunk/crossfire/ChangeLog trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/action.properties trunk/daimonin/ChangeLog trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/action.properties trunk/src/app/net/sf/gridarta/action.properties trunk/src/app/net/sf/gridarta/gui/map/MapFileActions.java trunk/src/app/net/sf/gridarta/messages.properties trunk/src/app/net/sf/gridarta/messages_de.properties trunk/src/app/net/sf/gridarta/messages_fr.properties trunk/src/app/net/sf/gridarta/messages_sv.properties Modified: trunk/atrinik/ChangeLog =================================================================== --- trunk/atrinik/ChangeLog 2011-11-03 17:52:27 UTC (rev 9100) +++ trunk/atrinik/ChangeLog 2011-11-05 15:38:03 UTC (rev 9101) @@ -1,3 +1,9 @@ +2011-11-05 Andreas Kirschbaum + + * Replace "Revert Map" with "Reload Map". Now the current map can + be reloaded even if it is not modified. This allows to reload the + map when it has been changed externally. + 2011-10-30 Andreas Kirschbaum * Set the map cursor and select the affected game object for Modified: trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/action.properties =================================================================== --- trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/action.properties 2011-11-03 17:52:27 UTC (rev 9100) +++ trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/action.properties 2011-11-05 15:38:03 UTC (rev 9101) @@ -25,7 +25,7 @@ ######## # Menus main.menubar=file edit map archetypes pickmaps resources tools analyze view bookmarks plugins window help -file.menu=newMap openFile goMap recent closeMap - saveMap saveMapAs saveAllMaps - closeAllMaps revertMap createImage - options shortcuts - exit +file.menu=newMap openFile goMap recent closeMap - saveMap saveMapAs saveAllMaps - closeAllMaps reloadMap createImage - options shortcuts - exit edit.menu=undo redo - clear cut copy paste pasteTiled - shift - replace fillAuto fillAbove fillBelow randFillAuto randFillAbove randFillBelow floodFill - selectAll invertSelection expandEmptySelection growSelection shrinkSelection map.menu=autoJoin - enterExit nextExit prevExit enterNorthMap enterEastMap enterSouthMap enterWestMap enterNorthEastMap enterSouthEastMap enterSouthWestMap enterNorthWestMap - mapCreateView mapProperties shrinkMapSize deleteUnknownObjects - gameObjectTextEditor archetypes.menu=displayGameObjectNames displayArchetypeNames displayIconsOnly - findArchetypes @@ -40,7 +40,7 @@ mapwindow.menubar=mapwindowFile mapwindowEdit mapwindowMap mapwindowCursor -mapwindowFile.menu=saveMap saveMapAs createImage - revertMap - closeMap +mapwindowFile.menu=saveMap saveMapAs createImage - reloadMap - closeMap mapwindowEdit.menu=undo redo - clear cut copy paste pasteTiled - shift - replace fillAuto fillAbove fillBelow randFillAuto randFillAbove randFillBelow floodFill - selectAll invertSelection expandEmptySelection growSelection shrinkSelection mapwindowMap.menu=gridVisible - goExit enterExit nextExit prevExit enterNorthMap enterEastMap enterSouthMap enterWestMap enterNorthEastMap enterSouthEastMap enterSouthWestMap enterNorthWestMap - mapCreateView mapProperties shrinkMapSize deleteUnknownObjects mapwindowCursor.menu=moveCursor - exitConnector - selectSquare startStopDrag addToSelection subFromSelection releaseDrag - insertArch deleteArch - selectArchAbove selectArchBelow - archAttributes Modified: trunk/crossfire/ChangeLog =================================================================== --- trunk/crossfire/ChangeLog 2011-11-03 17:52:27 UTC (rev 9100) +++ trunk/crossfire/ChangeLog 2011-11-05 15:38:03 UTC (rev 9101) @@ -1,3 +1,9 @@ +2011-11-05 Andreas Kirschbaum + + * Replace "Revert Map" with "Reload Map". Now the current map can + be reloaded even if it is not modified. This allows to reload the + map when it has been changed externally. + 2011-10-30 Andreas Kirschbaum * Set the map cursor and select the affected game object for Modified: trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/action.properties =================================================================== --- trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/action.properties 2011-11-03 17:52:27 UTC (rev 9100) +++ trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/action.properties 2011-11-05 15:38:03 UTC (rev 9101) @@ -25,7 +25,7 @@ ######## # Menus main.menubar=file edit map archetypes pickmaps resources tools analyze view bookmarks plugins window help -file.menu=newMap openFile goMap recent closeMap - saveMap saveMapAs saveAllMaps - closeAllMaps revertMap createImage - options shortcuts - exit +file.menu=newMap openFile goMap recent closeMap - saveMap saveMapAs saveAllMaps - closeAllMaps reloadMap createImage - options shortcuts - exit edit.menu=undo redo - clear cut copy paste pasteTiled - shift - replace fillAuto fillAbove fillBelow randFillAuto randFillAbove randFillBelow floodFill - selectAll invertSelection expandEmptySelection growSelection shrinkSelection map.menu=autoJoin - enterExit nextExit prevExit enterNorthMap enterEastMap enterSouthMap enterWestMap tileShow - mapCreateView mapProperties shrinkMapSize deleteUnknownObjects - gameObjectTextEditor archetypes.menu=displayGameObjectNames displayArchetypeNames displayIconsOnly - findArchetypes @@ -40,7 +40,7 @@ mapwindow.menubar=mapwindowFile mapwindowEdit mapwindowMap mapwindowCursor -mapwindowFile.menu=saveMap saveMapAs createImage - revertMap - closeMap +mapwindowFile.menu=saveMap saveMapAs createImage - reloadMap - closeMap mapwindowEdit.menu=undo redo - clear cut copy paste pasteTiled - shift - replace fillAuto fillAbove fillBelow randFillAuto randFillAbove randFillBelow floodFill - selectAll invertSelection expandEmptySelection growSelection shrinkSelection mapwindowMap.menu=gridVisible smoothing - goExit enterExit nextExit prevExit enterNorthMap enterEastMap enterSouthMap enterWestMap tileShow - mapCreateView mapProperties shrinkMapSize deleteUnknownObjects mapwindowCursor.menu=moveCursor - exitConnector - selectSquare startStopDrag addToSelection subFromSelection releaseDrag - insertArch deleteArch - selectArchAbove selectArchBelow - archAttributes Modified: trunk/daimonin/ChangeLog =================================================================== --- trunk/daimonin/ChangeLog 2011-11-03 17:52:27 UTC (rev 9100) +++ trunk/daimonin/ChangeLog 2011-11-05 15:38:03 UTC (rev 9101) @@ -1,3 +1,9 @@ +2011-11-05 Andreas Kirschbaum + + * Replace "Revert Map" with "Reload Map". Now the current map can + be reloaded even if it is not modified. This allows to reload the + map when it has been changed externally. + 2011-10-30 Andreas Kirschbaum * Set the map cursor and select the affected game object for Modified: trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/action.properties =================================================================== --- trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/action.properties 2011-11-03 17:52:27 UTC (rev 9100) +++ trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/action.properties 2011-11-05 15:38:03 UTC (rev 9101) @@ -25,7 +25,7 @@ ######## # Menus main.menubar=file edit map archetypes pickmaps resources tools analyze view bookmarks plugins window help -file.menu=newMap openFile goMap recent closeMap - saveMap saveMapAs saveAllMaps - closeAllMaps revertMap createImage - options shortcuts - exit +file.menu=newMap openFile goMap recent closeMap - saveMap saveMapAs saveAllMaps - closeAllMaps reloadMap createImage - options shortcuts - exit edit.menu=undo redo - clear cut copy paste pasteTiled - shift - replace fillAuto fillAbove fillBelow randFillAuto randFillAbove randFillBelow floodFill - selectAll invertSelection expandEmptySelection growSelection shrinkSelection map.menu=autoJoin - enterExit nextExit prevExit enterNorthMap enterEastMap enterSouthMap enterWestMap enterNorthEastMap enterSouthEastMap enterSouthWestMap enterNorthWestMap - mapCreateView mapProperties shrinkMapSize deleteUnknownObjects - gameObjectTextEditor archetypes.menu=displayGameObjectNames displayArchetypeNames displayIconsOnly - findArchetypes @@ -40,7 +40,7 @@ mapwindow.menubar=mapwindowFile mapwindowEdit mapwindowMap mapwindowCursor -mapwindowFile.menu=saveMap saveMapAs createImage - revertMap - closeMap +mapwindowFile.menu=saveMap saveMapAs createImage - reloadMap - closeMap mapwindowEdit.menu=undo redo - clear cut copy paste pasteTiled - shift - replace fillAuto fillAbove fillBelow randFillAuto randFillAbove randFillBelow floodFill - selectAll invertSelection expandEmptySelection growSelection shrinkSelection mapwindowMap.menu=gridVisible - goExit enterExit nextExit prevExit enterNorthMap enterEastMap enterSouthMap enterWestMap enterNorthEastMap enterSouthEastMap enterSouthWestMap enterNorthWestMap - mapCreateView mapProperties shrinkMapSize deleteUnknownObjects mapwindowCursor.menu=moveCursor - exitConnector - selectSquare startStopDrag addToSelection subFromSelection releaseDrag - insertArch deleteArch - selectArchAbove selectArchBelow - archAttributes Modified: trunk/src/app/net/sf/gridarta/action.properties =================================================================== --- trunk/src/app/net/sf/gridarta/action.properties 2011-11-03 17:52:27 UTC (rev 9100) +++ trunk/src/app/net/sf/gridarta/action.properties 2011-11-05 15:38:03 UTC (rev 9101) @@ -39,7 +39,7 @@ createImage.icon=CreateImageSmallIcon -revertMap.icon=general/Refresh16 +reloadMap.icon=general/Refresh16 closeMap.icon=EmptySmallIcon Modified: trunk/src/app/net/sf/gridarta/gui/map/MapFileActions.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/MapFileActions.java 2011-11-03 17:52:27 UTC (rev 9100) +++ trunk/src/app/net/sf/gridarta/gui/map/MapFileActions.java 2011-11-05 15:38:03 UTC (rev 9101) @@ -110,10 +110,10 @@ private final Action aCreateImage = ActionUtils.newAction(ACTION_BUILDER, "Map,Image", this, "createImage"); /** - * The action for "revert map". + * The action for "reload map". */ @NotNull - private final Action aRevertMap = ActionUtils.newAction(ACTION_BUILDER, "Map", this, "revertMap"); + private final Action aReloadMap = ActionUtils.newAction(ACTION_BUILDER, "Map", this, "reloadMap"); /** * The action for "close map". @@ -281,7 +281,7 @@ aSaveMap.setEnabled(doSaveMap(false)); aSaveMapAs.setEnabled(doSaveMapAs(false)); aCreateImage.setEnabled(doCreateImage(false)); - aRevertMap.setEnabled(doRevertMap(false)); + aReloadMap.setEnabled(doReloadMap(false)); aCloseMap.setEnabled(doCloseMap(false)); } @@ -310,12 +310,12 @@ } /** - * Invoked when the user wants to revert the map to the previously saved + * Invoked when the user wants to reload the map to the previously saved * state. */ @ActionMethod - public void revertMap() { - doRevertMap(true); + public void reloadMap() { + doReloadMap(true); } /** @@ -386,22 +386,17 @@ } /** - * Executes the "revert map" action. + * Executes the "reload map" action. * @param performAction whether the action should be performed * @return whether the action was or can be performed */ - private boolean doRevertMap(final boolean performAction) { + private boolean doReloadMap(final boolean performAction) { final MapControl<G, A, R> mapControl = currentMapControl; if (mapControl == null) { return false; } - final MapModel<G, A, R> mapModel = mapControl.getMapModel(); - if (!mapModel.isModified()) { - return false; - } - - final File mapFile = mapModel.getMapFile(); + final File mapFile = mapControl.getMapModel().getMapFile(); if (mapFile == null) { return false; } Modified: trunk/src/app/net/sf/gridarta/messages.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages.properties 2011-11-03 17:52:27 UTC (rev 9100) +++ trunk/src/app/net/sf/gridarta/messages.properties 2011-11-05 15:38:03 UTC (rev 9101) @@ -684,10 +684,10 @@ createImage.shortdescription=Saves an image of the current map to a file. createImage.error.text=Error while creating snapshot image -revertMap.text=Revert Map -revertMap.mnemonic=R -revertMap.shortdescription=Reverts the current map from its last saved state. -revertMap.error.text=Error while reverting map +reloadMap.text=Reload Map +reloadMap.mnemonic=R +reloadMap.shortdescription=Reloads the current map from its last saved state. +reloadMap.error.text=Error while reloading map closeMap.text=Close Map closeMap.mnemonic=C Modified: trunk/src/app/net/sf/gridarta/messages_de.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages_de.properties 2011-11-03 17:52:27 UTC (rev 9100) +++ trunk/src/app/net/sf/gridarta/messages_de.properties 2011-11-05 15:38:03 UTC (rev 9101) @@ -642,10 +642,10 @@ createImage.shortdescription=Speichert ein Bild der aktiven Karte. createImage.error.text=Fehler beim Bild speichern -revertMap.text=Karte zur\u00fccksetzen -revertMap.mnemonic=R -revertMap.shortdescription=Nimmt alle \u00c4nderungen der aktiven Karte zur\u00fcck und stellt die zuletzt gespeicherte Fassung wieder her. -revertMap.error.text=Fehler beim Zur\u00fccksetzen +reloadMap.text=Karte neu laden +reloadMap.mnemonic=R +reloadMap.shortdescription=Nimmt alle \u00c4nderungen der aktiven Karte zur\u00fcck und stellt die zuletzt gespeicherte Fassung wieder her. +rrloadMap.error.text=Fehler beim Neuladen closeMap.text=Karte schie\u00dfen closeMap.mnemonic=C Modified: trunk/src/app/net/sf/gridarta/messages_fr.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages_fr.properties 2011-11-03 17:52:27 UTC (rev 9100) +++ trunk/src/app/net/sf/gridarta/messages_fr.properties 2011-11-05 15:38:03 UTC (rev 9101) @@ -640,10 +640,10 @@ createImage.mnemonic=I createImage.error.text=Erreur lors de la cr\u00e9ation d''une image. -revertMap.text=Restaurer -revertMap.shortdescription=Restaure la carte selon la derni\u00e8re version enregistr\u00e9e. -revertMap.mnemonic=R -revertMap.error.text=Erreur lors de la restauration de la carte. +#reloadMap.text=Restaurer +#reloadMap.shortdescription=Restaure la carte selon la derni\u00e8re version enregistr\u00e9e. +#reloadMap.mnemonic=R +#reloadMap.error.text=Erreur lors de la restauration de la carte. closeMap.text=Fermer closeMap.shortdescription=Ferme la carte active. Modified: trunk/src/app/net/sf/gridarta/messages_sv.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages_sv.properties 2011-11-03 17:52:27 UTC (rev 9100) +++ trunk/src/app/net/sf/gridarta/messages_sv.properties 2011-11-05 15:38:03 UTC (rev 9101) @@ -642,10 +642,10 @@ createImage.mnemonic=B createImage.error.text=Kunde inte spara bilden -revertMap.text=\u00c5terst\u00e4ll -revertMap.shortdescription=\u00c5terst\u00e4ller kartan till den senast sparade versionen -revertMap.mnemonic=R -revertMap.error.text=Kunde inte \u00e5terst\u00e4lla kartan +#reloadMap.text=\u00c5terst\u00e4ll +#reloadMap.shortdescription=\u00c5terst\u00e4ller kartan till den senast sparade versionen +#reloadMap.mnemonic=R +#reloadMap.error.text=Kunde inte \u00e5terst\u00e4lla kartan closeMap.text=St\u00e4ng closeMap.shortdescription=St\u00e4nger den aktuella kartan This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2011-11-12 06:39:39
|
Revision: 9104 http://gridarta.svn.sourceforge.net/gridarta/?rev=9104&view=rev Author: akirschbaum Date: 2011-11-12 06:39:32 +0000 (Sat, 12 Nov 2011) Log Message: ----------- Add game object matcher 'Messages' that matches game objects having a non-empty msg..endmsg attribute. [Crossfire] Modified Paths: -------------- trunk/crossfire/ChangeLog trunk/crossfire/resource/resource/conf/GameObjectMatchers.xml trunk/model/src/app/net/sf/gridarta/model/match/StringAttributeGameObjectMatcher.java Modified: trunk/crossfire/ChangeLog =================================================================== --- trunk/crossfire/ChangeLog 2011-11-12 06:15:34 UTC (rev 9103) +++ trunk/crossfire/ChangeLog 2011-11-12 06:39:32 UTC (rev 9104) @@ -1,3 +1,8 @@ +2011-11-12 Andreas Kirschbaum + + * Add game object matcher 'Messages' that matches game objects + having a non-empty msg..endmsg attribute. + 2011-11-05 Andreas Kirschbaum * Replace "Revert Map" with "Reload Map". Now the current map can Modified: trunk/crossfire/resource/resource/conf/GameObjectMatchers.xml =================================================================== --- trunk/crossfire/resource/resource/conf/GameObjectMatchers.xml 2011-11-12 06:15:34 UTC (rev 9103) +++ trunk/crossfire/resource/resource/conf/GameObjectMatchers.xml 2011-11-12 06:39:32 UTC (rev 9104) @@ -272,4 +272,13 @@ </And> </GameObjectMatcher> + <!-- Objects having a non-empty msg..endmsg field --> + <GameObjectMatcher id="messages"> + <title xml:lang="en">Messages</title> + <title xml:lang="de">Text</title> + <And> + <Attrib name="msg" op="ne" value=""/> + </And> + </GameObjectMatcher> + </GameObjectMatchers> Modified: trunk/model/src/app/net/sf/gridarta/model/match/StringAttributeGameObjectMatcher.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/match/StringAttributeGameObjectMatcher.java 2011-11-12 06:15:34 UTC (rev 9103) +++ trunk/model/src/app/net/sf/gridarta/model/match/StringAttributeGameObjectMatcher.java 2011-11-12 06:39:32 UTC (rev 9104) @@ -73,7 +73,13 @@ */ @Override protected int compareValue(@NotNull final GameObject<?, ?, ?> gameObject) { - final Comparable<String> actual = gameObject.getAttributeString(name, useDefArch); + final Comparable<String> actual; + if (name.equals("msg")) { + final String tmp = gameObject.getMsgText(); + actual = tmp == null ? "" : tmp; + } else { + actual = gameObject.getAttributeString(name, useDefArch); + } return actual.compareTo(value); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2011-11-12 06:46:49
|
Revision: 9105 http://gridarta.svn.sourceforge.net/gridarta/?rev=9105&view=rev Author: akirschbaum Date: 2011-11-12 06:46:42 +0000 (Sat, 12 Nov 2011) Log Message: ----------- Change default keybindings for cursor keys. Modified Paths: -------------- trunk/atrinik/ChangeLog trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/messages.properties trunk/crossfire/ChangeLog trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/messages.properties trunk/daimonin/ChangeLog trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/messages.properties trunk/src/app/net/sf/gridarta/gui/map/mapview/DefaultMapView.java trunk/src/app/net/sf/gridarta/messages.properties trunk/utils/src/app/net/sf/gridarta/utils/ActionUtils.java Modified: trunk/atrinik/ChangeLog =================================================================== --- trunk/atrinik/ChangeLog 2011-11-12 06:39:32 UTC (rev 9104) +++ trunk/atrinik/ChangeLog 2011-11-12 06:46:42 UTC (rev 9105) @@ -1,3 +1,18 @@ +2011-11-12 Andreas Kirschbaum + + * Add default keybindings ALT-LEFT/RIGHT to move the selected game + object to its environment/into the inventory of the previous game + object. + + * Add default keybindings ALT-UP/DOWN to select the previous/next + game object within the map square. + + * Add default keybinding ALT-SHIFT-UP/DOWN to move the selected + game object UP/DOWN within the map square. + + * Change default keybindings for cursor keys to move the map + cursor. + 2011-11-05 Andreas Kirschbaum * Replace "Revert Map" with "Reload Map". Now the current map can Modified: trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/messages.properties =================================================================== --- trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/messages.properties 2011-11-12 06:39:32 UTC (rev 9104) +++ trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/messages.properties 2011-11-12 06:46:42 UTC (rev 9105) @@ -129,12 +129,16 @@ moveCursorNorth.accel=NUMPAD9 moveCursorNorthEast.accel=NUMPAD6 +moveCursorNorthEast.accel2=RIGHT moveCursorEast.accel=NUMPAD3 moveCursorSouthEast.accel=NUMPAD2 +moveCursorSouthEast.accel2=DOWN moveCursorSouth.accel=NUMPAD1 moveCursorSouthWest.accel=NUMPAD4 +moveCursorSouthWest.accel2=LEFT moveCursorWest.accel=NUMPAD7 moveCursorNorthWest.accel=NUMPAD8 +moveCursorNorthWest.accel2=UP ####### Modified: trunk/crossfire/ChangeLog =================================================================== --- trunk/crossfire/ChangeLog 2011-11-12 06:39:32 UTC (rev 9104) +++ trunk/crossfire/ChangeLog 2011-11-12 06:46:42 UTC (rev 9105) @@ -1,5 +1,18 @@ 2011-11-12 Andreas Kirschbaum + * Add default keybindings ALT-LEFT/RIGHT to move the selected game + object to its environment/into the inventory of the previous game + object. + + * Add default keybindings ALT-UP/DOWN to select the previous/next + game object within the map square. + + * Add default keybinding ALT-SHIFT-UP/DOWN to move the selected + game object UP/DOWN within the map square. + + * Change default keybindings for cursor keys to move the map + cursor. + * Add game object matcher 'Messages' that matches game objects having a non-empty msg..endmsg attribute. Modified: trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/messages.properties =================================================================== --- trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/messages.properties 2011-11-12 06:39:32 UTC (rev 9104) +++ trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/messages.properties 2011-11-12 06:46:42 UTC (rev 9105) @@ -119,12 +119,16 @@ # Cursor moveCursorNorth.accel=NUMPAD8 +moveCursorNorth.accel2=UP moveCursorNorthEast.accel=NUMPAD9 moveCursorEast.accel=NUMPAD6 +moveCursorEast.accel2=RIGHT moveCursorSouthEast.accel=NUMPAD3 moveCursorSouth.accel=NUMPAD2 +moveCursorSouth.accel2=DOWN moveCursorSouthWest.accel=NUMPAD1 moveCursorWest.accel=NUMPAD4 +moveCursorWest.accel2=LEFT moveCursorNorthWest.accel=NUMPAD7 Modified: trunk/daimonin/ChangeLog =================================================================== --- trunk/daimonin/ChangeLog 2011-11-12 06:39:32 UTC (rev 9104) +++ trunk/daimonin/ChangeLog 2011-11-12 06:46:42 UTC (rev 9105) @@ -1,3 +1,18 @@ +2011-11-12 Andreas Kirschbaum + + * Add default keybindings ALT-LEFT/RIGHT to move the selected game + object to its environment/into the inventory of the previous game + object. + + * Add default keybindings ALT-UP/DOWN to select the previous/next + game object within the map square. + + * Add default keybinding ALT-SHIFT-UP/DOWN to move the selected + game object UP/DOWN within the map square. + + * Change default keybindings for cursor keys to move the map + cursor. + 2011-11-05 Andreas Kirschbaum * Replace "Revert Map" with "Reload Map". Now the current map can Modified: trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/messages.properties =================================================================== --- trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/messages.properties 2011-11-12 06:39:32 UTC (rev 9104) +++ trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/messages.properties 2011-11-12 06:46:42 UTC (rev 9105) @@ -129,12 +129,16 @@ moveCursorNorth.accel=NUMPAD9 moveCursorNorthEast.accel=NUMPAD6 +moveCursorNorthEast.accel2=RIGHT moveCursorEast.accel=NUMPAD3 moveCursorSouthEast.accel=NUMPAD2 +moveCursorSouthEast.accel2=DOWN moveCursorSouth.accel=NUMPAD1 moveCursorSouthWest.accel=NUMPAD4 +moveCursorSouthWest.accel2=LEFT moveCursorWest.accel=NUMPAD7 moveCursorNorthWest.accel=NUMPAD8 +moveCursorNorthWest.accel2=UP ####### Modified: trunk/src/app/net/sf/gridarta/gui/map/mapview/DefaultMapView.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/mapview/DefaultMapView.java 2011-11-12 06:39:32 UTC (rev 9104) +++ trunk/src/app/net/sf/gridarta/gui/map/mapview/DefaultMapView.java 2011-11-12 06:46:42 UTC (rev 9105) @@ -25,13 +25,17 @@ import java.beans.PropertyVetoException; import java.io.File; import java.util.Set; +import javax.swing.Action; +import javax.swing.JComponent; import javax.swing.JInternalFrame; import javax.swing.JScrollPane; +import javax.swing.KeyStroke; import javax.swing.WindowConstants; import net.sf.gridarta.gui.map.renderer.AbstractMapRenderer; import net.sf.gridarta.gui.map.renderer.MapRenderer; import net.sf.gridarta.gui.utils.MenuUtils; import net.sf.gridarta.model.archetype.Archetype; +import net.sf.gridarta.model.direction.Direction; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.io.PathManager; import net.sf.gridarta.model.maparchobject.MapArchObject; @@ -45,7 +49,10 @@ import net.sf.gridarta.model.mapmodel.MapModelListener; import net.sf.gridarta.model.mapmodel.MapSquare; import net.sf.gridarta.model.validation.ErrorCollector; +import net.sf.gridarta.utils.ActionUtils; import net.sf.gridarta.utils.Size2D; +import net.sf.japi.swing.action.ActionBuilder; +import net.sf.japi.swing.action.ActionBuilderFactory; import org.apache.log4j.Category; import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; @@ -63,6 +70,12 @@ private static final Category log = Logger.getLogger(DefaultMapView.class); /** + * Action Builder to create Actions. + */ + @NotNull + private static final ActionBuilder ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder("net.sf.gridarta"); + + /** * The controller of this view. */ @NotNull @@ -213,9 +226,38 @@ internalFrame.getContentPane().add(mapCursorTracker.getScrollPane(), BorderLayout.CENTER); internalFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); internalFrame.setAutoscrolls(true); + internalFrame.setFocusable(true); + for (final Direction direction : Direction.values()) { + installAccelerator("moveCursor"+direction.getId()); + } + installAccelerator("moveSquarePrev"); + installAccelerator("moveSquareNext"); + installAccelerator("moveSquareUp"); + installAccelerator("moveSquareDown"); + installAccelerator("moveSquareInv"); + installAccelerator("moveSquareEnv"); } /** + * Installs accelerator keys for an action. + * @param key the action's key + */ + private void installAccelerator(@NotNull final String key) { + final Action action = ACTION_BUILDER.getAction(key); + if (action != null) { + final KeyStroke keyStroke1 = ActionUtils.getShortcut(action); + if (keyStroke1 != null) { + internalFrame.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(keyStroke1, key); + } + final KeyStroke keyStroke2 = ActionUtils.getAlternativeShortcut(action); + if (keyStroke2 != null) { + internalFrame.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(keyStroke2, key); + } + internalFrame.getActionMap().put(key, action); + } + } + + /** * {@inheritDoc} */ @Override Modified: trunk/src/app/net/sf/gridarta/messages.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages.properties 2011-11-12 06:39:32 UTC (rev 9104) +++ trunk/src/app/net/sf/gridarta/messages.properties 2011-11-12 06:46:42 UTC (rev 9105) @@ -1577,14 +1577,18 @@ moveSquareTop.shortdescription=Moves the selected game object to top of map square. moveSquareUp.text= moveSquareUp.shortdescription=Moves the selected game object up in map square. +moveSquareUp.accel=alt shift pressed UP moveSquareDown.text= moveSquareDown.shortdescription=Moves the selected game object down in map square. +moveSquareDown.accel=alt shift pressed DOWN moveSquareBottom.text= moveSquareBottom.shortdescription=Moves the selected game object to bottom of map square. moveSquareInv.text= moveSquareInv.shortdescription=Moves the selected game object into the inventory. +moveSquareInv.accel=alt shift pressed RIGHT moveSquareEnv.text= moveSquareEnv.shortdescription=Moves the selected game object to its environment. +moveSquareEnv.accel=alt shift pressed LEFT ############### Modified: trunk/utils/src/app/net/sf/gridarta/utils/ActionUtils.java =================================================================== --- trunk/utils/src/app/net/sf/gridarta/utils/ActionUtils.java 2011-11-12 06:39:32 UTC (rev 9104) +++ trunk/utils/src/app/net/sf/gridarta/utils/ActionUtils.java 2011-11-12 06:46:42 UTC (rev 9105) @@ -130,6 +130,16 @@ } /** + * Returns the alternative shortcut of an {@link Action}. + * @param action the action + * @return the alternative shortcut or <code>null</code> + */ + @Nullable + public static KeyStroke getAlternativeShortcut(@NotNull final Action action) { + return getShortcut(action, ActionBuilder.ACCELERATOR_KEY_2); + } + + /** * Returns the shortcut of an {@link Action}. * @param action the action * @param key the action key to query This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2011-11-12 10:52:18
|
Revision: 9107 http://gridarta.svn.sourceforge.net/gridarta/?rev=9107&view=rev Author: akirschbaum Date: 2011-11-12 10:52:09 +0000 (Sat, 12 Nov 2011) Log Message: ----------- Implement Edit|Find... which searches the current map. Modified Paths: -------------- trunk/atrinik/ChangeLog trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/action.properties trunk/crossfire/ChangeLog trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/action.properties trunk/daimonin/ChangeLog trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/action.properties trunk/src/app/net/sf/gridarta/mainactions/MainActions.java trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java trunk/src/app/net/sf/gridarta/messages.properties trunk/src/app/net/sf/gridarta/messages_de.properties trunk/src/app/net/sf/gridarta/messages_fr.properties trunk/src/app/net/sf/gridarta/messages_sv.properties trunk/utils/src/app/net/sf/gridarta/utils/ActionBuilderUtils.java Added Paths: ----------- trunk/model/src/app/net/sf/gridarta/model/select/AttributeOtherValueMatchCriteria.java trunk/model/src/app/net/sf/gridarta/model/select/AttributeValueMatchCriteria.java trunk/src/app/net/sf/gridarta/gui/dialog/find/ trunk/src/app/net/sf/gridarta/gui/dialog/find/FindDialog.java trunk/src/app/net/sf/gridarta/gui/dialog/find/FindDialogManager.java Modified: trunk/atrinik/ChangeLog =================================================================== --- trunk/atrinik/ChangeLog 2011-11-12 10:49:07 UTC (rev 9106) +++ trunk/atrinik/ChangeLog 2011-11-12 10:52:09 UTC (rev 9107) @@ -1,5 +1,8 @@ 2011-11-12 Andreas Kirschbaum + * Implement Edit|Find... which searches the current map. Relocate + CTRL-F (Fill) to ALT-F. + * Add default keybindings ALT-LEFT/RIGHT to move the selected game object to its environment/into the inventory of the previous game object. Modified: trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/action.properties =================================================================== --- trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/action.properties 2011-11-12 10:49:07 UTC (rev 9106) +++ trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/action.properties 2011-11-12 10:52:09 UTC (rev 9107) @@ -26,7 +26,7 @@ # Menus main.menubar=file edit map archetypes pickmaps resources tools analyze view bookmarks plugins window help file.menu=newMap openFile goMap recent closeMap - saveMap saveMapAs saveAllMaps - closeAllMaps reloadMap createImage - options shortcuts - exit -edit.menu=undo redo - clear cut copy paste pasteTiled - shift - replace fillAuto fillAbove fillBelow randFillAuto randFillAbove randFillBelow floodFill - selectAll invertSelection expandEmptySelection growSelection shrinkSelection +edit.menu=undo redo - clear cut copy paste pasteTiled - shift - find findNext findPrev replace fillAuto fillAbove fillBelow randFillAuto randFillAbove randFillBelow floodFill - selectAll invertSelection expandEmptySelection growSelection shrinkSelection map.menu=autoJoin - enterExit nextExit prevExit enterNorthMap enterEastMap enterSouthMap enterWestMap enterNorthEastMap enterSouthEastMap enterSouthWestMap enterNorthWestMap - mapCreateView mapProperties shrinkMapSize deleteUnknownObjects - gameObjectTextEditor archetypes.menu=displayGameObjectNames displayArchetypeNames displayIconsOnly - findArchetypes #pickmaps.menu: See gridarta @@ -41,7 +41,7 @@ mapwindow.menubar=mapwindowFile mapwindowEdit mapwindowMap mapwindowCursor mapwindowFile.menu=saveMap saveMapAs createImage - reloadMap - closeMap -mapwindowEdit.menu=undo redo - clear cut copy paste pasteTiled - shift - replace fillAuto fillAbove fillBelow randFillAuto randFillAbove randFillBelow floodFill - selectAll invertSelection expandEmptySelection growSelection shrinkSelection +mapwindowEdit.menu=undo redo - clear cut copy paste pasteTiled - shift - find findNext findPrev replace fillAuto fillAbove fillBelow randFillAuto randFillAbove randFillBelow floodFill - selectAll invertSelection expandEmptySelection growSelection shrinkSelection mapwindowMap.menu=gridVisible - goExit enterExit nextExit prevExit enterNorthMap enterEastMap enterSouthMap enterWestMap enterNorthEastMap enterSouthEastMap enterSouthWestMap enterNorthWestMap - mapCreateView mapProperties shrinkMapSize deleteUnknownObjects mapwindowCursor.menu=moveCursor - exitConnector - selectSquare startStopDrag addToSelection subFromSelection releaseDrag - insertArch deleteArch - selectArchAbove selectArchBelow - archAttributes Modified: trunk/crossfire/ChangeLog =================================================================== --- trunk/crossfire/ChangeLog 2011-11-12 10:49:07 UTC (rev 9106) +++ trunk/crossfire/ChangeLog 2011-11-12 10:52:09 UTC (rev 9107) @@ -1,5 +1,8 @@ 2011-11-12 Andreas Kirschbaum + * Implement Edit|Find... which searches the current map. Relocate + CTRL-F (Fill) to ALT-F. + * Add default keybindings ALT-LEFT/RIGHT to move the selected game object to its environment/into the inventory of the previous game object. Modified: trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/action.properties =================================================================== --- trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/action.properties 2011-11-12 10:49:07 UTC (rev 9106) +++ trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/action.properties 2011-11-12 10:52:09 UTC (rev 9107) @@ -26,7 +26,7 @@ # Menus main.menubar=file edit map archetypes pickmaps resources tools analyze view bookmarks plugins window help file.menu=newMap openFile goMap recent closeMap - saveMap saveMapAs saveAllMaps - closeAllMaps reloadMap createImage - options shortcuts - exit -edit.menu=undo redo - clear cut copy paste pasteTiled - shift - replace fillAuto fillAbove fillBelow randFillAuto randFillAbove randFillBelow floodFill - selectAll invertSelection expandEmptySelection growSelection shrinkSelection +edit.menu=undo redo - clear cut copy paste pasteTiled - shift - find findNext findPrev replace fillAuto fillAbove fillBelow randFillAuto randFillAbove randFillBelow floodFill - selectAll invertSelection expandEmptySelection growSelection shrinkSelection map.menu=autoJoin - enterExit nextExit prevExit enterNorthMap enterEastMap enterSouthMap enterWestMap tileShow - mapCreateView mapProperties shrinkMapSize deleteUnknownObjects - gameObjectTextEditor archetypes.menu=displayGameObjectNames displayArchetypeNames displayIconsOnly - findArchetypes #pickmaps.menu: See gridarta @@ -41,7 +41,7 @@ mapwindow.menubar=mapwindowFile mapwindowEdit mapwindowMap mapwindowCursor mapwindowFile.menu=saveMap saveMapAs createImage - reloadMap - closeMap -mapwindowEdit.menu=undo redo - clear cut copy paste pasteTiled - shift - replace fillAuto fillAbove fillBelow randFillAuto randFillAbove randFillBelow floodFill - selectAll invertSelection expandEmptySelection growSelection shrinkSelection +mapwindowEdit.menu=undo redo - clear cut copy paste pasteTiled - shift - find findNext findPrev replace fillAuto fillAbove fillBelow randFillAuto randFillAbove randFillBelow floodFill - selectAll invertSelection expandEmptySelection growSelection shrinkSelection mapwindowMap.menu=gridVisible smoothing - goExit enterExit nextExit prevExit enterNorthMap enterEastMap enterSouthMap enterWestMap tileShow - mapCreateView mapProperties shrinkMapSize deleteUnknownObjects mapwindowCursor.menu=moveCursor - exitConnector - selectSquare startStopDrag addToSelection subFromSelection releaseDrag - insertArch deleteArch - selectArchAbove selectArchBelow - archAttributes Modified: trunk/daimonin/ChangeLog =================================================================== --- trunk/daimonin/ChangeLog 2011-11-12 10:49:07 UTC (rev 9106) +++ trunk/daimonin/ChangeLog 2011-11-12 10:52:09 UTC (rev 9107) @@ -1,5 +1,8 @@ 2011-11-12 Andreas Kirschbaum + * Implement Edit|Find... which searches the current map. Relocate + CTRL-F (Fill) to ALT-F. + * Add default keybindings ALT-LEFT/RIGHT to move the selected game object to its environment/into the inventory of the previous game object. Modified: trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/action.properties =================================================================== --- trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/action.properties 2011-11-12 10:49:07 UTC (rev 9106) +++ trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/action.properties 2011-11-12 10:52:09 UTC (rev 9107) @@ -26,7 +26,7 @@ # Menus main.menubar=file edit map archetypes pickmaps resources tools analyze view bookmarks plugins window help file.menu=newMap openFile goMap recent closeMap - saveMap saveMapAs saveAllMaps - closeAllMaps reloadMap createImage - options shortcuts - exit -edit.menu=undo redo - clear cut copy paste pasteTiled - shift - replace fillAuto fillAbove fillBelow randFillAuto randFillAbove randFillBelow floodFill - selectAll invertSelection expandEmptySelection growSelection shrinkSelection +edit.menu=undo redo - clear cut copy paste pasteTiled - shift - find findNext findPrev replace fillAuto fillAbove fillBelow randFillAuto randFillAbove randFillBelow floodFill - selectAll invertSelection expandEmptySelection growSelection shrinkSelection map.menu=autoJoin - enterExit nextExit prevExit enterNorthMap enterEastMap enterSouthMap enterWestMap enterNorthEastMap enterSouthEastMap enterSouthWestMap enterNorthWestMap - mapCreateView mapProperties shrinkMapSize deleteUnknownObjects - gameObjectTextEditor archetypes.menu=displayGameObjectNames displayArchetypeNames displayIconsOnly - findArchetypes #pickmaps.menu: See gridarta @@ -41,7 +41,7 @@ mapwindow.menubar=mapwindowFile mapwindowEdit mapwindowMap mapwindowCursor mapwindowFile.menu=saveMap saveMapAs createImage - reloadMap - closeMap -mapwindowEdit.menu=undo redo - clear cut copy paste pasteTiled - shift - replace fillAuto fillAbove fillBelow randFillAuto randFillAbove randFillBelow floodFill - selectAll invertSelection expandEmptySelection growSelection shrinkSelection +mapwindowEdit.menu=undo redo - clear cut copy paste pasteTiled - shift - find findNext findPrev replace fillAuto fillAbove fillBelow randFillAuto randFillAbove randFillBelow floodFill - selectAll invertSelection expandEmptySelection growSelection shrinkSelection mapwindowMap.menu=gridVisible - goExit enterExit nextExit prevExit enterNorthMap enterEastMap enterSouthMap enterWestMap enterNorthEastMap enterSouthEastMap enterSouthWestMap enterNorthWestMap - mapCreateView mapProperties shrinkMapSize deleteUnknownObjects mapwindowCursor.menu=moveCursor - exitConnector - selectSquare startStopDrag addToSelection subFromSelection releaseDrag - insertArch deleteArch - selectArchAbove selectArchBelow - archAttributes Added: trunk/model/src/app/net/sf/gridarta/model/select/AttributeOtherValueMatchCriteria.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/select/AttributeOtherValueMatchCriteria.java (rev 0) +++ trunk/model/src/app/net/sf/gridarta/model/select/AttributeOtherValueMatchCriteria.java 2011-11-12 10:52:09 UTC (rev 9107) @@ -0,0 +1,77 @@ +/* + * 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.model.select; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; +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.utils.StringUtils; +import org.jetbrains.annotations.NotNull; + +/** + * A {@link MatchCriteria} that matches attribute values of all but a set of + * attributes. + * @author Andreas Kirschbaum + */ +public class AttributeOtherValueMatchCriteria<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements MatchCriteria<G, A, R> { + + /** + * The attribute names <em>not</em> to check. + */ + @NotNull + private final Set<String> attributeNames; + + /** + * The attribute value to check. + */ + @NotNull + private final String attributeValue; + + /** + * Creates a new instance. + * @param attributeValue the attribute value to check + * @param attributeNames the attribute names <em>not</em> to check + */ + public AttributeOtherValueMatchCriteria(@NotNull final String attributeValue, @NotNull final String... attributeNames) { + this.attributeValue = attributeValue; + this.attributeNames = new HashSet<String>(Arrays.asList(attributeNames)); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean matches(@NotNull final G gameObject) { + for (final String attribute : StringUtils.PATTERN_END_OF_LINE.split(gameObject.getObjectText())) { + final String[] tmp = StringUtils.PATTERN_SPACES.split(attribute, 2); + if (tmp.length == 2 && !attributeNames.contains(tmp[0])) { + if (tmp[1].contains(attributeValue)) { + return true; + } + } + } + + return false; + } + +} Property changes on: trunk/model/src/app/net/sf/gridarta/model/select/AttributeOtherValueMatchCriteria.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Added: trunk/model/src/app/net/sf/gridarta/model/select/AttributeValueMatchCriteria.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/select/AttributeValueMatchCriteria.java (rev 0) +++ trunk/model/src/app/net/sf/gridarta/model/select/AttributeValueMatchCriteria.java 2011-11-12 10:52:09 UTC (rev 9107) @@ -0,0 +1,63 @@ +/* + * 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.model.select; + +import net.sf.gridarta.model.archetype.Archetype; +import net.sf.gridarta.model.gameobject.GameObject; +import net.sf.gridarta.model.maparchobject.MapArchObject; +import org.jetbrains.annotations.NotNull; + +/** + * A {@link MatchCriteria} that matches an attribute value. + * @author Andreas Kirschbaum + */ +public class AttributeValueMatchCriteria<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements MatchCriteria<G, A, R> { + + /** + * The attribute name to check. + */ + @NotNull + private final String attributeName; + + /** + * The attribute value to check. + */ + @NotNull + private final String attributeValue; + + /** + * Creates a new instance. + * @param attributeName the attribute name to check + * @param attributeValue the attribute value to check + */ + public AttributeValueMatchCriteria(@NotNull final String attributeName, @NotNull final String attributeValue) { + this.attributeName = attributeName; + this.attributeValue = attributeValue; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean matches(@NotNull final G gameObject) { + return gameObject.getAttributeString(attributeName).contains(attributeValue); + } + +} Property changes on: trunk/model/src/app/net/sf/gridarta/model/select/AttributeValueMatchCriteria.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Added: trunk/src/app/net/sf/gridarta/gui/dialog/find/FindDialog.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/dialog/find/FindDialog.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gui/dialog/find/FindDialog.java 2011-11-12 10:52:09 UTC (rev 9107) @@ -0,0 +1,373 @@ +/* + * 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.gui.dialog.find; + +import java.awt.Component; +import java.awt.Container; +import java.awt.FlowLayout; +import java.awt.Point; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import javax.swing.AbstractButton; +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComponent; +import javax.swing.JDialog; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.WindowConstants; +import javax.swing.text.JTextComponent; +import net.sf.gridarta.gui.map.mapview.MapView; +import net.sf.gridarta.gui.utils.TextComponentUtils; +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.mapcontrol.MapControl; +import net.sf.gridarta.model.mapcursor.MapCursor; +import net.sf.gridarta.model.mapgrid.MapGrid; +import net.sf.gridarta.model.mapgrid.SelectionMode; +import net.sf.gridarta.model.mapmodel.MapModel; +import net.sf.gridarta.model.mapmodel.MapSquare; +import net.sf.gridarta.model.select.ArchetypeNameMatchCriteria; +import net.sf.gridarta.model.select.AttributeOtherValueMatchCriteria; +import net.sf.gridarta.model.select.AttributeValueMatchCriteria; +import net.sf.gridarta.model.select.MatchCriteria; +import net.sf.gridarta.model.select.ObjectNameMatchCriteria; +import net.sf.gridarta.utils.ActionBuilderUtils; +import net.sf.japi.swing.action.ActionBuilder; +import net.sf.japi.swing.action.ActionBuilderFactory; +import net.sf.japi.swing.action.ActionMethod; +import org.jetbrains.annotations.NotNull; + +/** + * This dialog manages the find action. + * @author Andreas Kirschbaum + */ +public class FindDialog<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends JOptionPane { + + /** + * Serial Version UID. + */ + private static final long serialVersionUID = 1L; + + /** + * Action Builder. + */ + @NotNull + private static final ActionBuilder ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder("net.sf.gridarta"); + + /** + * The dialog instance. + */ + @NotNull + private final JDialog dialog; + + /** + * The parent component for dialogs. + */ + @NotNull + private final Component parent; + + /** + * Whether this find dialog has been displayed. + */ + private boolean isBuilt = false; + + /** + * The {@link MapView} to operate on. + */ + @NotNull + private MapView<G, A, R> mapView; + + /** + * The text input field for the string to find. + */ + @NotNull + private final JTextComponent findInput = new JTextField(20); + + /** + * The checkbox for matching 'name' attributes. + */ + @NotNull + private final AbstractButton findNameCheckbox = new JCheckBox(ActionBuilderUtils.getString(ACTION_BUILDER, "findWhereName")); + + /** + * The checkbox for matching archetype names. + */ + @NotNull + private final AbstractButton findArchCheckbox = new JCheckBox(ActionBuilderUtils.getString(ACTION_BUILDER, "findWhereArch")); + + /** + * The checkbox for matching 'msg' attributes. + */ + @NotNull + private final AbstractButton findMsgCheckbox = new JCheckBox(ActionBuilderUtils.getString(ACTION_BUILDER, "findWhereMsg")); + + /** + * The checkbox for matching 'face' or 'animation' attributes. + */ + @NotNull + private final AbstractButton findFaceCheckbox = new JCheckBox(ActionBuilderUtils.getString(ACTION_BUILDER, "findWhereFace")); + + /** + * The checkbox for matching 'slaying' attributes. + */ + @NotNull + private final AbstractButton findSlayingCheckbox = new JCheckBox(ActionBuilderUtils.getString(ACTION_BUILDER, "findWhereSlaying")); + + /** + * The checkbox for matching all other attributes. + */ + @NotNull + private final AbstractButton findOtherCheckbox = new JCheckBox(ActionBuilderUtils.getString(ACTION_BUILDER, "findWhereOther")); + + /** + * Creates a new instance. + * @param parent the parent component for dialogs + */ + public FindDialog(@NotNull final Component parent) { + dialog = createDialog(parent, ""); + dialog.setModal(false); + dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); + this.parent = parent; + + TextComponentUtils.setAutoSelectOnFocus(findInput); + } + + /** + * Replace objects on the map. + * @param mapView map view of the active map where the action was invoked + */ + public void display(@NotNull final MapView<G, A, R> mapView) { + if (isBuilt) { + this.mapView = mapView; + + dialog.pack(); + dialog.toFront(); + } else { + this.mapView = mapView; + final JPanel mainPanel = new JPanel(); + mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); + mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 2, 5)); + + final Container lineFind = new JPanel(new FlowLayout(FlowLayout.LEFT)); + final JComponent labelFind = ActionBuilderUtils.newLabel(ACTION_BUILDER, "findFind"); + labelFind.setToolTipText(ActionBuilderUtils.getString(ACTION_BUILDER, "findFind.shortdescription")); + lineFind.add(labelFind); + lineFind.add(Box.createVerticalStrut(3)); + lineFind.add(findInput); + lineFind.add(Box.createVerticalStrut(3)); + mainPanel.add(lineFind); + + final Container lineWhere = new JPanel(new FlowLayout(FlowLayout.LEFT)); + final JComponent labelWhere = ActionBuilderUtils.newLabel(ACTION_BUILDER, "findWhere"); + labelWhere.setToolTipText(ActionBuilderUtils.getString(ACTION_BUILDER, "findWhere.shortdescription")); + lineWhere.add(labelWhere); + lineWhere.add(Box.createVerticalStrut(5)); + + final JPanel panelWhere = new JPanel(); + panelWhere.setLayout(new BoxLayout(panelWhere, BoxLayout.Y_AXIS)); + panelWhere.add(findNameCheckbox); + panelWhere.add(findArchCheckbox); + panelWhere.add(findMsgCheckbox); + panelWhere.add(findFaceCheckbox); + panelWhere.add(findSlayingCheckbox); + panelWhere.add(findOtherCheckbox); + lineWhere.add(panelWhere); + mainPanel.add(lineWhere); + + final JButton okButton = new JButton(ACTION_BUILDER.createAction(false, "findOk", this)); + final JButton cancelButton = new JButton(ACTION_BUILDER.createAction(false, "findCancel", this)); + + findNameCheckbox.setSelected(true); + findMsgCheckbox.setSelected(true); + findSlayingCheckbox.setSelected(true); + + setMessage(mainPanel); + setOptions(new Object[] { okButton, cancelButton }); + dialog.getRootPane().setDefaultButton(okButton); + dialog.pack(); + dialog.setLocationRelativeTo(parent); + + isBuilt = true; + } + dialog.setTitle(ActionBuilderUtils.format(ACTION_BUILDER, "findTitle", mapView.getMapControl().getMapModel().getMapArchObject().getMapName())); + dialog.setVisible(true); + findInput.requestFocusInWindow(); + } + + /** + * Re-executes the previous find operation. + * @param mapView the map view to operate on + * @param forward whether to search forward (<code>true</code>) or backward + * (<code>false</code>) + * @param performAction whether the action should be performed + * @return whether the action was or can be performed + */ + public boolean findAgain(@NotNull final MapView<G, A, R> mapView, final boolean forward, final boolean performAction) { + if (this.mapView != mapView) { + return false; + } + if (performAction) { + doFind(forward); + } + return true; + } + + /** + * Action method for Ok button. + */ + @ActionMethod + public void findOk() { + if (doFind(true)) { + dialog.setVisible(false); + } + } + + /** + * Action method for Cancel button. + */ + @ActionMethod + public void findCancel() { + dialog.setVisible(false); + } + + /** + * Executes one find operation. + * @param forward whether to search forward (<code>true</code>) or backward + * (<code>false</code>) + * @return whether the find operation was successful + */ + private boolean doFind(final boolean forward) { + final String findString = findInput.getText().trim(); + final Collection<MatchCriteria<G, A, R>> matchCriterias = new ArrayList<MatchCriteria<G, A, R>>(); + if (findNameCheckbox.isSelected()) { + matchCriterias.add(new ObjectNameMatchCriteria<G, A, R>(findString)); + } + if (findArchCheckbox.isSelected()) { + matchCriterias.add(new ArchetypeNameMatchCriteria<G, A, R>(findString)); + } + if (findMsgCheckbox.isSelected()) { + matchCriterias.add(new AttributeValueMatchCriteria<G, A, R>("msg", findString)); + } + if (findFaceCheckbox.isSelected()) { + matchCriterias.add(new AttributeValueMatchCriteria<G, A, R>("face", findString)); + matchCriterias.add(new AttributeValueMatchCriteria<G, A, R>("animation", findString)); + } + if (findSlayingCheckbox.isSelected()) { + matchCriterias.add(new AttributeValueMatchCriteria<G, A, R>("slaying", findString)); + } + if (findOtherCheckbox.isSelected()) { + matchCriterias.add(new AttributeOtherValueMatchCriteria<G, A, R>(findString, "msg", "face", "animation", "slaying")); + } + return !matchCriterias.isEmpty() && doFind(matchCriterias, forward) > 0; + } + + /** + * This method performs the actual find action on a map. + * @param matchCriterias the matching criterias to find + * @param forward whether to search forward (<code>true</code>) or backward + * (<code>false</code>) + * @return the number of objects found + */ + private int doFind(@NotNull final Iterable<MatchCriteria<G, A, R>> matchCriterias, final boolean forward) { + final List<G> matchingGameObjects = new ArrayList<G>(); + final Collection<MapSquare<G, A, R>> matchingMapSquares = new ArrayList<MapSquare<G, A, R>>(); + final MapControl<G, A, R> mapControl = mapView.getMapControl(); + final MapModel<G, A, R> mapModel = mapControl.getMapModel(); + for (final MapSquare<G, A, R> mapSquare : mapModel) { + boolean matchesMapSquare = false; + for (final G gameObject : mapSquare.recursive()) { + for (final MatchCriteria<G, A, R> matchCriteria : matchCriterias) { + if (matchCriteria.matches(gameObject)) { + matchingGameObjects.add(gameObject); + matchesMapSquare = true; + } + } + } + if (matchesMapSquare) { + matchingMapSquares.add(mapSquare); + } + } + selectMapSquares(matchingMapSquares); + setMapCursor(forward, matchingGameObjects); + return matchingGameObjects.size(); + } + + /** + * Selects a set of {@link MapSquare MapSquares} on the map. + * @param mapSquares the map squares to select + */ + private void selectMapSquares(@NotNull final Iterable<MapSquare<G, A, R>> mapSquares) { + final MapGrid mapGrid = mapView.getMapGrid(); + mapGrid.unSelect(); + final Point p = new Point(); + for (final MapSquare<G, A, R> mapSquare : mapSquares) { + p.x = mapSquare.getMapX(); + p.y = mapSquare.getMapY(); + mapGrid.select(p, SelectionMode.ADD); + } + } + + /** + * Moves the cursor to the next or previous matching game object. + * @param forward whether to move the cursor forward (<code>true</code>) or + * backward (<code>false</code>) + * @param gameObjects the game objects to consider + */ + private void setMapCursor(final boolean forward, @NotNull final List<G> gameObjects) { + if (gameObjects.isEmpty()) { + return; + } + + final MapCursor<G, A, R> mapCursor = mapView.getMapCursor(); + final int index; + final G selectedGameObject = mapCursor.getGameObject(); + if (selectedGameObject == null) { + index = 0; + } else { + final int selectedIndex = gameObjects.indexOf(selectedGameObject); + if (selectedIndex == -1) { + index = 0; + } else if (forward) { + index = selectedIndex + 1 < gameObjects.size() ? selectedIndex + 1 : 0; + } else { + index = selectedIndex > 0 ? selectedIndex - 1 : gameObjects.size() - 1; + } + } + mapCursor.setGameObject(gameObjects.get(index)); + } + + /** + * Disposes the find dialog. + * @param mapView the map view to dispose the dialog of; do nothing if no + */ + public void dispose(@NotNull final MapView<G, A, R> mapView) { + if (mapView == this.mapView) { + dialog.setVisible(false); + } + } + +} // class ReplaceDialog Property changes on: trunk/src/app/net/sf/gridarta/gui/dialog/find/FindDialog.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Added: trunk/src/app/net/sf/gridarta/gui/dialog/find/FindDialogManager.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/dialog/find/FindDialogManager.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gui/dialog/find/FindDialogManager.java 2011-11-12 10:52:09 UTC (rev 9107) @@ -0,0 +1,124 @@ +/* + * 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.gui.dialog.find; + +import java.awt.Component; +import net.sf.gridarta.gui.map.mapview.MapView; +import net.sf.gridarta.gui.map.mapview.MapViewManager; +import net.sf.gridarta.gui.map.mapview.MapViewManagerListener; +import net.sf.gridarta.model.archetype.Archetype; +import net.sf.gridarta.model.gameobject.GameObject; +import net.sf.gridarta.model.maparchobject.MapArchObject; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Creates and displays the find dialog. + * @author Andreas Kirschbaum + */ +public class FindDialogManager<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> { + + /** + * Singleton Instance. + */ + @Nullable + private FindDialog<G, A, R> instance = null; + + /** + * The parent component for dialogs. + */ + @NotNull + private final Component parent; + + /** + * Creates a new instance. + * @param parent the parent component for dialogs + * @param mapViewManager the map view manager to use + */ + public FindDialogManager(@NotNull final Component parent, @NotNull final MapViewManager<G, A, R> mapViewManager) { + this.parent = parent; + + final MapViewManagerListener<G, A, R> mapViewManagerListener = new MapViewManagerListener<G, A, R>() { + + /** {@inheritDoc} */ + @Override + public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) { + // ignore + } + + /** {@inheritDoc} */ + @Override + public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) { + // ignore + } + + /** {@inheritDoc} */ + @Override + public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) { + disposeDialog(mapView); + } + + }; + mapViewManager.addMapViewManagerListener(mapViewManagerListener); + } + + /** + * Dispose the replace dialog. + * @param mapView the map view to dispose the dialog of; do nothing if no + * dialog exists + */ + private void disposeDialog(@NotNull final MapView<G, A, R> mapView) { + if (instance != null) { + instance.dispose(mapView); + } + } + + /** + * Displays the replace dialog. + * @param mapView the map view to operate on + */ + public void showDialog(@NotNull final MapView<G, A, R> mapView) { + if (instance == null) { + instance = new FindDialog<G, A, R>(parent); + } + instance.display(mapView); + } + + /** + * Executes the "find next" action. + * @param mapView the map view to operate on + * @param performAction whether the action should be performed + * @return whether the action was or can be performed + */ + public boolean findNext(@NotNull final MapView<G, A, R> mapView, final boolean performAction) { + return instance != null && instance.findAgain(mapView, true, performAction); + } + + /** + * Executes the "find next" action. + * @param mapView the map view to operate on + * @param performAction whether the action should be performed + * @return whether the action was or can be performed + */ + public boolean findPrev(@NotNull final MapView<G, A, R> mapView, final boolean performAction) { + return instance != null && instance.findAgain(mapView, false, performAction); + } + +} // class ReplaceDialogManager Property changes on: trunk/src/app/net/sf/gridarta/gui/dialog/find/FindDialogManager.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Modified: trunk/src/app/net/sf/gridarta/mainactions/MainActions.java =================================================================== --- trunk/src/app/net/sf/gridarta/mainactions/MainActions.java 2011-11-12 10:49:07 UTC (rev 9106) +++ trunk/src/app/net/sf/gridarta/mainactions/MainActions.java 2011-11-12 10:52:09 UTC (rev 9107) @@ -31,6 +31,7 @@ import javax.swing.JFrame; import net.sf.gridarta.commands.Collector; import net.sf.gridarta.gui.copybuffer.CopyBuffer; +import net.sf.gridarta.gui.dialog.find.FindDialogManager; import net.sf.gridarta.gui.dialog.replace.ReplaceDialogManager; import net.sf.gridarta.gui.map.mapview.MapView; import net.sf.gridarta.gui.map.mapview.MapViewManager; @@ -98,6 +99,12 @@ private static final Category log = Logger.getLogger(MainActions.class); /** + * The find dialog manager to use. + */ + @NotNull + private final FindDialogManager<G, A, R> findDialogManager; + + /** * The replace dialog manager to use. */ @NotNull @@ -242,6 +249,24 @@ private final Action aPasteTiled; /** + * Action called for "find". + */ + @NotNull + private final Action aFind; + + /** + * Action called for "find next". + */ + @NotNull + private final Action aFindNext; + + /** + * Action called for "find prev". + */ + @NotNull + private final Action aFindPrev; + + /** * Action called for "replace". */ @NotNull @@ -409,6 +434,7 @@ /** * Create a new instance. + * @param findDialogManager the find dialog manager to use * @param replaceDialogManager the replace dialog manager to use * @param parent the parent component for dialog windows * @param globalSettings the global settings instance @@ -425,7 +451,8 @@ * @param insertionModeSet the insertion mode set to use * @param exiter the exiter instance */ - public MainActions(@NotNull final ReplaceDialogManager<G, A, R> replaceDialogManager, @NotNull final JFrame parent, @NotNull final GlobalSettings globalSettings, @NotNull final DelegatingMapValidator<G, A, R> validators, @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 MapViewManager<G, A, R> mapViewManager, @NotNull final AbstractResources<G, A, R> resources, @NotNull final FaceObjectProviders faceObjectProviders, @NotNull final InsertionModeSet<G, A, R> insertionModeSet, @NotNull final Exiter exiter) { + public MainActions(@NotNull final FindDialogManager<G, A, R> findDialogManager, @NotNull final ReplaceDialogManager<G, A, R> replaceDialogManager, @NotNull final JFrame parent, @NotNull final GlobalSettings globalSettings, @NotNull final DelegatingMapValidator<G, A, R> validators, @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 MapViewManager<G, A, R> mapViewManager, @NotNull final AbstractResources<G, A, R> resources, @NotNull final FaceObjectProviders faceObjectProviders, @NotNull final InsertionModeSet<G, A, R> insertionModeSet, @NotNull final Exiter exiter) { + this.findDialogManager = findDialogManager; this.replaceDialogManager = replaceDialogManager; this.parent = parent; this.globalSettings = globalSettings; @@ -450,6 +477,9 @@ aShiftSouthWest = ActionUtils.newAction(ACTION_BUILDER, "Map/Shift", this, "shiftSouthWest"); aShiftWest = ActionUtils.newAction(ACTION_BUILDER, "Map/Shift", this, "shiftWest"); aShiftNorthWest = ActionUtils.newAction(ACTION_BUILDER, "Map/Shift", this, "shiftNorthWest"); + aFind = ActionUtils.newAction(ACTION_BUILDER, "Map", this, "find"); + aFindNext = ActionUtils.newAction(ACTION_BUILDER, "Map", this, "findNext"); + aFindPrev = ActionUtils.newAction(ACTION_BUILDER, "Map", this, "findPrev"); aReplace = ActionUtils.newAction(ACTION_BUILDER, "Map", this, "replace"); aFillAuto = ActionUtils.newAction(ACTION_BUILDER, "Map/Fill", this, "fillAuto"); aFillAbove = ActionUtils.newAction(ACTION_BUILDER, "Map/Fill", this, "fillAbove"); @@ -681,6 +711,9 @@ aShiftSouthWest.setEnabled(doShift(false, Direction.SOUTH_WEST)); aShiftWest.setEnabled(doShift(false, Direction.WEST)); aShiftNorthWest.setEnabled(doShift(false, Direction.NORTH_WEST)); + aFind.setEnabled(doFind(false)); + aFindNext.setEnabled(doFindNext(false)); + aFindPrev.setEnabled(doFindPrev(false)); aReplace.setEnabled(doReplace(false)); aFillAuto.setEnabled(doFillAuto(false)); aFillAbove.setEnabled(doFillAbove(false)); @@ -804,6 +837,30 @@ } /** + * "Find" was selected from the Edit menu. + */ + @ActionMethod + public void find() { + doFind(true); + } + + /** + * "Find next" was selected from the Edit menu. + */ + @ActionMethod + public void findNext() { + doFindNext(true); + } + + /** + * "Find previous" was selected from the Edit menu. + */ + @ActionMethod + public void findPrev() { + doFindPrev(true); + } + + /** * "Replace" was selected from the Edit menu. */ @ActionMethod @@ -943,6 +1000,44 @@ } /** + * Executes the "find" action. + * @param performAction whether the action should be performed + * @return whether the action was or can be performed + */ + private boolean doFind(final boolean performAction) { + final MapView<G, A, R> mapView = currentMapView; + if (mapView == null) { + return false; + } + + if (performAction) { + findDialogManager.showDialog(mapView); + } + + return true; + } + + /** + * Executes the "find next" action. + * @param performAction whether the action should be performed + * @return whether the action was or can be performed + */ + private boolean doFindNext(final boolean performAction) { + final MapView<G, A, R> mapView = currentMapView; + return mapView != null && findDialogManager.findNext(mapView, performAction); + } + + /** + * Executes the "find prev" action. + * @param performAction whether the action should be performed + * @return whether the action was or can be performed + */ + private boolean doFindPrev(final boolean performAction) { + final MapView<G, A, R> mapView = currentMapView; + return mapView != null && findDialogManager.findPrev(mapView, performAction); + } + + /** * Executes the "replace" action. * @param performAction whether the action should be performed * @return whether the action was or can be performed Modified: trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java 2011-11-12 10:49:07 UTC (rev 9106) +++ trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java 2011-11-12 10:52:09 UTC (rev 9107) @@ -39,6 +39,7 @@ import net.sf.gridarta.gui.copybuffer.CopyBuffer; import net.sf.gridarta.gui.delayedmapmodel.DelayedMapModelListenerManager; import net.sf.gridarta.gui.dialog.bookmarks.BookmarkActions; +import net.sf.gridarta.gui.dialog.find.FindDialogManager; import net.sf.gridarta.gui.dialog.findarchetypes.FindArchetypesDialogManager; import net.sf.gridarta.gui.dialog.gameobjectattributes.GameObjectAttributesDialogFactory; import net.sf.gridarta.gui.dialog.goexit.GoExitDialogManager; @@ -474,6 +475,7 @@ final GameObjectMatcher systemObjectMatcher = gameObjectMatchers.getMatcher("system_system_object"); final InsertionModeSet<G, A, R> insertionModeSet = new InsertionModeSet<G, A, R>(topmostInsertionMode, floorMatcher, wallMatcher, belowFloorMatcher, systemObjectMatcher); final CopyBuffer<G, A, R> copyBuffer = new CopyBuffer<G, A, R>(mapViewSettings, gameObjectFactory, mapArchObjectFactory, mapModelFactory, insertionModeSet); + final FindDialogManager<G, A, R> findDialogManager = new FindDialogManager<G, A, R>(mainViewFrame, mapViewManager); final ReplaceDialogManager<G, A, R> replaceDialogManager = new ReplaceDialogManager<G, A, R>(mainViewFrame, copyBuffer, objectChooser, mapViewManager, faceObjectProviders, insertionModeSet); exiter = new DefaultExiter(mainViewFrame); scriptEditControl = new ScriptEditControl(scriptFileFilter, scriptExtension, mainViewFrame, globalSettings.getMapsDirectory(), preferences, exiter); @@ -519,7 +521,7 @@ //noinspection ResultOfObjectAllocationIgnored new MapFileActions<G, A, R>(imageCreator2, mapManager, mapViewsManager, mapViewManager, fileControl, mainViewFrame); //noinspection ResultOfObjectAllocationIgnored - new MainActions<G, A, R>(replaceDialogManager, mainViewFrame, globalSettings, validators, mapViewSettings, archetypeSet, copyBuffer, objectChooser, mapManager, mapViewManager, resources, faceObjectProviders, insertionModeSet, exiter); + new MainActions<G, A, R>(findDialogManager, replaceDialogManager, mainViewFrame, globalSettings, validators, mapViewSettings, archetypeSet, copyBuffer, objectChooser, mapManager, mapViewManager, resources, faceObjectProviders, insertionModeSet, exiter); final HelpActions helpActions = new HelpActions(mainViewFrame); ActionUtils.newActions(ACTION_BUILDER, "Map", newMapDialogFactory, "newMap"); final GoMapDialogManager<G, A, R> goMapDialogManager = new GoMapDialogManager<G, A, R>(mainViewFrame, mapManager, mapViewsManager, globalSettings, exiter); Modified: trunk/src/app/net/sf/gridarta/messages.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages.properties 2011-11-12 10:49:07 UTC (rev 9106) +++ trunk/src/app/net/sf/gridarta/messages.properties 2011-11-12 10:52:09 UTC (rev 9107) @@ -570,6 +570,21 @@ mapOkay.text=Ok mapCancel.text=Cancel +#find dialog +findTitle=Find on {0} +findFind=Find: +findFind.shortdescription=<html>Selects the text to find. +findWhere=Where: +findWhere.shortdescription=<html>Selects the categories to search. +findWhereName='name' attribute +findWhereArch=archetype name +findWhereMsg='msg' attribute +findWhereFace='face' or 'animation' attribute +findWhereSlaying='slaying' attribute +findWhereOther=any other attribute +findOk.text=OK +findCancel.text=Cancel + #replace replaceTitle=Replace replaceOn=On @@ -782,16 +797,28 @@ shiftNorthWest.text=Shift Northwest shiftNorthWest.shortdescription=Shifts the selected squares north west. +find.text=Find +find.shortdescription=Opens the find dialog. +find.accel=ctrl pressed F + +findNext.text=Find Next +findNext.shortdescription=Repeats the previous find operation. +findNext.accel=pressed F3 + +findPrev.text=Find Previous +findPrev.shortdescription=Repeats the previous find operation. +findPrev.accel=shift pressed F3 + replace.text=Replace replace.mnemonic=R replace.shortdescription=Opens the replace dialog. replace.accel=ctrl pressed R fillAuto.text=Fill -fillAuto.mnemonic=F +fillAuto.mnemonic=alt pressed F fillAuto.shortdescription=Fills the selected squares. fillAuto.longdescription=Fills the selected squares. Existing floor game objects are replaced when filled with other floor game objects. -fillAuto.accel=ctrl pressed F +fillAuto.accel=ctrl shift pressed F fillAbove.text=Fill Above fillAbove.mnemonic=A Modified: trunk/src/app/net/sf/gridarta/messages_de.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages_de.properties 2011-11-12 10:49:07 UTC (rev 9106) +++ trunk/src/app/net/sf/gridarta/messages_de.properties 2011-11-12 10:52:09 UTC (rev 9107) @@ -545,6 +545,21 @@ mapOkay.text=OK mapCancel.text=Abbrechen +#find dialog +findTitle=Suchen auf {0} +findFind=Suche: +findFind.shortdescription=<html>W\u00e4hlt den zu suchenden Text. +findWhere=Wo: +findWhere.shortdescription=<html>W\u00e4 die zu durchsuchende Kartegorie. +findWhereName='name'-Attribut +findWhereArch=Archetyp-Name +findWhereMsg='msg'-Attribute +findWhereFace='face'- oder 'animation'-Attribut +findWhereSlaying='slaying'-Attribut +findWhereOther=ein anderes Attribut +findOk.text=OK +findCancel.text=Abbrechen + #replace replaceTitle=Ersetze replaceOn=In @@ -731,6 +746,15 @@ shiftNorthWest.text=Nach Nordwest verschieben shiftNorthWest.shortdescription=Verschiebt die ausgew\u00e4hlten Felder nach Nordwest. +find.text=Suchen +find.shortdescription=\u00d6ffnet den Dialog zum Suchen von Objekten. + +findNext.text=Vorw\u00e4rts suchen +findNext.shortdescription=Wiederholt den letzten Suchvorgang. + +findPrev.text=R\u00cfw\u00e4rts suchen +findPrev.shortdescription=Wiederholt den letzten Suchvorgang. + replace.text=Ersetzen replace.mnemonic=Z replace.shortdescription=\u00d6ffnet den Dialog zum Ersetzen von Objekten. Modified: trunk/src/app/net/sf/gridarta/messages_fr.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages_fr.properties 2011-11-12 10:49:07 UTC (rev 9106) +++ trunk/src/app/net/sf/gridarta/messages_fr.properties 2011-11-12 10:52:09 UTC (rev 9107) @@ -543,6 +543,21 @@ #mapOkay.text= #mapCancel.text= +#find dialog +#findTitle= +#findFind= +#findFind.shortdescription= +#findWhere= +#findWhere.shortdescription= +#findWhereName= +#findWhereArch= +#findWhereMsg= +#findWhereFace= +#findWhereSlaying= +#findWhereOther= +#findOk.text= +#findCancel.text= + #replace replaceTitle=Remplacer replaceOn=Dans @@ -727,6 +742,15 @@ shiftNorthWest.text=D\u00e9caler vers le nord-ouest shiftNorthWest.shortdescription=D\u00e9cale la s\u00e9lection vers le nord-ouest. +#find.text= +#find.shortdescription= + +#findNext.text= +#findNext.shortdescription= + +#findPrev.text=R +#findPrev.shortdescription= + replace.text=Remplacer replace.mnemonic=M #replace.shortdescription= Modified: trunk/src/app/net/sf/gridarta/messages_sv.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages_sv.properties 2011-11-12 10:49:07 UTC (rev 9106) +++ trunk/src/app/net/sf/gridarta/messages_sv.properties 2011-11-12 10:52:09 UTC (rev 9107) @@ -542,6 +542,21 @@ mapOkay.text=Ok mapCancel.text=Avbryt +#find dialog +#findTitle= +#findFind= +#findFind.shortdescription= +#findWhere= +#findWhere.shortdescription= +#findWhereName= +#findWhereArch= +#findWhereMsg= +#findWhereFace= +#findWhereSlaying= +#findWhereOther= +#findOk.text= +#findCancel.text= + #replace replaceTitle=Ers\u00e4tt replaceOn=P\u00e5 @@ -729,6 +744,15 @@ #shiftNorthWest.text= #shiftNorthWest.shortdescription= +#find.text= +#find.shortdescription= + +#findNext.text= +#findNext.shortdescription= + +#findPrev.text=R +#findPrev.shortdescription= + replace.text=Ers\u00e4tt replace.mnemonic=E #replace.shortdescription= Modified: trunk/utils/src/app/net/sf/gridarta/utils/ActionBuilderUtils.java =================================================================== --- trunk/utils/src/app/net/sf/gridarta/utils/ActionBuilderUtils.java 2011-11-12 10:49:07 UTC (rev 9106) +++ trunk/utils/src/app/net/sf/gridarta/utils/ActionBuilderUtils.java 2011-11-12 10:52:09 UTC (rev 9107) @@ -93,6 +93,22 @@ } /** + * Returns the value of a key. + * @param actionBuilder the action builder to query + * @param key the key to query + * @param args the arguments to replace in the format string + * @return the value + */ + @NotNull + public static String format(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final Object... args) { + final String value = actionBuilder.format(key, args); + if (value == null) { + throw new MissingResourceException("missing resource key: " + key, ActionBuilderUtils.class.getName(), key); + } + return value; + } + + /** * Creates a new {@link JLabel} from a resource key. * @param actionBuilder the action builder to query * @param key the resource key This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2011-11-17 06:01:19
|
Revision: 9109 http://gridarta.svn.sourceforge.net/gridarta/?rev=9109&view=rev Author: akirschbaum Date: 2011-11-17 06:01:12 +0000 (Thu, 17 Nov 2011) Log Message: ----------- Ignore "enable updates" setting for builds without valid update URLs. Modified Paths: -------------- trunk/atrinik/ChangeLog trunk/crossfire/ChangeLog trunk/daimonin/ChangeLog trunk/src/app/net/sf/gridarta/updater/UpdaterManager.java Modified: trunk/atrinik/ChangeLog =================================================================== --- trunk/atrinik/ChangeLog 2011-11-13 08:45:19 UTC (rev 9108) +++ trunk/atrinik/ChangeLog 2011-11-17 06:01:12 UTC (rev 9109) @@ -1,3 +1,10 @@ +2011-11-17 Andreas Kirschbaum + + * Ignore "enable updates" setting for builds without valid update + URLs. This prevents possbile errors 'Error while updating: + java.net.MalformedURLException: no protocol: Please Update + manually.' + 2011-11-12 Andreas Kirschbaum * Implement Edit|Find... which searches the current map. Relocate Modified: trunk/crossfire/ChangeLog =================================================================== --- trunk/crossfire/ChangeLog 2011-11-13 08:45:19 UTC (rev 9108) +++ trunk/crossfire/ChangeLog 2011-11-17 06:01:12 UTC (rev 9109) @@ -1,3 +1,10 @@ +2011-11-17 Andreas Kirschbaum + + * Ignore "enable updates" setting for builds without valid update + URLs. This prevents possbile errors 'Error while updating: + java.net.MalformedURLException: no protocol: Please Update + manually.' + 2011-11-12 Andreas Kirschbaum * Implement Edit|Find... which searches the current map. Relocate Modified: trunk/daimonin/ChangeLog =================================================================== --- trunk/daimonin/ChangeLog 2011-11-13 08:45:19 UTC (rev 9108) +++ trunk/daimonin/ChangeLog 2011-11-17 06:01:12 UTC (rev 9109) @@ -1,3 +1,10 @@ +2011-11-17 Andreas Kirschbaum + + * Ignore "enable updates" setting for builds without valid update + URLs. This prevents possbile errors 'Error while updating: + java.net.MalformedURLException: no protocol: Please Update + manually.' + 2011-11-12 Andreas Kirschbaum * Implement Edit|Find... which searches the current map. Relocate Modified: trunk/src/app/net/sf/gridarta/updater/UpdaterManager.java =================================================================== --- trunk/src/app/net/sf/gridarta/updater/UpdaterManager.java 2011-11-13 08:45:19 UTC (rev 9108) +++ trunk/src/app/net/sf/gridarta/updater/UpdaterManager.java 2011-11-17 06:01:12 UTC (rev 9109) @@ -98,6 +98,11 @@ private final String updateFileName; /** + * Whether an update URL is defined. + */ + private final boolean hasUpdateURL; + + /** * Creates a new instance. * @param exiter the exiter for terminating the application * @param mapManager the map manager to use @@ -112,14 +117,15 @@ final Action aUpdate = ActionUtils.newAction(ACTION_BUILDER, "Tool", this, "update"); final CharSequence propUrl = ACTION_BUILDER.getString("update.url"); - aUpdate.setEnabled(propUrl != null && propUrl.length() > 0); + hasUpdateURL = propUrl != null && propUrl.length() > 0; + aUpdate.setEnabled(hasUpdateURL); } /** * Eventually perform an update during startup. */ public void startup() { - if (!preferences.getBoolean(AUTO_CHECK_KEY, AUTO_CHECK_DEFAULT)) { + if (!hasUpdateURL || !preferences.getBoolean(AUTO_CHECK_KEY, AUTO_CHECK_DEFAULT)) { return; } final long timeDifference = UPDATE_TIMES[preferences.getInt(INTERVAL_KEY, INTERVAL_DEFAULT)]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2011-11-19 11:08:36
|
Revision: 9111 http://gridarta.svn.sourceforge.net/gridarta/?rev=9111&view=rev Author: akirschbaum Date: 2011-11-19 11:08:29 +0000 (Sat, 19 Nov 2011) Log Message: ----------- Fix typos. Modified Paths: -------------- trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/model/validation/checks/NonAbsoluteExitPathChecker.java trunk/src/app/net/sf/gridarta/messages.properties Modified: trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/model/validation/checks/NonAbsoluteExitPathChecker.java =================================================================== --- trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/model/validation/checks/NonAbsoluteExitPathChecker.java 2011-11-17 06:12:26 UTC (rev 9110) +++ trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/model/validation/checks/NonAbsoluteExitPathChecker.java 2011-11-19 11:08:29 UTC (rev 9111) @@ -76,7 +76,7 @@ final MapModel<GameObject, MapArchObject, Archetype> mapModel = mapSquare.getMapModel(); final MapArchObject mapArchObject = mapModel.getMapArchObject(); if (!mapArchObject.isUnique()) { - return; // not o a unique map => skip + return; // not on an unique map => skip } final String exitPath; Modified: trunk/src/app/net/sf/gridarta/messages.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages.properties 2011-11-17 06:12:26 UTC (rev 9110) +++ trunk/src/app/net/sf/gridarta/messages.properties 2011-11-19 11:08:29 UTC (rev 9111) @@ -1193,31 +1193,31 @@ prefs.useImageSet=The image set to use. prefs.username=The user name to use for new maps. prefs.Validator.All=Whether the map validator is enabled. -prefs.Validator.AttributeRange=Whether this map validator check is is enabled. -prefs.Validator.BlockedMobOrSpawnPoint=Whether this map validator check is is enabled. -prefs.Validator.BlockedSpawnPoint=Whether this map validator check is is enabled. -prefs.Validator.BlockedSquare=Whether this map validator check is is enabled. -prefs.Validator.ConnectedInsideContainer=Whether this map validator check is is enabled. -prefs.Validator.ConnectedPickable=Whether this map validator check is is enabled. -prefs.Validator.Connection=Whether this map validator check is is enabled. +prefs.Validator.AttributeRange=Whether this map validator check is enabled. +prefs.Validator.BlockedMobOrSpawnPoint=Whether this map validator check is enabled. +prefs.Validator.BlockedSpawnPoint=Whether this map validator check is enabled. +prefs.Validator.BlockedSquare=Whether this map validator check is enabled. +prefs.Validator.ConnectedInsideContainer=Whether this map validator check is enabled. +prefs.Validator.ConnectedPickable=Whether this map validator check is enabled. +prefs.Validator.Connection=Whether this map validator check is enabled. prefs.Validator.CustomType=Whether this map validator check is enabled. -prefs.Validator.DoubleLayer=Whether this map validator check is is enabled. -prefs.Validator.DoubleType=Whether this map validator check is is enabled. -prefs.Validator.EmptySpawnPoint=Whether this map validator check is is enabled. -prefs.Validator.Environment=Whether this map validator check is is enabled. -prefs.Validator.Exit=Whether this map validator check is is enabled. -prefs.Validator.MapDifficulty=Whether this map validator check is is enabled. -prefs.Validator.MobOutsideSpawnPoint=Whether this map validator check is is enabled. -prefs.Validator.NonAbsoluteExitPath=Whether this map validator check is is enabled. -prefs.Validator.PaidItemShopSquare=Whether this map validator check is is enabled. -prefs.Validator.ShopSquare=Whether this map validator check is is enabled. -prefs.Validator.Slaying=Whether this map validator check is is enabled. -prefs.Validator.SquareWithoutFloor=Whether this map validator check is is enabled. -prefs.Validator.SysObjectNotOnLayerZero=Whether this map validator check is is enabled. -prefs.Validator.TilePaths=Whether this map validator check is is enabled. -prefs.Validator.UndefinedArchetype=Whether this map validator check is is enabled. -prefs.Validator.UndefinedFace=Whether this map validator check is is enabled. -prefs.Validator.UnsetSlaying=Whether this map validator check is is enabled. +prefs.Validator.DoubleLayer=Whether this map validator check is enabled. +prefs.Validator.DoubleType=Whether this map validator check is enabled. +prefs.Validator.EmptySpawnPoint=Whether this map validator check is enabled. +prefs.Validator.Environment=Whether this map validator check is enabled. +prefs.Validator.Exit=Whether this map validator check is enabled. +prefs.Validator.MapDifficulty=Whether this map validator check is enabled. +prefs.Validator.MobOutsideSpawnPoint=Whether this map validator check is enabled. +prefs.Validator.NonAbsoluteExitPath=Whether this map validator check is enabled. +prefs.Validator.PaidItemShopSquare=Whether this map validator check is enabled. +prefs.Validator.ShopSquare=Whether this map validator check is enabled. +prefs.Validator.Slaying=Whether this map validator check is enabled. +prefs.Validator.SquareWithoutFloor=Whether this map validator check is enabled. +prefs.Validator.SysObjectNotOnLayerZero=Whether this map validator check is enabled. +prefs.Validator.TilePaths=Whether this map validator check is enabled. +prefs.Validator.UndefinedArchetype=Whether this map validator check is enabled. +prefs.Validator.UndefinedFace=Whether this map validator check is enabled. +prefs.Validator.UnsetSlaying=Whether this map validator check is enabled. prefs.WindowState=Main windows''s state (maximized, iconized, etc.) prefs.appClient=Filename of client executable. prefs.appEditor=Filename of external editor executable. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2011-11-19 11:11:37
|
Revision: 9112 http://gridarta.svn.sourceforge.net/gridarta/?rev=9112&view=rev Author: akirschbaum Date: 2011-11-19 11:11:29 +0000 (Sat, 19 Nov 2011) Log Message: ----------- Move MapLocation to model module. Added Paths: ----------- trunk/model/src/app/net/sf/gridarta/gui/ trunk/model/src/app/net/sf/gridarta/gui/map/ trunk/model/src/app/net/sf/gridarta/gui/map/mapactions/ trunk/model/src/app/net/sf/gridarta/gui/map/mapactions/MapLocation.java trunk/model/src/app/net/sf/gridarta/gui/map/mapactions/NoExitPathException.java Removed Paths: ------------- trunk/src/app/net/sf/gridarta/gui/map/mapactions/MapLocation.java trunk/src/app/net/sf/gridarta/gui/map/mapactions/NoExitPathException.java Copied: trunk/model/src/app/net/sf/gridarta/gui/map/mapactions/MapLocation.java (from rev 9110, trunk/src/app/net/sf/gridarta/gui/map/mapactions/MapLocation.java) =================================================================== --- trunk/model/src/app/net/sf/gridarta/gui/map/mapactions/MapLocation.java (rev 0) +++ trunk/model/src/app/net/sf/gridarta/gui/map/mapactions/MapLocation.java 2011-11-19 11:11:29 UTC (rev 9112) @@ -0,0 +1,254 @@ +/* + * 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.gui.map.mapactions; + +import java.awt.Point; +import java.io.File; +import java.util.regex.Pattern; +import net.sf.gridarta.model.baseobject.BaseObject; +import net.sf.gridarta.model.gameobject.GameObject; +import net.sf.gridarta.model.io.PathManager; +import net.sf.gridarta.model.mapmodel.MapModel; +import net.sf.gridarta.model.mapmodel.MapSquare; +import net.sf.gridarta.utils.StringUtils; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Represents a location on a map consisting of a map path and a map + * coordinate. + * @author Andreas Kirschbaum + */ +public class MapLocation implements Comparable<MapLocation> { + + /** + * The {@link Pattern} that matches end of lines in random map parameters. + */ + @NotNull + private static final Pattern PATTERN_END_OF_LINE = Pattern.compile("[\r\n]+"); + + /** + * The map path. + */ + @NotNull + private final String mapPath; + + /** + * The map coordinate. + */ + @NotNull + private final Point mapCoordinate; + + /** + * Creates a new instance. + * @param mapPath the map path + * @param mapXCoordinate the map x-coordinate + * @param mapYCoordinate the map y-coordinate + */ + private MapLocation(@NotNull final String mapPath, final int mapXCoordinate, final int mapYCoordinate) { + this.mapPath = mapPath; + mapCoordinate = new Point(mapXCoordinate, mapYCoordinate); + } + + /** + * Creates a new instance from a {@link BaseObject} instance. + * @param gameObject the game object + * @param allowRandomMapParameters whether random map parameters should be + * considered + * @throws NoExitPathException if the game object is not a valid exit + */ + public MapLocation(@NotNull final BaseObject<?, ?, ?, ?> gameObject, final boolean allowRandomMapParameters) throws NoExitPathException { + this(getMapPath(gameObject, allowRandomMapParameters), getMapX(gameObject), getMapY(gameObject)); + } + + /** + * Creates a new instance from a {@link BaseObject} instance. The new + * <code>MapLocation</code> instance includes an absolute map path. + * @param gameObject the game object + * @param allowRandomMapParameters whether random map parameters should be + * considered + * @param pathManager the path manager for converting relative path names + * @return the new map location instance + * @throws NoExitPathException if the game object is not a valid exit + */ + @NotNull + public static MapLocation newAbsoluteMapLocation(@NotNull final GameObject<?, ?, ?> gameObject, final boolean allowRandomMapParameters, @NotNull final PathManager pathManager) throws NoExitPathException { + final String mapPath = getMapPath(gameObject, allowRandomMapParameters); + if (mapPath.isEmpty()) { + throw new NoExitPathException(gameObject); + } + final String baseMapPath; + final MapSquare<?, ?, ?> mapSquare = gameObject.getMapSquare(); + if (mapSquare == null) { + baseMapPath = "/"; + } else { + final MapModel<?, ?, ?> mapModel = mapSquare.getMapModel(); + final File mapFile = mapModel.getMapFile(); + if (mapFile == null) { + baseMapPath = "/"; + } else { + baseMapPath = pathManager.getMapPath(mapFile); + } + } + final String canonicalMapPath = PathManager.relativeToAbsolute(baseMapPath, mapPath); + final int mapX = getMapX(gameObject); + final int mapY = getMapY(gameObject); + return new MapLocation(canonicalMapPath, mapX, mapY); + } + + /** + * Returns the map path. + * @return the map path + */ + @NotNull + public String getMapPath() { + return mapPath; + } + + /** + * Returns the map coordinate. + * @return the map coordinate + */ + @NotNull + public Point getMapCoordinate() { + return new Point(mapCoordinate); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(@Nullable final Object obj) { + if (obj == this) { + return true; + } + if (obj == null || obj.getClass() != getClass()) { + return false; + } + final MapLocation mapLocation = (MapLocation) obj; + return mapLocation.mapPath.equals(mapPath) && mapLocation.mapCoordinate.equals(mapCoordinate); + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + return mapPath.hashCode() ^ mapCoordinate.hashCode(); + } + + /** + * Returns the exit x coordinate of a {@link BaseObject}. + * @param gameObject the game object + * @return the exit x coordinate + */ + private static int getMapY(@NotNull final BaseObject<?, ?, ?, ?> gameObject) { + return gameObject.getAttributeInt(BaseObject.SP); + } + + /** + * Returns the exit y coordinate of a {@link BaseObject}. + * @param gameObject the game object + * @return the exit y coordinate + */ + private static int getMapX(@NotNull final BaseObject<?, ?, ?, ?> gameObject) { + return gameObject.getAttributeInt(BaseObject.HP); + } + + /** + * Returns the exit map path of a {@link BaseObject}. + * @param gameObject the game object + * @param allowRandomMapParameters whether random maps should be considered + * @return the exit map path + * @throws NoExitPathException if the game object is not a valid exit + */ + public static String getMapPath(@NotNull final BaseObject<?, ?, ?, ?> gameObject, final boolean allowRandomMapParameters) throws NoExitPathException { + String path = gameObject.getAttributeString(BaseObject.SLAYING); + if (allowRandomMapParameters && (path.equals("/!") || path.startsWith("/random/"))) { + // destination is a random map; extract the final non-random map + path = getRandomMapParameter(gameObject, "final_map"); + if (path == null) { + throw new NoExitPathException(gameObject); + } + } + + return path; + } + + /** + * Extracts a parameter value for an exit to a random map. + * @param gameObject the exit object containing the parameters + * @param parameterName the parameter name to use + * @return the value of the given parameter name, or <code>null</code> if + * the parameter does not exist + */ + @Nullable + private static String getRandomMapParameter(@NotNull final BaseObject<?, ?, ?, ?> gameObject, @NotNull final String parameterName) { + final String msg = gameObject.getMsgText(); + if (msg == null) { + return null; + } + + final String[] lines = PATTERN_END_OF_LINE.split(msg); + for (final String line : lines) { + final String[] tmp = StringUtils.PATTERN_SPACES.split(line, 2); + if (tmp.length == 2 && tmp[0].equals(parameterName)) { + return tmp[1]; + } + } + + return null; + } + + /** + * {@inheritDoc} + */ + @NotNull + @Override + public String toString() { + return mapCoordinate.x + "/" + mapCoordinate.y + "@" + mapPath; + } + + /** + * {@inheritDoc} + */ + @Override + @SuppressWarnings("CompareToUsesNonFinalVariable") + public int compareTo(@NotNull final MapLocation o) { + final int cmp = mapPath.compareTo(o.mapPath); + if (cmp != 0) { + return cmp; + } + if (mapCoordinate.x < o.mapCoordinate.x) { + return -1; + } + if (mapCoordinate.x > o.mapCoordinate.x) { + return -1; + } + if (mapCoordinate.y < o.mapCoordinate.y) { + return -1; + } + if (mapCoordinate.y > o.mapCoordinate.y) { + return -1; + } + return 0; + } + +} // class MapLocation Property changes on: trunk/model/src/app/net/sf/gridarta/gui/map/mapactions/MapLocation.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Copied: trunk/model/src/app/net/sf/gridarta/gui/map/mapactions/NoExitPathException.java (from rev 9110, trunk/src/app/net/sf/gridarta/gui/map/mapactions/NoExitPathException.java) =================================================================== --- trunk/model/src/app/net/sf/gridarta/gui/map/mapactions/NoExitPathException.java (rev 0) +++ trunk/model/src/app/net/sf/gridarta/gui/map/mapactions/NoExitPathException.java 2011-11-19 11:11:29 UTC (rev 9112) @@ -0,0 +1,45 @@ +/* + * 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.gui.map.mapactions; + +import net.sf.gridarta.model.baseobject.BaseObject; +import org.jetbrains.annotations.NotNull; + +/** + * Exception thrown if a game object does not specify a valid exit path. + * @author Andreas Kirschbaum + */ +public class NoExitPathException extends Exception { + + /** + * The serial version UID. + */ + private static final long serialVersionUID = 1L; + + /** + * Creates a new instance. + * @param baseObject the game object that does not specify a valid exit + * path + */ + public NoExitPathException(@NotNull final BaseObject<?, ?, ?, ?> baseObject) { + super(baseObject.getBestName()); + } + +} // class NoExitPathException Property changes on: trunk/model/src/app/net/sf/gridarta/gui/map/mapactions/NoExitPathException.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Deleted: trunk/src/app/net/sf/gridarta/gui/map/mapactions/MapLocation.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/mapactions/MapLocation.java 2011-11-19 11:08:29 UTC (rev 9111) +++ trunk/src/app/net/sf/gridarta/gui/map/mapactions/MapLocation.java 2011-11-19 11:11:29 UTC (rev 9112) @@ -1,254 +0,0 @@ -/* - * 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.gui.map.mapactions; - -import java.awt.Point; -import java.io.File; -import java.util.regex.Pattern; -import net.sf.gridarta.model.baseobject.BaseObject; -import net.sf.gridarta.model.gameobject.GameObject; -import net.sf.gridarta.model.io.PathManager; -import net.sf.gridarta.model.mapmodel.MapModel; -import net.sf.gridarta.model.mapmodel.MapSquare; -import net.sf.gridarta.utils.StringUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * Represents a location on a map consisting of a map path and a map - * coordinate. - * @author Andreas Kirschbaum - */ -public class MapLocation implements Comparable<MapLocation> { - - /** - * The {@link Pattern} that matches end of lines in random map parameters. - */ - @NotNull - private static final Pattern PATTERN_END_OF_LINE = Pattern.compile("[\r\n]+"); - - /** - * The map path. - */ - @NotNull - private final String mapPath; - - /** - * The map coordinate. - */ - @NotNull - private final Point mapCoordinate; - - /** - * Creates a new instance. - * @param mapPath the map path - * @param mapXCoordinate the map x-coordinate - * @param mapYCoordinate the map y-coordinate - */ - private MapLocation(@NotNull final String mapPath, final int mapXCoordinate, final int mapYCoordinate) { - this.mapPath = mapPath; - mapCoordinate = new Point(mapXCoordinate, mapYCoordinate); - } - - /** - * Creates a new instance from a {@link BaseObject} instance. - * @param gameObject the game object - * @param allowRandomMapParameters whether random map parameters should be - * considered - * @throws NoExitPathException if the game object is not a valid exit - */ - public MapLocation(@NotNull final BaseObject<?, ?, ?, ?> gameObject, final boolean allowRandomMapParameters) throws NoExitPathException { - this(getMapPath(gameObject, allowRandomMapParameters), getMapX(gameObject), getMapY(gameObject)); - } - - /** - * Creates a new instance from a {@link BaseObject} instance. The new - * <code>MapLocation</code> instance includes an absolute map path. - * @param gameObject the game object - * @param allowRandomMapParameters whether random map parameters should be - * considered - * @param pathManager the path manager for converting relative path names - * @return the new map location instance - * @throws NoExitPathException if the game object is not a valid exit - */ - @NotNull - public static MapLocation newAbsoluteMapLocation(@NotNull final GameObject<?, ?, ?> gameObject, final boolean allowRandomMapParameters, @NotNull final PathManager pathManager) throws NoExitPathException { - final String mapPath = getMapPath(gameObject, allowRandomMapParameters); - if (mapPath.isEmpty()) { - throw new NoExitPathException(gameObject); - } - final String baseMapPath; - final MapSquare<?, ?, ?> mapSquare = gameObject.getMapSquare(); - if (mapSquare == null) { - baseMapPath = "/"; - } else { - final MapModel<?, ?, ?> mapModel = mapSquare.getMapModel(); - final File mapFile = mapModel.getMapFile(); - if (mapFile == null) { - baseMapPath = "/"; - } else { - baseMapPath = pathManager.getMapPath(mapFile); - } - } - final String canonicalMapPath = PathManager.relativeToAbsolute(baseMapPath, mapPath); - final int mapX = getMapX(gameObject); - final int mapY = getMapY(gameObject); - return new MapLocation(canonicalMapPath, mapX, mapY); - } - - /** - * Returns the map path. - * @return the map path - */ - @NotNull - public String getMapPath() { - return mapPath; - } - - /** - * Returns the map coordinate. - * @return the map coordinate - */ - @NotNull - public Point getMapCoordinate() { - return new Point(mapCoordinate); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean equals(@Nullable final Object obj) { - if (obj == this) { - return true; - } - if (obj == null || obj.getClass() != getClass()) { - return false; - } - final MapLocation mapLocation = (MapLocation) obj; - return mapLocation.mapPath.equals(mapPath) && mapLocation.mapCoordinate.equals(mapCoordinate); - } - - /** - * {@inheritDoc} - */ - @Override - public int hashCode() { - return mapPath.hashCode() ^ mapCoordinate.hashCode(); - } - - /** - * Returns the exit x coordinate of a {@link BaseObject}. - * @param gameObject the game object - * @return the exit x coordinate - */ - private static int getMapY(@NotNull final BaseObject<?, ?, ?, ?> gameObject) { - return gameObject.getAttributeInt(BaseObject.SP); - } - - /** - * Returns the exit y coordinate of a {@link BaseObject}. - * @param gameObject the game object - * @return the exit y coordinate - */ - private static int getMapX(@NotNull final BaseObject<?, ?, ?, ?> gameObject) { - return gameObject.getAttributeInt(BaseObject.HP); - } - - /** - * Returns the exit map path of a {@link BaseObject}. - * @param gameObject the game object - * @param allowRandomMapParameters whether random maps should be considered - * @return the exit map path - * @throws NoExitPathException if the game object is not a valid exit - */ - public static String getMapPath(@NotNull final BaseObject<?, ?, ?, ?> gameObject, final boolean allowRandomMapParameters) throws NoExitPathException { - String path = gameObject.getAttributeString(BaseObject.SLAYING); - if (allowRandomMapParameters && (path.equals("/!") || path.startsWith("/random/"))) { - // destination is a random map; extract the final non-random map - path = getRandomMapParameter(gameObject, "final_map"); - if (path == null) { - throw new NoExitPathException(gameObject); - } - } - - return path; - } - - /** - * Extracts a parameter value for an exit to a random map. - * @param gameObject the exit object containing the parameters - * @param parameterName the parameter name to use - * @return the value of the given parameter name, or <code>null</code> if - * the parameter does not exist - */ - @Nullable - private static String getRandomMapParameter(@NotNull final BaseObject<?, ?, ?, ?> gameObject, @NotNull final String parameterName) { - final String msg = gameObject.getMsgText(); - if (msg == null) { - return null; - } - - final String[] lines = PATTERN_END_OF_LINE.split(msg); - for (final String line : lines) { - final String[] tmp = StringUtils.PATTERN_SPACES.split(line, 2); - if (tmp.length == 2 && tmp[0].equals(parameterName)) { - return tmp[1]; - } - } - - return null; - } - - /** - * {@inheritDoc} - */ - @NotNull - @Override - public String toString() { - return mapCoordinate.x + "/" + mapCoordinate.y + "@" + mapPath; - } - - /** - * {@inheritDoc} - */ - @Override - @SuppressWarnings("CompareToUsesNonFinalVariable") - public int compareTo(@NotNull final MapLocation o) { - final int cmp = mapPath.compareTo(o.mapPath); - if (cmp != 0) { - return cmp; - } - if (mapCoordinate.x < o.mapCoordinate.x) { - return -1; - } - if (mapCoordinate.x > o.mapCoordinate.x) { - return -1; - } - if (mapCoordinate.y < o.mapCoordinate.y) { - return -1; - } - if (mapCoordinate.y > o.mapCoordinate.y) { - return -1; - } - return 0; - } - -} // class MapLocation Deleted: trunk/src/app/net/sf/gridarta/gui/map/mapactions/NoExitPathException.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/mapactions/NoExitPathException.java 2011-11-19 11:08:29 UTC (rev 9111) +++ trunk/src/app/net/sf/gridarta/gui/map/mapactions/NoExitPathException.java 2011-11-19 11:11:29 UTC (rev 9112) @@ -1,45 +0,0 @@ -/* - * 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.gui.map.mapactions; - -import net.sf.gridarta.model.baseobject.BaseObject; -import org.jetbrains.annotations.NotNull; - -/** - * Exception thrown if a game object does not specify a valid exit path. - * @author Andreas Kirschbaum - */ -public class NoExitPathException extends Exception { - - /** - * The serial version UID. - */ - private static final long serialVersionUID = 1L; - - /** - * Creates a new instance. - * @param baseObject the game object that does not specify a valid exit - * path - */ - public NoExitPathException(@NotNull final BaseObject<?, ?, ?, ?> baseObject) { - super(baseObject.getBestName()); - } - -} // class NoExitPathException This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2011-11-19 11:56:47
|
Revision: 9113 http://gridarta.svn.sourceforge.net/gridarta/?rev=9113&view=rev Author: akirschbaum Date: 2011-11-19 11:56:40 +0000 (Sat, 19 Nov 2011) Log Message: ----------- Include exit path name in invalid exit path map validator. Modified Paths: -------------- trunk/model/src/app/net/sf/gridarta/model/validation/errors/ExitError.java trunk/src/app/net/sf/gridarta/messages.properties trunk/src/app/net/sf/gridarta/messages_de.properties trunk/test-mapvalidator/crossfire/maps/Exit.expected Modified: trunk/model/src/app/net/sf/gridarta/model/validation/errors/ExitError.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/validation/errors/ExitError.java 2011-11-19 11:11:29 UTC (rev 9112) +++ trunk/model/src/app/net/sf/gridarta/model/validation/errors/ExitError.java 2011-11-19 11:56:40 UTC (rev 9113) @@ -52,12 +52,17 @@ } /** - * Returns the exit path that was wrong. - * @return the exit path that was wrong + * {@inheritDoc} */ - @NotNull - public String getExitPath() { - return exitPath; + @Override + public String getParameter(final int id) { + switch (id) { + case 0: + return exitPath; + + default: + return null; + } } } // class ExitError Modified: trunk/src/app/net/sf/gridarta/messages.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages.properties 2011-11-19 11:11:29 UTC (rev 9112) +++ trunk/src/app/net/sf/gridarta/messages.properties 2011-11-19 11:56:40 UTC (rev 9113) @@ -1387,7 +1387,7 @@ Validator.Exit.default=true Validator.Exit.title=Exit path invalid -Validator.Exit.msg=<html><h3>{0}</h3><p>This exit has an invalid path.<br>Change the path or create the missing map. +Validator.Exit.msg=<html><h3>{0}</h3><p>This exit has an invalid path {4}.<br>Change the path or create the missing map. Validator.MapCheckerScript.default=false Validator.MapCheckerScript.title=External validator script Modified: trunk/src/app/net/sf/gridarta/messages_de.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages_de.properties 2011-11-19 11:11:29 UTC (rev 9112) +++ trunk/src/app/net/sf/gridarta/messages_de.properties 2011-11-19 11:56:40 UTC (rev 9113) @@ -1177,7 +1177,7 @@ Validator.EnvironmentSensorSlaying.msg=<html><h3>{0}</h3><p>Dieses Objekt besitzt einen ung\u00fcltigen Wert im Attribut "slaying".<br>Der Wert sollte entweder leer sein oder den Aufbau HH:MM-HH:MM haben.</p><p>Sie k\u00f6nnen:</p><ul><li>Das Attribut \u00e4ndern</li><li>Das Objekt l\u00f6schen</li></ul> Validator.Exit.title=Ung\u00fcltiger Kartenpfad -Validator.Exit.msg=<html><h3>{0}</h3><p>Dieser Ausgang besitzt einen ung\u00fcltigen Kartenpfad.<br>\u00c4ndern sie den Kartenpfad oder erstellen Sie die fehlende Karte. +Validator.Exit.msg=<html><h3>{0}</h3><p>Dieser Ausgang besitzt einen ung\u00fcltigen Kartenpfad {4}.<br>\u00c4ndern sie den Kartenpfad oder erstellen Sie die fehlende Karte. Validator.MapDifficulty.title=Ung\u00fcltige Schwierigkeit Validator.MapDifficulty.msg=<html><h3>{0}</h3>Die Karte besitzt eine ung\u00fcltige Schwierigkeit.<br>\u00c4ndern Sie die Schwierigkeit in den Karteneigenschaften. Modified: trunk/test-mapvalidator/crossfire/maps/Exit.expected =================================================================== --- trunk/test-mapvalidator/crossfire/maps/Exit.expected 2011-11-19 11:11:29 UTC (rev 9112) +++ trunk/test-mapvalidator/crossfire/maps/Exit.expected 2011-11-19 11:56:40 UTC (rev 9113) @@ -1,2 +1,2 @@ -[1|2] Exit path invalid [exit1] [exit1] -[1|4] Exit path invalid [exit1] [exit1] +[1|2] Exit path invalid [exit1] [exit1] [/nonexisting] +[1|4] Exit path invalid [exit1] [exit1] [nonexisting] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2011-12-15 19:18:31
|
Revision: 9115 http://gridarta.svn.sourceforge.net/gridarta/?rev=9115&view=rev Author: akirschbaum Date: 2011-12-15 19:18:23 +0000 (Thu, 15 Dec 2011) Log Message: ----------- Merge duplicated code. Modified Paths: -------------- trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/resource/CollectedResourcesReader.java trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/resource/CollectedResourcesReader.java trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/resource/CollectedResourcesReader.java Added Paths: ----------- trunk/model/src/app/net/sf/gridarta/model/resource/AbstractCollectedResourcesReader.java Modified: trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/resource/CollectedResourcesReader.java =================================================================== --- trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/resource/CollectedResourcesReader.java 2011-12-15 18:47:26 UTC (rev 9114) +++ trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/resource/CollectedResourcesReader.java 2011-12-15 19:18:23 UTC (rev 9115) @@ -19,70 +19,25 @@ package net.sf.gridarta.var.atrinik.resource; -import java.io.BufferedReader; import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.net.URL; -import java.util.Collections; -import java.util.List; -import java.util.Map; import net.sf.gridarta.model.anim.AnimationObjects; import net.sf.gridarta.model.archetype.AbstractArchetypeParser; import net.sf.gridarta.model.archetype.ArchetypeSet; -import net.sf.gridarta.model.errorview.ErrorView; -import net.sf.gridarta.model.errorview.ErrorViewCategory; -import net.sf.gridarta.model.errorview.ErrorViewCollector; import net.sf.gridarta.model.face.FaceObjects; -import net.sf.gridarta.model.face.FaceProvider; -import net.sf.gridarta.model.resource.AbstractResourcesReader; -import net.sf.gridarta.utils.IOUtils; +import net.sf.gridarta.model.resource.AbstractCollectedResourcesReader; import net.sf.gridarta.var.atrinik.IGUIConstants; import net.sf.gridarta.var.atrinik.model.archetype.Archetype; import net.sf.gridarta.var.atrinik.model.gameobject.GameObject; import net.sf.gridarta.var.atrinik.model.maparchobject.MapArchObject; -import org.apache.log4j.Category; -import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; /** * Loads all resources from collected files. * @author Andreas Kirschbaum */ -public class CollectedResourcesReader extends AbstractResourcesReader<GameObject, MapArchObject, Archetype> { +public class CollectedResourcesReader extends AbstractCollectedResourcesReader<GameObject, MapArchObject, Archetype> { /** - * The logger for printing log messages. - */ - private static final Category log = Logger.getLogger(CollectedResourcesReader.class); - - /** - * The collected directory. - */ - @NotNull - private final File collectedDirectory; - - /** - * The {@link ArchetypeSet} to update. - */ - @NotNull - private final ArchetypeSet<GameObject, MapArchObject, Archetype> archetypeSet; - - /** - * The {@link AbstractArchetypeParser} to use. - */ - @NotNull - private final AbstractArchetypeParser<GameObject, MapArchObject, Archetype, ?> archetypeParser; - - /** - * The {@link FaceObjects} instance. - */ - @NotNull - private final FaceObjects<GameObject, MapArchObject, Archetype> faceObjects; - - /** * Creates a new instance. * @param collectedDirectory the collected directory * @param archetypeSet the archetype set to update @@ -91,64 +46,7 @@ * @param animationObjects the animation objects instance */ public CollectedResourcesReader(@NotNull final File collectedDirectory, @NotNull final ArchetypeSet<GameObject, MapArchObject, Archetype> archetypeSet, @NotNull final AbstractArchetypeParser<GameObject, MapArchObject, Archetype, ?> archetypeParser, @NotNull final FaceObjects<GameObject, MapArchObject, Archetype> faceObjects, @NotNull final AnimationObjects<GameObject, MapArchObject, Archetype> animationObjects) { - super(collectedDirectory, null, animationObjects, faceObjects); - this.collectedDirectory = collectedDirectory; - this.archetypeSet = archetypeSet; - this.archetypeParser = archetypeParser; - this.faceObjects = faceObjects; + super(collectedDirectory, null, archetypeSet, archetypeParser, animationObjects, faceObjects, IGUIConstants.ANIMTREE_FILE, IGUIConstants.ARCH_FILE); } - /** - * {@inheritDoc} - */ - @NotNull - @Override - public FaceProvider read(@NotNull final ErrorView errorView, @NotNull final List<GameObject> invObjects) { - archetypeSet.setLoadedFromArchive(true); // load from the collected files - Map<String, String> animations = null; - try { - final URL url = IOUtils.getResource(collectedDirectory, IGUIConstants.ANIMTREE_FILE); - try { - animations = loadAnimTree(url); - } catch (final IOException ex) { - errorView.addWarning(ErrorViewCategory.ANIMTREE_FILE_INVALID, url + ": " + ex.getMessage()); - } - } catch (final IOException ex) { - errorView.addWarning(ErrorViewCategory.ANIMTREE_FILE_INVALID, IGUIConstants.ANIMTREE_FILE + ": " + ex.getMessage()); - } - loadAnimationsFromCollect(errorView, animations == null ? Collections.<String, String>emptyMap() : animations); - try { - final int archetypeCount = archetypeSet.getArchetypeCount(); - - final URL url = IOUtils.getResource(collectedDirectory, IGUIConstants.ARCH_FILE); - try { - final InputStream inputStream = url.openStream(); - try { - final Reader reader = new InputStreamReader(inputStream, IOUtils.MAP_ENCODING); - try { - final BufferedReader bufferedReader = new BufferedReader(reader); - try { - archetypeParser.parseArchetypeFromStream(bufferedReader, null, null, null, "default", "default", "", invObjects, new ErrorViewCollector(errorView, url)); - } finally { - bufferedReader.close(); - } - } finally { - reader.close(); - } - } finally { - inputStream.close(); - } - } catch (final IOException ex) { - errorView.addWarning(ErrorViewCategory.ARCHETYPES_FILE_INVALID, url + ": " + ex.getMessage()); - } - - if (log.isInfoEnabled()) { - log.info("Loaded " + (archetypeSet.getArchetypeCount() - archetypeCount) + " archetypes from '" + url + "'."); - } - } catch (final IOException ex) { - errorView.addWarning(ErrorViewCategory.ARCHETYPES_FILE_INVALID, IGUIConstants.ARCH_FILE + ": " + ex.getMessage()); - } - return faceObjects.loadFacesCollection(errorView, collectedDirectory); - } - } // class CollectedResourcesReader Modified: trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/resource/CollectedResourcesReader.java =================================================================== --- trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/resource/CollectedResourcesReader.java 2011-12-15 18:47:26 UTC (rev 9114) +++ trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/resource/CollectedResourcesReader.java 2011-12-15 19:18:23 UTC (rev 9115) @@ -19,25 +19,18 @@ package net.sf.gridarta.var.crossfire.resource; -import java.io.BufferedReader; import java.io.File; import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; import java.net.URL; -import java.util.Collections; import java.util.List; -import java.util.Map; import net.sf.gridarta.model.anim.AnimationObjects; import net.sf.gridarta.model.archetype.AbstractArchetypeParser; import net.sf.gridarta.model.archetype.ArchetypeSet; import net.sf.gridarta.model.errorview.ErrorView; import net.sf.gridarta.model.errorview.ErrorViewCategory; -import net.sf.gridarta.model.errorview.ErrorViewCollector; import net.sf.gridarta.model.face.FaceObjects; import net.sf.gridarta.model.face.FaceProvider; -import net.sf.gridarta.model.resource.AbstractResourcesReader; +import net.sf.gridarta.model.resource.AbstractCollectedResourcesReader; import net.sf.gridarta.utils.IOUtils; import net.sf.gridarta.var.crossfire.IGUIConstants; import net.sf.gridarta.var.crossfire.model.archetype.Archetype; @@ -45,52 +38,21 @@ import net.sf.gridarta.var.crossfire.model.maparchobject.MapArchObject; import net.sf.gridarta.var.crossfire.model.smoothface.SmoothFaces; import net.sf.gridarta.var.crossfire.model.smoothface.SmoothFacesLoader; -import org.apache.log4j.Category; -import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; /** * Loads all resources from collected files. * @author Andreas Kirschbaum */ -public class CollectedResourcesReader extends AbstractResourcesReader<GameObject, MapArchObject, Archetype> { +public class CollectedResourcesReader extends AbstractCollectedResourcesReader<GameObject, MapArchObject, Archetype> { /** - * The logger for printing log messages. - */ - private static final Category log = Logger.getLogger(CollectedResourcesReader.class); - - /** * The configuration directory. */ @NotNull private final File configurationDirectory; /** - * The collected directory. - */ - @NotNull - private final File collectedDirectory; - - /** - * The archetype set to update. - */ - @NotNull - private final ArchetypeSet<GameObject, MapArchObject, Archetype> archetypeSet; - - /** - * The archetype parser to use. - */ - @NotNull - private final AbstractArchetypeParser<GameObject, MapArchObject, Archetype, ?> archetypeParser; - - /** - * The face objects to update. - */ - @NotNull - private final FaceObjects<GameObject, MapArchObject, Archetype> faceObjects; - - /** * The smooth faces to update. */ @NotNull @@ -107,12 +69,8 @@ * @param smoothFaces the smooth faces to update */ public CollectedResourcesReader(@NotNull final File configurationDirectory, @NotNull final File collectedDirectory, @NotNull final ArchetypeSet<GameObject, MapArchObject, Archetype> archetypeSet, @NotNull final AbstractArchetypeParser<GameObject, MapArchObject, Archetype, ?> archetypeParser, @NotNull final FaceObjects<GameObject, MapArchObject, Archetype> faceObjects, @NotNull final AnimationObjects<GameObject, MapArchObject, Archetype> animationObjects, @NotNull final SmoothFaces smoothFaces) { - super(collectedDirectory, archetypeSet.getImageSet(), animationObjects, faceObjects); + super(collectedDirectory, archetypeSet.getImageSet(), archetypeSet, archetypeParser, animationObjects, faceObjects, IGUIConstants.ANIMTREE_FILE, IGUIConstants.ARCH_FILE); this.configurationDirectory = configurationDirectory; - this.collectedDirectory = collectedDirectory; - this.archetypeSet = archetypeSet; - this.archetypeParser = archetypeParser; - this.faceObjects = faceObjects; this.smoothFaces = smoothFaces; } @@ -122,52 +80,8 @@ @NotNull @Override public FaceProvider read(@NotNull final ErrorView errorView, @NotNull final List<GameObject> invObjects) { - archetypeSet.setLoadedFromArchive(true); - Map<String, String> animations = null; + final FaceProvider faceProvider = super.read(errorView, invObjects); try { - final URL url = IOUtils.getResource(collectedDirectory, IGUIConstants.ANIMTREE_FILE); - try { - animations = loadAnimTree(url); - } catch (final IOException ex) { - errorView.addWarning(ErrorViewCategory.ANIMTREE_FILE_INVALID, url + ": " + ex.getMessage()); - } - } catch (final IOException ex) { - errorView.addWarning(ErrorViewCategory.ANIMTREE_FILE_INVALID, IGUIConstants.ANIMTREE_FILE + ": " + ex.getMessage()); - } - loadAnimationsFromCollect(errorView, animations == null ? Collections.<String, String>emptyMap() : animations); - try { - final int archetypeCount = archetypeSet.getArchetypeCount(); - - final URL url = IOUtils.getResource(collectedDirectory, IGUIConstants.ARCH_FILE); - try { - final InputStream inputStream = url.openStream(); - try { - final Reader reader = new InputStreamReader(inputStream, IOUtils.MAP_ENCODING); - try { - final BufferedReader bufferedReader = new BufferedReader(reader); - try { - archetypeParser.parseArchetypeFromStream(bufferedReader, null, null, null, "default", "default", "", invObjects, new ErrorViewCollector(errorView, url)); - } finally { - bufferedReader.close(); - } - } finally { - reader.close(); - } - } finally { - inputStream.close(); - } - } catch (final IOException ex) { - errorView.addWarning(ErrorViewCategory.ARCHETYPES_FILE_INVALID, url + ": " + ex.getMessage()); - } - - if (log.isInfoEnabled()) { - log.info("Loaded " + (archetypeSet.getArchetypeCount() - archetypeCount) + " archetypes from '" + url + "'."); - } - } catch (final IOException ex) { - errorView.addWarning(ErrorViewCategory.ARCHETYPES_FILE_INVALID, IGUIConstants.ARCH_FILE + ": " + ex.getMessage()); - } - final FaceProvider faceProvider = faceObjects.loadFacesCollection(errorView, collectedDirectory); - try { final URL url = IOUtils.getResource(configurationDirectory, IGUIConstants.SMOOTH_FILE); SmoothFacesLoader.load(url, smoothFaces, errorView); } catch (final IOException ex) { Modified: trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/resource/CollectedResourcesReader.java =================================================================== --- trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/resource/CollectedResourcesReader.java 2011-12-15 18:47:26 UTC (rev 9114) +++ trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/resource/CollectedResourcesReader.java 2011-12-15 19:18:23 UTC (rev 9115) @@ -19,70 +19,25 @@ package net.sf.gridarta.var.daimonin.resource; -import java.io.BufferedReader; import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.net.URL; -import java.util.Collections; -import java.util.List; -import java.util.Map; import net.sf.gridarta.model.anim.AnimationObjects; import net.sf.gridarta.model.archetype.AbstractArchetypeParser; import net.sf.gridarta.model.archetype.ArchetypeSet; -import net.sf.gridarta.model.errorview.ErrorView; -import net.sf.gridarta.model.errorview.ErrorViewCategory; -import net.sf.gridarta.model.errorview.ErrorViewCollector; import net.sf.gridarta.model.face.FaceObjects; -import net.sf.gridarta.model.face.FaceProvider; -import net.sf.gridarta.model.resource.AbstractResourcesReader; -import net.sf.gridarta.utils.IOUtils; +import net.sf.gridarta.model.resource.AbstractCollectedResourcesReader; import net.sf.gridarta.var.daimonin.IGUIConstants; import net.sf.gridarta.var.daimonin.model.archetype.Archetype; import net.sf.gridarta.var.daimonin.model.gameobject.GameObject; import net.sf.gridarta.var.daimonin.model.maparchobject.MapArchObject; -import org.apache.log4j.Category; -import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; /** * Loads all resources from collected files. * @author Andreas Kirschbaum */ -public class CollectedResourcesReader extends AbstractResourcesReader<GameObject, MapArchObject, Archetype> { +public class CollectedResourcesReader extends AbstractCollectedResourcesReader<GameObject, MapArchObject, Archetype> { /** - * The logger for printing log messages. - */ - private static final Category log = Logger.getLogger(CollectedResourcesReader.class); - - /** - * The collected directory. - */ - @NotNull - private final File collectedDirectory; - - /** - * The {@link ArchetypeSet} to update. - */ - @NotNull - private final ArchetypeSet<GameObject, MapArchObject, Archetype> archetypeSet; - - /** - * The {@link AbstractArchetypeParser} to use. - */ - @NotNull - private final AbstractArchetypeParser<GameObject, MapArchObject, Archetype, ?> archetypeParser; - - /** - * The {@link FaceObjects} instance. - */ - @NotNull - private final FaceObjects<GameObject, MapArchObject, Archetype> faceObjects; - - /** * Creates a new instance. * @param collectedDirectory the collected directory * @param archetypeSet the archetype set to update @@ -91,64 +46,7 @@ * @param animationObjects the animation objects instance */ public CollectedResourcesReader(@NotNull final File collectedDirectory, @NotNull final ArchetypeSet<GameObject, MapArchObject, Archetype> archetypeSet, @NotNull final AbstractArchetypeParser<GameObject, MapArchObject, Archetype, ?> archetypeParser, @NotNull final FaceObjects<GameObject, MapArchObject, Archetype> faceObjects, @NotNull final AnimationObjects<GameObject, MapArchObject, Archetype> animationObjects) { - super(collectedDirectory, null, animationObjects, faceObjects); - this.collectedDirectory = collectedDirectory; - this.archetypeSet = archetypeSet; - this.archetypeParser = archetypeParser; - this.faceObjects = faceObjects; + super(collectedDirectory, null, archetypeSet, archetypeParser, animationObjects, faceObjects, IGUIConstants.ANIMTREE_FILE, IGUIConstants.ARCH_FILE); } - /** - * {@inheritDoc} - */ - @NotNull - @Override - public FaceProvider read(@NotNull final ErrorView errorView, @NotNull final List<GameObject> invObjects) { - archetypeSet.setLoadedFromArchive(true); // load from the collected files - Map<String, String> animations = null; - try { - final URL url = IOUtils.getResource(collectedDirectory, IGUIConstants.ANIMTREE_FILE); - try { - animations = loadAnimTree(url); - } catch (final IOException ex) { - errorView.addWarning(ErrorViewCategory.ANIMTREE_FILE_INVALID, url + ": " + ex.getMessage()); - } - } catch (final IOException ex) { - errorView.addWarning(ErrorViewCategory.ANIMTREE_FILE_INVALID, IGUIConstants.ANIMTREE_FILE + ": " + ex.getMessage()); - } - loadAnimationsFromCollect(errorView, animations == null ? Collections.<String, String>emptyMap() : animations); - try { - final int archetypeCount = archetypeSet.getArchetypeCount(); - - final URL url = IOUtils.getResource(collectedDirectory, IGUIConstants.ARCH_FILE); - try { - final InputStream inputStream = url.openStream(); - try { - final Reader reader = new InputStreamReader(inputStream, IOUtils.MAP_ENCODING); - try { - final BufferedReader bufferedReader = new BufferedReader(reader); - try { - archetypeParser.parseArchetypeFromStream(bufferedReader, null, null, null, "default", "default", "", invObjects, new ErrorViewCollector(errorView, url)); - } finally { - bufferedReader.close(); - } - } finally { - reader.close(); - } - } finally { - inputStream.close(); - } - } catch (final IOException ex) { - errorView.addWarning(ErrorViewCategory.ARCHETYPES_FILE_INVALID, url + ": " + ex.getMessage()); - } - - if (log.isInfoEnabled()) { - log.info("Loaded " + (archetypeSet.getArchetypeCount() - archetypeCount) + " archetypes from '" + url + "'."); - } - } catch (final IOException ex) { - errorView.addWarning(ErrorViewCategory.ARCHETYPES_FILE_INVALID, IGUIConstants.ARCH_FILE + ": " + ex.getMessage()); - } - return faceObjects.loadFacesCollection(errorView, collectedDirectory); - } - } // class CollectedResourcesReader Added: trunk/model/src/app/net/sf/gridarta/model/resource/AbstractCollectedResourcesReader.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/resource/AbstractCollectedResourcesReader.java (rev 0) +++ trunk/model/src/app/net/sf/gridarta/model/resource/AbstractCollectedResourcesReader.java 2011-12-15 19:18:23 UTC (rev 9115) @@ -0,0 +1,171 @@ +/* + * 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.model.resource; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.net.URL; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import net.sf.gridarta.model.anim.AnimationObjects; +import net.sf.gridarta.model.archetype.AbstractArchetypeParser; +import net.sf.gridarta.model.archetype.Archetype; +import net.sf.gridarta.model.archetype.ArchetypeSet; +import net.sf.gridarta.model.errorview.ErrorView; +import net.sf.gridarta.model.errorview.ErrorViewCategory; +import net.sf.gridarta.model.errorview.ErrorViewCollector; +import net.sf.gridarta.model.face.FaceObjects; +import net.sf.gridarta.model.face.FaceProvider; +import net.sf.gridarta.model.gameobject.GameObject; +import net.sf.gridarta.model.maparchobject.MapArchObject; +import net.sf.gridarta.utils.IOUtils; +import org.apache.log4j.Category; +import org.apache.log4j.Logger; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Abstract base class for {@link AbstractResourcesReader + * AbstractResourcesReaders} that read from collected files. + * @author Andreas Kirschbaum + */ +public class AbstractCollectedResourcesReader<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractResourcesReader<G, A, R> { + + /** + * The logger for printing log messages. + */ + private static final Category log = Logger.getLogger(AbstractCollectedResourcesReader.class); + + /** + * The collected directory. + */ + @NotNull + private final File collectedDirectory; + + /** + * The {@link ArchetypeSet} to update. + */ + @NotNull + private final ArchetypeSet<G, A, R> archetypeSet; + + /** + * The {@link AbstractArchetypeParser} to use. + */ + @NotNull + private final AbstractArchetypeParser<G, A, R, ?> archetypeParser; + + /** + * The {@link FaceObjects} instance. + */ + @NotNull + private final FaceObjects<G, A, R> faceObjects; + + /** + * The name of the animation tree information file. + */ + @NotNull + private final String animTreeFile; + + /** + * The name of the collected archetypes file. + */ + @NotNull + private final String archetypesFile; + + /** + * Creates a new instance. + * @param collectedDirectory the collected directory + * @param imageSet the active image set or <code>null</code> + * @param archetypeSet the archetype set to update + * @param archetypeParser the archetype parser to use + * @param animationObjects the animation objects instance + * @param faceObjects the face objects instance + * @param animTreeFile the name of the animation tree information file + * @param archetypesFile the name of the collected archetypes file + */ + protected AbstractCollectedResourcesReader(@NotNull final File collectedDirectory, @Nullable final String imageSet, @NotNull final ArchetypeSet<G, A, R> archetypeSet, @NotNull final AbstractArchetypeParser<G, A, R, ?> archetypeParser, @NotNull final AnimationObjects<G, A, R> animationObjects, @NotNull final FaceObjects<G, A, R> faceObjects, @NotNull final String animTreeFile, @NotNull final String archetypesFile) { + super(collectedDirectory, imageSet, animationObjects, faceObjects); + this.collectedDirectory = collectedDirectory; + this.archetypeSet = archetypeSet; + this.archetypeParser = archetypeParser; + this.faceObjects = faceObjects; + this.animTreeFile = animTreeFile; + this.archetypesFile = archetypesFile; + } + + /** + * {@inheritDoc} + */ + @NotNull + @Override + public FaceProvider read(@NotNull final ErrorView errorView, @NotNull final List<G> invObjects) { + archetypeSet.setLoadedFromArchive(true); + Map<String, String> animations = null; + try { + final URL url = IOUtils.getResource(collectedDirectory, animTreeFile); + try { + animations = loadAnimTree(url); + } catch (final IOException ex) { + errorView.addWarning(ErrorViewCategory.ANIMTREE_FILE_INVALID, url + ": " + ex.getMessage()); + } + } catch (final IOException ex) { + errorView.addWarning(ErrorViewCategory.ANIMTREE_FILE_INVALID, animTreeFile + ": " + ex.getMessage()); + } + loadAnimationsFromCollect(errorView, animations == null ? Collections.<String, String>emptyMap() : animations); + try { + final int archetypeCount = archetypeSet.getArchetypeCount(); + + final URL url = IOUtils.getResource(collectedDirectory, archetypesFile); + try { + final InputStream inputStream = url.openStream(); + try { + final Reader reader = new InputStreamReader(inputStream, IOUtils.MAP_ENCODING); + try { + final BufferedReader bufferedReader = new BufferedReader(reader); + try { + archetypeParser.parseArchetypeFromStream(bufferedReader, null, null, null, "default", "default", "", invObjects, new ErrorViewCollector(errorView, url)); + } finally { + bufferedReader.close(); + } + } finally { + reader.close(); + } + } finally { + inputStream.close(); + } + } catch (final IOException ex) { + errorView.addWarning(ErrorViewCategory.ARCHETYPES_FILE_INVALID, url + ": " + ex.getMessage()); + } + + if (log.isInfoEnabled()) { + log.info("Loaded " + (archetypeSet.getArchetypeCount() - archetypeCount) + " archetypes from '" + url + "'."); + } + } catch (final IOException ex) { + errorView.addWarning(ErrorViewCategory.ARCHETYPES_FILE_INVALID, archetypesFile + ": " + ex.getMessage()); + } + return faceObjects.loadFacesCollection(errorView, collectedDirectory); + } + +} // class AbstractCollectedResourcesReader Property changes on: trunk/model/src/app/net/sf/gridarta/model/resource/AbstractCollectedResourcesReader.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2011-12-15 19:22:05
|
Revision: 9116 http://gridarta.svn.sourceforge.net/gridarta/?rev=9116&view=rev Author: akirschbaum Date: 2011-12-15 19:21:58 +0000 (Thu, 15 Dec 2011) Log Message: ----------- Extract code into functions. Modified Paths: -------------- trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/resource/CollectedResourcesReader.java trunk/model/src/app/net/sf/gridarta/model/resource/AbstractCollectedResourcesReader.java Modified: trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/resource/CollectedResourcesReader.java =================================================================== --- trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/resource/CollectedResourcesReader.java 2011-12-15 19:18:23 UTC (rev 9115) +++ trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/resource/CollectedResourcesReader.java 2011-12-15 19:21:58 UTC (rev 9116) @@ -81,13 +81,21 @@ @Override public FaceProvider read(@NotNull final ErrorView errorView, @NotNull final List<GameObject> invObjects) { final FaceProvider faceProvider = super.read(errorView, invObjects); + loadSmoothFaces(errorView); + return faceProvider; + } + + /** + * Loads all smooth faces. + * @param errorView the error view for reporting problems + */ + private void loadSmoothFaces(final ErrorView errorView) { try { final URL url = IOUtils.getResource(configurationDirectory, IGUIConstants.SMOOTH_FILE); SmoothFacesLoader.load(url, smoothFaces, errorView); } catch (final IOException ex) { errorView.addWarning(ErrorViewCategory.ARCHETYPES_FILE_INVALID, IGUIConstants.SMOOTH_FILE + ": " + ex.getMessage()); } - return faceProvider; } } // class CollectedResourcesReader Modified: trunk/model/src/app/net/sf/gridarta/model/resource/AbstractCollectedResourcesReader.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/resource/AbstractCollectedResourcesReader.java 2011-12-15 19:18:23 UTC (rev 9115) +++ trunk/model/src/app/net/sf/gridarta/model/resource/AbstractCollectedResourcesReader.java 2011-12-15 19:21:58 UTC (rev 9116) @@ -122,6 +122,16 @@ @Override public FaceProvider read(@NotNull final ErrorView errorView, @NotNull final List<G> invObjects) { archetypeSet.setLoadedFromArchive(true); + loadAnimations(errorView); + loadArchetypes(errorView, invObjects); + return faceObjects.loadFacesCollection(errorView, collectedDirectory); + } + + /** + * Loads all animations. + * @param errorView the error view for reporting problems + */ + private void loadAnimations(@NotNull final ErrorView errorView) { Map<String, String> animations = null; try { final URL url = IOUtils.getResource(collectedDirectory, animTreeFile); @@ -134,6 +144,14 @@ errorView.addWarning(ErrorViewCategory.ANIMTREE_FILE_INVALID, animTreeFile + ": " + ex.getMessage()); } loadAnimationsFromCollect(errorView, animations == null ? Collections.<String, String>emptyMap() : animations); + } + + /** + * Loads all archetypes. + * @param errorView the error view for reporting problems + * @param invObjects all read archetypes are added to this list + */ + private void loadArchetypes(@NotNull final ErrorView errorView, @NotNull final List<G> invObjects) { try { final int archetypeCount = archetypeSet.getArchetypeCount(); @@ -165,7 +183,6 @@ } catch (final IOException ex) { errorView.addWarning(ErrorViewCategory.ARCHETYPES_FILE_INVALID, archetypesFile + ": " + ex.getMessage()); } - return faceObjects.loadFacesCollection(errorView, collectedDirectory); } } // class AbstractCollectedResourcesReader This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2011-12-15 19:37:41
|
Revision: 9118 http://gridarta.svn.sourceforge.net/gridarta/?rev=9118&view=rev Author: akirschbaum Date: 2011-12-15 19:37:34 +0000 (Thu, 15 Dec 2011) Log Message: ----------- Remove default implementation for AbstractCollectedResourcesReader.read(). Modified Paths: -------------- trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/resource/CollectedResourcesReader.java trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/resource/CollectedResourcesReader.java trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/resource/CollectedResourcesReader.java trunk/model/src/app/net/sf/gridarta/model/resource/AbstractCollectedResourcesReader.java Modified: trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/resource/CollectedResourcesReader.java =================================================================== --- trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/resource/CollectedResourcesReader.java 2011-12-15 19:27:54 UTC (rev 9117) +++ trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/resource/CollectedResourcesReader.java 2011-12-15 19:37:34 UTC (rev 9118) @@ -1,6 +1,6 @@ /* * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2010 The Gridarta Developers. + * 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 @@ -20,10 +20,13 @@ package net.sf.gridarta.var.atrinik.resource; import java.io.File; +import java.util.List; import net.sf.gridarta.model.anim.AnimationObjects; import net.sf.gridarta.model.archetype.AbstractArchetypeParser; import net.sf.gridarta.model.archetype.ArchetypeSet; +import net.sf.gridarta.model.errorview.ErrorView; import net.sf.gridarta.model.face.FaceObjects; +import net.sf.gridarta.model.face.FaceProvider; import net.sf.gridarta.model.resource.AbstractCollectedResourcesReader; import net.sf.gridarta.var.atrinik.IGUIConstants; import net.sf.gridarta.var.atrinik.model.archetype.Archetype; @@ -49,4 +52,15 @@ super(collectedDirectory, null, archetypeSet, archetypeParser, animationObjects, faceObjects, IGUIConstants.ANIMTREE_FILE, IGUIConstants.ARCH_FILE); } + /** + * {@inheritDoc} + */ + @NotNull + @Override + public FaceProvider read(@NotNull final ErrorView errorView, @NotNull final List<GameObject> invObjects) { + loadAnimations(errorView); + loadArchetypes(errorView, invObjects); + return loadFacesCollection(errorView); + } + } // class CollectedResourcesReader Modified: trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/resource/CollectedResourcesReader.java =================================================================== --- trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/resource/CollectedResourcesReader.java 2011-12-15 19:27:54 UTC (rev 9117) +++ trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/resource/CollectedResourcesReader.java 2011-12-15 19:37:34 UTC (rev 9118) @@ -1,6 +1,6 @@ /* * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2010 The Gridarta Developers. + * 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 @@ -80,7 +80,9 @@ @NotNull @Override public FaceProvider read(@NotNull final ErrorView errorView, @NotNull final List<GameObject> invObjects) { - final FaceProvider faceProvider = super.read(errorView, invObjects); + loadAnimations(errorView); + loadArchetypes(errorView, invObjects); + final FaceProvider faceProvider = loadFacesCollection(errorView); loadSmoothFaces(errorView); return faceProvider; } Modified: trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/resource/CollectedResourcesReader.java =================================================================== --- trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/resource/CollectedResourcesReader.java 2011-12-15 19:27:54 UTC (rev 9117) +++ trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/resource/CollectedResourcesReader.java 2011-12-15 19:37:34 UTC (rev 9118) @@ -1,6 +1,6 @@ /* * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2010 The Gridarta Developers. + * 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 @@ -20,10 +20,13 @@ package net.sf.gridarta.var.daimonin.resource; import java.io.File; +import java.util.List; import net.sf.gridarta.model.anim.AnimationObjects; import net.sf.gridarta.model.archetype.AbstractArchetypeParser; import net.sf.gridarta.model.archetype.ArchetypeSet; +import net.sf.gridarta.model.errorview.ErrorView; import net.sf.gridarta.model.face.FaceObjects; +import net.sf.gridarta.model.face.FaceProvider; import net.sf.gridarta.model.resource.AbstractCollectedResourcesReader; import net.sf.gridarta.var.daimonin.IGUIConstants; import net.sf.gridarta.var.daimonin.model.archetype.Archetype; @@ -49,4 +52,15 @@ super(collectedDirectory, null, archetypeSet, archetypeParser, animationObjects, faceObjects, IGUIConstants.ANIMTREE_FILE, IGUIConstants.ARCH_FILE); } + /** + * {@inheritDoc} + */ + @NotNull + @Override + public FaceProvider read(@NotNull final ErrorView errorView, @NotNull final List<GameObject> invObjects) { + loadAnimations(errorView); + loadArchetypes(errorView, invObjects); + return loadFacesCollection(errorView); + } + } // class CollectedResourcesReader Modified: trunk/model/src/app/net/sf/gridarta/model/resource/AbstractCollectedResourcesReader.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/resource/AbstractCollectedResourcesReader.java 2011-12-15 19:27:54 UTC (rev 9117) +++ trunk/model/src/app/net/sf/gridarta/model/resource/AbstractCollectedResourcesReader.java 2011-12-15 19:37:34 UTC (rev 9118) @@ -51,7 +51,7 @@ * AbstractResourcesReaders} that read from collected files. * @author Andreas Kirschbaum */ -public class AbstractCollectedResourcesReader<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractResourcesReader<G, A, R> { +public abstract class AbstractCollectedResourcesReader<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractResourcesReader<G, A, R> { /** * The logger for printing log messages. @@ -116,21 +116,10 @@ } /** - * {@inheritDoc} - */ - @NotNull - @Override - public FaceProvider read(@NotNull final ErrorView errorView, @NotNull final List<G> invObjects) { - loadAnimations(errorView); - loadArchetypes(errorView, invObjects); - return faceObjects.loadFacesCollection(errorView, collectedDirectory); - } - - /** * Loads all animations. * @param errorView the error view for reporting problems */ - private void loadAnimations(@NotNull final ErrorView errorView) { + protected void loadAnimations(@NotNull final ErrorView errorView) { Map<String, String> animations = null; try { final URL url = IOUtils.getResource(collectedDirectory, animTreeFile); @@ -150,7 +139,7 @@ * @param errorView the error view for reporting problems * @param invObjects all read archetypes are added to this list */ - private void loadArchetypes(@NotNull final ErrorView errorView, @NotNull final List<G> invObjects) { + protected void loadArchetypes(@NotNull final ErrorView errorView, @NotNull final List<G> invObjects) { archetypeSet.setLoadedFromArchive(true); try { final int archetypeCount = archetypeSet.getArchetypeCount(); @@ -185,4 +174,14 @@ } } + /** + * Loads all faces. + * @param errorView the error view for reporting problems + * @return the face provider for accessing the read faces + */ + @NotNull + protected FaceProvider loadFacesCollection(@NotNull final ErrorView errorView) { + return faceObjects.loadFacesCollection(errorView, collectedDirectory); + } + } // class AbstractCollectedResourcesReader This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2011-12-16 19:17:25
|
Revision: 9119 http://gridarta.svn.sourceforge.net/gridarta/?rev=9119&view=rev Author: akirschbaum Date: 2011-12-16 19:17:18 +0000 (Fri, 16 Dec 2011) Log Message: ----------- Move MapLocation and related classes to different package. Modified Paths: -------------- trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/model/validation/checks/NonAbsoluteExitPathChecker.java trunk/src/app/net/sf/gridarta/gui/dialog/goexit/GoExitDialog.java trunk/src/app/net/sf/gridarta/gui/dialog/goexit/MapListCellRenderer.java trunk/src/app/net/sf/gridarta/gui/map/mapactions/EnterMap.java Added Paths: ----------- trunk/model/src/app/net/sf/gridarta/model/maplocation/ trunk/model/src/app/net/sf/gridarta/model/maplocation/MapLocation.java trunk/model/src/app/net/sf/gridarta/model/maplocation/NoExitPathException.java Removed Paths: ------------- trunk/model/src/app/net/sf/gridarta/gui/map/mapactions/ Modified: trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/model/validation/checks/NonAbsoluteExitPathChecker.java =================================================================== --- trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/model/validation/checks/NonAbsoluteExitPathChecker.java 2011-12-15 19:37:34 UTC (rev 9118) +++ trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/model/validation/checks/NonAbsoluteExitPathChecker.java 2011-12-16 19:17:18 UTC (rev 9119) @@ -19,8 +19,8 @@ package net.sf.gridarta.var.crossfire.model.validation.checks; -import net.sf.gridarta.gui.map.mapactions.MapLocation; -import net.sf.gridarta.gui.map.mapactions.NoExitPathException; +import net.sf.gridarta.model.maplocation.MapLocation; +import net.sf.gridarta.model.maplocation.NoExitPathException; import net.sf.gridarta.model.mapmodel.MapModel; import net.sf.gridarta.model.mapmodel.MapSquare; import net.sf.gridarta.model.match.GameObjectMatcher; Copied: trunk/model/src/app/net/sf/gridarta/model/maplocation/MapLocation.java (from rev 9114, trunk/model/src/app/net/sf/gridarta/gui/map/mapactions/MapLocation.java) =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/maplocation/MapLocation.java (rev 0) +++ trunk/model/src/app/net/sf/gridarta/model/maplocation/MapLocation.java 2011-12-16 19:17:18 UTC (rev 9119) @@ -0,0 +1,254 @@ +/* + * 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.model.maplocation; + +import java.awt.Point; +import java.io.File; +import java.util.regex.Pattern; +import net.sf.gridarta.model.baseobject.BaseObject; +import net.sf.gridarta.model.gameobject.GameObject; +import net.sf.gridarta.model.io.PathManager; +import net.sf.gridarta.model.mapmodel.MapModel; +import net.sf.gridarta.model.mapmodel.MapSquare; +import net.sf.gridarta.utils.StringUtils; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Represents a location on a map consisting of a map path and a map + * coordinate. + * @author Andreas Kirschbaum + */ +public class MapLocation implements Comparable<MapLocation> { + + /** + * The {@link Pattern} that matches end of lines in random map parameters. + */ + @NotNull + private static final Pattern PATTERN_END_OF_LINE = Pattern.compile("[\r\n]+"); + + /** + * The map path. + */ + @NotNull + private final String mapPath; + + /** + * The map coordinate. + */ + @NotNull + private final Point mapCoordinate; + + /** + * Creates a new instance. + * @param mapPath the map path + * @param mapXCoordinate the map x-coordinate + * @param mapYCoordinate the map y-coordinate + */ + private MapLocation(@NotNull final String mapPath, final int mapXCoordinate, final int mapYCoordinate) { + this.mapPath = mapPath; + mapCoordinate = new Point(mapXCoordinate, mapYCoordinate); + } + + /** + * Creates a new instance from a {@link BaseObject} instance. + * @param gameObject the game object + * @param allowRandomMapParameters whether random map parameters should be + * considered + * @throws NoExitPathException if the game object is not a valid exit + */ + public MapLocation(@NotNull final BaseObject<?, ?, ?, ?> gameObject, final boolean allowRandomMapParameters) throws NoExitPathException { + this(getMapPath(gameObject, allowRandomMapParameters), getMapX(gameObject), getMapY(gameObject)); + } + + /** + * Creates a new instance from a {@link BaseObject} instance. The new + * <code>MapLocation</code> instance includes an absolute map path. + * @param gameObject the game object + * @param allowRandomMapParameters whether random map parameters should be + * considered + * @param pathManager the path manager for converting relative path names + * @return the new map location instance + * @throws NoExitPathException if the game object is not a valid exit + */ + @NotNull + public static MapLocation newAbsoluteMapLocation(@NotNull final GameObject<?, ?, ?> gameObject, final boolean allowRandomMapParameters, @NotNull final PathManager pathManager) throws NoExitPathException { + final String mapPath = getMapPath(gameObject, allowRandomMapParameters); + if (mapPath.isEmpty()) { + throw new NoExitPathException(gameObject); + } + final String baseMapPath; + final MapSquare<?, ?, ?> mapSquare = gameObject.getMapSquare(); + if (mapSquare == null) { + baseMapPath = "/"; + } else { + final MapModel<?, ?, ?> mapModel = mapSquare.getMapModel(); + final File mapFile = mapModel.getMapFile(); + if (mapFile == null) { + baseMapPath = "/"; + } else { + baseMapPath = pathManager.getMapPath(mapFile); + } + } + final String canonicalMapPath = PathManager.relativeToAbsolute(baseMapPath, mapPath); + final int mapX = getMapX(gameObject); + final int mapY = getMapY(gameObject); + return new MapLocation(canonicalMapPath, mapX, mapY); + } + + /** + * Returns the map path. + * @return the map path + */ + @NotNull + public String getMapPath() { + return mapPath; + } + + /** + * Returns the map coordinate. + * @return the map coordinate + */ + @NotNull + public Point getMapCoordinate() { + return new Point(mapCoordinate); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(@Nullable final Object obj) { + if (obj == this) { + return true; + } + if (obj == null || obj.getClass() != getClass()) { + return false; + } + final MapLocation mapLocation = (MapLocation) obj; + return mapLocation.mapPath.equals(mapPath) && mapLocation.mapCoordinate.equals(mapCoordinate); + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + return mapPath.hashCode() ^ mapCoordinate.hashCode(); + } + + /** + * Returns the exit x coordinate of a {@link BaseObject}. + * @param gameObject the game object + * @return the exit x coordinate + */ + private static int getMapY(@NotNull final BaseObject<?, ?, ?, ?> gameObject) { + return gameObject.getAttributeInt(BaseObject.SP); + } + + /** + * Returns the exit y coordinate of a {@link BaseObject}. + * @param gameObject the game object + * @return the exit y coordinate + */ + private static int getMapX(@NotNull final BaseObject<?, ?, ?, ?> gameObject) { + return gameObject.getAttributeInt(BaseObject.HP); + } + + /** + * Returns the exit map path of a {@link BaseObject}. + * @param gameObject the game object + * @param allowRandomMapParameters whether random maps should be considered + * @return the exit map path + * @throws NoExitPathException if the game object is not a valid exit + */ + public static String getMapPath(@NotNull final BaseObject<?, ?, ?, ?> gameObject, final boolean allowRandomMapParameters) throws NoExitPathException { + String path = gameObject.getAttributeString(BaseObject.SLAYING); + if (allowRandomMapParameters && (path.equals("/!") || path.startsWith("/random/"))) { + // destination is a random map; extract the final non-random map + path = getRandomMapParameter(gameObject, "final_map"); + if (path == null) { + throw new NoExitPathException(gameObject); + } + } + + return path; + } + + /** + * Extracts a parameter value for an exit to a random map. + * @param gameObject the exit object containing the parameters + * @param parameterName the parameter name to use + * @return the value of the given parameter name, or <code>null</code> if + * the parameter does not exist + */ + @Nullable + private static String getRandomMapParameter(@NotNull final BaseObject<?, ?, ?, ?> gameObject, @NotNull final String parameterName) { + final String msg = gameObject.getMsgText(); + if (msg == null) { + return null; + } + + final String[] lines = PATTERN_END_OF_LINE.split(msg); + for (final String line : lines) { + final String[] tmp = StringUtils.PATTERN_SPACES.split(line, 2); + if (tmp.length == 2 && tmp[0].equals(parameterName)) { + return tmp[1]; + } + } + + return null; + } + + /** + * {@inheritDoc} + */ + @NotNull + @Override + public String toString() { + return mapCoordinate.x + "/" + mapCoordinate.y + "@" + mapPath; + } + + /** + * {@inheritDoc} + */ + @Override + @SuppressWarnings("CompareToUsesNonFinalVariable") + public int compareTo(@NotNull final MapLocation o) { + final int cmp = mapPath.compareTo(o.mapPath); + if (cmp != 0) { + return cmp; + } + if (mapCoordinate.x < o.mapCoordinate.x) { + return -1; + } + if (mapCoordinate.x > o.mapCoordinate.x) { + return -1; + } + if (mapCoordinate.y < o.mapCoordinate.y) { + return -1; + } + if (mapCoordinate.y > o.mapCoordinate.y) { + return -1; + } + return 0; + } + +} // class MapLocation Property changes on: trunk/model/src/app/net/sf/gridarta/model/maplocation/MapLocation.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Copied: trunk/model/src/app/net/sf/gridarta/model/maplocation/NoExitPathException.java (from rev 9114, trunk/model/src/app/net/sf/gridarta/gui/map/mapactions/NoExitPathException.java) =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/maplocation/NoExitPathException.java (rev 0) +++ trunk/model/src/app/net/sf/gridarta/model/maplocation/NoExitPathException.java 2011-12-16 19:17:18 UTC (rev 9119) @@ -0,0 +1,45 @@ +/* + * 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.model.maplocation; + +import net.sf.gridarta.model.baseobject.BaseObject; +import org.jetbrains.annotations.NotNull; + +/** + * Exception thrown if a game object does not specify a valid exit path. + * @author Andreas Kirschbaum + */ +public class NoExitPathException extends Exception { + + /** + * The serial version UID. + */ + private static final long serialVersionUID = 1L; + + /** + * Creates a new instance. + * @param baseObject the game object that does not specify a valid exit + * path + */ + public NoExitPathException(@NotNull final BaseObject<?, ?, ?, ?> baseObject) { + super(baseObject.getBestName()); + } + +} // class NoExitPathException Property changes on: trunk/model/src/app/net/sf/gridarta/model/maplocation/NoExitPathException.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Modified: trunk/src/app/net/sf/gridarta/gui/dialog/goexit/GoExitDialog.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/dialog/goexit/GoExitDialog.java 2011-12-15 19:37:34 UTC (rev 9118) +++ trunk/src/app/net/sf/gridarta/gui/dialog/goexit/GoExitDialog.java 2011-12-16 19:17:18 UTC (rev 9119) @@ -36,8 +36,6 @@ import javax.swing.ScrollPaneConstants; import javax.swing.WindowConstants; import net.sf.gridarta.gui.map.mapactions.EnterMap; -import net.sf.gridarta.gui.map.mapactions.MapLocation; -import net.sf.gridarta.gui.map.mapactions.NoExitPathException; import net.sf.gridarta.gui.map.mapview.MapView; import net.sf.gridarta.gui.utils.SwingUtils; import net.sf.gridarta.model.archetype.Archetype; @@ -46,6 +44,8 @@ import net.sf.gridarta.model.io.PathManager; import net.sf.gridarta.model.maparchobject.MapArchObject; import net.sf.gridarta.model.mapcontrol.MapControl; +import net.sf.gridarta.model.maplocation.MapLocation; +import net.sf.gridarta.model.maplocation.NoExitPathException; import net.sf.gridarta.model.mapmodel.MapModel; import net.sf.gridarta.model.match.GameObjectMatcher; import net.sf.gridarta.utils.ActionBuilderUtils; Modified: trunk/src/app/net/sf/gridarta/gui/dialog/goexit/MapListCellRenderer.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/dialog/goexit/MapListCellRenderer.java 2011-12-15 19:37:34 UTC (rev 9118) +++ trunk/src/app/net/sf/gridarta/gui/dialog/goexit/MapListCellRenderer.java 2011-12-16 19:17:18 UTC (rev 9119) @@ -24,11 +24,11 @@ import java.util.Comparator; import javax.swing.DefaultListCellRenderer; import javax.swing.JList; -import net.sf.gridarta.gui.map.mapactions.MapLocation; -import net.sf.gridarta.gui.map.mapactions.NoExitPathException; import net.sf.gridarta.model.face.FaceObjectProviders; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.io.PathManager; +import net.sf.gridarta.model.maplocation.MapLocation; +import net.sf.gridarta.model.maplocation.NoExitPathException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; Modified: trunk/src/app/net/sf/gridarta/gui/map/mapactions/EnterMap.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/mapactions/EnterMap.java 2011-12-15 19:37:34 UTC (rev 9118) +++ trunk/src/app/net/sf/gridarta/gui/map/mapactions/EnterMap.java 2011-12-16 19:17:18 UTC (rev 9119) @@ -33,6 +33,8 @@ import net.sf.gridarta.model.direction.Direction; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; +import net.sf.gridarta.model.maplocation.MapLocation; +import net.sf.gridarta.model.maplocation.NoExitPathException; import net.sf.gridarta.model.mapmanager.FileControl; import net.sf.gridarta.model.mappathnormalizer.IOErrorException; import net.sf.gridarta.model.mappathnormalizer.InvalidPathException; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |