From: <chr...@us...> - 2006-06-25 14:10:59
|
Revision: 188 Author: christianhujer Date: 2006-06-25 07:10:25 -0700 (Sun, 25 Jun 2006) ViewCVS: http://svn.sourceforge.net/gridarta/?rev=188&view=rev Log Message: ----------- Fixed bug in Size2D (package and documentation). Changed MapCursorTest for Size2D. Changed transaction system for MapSquare changes. Modified Paths: -------------- trunk/daimonin/src/daieditor/CMapFileEncode.java trunk/daimonin/src/daieditor/CMapViewBasic.java trunk/daimonin/src/daieditor/CNewMapDialog.java trunk/daimonin/src/daieditor/CopyBuffer.java trunk/daimonin/src/daieditor/arch/ArchObject.java trunk/daimonin/src/daieditor/arch/ArchObjectContainer.java trunk/daimonin/src/daieditor/gui/map/DefaultLevelRenderer.java trunk/daimonin/src/daieditor/gui/map/MapPropertiesDialog.java trunk/daimonin/src/daieditor/gui/map/MapTilePane.java trunk/daimonin/src/daieditor/gui/map/SimpleLevelRenderer.java trunk/daimonin/src/daieditor/map/DefaultMapModel.java trunk/daimonin/src/daieditor/map/MapArchObject.java trunk/daimonin/src/daieditor/map/MapControl.java trunk/daimonin/src/daieditor/map/MapModel.java trunk/daimonin/src/test/daieditor/gui/map/MapCursorTest.java trunk/src/app/net/sf/gridarta/Size2D.java trunk/src/app/net/sf/gridarta/gui/map/MapGrid.java Modified: trunk/daimonin/src/daieditor/CMapFileEncode.java =================================================================== --- trunk/daimonin/src/daieditor/CMapFileEncode.java 2006-06-25 13:25:39 UTC (rev 187) +++ trunk/daimonin/src/daieditor/CMapFileEncode.java 2006-06-25 14:10:25 UTC (rev 188) @@ -24,7 +24,6 @@ package daieditor; -import app.net.sf.gridarta.Size2D; import daieditor.arch.ArchObject; import daieditor.map.MapArchObject; import daieditor.map.MapModel; @@ -36,6 +35,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; +import net.sf.gridarta.Size2D; /** * The <code>CMapFileEncode</code> Modified: trunk/daimonin/src/daieditor/CMapViewBasic.java =================================================================== --- trunk/daimonin/src/daieditor/CMapViewBasic.java 2006-06-25 13:25:39 UTC (rev 187) +++ trunk/daimonin/src/daieditor/CMapViewBasic.java 2006-06-25 14:10:25 UTC (rev 188) @@ -24,7 +24,6 @@ package daieditor; -import app.net.sf.gridarta.Size2D; import daieditor.arch.ArchObject; import daieditor.gui.map.DefaultLevelRenderer; import daieditor.gui.map.MapUserListener; @@ -50,6 +49,7 @@ import javax.imageio.ImageIO; import javax.swing.JScrollPane; import javax.swing.JViewport; +import net.sf.gridarta.Size2D; import net.sf.gridarta.gui.map.MapCursor; import net.sf.gridarta.gui.map.MapCursorEvent; import net.sf.gridarta.gui.map.MapCursorListener; Modified: trunk/daimonin/src/daieditor/CNewMapDialog.java =================================================================== --- trunk/daimonin/src/daieditor/CNewMapDialog.java 2006-06-25 13:25:39 UTC (rev 187) +++ trunk/daimonin/src/daieditor/CNewMapDialog.java 2006-06-25 14:10:25 UTC (rev 188) @@ -25,7 +25,6 @@ package daieditor; -import app.net.sf.gridarta.Size2D; import static net.sf.japi.swing.ActionFactory.getFactory; import static daieditor.CMainControl.PREFS_USERNAME; import static daieditor.CMainControl.PREFS_USERNAME_DEFAULT; @@ -50,6 +49,7 @@ import javax.swing.border.EtchedBorder; import javax.swing.border.TitledBorder; import net.sf.japi.swing.ActionFactory; +import net.sf.gridarta.Size2D; /** * Dialog used to ask the user the properties for the new level. Contains a Modified: trunk/daimonin/src/daieditor/CopyBuffer.java =================================================================== --- trunk/daimonin/src/daieditor/CopyBuffer.java 2006-06-25 13:25:39 UTC (rev 187) +++ trunk/daimonin/src/daieditor/CopyBuffer.java 2006-06-25 14:10:25 UTC (rev 188) @@ -24,7 +24,6 @@ package daieditor; -import app.net.sf.gridarta.Size2D; import static daieditor.CMainControl.rnd; import daieditor.arch.ArchObject; import daieditor.map.MapArchObject; @@ -36,6 +35,7 @@ import java.util.ArrayList; import java.util.List; import org.jetbrains.annotations.Nullable; +import net.sf.gridarta.Size2D; /** * This class manages the cut/copy/paste actions in maps. The data is stored in @@ -148,7 +148,7 @@ } final Point offset = selRec.getLocation(); - mapControl.getMapModel().setAutoCommitSquareChanges(false); + mapControl.getMapModel().beginTransaction(); for (final MapSquare square : mapControl.getMapViewFrame().view.getSelectedSquares()) { final int posx = square.getMapX(); final int posy = square.getMapY(); @@ -178,7 +178,7 @@ } } } - mapControl.getMapModel().setAutoCommitSquareChanges(true); + mapControl.getMapModel().endTransaction(); // finally redraw the map if (mode != Mode.DO_COPY) { mainControl.refreshCurrentMap(); @@ -195,7 +195,7 @@ assert startp != null; // cycle through all tile coordinates which are highlighted: - mapControl.getMapModel().setAutoCommitSquareChanges(false); + mapControl.getMapModel().beginTransaction(); final Point pos = new Point(); assert copyMap != null; ArchObject clone; @@ -240,7 +240,7 @@ } } } - mapControl.getMapModel().setAutoCommitSquareChanges(true); + mapControl.getMapModel().endTransaction(); // now the map and toolbars must be redrawn mapControl.repaint(); @@ -282,7 +282,7 @@ assert p != null; floodfill(mapControl, p.x, p.y, archList); // floodfill } else { - mapControl.getMapModel().setAutoCommitSquareChanges(false); + mapControl.getMapModel().beginTransaction(); for (final Point p : mapControl.getMapViewFrame().view.getSelection()) { if (rand != -1 && rand != 100 && rand < rnd.nextInt(100) + 1) { continue; @@ -296,7 +296,7 @@ mapControl.addArchObjectToMap(arch.createClone(p.x, p.y), fillBelow); } } - mapControl.getMapModel().setAutoCommitSquareChanges(true); + mapControl.getMapModel().endTransaction(); } // now the map and toolbars must be redrawn @@ -420,7 +420,7 @@ final byte[][] area = new byte[mapSize.getWidth()][mapSize.getHeight()]; area[startX][startY] = BORDER; //int iter = 0; - mapControl.getMapModel().setAutoCommitSquareChanges(false); + mapControl.getMapModel().beginTransaction(); int border = 1; while (border > 0) { //iter++; @@ -469,7 +469,7 @@ } } } - mapControl.getMapModel().setAutoCommitSquareChanges(true); + mapControl.getMapModel().endTransaction(); //mainControl.setStatusText("Flood fill took " + (System.currentTimeMillis() - start) + " milliseconds in " + iter + " iterations."); } Modified: trunk/daimonin/src/daieditor/arch/ArchObject.java =================================================================== --- trunk/daimonin/src/daieditor/arch/ArchObject.java 2006-06-25 13:25:39 UTC (rev 187) +++ trunk/daimonin/src/daieditor/arch/ArchObject.java 2006-06-25 14:10:25 UTC (rev 188) @@ -271,6 +271,7 @@ * determined by the various attributes of the arch (->archText). * @param checkType bitmask containing the edit type(s) to be calculated * @return new editType for this arch + * @todo use arch object matchers, eventually deprecated this method and remove it */ public int calculateEditType(final int checkType) { /* if one of the types in checkType already is in editType, Modified: trunk/daimonin/src/daieditor/arch/ArchObjectContainer.java =================================================================== --- trunk/daimonin/src/daieditor/arch/ArchObjectContainer.java 2006-06-25 13:25:39 UTC (rev 187) +++ trunk/daimonin/src/daieditor/arch/ArchObjectContainer.java 2006-06-25 14:10:25 UTC (rev 188) @@ -159,6 +159,18 @@ } /** + * Move an item to top. + * @param arch item to move to top + */ + public final void moveTop(final ArchObject arch) { + getMapSquare().getModel().beginTransaction(); + while (first != arch) { + swap(arch, arch.getNext()); + } + getMapSquare().getModel().endTransaction(); + } + + /** * Move an item up. * @param arch item to move up */ @@ -175,6 +187,18 @@ } /** + * Move an item to top. + * @param arch item to move to top + */ + public final void moveBottom(final ArchObject arch) { + getMapSquare().getModel().beginTransaction(); + while (last != arch) { + swap(arch, arch.getPrev()); + } + getMapSquare().getModel().endTransaction(); + } + + /** * Swap to ArchObjects, exchanging them with each other. * If at least one of <var>a1</var> and <var>a2</var> is <code>null</code>, this method simply does nothing. * @param a1 first ArchObject, maybe <code>null</code> Modified: trunk/daimonin/src/daieditor/gui/map/DefaultLevelRenderer.java =================================================================== --- trunk/daimonin/src/daieditor/gui/map/DefaultLevelRenderer.java 2006-06-25 13:25:39 UTC (rev 187) +++ trunk/daimonin/src/daieditor/gui/map/DefaultLevelRenderer.java 2006-06-25 14:10:25 UTC (rev 188) @@ -25,7 +25,6 @@ package daieditor.gui.map; -import app.net.sf.gridarta.Size2D; import daieditor.CMainControl; import daieditor.IGUIConstants; import daieditor.MultiPositionData; @@ -48,6 +47,7 @@ import net.sf.gridarta.gui.map.MapGrid; import net.sf.gridarta.gui.map.MapGridEvent; import net.sf.gridarta.gui.map.MapGridListener; +import net.sf.gridarta.Size2D; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; Modified: trunk/daimonin/src/daieditor/gui/map/MapPropertiesDialog.java =================================================================== --- trunk/daimonin/src/daieditor/gui/map/MapPropertiesDialog.java 2006-06-25 13:25:39 UTC (rev 187) +++ trunk/daimonin/src/daieditor/gui/map/MapPropertiesDialog.java 2006-06-25 14:10:25 UTC (rev 188) @@ -25,12 +25,12 @@ package daieditor.gui.map; -import app.net.sf.gridarta.Size2D; import static net.sf.japi.swing.ActionFactory.getFactory; import daieditor.CMainControl; import daieditor.CMainView; import daieditor.IGUIConstants; import net.sf.gridarta.help.Help; +import net.sf.gridarta.Size2D; import daieditor.map.MapArchObject; import daieditor.map.MapControl; import java.awt.BorderLayout; Modified: trunk/daimonin/src/daieditor/gui/map/MapTilePane.java =================================================================== --- trunk/daimonin/src/daieditor/gui/map/MapTilePane.java 2006-06-25 13:25:39 UTC (rev 187) +++ trunk/daimonin/src/daieditor/gui/map/MapTilePane.java 2006-06-25 14:10:25 UTC (rev 188) @@ -23,7 +23,6 @@ package daieditor.gui.map; -import app.net.sf.gridarta.Size2D; import static net.sf.japi.swing.ActionFactory.getFactory; import daieditor.CMainControl; import daieditor.IGUIConstants; @@ -60,6 +59,7 @@ import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import net.sf.japi.swing.ActionFactory; +import net.sf.gridarta.Size2D; import org.jetbrains.annotations.Nullable; /** Modified: trunk/daimonin/src/daieditor/gui/map/SimpleLevelRenderer.java =================================================================== --- trunk/daimonin/src/daieditor/gui/map/SimpleLevelRenderer.java 2006-06-25 13:25:39 UTC (rev 187) +++ trunk/daimonin/src/daieditor/gui/map/SimpleLevelRenderer.java 2006-06-25 14:10:25 UTC (rev 188) @@ -25,7 +25,6 @@ package daieditor.gui.map; -import app.net.sf.gridarta.Size2D; import daieditor.CMainControl; import daieditor.IGUIConstants; import daieditor.MultiPositionData; @@ -39,6 +38,7 @@ import java.awt.Rectangle; import java.awt.image.BufferedImage; import javax.swing.ImageIcon; +import net.sf.gridarta.Size2D; /** * The SimpleLevelRenderer renders maps without MapGrid or validation errors. Modified: trunk/daimonin/src/daieditor/map/DefaultMapModel.java =================================================================== --- trunk/daimonin/src/daieditor/map/DefaultMapModel.java 2006-06-25 13:25:39 UTC (rev 187) +++ trunk/daimonin/src/daieditor/map/DefaultMapModel.java 2006-06-25 14:10:25 UTC (rev 188) @@ -25,7 +25,6 @@ package daieditor.map; -import app.net.sf.gridarta.Size2D; import static net.sf.japi.swing.ActionFactory.getFactory; import daieditor.CFArchTypeList; import daieditor.CMainControl; @@ -41,6 +40,7 @@ import java.util.NoSuchElementException; import javax.swing.event.EventListenerList; import net.sf.japi.swing.ActionFactory; +import net.sf.gridarta.Size2D; import org.jetbrains.annotations.Nullable; /** @@ -86,9 +86,12 @@ /** CMainControl. */ private final CMainControl mainControl; - /** MapControl. */ + /** The MapControl that controls this MapModel. */ private final MapControl mapControl; + /** The transaction depth. */ + private int transactionDepth; + /** * Constructs a level model. * @param mainControl main controller @@ -178,7 +181,10 @@ } } - /** Reset the level changed flag to false. */ + /** + * Reset the level changed flag to false. + * @todo it's not a good idea to use the mapViewFrame here + */ public void resetLevelChangedFlag() { if (!levelChanged) { return; @@ -191,7 +197,10 @@ } } - /** Set the level changed flag to true. */ + /** + * Set the level changed flag to true. + * @todo it's not a good idea to use the mapViewFrame here + */ public void setLevelChangedFlag() { if (levelChanged) { return; @@ -575,22 +584,17 @@ fireMapSizeChanged(); } + /** {@inheritDoc} */ public MapControl getMapControl() { return mapControl; } - /** - * Register a map listener. - * @param listener MapListener to register - */ + /** {@inheritDoc} */ public void addMapModelListener(final MapModelListener listener) { listenerList.add(MapModelListener.class, listener); } - /** - * Unregister a map listener. - * @param listener MapListener to unregsiter - */ + /** {@inheritDoc} */ public void removeMapModelListener(final MapModelListener listener) { listenerList.remove(MapModelListener.class, listener); } @@ -609,55 +613,44 @@ /** The ArrayList with changed squares. */ private final List<MapSquare> changedSquares = new ArrayList<MapSquare>(); - /** Wether in autocommit mode. */ - private boolean autoCommitSquareChanges = true; + /** {@inheritDoc} */ + public void squareChanged(final MapSquare square) { + if (transactionDepth == 0) { + fireMapSquaresChangedEvent(square); + } else { + synchronized (changedSquares) { + changedSquares.add(square); + } + } + } - /** - * Set the autocommit mode for square changes. - * Invoking this method also fires any pending events, independently of the argument. - * @param autoCommitSquareChanges <code>true</code> if every single square change should fire an event, <code>false</code> for bulk changes - * @see #isAutoCommitSquareChanges() - */ - public void setAutoCommitSquareChanges(final boolean autoCommitSquareChanges) { - this.autoCommitSquareChanges = autoCommitSquareChanges; - commitSquareChanges(); + /** {@inheritDoc} */ + public void beginTransaction() { + transactionDepth++; } - /** - * Get the autocommit mode for square changes. - * @return autocommit mode for square changes - * @see #setAutoCommitSquareChanges(boolean) - */ - public boolean isAutoCommitSquareChanges() { - return autoCommitSquareChanges; + /** {@inheritDoc} */ + public void endTransaction() { + transactionDepth--; + assert transactionDepth >= 0; + if (transactionDepth == 0 && !changedSquares.isEmpty()) { + fireMapSquaresChangedEvent(changedSquares.toArray(new MapSquare[changedSquares.size()])); + } } - /** - * Commits all squareChanges. - * If there are no changed squares, this method does nothing. - * Listeners are not notified with an empty list of squares. - */ - public void commitSquareChanges() { - synchronized (changedSquares) { + /** {@inheritDoc} */ + public void endAllTransactions() { + if (transactionDepth > 0) { + transactionDepth = 0; if (!changedSquares.isEmpty()) { fireMapSquaresChangedEvent(changedSquares.toArray(new MapSquare[changedSquares.size()])); } } } - /** - * Method to notify the model that a map square was changed. - * The model then notifies the registered listeners of the changes. - * @param square MapSquare that has changed - */ - public void squareChanged(final MapSquare square) { - if (autoCommitSquareChanges) { - fireMapSquaresChangedEvent(square); - } else { - synchronized (changedSquares) { - changedSquares.add(square); - } - } + /** {@inheritDoc} */ + public int getTransactionDepth() { + return transactionDepth; } /** Modified: trunk/daimonin/src/daieditor/map/MapArchObject.java =================================================================== --- trunk/daimonin/src/daieditor/map/MapArchObject.java 2006-06-25 13:25:39 UTC (rev 187) +++ trunk/daimonin/src/daieditor/map/MapArchObject.java 2006-06-25 14:10:25 UTC (rev 188) @@ -24,11 +24,11 @@ package daieditor.map; -import app.net.sf.gridarta.Size2D; import static daieditor.IGUIConstants.DEF_MAPFNAME; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; +import net.sf.gridarta.Size2D; /** * MapArchObject contains the specific meta data about a map that is stored in Modified: trunk/daimonin/src/daieditor/map/MapControl.java =================================================================== --- trunk/daimonin/src/daieditor/map/MapControl.java 2006-06-25 13:25:39 UTC (rev 187) +++ trunk/daimonin/src/daieditor/map/MapControl.java 2006-06-25 14:10:25 UTC (rev 188) @@ -24,7 +24,6 @@ package daieditor.map; -import app.net.sf.gridarta.Size2D; import daieditor.CMainControl; import daieditor.CMapViewIFrame; import daieditor.CPickmapPanel; @@ -49,6 +48,7 @@ import javax.swing.ImageIcon; import net.sf.gridarta.gui.map.MapCursor; import net.sf.gridarta.gui.map.MapGrid; +import net.sf.gridarta.Size2D; import net.sf.japi.swing.ActionFactory; import static net.sf.japi.swing.ActionFactory.getFactory; import org.jetbrains.annotations.Nullable; @@ -478,11 +478,11 @@ if (!mainControl.getMainView().isPickmapActive() || isPickmap() || newarch != null && newarch.isDefaultArch()) { // insert default arch from archlist: - mapModel.setAutoCommitSquareChanges(false); + mapModel.beginTransaction(); if (!addArchToMap(mainControl.getPanelArchName(), p, allowMany)) { // todo } - mapModel.setAutoCommitSquareChanges(true); + mapModel.endTransaction(); } else { // insert custom arch from the pickmap: if (newarch != null) { Modified: trunk/daimonin/src/daieditor/map/MapModel.java =================================================================== --- trunk/daimonin/src/daieditor/map/MapModel.java 2006-06-25 13:25:39 UTC (rev 187) +++ trunk/daimonin/src/daieditor/map/MapModel.java 2006-06-25 14:10:25 UTC (rev 188) @@ -1,10 +1,9 @@ package daieditor.map; -import app.net.sf.gridarta.Size2D; import daieditor.arch.ArchObject; -import java.awt.Dimension; import java.awt.Point; import java.util.Iterator; +import net.sf.gridarta.Size2D; import org.jetbrains.annotations.Nullable; /** @@ -96,18 +95,70 @@ void resizeMap(Size2D newSize); + /** + * Returns the MapControl that controls this MapModel. + * @return the MapControl that controls this MapModel + */ MapControl getMapControl(); + /** + * Register a map listener. + * @param listener MapListener to register + */ void addMapModelListener(MapModelListener listener); + /** + * Unregister a map listener. + * @param listener MapListener to unregsiter + */ void removeMapModelListener(MapModelListener listener); - void setAutoCommitSquareChanges(boolean autoCommitSquareChanges); + /** + * Method to notify the model that a map square was changed. + * A change to a square is atomic if {@link #getTransactionDepth()} returns 0, otherwise it is transactional. + * The model then notifies the registered listeners of the changes. + * @param square MapSquare that has changed + */ + void squareChanged(MapSquare square); - boolean isAutoCommitSquareChanges(); + /** + * Start a new transaction. + * Transactions may be nested. + * Transactions serve the purpose of firing events to the views when more changes are known to come before the view is really required to update. + * Each invocation of {@link #beginTransaction()} requires its own invocation of {@link #endTransaction()}. + * @see #endTransaction() + * @see #getTransactionDepth() + * @see #endAllTransactions() + */ + void beginTransaction(); - void commitSquareChanges(); + /** + * End a transaction. + * Invoking this method will reduce the transaction depth by only 1. + * @see #beginTransaction() + * @see #getTransactionDepth() + * @see #endAllTransactions() + */ + void endTransaction(); - void squareChanged(MapSquare square); + /** + * Ends all transaction. + * Invoking this method will reduce set the transaction depth to 0. + * You shouldn't invoke this method regularly. + * It is meant as a fallback in high level methods / exception handlers to prevent errors from causing unclosed transactions. + * @see #beginTransaction() + * @see #getTransactionDepth() + */ + void endAllTransactions(); + /** + * Get the transaction depth, which is the number of {@link #beginTransaction()} invocations without matching {@link #endTransaction()} invocations. + * A transaction depth of 0 means there is no ongoing transaction. + * @return transaction depth + * @see #beginTransaction() + * @see #endTransaction() + * @see #endAllTransactions() + */ + int getTransactionDepth(); + } // interface MapModel Modified: trunk/daimonin/src/test/daieditor/gui/map/MapCursorTest.java =================================================================== --- trunk/daimonin/src/test/daieditor/gui/map/MapCursorTest.java 2006-06-25 13:25:39 UTC (rev 187) +++ trunk/daimonin/src/test/daieditor/gui/map/MapCursorTest.java 2006-06-25 14:10:25 UTC (rev 188) @@ -28,6 +28,7 @@ import net.sf.gridarta.gui.map.MapCursorEvent; import net.sf.gridarta.gui.map.MapCursorListener; import net.sf.gridarta.gui.map.MapGrid; +import net.sf.gridarta.Size2D; import org.junit.AfterClass; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -41,7 +42,7 @@ /** This class is testing #MapCursor. */ public class MapCursorTest implements MapCursorListener { private static MapCursor cursor; - private static final Dimension gridSize = new Dimension(6, 7); + private static final Size2D gridSize = new Size2D(6, 7); private static final MapGrid grid = new MapGrid(gridSize); private static int changedPosCounter = 0; private static int changedModeCounter = 0; @@ -62,7 +63,7 @@ @Test public void setOutside() { final Point p = new Point(); - for (int i = -2; i < gridSize.width + 2; i++) { + for (int i = -2; i < gridSize.getWidth() + 2; i++) { p.setLocation(i, -1); assertFalse("setLocation(" + p + ") should return false", cursor.setLocation(p)); testEvents(0, 0); @@ -70,7 +71,7 @@ testEvents(0, 0); assertNull("getLocation() should return null after setLocation(" + p + ")", cursor.getLocation()); testEvents(0, 0); - p.setLocation(i, gridSize.height); + p.setLocation(i, gridSize.getHeight()); assertFalse("setLocation(" + p + ") should return false", cursor.setLocation(p)); testEvents(0, 0); assertFalse("MapCursor should be disabled after setLocation(" + p + ")", cursor.isActive()); @@ -78,7 +79,7 @@ assertNull("getLocation() should return null after setLocation(" + p + ")", cursor.getLocation()); testEvents(0, 0); } - for (int i = -2; i < gridSize.height + 2; i++) { + for (int i = -2; i < gridSize.getHeight() + 2; i++) { p.setLocation(-1, i); assertFalse("setLocation(" + p + ") should return false", cursor.setLocation(p)); testEvents(0, 0); @@ -86,7 +87,7 @@ testEvents(0, 0); assertNull("getLocation() should return null after setLocation(" + p + ")", cursor.getLocation()); testEvents(0, 0); - p.setLocation(gridSize.width, i); + p.setLocation(gridSize.getWidth(), i); assertFalse("setLocation(" + p + ") should return false", cursor.setLocation(p)); testEvents(0, 0); assertFalse("MapCursor should be disabled after setLocation(" + p + ")", cursor.isActive()); @@ -99,8 +100,8 @@ @Test public void setInside() { boolean first = true; final Point p = new Point(); - for (int j = 0; j < gridSize.height; j++) { - for (int i = 0; i < gridSize.width; i++) { + for (int j = 0; j < gridSize.getHeight(); j++) { + for (int i = 0; i < gridSize.getWidth(); i++) { p.setLocation(i, j); assertTrue("setLocation(" + p + ") should return true", cursor.setLocation(p)); if (first) { @@ -177,10 +178,10 @@ @Test public void isOnGrid() { final Point p = new Point(); - for (int j = -2; j < gridSize.height + 2; j++) { - for (int i = -2; i < gridSize.width + 2; i++) { + for (int j = -2; j < gridSize.getHeight() + 2; j++) { + for (int i = -2; i < gridSize.getWidth() + 2; i++) { p.setLocation(i, j); - if (i >= 0 && i < gridSize.width && j >= 0 && j < gridSize.height) { + if (i >= 0 && i < gridSize.getWidth() && j >= 0 && j < gridSize.getHeight()) { assertTrue(p + " should be on the grid.", cursor.isOnGrid(p)); } else { assertFalse(p + " should not be on the grid.", cursor.isOnGrid(p)); @@ -273,8 +274,8 @@ minY = end.y; maxY = start.y; } - for (int j = 0; j < gridSize.height; j++) { - for (int i = 0; i < gridSize.width; i++) { + for (int j = 0; j < gridSize.getHeight(); j++) { + for (int i = 0; i < gridSize.getWidth(); i++) { if (i < minX || i > maxX || j < minY || j > maxY) { //Not preselected assertFalse("Preselection", (grid.getFlags(i, j) & MapGrid.GRID_FLAG_SELECTING) > 0); @@ -314,7 +315,7 @@ @Test public void selecting() { final Point start = new Point(2, 3); final Point end = new Point(4, 5); - final Point gridMaxIndex = new Point(gridSize.width - 1 , gridSize.height - 1); + final Point gridMaxIndex = new Point(gridSize.getWidth() - 1 , gridSize.getHeight() - 1); cursor.dragRelease(); testEvents(0, 0); cursor.setLocation(start); Modified: trunk/src/app/net/sf/gridarta/Size2D.java =================================================================== --- trunk/src/app/net/sf/gridarta/Size2D.java 2006-06-25 13:25:39 UTC (rev 187) +++ trunk/src/app/net/sf/gridarta/Size2D.java 2006-06-25 14:10:25 UTC (rev 188) @@ -18,43 +18,56 @@ * 02111-1307, USA. */ -package app.net.sf.gridarta; +package net.sf.gridarta; /** * The class Size2D represents a 2d rectangular area. */ -public final class Size2D -{ +public final class Size2D { - /** The width of the area. It is always positive. */ + /** + * The width of the area. + * It is always greater than zero. + */ private final int width; - /** The height of the area. It is always positive. */ + /** + * The height of the area. + * It is always greater than zero. + */ private final int height; /** - * Create a new instance. - * @param width the width of the area; must be positive - * @param height the height of the area; must be positive + * Create a new Size2D. + * @param width the width of the area; must be greater than zero + * @param height the height of the area; must be greater than zero */ public Size2D(final int width, final int height) { if (width < 1) { - throw new IllegalArgumentException("Width must be positive"); + throw new IllegalArgumentException("Width must be > 0"); } if (height < 1) { - throw new IllegalArgumentException("Height must be positive"); + throw new IllegalArgumentException("Height must be > 0"); } this.width = width; this.height = height; } - /** Return the width of this area. It is always positive. */ + /** + * Returns the width of the area. + * It is always greater than zero. + * @return the width of the area + */ public int getWidth() { return width; } - /** Return the height of this area. It is always positive. */ + /** + * Returns the height of the area. + * It is always greater than zero. + * @return the height of the area + */ public int getHeight() { return height; } Modified: trunk/src/app/net/sf/gridarta/gui/map/MapGrid.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/MapGrid.java 2006-06-25 13:25:39 UTC (rev 187) +++ trunk/src/app/net/sf/gridarta/gui/map/MapGrid.java 2006-06-25 14:10:25 UTC (rev 188) @@ -21,12 +21,11 @@ package net.sf.gridarta.gui.map; - -import app.net.sf.gridarta.Size2D; import java.awt.Point; import java.awt.Rectangle; import static java.lang.Math.min; import javax.swing.event.EventListenerList; +import net.sf.gridarta.Size2D; import org.jetbrains.annotations.Nullable; /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |