You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(103) |
Jun
(121) |
Jul
(16) |
Aug
(67) |
Sep
(126) |
Oct
(161) |
Nov
(164) |
Dec
(588) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(394) |
Feb
(181) |
Mar
(131) |
Apr
(180) |
May
(255) |
Jun
(11) |
Jul
(79) |
Aug
(70) |
Sep
(274) |
Oct
(138) |
Nov
(195) |
Dec
(8) |
2008 |
Jan
(3) |
Feb
(142) |
Mar
(162) |
Apr
(124) |
May
(148) |
Jun
(157) |
Jul
(425) |
Aug
(373) |
Sep
(264) |
Oct
(315) |
Nov
(225) |
Dec
(6) |
2009 |
Jan
(67) |
Feb
(78) |
Mar
(279) |
Apr
(294) |
May
(92) |
Jun
(65) |
Jul
(134) |
Aug
(41) |
Sep
(138) |
Oct
(125) |
Nov
(126) |
Dec
(122) |
2010 |
Jan
(15) |
Feb
(48) |
Mar
(9) |
Apr
(195) |
May
(373) |
Jun
(507) |
Jul
(42) |
Aug
(16) |
Sep
(38) |
Oct
(81) |
Nov
(64) |
Dec
(18) |
2011 |
Jan
(13) |
Feb
(12) |
Mar
(39) |
Apr
(1) |
May
(2) |
Jun
(27) |
Jul
(27) |
Aug
(31) |
Sep
(14) |
Oct
(102) |
Nov
(20) |
Dec
(37) |
2012 |
Jan
(22) |
Feb
(1) |
Mar
(1) |
Apr
(2) |
May
(2) |
Jun
(18) |
Jul
(6) |
Aug
(1) |
Sep
(1) |
Oct
|
Nov
|
Dec
|
2013 |
Jan
(1) |
Feb
(2) |
Mar
(1) |
Apr
(1) |
May
(47) |
Jun
(7) |
Jul
(107) |
Aug
|
Sep
|
Oct
(112) |
Nov
(31) |
Dec
(17) |
2014 |
Jan
(29) |
Feb
(111) |
Mar
(34) |
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
(18) |
Dec
(10) |
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-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 22:46:15
|
Revision: 9083 http://gridarta.svn.sourceforge.net/gridarta/?rev=9083&view=rev Author: akirschbaum Date: 2011-10-30 22:46:08 +0000 (Sun, 30 Oct 2011) Log Message: ----------- Remove dependency MapCursorActions -> SelectedSquareModel. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java 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:38:01 UTC (rev 9082) +++ trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java 2011-10-30 22:46:08 UTC (rev 9083) @@ -29,7 +29,6 @@ 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.model.archetype.Archetype; import net.sf.gridarta.model.baseobject.BaseObject; import net.sf.gridarta.model.direction.Direction; @@ -139,12 +138,6 @@ private final GameObjectAttributesDialogFactory<G, A, R> gameObjectAttributesDialogFactory; /** - * The selected square model. - */ - @NotNull - private final SelectedSquareModel<G, A, R> selectedSquareModel; - - /** * The {@link GoLocationDialogManager} to track go location dialog * instances. */ @@ -216,12 +209,10 @@ * @param gameObjectAttributesDialogFactory the factory for creating game * object attributes dialog instances * @param mapViewManager the map view manager - * @param selectedSquareModel the selected square model */ - 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) { + public MapCursorActions(@NotNull final ObjectChooser<G, A, R> objectChooser, @NotNull final GameObjectAttributesDialogFactory<G, A, R> gameObjectAttributesDialogFactory, @NotNull final MapViewManager<G, A, R> mapViewManager) { this.objectChooser = objectChooser; this.gameObjectAttributesDialogFactory = gameObjectAttributesDialogFactory; - this.selectedSquareModel = selectedSquareModel; goLocationDialogManager = new GoLocationDialogManager<G, A, R>(mapViewManager); final String[] directionsGo = { "goNorth", "goEast", "goSouth", "goWest", "goNorthEast", "goSouthEast", "goSouthWest", "goNorthWest" }; aGo = new Action[directionsGo.length]; @@ -678,7 +669,7 @@ return false; } - final G gameObject = selectedSquareModel.getSelectedGameObject(); + final G gameObject = mapCursor.getGameObject(); if (gameObject == null) { return false; } Modified: trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java 2011-10-30 22:38:01 UTC (rev 9082) +++ trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java 2011-10-30 22:46:08 UTC (rev 9083) @@ -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>(objectChooser, gameObjectAttributesDialogFactory, mapViewManager, selectedSquareModel); + new MapCursorActions<G, A, R>(objectChooser, gameObjectAttributesDialogFactory, mapViewManager); 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:38:08
|
Revision: 9082 http://gridarta.svn.sourceforge.net/gridarta/?rev=9082&view=rev Author: akirschbaum Date: 2011-10-30 22:38:01 +0000 (Sun, 30 Oct 2011) Log Message: ----------- Simplify code. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareView.java 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:34:50 UTC (rev 9081) +++ trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareView.java 2011-10-30 22:38:01 UTC (rev 9082) @@ -355,10 +355,7 @@ } } } else if (isInsert(e)) { - final int index = getListIndex(e); - setSelectedIndex(index); - insertGameObjectFromObjectChooser(index >= model.getSize()); - setSelectedIndex(index); + insertGameObjectFromObjectChooser(getListIndex(e)); } else if (isDelete(e)) { deleteIndex(getListIndex(e)); } @@ -636,19 +633,17 @@ /** * Inserts a new game object. + * @param index the list index to insert at */ - private void insertGameObjectFromObjectChooser(final boolean insertAtEnd) { + private void insertGameObjectFromObjectChooser(final int index) { final BaseObject<G, A, R, ?> gameObject = objectChooser.getSelection(); - if (gameObject == null) { - return; + if (gameObject != null) { + final MapCursor<G, A, R> mapCursor = this.mapCursor; + if (mapCursor != null) { + mapCursor.insertGameObject(gameObject, index >= model.getSize(), true); + } } - - final MapCursor<G, A, R> mapCursor = this.mapCursor; - if (mapCursor == null) { - return; - } - - mapCursor.insertGameObject(gameObject, insertAtEnd, 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-30 22:34:57
|
Revision: 9081 http://gridarta.svn.sourceforge.net/gridarta/?rev=9081&view=rev Author: akirschbaum Date: 2011-10-30 22:34:50 +0000 (Sun, 30 Oct 2011) Log Message: ----------- Properly update selected object in selected square view when deleting game objects. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareView.java 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:07:19 UTC (rev 9080) +++ trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareView.java 2011-10-30 22:34:50 UTC (rev 9081) @@ -532,7 +532,7 @@ } //JList does not use type parameters @SuppressWarnings("unchecked") - final G gameObject = index >= model.getSize() ? null : (G) list.getSelectedValue(); + final G gameObject = (G) list.getSelectedValue(); if (mapCursor != null) { mapCursor.setGameObject(gameObject); } @@ -630,6 +630,8 @@ } finally { mapModel.endTransaction(); } + + 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-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 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 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 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 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 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 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: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-29 20:24:57
|
Revision: 9072 http://gridarta.svn.sourceforge.net/gridarta/?rev=9072&view=rev Author: akirschbaum Date: 2011-10-29 20:24:50 +0000 (Sat, 29 Oct 2011) Log Message: ----------- Add nullable annotations. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareView.java 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-29 20:22:56 UTC (rev 9071) +++ trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareView.java 2011-10-29 20:24:50 UTC (rev 9072) @@ -133,16 +133,19 @@ /** * The {@link DefaultListModel} of {@link #list}. */ + @NotNull private final DefaultListModel model = new DefaultListModel(); /** * The list of game objects. */ + @NotNull private final JList list = new JList(model); /** * The arrow buttons. */ + @NotNull private final Container arrows = new JPanel(); /** @@ -197,6 +200,7 @@ /** * The map manager listener. */ + @NotNull private final MapManagerListener<G, A, R> mapManagerListener = new MapManagerListener<G, A, R>() { /** {@inheritDoc} */ @@ -278,6 +282,7 @@ /** * The map view manager listener. */ + @NotNull private final MapViewManagerListener<G, A, R> mapViewManagerListener = new MapViewManagerListener<G, A, R>() { /** {@inheritDoc} */ @@ -309,6 +314,7 @@ * The {@link SelectedSquareModelListener} attached to {@link * #selectedSquareModel}. */ + @NotNull private final SelectedSquareModelListener<G, A, R> selectedSquareModelListener = new SelectedSquareModelListener<G, A, R>() { /** {@inheritDoc} */ @@ -329,6 +335,7 @@ * The listener attached to {@link #list} to be informed about selection * changes. */ + @NotNull private final ListSelectionListener listSelectionListener = new ListSelectionListener() { /** {@inheritDoc} */ @@ -342,6 +349,7 @@ /** * The {@link MapCursorListener} attached to all map views. */ + @NotNull private final MapCursorListener mapCursorListener = new MapCursorListener() { /** {@inheritDoc} */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2011-10-29 20:23:03
|
Revision: 9071 http://gridarta.svn.sourceforge.net/gridarta/?rev=9071&view=rev Author: akirschbaum Date: 2011-10-29 20:22:56 +0000 (Sat, 29 Oct 2011) Log Message: ----------- Fix Javadoc issue. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareModelListener.java Modified: trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareModelListener.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareModelListener.java 2011-10-23 21:18:03 UTC (rev 9070) +++ trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareModelListener.java 2011-10-29 20:22:56 UTC (rev 9071) @@ -26,7 +26,7 @@ import org.jetbrains.annotations.Nullable; /** - * Interface for listeners interested in events of {@link SelectedSquareControl} + * Interface for listeners interested in events of {@link SelectedSquareModel} * instances. * @author Andreas Kirschbaum */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2011-10-23 21:18:10
|
Revision: 9070 http://gridarta.svn.sourceforge.net/gridarta/?rev=9070&view=rev Author: akirschbaum Date: 2011-10-23 21:18:03 +0000 (Sun, 23 Oct 2011) Log Message: ----------- Remove MapCursorEvent. Modified Paths: -------------- 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/map/mapactions/MapActions.java trunk/src/app/net/sf/gridarta/gui/map/mapview/MapCursorTracker.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/objectchooser/DefaultObjectChooser.java trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareView.java trunk/src/app/net/sf/gridarta/mainactions/MainActions.java Removed Paths: ------------- trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursorEvent.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-23 21:15:06 UTC (rev 9069) +++ trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java 2011-10-23 21:18:03 UTC (rev 9070) @@ -36,7 +36,7 @@ * a {@link MapGrid} which will change it flags depending on MapCursor * movement/selection. <p/> There are three different states for MapCursor: <ul> * <li>Deactivated</li> <li>On the map</li> <li>Dragging</li> </ul> When - * coordinates or state of MapCursor changes a {@link MapCursorEvent} is fired. + * coordinates or state of MapCursor changes an event is fired. * @author <a href="mailto:dlv...@gm...">Daniel Viegas</a> */ public class MapCursor { @@ -390,9 +390,8 @@ * Inform all registered listeners that the MapCursor's mode has changed. */ private void fireMapCursorChangedModeEvent() { - final MapCursorEvent e = new MapCursorEvent(this); for (final MapCursorListener listener : listenerList.getListeners()) { - listener.mapCursorChangedMode(e); + listener.mapCursorChangedMode(); } } @@ -401,9 +400,8 @@ * changed. */ private void fireMapCursorChangedPosEvent() { - final MapCursorEvent e = new MapCursorEvent(this); for (final MapCursorListener listener : listenerList.getListeners()) { - listener.mapCursorChangedPos(e); + listener.mapCursorChangedPos(getLocation()); } } Deleted: trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursorEvent.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursorEvent.java 2011-10-23 21:15:06 UTC (rev 9069) +++ trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursorEvent.java 2011-10-23 21:18:03 UTC (rev 9070) @@ -1,54 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2010 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.mapcursor; - -import java.util.EventObject; -import org.jetbrains.annotations.NotNull; - -/** - * This Event is created by {@link MapCursor}. - * @author <a href="mailto:dlv...@gm...">Daniel Viegas</a> - */ -public class MapCursorEvent extends EventObject { - - /** - * The serial version UID. - */ - private static final long serialVersionUID = 1L; - - /** - * Constructs a MapCursorEvent. - * @param source The object on which the Event initially occurred. - * @throws IllegalArgumentException if source is null. - */ - public MapCursorEvent(@NotNull final MapCursor source) { - super(source); - } - - /** - * {@inheritDoc} - */ - @Override - @NotNull - public MapCursor getSource() { - return (MapCursor) super.getSource(); - } - -} // class MapCursorEvent 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-23 21:15:06 UTC (rev 9069) +++ trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursorListener.java 2011-10-23 21:18:03 UTC (rev 9070) @@ -19,11 +19,12 @@ package net.sf.gridarta.model.mapcursor; +import java.awt.Point; import java.util.EventListener; -import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** - * Interface for listeners listening to {@link MapCursorEvent MapCursorEvents}. + * Interface for listeners listening to {@link MapCursor} related events. * @author <a href="mailto:dlv...@gm...">Daniel Viegas</a> */ public interface MapCursorListener extends EventListener { @@ -31,15 +32,15 @@ /** * This event handler is called when {@link MapCursor} has moved, appeared * or disappeared. - * @param e MapCursorEvent + * @param location the new location or <code>null</code> if the cursor + * disappeared */ - void mapCursorChangedPos(@NotNull MapCursorEvent e); + void mapCursorChangedPos(@Nullable Point location); /** * This event handler is called when {@link MapCursor} changes mode (drag, * select). - * @param e MapCursorEvent */ - void mapCursorChangedMode(@NotNull MapCursorEvent e); + void mapCursorChangedMode(); } // 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-23 21:15:06 UTC (rev 9069) +++ trunk/model/src/test/net/sf/gridarta/model/mapcursor/MapCursorTest.java 2011-10-23 21:18:03 UTC (rev 9070) @@ -27,6 +27,7 @@ import net.sf.gridarta.model.mapgrid.SelectionMode; import net.sf.gridarta.utils.Size2D; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.junit.Assert; import org.junit.Test; @@ -473,12 +474,12 @@ private static class TestMapCursorListener implements MapCursorListener { /** - * The number of calls to {@link #mapCursorChangedPos(MapCursorEvent)}. + * The number of calls to {@link #mapCursorChangedPos(Point)}. */ private int changedPosCounter = 0; /** - * The number of calls to {@link #mapCursorChangedMode(MapCursorEvent)}. + * The number of calls to {@link #mapCursorChangedMode()}. */ private int changedModeCounter = 0; @@ -486,7 +487,7 @@ * {@inheritDoc} */ @Override - public void mapCursorChangedPos(@NotNull final MapCursorEvent e) { + public void mapCursorChangedPos(@Nullable final Point location) { changedPosCounter++; } @@ -494,7 +495,7 @@ * {@inheritDoc} */ @Override - public void mapCursorChangedMode(@NotNull final MapCursorEvent e) { + public void mapCursorChangedMode() { changedModeCounter++; } Modified: trunk/src/app/net/sf/gridarta/gui/exitconnector/ExitConnectorController.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/exitconnector/ExitConnectorController.java 2011-10-23 21:15:06 UTC (rev 9069) +++ trunk/src/app/net/sf/gridarta/gui/exitconnector/ExitConnectorController.java 2011-10-23 21:18:03 UTC (rev 9070) @@ -31,7 +31,6 @@ import net.sf.gridarta.model.exitconnector.ExitLocation; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; -import net.sf.gridarta.model.mapcursor.MapCursorEvent; import net.sf.gridarta.model.mapcursor.MapCursorListener; import net.sf.gridarta.utils.ActionUtils; import net.sf.japi.swing.action.ActionBuilder; @@ -149,13 +148,13 @@ /** {@inheritDoc} */ @Override - public void mapCursorChangedPos(@NotNull final MapCursorEvent e) { + public void mapCursorChangedPos(@Nullable final Point location) { // ignore } /** {@inheritDoc} */ @Override - public void mapCursorChangedMode(@NotNull final MapCursorEvent e) { + public void mapCursorChangedMode() { refreshActions(); } 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-23 21:15:06 UTC (rev 9069) +++ trunk/src/app/net/sf/gridarta/gui/map/mapactions/MapActions.java 2011-10-23 21:18:03 UTC (rev 9070) @@ -41,7 +41,6 @@ import net.sf.gridarta.model.maparchobject.MapArchObject; import net.sf.gridarta.model.maparchobject.MapArchObjectListener; import net.sf.gridarta.model.mapcontrol.MapControl; -import net.sf.gridarta.model.mapcursor.MapCursorEvent; import net.sf.gridarta.model.mapcursor.MapCursorListener; import net.sf.gridarta.model.mapmanager.MapManager; import net.sf.gridarta.model.mapmanager.MapManagerListener; @@ -350,13 +349,13 @@ /** {@inheritDoc} */ @Override - public void mapCursorChangedPos(@NotNull final MapCursorEvent e) { + public void mapCursorChangedPos(@Nullable final Point location) { updateActions(); } /** {@inheritDoc} */ @Override - public void mapCursorChangedMode(@NotNull final MapCursorEvent e) { + public void mapCursorChangedMode() { // ignore } 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-23 21:15:06 UTC (rev 9069) +++ trunk/src/app/net/sf/gridarta/gui/map/mapview/MapCursorTracker.java 2011-10-23 21:18:03 UTC (rev 9070) @@ -28,7 +28,6 @@ import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; import net.sf.gridarta.model.mapcursor.MapCursor; -import net.sf.gridarta.model.mapcursor.MapCursorEvent; import net.sf.gridarta.model.mapcursor.MapCursorListener; import net.sf.gridarta.utils.CommonConstants; import org.jetbrains.annotations.NotNull; @@ -68,13 +67,13 @@ /** {@inheritDoc} */ @Override - public void mapCursorChangedPos(@NotNull final MapCursorEvent e) { + public void mapCursorChangedPos(@Nullable final Point location) { ensureVisibleMapCursor(); } /** {@inheritDoc} */ @Override - public void mapCursorChangedMode(@NotNull final MapCursorEvent e) { + public void mapCursorChangedMode() { // Ignore mode change events } Modified: trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java 2011-10-23 21:15:06 UTC (rev 9069) +++ trunk/src/app/net/sf/gridarta/gui/mapcursor/MapCursorActions.java 2011-10-23 21:18:03 UTC (rev 9070) @@ -35,7 +35,6 @@ import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; import net.sf.gridarta.model.mapcursor.MapCursor; -import net.sf.gridarta.model.mapcursor.MapCursorEvent; import net.sf.gridarta.model.mapcursor.MapCursorListener; import net.sf.gridarta.model.mapgrid.SelectionMode; import net.sf.gridarta.utils.ActionUtils; @@ -191,13 +190,13 @@ /** {@inheritDoc} */ @Override - public void mapCursorChangedPos(@NotNull final MapCursorEvent e) { + public void mapCursorChangedPos(@Nullable final Point location) { // ignore } /** {@inheritDoc} */ @Override - public void mapCursorChangedMode(@NotNull final MapCursorEvent e) { + public void mapCursorChangedMode() { refreshActions(); } Modified: trunk/src/app/net/sf/gridarta/gui/misc/StatusBar.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/misc/StatusBar.java 2011-10-23 21:15:06 UTC (rev 9069) +++ trunk/src/app/net/sf/gridarta/gui/misc/StatusBar.java 2011-10-23 21:18:03 UTC (rev 9070) @@ -46,7 +46,6 @@ import net.sf.gridarta.model.mapcontrol.MapControl; import net.sf.gridarta.model.mapcontrol.MapControlListener; import net.sf.gridarta.model.mapcursor.MapCursor; -import net.sf.gridarta.model.mapcursor.MapCursorEvent; import net.sf.gridarta.model.mapcursor.MapCursorListener; import net.sf.gridarta.model.mapmanager.MapManager; import net.sf.gridarta.model.mapmanager.MapManagerListener; @@ -134,14 +133,14 @@ /** {@inheritDoc} */ @Override - public void mapCursorChangedPos(@NotNull final MapCursorEvent e) { - mapCursorChanged(e.getSource()); + public void mapCursorChangedPos(@Nullable final Point location) { + mapCursorChanged(mapView == null ? null : mapView.getMapCursor()); } /** {@inheritDoc} */ @Override - public void mapCursorChangedMode(@NotNull final MapCursorEvent e) { - mapCursorChanged(e.getSource()); + public void mapCursorChangedMode() { + mapCursorChanged(mapView == null ? null : mapView.getMapCursor()); } }; 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-23 21:15:06 UTC (rev 9069) +++ trunk/src/app/net/sf/gridarta/gui/panel/objectchooser/DefaultObjectChooser.java 2011-10-23 21:18:03 UTC (rev 9070) @@ -46,7 +46,6 @@ 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.mapcursor.MapCursorEvent; import net.sf.gridarta.model.mapcursor.MapCursorListener; import net.sf.gridarta.model.mapmodel.MapModel; import org.jetbrains.annotations.NotNull; @@ -133,14 +132,14 @@ /** {@inheritDoc} */ @Override - public void mapCursorChangedPos(@NotNull final MapCursorEvent e) { - updatePickmapInfo(e.getSource()); + public void mapCursorChangedPos(@Nullable final Point location) { + updatePickmapInfo(activePickmapView == null ? null : activePickmapView.getMapCursor()); } /** {@inheritDoc} */ @Override - public void mapCursorChangedMode(@NotNull final MapCursorEvent e) { - updatePickmapInfo(e.getSource()); + public void mapCursorChangedMode() { + updatePickmapInfo(activePickmapView == null ? null : activePickmapView.getMapCursor()); } }; 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-23 21:15:06 UTC (rev 9069) +++ trunk/src/app/net/sf/gridarta/gui/panel/selectedsquare/SelectedSquareView.java 2011-10-23 21:18:03 UTC (rev 9070) @@ -63,7 +63,6 @@ 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.MapCursorEvent; import net.sf.gridarta.model.mapcursor.MapCursorListener; import net.sf.gridarta.model.mapmanager.MapManager; import net.sf.gridarta.model.mapmanager.MapManagerListener; @@ -347,7 +346,7 @@ /** {@inheritDoc} */ @Override - public void mapCursorChangedPos(@NotNull final MapCursorEvent e) { + public void mapCursorChangedPos(@Nullable final Point location) { final MapView<G, A, R> mapView = selectedSquareModel.getCurrentMapView(); if (mapView == null) { return; @@ -355,15 +354,14 @@ final MapControl<G, A, R> mapControl = mapView.getMapControl(); - final Point cursorPos = e.getSource().getLocation(); - if (cursorPos == null || !mapControl.getMapModel().getMapArchObject().isPointValid(cursorPos)) { + if (location == null || !mapControl.getMapModel().getMapArchObject().isPointValid(location)) { if (selectedSquareModel.setSelectedMapSquare(null, null, 0)) { refresh(); } return; } - final MapSquare<G, A, R> mapSquare = mapControl.getMapModel().getMapSquare(cursorPos); + final MapSquare<G, A, R> mapSquare = mapControl.getMapModel().getMapSquare(location); if (selectedSquareModel.setSelectedMapSquare(mapSquare, null, 0)) { refresh(); } @@ -371,7 +369,7 @@ /** {@inheritDoc} */ @Override - public void mapCursorChangedMode(@NotNull final MapCursorEvent e) { + public void mapCursorChangedMode() { // ignore } Modified: trunk/src/app/net/sf/gridarta/mainactions/MainActions.java =================================================================== --- trunk/src/app/net/sf/gridarta/mainactions/MainActions.java 2011-10-23 21:15:06 UTC (rev 9069) +++ trunk/src/app/net/sf/gridarta/mainactions/MainActions.java 2011-10-23 21:18:03 UTC (rev 9070) @@ -47,7 +47,6 @@ 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.MapCursorEvent; import net.sf.gridarta.model.mapcursor.MapCursorListener; import net.sf.gridarta.model.mapgrid.MapGrid; import net.sf.gridarta.model.mapgrid.MapGridEvent; @@ -391,13 +390,13 @@ /** {@inheritDoc} */ @Override - public void mapCursorChangedPos(@NotNull final MapCursorEvent e) { + public void mapCursorChangedPos(@Nullable final Point location) { // ignore } /** {@inheritDoc} */ @Override - public void mapCursorChangedMode(@NotNull final MapCursorEvent e) { + public void mapCursorChangedMode() { refreshMenus(); // cursor may have been activated or deactivated } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2011-10-23 21:15:13
|
Revision: 9069 http://gridarta.svn.sourceforge.net/gridarta/?rev=9069&view=rev Author: akirschbaum Date: 2011-10-23 21:15:06 +0000 (Sun, 23 Oct 2011) Log Message: ----------- Add nullable annotations. Modified Paths: -------------- trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.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-22 19:28:57 UTC (rev 9068) +++ trunk/model/src/app/net/sf/gridarta/model/mapcursor/MapCursor.java 2011-10-23 21:15:06 UTC (rev 9069) @@ -45,16 +45,19 @@ * Current cursor position. When cursor is active it is highlighted on the * MapGrid. */ + @NotNull private final Point pos = new Point(); /** * Position where dragging has started. */ + @NotNull private final Point dragStart = new Point(); /** * Offset of dragging. (0, 0) when drag is on the starting position. */ + @NotNull private final Dimension dragOffset = new Dimension(); /** @@ -70,22 +73,26 @@ /** * Grid where cursor is bound to. */ + @NotNull private final MapGrid mapGrid; /** * Used to test if coordinates are on the map. Created by MapGrid. */ + @NotNull private final Rectangle mapRec; /** * Temporary point used in some methods. Placed as instance var to prevent * creation of temporary objects. */ + @NotNull private final Point tmpPoint = new Point(); /** * The MapCursorListeners to inform of changes. */ + @NotNull private final EventListenerList2<MapCursorListener> listenerList = new EventListenerList2<MapCursorListener>(MapCursorListener.class); /** @@ -93,7 +100,7 @@ * construction. * @param mapGrid Cursor is bound to this grid */ - public MapCursor(final MapGrid mapGrid) { + public MapCursor(@NotNull final MapGrid mapGrid) { this.mapGrid = mapGrid; mapRec = mapGrid.getMapRec(); final MapGridListener mapGridListener = new MapGridListener() { @@ -278,7 +285,7 @@ * @param selectionMode Mode how to change selection state * @see SelectionMode */ - public void dragSelect(final SelectionMode selectionMode) { + public void dragSelect(@NotNull final SelectionMode selectionMode) { if (dragging) { mapGrid.beginTransaction(); try { @@ -321,6 +328,7 @@ /** * Get offset from start position of dragging. * @return offset or <code>null</code> when not in drag mode + * @noinspection NullableProblems */ @Nullable public Dimension getDragOffset() { @@ -366,7 +374,7 @@ * Register a MapCursorListener. * @param listener MapCursorListener to register */ - public void addMapCursorListener(final MapCursorListener listener) { + public void addMapCursorListener(@NotNull final MapCursorListener listener) { listenerList.add(listener); } @@ -374,7 +382,7 @@ * Remove a MapCursorListener. * @param listener MapCursorListener to remove */ - public void removeMapCursorListener(final MapCursorListener listener) { + public void removeMapCursorListener(@NotNull final MapCursorListener listener) { listenerList.remove(listener); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ryo...@us...> - 2011-10-22 19:29:03
|
Revision: 9068 http://gridarta.svn.sourceforge.net/gridarta/?rev=9068&view=rev Author: ryo_saeba Date: 2011-10-22 19:28:57 +0000 (Sat, 22 Oct 2011) Log Message: ----------- Adjust to server behaviour. Modified Paths: -------------- trunk/crossfire/resource/resource/conf/types.xml Modified: trunk/crossfire/resource/resource/conf/types.xml =================================================================== --- trunk/crossfire/resource/resource/conf/types.xml 2011-10-19 06:38:58 UTC (rev 9067) +++ trunk/crossfire/resource/resource/conf/types.xml 2011-10-22 19:28:57 UTC (rev 9068) @@ -1466,9 +1466,9 @@ of uses> 1 (-> one-time usage). </attribute> <attribute arch="slaying" editor="name of creation" type="string"> - The created object will bear the name and title specified in <name - of creation>. If nothing is set, the standard name and title of - the archetype is used. + The created object will bear the name specified in <name + of creation>, and not use any title. If nothing is set, the standard name and title of + the archetype are used. </attribute> <attribute arch="level" editor="level of creation" type="int" min="-32768" max="32767" check_min="0" check_max="115"> The created object will be of that level. If zero/unset, the This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2011-10-19 06:39:05
|
Revision: 9067 http://gridarta.svn.sourceforge.net/gridarta/?rev=9067&view=rev Author: akirschbaum Date: 2011-10-19 06:38:58 +0000 (Wed, 19 Oct 2011) Log Message: ----------- Merge duplicated code. Modified Paths: -------------- trunk/model/src/app/net/sf/gridarta/model/exitconnector/ExitMatcher.java trunk/model/src/app/net/sf/gridarta/model/mapmodel/DefaultMapModel.java trunk/model/src/app/net/sf/gridarta/model/mapmodel/MapSquareIterator.java trunk/model/src/app/net/sf/gridarta/model/mapmodel/TopLevelGameObjectIterator.java trunk/model/src/test/net/sf/gridarta/model/mapmodel/MapSquareIteratorTest.java trunk/model/src/test/net/sf/gridarta/model/mapmodel/TopLevelGameObjectIteratorTest.java trunk/src/app/net/sf/gridarta/gui/map/mapactions/MapActions.java Modified: trunk/model/src/app/net/sf/gridarta/model/exitconnector/ExitMatcher.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/exitconnector/ExitMatcher.java 2011-10-19 06:14:11 UTC (rev 9066) +++ trunk/model/src/app/net/sf/gridarta/model/exitconnector/ExitMatcher.java 2011-10-19 06:38:58 UTC (rev 9067) @@ -33,9 +33,14 @@ * Selects valid exit game objects from maps. * @author Andreas Kirschbaum */ -public class ExitMatcher<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> { +public class ExitMatcher<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements GameObjectMatcher { /** + * The serial version UID. + */ + private static final long serialVersionUID = 1L; + + /** * The matcher for selecting exit objects. */ @NotNull @@ -144,8 +149,16 @@ * @param gameObject the exit game object * @return whether the game object has "slaying" set */ - private boolean isExit(@NotNull final GameObject<G, A, R> gameObject) { + private boolean isExit(@NotNull final GameObject<?, ?, ?> gameObject) { return exitMatcher.isMatching(gameObject); } + /** + * {@inheritDoc} + */ + @Override + public boolean isMatching(@NotNull final GameObject<?, ?, ?> gameObject) { + return isExit(gameObject); + } + } // class ExitMatcher Modified: trunk/model/src/app/net/sf/gridarta/model/mapmodel/DefaultMapModel.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/mapmodel/DefaultMapModel.java 2011-10-19 06:14:11 UTC (rev 9066) +++ trunk/model/src/app/net/sf/gridarta/model/mapmodel/DefaultMapModel.java 2011-10-19 06:38:58 UTC (rev 9067) @@ -263,7 +263,7 @@ */ @Override public Iterator<MapSquare<G, A, R>> iterator() { - return new MapSquareIterator<G, A, R>(this, null, 1); + return new MapSquareIterator<G, A, R>(this, null, 1, false); } /** Modified: trunk/model/src/app/net/sf/gridarta/model/mapmodel/MapSquareIterator.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/mapmodel/MapSquareIterator.java 2011-10-19 06:14:11 UTC (rev 9066) +++ trunk/model/src/app/net/sf/gridarta/model/mapmodel/MapSquareIterator.java 2011-10-19 06:38:58 UTC (rev 9067) @@ -76,8 +76,10 @@ * @param start the starting point or <code>null</code> for default * @param direction the direction to iterate: <code>+1</code> for forward, * <code>-1</code> for backward + * @param skipFirst whether to skip the first map square and return it at + * the end */ - public MapSquareIterator(@NotNull final MapModel<G, A, R> mapModel, @Nullable final Point start, final int direction) { + public MapSquareIterator(@NotNull final MapModel<G, A, R> mapModel, @Nullable final Point start, final int direction, final boolean skipFirst) { if (direction != -1 && direction != +1) { throw new IllegalArgumentException(); } @@ -94,6 +96,9 @@ point = mapWidth * mapHeight - 1; } remainingMapSquares = mapWidth * mapHeight; + if (skipFirst) { + nextMapSquare(); + } } /** @@ -123,13 +128,20 @@ remainingMapSquares--; final MapSquare<G, A, R> square = mapModel.getMapSquare(new Point(point % mapWidth, point / mapWidth)); + nextMapSquare(); + return square; + } + + /** + * Updates {@link #point} to the next map square. + */ + private void nextMapSquare() { point += direction; if (point < 0) { point += mapWidth * mapHeight; } else if (point >= mapWidth * mapHeight) { point -= mapWidth * mapHeight; } - return square; } } // class MapSquareIterator Modified: trunk/model/src/app/net/sf/gridarta/model/mapmodel/TopLevelGameObjectIterator.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/mapmodel/TopLevelGameObjectIterator.java 2011-10-19 06:14:11 UTC (rev 9066) +++ trunk/model/src/app/net/sf/gridarta/model/mapmodel/TopLevelGameObjectIterator.java 2011-10-19 06:38:58 UTC (rev 9067) @@ -61,9 +61,11 @@ * @param start the starting point or <code>null</code> for default * @param direction the direction to iterate: <code>+1</code> for forward, * <code>-1</code> for backward + * @param skipFirst whether to skip the first map square and return it at + * the end */ - public TopLevelGameObjectIterator(@NotNull final MapModel<G, A, R> mapModel, @Nullable final Point start, final int direction) { - mapSquareIterator = new MapSquareIterator<G, A, R>(mapModel, start, direction); + public TopLevelGameObjectIterator(@NotNull final MapModel<G, A, R> mapModel, @Nullable final Point start, final int direction, final boolean skipFirst) { + mapSquareIterator = new MapSquareIterator<G, A, R>(mapModel, start, direction, skipFirst); findNext(); } Modified: trunk/model/src/test/net/sf/gridarta/model/mapmodel/MapSquareIteratorTest.java =================================================================== --- trunk/model/src/test/net/sf/gridarta/model/mapmodel/MapSquareIteratorTest.java 2011-10-19 06:14:11 UTC (rev 9066) +++ trunk/model/src/test/net/sf/gridarta/model/mapmodel/MapSquareIteratorTest.java 2011-10-19 06:38:58 UTC (rev 9067) @@ -40,7 +40,7 @@ public void testIteratorForward() { final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false); final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(3, 2); - final Iterator<MapSquare<TestGameObject, TestMapArchObject, TestArchetype>> it = new MapSquareIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, null, +1); + final Iterator<MapSquare<TestGameObject, TestMapArchObject, TestArchetype>> it = new MapSquareIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, null, +1, false); Assert.assertTrue(it.hasNext()); Assert.assertSame(mapModel.getMapSquare(new Point(0, 0)), it.next()); Assert.assertTrue(it.hasNext()); @@ -63,7 +63,7 @@ public void testIteratorBackward() { final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false); final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(3, 2); - final Iterator<MapSquare<TestGameObject, TestMapArchObject, TestArchetype>> it = new MapSquareIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, null, -1); + final Iterator<MapSquare<TestGameObject, TestMapArchObject, TestArchetype>> it = new MapSquareIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, null, -1, false); Assert.assertTrue(it.hasNext()); Assert.assertSame(mapModel.getMapSquare(new Point(2, 1)), it.next()); Assert.assertTrue(it.hasNext()); @@ -86,7 +86,7 @@ public void testIteratorForwardStart() { final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false); final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(3, 2); - final Iterator<MapSquare<TestGameObject, TestMapArchObject, TestArchetype>> it = new MapSquareIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, new Point(0, 1), +1); + final Iterator<MapSquare<TestGameObject, TestMapArchObject, TestArchetype>> it = new MapSquareIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, new Point(0, 1), +1, false); Assert.assertTrue(it.hasNext()); Assert.assertSame(mapModel.getMapSquare(new Point(0, 1)), it.next()); Assert.assertTrue(it.hasNext()); @@ -109,7 +109,7 @@ public void testIteratorBackwardStart() { final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false); final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(3, 2); - final Iterator<MapSquare<TestGameObject, TestMapArchObject, TestArchetype>> it = new MapSquareIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, new Point(0, 1), -1); + final Iterator<MapSquare<TestGameObject, TestMapArchObject, TestArchetype>> it = new MapSquareIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, new Point(0, 1), -1, false); Assert.assertTrue(it.hasNext()); Assert.assertSame(mapModel.getMapSquare(new Point(0, 1)), it.next()); Assert.assertTrue(it.hasNext()); @@ -126,13 +126,61 @@ } /** + * Checks that the forward iterator returns all map squares when skip is + * enabled. + */ + @Test + public void testIteratorForwardStartSkip() { + final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false); + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(3, 2); + final Iterator<MapSquare<TestGameObject, TestMapArchObject, TestArchetype>> it = new MapSquareIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, new Point(0, 1), +1, true); + Assert.assertTrue(it.hasNext()); + Assert.assertSame(mapModel.getMapSquare(new Point(1, 1)), it.next()); + Assert.assertTrue(it.hasNext()); + Assert.assertSame(mapModel.getMapSquare(new Point(2, 1)), it.next()); + Assert.assertTrue(it.hasNext()); + Assert.assertSame(mapModel.getMapSquare(new Point(0, 0)), it.next()); + Assert.assertTrue(it.hasNext()); + Assert.assertSame(mapModel.getMapSquare(new Point(1, 0)), it.next()); + Assert.assertTrue(it.hasNext()); + Assert.assertSame(mapModel.getMapSquare(new Point(2, 0)), it.next()); + Assert.assertTrue(it.hasNext()); + Assert.assertSame(mapModel.getMapSquare(new Point(0, 1)), it.next()); + Assert.assertFalse(it.hasNext()); + } + + /** + * Checks that the backward iterator returns all map squares when skip is + * enabled. + */ + @Test + public void testIteratorBackwardStartSkip() { + final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false); + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(3, 2); + final Iterator<MapSquare<TestGameObject, TestMapArchObject, TestArchetype>> it = new MapSquareIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, new Point(0, 1), -1, true); + Assert.assertTrue(it.hasNext()); + Assert.assertSame(mapModel.getMapSquare(new Point(2, 0)), it.next()); + Assert.assertTrue(it.hasNext()); + Assert.assertSame(mapModel.getMapSquare(new Point(1, 0)), it.next()); + Assert.assertTrue(it.hasNext()); + Assert.assertSame(mapModel.getMapSquare(new Point(0, 0)), it.next()); + Assert.assertTrue(it.hasNext()); + Assert.assertSame(mapModel.getMapSquare(new Point(2, 1)), it.next()); + Assert.assertTrue(it.hasNext()); + Assert.assertSame(mapModel.getMapSquare(new Point(1, 1)), it.next()); + Assert.assertTrue(it.hasNext()); + Assert.assertSame(mapModel.getMapSquare(new Point(0, 1)), it.next()); + Assert.assertFalse(it.hasNext()); + } + + /** * Checks that invalid directions are rejected. */ @Test(expected = IllegalArgumentException.class) public void testIteratorDirection0() { final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false); final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(3, 2); - final Iterator<MapSquare<TestGameObject, TestMapArchObject, TestArchetype>> it = new MapSquareIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, null, 0); + final Iterator<MapSquare<TestGameObject, TestMapArchObject, TestArchetype>> it = new MapSquareIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, null, 0, false); } /** @@ -142,7 +190,7 @@ public void testIteratorDirection2() { final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false); final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(3, 2); - final Iterator<MapSquare<TestGameObject, TestMapArchObject, TestArchetype>> it = new MapSquareIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, null, 2); + final Iterator<MapSquare<TestGameObject, TestMapArchObject, TestArchetype>> it = new MapSquareIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, null, 2, false); } } Modified: trunk/model/src/test/net/sf/gridarta/model/mapmodel/TopLevelGameObjectIteratorTest.java =================================================================== --- trunk/model/src/test/net/sf/gridarta/model/mapmodel/TopLevelGameObjectIteratorTest.java 2011-10-19 06:14:11 UTC (rev 9066) +++ trunk/model/src/test/net/sf/gridarta/model/mapmodel/TopLevelGameObjectIteratorTest.java 2011-10-19 06:38:58 UTC (rev 9067) @@ -41,7 +41,7 @@ public void testIteratorForwardEmpty() { final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false); final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(3, 2); - final Iterator<TestGameObject> it = new TopLevelGameObjectIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, new Point(1, 1), +1); + final Iterator<TestGameObject> it = new TopLevelGameObjectIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, new Point(1, 1), +1, false); Assert.assertFalse(it.hasNext()); } @@ -52,7 +52,7 @@ public void testIteratorBackwardEmpty() { final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false); final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(3, 2); - final Iterator<TestGameObject> it = new TopLevelGameObjectIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, new Point(1, 1), -1); + final Iterator<TestGameObject> it = new TopLevelGameObjectIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, new Point(1, 1), -1, false); Assert.assertFalse(it.hasNext()); } @@ -62,7 +62,7 @@ @Test public void testIteratorForward() { final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = createMap(); - final Iterator<TestGameObject> it = new TopLevelGameObjectIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, new Point(1, 1), +1); + final Iterator<TestGameObject> it = new TopLevelGameObjectIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, new Point(1, 1), +1, false); Assert.assertTrue(it.hasNext()); Assert.assertEquals("n4", it.next().getBestName()); Assert.assertTrue(it.hasNext()); @@ -82,7 +82,7 @@ @Test public void testIteratorBackward() { final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = createMap(); - final Iterator<TestGameObject> it = new TopLevelGameObjectIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, new Point(1, 1), -1); + final Iterator<TestGameObject> it = new TopLevelGameObjectIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, new Point(1, 1), -1, false); Assert.assertTrue(it.hasNext()); Assert.assertEquals("n4", it.next().getBestName()); Assert.assertTrue(it.hasNext()); @@ -97,6 +97,46 @@ } /** + * Checks the forward iterator with skipped first element. + */ + @Test + public void testIteratorForwardSkip() { + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = createMap(); + final Iterator<TestGameObject> it = new TopLevelGameObjectIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, new Point(1, 1), +1, true); + Assert.assertTrue(it.hasNext()); + Assert.assertEquals("n5", it.next().getBestName()); + Assert.assertTrue(it.hasNext()); + Assert.assertEquals("n1", it.next().getBestName()); + Assert.assertTrue(it.hasNext()); + Assert.assertEquals("n2", it.next().getBestName()); + Assert.assertTrue(it.hasNext()); + Assert.assertEquals("n3", it.next().getBestName()); + Assert.assertTrue(it.hasNext()); + Assert.assertEquals("n4", it.next().getBestName()); + Assert.assertFalse(it.hasNext()); + } + + /** + * Checks the backward iterator with skipped first element. + */ + @Test + public void testIteratorBackwardSkip() { + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = createMap(); + final Iterator<TestGameObject> it = new TopLevelGameObjectIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, new Point(1, 1), -1, true); + Assert.assertTrue(it.hasNext()); + Assert.assertEquals("n3", it.next().getBestName()); + Assert.assertTrue(it.hasNext()); + Assert.assertEquals("n1", it.next().getBestName()); + Assert.assertTrue(it.hasNext()); + Assert.assertEquals("n2", it.next().getBestName()); + Assert.assertTrue(it.hasNext()); + Assert.assertEquals("n5", it.next().getBestName()); + Assert.assertTrue(it.hasNext()); + Assert.assertEquals("n4", it.next().getBestName()); + Assert.assertFalse(it.hasNext()); + } + + /** * Creates a new {@link MapModel} instance filled with game objects. * @return the new map model instance */ 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-19 06:14:11 UTC (rev 9066) +++ trunk/src/app/net/sf/gridarta/gui/map/mapactions/MapActions.java 2011-10-19 06:38:58 UTC (rev 9067) @@ -23,6 +23,7 @@ import java.io.File; import java.util.ArrayList; import java.util.Collection; +import java.util.Iterator; import javax.swing.Action; import javax.swing.JFrame; import javax.swing.filechooser.FileFilter; @@ -44,8 +45,10 @@ 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.FilterGameObjectIterator; import net.sf.gridarta.model.mapmodel.MapModel; import net.sf.gridarta.model.mapmodel.MapSquare; +import net.sf.gridarta.model.mapmodel.TopLevelGameObjectIterator; import net.sf.gridarta.model.mapviewsettings.MapViewSettings; import net.sf.gridarta.model.mapviewsettings.MapViewSettingsListener; import net.sf.gridarta.utils.ActionUtils; @@ -571,13 +574,11 @@ /** * Selects an exit square. * @param mapView the map view to operate on - * @param xStart the x-coordinate to start searching - * @param yStart the y-coordinate to start searching * @param direction the direction to search */ - private void selectExit(@NotNull final MapView<G, A, R> mapView, final int xStart, final int yStart, final int direction) { - final MapModel<G, A, R> mapModel = mapView.getMapControl().getMapModel(); - final ExitIterator<G, A, R> exitIterator = new ExitIterator<G, A, R>(exitMatcher, mapModel, xStart, yStart, direction); + private void selectExit(@NotNull final MapView<G, A, R> mapView, final int direction) { + final TopLevelGameObjectIterator<G, A, R> gameObjectIterator = new TopLevelGameObjectIterator<G, A, R>(mapView.getMapControl().getMapModel(), mapView.getMapCursor().getLocation(), direction, true); + final Iterator<G> exitIterator = new FilterGameObjectIterator<G, A, R>(gameObjectIterator, exitMatcher); if (exitIterator.hasNext()) { final G exit = exitIterator.next(); final MapSquare<G, A, R> mapSquare = exit.getMapSquare(); @@ -852,12 +853,7 @@ } if (performAction) { - final Point cursorLocation = mapView.getMapCursor().getLocation(); - if (cursorLocation == null) { - selectExit(mapView, -1, 0, 1); - } else { - selectExit(mapView, cursorLocation.x, cursorLocation.y, 1); - } + selectExit(mapView, 1); } return true; @@ -875,13 +871,7 @@ } if (performAction) { - final Point cursorLocation = mapView.getMapCursor().getLocation(); - if (cursorLocation == null) { - final Size2D mapSize = mapView.getMapControl().getMapModel().getMapArchObject().getMapSize(); - selectExit(mapView, mapSize.getWidth(), mapSize.getHeight() - 1, -1); - } else { - selectExit(mapView, cursorLocation.x, cursorLocation.y, -1); - } + selectExit(mapView, -1); } return true; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2011-10-19 06:14:18
|
Revision: 9066 http://gridarta.svn.sourceforge.net/gridarta/?rev=9066&view=rev Author: akirschbaum Date: 2011-10-19 06:14:11 +0000 (Wed, 19 Oct 2011) Log Message: ----------- Add FilterGameObjectIterator. Modified Paths: -------------- trunk/model/src/test/net/sf/gridarta/model/mapmodel/TestMapModelCreator.java Added Paths: ----------- trunk/model/src/app/net/sf/gridarta/model/mapmodel/FilterGameObjectIterator.java trunk/model/src/test/net/sf/gridarta/model/mapmodel/FilterGameObjectIteratorTest.java Added: trunk/model/src/app/net/sf/gridarta/model/mapmodel/FilterGameObjectIterator.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/mapmodel/FilterGameObjectIterator.java (rev 0) +++ trunk/model/src/app/net/sf/gridarta/model/mapmodel/FilterGameObjectIterator.java 2011-10-19 06:14:11 UTC (rev 9066) @@ -0,0 +1,130 @@ +/* + * 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.mapmodel; + +import java.util.Iterator; +import java.util.NoSuchElementException; +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.match.GameObjectMatcher; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * An {@link Iterator} that filters another iterator according to a {@link + * GameObjectMatcher}. Only game objects matching the matcher are returned. + * @author Andreas Kirschbaum + */ +public class FilterGameObjectIterator<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements Iterator<G> { + + /** + * The {@link Iterator} being filtered. + */ + @NotNull + private final Iterator<G> iterator; + + /** + * The {@link GameObjectMatcher} for filtering returned game objects. + */ + @NotNull + private final GameObjectMatcher matcher; + + /** + * The next element to return from {@link #next()} or <code>null</code> if + * no next element exists. Only valid if {@link #findNextPending} is set. + */ + @Nullable + private G next; + + /** + * Whether {@link #findNext()} has to be called. + */ + private boolean findNextPending = true; + + /** + * Creates a new instance. + * @param iterator the iterator to filter + * @param matcher the game object matcher to filter with + */ + public FilterGameObjectIterator(@NotNull final Iterator<G> iterator, @NotNull final GameObjectMatcher matcher) { + this.iterator = iterator; + this.matcher = matcher; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean hasNext() { + findNext(); + return next != null; + } + + /** + * {@inheritDoc} + */ + @Override + public G next() { + findNext(); + if (next == null) { + throw new NoSuchElementException(); + } + findNextPending = true; + return next; + } + + /** + * {@inheritDoc} + */ + @Override + public void remove() { + if (findNextPending) { + throw new IllegalStateException(); + } + findNextPending = true; + iterator.remove(); + } + + /** + * Updates {@link #next} to hold the next matching game object. Does nothing + * unless {@link #findNextPending} is set. + */ + private void findNext() { + if (!findNextPending) { + return; + } + findNextPending = false; + + while (true) { + if (!iterator.hasNext()) { + next = null; + return; + } + + final G tmp = iterator.next(); + if (matcher.isMatching(tmp)) { + next = tmp; + return; + } + } + } + +} Property changes on: trunk/model/src/app/net/sf/gridarta/model/mapmodel/FilterGameObjectIterator.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Added: trunk/model/src/test/net/sf/gridarta/model/mapmodel/FilterGameObjectIteratorTest.java =================================================================== --- trunk/model/src/test/net/sf/gridarta/model/mapmodel/FilterGameObjectIteratorTest.java (rev 0) +++ trunk/model/src/test/net/sf/gridarta/model/mapmodel/FilterGameObjectIteratorTest.java 2011-10-19 06:14:11 UTC (rev 9066) @@ -0,0 +1,201 @@ +/* + * 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.mapmodel; + +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.NoSuchElementException; +import net.sf.gridarta.model.archetype.TestArchetype; +import net.sf.gridarta.model.gameobject.GameObject; +import net.sf.gridarta.model.gameobject.TestGameObject; +import net.sf.gridarta.model.maparchobject.TestMapArchObject; +import net.sf.gridarta.model.match.GameObjectMatcher; +import org.jetbrains.annotations.NotNull; +import org.junit.Assert; +import org.junit.Test; + +/** + * Regression tests for {@link FilterGameObjectIterator}. + * @author Andreas Kirschbaum + */ +public class FilterGameObjectIteratorTest { + + /** + * Checks that an empty iterator is filtered correctly. + */ + @Test + public void testEmptyIterator() { + check(new AcceptAllMatcher(), new ArrayGameObjectIterator()); + } + + /** + * Checks that a matcher that accepts all game objects returns all game + * objects. + */ + @Test + public void testAllMatcher() { + final TestMapModelCreator creator = new TestMapModelCreator(false); + final TestGameObject o1 = creator.newGameObject("arch", "o1"); + final TestGameObject o2 = creator.newGameObject("arch", "o2"); + final TestGameObject o3 = creator.newGameObject("arch", "o3"); + check(new AcceptAllMatcher(), new ArrayGameObjectIterator(o1, o2, o3), o1, o2, o3); + } + + /** + * Checks that a matcher that accepts some game objects returns only the + * accepted game objects. + */ + @Test + public void testAcceptMatcher() { + final TestMapModelCreator creator = new TestMapModelCreator(false); + final TestGameObject o1 = creator.newGameObject("arch", "o1"); + final TestGameObject o2 = creator.newGameObject("arch", "o2"); + final TestGameObject o3 = creator.newGameObject("arch", "o3"); + check(new AcceptMatcher(o1, o2), new ArrayGameObjectIterator(o1, o2, o3, o1, o2, o3, o1, o1, o2, o3, o3), o1, o2, o1, o2, o1, o1, o2); + } + + /** + * Creates a new {@link FilterGameObjectIterator} instance and checks that + * it returns the expected game objects. + * @param matcher the matcher for the filter game object iterator + * @param iterator the underlying iterator for the filter game object + * iterator + * @param gameObjects the expected game objects to be returned from the + * filter game object iterator + */ + private static void check(@NotNull final GameObjectMatcher matcher, @NotNull final Iterator<TestGameObject> iterator, @NotNull final TestGameObject... gameObjects) { + final Iterator<TestGameObject> filterGameObjectIterator = new FilterGameObjectIterator<TestGameObject, TestMapArchObject, TestArchetype>(iterator, matcher); + for (final TestGameObject gameObject : gameObjects) { + Assert.assertTrue(filterGameObjectIterator.hasNext()); + Assert.assertSame(gameObject, filterGameObjectIterator.next()); + } + Assert.assertFalse(filterGameObjectIterator.hasNext()); + } + + /** + * A {@link GameObjectMatcher} that accepts all game objects. + */ + private static class AcceptAllMatcher implements GameObjectMatcher { + + /** + * The serial version UID. + */ + private static final long serialVersionUID = 1L; + + /** + * {@inheritDoc} + */ + @Override + public boolean isMatching(@NotNull final GameObject<?, ?, ?> gameObject) { + return true; + } + + } + + /** + * A {@link GameObjectMatcher} that accepts a set of game objects. + */ + private static class AcceptMatcher implements GameObjectMatcher { + + /** + * The serial version UID. + */ + private static final long serialVersionUID = 1L; + + /** + * The accepted game objects. + */ + @NotNull + private final Collection<GameObject<?, ?, ?>> gameObjects = new HashSet<GameObject<?, ?, ?>>(); + + /** + * Creates a new instance. + * @param gameObjects the game objects to accept + */ + private AcceptMatcher(@NotNull final GameObject<?, ?, ?>... gameObjects) { + this.gameObjects.addAll(Arrays.asList(gameObjects)); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isMatching(@NotNull final GameObject<?, ?, ?> gameObject) { + return gameObjects.contains(gameObject); + } + + } + + /** + * An {@link Iterator} that returns a fixed list of {@link GameObject + * GameObjects}. + */ + private static class ArrayGameObjectIterator implements Iterator<TestGameObject> { + + /** + * The {@link GameObject GameObjects} to return. + */ + @NotNull + private final TestGameObject[] gameObjects; + + /** + * The current index into {@link #gameObjects}. + */ + private int index; + + /** + * Creates a new instance. + * @param gameObjects the game objects to return + */ + private ArrayGameObjectIterator(@NotNull final TestGameObject... gameObjects) { + this.gameObjects = gameObjects.clone(); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean hasNext() { + return index < gameObjects.length; + } + + /** + * {@inheritDoc} + */ + @Override + public TestGameObject next() { + if (index >= gameObjects.length) { + throw new NoSuchElementException(); + } + return gameObjects[index++]; + } + + /** + * {@inheritDoc} + */ + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + + } +} Property changes on: trunk/model/src/test/net/sf/gridarta/model/mapmodel/FilterGameObjectIteratorTest.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Modified: trunk/model/src/test/net/sf/gridarta/model/mapmodel/TestMapModelCreator.java =================================================================== --- trunk/model/src/test/net/sf/gridarta/model/mapmodel/TestMapModelCreator.java 2011-10-19 05:44:41 UTC (rev 9065) +++ trunk/model/src/test/net/sf/gridarta/model/mapmodel/TestMapModelCreator.java 2011-10-19 06:14:11 UTC (rev 9066) @@ -169,7 +169,7 @@ * @return the game object */ @NotNull - private TestGameObject newGameObject(@NotNull final String archetypeName, @NotNull final String objectName) { + public TestGameObject newGameObject(@NotNull final String archetypeName, @NotNull final String objectName) { final TestArchetype archetype = getArchetype(archetypeName); final TestGameObject gameObject = new TestGameObject(archetype, faceObjectProviders, animationObjects); gameObject.setAttributeString(BaseObject.NAME, objectName); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2011-10-19 05:44:48
|
Revision: 9065 http://gridarta.svn.sourceforge.net/gridarta/?rev=9065&view=rev Author: akirschbaum Date: 2011-10-19 05:44:41 +0000 (Wed, 19 Oct 2011) Log Message: ----------- Whitespace changes. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/gui/map/mapactions/MapActions.java 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-18 21:16:28 UTC (rev 9064) +++ trunk/src/app/net/sf/gridarta/gui/map/mapactions/MapActions.java 2011-10-19 05:44:41 UTC (rev 9065) @@ -580,7 +580,7 @@ final ExitIterator<G, A, R> exitIterator = new ExitIterator<G, A, R>(exitMatcher, mapModel, xStart, yStart, direction); if (exitIterator.hasNext()) { final G exit = exitIterator.next(); - final MapSquare<G,A,R> mapSquare = exit.getMapSquare(); + final MapSquare<G, A, R> mapSquare = exit.getMapSquare(); assert mapSquare != null; mapView.setCursorLocation(mapSquare.getMapLocation()); } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2011-10-18 21:16:35
|
Revision: 9064 http://gridarta.svn.sourceforge.net/gridarta/?rev=9064&view=rev Author: akirschbaum Date: 2011-10-18 21:16:28 +0000 (Tue, 18 Oct 2011) Log Message: ----------- Add TopLevelGameObjectIterator. Added Paths: ----------- trunk/model/src/app/net/sf/gridarta/model/mapmodel/TopLevelGameObjectIterator.java trunk/model/src/test/net/sf/gridarta/model/mapmodel/TopLevelGameObjectIteratorTest.java Added: trunk/model/src/app/net/sf/gridarta/model/mapmodel/TopLevelGameObjectIterator.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/mapmodel/TopLevelGameObjectIterator.java (rev 0) +++ trunk/model/src/app/net/sf/gridarta/model/mapmodel/TopLevelGameObjectIterator.java 2011-10-18 21:16:28 UTC (rev 9064) @@ -0,0 +1,126 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2010 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.mapmodel; + +import java.awt.Point; +import java.util.Iterator; +import java.util.NoSuchElementException; +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; + +/** + * Iterator for iterating over top-level game object of a map model. + * @author Andreas Kirschbaum + */ +public class TopLevelGameObjectIterator<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements Iterator<G> { + + /** + * The {@link Iterator} returning all {@link MapSquare MapSquares} to + * consider. + */ + @NotNull + private final Iterator<MapSquare<G, A, R>> mapSquareIterator; + + /** + * The {@link Iterator} returning all top-level game objects in the current + * map square or <code>null</code> if no more top-level game objects exist. + */ + @Nullable + private Iterator<G> gameObjectIterator; + + /** + * The {@link GameObject} to return from the next call to {@link #next()} or + * <code>null</code> if no next game object exists. + */ + @Nullable + private G gameObject; + + /** + * Creates a new instance. + * @param mapModel the map model to iterate over + * @param start the starting point or <code>null</code> for default + * @param direction the direction to iterate: <code>+1</code> for forward, + * <code>-1</code> for backward + */ + public TopLevelGameObjectIterator(@NotNull final MapModel<G, A, R> mapModel, @Nullable final Point start, final int direction) { + mapSquareIterator = new MapSquareIterator<G, A, R>(mapModel, start, direction); + findNext(); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean hasNext() { + return gameObject != null; + } + + /** + * {@inheritDoc} + */ + @NotNull + @Override + public G next() { + final G result = gameObject; + if (result == null) { + throw new NoSuchElementException(); + } + findNext(); + return result; + } + + /** + * {@inheritDoc} + */ + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + + /** + * Updates {@link #gameObject} to contain the next top-level game object. + */ + private void findNext() { + while (true) { + if (gameObjectIterator != null) { + if (gameObjectIterator.hasNext()) { + assert gameObjectIterator != null; + gameObject = gameObjectIterator.next(); + return; + } + gameObjectIterator = null; + } + + if (!mapSquareIterator.hasNext()) { + gameObject = null; + return; + } + + final MapSquare<G, A, R> mapSquare = mapSquareIterator.next(); + if (!mapSquare.isEmpty()) { + gameObjectIterator = mapSquare.iterator(); + } + } + } + +} // class TopLevelGameObjectIterator Property changes on: trunk/model/src/app/net/sf/gridarta/model/mapmodel/TopLevelGameObjectIterator.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Added: trunk/model/src/test/net/sf/gridarta/model/mapmodel/TopLevelGameObjectIteratorTest.java =================================================================== --- trunk/model/src/test/net/sf/gridarta/model/mapmodel/TopLevelGameObjectIteratorTest.java (rev 0) +++ trunk/model/src/test/net/sf/gridarta/model/mapmodel/TopLevelGameObjectIteratorTest.java 2011-10-18 21:16:28 UTC (rev 9064) @@ -0,0 +1,120 @@ +/* + * 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.mapmodel; + +import java.awt.Point; +import java.util.Iterator; +import net.sf.gridarta.model.archetype.TestArchetype; +import net.sf.gridarta.model.gameobject.TestGameObject; +import net.sf.gridarta.model.maparchobject.TestMapArchObject; +import org.jetbrains.annotations.NotNull; +import org.junit.Assert; +import org.junit.Test; + +/** + * Regression tests for {@link TopLevelGameObjectIterator}. + * @author Andreas Kirschbaum + */ +public class TopLevelGameObjectIteratorTest { + + /** + * Checks the forward iterator on an empty map. + */ + @Test + public void testIteratorForwardEmpty() { + final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false); + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(3, 2); + final Iterator<TestGameObject> it = new TopLevelGameObjectIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, new Point(1, 1), +1); + Assert.assertFalse(it.hasNext()); + } + + /** + * Checks the backward iterator on an empty map. + */ + @Test + public void testIteratorBackwardEmpty() { + final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false); + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(3, 2); + final Iterator<TestGameObject> it = new TopLevelGameObjectIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, new Point(1, 1), -1); + Assert.assertFalse(it.hasNext()); + } + + /** + * Checks the forward iterator. + */ + @Test + public void testIteratorForward() { + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = createMap(); + final Iterator<TestGameObject> it = new TopLevelGameObjectIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, new Point(1, 1), +1); + Assert.assertTrue(it.hasNext()); + Assert.assertEquals("n4", it.next().getBestName()); + Assert.assertTrue(it.hasNext()); + Assert.assertEquals("n5", it.next().getBestName()); + Assert.assertTrue(it.hasNext()); + Assert.assertEquals("n1", it.next().getBestName()); + Assert.assertTrue(it.hasNext()); + Assert.assertEquals("n2", it.next().getBestName()); + Assert.assertTrue(it.hasNext()); + Assert.assertEquals("n3", it.next().getBestName()); + Assert.assertFalse(it.hasNext()); + } + + /** + * Checks the backward iterator. + */ + @Test + public void testIteratorBackward() { + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = createMap(); + final Iterator<TestGameObject> it = new TopLevelGameObjectIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, new Point(1, 1), -1); + Assert.assertTrue(it.hasNext()); + Assert.assertEquals("n4", it.next().getBestName()); + Assert.assertTrue(it.hasNext()); + Assert.assertEquals("n3", it.next().getBestName()); + Assert.assertTrue(it.hasNext()); + Assert.assertEquals("n1", it.next().getBestName()); + Assert.assertTrue(it.hasNext()); + Assert.assertEquals("n2", it.next().getBestName()); + Assert.assertTrue(it.hasNext()); + Assert.assertEquals("n5", it.next().getBestName()); + Assert.assertFalse(it.hasNext()); + } + + /** + * Creates a new {@link MapModel} instance filled with game objects. + * @return the new map model instance + */ + @NotNull + private static MapModel<TestGameObject, TestMapArchObject, TestArchetype> createMap() { + final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false); + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(3, 2); + final InsertionMode<TestGameObject, TestMapArchObject, TestArchetype> insertionMode = mapModelCreator.getTopmostInsertionMode(); + mapModelCreator.addGameObjectToMap(mapModel, "arch", "n1", 0, 0, insertionMode); + mapModelCreator.addGameObjectToMap(mapModel, "arch", "n2", 0, 0, insertionMode); + mapModelCreator.addGameObjectToMap(mapModel, "arch", "n3", 2, 0, insertionMode); + mapModelCreator.addGameObjectToMap(mapModel, "arch", "n4", 1, 1, insertionMode); + mapModelCreator.addGameObjectToMap(mapModel, "arch", "n5", 2, 1, insertionMode); + + //noinspection ConstantConditions + mapModelCreator.insertGameObject(mapModel.getMapSquare(new Point(2, 0)).getFirst(), "arch", "i1"); + + return mapModel; + } + +} Property changes on: trunk/model/src/test/net/sf/gridarta/model/mapmodel/TopLevelGameObjectIteratorTest.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-10-18 20:41:20
|
Revision: 9063 http://gridarta.svn.sourceforge.net/gridarta/?rev=9063&view=rev Author: akirschbaum Date: 2011-10-18 20:41:13 +0000 (Tue, 18 Oct 2011) Log Message: ----------- Support starting point in MapSquareIterator. Modified Paths: -------------- trunk/model/src/app/net/sf/gridarta/model/mapmodel/DefaultMapModel.java trunk/model/src/app/net/sf/gridarta/model/mapmodel/MapSquareIterator.java trunk/model/src/test/net/sf/gridarta/model/mapmodel/MapSquareIteratorTest.java Modified: trunk/model/src/app/net/sf/gridarta/model/mapmodel/DefaultMapModel.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/mapmodel/DefaultMapModel.java 2011-10-18 20:37:07 UTC (rev 9062) +++ trunk/model/src/app/net/sf/gridarta/model/mapmodel/DefaultMapModel.java 2011-10-18 20:41:13 UTC (rev 9063) @@ -263,7 +263,7 @@ */ @Override public Iterator<MapSquare<G, A, R>> iterator() { - return new MapSquareIterator<G, A, R>(this, 1); + return new MapSquareIterator<G, A, R>(this, null, 1); } /** Modified: trunk/model/src/app/net/sf/gridarta/model/mapmodel/MapSquareIterator.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/mapmodel/MapSquareIterator.java 2011-10-18 20:37:07 UTC (rev 9062) +++ trunk/model/src/app/net/sf/gridarta/model/mapmodel/MapSquareIterator.java 2011-10-18 20:41:13 UTC (rev 9063) @@ -27,6 +27,7 @@ import net.sf.gridarta.model.maparchobject.MapArchObject; import net.sf.gridarta.utils.Size2D; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * Iterator for iterating over all squares of a model. @@ -72,10 +73,11 @@ /** * Creates a new instance. * @param mapModel the map model to iterate over + * @param start the starting point or <code>null</code> for default * @param direction the direction to iterate: <code>+1</code> for forward, * <code>-1</code> for backward */ - public MapSquareIterator(@NotNull final MapModel<G, A, R> mapModel, final int direction) { + public MapSquareIterator(@NotNull final MapModel<G, A, R> mapModel, @Nullable final Point start, final int direction) { if (direction != -1 && direction != +1) { throw new IllegalArgumentException(); } @@ -84,7 +86,13 @@ final Size2D mapSize = mapModel.getMapArchObject().getMapSize(); mapWidth = mapSize.getWidth(); mapHeight = mapSize.getHeight(); - point = direction > 0 ? 0 : mapWidth * mapHeight - 1; + if (start != null) { + point = start.x + start.y * mapWidth; + } else if (direction > 0) { + point = 0; + } else { + point = mapWidth * mapHeight - 1; + } remainingMapSquares = mapWidth * mapHeight; } Modified: trunk/model/src/test/net/sf/gridarta/model/mapmodel/MapSquareIteratorTest.java =================================================================== --- trunk/model/src/test/net/sf/gridarta/model/mapmodel/MapSquareIteratorTest.java 2011-10-18 20:37:07 UTC (rev 9062) +++ trunk/model/src/test/net/sf/gridarta/model/mapmodel/MapSquareIteratorTest.java 2011-10-18 20:41:13 UTC (rev 9063) @@ -40,7 +40,7 @@ public void testIteratorForward() { final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false); final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(3, 2); - final Iterator<MapSquare<TestGameObject, TestMapArchObject, TestArchetype>> it = new MapSquareIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, +1); + final Iterator<MapSquare<TestGameObject, TestMapArchObject, TestArchetype>> it = new MapSquareIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, null, +1); Assert.assertTrue(it.hasNext()); Assert.assertSame(mapModel.getMapSquare(new Point(0, 0)), it.next()); Assert.assertTrue(it.hasNext()); @@ -63,7 +63,7 @@ public void testIteratorBackward() { final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false); final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(3, 2); - final Iterator<MapSquare<TestGameObject, TestMapArchObject, TestArchetype>> it = new MapSquareIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, -1); + final Iterator<MapSquare<TestGameObject, TestMapArchObject, TestArchetype>> it = new MapSquareIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, null, -1); Assert.assertTrue(it.hasNext()); Assert.assertSame(mapModel.getMapSquare(new Point(2, 1)), it.next()); Assert.assertTrue(it.hasNext()); @@ -80,13 +80,59 @@ } /** + * Checks that the forward iterator returns all map squares. + */ + @Test + public void testIteratorForwardStart() { + final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false); + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(3, 2); + final Iterator<MapSquare<TestGameObject, TestMapArchObject, TestArchetype>> it = new MapSquareIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, new Point(0, 1), +1); + Assert.assertTrue(it.hasNext()); + Assert.assertSame(mapModel.getMapSquare(new Point(0, 1)), it.next()); + Assert.assertTrue(it.hasNext()); + Assert.assertSame(mapModel.getMapSquare(new Point(1, 1)), it.next()); + Assert.assertTrue(it.hasNext()); + Assert.assertSame(mapModel.getMapSquare(new Point(2, 1)), it.next()); + Assert.assertTrue(it.hasNext()); + Assert.assertSame(mapModel.getMapSquare(new Point(0, 0)), it.next()); + Assert.assertTrue(it.hasNext()); + Assert.assertSame(mapModel.getMapSquare(new Point(1, 0)), it.next()); + Assert.assertTrue(it.hasNext()); + Assert.assertSame(mapModel.getMapSquare(new Point(2, 0)), it.next()); + Assert.assertFalse(it.hasNext()); + } + + /** + * Checks that the backward iterator returns all map squares. + */ + @Test + public void testIteratorBackwardStart() { + final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false); + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(3, 2); + final Iterator<MapSquare<TestGameObject, TestMapArchObject, TestArchetype>> it = new MapSquareIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, new Point(0, 1), -1); + Assert.assertTrue(it.hasNext()); + Assert.assertSame(mapModel.getMapSquare(new Point(0, 1)), it.next()); + Assert.assertTrue(it.hasNext()); + Assert.assertSame(mapModel.getMapSquare(new Point(2, 0)), it.next()); + Assert.assertTrue(it.hasNext()); + Assert.assertSame(mapModel.getMapSquare(new Point(1, 0)), it.next()); + Assert.assertTrue(it.hasNext()); + Assert.assertSame(mapModel.getMapSquare(new Point(0, 0)), it.next()); + Assert.assertTrue(it.hasNext()); + Assert.assertSame(mapModel.getMapSquare(new Point(2, 1)), it.next()); + Assert.assertTrue(it.hasNext()); + Assert.assertSame(mapModel.getMapSquare(new Point(1, 1)), it.next()); + Assert.assertFalse(it.hasNext()); + } + + /** * Checks that invalid directions are rejected. */ @Test(expected = IllegalArgumentException.class) public void testIteratorDirection0() { final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false); final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(3, 2); - final Iterator<MapSquare<TestGameObject, TestMapArchObject, TestArchetype>> it = new MapSquareIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, 0); + final Iterator<MapSquare<TestGameObject, TestMapArchObject, TestArchetype>> it = new MapSquareIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, null, 0); } /** @@ -96,7 +142,7 @@ public void testIteratorDirection2() { final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false); final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(3, 2); - final Iterator<MapSquare<TestGameObject, TestMapArchObject, TestArchetype>> it = new MapSquareIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, 2); + final Iterator<MapSquare<TestGameObject, TestMapArchObject, TestArchetype>> it = new MapSquareIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, null, 2); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2011-10-18 20:37:14
|
Revision: 9062 http://gridarta.svn.sourceforge.net/gridarta/?rev=9062&view=rev Author: akirschbaum Date: 2011-10-18 20:37:07 +0000 (Tue, 18 Oct 2011) Log Message: ----------- Support iteration direction in MapSquareIterator. Modified Paths: -------------- trunk/model/src/app/net/sf/gridarta/model/mapmodel/DefaultMapModel.java trunk/model/src/app/net/sf/gridarta/model/mapmodel/MapSquareIterator.java trunk/model/src/test/net/sf/gridarta/model/mapmodel/MapSquareIteratorTest.java Modified: trunk/model/src/app/net/sf/gridarta/model/mapmodel/DefaultMapModel.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/mapmodel/DefaultMapModel.java 2011-10-18 20:25:18 UTC (rev 9061) +++ trunk/model/src/app/net/sf/gridarta/model/mapmodel/DefaultMapModel.java 2011-10-18 20:37:07 UTC (rev 9062) @@ -263,7 +263,7 @@ */ @Override public Iterator<MapSquare<G, A, R>> iterator() { - return new MapSquareIterator<G, A, R>(this); + return new MapSquareIterator<G, A, R>(this, 1); } /** Modified: trunk/model/src/app/net/sf/gridarta/model/mapmodel/MapSquareIterator.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/mapmodel/MapSquareIterator.java 2011-10-18 20:25:18 UTC (rev 9061) +++ trunk/model/src/app/net/sf/gridarta/model/mapmodel/MapSquareIterator.java 2011-10-18 20:37:07 UTC (rev 9062) @@ -42,6 +42,12 @@ private final MapModel<G, A, R> mapModel; /** + * The direction to iterate: <code>+1</code> for forward, <code>-1</code> + * for backward. + */ + private final int direction; + + /** * The {@link #mapModel}'s map width. */ private final int mapWidth; @@ -56,17 +62,30 @@ * two dimensional array. That works fine because the two dimensional array * is a rectangular array. */ - private int point = 0; + private int point; /** + * The number of remaining map square to return from {@link #next()}. + */ + private int remainingMapSquares; + + /** * Creates a new instance. * @param mapModel the map model to iterate over + * @param direction the direction to iterate: <code>+1</code> for forward, + * <code>-1</code> for backward */ - MapSquareIterator(@NotNull final MapModel<G, A, R> mapModel) { + public MapSquareIterator(@NotNull final MapModel<G, A, R> mapModel, final int direction) { + if (direction != -1 && direction != +1) { + throw new IllegalArgumentException(); + } this.mapModel = mapModel; + this.direction = direction; final Size2D mapSize = mapModel.getMapArchObject().getMapSize(); mapWidth = mapSize.getWidth(); mapHeight = mapSize.getHeight(); + point = direction > 0 ? 0 : mapWidth * mapHeight - 1; + remainingMapSquares = mapWidth * mapHeight; } /** @@ -82,7 +101,7 @@ */ @Override public boolean hasNext() { - return point < mapWidth * mapHeight; + return remainingMapSquares > 0; } /** @@ -90,15 +109,19 @@ */ @Override public MapSquare<G, A, R> next() { - try { - final MapSquare<G, A, R> square = mapModel.getMapSquare(new Point(point % mapWidth, point / mapWidth)); - point++; - return square; - } catch (final IndexOutOfBoundsException ignore) { - //There is no constructor that takes a cause. - //noinspection ThrowInsideCatchBlockWhichIgnoresCaughtException + if (remainingMapSquares <= 0) { throw new NoSuchElementException(); } + remainingMapSquares--; + + final MapSquare<G, A, R> square = mapModel.getMapSquare(new Point(point % mapWidth, point / mapWidth)); + point += direction; + if (point < 0) { + point += mapWidth * mapHeight; + } else if (point >= mapWidth * mapHeight) { + point -= mapWidth * mapHeight; + } + return square; } } // class MapSquareIterator Modified: trunk/model/src/test/net/sf/gridarta/model/mapmodel/MapSquareIteratorTest.java =================================================================== --- trunk/model/src/test/net/sf/gridarta/model/mapmodel/MapSquareIteratorTest.java 2011-10-18 20:25:18 UTC (rev 9061) +++ trunk/model/src/test/net/sf/gridarta/model/mapmodel/MapSquareIteratorTest.java 2011-10-18 20:37:07 UTC (rev 9062) @@ -34,13 +34,13 @@ public class MapSquareIteratorTest { /** - * Checks that the iterator returns all map squares. + * Checks that the forward iterator returns all map squares. */ @Test - public void testIterator1() { + public void testIteratorForward() { final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false); final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(3, 2); - final Iterator<MapSquare<TestGameObject, TestMapArchObject, TestArchetype>> it = new MapSquareIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel); + final Iterator<MapSquare<TestGameObject, TestMapArchObject, TestArchetype>> it = new MapSquareIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, +1); Assert.assertTrue(it.hasNext()); Assert.assertSame(mapModel.getMapSquare(new Point(0, 0)), it.next()); Assert.assertTrue(it.hasNext()); @@ -56,4 +56,47 @@ Assert.assertFalse(it.hasNext()); } + /** + * Checks that the backward iterator returns all map squares. + */ + @Test + public void testIteratorBackward() { + final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false); + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(3, 2); + final Iterator<MapSquare<TestGameObject, TestMapArchObject, TestArchetype>> it = new MapSquareIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, -1); + Assert.assertTrue(it.hasNext()); + Assert.assertSame(mapModel.getMapSquare(new Point(2, 1)), it.next()); + Assert.assertTrue(it.hasNext()); + Assert.assertSame(mapModel.getMapSquare(new Point(1, 1)), it.next()); + Assert.assertTrue(it.hasNext()); + Assert.assertSame(mapModel.getMapSquare(new Point(0, 1)), it.next()); + Assert.assertTrue(it.hasNext()); + Assert.assertSame(mapModel.getMapSquare(new Point(2, 0)), it.next()); + Assert.assertTrue(it.hasNext()); + Assert.assertSame(mapModel.getMapSquare(new Point(1, 0)), it.next()); + Assert.assertTrue(it.hasNext()); + Assert.assertSame(mapModel.getMapSquare(new Point(0, 0)), it.next()); + Assert.assertFalse(it.hasNext()); + } + + /** + * Checks that invalid directions are rejected. + */ + @Test(expected = IllegalArgumentException.class) + public void testIteratorDirection0() { + final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false); + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(3, 2); + final Iterator<MapSquare<TestGameObject, TestMapArchObject, TestArchetype>> it = new MapSquareIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, 0); + } + + /** + * Checks that invalid directions are rejected. + */ + @Test(expected = IllegalArgumentException.class) + public void testIteratorDirection2() { + final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false); + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(3, 2); + final Iterator<MapSquare<TestGameObject, TestMapArchObject, TestArchetype>> it = new MapSquareIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel, 2); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2011-10-18 20:25:25
|
Revision: 9061 http://gridarta.svn.sourceforge.net/gridarta/?rev=9061&view=rev Author: akirschbaum Date: 2011-10-18 20:25:18 +0000 (Tue, 18 Oct 2011) Log Message: ----------- Add test for MapSquareIterator. Added Paths: ----------- trunk/model/src/test/net/sf/gridarta/model/mapmodel/MapSquareIteratorTest.java Added: trunk/model/src/test/net/sf/gridarta/model/mapmodel/MapSquareIteratorTest.java =================================================================== --- trunk/model/src/test/net/sf/gridarta/model/mapmodel/MapSquareIteratorTest.java (rev 0) +++ trunk/model/src/test/net/sf/gridarta/model/mapmodel/MapSquareIteratorTest.java 2011-10-18 20:25:18 UTC (rev 9061) @@ -0,0 +1,59 @@ +/* + * 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.mapmodel; + +import java.awt.Point; +import java.util.Iterator; +import net.sf.gridarta.model.archetype.TestArchetype; +import net.sf.gridarta.model.gameobject.TestGameObject; +import net.sf.gridarta.model.maparchobject.TestMapArchObject; +import org.junit.Assert; +import org.junit.Test; + +/** + * Regression tests for {@link MapSquareIterator}. + * @author Andreas Kirschbaum + */ +public class MapSquareIteratorTest { + + /** + * Checks that the iterator returns all map squares. + */ + @Test + public void testIterator1() { + final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false); + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(3, 2); + final Iterator<MapSquare<TestGameObject, TestMapArchObject, TestArchetype>> it = new MapSquareIterator<TestGameObject, TestMapArchObject, TestArchetype>(mapModel); + Assert.assertTrue(it.hasNext()); + Assert.assertSame(mapModel.getMapSquare(new Point(0, 0)), it.next()); + Assert.assertTrue(it.hasNext()); + Assert.assertSame(mapModel.getMapSquare(new Point(1, 0)), it.next()); + Assert.assertTrue(it.hasNext()); + Assert.assertSame(mapModel.getMapSquare(new Point(2, 0)), it.next()); + Assert.assertTrue(it.hasNext()); + Assert.assertSame(mapModel.getMapSquare(new Point(0, 1)), it.next()); + Assert.assertTrue(it.hasNext()); + Assert.assertSame(mapModel.getMapSquare(new Point(1, 1)), it.next()); + Assert.assertTrue(it.hasNext()); + Assert.assertSame(mapModel.getMapSquare(new Point(2, 1)), it.next()); + Assert.assertFalse(it.hasNext()); + } + +} Property changes on: trunk/model/src/test/net/sf/gridarta/model/mapmodel/MapSquareIteratorTest.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. |