From: <aki...@us...> - 2010-04-27 20:14:14
|
Revision: 7645 http://gridarta.svn.sourceforge.net/gridarta/?rev=7645&view=rev Author: akirschbaum Date: 2010-04-27 20:14:08 +0000 (Tue, 27 Apr 2010) Log Message: ----------- Remove MapModel.insertArchetype(). Modified Paths: -------------- trunk/src/app/net/sf/gridarta/exitconnector/ExitConnectorActions.java trunk/src/app/net/sf/gridarta/gui/archetypechooser/ArchetypeChooserControl.java trunk/src/app/net/sf/gridarta/gui/replacedialog/ReplaceDialog.java trunk/src/app/net/sf/gridarta/gui/replacedialog/ReplaceDialogManager.java trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java trunk/src/app/net/sf/gridarta/model/map/mapmodel/DefaultMapModel.java trunk/src/app/net/sf/gridarta/model/map/mapmodel/MapModel.java trunk/src/test/net/sf/gridarta/exitconnector/ExitConnectorActionsTest.java trunk/src/test/net/sf/gridarta/model/map/mapmodel/DefaultMapModelTest.java Modified: trunk/src/app/net/sf/gridarta/exitconnector/ExitConnectorActions.java =================================================================== --- trunk/src/app/net/sf/gridarta/exitconnector/ExitConnectorActions.java 2010-04-27 19:57:52 UTC (rev 7644) +++ trunk/src/app/net/sf/gridarta/exitconnector/ExitConnectorActions.java 2010-04-27 20:14:08 UTC (rev 7645) @@ -26,6 +26,7 @@ import net.sf.gridarta.mapmanager.MapManager; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.archetype.ArchetypeSet; +import net.sf.gridarta.model.archetypechooser.ArchetypeChooserModel; import net.sf.gridarta.model.baseobject.BaseObject; import net.sf.gridarta.model.exitconnector.ExitConnectorModel; import net.sf.gridarta.model.exitconnector.ExitLocation; @@ -89,6 +90,12 @@ private final InsertionModeSet<G, A, R> insertionModeSet; /** + * The {@link ArchetypeChooserModel} to use. + */ + @NotNull + private final ArchetypeChooserModel<G, A, R> archetypeChooserModel; + + /** * Creates a new instance. * @param exitConnectorModel the exit connector model to use * @param exitMatcher the exit matcher to use @@ -97,8 +104,9 @@ * @param fileControl the file control to use * @param pathManager the path manager for converting path names * @param insertionModeSet the insertion mode set to use + * @param archetypeChooserModel the archetype chooser model to use */ - public ExitConnectorActions(@NotNull final ExitConnectorModel exitConnectorModel, @NotNull final ExitMatcher<G, A, R> exitMatcher, @NotNull final ArchetypeSet<G, A, R> archetypeSet, @NotNull final MapManager<G, A, R> mapManager, @NotNull final FileControl<G, A, R> fileControl, @NotNull final PathManager pathManager, @NotNull final InsertionModeSet<G, A, R> insertionModeSet) { + public ExitConnectorActions(@NotNull final ExitConnectorModel exitConnectorModel, @NotNull final ExitMatcher<G, A, R> exitMatcher, @NotNull final ArchetypeSet<G, A, R> archetypeSet, @NotNull final MapManager<G, A, R> mapManager, @NotNull final FileControl<G, A, R> fileControl, @NotNull final PathManager pathManager, @NotNull final InsertionModeSet<G, A, R> insertionModeSet, @NotNull final ArchetypeChooserModel<G, A, R> archetypeChooserModel) { this.exitConnectorModel = exitConnectorModel; this.exitMatcher = exitMatcher; this.archetypeSet = archetypeSet; @@ -106,6 +114,7 @@ this.fileControl = fileControl; this.pathManager = pathManager; this.insertionModeSet = insertionModeSet; + this.archetypeChooserModel = archetypeChooserModel; } /** @@ -168,7 +177,7 @@ } else { // paste into newly created exit game object - final R targetArchetype = archetypeSet.getArchetype(exitConnectorModel.getExitArchetypeName()); + final BaseObject<G, A, R, ?> targetArchetype = archetypeSet.getArchetype(exitConnectorModel.getExitArchetypeName()); if (targetArchetype == null) { return false; } @@ -204,7 +213,7 @@ } @Nullable final BaseObject<G, A, R, ?> targetExit; - @Nullable final R targetArchetype; + @Nullable final BaseObject<G, A, R, ?> targetArchetype; //XXX final G selectedExit = exitMatcher.getValidExit(selectedSquareModel.getSelectedGameObject()); //XXX if (selectedExit != null) { //XXX targetExit = selectedExit; @@ -259,7 +268,7 @@ * @param sourceExitLocation the source's exit location @return whether the action was or can be performed * @return whether the action was or can be performed */ - private boolean doExitConnect(final boolean performAction, @Nullable final BaseObject<?, ?, ?, ?> targetExit, @Nullable final R targetArchetype, @NotNull final MapModel<G, A, R> targetMapModel, @NotNull final Point targetLocation, @NotNull final File targetMapFile, @NotNull final MapModel<G, A, R> sourceMapModel, @NotNull final ExitLocation sourceExitLocation) { + private boolean doExitConnect(final boolean performAction, @Nullable final BaseObject<?, ?, ?, ?> targetExit, @Nullable final BaseObject<G, A, R, ?> targetArchetype, @NotNull final MapModel<G, A, R> targetMapModel, @NotNull final Point targetLocation, @NotNull final File targetMapFile, @NotNull final MapModel<G, A, R> sourceMapModel, @NotNull final ExitLocation sourceExitLocation) { final File sourceMapFile = sourceMapModel.getMapFile(); if (sourceMapFile == null) { // source map is unsaved ==> cannot connect @@ -269,7 +278,7 @@ final Point sourceLocation = sourceExitLocation.getMapCoordinate(); @Nullable final BaseObject<G, A, R, ?> sourceExit; - @Nullable final R sourceArchetype; + @Nullable final BaseObject<G, A, R, ?> sourceArchetype; final BaseObject<G, A, R, ?> exit = exitMatcher.getExit(sourceMapModel, sourceLocation); if (exit != null) { sourceExit = exit; @@ -330,10 +339,10 @@ * @param exitLocation the exit information to use * @return whether insertion was successful */ - private boolean pasteExit(@NotNull final Point location, @NotNull final MapModel<G, A, R> mapModel, @NotNull final R archetype, @NotNull final ExitLocation exitLocation) { + private boolean pasteExit(@NotNull final Point location, @NotNull final MapModel<G, A, R> mapModel, @NotNull final BaseObject<G, A, R, ?> archetype, @NotNull final ExitLocation exitLocation) { mapModel.beginTransaction("paste exit"); try { - final BaseObject<G, A, R, ?> newExit = mapModel.insertArchetype(archetype, location, true, false, insertionModeSet.getTopmostInsertionMode()); + final BaseObject<G, A, R, ?> newExit = mapModel.insertBaseObject(archetype, location, true, false, insertionModeSet.getTopmostInsertionMode(), archetypeChooserModel.getDirection()); if (newExit == null) { return false; } Modified: trunk/src/app/net/sf/gridarta/gui/archetypechooser/ArchetypeChooserControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/archetypechooser/ArchetypeChooserControl.java 2010-04-27 19:57:52 UTC (rev 7644) +++ trunk/src/app/net/sf/gridarta/gui/archetypechooser/ArchetypeChooserControl.java 2010-04-27 20:14:08 UTC (rev 7645) @@ -33,6 +33,7 @@ import net.sf.gridarta.model.archetypechooser.ArchetypeChooserFolder; import net.sf.gridarta.model.archetypechooser.ArchetypeChooserModel; import net.sf.gridarta.model.archetypechooser.ArchetypeChooserPanel; +import net.sf.gridarta.model.baseobject.BaseObject; import net.sf.gridarta.model.face.FaceObjectProviders; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.map.maparchobject.MapArchObject; @@ -141,8 +142,8 @@ @Nullable @Override public G insertSelectedObject(@NotNull final MapModel<G, A, R> mapModel, @NotNull final Point pos, final boolean allowMany, @NotNull final InsertionMode<G, A, R> insertionMode) { - final R selectedArchetype = getSelection(); - return selectedArchetype == null ? null : mapModel.insertArchetype(selectedArchetype, pos, allowMany, true, insertionMode); + final BaseObject<G, A, R, ?> selectedArchetype = getSelection(); + return selectedArchetype == null ? null : mapModel.insertBaseObject(selectedArchetype, pos, allowMany, true, insertionMode, archetypeChooserModel.getDirection()); } /** {@inheritDoc} */ Modified: trunk/src/app/net/sf/gridarta/gui/replacedialog/ReplaceDialog.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/replacedialog/ReplaceDialog.java 2010-04-27 19:57:52 UTC (rev 7644) +++ trunk/src/app/net/sf/gridarta/gui/replacedialog/ReplaceDialog.java 2010-04-27 20:14:08 UTC (rev 7645) @@ -47,6 +47,7 @@ import net.sf.gridarta.gui.objectchooser.ObjectChooser; import net.sf.gridarta.gui.objectchooser.ObjectChooserListener; import net.sf.gridarta.model.archetype.Archetype; +import net.sf.gridarta.model.archetypechooser.ArchetypeChooserModel; import net.sf.gridarta.model.baseobject.BaseObject; import net.sf.gridarta.model.face.FaceObjectProviders; import net.sf.gridarta.model.gameobject.GameObject; @@ -112,6 +113,12 @@ private final InsertionModeSet<G, A, R> insertionModeSet; /** + * The {@link ArchetypeChooserModel} to use. + */ + @NotNull + private final ArchetypeChooserModel<G, A, R> archetypeChooserModel; + + /** * The dialog instance. */ private final JDialog dialog; @@ -208,9 +215,11 @@ * @param faceObjectProviders the face object providers for looking up * faces * @param insertionModeSet the insertion mode set to use + * @param archetypeChooserModel the archetype chooser model to use */ - public ReplaceDialog(@NotNull final Component parent, @NotNull final MapModel<G, A, R> copyBufferMapModel, @NotNull final ObjectChooser<G, A, R> objectChooser, @NotNull final FaceObjectProviders faceObjectProviders, @NotNull final InsertionModeSet<G, A, R> insertionModeSet) { + public ReplaceDialog(@NotNull final Component parent, @NotNull final MapModel<G, A, R> copyBufferMapModel, @NotNull final ObjectChooser<G, A, R> objectChooser, @NotNull final FaceObjectProviders faceObjectProviders, @NotNull final InsertionModeSet<G, A, R> insertionModeSet, @NotNull final ArchetypeChooserModel<G, A, R> archetypeChooserModel) { this.insertionModeSet = insertionModeSet; + this.archetypeChooserModel = archetypeChooserModel; dialog = createDialog(parent, ACTION_BUILDER.getString("replaceTitle")); dialog.setModal(false); dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); @@ -471,7 +480,7 @@ // insert replacement object if (randomArch.isMulti()) { // multi's cannot be inserted properly, so we just put them ontop - mapModel.insertArchetype(randomArch.getArchetype(), new Point(square.getMapX(), square.getMapY()), false, false, insertionModeSet.getTopmostInsertionMode()); + mapModel.insertBaseObject(randomArch.getArchetype(), new Point(square.getMapX(), square.getMapY()), false, false, insertionModeSet.getTopmostInsertionMode(), archetypeChooserModel.getDirection()); // TODO: if from pickmap it could have special attributes -> copy them } else { Modified: trunk/src/app/net/sf/gridarta/gui/replacedialog/ReplaceDialogManager.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/replacedialog/ReplaceDialogManager.java 2010-04-27 19:57:52 UTC (rev 7644) +++ trunk/src/app/net/sf/gridarta/gui/replacedialog/ReplaceDialogManager.java 2010-04-27 20:14:08 UTC (rev 7645) @@ -25,6 +25,7 @@ import net.sf.gridarta.gui.map.mapview.MapViewManagerListener; import net.sf.gridarta.gui.objectchooser.ObjectChooser; import net.sf.gridarta.model.archetype.Archetype; +import net.sf.gridarta.model.archetypechooser.ArchetypeChooserModel; import net.sf.gridarta.model.face.FaceObjectProviders; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.map.maparchobject.MapArchObject; @@ -68,6 +69,12 @@ @NotNull private final InsertionModeSet<G, A, R> insertionModeSet; + /** + * The {@link ArchetypeChooserModel} to use. + */ + @NotNull + private final ArchetypeChooserModel<G, A, R> archetypeChooserModel; + /** The map view manager listener to detect closed map views. */ private final MapViewManagerListener<G, A, R> mapViewManagerListener = new MapViewManagerListener<G, A, R>() { @@ -97,13 +104,15 @@ * @param faceObjectProviders the face object providers for looking up * faces * @param insertionModeSet the insertion mode set to use + * @param archetypeChooserModel the archetype chooser model to use */ - public ReplaceDialogManager(@NotNull final Component parent, @NotNull final MapModel<G, A, R> copyBufferMapModel, @NotNull final ObjectChooser<G, A, R> objectChooser, @NotNull final MapViewManager<G, A, R> mapViewManager, @NotNull final FaceObjectProviders faceObjectProviders, @NotNull final InsertionModeSet<G, A, R> insertionModeSet) { + public ReplaceDialogManager(@NotNull final Component parent, @NotNull final MapModel<G, A, R> copyBufferMapModel, @NotNull final ObjectChooser<G, A, R> objectChooser, @NotNull final MapViewManager<G, A, R> mapViewManager, @NotNull final FaceObjectProviders faceObjectProviders, @NotNull final InsertionModeSet<G, A, R> insertionModeSet, @NotNull final ArchetypeChooserModel<G, A, R> archetypeChooserModel) { this.parent = parent; this.copyBufferMapModel = copyBufferMapModel; this.objectChooser = objectChooser; this.faceObjectProviders = faceObjectProviders; this.insertionModeSet = insertionModeSet; + this.archetypeChooserModel = archetypeChooserModel; mapViewManager.addMapViewManagerListener(mapViewManagerListener); } @@ -119,7 +128,7 @@ @NotNull public ReplaceDialog<G, A, R> getInstance() { if (instance == null) { - instance = new ReplaceDialog<G, A, R>(parent, copyBufferMapModel, objectChooser, faceObjectProviders, insertionModeSet); + instance = new ReplaceDialog<G, A, R>(parent, copyBufferMapModel, objectChooser, faceObjectProviders, insertionModeSet, archetypeChooserModel); } return instance; } Modified: trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java 2010-04-27 19:57:52 UTC (rev 7644) +++ trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java 2010-04-27 20:14:08 UTC (rev 7645) @@ -387,7 +387,7 @@ final MapModel<G, A, R> copyBufferMapModel = mapControlFactory.newMapModel(mapArchObject, null); final InsertionModeSet<G, A, R> insertionModeSet = new InsertionModeSet<G, A, R>(topmostInsertionMode); final CopyBuffer<G, A, R> copyBuffer = new CopyBuffer<G, A, R>(mapViewSettings, copyBufferMapModel, gameObjectFactory, insertionModeSet); - final ReplaceDialogManager<G, A, R> replaceDialogManager = new ReplaceDialogManager<G, A, R>(mainViewFrame, copyBufferMapModel, objectChooser, mapViewManager, faceObjectProviders, insertionModeSet); + final ReplaceDialogManager<G, A, R> replaceDialogManager = new ReplaceDialogManager<G, A, R>(mainViewFrame, copyBufferMapModel, objectChooser, mapViewManager, faceObjectProviders, insertionModeSet, archetypeChooserModel); new About(mainViewFrame); exiter = new DefaultExiter(mainViewFrame); scriptEditControl = new ScriptEditControl(scriptFileFilter, scriptExtension, mainViewFrame, globalSettings.getMapsDirectory(), prefs, exiter); @@ -432,7 +432,7 @@ final MainToolbar mainToolbar = new MainToolbar(globalSettings); mainView = new MainView(mainViewFrame, exitAction, statusBar, mapDesktop, icon, gameObjectAttributesControl, selectedSquareView, objectChooser, toolPalette, objectChoiceDisplay, exiter, menuBar, globalSettings, mainToolbar.getComponent()); exitConnectorModel = new ExitConnectorModel(); // XXX: should be part of DefaultMainControl - final ExitConnectorActions<G, A, R> exitConnectorActions = new ExitConnectorActions<G, A, R>(exitConnectorModel, exitMatcher, archetypeSet, mapManager, fileControl, pathManager, insertionModeSet); // XXX: should be part of DefaultMainControl + final ExitConnectorActions<G, A, R> exitConnectorActions = new ExitConnectorActions<G, A, R>(exitConnectorModel, exitMatcher, archetypeSet, mapManager, fileControl, pathManager, insertionModeSet, archetypeChooserModel); // XXX: should be part of DefaultMainControl new ExitConnectorController<G, A, R>(exitConnectorActions, exitConnectorModel, mapViewManager); final JMenu windowMenu = getMenu(menuBar, "window"); if (windowMenu == null) { Modified: trunk/src/app/net/sf/gridarta/model/map/mapmodel/DefaultMapModel.java =================================================================== --- trunk/src/app/net/sf/gridarta/model/map/mapmodel/DefaultMapModel.java 2010-04-27 19:57:52 UTC (rev 7644) +++ trunk/src/app/net/sf/gridarta/model/map/mapmodel/DefaultMapModel.java 2010-04-27 20:14:08 UTC (rev 7645) @@ -775,7 +775,7 @@ // put arch on the map if (templateGameObject.isArchetype()) { - newGameObject = insertArchetype(templateGameObject.getArchetype(), pos, true, join, topmostInsertionMode); + newGameObject = insertBaseObject(templateGameObject.getArchetype(), pos, true, join, topmostInsertionMode, archetypeChooserModel.getDirection()); if (newGameObject == null) { return null; } @@ -817,13 +817,6 @@ /** {@inheritDoc} */ @Nullable @Override - public G insertArchetype(@NotNull final R archetype, @NotNull final Point pos, final boolean allowDouble, final boolean join, @NotNull final InsertionMode<G, A, R> insertionMode) { - return insertBaseObject(archetype, pos, allowDouble, join, insertionMode, archetypeChooserModel.getDirection()); - } - - /** {@inheritDoc} */ - @Nullable - @Override public G insertBaseObject(@NotNull final BaseObject<G, A, R, ?> baseObject, @NotNull final Point pos, final boolean allowMany, final boolean join, @NotNull final InsertionMode<G, A, R> insertionMode, @Nullable final Integer direction) { if (!isPointValid(pos)) { return null; @@ -985,7 +978,7 @@ @Override public void addCopyToMap(@NotNull final BaseObject<G, A, R, ?> gameObject, @NotNull final Point pos, final boolean allowDouble, @NotNull final InsertionMode<G, A, R> insertionMode) { if (gameObject.isArchetype()) { - insertArchetype(gameObject.getArchetype(), pos, allowDouble, false, insertionMode); + insertBaseObject(gameObject.getArchetype(), pos, allowDouble, false, insertionMode, archetypeChooserModel.getDirection()); } else { final G newGameObject = gameObject.newInstance(gameObjectFactory); newGameObject.setMapX(pos.x); Modified: trunk/src/app/net/sf/gridarta/model/map/mapmodel/MapModel.java =================================================================== --- trunk/src/app/net/sf/gridarta/model/map/mapmodel/MapModel.java 2010-04-27 19:57:52 UTC (rev 7644) +++ trunk/src/app/net/sf/gridarta/model/map/mapmodel/MapModel.java 2010-04-27 20:14:08 UTC (rev 7645) @@ -319,26 +319,6 @@ void addGameObjectToMap(@NotNull G gameObject, @NotNull InsertionMode<G, A, R> insertionMode); /** - * Creates a game object from an archetype and adds it to the map. - * @param archetype the archetype to insert - * @param pos the insert-location on this map - * @param allowDouble if set, only one arch of the same kind can be - * inserted per square - * @param join if set, auto-joining is supported; autojoining is only done - * if enabled in the main control - * @param insertionMode the insertion mode to use - * @return The head of the inserted object or <code>null</code> if for some - * reason no object could be inserted. - * @todo discuss whether this method really belongs to a map model, as - * implementing this would require the map model to know more than is - * desireable (e.g. ArchObjectStack + MainControl). - * @todo discuss whether in the bad case an exception wouldn't be better - * than returning <code>null</code>. - */ - @Nullable - G insertArchetype(@NotNull R archetype, @NotNull Point pos, boolean allowDouble, boolean join, @NotNull InsertionMode<G, A, R> insertionMode); - - /** * Inserts a {@link BaseObject} to a map. Archetypes are instantiated, * game objects are cloned. * @param baseObject the base object Modified: trunk/src/test/net/sf/gridarta/exitconnector/ExitConnectorActionsTest.java =================================================================== --- trunk/src/test/net/sf/gridarta/exitconnector/ExitConnectorActionsTest.java 2010-04-27 19:57:52 UTC (rev 7644) +++ trunk/src/test/net/sf/gridarta/exitconnector/ExitConnectorActionsTest.java 2010-04-27 20:14:08 UTC (rev 7645) @@ -158,6 +158,11 @@ private GlobalSettings globalSettings; /** + * The {@link ArchetypeChooserModel} instance. + */ + private ArchetypeChooserModel<TestGameObject, TestMapArchObject, TestArchetype> archetypeChooserModel; + + /** * The "topmost" {@link InsertionMode} instance. */ private InsertionMode<TestGameObject, TestMapArchObject, TestArchetype> topmostInsertionMode; @@ -395,7 +400,7 @@ final MapWriter<TestGameObject, TestMapArchObject, TestArchetype> mapWriter = new TestMapWriter(); final FaceObjectProviders faceObjectProviders = newFaceObjectProviders(); final AutojoinLists<TestGameObject, TestMapArchObject, TestArchetype> autojoinLists = new AutojoinLists<TestGameObject, TestMapArchObject, TestArchetype>(mapViewSettings); - final ArchetypeChooserModel<TestGameObject, TestMapArchObject, TestArchetype> archetypeChooserModel = new ArchetypeChooserModel<TestGameObject, TestMapArchObject, TestArchetype>(); + archetypeChooserModel = new ArchetypeChooserModel<TestGameObject, TestMapArchObject, TestArchetype>(); pathManager = new PathManager(globalSettings); final ScriptArchData<TestGameObject, TestMapArchObject, TestArchetype> scriptArchData = new TestScriptArchData(); final GameObjectFactory<TestGameObject, TestMapArchObject, TestArchetype> gameObjectFactory = new TestGameObjectFactory(scriptArchData, faceObjectProviders, animationObjects); @@ -423,7 +428,7 @@ * @return the new exit connector actions instance */ private ExitConnectorActions<TestGameObject, TestMapArchObject, TestArchetype> createActions(@NotNull final ExitConnectorModel model) { - return new ExitConnectorActions<TestGameObject, TestMapArchObject, TestArchetype>(model, exitMatcher, archetypeSet, mapManager, new TestFileControl(), pathManager, insertionModeSet); + return new ExitConnectorActions<TestGameObject, TestMapArchObject, TestArchetype>(model, exitMatcher, archetypeSet, mapManager, new TestFileControl(), pathManager, insertionModeSet, archetypeChooserModel); } /** @@ -465,10 +470,10 @@ * @param point the position to insert at * @param archetype the archetype to insert */ - private void insertArchetype(@NotNull final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel, @NotNull final Point point, @NotNull final TestArchetype archetype) { + private void insertArchetype(@NotNull final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel, @NotNull final Point point, @NotNull final BaseObject<TestGameObject, TestMapArchObject, TestArchetype, ?> archetype) { mapModel.beginTransaction("test"); try { - mapModel.insertArchetype(archetype, point, true, false, topmostInsertionMode); + mapModel.insertBaseObject(archetype, point, true, false, topmostInsertionMode, archetypeChooserModel.getDirection()); } finally { mapModel.endTransaction(); } Modified: trunk/src/test/net/sf/gridarta/model/map/mapmodel/DefaultMapModelTest.java =================================================================== --- trunk/src/test/net/sf/gridarta/model/map/mapmodel/DefaultMapModelTest.java 2010-04-27 19:57:52 UTC (rev 7644) +++ trunk/src/test/net/sf/gridarta/model/map/mapmodel/DefaultMapModelTest.java 2010-04-27 20:14:08 UTC (rev 7645) @@ -34,6 +34,7 @@ import net.sf.gridarta.model.archetype.TestArchetype; import net.sf.gridarta.model.archetypechooser.ArchetypeChooserModel; import net.sf.gridarta.model.autojoin.AutojoinLists; +import net.sf.gridarta.model.baseobject.BaseObject; import net.sf.gridarta.model.face.ArchFaceProvider; import net.sf.gridarta.model.face.DefaultFaceObjects; import net.sf.gridarta.model.face.FaceObjectProviders; @@ -138,6 +139,12 @@ private SystemIcons systemIcons = null; /** + * The {@link ArchetypeChooserModel} instance. + */ + @Nullable + private ArchetypeChooserModel<TestGameObject, TestMapArchObject, TestArchetype> archetypeChooserModel; + + /** * The {@link AnimationObjects} instance. */ @Nullable @@ -213,7 +220,7 @@ result.setLength(0); mapModel.beginTransaction("TEST"); - for (final GameObject<TestGameObject, TestMapArchObject, TestArchetype> gameObject : mapModel.getMapSquare(new Point(1, 2))) { + for (final BaseObject<TestGameObject, TestMapArchObject, TestArchetype, ?> gameObject : mapModel.getMapSquare(new Point(1, 2))) { gameObject.setAttributeString("key", "value"); } addGameObjectToMap(mapModel, "1", 2, 2, insertionModeSet.getAutoInsertionMode()); @@ -296,7 +303,7 @@ result.setLength(0); mapModel.beginTransaction("TEST"); - for (final GameObject<TestGameObject, TestMapArchObject, TestArchetype> gameObject : mapModel.getMapSquare(new Point(1, 2))) { + for (final BaseObject<TestGameObject, TestMapArchObject, TestArchetype, ?> gameObject : mapModel.getMapSquare(new Point(1, 2))) { gameObject.setAttributeString("key", "value"); } mapModel.endTransaction(); @@ -315,7 +322,7 @@ public void testGetAllGameObjects1() { final FaceObjectProviders faceObjectProviders = newFaceObjectProviders(); assert animationObjects != null; - final TestArchetype archetype = new TestArchetype("arch", faceObjectProviders, animationObjects); + final BaseObject<TestGameObject, TestMapArchObject, TestArchetype, TestArchetype> archetype = new TestArchetype("arch", faceObjectProviders, animationObjects); assert animationObjects != null; final TestArchetype archetype2 = new TestArchetype("arch2", faceObjectProviders, animationObjects); archetype2.setMultiY(1); @@ -323,7 +330,9 @@ mapModel.beginTransaction("TEST"); mapModel.resizeMap(new Size2D(1, 2)); - final TestGameObject gameObject = mapModel.insertArchetype(archetype, new Point(0, 0), true, false, insertionModeSet.getAutoInsertionMode()); + assert archetypeChooserModel != null; + final Integer direction = archetypeChooserModel.getDirection(); + final TestGameObject gameObject = mapModel.insertBaseObject(archetype, new Point(0, 0), true, false, insertionModeSet.getAutoInsertionMode(), direction); mapModel.endTransaction(); final List<TestGameObject> gameObjects = mapModel.getAllGameObjects(); @@ -393,7 +402,7 @@ } if (gameObjects != null) { final Collection<String> lines = new TreeSet<String>(); - for (final GameObject<TestGameObject, TestMapArchObject, TestArchetype> gameObject : gameObjects) { + for (final BaseObject<TestGameObject, TestMapArchObject, TestArchetype, ?> gameObject : gameObjects) { lines.add("game object " + gameObject.getMapX() + " " + gameObject.getMapY() + " " + gameObject.getBestName() + "\n"); } for (final String line : lines) { @@ -431,7 +440,7 @@ guiUtils.addToCache(iconName, imageIcon); } final TestMapArchObject mapArchObject = new TestMapArchObject(); - final ArchetypeChooserModel<TestGameObject, TestMapArchObject, TestArchetype> archetypeChooserModel = new ArchetypeChooserModel<TestGameObject, TestMapArchObject, TestArchetype>(); + archetypeChooserModel = new ArchetypeChooserModel<TestGameObject, TestMapArchObject, TestArchetype>(); final FaceObjectProviders faceObjectProviders = newFaceObjectProviders(); final MapViewSettings mapViewSettings = new MapViewSettings(); final AutojoinLists<TestGameObject, TestMapArchObject, TestArchetype> autojoinLists = new AutojoinLists<TestGameObject, TestMapArchObject, TestArchetype>(mapViewSettings); @@ -442,6 +451,7 @@ final InsertionMode<TestGameObject, TestMapArchObject, TestArchetype> topmostInsertionMode = new TopmostInsertionMode<TestGameObject, TestMapArchObject, TestArchetype>(); insertionModeSet = new InsertionModeSet<TestGameObject, TestMapArchObject, TestArchetype>(topmostInsertionMode); insertionModeSet.init(new TypeNrsGameObjectMatcher(), new TypeNrsGameObjectMatcher(), new TypeNrsGameObjectMatcher()); + assert archetypeChooserModel != null; mapModel = new DefaultMapModel<TestGameObject, TestMapArchObject, TestArchetype>(autojoinLists, null, mapArchObject, archetypeChooserModel, 0, gameObjectFactory, gameObjectMatchers, topmostInsertionMode); result.setLength(0); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2010-04-29 02:09:33
|
Revision: 7660 http://gridarta.svn.sourceforge.net/gridarta/?rev=7660&view=rev Author: akirschbaum Date: 2010-04-29 02:09:26 +0000 (Thu, 29 Apr 2010) Log Message: ----------- Move MapManager.confirmSaveChanges() to FileControl. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/gui/map/mapview/MapViewsManager.java trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java trunk/src/app/net/sf/gridarta/mapmanager/AbstractMapManager.java trunk/src/app/net/sf/gridarta/mapmanager/DefaultFileControl.java trunk/src/app/net/sf/gridarta/mapmanager/FileControl.java trunk/src/app/net/sf/gridarta/mapmanager/MapManager.java trunk/src/test/net/sf/gridarta/mapmanager/TestFileControl.java Modified: trunk/src/app/net/sf/gridarta/gui/map/mapview/MapViewsManager.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/mapview/MapViewsManager.java 2010-04-29 00:36:56 UTC (rev 7659) +++ trunk/src/app/net/sf/gridarta/gui/map/mapview/MapViewsManager.java 2010-04-29 02:09:26 UTC (rev 7660) @@ -25,6 +25,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import net.sf.gridarta.mapmanager.FileControl; import net.sf.gridarta.mapmanager.MapManager; import net.sf.gridarta.mapmanager.MapManagerListener; import net.sf.gridarta.model.archetype.Archetype; @@ -49,6 +50,12 @@ private final MapManager<G, A, R> mapManager; /** + * The {@link FileControl} to use. + */ + @NotNull + private FileControl<G, A, R> fileControl; + + /** * The {@link MapViewFactory} to use. */ @NotNull @@ -153,6 +160,11 @@ pickmapManager.addMapManagerListener(mapManagerListener); } + @Deprecated + public void setFileControl(@NotNull final FileControl<G, A, R> fileControl) { + this.fileControl = fileControl; + } + /** * Adds a {@link MapViewsListener} to be notified of events. * @param mapControl the map control to attach to @@ -291,7 +303,7 @@ public void closeMapView(@NotNull final MapView<G, A, R> mapView) { final MapControl<G, A, R> mapControl = mapView.getMapControl(); if (getMapViews(mapControl) <= 1) { - if (!mapManager.confirmSaveChanges(mapControl)) { + if (!fileControl.confirmSaveChanges(mapControl)) { return; } closeView(mapView); Modified: trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java 2010-04-29 00:36:56 UTC (rev 7659) +++ trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java 2010-04-29 02:09:26 UTC (rev 7660) @@ -399,6 +399,7 @@ scriptedEventEditor.setScriptEditControl(scriptEditControl); scriptArchEditor.setScriptEditControl(scriptEditControl); fileControl = new DefaultFileControl<G, A, R>(globalSettings, archetypeSet, mapImageCache, mapManager, mapViewsManager, mainViewFrame, FileFilters.mapFileFilter, scriptFileFilter, newMapDialogFactory, scriptExtension, scriptEditControl); + mapViewsManager.setFileControl(fileControl); new MapFileActions<G, A, R>(imageCreator2, mapManager, mapViewsManager, mapViewManager, fileControl, mainViewFrame); final MapManagerActions<G, A, R> mapManagerActions = new MapManagerActions<G, A, R>(fileControl); new MainActions<G, A, R>(replaceDialogManager, mainViewFrame, globalSettings, validators, mapViewSettings, archetypeSet, copyBuffer, copyBufferMapModel, objectChooser, mapManager, mapViewManager, resources, faceObjectProviders, gameObjectFactory, insertionModeSet, exiter); Modified: trunk/src/app/net/sf/gridarta/mapmanager/AbstractMapManager.java =================================================================== --- trunk/src/app/net/sf/gridarta/mapmanager/AbstractMapManager.java 2010-04-29 00:36:56 UTC (rev 7659) +++ trunk/src/app/net/sf/gridarta/mapmanager/AbstractMapManager.java 2010-04-29 02:09:26 UTC (rev 7660) @@ -25,7 +25,6 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; -import javax.swing.JOptionPane; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.io.MapReader; @@ -147,23 +146,6 @@ /** {@inheritDoc} */ @Override - public boolean confirmSaveChanges(@NotNull final MapControl<G, A, R> mapControl) { - if (mapControl.getMapModel().isModified()) { - final int result = fileControl.confirmSaveChanges(mapControl.getMapModel().getMapArchObject().getMapName()); - if (result == JOptionPane.YES_OPTION) { - if (!fileControl.save(mapControl)) { - return false; - } - } else if (result == JOptionPane.CANCEL_OPTION || result == JOptionPane.CLOSED_OPTION) { - return false; - } - } - - return true; - } - - /** {@inheritDoc} */ - @Override public void closeMap(@NotNull final MapControl<G, A, R> mapControl) { fireMapClosingEvent(mapControl); assert mapControl.getUseCounter() <= 0; Modified: trunk/src/app/net/sf/gridarta/mapmanager/DefaultFileControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/mapmanager/DefaultFileControl.java 2010-04-29 00:36:56 UTC (rev 7659) +++ trunk/src/app/net/sf/gridarta/mapmanager/DefaultFileControl.java 2010-04-29 02:09:26 UTC (rev 7660) @@ -241,7 +241,7 @@ break; } - if (!mapManager.confirmSaveChanges(mapControl)) { + if (!confirmSaveChanges(mapControl)) { return false; } @@ -312,8 +312,19 @@ /** {@inheritDoc} */ @Override - public int confirmSaveChanges(@NotNull final String mapName) { - return ACTION_BUILDER.showConfirmDialog(parent, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, "confirmSaveChanges", mapName); + public boolean confirmSaveChanges(@NotNull final MapControl<G, A, R> mapControl) { + if (mapControl.getMapModel().isModified()) { + final int result = ACTION_BUILDER.showConfirmDialog(parent, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, "confirmSaveChanges", mapControl.getMapModel().getMapArchObject().getMapName()); + if (result == JOptionPane.YES_OPTION) { + if (!save(mapControl)) { + return false; + } + } else if (result == JOptionPane.CANCEL_OPTION || result == JOptionPane.CLOSED_OPTION) { + return false; + } + } + + return true; } /** {@inheritDoc} */ Modified: trunk/src/app/net/sf/gridarta/mapmanager/FileControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/mapmanager/FileControl.java 2010-04-29 00:36:56 UTC (rev 7659) +++ trunk/src/app/net/sf/gridarta/mapmanager/FileControl.java 2010-04-29 02:09:26 UTC (rev 7660) @@ -63,7 +63,13 @@ */ boolean saveAs(@NotNull MapControl<G, A, R> mapControl); - int confirmSaveChanges(@NotNull String mapName); + /** + * Asks the user whether to save changes of a map. Returns + * <code>true</code> (and does not ask the user) if the map is unmodified. + * @param mapControl the map + * @return whether closing the map is allowed + */ + boolean confirmSaveChanges(@NotNull MapControl<G, A, R> mapControl); /** * Reports an error while saving a map file to the user. Modified: trunk/src/app/net/sf/gridarta/mapmanager/MapManager.java =================================================================== --- trunk/src/app/net/sf/gridarta/mapmanager/MapManager.java 2010-04-29 00:36:56 UTC (rev 7659) +++ trunk/src/app/net/sf/gridarta/mapmanager/MapManager.java 2010-04-29 02:09:26 UTC (rev 7660) @@ -46,14 +46,6 @@ MapControl<G, A, R> openMapFile(@NotNull File file, final boolean isInteractive); /** - * Asks the user whether to save changes of a map. Returns - * <code>true</code> (and does not ask the user) if the map is unmodified. - * @param mapControl the map - * @return whether closing the map is allowed - */ - boolean confirmSaveChanges(@NotNull MapControl<G, A, R> mapControl); - - /** * Closes the given map, ignoring modified status. * @param mapControl the map to close */ Modified: trunk/src/test/net/sf/gridarta/mapmanager/TestFileControl.java =================================================================== --- trunk/src/test/net/sf/gridarta/mapmanager/TestFileControl.java 2010-04-29 00:36:56 UTC (rev 7659) +++ trunk/src/test/net/sf/gridarta/mapmanager/TestFileControl.java 2010-04-29 02:09:26 UTC (rev 7660) @@ -70,7 +70,7 @@ /** {@inheritDoc} */ @Override - public int confirmSaveChanges(@NotNull final String mapName) { + public boolean confirmSaveChanges(@NotNull final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl) { throw new AssertionError(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2010-04-29 08:11:42
|
Revision: 7665 http://gridarta.svn.sourceforge.net/gridarta/?rev=7665&view=rev Author: akirschbaum Date: 2010-04-29 08:11:35 +0000 (Thu, 29 Apr 2010) Log Message: ----------- Do not complain about unsaved maps when creating event script paths names. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/mapmanager/AbstractMapManager.java trunk/src/app/net/sf/gridarta/mapmanager/DefaultFileControl.java trunk/src/app/net/sf/gridarta/mapmanager/FileControl.java trunk/src/app/net/sf/gridarta/messages.properties trunk/src/app/net/sf/gridarta/messages_de.properties trunk/src/app/net/sf/gridarta/messages_fr.properties trunk/src/app/net/sf/gridarta/messages_sv.properties trunk/src/test/net/sf/gridarta/mapmanager/TestFileControl.java Modified: trunk/src/app/net/sf/gridarta/mapmanager/AbstractMapManager.java =================================================================== --- trunk/src/app/net/sf/gridarta/mapmanager/AbstractMapManager.java 2010-04-29 02:40:26 UTC (rev 7664) +++ trunk/src/app/net/sf/gridarta/mapmanager/AbstractMapManager.java 2010-04-29 08:11:35 UTC (rev 7665) @@ -374,7 +374,6 @@ final File mapFile = mapControl.getMapModel().getMapFile(); if (mapFile == null) { - fileControl.reportNoMapPath(); return globalSettings.getMapsDirectory(); } Modified: trunk/src/app/net/sf/gridarta/mapmanager/DefaultFileControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/mapmanager/DefaultFileControl.java 2010-04-29 02:40:26 UTC (rev 7664) +++ trunk/src/app/net/sf/gridarta/mapmanager/DefaultFileControl.java 2010-04-29 08:11:35 UTC (rev 7665) @@ -359,12 +359,6 @@ /** {@inheritDoc} */ @Override - public void reportNoMapPath() { - ACTION_BUILDER.showMessageDialog(parent, "createNewEventNoMapPath"); - } - - /** {@inheritDoc} */ - @Override public void reportOutOfMemory(@NotNull final File file) { ACTION_BUILDER.showMessageDialog(parent, "mapOutOfMemory", file); } Modified: trunk/src/app/net/sf/gridarta/mapmanager/FileControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/mapmanager/FileControl.java 2010-04-29 02:40:26 UTC (rev 7664) +++ trunk/src/app/net/sf/gridarta/mapmanager/FileControl.java 2010-04-29 08:11:35 UTC (rev 7665) @@ -89,8 +89,6 @@ void reportOutOfMapBoundsDeleted(@NotNull File file, int outOfMapBoundsDeleted, @NotNull StringBuilder outOfMapBoundsObjects); - void reportNoMapPath(); - void reportOutOfMemory(@NotNull File file); } // class FileControl Modified: trunk/src/app/net/sf/gridarta/messages.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages.properties 2010-04-29 02:40:26 UTC (rev 7664) +++ trunk/src/app/net/sf/gridarta/messages.properties 2010-04-29 08:11:35 UTC (rev 7665) @@ -352,9 +352,6 @@ confirmRevertPickmap.title=Revert pickmap? confirmRevertPickmap.message=If you revert the pickmap ''{0}''\n to its last saved state, all recent changes will be lost.\nDo you really want to revert this pickmap? -createNewEventNoMapPath.title=Can''t create script path -createNewEventNoMapPath.message=Can''t create script path from map. Perhaps you should save your map first. - goLocation.title=Goto Location goLocationOkay.text=Ok goLocationApply.text=Apply Modified: trunk/src/app/net/sf/gridarta/messages_de.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages_de.properties 2010-04-29 02:40:26 UTC (rev 7664) +++ trunk/src/app/net/sf/gridarta/messages_de.properties 2010-04-29 08:11:35 UTC (rev 7665) @@ -331,9 +331,6 @@ confirmRevertPickmap.title=\xC4nderungen in Pickmap zur\xFCcknehmen? confirmRevertPickmap.message=Die letzten \xC4nderungen in der Pickmap ''{0}''\ngehen verlosen, wenn Sie die Datei neu laden.\nSind Sie sicher, dass die das wollen? -createNewEventNoMapPath.title=Kann Script-Pfad nicht ermitteln -createNewEventNoMapPath.message=Kann Script-Pfad nicht ermitteln, da die Karte noch nicht gespeichert ist. - goLocation.title=Cursor setzen goLocationOkay.text=OK goLocationApply.text=Anwenden Modified: trunk/src/app/net/sf/gridarta/messages_fr.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages_fr.properties 2010-04-29 02:40:26 UTC (rev 7664) +++ trunk/src/app/net/sf/gridarta/messages_fr.properties 2010-04-29 08:11:35 UTC (rev 7665) @@ -326,9 +326,6 @@ #confirmRevertPickmap.title= #confirmRevertPickmap.message= -#createNewEventNoMapPath.title= -#createNewEventNoMapPath.message= - #goLocation.title= #goLocationOkay.text= #goLocationApply.text= Modified: trunk/src/app/net/sf/gridarta/messages_sv.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages_sv.properties 2010-04-29 02:40:26 UTC (rev 7664) +++ trunk/src/app/net/sf/gridarta/messages_sv.properties 2010-04-29 08:11:35 UTC (rev 7665) @@ -329,9 +329,6 @@ confirmRevertPickmap.title=\xC5terst\xE4ll plockkarta? confirmRevertPickmap.message=Om du \xE5terst\xE4ller plockkartan ''{0}''\ntill dess senaste sparade version kommer alla nyliga \xE4ndringar att f\xF6rloras.\nVill du verkligen \xE5terst\xE4lla plockkartan? -createNewEventNoMapPath.title=Kan inte skapa s\xF6kv\xE4g f\xF6r script -createNewEventNoMapPath.message=Kan inte utg\xE5 fr\xE5n kartans s\xF6kv\xE4g. Du kanske skall spara kartan f\xF6rst? - #goLocation.title= #goLocationOkay.text= #goLocationApply.text= Modified: trunk/src/test/net/sf/gridarta/mapmanager/TestFileControl.java =================================================================== --- trunk/src/test/net/sf/gridarta/mapmanager/TestFileControl.java 2010-04-29 02:40:26 UTC (rev 7664) +++ trunk/src/test/net/sf/gridarta/mapmanager/TestFileControl.java 2010-04-29 08:11:35 UTC (rev 7665) @@ -104,12 +104,6 @@ /** {@inheritDoc} */ @Override - public void reportNoMapPath() { - throw new AssertionError(); - } - - /** {@inheritDoc} */ - @Override public void reportOutOfMemory(@NotNull final File file) { throw new AssertionError(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2010-05-08 22:04:03
|
Revision: 7711 http://gridarta.svn.sourceforge.net/gridarta/?rev=7711&view=rev Author: akirschbaum Date: 2010-05-08 22:03:56 +0000 (Sat, 08 May 2010) Log Message: ----------- Remove direction parameter from MapModel.insertBaseObject(). Modified Paths: -------------- trunk/src/app/net/sf/gridarta/exitconnector/ExitConnectorActions.java trunk/src/app/net/sf/gridarta/gui/map/tools/InsertionTool.java trunk/src/app/net/sf/gridarta/gui/map/tools/ToolPalette.java trunk/src/app/net/sf/gridarta/gui/map/tools/ToolSelector.java trunk/src/app/net/sf/gridarta/gui/replacedialog/ReplaceDialog.java trunk/src/app/net/sf/gridarta/gui/replacedialog/ReplaceDialogManager.java trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java trunk/src/app/net/sf/gridarta/model/map/mapmodel/DefaultMapModel.java trunk/src/app/net/sf/gridarta/model/map/mapmodel/MapModel.java trunk/src/test/net/sf/gridarta/exitconnector/ExitConnectorActionsTest.java trunk/src/test/net/sf/gridarta/model/map/mapmodel/DefaultMapModelTest.java Modified: trunk/src/app/net/sf/gridarta/exitconnector/ExitConnectorActions.java =================================================================== --- trunk/src/app/net/sf/gridarta/exitconnector/ExitConnectorActions.java 2010-05-08 18:35:21 UTC (rev 7710) +++ trunk/src/app/net/sf/gridarta/exitconnector/ExitConnectorActions.java 2010-05-08 22:03:56 UTC (rev 7711) @@ -26,7 +26,6 @@ import net.sf.gridarta.mapmanager.MapManager; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.archetype.ArchetypeSet; -import net.sf.gridarta.model.archetypechooser.ArchetypeChooserModel; import net.sf.gridarta.model.baseobject.BaseObject; import net.sf.gridarta.model.exitconnector.ExitConnectorModel; import net.sf.gridarta.model.exitconnector.ExitLocation; @@ -90,12 +89,6 @@ private final InsertionModeSet<G, A, R> insertionModeSet; /** - * The {@link ArchetypeChooserModel} to use. - */ - @NotNull - private final ArchetypeChooserModel<G, A, R> archetypeChooserModel; - - /** * Creates a new instance. * @param exitConnectorModel the exit connector model to use * @param exitMatcher the exit matcher to use @@ -104,9 +97,8 @@ * @param fileControl the file control to use * @param pathManager the path manager for converting path names * @param insertionModeSet the insertion mode set to use - * @param archetypeChooserModel the archetype chooser model to use */ - public ExitConnectorActions(@NotNull final ExitConnectorModel exitConnectorModel, @NotNull final ExitMatcher<G, A, R> exitMatcher, @NotNull final ArchetypeSet<G, A, R> archetypeSet, @NotNull final MapManager<G, A, R> mapManager, @NotNull final FileControl<G, A, R> fileControl, @NotNull final PathManager pathManager, @NotNull final InsertionModeSet<G, A, R> insertionModeSet, @NotNull final ArchetypeChooserModel<G, A, R> archetypeChooserModel) { + public ExitConnectorActions(@NotNull final ExitConnectorModel exitConnectorModel, @NotNull final ExitMatcher<G, A, R> exitMatcher, @NotNull final ArchetypeSet<G, A, R> archetypeSet, @NotNull final MapManager<G, A, R> mapManager, @NotNull final FileControl<G, A, R> fileControl, @NotNull final PathManager pathManager, @NotNull final InsertionModeSet<G, A, R> insertionModeSet) { this.exitConnectorModel = exitConnectorModel; this.exitMatcher = exitMatcher; this.archetypeSet = archetypeSet; @@ -114,7 +106,6 @@ this.fileControl = fileControl; this.pathManager = pathManager; this.insertionModeSet = insertionModeSet; - this.archetypeChooserModel = archetypeChooserModel; } /** @@ -346,7 +337,7 @@ private boolean pasteExit(@NotNull final Point location, @NotNull final MapModel<G, A, R> mapModel, @NotNull final BaseObject<G, A, R, ?> archetype, @NotNull final ExitLocation exitLocation) { mapModel.beginTransaction("paste exit"); try { - final BaseObject<G, A, R, ?> newExit = mapModel.insertBaseObject(archetype, location, true, false, insertionModeSet.getTopmostInsertionMode(), archetypeChooserModel.getDirection()); + final BaseObject<G, A, R, ?> newExit = mapModel.insertBaseObject(archetype, location, true, false, insertionModeSet.getTopmostInsertionMode()); if (newExit == null) { return false; } Modified: trunk/src/app/net/sf/gridarta/gui/map/tools/InsertionTool.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/tools/InsertionTool.java 2010-05-08 18:35:21 UTC (rev 7710) +++ trunk/src/app/net/sf/gridarta/gui/map/tools/InsertionTool.java 2010-05-08 22:03:56 UTC (rev 7711) @@ -34,7 +34,6 @@ import net.sf.gridarta.gui.selectedsquare.SelectedSquareView; import net.sf.gridarta.gui.utils.SwingUtils; import net.sf.gridarta.model.archetype.Archetype; -import net.sf.gridarta.model.archetypechooser.ArchetypeChooserModel; import net.sf.gridarta.model.baseobject.BaseObject; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.map.maparchobject.MapArchObject; @@ -120,28 +119,20 @@ private final InsertionModeSet<G, A, R> insertionModeSet; /** - * The {@link ArchetypeChooserModel} to use. - */ - @NotNull - private final ArchetypeChooserModel<G, A, R> archetypeChooserModel; - - /** * Create a BasicAbstractTool. * @param selectedSquareView the selected square view * @param selectedSquareModel the selected square model * @param objectChooser the ObjectChooser to use * @param pickmapChooserControl the pickmap chooser control to use * @param insertionModeSet the insertion mode set to use - * @param archetypeChooserModel the archetype chooser model to use */ - public InsertionTool(@NotNull final SelectedSquareView<G, A, R> selectedSquareView, @NotNull final SelectedSquareModel<G, A, R> selectedSquareModel, @NotNull final ObjectChooser<G, A, R> objectChooser, @NotNull final PickmapChooserControl<G, A, R> pickmapChooserControl, @NotNull final InsertionModeSet<G, A, R> insertionModeSet, @NotNull final ArchetypeChooserModel<G, A, R> archetypeChooserModel) { + public InsertionTool(@NotNull final SelectedSquareView<G, A, R> selectedSquareView, @NotNull final SelectedSquareModel<G, A, R> selectedSquareModel, @NotNull final ObjectChooser<G, A, R> objectChooser, @NotNull final PickmapChooserControl<G, A, R> pickmapChooserControl, @NotNull final InsertionModeSet<G, A, R> insertionModeSet) { super("insertion"); this.selectedSquareView = selectedSquareView; this.selectedSquareModel = selectedSquareModel; this.objectChooser = objectChooser; this.pickmapChooserControl = pickmapChooserControl; this.insertionModeSet = insertionModeSet; - this.archetypeChooserModel = archetypeChooserModel; } /** @@ -241,7 +232,7 @@ throw new AssertionError(); } final BaseObject<G, A, R, ?> selectedArchetype = objectChooser.getSelection(); - insertedObject = selectedArchetype == null ? null : mapModel.insertBaseObject(selectedArchetype, p, isPressed || modeIndex == MODE_AUTO, true, insertionMode, archetypeChooserModel.getDirection()); + insertedObject = selectedArchetype == null ? null : mapModel.insertBaseObject(selectedArchetype, p, isPressed || modeIndex == MODE_AUTO, true, insertionMode); } selectedSquareView.setSelectedGameObject(insertedObject); } finally { Modified: trunk/src/app/net/sf/gridarta/gui/map/tools/ToolPalette.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/tools/ToolPalette.java 2010-05-08 18:35:21 UTC (rev 7710) +++ trunk/src/app/net/sf/gridarta/gui/map/tools/ToolPalette.java 2010-05-08 22:03:56 UTC (rev 7711) @@ -33,7 +33,6 @@ import net.sf.gridarta.gui.selectedsquare.SelectedSquareModel; import net.sf.gridarta.gui.selectedsquare.SelectedSquareView; import net.sf.gridarta.model.archetype.Archetype; -import net.sf.gridarta.model.archetypechooser.ArchetypeChooserModel; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.map.maparchobject.MapArchObject; import net.sf.gridarta.model.map.mapmodel.InsertionModeSet; @@ -87,13 +86,12 @@ * @param wallGameObjectMatcher the wall matcher to use * @param monsterGameObjectMatcher the monster matcher to use * @param insertionModeSet the insertion mode set to use - * @param archetypeChooserModel the archetype chooser model */ - public ToolPalette(@NotNull final MapViewSettings mapViewSettings, @NotNull final SelectedSquareView<G, A, R> selectedSquareView, @NotNull final SelectedSquareModel<G, A, R> selectedSquareModel, @NotNull final ObjectChooser<G, A, R> objectChooser, @NotNull final PickmapChooserControl<G, A, R> pickmapChooserControl, @Nullable final GameObjectMatcher floorGameObjectMatcher, @Nullable final GameObjectMatcher wallGameObjectMatcher, @Nullable final GameObjectMatcher monsterGameObjectMatcher, @NotNull final InsertionModeSet<G, A, R> insertionModeSet, @NotNull final ArchetypeChooserModel<G, A, R> archetypeChooserModel) { + public ToolPalette(@NotNull final MapViewSettings mapViewSettings, @NotNull final SelectedSquareView<G, A, R> selectedSquareView, @NotNull final SelectedSquareModel<G, A, R> selectedSquareModel, @NotNull final ObjectChooser<G, A, R> objectChooser, @NotNull final PickmapChooserControl<G, A, R> pickmapChooserControl, @Nullable final GameObjectMatcher floorGameObjectMatcher, @Nullable final GameObjectMatcher wallGameObjectMatcher, @Nullable final GameObjectMatcher monsterGameObjectMatcher, @NotNull final InsertionModeSet<G, A, R> insertionModeSet) { super(new BorderLayout()); - lmbSelector = new ToolSelector<G, A, R>("selection", mapViewSettings, selectedSquareView, selectedSquareModel, objectChooser, pickmapChooserControl, floorGameObjectMatcher, wallGameObjectMatcher, monsterGameObjectMatcher, insertionModeSet, archetypeChooserModel); - mmbSelector = new ToolSelector<G, A, R>("deletion", mapViewSettings, selectedSquareView, selectedSquareModel, objectChooser, pickmapChooserControl, floorGameObjectMatcher, wallGameObjectMatcher, monsterGameObjectMatcher, insertionModeSet, archetypeChooserModel); - rmbSelector = new ToolSelector<G, A, R>("insertion", mapViewSettings, selectedSquareView, selectedSquareModel, objectChooser, pickmapChooserControl, floorGameObjectMatcher, wallGameObjectMatcher, monsterGameObjectMatcher, insertionModeSet, archetypeChooserModel); + lmbSelector = new ToolSelector<G, A, R>("selection", mapViewSettings, selectedSquareView, selectedSquareModel, objectChooser, pickmapChooserControl, floorGameObjectMatcher, wallGameObjectMatcher, monsterGameObjectMatcher, insertionModeSet); + mmbSelector = new ToolSelector<G, A, R>("deletion", mapViewSettings, selectedSquareView, selectedSquareModel, objectChooser, pickmapChooserControl, floorGameObjectMatcher, wallGameObjectMatcher, monsterGameObjectMatcher, insertionModeSet); + rmbSelector = new ToolSelector<G, A, R>("insertion", mapViewSettings, selectedSquareView, selectedSquareModel, objectChooser, pickmapChooserControl, floorGameObjectMatcher, wallGameObjectMatcher, monsterGameObjectMatcher, insertionModeSet); add(new JLabel(ACTION_BUILDER.getString("mouse")), BorderLayout.NORTH); final Container mouseTabs = new JTabbedPane(); mouseTabs.add(ACTION_BUILDER.getString("left"), lmbSelector); Modified: trunk/src/app/net/sf/gridarta/gui/map/tools/ToolSelector.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/tools/ToolSelector.java 2010-05-08 18:35:21 UTC (rev 7710) +++ trunk/src/app/net/sf/gridarta/gui/map/tools/ToolSelector.java 2010-05-08 22:03:56 UTC (rev 7711) @@ -40,7 +40,6 @@ import net.sf.gridarta.gui.selectedsquare.SelectedSquareModel; import net.sf.gridarta.gui.selectedsquare.SelectedSquareView; import net.sf.gridarta.model.archetype.Archetype; -import net.sf.gridarta.model.archetypechooser.ArchetypeChooserModel; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.map.maparchobject.MapArchObject; import net.sf.gridarta.model.map.mapmodel.InsertionModeSet; @@ -121,14 +120,13 @@ * @param wallGameObjectMatcher the wall matcher to use * @param monsterGameObjectMatcher the monster matcher to use * @param insertionModeSet the insertion mode set to use - * @param archetypeChooserModel the archetype chooser model to use */ - public ToolSelector(@NotNull final String defaultTool, @NotNull final MapViewSettings mapViewSettings, @NotNull final SelectedSquareView<G, A, R> selectedSquareView, @NotNull final SelectedSquareModel<G, A, R> selectedSquareModel, @NotNull final ObjectChooser<G, A, R> objectChooser, @NotNull final PickmapChooserControl<G, A, R> pickmapChooserControl, @Nullable final GameObjectMatcher floorGameObjectMatcher, @Nullable final GameObjectMatcher wallGameObjectMatcher, @Nullable final GameObjectMatcher monsterGameObjectMatcher, @NotNull final InsertionModeSet<G, A, R> insertionModeSet, @NotNull final ArchetypeChooserModel<G, A, R> archetypeChooserModel) { + public ToolSelector(@NotNull final String defaultTool, @NotNull final MapViewSettings mapViewSettings, @NotNull final SelectedSquareView<G, A, R> selectedSquareView, @NotNull final SelectedSquareModel<G, A, R> selectedSquareModel, @NotNull final ObjectChooser<G, A, R> objectChooser, @NotNull final PickmapChooserControl<G, A, R> pickmapChooserControl, @Nullable final GameObjectMatcher floorGameObjectMatcher, @Nullable final GameObjectMatcher wallGameObjectMatcher, @Nullable final GameObjectMatcher monsterGameObjectMatcher, @NotNull final InsertionModeSet<G, A, R> insertionModeSet) { createUI(); addTool(new VoidTool<G, A, R>(), defaultTool); addTool(new SelectionTool<G, A, R>(objectChooser, insertionModeSet), defaultTool); addTool(new DeletionTool<G, A, R>(mapViewSettings, objectChooser, pickmapChooserControl, floorGameObjectMatcher, wallGameObjectMatcher, monsterGameObjectMatcher), defaultTool); - addTool(new InsertionTool<G, A, R>(selectedSquareView, selectedSquareModel, objectChooser, pickmapChooserControl, insertionModeSet, archetypeChooserModel), defaultTool); + addTool(new InsertionTool<G, A, R>(selectedSquareView, selectedSquareModel, objectChooser, pickmapChooserControl, insertionModeSet), defaultTool); } /** Modified: trunk/src/app/net/sf/gridarta/gui/replacedialog/ReplaceDialog.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/replacedialog/ReplaceDialog.java 2010-05-08 18:35:21 UTC (rev 7710) +++ trunk/src/app/net/sf/gridarta/gui/replacedialog/ReplaceDialog.java 2010-05-08 22:03:56 UTC (rev 7711) @@ -47,7 +47,6 @@ import net.sf.gridarta.gui.objectchooser.ObjectChooser; import net.sf.gridarta.gui.objectchooser.ObjectChooserListener; import net.sf.gridarta.model.archetype.Archetype; -import net.sf.gridarta.model.archetypechooser.ArchetypeChooserModel; import net.sf.gridarta.model.baseobject.BaseObject; import net.sf.gridarta.model.face.FaceObjectProviders; import net.sf.gridarta.model.gameobject.GameObject; @@ -117,12 +116,6 @@ private final InsertionModeSet<G, A, R> insertionModeSet; /** - * The {@link ArchetypeChooserModel} to use. - */ - @NotNull - private final ArchetypeChooserModel<G, A, R> archetypeChooserModel; - - /** * The dialog instance. */ private final JDialog dialog; @@ -221,11 +214,9 @@ * @param faceObjectProviders the face object providers for looking up * faces * @param insertionModeSet the insertion mode set to use - * @param archetypeChooserModel the archetype chooser model to use */ - public ReplaceDialog(@NotNull final Component parent, @NotNull final MapModel<G, A, R> copyBufferMapModel, @NotNull final ObjectChooser<G, A, R> objectChooser, @NotNull final FaceObjectProviders faceObjectProviders, @NotNull final InsertionModeSet<G, A, R> insertionModeSet, @NotNull final ArchetypeChooserModel<G, A, R> archetypeChooserModel) { + public ReplaceDialog(@NotNull final Component parent, @NotNull final MapModel<G, A, R> copyBufferMapModel, @NotNull final ObjectChooser<G, A, R> objectChooser, @NotNull final FaceObjectProviders faceObjectProviders, @NotNull final InsertionModeSet<G, A, R> insertionModeSet) { this.insertionModeSet = insertionModeSet; - this.archetypeChooserModel = archetypeChooserModel; dialog = createDialog(parent, ACTION_BUILDER.getString("replaceTitle")); dialog.setModal(false); dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); @@ -486,7 +477,7 @@ // insert replacement object if (randomArch.isMulti()) { // multi's cannot be inserted properly, so we just put them ontop - mapModel.insertBaseObject(randomArch.getArchetype(), new Point(square.getMapX(), square.getMapY()), false, false, insertionModeSet.getTopmostInsertionMode(), archetypeChooserModel.getDirection()); + mapModel.insertBaseObject(randomArch.getArchetype(), new Point(square.getMapX(), square.getMapY()), false, false, insertionModeSet.getTopmostInsertionMode()); // TODO: if from pickmap it could have special attributes -> copy them } else { Modified: trunk/src/app/net/sf/gridarta/gui/replacedialog/ReplaceDialogManager.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/replacedialog/ReplaceDialogManager.java 2010-05-08 18:35:21 UTC (rev 7710) +++ trunk/src/app/net/sf/gridarta/gui/replacedialog/ReplaceDialogManager.java 2010-05-08 22:03:56 UTC (rev 7711) @@ -25,7 +25,6 @@ import net.sf.gridarta.gui.map.mapview.MapViewManagerListener; import net.sf.gridarta.gui.objectchooser.ObjectChooser; import net.sf.gridarta.model.archetype.Archetype; -import net.sf.gridarta.model.archetypechooser.ArchetypeChooserModel; import net.sf.gridarta.model.face.FaceObjectProviders; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.map.maparchobject.MapArchObject; @@ -70,12 +69,6 @@ private final InsertionModeSet<G, A, R> insertionModeSet; /** - * The {@link ArchetypeChooserModel} to use. - */ - @NotNull - private final ArchetypeChooserModel<G, A, R> archetypeChooserModel; - - /** * The map view manager listener to detect closed map views. */ private final MapViewManagerListener<G, A, R> mapViewManagerListener = new MapViewManagerListener<G, A, R>() { @@ -106,15 +99,13 @@ * @param faceObjectProviders the face object providers for looking up * faces * @param insertionModeSet the insertion mode set to use - * @param archetypeChooserModel the archetype chooser model to use */ - public ReplaceDialogManager(@NotNull final Component parent, @NotNull final MapModel<G, A, R> copyBufferMapModel, @NotNull final ObjectChooser<G, A, R> objectChooser, @NotNull final MapViewManager<G, A, R> mapViewManager, @NotNull final FaceObjectProviders faceObjectProviders, @NotNull final InsertionModeSet<G, A, R> insertionModeSet, @NotNull final ArchetypeChooserModel<G, A, R> archetypeChooserModel) { + public ReplaceDialogManager(@NotNull final Component parent, @NotNull final MapModel<G, A, R> copyBufferMapModel, @NotNull final ObjectChooser<G, A, R> objectChooser, @NotNull final MapViewManager<G, A, R> mapViewManager, @NotNull final FaceObjectProviders faceObjectProviders, @NotNull final InsertionModeSet<G, A, R> insertionModeSet) { this.parent = parent; this.copyBufferMapModel = copyBufferMapModel; this.objectChooser = objectChooser; this.faceObjectProviders = faceObjectProviders; this.insertionModeSet = insertionModeSet; - this.archetypeChooserModel = archetypeChooserModel; mapViewManager.addMapViewManagerListener(mapViewManagerListener); } @@ -130,7 +121,7 @@ @NotNull public ReplaceDialog<G, A, R> getInstance() { if (instance == null) { - instance = new ReplaceDialog<G, A, R>(parent, copyBufferMapModel, objectChooser, faceObjectProviders, insertionModeSet, archetypeChooserModel); + instance = new ReplaceDialog<G, A, R>(parent, copyBufferMapModel, objectChooser, faceObjectProviders, insertionModeSet); } return instance; } Modified: trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java 2010-05-08 18:35:21 UTC (rev 7710) +++ trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java 2010-05-08 22:03:56 UTC (rev 7711) @@ -426,7 +426,7 @@ final MapModel<G, A, R> copyBufferMapModel = mapControlFactory.newMapModel(mapArchObject); final InsertionModeSet<G, A, R> insertionModeSet = new InsertionModeSet<G, A, R>(topmostInsertionMode); final CopyBuffer<G, A, R> copyBuffer = new CopyBuffer<G, A, R>(mapViewSettings, copyBufferMapModel, gameObjectFactory, insertionModeSet); - final ReplaceDialogManager<G, A, R> replaceDialogManager = new ReplaceDialogManager<G, A, R>(mainViewFrame, copyBufferMapModel, objectChooser, mapViewManager, faceObjectProviders, insertionModeSet, archetypeChooserModel); + final ReplaceDialogManager<G, A, R> replaceDialogManager = new ReplaceDialogManager<G, A, R>(mainViewFrame, copyBufferMapModel, objectChooser, mapViewManager, faceObjectProviders, insertionModeSet); new About(mainViewFrame); exiter = new DefaultExiter(mainViewFrame); scriptEditControl = new ScriptEditControl(scriptFileFilter, scriptExtension, mainViewFrame, globalSettings.getMapsDirectory(), prefs, exiter); @@ -463,7 +463,7 @@ final PluginParameterViewFactory<G, A, R> pluginParameterViewFactory = new PluginParameterViewFactory<G, A, R>(archetypeSet, gameObjectAttributesModel, objectChooser, defaultFilterList, mapManager, faceObjectProviders); final File scriptsFile = new File(globalSettings.getMapsDirectory(), scriptsDir); scriptControl = new ScriptController<G, A, R>(filterControl, scriptParameters, mainViewFrame, pluginParameterViewFactory, scriptsFile, scriptModel, pluginParameterFactory, scriptExecutor, systemIcons); - final ToolPalette<G, A, R> toolPalette = new ToolPalette<G, A, R>(mapViewSettings, selectedSquareView, selectedSquareModel, objectChooser, pickmapChooserControl, floorMatcher, wallMatcher, monsterMatcher, insertionModeSet, archetypeChooserModel); + final ToolPalette<G, A, R> toolPalette = new ToolPalette<G, A, R>(mapViewSettings, selectedSquareView, selectedSquareModel, objectChooser, pickmapChooserControl, floorMatcher, wallMatcher, monsterMatcher, insertionModeSet); new FindArchetypesDialogManager<G, A, R>(mainViewFrame, archetypeChooserControl, objectChooser, archetypeTypeSet); new UndoControl<G, A, R>(mapManager, gameObjectFactory, gameObjectMatchers); final UpdaterManager updaterManager = new UpdaterManager(exiter, mapManager, mainViewFrame, gridartaJarFilename); @@ -486,7 +486,7 @@ mainView.addTab(new Tab("tools", toolPalette, Location.LEFT, 2, false)); mainView.addTab(new Tab("objects", objectChooser, Location.LEFT, 3, true)); exitConnectorModel = new ExitConnectorModel(); // XXX: should be part of DefaultMainControl - final ExitConnectorActions<G, A, R> exitConnectorActions = new ExitConnectorActions<G, A, R>(exitConnectorModel, exitMatcher, archetypeSet, mapManager, fileControl, pathManager, insertionModeSet, archetypeChooserModel); // XXX: should be part of DefaultMainControl + final ExitConnectorActions<G, A, R> exitConnectorActions = new ExitConnectorActions<G, A, R>(exitConnectorModel, exitMatcher, archetypeSet, mapManager, fileControl, pathManager, insertionModeSet); // XXX: should be part of DefaultMainControl new ExitConnectorController<G, A, R>(exitConnectorActions, exitConnectorModel, mapViewManager); final JMenu windowMenu = MenuUtils.getMenu(menuBar, "window"); if (windowMenu == null) { Modified: trunk/src/app/net/sf/gridarta/model/map/mapmodel/DefaultMapModel.java =================================================================== --- trunk/src/app/net/sf/gridarta/model/map/mapmodel/DefaultMapModel.java 2010-05-08 18:35:21 UTC (rev 7710) +++ trunk/src/app/net/sf/gridarta/model/map/mapmodel/DefaultMapModel.java 2010-05-08 22:03:56 UTC (rev 7711) @@ -853,7 +853,7 @@ // put arch on the map if (templateGameObject.isArchetype()) { - newGameObject = insertBaseObject(templateGameObject.getArchetype(), pos, true, join, topmostInsertionMode, archetypeChooserModel.getDirection()); + newGameObject = insertBaseObject(templateGameObject.getArchetype(), pos, true, join, topmostInsertionMode); if (newGameObject == null) { return null; } @@ -897,7 +897,7 @@ */ @Nullable @Override - public G insertBaseObject(@NotNull final BaseObject<G, A, R, ?> baseObject, @NotNull final Point pos, final boolean allowMany, final boolean join, @NotNull final InsertionMode<G, A, R> insertionMode, @Nullable final Integer direction) { + public G insertBaseObject(@NotNull final BaseObject<G, A, R, ?> baseObject, @NotNull final Point pos, final boolean allowMany, final boolean join, @NotNull final InsertionMode<G, A, R> insertionMode) { if (!isPointValid(pos)) { return null; } @@ -925,6 +925,7 @@ } final G part = baseObjectPart.newInstance(gameObjectFactory); part.setArchetype(archetypePart); + final Object direction = archetypeChooserModel.getDirection(); if (direction != null) { part.setAttributeString("direction", direction.toString()); } @@ -1080,7 +1081,7 @@ @Override public void addCopyToMap(@NotNull final BaseObject<G, A, R, ?> gameObject, @NotNull final Point pos, final boolean allowDouble, @NotNull final InsertionMode<G, A, R> insertionMode) { if (gameObject.isArchetype()) { - insertBaseObject(gameObject.getArchetype(), pos, allowDouble, false, insertionMode, archetypeChooserModel.getDirection()); + insertBaseObject(gameObject.getArchetype(), pos, allowDouble, false, insertionMode); } else { final G newGameObject = gameObject.newInstance(gameObjectFactory); newGameObject.setMapX(pos.x); Modified: trunk/src/app/net/sf/gridarta/model/map/mapmodel/MapModel.java =================================================================== --- trunk/src/app/net/sf/gridarta/model/map/mapmodel/MapModel.java 2010-05-08 18:35:21 UTC (rev 7710) +++ trunk/src/app/net/sf/gridarta/model/map/mapmodel/MapModel.java 2010-05-08 22:03:56 UTC (rev 7711) @@ -305,19 +305,19 @@ /** * Inserts a {@link BaseObject} to a map. Archetypes are instantiated, game - * objects are cloned. + * objects are cloned. The direction of the inserted game object is set to + * the direction of the archetype chooser. * @param baseObject the base object * @param pos the insert-location on this map * @param allowMany whether duplicates are allowed * @param join if set, auto-joining is supported; autojoining is only done * if enabled in the main control * @param insertionMode the insertion mode to use - * @param direction the game object's direction; <code>null</code>=default * @return the inserted game object or <code>null</code> if nothing was * inserted */ @Nullable - G insertBaseObject(@NotNull BaseObject<G, A, R, ?> baseObject, @NotNull Point pos, boolean allowMany, boolean join, @NotNull InsertionMode<G, A, R> insertionMode, @Nullable Integer direction); + G insertBaseObject(@NotNull BaseObject<G, A, R, ?> baseObject, @NotNull Point pos, boolean allowMany, boolean join, @NotNull InsertionMode<G, A, R> insertionMode); /** * Checks whether an GameObject (multi-arch) would still fit on this map. Modified: trunk/src/test/net/sf/gridarta/exitconnector/ExitConnectorActionsTest.java =================================================================== --- trunk/src/test/net/sf/gridarta/exitconnector/ExitConnectorActionsTest.java 2010-05-08 18:35:21 UTC (rev 7710) +++ trunk/src/test/net/sf/gridarta/exitconnector/ExitConnectorActionsTest.java 2010-05-08 22:03:56 UTC (rev 7711) @@ -158,11 +158,6 @@ private GlobalSettings globalSettings; /** - * The {@link ArchetypeChooserModel} instance. - */ - private ArchetypeChooserModel<TestGameObject, TestMapArchObject, TestArchetype> archetypeChooserModel; - - /** * The "topmost" {@link InsertionMode} instance. */ private InsertionMode<TestGameObject, TestMapArchObject, TestArchetype> topmostInsertionMode; @@ -400,7 +395,7 @@ final MapWriter<TestGameObject, TestMapArchObject, TestArchetype> mapWriter = new TestMapWriter(); final FaceObjectProviders faceObjectProviders = newFaceObjectProviders(); final AutojoinLists<TestGameObject, TestMapArchObject, TestArchetype> autojoinLists = new AutojoinLists<TestGameObject, TestMapArchObject, TestArchetype>(mapViewSettings); - archetypeChooserModel = new ArchetypeChooserModel<TestGameObject, TestMapArchObject, TestArchetype>(); + final ArchetypeChooserModel<TestGameObject, TestMapArchObject, TestArchetype> archetypeChooserModel = new ArchetypeChooserModel<TestGameObject, TestMapArchObject, TestArchetype>(); pathManager = new PathManager(globalSettings); final ScriptArchData<TestGameObject, TestMapArchObject, TestArchetype> scriptArchData = new TestScriptArchData(); final GameObjectFactory<TestGameObject, TestMapArchObject, TestArchetype> gameObjectFactory = new TestGameObjectFactory(scriptArchData, faceObjectProviders, animationObjects); @@ -428,7 +423,7 @@ * @return the new exit connector actions instance */ private ExitConnectorActions<TestGameObject, TestMapArchObject, TestArchetype> createActions(@NotNull final ExitConnectorModel model) { - return new ExitConnectorActions<TestGameObject, TestMapArchObject, TestArchetype>(model, exitMatcher, archetypeSet, mapManager, new TestFileControl(), pathManager, insertionModeSet, archetypeChooserModel); + return new ExitConnectorActions<TestGameObject, TestMapArchObject, TestArchetype>(model, exitMatcher, archetypeSet, mapManager, new TestFileControl(), pathManager, insertionModeSet); } /** @@ -473,7 +468,7 @@ private void insertArchetype(@NotNull final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel, @NotNull final Point point, @NotNull final BaseObject<TestGameObject, TestMapArchObject, TestArchetype, ?> archetype) { mapModel.beginTransaction("test"); try { - mapModel.insertBaseObject(archetype, point, true, false, topmostInsertionMode, archetypeChooserModel.getDirection()); + mapModel.insertBaseObject(archetype, point, true, false, topmostInsertionMode); } finally { mapModel.endTransaction(); } Modified: trunk/src/test/net/sf/gridarta/model/map/mapmodel/DefaultMapModelTest.java =================================================================== --- trunk/src/test/net/sf/gridarta/model/map/mapmodel/DefaultMapModelTest.java 2010-05-08 18:35:21 UTC (rev 7710) +++ trunk/src/test/net/sf/gridarta/model/map/mapmodel/DefaultMapModelTest.java 2010-05-08 22:03:56 UTC (rev 7711) @@ -161,12 +161,6 @@ private SystemIcons systemIcons = null; /** - * The {@link ArchetypeChooserModel} instance. - */ - @Nullable - private ArchetypeChooserModel<TestGameObject, TestMapArchObject, TestArchetype> archetypeChooserModel; - - /** * The {@link AnimationObjects} instance. */ @Nullable @@ -372,9 +366,7 @@ mapModel.beginTransaction("TEST"); mapModel.resizeMap(new Size2D(1, 2)); - assert archetypeChooserModel != null; - final Integer direction = archetypeChooserModel.getDirection(); - final TestGameObject gameObject = mapModel.insertBaseObject(archetype, new Point(0, 0), true, false, insertionModeSet.getAutoInsertionMode(), direction); + final TestGameObject gameObject = mapModel.insertBaseObject(archetype, new Point(0, 0), true, false, insertionModeSet.getAutoInsertionMode()); mapModel.endTransaction(); final List<TestGameObject> gameObjects = mapModel.getAllGameObjects(); @@ -482,7 +474,7 @@ guiUtils.addToCache(iconName, imageIcon); } final TestMapArchObject mapArchObject = new TestMapArchObject(); - archetypeChooserModel = new ArchetypeChooserModel<TestGameObject, TestMapArchObject, TestArchetype>(); + final ArchetypeChooserModel<TestGameObject, TestMapArchObject, TestArchetype> archetypeChooserModel = new ArchetypeChooserModel<TestGameObject, TestMapArchObject, TestArchetype>(); final FaceObjectProviders faceObjectProviders = newFaceObjectProviders(); final MapViewSettings mapViewSettings = new MapViewSettings(); final AutojoinLists<TestGameObject, TestMapArchObject, TestArchetype> autojoinLists = new AutojoinLists<TestGameObject, TestMapArchObject, TestArchetype>(mapViewSettings); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2010-05-13 10:28:05
|
Revision: 7726 http://gridarta.svn.sourceforge.net/gridarta/?rev=7726&view=rev Author: akirschbaum Date: 2010-05-13 10:27:59 +0000 (Thu, 13 May 2010) Log Message: ----------- Weaken types. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java trunk/src/test/net/sf/gridarta/model/baseobject/AbstractBaseObjectTest.java Modified: trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java 2010-05-12 20:53:31 UTC (rev 7725) +++ trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java 2010-05-13 10:27:59 UTC (rev 7726) @@ -43,6 +43,7 @@ import net.sf.gridarta.gui.archetypetype.ArchetypeTypeChecks; import net.sf.gridarta.gui.autovalidator.AutoValidator; import net.sf.gridarta.gui.connectionview.ConnectionControl; +import net.sf.gridarta.gui.connectionview.Control; import net.sf.gridarta.gui.connectionview.LockedItemsControl; import net.sf.gridarta.gui.connectionview.MonsterControl; import net.sf.gridarta.gui.copybuffer.CopyBuffer; @@ -456,7 +457,7 @@ new DefaultMapActions<G, A, R>(mainViewFrame, mainViewFrame, mapManager, mapViewManager, exitMatcher, FileFilters.mapFileFilter, selectedSquareModel, directionMap, allowRandomMapParameters, mapPropertiesDialogFactory, mapViewSettings, mapPathNormalizer, mapViewsManager, fileControl); ArchetypeTypeChecks.addChecks(archetypeTypeSet, attributeRangeChecker); final DelayedMapModelListenerManager<G, A, R> delayedMapModelListenerManager = new DelayedMapModelListenerManager<G, A, R>(mapManager, exiter); - final LockedItemsControl<G, A, R> lockedItemsControl = new LockedItemsControl<G, A, R>(mapViewManager, delayedMapModelListenerManager, lockedItemsTypeNumbers); + final Control<?, G, A, R> lockedItemsControl = new LockedItemsControl<G, A, R>(mapViewManager, delayedMapModelListenerManager, lockedItemsTypeNumbers); final GameObjectAttributesModel<G, A, R> gameObjectAttributesModel = new GameObjectAttributesModel<G, A, R>(); final SelectedSquareView<G, A, R> selectedSquareView = selectedSquareControl.getSelectedSquareView(); final GameObjectAttributesControl<G, A, R> gameObjectAttributesControl = new GameObjectAttributesControl<G, A, R>(gameObjectAttributesModel, gameObjectAttributesDialogFactory, objectChooser, mapManager, selectedSquareModel, selectedSquareView, gameObjectFactory, gameObjectMatchers); Modified: trunk/src/test/net/sf/gridarta/model/baseobject/AbstractBaseObjectTest.java =================================================================== --- trunk/src/test/net/sf/gridarta/model/baseobject/AbstractBaseObjectTest.java 2010-05-12 20:53:31 UTC (rev 7725) +++ trunk/src/test/net/sf/gridarta/model/baseobject/AbstractBaseObjectTest.java 2010-05-13 10:27:59 UTC (rev 7726) @@ -123,7 +123,7 @@ final FaceObjectProviders faceObjectProviders = newFaceObjectProviders(); final TestArchetype archetype = newArchetype("arch", "key1 value1\nkey2 value2\n", faceObjectProviders, animationObjects); - final GameObject<TestGameObject, TestMapArchObject, TestArchetype> gameObject = new TestGameObject(archetype, faceObjectProviders, animationObjects); + final BaseObject<?, ?, ?, ?> gameObject = new TestGameObject(archetype, faceObjectProviders, animationObjects); Assert.assertEquals("value1", gameObject.getAttributeString("key1")); Assert.assertEquals("value1", gameObject.getAttributeString("key1", true)); @@ -250,7 +250,7 @@ * @param gameObject the game object to check * @param direction the expected direction */ - private static void checkDirection(@NotNull final GameObject<TestGameObject, TestMapArchObject, TestArchetype> gameObject, final int direction) { + private static void checkDirection(@NotNull final BaseObject<?, ?, ?, ?> gameObject, final int direction) { Assert.assertEquals(direction, gameObject.getDirection()); Assert.assertEquals(direction, gameObject.getAttributeInt("direction")); } @@ -316,7 +316,7 @@ * @param gameObject the game object to check * @param type the expected direction */ - private static void checkType(@NotNull final GameObject<TestGameObject, TestMapArchObject, TestArchetype> gameObject, final int type) { + private static void checkType(@NotNull final BaseObject<?, ?, ?, ?> gameObject, final int type) { Assert.assertEquals(type, gameObject.getTypeNo()); Assert.assertEquals(type, gameObject.getAttributeInt("type")); } @@ -329,7 +329,7 @@ final AnimationObjects animationObjects = new DefaultAnimationObjects("anim"); final FaceObjectProviders faceObjectProviders = newFaceObjectProviders(); final TestArchetype archetype = newArchetype("arch", null, faceObjectProviders, animationObjects); - final GameObject<TestGameObject, TestMapArchObject, TestArchetype> gameObject = new TestGameObject(archetype, faceObjectProviders, animationObjects); + final BaseObject<?, ?, ?, ?> gameObject = new TestGameObject(archetype, faceObjectProviders, animationObjects); checkName(gameObject, "arch", ""); gameObject.setAttributeString("name", "3"); checkName(gameObject, "3", "3"); @@ -347,7 +347,7 @@ final AnimationObjects animationObjects = new DefaultAnimationObjects("anim"); final FaceObjectProviders faceObjectProviders = newFaceObjectProviders(); final TestArchetype archetype = newArchetype("arch", "name 2", faceObjectProviders, animationObjects); - final GameObject<TestGameObject, TestMapArchObject, TestArchetype> gameObject = new TestGameObject(archetype, faceObjectProviders, animationObjects); + final BaseObject<?, ?, ?, ?> gameObject = new TestGameObject(archetype, faceObjectProviders, animationObjects); checkName(gameObject, "2", "2"); gameObject.setAttributeString("name", "3"); checkName(gameObject, "3", "3"); @@ -383,7 +383,7 @@ * @param name the expected name (cached value) * @param nameAttribute the expected name ("name" attribute) */ - private static void checkName(@NotNull final GameObject<TestGameObject, TestMapArchObject, TestArchetype> gameObject, @NotNull final String name, @NotNull final String nameAttribute) { + private static void checkName(@NotNull final BaseObject<?, ?, ?, ?> gameObject, @NotNull final String name, @NotNull final String nameAttribute) { Assert.assertEquals(name, gameObject.getObjName()); Assert.assertEquals(nameAttribute, gameObject.getAttributeString("name")); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2010-05-16 10:00:53
|
Revision: 7796 http://gridarta.svn.sourceforge.net/gridarta/?rev=7796&view=rev Author: akirschbaum Date: 2010-05-16 10:00:47 +0000 (Sun, 16 May 2010) Log Message: ----------- Add @NotNull annotations. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/gui/filter/DefaultFilterControl.java trunk/src/app/net/sf/gridarta/gui/filter/FilterControl.java trunk/src/test/net/sf/gridarta/gui/filter/TestFilterControl.java Modified: trunk/src/app/net/sf/gridarta/gui/filter/DefaultFilterControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/filter/DefaultFilterControl.java 2010-05-16 09:58:55 UTC (rev 7795) +++ trunk/src/app/net/sf/gridarta/gui/filter/DefaultFilterControl.java 2010-05-16 10:00:47 UTC (rev 7796) @@ -50,17 +50,22 @@ //TODO allow implementation of own filter public class DefaultFilterControl<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements FilterControl<G, A, R> { + @NotNull private final NamedFilter filterList; + @NotNull private final NamedFilterConfig filterOutConfig; + @NotNull private final NamedFilterConfig[] highlightConfig; /** * The {@link FilterConfigListener}s to notify. */ + @NotNull private final EventListenerList2<FilterConfigListener> configListeners = new EventListenerList2<FilterConfigListener>(FilterConfigListener.class); + @NotNull private final FilterConfigListener filterConfigListener = new FilterConfigListener() { /** {@inheritDoc} */ @@ -78,7 +83,7 @@ * filterOut anything * @param filterList the filter list instance to use */ - public DefaultFilterControl(final NamedFilter filterList) { + public DefaultFilterControl(@NotNull final NamedFilter filterList) { this.filterList = filterList; filterOutConfig = filterList.createConfig(); highlightConfig = new NamedFilterConfig[MAX_HIGHLIGHT]; @@ -111,7 +116,7 @@ * {@inheritDoc} */ @Override - public void createMenuEntries(final JMenu menu) { + public void createMenuEntries(@NotNull final JMenu menu) { final JMenuItem menuItem = new MenuItemCreator(filterOutConfig).getMenuItem(); menuItem.setText("Filter view"); menu.add(menuItem); @@ -162,7 +167,7 @@ * {@inheritDoc} */ @Override - public boolean canShow(final G gameObject) { + public boolean canShow(@NotNull final G gameObject) { return !filterOutConfig.isEnabled() || filterList.canShow(gameObject, filterOutConfig); } @@ -170,7 +175,7 @@ * {@inheritDoc} */ @Override - public void addFilter(final String name, final Filter<?, ?> filter) { + public void addFilter(@NotNull final String name, @NotNull final Filter<?, ?> filter) { filterList.addFilter(name, filter); } @@ -178,7 +183,7 @@ * {@inheritDoc} */ @Override - public void removeFilter(final String name) { + public void removeFilter(@NotNull final String name) { filterList.removeFilter(name); } Modified: trunk/src/app/net/sf/gridarta/gui/filter/FilterControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/filter/FilterControl.java 2010-05-16 09:58:55 UTC (rev 7795) +++ trunk/src/app/net/sf/gridarta/gui/filter/FilterControl.java 2010-05-16 10:00:47 UTC (rev 7796) @@ -46,7 +46,7 @@ */ void removeConfigListener(@NotNull FilterConfigListener listener); - void createMenuEntries(JMenu menu); + void createMenuEntries(@NotNull JMenu menu); void newSquare(@NotNull FilterState filterState); @@ -54,10 +54,10 @@ void objectInSquare(@NotNull FilterState filterState, @NotNull G gameObject); - boolean canShow(G gameObject); + boolean canShow(@NotNull G gameObject); - void addFilter(String name, Filter<?, ?> filter); + void addFilter(@NotNull String name, @NotNull Filter<?, ?> filter); - void removeFilter(String name); + void removeFilter(@NotNull String name); } // interface FilterControl Modified: trunk/src/test/net/sf/gridarta/gui/filter/TestFilterControl.java =================================================================== --- trunk/src/test/net/sf/gridarta/gui/filter/TestFilterControl.java 2010-05-16 09:58:55 UTC (rev 7795) +++ trunk/src/test/net/sf/gridarta/gui/filter/TestFilterControl.java 2010-05-16 10:00:47 UTC (rev 7796) @@ -53,7 +53,7 @@ * {@inheritDoc} */ @Override - public void createMenuEntries(final JMenu menu) { + public void createMenuEntries(@NotNull final JMenu menu) { throw new AssertionError(); } @@ -85,7 +85,7 @@ * {@inheritDoc} */ @Override - public boolean canShow(final TestGameObject gameObject) { + public boolean canShow(@NotNull final TestGameObject gameObject) { throw new AssertionError(); } @@ -93,7 +93,7 @@ * {@inheritDoc} */ @Override - public void addFilter(final String name, final Filter<?, ?> filter) { + public void addFilter(@NotNull final String name, @NotNull final Filter<?, ?> filter) { throw new AssertionError(); } @@ -101,7 +101,7 @@ * {@inheritDoc} */ @Override - public void removeFilter(final String name) { + public void removeFilter(@NotNull final String name) { throw new AssertionError(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2010-05-16 17:32:29
|
Revision: 7812 http://gridarta.svn.sourceforge.net/gridarta/?rev=7812&view=rev Author: akirschbaum Date: 2010-05-16 17:32:21 +0000 (Sun, 16 May 2010) Log Message: ----------- Fix possible NullPointerException. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/mapmanager/DefaultFileControl.java trunk/src/app/net/sf/gridarta/mapmanager/FileControl.java trunk/src/test/net/sf/gridarta/mapmanager/TestFileControl.java Modified: trunk/src/app/net/sf/gridarta/mapmanager/DefaultFileControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/mapmanager/DefaultFileControl.java 2010-05-16 17:31:42 UTC (rev 7811) +++ trunk/src/app/net/sf/gridarta/mapmanager/DefaultFileControl.java 2010-05-16 17:32:21 UTC (rev 7812) @@ -371,8 +371,8 @@ * {@inheritDoc} */ @Override - public void reportLoadError(@NotNull final File file, @NotNull final String message) { - ACTION_BUILDER.showMessageDialog(parent, "openFileLoadMap", file, message); + public void reportLoadError(@Nullable final File file, @NotNull final String message) { + ACTION_BUILDER.showMessageDialog(parent, "openFileLoadMap", file == null ? "<unknown>" : file, message); } /** Modified: trunk/src/app/net/sf/gridarta/mapmanager/FileControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/mapmanager/FileControl.java 2010-05-16 17:31:42 UTC (rev 7811) +++ trunk/src/app/net/sf/gridarta/mapmanager/FileControl.java 2010-05-16 17:32:21 UTC (rev 7812) @@ -25,6 +25,7 @@ import net.sf.gridarta.model.map.maparchobject.MapArchObject; import net.sf.gridarta.model.map.mapcontrol.MapControl; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public interface FileControl<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> { @@ -85,7 +86,7 @@ */ void reportSaveError(@NotNull File mapFile, @NotNull String message); - void reportLoadError(@NotNull File file, @NotNull String message); + void reportLoadError(@Nullable File file, @NotNull String message); void reportOutOfMapBoundsDeleted(@NotNull File file, int outOfMapBoundsDeleted, @NotNull StringBuilder outOfMapBoundsObjects); Modified: trunk/src/test/net/sf/gridarta/mapmanager/TestFileControl.java =================================================================== --- trunk/src/test/net/sf/gridarta/mapmanager/TestFileControl.java 2010-05-16 17:31:42 UTC (rev 7811) +++ trunk/src/test/net/sf/gridarta/mapmanager/TestFileControl.java 2010-05-16 17:32:21 UTC (rev 7812) @@ -25,6 +25,7 @@ import net.sf.gridarta.model.map.maparchobject.TestMapArchObject; import net.sf.gridarta.model.map.mapcontrol.MapControl; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * A {@link FileControl} implementation for testing purposes. @@ -110,7 +111,7 @@ * {@inheritDoc} */ @Override - public void reportLoadError(@NotNull final File file, @NotNull final String message) { + public void reportLoadError(@Nullable final File file, @NotNull final String message) { throw new AssertionError(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2010-05-16 18:41:47
|
Revision: 7828 http://gridarta.svn.sourceforge.net/gridarta/?rev=7828&view=rev Author: akirschbaum Date: 2010-05-16 18:41:41 +0000 (Sun, 16 May 2010) Log Message: ----------- Unify action names and function names. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/gui/newmap/NewMapDialogFactory.java trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java trunk/src/app/net/sf/gridarta/mapmanager/DefaultFileControl.java trunk/src/app/net/sf/gridarta/mapmanager/FileControl.java trunk/src/app/net/sf/gridarta/mapmanager/MapManagerActions.java trunk/src/app/net/sf/gridarta/textedit/scripteditor/Actions.java trunk/src/app/net/sf/gridarta/textedit/scripteditor/ScriptEditControl.java trunk/src/test/net/sf/gridarta/mapmanager/TestFileControl.java Modified: trunk/src/app/net/sf/gridarta/gui/newmap/NewMapDialogFactory.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/newmap/NewMapDialogFactory.java 2010-05-16 18:32:19 UTC (rev 7827) +++ trunk/src/app/net/sf/gridarta/gui/newmap/NewMapDialogFactory.java 2010-05-16 18:41:41 UTC (rev 7828) @@ -142,7 +142,7 @@ /** * Shows a dialog for creating a new map. */ - public void showNewMapDialog() { + public void newMap() { new NewMapDialog<G, A, R>(mapViewsManager, mapArchObjectFactory, parent, showMapSizeDefault, showMapDifficulty, defaultMapWidth, defaultMapHeight, defaultMapDifficulty); } Modified: trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java 2010-05-16 18:32:19 UTC (rev 7827) +++ trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java 2010-05-16 18:41:41 UTC (rev 7828) @@ -586,7 +586,7 @@ */ @ActionMethod public void newMap() { - newMapDialogFactory.showNewMapDialog(); + newMapDialogFactory.newMap(); } /** @@ -604,7 +604,7 @@ */ @ActionMethod public void newScript() { - scriptEditControl.openScriptNew(); + scriptEditControl.newScript(); } /** @@ -612,7 +612,7 @@ */ @ActionMethod public void editScript() { - fileControl.openFile(false); + fileControl.editScript(); } /** @@ -633,7 +633,7 @@ */ @ActionMethod public void openFile() { - fileControl.openFile(true); + fileControl.openFile(); } @ActionMethod @@ -660,7 +660,7 @@ * @return whether all modified data has been saved */ private boolean canExit() { - return scriptEditControl.closeAllTabs() && fileControl.closeAll() && pickmapChooserControl.canExit() && scriptControl.canExit(); + return scriptEditControl.closeAllTabs() && fileControl.closeAllMaps() && pickmapChooserControl.canExit() && scriptControl.canExit(); } /** @@ -681,7 +681,7 @@ } else if (!file.exists()) { if (isScriptFile) { // TODO: pass filename - scriptEditControl.openScriptNew(); + scriptEditControl.newScript(); } else { newMap(); // XXX: pass file } Modified: trunk/src/app/net/sf/gridarta/mapmanager/DefaultFileControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/mapmanager/DefaultFileControl.java 2010-05-16 18:32:19 UTC (rev 7827) +++ trunk/src/app/net/sf/gridarta/mapmanager/DefaultFileControl.java 2010-05-16 18:41:41 UTC (rev 7828) @@ -169,7 +169,25 @@ * {@inheritDoc} */ @Override - public void openFile(final boolean mapFilter) { + public void editScript() { + openFile(false); + } + + /** + * {@inheritDoc} + */ + @Override + public void openFile() { + openFile(true); + } + + /** + * The user wants to open a file. The filefilters and preselected filefilter + * are set accordingly to <var>mapFilter</var>. + * @param mapFilter set to <code>true</code> if the user probably wants to + * open a map, <code>false</code> otherwise + */ + private void openFile(final boolean mapFilter) { if (fileChooser == null) { createFileChooser(); } @@ -209,9 +227,9 @@ } else if (!file.exists()) { if (isScriptFile) { // TODO: pass filename - scriptEditControl.openScriptNew(); + scriptEditControl.newScript(); } else { - newMapDialogFactory.showNewMapDialog(); // XXX: pass file + newMapDialogFactory.newMap(); // XXX: pass file } } // If neither branch matches, it's a directory - what to do with directories? } @@ -240,7 +258,7 @@ * {@inheritDoc} */ @Override - public void saveAll() { + public void saveAllMaps() { for (final MapControl<G, A, R> mapControl : mapManager.getOpenedMaps()) { if (mapControl.getMapModel().isModified() && !save(mapControl)) { return; @@ -252,7 +270,7 @@ * {@inheritDoc} */ @Override - public boolean closeAll() { + public boolean closeAllMaps() { for (; ;) { final MapControl<G, A, R> mapControl = mapManager.getOpenMap(); if (mapControl == null) { Modified: trunk/src/app/net/sf/gridarta/mapmanager/FileControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/mapmanager/FileControl.java 2010-05-16 18:32:19 UTC (rev 7827) +++ trunk/src/app/net/sf/gridarta/mapmanager/FileControl.java 2010-05-16 18:41:41 UTC (rev 7828) @@ -30,14 +30,16 @@ public interface FileControl<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> { /** - * The user wants to open a file. The filefilters and preselected filefilter - * are set accordingly to <var>mapFilter</var>. - * @param mapFilter set to <code>true</code> if the user probably wants to - * open a map, <code>false</code> otherwise + * The user wants to edit a script file. */ - void openFile(boolean mapFilter); + void editScript(); /** + * The user wants to open a map file. + */ + void openFile(); + + /** * Save one map. * @param mapControl the map * @return <code>false</code> if saving failed, <code>true</code> otherwise @@ -47,14 +49,14 @@ /** * Saves all maps. */ - void saveAll(); + void saveAllMaps(); /** * Invoked when the user wants to close all maps. * @return <code>true</code> if all maps closed, <code>false</code> if user * cancelled. */ - boolean closeAll(); + boolean closeAllMaps(); /** * Asks the user for a filename, then saves the map. Modified: trunk/src/app/net/sf/gridarta/mapmanager/MapManagerActions.java =================================================================== --- trunk/src/app/net/sf/gridarta/mapmanager/MapManagerActions.java 2010-05-16 18:32:19 UTC (rev 7827) +++ trunk/src/app/net/sf/gridarta/mapmanager/MapManagerActions.java 2010-05-16 18:41:41 UTC (rev 7828) @@ -74,14 +74,14 @@ * Invoked when the user wants to save all map files. */ public void saveAllMaps() { - fileControl.saveAll(); + fileControl.saveAllMaps(); } /** * Invoked when the user wants to close all map files. */ public void closeAllMaps() { - fileControl.closeAll(); + fileControl.closeAllMaps(); } } // class MapManagerActions Modified: trunk/src/app/net/sf/gridarta/textedit/scripteditor/Actions.java =================================================================== --- trunk/src/app/net/sf/gridarta/textedit/scripteditor/Actions.java 2010-05-16 18:32:19 UTC (rev 7827) +++ trunk/src/app/net/sf/gridarta/textedit/scripteditor/Actions.java 2010-05-16 18:41:41 UTC (rev 7828) @@ -143,7 +143,7 @@ * Action for "new script". */ public void scriptEditNewScript() { - control.openScriptNew(); + control.newScript(); } /** Modified: trunk/src/app/net/sf/gridarta/textedit/scripteditor/ScriptEditControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/textedit/scripteditor/ScriptEditControl.java 2010-05-16 18:32:19 UTC (rev 7827) +++ trunk/src/app/net/sf/gridarta/textedit/scripteditor/ScriptEditControl.java 2010-05-16 18:41:41 UTC (rev 7828) @@ -102,7 +102,7 @@ /** * Open a new empty script document. */ - public void openScriptNew() { + public void newScript() { tabs.add("<>"); // this script has no filename assigned yet view.addTab("<New Script>", null); } @@ -164,7 +164,7 @@ openScriptFile(file.getAbsolutePath()); } else { // user entered a filename which doesn't yet exist -> open new script - openScriptNew(); + newScript(); } } Modified: trunk/src/test/net/sf/gridarta/mapmanager/TestFileControl.java =================================================================== --- trunk/src/test/net/sf/gridarta/mapmanager/TestFileControl.java 2010-05-16 18:32:19 UTC (rev 7827) +++ trunk/src/test/net/sf/gridarta/mapmanager/TestFileControl.java 2010-05-16 18:41:41 UTC (rev 7828) @@ -43,7 +43,7 @@ * {@inheritDoc} */ @Override - public void openFile(final boolean mapFilter) { + public void editScript() { throw new AssertionError(); } @@ -51,6 +51,14 @@ * {@inheritDoc} */ @Override + public void openFile() { + throw new AssertionError(); + } + + /** + * {@inheritDoc} + */ + @Override public boolean save(@NotNull final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl) { throw new AssertionError(); } @@ -59,7 +67,7 @@ * {@inheritDoc} */ @Override - public void saveAll() { + public void saveAllMaps() { throw new AssertionError(); } @@ -67,7 +75,7 @@ * {@inheritDoc} */ @Override - public boolean closeAll() { + public boolean closeAllMaps() { throw new AssertionError(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2010-05-23 13:46:30
|
Revision: 7928 http://gridarta.svn.sourceforge.net/gridarta/?rev=7928&view=rev Author: akirschbaum Date: 2010-05-23 13:46:23 +0000 (Sun, 23 May 2010) Log Message: ----------- Fix or suppress clone() related compiler warnings. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/gui/gameobjectattributesdialog/MaskChangeAL.java trunk/src/app/net/sf/gridarta/gui/gameobjectattributesdialog/ViewTreasurelistAL.java trunk/src/app/net/sf/gridarta/gui/mapdesktop/WindowAction.java trunk/src/app/net/sf/gridarta/gui/mapfiles/MapFolderTreeAction.java trunk/src/app/net/sf/gridarta/gui/misc/Recent.java trunk/src/app/net/sf/gridarta/gui/utils/AnimTreeChooseAction.java trunk/src/app/net/sf/gridarta/gui/utils/FaceTreeChooseAction.java trunk/src/app/net/sf/gridarta/gui/utils/TreeChooseAction.java trunk/src/app/net/sf/gridarta/gui/utils/tabbedpanel/TabButtonAction.java trunk/src/app/net/sf/gridarta/model/archetypetype/ArchetypeAttribute.java trunk/src/app/net/sf/gridarta/model/archetypetype/ArchetypeTypeParser.java trunk/src/app/net/sf/gridarta/model/baseobject/AbstractBaseObject.java trunk/src/app/net/sf/gridarta/model/baseobject/GameObjectContainer.java trunk/src/app/net/sf/gridarta/model/baseobject/GameObjectText.java trunk/src/app/net/sf/gridarta/model/gameobject/DefaultIsoGameObject.java trunk/src/app/net/sf/gridarta/model/map/maparchobject/AbstractMapArchObject.java trunk/src/app/net/sf/gridarta/model/map/mapmodel/MapSquare.java trunk/src/app/net/sf/gridarta/model/match/SetEnabledAction.java trunk/src/app/net/sf/gridarta/model/match/ViewGameObjectMatcherManager.java trunk/src/test/net/sf/gridarta/model/map/maparchobject/TestMapArchObject.java Modified: trunk/src/app/net/sf/gridarta/gui/gameobjectattributesdialog/MaskChangeAL.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/gameobjectattributesdialog/MaskChangeAL.java 2010-05-23 13:22:46 UTC (rev 7927) +++ trunk/src/app/net/sf/gridarta/gui/gameobjectattributesdialog/MaskChangeAL.java 2010-05-23 13:46:23 UTC (rev 7928) @@ -154,8 +154,12 @@ * {@inheritDoc} */ @Override - protected Object clone() throws CloneNotSupportedException { - return super.clone(); + protected Object clone() { + try { + return super.clone(); + } catch (final CloneNotSupportedException ex) { + throw new AssertionError(ex); + } } /** Modified: trunk/src/app/net/sf/gridarta/gui/gameobjectattributesdialog/ViewTreasurelistAL.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/gameobjectattributesdialog/ViewTreasurelistAL.java 2010-05-23 13:22:46 UTC (rev 7927) +++ trunk/src/app/net/sf/gridarta/gui/gameobjectattributesdialog/ViewTreasurelistAL.java 2010-05-23 13:46:23 UTC (rev 7928) @@ -75,8 +75,12 @@ * {@inheritDoc} */ @Override - protected Object clone() throws CloneNotSupportedException { - return super.clone(); + protected Object clone() { + try { + return super.clone(); + } catch (final CloneNotSupportedException ex) { + throw new AssertionError(ex); + } } } // class ViewTreasurelistAL Modified: trunk/src/app/net/sf/gridarta/gui/mapdesktop/WindowAction.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/mapdesktop/WindowAction.java 2010-05-23 13:22:46 UTC (rev 7927) +++ trunk/src/app/net/sf/gridarta/gui/mapdesktop/WindowAction.java 2010-05-23 13:46:23 UTC (rev 7928) @@ -214,8 +214,12 @@ */ @NotNull @Override - public Object clone() throws CloneNotSupportedException { - return super.clone(); + public Object clone() { + try { + return super.clone(); + } catch (final CloneNotSupportedException ex) { + throw new AssertionError(ex); + } } } // class WindowAction Modified: trunk/src/app/net/sf/gridarta/gui/mapfiles/MapFolderTreeAction.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/mapfiles/MapFolderTreeAction.java 2010-05-23 13:22:46 UTC (rev 7927) +++ trunk/src/app/net/sf/gridarta/gui/mapfiles/MapFolderTreeAction.java 2010-05-23 13:46:23 UTC (rev 7928) @@ -101,8 +101,12 @@ * {@inheritDoc} */ @Override - protected Object clone() throws CloneNotSupportedException { - return super.clone(); + protected Object clone() { + try { + return super.clone(); + } catch (final CloneNotSupportedException ex) { + throw new AssertionError(ex); + } } } // class MapFolderTreeAction Modified: trunk/src/app/net/sf/gridarta/gui/misc/Recent.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/misc/Recent.java 2010-05-23 13:22:46 UTC (rev 7927) +++ trunk/src/app/net/sf/gridarta/gui/misc/Recent.java 2010-05-23 13:46:23 UTC (rev 7928) @@ -218,8 +218,12 @@ * {@inheritDoc} */ @Override - protected Object clone() throws CloneNotSupportedException { - return super.clone(); + protected Object clone() { + try { + return super.clone(); + } catch (final CloneNotSupportedException ex) { + throw new AssertionError(ex); + } } } // class Recent Modified: trunk/src/app/net/sf/gridarta/gui/utils/AnimTreeChooseAction.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/utils/AnimTreeChooseAction.java 2010-05-23 13:22:46 UTC (rev 7927) +++ trunk/src/app/net/sf/gridarta/gui/utils/AnimTreeChooseAction.java 2010-05-23 13:46:23 UTC (rev 7928) @@ -119,7 +119,7 @@ */ @NotNull @Override - protected Object clone() throws CloneNotSupportedException { + protected Object clone() { return super.clone(); } Modified: trunk/src/app/net/sf/gridarta/gui/utils/FaceTreeChooseAction.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/utils/FaceTreeChooseAction.java 2010-05-23 13:22:46 UTC (rev 7927) +++ trunk/src/app/net/sf/gridarta/gui/utils/FaceTreeChooseAction.java 2010-05-23 13:46:23 UTC (rev 7928) @@ -105,7 +105,7 @@ */ @NotNull @Override - protected Object clone() throws CloneNotSupportedException { + protected Object clone() { return super.clone(); } Modified: trunk/src/app/net/sf/gridarta/gui/utils/TreeChooseAction.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/utils/TreeChooseAction.java 2010-05-23 13:22:46 UTC (rev 7927) +++ trunk/src/app/net/sf/gridarta/gui/utils/TreeChooseAction.java 2010-05-23 13:46:23 UTC (rev 7928) @@ -104,8 +104,12 @@ */ @NotNull @Override - protected Object clone() throws CloneNotSupportedException { - return super.clone(); + protected Object clone() { + try { + return super.clone(); + } catch (final CloneNotSupportedException ex) { + throw new AssertionError(ex); + } } } // class TreeChooseAction Modified: trunk/src/app/net/sf/gridarta/gui/utils/tabbedpanel/TabButtonAction.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/utils/tabbedpanel/TabButtonAction.java 2010-05-23 13:22:46 UTC (rev 7927) +++ trunk/src/app/net/sf/gridarta/gui/utils/tabbedpanel/TabButtonAction.java 2010-05-23 13:46:23 UTC (rev 7928) @@ -80,8 +80,12 @@ * {@inheritDoc} */ @Override - protected Object clone() throws CloneNotSupportedException { - return super.clone(); + protected Object clone() { + try { + return super.clone(); + } catch (final CloneNotSupportedException ex) { + throw new AssertionError(ex); + } } } Modified: trunk/src/app/net/sf/gridarta/model/archetypetype/ArchetypeAttribute.java =================================================================== --- trunk/src/app/net/sf/gridarta/model/archetypetype/ArchetypeAttribute.java 2010-05-23 13:22:46 UTC (rev 7927) +++ trunk/src/app/net/sf/gridarta/model/archetypetype/ArchetypeAttribute.java 2010-05-23 13:46:23 UTC (rev 7928) @@ -90,8 +90,13 @@ */ @NotNull @Override - public ArchetypeAttribute<G, A, R> clone() throws CloneNotSupportedException { - return (ArchetypeAttribute<G, A, R>) super.clone(); + @SuppressWarnings({ "unchecked" }) + public ArchetypeAttribute<G, A, R> clone() { + try { + return (ArchetypeAttribute<G, A, R>) super.clone(); + } catch (final CloneNotSupportedException ex) { + throw new AssertionError(ex); + } } /** Modified: trunk/src/app/net/sf/gridarta/model/archetypetype/ArchetypeTypeParser.java =================================================================== --- trunk/src/app/net/sf/gridarta/model/archetypetype/ArchetypeTypeParser.java 2010-05-23 13:22:46 UTC (rev 7927) +++ trunk/src/app/net/sf/gridarta/model/archetypetype/ArchetypeTypeParser.java 2010-05-23 13:46:23 UTC (rev 7928) @@ -212,11 +212,7 @@ @NotNull private ArchetypeAttribute<G, A, R> cloneAttribute(@NotNull final ArchetypeAttribute<G, A, R> attrib) { - try { - return attrib.clone(); - } catch (final CloneNotSupportedException e) { - throw new AssertionError(); - } + return attrib.clone(); } @Nullable Modified: trunk/src/app/net/sf/gridarta/model/baseobject/AbstractBaseObject.java =================================================================== --- trunk/src/app/net/sf/gridarta/model/baseobject/AbstractBaseObject.java 2010-05-23 13:22:46 UTC (rev 7927) +++ trunk/src/app/net/sf/gridarta/model/baseobject/AbstractBaseObject.java 2010-05-23 13:46:23 UTC (rev 7928) @@ -754,7 +754,7 @@ @Override @NotNull public Object clone() { - final AbstractBaseObject<G, A, R, T> clone = (AbstractBaseObject<G, A, R, T>) super.clone(); + final AbstractBaseObject<?, ?, ?, ?> clone = (AbstractBaseObject<?, ?, ?, ?>) super.clone(); // clone.archetype = archetype; // will NOT be cloned: archetypes are unique clone.gameObjectText = gameObjectText.clone(); if (msgText != null) { Modified: trunk/src/app/net/sf/gridarta/model/baseobject/GameObjectContainer.java =================================================================== --- trunk/src/app/net/sf/gridarta/model/baseobject/GameObjectContainer.java 2010-05-23 13:22:46 UTC (rev 7927) +++ trunk/src/app/net/sf/gridarta/model/baseobject/GameObjectContainer.java 2010-05-23 13:46:23 UTC (rev 7928) @@ -594,6 +594,7 @@ */ @NotNull @Override + @SuppressWarnings({ "unchecked" }) protected Object clone() { try { final GameObjectContainer<G, A, R> clone = (GameObjectContainer<G, A, R>) super.clone(); Modified: trunk/src/app/net/sf/gridarta/model/baseobject/GameObjectText.java =================================================================== --- trunk/src/app/net/sf/gridarta/model/baseobject/GameObjectText.java 2010-05-23 13:22:46 UTC (rev 7927) +++ trunk/src/app/net/sf/gridarta/model/baseobject/GameObjectText.java 2010-05-23 13:46:23 UTC (rev 7928) @@ -105,7 +105,7 @@ try { clone = (GameObjectText) super.clone(); } catch (final CloneNotSupportedException ex) { - throw new AssertionError(); + throw new AssertionError(ex); } clone.objectText = new StringBuilder(objectText); clone.attributeCache = new HashMap<String, String>(attributeCache); Modified: trunk/src/app/net/sf/gridarta/model/gameobject/DefaultIsoGameObject.java =================================================================== --- trunk/src/app/net/sf/gridarta/model/gameobject/DefaultIsoGameObject.java 2010-05-23 13:22:46 UTC (rev 7927) +++ trunk/src/app/net/sf/gridarta/model/gameobject/DefaultIsoGameObject.java 2010-05-23 13:46:23 UTC (rev 7928) @@ -154,6 +154,7 @@ */ @NotNull @Override + @SuppressWarnings({ "unchecked" }) public DefaultIsoGameObject<G, A, R> clone() { return (DefaultIsoGameObject<G, A, R>) super.clone(); } Modified: trunk/src/app/net/sf/gridarta/model/map/maparchobject/AbstractMapArchObject.java =================================================================== --- trunk/src/app/net/sf/gridarta/model/map/maparchobject/AbstractMapArchObject.java 2010-05-23 13:22:46 UTC (rev 7927) +++ trunk/src/app/net/sf/gridarta/model/map/maparchobject/AbstractMapArchObject.java 2010-05-23 13:46:23 UTC (rev 7928) @@ -612,7 +612,7 @@ try { clone = (AbstractMapArchObject<?>) super.clone(); } catch (final CloneNotSupportedException ex) { - throw new AssertionError(); + throw new AssertionError(ex); } clone.msgText = new StringBuilder(msgText.toString()); clone.tilePaths = tilePaths.clone(); Modified: trunk/src/app/net/sf/gridarta/model/map/mapmodel/MapSquare.java =================================================================== --- trunk/src/app/net/sf/gridarta/model/map/mapmodel/MapSquare.java 2010-05-23 13:22:46 UTC (rev 7927) +++ trunk/src/app/net/sf/gridarta/model/map/mapmodel/MapSquare.java 2010-05-23 13:46:23 UTC (rev 7928) @@ -126,6 +126,7 @@ */ @NotNull @Override + @SuppressWarnings({ "unchecked" }) protected MapSquare<G, A, R> clone() { final MapSquare<G, A, R> clone = (MapSquare<G, A, R>) super.clone(); return clone; Modified: trunk/src/app/net/sf/gridarta/model/match/SetEnabledAction.java =================================================================== --- trunk/src/app/net/sf/gridarta/model/match/SetEnabledAction.java 2010-05-23 13:22:46 UTC (rev 7927) +++ trunk/src/app/net/sf/gridarta/model/match/SetEnabledAction.java 2010-05-23 13:46:23 UTC (rev 7928) @@ -101,7 +101,7 @@ try { return (SetEnabledAction) super.clone(); } catch (final CloneNotSupportedException ex) { - throw new AssertionError(); + throw new AssertionError(ex); } } Modified: trunk/src/app/net/sf/gridarta/model/match/ViewGameObjectMatcherManager.java =================================================================== --- trunk/src/app/net/sf/gridarta/model/match/ViewGameObjectMatcherManager.java 2010-05-23 13:22:46 UTC (rev 7927) +++ trunk/src/app/net/sf/gridarta/model/match/ViewGameObjectMatcherManager.java 2010-05-23 13:46:23 UTC (rev 7928) @@ -131,8 +131,12 @@ */ @NotNull @Override - protected Object clone() throws CloneNotSupportedException { - return super.clone(); + protected Object clone() { + try { + return super.clone(); + } catch (final CloneNotSupportedException ex) { + throw new AssertionError(ex); + } } } // class ResetAction @@ -217,8 +221,12 @@ */ @NotNull @Override - protected Object clone() throws CloneNotSupportedException { - return super.clone(); + protected Object clone() { + try { + return super.clone(); + } catch (final CloneNotSupportedException ex) { + throw new AssertionError(ex); + } } } // class GameObjectMatcherToggleAction Modified: trunk/src/test/net/sf/gridarta/model/map/maparchobject/TestMapArchObject.java =================================================================== --- trunk/src/test/net/sf/gridarta/model/map/maparchobject/TestMapArchObject.java 2010-05-23 13:22:46 UTC (rev 7927) +++ trunk/src/test/net/sf/gridarta/model/map/maparchobject/TestMapArchObject.java 2010-05-23 13:46:23 UTC (rev 7928) @@ -257,7 +257,7 @@ try { return super.clone(); } catch (final CloneNotSupportedException ex) { - throw new AssertionError(); + throw new AssertionError(ex); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2010-05-23 15:26:46
|
Revision: 7932 http://gridarta.svn.sourceforge.net/gridarta/?rev=7932&view=rev Author: akirschbaum Date: 2010-05-23 15:26:39 +0000 (Sun, 23 May 2010) Log Message: ----------- Replace null return value with exception. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/exitconnector/ExitConnectorActions.java trunk/src/app/net/sf/gridarta/gui/treasurelist/TreasureCellRenderer.java trunk/src/app/net/sf/gridarta/model/archetype/AbstractArchetypeSet.java trunk/src/app/net/sf/gridarta/model/archetype/ArchetypeSet.java trunk/src/app/net/sf/gridarta/model/artifact/ArtifactParser.java trunk/src/app/net/sf/gridarta/model/autojoin/AutojoinListsParser.java trunk/src/app/net/sf/gridarta/model/scripts/AbstractScriptedEventFactory.java trunk/src/app/net/sf/gridarta/model/scripts/UndefinedEventArchetypeException.java trunk/src/app/net/sf/gridarta/model/scripts/UndefinedEventArchetypeNameException.java trunk/src/app/net/sf/gridarta/script/parameter/ArchParameter.java trunk/src/test/net/sf/gridarta/model/archetype/ArchetypeParserTest.java trunk/src/test/net/sf/gridarta/model/artifact/ArtifactParserTest.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/model/archetype/UndefinedArchetypeException.java Modified: trunk/src/app/net/sf/gridarta/exitconnector/ExitConnectorActions.java =================================================================== --- trunk/src/app/net/sf/gridarta/exitconnector/ExitConnectorActions.java 2010-05-23 14:55:44 UTC (rev 7931) +++ trunk/src/app/net/sf/gridarta/exitconnector/ExitConnectorActions.java 2010-05-23 15:26:39 UTC (rev 7932) @@ -26,6 +26,7 @@ import net.sf.gridarta.mapmanager.MapManager; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.archetype.ArchetypeSet; +import net.sf.gridarta.model.archetype.UndefinedArchetypeException; import net.sf.gridarta.model.baseobject.BaseObject; import net.sf.gridarta.model.exitconnector.ExitConnectorModel; import net.sf.gridarta.model.exitconnector.ExitLocation; @@ -168,8 +169,10 @@ } else { // paste into newly created exit game object - final BaseObject<G, A, R, ?> targetArchetype = archetypeSet.getArchetype(exitConnectorModel.getExitArchetypeName()); - if (targetArchetype == null) { + final BaseObject<G, A, R, ?> targetArchetype; + try { + targetArchetype = archetypeSet.getArchetype(exitConnectorModel.getExitArchetypeName()); + } catch (final UndefinedArchetypeException ignored) { return false; } @@ -216,8 +219,9 @@ targetArchetype = null; } else if (exitConnectorModel.isAutoCreateExit()) { targetExit = null; - targetArchetype = archetypeSet.getArchetype(exitConnectorModel.getExitArchetypeName()); - if (targetArchetype == null) { + try { + targetArchetype = archetypeSet.getArchetype(exitConnectorModel.getExitArchetypeName()); + } catch (final UndefinedArchetypeException ignored) { return false; } } else { @@ -280,8 +284,9 @@ sourceArchetype = null; } else if (exitConnectorModel.isAutoCreateExit()) { sourceExit = null; - sourceArchetype = archetypeSet.getArchetype(exitConnectorModel.getExitArchetypeName()); - if (sourceArchetype == null) { + try { + sourceArchetype = archetypeSet.getArchetype(exitConnectorModel.getExitArchetypeName()); + } catch (final UndefinedArchetypeException ignored) { return false; } } else { Modified: trunk/src/app/net/sf/gridarta/gui/treasurelist/TreasureCellRenderer.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/treasurelist/TreasureCellRenderer.java 2010-05-23 14:55:44 UTC (rev 7931) +++ trunk/src/app/net/sf/gridarta/gui/treasurelist/TreasureCellRenderer.java 2010-05-23 15:26:39 UTC (rev 7932) @@ -28,7 +28,7 @@ import javax.swing.tree.DefaultTreeCellRenderer; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.archetype.ArchetypeSet; -import net.sf.gridarta.model.baseobject.BaseObject; +import net.sf.gridarta.model.archetype.UndefinedArchetypeException; import net.sf.gridarta.model.face.FaceObjectProviders; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.map.maparchobject.MapArchObject; @@ -81,10 +81,9 @@ /** {@inheritDoc} */ @Override public void visit(@NotNull final ArchTreasureObj treasureObj) { - final BaseObject<G, A, R, ?> archetype = archetypeSet.getArchetype(treasureObj.getName()); - if (archetype != null) { - setIcon(faceObjectProviders.getFace(archetype)); - } else { + try { + setIcon(faceObjectProviders.getFace(archetypeSet.getArchetype(treasureObj.getName()))); + } catch (final UndefinedArchetypeException ignored) { setIcon(systemIcons.getNoarchSquareIcon()); } setBorder(BorderFactory.createEmptyBorder(1, 0, 1, 0)); Modified: trunk/src/app/net/sf/gridarta/model/archetype/AbstractArchetypeSet.java =================================================================== --- trunk/src/app/net/sf/gridarta/model/archetype/AbstractArchetypeSet.java 2010-05-23 14:55:44 UTC (rev 7931) +++ trunk/src/app/net/sf/gridarta/model/archetype/AbstractArchetypeSet.java 2010-05-23 15:26:39 UTC (rev 7932) @@ -41,7 +41,6 @@ import net.sf.japi.swing.action.ActionBuilderFactory; import net.sf.japi.swing.misc.Progress; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; /** * Base implementation of ArchetypeSet. @@ -128,10 +127,15 @@ /** * {@inheritDoc} */ - @Nullable + @NotNull @Override - public R getArchetype(@NotNull final String archetypeName) { - return archetypeMap.get(archetypeName); + public R getArchetype(@NotNull final String archetypeName) throws UndefinedArchetypeException { + final R archetype = archetypeMap.get(archetypeName); + if (archetype == null) { + throw new UndefinedArchetypeException(archetypeName); + } + + return archetype; } /** @@ -140,23 +144,22 @@ @NotNull @Override public R getOrCreateArchetype(@NotNull final String archetypeName) { - final R existingArchetype = getArchetype(archetypeName); - if (existingArchetype != null) { - return existingArchetype; - } + try { + return getArchetype(archetypeName); + } catch (final UndefinedArchetypeException ignored) { + synchronized (undefinedArchetypes) { + final WeakReference<R> existingUndefinedArchetypeRef = undefinedArchetypes.get(archetypeName); + if (existingUndefinedArchetypeRef != null) { + final R existingUndefinedArchetype = existingUndefinedArchetypeRef.get(); + if (existingUndefinedArchetype != null) { + return existingUndefinedArchetype; + } + } - synchronized (undefinedArchetypes) { - final WeakReference<R> existingUndefinedArchetypeRef = undefinedArchetypes.get(archetypeName); - if (existingUndefinedArchetypeRef != null) { - final R existingUndefinedArchetype = existingUndefinedArchetypeRef.get(); - if (existingUndefinedArchetype != null) { - return existingUndefinedArchetype; - } + final R newArchetype = archetypeFactory.newUndefinedArchetype(archetypeName); + undefinedArchetypes.put(archetypeName, new WeakReference<R>(newArchetype)); + return newArchetype; } - - final R newArchetype = archetypeFactory.newUndefinedArchetype(archetypeName); - undefinedArchetypes.put(archetypeName, new WeakReference<R>(newArchetype)); - return newArchetype; } } Modified: trunk/src/app/net/sf/gridarta/model/archetype/ArchetypeSet.java =================================================================== --- trunk/src/app/net/sf/gridarta/model/archetype/ArchetypeSet.java 2010-05-23 14:55:44 UTC (rev 7931) +++ trunk/src/app/net/sf/gridarta/model/archetype/ArchetypeSet.java 2010-05-23 15:26:39 UTC (rev 7932) @@ -50,15 +50,15 @@ /** * Get an Archetype by its name. * @param archetypeName name of the Archetype to get - * @return Archetype for <var>archetypeName</var> or <code>null</code> if no - * such Archetype + * @return the archetype + * @throws UndefinedArchetypeException if the no such archetype exists * @see net.sf.gridarta.model.gameobject.GameObjectFactory#newGameObject(String) * for a similar method that instantiates. * @see #getOrCreateArchetype(String) for a similar method that creates * undefined archetypes */ - @Nullable - R getArchetype(@NotNull String archetypeName); + @NotNull + R getArchetype(@NotNull String archetypeName) throws UndefinedArchetypeException; /** * Get an archetype by its name. If this archetype does not exist, return an Added: trunk/src/app/net/sf/gridarta/model/archetype/UndefinedArchetypeException.java =================================================================== --- trunk/src/app/net/sf/gridarta/model/archetype/UndefinedArchetypeException.java (rev 0) +++ trunk/src/app/net/sf/gridarta/model/archetype/UndefinedArchetypeException.java 2010-05-23 15:26:39 UTC (rev 7932) @@ -0,0 +1,43 @@ +/* + * 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.archetype; + +import org.jetbrains.annotations.NotNull; + +/** + * Exception thrown if an {@link Archetype} does not exist. + * @author Andreas Kirschbaum + */ +public class UndefinedArchetypeException extends Exception { + + /** + * The serial version UID. + */ + private static final long serialVersionUID = 1L; + + /** + * Creates a new instance. + * @param archetypeName the name of the undefined archetype + */ + public UndefinedArchetypeException(@NotNull final String archetypeName) { + super(archetypeName); + } + +} // class UndefinedArchetypeException Property changes on: trunk/src/app/net/sf/gridarta/model/archetype/UndefinedArchetypeException.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Modified: trunk/src/app/net/sf/gridarta/model/artifact/ArtifactParser.java =================================================================== --- trunk/src/app/net/sf/gridarta/model/artifact/ArtifactParser.java 2010-05-23 14:55:44 UTC (rev 7931) +++ trunk/src/app/net/sf/gridarta/model/artifact/ArtifactParser.java 2010-05-23 15:26:39 UTC (rev 7932) @@ -30,6 +30,7 @@ import net.sf.gridarta.model.archetype.AbstractArchetypeParser; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.archetype.ArchetypeSet; +import net.sf.gridarta.model.archetype.UndefinedArchetypeException; import net.sf.gridarta.model.errorview.ErrorView; import net.sf.gridarta.model.errorview.ErrorViewCategory; import net.sf.gridarta.model.errorview.ErrorViewCollector; @@ -231,19 +232,20 @@ } else if (name == null || name.length() == 0 || defArchName.length() == 0) { errorViewCollector.addWarning(ErrorViewCategory.ARTIFACT_ENTRY_INVALID, "line " + lineCount + ", Object '" + defArchName + "' / '" + name + "' / '" + objTitle + "' has missing name"); } else { - final R archetype = archetypeSet.getArchetype(defArchName); - if (archetype == null) { + try { + final R archetype = archetypeSet.getArchetype(defArchName); + if (editorCode != 0 && editorCode != 2) { // the next line of our file is part of a arch parse until a "end" comes + // now the editor will do the same as the real server: + // get the default arch as base and parse the new values over it + // the extended functions of the artifacts file can be ignored here. + archetypeParser.parseArchetypeFromStream(in, editorCode == 2 ? null : archetype, thisLine, name, panelName, folderName, archPath, invObjects, errorViewCollector); // XXX: editorCode == 2 looks incorrect due to the enclosing condition editorCode != 2 + // note: in the parser is a small part where we handle the title setting + // and the reverse type setting for type == -1 (unique items marker in artifacts file) + } else { + while ((thisLine = in.readLine()) != null && !thisLine.equals("end")) { + } +} } catch (final UndefinedArchetypeException ex) { errorViewCollector.addWarning(ErrorViewCategory.ARTIFACT_ENTRY_INVALID, "line " + lineCount + ", Object '" + defArchName + "' / '" + name + "' / '" + objTitle + "' references undefined defArch"); - } else if (editorCode != 0 && editorCode != 2) { // the next line of our file is part of a arch parse until a "end" comes - // now the editor will do the same as the real server: - // get the default arch as base and parse the new values over it - // the extended functions of the artifacts file can be ignored here. - archetypeParser.parseArchetypeFromStream(in, editorCode == 2 ? null : archetype, thisLine, name, panelName, folderName, archPath, invObjects, errorViewCollector); // XXX: editorCode == 2 looks incorrect due to the enclosing condition editorCode != 2 - // note: in the parser is a small part where we handle the title setting - // and the reverse type setting for type == -1 (unique items marker in artifacts file) - } else { - while ((thisLine = in.readLine()) != null && !thisLine.equals("end")) { - } } } name = null; Modified: trunk/src/app/net/sf/gridarta/model/autojoin/AutojoinListsParser.java =================================================================== --- trunk/src/app/net/sf/gridarta/model/autojoin/AutojoinListsParser.java 2010-05-23 14:55:44 UTC (rev 7931) +++ trunk/src/app/net/sf/gridarta/model/autojoin/AutojoinListsParser.java 2010-05-23 15:26:39 UTC (rev 7932) @@ -30,6 +30,7 @@ import java.util.List; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.archetype.ArchetypeSet; +import net.sf.gridarta.model.archetype.UndefinedArchetypeException; import net.sf.gridarta.model.errorview.ErrorView; import net.sf.gridarta.model.errorview.ErrorViewCategory; import net.sf.gridarta.model.gameobject.GameObject; @@ -112,15 +113,15 @@ } sectionFlag = false; } else { - final R archetype = archetypeSet.getArchetype(line); - if (archetype != null) { + try { + final R archetype = archetypeSet.getArchetype(line); if (archetype.isMulti()) { errorView.addWarning(ErrorViewCategory.AUTOJOIN_ENTRY_INVALID, url + ": list contains multi-part game object: archetype '" + line + "'"); skipList = true; } else { archetypes.add(archetype); } - } else { + } catch (final UndefinedArchetypeException ex) { if (archetypeSet.getArchetypeCount() >= 1) { errorView.addWarning(ErrorViewCategory.AUTOJOIN_ENTRY_INVALID, url + ": Autojoin list references undefined archetype: archetype '" + line + "'"); skipList = true; Modified: trunk/src/app/net/sf/gridarta/model/scripts/AbstractScriptedEventFactory.java =================================================================== --- trunk/src/app/net/sf/gridarta/model/scripts/AbstractScriptedEventFactory.java 2010-05-23 14:55:44 UTC (rev 7931) +++ trunk/src/app/net/sf/gridarta/model/scripts/AbstractScriptedEventFactory.java 2010-05-23 15:26:39 UTC (rev 7932) @@ -21,6 +21,7 @@ import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.archetype.ArchetypeSet; +import net.sf.gridarta.model.archetype.UndefinedArchetypeException; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.gameobject.GameObjectFactory; import net.sf.gridarta.model.map.maparchobject.MapArchObject; @@ -70,9 +71,11 @@ @Override public G newEventGameObject(final int eventType) throws UndefinedEventArchetypeException { final String eventArchetypeName = scriptArchUtils.getArchetypeNameForEventType(eventType); - final R eventArchetype = archetypeSet.getArchetype(eventArchetypeName); - if (eventArchetype == null) { - throw new UndefinedEventArchetypeNameException(eventArchetypeName); + final R eventArchetype; + try { + eventArchetype = archetypeSet.getArchetype(eventArchetypeName); + } catch (final UndefinedArchetypeException ex) { + throw new UndefinedEventArchetypeNameException(eventArchetypeName, ex); } return gameObjectFactory.createGameObject(eventArchetype); } Modified: trunk/src/app/net/sf/gridarta/model/scripts/UndefinedEventArchetypeException.java =================================================================== --- trunk/src/app/net/sf/gridarta/model/scripts/UndefinedEventArchetypeException.java 2010-05-23 14:55:44 UTC (rev 7931) +++ trunk/src/app/net/sf/gridarta/model/scripts/UndefinedEventArchetypeException.java 2010-05-23 15:26:39 UTC (rev 7932) @@ -34,11 +34,20 @@ private static final long serialVersionUID = 1L; /** - * Create a new instance. + * Creates a new instance. * @param msg the exception message */ protected UndefinedEventArchetypeException(@NotNull final String msg) { super(msg); } + /** + * Creates a new instance. + * @param msg the exception message + * @param cause the cause + */ + protected UndefinedEventArchetypeException(@NotNull final String msg, @NotNull final Throwable cause) { + super(msg, cause); + } + } // class UndefinedEventArchetypeException Modified: trunk/src/app/net/sf/gridarta/model/scripts/UndefinedEventArchetypeNameException.java =================================================================== --- trunk/src/app/net/sf/gridarta/model/scripts/UndefinedEventArchetypeNameException.java 2010-05-23 14:55:44 UTC (rev 7931) +++ trunk/src/app/net/sf/gridarta/model/scripts/UndefinedEventArchetypeNameException.java 2010-05-23 15:26:39 UTC (rev 7932) @@ -43,9 +43,10 @@ /** * Create a new instance. * @param archName the archetype that could not be found + * @param cause the cause */ - public UndefinedEventArchetypeNameException(@NotNull final String archName) { - super("undefined archetype " + archName); + public UndefinedEventArchetypeNameException(@NotNull final String archName, @NotNull final Throwable cause) { + super("undefined archetype " + archName, cause); this.archName = archName; } Modified: trunk/src/app/net/sf/gridarta/script/parameter/ArchParameter.java =================================================================== --- trunk/src/app/net/sf/gridarta/script/parameter/ArchParameter.java 2010-05-23 14:55:44 UTC (rev 7931) +++ trunk/src/app/net/sf/gridarta/script/parameter/ArchParameter.java 2010-05-23 15:26:39 UTC (rev 7932) @@ -21,6 +21,7 @@ import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.archetype.ArchetypeSet; +import net.sf.gridarta.model.archetype.UndefinedArchetypeException; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.map.maparchobject.MapArchObject; import org.jdom.Element; @@ -47,7 +48,7 @@ public void fromXML(@NotNull final Element e) { super.fromXML(e); valueString = e.getChildTextTrim("value"); - setValue(archetypeSet.getArchetype(valueString)); + setValue(archetypeSet.getOrCreateArchetype(valueString)); } /** @@ -75,10 +76,7 @@ @Override public Archetype<G, A, R> getValue() { if (super.getValue() == null) { - final Archetype<G, A, R> o = archetypeSet.getArchetype(valueString); - if (o != null) { - setValue(o); - } + setValue(archetypeSet.getOrCreateArchetype(valueString)); } return super.getValue(); } @@ -88,8 +86,10 @@ */ @Override public boolean setStringValue(@NotNull final String value) { - final Archetype<G, A, R> archetype = archetypeSet.getArchetype(value); - if (archetype == null) { + final Archetype<G, A, R> archetype; + try { + archetype = archetypeSet.getArchetype(value); + } catch (final UndefinedArchetypeException ignored) { return false; } setValue(archetype); Modified: trunk/src/test/net/sf/gridarta/model/archetype/ArchetypeParserTest.java =================================================================== --- trunk/src/test/net/sf/gridarta/model/archetype/ArchetypeParserTest.java 2010-05-23 14:55:44 UTC (rev 7931) +++ trunk/src/test/net/sf/gridarta/model/archetype/ArchetypeParserTest.java 2010-05-23 15:26:39 UTC (rev 7932) @@ -79,52 +79,52 @@ /** * Checks that msg...endmsg fields are parsed correctly. * @throws IOException if the test fails + * @throws UndefinedArchetypeException if the test fails */ @Test - public void testMsgTextEmpty() throws IOException { + public void testMsgTextEmpty() throws IOException, UndefinedArchetypeException { check("Object test\nmsg\nendmsg\nend\n", false, false, 1); assert archetypeSet != null; final Archetype<TestGameObject, TestMapArchObject, TestArchetype> archetype = archetypeSet.getArchetype("test"); - assert archetype != null; Assert.assertNull(archetype.getMsgText()); } /** * Checks that msg...endmsg fields are parsed correctly. * @throws IOException if the test fails + * @throws UndefinedArchetypeException if the test fails */ @Test - public void testMsgTextLines() throws IOException { + public void testMsgTextLines() throws IOException, UndefinedArchetypeException { check("Object test\nmsg\nabc\ndef\nghi\nendmsg\nend\n", false, false, 1); assert archetypeSet != null; final Archetype<TestGameObject, TestMapArchObject, TestArchetype> archetype = archetypeSet.getArchetype("test"); - assert archetype != null; Assert.assertEquals("abc\ndef\nghi\n", archetype.getMsgText()); } /** * Checks that msg...endmsg fields are parsed correctly. * @throws IOException if the test fails + * @throws UndefinedArchetypeException if the test fails */ @Test - public void testMsgTextTrailingWhitespace() throws IOException { + public void testMsgTextTrailingWhitespace() throws IOException, UndefinedArchetypeException { check("Object test\nmsg\nabc \ndef\nghi \n\nendmsg\nend\n", false, false, 1); assert archetypeSet != null; final Archetype<TestGameObject, TestMapArchObject, TestArchetype> archetype = archetypeSet.getArchetype("test"); - assert archetype != null; Assert.assertEquals("abc\ndef\nghi\n\n", archetype.getMsgText()); } /** * Checks that msg...endmsg fields are parsed correctly. * @throws IOException if the test fails + * @throws UndefinedArchetypeException if the test fails */ @Test - public void testMsgTextLeadingWhitespace() throws IOException { + public void testMsgTextLeadingWhitespace() throws IOException, UndefinedArchetypeException { check("Object test\nmsg\n\n abc\ndef\n ghi\nendmsg\nend\n", false, false, 1); assert archetypeSet != null; final Archetype<TestGameObject, TestMapArchObject, TestArchetype> archetype = archetypeSet.getArchetype("test"); - assert archetype != null; Assert.assertEquals("\n abc\ndef\n ghi\n", archetype.getMsgText()); } Modified: trunk/src/test/net/sf/gridarta/model/artifact/ArtifactParserTest.java =================================================================== --- trunk/src/test/net/sf/gridarta/model/artifact/ArtifactParserTest.java 2010-05-23 14:55:44 UTC (rev 7931) +++ trunk/src/test/net/sf/gridarta/model/artifact/ArtifactParserTest.java 2010-05-23 15:26:39 UTC (rev 7932) @@ -37,6 +37,7 @@ import net.sf.gridarta.model.archetype.TestArchetypeFactory; import net.sf.gridarta.model.archetype.TestArchetypeParser; import net.sf.gridarta.model.archetype.TestArchetypeSet; +import net.sf.gridarta.model.archetype.UndefinedArchetypeException; import net.sf.gridarta.model.errorview.ErrorViewCollector; import net.sf.gridarta.model.errorview.TestErrorView; import net.sf.gridarta.model.face.ArchFaceProvider; @@ -62,9 +63,10 @@ * Checks that a missing "object" line is detected. * @throws DuplicateArchetypeException if the test fails * @throws IOException if the test fails + * @throws UndefinedArchetypeException if the test fails */ @Test - public void testMissingObject() throws DuplicateArchetypeException, IOException { + public void testMissingObject() throws DuplicateArchetypeException, IOException, UndefinedArchetypeException { final TestArchetypeFactory archetypeFactory = new TestArchetypeFactory(); final TestArchetypeSet archetypeSet = new TestArchetypeSet(archetypeFactory, "archetypes"); final ArchFaceProvider archFaceProvider = new ArchFaceProvider(); @@ -96,7 +98,6 @@ Assert.assertFalse(errorView.hasErrors()); Assert.assertEquals(2, archetypeSet.getArchetypeCount()); final Archetype<TestGameObject, TestMapArchObject, TestArchetype> archetype = archetypeSet.getArchetype("art"); - assert archetype != null; Assert.assertEquals("sp 3\n", archetype.getObjectText()); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2010-05-24 19:08:55
|
Revision: 7987 http://gridarta.svn.sourceforge.net/gridarta/?rev=7987&view=rev Author: akirschbaum Date: 2010-05-24 19:08:48 +0000 (Mon, 24 May 2010) Log Message: ----------- Whitespace changes. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/gui/filter/MenuItemCreator.java trunk/src/doc/copyright.xhtml trunk/src/doc/dev/codeStyle.xhtml trunk/src/doc/hist/MergingEditors.xhtml trunk/src/test/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParserTest.java trunk/src/test/net/sf/gridarta/model/map/grid/MapGridTest.java trunk/src/test/net/sf/gridarta/model/map/mapmodel/DefaultMapModelTest.java Modified: trunk/src/app/net/sf/gridarta/gui/filter/MenuItemCreator.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/filter/MenuItemCreator.java 2010-05-24 18:49:57 UTC (rev 7986) +++ trunk/src/app/net/sf/gridarta/gui/filter/MenuItemCreator.java 2010-05-24 19:08:48 UTC (rev 7987) @@ -31,7 +31,8 @@ import org.jetbrains.annotations.Nullable; /** - * Creates menu items for {@link net.sf.gridarta.model.filter.Filter} instances. + * Creates menu items for {@link net.sf.gridarta.model.filter.Filter} + * instances. * @author tchize * @author Andreas Kirschbaum */ Modified: trunk/src/doc/copyright.xhtml =================================================================== --- trunk/src/doc/copyright.xhtml 2010-05-24 18:49:57 UTC (rev 7986) +++ trunk/src/doc/copyright.xhtml 2010-05-24 19:08:48 UTC (rev 7987) @@ -28,6 +28,6 @@ <body> <p> Gridarta is licensed under GPL version 2 or newer. </p> - <pre><xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../COPYING"/></pre> +<pre><xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../COPYING"/></pre> </body> </html> Modified: trunk/src/doc/dev/codeStyle.xhtml =================================================================== --- trunk/src/doc/dev/codeStyle.xhtml 2010-05-24 18:49:57 UTC (rev 7986) +++ trunk/src/doc/dev/codeStyle.xhtml 2010-05-24 19:08:48 UTC (rev 7987) @@ -69,7 +69,7 @@ <p> The following example code shows how streams should be opened / closed: </p> - <pre class="listing"><xi:include href="SafeCopy.java.xhtml" xpointer="element(/1/2/1/1)"/></pre> +<pre class="listing"><xi:include href="SafeCopy.java.xhtml" xpointer="element(/1/2/1/1)"/></pre> <p> Rationale: </p> <ul> @@ -115,239 +115,222 @@ developers that do not use IntelliJ IDEA / InspectionGadgets to know what the rules are to be able to perform the same verifications. </p> <ul> - <li> - Inspections - <ul> - <li> - Abstraction issues - <dl> - <dt>'instanceof' check for 'this'</dt> - <dd> - This most likely is a failure to understand object - oriented programming. Such constructs must be replaced - by proper polymorphism. - </dd> - </dl> - </li> - <li> - Assignment issues - <dl> - <dt>Assignment replaceable with operator assignment</dt> - <dd> - Operator assignments should be used wherever applicable - because they are easier to read: It's faster to see and - understand that the new variable value is based on a - modification of the original value, not a completely new - value. - <br/> - Conditional operators are currently ignored because - <code>foo |= bar();</code> is not the same as <code>foo - = foo || bar();</code> because the behavior regarding - side-effects in <code>bar()</code> is changed. - </dd> - <dt>Assignment to catch block parameter</dt> - <dd> - This reports things like <code>catch (FooException e) { - e = ...; }</code> as they are either errors or, if not, - at least very confusing. - </dd> - </dl> - </li> - <li> - Bitwise operation issues - <dl> - <dt>Incompatible bitwise mask operation</dt> - <dd> - Bitwise mask expressions which are guaranteed to always - evaluate to true or false most likely are logical - errors. Example: <code>(var & constant1) == - constant2</code>. - </dd> - <dt>Pointless bitwise expression</dt> - <dd> - Pointless expressions that and with zero, or with zero - or shift with zero most likely are logical errors. - </dd> - <dt>Shift operation by inappropriate constant</dt> - <dd> - Shifts with shift values out of range (0..31 for int, - 0..63 for long) most likely are logical errors. - </dd> - </dl> - </li> - <li> - Class structure - <dl> - <dt>'final' method in 'final' class</dt> - <dd> - This is unnecessary and may be confusing. Methods in - final classes are always implicitly final. A method - should only be explicitly declared final if the context - is "the class might be subclasses, but this method is - not designed to be overridden". Thus if a method in a - final class is explicitly declared final, it may lead to - the conclusion that the class was declared final by - mistake. - </dd> - <dt>Missing @Deprecated annotation</dt> - <dd> - Makes sure that deprecated members that are documented - as deprecated in Javadoc (<code>@deprecated</code> - Javadoc tag) are also annotated as - <code>@Deprecated</code> in the source code. - <br/> - Background: Future compiler versions (JDK 1.6 or JDK - 1.7) might stop to parse Javadoc comments. To get the - deprecation information into the class file, the - annotation must be used then. Also, deprecation - information might only be fully reflective on 1.5 or - later if it was declared with the annotation. - </dd> - <dt>Missing @Override annotation</dt> - <dd> - Makes sure that members that override members from a - class (not implement from an interface) are annotated as - <code>@Override</code> in the source code. - <br/> - Background: A missing <code>@Override</code> isn't an - error by itself. But the opposite situation, an <code>@Override</code> - when nothing is overridden is an error. That is useful - for finding typos when wanting to override a method. - E.g. if you override <code>toString()</code> using - <code>@Override public String tostring()</code> (not the - typo), the compiler will be able to report this as an - error. - </dd> - <dt>'private' method declared 'final'</dt> - <dd> - Private methods are implicitly final. Explicitly - declaring them final looks like the method should be - public or protected instead. - </dd> - <dt>'protected' member in 'final' class</dt> - <dd> - Final classes cannot be sub-classed. Protected members - are explicitly visible for subclasses. Because of that, - protected members in final classes are an oxymoron that - indicates an error. - </dd> - <dt>'public' constructor in non-public class</dt> - <dd> - If the class is not visible, the constructor isn't - either. Declaring the constructor of higher - accessibility than its class is pointless and most - likely an error. - </dd> - </dl> - </li> - <li> - Code style issues - <dl> - <dt>Missorted modifiers</dt> - <dt>Modifier order does not match JLS suggestion</dt> - <dd>Annotations should be sorted alphabetically, annotations - MUST be sorted before keywords, keywords must be sorted - according to JLS. - </dd> - </dl> - </li> - <li> - Finalization issues - <dl> - <dt>'finalize()' called explicitly</dt> - <dd>finalize() must only be called by the garbage collector, - but not application software. - </dd> - <dt>'finalize()' does not call 'super.finalize()'</dt> - <dd>This always is an error as this prevents the superclass - from performing its own finalization code. - </dd> - <dt>'finalize()' not declared 'protected'</dt> - <dd>This is an error because 'finalize()' must not be public - because it never needs to be called directly. - </dd> - </dl> - </li> - <li> - General - <dl> - <dt>Declaration has Javadoc problems</dt> - <dd> - Makes sure that a Javadoc comment that is present also - has a certain level of technical quality. Currently the - following omissions are treated as errors: - <code>@author</code> for top level classes, periods in - briefs, <code>@return</code> for methods, - <code>@param</code> and <code>ŧrhwos</code> or <code>@exception</code> - for methods and constructors. Unknown Javadoc tags are - also reported (<code>@note</code> and similar extension - tags are known to this inspection and won't cause false - positives). - <br/> - Though it would be possible to ignore deprecated - elements, they're not. Even if an element is deprecated, - it must still be documented properly and without errors. - </dd> - <dt>Declaration has problems in Javadoc references</dt> - <dd> - Makes sure that references in Javadoc comments (<code>{@link - ...}</code> and eventually <code>@see ...</code>) can be - resolved. - </dd> - <dt>equals() and hashCode() not paired</dt> - <dd> - Due to their contract, equals() and hashCode() must - always be paired. If one of them is overridden, so must - be the other. - </dd> - <dt>Redundant suppression</dt> - <dd>Reports usages of warning suppression when they suppress - something that isn't there. - </dd> - <dt>Variable is assigned to itself</dt> - <dd>Stuff like <code>a = a;</code> most likely is an error. - </dd> - <dt>Wrong package statement</dt> - <dd>Reports when the package statement doesn't correspond to - the project directory structure. - </dd> - </dl> - </li> - <li> - Imports - <dl> - <dt>* import</dt> - <dd> - * imports are forbidden in Gridarta. - </dd> - <dt>Import from same package</dt> - <dt>java.lang import</dt> - <dt>Redundant import</dt> - <dd> - Redundant or pointless imports are forbidden in - Gridarta. - </dd> - <dt>Static import</dt> - <dd>Our code style doesn't allow static import.</dd> - <dt>Unused import</dt> - <dd>Import statements must not list types they don't use. - </dd> - </dl> - </li> - <li> - Inheritance issues - <dl> - <dt>Abstract method with missing implementations</dt> - <dd> - The compiler would of course report this in the - subclasses that miss the implementation. This inspection - supports you while editing or if you're too lazy to - perform a build prior to a commit. - </dd> - </dl> - </li> - </ul> - </li> +<li> +Inspections +<ul> +<li> + Abstraction issues + <dl> + <dt>'instanceof' check for 'this'</dt> + <dd> + This most likely is a failure to understand object oriented + programming. Such constructs must be replaced by proper + polymorphism. + </dd> + </dl> +</li> +<li> + Assignment issues + <dl> + <dt>Assignment replaceable with operator assignment</dt> + <dd> + Operator assignments should be used wherever applicable because they + are easier to read: It's faster to see and understand that the new + variable value is based on a modification of the original value, not + a completely new value. + <br/> + Conditional operators are currently ignored because <code>foo |= + bar();</code> is not the same as <code>foo = foo || bar();</code> + because the behavior regarding side-effects in <code>bar()</code> is + changed. + </dd> + <dt>Assignment to catch block parameter</dt> + <dd> + This reports things like <code>catch (FooException e) { e = ...; + }</code> as they are either errors or, if not, at least very + confusing. + </dd> + </dl> +</li> +<li> + Bitwise operation issues + <dl> + <dt>Incompatible bitwise mask operation</dt> + <dd> + Bitwise mask expressions which are guaranteed to always evaluate to + true or false most likely are logical errors. Example: <code>(var + & constant1) == constant2</code>. + </dd> + <dt>Pointless bitwise expression</dt> + <dd> + Pointless expressions that and with zero, or with zero or shift with + zero most likely are logical errors. + </dd> + <dt>Shift operation by inappropriate constant</dt> + <dd> + Shifts with shift values out of range (0..31 for int, 0..63 for + long) most likely are logical errors. + </dd> + </dl> +</li> +<li> + Class structure + <dl> + <dt>'final' method in 'final' class</dt> + <dd> + This is unnecessary and may be confusing. Methods in final classes + are always implicitly final. A method should only be explicitly + declared final if the context is "the class might be subclasses, but + this method is not designed to be overridden". Thus if a method in a + final class is explicitly declared final, it may lead to the + conclusion that the class was declared final by mistake. + </dd> + <dt>Missing @Deprecated annotation</dt> + <dd> + Makes sure that deprecated members that are documented as deprecated + in Javadoc (<code>@deprecated</code> Javadoc tag) are also annotated + as <code>@Deprecated</code> in the source code. + <br/> + Background: Future compiler versions (JDK 1.6 or JDK 1.7) might stop + to parse Javadoc comments. To get the deprecation information into + the class file, the annotation must be used then. Also, deprecation + information might only be fully reflective on 1.5 or later if it was + declared with the annotation. + </dd> + <dt>Missing @Override annotation</dt> + <dd> + Makes sure that members that override members from a class (not + implement from an interface) are annotated as <code>@Override</code> + in the source code. + <br/> + Background: A missing <code>@Override</code> isn't an error by + itself. But the opposite situation, an <code>@Override</code> when + nothing is overridden is an error. That is useful for finding typos + when wanting to override a method. E.g. if you override <code>toString()</code> + using <code>@Override public String tostring()</code> (not the + typo), the compiler will be able to report this as an error. + </dd> + <dt>'private' method declared 'final'</dt> + <dd> + Private methods are implicitly final. Explicitly declaring them + final looks like the method should be public or protected instead. + </dd> + <dt>'protected' member in 'final' class</dt> + <dd> + Final classes cannot be sub-classed. Protected members are + explicitly visible for subclasses. Because of that, protected + members in final classes are an oxymoron that indicates an error. + </dd> + <dt>'public' constructor in non-public class</dt> + <dd> + If the class is not visible, the constructor isn't either. Declaring + the constructor of higher accessibility than its class is pointless + and most likely an error. + </dd> + </dl> +</li> +<li> + Code style issues + <dl> + <dt>Missorted modifiers</dt> + <dt>Modifier order does not match JLS suggestion</dt> + <dd>Annotations should be sorted alphabetically, annotations MUST be + sorted before keywords, keywords must be sorted according to JLS. + </dd> + </dl> +</li> +<li> + Finalization issues + <dl> + <dt>'finalize()' called explicitly</dt> + <dd>finalize() must only be called by the garbage collector, but not + application software. + </dd> + <dt>'finalize()' does not call 'super.finalize()'</dt> + <dd>This always is an error as this prevents the superclass from + performing its own finalization code. + </dd> + <dt>'finalize()' not declared 'protected'</dt> + <dd>This is an error because 'finalize()' must not be public because it + never needs to be called directly. + </dd> + </dl> +</li> +<li> + General + <dl> + <dt>Declaration has Javadoc problems</dt> + <dd> + Makes sure that a Javadoc comment that is present also has a certain + level of technical quality. Currently the following omissions are + treated as errors: <code>@author</code> for top level classes, + periods in briefs, <code>@return</code> for methods, + <code>@param</code> and <code>ŧrhwos</code> or + <code>@exception</code> for methods and constructors. Unknown + Javadoc tags are also reported (<code>@note</code> and similar + extension tags are known to this inspection and won't cause false + positives). + <br/> + Though it would be possible to ignore deprecated elements, they're + not. Even if an element is deprecated, it must still be documented + properly and without errors. + </dd> + <dt>Declaration has problems in Javadoc references</dt> + <dd> + Makes sure that references in Javadoc comments (<code>{@link + ...}</code> and eventually <code>@see ...</code>) can be resolved. + </dd> + <dt>equals() and hashCode() not paired</dt> + <dd> + Due to their contract, equals() and hashCode() must always be + paired. If one of them is overridden, so must be the other. + </dd> + <dt>Redundant suppression</dt> + <dd>Reports usages of warning suppression when they suppress something + that isn't there. + </dd> + <dt>Variable is assigned to itself</dt> + <dd>Stuff like <code>a = a;</code> most likely is an error. + </dd> + <dt>Wrong package statement</dt> + <dd>Reports when the package statement doesn't correspond to the project + directory structure. + </dd> + </dl> +</li> +<li> + Imports + <dl> + <dt>* import</dt> + <dd> + * imports are forbidden in Gridarta. + </dd> + <dt>Import from same package</dt> + <dt>java.lang import</dt> + <dt>Redundant import</dt> + <dd> + Redundant or pointless imports are forbidden in Gridarta. + </dd> + <dt>Static import</dt> + <dd>Our code style doesn't allow static import.</dd> + <dt>Unused import</dt> + <dd>Import statements must not list types they don't use. + </dd> + </dl> +</li> +<li> + Inheritance issues + <dl> + <dt>Abstract method with missing implementations</dt> + <dd> + The compiler would of course report this in the subclasses that miss + the implementation. This inspection supports you while editing or if + you're too lazy to perform a build prior to a commit. + </dd> + </dl> +</li> </ul> +</li> +</ul> </body> </html> Modified: trunk/src/doc/hist/MergingEditors.xhtml =================================================================== --- trunk/src/doc/hist/MergingEditors.xhtml 2010-05-24 18:49:57 UTC (rev 7986) +++ trunk/src/doc/hist/MergingEditors.xhtml 2010-05-24 19:08:48 UTC (rev 7987) @@ -141,8 +141,7 @@ <p> The following persons have made statements about the possibilities: </p> <ul> - <li>Cher, definitely declining D. and E., but unsure whether to do F. or - G.. + <li>Cher, definitely declining D. and E., but unsure whether to do F. or G.. </li> <li>Ragnor, zergus and other editor developers: votes missing</li> <li>Project leaders / admins: votes missing</li> Modified: trunk/src/test/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParserTest.java =================================================================== --- trunk/src/test/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParserTest.java 2010-05-24 18:49:57 UTC (rev 7986) +++ trunk/src/test/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParserTest.java 2010-05-24 19:08:48 UTC (rev 7987) @@ -610,7 +610,8 @@ * @param archetypeAttributeName the archetype attribute name * @param attributeName the user interface attribute name * @param description the attribute's description - * @param inputLength the input length in characters for text input fields + * @param inputLength the input length in characters for text input + * fields * @param sectionName the section name */ public TestArchetypeAttribute(@NotNull final String type, @NotNull final String archetypeAttributeName, @NotNull final String attributeName, @NotNull final String description, final int inputLength, @NotNull final String sectionName) { Modified: trunk/src/test/net/sf/gridarta/model/map/grid/MapGridTest.java =================================================================== --- trunk/src/test/net/sf/gridarta/model/map/grid/MapGridTest.java 2010-05-24 18:49:57 UTC (rev 7986) +++ trunk/src/test/net/sf/gridarta/model/map/grid/MapGridTest.java 2010-05-24 19:08:48 UTC (rev 7987) @@ -89,11 +89,20 @@ for (int y = 0; y < size.getHeight(); y++) { for (int x = 0; x < size.getWidth(); x++) { final int flags = mapGrid.getFlags(x, y); - sb.append(Integer.toHexString( - ((flags & MapGrid.GRID_FLAG_SELECTION_NORTH) == 0 ? 0 : 1) - + ((flags & MapGrid.GRID_FLAG_SELECTION_EAST) == 0 ? 0 : 2) - + ((flags & MapGrid.GRID_FLAG_SELECTION_SOUTH) == 0 ? 0 : 4) - + ((flags & MapGrid.GRID_FLAG_SELECTION_WEST) == 0 ? 0 : 8))); + int value = 0; + if ((flags & MapGrid.GRID_FLAG_SELECTION_NORTH) != 0) { + value |= 1; + } + if ((flags & MapGrid.GRID_FLAG_SELECTION_EAST) != 0) { + value |= 2; + } + if ((flags & MapGrid.GRID_FLAG_SELECTION_SOUTH) != 0) { + value |= 4; + } + if ((flags & MapGrid.GRID_FLAG_SELECTION_WEST) != 0) { + value |= 8; + } + sb.append(Integer.toHexString(value)); } } Assert.assertEquals(expectedBorder, sb.toString()); Modified: trunk/src/test/net/sf/gridarta/model/map/mapmodel/DefaultMapModelTest.java =================================================================== --- trunk/src/test/net/sf/gridarta/model/map/mapmodel/DefaultMapModelTest.java 2010-05-24 18:49:57 UTC (rev 7986) +++ trunk/src/test/net/sf/gridarta/model/map/mapmodel/DefaultMapModelTest.java 2010-05-24 19:08:48 UTC (rev 7987) @@ -65,6 +65,12 @@ public class DefaultMapModelTest { /** + * Predefined icon names. + */ + @NotNull + private static final String[] ICON_NAMES = { SystemIcons.SQUARE_SEL_SQUARE, SystemIcons.SQUARE_SEL_SQUARE_NORTH, SystemIcons.SQUARE_SEL_SQUARE_EAST, SystemIcons.SQUARE_SEL_SQUARE_SOUTH, SystemIcons.SQUARE_SEL_SQUARE_WEST, SystemIcons.SQUARE_PRESEL_SQUARE, SystemIcons.SQUARE_CURSOR, SystemIcons.SQUARE_EMPTY, SystemIcons.SQUARE_UNKNOWN, SystemIcons.SQUARE_NOFACE, SystemIcons.SQUARE_NOARCH, SystemIcons.DEFAULT_ICON, SystemIcons.DEFAULT_PREVIEW, SystemIcons.SQUARE_WARNING, }; + + /** * The map model listener registered to {@link #mapModel} to record map * changes. */ @@ -178,11 +184,7 @@ mapModel.beginTransaction("TEST"); mapModel.resizeMap(new Size2D(4, 3)); mapModel.endTransaction(); - Assert.assertEquals( - "mapSizeChanged:\n" - + "no squares\n" - + "no game objects\n", - result.toString()); + Assert.assertEquals("mapSizeChanged:\n" + "no squares\n" + "no game objects\n", result.toString()); } /** @@ -216,11 +218,7 @@ addGameObjectToMap(mapModel, "1", 2, 2, insertionModeSet.getAutoInsertionMode()); mapModel.resizeMap(new Size2D(1, 2)); // cancels square changed event mapModel.endTransaction(); - Assert.assertEquals( - "mapSizeChanged:\n" - + "no squares\n" - + "no game objects\n", - result.toString()); + Assert.assertEquals("mapSizeChanged:\n" + "no squares\n" + "no game objects\n", result.toString()); } /** @@ -241,11 +239,7 @@ addGameObjectToMap(mapModel, "1", 2, 2, insertionModeSet.getAutoInsertionMode()); mapModel.resizeMap(new Size2D(1, 2)); // cancels square changed event mapModel.endTransaction(); - Assert.assertEquals( - "mapSizeChanged:\n" - + "no squares\n" - + "no game objects\n", - result.toString()); + Assert.assertEquals("mapSizeChanged:\n" + "no squares\n" + "no game objects\n", result.toString()); } /** @@ -262,11 +256,7 @@ mapModel.beginTransaction("TEST"); addGameObjectToMap(mapModel, "1", 1, 2, insertionModeSet.getAutoInsertionMode()); mapModel.endTransaction(); - Assert.assertEquals( - "mapSquaresChanged:\n" - + "square 1 2\n" - + "no game objects\n", - result.toString()); + Assert.assertEquals("mapSquaresChanged:\n" + "square 1 2\n" + "no game objects\n", result.toString()); } /** @@ -285,12 +275,7 @@ addGameObjectToMap(mapModel, "1", 1, 2, insertionModeSet.getAutoInsertionMode()); addGameObjectToMap(mapModel, "1", 2, 2, insertionModeSet.getAutoInsertionMode()); mapModel.endTransaction(); - Assert.assertEquals( - "mapSquaresChanged:\n" - + "square 1 2\n" - + "square 2 2\n" - + "no game objects\n", - result.toString()); + Assert.assertEquals("mapSquaresChanged:\n" + "square 1 2\n" + "square 2 2\n" + "no game objects\n", result.toString()); } /** @@ -309,11 +294,7 @@ insertGameObject(gameObject, "2"); } mapModel.endTransaction(); - Assert.assertEquals( - "mapObjectsChanged:\n" - + "no squares\n" - + "game object 1 2 1\n", - result.toString()); + Assert.assertEquals("mapObjectsChanged:\n" + "no squares\n" + "game object 1 2 1\n", result.toString()); } /** @@ -332,16 +313,12 @@ gameObject.setAttributeString("key", "value"); } mapModel.endTransaction(); - Assert.assertEquals( - "mapObjectsChanged:\n" - + "no squares\n" - + "game object 1 2 1\n", - result.toString()); + Assert.assertEquals("mapObjectsChanged:\n" + "no squares\n" + "game object 1 2 1\n", result.toString()); } /** - * Test case for {@link DefaultMapModel#getAllGameObjects()}: for a 1x2 - * game object only the head should be returned. + * Test case for {@link DefaultMapModel#getAllGameObjects()}: for a 1x2 game + * object only the head should be returned. */ @Test public void testGetAllGameObjects1() { @@ -442,22 +419,7 @@ final ImageIcon imageIcon = new ImageIcon(new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB)); final GUIUtils guiUtils = new GUIUtils(); systemIcons = new SystemIcons(guiUtils); - for (final String iconName : new String[] { - SystemIcons.SQUARE_SEL_SQUARE, - SystemIcons.SQUARE_SEL_SQUARE_NORTH, - SystemIcons.SQUARE_SEL_SQUARE_EAST, - SystemIcons.SQUARE_SEL_SQUARE_SOUTH, - SystemIcons.SQUARE_SEL_SQUARE_WEST, - SystemIcons.SQUARE_PRESEL_SQUARE, - SystemIcons.SQUARE_CURSOR, - SystemIcons.SQUARE_EMPTY, - SystemIcons.SQUARE_UNKNOWN, - SystemIcons.SQUARE_NOFACE, - SystemIcons.SQUARE_NOARCH, - SystemIcons.DEFAULT_ICON, - SystemIcons.DEFAULT_PREVIEW, - SystemIcons.SQUARE_WARNING, - }) { + for (final String iconName : ICON_NAMES) { guiUtils.addToCache(iconName, imageIcon); } final TestMapArchObject mapArchObject = new TestMapArchObject(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2010-05-29 06:50:47
|
Revision: 8028 http://gridarta.svn.sourceforge.net/gridarta/?rev=8028&view=rev Author: akirschbaum Date: 2010-05-29 06:50:41 +0000 (Sat, 29 May 2010) Log Message: ----------- Add @NotNull/@Nullable annotations. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/gui/misc/Recent.java trunk/src/app/net/sf/gridarta/gui/misc/RecentManager.java trunk/src/app/net/sf/gridarta/model/settings/AbstractGlobalSettings.java trunk/src/app/net/sf/gridarta/model/settings/DefaultGlobalSettings.java trunk/src/app/net/sf/gridarta/model/settings/GlobalSettings.java trunk/src/test/net/sf/gridarta/model/settings/TestGlobalSettings.java Modified: trunk/src/app/net/sf/gridarta/gui/misc/Recent.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/misc/Recent.java 2010-05-29 06:42:33 UTC (rev 8027) +++ trunk/src/app/net/sf/gridarta/gui/misc/Recent.java 2010-05-29 06:50:41 UTC (rev 8028) @@ -52,16 +52,19 @@ /** * The {@link ActionBuilder}. */ + @NotNull private static final ActionBuilder ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder("net.sf.gridarta"); /** * The {@link Preferences}. */ + @NotNull private static final Preferences prefs = Preferences.userNodeForPackage(RecentManager.class); /** * Title = map name. */ + @NotNull private final String title; /** @@ -103,7 +106,7 @@ * @param mapImageCache the map image cache instance * @param fileControl the file control */ - Recent(final String title, final File mapFile, @NotNull final GlobalSettings globalSettings, @NotNull final MapViewsManager<G, A, R> mapViewsManager, @NotNull final MapImageCache<G, A, R> mapImageCache, @NotNull final FileControl<G, A, R> fileControl) { + Recent(@NotNull final String title, @NotNull final File mapFile, @NotNull final GlobalSettings globalSettings, @NotNull final MapViewsManager<G, A, R> mapViewsManager, @NotNull final MapImageCache<G, A, R> mapImageCache, @NotNull final FileControl<G, A, R> fileControl) { super(title); this.mapFile = mapFile; this.title = title; @@ -143,6 +146,7 @@ * Get the short filename. * @return short filename */ + @NotNull private String getShortFileName() { try { if (mapFile.getCanonicalPath().startsWith(globalSettings.getMapsDirectory().getCanonicalPath())) { @@ -172,7 +176,7 @@ * {@inheritDoc} */ @Override - public void actionPerformed(final ActionEvent e) { + public void actionPerformed(@NotNull final ActionEvent e) { try { mapViewsManager.openMapFileWithView(mapFile, null); } catch (final IOException ex) { @@ -202,7 +206,7 @@ * {@inheritDoc} */ @Override - public boolean equals(final Object obj) { + public boolean equals(@Nullable final Object obj) { return obj != null && obj instanceof Recent && mapFile.equals(((Recent<?, ?, ?>) obj).mapFile); } @@ -217,6 +221,7 @@ /** * {@inheritDoc} */ + @NotNull @Override protected Object clone() { try { Modified: trunk/src/app/net/sf/gridarta/gui/misc/RecentManager.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/misc/RecentManager.java 2010-05-29 06:42:33 UTC (rev 8027) +++ trunk/src/app/net/sf/gridarta/gui/misc/RecentManager.java 2010-05-29 06:50:41 UTC (rev 8028) @@ -58,6 +58,7 @@ /** * Preferences. */ + @NotNull private static final Preferences prefs = Preferences.userNodeForPackage(RecentManager.class); /** @@ -69,6 +70,7 @@ /** * List with recents. */ + @NotNull private final LinkedList<Recent<G, A, R>> recents = new LinkedList<Recent<G, A, R>>(); /** @@ -227,7 +229,7 @@ * Update the recent menu. * @param recents current recents */ - private void updateRecent(final Iterable<Recent<G, A, R>> recents) { + private void updateRecent(@NotNull final Iterable<Recent<G, A, R>> recents) { if (recentMenu == null) { return; } Modified: trunk/src/app/net/sf/gridarta/model/settings/AbstractGlobalSettings.java =================================================================== --- trunk/src/app/net/sf/gridarta/model/settings/AbstractGlobalSettings.java 2010-05-29 06:42:33 UTC (rev 8027) +++ trunk/src/app/net/sf/gridarta/model/settings/AbstractGlobalSettings.java 2010-05-29 06:50:41 UTC (rev 8028) @@ -20,6 +20,7 @@ package net.sf.gridarta.model.settings; import net.sf.gridarta.utils.EventListenerList2; +import org.jetbrains.annotations.NotNull; /** * Abstract base class for {@link GlobalSettings} implementations. @@ -30,13 +31,14 @@ /** * The {@link GlobalSettingsListener}s to inform of changes. */ + @NotNull private final EventListenerList2<GlobalSettingsListener> listenerList = new EventListenerList2<GlobalSettingsListener>(GlobalSettingsListener.class); /** * {@inheritDoc} */ @Override - public void addGlobalSettingsListener(final GlobalSettingsListener listener) { + public void addGlobalSettingsListener(@NotNull final GlobalSettingsListener listener) { listenerList.add(listener); } @@ -44,7 +46,7 @@ * {@inheritDoc} */ @Override - public void removeGlobalSettingsListener(final GlobalSettingsListener listener) { + public void removeGlobalSettingsListener(@NotNull final GlobalSettingsListener listener) { listenerList.remove(listener); } Modified: trunk/src/app/net/sf/gridarta/model/settings/DefaultGlobalSettings.java =================================================================== --- trunk/src/app/net/sf/gridarta/model/settings/DefaultGlobalSettings.java 2010-05-29 06:42:33 UTC (rev 8027) +++ trunk/src/app/net/sf/gridarta/model/settings/DefaultGlobalSettings.java 2010-05-29 06:50:41 UTC (rev 8028) @@ -38,16 +38,19 @@ /** * The {@link ActionBuilder}. */ + @NotNull private static final ActionBuilder ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder("net.sf.gridarta"); /** * The preferences key for the archetype directory. */ + @NotNull private static final String MAP_DIRECTORY_KEY = "mapDirectory"; /** * The preferences key for the archetype directory. */ + @NotNull private static final String ARCH_DIRECTORY_KEY = "archDirectory"; /** @@ -65,31 +68,37 @@ /** * The preferences key for storing the last known docu version. */ + @NotNull private static final String DOCU_VERSION_KEY = "docuVersion"; /** * Key for info whether the main windows's toolbar is shown. */ + @NotNull private static final String SHOW_MAIN_TOOLBAR_KEY = "ShowMainToolbar"; /** * Preferences key for username. */ + @NotNull private static final String PREFS_USERNAME = "username"; /** * Preferences default value for username. */ + @NotNull private static final String PREFS_USERNAME_DEFAULT = System.getProperty("user.name"); /** * The preferences key for configuration source. */ + @NotNull private static final String CONFIG_SOURCE_KEY = "configSource"; /** * Preferences. */ + @NotNull private static final Preferences prefs = Preferences.userNodeForPackage(MainControl.class); /** @@ -159,12 +168,14 @@ /** * The current main directory. */ + @NotNull private File currentDirectory = new File(System.getProperty("user.dir")); /** * The image directory. By default, created images are stored in this * directory. */ + @NotNull private File imageDirectory; /** @@ -187,6 +198,7 @@ /** * The {@link PreferenceChangeListener} used to detect settings changes. */ + @NotNull private final PreferenceChangeListener preferenceChangeListener = new PreferenceChangeListener() { /** {@inheritDoc} */ @@ -301,6 +313,7 @@ /** * {@inheritDoc} */ + @NotNull @Override public File getCurrentDirectory() { return currentDirectory; @@ -310,7 +323,7 @@ * {@inheritDoc} */ @Override - public void setCurrentDirectory(final File currentDirectory) { + public void setCurrentDirectory(@NotNull final File currentDirectory) { this.currentDirectory = currentDirectory; } @@ -401,6 +414,7 @@ /** * {@inheritDoc} */ + @NotNull @Override public File getImageDirectory() { return imageDirectory; @@ -410,7 +424,7 @@ * {@inheritDoc} */ @Override - public void setImageDirectory(final File imageDirectory) { + public void setImageDirectory(@NotNull final File imageDirectory) { this.imageDirectory = imageDirectory; } Modified: trunk/src/app/net/sf/gridarta/model/settings/GlobalSettings.java =================================================================== --- trunk/src/app/net/sf/gridarta/model/settings/GlobalSettings.java 2010-05-29 06:42:33 UTC (rev 8027) +++ trunk/src/app/net/sf/gridarta/model/settings/GlobalSettings.java 2010-05-29 06:50:41 UTC (rev 8028) @@ -76,12 +76,13 @@ * Sets the directory to save created image to. * @param imageDirectory the image directory */ - void setImageDirectory(File imageDirectory); + void setImageDirectory(@NotNull File imageDirectory); /** * Returns the directory to save images to. * @return the image directory */ + @NotNull File getImageDirectory(); /** @@ -105,9 +106,10 @@ void setAutoPopupDocu(boolean autoPopupDocu); + @NotNull File getCurrentDirectory(); - void setCurrentDirectory(File currentDirectory); + void setCurrentDirectory(@NotNull File currentDirectory); /** * Returns the pickmap directory. @@ -219,12 +221,12 @@ * Adds a {@link GlobalSettingsListener} to be notified of changes. * @param listener the listener */ - void addGlobalSettingsListener(GlobalSettingsListener listener); + void addGlobalSettingsListener(@NotNull GlobalSettingsListener listener); /** * Removes a {@link GlobalSettingsListener} to be notified of changes. * @param listener the listener */ - void removeGlobalSettingsListener(GlobalSettingsListener listener); + void removeGlobalSettingsListener(@NotNull GlobalSettingsListener listener); } // interface GlobalSettings Modified: trunk/src/test/net/sf/gridarta/model/settings/TestGlobalSettings.java =================================================================== --- trunk/src/test/net/sf/gridarta/model/settings/TestGlobalSettings.java 2010-05-29 06:42:33 UTC (rev 8027) +++ trunk/src/test/net/sf/gridarta/model/settings/TestGlobalSettings.java 2010-05-29 06:50:41 UTC (rev 8028) @@ -84,13 +84,14 @@ * {@inheritDoc} */ @Override - public void setImageDirectory(final File imageDirectory) { + public void setImageDirectory(@NotNull final File imageDirectory) { throw new AssertionError(); } /** * {@inheritDoc} */ + @NotNull @Override public File getImageDirectory() { throw new AssertionError(); @@ -148,6 +149,7 @@ /** * {@inheritDoc} */ + @NotNull @Override public File getCurrentDirectory() { throw new AssertionError(); @@ -157,7 +159,7 @@ * {@inheritDoc} */ @Override - public void setCurrentDirectory(final File currentDirectory) { + public void setCurrentDirectory(@NotNull final File currentDirectory) { throw new AssertionError(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2010-06-03 17:05:14
|
Revision: 8082 http://gridarta.svn.sourceforge.net/gridarta/?rev=8082&view=rev Author: akirschbaum Date: 2010-06-03 17:05:07 +0000 (Thu, 03 Jun 2010) Log Message: ----------- Fix checkstyle issues. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/gui/misc/RecentManager.java trunk/src/app/net/sf/gridarta/gui/selectedsquare/SelectedSquareActions.java trunk/src/test/net/sf/gridarta/gui/copybuffer/CopyBufferTest.java trunk/src/test/net/sf/gridarta/gui/selectedsquare/SelectedSquareActionsTest.java trunk/src/test/net/sf/gridarta/model/gameobject/GameObjectFactoryTest.java Modified: trunk/src/app/net/sf/gridarta/gui/misc/RecentManager.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/misc/RecentManager.java 2010-06-03 16:58:45 UTC (rev 8081) +++ trunk/src/app/net/sf/gridarta/gui/misc/RecentManager.java 2010-06-03 17:05:07 UTC (rev 8082) @@ -54,7 +54,7 @@ @Override public void mapCreated(@NotNull final MapControl<G, A, R> mapControl, final boolean interactive) { if (interactive) { - final MapModel<G,A,R> mapModel = mapControl.getMapModel(); + final MapModel<G, A, R> mapModel = mapControl.getMapModel(); mapMenuManager.addRecent(mapModel, mapModel.getMapArchObject().getMapName()); } } Modified: trunk/src/app/net/sf/gridarta/gui/selectedsquare/SelectedSquareActions.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/selectedsquare/SelectedSquareActions.java 2010-06-03 16:58:45 UTC (rev 8081) +++ trunk/src/app/net/sf/gridarta/gui/selectedsquare/SelectedSquareActions.java 2010-06-03 17:05:07 UTC (rev 8082) @@ -192,7 +192,7 @@ if (mapSquare == null) { return false; } - + final MapModel<G, A, R> mapModel = mapSquare.getMapModel(); final Point pos = new Point(mapSquare.getMapX(), mapSquare.getMapY()); if (!envGameObject.isInContainer() && gameObject.getArchetype().isMulti() && !mapModel.isMultiArchFittingToMap(gameObject.getArchetype(), pos, true)) { Modified: trunk/src/test/net/sf/gridarta/gui/copybuffer/CopyBufferTest.java =================================================================== --- trunk/src/test/net/sf/gridarta/gui/copybuffer/CopyBufferTest.java 2010-06-03 16:58:45 UTC (rev 8081) +++ trunk/src/test/net/sf/gridarta/gui/copybuffer/CopyBufferTest.java 2010-06-03 17:05:07 UTC (rev 8082) @@ -61,7 +61,7 @@ final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl = testMapControlCreator.newMapControl(MAP_FILE1, MAP_NAME1, new Size2D(3, 3)); final Point point = new Point(1, 1); - final MapModel<TestGameObject,TestMapArchObject,TestArchetype> mapModel = mapControl.getMapModel(); + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); mapModel.beginTransaction("TEST"); final TestGameObject ob1 = testMapControlCreator.insertFloor(mapModel, point); final TestGameObject ob2 = testMapControlCreator.insertMob21(ob1); Modified: trunk/src/test/net/sf/gridarta/gui/selectedsquare/SelectedSquareActionsTest.java =================================================================== --- trunk/src/test/net/sf/gridarta/gui/selectedsquare/SelectedSquareActionsTest.java 2010-06-03 16:58:45 UTC (rev 8081) +++ trunk/src/test/net/sf/gridarta/gui/selectedsquare/SelectedSquareActionsTest.java 2010-06-03 17:05:07 UTC (rev 8082) @@ -64,7 +64,7 @@ final SelectedSquareActions<TestGameObject, TestMapArchObject, TestArchetype> selectedSquareActions = new SelectedSquareActions<TestGameObject, TestMapArchObject, TestArchetype>(selectedSquareModel); final Point point = new Point(0, 0); - final MapModel<TestGameObject,TestMapArchObject,TestArchetype> mapModel = mapControl.getMapModel(); + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); mapModel.beginTransaction("TEST"); final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquare = mapModel.getMapSquare(point); final TestGameObject ob2 = testMapControlCreator.insertFloor(mapModel, point); @@ -104,7 +104,7 @@ final Point pointHead = new Point(0, 0); final Point pointTail = new Point(1, 0); - final MapModel<TestGameObject,TestMapArchObject,TestArchetype> mapModel = mapControl.getMapModel(); + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); mapModel.beginTransaction("TEST"); final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquareHead = mapModel.getMapSquare(pointHead); final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquareTail = mapModel.getMapSquare(pointTail); @@ -164,7 +164,7 @@ final SelectedSquareActions<TestGameObject, TestMapArchObject, TestArchetype> selectedSquareActions = new SelectedSquareActions<TestGameObject, TestMapArchObject, TestArchetype>(selectedSquareModel); final Point point = new Point(0, 0); - final MapModel<TestGameObject,TestMapArchObject,TestArchetype> mapModel = mapControl.getMapModel(); + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); mapModel.beginTransaction("TEST"); final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquare = mapModel.getMapSquare(point); final TestGameObject ob2 = testMapControlCreator.insertFloor(mapModel, point); @@ -204,7 +204,7 @@ final Point pointHead = new Point(0, 0); final Point pointTail = new Point(1, 0); - final MapModel<TestGameObject,TestMapArchObject,TestArchetype> mapModel = mapControl.getMapModel(); + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); mapModel.beginTransaction("TEST"); final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquareHead = mapModel.getMapSquare(pointHead); final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquareTail = mapModel.getMapSquare(pointTail); @@ -264,7 +264,7 @@ final SelectedSquareActions<TestGameObject, TestMapArchObject, TestArchetype> selectedSquareActions = new SelectedSquareActions<TestGameObject, TestMapArchObject, TestArchetype>(selectedSquareModel); final Point point = new Point(0, 0); - final MapModel<TestGameObject,TestMapArchObject,TestArchetype> mapModel = mapControl.getMapModel(); + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); mapModel.beginTransaction("TEST"); final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquare = mapModel.getMapSquare(point); final TestGameObject ob1 = testMapControlCreator.insertExit(mapModel, point); @@ -304,7 +304,7 @@ final Point pointHead = new Point(0, 0); final Point pointTail = new Point(1, 0); - final MapModel<TestGameObject,TestMapArchObject,TestArchetype> mapModel = mapControl.getMapModel(); + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); mapModel.beginTransaction("TEST"); final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquareHead = mapModel.getMapSquare(pointHead); final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquareTail = mapModel.getMapSquare(pointTail); @@ -364,7 +364,7 @@ final SelectedSquareActions<TestGameObject, TestMapArchObject, TestArchetype> selectedSquareActions = new SelectedSquareActions<TestGameObject, TestMapArchObject, TestArchetype>(selectedSquareModel); final Point point = new Point(0, 0); - final MapModel<TestGameObject,TestMapArchObject,TestArchetype> mapModel = mapControl.getMapModel(); + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); mapModel.beginTransaction("TEST"); final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquare = mapModel.getMapSquare(point); final TestGameObject ob1 = testMapControlCreator.insertExit(mapModel, point); @@ -404,7 +404,7 @@ final Point pointHead = new Point(0, 0); final Point pointTail = new Point(1, 0); - final MapModel<TestGameObject,TestMapArchObject,TestArchetype> mapModel = mapControl.getMapModel(); + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); mapModel.beginTransaction("TEST"); final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquareHead = mapModel.getMapSquare(pointHead); final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquareTail = mapModel.getMapSquare(pointTail); @@ -464,7 +464,7 @@ final SelectedSquareActions<TestGameObject, TestMapArchObject, TestArchetype> selectedSquareActions = new SelectedSquareActions<TestGameObject, TestMapArchObject, TestArchetype>(selectedSquareModel); final Point point = new Point(0, 0); - final MapModel<TestGameObject,TestMapArchObject,TestArchetype> mapModel = mapControl.getMapModel(); + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); mapModel.beginTransaction("TEST"); final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquare = mapModel.getMapSquare(point); final TestGameObject ob1 = testMapControlCreator.insertExit(mapModel, point); @@ -497,7 +497,7 @@ final SelectedSquareActions<TestGameObject, TestMapArchObject, TestArchetype> selectedSquareActions = new SelectedSquareActions<TestGameObject, TestMapArchObject, TestArchetype>(selectedSquareModel); final Point point = new Point(0, 0); - final MapModel<TestGameObject,TestMapArchObject,TestArchetype> mapModel = mapControl.getMapModel(); + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); mapModel.beginTransaction("TEST"); final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquare = mapModel.getMapSquare(point); final TestGameObject ob1 = testMapControlCreator.insertExit(mapModel, point); @@ -543,7 +543,7 @@ final SelectedSquareActions<TestGameObject, TestMapArchObject, TestArchetype> selectedSquareActions = new SelectedSquareActions<TestGameObject, TestMapArchObject, TestArchetype>(selectedSquareModel); final Point point = new Point(0, 0); - final MapModel<TestGameObject,TestMapArchObject,TestArchetype> mapModel = mapControl.getMapModel(); + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); mapModel.beginTransaction("TEST"); final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquare = mapModel.getMapSquare(point); final TestGameObject ob1 = testMapControlCreator.insertExit(mapModel, point); @@ -604,7 +604,7 @@ final SelectedSquareActions<TestGameObject, TestMapArchObject, TestArchetype> selectedSquareActions = new SelectedSquareActions<TestGameObject, TestMapArchObject, TestArchetype>(selectedSquareModel); final Point point = new Point(0, 0); - final MapModel<TestGameObject,TestMapArchObject,TestArchetype> mapModel = mapControl.getMapModel(); + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); mapModel.beginTransaction("TEST"); final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquareHead = mapModel.getMapSquare(point); final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquareTail = mapModel.getMapSquare(new Point(1, 0)); @@ -675,7 +675,7 @@ final SelectedSquareActions<TestGameObject, TestMapArchObject, TestArchetype> selectedSquareActions = new SelectedSquareActions<TestGameObject, TestMapArchObject, TestArchetype>(selectedSquareModel); final Point point = new Point(0, 0); - final MapModel<TestGameObject,TestMapArchObject,TestArchetype> mapModel = mapControl.getMapModel(); + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); mapModel.beginTransaction("TEST"); final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquareHead = mapModel.getMapSquare(point); final TestGameObject ob1 = testMapControlCreator.insertExit(mapModel, point); @@ -708,7 +708,7 @@ final SelectedSquareActions<TestGameObject, TestMapArchObject, TestArchetype> selectedSquareActions = new SelectedSquareActions<TestGameObject, TestMapArchObject, TestArchetype>(selectedSquareModel); final Point point = new Point(0, 0); - final MapModel<TestGameObject,TestMapArchObject,TestArchetype> mapModel = mapControl.getMapModel(); + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); mapModel.beginTransaction("TEST"); final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquare = mapModel.getMapSquare(point); final TestGameObject ob4 = testMapControlCreator.insertExit(mapModel, point); @@ -818,7 +818,7 @@ final SelectedSquareActions<TestGameObject, TestMapArchObject, TestArchetype> selectedSquareActions = new SelectedSquareActions<TestGameObject, TestMapArchObject, TestArchetype>(selectedSquareModel); final Point point = new Point(0, 0); - final MapModel<TestGameObject,TestMapArchObject,TestArchetype> mapModel = mapControl.getMapModel(); + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); mapModel.beginTransaction("TEST"); final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquareHead = mapModel.getMapSquare(point); final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquareTail = mapModel.getMapSquare(new Point(1, 0)); @@ -887,7 +887,7 @@ final Point point0 = new Point(0, 0); final Point point1 = new Point(1, 0); - final MapModel<TestGameObject,TestMapArchObject,TestArchetype> mapModel = mapControl.getMapModel(); + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); mapModel.beginTransaction("TEST"); final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquare0 = mapModel.getMapSquare(point0); final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquare1 = mapModel.getMapSquare(point1); @@ -924,7 +924,7 @@ final Point pointHead = new Point(0, 0); final Point pointTail = new Point(1, 0); - final MapModel<TestGameObject,TestMapArchObject,TestArchetype> mapModel = mapControl.getMapModel(); + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); mapModel.beginTransaction("TEST"); final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquareTail = mapModel.getMapSquare(pointTail); testMapControlCreator.insertExit(mapModel, pointHead); @@ -962,7 +962,7 @@ final Point point0 = new Point(0, 0); final Point point1 = new Point(1, 0); - final MapModel<TestGameObject,TestMapArchObject,TestArchetype> mapModel = mapControl.getMapModel(); + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); mapModel.beginTransaction("TEST"); final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquare0 = mapModel.getMapSquare(point0); final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquare1 = mapModel.getMapSquare(point1); Modified: trunk/src/test/net/sf/gridarta/model/gameobject/GameObjectFactoryTest.java =================================================================== --- trunk/src/test/net/sf/gridarta/model/gameobject/GameObjectFactoryTest.java 2010-06-03 16:58:45 UTC (rev 8081) +++ trunk/src/test/net/sf/gridarta/model/gameobject/GameObjectFactoryTest.java 2010-06-03 17:05:07 UTC (rev 8082) @@ -22,7 +22,6 @@ import java.awt.Point; import java.io.File; import net.sf.gridarta.gui.map.test.TestMapControlCreator; -import net.sf.gridarta.gui.selectedsquare.SelectedSquareActions; import net.sf.gridarta.model.archetype.DuplicateArchetypeException; import net.sf.gridarta.model.archetype.TestArchetype; import net.sf.gridarta.model.map.maparchobject.TestMapArchObject; @@ -39,8 +38,9 @@ public class GameObjectFactoryTest { /** - * Checks that {@link SelectedSquareActions#doMoveSquareTop(boolean)} does - * work for single-square game objects. + * Checks that {@link + * net.sf.gridarta.model.gameobject.GameObjectFactory#cloneGameObject(GameObject)} + * correctly updates the container. * @throws DuplicateArchetypeException if the test fails */ @Test @@ -49,7 +49,7 @@ final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl = testMapControlCreator.newMapControl(new File("file"), "name", new Size2D(1, 1)); final Point point = new Point(0, 0); - final MapModel<TestGameObject,TestMapArchObject,TestArchetype> mapModel = mapControl.getMapModel(); + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); mapModel.beginTransaction("TEST"); final TestGameObject ob1 = testMapControlCreator.insertFloor(mapModel, point); final TestGameObject ob2 = testMapControlCreator.insertExit(ob1); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2010-06-06 16:14:02
|
Revision: 8176 http://gridarta.svn.sourceforge.net/gridarta/?rev=8176&view=rev Author: akirschbaum Date: 2010-06-06 16:13:56 +0000 (Sun, 06 Jun 2010) Log Message: ----------- Make regression tests independent on editor settings. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java trunk/src/app/net/sf/gridarta/model/exitconnector/ExitConnectorModel.java trunk/src/test/net/sf/gridarta/exitconnector/ExitConnectorActionsTest.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/model/exitconnector/AbstractExitConnectorModel.java trunk/src/app/net/sf/gridarta/model/exitconnector/DefaultExitConnectorModel.java trunk/src/test/net/sf/gridarta/model/exitconnector/ trunk/src/test/net/sf/gridarta/model/exitconnector/TestExitConnectorModel.java Modified: trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java 2010-06-06 15:47:38 UTC (rev 8175) +++ trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java 2010-06-06 16:13:56 UTC (rev 8176) @@ -130,6 +130,7 @@ import net.sf.gridarta.model.baseobject.GameObjectContainer; import net.sf.gridarta.model.errorview.ErrorView; import net.sf.gridarta.model.errorview.ErrorViewCollector; +import net.sf.gridarta.model.exitconnector.DefaultExitConnectorModel; import net.sf.gridarta.model.exitconnector.ExitConnectorModel; import net.sf.gridarta.model.exitconnector.ExitMatcher; import net.sf.gridarta.model.face.FaceObjectProviders; @@ -547,7 +548,7 @@ mainView.addTab(new Tab("selectedSquare", selectedSquareView, Location.RIGHT, 1, true)); mainView.addTab(new Tab("tools", toolPalette, Location.LEFT, 2, false)); mainView.addTab(new Tab("objects", objectChooser, Location.LEFT, 3, true)); - exitConnectorModel = new ExitConnectorModel(); // XXX: should be part of DefaultMainControl + exitConnectorModel = new DefaultExitConnectorModel(); // XXX: should be part of DefaultMainControl final ExitConnectorActions<G, A, R> exitConnectorActions = new ExitConnectorActions<G, A, R>(exitConnectorModel, exitMatcher, archetypeSet, mapManager, fileControl, pathManager, insertionModeSet); // XXX: should be part of DefaultMainControl //noinspection ResultOfObjectAllocationIgnored new ExitConnectorController<G, A, R>(exitConnectorActions, exitConnectorModel, mapViewManager); Copied: trunk/src/app/net/sf/gridarta/model/exitconnector/AbstractExitConnectorModel.java (from rev 8173, trunk/src/app/net/sf/gridarta/model/exitconnector/ExitConnectorModel.java) =================================================================== --- trunk/src/app/net/sf/gridarta/model/exitconnector/AbstractExitConnectorModel.java (rev 0) +++ trunk/src/app/net/sf/gridarta/model/exitconnector/AbstractExitConnectorModel.java 2010-06-06 16:13:56 UTC (rev 8176) @@ -0,0 +1,210 @@ +/* + * 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.exitconnector; + +import net.sf.gridarta.utils.EventListenerList2; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Stores information needed by the exit connector. + * @author Andreas Kirschbaum + */ +public abstract class AbstractExitConnectorModel implements ExitConnectorModel { + + /** + * The listeners to notify. + */ + private final EventListenerList2<ExitConnectorModelListener> listeners = new EventListenerList2<ExitConnectorModelListener>(ExitConnectorModelListener.class); + + /** + * Whether an exit has been remembered. Set to <code>null</code> if no exit + * location has been remembered. + */ + @Nullable + private ExitLocation exitLocation = null; + + /** + * Whether the exit's name should be set when pasted. + */ + private boolean pasteExitName = loadPasteExitName(); + + /** + * Whether exit game objects should be auto-created when needed. + */ + private boolean autoCreateExit = loadAutoCreateExit(); + + /** + * The archetype to insert when creating new exit game objects. + */ + @NotNull + private String exitArchetypeName = loadExitArchetypeName(); + + /** + * {@inheritDoc} + */ + @Override + @Nullable + public ExitLocation getExitLocation() { + return exitLocation; + } + + /** + * {@inheritDoc} + */ + @Override + public void setExitLocation(@Nullable final ExitLocation exitLocation) { + if (exitLocation == null ? this.exitLocation == null : exitLocation.equals(this.exitLocation)) { + return; + } + + this.exitLocation = exitLocation; + for (final ExitConnectorModelListener listener : listeners.getListeners()) { + listener.exitLocationChanged(exitLocation); + } + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isPasteExitName() { + return pasteExitName; + } + + /** + * {@inheritDoc} + */ + @Override + public void setPasteExitName(final boolean pasteExitName) { + if (this.pasteExitName == pasteExitName) { + return; + } + + this.pasteExitName = pasteExitName; + savePasteExitName(pasteExitName); + for (final ExitConnectorModelListener listener : listeners.getListeners()) { + listener.pasteExitNameChanged(pasteExitName); + } + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isAutoCreateExit() { + return autoCreateExit; + } + + /** + * {@inheritDoc} + */ + @Override + public void setAutoCreateExit(final boolean autoCreateExit) { + if (this.autoCreateExit == autoCreateExit) { + return; + } + + this.autoCreateExit = autoCreateExit; + saveAutoCreateExit(autoCreateExit); + for (final ExitConnectorModelListener listener : listeners.getListeners()) { + listener.autoCreateExitChanged(autoCreateExit); + } + } + + /** + * {@inheritDoc} + */ + @Override + @NotNull + public String getExitArchetypeName() { + return exitArchetypeName; + } + + /** + * {@inheritDoc} + */ + @Override + public void setExitArchetypeName(@NotNull final String exitArchetypeName) { + if (this.exitArchetypeName.equals(exitArchetypeName)) { + return; + } + + this.exitArchetypeName = exitArchetypeName; + saveExitArchetypeName(exitArchetypeName); + for (final ExitConnectorModelListener listener : listeners.getListeners()) { + listener.exitArchetypeNameChanged(exitArchetypeName); + } + } + + /** + * {@inheritDoc} + */ + @Override + public void addExitConnectorModelListener(@NotNull final ExitConnectorModelListener listener) { + listeners.add(listener); + } + + /** + * {@inheritDoc} + */ + @Override + public void removeExitConnectorModelListener(@NotNull final ExitConnectorModelListener listener) { + listeners.remove(listener); + } + + /** + * Returns the stored attribute value for {@link #pasteExitName}. + * @return the attribute value + */ + protected abstract boolean loadPasteExitName(); + + /** + * Sets the stored attribute value for {@link #pasteExitName}. + * @param pasteExitName the attribute value + */ + protected abstract void savePasteExitName(final boolean pasteExitName); + + /** + * Returns the stored attribute value for {@link #autoCreateExit}. + * @return the attribute value + */ + protected abstract boolean loadAutoCreateExit(); + + /** + * Sets the stored attribute value for {@link #isAutoCreateExit()}. + * @param autoCreateExit the attribute value + */ + protected abstract void saveAutoCreateExit(final boolean autoCreateExit); + + /** + * Returns the stored attribute value for {@link #exitArchetypeName}. + * @return the attribute value + */ + @NotNull + protected abstract String loadExitArchetypeName(); + + /** + * Sets the stored attribute value for {@link #setExitArchetypeName(String)}. + * @param exitArchetypeName the attribute value + */ + protected abstract void saveExitArchetypeName(@NotNull final String exitArchetypeName); + +} // class ExitConnectorModel Added: trunk/src/app/net/sf/gridarta/model/exitconnector/DefaultExitConnectorModel.java =================================================================== --- trunk/src/app/net/sf/gridarta/model/exitconnector/DefaultExitConnectorModel.java (rev 0) +++ trunk/src/app/net/sf/gridarta/model/exitconnector/DefaultExitConnectorModel.java 2010-06-06 16:13:56 UTC (rev 8176) @@ -0,0 +1,117 @@ +/* + * 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.exitconnector; + +import java.util.prefs.Preferences; +import net.sf.gridarta.MainControl; +import org.jetbrains.annotations.NotNull; + +/** + * Default {@link ExitConnectorModel} implementation. It saves and restores + * attribute values to/from preferences. + * @author Andreas Kirschbaum + */ +public class DefaultExitConnectorModel extends AbstractExitConnectorModel { + + /** + * The preferences key for "paste exit name". + */ + private static final String PASTE_EXIT_NAME_KEY = "exitConnectorPasteExitName"; + + /** + * The default value for {@link #PASTE_EXIT_NAME_KEY}. + */ + public static final boolean PASTE_EXIT_NAME_DEFAULT = true; + + /** + * The preferences key for "auto create exit". + */ + private static final String AUTO_CREATE_EXIT_KEY = "exitConnectorAutoCreateExit"; + + /** + * The default value for {@link #AUTO_CREATE_EXIT_KEY}. + */ + public static final boolean AUTO_CREATE_EXIT_DEFAULT = true; + + /** + * The preferences key for "exit archetype". + */ + private static final String EXIT_ARCHETYPE_NAME_KEY = "exitConnectorExitArchetypeName"; + + /** + * The default value for {@link #EXIT_ARCHETYPE_NAME_KEY}. + */ + public static final String EXIT_ARCHETYPE_NAME_DEFAULT = "invis_exit"; + + /** + * The {@link Preferences}. + */ + private static final Preferences preferences = Preferences.userNodeForPackage(MainControl.class); + + /** + * {@inheritDoc} + */ + @Override + protected boolean loadPasteExitName() { + return preferences.getBoolean(PASTE_EXIT_NAME_KEY, PASTE_EXIT_NAME_DEFAULT); + } + + /** + * {@inheritDoc} + */ + @Override + protected void savePasteExitName(final boolean pasteExitName) { + preferences.putBoolean(PASTE_EXIT_NAME_KEY, pasteExitName); + } + + /** + * {@inheritDoc} + */ + @Override + protected boolean loadAutoCreateExit() { + return preferences.getBoolean(AUTO_CREATE_EXIT_KEY, AUTO_CREATE_EXIT_DEFAULT); + } + + /** + * {@inheritDoc} + */ + @Override + protected void saveAutoCreateExit(final boolean autoCreateExit) { + preferences.putBoolean(AUTO_CREATE_EXIT_KEY, autoCreateExit); + } + + /** + * {@inheritDoc} + */ + @NotNull + @Override + protected String loadExitArchetypeName() { + return preferences.get(EXIT_ARCHETYPE_NAME_KEY, EXIT_ARCHETYPE_NAME_DEFAULT); + } + + /** + * {@inheritDoc} + */ + @Override + protected void saveExitArchetypeName(@NotNull final String exitArchetypeName) { + preferences.put(EXIT_ARCHETYPE_NAME_KEY, exitArchetypeName); + } + +} // class DefaultExitConnectorModel Property changes on: trunk/src/app/net/sf/gridarta/model/exitconnector/DefaultExitConnectorModel.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Modified: trunk/src/app/net/sf/gridarta/model/exitconnector/ExitConnectorModel.java =================================================================== --- trunk/src/app/net/sf/gridarta/model/exitconnector/ExitConnectorModel.java 2010-06-06 15:47:38 UTC (rev 8175) +++ trunk/src/app/net/sf/gridarta/model/exitconnector/ExitConnectorModel.java 2010-06-06 16:13:56 UTC (rev 8176) @@ -19,9 +19,6 @@ package net.sf.gridarta.model.exitconnector; -import java.util.prefs.Preferences; -import net.sf.gridarta.MainControl; -import net.sf.gridarta.utils.EventListenerList2; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -29,183 +26,84 @@ * Stores information needed by the exit connector. * @author Andreas Kirschbaum */ -public class ExitConnectorModel { +public interface ExitConnectorModel { /** - * The preferences key for "paste exit name". + * The default value for {@link #isPasteExitName()}. */ - private static final String PASTE_EXIT_NAME_KEY = "exitConnectorPasteExitName"; + boolean PASTE_EXIT_NAME_DEFAULT = true; /** - * The default value for {@link #PASTE_EXIT_NAME_KEY}. + * The default value for {@link #isAutoCreateExit()}. */ - public static final boolean PASTE_EXIT_NAME_DEFAULT = true; + boolean AUTO_CREATE_EXIT_DEFAULT = true; /** - * The preferences key for "auto create exit". + * The default value for {@link #getExitArchetypeName()}. */ - private static final String AUTO_CREATE_EXIT_KEY = "exitConnectorAutoCreateExit"; + String EXIT_ARCHETYPE_NAME_DEFAULT = "invis_exit"; /** - * The default value for {@link #AUTO_CREATE_EXIT_KEY}. - */ - public static final boolean AUTO_CREATE_EXIT_DEFAULT = true; - - /** - * The preferences key for "exit archetype". - */ - private static final String EXIT_ARCHETYPE_NAME_KEY = "exitConnectorExitArchetypeName"; - - /** - * The default value for {@link #EXIT_ARCHETYPE_NAME_KEY}. - */ - public static final String EXIT_ARCHETYPE_NAME_DEFAULT = "invis_exit"; - - /** - * The {@link Preferences}. - */ - private static final Preferences preferences = Preferences.userNodeForPackage(MainControl.class); - - /** - * The listeners to notify. - */ - private final EventListenerList2<ExitConnectorModelListener> listeners = new EventListenerList2<ExitConnectorModelListener>(ExitConnectorModelListener.class); - - /** - * Whether an exit has been remembered. Set to <code>null</code> if no exit - * location has been remembered. - */ - @Nullable - private ExitLocation exitLocation = null; - - /** - * Whether the exit's name should be set when pasted. - */ - private boolean pasteExitName = preferences.getBoolean(PASTE_EXIT_NAME_KEY, PASTE_EXIT_NAME_DEFAULT); - - /** - * Whether exit game objects should be auto-created when needed. - */ - private boolean autoCreateExit = preferences.getBoolean(AUTO_CREATE_EXIT_KEY, AUTO_CREATE_EXIT_DEFAULT); - - /** - * The archetype to insert when creating new exit game objects. - */ - @NotNull - private String exitArchetypeName = preferences.get(EXIT_ARCHETYPE_NAME_KEY, EXIT_ARCHETYPE_NAME_DEFAULT); - - /** * Returns the remembered exit location. * @return the exit location or <code>null</code> */ @Nullable - public ExitLocation getExitLocation() { - return exitLocation; - } + ExitLocation getExitLocation(); /** * Sets the remembered exit location. * @param exitLocation the exit location or <code>null</code> */ - public void setExitLocation(@Nullable final ExitLocation exitLocation) { - if (exitLocation == null ? this.exitLocation == null : exitLocation.equals(this.exitLocation)) { - return; - } + void setExitLocation(@Nullable ExitLocation exitLocation); - this.exitLocation = exitLocation; - for (final ExitConnectorModelListener listener : listeners.getListeners()) { - listener.exitLocationChanged(exitLocation); - } - } - /** * Returns whether the exit name should be updated. * @return whether the exit name should be updated */ - public boolean isPasteExitName() { - return pasteExitName; - } + boolean isPasteExitName(); /** * Sets whether the exit name should be updated. * @param pasteExitName whether the exit name should be updated */ - public void setPasteExitName(final boolean pasteExitName) { - if (this.pasteExitName == pasteExitName) { - return; - } + void setPasteExitName(boolean pasteExitName); - this.pasteExitName = pasteExitName; - preferences.putBoolean(PASTE_EXIT_NAME_KEY, pasteExitName); - for (final ExitConnectorModelListener listener : listeners.getListeners()) { - listener.pasteExitNameChanged(pasteExitName); - } - } - /** * Returns whether exit game objects should be auto-created when needed. * @return whether exit game objects should be auto-created when needed */ - public boolean isAutoCreateExit() { - return autoCreateExit; - } + boolean isAutoCreateExit(); /** * Sets whether exit game objects should be auto-created when needed. * @param autoCreateExit whether exit game objects should be auto-created * when needed */ - public void setAutoCreateExit(final boolean autoCreateExit) { - if (this.autoCreateExit == autoCreateExit) { - return; - } + void setAutoCreateExit(boolean autoCreateExit); - this.autoCreateExit = autoCreateExit; - preferences.putBoolean(AUTO_CREATE_EXIT_KEY, autoCreateExit); - for (final ExitConnectorModelListener listener : listeners.getListeners()) { - listener.autoCreateExitChanged(autoCreateExit); - } - } - /** * Returns the archetype name when creating exit game objects. * @return the archetype name */ @NotNull - public String getExitArchetypeName() { - return exitArchetypeName; - } + String getExitArchetypeName(); /** * Sets the archetype name for creating exit game objects. * @param exitArchetypeName the archetype name */ - public void setExitArchetypeName(@NotNull final String exitArchetypeName) { - if (this.exitArchetypeName.equals(exitArchetypeName)) { - return; - } + void setExitArchetypeName(@NotNull String exitArchetypeName); - this.exitArchetypeName = exitArchetypeName; - preferences.put(EXIT_ARCHETYPE_NAME_KEY, exitArchetypeName); - for (final ExitConnectorModelListener listener : listeners.getListeners()) { - listener.exitArchetypeNameChanged(exitArchetypeName); - } - } - /** * Adds an {@link ExitConnectorModelListener} to be notified of changes. * @param listener the listener */ - public void addExitConnectorModelListener(@NotNull final ExitConnectorModelListener listener) { - listeners.add(listener); - } + void addExitConnectorModelListener(@NotNull ExitConnectorModelListener listener); /** * Removes an {@link ExitConnectorModelListener} to be notified of changes. * @param listener the listener */ - public void removeExitConnectorModelListener(@NotNull final ExitConnectorModelListener listener) { - listeners.remove(listener); - } + void removeExitConnectorModelListener(@NotNull ExitConnectorModelListener listener); -} // class ExitConnectorModel +} // interface ExitConnectorModel Modified: trunk/src/test/net/sf/gridarta/exitconnector/ExitConnectorActionsTest.java =================================================================== --- trunk/src/test/net/sf/gridarta/exitconnector/ExitConnectorActionsTest.java 2010-06-06 15:47:38 UTC (rev 8175) +++ trunk/src/test/net/sf/gridarta/exitconnector/ExitConnectorActionsTest.java 2010-06-06 16:13:56 UTC (rev 8176) @@ -28,6 +28,7 @@ import net.sf.gridarta.model.baseobject.BaseObject; import net.sf.gridarta.model.exitconnector.ExitConnectorModel; import net.sf.gridarta.model.exitconnector.ExitLocation; +import net.sf.gridarta.model.exitconnector.TestExitConnectorModel; import net.sf.gridarta.model.gameobject.TestGameObject; import net.sf.gridarta.model.map.maparchobject.TestMapArchObject; import net.sf.gridarta.model.map.mapcontrol.MapControl; @@ -79,7 +80,7 @@ */ @Test public void testExitCopy1() { - final ExitConnectorModel model = new ExitConnectorModel(); + final ExitConnectorModel model = new TestExitConnectorModel(); final ExitConnectorActions<TestGameObject, TestMapArchObject, TestArchetype> actions = createActions(model); final Size2D mapSize = new Size2D(5, 5); assert testMapControlCreator != null; @@ -108,7 +109,7 @@ */ @Test public void testExitPaste1() { - final ExitConnectorModel model = new ExitConnectorModel(); + final ExitConnectorModel model = new TestExitConnectorModel(); final ExitConnectorActions<TestGameObject, TestMapArchObject, TestArchetype> actions = createActions(model); final Size2D mapSize = new Size2D(5, 5); assert testMapControlCreator != null; @@ -148,7 +149,7 @@ */ @Test public void testExitPaste2() { - final ExitConnectorModel model = new ExitConnectorModel(); + final ExitConnectorModel model = new TestExitConnectorModel(); final ExitConnectorActions<TestGameObject, TestMapArchObject, TestArchetype> actions = createActions(model); final Size2D mapSize = new Size2D(5, 5); @@ -163,7 +164,6 @@ model.setExitLocation(new ExitLocation(MAP_FILE2, point2, MAP_NAME2, testMapControlCreator.getPathManager())); model.setAutoCreateExit(true); - model.setExitArchetypeName("exit"); // paste must fail for unsaved map mapModel1.setMapFile(null); // pretend unsaved map @@ -180,7 +180,7 @@ */ @Test public void testExitConnect1() { - final ExitConnectorModel model = new ExitConnectorModel(); + final ExitConnectorModel model = new TestExitConnectorModel(); final ExitConnectorActions<TestGameObject, TestMapArchObject, TestArchetype> actions = createActions(model); final Size2D mapSize = new Size2D(5, 5); @@ -233,7 +233,7 @@ */ @Test public void testExitConnectAuto1() { - final ExitConnectorModel model = new ExitConnectorModel(); + final ExitConnectorModel model = new TestExitConnectorModel(); final ExitConnectorActions<TestGameObject, TestMapArchObject, TestArchetype> actions = createActions(model); final Size2D mapSize = new Size2D(5, 5); @@ -252,6 +252,8 @@ model.setExitLocation(new ExitLocation(MAP_FILE2, point2, MAP_NAME2, testMapControlCreator.getPathManager())); model.setAutoCreateExit(true); + model.setExitArchetypeName("undefined"); + // fails due to undefined archetype Assert.assertFalse(actions.doExitConnect(true, mapControl1, point1)); checkExit(mapModel1, point1, 0, null, null); @@ -304,7 +306,7 @@ * @param expectedExitPath the expected map in the exit object */ private void testPath(@NotNull final String mapPathFrom, @NotNull final String mapPathTo, @NotNull final String expectedExitPath) { - final ExitConnectorModel model = new ExitConnectorModel(); + final ExitConnectorModel model = new TestExitConnectorModel(); final ExitConnectorActions<TestGameObject, TestMapArchObject, TestArchetype> actions = createActions(model); assert testMapControlCreator != null; Added: trunk/src/test/net/sf/gridarta/model/exitconnector/TestExitConnectorModel.java =================================================================== --- trunk/src/test/net/sf/gridarta/model/exitconnector/TestExitConnectorModel.java (rev 0) +++ trunk/src/test/net/sf/gridarta/model/exitconnector/TestExitConnectorModel.java 2010-06-06 16:13:56 UTC (rev 8176) @@ -0,0 +1,80 @@ +/* + * 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.exitconnector; + +import org.jetbrains.annotations.NotNull; + +/** + * {@link ExitConnectorModel} implementation for regression tests. It does not + * retain attribute values. + * @author Andreas Kirschbaum + */ +public class TestExitConnectorModel extends AbstractExitConnectorModel { + + /** + * {@inheritDoc} + */ + @Override + protected boolean loadPasteExitName() { + return true; + } + + /** + * {@inheritDoc} + */ + @Override + protected void savePasteExitName(final boolean pasteExitName) { + // ignore + } + + /** + * {@inheritDoc} + */ + @Override + protected boolean loadAutoCreateExit() { + return false; + } + + /** + * {@inheritDoc} + */ + @Override + protected void saveAutoCreateExit(final boolean autoCreateExit) { + // ignore + } + + /** + * {@inheritDoc} + */ + @NotNull + @Override + protected String loadExitArchetypeName() { + return "exit"; + } + + /** + * {@inheritDoc} + */ + @Override + protected void saveExitArchetypeName(@NotNull final String exitArchetypeName) { + // ignore + } + +} // class TestExitConnectorModel Property changes on: trunk/src/test/net/sf/gridarta/model/exitconnector/TestExitConnectorModel.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...> - 2010-06-06 16:44:15
|
Revision: 8181 http://gridarta.svn.sourceforge.net/gridarta/?rev=8181&view=rev Author: akirschbaum Date: 2010-06-06 16:44:08 +0000 (Sun, 06 Jun 2010) Log Message: ----------- Properly fix "paste exit" when connecting to an unsaved map. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/exitconnector/ExitConnectorActions.java trunk/src/app/net/sf/gridarta/model/exitconnector/ExitLocation.java trunk/src/test/net/sf/gridarta/exitconnector/ExitConnectorActionsTest.java Modified: trunk/src/app/net/sf/gridarta/exitconnector/ExitConnectorActions.java =================================================================== --- trunk/src/app/net/sf/gridarta/exitconnector/ExitConnectorActions.java 2010-06-06 16:20:42 UTC (rev 8180) +++ trunk/src/app/net/sf/gridarta/exitconnector/ExitConnectorActions.java 2010-06-06 16:44:08 UTC (rev 8181) @@ -161,9 +161,6 @@ } final File targetMapFile = targetMapModel.getMapFile(); - if (targetMapFile == null) { - return false; - } if (targetExit != null) { // paste into existing exit @@ -326,12 +323,13 @@ * @param gameObject the exit game object to paste into * @param mapModel the map model to paste into * @param exitLocation the exit information to paste - * @param mapFile the map file to path + * @param gameObjectMapFile the map file of <code>gameObject</code> or + * <code>null</code> if on an unsaved map */ - private void pasteExit(@NotNull final BaseObject<?, ?, ?, ?> gameObject, @NotNull final MapModel<G, A, R> mapModel, @NotNull final ExitLocation exitLocation, @NotNull final File mapFile) { + private void pasteExit(@NotNull final BaseObject<?, ?, ?, ?> gameObject, @NotNull final MapModel<G, A, R> mapModel, @NotNull final ExitLocation exitLocation, @Nullable final File gameObjectMapFile) { mapModel.beginTransaction("paste exit"); try { - exitLocation.updateExitObject(gameObject, exitConnectorModel.isPasteExitName(), mapFile); + exitLocation.updateExitObject(gameObject, exitConnectorModel.isPasteExitName(), gameObjectMapFile); } finally { mapModel.endTransaction(); } @@ -343,10 +341,11 @@ * @param mapModel the map model to insert into * @param archetype the archetype to insert * @param exitLocation the exit information to use - * @param mapFile the map file to paste + * @param mapFile the map file to insert into or <code>null</code> for + * unsaved maps * @return whether insertion was successful */ - private boolean pasteExit(@NotNull final Point location, @NotNull final MapModel<G, A, R> mapModel, @NotNull final BaseObject<G, A, R, ?> archetype, @NotNull final ExitLocation exitLocation, @NotNull final File mapFile) { + private boolean pasteExit(@NotNull final Point location, @NotNull final MapModel<G, A, R> mapModel, @NotNull final BaseObject<G, A, R, ?> archetype, @NotNull final ExitLocation exitLocation, @Nullable final File mapFile) { mapModel.beginTransaction("paste exit"); try { final BaseObject<G, A, R, ?> newExit = mapModel.insertBaseObject(archetype, location, true, false, insertionModeSet.getTopmostInsertionMode()); Modified: trunk/src/app/net/sf/gridarta/model/exitconnector/ExitLocation.java =================================================================== --- trunk/src/app/net/sf/gridarta/model/exitconnector/ExitLocation.java 2010-06-06 16:20:42 UTC (rev 8180) +++ trunk/src/app/net/sf/gridarta/model/exitconnector/ExitLocation.java 2010-06-06 16:44:08 UTC (rev 8181) @@ -89,21 +89,25 @@ * @param gameObject the exit game object to update * @param updateName whether the exit's name should be updated * @param sourceMapFile the file of the map containing - * <code>gameObject</code> + * <code>gameObject</code> or <code>null</code> if on an unsaved map */ - public void updateExitObject(@NotNull final BaseObject<?, ?, ?, ?> gameObject, final boolean updateName, @NotNull final File sourceMapFile) { - final String sourceMapPath = pathManager.getMapPath(sourceMapFile); + public void updateExitObject(@NotNull final BaseObject<?, ?, ?, ?> gameObject, final boolean updateName, @Nullable final File sourceMapFile) { final String targetMapPath = pathManager.getMapPath(file); - - final String sourceMapComponent = getMapComponent(sourceMapPath); - final String targetMapComponent = getMapComponent(targetMapPath); final String mapPath; - if (sourceMapComponent == null ? targetMapComponent == null : sourceMapComponent.equals(targetMapComponent)) { - // relative reference - mapPath = PathManager.absoluteToRelative(sourceMapPath, targetMapPath); + if (sourceMapFile == null) { + // unsaved source map => absolute reference + mapPath = targetMapPath; } else { - // absolute reference - mapPath = targetMapPath; + final String sourceMapPath = pathManager.getMapPath(sourceMapFile); + final String sourceMapComponent = getMapComponent(sourceMapPath); + final String targetMapComponent = getMapComponent(targetMapPath); + if (sourceMapComponent == null ? targetMapComponent == null : sourceMapComponent.equals(targetMapComponent)) { + // relative reference + mapPath = PathManager.absoluteToRelative(sourceMapPath, targetMapPath); + } else { + // absolute reference + mapPath = targetMapPath; + } } gameObject.setAttributeString("slaying", mapPath); gameObject.setAttributeString("hp", Integer.toString(x)); Modified: trunk/src/test/net/sf/gridarta/exitconnector/ExitConnectorActionsTest.java =================================================================== --- trunk/src/test/net/sf/gridarta/exitconnector/ExitConnectorActionsTest.java 2010-06-06 16:20:42 UTC (rev 8180) +++ trunk/src/test/net/sf/gridarta/exitconnector/ExitConnectorActionsTest.java 2010-06-06 16:44:08 UTC (rev 8181) @@ -175,12 +175,11 @@ model.setAutoCreateExit(true); - // paste must fail for unsaved map + // copy must fail for unsaved map mapModel1.setMapFile(null); // pretend unsaved map - Assert.assertFalse(actions.doExitPaste(true, mapControl1, point1)); + Assert.assertFalse(actions.doExitCopy(true, mapControl1, point1)); - // paste must succeed for saved map - mapModel1.setMapFile(MAP_FILE1); // pretend saved map + // paste must succeed for unsaved map Assert.assertTrue(actions.doExitPaste(true, mapControl1, point1)); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2010-06-06 20:27:31
|
Revision: 8190 http://gridarta.svn.sourceforge.net/gridarta/?rev=8190&view=rev Author: akirschbaum Date: 2010-06-06 20:27:24 +0000 (Sun, 06 Jun 2010) Log Message: ----------- Remove doSave parameters from MapMenuPreferences classes. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/gui/mapmenu/AbstractMapMenuPreferences.java trunk/src/app/net/sf/gridarta/gui/mapmenu/BookmarksMapMenuPreferences.java trunk/src/app/net/sf/gridarta/gui/mapmenu/MapMenuManager.java trunk/src/app/net/sf/gridarta/gui/mapmenu/MapMenuPreferences.java trunk/src/app/net/sf/gridarta/gui/mapmenu/RecentMapMenuPreferences.java trunk/src/test/net/sf/gridarta/gui/mapmenu/MapMenuManagerTest.java Modified: trunk/src/app/net/sf/gridarta/gui/mapmenu/AbstractMapMenuPreferences.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/mapmenu/AbstractMapMenuPreferences.java 2010-06-06 19:57:49 UTC (rev 8189) +++ trunk/src/app/net/sf/gridarta/gui/mapmenu/AbstractMapMenuPreferences.java 2010-06-06 20:27:24 UTC (rev 8190) @@ -121,13 +121,12 @@ } /** - * Adds a {@link MapMenuEntry}. + * Adds a {@link MapMenuEntry}. The change is not saved to preferences. * @param index the insertion index * @param mapMenuEntry the map menu entry */ - protected void addMapMenuEntry(final int index, @NotNull final MapMenuEntry<G, A, R> mapMenuEntry) { + protected void addMapMenuEntryInt(final int index, @NotNull final MapMenuEntry<G, A, R> mapMenuEntry) { mapMenuEntries.add(index, mapMenuEntry); - save(); fireIntervalAdded(this, index, index); } @@ -135,14 +134,38 @@ * {@inheritDoc} */ @Override + public void addMapMenuEntry(@NotNull final String title, @NotNull final File mapFile) { + addMapMenuEntryInt(title, mapFile); + save(); + } + + /** + * Adds a {@link MapMenuEntry}. The change is not saved to preferences. + * @param title the entry's title + * @param mapFile the entry's short map file + */ + protected abstract void addMapMenuEntryInt(@NotNull String title, @NotNull File mapFile); + + /** + * {@inheritDoc} + */ + @Override public void removeMapMenuEntry(@NotNull final MapMenuEntry<G, A, R> mapMenuEntry) { + removeMapMenuEntryInt(mapMenuEntry); + save(); + } + + /** + * Removes a {@link MapMenuEntry}. The change is not saved to preferences. + * @param mapMenuEntry the map menu entry + */ + protected void removeMapMenuEntryInt(@NotNull final MapMenuEntry<G, A, R> mapMenuEntry) { final int index = mapMenuEntries.indexOf(mapMenuEntry); if (index == -1) { return; } mapMenuEntries.remove(index); - save(); fireIntervalRemoved(this, index, index); } Modified: trunk/src/app/net/sf/gridarta/gui/mapmenu/BookmarksMapMenuPreferences.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/mapmenu/BookmarksMapMenuPreferences.java 2010-06-06 19:57:49 UTC (rev 8189) +++ trunk/src/app/net/sf/gridarta/gui/mapmenu/BookmarksMapMenuPreferences.java 2010-06-06 20:27:24 UTC (rev 8190) @@ -76,7 +76,7 @@ for (int i = 0; i < numRecents; i++) { final String title = getTitle(i); final File mapFile = getMapFile(i); - addMapMenuEntry(title, mapFile, false); + addMapMenuEntryInt(title, mapFile); } } @@ -126,11 +126,8 @@ * {@inheritDoc} */ @Override - public void addMapMenuEntry(@NotNull final String title, @NotNull final File mapFile, final boolean doSave) { - addMapMenuEntry(getSize(), newMapMenuEntry(title, mapFile)); - if (doSave) { - save(); - } + protected void addMapMenuEntryInt(@NotNull final String title, @NotNull final File mapFile) { + addMapMenuEntryInt(getSize(), newMapMenuEntry(title, mapFile)); } /** Modified: trunk/src/app/net/sf/gridarta/gui/mapmenu/MapMenuManager.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/mapmenu/MapMenuManager.java 2010-06-06 19:57:49 UTC (rev 8189) +++ trunk/src/app/net/sf/gridarta/gui/mapmenu/MapMenuManager.java 2010-06-06 20:27:24 UTC (rev 8190) @@ -160,7 +160,7 @@ return; } - mapMenuPreferences.addMapMenuEntry(title, mapFile, true); + mapMenuPreferences.addMapMenuEntry(title, mapFile); updateRecent(); } Modified: trunk/src/app/net/sf/gridarta/gui/mapmenu/MapMenuPreferences.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/mapmenu/MapMenuPreferences.java 2010-06-06 19:57:49 UTC (rev 8189) +++ trunk/src/app/net/sf/gridarta/gui/mapmenu/MapMenuPreferences.java 2010-06-06 20:27:24 UTC (rev 8190) @@ -68,9 +68,8 @@ * Adds a {@link MapMenuEntry}. * @param title the entry's title * @param mapFile the entry's short map file - * @param doSave whether to save the change to preferences */ - void addMapMenuEntry(@NotNull String title, @NotNull File mapFile, boolean doSave); + void addMapMenuEntry(@NotNull String title, @NotNull File mapFile); /** * Removes a {@link MapMenuEntry}. Modified: trunk/src/app/net/sf/gridarta/gui/mapmenu/RecentMapMenuPreferences.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/mapmenu/RecentMapMenuPreferences.java 2010-06-06 19:57:49 UTC (rev 8189) +++ trunk/src/app/net/sf/gridarta/gui/mapmenu/RecentMapMenuPreferences.java 2010-06-06 20:27:24 UTC (rev 8190) @@ -77,7 +77,7 @@ for (int i = numRecents - 1; i >= 0; i--) { final String title = getTitle(i); final File mapFile = getMapFile(i); - addMapMenuEntry(title, mapFile, false); + addMapMenuEntryInt(title, mapFile); } } @@ -112,10 +112,10 @@ * {@inheritDoc} */ @Override - public void addMapMenuEntry(@NotNull final String title, @NotNull final File mapFile, final boolean doSave) { + protected void addMapMenuEntryInt(@NotNull final String title, @NotNull final File mapFile) { final MapMenuEntry<G, A, R> mapMenuEntry = newMapMenuEntry(title, mapFile); - removeMapMenuEntry(mapMenuEntry); // remove old entry to get new entry at first pos. - addMapMenuEntry(0, mapMenuEntry); + removeMapMenuEntryInt(mapMenuEntry); // remove old entry to get new entry at first pos. + addMapMenuEntryInt(0, mapMenuEntry); // Now remove those that are too many. // Please keep this while loop as the constant 10 might be replaced by a preferences var int i = 0; @@ -125,9 +125,6 @@ it.remove(); } } - if (doSave) { - save(); - } } /** Modified: trunk/src/test/net/sf/gridarta/gui/mapmenu/MapMenuManagerTest.java =================================================================== --- trunk/src/test/net/sf/gridarta/gui/mapmenu/MapMenuManagerTest.java 2010-06-06 19:57:49 UTC (rev 8189) +++ trunk/src/test/net/sf/gridarta/gui/mapmenu/MapMenuManagerTest.java 2010-06-06 20:27:24 UTC (rev 8190) @@ -87,9 +87,9 @@ } @Override - public void addMapMenuEntry(@NotNull final String title, @NotNull final File mapFile, final boolean doSave) { + protected void addMapMenuEntryInt(@NotNull final String title, @NotNull final File mapFile) { final MapMenuEntry<TestGameObject, TestMapArchObject, TestArchetype> mapMenuEntry = newMapMenuEntry(title, mapFile); - addMapMenuEntry(getSize(), mapMenuEntry); + addMapMenuEntryInt(getSize(), mapMenuEntry); } }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2010-06-06 22:34:38
|
Revision: 8220 http://gridarta.svn.sourceforge.net/gridarta/?rev=8220&view=rev Author: akirschbaum Date: 2010-06-06 22:34:32 +0000 (Sun, 06 Jun 2010) Log Message: ----------- Remove unneeded warning suppressions. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/gui/prefs/NetPreferences.java trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java trunk/src/app/net/sf/gridarta/model/face/DefaultFaceObjects.java trunk/src/app/net/sf/gridarta/model/filter/AbstractFilterConfig.java trunk/src/test/net/sf/gridarta/model/archetype/AttributeListUtilsTest.java Modified: trunk/src/app/net/sf/gridarta/gui/prefs/NetPreferences.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/prefs/NetPreferences.java 2010-06-06 22:31:01 UTC (rev 8219) +++ trunk/src/app/net/sf/gridarta/gui/prefs/NetPreferences.java 2010-06-06 22:34:32 UTC (rev 8220) @@ -144,8 +144,7 @@ */ @Override public void revert() { - //XXX: suppression needed because some javac versions (1.6.0_01, 1.6.0_16, 1.7.0-ea) report incomparable types - //noinspection TypeMayBeWeakened + //Cannot weaken tp Enum<Proxy.Type> because some javac versions (1.6.0_01, 1.6.0_16, 1.7.0-ea) report incomparable types final Proxy.Type keyType = Proxy.Type.valueOf(PREFERENCES.get(NET_PREFERENCES_KEY_TYPE, "DIRECT")); proxyType.setSelectedIndex(keyType.ordinal()); final boolean enableProxy = keyType != Proxy.Type.DIRECT; Modified: trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java 2010-06-06 22:31:01 UTC (rev 8219) +++ trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java 2010-06-06 22:34:32 UTC (rev 8220) @@ -534,7 +534,6 @@ final Action aCloseAllMaps = ActionUtils.newAction(ACTION_BUILDER, "Map,Window", fileControl, "closeAllMaps"); mainView = new MainView(mainViewFrame, exitAction, mapDesktop, icon, exiter); ActionUtils.newAction(ACTION_BUILDER, "Tool", new MainViewActions<G, A, R>(mainView, gameObjectAttributesControl, gameObjectTab, textEditorTab), "gameObjectTextEditor"); - //noinspection ResultOfObjectAllocationIgnored final BookmarksMapMenuPreferences<G, A, R> bookmarksMapMenuPreferences = new BookmarksMapMenuPreferences<G, A, R>(mapViewsManager, globalSettings, mapImageCache, fileControl); @Nullable final MapMenuManager<G, A, R> bookmarksMapMenuManager = new MapMenuManager<G, A, R>(mapManager, bookmarksMapMenuPreferences); //noinspection ResultOfObjectAllocationIgnored Modified: trunk/src/app/net/sf/gridarta/model/face/DefaultFaceObjects.java =================================================================== --- trunk/src/app/net/sf/gridarta/model/face/DefaultFaceObjects.java 2010-06-06 22:31:01 UTC (rev 8219) +++ trunk/src/app/net/sf/gridarta/model/face/DefaultFaceObjects.java 2010-06-06 22:34:32 UTC (rev 8220) @@ -170,8 +170,6 @@ try { final FileInputStream fin = new FileInputStream(path); try { - //It's safely closed because the stream is closed and that closes the channel. - //noinspection ChannelOpenedButNotSafelyClosed final FileChannel inChannel = fin.getChannel(); final long imageSize = inChannel.size(); binFile.format("IMAGE %d %d %s\n", i, imageSize, face); Modified: trunk/src/app/net/sf/gridarta/model/filter/AbstractFilterConfig.java =================================================================== --- trunk/src/app/net/sf/gridarta/model/filter/AbstractFilterConfig.java 2010-06-06 22:31:01 UTC (rev 8219) +++ trunk/src/app/net/sf/gridarta/model/filter/AbstractFilterConfig.java 2010-06-06 22:34:32 UTC (rev 8220) @@ -29,7 +29,6 @@ * Abstract base class for filter configurations. * @author tchize */ -@SuppressWarnings({ "AbstractClassWithoutAbstractMethods" }) public abstract class AbstractFilterConfig<F extends Filter<F, C>, C extends FilterConfig<F, C>> implements FilterConfig<F, C> { /** Modified: trunk/src/test/net/sf/gridarta/model/archetype/AttributeListUtilsTest.java =================================================================== --- trunk/src/test/net/sf/gridarta/model/archetype/AttributeListUtilsTest.java 2010-06-06 22:31:01 UTC (rev 8219) +++ trunk/src/test/net/sf/gridarta/model/archetype/AttributeListUtilsTest.java 2010-06-06 22:34:32 UTC (rev 8220) @@ -26,8 +26,6 @@ * Test for {@link AttributeListUtils}. * @author Andreas Kirschbaum */ -@SuppressWarnings({ "FeatureEnvy" }) -// This is a test. It has feature envy by definition. public class AttributeListUtilsTest { /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2010-06-06 23:08:59
|
Revision: 8211 http://gridarta.svn.sourceforge.net/gridarta/?rev=8211&view=rev Author: akirschbaum Date: 2010-06-06 22:16:57 +0000 (Sun, 06 Jun 2010) Log Message: ----------- Add private modifiers. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/model/archetypetype/ArchetypeTypeParser.java trunk/src/app/net/sf/gridarta/model/exitconnector/DefaultExitConnectorModel.java trunk/src/test/net/sf/gridarta/gui/map/test/TestMapControlCreator.java Modified: trunk/src/app/net/sf/gridarta/model/archetypetype/ArchetypeTypeParser.java =================================================================== --- trunk/src/app/net/sf/gridarta/model/archetypetype/ArchetypeTypeParser.java 2010-06-06 22:14:05 UTC (rev 8210) +++ trunk/src/app/net/sf/gridarta/model/archetypetype/ArchetypeTypeParser.java 2010-06-06 22:16:57 UTC (rev 8211) @@ -44,7 +44,7 @@ * Attribute Element Name. */ @NotNull - public static final String XML_ELEMENT_ATTRIBUTE = "attribute"; + private static final String XML_ELEMENT_ATTRIBUTE = "attribute"; /** * Required Element Name. @@ -80,7 +80,7 @@ * The "arch" attribute name of a {@link #XML_ELEMENT_ATTRIBUTE} element. */ @NotNull - public static final String XML_ATTRIBUTE_ARCH = "arch"; + private static final String XML_ATTRIBUTE_ARCH = "arch"; /** * The "value" attribute name of a {@link #XML_ELEMENT_ATTRIBUTE} element. Modified: trunk/src/app/net/sf/gridarta/model/exitconnector/DefaultExitConnectorModel.java =================================================================== --- trunk/src/app/net/sf/gridarta/model/exitconnector/DefaultExitConnectorModel.java 2010-06-06 22:14:05 UTC (rev 8210) +++ trunk/src/app/net/sf/gridarta/model/exitconnector/DefaultExitConnectorModel.java 2010-06-06 22:16:57 UTC (rev 8211) @@ -38,7 +38,7 @@ /** * The default value for {@link #PASTE_EXIT_NAME_KEY}. */ - public static final boolean PASTE_EXIT_NAME_DEFAULT = true; + private static final boolean PASTE_EXIT_NAME_DEFAULT = true; /** * The preferences key for "auto create exit". @@ -48,7 +48,7 @@ /** * The default value for {@link #AUTO_CREATE_EXIT_KEY}. */ - public static final boolean AUTO_CREATE_EXIT_DEFAULT = true; + private static final boolean AUTO_CREATE_EXIT_DEFAULT = true; /** * The preferences key for "exit archetype". @@ -58,7 +58,7 @@ /** * The default value for {@link #EXIT_ARCHETYPE_NAME_KEY}. */ - public static final String EXIT_ARCHETYPE_NAME_DEFAULT = "invis_exit"; + private static final String EXIT_ARCHETYPE_NAME_DEFAULT = "invis_exit"; /** * The {@link Preferences}. Modified: trunk/src/test/net/sf/gridarta/gui/map/test/TestMapControlCreator.java =================================================================== --- trunk/src/test/net/sf/gridarta/gui/map/test/TestMapControlCreator.java 2010-06-06 22:14:05 UTC (rev 8210) +++ trunk/src/test/net/sf/gridarta/gui/map/test/TestMapControlCreator.java 2010-06-06 22:16:57 UTC (rev 8211) @@ -468,7 +468,7 @@ * @param mapSquare the map square * @param gameObjects the game object */ - public static void checkContentsString(@NotNull final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquare, @NotNull final String... gameObjects) { + private static void checkContentsString(@NotNull final MapSquare<TestGameObject, TestMapArchObject, TestArchetype> mapSquare, @NotNull final String... gameObjects) { int i = 0; for (final TestGameObject gameObject : mapSquare) { final String gameObjectName = gameObject.getBestName(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2010-06-06 23:09:19
|
Revision: 8208 http://gridarta.svn.sourceforge.net/gridarta/?rev=8208&view=rev Author: akirschbaum Date: 2010-06-06 22:10:07 +0000 (Sun, 06 Jun 2010) Log Message: ----------- Suppress warnings. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/MainControl.java trunk/src/app/net/sf/gridarta/textedit/textarea/InputHandler.java trunk/src/test/net/sf/gridarta/validation/AbstractValidatorTest.java Modified: trunk/src/app/net/sf/gridarta/MainControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/MainControl.java 2010-06-06 22:07:50 UTC (rev 8207) +++ trunk/src/app/net/sf/gridarta/MainControl.java 2010-06-06 22:10:07 UTC (rev 8208) @@ -22,6 +22,7 @@ /** * Interface used as preferences location. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @noinspection InterfaceNeverImplemented,MarkerInterface */ public interface MainControl { Modified: trunk/src/app/net/sf/gridarta/textedit/textarea/InputHandler.java =================================================================== --- trunk/src/app/net/sf/gridarta/textedit/textarea/InputHandler.java 2010-06-06 22:07:50 UTC (rev 8207) +++ trunk/src/app/net/sf/gridarta/textedit/textarea/InputHandler.java 2010-06-06 22:10:07 UTC (rev 8208) @@ -208,6 +208,7 @@ /** * If an action implements this interface, it should not be repeated. * Instead, it will handle the repetition itself. + * @noinspection MarkerInterface,PublicInnerClass */ public interface NonRepeatable { Modified: trunk/src/test/net/sf/gridarta/validation/AbstractValidatorTest.java =================================================================== --- trunk/src/test/net/sf/gridarta/validation/AbstractValidatorTest.java 2010-06-06 22:07:50 UTC (rev 8207) +++ trunk/src/test/net/sf/gridarta/validation/AbstractValidatorTest.java 2010-06-06 22:10:07 UTC (rev 8208) @@ -36,16 +36,19 @@ /** * {@inheritDoc} + * @noinspection ProhibitedExceptionDeclared */ @Override public void setUp() throws Exception { super.setUp(); + //noinspection EmptyClass oUT = new AbstractValidator("") { }; } /** * {@inheritDoc} + * @noinspection ProhibitedExceptionDeclared */ @Override public void tearDown() throws Exception { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2010-06-07 18:30:42
|
Revision: 8262 http://gridarta.svn.sourceforge.net/gridarta/?rev=8262&view=rev Author: akirschbaum Date: 2010-06-07 18:30:34 +0000 (Mon, 07 Jun 2010) Log Message: ----------- Make regression tests independent on editor settings. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/maincontrol/GridartaEditor.java trunk/src/app/net/sf/gridarta/maincontrol/ImageCreatorFactory.java trunk/src/app/net/sf/gridarta/model/mapviewsettings/MapViewSettings.java trunk/src/test/net/sf/gridarta/gui/map/test/TestMapControlCreator.java trunk/src/test/net/sf/gridarta/model/map/mapmodel/DefaultMapModelTest.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/model/mapviewsettings/AbstractMapViewSettings.java trunk/src/app/net/sf/gridarta/model/mapviewsettings/DefaultMapViewSettings.java trunk/src/test/net/sf/gridarta/model/mapviewsettings/ trunk/src/test/net/sf/gridarta/model/mapviewsettings/TestMapViewSettings.java Modified: trunk/src/app/net/sf/gridarta/maincontrol/GridartaEditor.java =================================================================== --- trunk/src/app/net/sf/gridarta/maincontrol/GridartaEditor.java 2010-06-07 07:41:06 UTC (rev 8261) +++ trunk/src/app/net/sf/gridarta/maincontrol/GridartaEditor.java 2010-06-07 18:30:34 UTC (rev 8262) @@ -77,6 +77,7 @@ import net.sf.gridarta.model.map.mapcontrol.MapControlFactory; import net.sf.gridarta.model.map.mapmodel.InsertionMode; import net.sf.gridarta.model.map.mapmodel.TopmostInsertionMode; +import net.sf.gridarta.model.mapviewsettings.DefaultMapViewSettings; import net.sf.gridarta.model.mapviewsettings.MapViewSettings; import net.sf.gridarta.model.match.GameObjectMatchers; import net.sf.gridarta.model.match.NamedGameObjectMatcher; @@ -219,7 +220,7 @@ final GUIUtils guiUtils = new GUIUtils(); final SystemIcons systemIcons = new SystemIcons(guiUtils); final ConfigSourceFactory configSourceFactory = new DefaultConfigSourceFactory(); - final MapViewSettings mapViewSettings = new MapViewSettings(); + final MapViewSettings mapViewSettings = new DefaultMapViewSettings(); final GlobalSettings globalSettings = editorFactory.newGlobalSettings(configSourceFactory); final PathManager pathManager = new PathManager(globalSettings); final GameObjectMatchers gameObjectMatchers = new GameObjectMatchers(); Modified: trunk/src/app/net/sf/gridarta/maincontrol/ImageCreatorFactory.java =================================================================== --- trunk/src/app/net/sf/gridarta/maincontrol/ImageCreatorFactory.java 2010-06-07 07:41:06 UTC (rev 8261) +++ trunk/src/app/net/sf/gridarta/maincontrol/ImageCreatorFactory.java 2010-06-07 18:30:34 UTC (rev 8262) @@ -52,6 +52,7 @@ import net.sf.gridarta.model.map.mapcontrol.MapControlFactory; import net.sf.gridarta.model.map.mapmodel.InsertionMode; import net.sf.gridarta.model.map.mapmodel.TopmostInsertionMode; +import net.sf.gridarta.model.mapviewsettings.DefaultMapViewSettings; import net.sf.gridarta.model.mapviewsettings.MapViewSettings; import net.sf.gridarta.model.match.GameObjectMatchers; import net.sf.gridarta.model.match.NamedGameObjectMatcher; @@ -103,7 +104,7 @@ final ArchetypeFactory<G, A, R> archetypeFactory = editorFactory.newArchetypeFactory(faceObjectProviders, animationObjects); final GameObjectParser<G, A, R> gameObjectParser = gameObjectParserFactory.newGameObjectParser(); final ArchetypeSet<G, A, R> archetypeSet = editorFactory.newArchetypeSet(globalSettings, archetypeFactory, gameObjectParser, faceObjectProviders); - final MapViewSettings mapViewSettings = new MapViewSettings(); + final MapViewSettings mapViewSettings = new DefaultMapViewSettings(); final MapReaderFactory<G, A> mapReaderFactory = new DefaultMapReaderFactory<G, A, R>(mapArchObjectFactory, mapArchObjectParserFactory, gameObjectParserFactory, archetypeSet, mapViewSettings); final MapWriter<G, A, R> mapWriter = new DefaultMapWriter<G, A, R>(mapArchObjectParserFactory, gameObjectParser); final AutojoinLists<G, A, R> autojoinLists = new AutojoinLists<G, A, R>(mapViewSettings); Added: trunk/src/app/net/sf/gridarta/model/mapviewsettings/AbstractMapViewSettings.java =================================================================== --- trunk/src/app/net/sf/gridarta/model/mapviewsettings/AbstractMapViewSettings.java (rev 0) +++ trunk/src/app/net/sf/gridarta/model/mapviewsettings/AbstractMapViewSettings.java 2010-06-07 18:30:34 UTC (rev 8262) @@ -0,0 +1,385 @@ +/* + * 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.mapviewsettings; + +import net.sf.gridarta.gui.utils.GUIConstants; +import net.sf.gridarta.model.baseobject.BaseObject; +import net.sf.gridarta.model.match.ViewGameObjectMatcherManager; +import net.sf.gridarta.utils.EventListenerList2; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Abstract base class for {@link MapViewSettings} implementations. + * @author Andreas Kirschbaum + */ +public abstract class AbstractMapViewSettings implements MapViewSettings { + + /** + * The visibility of the grid. + */ + private boolean gridVisible = false; + + /** + * Whether smoothing display is active. + */ + private boolean smoothing = false; + + /** + * Whether double faces should be drawn double height. + */ + private boolean doubleFaces = false; + + /** + * Bit field of edit types to show transparent. + */ + private int alphaType = 0; + + /** + * Bit field of edit types to show only. + */ + private int editType = 0; + + /** + * Whether autojoining is on/off. + */ + private boolean autojoin = loadAutojoin(); + + /** + * The transparency settings. + */ + // TODO: use this field (it looks unused but usage is planned) + @Nullable + private ViewGameObjectMatcherManager transparencyManager = null; + + /** + * The visibility settings. + */ + // TODO: use this field (it looks unused but usage is planned) + @Nullable + private ViewGameObjectMatcherManager visibilityManager = null; + + /** + * The MapViewSettingsListeners to inform of changes. + */ + @NotNull + private final EventListenerList2<MapViewSettingsListener> listenerList = new EventListenerList2<MapViewSettingsListener>(MapViewSettingsListener.class); + + /** + * {@inheritDoc} + */ + @Override + public void addMapViewSettingsListener(@NotNull final MapViewSettingsListener listener) { + listenerList.add(listener); + } + + /** + * {@inheritDoc} + */ + @Override + public void removeMapViewSettingsListener(@NotNull final MapViewSettingsListener listener) { + listenerList.remove(listener); + } + + /** + * Get the visibility of the grid. + * @return visibility of the grid (<code>true</code> for visible, + * <code>false</code> for invisible) + */ + @Override + public boolean isGridVisible() { + return gridVisible; + } + + /** + * Set the visibility of the grid. + * @param gridVisible new visibility of the grid (<code>true</code> for + * making the grid visible, <code>false</code> for invisible) + */ + @Override + public void setGridVisible(final boolean gridVisible) { + if (this.gridVisible == gridVisible) { + return; + } + + this.gridVisible = gridVisible; + fireGridVisibleChanged(); + } + + /** + * Returns the smoothing setting. + * @return the smoothing setting + */ + @Override + public boolean isSmoothing() { + return smoothing; + } + + /** + * Sets the smoothing setting. + * @param smoothing the new smoothing setting + */ + @Override + public void setSmoothing(final boolean smoothing) { + if (this.smoothing == smoothing) { + return; + } + + this.smoothing = smoothing; + fireSmoothingChanged(); + } + + /** + * Get whether double faces are drawn double height. + * @return <code>true</code> if double faces are drawn double height, + * otherwise <code>false</code> + */ + @Override + public boolean isDoubleFaces() { + return doubleFaces; + } + + /** + * Sets whether double faces should be drawn double height. + * @param doubleFaces whether double faces should be drawn double height + */ + @Override + public void setDoubleFaces(final boolean doubleFaces) { + if (this.doubleFaces == doubleFaces) { + return; + } + + this.doubleFaces = doubleFaces; + fireDoubleFacesChanged(); + } + + /** + * Returns whether the specified edit type is to be shown transparent. + * @param v edit type to check + * @return <code>true</code> if to be displayed transparent, otherwise + * <code>false</code> + */ + @Override + public boolean isAlphaType(final int v) { + return v > 0 && (alphaType & v) == v; + } + + /** + * Sets whether the specified edit type is to be shown transparent. + * @param v edit type to set + * @param state state, <code>true</code> to make edit type <code>v</code> + * transparent, <code>false</code> for opaque + */ + @Override + public void setAlphaType(final int v, final boolean state) { + if (state) { + alphaType |= v; + } else { + alphaType &= ~v; + } + fireAlphaTypeChanged(); + } + + /** + * Clear the transparency. + */ + @Override + public void clearAlpha() { + alphaType = 0; + fireAlphaTypeChanged(); + } + + /** + * Returns the currently set edit type. + * @return the currently set edit type. + */ + @Override + public int getEditType() { + return editType; + } + + /** + * Set the map view to show squares of the given type. (If no edit type is + * set, everything is displayed) + * @param editType edit type bitmask of types to show + */ + private void setEditType(final int editType) { + if ((this.editType & editType) == editType) { + return; + } + + this.editType |= editType; + fireEditTypeChanged(); + } + + /** + * Set the map view to hide squares of the given type. (If no edit type is + * set, everything is displayed) + * @param editType edit type bitmask of types to hide + */ + @Override + public void unsetEditType(final int editType) { + if ((this.editType & editType) == 0) { + return; + } + + this.editType &= ~editType; + fireEditTypeChanged(); + } + + /** + * Get information on the current state of edit type. Are squares of type + * 'editType' displayed? + * @param editType are squares of this type displayed? + * @return <code>true</code> if these squares are currently displayed + */ + @Override + public boolean isEditType(final int editType) { + final int mask = editType == 0 ? GUIConstants.EDIT_TYPE_NONE : editType; + return (this.editType & mask) != 0; + } + + /** + * Get information whether the gameObject is edited. Are squares of type 'v' + * displayed? + * @param gameObject are squares of this type displayed? + * @return true if these squares are currently displayed + */ + @Override + public boolean isEditType(@NotNull final BaseObject<?, ?, ?, ?> gameObject) { + return editType == 0 || isEditType(gameObject.getEditType()); + } + + /** + * Returns whether a editType value is set so that not all squares are + * displayed. + * @return <code>true</code> if a editType value is set, otherwise + * <code>false</code>. + */ + @Override + public boolean isEditTypeSet() { + return (editType & GUIConstants.EDIT_TYPE_NONE) == 0 && editType != 0; + } + + /** + * Toggle an edit type. + * @param editType the edit type to toggle + */ + @Override + public void toggleEditType(final int editType) { + if (isEditType(editType)) { + unsetEditType(editType); + } else { + setEditType(editType); + } + } + + /** + * Returns whether "autojoin" is enabled. + * @return the autojoin state + */ + @Override + public boolean isAutojoin() { + return autojoin; + } + + /** + * Sets the "autojoin" state. + * @param autojoin if set, enable autojoining + */ + @Override + public void setAutojoin(final boolean autojoin) { + if (this.autojoin == autojoin) { + return; + } + + this.autojoin = autojoin; + saveAutojoin(autojoin); + fireAutojoinChanged(); + } + + /** + * Informs all registered listeners that the grid visibility has changed. + */ + private void fireGridVisibleChanged() { + for (final MapViewSettingsListener listener : listenerList.getListeners()) { + listener.gridVisibleChanged(gridVisible); + } + } + + /** + * Informs all registered listeners that the smoothing setting has changed. + */ + private void fireSmoothingChanged() { + for (final MapViewSettingsListener listener : listenerList.getListeners()) { + listener.smoothingChanged(smoothing); + } + } + + /** + * Informs all registered listeners that the double faces visibility has + * changed. + */ + private void fireDoubleFacesChanged() { + for (final MapViewSettingsListener listener : listenerList.getListeners()) { + listener.doubleFacesChanged(doubleFaces); + } + } + + /** + * Informs all registered listeners that the alpha type haves changed. + */ + private void fireAlphaTypeChanged() { + for (final MapViewSettingsListener listener : listenerList.getListeners()) { + listener.alphaTypeChanged(alphaType); + } + } + + /** + * Notify all listeners about changed {@link #editType}. + */ + private void fireEditTypeChanged() { + for (final MapViewSettingsListener listener : listenerList.getListeners()) { + listener.editTypeChanged(editType); + } + } + + /** + * Notify all listeners about changed {@link #autojoin}. + */ + private void fireAutojoinChanged() { + for (final MapViewSettingsListener listener : listenerList.getListeners()) { + listener.autojoinChanged(autojoin); + } + } + + /** + * Loads the default value for {@link #autojoin}. + * @return the default value + */ + protected abstract boolean loadAutojoin(); + + /** + * Saves the autojoin value. + * @param autojoin the autojoin value + */ + protected abstract void saveAutojoin(final boolean autojoin); + +} // class AbstractMapViewSettings Property changes on: trunk/src/app/net/sf/gridarta/model/mapviewsettings/AbstractMapViewSettings.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Added: trunk/src/app/net/sf/gridarta/model/mapviewsettings/DefaultMapViewSettings.java =================================================================== --- trunk/src/app/net/sf/gridarta/model/mapviewsettings/DefaultMapViewSettings.java (rev 0) +++ trunk/src/app/net/sf/gridarta/model/mapviewsettings/DefaultMapViewSettings.java 2010-06-07 18:30:34 UTC (rev 8262) @@ -0,0 +1,62 @@ +/* + * 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.mapviewsettings; + +import java.util.prefs.Preferences; +import net.sf.gridarta.MainControl; +import org.jetbrains.annotations.NotNull; + +/** + * Default {@link MapViewSettings} implementation. Attributes are retained + * across editor restarts. The attributes are stored in the {@link + * Preferences}. + * @author Andreas Kirschbaum + */ +public class DefaultMapViewSettings extends AbstractMapViewSettings { + + /** + * Key for saving {@link #autojoin} state in preferences. + */ + @NotNull + private static final String AUTOJOIN_KEY = "autojoin"; + + /** + * Preferences. + */ + @NotNull + private static final Preferences preferences = Preferences.userNodeForPackage(MainControl.class); + + /** + * {@inheritDoc} + */ + @Override + protected boolean loadAutojoin() { + return preferences.getBoolean(AUTOJOIN_KEY, false); + } + + /** + * {@inheritDoc} + */ + @Override + protected void saveAutojoin(final boolean autojoin) { + preferences.putBoolean(AUTOJOIN_KEY, autojoin); + } + +} // class DefaultMapViewSettings Property changes on: trunk/src/app/net/sf/gridarta/model/mapviewsettings/DefaultMapViewSettings.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Modified: trunk/src/app/net/sf/gridarta/model/mapviewsettings/MapViewSettings.java =================================================================== --- trunk/src/app/net/sf/gridarta/model/mapviewsettings/MapViewSettings.java 2010-06-07 07:41:06 UTC (rev 8261) +++ trunk/src/app/net/sf/gridarta/model/mapviewsettings/MapViewSettings.java 2010-06-07 18:30:34 UTC (rev 8262) @@ -19,230 +19,74 @@ package net.sf.gridarta.model.mapviewsettings; -import java.util.prefs.Preferences; -import net.sf.gridarta.MainControl; -import net.sf.gridarta.gui.utils.GUIConstants; import net.sf.gridarta.model.baseobject.BaseObject; -import net.sf.gridarta.model.match.ViewGameObjectMatcherManager; -import net.sf.gridarta.utils.EventListenerList2; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; /** * Container for settings that affect the rendering of maps. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> * @author Andreas Kirschbaum */ -public class MapViewSettings { +public interface MapViewSettings { /** - * Key for saving {@link #autojoin} state in preferences. - */ - @NotNull - private static final String AUTOJOIN_KEY = "autojoin"; - - /** - * Preferences. - */ - @NotNull - private static final Preferences preferences = Preferences.userNodeForPackage(MainControl.class); - - /** - * The visibility of the grid. - */ - private boolean gridVisible = false; - - /** - * Whether smoothing display is active. - */ - private boolean smoothing = false; - - /** - * Whether double faces should be drawn double height. - */ - private boolean doubleFaces = false; - - /** - * Bit field of edit types to show transparent. - */ - private int alphaType = 0; - - /** - * Bit field of edit types to show only. - */ - private int editType = 0; - - /** - * Whether autojoining is on/off. - */ - private boolean autojoin = preferences.getBoolean(AUTOJOIN_KEY, false); - - /** - * The transparency settings. - */ - // TODO: use this field (it looks unused but usage is planned) - @Nullable - private ViewGameObjectMatcherManager transparencyManager = null; - - /** - * The visibility settings. - */ - // TODO: use this field (it looks unused but usage is planned) - @Nullable - private ViewGameObjectMatcherManager visibilityManager = null; - - /** - * The MapViewSettingsListeners to inform of changes. - */ - @NotNull - private final EventListenerList2<MapViewSettingsListener> listenerList = new EventListenerList2<MapViewSettingsListener>(MapViewSettingsListener.class); - - /** * Register a MapViewSettingsListener. * @param listener MapViewSettingsListener to register */ - public void addMapViewSettingsListener(@NotNull final MapViewSettingsListener listener) { - listenerList.add(listener); - } + void addMapViewSettingsListener(@NotNull MapViewSettingsListener listener); /** * Unregister a MapViewSettingsListener. * @param listener MapViewSettingsListener to unregister */ - public void removeMapViewSettingsListener(@NotNull final MapViewSettingsListener listener) { - listenerList.remove(listener); - } + void removeMapViewSettingsListener(@NotNull MapViewSettingsListener listener); /** - * Informs all registered listeners that the grid visibility has changed. - */ - private void fireGridVisibleChanged() { - for (final MapViewSettingsListener listener : listenerList.getListeners()) { - listener.gridVisibleChanged(gridVisible); - } - } - - /** - * Informs all registered listeners that the smoothing setting has changed. - */ - private void fireSmoothingChanged() { - for (final MapViewSettingsListener listener : listenerList.getListeners()) { - listener.smoothingChanged(smoothing); - } - } - - /** - * Informs all registered listeners that the double faces visibility has - * changed. - */ - private void fireDoubleFacesChanged() { - for (final MapViewSettingsListener listener : listenerList.getListeners()) { - listener.doubleFacesChanged(doubleFaces); - } - } - - /** - * Informs all registered listeners that the alpha type haves changed. - */ - private void fireAlphaTypeChanged() { - for (final MapViewSettingsListener listener : listenerList.getListeners()) { - listener.alphaTypeChanged(alphaType); - } - } - - /** - * Notify all listeners about changed {@link #editType}. - */ - private void fireEditTypeChanged() { - for (final MapViewSettingsListener listener : listenerList.getListeners()) { - listener.editTypeChanged(editType); - } - } - - /** - * Notify all listeners about changed {@link #autojoin}. - */ - private void fireAutojoinChanged() { - for (final MapViewSettingsListener listener : listenerList.getListeners()) { - listener.autojoinChanged(autojoin); - } - } - - /** * Get the visibility of the grid. * @return visibility of the grid (<code>true</code> for visible, * <code>false</code> for invisible) */ - public boolean isGridVisible() { - return gridVisible; - } + boolean isGridVisible(); /** * Set the visibility of the grid. * @param gridVisible new visibility of the grid (<code>true</code> for * making the grid visible, <code>false</code> for invisible) */ - public void setGridVisible(final boolean gridVisible) { - if (this.gridVisible == gridVisible) { - return; - } + void setGridVisible(boolean gridVisible); - this.gridVisible = gridVisible; - fireGridVisibleChanged(); - } - /** * Returns the smoothing setting. * @return the smoothing setting */ - public boolean isSmoothing() { - return smoothing; - } + boolean isSmoothing(); /** * Sets the smoothing setting. * @param smoothing the new smoothing setting */ - public void setSmoothing(final boolean smoothing) { - if (this.smoothing == smoothing) { - return; - } + void setSmoothing(boolean smoothing); - this.smoothing = smoothing; - fireSmoothingChanged(); - } - /** * Get whether double faces are drawn double height. * @return <code>true</code> if double faces are drawn double height, * otherwise <code>false</code> */ - public boolean isDoubleFaces() { - return doubleFaces; - } + boolean isDoubleFaces(); /** * Sets whether double faces should be drawn double height. * @param doubleFaces whether double faces should be drawn double height */ - public void setDoubleFaces(final boolean doubleFaces) { - if (this.doubleFaces == doubleFaces) { - return; - } + void setDoubleFaces(final boolean doubleFaces); - this.doubleFaces = doubleFaces; - fireDoubleFacesChanged(); - } - /** * Returns whether the specified edit type is to be shown transparent. * @param v edit type to check * @return <code>true</code> if to be displayed transparent, otherwise * <code>false</code> */ - public boolean isAlphaType(final int v) { - return v > 0 && (alphaType & v) == v; - } + boolean isAlphaType(int v); /** * Sets whether the specified edit type is to be shown transparent. @@ -250,69 +94,33 @@ * @param state state, <code>true</code> to make edit type <code>v</code> * transparent, <code>false</code> for opaque */ - public void setAlphaType(final int v, final boolean state) { - if (state) { - alphaType |= v; - } else { - alphaType &= ~v; - } - fireAlphaTypeChanged(); - } + void setAlphaType(int v, boolean state); /** * Clear the transparency. */ - public void clearAlpha() { - alphaType = 0; - fireAlphaTypeChanged(); - } + void clearAlpha(); /** * Returns the currently set edit type. * @return the currently set edit type. */ - public int getEditType() { - return editType; - } + int getEditType(); /** - * Set the map view to show squares of the given type. (If no edit type is - * set, everything is displayed) - * @param editType edit type bitmask of types to show - */ - private void setEditType(final int editType) { - if ((this.editType & editType) == editType) { - return; - } - - this.editType |= editType; - fireEditTypeChanged(); - } - - /** * Set the map view to hide squares of the given type. (If no edit type is * set, everything is displayed) * @param editType edit type bitmask of types to hide */ - public void unsetEditType(final int editType) { - if ((this.editType & editType) == 0) { - return; - } + void unsetEditType(int editType); - this.editType &= ~editType; - fireEditTypeChanged(); - } - /** * Get information on the current state of edit type. Are squares of type * 'editType' displayed? * @param editType are squares of this type displayed? * @return <code>true</code> if these squares are currently displayed */ - public boolean isEditType(final int editType) { - final int mask = editType == 0 ? GUIConstants.EDIT_TYPE_NONE : editType; - return (this.editType & mask) != 0; - } + boolean isEditType(int editType); /** * Get information whether the gameObject is edited. Are squares of type 'v' @@ -320,9 +128,7 @@ * @param gameObject are squares of this type displayed? * @return true if these squares are currently displayed */ - public boolean isEditType(@NotNull final BaseObject<?, ?, ?, ?> gameObject) { - return editType == 0 || isEditType(gameObject.getEditType()); - } + boolean isEditType(@NotNull BaseObject<?, ?, ?, ?> gameObject); /** * Returns whether a editType value is set so that not all squares are @@ -330,42 +136,24 @@ * @return <code>true</code> if a editType value is set, otherwise * <code>false</code>. */ - public boolean isEditTypeSet() { - return (editType & GUIConstants.EDIT_TYPE_NONE) == 0 && editType != 0; - } + boolean isEditTypeSet(); /** * Toggle an edit type. * @param editType the edit type to toggle */ - public void toggleEditType(final int editType) { - if (isEditType(editType)) { - unsetEditType(editType); - } else { - setEditType(editType); - } - } + void toggleEditType(int editType); /** * Returns whether "autojoin" is enabled. * @return the autojoin state */ - public boolean isAutojoin() { - return autojoin; - } + boolean isAutojoin(); /** * Sets the "autojoin" state. * @param autojoin if set, enable autojoining */ - public void setAutojoin(final boolean autojoin) { - if (this.autojoin == autojoin) { - return; - } + void setAutojoin(boolean autojoin); - this.autojoin = autojoin; - preferences.putBoolean(AUTOJOIN_KEY, autojoin); - fireAutojoinChanged(); - } - } // class MapViewSettings Modified: trunk/src/test/net/sf/gridarta/gui/map/test/TestMapControlCreator.java =================================================================== --- trunk/src/test/net/sf/gridarta/gui/map/test/TestMapControlCreator.java 2010-06-07 07:41:06 UTC (rev 8261) +++ trunk/src/test/net/sf/gridarta/gui/map/test/TestMapControlCreator.java 2010-06-07 18:30:34 UTC (rev 8262) @@ -77,6 +77,7 @@ import net.sf.gridarta.model.map.mapmodel.MapSquare; import net.sf.gridarta.model.map.mapmodel.TopmostInsertionMode; import net.sf.gridarta.model.mapviewsettings.MapViewSettings; +import net.sf.gridarta.model.mapviewsettings.TestMapViewSettings; import net.sf.gridarta.model.match.GameObjectMatcher; import net.sf.gridarta.model.match.GameObjectMatchers; import net.sf.gridarta.model.match.TypeNrsGameObjectMatcher; @@ -233,7 +234,7 @@ archetypeSet = new TestArchetypeSet(archetypeFactory, "archetypes", faceObjectProviders); final MapReaderFactory<TestGameObject, TestMapArchObject> mapReaderFactory = new TestMapReaderFactory(); globalSettings = new TestGlobalSettings(); - mapViewSettings = new MapViewSettings(); + mapViewSettings = new TestMapViewSettings(); final MapWriter<TestGameObject, TestMapArchObject, TestArchetype> mapWriter = new TestMapWriter(); final AutojoinLists<TestGameObject, TestMapArchObject, TestArchetype> autojoinLists = new AutojoinLists<TestGameObject, TestMapArchObject, TestArchetype>(mapViewSettings); final ArchetypeChooserModel<TestGameObject, TestMapArchObject, TestArchetype> archetypeChooserModel = new ArchetypeChooserModel<TestGameObject, TestMapArchObject, TestArchetype>(); Modified: trunk/src/test/net/sf/gridarta/model/map/mapmodel/DefaultMapModelTest.java =================================================================== --- trunk/src/test/net/sf/gridarta/model/map/mapmodel/DefaultMapModelTest.java 2010-06-07 07:41:06 UTC (rev 8261) +++ trunk/src/test/net/sf/gridarta/model/map/mapmodel/DefaultMapModelTest.java 2010-06-07 18:30:34 UTC (rev 8262) @@ -45,6 +45,7 @@ import net.sf.gridarta.model.map.maparchobject.TestMapArchObject; import net.sf.gridarta.model.map.validation.ErrorCollector; import net.sf.gridarta.model.mapviewsettings.MapViewSettings; +import net.sf.gridarta.model.mapviewsettings.TestMapViewSettings; import net.sf.gridarta.model.match.GameObjectMatchers; import net.sf.gridarta.model.match.TypeNrsGameObjectMatcher; import net.sf.gridarta.utils.GUIUtils; @@ -425,7 +426,7 @@ final TestMapArchObject mapArchObject = new TestMapArchObject(); final ArchetypeChooserModel<TestGameObject, TestMapArchObject, TestArchetype> archetypeChooserModel = new ArchetypeChooserModel<TestGameObject, TestMapArchObject, TestArchetype>(); final FaceObjectProviders faceObjectProviders = newFaceObjectProviders(); - final MapViewSettings mapViewSettings = new MapViewSettings(); + final MapViewSettings mapViewSettings = new TestMapViewSettings(); final AutojoinLists<TestGameObject, TestMapArchObject, TestArchetype> autojoinLists = new AutojoinLists<TestGameObject, TestMapArchObject, TestArchetype>(mapViewSettings); animationObjects = new DefaultAnimationObjects("anim"); final GameObjectFactory<TestGameObject, TestMapArchObject, TestArchetype> gameObjectFactory = new TestGameObjectFactory(faceObjectProviders, animationObjects); Added: trunk/src/test/net/sf/gridarta/model/mapviewsettings/TestMapViewSettings.java =================================================================== --- trunk/src/test/net/sf/gridarta/model/mapviewsettings/TestMapViewSettings.java (rev 0) +++ trunk/src/test/net/sf/gridarta/model/mapviewsettings/TestMapViewSettings.java 2010-06-07 18:30:34 UTC (rev 8262) @@ -0,0 +1,45 @@ +/* + * 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.mapviewsettings; + +/** + * A {@link MapViewSettings} implementation for regression tests. The attribute + * values are not retained. + * @author Andreas Kirschbaum + */ +public class TestMapViewSettings extends AbstractMapViewSettings { + + /** + * {@inheritDoc} + */ + @Override + protected boolean loadAutojoin() { + return false; + } + + /** + * {@inheritDoc} + */ + @Override + protected void saveAutojoin(final boolean autojoin) { + // ignore + } + +} // class TestMapViewSettings Property changes on: trunk/src/test/net/sf/gridarta/model/mapviewsettings/TestMapViewSettings.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...> - 2010-06-23 17:43:57
|
Revision: 8410 http://gridarta.svn.sourceforge.net/gridarta/?rev=8410&view=rev Author: akirschbaum Date: 2010-06-23 17:43:50 +0000 (Wed, 23 Jun 2010) Log Message: ----------- Make CopyBufferTest work in headless mode. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/gui/bookmarks/BookmarkActions.java trunk/src/app/net/sf/gridarta/gui/map/mapactions/MapActions.java trunk/src/app/net/sf/gridarta/gui/map/mapview/DefaultMapViewFactory.java trunk/src/app/net/sf/gridarta/gui/map/mapview/MapView.java trunk/src/app/net/sf/gridarta/gui/map/mapview/MapViewBasic.java trunk/src/app/net/sf/gridarta/gui/map/mapview/MapViews.java trunk/src/app/net/sf/gridarta/gui/mapdesktop/MapDesktop.java trunk/src/app/net/sf/gridarta/gui/mapdesktop/WindowAction.java trunk/src/app/net/sf/gridarta/gui/pickmapchooser/PickmapChooserView.java trunk/src/test/net/sf/gridarta/gui/copybuffer/CopyBufferTest.java trunk/src/test/net/sf/gridarta/gui/map/mapview/TestMapViewFactory.java trunk/src/test/net/sf/gridarta/gui/map/test/TestMapControlCreator.java trunk/src/test/net/sf/gridarta/gui/selectedsquare/SelectedSquareActionsTest.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/gui/map/mapview/AbstractMapViewBasic.java trunk/src/app/net/sf/gridarta/gui/map/mapview/DefaultMapView.java trunk/src/app/net/sf/gridarta/gui/map/mapview/DefaultMapViewBasic.java trunk/src/test/net/sf/gridarta/gui/map/mapview/TestMapView.java trunk/src/test/net/sf/gridarta/gui/map/mapview/TestMapViewBasic.java Modified: trunk/src/app/net/sf/gridarta/gui/bookmarks/BookmarkActions.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/bookmarks/BookmarkActions.java 2010-06-23 16:21:32 UTC (rev 8409) +++ trunk/src/app/net/sf/gridarta/gui/bookmarks/BookmarkActions.java 2010-06-23 17:43:50 UTC (rev 8410) @@ -184,8 +184,8 @@ if (performAction) { final A mapArchObject = mapModel.getMapArchObject(); - final EditBookmarkDialog<G, A, R> editBookmarkDialog = new EditBookmarkDialog<G, A, R>(mapView, mapArchObject.getMapName()); - if (editBookmarkDialog.showDialog(mapView)) { + final EditBookmarkDialog<G, A, R> editBookmarkDialog = new EditBookmarkDialog<G, A, R>(mapView.getInternalFrame(), mapArchObject.getMapName()); + if (editBookmarkDialog.showDialog(mapView.getInternalFrame())) { bookmarksMapMenuManager.addRecent(mapModel, editBookmarkDialog.getDescription()); } } Modified: trunk/src/app/net/sf/gridarta/gui/map/mapactions/MapActions.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/mapactions/MapActions.java 2010-06-23 16:21:32 UTC (rev 8409) +++ trunk/src/app/net/sf/gridarta/gui/map/mapactions/MapActions.java 2010-06-23 17:43:50 UTC (rev 8410) @@ -735,7 +735,7 @@ if (destinationPoint != null) { showLocation(newMapView, destinationPoint); } else { - newMapView.getMapViewBasic().getViewport().setViewPosition(calculateNewViewPosition(currentMapView.getMapViewBasic(), newMapView.getMapViewBasic(), direction)); + newMapView.getMapViewBasic().getScrollPane().getViewport().setViewPosition(calculateNewViewPosition(currentMapView.getMapViewBasic().getScrollPane(), newMapView.getMapViewBasic().getScrollPane(), direction)); } if (ACTION_BUILDER.showOnetimeConfirmDialog(parent, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, "enterExitClose") == JOptionPane.YES_OPTION) { @@ -923,7 +923,7 @@ } if (performAction) { - mapViewsManager.newMapView(mapView.getMapControl(), mapView.getMapViewBasic().getViewport().getViewPosition()); + mapViewsManager.newMapView(mapView.getMapControl(), mapView.getMapViewBasic().getScrollPane().getViewport().getViewPosition()); } return true; Added: trunk/src/app/net/sf/gridarta/gui/map/mapview/AbstractMapViewBasic.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/mapview/AbstractMapViewBasic.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gui/map/mapview/AbstractMapViewBasic.java 2010-06-23 17:43:50 UTC (rev 8410) @@ -0,0 +1,130 @@ +/* + * 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.gui.map.mapview; + +import java.awt.Point; +import java.awt.Rectangle; +import java.util.ArrayList; +import java.util.List; +import net.sf.gridarta.model.archetype.Archetype; +import net.sf.gridarta.model.gameobject.GameObject; +import net.sf.gridarta.model.map.grid.MapGrid; +import net.sf.gridarta.model.map.maparchobject.MapArchObject; +import net.sf.gridarta.model.map.mapmodel.MapModel; +import net.sf.gridarta.model.map.mapmodel.MapSquare; +import net.sf.gridarta.model.mapcursor.MapCursor; +import org.jetbrains.annotations.NotNull; + +/** + * Abstract base class for {@link MapViewBasic} implementations. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @author Andreas Kirschbaum + */ +public abstract class AbstractMapViewBasic<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements MapViewBasic<G, A, R> { + + /** + * The {@link MapModel} to display. + */ + @NotNull + private final MapModel<G, A, R> mapModel; + + /** + * The {@link MapGrid} of this view. + */ + @NotNull + private final MapGrid mapGrid; + + /** + * The {@link MapCursor} of this view. + */ + @NotNull + private final MapCursor mapCursor; + + /** + * Creates a new instance. + * @param mapModel the map model to use + */ + protected AbstractMapViewBasic(@NotNull final MapModel<G, A, R> mapModel) { + this.mapModel = mapModel; + mapGrid = new MapGrid(this.mapModel.getMapArchObject().getMapSize()); + mapCursor = new MapCursor(mapGrid); + } + + /** + * {@inheritDoc} + */ + @NotNull + @Override + public MapGrid getMapGrid() { + return mapGrid; + } + + /** + * {@inheritDoc} + */ + @NotNull + @Override + public MapCursor getMapCursor() { + return mapCursor; + } + + /** + * {@inheritDoc} + */ + @NotNull + @Override + public Point[] getSelection() { + final List<Point> selection = new ArrayList<Point>(); + final Point pos = new Point(); + final Rectangle selectedRec = mapGrid.getSelectedRec(); + if (selectedRec != null) { + for (pos.x = selectedRec.x; pos.x < selectedRec.x + selectedRec.width; pos.x++) { + for (pos.y = selectedRec.y; pos.y < selectedRec.y + selectedRec.height; pos.y++) { + if ((mapGrid.getFlags(pos) & MapGrid.GRID_FLAG_SELECTION) > 0) { + selection.add((Point) pos.clone()); + } + } + } + } + return selection.toArray(new Point[selection.size()]); + } + + /** + * {@inheritDoc} + */ + @NotNull + @Override + public List<MapSquare<G, A, R>> getSelectedSquares() { + final List<MapSquare<G, A, R>> selection = new ArrayList<MapSquare<G, A, R>>(); + final Point pos = new Point(); + final Rectangle selectedRec = mapGrid.getSelectedRec(); + if (selectedRec != null) { + for (pos.x = selectedRec.x; pos.x < selectedRec.x + selectedRec.width; pos.x++) { + for (pos.y = selectedRec.y; pos.y < selectedRec.y + selectedRec.height; pos.y++) { + if ((mapGrid.getFlags(pos) & MapGrid.GRID_FLAG_SELECTION) > 0) { + selection.add(mapModel.getMapSquare(pos)); + } + } + } + } + return selection; + } + +} // class AbstractMapViewBasic Property changes on: trunk/src/app/net/sf/gridarta/gui/map/mapview/AbstractMapViewBasic.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Copied: trunk/src/app/net/sf/gridarta/gui/map/mapview/DefaultMapView.java (from rev 8409, trunk/src/app/net/sf/gridarta/gui/map/mapview/MapView.java) =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/mapview/DefaultMapView.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gui/map/mapview/DefaultMapView.java 2010-06-23 17:43:50 UTC (rev 8410) @@ -0,0 +1,325 @@ +/* + * 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.gui.map.mapview; + +import java.awt.BorderLayout; +import java.awt.Component; +import java.beans.PropertyVetoException; +import java.io.File; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Set; +import javax.swing.JInternalFrame; +import net.sf.gridarta.gui.utils.MenuUtils; +import net.sf.gridarta.model.archetype.Archetype; +import net.sf.gridarta.model.gameobject.GameObject; +import net.sf.gridarta.model.io.PathManager; +import net.sf.gridarta.model.map.maparchobject.MapArchObject; +import net.sf.gridarta.model.map.maparchobject.MapArchObjectListener; +import net.sf.gridarta.model.map.mapcontrol.DefaultMapControl; +import net.sf.gridarta.model.map.mapcontrol.MapControl; +import net.sf.gridarta.model.map.mapcontrol.MapControlListener; +import net.sf.gridarta.model.map.mapmodel.MapModel; +import net.sf.gridarta.model.map.mapmodel.MapModelListener; +import net.sf.gridarta.model.map.mapmodel.MapSquare; +import net.sf.gridarta.model.map.validation.ErrorCollector; +import net.sf.gridarta.utils.RandomUtils; +import net.sf.gridarta.utils.Size2D; +import org.apache.log4j.Category; +import org.apache.log4j.Logger; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Default {@link MapView} implementation. + * @author Andreas Kirschbaum + */ +public class DefaultMapView<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends JInternalFrame implements MapView<G, A, R> { + + /** + * The Logger for printing log messages. + */ + private static final Category log = Logger.getLogger(DefaultMapView.class); + + /** + * The serial version UID. + */ + private static final long serialVersionUID = 1L; + + /** + * The controller of this view. + */ + @NotNull + private final MapControl<G, A, R> mapControl; + + /** + * View number. + */ + private final int number; + + /** + * The underlying map view object. + */ + @NotNull + private final MapViewBasic<G, A, R> mapViewBasic; + + /** + * The {@link PathManager} for converting path names. + */ + @NotNull + private final PathManager pathManager; + + /** + * The {@link MapModelListener} used to detect changes in the map model that + * should be reflected in the window title. + */ + private final MapModelListener<G, A, R> mapModelListener = new MapModelListener<G, A, R>() { + + /** {@inheritDoc} */ + @Override + public void mapSizeChanged(@NotNull final MapModel<G, A, R> mapModel, @NotNull final Size2D newSize) { + // ignore + } + + /** {@inheritDoc} */ + @Override + public void mapSquaresChanged(@NotNull final Set<MapSquare<G, A, R>> mapSquares) { + // ignore + } + + /** {@inheritDoc} */ + @Override + public void mapObjectsChanged(@NotNull final Set<G> gameObjects, @NotNull final Set<G> transientGameObjects) { + // ignore + } + + /** {@inheritDoc} */ + @Override + public void errorsChanged(@NotNull final ErrorCollector<G, A, R> errors) { + // ignore + } + + /** {@inheritDoc} */ + @Override + public void mapFileChanged(@Nullable final File oldMapFile) { + updateTitle(); + } + + /** {@inheritDoc} */ + @Override + public void modifiedChanged(@NotNull final MapModel<G, A, R> mapModel) { + updateTitle(); + } + + }; + + /** + * The {@link MapArchObjectListener} used to detect changes in the map model + * that should be reflected in the window title. + */ + private final MapArchObjectListener mapArchObjectListener = new MapArchObjectListener() { + + /** {@inheritDoc} */ + @Override + public void mapMetaChanged() { + updateTitle(); + } + + /** + * {@inheritDoc} + */ + @Override + public void mapSizeChanged(@NotNull final Size2D mapSize) { + // ignore + } + + }; + + /** + * The {@link MapControlListener} used to detect changes in the map control + * that should be reflected in the window title. + */ + private final MapControlListener<G, A, R> mapControlListener = new MapControlListener<G, A, R>() { + + /** {@inheritDoc} */ + @Override + public void saved(@NotNull final DefaultMapControl<G, A, R> mapControl) { + updateTitle(); + } + + }; + + /** + * Create a new instance. + * @param mapControl the controller of this view + * @param number Each view of a map will get a number + * @param mapViewBasic The underlying map view object. <code>null</code> + * @param pathManager the path manager for converting path names + */ + public DefaultMapView(@NotNull final MapControl<G, A, R> mapControl, final int number, @NotNull final MapViewBasic<G, A, R> mapViewBasic, @NotNull final PathManager pathManager) { + super(getWindowTitle(mapControl, number, pathManager), true, true, true, true); + this.mapControl = mapControl; + this.number = number; + this.mapViewBasic = mapViewBasic; + this.pathManager = pathManager; + final MapModel<G, A, R> mapModel = mapControl.getMapModel(); + mapModel.addMapModelListener(mapModelListener); + mapModel.getMapArchObject().addMapArchObjectListener(mapArchObjectListener); + mapControl.addMapControlListener(mapControlListener); + getContentPane().setLayout(new BorderLayout()); + getContentPane().add(mapViewBasic.getScrollPane(), BorderLayout.CENTER); + setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); + setAutoscrolls(true); + } + + /** + * {@inheritDoc} + */ + @Override + public void closeNotify() { + getContentPane().remove(mapViewBasic.getScrollPane()); + mapViewBasic.closeNotify(); + mapControl.removeMapControlListener(mapControlListener); + final MapModel<G, A, R> mapModel = mapControl.getMapModel(); + mapModel.getMapArchObject().removeMapArchObjectListener(mapArchObjectListener); + mapModel.removeMapModelListener(mapModelListener); + //mapFileActions.closeNotify(); + MenuUtils.disposeMenuElement(getJMenuBar()); + } + + /** + * {@inheritDoc} + */ + @Nullable + @Override + public G getSelectedGameObject() { + final List<G> objects = getSelectedGameObjects(); + final int objectSize = objects.size(); + if (objectSize == 0) { + return null; + } + if (objectSize == 1) { + return objects.get(0); + } + return objects.get(RandomUtils.rnd.nextInt(objects.size())); + } + + /** + * {@inheritDoc} + */ + @NotNull + @Override + public List<G> getSelectedGameObjects() { + final Collection<MapSquare<G, A, R>> selectedMapSquares = mapViewBasic.getSelectedSquares(); + if (selectedMapSquares.isEmpty()) { + return mapControl.getMapModel().getAllGameObjects(); + } + + final List<G> objects = new ArrayList<G>(); + for (final Iterable<G> mapSquare : selectedMapSquares) { + for (final GameObject<G, A, R> gameObject : mapSquare) { + objects.add(gameObject.getHead()); + } + } + return objects; + } + + /** + * Update the Map-Window Title (according to name and changeFlag). + */ + private void updateTitle() { + setTitle(getWindowTitle()); + } + + /** + * {@inheritDoc} + */ + @NotNull + @Override + public String getWindowTitle() { + return getWindowTitle(mapControl, number, pathManager); + } + + /** + * Returns the title for the map window. + * @param mapControl the map control to use + * @param number the view number + * @param pathManager the path manager for converting path names + * @return the title + */ + @NotNull + private static String getWindowTitle(@NotNull final MapControl<?, ?, ?> mapControl, final int number, @NotNull final PathManager pathManager) { + final File mapFile = mapControl.getMapModel().getMapFile(); + return (mapFile == null ? "<unsaved>" : pathManager.getMapPath(mapFile)) + " [ " + mapControl.getMapModel().getMapArchObject().getMapName() + " ] (" + number + ")" + (mapControl.getMapModel().isModified() ? " *" : ""); + } + + /** + * {@inheritDoc} + */ + @NotNull + @Override + public Component getComponent() { + return this; + } + + /** + * {@inheritDoc} + */ + @NotNull + @Override + public MapControl<G, A, R> getMapControl() { + return mapControl; + } + + /** + * {@inheritDoc} + */ + @NotNull + @Override + public MapViewBasic<G, A, R> getMapViewBasic() { + return mapViewBasic; + } + + /** + * {@inheritDoc} + */ + @Override + public void activate() { + try { + setSelected(true); + } catch (final PropertyVetoException e) { + log.warn("Unexpected exception", e); + } + setVisible(true); + requestFocus(); + restoreSubcomponentFocus(); + } + + /** + * {@inheritDoc} + */ + @NotNull + @Override + public JInternalFrame getInternalFrame() { + return this; + } + +} // class MapView Copied: trunk/src/app/net/sf/gridarta/gui/map/mapview/DefaultMapViewBasic.java (from rev 8409, trunk/src/app/net/sf/gridarta/gui/map/mapview/MapViewBasic.java) =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/mapview/DefaultMapViewBasic.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gui/map/mapview/DefaultMapViewBasic.java 2010-06-23 17:43:50 UTC (rev 8410) @@ -0,0 +1,244 @@ +/* + * 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.gui.map.mapview; + +import java.awt.Point; +import java.awt.Rectangle; +import java.io.File; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import javax.swing.JScrollPane; +import javax.swing.JViewport; +import javax.swing.ScrollPaneConstants; +import net.sf.gridarta.gui.map.renderer.AbstractMapRenderer; +import net.sf.gridarta.gui.map.renderer.MapRenderer; +import net.sf.gridarta.gui.map.renderer.RendererFactory; +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.map.grid.MapGrid; +import net.sf.gridarta.model.map.maparchobject.MapArchObject; +import net.sf.gridarta.model.map.mapmodel.MapModel; +import net.sf.gridarta.model.map.mapmodel.MapModelListener; +import net.sf.gridarta.model.map.mapmodel.MapSquare; +import net.sf.gridarta.model.map.validation.ErrorCollector; +import net.sf.gridarta.model.map.validation.errors.ValidationError; +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 net.sf.gridarta.utils.Size2D; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Default {@link MapViewBasic} implementation. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @author Andreas Kirschbaum + */ +public class DefaultMapViewBasic<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractMapViewBasic<G, A, R> { + + /** + * The {@link MapModel} to display. + */ + @NotNull + private final MapModel<G, A, R> mapModel; + + /** + * The erroneous {@link MapSquare}s. + */ + @NotNull + private final Map<MapSquare<G, A, R>, ValidationError<G, A, R>> erroneousMapSquares = new HashMap<MapSquare<G, A, R>, ValidationError<G, A, R>>(); + + /** + * The {@link AbstractMapRenderer} for rendering {@link #mapModel}. + */ + @NotNull + private final AbstractMapRenderer<G, A, R> renderer; + + /** + * The {@link JScrollPane} for this instance. + */ + @NotNull + private final JScrollPane scrollPane; + + /** + * The {@link MapCursorListener} attached to {@link #mapCursor}. + */ + @NotNull + private final MapCursorListener mapCursorListener = new MapCursorListener() { + + /** {@inheritDoc} */ + @Override + public void mapCursorChangedPos(@NotNull final MapCursorEvent e) { + final MapCursor mapCursor = e.getSource(); + final Point cursorLocation = mapCursor.getLocation(); + if (cursorLocation != null) { + final Rectangle rectangle = renderer.getSquareBounds(cursorLocation); + renderer.scrollRectToVisible(rectangle); + } + } + + /** {@inheritDoc} */ + @Override + public void mapCursorChangedMode(@NotNull final MapCursorEvent e) { + // Ignore mode change events + } + + }; + + /** + * The {@link MapModelListener} attached to {@link #mapModel}. + */ + @NotNull + private final MapModelListener<G, A, R> mapModelListener = new MapModelListener<G, A, R>() { + + /** {@inheritDoc} */ + @Override + public void mapSizeChanged(@NotNull final MapModel<G, A, R> mapModel, @NotNull final Size2D newSize) { + getMapGrid().resize(newSize); + } + + /** {@inheritDoc} */ + @Override + public void mapSquaresChanged(@NotNull final Set<MapSquare<G, A, R>> mapSquares) { + // ignore + } + + /** {@inheritDoc} */ + @Override + public void mapObjectsChanged(@NotNull final Set<G> gameObjects, @NotNull final Set<G> transientGameObjects) { + // ignore + } + + /** {@inheritDoc} */ + @Override + public void errorsChanged(@NotNull final ErrorCollector<G, A, R> errors) { + DefaultMapViewBasic.this.errorsChanged(errors); + } + + /** {@inheritDoc} */ + @Override + public void mapFileChanged(@Nullable final File oldMapFile) { + // ignore + } + + /** {@inheritDoc} */ + @Override + public void modifiedChanged(@NotNull final MapModel<G, A, R> mapModel) { + // ignore + } + + }; + + /** + * Creates a new instance. + * @param mapModel the map model to use + * @param isPickmap whether the map model belongs to a pickmap + * @param initial the initial view position to show; null=show top left + * corner + * @param xScrollDistance the x distance when scrolling + * @param yScrollDistance the y distance when scrolling + * @param rendererFactory the renderer factory to use + */ + public DefaultMapViewBasic(@NotNull final MapModel<G, A, R> mapModel, final boolean isPickmap, @Nullable final Point initial, final int xScrollDistance, final int yScrollDistance, @NotNull final RendererFactory<G, A, R> rendererFactory) { + super(mapModel); + this.mapModel = mapModel; + scrollPane = new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); + if (isPickmap) { + scrollPane.setBackground(CommonConstants.BG_COLOR); + } + + // set the pixel increment scrolling for clicking once on a scroll bar arrow + scrollPane.getVerticalScrollBar().setUnitIncrement(yScrollDistance); + scrollPane.getHorizontalScrollBar().setUnitIncrement(xScrollDistance); + + scrollPane.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE); + getMapCursor().addMapCursorListener(mapCursorListener); + + renderer = isPickmap ? rendererFactory.newPickmapRenderer(mapModel, getMapGrid()) : rendererFactory.newMapRenderer(mapModel, getMapGrid()); + scrollPane.setViewportView(renderer); + if (initial != null) { + scrollPane.getViewport().setViewPosition(initial); + } + + mapModel.addMapModelListener(mapModelListener); + + renderer.setErroneousMapSquares(erroneousMapSquares); + renderer.setFocusable(true); + scrollPane.setFocusable(true); + } + + /** + * {@inheritDoc} + */ + @Override + public void closeNotify() { + renderer.closeNotify(); + getMapCursor().removeMapCursorListener(mapCursorListener); + scrollPane.setViewportView(null); + mapModel.removeMapModelListener(mapModelListener); + } + + /** + * {@inheritDoc} + */ + @NotNull + @Override + public MapRenderer getRenderer() { + return renderer; + } + + /** + * {@inheritDoc} + */ + @NotNull + @Override + public JScrollPane getScrollPane() { + return scrollPane; + } + + /** + * Updates the erroneous map squares. + * @param errors the errors to display + */ + private void errorsChanged(@NotNull final ErrorCollector<G, A, R> errors) { + erroneousMapSquares.clear(); + final MapGrid mapGrid = getMapGrid(); + mapGrid.beginTransaction(); + try { + mapGrid.clearErrors(); + for (final ValidationError<G, A, R> validationError : errors.getErrors()) { + for (final MapSquare<G, A, R> mapSquare : validationError.getMapSquares()) { + erroneousMapSquares.put(mapSquare, validationError); + mapGrid.setError(mapSquare.getMapX(), mapSquare.getMapY()); + } + for (final G gameObject : validationError.getGameObjects()) { + final BaseObject<G, A, R, ?> topContainer = gameObject.getTopContainer(); + mapGrid.setError(topContainer.getMapX(), topContainer.getMapY()); + } + } + } finally { + mapGrid.endTransaction(); + } + } + +} // class DefaultMapViewBasic Modified: trunk/src/app/net/sf/gridarta/gui/map/mapview/DefaultMapViewFactory.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/mapview/DefaultMapViewFactory.java 2010-06-23 16:21:32 UTC (rev 8409) +++ trunk/src/app/net/sf/gridarta/gui/map/mapview/DefaultMapViewFactory.java 2010-06-23 17:43:50 UTC (rev 8410) @@ -84,8 +84,8 @@ @NotNull @Override public MapView<G, A, R> newMapView(@NotNull final MapControl<G, A, R> mapControl, @Nullable final Point viewPosition, final int viewCounter) { - final MapView<G, A, R> mapView = new MapView<G, A, R>(mapControl, viewCounter, new MapViewBasic<G, A, R>(mapControl.getMapModel(), mapControl.isPickmap(), viewPosition, xScrollDistance, yScrollDistance, rendererFactory), pathManager); - mapView.setJMenuBar(ACTION_BUILDER.createMenuBar(false, "mapwindow")); + final MapView<G, A, R> mapView = new DefaultMapView<G, A, R>(mapControl, viewCounter, new DefaultMapViewBasic<G, A, R>(mapControl.getMapModel(), mapControl.isPickmap(), viewPosition, xScrollDistance, yScrollDistance, rendererFactory), pathManager); + mapView.getInternalFrame().setJMenuBar(ACTION_BUILDER.createMenuBar(false, "mapwindow")); return mapView; } Modified: trunk/src/app/net/sf/gridarta/gui/map/mapview/MapView.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/mapview/MapView.java 2010-06-23 16:21:32 UTC (rev 8409) +++ trunk/src/app/net/sf/gridarta/gui/map/mapview/MapView.java 2010-06-23 17:43:50 UTC (rev 8410) @@ -19,32 +19,13 @@ package net.sf.gridarta.gui.map.mapview; -import java.awt.BorderLayout; import java.awt.Component; -import java.beans.PropertyVetoException; -import java.io.File; -import java.util.ArrayList; -import java.util.Collection; import java.util.List; -import java.util.Set; import javax.swing.JInternalFrame; -import net.sf.gridarta.gui.utils.MenuUtils; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.gameobject.GameObject; -import net.sf.gridarta.model.io.PathManager; import net.sf.gridarta.model.map.maparchobject.MapArchObject; -import net.sf.gridarta.model.map.maparchobject.MapArchObjectListener; -import net.sf.gridarta.model.map.mapcontrol.DefaultMapControl; import net.sf.gridarta.model.map.mapcontrol.MapControl; -import net.sf.gridarta.model.map.mapcontrol.MapControlListener; -import net.sf.gridarta.model.map.mapmodel.MapModel; -import net.sf.gridarta.model.map.mapmodel.MapModelListener; -import net.sf.gridarta.model.map.mapmodel.MapSquare; -import net.sf.gridarta.model.map.validation.ErrorCollector; -import net.sf.gridarta.utils.RandomUtils; -import net.sf.gridarta.utils.Size2D; -import org.apache.log4j.Category; -import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -53,157 +34,12 @@ * control. * @author Andreas Kirschbaum */ -public class MapView<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends JInternalFrame { +public interface MapView<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> { /** - * The Logger for printing log messages. - */ - private static final Category log = Logger.getLogger(MapView.class); - - /** - * The serial version UID. - */ - private static final long serialVersionUID = 1L; - - /** - * The controller of this view. - */ - @NotNull - private final MapControl<G, A, R> mapControl; - - /** - * View number. - */ - private final int number; - - /** - * The underlying map view object. - */ - @NotNull - private final MapViewBasic<G, A, R> mapViewBasic; - - /** - * The {@link PathManager} for converting path names. - */ - @NotNull - private final PathManager pathManager; - - /** - * The {@link MapModelListener} used to detect changes in the map model that - * should be reflected in the window title. - */ - private final MapModelListener<G, A, R> mapModelListener = new MapModelListener<G, A, R>() { - - /** {@inheritDoc} */ - @Override - public void mapSizeChanged(@NotNull final MapModel<G, A, R> mapModel, @NotNull final Size2D newSize) { - // ignore - } - - /** {@inheritDoc} */ - @Override - public void mapSquaresChanged(@NotNull final Set<MapSquare<G, A, R>> mapSquares) { - // ignore - } - - /** {@inheritDoc} */ - @Override - public void mapObjectsChanged(@NotNull final Set<G> gameObjects, @NotNull final Set<G> transientGameObjects) { - // ignore - } - - /** {@inheritDoc} */ - @Override - public void errorsChanged(@NotNull final ErrorCollector<G, A, R> errors) { - // ignore - } - - /** {@inheritDoc} */ - @Override - public void mapFileChanged(@Nullable final File oldMapFile) { - updateTitle(); - } - - /** {@inheritDoc} */ - @Override - public void modifiedChanged(@NotNull final MapModel<G, A, R> mapModel) { - updateTitle(); - } - - }; - - /** - * The {@link MapArchObjectListener} used to detect changes in the map model - * that should be reflected in the window title. - */ - private final MapArchObjectListener mapArchObjectListener = new MapArchObjectListener() { - - /** {@inheritDoc} */ - @Override - public void mapMetaChanged() { - updateTitle(); - } - - /** - * {@inheritDoc} - */ - @Override - public void mapSizeChanged(@NotNull final Size2D mapSize) { - // ignore - } - - }; - - /** - * The {@link MapControlListener} used to detect changes in the map control - * that should be reflected in the window title. - */ - private final MapControlListener<G, A, R> mapControlListener = new MapControlListener<G, A, R>() { - - /** {@inheritDoc} */ - @Override - public void saved(@NotNull final DefaultMapControl<G, A, R> mapControl) { - updateTitle(); - } - - }; - - /** - * Create a new instance. - * @param mapControl the controller of this view - * @param number Each view of a map will get a number - * @param mapViewBasic The underlying map view object. <code>null</code> - * @param pathManager the path manager for converting path names - */ - public MapView(@NotNull final MapControl<G, A, R> mapControl, final int number, @NotNull final MapViewBasic<G, A, R> mapViewBasic, @NotNull final PathManager pathManager) { - super(getWindowTitle(mapControl, number, pathManager), true, true, true, true); - this.mapControl = mapControl; - this.number = number; - this.mapViewBasic = mapViewBasic; - this.pathManager = pathManager; - final MapModel<G, A, R> mapModel = mapControl.getMapModel(); - mapModel.addMapModelListener(mapModelListener); - mapModel.getMapArchObject().addMapArchObjectListener(mapArchObjectListener); - mapControl.addMapControlListener(mapControlListener); - getContentPane().setLayout(new BorderLayout()); - getContentPane().add(mapViewBasic, BorderLayout.CENTER); - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - setAutoscrolls(true); - } - - /** * This function must be called when the view is closed. */ - public void closeNotify() { - getContentPane().remove(mapViewBasic); - mapViewBasic.closeNotify(); - mapControl.removeMapControlListener(mapControlListener); - final MapModel<G, A, R> mapModel = mapControl.getMapModel(); - mapModel.getMapArchObject().removeMapArchObjectListener(mapArchObjectListener); - mapModel.removeMapModelListener(mapModelListener); - //mapFileActions.closeNotify(); - MenuUtils.disposeMenuElement(getJMenuBar()); - } + void closeNotify(); /** * Return one selected game object. If more than one game object is @@ -213,17 +49,7 @@ * object is selected. */ @Nullable - public G getSelectedGameObject() { - final List<G> objects = getSelectedGameObjects(); - final int objectSize = objects.size(); - if (objectSize == 0) { - return null; - } - if (objectSize == 1) { - return objects.get(0); - } - return objects.get(RandomUtils.rnd.nextInt(objects.size())); - } + G getSelectedGameObject(); /** * Return all selected game objects. If nothing is selected, return all game @@ -231,89 +57,47 @@ * @return The selected game objects. */ @NotNull - public List<G> getSelectedGameObjects() { - final Collection<MapSquare<G, A, R>> selectedMapSquares = mapViewBasic.getSelectedSquares(); - if (selectedMapSquares.isEmpty()) { - return mapControl.getMapModel().getAllGameObjects(); - } + List<G> getSelectedGameObjects(); - final List<G> objects = new ArrayList<G>(); - for (final Iterable<G> mapSquare : selectedMapSquares) { - for (final GameObject<G, A, R> gameObject : mapSquare) { - objects.add(gameObject.getHead()); - } - } - return objects; - } - /** - * Update the Map-Window Title (according to name and changeFlag). - */ - private void updateTitle() { - setTitle(getWindowTitle()); - } - - /** * Returns the title for the map window. * @return the title */ @NotNull - public String getWindowTitle() { - return getWindowTitle(mapControl, number, pathManager); - } + String getWindowTitle(); /** - * Returns the title for the map window. - * @param mapControl the map control to use - * @param number the view number - * @param pathManager the path manager for converting path names - * @return the title - */ - @NotNull - private static String getWindowTitle(@NotNull final MapControl<?, ?, ?> mapControl, final int number, @NotNull final PathManager pathManager) { - final File mapFile = mapControl.getMapModel().getMapFile(); - return (mapFile == null ? "<unsaved>" : pathManager.getMapPath(mapFile)) + " [ " + mapControl.getMapModel().getMapArchObject().getMapName() + " ] (" + number + ")" + (mapControl.getMapModel().isModified() ? " *" : ""); - } - - /** * Returns the component associated with this MapView that can be used as * parent for dialogs. * @return Component as parent for dialogs. */ - public Component getComponent() { - return this; - } + @NotNull + Component getComponent(); /** * Return the controller of this view. * @return the controller of this view */ @NotNull - public MapControl<G, A, R> getMapControl() { - return mapControl; - } + MapControl<G, A, R> getMapControl(); /** * Return the associated {@link MapViewBasic}. * @return the associated <code>MapViewBasic</code> */ @NotNull - public MapViewBasic<G, A, R> getMapViewBasic() { - return mapViewBasic; - } + MapViewBasic<G, A, R> getMapViewBasic(); /** * Activate this map view. */ - public void activate() { - try { - setSelected(true); - } catch (final PropertyVetoException e) { - log.warn("Unexpected exception", e); - } - setVisible(true); - requestFocus(); - restoreSubcomponentFocus(); - } + void activate(); -} // class MapView + /** + * Returns the {@link JInternalFrame} instance for this map view. + * @return the internal frame + */ + @NotNull + JInternalFrame getInternalFrame(); + +} // interface MapView Modified: trunk/src/app/net/sf/gridarta/gui/map/mapview/MapViewBasic.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/mapview/MapViewBasic.java 2010-06-23 16:21:32 UTC (rev 8409) +++ trunk/src/app/net/sf/gridarta/gui/map/mapview/MapViewBasic.java 2010-06-23 17:43:50 UTC (rev 8410) @@ -20,289 +20,70 @@ package net.sf.gridarta.gui.map.mapview; import java.awt.Point; -import java.awt.Rectangle; -import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; -import java.util.Set; import javax.swing.JScrollPane; -import javax.swing.JViewport; -import net.sf.gridarta.gui.map.renderer.AbstractMapRenderer; import net.sf.gridarta.gui.map.renderer.MapRenderer; -import net.sf.gridarta.gui.map.renderer.RendererFactory; 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.map.grid.MapGrid; import net.sf.gridarta.model.map.maparchobject.MapArchObject; -import net.sf.gridarta.model.map.mapmodel.MapModel; -import net.sf.gridarta.model.map.mapmodel.MapModelListener; import net.sf.gridarta.model.map.mapmodel.MapSquare; -import net.sf.gridarta.model.map.validation.ErrorCollector; -import net.sf.gridarta.model.map.validation.errors.ValidationError; 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 net.sf.gridarta.utils.Size2D; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; /** * MapViewBasic is a view for maps. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> * @author Andreas Kirschbaum - * @todo extending JScrollPane is not a good idea. */ -public class MapViewBasic<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends JScrollPane { +public interface MapViewBasic<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> { /** - * The serial version UID. - */ - private static final long serialVersionUID = 1L; - - /** - * The {@link MapModel} to display. - */ - @NotNull - private final MapModel<G, A, R> mapModel; - - /** - * The {@link MapGrid} of this view. - */ - @NotNull - private final MapGrid mapGrid; - - /** - * The {@link MapCursor} of this view. - */ - @NotNull - private final MapCursor mapCursor; - - /** - * The erroneous {@link MapSquare}s. - */ - @NotNull - private final Map<MapSquare<G, A, R>, ValidationError<G, A, R>> erroneousMapSquares = new HashMap<MapSquare<G, A, R>, ValidationError<G, A, R>>(); - - /** - * The {@link AbstractMapRenderer} for rendering {@link #mapModel}. - */ - @NotNull - private final AbstractMapRenderer<G, A, R> renderer; - - /** - * The {@link MapCursorListener} attached to {@link #mapCursor}. - */ - @NotNull - private final MapCursorListener mapCursorListener = new MapCursorListener() { - - /** {@inheritDoc} */ - @Override - public void mapCursorChangedPos(@NotNull final MapCursorEvent e) { - final MapCursor mapCursor = e.getSource(); - final Point cursorLocation = mapCursor.getLocation(); - if (cursorLocation != null) { - final Rectangle rectangle = renderer.getSquareBounds(cursorLocation); - renderer.scrollRectToVisible(rectangle); - } - } - - /** {@inheritDoc} */ - @Override - public void mapCursorChangedMode(@NotNull final MapCursorEvent e) { - // Ignore mode change events - } - - }; - - /** - * The {@link MapModelListener} attached to {@link #mapModel}. - */ - @NotNull - private final MapModelListener<G, A, R> mapModelListener = new MapModelListener<G, A, R>() { - - /** {@inheritDoc} */ - @Override - public void mapSizeChanged(@NotNull final MapModel<G, A, R> mapModel, @NotNull final Size2D newSize) { - getMapGrid().resize(newSize); - } - - /** {@inheritDoc} */ - @Override - public void mapSquaresChanged(@NotNull final Set<MapSquare<G, A, R>> mapSquares) { - // ignore - } - - /** {@inheritDoc} */ - @Override - public void mapObjectsChanged(@NotNull final Set<G> gameObjects, @NotNull final Set<G> transientGameObjects) { - // ignore - } - - /** {@inheritDoc} */ - @Override - public void errorsChanged(@NotNull final ErrorCollector<G, A, R> errors) { - MapViewBasic.this.errorsChanged(errors); - } - - /** {@inheritDoc} */ - @Override - public void mapFileChanged(@Nullable final File oldMapFile) { - // ignore - } - - /** {@inheritDoc} */ - @Override - public void modifiedChanged(@NotNull final MapModel<G, A, R> mapModel) { - // ignore - } - - }; - - /** - * Creates a new instance. - * @param mapModel the map model to use - * @param isPickmap whether the map model belongs to a pickmap - * @param initial the initial view position to show; null=show top left - * corner - * @param xScrollDistance the x distance when scrolling - * @param yScrollDistance the y distance when scrolling - * @param rendererFactory the renderer factory to use - */ - public MapViewBasic(@NotNull final MapModel<G, A, R> mapModel, final boolean isPickmap, @Nullable final Point initial, final int xScrollDistance, final int yScrollDistance, @NotNull final RendererFactory<G, A, R> rendererFactory) { - super(VERTICAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_AS_NEEDED); - this.mapModel = mapModel; - mapGrid = new MapGrid(this.mapModel.getMapArchObject().getMapSize()); - mapCursor = new MapCursor(mapGrid); - if (isPickmap) { - setBackground(CommonConstants.BG_COLOR); - } - - // set the pixel increment scrolling for clicking once on a scroll bar arrow - getVerticalScrollBar().setUnitIncrement(yScrollDistance); - getHorizontalScrollBar().setUnitIncrement(xScrollDistance); - - getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE); - mapCursor.addMapCursorListener(mapCursorListener); - - renderer = isPickmap ? rendererFactory.newPickmapRenderer(mapModel, mapGrid) : rendererFactory.newMapRenderer(mapModel, mapGrid); - setViewportView(renderer); - if (initial != null) { - getViewport().setViewPosition(initial); - } - - mapModel.addMapModelListener(mapModelListener); - - renderer.setErroneousMapSquares(erroneousMapSquares); - renderer.setFocusable(true); - setFocusable(true); - } - - /** * Returns the {@link MapGrid} of this view. * @return the map grid of this view */ @NotNull - public MapGrid getMapGrid() { - return mapGrid; - } + MapGrid getMapGrid(); /** * Returns the {@link MapCursor} of this view. * @return the map cursor of this view */ @NotNull - public MapCursor getMapCursor() { - return mapCursor; - } + MapCursor getMapCursor(); /** * Returns the selection. * @return the selection */ @NotNull - public Point[] getSelection() { - final List<Point> selection = new ArrayList<Point>(); - final Point pos = new Point(); - final Rectangle selectedRec = mapGrid.getSelectedRec(); - if (selectedRec != null) { - for (pos.x = selectedRec.x; pos.x < selectedRec.x + selectedRec.width; pos.x++) { - for (pos.y = selectedRec.y; pos.y < selectedRec.y + selectedRec.height; pos.y++) { - if ((mapGrid.getFlags(pos) & MapGrid.GRID_FLAG_SELECTION) > 0) { - selection.add((Point) pos.clone()); - } - } - } - } - return selection.toArray(new Point[selection.size()]); - } + Point[] getSelection(); /** * Returns the selected squares. * @return the selected squares; the list may be modified by the caller */ @NotNull - public List<MapSquare<G, A, R>> getSelectedSquares() { - final List<MapSquare<G, A, R>> selection = new ArrayList<MapSquare<G, A, R>>(); - final Point pos = new Point(); - final Rectangle selectedRec = mapGrid.getSelectedRec(); - if (selectedRec != null) { - for (pos.x = selectedRec.x; pos.x < selectedRec.x + selectedRec.width; pos.x++) { - for (pos.y = selectedRec.y; pos.y < selectedRec.y + selectedRec.height; pos.y++) { - if ((mapGrid.getFlags(pos) & MapGrid.GRID_FLAG_SELECTION) > 0) { - selection.add(mapModel.getMapSquare(pos)); - } - } - } - } - return selection; - } + List<MapSquare<G, A, R>> getSelectedSquares(); /** * Must be called when this renderer is not used anymore. It un-registers all * listeners. */ - public void closeNotify() { - renderer.closeNotify(); - mapCursor.removeMapCursorListener(mapCursorListener); - setViewportView(null); - mapModel.removeMapModelListener(mapModelListener); - } + void closeNotify(); /** * Returns the {@link MapRenderer} for this view. * @return the map renderer. */ @NotNull - public MapRenderer getRenderer() { - return renderer; - } + MapRenderer getRenderer(); /** - * Updates the erroneous map squares. - * @param errors the errors to display + * Returns the {@link JScrollPane} of this map view basic. + * @return the scroll pane */ - private void errorsChanged(@NotNull final ErrorCollector<G, A, R> errors) { - erroneousMapSquares.clear(); - mapGrid.beginTransaction(); - try { - mapGrid.clearErrors(); - for (final ValidationError<G, A, R> validationError : errors.getErrors()) { - for (final MapSquare<G, A, R> mapSquare : validationError.getMapSquares()) { - erroneousMapSquares.put(mapSquare, validationError); - mapGrid.setError(mapSquare.getMapX(), mapSquare.getMapY()); - } - for (final G gameObject : validationError.getGameObjects()) { - final BaseObject<G, A, R, ?> topContainer = gameObject.getTopContainer(); - mapGrid.setError(topContainer.getMapX(), topContainer.getMapY()); - } - } - } finally { - mapGrid.endTransaction(); - } - } + @NotNull + JScrollPane getScrollPane(); -} // class MapViewBasic +} // interface MapViewBasic Modified: trunk/src/app/net/sf/gridarta/gui/map/mapview/MapViews.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/mapview/MapViews.java 2010-06-23 16:21:32 UTC (rev 8409) +++ trunk/src/app/net/sf/gridarta/gui/map/mapview/MapViews.java 2010-06-23 17:43:50 UTC (rev 8410) @@ -123,7 +123,7 @@ public Point[] getViewPositions() { final Point[] result = new Point[mapViews.size()]; for (int i = 0; i < result.length; i++) { - result[i] = mapViews.get(i).getMapViewBasic().getViewport().getViewPosition(); + result[i] = mapViews.get(i).getMapViewBasic().getScrollPane().getViewport().getViewPosition(); } return result; } Modified: trunk/src/app/net/sf/gridarta/gui/mapdesktop/MapDesktop.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/mapdesktop/MapDesktop.java 2010-06-23 16:21:32 UTC (rev 8409) +++ trunk/src/app/net/sf/gridarta/gui/mapdesktop/MapDesktop.java 2010-06-23 17:43:50 UTC (rev 8410) @@ -27,6 +27,7 @@ import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JDesktopPane; +import javax.swing.JInternalFrame; import javax.swing.JMenu; import javax.swing.event.InternalFrameEvent; import javax.swing.event.InternalFrameListener; @@ -273,9 +274,10 @@ public void setCurrentMapView(@NotNull final MapView<G, A, R> mapView) { mapViewManager.setActiveMapView(mapView); // De-iconify if necessary - if (mapView.isIcon()) { + final JInternalFrame internalFrame = mapView.getInternalFrame(); + if (internalFrame.isIcon()) { try { - mapView.setIcon(false); + internalFrame.setIcon(false); } catch (final PropertyVetoException e) { log.warn(ACTION_BUILDER.format("logUnexpectedException", e)); } @@ -283,8 +285,8 @@ return; } updateFocus(true); - mapView.requestFocus(); - mapView.restoreSubcomponentFocus(); + internalFrame.requestFocus(); + internalFrame.restoreSubcomponentFocus(); } /** @@ -292,19 +294,20 @@ * @param mapView the map view to be removed (closed) */ private void removeMapView(@NotNull final MapView<G, A, R> mapView) { - mapView.removeInternalFrameListener(internalFrameListener); + final JInternalFrame internalFrame = mapView.getInternalFrame(); + internalFrame.removeInternalFrameListener(internalFrameListener); mapViewManager.removeMapView(mapView); if (windowActions.remove(mapView) == null) { assert false; } - remove(mapView); + remove(internalFrame); // This is important: Removing a JInternalFrame from a JDesktopPane doesn't deselect it. // Thus it will still be referenced. To prevent a closed map from being referenced by Swing, // we check whether it's selected and if so deselect it. if (getSelectedFrame() == mapView) { setSelectedFrame(null); } - mapView.dispose(); + internalFrame.dispose(); repaint(); updateFocus(true); @@ -320,14 +323,15 @@ windowActions.put(mapView, windowAction); updateFrameIcon(mapView); - mapView.addInternalFrameListener(internalFrameListener); - add(mapView); + final JInternalFrame internalFrame = mapView.getInternalFrame(); + internalFrame.addInternalFrameListener(internalFrameListener); + add(internalFrame); mapViewManager.addMapView(mapView); setCurrentMapView(mapView); - mapView.setVisible(true); - mapView.setBounds(0, 0, getWidth(), getHeight()); + internalFrame.setVisible(true); + internalFrame.setBounds(0, 0, getWidth(), getHeight()); try { - mapView.setMaximum(true); + internalFrame.setMaximum(true); } catch (final PropertyVetoException e) { log.error("PropertyVetoException: " + e); } @@ -342,7 +346,7 @@ final Action windowAction = windowActions.get(mapView); assert windowAction != null; final Icon icon = new ImageIcon(mapImageCache.getOrCreateIcon(mapView.getMapControl())); - mapView.setFrameIcon(icon); + mapView.getInternalFrame().setFrameIcon(icon); windowAction.putValue(Action.SMALL_ICON, icon); } @@ -366,8 +370,9 @@ private void activateAndRaiseMapView(@NotNull final MapView<G, A, R> mapView) { mapManager.setCurrentMap(mapView.getMapControl()); mapView.activate(); - mapView.moveToFront(); - setSelectedFrame(mapView); + final JInternalFrame internalFrame = mapView.getInternalFrame(); + internalFrame.moveToFront(); + setSelectedFrame(internalFrame); } /** @@ -398,10 +403,11 @@ private void updateFocus(final boolean fCareAboutIconification) { // Show the next map (if such exists) for (final MapView<G, A, R> mapView : mapViewManager) { - if (mapView.isIcon()) { + final JInternalFrame internalFrame = mapView.getInternalFrame(); + if (internalFrame.isIcon()) { if (!fCareAboutIconification) { try { - mapView.setIcon(false); + internalFrame.setIcon(false); } catch (final PropertyVetoException e) { log.warn(ACTION_BUILDER.format("logUnexpectedException", e)); } Modified: trunk/src/app/net/sf/gridarta/gui/mapdesktop/WindowAction.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/mapdesktop/WindowAction.java 2010-06-23 16:21:32 UTC (rev 8409) +++ trunk/src/app/net/sf/gridarta/gui/mapdesktop/WindowAction.java 2010-06-23 17:43:50 UTC (rev 8410) @@ -160,7 +160,7 @@ this.mapDesktop = mapDesktop; this.mapView = mapView; this.mapManager = mapManager; - putValue(SHORT_DESCRIPTION, "Switches to map " + mapView.getTitle()); + putValue(SHORT_DESCRIPTION, "Switches to map " + mapView.getInternalFrame().getTitle()); mapView.getMapControl().getMapModel().addMapModelListener(mapModelListener); mapManager.addMapManagerListener(mapManagerListener); setIndex(-1); Modified: trunk/src/app/net/sf/gridarta/gui/pickmapchooser/PickmapChooserView.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/pickmapchooser/PickmapChooserView.java 2010-06-23 16:21:32 UTC (rev 8409) +++ trunk/src/app/net/sf/gridarta/gui/pickmapchooser/PickmapChooserView.java 2010-06-23 17:43:50 UTC (rev 8410) @@ -26,6 +26,7 @@ import javax.swing.JTabbedPane; import javax.swing.SwingConstants; import javax.swing.event.ChangeListener; +import net.sf.gridarta.gui.map.mapview.MapViewBasic; import net.sf.gridarta.mapfiles.MapFile; import net.sf.gridarta.mapfiles.MapFolder; import net.sf.gridarta.mapfiles.MapFolderListener; @@ -209,7 +210,8 @@ } final int index = pickmapChooserModel.addMapFile(mapFile); - pickmapPanel.insertTab(getTitle(mapFile), null, mapFile.getView(), null, index); + final MapViewBasic<G,A,R> mapViewBasic = mapFile.getView(); + pickmapPanel.insertTab(getTitle(mapFile), null, mapViewBasic == null ? null : mapViewBasic.getScrollPane(), null, index); } /** @@ -234,7 +236,8 @@ return; } pickmapPanel.setTitleAt(index, getTitle(mapFile)); - pickmapPanel.setComponentAt(index, mapFile.getView()); + final MapViewBasic<G, A, R> mapViewBasic = mapFile.getView(); + pickmapPanel.setComponentAt(index, mapViewBasic == null ? null : mapViewBasic.getScrollPane()); } /** Modified: trunk/src/test/net/sf/gridarta/gui/copybuffer/CopyBufferTest.java =================================================================== --- trunk/src/test/net/... [truncated message content] |
From: <aki...@us...> - 2010-11-13 22:06:28
|
Revision: 8793 http://gridarta.svn.sourceforge.net/gridarta/?rev=8793&view=rev Author: akirschbaum Date: 2010-11-13 22:06:21 +0000 (Sat, 13 Nov 2010) Log Message: ----------- Move classes to different packages. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/gui/autovalidator/AutoValidator.java trunk/src/app/net/sf/gridarta/gui/connectionview/ConnectionControl.java trunk/src/app/net/sf/gridarta/gui/connectionview/ConnectionView.java trunk/src/app/net/sf/gridarta/gui/connectionview/LockedItemsControl.java trunk/src/app/net/sf/gridarta/gui/connectionview/LockedItemsView.java trunk/src/app/net/sf/gridarta/gui/connectionview/MonsterControl.java trunk/src/app/net/sf/gridarta/gui/connectionview/MonsterView.java trunk/src/app/net/sf/gridarta/gui/connectionview/View.java trunk/src/app/net/sf/gridarta/gui/delayedmapmodel/DelayedMapModelListener.java trunk/src/app/net/sf/gridarta/gui/delayedmapmodel/DelayedMapModelListenerManager.java trunk/src/app/net/sf/gridarta/gui/exitconnector/ExitConnectorController.java trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/actions/ExitConnectorActions.java trunk/src/app/net/sf/gridarta/gui/delayedmapmodel/ trunk/src/test/net/sf/gridarta/actions/ExitConnectorActionsTest.java Removed Paths: ------------- trunk/src/app/net/sf/gridarta/delayedmapmodel/ trunk/src/app/net/sf/gridarta/exitconnector/ trunk/src/test/net/sf/gridarta/exitconnector/ Copied: trunk/src/app/net/sf/gridarta/actions/ExitConnectorActions.java (from rev 8792, trunk/src/app/net/sf/gridarta/exitconnector/ExitConnectorActions.java) =================================================================== --- trunk/src/app/net/sf/gridarta/actions/ExitConnectorActions.java (rev 0) +++ trunk/src/app/net/sf/gridarta/actions/ExitConnectorActions.java 2010-11-13 22:06:21 UTC (rev 8793) @@ -0,0 +1,364 @@ +/* + * 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.actions; + +import java.awt.Point; +import java.io.File; +import java.io.IOException; +import net.sf.gridarta.model.archetype.Archetype; +import net.sf.gridarta.model.archetype.ArchetypeSet; +import net.sf.gridarta.model.archetype.UndefinedArchetypeException; +import net.sf.gridarta.model.baseobject.BaseObject; +import net.sf.gridarta.model.exitconnector.ExitConnectorModel; +import net.sf.gridarta.model.exitconnector.ExitLocation; +import net.sf.gridarta.model.exitconnector.ExitMatcher; +import net.sf.gridarta.model.gameobject.GameObject; +import net.sf.gridarta.model.io.PathManager; +import net.sf.gridarta.model.maparchobject.MapArchObject; +import net.sf.gridarta.model.mapcontrol.MapControl; +import net.sf.gridarta.model.mapmanager.FileControl; +import net.sf.gridarta.model.mapmanager.MapManager; +import net.sf.gridarta.model.mapmodel.InsertionModeSet; +import net.sf.gridarta.model.mapmodel.MapModel; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Utility class implementing actions that operate on {@link + * ExitConnectorModel}s. + * @author Andreas Kirschbaum + */ +public class ExitConnectorActions<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> { + + /** + * The {@link ExitConnectorModel} to use. + */ + @NotNull + private final ExitConnectorModel exitConnectorModel; + + /** + * The {@link ExitMatcher} to use. + */ + @NotNull + private final ExitMatcher<G, A, R> exitMatcher; + + /** + * The {@link ArchetypeSet} to use. + */ + @NotNull + private final ArchetypeSet<G, A, R> archetypeSet; + + /** + * The {@link MapManager} for loading maps. + */ + @NotNull + private final MapManager<G, A, R> mapManager; + + /** + * The {@link FileControl} to use. + */ + @NotNull + private final FileControl<G, A, R> fileControl; + + /** + * The {@link PathManager} for converting path names. + */ + @NotNull + private final PathManager pathManager; + + /** + * The {@link InsertionModeSet} to use. + */ + @NotNull + private final InsertionModeSet<G, A, R> insertionModeSet; + + /** + * Creates a new instance. + * @param exitConnectorModel the exit connector model to use + * @param exitMatcher the exit matcher to use + * @param archetypeSet the archetype set to use + * @param mapManager the map manager for loading maps + * @param fileControl the file control to use + * @param pathManager the path manager for converting path names + * @param insertionModeSet the insertion mode set to use + */ + public ExitConnectorActions(@NotNull final ExitConnectorModel exitConnectorModel, @NotNull final ExitMatcher<G, A, R> exitMatcher, @NotNull final ArchetypeSet<G, A, R> archetypeSet, @NotNull final MapManager<G, A, R> mapManager, @NotNull final FileControl<G, A, R> fileControl, @NotNull final PathManager pathManager, @NotNull final InsertionModeSet<G, A, R> insertionModeSet) { + this.exitConnectorModel = exitConnectorModel; + this.exitMatcher = exitMatcher; + this.archetypeSet = archetypeSet; + this.mapManager = mapManager; + this.fileControl = fileControl; + this.pathManager = pathManager; + this.insertionModeSet = insertionModeSet; + } + + /** + * Executes the "exit copy" action. + * @param performAction whether the action should be performed + * @param mapControl the map control to copy from + * @param location the cursor location + * @return whether the action was or can be performed + */ + public boolean doExitCopy(final boolean performAction, @NotNull final MapControl<G, A, R> mapControl, @NotNull final Point location) { + final MapModel<G, A, R> mapModel = mapControl.getMapModel(); + final File mapFile = mapModel.getMapFile(); + if (mapFile == null) { + // unsaved maps do not have a map path ==> no location to remember + return false; + } + + if (performAction) { + final ExitLocation exitLocation = new ExitLocation(mapFile, location, mapModel.getMapArchObject().getMapName(), pathManager); + exitConnectorModel.setExitLocation(exitLocation); + } + + return true; + } + + /** + * Executes the "exit paste" action. + * @param performAction whether the action should be performed + * @param mapControl the map control to paste into + * @param targetLocation the target location to paste to + * @return whether the action was or can be performed + */ + public boolean doExitPaste(final boolean performAction, @NotNull final MapControl<G, A, R> mapControl, @NotNull final Point targetLocation) { + final ExitLocation sourceExitLocation = exitConnectorModel.getExitLocation(); + if (sourceExitLocation == null) { + return false; + } + + final MapModel<G, A, R> targetMapModel = mapControl.getMapModel(); + @Nullable final BaseObject<G, A, R, ?> targetExit; + //XXX final G selectedExit = exitMatcher.getValidExit(selectedSquareModel.getSelectedGameObject()); + //XXX if (selectedExit != null) { + //XXX targetExit = selectedExit; + //XXX } else { + final BaseObject<G, A, R, ?> cursorExit = exitMatcher.getExit(targetMapModel, targetLocation); + if (cursorExit != null) { + targetExit = cursorExit; + } else if (exitConnectorModel.isAutoCreateExit()) { + targetExit = null; + } else { + return false; + } + + final File targetMapFile = targetMapModel.getMapFile(); + + if (targetExit != null) { + // paste into existing exit + + if (performAction) { + pasteExit(targetExit, targetMapModel, sourceExitLocation, targetMapFile); + } + } else { + // paste into newly created exit game object + + final BaseObject<G, A, R, ?> targetArchetype; + try { + targetArchetype = archetypeSet.getArchetype(exitConnectorModel.getExitArchetypeName()); + } catch (final UndefinedArchetypeException ignored) { + return false; + } + + if (performAction) { + if (!pasteExit(targetLocation, targetMapModel, targetArchetype, sourceExitLocation, targetMapFile)) { + return false; + } + } + } + + return true; + } + + /** + * Executes the "exit connect" action. + * @param performAction whether the action should be performed + * @param mapControl the map control to connect with + * @param targetLocation the target location to connect + * @return whether the action was or can be performed + */ + public boolean doExitConnect(final boolean performAction, @NotNull final MapControl<G, A, R> mapControl, @NotNull final Point targetLocation) { + final ExitLocation sourceExitLocation = exitConnectorModel.getExitLocation(); + if (sourceExitLocation == null) { + return false; + } + + final MapModel<G, A, R> targetMapModel = mapControl.getMapModel(); + final File targetMapFile = targetMapModel.getMapFile(); + if (targetMapFile == null) { + // target map file is unsaved ==> no location to connect + return false; + } + + @Nullable final BaseObject<G, A, R, ?> targetExit; + @Nullable final BaseObject<G, A, R, ?> targetArchetype; + //XXX final G selectedExit = exitMatcher.getValidExit(selectedSquareModel.getSelectedGameObject()); + //XXX if (selectedExit != null) { + //XXX targetExit = selectedExit; + //XXX targetArchetype = null; + //XXX } else { + final BaseObject<G, A, R, ?> cursorExit = exitMatcher.getExit(targetMapModel, targetLocation); + if (cursorExit != null) { + targetExit = cursorExit; + targetArchetype = null; + } else if (exitConnectorModel.isAutoCreateExit()) { + targetExit = null; + try { + targetArchetype = archetypeSet.getArchetype(exitConnectorModel.getExitArchetypeName()); + } catch (final UndefinedArchetypeException ignored) { + return false; + } + } else { + return false; + } + + final MapControl<G, A, R> sourceMapControl; + try { + sourceMapControl = mapManager.openMapFile(sourceExitLocation.getFile(), false); + } catch (final IOException ex) { + fileControl.reportLoadError(sourceExitLocation.getFile(), ex.getMessage()); + return false; + } + try { + return doExitConnect(performAction, targetExit, targetArchetype, targetMapModel, targetLocation, targetMapFile, sourceMapControl.getMapModel(), sourceExitLocation); + } finally { + try { + // XXX: remove hack when MapManager automatically saves released maps + if (sourceMapControl.getMapModel().isModified() && sourceMapControl.getUseCounter() <= 1) { + try { + sourceMapControl.save(); + } catch (final IOException ex) { + fileControl.reportSaveError(sourceMapControl, ex.getMessage()); + } + } + } finally { + mapManager.release(sourceMapControl); + } + } + } + + /** + * Executes part of the "exit connect" action. + * @param performAction whether the action should be performed + * @param targetExit the target exit game object or <code>null</code> + * @param targetArchetype the target exit archetype; <code>null</code> if + * <code>targetExit</code> is non-<code>null</code>; unused otherwise + * @param targetMapModel the target's map model + * @param targetLocation the target's coordinates + * @param targetMapFile the target's file + * @param sourceMapModel the source's map model + * @param sourceExitLocation the source's exit location @return whether the + * action was or can be performed + * @return whether the action was or can be performed + */ + private boolean doExitConnect(final boolean performAction, @Nullable final BaseObject<?, ?, ?, ?> targetExit, @Nullable final BaseObject<G, A, R, ?> targetArchetype, @NotNull final MapModel<G, A, R> targetMapModel, @NotNull final Point targetLocation, @NotNull final File targetMapFile, @NotNull final MapModel<G, A, R> sourceMapModel, @NotNull final ExitLocation sourceExitLocation) { + final File sourceMapFile = sourceMapModel.getMapFile(); + if (sourceMapFile == null) { + // source map is unsaved ==> cannot connect + return false; + } + + final Point sourceLocation = sourceExitLocation.getMapCoordinate(); + + @Nullable final BaseObject<G, A, R, ?> sourceExit; + @Nullable final BaseObject<G, A, R, ?> sourceArchetype; + final BaseObject<G, A, R, ?> exit = exitMatcher.getExit(sourceMapModel, sourceLocation); + if (exit != null) { + sourceExit = exit; + sourceArchetype = null; + } else if (exitConnectorModel.isAutoCreateExit()) { + sourceExit = null; + try { + sourceArchetype = archetypeSet.getArchetype(exitConnectorModel.getExitArchetypeName()); + } catch (final UndefinedArchetypeException ignored) { + return false; + } + } else { + return false; + } + + if (performAction) { + final ExitLocation targetExitLocation = new ExitLocation(targetMapFile, targetLocation, targetMapModel.getMapArchObject().getMapName(), pathManager); + if (sourceExit != null) { + pasteExit(sourceExit, sourceMapModel, targetExitLocation, sourceMapFile); + } else { + if (!pasteExit(sourceLocation, sourceMapModel, sourceArchetype, targetExitLocation, sourceMapFile)) { + return false; + } + } + + if (targetExit != null) { + pasteExit(targetExit, targetMapModel, sourceExitLocation, targetMapFile); + } else { + assert targetArchetype != null; + if (!pasteExit(targetLocation, targetMapModel, targetArchetype, sourceExitLocation, targetMapFile)) { + return false; + } + } + } + + return true; + } + + /** + * Pastes exit information into an exit game object. + * @param gameObject the exit game object to paste into + * @param mapModel the map model to paste into + * @param exitLocation the exit information to paste + * @param gameObjectMapFile the map file of <code>gameObject</code> or + * <code>null</code> if on an unsaved map + */ + private void pasteExit(@NotNull final BaseObject<?, ?, ?, ?> gameObject, @NotNull final MapModel<G, A, R> mapModel, @NotNull final ExitLocation exitLocation, @Nullable final File gameObjectMapFile) { + mapModel.beginTransaction("paste exit"); + try { + exitLocation.updateExitObject(gameObject, exitConnectorModel.isPasteExitName(), gameObjectMapFile); + } finally { + mapModel.endTransaction(); + } + } + + /** + * Creates a new exit game object. + * @param location the location to insert into + * @param mapModel the map model to insert into + * @param archetype the archetype to insert + * @param exitLocation the exit information to use + * @param mapFile the map file to insert into or <code>null</code> for + * unsaved maps + * @return whether insertion was successful + */ + private boolean pasteExit(@NotNull final Point location, @NotNull final MapModel<G, A, R> mapModel, @NotNull final BaseObject<G, A, R, ?> archetype, @NotNull final ExitLocation exitLocation, @Nullable final File mapFile) { + mapModel.beginTransaction("paste exit"); + try { + final BaseObject<G, A, R, ?> newExit = mapModel.insertBaseObject(archetype, location, true, false, insertionModeSet.getTopmostInsertionMode()); + if (newExit == null) { + return false; + } + + exitLocation.updateExitObject(newExit, exitConnectorModel.isPasteExitName(), mapFile); + } finally { + mapModel.endTransaction(); + } + + return true; + } + +} // class ExitConnectorActions Property changes on: trunk/src/app/net/sf/gridarta/actions/ExitConnectorActions.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Modified: trunk/src/app/net/sf/gridarta/gui/autovalidator/AutoValidator.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/autovalidator/AutoValidator.java 2010-11-13 21:49:58 UTC (rev 8792) +++ trunk/src/app/net/sf/gridarta/gui/autovalidator/AutoValidator.java 2010-11-13 22:06:21 UTC (rev 8793) @@ -23,8 +23,8 @@ import java.util.prefs.PreferenceChangeListener; import java.util.prefs.Preferences; import net.sf.gridarta.MainControl; -import net.sf.gridarta.delayedmapmodel.DelayedMapModelListener; -import net.sf.gridarta.delayedmapmodel.DelayedMapModelListenerManager; +import net.sf.gridarta.gui.delayedmapmodel.DelayedMapModelListener; +import net.sf.gridarta.gui.delayedmapmodel.DelayedMapModelListenerManager; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; Modified: trunk/src/app/net/sf/gridarta/gui/connectionview/ConnectionControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/connectionview/ConnectionControl.java 2010-11-13 21:49:58 UTC (rev 8792) +++ trunk/src/app/net/sf/gridarta/gui/connectionview/ConnectionControl.java 2010-11-13 22:06:21 UTC (rev 8793) @@ -19,7 +19,7 @@ package net.sf.gridarta.gui.connectionview; -import net.sf.gridarta.delayedmapmodel.DelayedMapModelListenerManager; +import net.sf.gridarta.gui.delayedmapmodel.DelayedMapModelListenerManager; import net.sf.gridarta.gui.map.mapview.MapViewManager; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.gameobject.GameObject; Modified: trunk/src/app/net/sf/gridarta/gui/connectionview/ConnectionView.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/connectionview/ConnectionView.java 2010-11-13 21:49:58 UTC (rev 8792) +++ trunk/src/app/net/sf/gridarta/gui/connectionview/ConnectionView.java 2010-11-13 22:06:21 UTC (rev 8793) @@ -20,7 +20,7 @@ package net.sf.gridarta.gui.connectionview; import java.util.Comparator; -import net.sf.gridarta.delayedmapmodel.DelayedMapModelListenerManager; +import net.sf.gridarta.gui.delayedmapmodel.DelayedMapModelListenerManager; import net.sf.gridarta.gui.map.mapview.MapViewManager; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.baseobject.BaseObject; Modified: trunk/src/app/net/sf/gridarta/gui/connectionview/LockedItemsControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/connectionview/LockedItemsControl.java 2010-11-13 21:49:58 UTC (rev 8792) +++ trunk/src/app/net/sf/gridarta/gui/connectionview/LockedItemsControl.java 2010-11-13 22:06:21 UTC (rev 8793) @@ -19,7 +19,7 @@ package net.sf.gridarta.gui.connectionview; -import net.sf.gridarta.delayedmapmodel.DelayedMapModelListenerManager; +import net.sf.gridarta.gui.delayedmapmodel.DelayedMapModelListenerManager; import net.sf.gridarta.gui.map.mapview.MapViewManager; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.gameobject.GameObject; Modified: trunk/src/app/net/sf/gridarta/gui/connectionview/LockedItemsView.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/connectionview/LockedItemsView.java 2010-11-13 21:49:58 UTC (rev 8792) +++ trunk/src/app/net/sf/gridarta/gui/connectionview/LockedItemsView.java 2010-11-13 22:06:21 UTC (rev 8793) @@ -21,7 +21,7 @@ import java.util.Collection; import java.util.HashSet; -import net.sf.gridarta.delayedmapmodel.DelayedMapModelListenerManager; +import net.sf.gridarta.gui.delayedmapmodel.DelayedMapModelListenerManager; import net.sf.gridarta.gui.map.mapview.MapViewManager; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.baseobject.BaseObject; Modified: trunk/src/app/net/sf/gridarta/gui/connectionview/MonsterControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/connectionview/MonsterControl.java 2010-11-13 21:49:58 UTC (rev 8792) +++ trunk/src/app/net/sf/gridarta/gui/connectionview/MonsterControl.java 2010-11-13 22:06:21 UTC (rev 8793) @@ -19,7 +19,7 @@ package net.sf.gridarta.gui.connectionview; -import net.sf.gridarta.delayedmapmodel.DelayedMapModelListenerManager; +import net.sf.gridarta.gui.delayedmapmodel.DelayedMapModelListenerManager; import net.sf.gridarta.gui.map.mapview.MapViewManager; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.gameobject.GameObject; Modified: trunk/src/app/net/sf/gridarta/gui/connectionview/MonsterView.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/connectionview/MonsterView.java 2010-11-13 21:49:58 UTC (rev 8792) +++ trunk/src/app/net/sf/gridarta/gui/connectionview/MonsterView.java 2010-11-13 22:06:21 UTC (rev 8793) @@ -21,7 +21,7 @@ import java.io.Serializable; import java.util.Comparator; -import net.sf.gridarta.delayedmapmodel.DelayedMapModelListenerManager; +import net.sf.gridarta.gui.delayedmapmodel.DelayedMapModelListenerManager; import net.sf.gridarta.gui.map.mapview.MapViewManager; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.gameobject.GameObject; Modified: trunk/src/app/net/sf/gridarta/gui/connectionview/View.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/connectionview/View.java 2010-11-13 21:49:58 UTC (rev 8792) +++ trunk/src/app/net/sf/gridarta/gui/connectionview/View.java 2010-11-13 22:06:21 UTC (rev 8793) @@ -30,8 +30,8 @@ import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.event.ListSelectionListener; -import net.sf.gridarta.delayedmapmodel.DelayedMapModelListener; -import net.sf.gridarta.delayedmapmodel.DelayedMapModelListenerManager; +import net.sf.gridarta.gui.delayedmapmodel.DelayedMapModelListener; +import net.sf.gridarta.gui.delayedmapmodel.DelayedMapModelListenerManager; import net.sf.gridarta.gui.map.mapview.MapView; import net.sf.gridarta.gui.map.mapview.MapViewManager; import net.sf.gridarta.gui.map.mapview.MapViewManagerListener; Modified: trunk/src/app/net/sf/gridarta/gui/delayedmapmodel/DelayedMapModelListener.java =================================================================== --- trunk/src/app/net/sf/gridarta/delayedmapmodel/DelayedMapModelListener.java 2010-11-13 21:49:58 UTC (rev 8792) +++ trunk/src/app/net/sf/gridarta/gui/delayedmapmodel/DelayedMapModelListener.java 2010-11-13 22:06:21 UTC (rev 8793) @@ -17,7 +17,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.gridarta.delayedmapmodel; +package net.sf.gridarta.gui.delayedmapmodel; import java.util.EventListener; import net.sf.gridarta.model.archetype.Archetype; Modified: trunk/src/app/net/sf/gridarta/gui/delayedmapmodel/DelayedMapModelListenerManager.java =================================================================== --- trunk/src/app/net/sf/gridarta/delayedmapmodel/DelayedMapModelListenerManager.java 2010-11-13 21:49:58 UTC (rev 8792) +++ trunk/src/app/net/sf/gridarta/gui/delayedmapmodel/DelayedMapModelListenerManager.java 2010-11-13 22:06:21 UTC (rev 8793) @@ -17,7 +17,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -package net.sf.gridarta.delayedmapmodel; +package net.sf.gridarta.gui.delayedmapmodel; import java.io.File; import java.lang.reflect.InvocationTargetException; Modified: trunk/src/app/net/sf/gridarta/gui/exitconnector/ExitConnectorController.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/exitconnector/ExitConnectorController.java 2010-11-13 21:49:58 UTC (rev 8792) +++ trunk/src/app/net/sf/gridarta/gui/exitconnector/ExitConnectorController.java 2010-11-13 22:06:21 UTC (rev 8793) @@ -21,7 +21,7 @@ import java.awt.Point; import javax.swing.Action; -import net.sf.gridarta.exitconnector.ExitConnectorActions; +import net.sf.gridarta.actions.ExitConnectorActions; import net.sf.gridarta.gui.map.mapview.MapView; import net.sf.gridarta.gui.map.mapview.MapViewBasic; import net.sf.gridarta.gui.map.mapview.MapViewManager; Modified: trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java 2010-11-13 21:49:58 UTC (rev 8792) +++ trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java 2010-11-13 22:06:21 UTC (rev 8793) @@ -34,8 +34,8 @@ import javax.swing.JOptionPane; import javax.swing.filechooser.FileFilter; import net.sf.gridarta.MainControl; -import net.sf.gridarta.delayedmapmodel.DelayedMapModelListenerManager; -import net.sf.gridarta.exitconnector.ExitConnectorActions; +import net.sf.gridarta.actions.ExitConnectorActions; +import net.sf.gridarta.gui.delayedmapmodel.DelayedMapModelListenerManager; import net.sf.gridarta.gui.archetypechooser.ArchetypeChooserControl; import net.sf.gridarta.gui.autovalidator.AutoValidator; import net.sf.gridarta.gui.bookmarks.BookmarkActions; Copied: trunk/src/test/net/sf/gridarta/actions/ExitConnectorActionsTest.java (from rev 8792, trunk/src/test/net/sf/gridarta/exitconnector/ExitConnectorActionsTest.java) =================================================================== --- trunk/src/test/net/sf/gridarta/actions/ExitConnectorActionsTest.java (rev 0) +++ trunk/src/test/net/sf/gridarta/actions/ExitConnectorActionsTest.java 2010-11-13 22:06:21 UTC (rev 8793) @@ -0,0 +1,432 @@ +/* + * 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.actions; + +import java.awt.Point; +import java.io.File; +import net.sf.gridarta.model.archetype.DuplicateArchetypeException; +import net.sf.gridarta.model.archetype.TestArchetype; +import net.sf.gridarta.model.baseobject.BaseObject; +import net.sf.gridarta.model.exitconnector.ExitConnectorModel; +import net.sf.gridarta.model.exitconnector.ExitLocation; +import net.sf.gridarta.model.exitconnector.TestExitConnectorModel; +import net.sf.gridarta.model.gameobject.TestGameObject; +import net.sf.gridarta.model.maparchobject.TestMapArchObject; +import net.sf.gridarta.model.mapcontrol.MapControl; +import net.sf.gridarta.model.mapcontrol.TestMapControlCreator; +import net.sf.gridarta.model.mapmanager.TestFileControl; +import net.sf.gridarta.model.mapmodel.CannotInsertGameObjectException; +import net.sf.gridarta.model.mapmodel.MapModel; +import net.sf.gridarta.model.mapmodel.TestMapModelHelper; +import net.sf.gridarta.utils.Size2D; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * Regression tests for {@link ExitConnectorActions}. + * @author Andreas Kirschbaum + */ +public class ExitConnectorActionsTest { + + /** + * The first map file. + */ + private static final File MAP_FILE1 = new File("a"); + + /** + * The first map name. + */ + private static final String MAP_NAME1 = "name1"; + + /** + * The second map file. + */ + private static final File MAP_FILE2 = new File("b"); + + /** + * The second map name. + */ + private static final String MAP_NAME2 = "name2"; + + /** + * The {@link TestMapControlCreator} for creating maps. + */ + @Nullable + private TestMapControlCreator testMapControlCreator = null; + + /** + * The {@link TestMapModelHelper} instance. + */ + @Nullable + private TestMapModelHelper mapModelHelper = null; + + /** + * Checks that {@link ExitConnectorActions#doExitCopy(boolean, MapControl, + * Point)} does work. + */ + @Test + public void testExitCopy1() { + final ExitConnectorModel model = new TestExitConnectorModel(); + final ExitConnectorActions<TestGameObject, TestMapArchObject, TestArchetype> actions = createActions(model); + final Size2D mapSize = new Size2D(5, 5); + assert testMapControlCreator != null; + final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl = testMapControlCreator.newMapControl(MAP_FILE1, MAP_NAME1, mapSize); + + // active ==> enabled + final Point point1 = new Point(3, 4); + Assert.assertTrue(actions.doExitCopy(false, mapControl, point1)); + Assert.assertNull(model.getExitLocation()); + + // perform copy + Assert.assertTrue(actions.doExitCopy(true, mapControl, point1)); + assert testMapControlCreator != null; + Assert.assertEquals(new ExitLocation(MAP_FILE1, point1, MAP_NAME1, testMapControlCreator.getPathManager()), model.getExitLocation()); + + // unsaved map ==> disabled + mapControl.getMapModel().setMapFile(null); + Assert.assertFalse(actions.doExitCopy(false, mapControl, point1)); + assert testMapControlCreator != null; + Assert.assertEquals(new ExitLocation(MAP_FILE1, point1, MAP_NAME1, testMapControlCreator.getPathManager()), model.getExitLocation()); // disabled -> unchanged model + } + + /** + * Checks that {@link ExitConnectorActions#doExitPaste(boolean, MapControl, + * Point)} does work. + * @throws CannotInsertGameObjectException if the test fails + */ + @Test + public void testExitPaste1() throws CannotInsertGameObjectException { + final ExitConnectorModel model = new TestExitConnectorModel(); + final ExitConnectorActions<TestGameObject, TestMapArchObject, TestArchetype> actions = createActions(model); + final Size2D mapSize = new Size2D(5, 5); + assert testMapControlCreator != null; + final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl = testMapControlCreator.newMapControl(MAP_FILE1, MAP_NAME1, mapSize); + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); + + final Point point1 = new Point(3, 4); + final Point point2 = new Point(1, 2); + + assert testMapControlCreator != null; + model.setExitLocation(new ExitLocation(MAP_FILE2, point2, MAP_NAME2, testMapControlCreator.getPathManager())); + + // no exit at cursor and no auto-create ==> disabled + Assert.assertFalse(actions.doExitPaste(false, mapControl, point1)); + + mapModel.beginTransaction("TEST"); + try { + assert mapModelHelper != null; + mapModelHelper.insertFloor(mapModel, point1); + } finally { + mapModel.endTransaction(); + } + + // no exit at cursor and no auto-create ==> disabled + Assert.assertFalse(actions.doExitPaste(false, mapControl, point1)); + + mapModel.beginTransaction("TEST"); + try { + assert mapModelHelper != null; + mapModelHelper.insertExit(mapModel, point1); + } finally { + mapModel.endTransaction(); + } + + // exit at cursor ==> enabled + Assert.assertTrue(actions.doExitPaste(false, mapControl, point1)); + checkExit(mapModel, point1, 1, "", new Point(0, 0)); // "check only" ==> exit is unchanged + + // perform paste + Assert.assertTrue(actions.doExitPaste(true, mapControl, point1)); + checkExit(mapModel, point1, 1, "b", point2); + } + + /** + * Checks that {@link ExitConnectorActions#doExitPaste(boolean, MapControl, + * Point)} does not crash when connecting to an unsaved map. + */ + @Test + public void testExitPaste2() { + final ExitConnectorModel model = new TestExitConnectorModel(); + final ExitConnectorActions<TestGameObject, TestMapArchObject, TestArchetype> actions = createActions(model); + final Size2D mapSize = new Size2D(5, 5); + + assert testMapControlCreator != null; + final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl1 = testMapControlCreator.newMapControl(MAP_FILE1, MAP_NAME1, mapSize); + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel1 = mapControl1.getMapModel(); + + final Point point1 = new Point(3, 4); + final Point point2 = new Point(1, 2); + + assert testMapControlCreator != null; + model.setExitLocation(new ExitLocation(MAP_FILE2, point2, MAP_NAME2, testMapControlCreator.getPathManager())); + + model.setAutoCreateExit(true); + + // copy must fail for unsaved map + mapModel1.setMapFile(null); // pretend unsaved map + Assert.assertFalse(actions.doExitCopy(true, mapControl1, point1)); + + // paste must succeed for unsaved map + Assert.assertTrue(actions.doExitPaste(true, mapControl1, point1)); + } + + /** + * Checks that {@link ExitConnectorActions#doExitConnect(boolean, + * MapControl, Point)} does work. + * @throws CannotInsertGameObjectException if the test fails + */ + @Test + public void testExitConnect1() throws CannotInsertGameObjectException { + final ExitConnectorModel model = new TestExitConnectorModel(); + final ExitConnectorActions<TestGameObject, TestMapArchObject, TestArchetype> actions = createActions(model); + + final Size2D mapSize = new Size2D(5, 5); + assert testMapControlCreator != null; + final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl1 = testMapControlCreator.newMapControl(MAP_FILE1, MAP_NAME1, mapSize); + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel1 = mapControl1.getMapModel(); + + assert testMapControlCreator != null; + final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl2 = testMapControlCreator.newMapControl(MAP_FILE2, MAP_NAME2, mapSize); + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel2 = mapControl2.getMapModel(); + + final Point point1 = new Point(3, 4); + final Point point2 = new Point(1, 2); + + assert testMapControlCreator != null; + model.setExitLocation(new ExitLocation(MAP_FILE2, point2, MAP_NAME2, testMapControlCreator.getPathManager())); + + // no exit at cursor and no auto-create ==> disabled + Assert.assertFalse(actions.doExitConnect(false, mapControl1, point1)); + + mapModel1.beginTransaction("TEST"); + try { + assert mapModelHelper != null; + mapModelHelper.insertFloor(mapModel1, point1); + } finally { + mapModel1.endTransaction(); + } + + // no exit at cursor and no auto-create ==> disabled + Assert.assertFalse(actions.doExitConnect(false, mapControl1, point1)); + + mapModel1.beginTransaction("TEST"); + try { + assert mapModelHelper != null; + mapModelHelper.insertExit(mapModel1, point1); + } finally { + mapModel1.endTransaction(); + } + + // no exit at source and no auto-create ==> disabled + Assert.assertFalse(actions.doExitConnect(false, mapControl1, point1)); + + mapModel2.beginTransaction("TEST"); + try { + assert mapModelHelper != null; + mapModelHelper.insertExit(mapModel2, point2); + } finally { + mapModel2.endTransaction(); + } + + // exit at source and cursor ==> enabled + Assert.assertTrue(actions.doExitConnect(false, mapControl1, point1)); + checkExit(mapModel1, point1, 1, "", new Point(0, 0)); // "check only" ==> exit is unchanged + checkExit(mapModel2, point2, 0, "", new Point(0, 0)); + + // perform connect + Assert.assertTrue(actions.doExitConnect(true, mapControl1, point1)); + checkExit(mapModel1, point1, 1, "b", point2); + checkExit(mapModel2, point2, 0, "a", point1); + } + + /** + * Checks that {@link ExitConnectorActions#doExitConnect(boolean, + * MapControl, Point)} does work when auto-creating exit objects. + */ + @Test + public void testExitConnectAuto1() { + final ExitConnectorModel model = new TestExitConnectorModel(); + final ExitConnectorActions<TestGameObject, TestMapArchObject, TestArchetype> actions = createActions(model); + + final Size2D mapSize = new Size2D(5, 5); + assert testMapControlCreator != null; + final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl1 = testMapControlCreator.newMapControl(MAP_FILE1, MAP_NAME1, mapSize); + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel1 = mapControl1.getMapModel(); + + assert testMapControlCreator != null; + final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl2 = testMapControlCreator.newMapControl(MAP_FILE2, MAP_NAME2, mapSize); + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel2 = mapControl2.getMapModel(); + + final Point point1 = new Point(3, 4); + final Point point2 = new Point(1, 2); + + assert testMapControlCreator != null; + model.setExitLocation(new ExitLocation(MAP_FILE2, point2, MAP_NAME2, testMapControlCreator.getPathManager())); + model.setAutoCreateExit(true); + + model.setExitArchetypeName("undefined"); + + // fails due to undefined archetype + Assert.assertFalse(actions.doExitConnect(true, mapControl1, point1)); + checkExit(mapModel1, point1, 0, null, null); + checkExit(mapModel2, point2, 0, null, null); + + model.setExitArchetypeName("exit"); + + // perform connect + Assert.assertTrue(actions.doExitConnect(true, mapControl1, point1)); + checkExit(mapModel1, point1, 0, "b", point2); + checkExit(mapModel2, point2, 0, "a", point1); + + // perform connect; auto-create will re-use existing objects + Assert.assertTrue(actions.doExitConnect(true, mapControl1, point1)); + checkExit(mapModel1, point1, 0, "b", point2); + checkExit(mapModel1, point1, 1, null, null); + checkExit(mapModel2, point2, 0, "a", point1); + checkExit(mapModel2, point2, 1, null, null); + } + + /** + * Checks that exit paths are correctly generated. + * @throws CannotInsertGameObjectException if the test fails + */ + @Test + public void testPath1() throws CannotInsertGameObjectException { + // both root ==> relative + testPath("/a", "/b", "b"); // both root ==> relative + + // to or from root ==> absolute + testPath("/HallOfSelection", "/world/world_104_115", "/world/world_104_115"); + testPath("/world/world_104_115", "/HallOfSelection", "/HallOfSelection"); + + // same top-level component ==> relative + testPath("/a/b/c/d", "/a/d/e", "../../d/e"); + testPath("/a/b/c/d", "/a/b/d", "../d"); + testPath("/a/b/c", "/a/b/d", "d"); + testPath("/a/b/c", "/a/b/c/d", "c/d"); + + // else ==> absolute + testPath("/a/b/c", "/b/c/d", "/b/c/d"); + testPath("/a/b", "/b", "/b"); + testPath("/a", "/b/c", "/b/c"); + } + + /** + * Checks that an exit path is correctly generated. + * @param mapPathFrom the map path to connect from; this map contains the + * exit object + * @param mapPathTo the map path to connect to + * @param expectedExitPath the expected map in the exit object + * @throws CannotInsertGameObjectException if the test fails + */ + private void testPath(@NotNull final String mapPathFrom, @NotNull final String mapPathTo, @NotNull final String expectedExitPath) throws CannotInsertGameObjectException { + final ExitConnectorModel model = new TestExitConnectorModel(); + final ExitConnectorActions<TestGameObject, TestMapArchObject, TestArchetype> actions = createActions(model); + + assert testMapControlCreator != null; + final File mapDir = testMapControlCreator.getGlobalSettings().getMapsDirectory(); + final File mapFileFrom = new File(mapDir, mapPathFrom); + final File mapFileTo = new File(mapDir, mapPathTo); + + final Size2D mapSize = new Size2D(5, 5); + assert testMapControlCreator != null; + final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl = testMapControlCreator.newMapControl(mapFileFrom, MAP_NAME1, mapSize); + final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapControl.getMapModel(); + + final Point pointFrom = new Point(3, 4); + final Point pointTo = new Point(1, 2); + + assert testMapControlCreator != null; + model.setExitLocation(new ExitLocation(mapFileTo, pointTo, MAP_NAME2, testMapControlCreator.getPathManager())); + mapModel.beginTransaction("TEST"); + try { + assert mapModelHelper != null; + mapModelHelper.insertExit(mapModel, pointFrom); + } finally { + mapModel.endTransaction(); + } + + // perform connect + Assert.assertTrue(actions.doExitPaste(true, mapControl, pointFrom)); + checkExit(mapModel, pointFrom, 0, expectedExitPath, pointTo); + } + + /** + * Initializes the test case. + * @throws DuplicateArchetypeException if the test case fails + */ + @Before + public void setUp() throws DuplicateArchetypeException { + testMapControlCreator = new TestMapControlCreator(); + mapModelHelper = testMapControlCreator.newMapModelCreator(); + } + + /** + * Creates a new {@link ExitConnectorActions} instance. + * @param model the exit connector model to use + * @return the new exit connector actions instance + */ + private ExitConnectorActions<TestGameObject, TestMapArchObject, TestArchetype> createActions(@NotNull final ExitConnectorModel model) { + final TestMapControlCreator tmpTestMapControlCreator = testMapControlCreator; + assert tmpTestMapControlCreator != null; + return new ExitConnectorActions<TestGameObject, TestMapArchObject, TestArchetype>(model, tmpTestMapControlCreator.getExitMatcher(), tmpTestMapControlCreator.getArchetypeSet(), tmpTestMapControlCreator.getMapManager(), new TestFileControl(), tmpTestMapControlCreator.getPathManager(), tmpTestMapControlCreator.getInsertionModeSet()); + } + + /** + * Checks that a map model contains an exit game object. + * @param mapModel the map model to check + * @param point the position to check + * @param index the index to check + * @param exitPath the expected exit path or <code>null</code> if no exit + * game object is expected + * @param exitPoint the expected exit destination or <code>null</code> if no + * exit game object is expected + */ + private static void checkExit(@NotNull final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel, @NotNull final Point point, final int index, @Nullable final String exitPath, @Nullable final Point exitPoint) { + int thisIndex = 0; + for (final BaseObject<?, ?, ?, ?> gameObject : mapModel.getMapSquare(point)) { + if (thisIndex == index) { + if (gameObject.getTypeNo() != TestMapModelHelper.EXIT_TYPE) { + break; + } + + if (exitPath == null || exitPoint == null) { + Assert.fail("exit found but none expected"); + throw new AssertionError(); + } + + Assert.assertEquals(exitPath, gameObject.getAttributeString("slaying")); + Assert.assertEquals(exitPoint.x, gameObject.getAttributeInt("hp")); + Assert.assertEquals(exitPoint.y, gameObject.getAttributeInt("sp")); + return; + } + + thisIndex++; + } + + if (exitPath != null || exitPoint != null) { + Assert.fail("no exit found"); + } + } + +} // class ExitConnectorActionsTest Property changes on: trunk/src/test/net/sf/gridarta/actions/ExitConnectorActionsTest.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-01-23 17:33:03
|
Revision: 8834 http://gridarta.svn.sourceforge.net/gridarta/?rev=8834&view=rev Author: akirschbaum Date: 2011-01-23 17:32:56 +0000 (Sun, 23 Jan 2011) Log Message: ----------- Simplify code calling AbstractMapMenuPreferences.newMapMenuEntry(). Modified Paths: -------------- trunk/src/app/net/sf/gridarta/gui/mapmenu/AbstractMapMenuPreferences.java trunk/src/app/net/sf/gridarta/gui/mapmenu/BookmarksMapMenuPreferences.java trunk/src/app/net/sf/gridarta/gui/mapmenu/RecentMapMenuPreferences.java trunk/src/test/net/sf/gridarta/gui/mapmenu/MapMenuManagerTest.java Modified: trunk/src/app/net/sf/gridarta/gui/mapmenu/AbstractMapMenuPreferences.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/mapmenu/AbstractMapMenuPreferences.java 2011-01-11 20:12:02 UTC (rev 8833) +++ trunk/src/app/net/sf/gridarta/gui/mapmenu/AbstractMapMenuPreferences.java 2011-01-23 17:32:56 UTC (rev 8834) @@ -88,11 +88,18 @@ * Creates a new {@link MapMenuEntry}. * @param title the entry's title * @param mapFile the entry's map file - * @return the new instance + * @param replaceExisting whether an existing entry should be replaced */ - @NotNull - protected MapMenuEntry<G, A, R> newMapMenuEntry(@NotNull final String title, @NotNull final File mapFile) { - return new MapMenuEntry<G, A, R>(title, mapFile, mapViewsManager, mapImageCache, fileControl, getShortDescription(title, getShortMapFile(globalSettings.getMapsDirectory(), mapFile))); + protected void newMapMenuEntry(@NotNull final String title, @NotNull final File mapFile, final boolean replaceExisting) { + final MapMenuEntry<G, A, R> mapMenuEntry = new MapMenuEntry<G, A, R>(title, mapFile, mapViewsManager, mapImageCache, fileControl, getShortDescription(title, getShortMapFile(globalSettings.getMapsDirectory(), mapFile))); + final int index; + if (replaceExisting) { + removeMapMenuEntryInt(mapMenuEntry); // remove old entry to get new entry at first pos. + index = 0; + } else { + index = getSize(); + } + addMapMenuEntryInt(index, mapMenuEntry); } /** Modified: trunk/src/app/net/sf/gridarta/gui/mapmenu/BookmarksMapMenuPreferences.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/mapmenu/BookmarksMapMenuPreferences.java 2011-01-11 20:12:02 UTC (rev 8833) +++ trunk/src/app/net/sf/gridarta/gui/mapmenu/BookmarksMapMenuPreferences.java 2011-01-23 17:32:56 UTC (rev 8834) @@ -127,7 +127,7 @@ */ @Override protected void addMapMenuEntryInt(@NotNull final String title, @NotNull final File mapFile) { - addMapMenuEntryInt(getSize(), newMapMenuEntry(title, mapFile)); + newMapMenuEntry(title, mapFile, false); } /** Modified: trunk/src/app/net/sf/gridarta/gui/mapmenu/RecentMapMenuPreferences.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/mapmenu/RecentMapMenuPreferences.java 2011-01-11 20:12:02 UTC (rev 8833) +++ trunk/src/app/net/sf/gridarta/gui/mapmenu/RecentMapMenuPreferences.java 2011-01-23 17:32:56 UTC (rev 8834) @@ -115,9 +115,7 @@ */ @Override protected void addMapMenuEntryInt(@NotNull final String title, @NotNull final File mapFile) { - final MapMenuEntry<G, A, R> mapMenuEntry = newMapMenuEntry(title, mapFile); - removeMapMenuEntryInt(mapMenuEntry); // remove old entry to get new entry at first pos. - addMapMenuEntryInt(0, mapMenuEntry); + newMapMenuEntry(title, mapFile, true); // Now remove those that are too many. // Please keep this while loop as the constant 10 might be replaced by a preferences var int i = 0; Modified: trunk/src/test/net/sf/gridarta/gui/mapmenu/MapMenuManagerTest.java =================================================================== --- trunk/src/test/net/sf/gridarta/gui/mapmenu/MapMenuManagerTest.java 2011-01-11 20:12:02 UTC (rev 8833) +++ trunk/src/test/net/sf/gridarta/gui/mapmenu/MapMenuManagerTest.java 2011-01-23 17:32:56 UTC (rev 8834) @@ -94,8 +94,7 @@ @Override protected void addMapMenuEntryInt(@NotNull final String title, @NotNull final File mapFile) { - final MapMenuEntry<TestGameObject, TestMapArchObject, TestArchetype> mapMenuEntry = newMapMenuEntry(title, mapFile); - addMapMenuEntryInt(getSize(), mapMenuEntry); + newMapMenuEntry(title, mapFile, false); } }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2011-03-08 19:24:30
|
Revision: 8854 http://gridarta.svn.sourceforge.net/gridarta/?rev=8854&view=rev Author: akirschbaum Date: 2011-03-08 19:24:23 +0000 (Tue, 08 Mar 2011) Log Message: ----------- Weaken types. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/gui/mapmenu/TreeDragSource.java trunk/src/app/net/sf/gridarta/gui/mapmenu/TreeDropTarget.java trunk/src/app/net/sf/gridarta/gui/misc/RecentManager.java trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java trunk/src/test/net/sf/gridarta/gui/mapmenu/MapMenuManagerTest.java Modified: trunk/src/app/net/sf/gridarta/gui/mapmenu/TreeDragSource.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/mapmenu/TreeDragSource.java 2011-03-08 19:12:05 UTC (rev 8853) +++ trunk/src/app/net/sf/gridarta/gui/mapmenu/TreeDragSource.java 2011-03-08 19:24:23 UTC (rev 8854) @@ -29,7 +29,6 @@ import java.awt.dnd.DragSourceEvent; import java.awt.dnd.DragSourceListener; import javax.swing.JTree; -import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.MutableTreeNode; import javax.swing.tree.TreePath; @@ -139,7 +138,7 @@ return; } - draggedTreeNode = (DefaultMutableTreeNode) selectionPath.getLastPathComponent(); + draggedTreeNode = (MutableTreeNode) selectionPath.getLastPathComponent(); final Cursor cursor; switch (dge.getDragAction()) { case DnDConstants.ACTION_COPY: Modified: trunk/src/app/net/sf/gridarta/gui/mapmenu/TreeDropTarget.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/mapmenu/TreeDropTarget.java 2011-03-08 19:12:05 UTC (rev 8853) +++ trunk/src/app/net/sf/gridarta/gui/mapmenu/TreeDropTarget.java 2011-03-08 19:24:23 UTC (rev 8854) @@ -33,7 +33,6 @@ import java.awt.dnd.DropTargetListener; import java.io.IOException; import javax.swing.JTree; -import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.MutableTreeNode; import javax.swing.tree.TreePath; @@ -94,7 +93,7 @@ final DropTargetContext dropTargetContext = dtde.getDropTargetContext(); final JTree tree = (JTree) dropTargetContext.getComponent(); final TreePath parentTreePath = tree.getClosestPathForLocation(location.x, location.y); - final MutableTreeNode parentTreeNode = (DefaultMutableTreeNode) parentTreePath.getLastPathComponent(); + final MutableTreeNode parentTreeNode = (MutableTreeNode) parentTreePath.getLastPathComponent(); final int dropAction = dtde.getDropAction(); if (dropAction != DnDConstants.ACTION_COPY && dropAction != DnDConstants.ACTION_MOVE) { @@ -111,7 +110,7 @@ final Rectangle parentRectangle = tree.getPathBounds(parentTreePath); final int relativeY = location.y - parentRectangle.y; final TreePath treePath = (TreePath) transferable.getTransferData(flavor); - final MutableTreeNode draggedTreeNode = (DefaultMutableTreeNode) treePath.getLastPathComponent(); + final MutableTreeNode draggedTreeNode = (MutableTreeNode) treePath.getLastPathComponent(); final DefaultTreeModel treeModel = (DefaultTreeModel) tree.getModel(); final MutableTreeNode parent; final int index; Modified: trunk/src/app/net/sf/gridarta/gui/misc/RecentManager.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/misc/RecentManager.java 2011-03-08 19:12:05 UTC (rev 8853) +++ trunk/src/app/net/sf/gridarta/gui/misc/RecentManager.java 2011-03-08 19:24:23 UTC (rev 8854) @@ -20,8 +20,8 @@ package net.sf.gridarta.gui.misc; import java.io.File; -import net.sf.gridarta.gui.mapmenu.AbstractMapMenuPreferences; import net.sf.gridarta.gui.mapmenu.MapMenuEntryMap; +import net.sf.gridarta.gui.mapmenu.MapMenuPreferences; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; @@ -43,7 +43,7 @@ * @param mapManager the map manager to track for opened maps * @param mapMenuPreferences the map menu preferences to use */ - public RecentManager(@NotNull final MapManager<G, A, R> mapManager, @NotNull final AbstractMapMenuPreferences mapMenuPreferences) { + public RecentManager(@NotNull final MapManager<G, A, R> mapManager, @NotNull final MapMenuPreferences mapMenuPreferences) { final MapManagerListener<G, A, R> mapManagerListener = new MapManagerListener<G, A, R>() { /** {@inheritDoc} */ Modified: trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java 2011-03-08 19:12:05 UTC (rev 8853) +++ trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java 2011-03-08 19:24:23 UTC (rev 8854) @@ -79,10 +79,10 @@ import net.sf.gridarta.gui.mapfiles.MapFolderTree; import net.sf.gridarta.gui.mapfiles.MapFolderTreeActions; import net.sf.gridarta.gui.mapimagecache.MapImageCache; -import net.sf.gridarta.gui.mapmenu.AbstractMapMenuPreferences; import net.sf.gridarta.gui.mapmenu.BookmarksMapMenuPreferences; import net.sf.gridarta.gui.mapmenu.MapMenu; import net.sf.gridarta.gui.mapmenu.MapMenuManager; +import net.sf.gridarta.gui.mapmenu.MapMenuPreferences; import net.sf.gridarta.gui.mapmenu.RecentMapMenuPreferences; import net.sf.gridarta.gui.mappropertiesdialog.MapPropertiesDialogFactory; import net.sf.gridarta.gui.mapuserlistener.MapUserListenerManager; @@ -600,7 +600,7 @@ globalSettings.setAutoPopupDocumentation(false); } - final AbstractMapMenuPreferences recentMapMenuPreferences = new RecentMapMenuPreferences(); + final MapMenuPreferences recentMapMenuPreferences = new RecentMapMenuPreferences(); final MapMenuManager<G, A, R> recentMapMenuManager = new MapMenuManager<G, A, R>(recentMapMenuPreferences.getMapMenu(), mapViewsManager, fileControl, mapImageCache); final JMenu recentMenu = MenuUtils.getMenu(menuBar, "recent"); if (recentMenu == null) { Modified: trunk/src/test/net/sf/gridarta/gui/mapmenu/MapMenuManagerTest.java =================================================================== --- trunk/src/test/net/sf/gridarta/gui/mapmenu/MapMenuManagerTest.java 2011-03-08 19:12:05 UTC (rev 8853) +++ trunk/src/test/net/sf/gridarta/gui/mapmenu/MapMenuManagerTest.java 2011-03-08 19:24:23 UTC (rev 8854) @@ -52,7 +52,7 @@ final TestMapControlCreator testMapControlCreator = new TestMapControlCreator(); final File file = File.createTempFile("gridarta", null); - final AbstractMapMenuPreferences mapMenuPreferences = new TestMapMenuPreferences(); + final MapMenuPreferences mapMenuPreferences = new TestMapMenuPreferences(); try { final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl1 = testMapControlCreator.newMapControl(file, "name1", new Size2D(1, 1)); final MapMenuEntryMap mapMenuEntry = new MapMenuEntryMap(new File("test1"), "title1"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2011-10-15 19:50:27
|
Revision: 9022 http://gridarta.svn.sourceforge.net/gridarta/?rev=9022&view=rev Author: akirschbaum Date: 2011-10-15 19:50:20 +0000 (Sat, 15 Oct 2011) Log Message: ----------- Move MapViewBasic.getSelectedSquares() to MapView. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/gui/copybuffer/CopyBuffer.java trunk/src/app/net/sf/gridarta/gui/dialog/replace/ReplaceDialog.java trunk/src/app/net/sf/gridarta/gui/map/mapview/AbstractMapViewBasic.java trunk/src/app/net/sf/gridarta/gui/map/mapview/DefaultMapView.java trunk/src/app/net/sf/gridarta/gui/map/mapview/MapView.java trunk/src/app/net/sf/gridarta/gui/map/mapview/MapViewBasic.java trunk/src/app/net/sf/gridarta/gui/panel/tools/SelectionTool.java trunk/src/app/net/sf/gridarta/mainactions/MainActions.java trunk/src/test/net/sf/gridarta/gui/map/mapview/TestMapView.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/gui/map/mapview/AbstractMapView.java Modified: trunk/src/app/net/sf/gridarta/gui/copybuffer/CopyBuffer.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/copybuffer/CopyBuffer.java 2011-10-15 19:32:30 UTC (rev 9021) +++ trunk/src/app/net/sf/gridarta/gui/copybuffer/CopyBuffer.java 2011-10-15 19:50:20 UTC (rev 9022) @@ -153,7 +153,7 @@ mapModel2.beginTransaction("Cut / Clear"); // TODO: I18N/L10N try { final Collection<G> gameObjectsToDelete = new HashSet<G>(); - for (final MapSquare<G, A, R> square : mapView.getMapViewBasic().getSelectedSquares()) { + for (final MapSquare<G, A, R> square : mapView.getSelectedSquares()) { final int posX = square.getMapX() - selectedRec.x; final int posY = square.getMapY() - selectedRec.y; for (final G gameObject : square) { Modified: trunk/src/app/net/sf/gridarta/gui/dialog/replace/ReplaceDialog.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/dialog/replace/ReplaceDialog.java 2011-10-15 19:32:30 UTC (rev 9021) +++ trunk/src/app/net/sf/gridarta/gui/dialog/replace/ReplaceDialog.java 2011-10-15 19:50:20 UTC (rev 9022) @@ -290,7 +290,7 @@ colonLabel.setText(":"); } - if (mapView.getMapViewBasic().getSelectedSquares().size() > 1) { + if (mapView.getSelectedSquares().size() > 1) { replaceEntireBox.setSelectedIndex(REPLACE_ON_SELECTION); } else { replaceEntireBox.setSelectedIndex(REPLACE_ON_MAP); @@ -314,7 +314,7 @@ line1.add(Box.createVerticalStrut(3)); replaceEntireBox = new JComboBox(new String[] { ActionBuilderUtils.getString(ACTION_BUILDER, "replaceOnMap"), ActionBuilderUtils.getString(ACTION_BUILDER, "replaceOnSelection") }); replaceEntireBox.setToolTipText(ActionBuilderUtils.getString(ACTION_BUILDER, "replaceOn.shortdescription")); - if (mapView.getMapViewBasic().getSelectedSquares().size() > 1) { + if (mapView.getSelectedSquares().size() > 1) { replaceEntireBox.setSelectedIndex(REPLACE_ON_SELECTION); } else { replaceEntireBox.setSelectedIndex(REPLACE_ON_MAP); @@ -471,7 +471,7 @@ mapModel.beginTransaction("Replace"); // TODO: I18N/L10N try { int replaceCount = 0; - for (final MapSquare<G, A, R> square : entireMap ? mapModel : mapView.getMapViewBasic().getSelectedSquares()) { + for (final MapSquare<G, A, R> square : entireMap ? mapModel : mapView.getSelectedSquares()) { // Operate on a copy of the nodes to prevent ConcurrentModificationException // find objects to replace Added: trunk/src/app/net/sf/gridarta/gui/map/mapview/AbstractMapView.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/mapview/AbstractMapView.java (rev 0) +++ trunk/src/app/net/sf/gridarta/gui/map/mapview/AbstractMapView.java 2011-10-15 19:50:20 UTC (rev 9022) @@ -0,0 +1,115 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2011 The Gridarta Developers. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.gui.map.mapview; + +import java.awt.Point; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import net.sf.gridarta.model.archetype.Archetype; +import net.sf.gridarta.model.gameobject.GameObject; +import net.sf.gridarta.model.maparchobject.MapArchObject; +import net.sf.gridarta.model.mapgrid.MapGrid; +import net.sf.gridarta.model.mapmodel.MapModel; +import net.sf.gridarta.model.mapmodel.MapSquare; +import net.sf.gridarta.utils.RandomUtils; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Abstract base class for {@link MapView} implementations. + * @author Andreas Kirschbaum + */ +public abstract class AbstractMapView<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements MapView<G, A, R> { + + /** + * The {@link MapModel} of this map view. + */ + @NotNull + private final MapModel<G, A, R> mapModel; + + /** + * The {@link MapGrid} of this map view. + */ + @NotNull + private final MapGrid mapGrid; + + /** + * Creates a new instance. + * @param mapModel the map model of this map view + * @param mapGrid the map grid of this map view + */ + protected AbstractMapView(@NotNull final MapModel<G, A, R> mapModel, @NotNull final MapGrid mapGrid) { + this.mapModel = mapModel; + this.mapGrid = mapGrid; + } + + /** + * {@inheritDoc} + */ + @NotNull + @Override + public List<MapSquare<G, A, R>> getSelectedSquares() { + final Point[] selectedMapSquares = mapGrid.getSelection(); + final List<MapSquare<G, A, R>> selection = new ArrayList<MapSquare<G, A, R>>(); + for (final Point pos : selectedMapSquares) { + selection.add(mapModel.getMapSquare(pos)); + } + return selection; + } + + /** + * {@inheritDoc} + */ + @NotNull + @Override + public List<G> getSelectedGameObjects() { + final Collection<MapSquare<G, A, R>> selectedMapSquares = getSelectedSquares(); + if (selectedMapSquares.isEmpty()) { + return mapModel.getAllGameObjects(); + } + + final List<G> objects = new ArrayList<G>(); + for (final Iterable<G> mapSquare : selectedMapSquares) { + for (final GameObject<G, A, R> gameObject : mapSquare) { + objects.add(gameObject.getHead()); + } + } + return objects; + } + + /** + * {@inheritDoc} + */ + @Nullable + @Override + public G getSelectedGameObject() { + final List<G> objects = getSelectedGameObjects(); + final int objectSize = objects.size(); + if (objectSize == 0) { + return null; + } + if (objectSize == 1) { + return objects.get(0); + } + return objects.get(RandomUtils.rnd.nextInt(objects.size())); + } + +} Property changes on: trunk/src/app/net/sf/gridarta/gui/map/mapview/AbstractMapView.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Modified: trunk/src/app/net/sf/gridarta/gui/map/mapview/AbstractMapViewBasic.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/mapview/AbstractMapViewBasic.java 2011-10-15 19:32:30 UTC (rev 9021) +++ trunk/src/app/net/sf/gridarta/gui/map/mapview/AbstractMapViewBasic.java 2011-10-15 19:50:20 UTC (rev 9022) @@ -19,16 +19,12 @@ package net.sf.gridarta.gui.map.mapview; -import java.awt.Point; -import java.util.ArrayList; -import java.util.List; 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.mapcursor.MapCursor; import net.sf.gridarta.model.mapgrid.MapGrid; import net.sf.gridarta.model.mapmodel.MapModel; -import net.sf.gridarta.model.mapmodel.MapSquare; import org.jetbrains.annotations.NotNull; /** @@ -39,12 +35,6 @@ public abstract class AbstractMapViewBasic<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements MapViewBasic<G, A, R> { /** - * The {@link MapModel} to display. - */ - @NotNull - private final MapModel<G, A, R> mapModel; - - /** * The {@link MapGrid} of this view. */ @NotNull @@ -61,8 +51,7 @@ * @param mapModel the map model to use */ protected AbstractMapViewBasic(@NotNull final MapModel<G, A, R> mapModel) { - this.mapModel = mapModel; - mapGrid = new MapGrid(this.mapModel.getMapArchObject().getMapSize()); + mapGrid = new MapGrid(mapModel.getMapArchObject().getMapSize()); mapCursor = new MapCursor(mapGrid); } @@ -84,18 +73,4 @@ return mapCursor; } - /** - * {@inheritDoc} - */ - @NotNull - @Override - public List<MapSquare<G, A, R>> getSelectedSquares() { - final Point[] selectedMapSquares = mapGrid.getSelection(); - final List<MapSquare<G, A, R>> selection = new ArrayList<MapSquare<G, A, R>>(); - for (final Point pos : selectedMapSquares) { - selection.add(mapModel.getMapSquare(pos)); - } - return selection; - } - } // class AbstractMapViewBasic 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-15 19:32:30 UTC (rev 9021) +++ trunk/src/app/net/sf/gridarta/gui/map/mapview/DefaultMapView.java 2011-10-15 19:50:20 UTC (rev 9022) @@ -23,11 +23,9 @@ import java.awt.Component; import java.beans.PropertyVetoException; import java.io.File; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; import java.util.Set; import javax.swing.JInternalFrame; +import javax.swing.WindowConstants; import net.sf.gridarta.gui.utils.MenuUtils; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.gameobject.GameObject; @@ -41,7 +39,6 @@ import net.sf.gridarta.model.mapmodel.MapModelListener; import net.sf.gridarta.model.mapmodel.MapSquare; import net.sf.gridarta.model.validation.ErrorCollector; -import net.sf.gridarta.utils.RandomUtils; import net.sf.gridarta.utils.Size2D; import org.apache.log4j.Category; import org.apache.log4j.Logger; @@ -52,7 +49,7 @@ * Default {@link MapView} implementation. * @author Andreas Kirschbaum */ -public class DefaultMapView<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends JInternalFrame implements MapView<G, A, R> { +public class DefaultMapView<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractMapView<G, A, R> { /** * The Logger for printing log messages. @@ -60,15 +57,16 @@ private static final Category log = Logger.getLogger(DefaultMapView.class); /** - * The serial version UID. + * The controller of this view. */ - private static final long serialVersionUID = 1L; + @NotNull + private final MapControl<G, A, R> mapControl; /** - * The controller of this view. + * The {@link JInternalFrame} instance associated with this map view. */ @NotNull - private final MapControl<G, A, R> mapControl; + private final JInternalFrame internalFrame; /** * View number. @@ -175,7 +173,8 @@ * @param pathManager the path manager for converting path names */ public DefaultMapView(@NotNull final MapControl<G, A, R> mapControl, final int number, @NotNull final MapViewBasic<G, A, R> mapViewBasic, @NotNull final PathManager pathManager) { - super(getWindowTitle(mapControl, number, pathManager), true, true, true, true); + super(mapControl.getMapModel(), mapViewBasic.getMapGrid()); + internalFrame = new JInternalFrame(getWindowTitle(mapControl, number, pathManager), true, true, true, true); this.mapControl = mapControl; this.number = number; this.mapViewBasic = mapViewBasic; @@ -184,10 +183,10 @@ mapModel.addMapModelListener(mapModelListener); mapModel.getMapArchObject().addMapArchObjectListener(mapArchObjectListener); mapControl.addMapControlListener(mapControlListener); - getContentPane().setLayout(new BorderLayout()); - getContentPane().add(mapViewBasic.getScrollPane(), BorderLayout.CENTER); - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - setAutoscrolls(true); + internalFrame.getContentPane().setLayout(new BorderLayout()); + internalFrame.getContentPane().add(mapViewBasic.getScrollPane(), BorderLayout.CENTER); + internalFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); + internalFrame.setAutoscrolls(true); } /** @@ -195,58 +194,21 @@ */ @Override public void closeNotify() { - getContentPane().remove(mapViewBasic.getScrollPane()); + internalFrame.getContentPane().remove(mapViewBasic.getScrollPane()); mapViewBasic.closeNotify(); mapControl.removeMapControlListener(mapControlListener); final MapModel<G, A, R> mapModel = mapControl.getMapModel(); mapModel.getMapArchObject().removeMapArchObjectListener(mapArchObjectListener); mapModel.removeMapModelListener(mapModelListener); //mapFileActions.closeNotify(); - MenuUtils.disposeMenuElement(getJMenuBar()); + MenuUtils.disposeMenuElement(internalFrame.getJMenuBar()); } /** - * {@inheritDoc} - */ - @Nullable - @Override - public G getSelectedGameObject() { - final List<G> objects = getSelectedGameObjects(); - final int objectSize = objects.size(); - if (objectSize == 0) { - return null; - } - if (objectSize == 1) { - return objects.get(0); - } - return objects.get(RandomUtils.rnd.nextInt(objects.size())); - } - - /** - * {@inheritDoc} - */ - @NotNull - @Override - public List<G> getSelectedGameObjects() { - final Collection<MapSquare<G, A, R>> selectedMapSquares = mapViewBasic.getSelectedSquares(); - if (selectedMapSquares.isEmpty()) { - return mapControl.getMapModel().getAllGameObjects(); - } - - final List<G> objects = new ArrayList<G>(); - for (final Iterable<G> mapSquare : selectedMapSquares) { - for (final GameObject<G, A, R> gameObject : mapSquare) { - objects.add(gameObject.getHead()); - } - } - return objects; - } - - /** * Update the Map-Window Title (according to name and changeFlag). */ private void updateTitle() { - setTitle(getWindowTitle()); + internalFrame.setTitle(getWindowTitle()); } /** @@ -277,7 +239,7 @@ @NotNull @Override public Component getComponent() { - return this; + return internalFrame; } /** @@ -304,13 +266,13 @@ @Override public void activate() { try { - setSelected(true); + internalFrame.setSelected(true); } catch (final PropertyVetoException e) { log.warn("Unexpected exception", e); } - setVisible(true); - requestFocus(); - restoreSubcomponentFocus(); + internalFrame.setVisible(true); + internalFrame.requestFocus(); + internalFrame.restoreSubcomponentFocus(); } /** @@ -319,7 +281,7 @@ @NotNull @Override public JInternalFrame getInternalFrame() { - return this; + return internalFrame; } } // class MapView 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-15 19:32:30 UTC (rev 9021) +++ trunk/src/app/net/sf/gridarta/gui/map/mapview/MapView.java 2011-10-15 19:50:20 UTC (rev 9022) @@ -26,6 +26,7 @@ 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.mapmodel.MapSquare; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -100,4 +101,11 @@ @NotNull JInternalFrame getInternalFrame(); + /** + * Returns the selected squares. + * @return the selected squares; the list may be modified by the caller + */ + @NotNull + List<MapSquare<G, A, R>> getSelectedSquares(); + } // interface MapView Modified: trunk/src/app/net/sf/gridarta/gui/map/mapview/MapViewBasic.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/mapview/MapViewBasic.java 2011-10-15 19:32:30 UTC (rev 9021) +++ trunk/src/app/net/sf/gridarta/gui/map/mapview/MapViewBasic.java 2011-10-15 19:50:20 UTC (rev 9022) @@ -19,7 +19,6 @@ package net.sf.gridarta.gui.map.mapview; -import java.util.List; import javax.swing.JScrollPane; import net.sf.gridarta.gui.map.renderer.MapRenderer; import net.sf.gridarta.model.archetype.Archetype; @@ -27,7 +26,6 @@ import net.sf.gridarta.model.maparchobject.MapArchObject; import net.sf.gridarta.model.mapcursor.MapCursor; import net.sf.gridarta.model.mapgrid.MapGrid; -import net.sf.gridarta.model.mapmodel.MapSquare; import org.jetbrains.annotations.NotNull; /** @@ -52,13 +50,6 @@ MapCursor getMapCursor(); /** - * Returns the selected squares. - * @return the selected squares; the list may be modified by the caller - */ - @NotNull - List<MapSquare<G, A, R>> getSelectedSquares(); - - /** * Must be called when this renderer is not used anymore. It un-registers * all listeners. */ Modified: trunk/src/app/net/sf/gridarta/gui/panel/tools/SelectionTool.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/panel/tools/SelectionTool.java 2011-10-15 19:32:30 UTC (rev 9021) +++ trunk/src/app/net/sf/gridarta/gui/panel/tools/SelectionTool.java 2011-10-15 19:50:20 UTC (rev 9022) @@ -204,7 +204,7 @@ throw new AssertionError(); } final MapView<G, A, R> mapView = e.getMapView(); - FillUtils.fill(mapView.getMapControl().getMapModel(), mapView.getMapViewBasic().getSelectedSquares(), insertionMode, objectChooser.getSelections(), -1, false); + FillUtils.fill(mapView.getMapControl().getMapModel(), mapView.getSelectedSquares(), insertionMode, objectChooser.getSelections(), -1, false); } } Modified: trunk/src/app/net/sf/gridarta/mainactions/MainActions.java =================================================================== --- trunk/src/app/net/sf/gridarta/mainactions/MainActions.java 2011-10-15 19:32:30 UTC (rev 9021) +++ trunk/src/app/net/sf/gridarta/mainactions/MainActions.java 2011-10-15 19:50:20 UTC (rev 9022) @@ -1074,20 +1074,19 @@ return false; } - final MapViewBasic<G, A, R> mapViewBasic = mapView.getMapViewBasic(); - final List<MapSquare<G, A, R>> selectedSquares = mapViewBasic.getSelectedSquares(); + final List<MapSquare<G, A, R>> selectedSquares = mapView.getSelectedSquares(); if (selectedSquares.isEmpty()) { return false; } - final MapGrid mapGrid = mapViewBasic.getMapGrid(); + final MapGrid mapGrid = mapView.getMapViewBasic().getMapGrid(); final Rectangle selectedRec = mapGrid.getSelectedRec(); if (selectedRec == null) { return false; } if (performAction) { - final MapCursor mapCursor = mapViewBasic.getMapCursor(); + final MapCursor mapCursor = mapView.getMapViewBasic().getMapCursor(); final Point cursorLocation = mapCursor.getLocation(); final Point origin = cursorLocation == null ? selectedRec.getLocation() : cursorLocation; copyBuffer.pasteTiled(mapView, selectedSquares, origin); @@ -1304,7 +1303,7 @@ } boolean foundEmptySelectedSquare = false; - final List<MapSquare<G, A, R>> selectedSquares = mapView.getMapViewBasic().getSelectedSquares(); + final List<MapSquare<G, A, R>> selectedSquares = mapView.getSelectedSquares(); for (final MapSquare<G, A, R> selectedSquare : selectedSquares) { if (selectedSquare.isEmpty()) { foundEmptySelectedSquare = true; @@ -1374,14 +1373,13 @@ return false; } - final MapViewBasic<G, A, R> mapViewBasic = mapView.getMapViewBasic(); - final List<MapSquare<G, A, R>> selectedSquares = mapViewBasic.getSelectedSquares(); + final List<MapSquare<G, A, R>> selectedSquares = mapView.getSelectedSquares(); if (selectedSquares.isEmpty()) { return false; } if (performAction) { - final MapGrid mapGrid = mapViewBasic.getMapGrid(); + final MapGrid mapGrid = mapView.getMapViewBasic().getMapGrid(); final MapModel<G, A, R> mapModel = mapView.getMapControl().getMapModel(); final MapArchObject<A> mapArchObject = mapModel.getMapArchObject(); final Point point = new Point(); @@ -1417,14 +1415,13 @@ return false; } - final MapViewBasic<G, A, R> mapViewBasic = mapView.getMapViewBasic(); - final List<MapSquare<G, A, R>> selectedSquares = mapViewBasic.getSelectedSquares(); + final List<MapSquare<G, A, R>> selectedSquares = mapView.getSelectedSquares(); if (selectedSquares.isEmpty()) { return false; } if (performAction) { - final MapGrid mapGrid = mapViewBasic.getMapGrid(); + final MapGrid mapGrid = mapView.getMapViewBasic().getMapGrid(); final MapModel<G, A, R> mapModel = mapView.getMapControl().getMapModel(); final MapArchObject<A> mapArchObject = mapModel.getMapArchObject(); final Point point = new Point(); @@ -1553,7 +1550,7 @@ * @param insertionMode the insertion mode to use */ private void fill(@NotNull final MapView<G, A, R> mapView, @NotNull final InsertionMode<G, A, R> insertionMode) { - FillUtils.fill(mapView.getMapControl().getMapModel(), mapView.getMapViewBasic().getSelectedSquares(), insertionMode, objectChooser.getSelections(), -1, false); + FillUtils.fill(mapView.getMapControl().getMapModel(), mapView.getSelectedSquares(), insertionMode, objectChooser.getSelections(), -1, false); } /** @@ -1568,7 +1565,7 @@ final int fillDensity = randomFillDialog.getFillDensity(); final boolean noAdjacent = randomFillDialog.isRandomFillSkipAdjacentSquares(); - FillUtils.fill(mapView.getMapControl().getMapModel(), mapView.getMapViewBasic().getSelectedSquares(), insertionMode, objectChooser.getSelections(), fillDensity, noAdjacent); + FillUtils.fill(mapView.getMapControl().getMapModel(), mapView.getSelectedSquares(), insertionMode, objectChooser.getSelections(), fillDensity, noAdjacent); } } // class MainActions Modified: trunk/src/test/net/sf/gridarta/gui/map/mapview/TestMapView.java =================================================================== --- trunk/src/test/net/sf/gridarta/gui/map/mapview/TestMapView.java 2011-10-15 19:32:30 UTC (rev 9021) +++ trunk/src/test/net/sf/gridarta/gui/map/mapview/TestMapView.java 2011-10-15 19:50:20 UTC (rev 9022) @@ -34,7 +34,7 @@ * A {@link MapView} implementation for regression tests. * @author Andreas Kirschbaum */ -public class TestMapView implements MapView<TestGameObject, TestMapArchObject, TestArchetype> { +public class TestMapView extends AbstractMapView<TestGameObject, TestMapArchObject, TestArchetype> { /** * The controller of this view. @@ -54,6 +54,7 @@ * @param mapViewBasic the underlying map view object */ public TestMapView(@NotNull final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl, @NotNull final MapViewBasic<TestGameObject, TestMapArchObject, TestArchetype> mapViewBasic) { + super(mapControl.getMapModel(), mapViewBasic.getMapGrid()); this.mapControl = mapControl; this.mapViewBasic = mapViewBasic; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |