You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(103) |
Jun
(121) |
Jul
(16) |
Aug
(67) |
Sep
(126) |
Oct
(161) |
Nov
(164) |
Dec
(588) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(394) |
Feb
(181) |
Mar
(131) |
Apr
(180) |
May
(255) |
Jun
(11) |
Jul
(79) |
Aug
(70) |
Sep
(274) |
Oct
(138) |
Nov
(195) |
Dec
(8) |
2008 |
Jan
(3) |
Feb
(142) |
Mar
(162) |
Apr
(124) |
May
(148) |
Jun
(157) |
Jul
(425) |
Aug
(373) |
Sep
(264) |
Oct
(315) |
Nov
(225) |
Dec
(6) |
2009 |
Jan
(67) |
Feb
(78) |
Mar
(279) |
Apr
(294) |
May
(92) |
Jun
(65) |
Jul
(134) |
Aug
(41) |
Sep
(138) |
Oct
(125) |
Nov
(126) |
Dec
(122) |
2010 |
Jan
(15) |
Feb
(48) |
Mar
(9) |
Apr
(195) |
May
(373) |
Jun
(507) |
Jul
(42) |
Aug
(16) |
Sep
(38) |
Oct
(81) |
Nov
(64) |
Dec
(18) |
2011 |
Jan
(13) |
Feb
(12) |
Mar
(39) |
Apr
(1) |
May
(2) |
Jun
(27) |
Jul
(27) |
Aug
(31) |
Sep
(14) |
Oct
(102) |
Nov
(20) |
Dec
(37) |
2012 |
Jan
(22) |
Feb
(1) |
Mar
(1) |
Apr
(2) |
May
(2) |
Jun
(18) |
Jul
(6) |
Aug
(1) |
Sep
(1) |
Oct
|
Nov
|
Dec
|
2013 |
Jan
(1) |
Feb
(2) |
Mar
(1) |
Apr
(1) |
May
(47) |
Jun
(7) |
Jul
(107) |
Aug
|
Sep
|
Oct
(112) |
Nov
(31) |
Dec
(17) |
2014 |
Jan
(29) |
Feb
(111) |
Mar
(34) |
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
(18) |
Dec
(10) |
From: <aki...@us...> - 2010-12-05 10:17:31
|
Revision: 8810 http://gridarta.svn.sourceforge.net/gridarta/?rev=8810&view=rev Author: akirschbaum Date: 2010-12-05 10:17:25 +0000 (Sun, 05 Dec 2010) Log Message: ----------- Fix display issues in map preview tool. [Atrinik, Daimonin] Modified Paths: -------------- trunk/atrinik/ChangeLog trunk/daimonin/ChangeLog trunk/src/app/net/sf/gridarta/gui/map/renderer/SimpleIsoMapRenderer.java Modified: trunk/atrinik/ChangeLog =================================================================== --- trunk/atrinik/ChangeLog 2010-12-05 10:03:28 UTC (rev 8809) +++ trunk/atrinik/ChangeLog 2010-12-05 10:17:25 UTC (rev 8810) @@ -1,3 +1,7 @@ +2010-12-05 Andreas Kirschbaum + + * Fix display issues in map preview tool. + 2010-11-24 Andreas Kirschbaum * Fix keyboard shortcuts of the go map and find archetype dialogs Modified: trunk/daimonin/ChangeLog =================================================================== --- trunk/daimonin/ChangeLog 2010-12-05 10:03:28 UTC (rev 8809) +++ trunk/daimonin/ChangeLog 2010-12-05 10:17:25 UTC (rev 8810) @@ -1,3 +1,7 @@ +2010-12-05 Andreas Kirschbaum + + * Fix display issues in map preview tool. + 2010-11-24 Andreas Kirschbaum * Fix keyboard shortcuts of the go map and find archetype dialogs Modified: trunk/src/app/net/sf/gridarta/gui/map/renderer/SimpleIsoMapRenderer.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/renderer/SimpleIsoMapRenderer.java 2010-12-05 10:03:28 UTC (rev 8809) +++ trunk/src/app/net/sf/gridarta/gui/map/renderer/SimpleIsoMapRenderer.java 2010-12-05 10:17:25 UTC (rev 8810) @@ -88,10 +88,7 @@ protected void paint(@NotNull final Graphics2D graphics2D, final int xStart, final int yStart, @NotNull final G gameObject) { final GameObject<G, A, R> head = gameObject.getHead(); final ImageIcon icon = "trans.101".equals(head.getFaceObjName()) ? unknownSquareIcon : head.getNormalImage(); - int yOffset = 0; - if (icon.getIconHeight() > isoMapSquareInfo.getYLen()) { - yOffset = icon.getIconHeight() - isoMapSquareInfo.getYLen(); - } + final int yOffset = icon.getIconHeight() - isoMapSquareInfo.getYLen(); if (head.getMultiRefCount() > 0) { // multi-part images have to be painted with correct offset // TODO: This should be improved, especially regarding multi arch mobs inside spawn points. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2010-12-05 10:03:34
|
Revision: 8809 http://gridarta.svn.sourceforge.net/gridarta/?rev=8809&view=rev Author: akirschbaum Date: 2010-12-05 10:03:28 +0000 (Sun, 05 Dec 2010) Log Message: ----------- Unify renderer code. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/gui/map/renderer/SimpleIsoMapRenderer.java Modified: trunk/src/app/net/sf/gridarta/gui/map/renderer/SimpleIsoMapRenderer.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/renderer/SimpleIsoMapRenderer.java 2010-12-05 10:00:24 UTC (rev 8808) +++ trunk/src/app/net/sf/gridarta/gui/map/renderer/SimpleIsoMapRenderer.java 2010-12-05 10:03:28 UTC (rev 8809) @@ -86,39 +86,37 @@ */ @Override protected void paint(@NotNull final Graphics2D graphics2D, final int xStart, final int yStart, @NotNull final G gameObject) { - final BaseObject<G, A, R, ?> tmpNode = gameObject.isMulti() ? gameObject : null; - final GameObject<G, A, R> node = gameObject.getHead(); - final ImageIcon img = "trans.101".equals(node.getFaceObjName()) ? unknownSquareIcon : node.getNormalImage(); - int yOff = 0; - if (img.getIconHeight() > isoMapSquareInfo.getYLen()) { - yOff = img.getIconHeight() - isoMapSquareInfo.getYLen(); + final GameObject<G, A, R> head = gameObject.getHead(); + final ImageIcon icon = "trans.101".equals(head.getFaceObjName()) ? unknownSquareIcon : head.getNormalImage(); + int yOffset = 0; + if (icon.getIconHeight() > isoMapSquareInfo.getYLen()) { + yOffset = icon.getIconHeight() - isoMapSquareInfo.getYLen(); } - if (node.isMulti() && node.getMultiRefCount() > 0) { + if (head.getMultiRefCount() > 0) { // multi-part images have to be painted with correct offset // TODO: This should be improved, especially regarding multi arch mobs inside spawn points. - if (tmpNode != null && tmpNode.getArchetype().isLowestPart() || node.getArchetype().isLowestPart()) { - final int x = xStart - multiPositionData.getXOffset(node.getArchetype().getMultiShapeID(), tmpNode == null ? node.getArchetype().getMultiPartNr() : tmpNode.getArchetype().getMultiPartNr()); - final int y = yStart - yOff + multiPositionData.getYOffset(node.getArchetype().getMultiShapeID(), tmpNode == null ? node.getArchetype().getMultiPartNr() : tmpNode.getArchetype().getMultiPartNr()); - graphics2D.drawImage(img.getImage(), x, y, img.getImageObserver()); + final BaseObject<G, A, R, ?> tmpNode = gameObject.isMulti() ? gameObject : null; + final int x = xStart - multiPositionData.getXOffset(head.getArchetype().getMultiShapeID(), tmpNode == null ? head.getArchetype().getMultiPartNr() : tmpNode.getArchetype().getMultiPartNr()); + final int y = yStart - yOffset + multiPositionData.getYOffset(head.getArchetype().getMultiShapeID(), tmpNode == null ? head.getArchetype().getMultiPartNr() : tmpNode.getArchetype().getMultiPartNr()); + if (tmpNode != null && tmpNode.getArchetype().isLowestPart() || head.getArchetype().isLowestPart()) { + icon.paintIcon(this, graphics2D, x, y); } else { - final BaseObject<G, A, R, ?> env = node.getContainerGameObject(); + final BaseObject<G, A, R, ?> env = head.getContainerGameObject(); if (env != null && env.getTypeNo() == spawnPointTypeNo) { - final int x = xStart - multiPositionData.getXOffset(node.getArchetype().getMultiShapeID(), tmpNode == null ? node.getArchetype().getMultiPartNr() : tmpNode.getArchetype().getMultiPartNr()); - final int y = yStart - yOff + multiPositionData.getYOffset(node.getArchetype().getMultiShapeID(), tmpNode == null ? node.getArchetype().getMultiPartNr() : tmpNode.getArchetype().getMultiPartNr()); - graphics2D.drawImage(img.getImage(), x, y, img.getImageObserver()); + icon.paintIcon(this, graphics2D, x, y); } } } else { - int xOff = 0; - if (img.getIconWidth() > isoMapSquareInfo.getXLen()) { - xOff = (img.getIconWidth() - isoMapSquareInfo.getXLen()) / 2; + int xOffset = 0; + if (icon.getIconWidth() > isoMapSquareInfo.getXLen()) { + xOffset = (icon.getIconWidth() - isoMapSquareInfo.getXLen()) / 2; } - graphics2D.drawImage(img.getImage(), xStart - xOff, yStart - yOff, img.getImageObserver()); + icon.paintIcon(this, graphics2D, xStart - xOffset, yStart - yOffset); } // Paint first object (most likely a mob) in spawn points. - if (node.getTypeNo() == spawnPointTypeNo) { - final G mob = node.getFirst(); + if (head.getTypeNo() == spawnPointTypeNo) { + final G mob = head.getFirst(); if (mob != null) { paint(graphics2D, xStart, yStart, mob); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2010-12-05 10:00:30
|
Revision: 8808 http://gridarta.svn.sourceforge.net/gridarta/?rev=8808&view=rev Author: akirschbaum Date: 2010-12-05 10:00:24 +0000 (Sun, 05 Dec 2010) Log Message: ----------- Merge duplicated code. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/gui/map/renderer/AbstractIsoMapRenderer.java Modified: trunk/src/app/net/sf/gridarta/gui/map/renderer/AbstractIsoMapRenderer.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/renderer/AbstractIsoMapRenderer.java 2010-11-26 19:36:07 UTC (rev 8807) +++ trunk/src/app/net/sf/gridarta/gui/map/renderer/AbstractIsoMapRenderer.java 2010-12-05 10:00:24 UTC (rev 8808) @@ -535,12 +535,14 @@ // multi-part images have to be painted with correct offset // TODO: This should be improved, especially regarding multi arch mobs inside spawn points. final BaseObject<G, A, R, ?> tmpNode = gameObject.isMulti() ? gameObject : null; + final int x = xStart - multiPositionData.getXOffset(head.getArchetype().getMultiShapeID(), tmpNode == null ? head.getArchetype().getMultiPartNr() : tmpNode.getArchetype().getMultiPartNr()); + final int y = yStart - yOffset + multiPositionData.getYOffset(head.getArchetype().getMultiShapeID(), tmpNode == null ? head.getArchetype().getMultiPartNr() : tmpNode.getArchetype().getMultiPartNr()); if (tmpNode != null && tmpNode.getArchetype().isLowestPart() || head.getArchetype().isLowestPart()) { - icon.paintIcon(this, g, xStart - multiPositionData.getXOffset(head.getArchetype().getMultiShapeID(), tmpNode == null ? head.getArchetype().getMultiPartNr() : tmpNode.getArchetype().getMultiPartNr()), yStart - yOffset + multiPositionData.getYOffset(head.getArchetype().getMultiShapeID(), tmpNode == null ? head.getArchetype().getMultiPartNr() : tmpNode.getArchetype().getMultiPartNr())); + icon.paintIcon(this, g, x, y); } else { final BaseObject<G, A, R, ?> env = head.getContainerGameObject(); if (env != null && isSpawnPoint(env)) { - icon.paintIcon(this, g, xStart - multiPositionData.getXOffset(head.getArchetype().getMultiShapeID(), tmpNode == null ? head.getArchetype().getMultiPartNr() : tmpNode.getArchetype().getMultiPartNr()), yStart - yOffset + multiPositionData.getYOffset(head.getArchetype().getMultiShapeID(), tmpNode == null ? head.getArchetype().getMultiPartNr() : tmpNode.getArchetype().getMultiPartNr())); + icon.paintIcon(this, g, x, y); } } } else { @@ -550,6 +552,7 @@ } icon.paintIcon(this, g, xStart - xOffset, yStart - yOffset); } + // Paint first object (most likely a mob) in spawn points. if (isSpawnPoint(head)) { final G mob = head.getFirst(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2010-11-26 19:36:13
|
Revision: 8807 http://gridarta.svn.sourceforge.net/gridarta/?rev=8807&view=rev Author: akirschbaum Date: 2010-11-26 19:36:07 +0000 (Fri, 26 Nov 2010) Log Message: ----------- Accelerate map renderer when smoothing is enabled. [Crossfire] Modified Paths: -------------- trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/gui/map/renderer/FlatMapRenderer.java Modified: trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/gui/map/renderer/FlatMapRenderer.java =================================================================== --- trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/gui/map/renderer/FlatMapRenderer.java 2010-11-26 19:19:40 UTC (rev 8806) +++ trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/gui/map/renderer/FlatMapRenderer.java 2010-11-26 19:36:07 UTC (rev 8807) @@ -315,10 +315,10 @@ smoothingRenderer.paintSmooth(g, square.getMapX(), square.getMapY(), node.getAttributeInt("smoothlevel", true), layer, false, borderOffsetX, borderOffsetY); } } - if (layer > -1) { - smoothingRenderer.paintSmooth(g, square.getMapX(), square.getMapY(), 1, layer + 1, true, borderOffsetX, borderOffsetY); - } } + if (layer > -1) { + smoothingRenderer.paintSmooth(g, square.getMapX(), square.getMapY(), 1, layer + 1, true, borderOffsetX, borderOffsetY); + } } else { for (final GameObject node : square) { filterControl.objectInSquare(filterState, node); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2010-11-26 19:19:47
|
Revision: 8806 http://gridarta.svn.sourceforge.net/gridarta/?rev=8806&view=rev Author: akirschbaum Date: 2010-11-26 19:19:40 +0000 (Fri, 26 Nov 2010) Log Message: ----------- Accelerate map renderer when smoothing is enabled. [Crossfire] Modified Paths: -------------- trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/gui/map/renderer/SmoothingRenderer.java Modified: trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/gui/map/renderer/SmoothingRenderer.java =================================================================== --- trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/gui/map/renderer/SmoothingRenderer.java 2010-11-24 09:44:46 UTC (rev 8805) +++ trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/gui/map/renderer/SmoothingRenderer.java 2010-11-26 19:19:40 UTC (rev 8806) @@ -34,11 +34,30 @@ import org.jetbrains.annotations.NotNull; /** - * Abstract base class for Crossfire related renderers that support smoothing. + * Renderer for smoothed faces as used by Crossfire. + * @author tchize * @author Andreas Kirschbaum */ public class SmoothingRenderer { + @NotNull + private static final int[] dx = { 1, 2, 2, 2, 1, 0, 0, 0, }; + + @NotNull + private static final int[] dy = { 0, 0, 1, 2, 2, 2, 1, 0, }; + + @NotNull + private static final int[] bWeights = { 2, 0, 4, 0, 8, 0, 1, 0, }; + + @NotNull + private static final int[] cWeights = { 0, 2, 0, 4, 0, 8, 0, 1, }; + + @NotNull + private static final int[] bcExclude = { 1 + 2, /*north exclude northwest (bit0) and northeast(bit1)*/ + 0, 2 + 4, /*east exclude northeast and southeast*/ + 0, 4 + 8, /*and so on*/ + 0, 8 + 1, 0 }; + /** * The {@link MapModel} to render. */ @@ -57,6 +76,15 @@ @NotNull private final FaceObjectProviders faceObjectProviders; + @NotNull + private final net.sf.gridarta.model.gameobject.GameObject<?, ?, ?>[][] layerNode = new net.sf.gridarta.model.gameobject.GameObject<?, ?, ?>[3][3]; + + @NotNull + private final int[] sLevels = new int[8]; + + @NotNull + private final FaceObject[] sFaces = new FaceObject[8]; + /** * Creates a new instance. * @param mapModel the map model to render @@ -78,123 +106,129 @@ * @param x the x-coordinate of the map square to draw, in map coordinates * @param y the y-coordinate of the map square to draw, in map coordinates * @param level the limit smoothlevel (smooth levels above this are drawn) - * @param layer the layer (map z coordinate) to draw. Note that invisible - * objects are supposed to not use a layer, to stay coherent with client - * behavior + * @param firstLayer the layer (map z coordinate) to draw. Note that + * invisible objects are supposed to not use a layer, to stay coherent with + * client behavior * @param allLayers whether or not to draw also layers above current one * @param borderOffsetX the border x offset * @param borderOffsetY the border y offset */ - public void paintSmooth(@NotNull final Graphics graphics, final int x, final int y, final int level, final int layer, final boolean allLayers, final int borderOffsetX, final int borderOffsetY) { - final net.sf.gridarta.model.gameobject.GameObject<?, ?, ?>[][] layerNode = { new net.sf.gridarta.model.gameobject.GameObject<?, ?, ?>[3], new net.sf.gridarta.model.gameobject.GameObject<?, ?, ?>[3], new net.sf.gridarta.model.gameobject.GameObject<?, ?, ?>[3] }; - final MapArchObject mapArchObject = mapModel.getMapArchObject(); - boolean foundLayer = false; - for (int deltaX = -1; deltaX <= 1; deltaX++) { - for (int deltaY = -1; deltaY <= 1; deltaY++) { - final Point where = new Point(x + deltaX, y + deltaY); - if (mapArchObject.isPointValid(where)) { - int currentLayer = -1; - for (final net.sf.gridarta.model.gameobject.GameObject<GameObject, MapArchObject, Archetype> node : mapModel.getMapSquare(where)) { - if (node.getAttributeInt("invisible", true) == 0) { - currentLayer++; - } - if (currentLayer == layer) { - foundLayer = true; - if (node.getAttributeInt("smoothlevel", true) > 0) { - layerNode[deltaX + 1][deltaY + 1] = node; + public void paintSmooth(@NotNull final Graphics graphics, final int x, final int y, final int level, final int firstLayer, final boolean allLayers, final int borderOffsetX, final int borderOffsetY) { + int layer = firstLayer; + while (true) { + final MapArchObject mapArchObject = mapModel.getMapArchObject(); + boolean foundLayer = false; + final Point where = new Point(); + for (int deltaX = -1; deltaX <= 1; deltaX++) { + where.x = x + deltaX; + for (int deltaY = -1; deltaY <= 1; deltaY++) { + where.y = y + deltaY; + //false warning: cannot annotate with @Nullable + //noinspection AssignmentToNull + layerNode[deltaX + 1][deltaY + 1] = null; + if (mapArchObject.isPointValid(where)) { + int currentLayer = -1; + for (final net.sf.gridarta.model.gameobject.GameObject<GameObject, MapArchObject, Archetype> node : mapModel.getMapSquare(where)) { + if (node.getAttributeInt("invisible", true) == 0) { + currentLayer++; } - break; + if (currentLayer == layer) { + foundLayer = true; + if (node.getAttributeInt("smoothlevel", true) > 0) { + layerNode[deltaX + 1][deltaY + 1] = node; + } + break; + } } } } } - } - /*surrounding nodes having smoothlevel >0 found*/ - /*below is ripped and adapted from sdl client smooth renderer*/ - final int[] dx = { 0, 1, 1, 1, 0, -1, -1, -1, }; - final int[] dy = { -1, -1, 0, 1, 1, 1, 0, -1, }; - final int[] bWeights = { 2, 0, 4, 0, 8, 0, 1, 0, }; - final int[] cWeights = { 0, 2, 0, 4, 0, 8, 0, 1, }; - final int[] bcExclude = { 1 + 2, /*north exclude northwest (bit0) and northeast(bit1)*/ - 0, 2 + 4, /*east exclude northeast and southeast*/ - 0, 4 + 8, /*and so on*/ - 0, 8 + 1, 0 }; - final boolean[] partDone = { false, false, false, false, false, false, false, false, }; - final Point src = new Point(); - final int[] sLevels = new int[8]; - final FaceObject[] sFaces = new FaceObject[8]; - for (int i = 0; i < 8; i++) { - final int emx = 1 + dx[i]; - final int emy = 1 + dy[i]; - if (layerNode[emx][emy] == null || layerNode[emx][emy].getAttributeInt("smoothlevel", true) <= level) { - sLevels[i] = 0; - //false warning: cannot annotate with @Nullable - //noinspection AssignmentToNull - sFaces[i] = null; /*black picture*/ - } else { - sLevels[i] = layerNode[emx][emy].getAttributeInt("smoothlevel", true); - sFaces[i] = smoothFaces.getSmoothFace(layerNode[emx][emy]); - } - } - - /* ok, now we have a list of smoothlevel higher than current square. - * there are at most 8 different levels. so... let's check 8 times - * for the lowest one (we draw from bottom to top!). - */ - while (true) { - int lowest = -1; + /*surrounding nodes having smoothlevel >0 found*/ + /*below is ripped and adapted from sdl client smooth renderer*/ for (int i = 0; i < 8; i++) { - if (sLevels[i] > 0 && !partDone[i] && (lowest < 0 || sLevels[i] < sLevels[lowest])) { - lowest = i; + final net.sf.gridarta.model.gameobject.GameObject<?, ?, ?> node = layerNode[dx[i]][dy[i]]; + if (node == null) { + sLevels[i] = 0; + //false warning: cannot annotate with @Nullable + //noinspection AssignmentToNull + sFaces[i] = null; /*black picture*/ + } else { + final int smoothlevel = node.getAttributeInt("smoothlevel", true); + if (smoothlevel <= level) { + sLevels[i] = 0; + //false warning: cannot annotate with @Nullable + //noinspection AssignmentToNull + sFaces[i] = null; /*black picture*/ + } else { + sLevels[i] = smoothlevel; + sFaces[i] = smoothFaces.getSmoothFace(node); + } } } - if (lowest < 0) { - /*no more smooth to do on this square*/ - /*here we know 'what' to smooth*/ - break; - } - /* we need to calculate the weight for border and weight for corners. - * then we 'mark done' the corresponding squares - */ - /*first, the border, which may exclude some corners*/ - int weight = 0; - int weightC = 15; - for (int i = 0; i < 8; i++) { /*check all nearby squares*/ - if (sLevels[i] == sLevels[lowest] && sFaces[i] == sFaces[lowest]) { - partDone[i] = true; - weight += bWeights[i]; - weightC &= ~bcExclude[i]; - } else { - /*must remove the weight of a corner if not in smoothing*/ - weightC &= ~cWeights[i]; + + /* ok, now we have a list of smoothlevel higher than current square. + * there are at most 8 different levels. so... let's check 8 times + * for the lowest one (we draw from bottom to top!). + */ + final boolean[] partDone = { false, false, false, false, false, false, false, false, }; + final Point src = new Point(); + while (true) { + int lowest = -1; + for (int i = 0; i < 8; i++) { + if (sLevels[i] > 0 && !partDone[i] && (lowest < 0 || sLevels[i] < sLevels[lowest])) { + lowest = i; + } } + if (lowest < 0) { + /*no more smooth to do on this square*/ + /*here we know 'what' to smooth*/ + break; + } + /* we need to calculate the weight for border and weight for corners. + * then we 'mark done' the corresponding squares + */ + /*first, the border, which may exclude some corners*/ + int weight = 0; + int weightC = 15; + for (int i = 0; i < 8; i++) { /*check all nearby squares*/ + if (sLevels[i] == sLevels[lowest] && sFaces[i] == sFaces[lowest]) { + partDone[i] = true; + weight += bWeights[i]; + weightC &= ~bcExclude[i]; + } else { + /*must remove the weight of a corner if not in smoothing*/ + weightC &= ~cWeights[i]; + } + } + if (sFaces[lowest] == null) { + continue; /*Can't smooth black*/ + } + final NamedObject smoothFace = sFaces[lowest]; + /* now, it's quite easy. We must draw using a 32x32 part of + * the picture smooth face. + * This part is located using the 2 weights calculated: + * (32*weight,0) and (32*weightC,32) + */ + final ImageIcon img = faceObjectProviders.getDisplayIcon(smoothFace); + if (weight > 0) { + src.x = IGUIConstants.SQUARE_WIDTH * weight; + src.y = 0; + graphics.drawImage(img.getImage(), borderOffsetX + x * IGUIConstants.SQUARE_WIDTH, borderOffsetY + y * IGUIConstants.SQUARE_HEIGHT, borderOffsetX + x * IGUIConstants.SQUARE_WIDTH + IGUIConstants.SQUARE_WIDTH, borderOffsetY + y * IGUIConstants.SQUARE_HEIGHT + IGUIConstants.SQUARE_HEIGHT, src.x, src.y, src.x + IGUIConstants.SQUARE_WIDTH, src.y + IGUIConstants.SQUARE_HEIGHT, null); + } + if (weightC > 0) { + src.x = IGUIConstants.SQUARE_WIDTH * weightC; + src.y = IGUIConstants.SQUARE_HEIGHT; + graphics.drawImage(img.getImage(), borderOffsetX + x * IGUIConstants.SQUARE_WIDTH, borderOffsetY + y * IGUIConstants.SQUARE_HEIGHT, borderOffsetX + x * IGUIConstants.SQUARE_WIDTH + IGUIConstants.SQUARE_WIDTH, borderOffsetY + y * IGUIConstants.SQUARE_HEIGHT + IGUIConstants.SQUARE_HEIGHT, src.x, src.y, src.x + IGUIConstants.SQUARE_WIDTH, src.y + IGUIConstants.SQUARE_HEIGHT, null); + } + } /*while there's some smooth to do*/ + + if (!allLayers || !foundLayer) { + break; } - if (sFaces[lowest] == null) { - continue; /*Can't smooth black*/ - } - final NamedObject smoothFace = sFaces[lowest]; - /* now, it's quite easy. We must draw using a 32x32 part of - * the picture smooth face. - * This part is located using the 2 weights calculated: - * (32*weight,0) and (32*weightC,32) - */ - final ImageIcon img = faceObjectProviders.getDisplayIcon(smoothFace); - if (weight > 0) { - src.x = IGUIConstants.SQUARE_WIDTH * weight; - src.y = 0; - graphics.drawImage(img.getImage(), borderOffsetX + x * IGUIConstants.SQUARE_WIDTH, borderOffsetY + y * IGUIConstants.SQUARE_HEIGHT, borderOffsetX + x * IGUIConstants.SQUARE_WIDTH + IGUIConstants.SQUARE_WIDTH, borderOffsetY + y * IGUIConstants.SQUARE_HEIGHT + IGUIConstants.SQUARE_HEIGHT, src.x, src.y, src.x + IGUIConstants.SQUARE_WIDTH, src.y + IGUIConstants.SQUARE_HEIGHT, null); - } - if (weightC > 0) { - src.x = IGUIConstants.SQUARE_WIDTH * weightC; - src.y = IGUIConstants.SQUARE_HEIGHT; - graphics.drawImage(img.getImage(), borderOffsetX + x * IGUIConstants.SQUARE_WIDTH, borderOffsetY + y * IGUIConstants.SQUARE_HEIGHT, borderOffsetX + x * IGUIConstants.SQUARE_WIDTH + IGUIConstants.SQUARE_WIDTH, borderOffsetY + y * IGUIConstants.SQUARE_HEIGHT + IGUIConstants.SQUARE_HEIGHT, src.x, src.y, src.x + IGUIConstants.SQUARE_WIDTH, src.y + IGUIConstants.SQUARE_HEIGHT, null); - } - } /*while there's some smooth to do*/ - if (allLayers && foundLayer) { - paintSmooth(graphics, x, y, level, layer + 1, true, borderOffsetX, borderOffsetY); + layer++; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2010-11-24 09:44:53
|
Revision: 8805 http://gridarta.svn.sourceforge.net/gridarta/?rev=8805&view=rev Author: akirschbaum Date: 2010-11-24 09:44:46 +0000 (Wed, 24 Nov 2010) Log Message: ----------- Fix keyboard shortcuts of the go map and find archetype dialogs to be globally active on every input field. Modified Paths: -------------- trunk/atrinik/ChangeLog trunk/crossfire/ChangeLog trunk/daimonin/ChangeLog trunk/src/app/net/sf/gridarta/gui/utils/SwingUtils.java Modified: trunk/atrinik/ChangeLog =================================================================== --- trunk/atrinik/ChangeLog 2010-11-24 08:33:34 UTC (rev 8804) +++ trunk/atrinik/ChangeLog 2010-11-24 09:44:46 UTC (rev 8805) @@ -1,3 +1,8 @@ +2010-11-24 Andreas Kirschbaum + + * Fix keyboard shortcuts of the go map and find archetype dialogs + to be globally active on every input field. + 2010-11-17 Andreas Kirschbaum * Implement File|Goto Map... which opens maps by map name. Modified: trunk/crossfire/ChangeLog =================================================================== --- trunk/crossfire/ChangeLog 2010-11-24 08:33:34 UTC (rev 8804) +++ trunk/crossfire/ChangeLog 2010-11-24 09:44:46 UTC (rev 8805) @@ -1,3 +1,8 @@ +2010-11-24 Andreas Kirschbaum + + * Fix keyboard shortcuts of the go map and find archetype dialogs + to be globally active on every input field. + 2010-11-17 Andreas Kirschbaum * Implement File|Goto Map... which opens maps by map name. Modified: trunk/daimonin/ChangeLog =================================================================== --- trunk/daimonin/ChangeLog 2010-11-24 08:33:34 UTC (rev 8804) +++ trunk/daimonin/ChangeLog 2010-11-24 09:44:46 UTC (rev 8805) @@ -1,3 +1,8 @@ +2010-11-24 Andreas Kirschbaum + + * Fix keyboard shortcuts of the go map and find archetype dialogs + to be globally active on every input field. + 2010-11-17 Andreas Kirschbaum * Implement File|Goto Map... which opens maps by map name. Modified: trunk/src/app/net/sf/gridarta/gui/utils/SwingUtils.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/utils/SwingUtils.java 2010-11-24 08:33:34 UTC (rev 8804) +++ trunk/src/app/net/sf/gridarta/gui/utils/SwingUtils.java 2010-11-24 09:44:46 UTC (rev 8805) @@ -23,8 +23,8 @@ import javax.swing.Action; import javax.swing.JComponent; import javax.swing.KeyStroke; -import javax.swing.text.JTextComponent; import net.sf.gridarta.utils.ActionBuilderUtils; +import net.sf.gridarta.utils.ActionUtils; import net.sf.japi.swing.action.ActionBuilder; import net.sf.japi.swing.action.ActionBuilderFactory; import org.jetbrains.annotations.NotNull; @@ -62,16 +62,18 @@ } /** - * Adds an accelerator key for a text component. The accelerator key is - * extracted from the action to be added. If the action has no attached - * accelerator key, nothing is added. + * Adds an accelerator key for a component. The accelerator key is extracted + * from the action to be added. If the action has no attached accelerator + * key, nothing is added. * @param textComponent The text component to add to. * @param action The action to add. */ - public static void addAction(@NotNull final JTextComponent textComponent, @NotNull final Action action) { + public static void addAction(@NotNull final JComponent textComponent, @NotNull final Action action) { final KeyStroke keyStroke = (KeyStroke) action.getValue(Action.ACCELERATOR_KEY); if (keyStroke != null) { - textComponent.getKeymap().addActionForKeyStroke(keyStroke, action); + final String actionId = ActionUtils.getActionId(action); + textComponent.getInputMap().put(keyStroke, actionId); + textComponent.getActionMap().put(actionId, action); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2010-11-24 08:33:41
|
Revision: 8804 http://gridarta.svn.sourceforge.net/gridarta/?rev=8804&view=rev Author: akirschbaum Date: 2010-11-24 08:33:34 +0000 (Wed, 24 Nov 2010) Log Message: ----------- Fix Javadoc issues. Modified Paths: -------------- trunk/model/src/app/net/sf/gridarta/model/archetypetype/AbstractArchetypeAttributeInvSpell.java trunk/model/src/app/net/sf/gridarta/model/archetypetype/AbstractArchetypeAttributeList.java trunk/model/src/app/net/sf/gridarta/model/archetypetype/AbstractArchetypeAttributeSpell.java trunk/model/src/app/net/sf/gridarta/model/archetypetype/ArchetypeAttributeParser.java trunk/model/src/app/net/sf/gridarta/model/archetypetype/ArchetypeAttributeVisitor.java trunk/model/src/app/net/sf/gridarta/model/archetypetype/ArchetypeType.java trunk/model/src/app/net/sf/gridarta/model/archetypetype/ArchetypeTypeSet.java trunk/model/src/app/net/sf/gridarta/model/archetypetype/SectionNames.java trunk/model/src/app/net/sf/gridarta/model/validation/checks/package.html trunk/src/app/net/sf/gridarta/package.html Added Paths: ----------- trunk/model/src/app/net/sf/gridarta/model/archetypetype/package.html Modified: trunk/model/src/app/net/sf/gridarta/model/archetypetype/AbstractArchetypeAttributeInvSpell.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/archetypetype/AbstractArchetypeAttributeInvSpell.java 2010-11-20 15:09:38 UTC (rev 8803) +++ trunk/model/src/app/net/sf/gridarta/model/archetypetype/AbstractArchetypeAttributeInvSpell.java 2010-11-24 08:33:34 UTC (rev 8804) @@ -22,7 +22,8 @@ import org.jetbrains.annotations.NotNull; /** - * Abstract base class for {@link ArchetypeAttribute}s for inventory spells. + * Abstract base class for {@link ArchetypeAttribute ArchetypeAttributes} for + * inventory spells. * @author Andreas Kirschbaum */ public abstract class AbstractArchetypeAttributeInvSpell extends ArchetypeAttribute { Modified: trunk/model/src/app/net/sf/gridarta/model/archetypetype/AbstractArchetypeAttributeList.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/archetypetype/AbstractArchetypeAttributeList.java 2010-11-20 15:09:38 UTC (rev 8803) +++ trunk/model/src/app/net/sf/gridarta/model/archetypetype/AbstractArchetypeAttributeList.java 2010-11-24 08:33:34 UTC (rev 8804) @@ -22,7 +22,8 @@ import org.jetbrains.annotations.NotNull; /** - * Abstract base class for {@link ArchetypeAttribute}s for lists. + * Abstract base class for {@link ArchetypeAttribute ArchetypeAttributes} for + * lists. * @author Andreas Kirschbaum */ public abstract class AbstractArchetypeAttributeList extends ArchetypeAttribute { Modified: trunk/model/src/app/net/sf/gridarta/model/archetypetype/AbstractArchetypeAttributeSpell.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/archetypetype/AbstractArchetypeAttributeSpell.java 2010-11-20 15:09:38 UTC (rev 8803) +++ trunk/model/src/app/net/sf/gridarta/model/archetypetype/AbstractArchetypeAttributeSpell.java 2010-11-24 08:33:34 UTC (rev 8804) @@ -24,7 +24,8 @@ import org.jetbrains.annotations.NotNull; /** - * Abstract base class for {@link ArchetypeAttribute}s for spells. + * Abstract base class for {@link ArchetypeAttribute ArchetypeAttributes} for + * spells. * @author Andreas Kirschbaum */ public abstract class AbstractArchetypeAttributeSpell extends ArchetypeAttribute { Modified: trunk/model/src/app/net/sf/gridarta/model/archetypetype/ArchetypeAttributeParser.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/archetypetype/ArchetypeAttributeParser.java 2010-11-20 15:09:38 UTC (rev 8803) +++ trunk/model/src/app/net/sf/gridarta/model/archetypetype/ArchetypeAttributeParser.java 2010-11-24 08:33:34 UTC (rev 8804) @@ -28,7 +28,7 @@ import org.w3c.dom.Node; /** - * Utility class for parsing {@link ArchetypeAttribute}s. + * Utility class for parsing {@link ArchetypeAttribute ArchetypeAttributes}. * @author Andreas Kirschbaum */ public class ArchetypeAttributeParser { @@ -139,7 +139,7 @@ /** * The {@link ArchetypeAttributeFactory} for creating {@link - * ArchetypeAttribute}s. + * ArchetypeAttribute ArchetypeAttributes}. */ @NotNull private final ArchetypeAttributeFactory archetypeAttributeFactory; Modified: trunk/model/src/app/net/sf/gridarta/model/archetypetype/ArchetypeAttributeVisitor.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/archetypetype/ArchetypeAttributeVisitor.java 2010-11-20 15:09:38 UTC (rev 8803) +++ trunk/model/src/app/net/sf/gridarta/model/archetypetype/ArchetypeAttributeVisitor.java 2010-11-24 08:33:34 UTC (rev 8804) @@ -22,7 +22,7 @@ import org.jetbrains.annotations.NotNull; /** - * Interface for visitors of {@link ArchetypeAttribute}s. + * Interface for visitors of {@link ArchetypeAttribute ArchetypeAttributes}. * @author Andreas Kirschbaum */ public interface ArchetypeAttributeVisitor { Modified: trunk/model/src/app/net/sf/gridarta/model/archetypetype/ArchetypeType.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/archetypetype/ArchetypeType.java 2010-11-20 15:09:38 UTC (rev 8803) +++ trunk/model/src/app/net/sf/gridarta/model/archetypetype/ArchetypeType.java 2010-11-24 08:33:34 UTC (rev 8804) @@ -71,7 +71,7 @@ private final int sectionNum; /** - * The list of {@link ArchetypeAttribute}s. + * The list of {@link ArchetypeAttribute ArchetypeAttributes}. */ @NotNull private final ArchetypeAttributes archetypeAttributes; Modified: trunk/model/src/app/net/sf/gridarta/model/archetypetype/ArchetypeTypeSet.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/archetypetype/ArchetypeTypeSet.java 2010-11-20 15:09:38 UTC (rev 8803) +++ trunk/model/src/app/net/sf/gridarta/model/archetypetype/ArchetypeTypeSet.java 2010-11-24 08:33:34 UTC (rev 8804) @@ -50,8 +50,8 @@ private ArchetypeType fallbackArchetypeType = null; /** - * Lists with all {@link ArchetypeType}s. Contains all but the default - * archetype type. + * Lists with all {@link ArchetypeType ArchetypeTypes}. Contains all but the + * default archetype type. * @todo verify whether the default ArchetypeType really is not included in * this list. */ Modified: trunk/model/src/app/net/sf/gridarta/model/archetypetype/SectionNames.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/archetypetype/SectionNames.java 2010-11-20 15:09:38 UTC (rev 8803) +++ trunk/model/src/app/net/sf/gridarta/model/archetypetype/SectionNames.java 2010-11-24 08:33:34 UTC (rev 8804) @@ -24,7 +24,8 @@ import org.jetbrains.annotations.NotNull; /** - * Maintains a list of section names while parsing {@link ArchetypeAttribute}s. + * Maintains a list of section names while parsing {@link ArchetypeAttribute + * ArchetypeAttributes}. * @author Andreas Kirschbaum */ public class SectionNames { Added: trunk/model/src/app/net/sf/gridarta/model/archetypetype/package.html =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/archetypetype/package.html (rev 0) +++ trunk/model/src/app/net/sf/gridarta/model/archetypetype/package.html 2010-11-24 08:33:34 UTC (rev 8804) @@ -0,0 +1,35 @@ +<!-- + ~ 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. + --> + +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> +<html> +<body> +<p>Defines types of {@link net.sf.gridarta.model.gameobject.GameObject + GameObjects} with corresponding attributes. The game servers use different + types of game objects, such as floors, monsters, traps, etc. Each of these + types uses a specific set of attributes. Gridarta has no built-in knowledge + about these. Instead it reads a configuration file, "types.xml", which + defines game object types with corresponding attributes.</p> + +<p>{@link net.sf.gridarta.model.archetypetype.ArchetypeTypeSetParser} implements + a parser for the "types.xml" file. {@link + net.sf.gridarta.model.archetypetype.ArchetypeTypeSet} is a model class that + stores all type definitions.</p> +</body> +</html> Property changes on: trunk/model/src/app/net/sf/gridarta/model/archetypetype/package.html ___________________________________________________________________ Added: svn:mime-type + text/xml Added: svn:eol-style + LF Modified: trunk/model/src/app/net/sf/gridarta/model/validation/checks/package.html =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/validation/checks/package.html 2010-11-20 15:09:38 UTC (rev 8803) +++ trunk/model/src/app/net/sf/gridarta/model/validation/checks/package.html 2010-11-24 08:33:34 UTC (rev 8804) @@ -26,14 +26,14 @@ <p>The easiest way to create your own checks is this:</p> <ol> - <li>Extend {@link net.sf.gridarta.validation.AbstractValidator + <li>Extend {@link net.sf.gridarta.model.validation.AbstractValidator AbstractValidator} by a class named like net.sf.gridarta.map.validation.checks.MyMapChecker that additionally - implements one of the {@link net.sf.gridarta.validation.Validator + implements one of the {@link net.sf.gridarta.model.validation.Validator Validator} sub-interfaces </li> <li>Extend {@link net.sf.gridarta.model.validation.errors.ValidationError - ValidationError} or one of its subclasses by a class named like <code>net.sf.gridarta.map.validation.checks.MyError</code>. + ValidationError} or one of its subclasses by a class named like <code>net.sf.gridarta.map.model.validation.checks.MyError</code>. </li> </ol> <p>Note: to use the automatic localization feature, the error class and @@ -41,10 +41,10 @@ <h3>Caveats</h3> -<p>If you extend {@link net.sf.gridarta.validation.AbstractValidator +<p>If you extend {@link net.sf.gridarta.model.validation.AbstractValidator AbstractValidator} without actually really implementing one of the {@link - net.sf.gridarta.validation.Validator Validator}, your validator will be a - valid and compilable validator but also a dysfunctional stub. So don't + net.sf.gridarta.model.validation.Validator Validator}, your validator will + be a valid and compilable validator but also a dysfunctional stub. So don't forget to extend the corresponding sub-interface.</p> <h3>FAQ</h3> Modified: trunk/src/app/net/sf/gridarta/package.html =================================================================== --- trunk/src/app/net/sf/gridarta/package.html 2010-11-20 15:09:38 UTC (rev 8803) +++ trunk/src/app/net/sf/gridarta/package.html 2010-11-24 08:33:34 UTC (rev 8804) @@ -21,7 +21,7 @@ <html> <body> Base package of all Gridarta classes. This package contains only one interface: -{@link MainControl} which defines the location for storing preferences. All -other types are part of sub-packages. +{@link net.sf.gridarta.MainControl} which defines the location for storing +preferences. All other types are part of sub-packages. </body> </html> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ryo...@us...> - 2010-11-20 15:09:44
|
Revision: 8803 http://gridarta.svn.sourceforge.net/gridarta/?rev=8803&view=rev Author: ryo_saeba Date: 2010-11-20 15:09:38 +0000 (Sat, 20 Nov 2010) Log Message: ----------- Add new flags. Modified Paths: -------------- trunk/crossfire/resource/resource/conf/types.xml Modified: trunk/crossfire/resource/resource/conf/types.xml =================================================================== --- trunk/crossfire/resource/resource/conf/types.xml 2010-11-18 19:13:37 UTC (rev 8802) +++ trunk/crossfire/resource/resource/conf/types.xml 2010-11-20 15:09:38 UTC (rev 8803) @@ -4199,7 +4199,13 @@ <attribute arch="hp" editor="number of charges" type="int" min="0" max="32767"> The rune will detonate <number of charges> times before disappearing. + + Should be not 0 if 'unlimited charges' is set. </attribute> + <attribute arch="lifesave" editor="unlimited charges" type="bool"> + If set, then the rune will detonate forever if the number of charges + is not 0. + </attribute> <attribute arch="dam" editor="direct damage" type="int" min="0" max="32767"> <direct damage> specifies how much damage is done by the rune, if it doesn't contain a spell. This should be set in reasonable @@ -5235,9 +5241,15 @@ effects how easily the trap may be found. </attribute> <attribute arch="hp" editor="number of charges" type="int" min="0" max="32767"> - The trap will detonate <number of charges> times before + The rune will detonate <number of charges> times before disappearing. + + Should be not 0 if 'unlimited charges' is set. </attribute> + <attribute arch="lifesave" editor="unlimited charges" type="bool"> + If set, then the rune will detonate forever if the number of charges + is not 0. + </attribute> <attribute arch="dam" editor="direct damage" type="int" min="0" max="32767"> <direct damage> specifies how much damage is done by the trap. This should be set in reasonable relation to the trap's level. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2010-11-18 19:13:44
|
Revision: 8802 http://gridarta.svn.sourceforge.net/gridarta/?rev=8802&view=rev Author: akirschbaum Date: 2010-11-18 19:13:37 +0000 (Thu, 18 Nov 2010) Log Message: ----------- Fix checkstyle issues. Modified Paths: -------------- trunk/model/src/test/net/sf/gridarta/model/index/MapsIndexTest.java trunk/src/app/net/sf/gridarta/gui/gomapdialog/MapListCellRenderer.java trunk/utils/src/app/net/sf/gridarta/utils/DelayedChangeManager.java Modified: trunk/model/src/test/net/sf/gridarta/model/index/MapsIndexTest.java =================================================================== --- trunk/model/src/test/net/sf/gridarta/model/index/MapsIndexTest.java 2010-11-17 20:48:59 UTC (rev 8801) +++ trunk/model/src/test/net/sf/gridarta/model/index/MapsIndexTest.java 2010-11-18 19:13:37 UTC (rev 8802) @@ -146,7 +146,7 @@ @NotNull private static String getPending(@NotNull final Index<File> index) { final Collection<File> pendingFiles = new HashSet<File>(); - for (; ;) { + while (true) { final File pendingFile = index.removePending(); if (pendingFile == null) { break; Modified: trunk/src/app/net/sf/gridarta/gui/gomapdialog/MapListCellRenderer.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/gomapdialog/MapListCellRenderer.java 2010-11-17 20:48:59 UTC (rev 8801) +++ trunk/src/app/net/sf/gridarta/gui/gomapdialog/MapListCellRenderer.java 2010-11-18 19:13:37 UTC (rev 8802) @@ -27,7 +27,8 @@ import org.jetbrains.annotations.NotNull; /** - * A {@link DefaultListCellRenderer} that renders values of a {@link MapsIndex}. + * A {@link DefaultListCellRenderer} that renders values of a {@link + * MapsIndex}. * @author Andreas Kirschbaum */ public class MapListCellRenderer extends DefaultListCellRenderer { @@ -60,7 +61,7 @@ super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); final File file = (File) value; final String name = mapsIndex.getName(file); - setText((name == null ? "?" : name)+" ("+file.getName()+")"); + setText((name == null ? "?" : name) + " (" + file.getName() + ")"); setToolTipText(value.toString()); return this; } Modified: trunk/utils/src/app/net/sf/gridarta/utils/DelayedChangeManager.java =================================================================== --- trunk/utils/src/app/net/sf/gridarta/utils/DelayedChangeManager.java 2010-11-17 20:48:59 UTC (rev 8801) +++ trunk/utils/src/app/net/sf/gridarta/utils/DelayedChangeManager.java 2010-11-18 19:13:37 UTC (rev 8802) @@ -101,26 +101,26 @@ * The state "idle" of the FSM. */ @NotNull - private State IDLE = new State() { + private final State idle = new State() { @NotNull @Override public State change() { timer.schedule(new TimeoutTimerTask(), initialDelay); - return PENDING; + return pending; } @NotNull @Override public State finish() { - return IDLE; + return idle; } @NotNull @Override public State timeout() { assert false; - return IDLE; + return idle; } }; @@ -129,19 +129,19 @@ * The state "pending" of the FSM. */ @NotNull - private State PENDING = new State() { + private final State pending = new State() { @NotNull @Override public State change() { - return PENDING; + return pending; } @NotNull @Override public State finish() { delayedChangeListener.change(); - return WAIT; + return wait; } @NotNull @@ -149,7 +149,7 @@ public State timeout() { timer.schedule(new TimeoutTimerTask(), notificationDelay); delayedChangeListener.change(); - return WAIT; + return wait; } }; @@ -158,24 +158,24 @@ * The state "wait" of the FSM. */ @NotNull - private State WAIT = new State() { + private final State wait = new State() { @NotNull @Override public State change() { - return PENDING; + return pending; } @NotNull @Override public State finish() { - return WAIT; + return wait; } @NotNull @Override public State timeout() { - return IDLE; + return idle; } @@ -185,7 +185,7 @@ * The FSM's current state. */ @NotNull - private State state = IDLE; + private State state = idle; /** * Creates a new instance. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ryo...@us...> - 2010-11-17 20:49:05
|
Revision: 8801 http://gridarta.svn.sourceforge.net/gridarta/?rev=8801&view=rev Author: ryo_saeba Date: 2010-11-17 20:48:59 +0000 (Wed, 17 Nov 2010) Log Message: ----------- Translate. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/messages_fr.properties Modified: trunk/src/app/net/sf/gridarta/messages_fr.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages_fr.properties 2010-11-17 19:39:35 UTC (rev 8800) +++ trunk/src/app/net/sf/gridarta/messages_fr.properties 2010-11-17 20:48:59 UTC (rev 8801) @@ -67,6 +67,12 @@ #goNorthWest.text= #goNorthWest.shortdescription= +goMap.text=Aller \u00e0 une carte... +goMap.mnemonic=M +goMap.shortdescription=Ouvrir une carte par nom partiel. +goMap.accel=ctrl pressed N + + ####### # Map @@ -1422,3 +1428,29 @@ #randomFillSkipAdjacentSquares.shortdescription= #randomFillOkay.text= #randomFillCancel.text= + +############### +# Go Map Dialog +goMapLabel=Nom de la carte : +goMapScrollDown.text=- +goMapScrollDown.accel=pressed DOWN +goMapScrollUp.text=- +goMapScrollUp.accel=pressed UP +goMapScrollPageDown.text=- +goMapScrollPageDown.accel=pressed PAGE_DOWN +goMapScrollPageUp.text=- +goMapScrollPageUp.accel=pressed PAGE_UP +goMapScrollTop.text=- +goMapScrollTop.accel=pressed HOME +goMapScrollBottom.text=- +goMapScrollBottom.accel=pressed END +goMapSelectDown.text=- +goMapSelectDown.accel=shift pressed DOWN +goMapSelectUp.text=- +goMapSelectUp.accel=shift pressed UP +goMapCancel.text=- +goMapCancel.accel=pressed ESCAPE +goMapApply.text=- +goMapApply.accel=pressed ENTER +goMapIOException.title=Impossible de charger la carte +goMapIOException.message=La carte {0} ne peut \u00eatre charg\u00e9e :\n{1} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2010-11-17 19:39:44
|
Revision: 8800 http://gridarta.svn.sourceforge.net/gridarta/?rev=8800&view=rev Author: akirschbaum Date: 2010-11-17 19:39:35 +0000 (Wed, 17 Nov 2010) Log Message: ----------- Implement File|Goto Map... which opens maps by map name. Modified Paths: -------------- trunk/atrinik/ChangeLog trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/action.properties trunk/crossfire/ChangeLog trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/action.properties trunk/daimonin/ChangeLog trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/action.properties trunk/gridarta.ipr trunk/model/src/app/net/sf/gridarta/model/settings/DefaultGlobalSettings.java trunk/model/src/app/net/sf/gridarta/model/settings/GlobalSettings.java trunk/model/src/test/net/sf/gridarta/model/mapcontrol/TestMapControlCreator.java trunk/model/src/test/net/sf/gridarta/model/settings/TestGlobalSettings.java trunk/resource/log4j.properties trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java trunk/src/app/net/sf/gridarta/messages.properties Added Paths: ----------- trunk/model/src/app/net/sf/gridarta/model/index/ trunk/model/src/app/net/sf/gridarta/model/index/AbstractIndex.java trunk/model/src/app/net/sf/gridarta/model/index/Index.java trunk/model/src/app/net/sf/gridarta/model/index/IndexListener.java trunk/model/src/app/net/sf/gridarta/model/index/MapsIndex.java trunk/model/src/app/net/sf/gridarta/model/index/MapsIndexer.java trunk/model/src/test/net/sf/gridarta/model/index/ trunk/model/src/test/net/sf/gridarta/model/index/MapsIndexTest.java trunk/model/src/test/net/sf/gridarta/model/index/MapsIndexerTest.java trunk/src/app/net/sf/gridarta/gui/gomapdialog/ trunk/src/app/net/sf/gridarta/gui/gomapdialog/GoMapDialog.java trunk/src/app/net/sf/gridarta/gui/gomapdialog/GoMapDialogManager.java trunk/src/app/net/sf/gridarta/gui/gomapdialog/MapListCellRenderer.java trunk/utils/src/app/net/sf/gridarta/utils/DelayedChangeListener.java trunk/utils/src/app/net/sf/gridarta/utils/DelayedChangeManager.java trunk/utils/src/app/net/sf/gridarta/utils/Xtea.java trunk/utils/src/test/net/sf/gridarta/utils/XteaTest.java Modified: trunk/atrinik/ChangeLog =================================================================== --- trunk/atrinik/ChangeLog 2010-11-17 18:25:31 UTC (rev 8799) +++ trunk/atrinik/ChangeLog 2010-11-17 19:39:35 UTC (rev 8800) @@ -1,3 +1,7 @@ +2010-11-17 Andreas Kirschbaum + + * Implement File|Goto Map... which opens maps by map name. + 2010-11-07 Andreas Kirschbaum * Force non-GUI mode when using --script. Modified: trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/action.properties =================================================================== --- trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/action.properties 2010-11-17 18:25:31 UTC (rev 8799) +++ trunk/atrinik/src/app/net/sf/gridarta/var/atrinik/action.properties 2010-11-17 19:39:35 UTC (rev 8800) @@ -25,7 +25,7 @@ ######## # Menus main.menubar=file edit map archetypes pickmaps resources tools analyze view bookmarks plugins window help -file.menu=newMap openFile recent closeMap - saveMap saveMapAs saveAllMaps - closeAllMaps revertMap createImage - options shortcuts - exit +file.menu=newMap openFile goMap recent closeMap - saveMap saveMapAs saveAllMaps - closeAllMaps revertMap createImage - options shortcuts - exit edit.menu=undo redo - clear cut copy paste pasteTiled - shift - replace fillAuto fillAbove fillBelow randFillAuto randFillAbove randFillBelow floodFill - selectAll expandEmptySelection growSelection shrinkSelection map.menu=autoJoin - enterExit nextExit prevExit enterNorthMap enterEastMap enterSouthMap enterWestMap enterNorthEastMap enterSouthEastMap enterSouthWestMap enterNorthWestMap - mapCreateView mapProperties shrinkMapSize deleteUnknownObjects - gameObjectTextEditor archetypes.menu=displayGameObjectNames displayArchetypeNames displayIconsOnly - findArchetypes Modified: trunk/crossfire/ChangeLog =================================================================== --- trunk/crossfire/ChangeLog 2010-11-17 18:25:31 UTC (rev 8799) +++ trunk/crossfire/ChangeLog 2010-11-17 19:39:35 UTC (rev 8800) @@ -1,3 +1,7 @@ +2010-11-17 Andreas Kirschbaum + + * Implement File|Goto Map... which opens maps by map name. + 2010-11-07 Andreas Kirschbaum * Force non-GUI mode when using --script. Modified: trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/action.properties =================================================================== --- trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/action.properties 2010-11-17 18:25:31 UTC (rev 8799) +++ trunk/crossfire/src/app/net/sf/gridarta/var/crossfire/action.properties 2010-11-17 19:39:35 UTC (rev 8800) @@ -25,7 +25,7 @@ ######## # Menus main.menubar=file edit map archetypes pickmaps resources tools analyze view bookmarks plugins window help -file.menu=newMap openFile recent closeMap - saveMap saveMapAs saveAllMaps - closeAllMaps revertMap createImage - options shortcuts - exit +file.menu=newMap openFile goMap recent closeMap - saveMap saveMapAs saveAllMaps - closeAllMaps revertMap createImage - options shortcuts - exit edit.menu=undo redo - clear cut copy paste pasteTiled - shift - replace fillAuto fillAbove fillBelow randFillAuto randFillAbove randFillBelow floodFill - selectAll expandEmptySelection growSelection shrinkSelection map.menu=autoJoin - enterExit nextExit prevExit enterNorthMap enterEastMap enterSouthMap enterWestMap tileShow - mapCreateView mapProperties shrinkMapSize deleteUnknownObjects - gameObjectTextEditor archetypes.menu=displayGameObjectNames displayArchetypeNames displayIconsOnly - findArchetypes Modified: trunk/daimonin/ChangeLog =================================================================== --- trunk/daimonin/ChangeLog 2010-11-17 18:25:31 UTC (rev 8799) +++ trunk/daimonin/ChangeLog 2010-11-17 19:39:35 UTC (rev 8800) @@ -1,3 +1,7 @@ +2010-11-17 Andreas Kirschbaum + + * Implement File|Goto Map... which opens maps by map name. + 2010-11-07 Andreas Kirschbaum * Force non-GUI mode when using --script. Modified: trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/action.properties =================================================================== --- trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/action.properties 2010-11-17 18:25:31 UTC (rev 8799) +++ trunk/daimonin/src/app/net/sf/gridarta/var/daimonin/action.properties 2010-11-17 19:39:35 UTC (rev 8800) @@ -25,7 +25,7 @@ ######## # Menus main.menubar=file edit map archetypes pickmaps resources tools analyze view bookmarks plugins window help -file.menu=newMap openFile recent closeMap - saveMap saveMapAs saveAllMaps - closeAllMaps revertMap createImage - options shortcuts - exit +file.menu=newMap openFile goMap recent closeMap - saveMap saveMapAs saveAllMaps - closeAllMaps revertMap createImage - options shortcuts - exit edit.menu=undo redo - clear cut copy paste pasteTiled - shift - replace fillAuto fillAbove fillBelow randFillAuto randFillAbove randFillBelow floodFill - selectAll expandEmptySelection growSelection shrinkSelection map.menu=autoJoin - enterExit nextExit prevExit enterNorthMap enterEastMap enterSouthMap enterWestMap enterNorthEastMap enterSouthEastMap enterSouthWestMap enterNorthWestMap - mapCreateView mapProperties shrinkMapSize deleteUnknownObjects - gameObjectTextEditor archetypes.menu=displayGameObjectNames displayArchetypeNames displayIconsOnly - findArchetypes Modified: trunk/gridarta.ipr =================================================================== --- trunk/gridarta.ipr 2010-11-17 18:25:31 UTC (rev 8799) +++ trunk/gridarta.ipr 2010-11-17 19:39:35 UTC (rev 8800) @@ -1400,6 +1400,7 @@ <w>xnoagent</w> <w>xrunhprof</w> <w>xrunjdwp</w> + <w>xtea</w> <w>yoyodyne</w> <w>zergus</w> </words> Added: trunk/model/src/app/net/sf/gridarta/model/index/AbstractIndex.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/index/AbstractIndex.java (rev 0) +++ trunk/model/src/app/net/sf/gridarta/model/index/AbstractIndex.java 2010-11-17 19:39:35 UTC (rev 8800) @@ -0,0 +1,369 @@ +/* + * 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.index; + +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import net.sf.gridarta.utils.EventListenerList2; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Abstract base class for {@link Index} implementations. + * @author Andreas Kirschbaum + * @param <V> the value's type + */ +public class AbstractIndex<V extends Serializable> implements Index<V> { + + /** + * Objects used to synchronize accesses to other fields. + * @serial + */ + @NotNull + private final Object sync = new Object(); + + /** + * The registered listeners. + */ + @NotNull + private final EventListenerList2<IndexListener<V>> indexListeners = new EventListenerList2<IndexListener<V>>(IndexListener.class); + + /** + * Maps value to timestamp. + * @serial + */ + @NotNull + private Map<V, Long> timestamps = new HashMap<V, Long>(); + + /** + * Maps value to name. + * @serial + */ + @NotNull + private Map<V, String> names = new HashMap<V, String>(); + + /** + * Pending values. + * @serial + */ + @NotNull + private Set<V> pending = new HashSet<V>(); + + /** + * Whether the state ({@link #timestamps} or {@link #names}) was modified + * since last save. + */ + private boolean modified = false; + + /** + * Whether a transaction is active. + */ + private boolean transaction = false; + + /** + * The values to delete at the end of the current transaction. Empty if no + * transaction is active. + * @serial + */ + @NotNull + private final Collection<V> transactionDelete = new HashSet<V>(); + + /** + * {@inheritDoc} + */ + @Override + public int size() { + return timestamps.size(); + } + + /** + * {@inheritDoc} + */ + @NotNull + @Override + public Collection<V> findPartialName(@NotNull final String name) { + synchronized (sync) { + final String nameLowerCase = name.toLowerCase(); + final Collection<V> result = new HashSet<V>(); + for (final Map.Entry<V, String> e : names.entrySet()) { + if (e.getValue().toLowerCase().contains(nameLowerCase)) { + result.add(e.getKey()); + } + } + return result; + } + } + + /** + * {@inheritDoc} + */ + @Override + public void beginUpdate() { + synchronized (sync) { + transaction = true; + transactionDelete.clear(); + transactionDelete.addAll(timestamps.keySet()); + } + } + + /** + * {@inheritDoc} + */ + @Override + public void endUpdate() { + synchronized (sync) { + if (!transaction) { + throw new IllegalStateException(); + } + transaction = false; + + final Collection<V> tmp = new ArrayList<V>(transactionDelete); + transactionDelete.clear(); + if (!tmp.isEmpty()) { + modified = true; + for (final V value : tmp) { + timestamps.remove(value); + pending.remove(value); + names.remove(value); + } + for (final V value : tmp) { + for (final IndexListener<V> listener : indexListeners.getListeners()) { + listener.valueRemoved(value); + listener.nameChanged(); + } + } + } + } + } + + /** + * {@inheritDoc} + */ + @Override + public void add(@NotNull final V value, final long timestamp) { + synchronized (sync) { + final Long oldTimestamp = timestamps.put(value, timestamp); + final boolean notifyPending; + final boolean notifyAdded; + if (oldTimestamp == null || oldTimestamp != timestamp) { + notifyPending = pending.add(value) && pending.size() == 1; + notifyAdded = oldTimestamp == null; + modified = true; + } else { + notifyPending = false; + notifyAdded = false; + } + transactionDelete.remove(value); + if (notifyAdded) { + for (final IndexListener<V> listener : indexListeners.getListeners()) { + listener.valueAdded(value); + } + } + if (notifyPending) { + for (final IndexListener<V> listener : indexListeners.getListeners()) { + listener.pendingChanged(); + } + } + } + } + + /** + * {@inheritDoc} + */ + @Override + public void remove(@NotNull final V value) { + synchronized (sync) { + if (timestamps.remove(value) == null) { + return; + } + modified = true; + pending.remove(value); + names.remove(value); + for (final IndexListener<V> listener : indexListeners.getListeners()) { + listener.valueRemoved(value); + listener.nameChanged(); + } + } + } + + /** + * {@inheritDoc} + */ + @Override + public void setPending(@NotNull final V value) { + synchronized (sync) { + final boolean notifyPending = pending.add(value) && pending.size() == 1; + if (!timestamps.containsKey(value)) { + modified = true; + timestamps.put(value, 0L); + for (final IndexListener<V> listener : indexListeners.getListeners()) { + listener.valueAdded(value); + } + } + if (notifyPending) { + for (final IndexListener<V> listener : indexListeners.getListeners()) { + listener.pendingChanged(); + } + } + } + } + + /** + * {@inheritDoc} + */ + @Override + public void setName(@NotNull final V value, final long timestamp, @NotNull final String name) { + synchronized (sync) { + timestamps.put(value, timestamp); + final String oldName = names.put(value, name); + if (oldName != null && oldName.equals(name)) { + return; + } + modified = true; + for (final IndexListener<V> listener : indexListeners.getListeners()) { + listener.nameChanged(); + } + } + } + + /** + * {@inheritDoc} + */ + @Nullable + @Override + public String getName(@NotNull final V value) { + synchronized (sync) { + return names.get(value); + } + } + + /** + * {@inheritDoc} + */ + @Nullable + @Override + public V removePending() { + synchronized (sync) { + final Iterator<V> it = pending.iterator(); + if (!it.hasNext()) { + return null; + } + + final V result = it.next(); + it.remove(); + return result; + } + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isModified() { + synchronized (sync) { + return modified; + } + } + + /** + * {@inheritDoc} + */ + @Override + public void addIndexListener(@NotNull final IndexListener<V> listener) { + indexListeners.add(listener); + } + + /** + * {@inheritDoc} + */ + @Override + public void removeIndexListener(@NotNull final IndexListener<V> listener) { + indexListeners.remove(listener); + } + + /** + * {@inheritDoc} + */ + @Override + public void save(@NotNull final ObjectOutputStream objectOutputStream) throws IOException { + objectOutputStream.writeObject(timestamps); + objectOutputStream.writeObject(names); + modified = false; + } + + /** + * {@inheritDoc} + * @noinspection unchecked + */ + @Override + @SuppressWarnings({ "unchecked" }) + public void load(@NotNull final ObjectInputStream objectInputStream) throws IOException { + final Map<V, Long> tmpTimestamps; + final Map<V, String> tmpNames; + try { + tmpTimestamps = (Map<V, Long>) objectInputStream.readObject(); + tmpNames = (Map<V, String>) objectInputStream.readObject(); + } catch (final ClassNotFoundException ex) { + throw new IOException(ex.getMessage(), ex); + } + if (transaction) { + throw new IOException("cannot restore state within active transaction"); + } + + // drop excess elements from tmpNames to force a consistent state + tmpNames.keySet().retainAll(tmpTimestamps.keySet()); + + clear(); + timestamps.putAll(tmpTimestamps); + names.putAll(tmpNames); + } + + /** + * {@inheritDoc} + */ + @Override + public void clear() { + timestamps.clear(); + names.clear(); + pending.clear(); + transactionDelete.clear(); + modified = false; + } + + /** + * {@inheritDoc} + */ + @Override + public void indexingFinished() { + for (final IndexListener<V> listener : indexListeners.getListeners()) { + listener.indexingFinished(); + } + } + +} // class AbstractIndex Property changes on: trunk/model/src/app/net/sf/gridarta/model/index/AbstractIndex.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Added: trunk/model/src/app/net/sf/gridarta/model/index/Index.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/index/Index.java (rev 0) +++ trunk/model/src/app/net/sf/gridarta/model/index/Index.java 2010-11-17 19:39:35 UTC (rev 8800) @@ -0,0 +1,161 @@ +/* + * 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.index; + +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.Collection; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * An index of values. Values are associated with a timestamp and zero or one + * name. The timestamp is used to mark values as pending whenever they have + * changed. Pending values may be retrieved for re-indexing. + * <p/> + * Values may be looked up by partial names. + * <p/> + * All methods are synchronized: concurrent access from multiple threads is + * supported. + * @author Andreas Kirschbaum + * @param <V> the value's type + */ +public interface Index<V> { + + /** + * Returns the number of values in this cache. + * @return the number of values + */ + int size(); + + /** + * Returns all matching values for a (possibly partial) key name. + * @param name the partial name to look up + * @return the matching values + */ + @NotNull + Collection<V> findPartialName(@NotNull String name); + + /** + * Starts an update. Updates do not nest. This function and {@link + * #endUpdate()} should be called from only a single thread. + */ + void beginUpdate(); + + /** + * Ends an update. Removes all values from the index that were not {@link + * #add(Object, long) added} since the last call to {@link #beginUpdate()}. + * Must not be called unless a directly preceding call to + * <code>beginUpdate()</code> was made. + */ + void endUpdate(); + + /** + * Adds a value to the cache. Newly added values and existing values for + * which the new timestamp does not match the old timestamp are marked as + * pending. + * @param value the value to add + * @param timestamp a timestamp associated with the value + */ + void add(@NotNull V value, long timestamp); + + /** + * Removes a value from the cache. Does nothing if the values does not + * exist. + * @param value the value to remove + */ + void remove(@NotNull V value); + + /** + * Marks a value as pending. The value is added if it does not exist. + * @param value the value to mark pending + */ + void setPending(@NotNull V value); + + /** + * Associates a value with a name. Adds the value if it does not exist. + * @param value the value to associate with a name + * @param timestamp the value's timestamp + * @param name the name associated with the value + */ + void setName(@NotNull V value, long timestamp, @NotNull String name); + + /** + * Returns the name associated with a value. + * @param value the value + * @return the name or <code>null</code> if the value does not exist or has + * no associated name + */ + @Nullable + String getName(@NotNull V value); + + /** + * Returns one pending value. + * @return a pending value or <code>null</code> if no pending values exist + */ + @Nullable + V removePending(); + + /** + * Returns whether the state was modified since last save. + * @return whether the state was modified + */ + boolean isModified(); + + /** + * Adds an {@link IndexListener} to be notified of changes. + * @param listener the index listener to add + */ + void addIndexListener(@NotNull IndexListener<V> listener); + + /** + * Removes an {@link IndexListener} to be notified of changes. + * @param listener the index listener to remove + */ + void removeIndexListener(@NotNull IndexListener<V> listener); + + /** + * Saves the state to an {@link ObjectOutputStream}. Pending maps are not + * saved. + * @param objectOutputStream the object output stream to write to + * @throws IOException if an I/O error occurs + */ + void save(@NotNull ObjectOutputStream objectOutputStream) throws IOException; + + /** + * Restores the state from an {@link ObjectInputStream}. The previous state + * is overwritten. + * @param objectInputStream the input stream to read from + * @throws IOException if an I/O error occurs + */ + void load(@NotNull ObjectInputStream objectInputStream) throws IOException; + + /** + * Clears all values from the index. + */ + void clear(); + + /** + * Should be called after indexing has finished. + */ + void indexingFinished(); + +} // interface Index Property changes on: trunk/model/src/app/net/sf/gridarta/model/index/Index.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Added: trunk/model/src/app/net/sf/gridarta/model/index/IndexListener.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/index/IndexListener.java (rev 0) +++ trunk/model/src/app/net/sf/gridarta/model/index/IndexListener.java 2010-11-17 19:39:35 UTC (rev 8800) @@ -0,0 +1,59 @@ +/* + * 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.index; + +import java.util.EventListener; +import org.jetbrains.annotations.NotNull; + +/** + * Interface for listeners interested in {@link Index} related events. + * @param <V> the index's value's type + * @author Andreas Kirschbaum + */ +public interface IndexListener<V> extends EventListener { + + /** + * A new value has been added to the index. + * @param value the value + */ + void valueAdded(@NotNull V value); + + /** + * A value has been removed from the index. + * @param value the value + */ + void valueRemoved(@NotNull V value); + + /** + * A name mapping has changed. + */ + void nameChanged(); + + /** + * At least one pending value has become available. + */ + void pendingChanged(); + + /** + * Called after indexing has finished. + */ + void indexingFinished(); + +} // interface IndexListener Property changes on: trunk/model/src/app/net/sf/gridarta/model/index/IndexListener.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Added: trunk/model/src/app/net/sf/gridarta/model/index/MapsIndex.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/index/MapsIndex.java (rev 0) +++ trunk/model/src/app/net/sf/gridarta/model/index/MapsIndex.java 2010-11-17 19:39:35 UTC (rev 8800) @@ -0,0 +1,30 @@ +/* + * 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.index; + +import java.io.File; + +/** + * Indexes maps by map name. Allows searching for maps by partial map name. + * @author Andreas Kirschbaum + */ +public class MapsIndex extends AbstractIndex<File> { + +} // class MapsIndex Property changes on: trunk/model/src/app/net/sf/gridarta/model/index/MapsIndex.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Added: trunk/model/src/app/net/sf/gridarta/model/index/MapsIndexer.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/index/MapsIndexer.java (rev 0) +++ trunk/model/src/app/net/sf/gridarta/model/index/MapsIndexer.java 2010-11-17 19:39:35 UTC (rev 8800) @@ -0,0 +1,585 @@ +/* + * 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.index; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.OutputStream; +import java.io.UnsupportedEncodingException; +import java.util.Arrays; +import java.util.concurrent.Semaphore; +import net.sf.gridarta.model.archetype.Archetype; +import net.sf.gridarta.model.gameobject.GameObject; +import net.sf.gridarta.model.maparchobject.MapArchObject; +import net.sf.gridarta.model.mapcontrol.DefaultMapControl; +import net.sf.gridarta.model.mapcontrol.MapControl; +import net.sf.gridarta.model.mapcontrol.MapControlListener; +import net.sf.gridarta.model.mapmanager.MapManager; +import net.sf.gridarta.model.mapmanager.MapManagerListener; +import net.sf.gridarta.model.settings.GlobalSettings; +import net.sf.gridarta.model.settings.GlobalSettingsListener; +import net.sf.gridarta.utils.ConfigFileUtils; +import net.sf.gridarta.utils.Xtea; +import org.apache.log4j.Category; +import org.apache.log4j.Logger; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Maintains a {@link MapsIndex} for the maps directory. Changed maps are + * tracked and the index is updated. + * @author Andreas Kirschbaum + */ +public class MapsIndexer<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> { + + /** + * The Logger for printing log messages. + */ + @NotNull + private static final Category log = Logger.getLogger(MapsIndexer.class); + + /** + * A pending map may exist in {@link #mapsIndex} if a permit is available. + */ + @NotNull + private final Semaphore mapsIndexSemaphore = new Semaphore(1); + + /** + * The {@link MapsIndex} being updated. + */ + @NotNull + private final MapsIndex mapsIndex; + + /** + * The {@link MapManager} for loading map files. + */ + @NotNull + private final MapManager<G, A, R> mapManager; + + /** + * The {@link GlobalSettings} instance. + */ + @NotNull + private final GlobalSettings globalSettings; + + /** + * The object for synchronizing access to {@link #mapsDirectory} and {@link + * #newMapsDirectory}. + */ + @NotNull + private final Object syncMapsDirectory = new Object(); + + /** + * The currently indexed maps directory. + */ + @Nullable + private File mapsDirectory = null; + + /** + * The maps directory to index. If <code>null</code>, {@link #mapsDirectory} + * is valid. + */ + @Nullable + private File newMapsDirectory = null; + + /** + * The object for synchronizing access to {@link #state}. + */ + @NotNull + private final Object syncState = new Object(); + + /** + * The indexer state. + */ + @NotNull + private State state = State.INIT; + + /** + * Indexer states. + */ + private enum State { + + /** + * Indexer has been created but is not yet running. + */ + INIT, + + /** + * Indexer is scanning the maps directory searching for files differing + * to the current index. + */ + SCAN, + + /** + * Indexer is indexing maps differing from the current index. + */ + INDEX, + + /** + * Indexer is idle; the current index is up-to-date. + */ + IDLE + + } + + /** + * The {@link MapManagerListener} attached to {@link #mapManager} to detect + * current map changes. + */ + private final MapManagerListener<G, A, R> mapManagerListener = new MapManagerListener<G, A, R>() { + + @Override + public void currentMapChanged(@Nullable final MapControl<G, A, R> mapControl) { + // ignore + } + + @Override + public void mapCreated(@NotNull final MapControl<G, A, R> mapControl, final boolean interactive) { + if (!mapControl.isPickmap()) { + mapControl.addMapControlListener(mapControlListener); + } + } + + @Override + public void mapClosing(@NotNull final MapControl<G, A, R> mapControl) { + // ignore + } + + @Override + public void mapClosed(@NotNull final MapControl<G, A, R> mapControl) { + if (!mapControl.isPickmap()) { + mapControl.removeMapControlListener(mapControlListener); + } + } + + }; + + /** + * The {@link MapControlListener} attached to all opened maps. + */ + @NotNull + private final MapControlListener<G, A, R> mapControlListener = new MapControlListener<G, A, R>() { + + @Override + public void saved(@NotNull final DefaultMapControl<G, A, R> mapControl) { + final File file = mapControl.getMapModel().getMapFile(); + if (file != null) { + mapsIndex.setPending(file); + } + } + + }; + + /** + * The {@link GlobalSettingsListener} attached to {@link #globalSettings} + * for tracking changed maps directories. + */ + @NotNull + private final GlobalSettingsListener globalSettingsListener = new GlobalSettingsListener() { + + @Override + public void showMainToolbarChanged(final boolean visible) { + // ignore + } + + @Override + public void mapsDirectoryChanged(@NotNull final File mapsDirectory) { + synchronized (syncMapsDirectory) { + newMapsDirectory = globalSettings.getMapsDirectory(); + } + } + + }; + + /** + * The {@link IndexListener} attached to {@link #mapsIndex} to detect newly + * added pending maps. + */ + @NotNull + private final IndexListener<File> indexListener = new IndexListener<File>() { + + /** + * {@inheritDoc} + */ + @Override + public void valueAdded(@NotNull final File value) { + // ignore + } + + /** + * {@inheritDoc} + */ + @Override + public void valueRemoved(@NotNull final File value) { + // ignore + } + + /** + * {@inheritDoc} + */ + @Override + public void nameChanged() { + // ignore + } + + /** + * {@inheritDoc} + */ + @Override + public void pendingChanged() { + mapsIndexSemaphore.release(); + } + + @Override + public void indexingFinished() { + // ignore + } + + }; + + /** + * The {@link Runnable} scanning the maps directory and updating the index. + */ + @NotNull + private final Runnable runnable = new Runnable() { + + @Override + public void run() { + while (!Thread.currentThread().isInterrupted()) { + updateMapsDirectory(); + indexPendingMaps(); + if (state == State.IDLE) { + try { + mapsIndexSemaphore.acquire(); + } catch (final InterruptedException ignored) { + Thread.currentThread().interrupt(); + break; + } + } + } + } + + }; + + /** + * The {@link Thread} executing {@link #runnable}. + */ + @NotNull + private final Thread thread = new Thread(runnable, "indexer"); + + /** + * Creates a new instance. + * @param mapsIndex the maps index to update + * @param mapManager the map manager for loading map files + * @param globalSettings the global settings instance; defines the indexed + * maps directory + */ + public MapsIndexer(@NotNull final MapsIndex mapsIndex, @NotNull final MapManager<G, A, R> mapManager, @NotNull final GlobalSettings globalSettings) { + this.mapsIndex = mapsIndex; + this.mapManager = mapManager; + this.globalSettings = globalSettings; + reportStateChange(); + } + + /** + * Starts indexing. Must not be called more than once. + */ + public void start() { + globalSettings.addGlobalSettingsListener(globalSettingsListener); + mapManager.addMapManagerListener(mapManagerListener); + synchronized (syncMapsDirectory) { + newMapsDirectory = globalSettings.getMapsDirectory(); + } + mapsIndex.addIndexListener(indexListener); + thread.start(); + } + + /** + * Stops indexing. Must not be called more than once or before {@link + * #start()} has been called. + * @throws InterruptedException if the current thread was interrupted + */ + public void stop() throws InterruptedException { + try { + thread.interrupt(); + thread.join(); + } finally { + globalSettings.removeGlobalSettingsListener(globalSettingsListener); + mapManager.removeMapManagerListener(mapManagerListener); + for (final MapControl<G, A, R> mapControl : mapManager.getOpenedMaps()) { + if (!mapControl.isPickmap()) { + mapControl.removeMapControlListener(mapControlListener); + } + } + mapsIndex.removeIndexListener(indexListener); + } + + synchronized (syncMapsDirectory) { + saveMapsIndex(); + } + } + + /** + * Blocks the calling thread until all pending maps have been indexed. + * @throws InterruptedException if the current thread was interrupted during + * wait + */ + public void waitForIdle() throws InterruptedException { + synchronized (syncState) { + while (state != State.IDLE) { + syncState.wait(1000); + } + } + } + + /** + * Checks whether {@link #newMapsDirectory} has been set and updates {@link + * #mapsDirectory} accordingly. + */ + private void updateMapsDirectory() { + final File tmpMapsDirectory; + synchronized (syncMapsDirectory) { + if (newMapsDirectory == null || (mapsDirectory != null && mapsDirectory.equals(newMapsDirectory))) { + return; + } + + setState(State.SCAN); + + saveMapsIndex(); + + tmpMapsDirectory = newMapsDirectory; + assert tmpMapsDirectory != null; + mapsDirectory = tmpMapsDirectory; + newMapsDirectory = null; + + loadMapsIndex(); + } + mapsIndex.beginUpdate(); + scanMapsDirectoryInt(tmpMapsDirectory, ""); + mapsIndex.endUpdate(); + } + + /** + * Saves {@link #mapsIndex} to its cache file if modified. + */ + private void saveMapsIndex() { + assert Thread.holdsLock(syncMapsDirectory); + if (mapsDirectory == null) { + return; + } + + if (!globalSettings.saveIndices()) { + return; + } + + if (!mapsIndex.isModified()) { + return; + } + + assert mapsDirectory != null; + final File cacheFile = getCacheFile(mapsDirectory); + try { + final OutputStream outputStream = new FileOutputStream(cacheFile); + try { + final ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream); + try { + mapsIndex.save(objectOutputStream); + } finally { + objectOutputStream.close(); + } + } finally { + outputStream.close(); + } + if (log.isInfoEnabled()) { + log.info(cacheFile + ": saved " + mapsIndex.size() + " entries"); + } + } catch (final IOException ex) { + log.warn(cacheFile + ": cannot save cache file: " + ex.getMessage()); + } + } + + /** + * Loads {@link #mapsIndex} from its cache file. + */ + private void loadMapsIndex() { + assert Thread.holdsLock(syncMapsDirectory); + assert mapsDirectory != null; + final File cacheFile = getCacheFile(mapsDirectory); + try { + final InputStream inputStream = new FileInputStream(cacheFile); + try { + final ObjectInputStream objectInputStream = new ObjectInputStream(inputStream); + try { + mapsIndex.load(objectInputStream); + } finally { + objectInputStream.close(); + } + } finally { + inputStream.close(); + } + if (log.isInfoEnabled()) { + log.info(cacheFile + ": loaded " + mapsIndex.size() + " entries"); + } + } catch (final FileNotFoundException ex) { + if (log.isDebugEnabled()) { + log.debug(cacheFile + ": cache file does not exist: " + ex.getMessage()); + } + mapsIndex.clear(); + } catch (final IOException ex) { + log.warn(cacheFile + ": cannot load cache file: " + ex.getMessage()); + mapsIndex.clear(); + } + } + + /** + * Scans a directory for files. Adds all files found to {@link #mapsIndex}. + * @param dir the directory to scan + * @param mapPath the map path corresponding to <code>dir</code> + */ + private void scanMapsDirectoryInt(@NotNull final File dir, @NotNull final String mapPath) { + final File[] files = dir.listFiles(); + if (files == null) { + return; + } + + for (final File file : files) { + if (file.isFile()) { + mapsIndex.add(file, file.lastModified()); + } else if (file.isDirectory() && !file.getName().equalsIgnoreCase(".svn") && !file.getName().equalsIgnoreCase(".dedit")) { + scanMapsDirectoryInt(file, mapPath + "/" + file.getName()); + } + } + } + + /** + * Indexes one pending map from {@link #mapsIndex}. Does nothing if no + * pending map exists. + */ + private void indexPendingMaps() { + final File file = mapsIndex.removePending(); + if (file == null) { + setState(State.IDLE); + return; + } + + setState(State.INDEX); + final long timestamp = file.lastModified(); + final MapControl<G, A, R> mapControl; + try { + mapControl = mapManager.openMapFile(file, false); + } catch (final IOException ex) { + if (log.isInfoEnabled()) { + log.info(file + ": load failed:" + ex.getMessage()); + } + return; + } + try { + final String mapName = mapControl.getMapModel().getMapArchObject().getMapName(); + if (log.isDebugEnabled()) { + log.debug(file + ": indexing as '" + mapName + "'"); + } + mapsIndex.setName(file, timestamp, mapName); + } finally { + mapManager.release(mapControl); + } + } + + /** + * Returns the cache file for a given maps directory. + * @param mapsDirectory the maps directory + * @return the cache file + */ + @NotNull + private static File getCacheFile(@NotNull final File mapsDirectory) { + final byte[] key = new byte[16]; + final Xtea xtea = new Xtea(key); + final byte[] data; + try { + data = mapsDirectory.getAbsoluteFile().toString().getBytes("UTF-8"); + } catch (final UnsupportedEncodingException ex) { + throw new AssertionError(ex); // UTF-8 must be supported + } + final byte[] hash = new byte[8]; + final byte[] in = new byte[8]; + final byte[] out = new byte[8]; + int i; + for (i = 0; i + 8 < data.length; i++) { + System.arraycopy(data, i, in, 0, 8); + xtea.encrypt(in, out); + for (int j = 0; j < 8; j++) { + hash[j] ^= out[j]; + } + } + final int len = data.length % 8; + System.arraycopy(data, i, in, 0, len); + in[len] = (byte) 1; + Arrays.fill(in, len + 1, 8, (byte) 0); + xtea.encrypt(in, out); + for (int j = 0; j < 8; j++) { + hash[j] ^= out[j]; + } + + final StringBuilder sb = new StringBuilder("index/maps/"); + for (int j = 0; j < 8; j++) { + sb.append(String.format("%02x", hash[j] & 0xff)); + } + sb.append(mapsDirectory.getName()); + final File file = ConfigFileUtils.getHomeFile(sb.toString()); + final File dir = file.getParentFile(); + if (dir != null && !dir.exists() && !dir.mkdirs()) { + log.warn("cannot create directory: " + dir); + } + return file; + } + + /** + * Sets a new value to {@link #state}. Logs changed values. + * @param state the new state + */ + private void setState(@NotNull final State state) { + synchronized (syncState) { + if (this.state == state) { + return; + } + + this.state = state; + reportStateChange(); + syncState.notifyAll(); + } + } + + /** + * Logs a changed value of {@link #state}. + */ + private void reportStateChange() { + if (log.isDebugEnabled()) { + log.debug("state=" + state); + } + + mapsIndex.indexingFinished(); + } + +} // class MapsIndexer Property changes on: trunk/model/src/app/net/sf/gridarta/model/index/MapsIndexer.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Modified: trunk/model/src/app/net/sf/gridarta/model/settings/DefaultGlobalSettings.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/settings/DefaultGlobalSettings.java 2010-11-17 18:25:31 UTC (rev 8799) +++ trunk/model/src/app/net/sf/gridarta/model/settings/DefaultGlobalSettings.java 2010-11-17 19:39:35 UTC (rev 8800) @@ -530,4 +530,12 @@ preferences.put(PREFERENCES_USER_NAME, userName); } + /** + * {@inheritDoc} + */ + @Override + public boolean saveIndices() { + return true; + } + } // class DefaultGlobalSettings Modified: trunk/model/src/app/net/sf/gridarta/model/settings/GlobalSettings.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/settings/GlobalSettings.java 2010-11-17 18:25:31 UTC (rev 8799) +++ trunk/model/src/app/net/sf/gridarta/model/settings/GlobalSettings.java 2010-11-17 19:39:35 UTC (rev 8800) @@ -231,4 +231,10 @@ */ void removeGlobalSettingsListener(@NotNull GlobalSettingsListener listener); + /** + * Returns whether indices should be saved to disk. + * @return whether indices should be saved to disk + */ + boolean saveIndices(); + } // interface GlobalSettings Added: trunk/model/src/test/net/sf/gridarta/model/index/MapsIndexTest.java =================================================================== --- trunk/model/src/test/net/sf/gridarta/model/index/MapsIndexTest.java (rev 0) +++ trunk/model/src/test/net/sf/gridarta/model/index/MapsIndexTest.java 2010-11-17 19:39:35 UTC (rev 8800) @@ -0,0 +1,256 @@ +/* + * 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.index; + +import java.io.File; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.TreeSet; +import org.jetbrains.annotations.NotNull; +import org.junit.Assert; +import org.junit.Test; + +/** + * Regression tests for {@link MapsIndex}. + * @author Andreas Kirschbaum + */ +public class MapsIndexTest { + + /** + * Checks that values are correctly marked as pending. + */ + @Test + public void test1() { + final Index<File> index = new MapsIndex(); + index.add(new File("a"), 1); + index.add(new File("b"), 1); + index.add(new File("c"), 1); + Assert.assertEquals("a,b,c", getPending(index)); + Assert.assertEquals("", getPending(index)); + index.add(new File("d"), 1); + Assert.assertEquals("d", getPending(index)); + index.add(new File("b"), 1); + index.add(new File("d"), 1); + Assert.assertEquals("", getPending(index)); + index.add(new File("b"), 2); + index.add(new File("d"), 2); + Assert.assertEquals("b,d", getPending(index)); + index.setPending(new File("a")); + Assert.assertEquals("a", getPending(index)); + index.setPending(new File("a")); + index.add(new File("b"), 3); + index.add(new File("c"), 3); + index.remove(new File("b")); + Assert.assertEquals("a,c", getPending(index)); + } + + /** + * Checks that {@link Index#findPartialName(String)} works as expected. + */ + @Test + public void testFind1() { + final Index<File> index = new MapsIndex(); + Assert.assertEquals("", findPartialName(index, "a")); + index.add(new File("abc"), 1); + index.setName(new File("abc"), 1, "abC"); + Assert.assertEquals("abc", findPartialName(index, "a")); + Assert.assertEquals("abc", findPartialName(index, "b")); + Assert.assertEquals("", findPartialName(index, "x")); + index.add(new File("bcd"), 1); + index.setName(new File("bcd"), 1, "BcD"); + Assert.assertEquals("abc", findPartialName(index, "a")); + Assert.assertEquals("abc,bcd", findPartialName(index, "b")); + Assert.assertEquals("abc,bcd", findPartialName(index, "Bc")); + Assert.assertEquals("", findPartialName(index, "x")); + } + + /** + * Checks that {@link Index#beginUpdate()} and {@link Index#endUpdate()} + * works as expected. + */ + @Test + public void testTransaction() { + final Index<File> index = new MapsIndex(); + index.add(new File("a"), 1); + index.add(new File("b"), 1); + index.add(new File("c"), 1); + index.setName(new File("a"), 2, "a"); + index.setName(new File("b"), 2, "a"); + index.setName(new File("c"), 2, "a"); + index.beginUpdate(); + index.add(new File("b"), 1); + index.add(new File("c"), 2); + index.add(new File("d"), 2); + index.endUpdate(); + index.setName(new File("b"), 2, "a"); + index.setName(new File("c"), 2, "a"); + index.setName(new File("d"), 2, "a"); + Assert.assertEquals("b,c,d", findPartialName(index, "a")); + } + + /** + * Checks that listeners are notified. + */ + @Test + public void testListener() { + final Index<File> index = new MapsIndex(); + final Listener listener = new Listener(); + index.addIndexListener(listener); + + index.add(new File("a"), 1); + Assert.assertEquals("add a\n" + "pending changed\n", listener.getAndClearEvents()); + + index.add(new File("a"), 1); + Assert.assertEquals("", listener.getAndClearEvents()); + + index.add(new File("a"), 2); + Assert.assertEquals("", listener.getAndClearEvents()); + + index.add(new File("b"), 2); + index.add(new File("c"), 2); + Assert.assertEquals("add b\n" + "add c\n", listener.getAndClearEvents()); + + index.remove(new File("b")); + Assert.assertEquals("del b\n" + "name changed\n", listener.getAndClearEvents()); + + index.setName(new File("a"), 2, "name1"); + index.setName(new File("b"), 2, "name2"); + index.setName(new File("c"), 2, "name3"); + Assert.assertEquals("name changed\n" + "name changed\n" + "name changed\n", listener.getAndClearEvents()); + } + + /** + * Returns all pending values of a {@link MapsIndex}. Afterwards the pending + * entries have been removed from the index. + * @param index the index + * @return the pending values + */ + @NotNull + private static String getPending(@NotNull final Index<File> index) { + final Collection<File> pendingFiles = new HashSet<File>(); + for (; ;) { + final File pendingFile = index.removePending(); + if (pendingFile == null) { + break; + } + pendingFiles.add(pendingFile); + } + return format(pendingFiles); + } + + /** + * Calls {@link Index#findPartialName(String)} on the given {@link Index} + * and name and returns a string representation of the result. + * @param index the index + * @param name the name + * @return the string representation + */ + @NotNull + private static String findPartialName(@NotNull final Index<File> index, @NotNull final String name) { + return format(index.findPartialName(name)); + } + + /** + * Returns a text representation of a {@link Collection}. + * @param files the collection + * @return the text representation + */ + @NotNull + private static String format(@NotNull final Collection<File> files) { + final TreeSet<File> tmp = new TreeSet<File>(files); + final StringBuilder sb = new StringBuilder(); + final Iterator<File> it = tmp.iterator(); + if (it.hasNext()) { + sb.append(it.next()); + while (it.hasNext()) { + sb.append(','); + sb.append(it.next()); + } + } + return sb.toString(); + } + + /** + * An {@link IndexListener} that records a text representation of all + * generated events. + */ + private static class Listener implements IndexListener<File> { + + /** + * The recorded events in text representation. + */ + @NotNull + private final StringBuilder stringBuilder = new StringBuilder(); + + /** + * {@inheritDoc} + */ + @Override + public void valueAdded(@NotNull final File value) { + stringBuilder.append("add ").append(value).append("\n"); + } + + /** + * {@inheritDoc} + */ + @Override + public void valueRemoved(@NotNull final File value) { + stringBuilder.append("del ").append(value).append("\n"); + } + + /** + * {@inheritDoc} + */ + @Override + public void nameChanged() { + stringBuilder.append("name changed\n"); + } + + /** + * {@inheritDoc} + */ + @Override + public void pendingChanged() { + stringBuilder.append("pending changed\n"); + } + + /** + * {@inheritDoc} + */ + @Override + public void indexingFinished() { + stringBuilder.append("indexing finished"); + } + + /** + * Returns the accumulated events. + * @return the events + */ + @NotNull + public String getAndClearEvents() { + final String result = stringBuilder.toString(); + stringBuilder.setLength(0); + return result; + } + + } + +} // class MapsIndexTest Property changes on: trunk/model/src/test/net/sf/gridarta/model/index/MapsIndexTest.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Added: trunk/model/src/test/net/sf/gridarta/model/index/MapsIndexerTest.java =================================================================== --- trunk/model/src/test/net/sf/gridarta/model/index/MapsIndexerTest.java (rev 0) +++ trunk/model/src/test/net/sf/gridarta/model/index/MapsIndexerTest.java 2010-11-17 19:39:35 UTC (rev 8800) @@ -0,0 +1,179 @@ +/* + * 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.index; + +import java.io.File; +import java.io.IOException; +import java.util.Collection; +import java.util.Iterator; +import net.sf.gridarta.model.archetype.TestArchetype; +import net.sf.gridarta.model.gameobject.TestGameObject; +import net.sf.gridarta.model.maparchobject.TestMapArchObject; +import net.sf.gridarta.model.mapcontrol.DefaultMapControl; +import net.sf.gridarta.model.mapcontrol.TestMapControlCreator; +import net.sf.gridarta.model.mapmanager.MapManager; +import net.sf.gridarta.model.mapmodel.... [truncated message content] |
From: <aki...@us...> - 2010-11-17 18:25:37
|
Revision: 8799 http://gridarta.svn.sourceforge.net/gridarta/?rev=8799&view=rev Author: akirschbaum Date: 2010-11-17 18:25:31 +0000 (Wed, 17 Nov 2010) Log Message: ----------- Add @NotNull annotation. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/gui/delayedmapmodel/DelayedMapModelListenerManager.java Modified: trunk/src/app/net/sf/gridarta/gui/delayedmapmodel/DelayedMapModelListenerManager.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/delayedmapmodel/DelayedMapModelListenerManager.java 2010-11-17 18:22:35 UTC (rev 8798) +++ trunk/src/app/net/sf/gridarta/gui/delayedmapmodel/DelayedMapModelListenerManager.java 2010-11-17 18:25:31 UTC (rev 8799) @@ -111,6 +111,7 @@ * The {@link MapManagerListener} used to detect created and closed {@link * MapControl} instances. */ + @NotNull private final MapManagerListener<G, A, R> mapManagerListener = new MapManagerListener<G, A, R>() { /** {@inheritDoc} */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2010-11-17 18:22:41
|
Revision: 8798 http://gridarta.svn.sourceforge.net/gridarta/?rev=8798&view=rev Author: akirschbaum Date: 2010-11-17 18:22:35 +0000 (Wed, 17 Nov 2010) Log Message: ----------- Fix some race conditions when accessing loaded maps from different threads. Modified Paths: -------------- trunk/model/src/app/net/sf/gridarta/model/mapmanager/AbstractMapManager.java Modified: trunk/model/src/app/net/sf/gridarta/model/mapmanager/AbstractMapManager.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/mapmanager/AbstractMapManager.java 2010-11-17 18:20:10 UTC (rev 8797) +++ trunk/model/src/app/net/sf/gridarta/model/mapmanager/AbstractMapManager.java 2010-11-17 18:22:35 UTC (rev 8798) @@ -21,10 +21,10 @@ import java.io.File; import java.io.IOException; -import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.face.FaceObjectProviders; import net.sf.gridarta.model.face.FaceObjectProvidersListener; @@ -85,7 +85,7 @@ /** * All open maps. */ - private final List<MapControl<G, A, R>> mapControls = new ArrayList<MapControl<G, A, R>>(); + private final List<MapControl<G, A, R>> mapControls = new CopyOnWriteArrayList<MapControl<G, A, R>>(); /** * The MapManagerListeners to inform of changes. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2010-11-17 18:20:16
|
Revision: 8797 http://gridarta.svn.sourceforge.net/gridarta/?rev=8797&view=rev Author: akirschbaum Date: 2010-11-17 18:20:10 +0000 (Wed, 17 Nov 2010) Log Message: ----------- Disable warning. Modified Paths: -------------- trunk/gridarta.ipr Modified: trunk/gridarta.ipr =================================================================== --- trunk/gridarta.ipr 2010-11-17 18:18:22 UTC (rev 8796) +++ trunk/gridarta.ipr 2010-11-17 18:20:10 UTC (rev 8797) @@ -236,9 +236,6 @@ </inspection_tool> <inspection_tool class="CallToStringConcatCanBeReplacedByOperator" enabled="true" level="WARNING" enabled_by_default="true" /> <inspection_tool class="CastConflictsWithInstanceof" enabled="true" level="WARNING" enabled_by_default="true" /> - <inspection_tool class="CastThatLosesPrecision" enabled="true" level="WARNING" enabled_by_default="true"> - <option name="ignoreIntegerCharCasts" value="false" /> - </inspection_tool> <inspection_tool class="CastToIncompatibleInterface" enabled="true" level="WARNING" enabled_by_default="true" /> <inspection_tool class="CatchGenericClass" enabled="true" level="WARNING" enabled_by_default="true" /> <inspection_tool class="ChainedEquality" enabled="true" level="WARNING" enabled_by_default="true" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2010-11-17 18:18:28
|
Revision: 8796 http://gridarta.svn.sourceforge.net/gridarta/?rev=8796&view=rev Author: akirschbaum Date: 2010-11-17 18:18:22 +0000 (Wed, 17 Nov 2010) Log Message: ----------- Fix typo. Modified Paths: -------------- trunk/model/src/test/net/sf/gridarta/model/mapcontrol/TestMapControlCreator.java Modified: trunk/model/src/test/net/sf/gridarta/model/mapcontrol/TestMapControlCreator.java =================================================================== --- trunk/model/src/test/net/sf/gridarta/model/mapcontrol/TestMapControlCreator.java 2010-11-15 20:12:04 UTC (rev 8795) +++ trunk/model/src/test/net/sf/gridarta/model/mapcontrol/TestMapControlCreator.java 2010-11-17 18:18:22 UTC (rev 8796) @@ -284,7 +284,7 @@ /** * Returns the {@link MapManager pickmap manager} instance. - * @return the test pickmap manager instance + * @return the pickmap manager instance */ @NotNull public MapManager<TestGameObject, TestMapArchObject, TestArchetype> getPickmapManager() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2010-11-15 20:12:10
|
Revision: 8795 http://gridarta.svn.sourceforge.net/gridarta/?rev=8795&view=rev Author: akirschbaum Date: 2010-11-15 20:12:04 +0000 (Mon, 15 Nov 2010) Log Message: ----------- Add 'preparePublish' build target. Modified Paths: -------------- trunk/INSTALL trunk/build.xml Property Changed: ---------------- trunk/ trunk/atrinik/ trunk/crossfire/ trunk/daimonin/ Property changes on: trunk ___________________________________________________________________ Modified: svn:ignore - classes dest developer.properties docs gridarta.iws out AtrinikEditor.jar CrossfireEditor.jar DaimoninEditor.jar + classes dest developer.properties dist docs gridarta.iws out AtrinikEditor.jar CrossfireEditor.jar DaimoninEditor.jar Modified: trunk/INSTALL =================================================================== --- trunk/INSTALL 2010-11-13 22:22:50 UTC (rev 8794) +++ trunk/INSTALL 2010-11-15 20:12:04 UTC (rev 8795) @@ -39,3 +39,41 @@ --------------------------------------- Change to the main directory and run "ant javadoc". The documentation will be placed in dest/doc/dev/api/. + + +How to Publish a Build +---------------------- +Gridarta supports updating itself through the GUI (Help|Update...). Gridarta +first checks whether an update is available, then downloads the update. + +To check whether an update is available, Gridarta downloads a file specified in +"update.url=" in atrinik/src/app/net/sf/gridarta/var/atrinik/action.properties, +crossfire/src/app/net/sf/gridarta/var/crossfire/action.properties, or +daimonin/src/app/net/sf/gridarta/var/daimonin/action.properties. This file +contains the following entries: + - update.url=Download URL to AtrinikEditor.jar, CrossfireEditor.jar, or + DaimoninEditor.jar. + - update.number=the Gridarta version number corresponding to update.url + - update.tstamp=the timestamp corresponding to update.url + - update.developer=the name of the developer providing the build + +If update.tstamp is newer than the timestamp of the currently running editor, an +update is available from update.url. The other entries are displayed to the +user. + +To provide a build, edit the value of "update.url" in +*/src/app/net/sf/gridarta/var/*/action.properties for the editor variant. Then +create or edit the file "developer.properties" in the project's root directory. +Add the following entries: + - build.developer=Name of the developer providing the build. + - user.update.url.atrinik=Download URL to AtrinikEditor.jar. + - user.update.url.crossfire=Download URL to CrossfireEditor.jar. + - user.update.url.daimonin=Download URL to DaimoninEditor.jar. +The definitions of user.update.url.* are optional for editor variants not +provided. + +Run "ant preparePublish". This compiles the editors and creates the file +"update.properties" for the editor variants to publish. The result is in +dist/atrinik, dist/crossfire, and dist/daimonin. + +Upload the contents of dist/atrinik, dist/crossfire, and dist/daimonin. Property changes on: trunk/atrinik ___________________________________________________________________ Deleted: svn:ignore - developer.properties update.properties Modified: trunk/build.xml =================================================================== --- trunk/build.xml 2010-11-13 22:22:50 UTC (rev 8794) +++ trunk/build.xml 2010-11-15 20:12:04 UTC (rev 8795) @@ -1157,4 +1157,39 @@ </java> </target> + <target name="preparePublish" description="Prepare files to publish." depends="preparePublish-atrinik,preparePublish-crossfire,preparePublish-daimonin"/> + + <target name="preparePublish-atrinik" description="Prepare files to publish AtrinikEditor.jar." depends="jar" if="user.update.url.atrinik"> + <mkdir dir="${dist.dir}/atrinik"/> + <echo file="${dist.dir}/atrinik/update.properties"> +update.number=${build.number} +update.tstamp=${build.tstamp} +update.developer=${build.developer} +update.url=${user.update.url.atrinik} + </echo> + <copy file="AtrinikEditor.jar" tofile="${dist.dir}/atrinik/AtrinikEditor.jar"/> + </target> + + <target name="preparePublish-crossfire" description="Prepare files to publish CrossfireEditor.jar." depends="jar" if="user.update.url.crossfire"> + <mkdir dir="${dist.dir}/crossfire"/> + <echo file="${dist.dir}/crossfire/update.properties"> +update.number=${build.number} +update.tstamp=${build.tstamp} +update.developer=${build.developer} +update.url=${user.update.url.crossfire} + </echo> + <copy file="CrossfireEditor.jar" tofile="${dist.dir}/crossfire/CrossfireEditor.jar"/> + </target> + + <target name="preparePublish-daimonin" description="Prepare files to publish DaimoninEditor.jar." depends="jar" if="user.update.url.daimonin"> + <mkdir dir="${dist.dir}/daimonin"/> + <echo file="${dist.dir}/daimonin/update.properties"> +update.number=${build.number} +update.tstamp=${build.tstamp} +update.developer=${build.developer} +update.url=${user.update.url.daimonin} + </echo> + <copy file="DaimoninEditor.jar" tofile="${dist.dir}/daimonin/DaimoninEditor.jar"/> + </target> + </project> Property changes on: trunk/crossfire ___________________________________________________________________ Deleted: svn:ignore - developer.properties Property changes on: trunk/daimonin ___________________________________________________________________ Deleted: svn:ignore - developer.properties update.properties This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2010-11-13 22:22:57
|
Revision: 8794 http://gridarta.svn.sourceforge.net/gridarta/?rev=8794&view=rev Author: akirschbaum Date: 2010-11-13 22:22:50 +0000 (Sat, 13 Nov 2010) Log Message: ----------- Remove empty directories. Removed Paths: ------------- trunk/model/src/app/net/sf/gridarta/model/map/ trunk/model/src/test/net/sf/gridarta/model/scripts/ trunk/src/app/net/sf/gridarta/gui/io/ trunk/src/app/net/sf/gridarta/validation/ trunk/src/test/net/sf/gridarta/gui/filter/ trunk/src/test/net/sf/gridarta/gui/mapcursor/ trunk/src/test/net/sf/gridarta/gui/scripts/ trunk/src/test/net/sf/gridarta/model/ trunk/src/test/net/sf/gridarta/validation/ trunk/src/test/net/sf/gridarta/var/ trunk/utils/src/test/net/sf/gridarta/gui/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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...> - 2010-11-13 21:50:04
|
Revision: 8792 http://gridarta.svn.sourceforge.net/gridarta/?rev=8792&view=rev Author: akirschbaum Date: 2010-11-13 21:49:58 +0000 (Sat, 13 Nov 2010) Log Message: ----------- Fix compiler warning. Modified Paths: -------------- trunk/script/src/app/net/sf/gridarta/script/ScriptConsole.java Modified: trunk/script/src/app/net/sf/gridarta/script/ScriptConsole.java =================================================================== --- trunk/script/src/app/net/sf/gridarta/script/ScriptConsole.java 2010-11-13 21:46:44 UTC (rev 8791) +++ trunk/script/src/app/net/sf/gridarta/script/ScriptConsole.java 2010-11-13 21:49:58 UTC (rev 8792) @@ -23,4 +23,9 @@ public class ScriptConsole extends JConsole { + /** + * The serial version UID. + */ + private static final long serialVersionUID = 1L; + } // class ScriptConsole This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2010-11-13 21:46:51
|
Revision: 8791 http://gridarta.svn.sourceforge.net/gridarta/?rev=8791&view=rev Author: akirschbaum Date: 2010-11-13 21:46:44 +0000 (Sat, 13 Nov 2010) Log Message: ----------- Extract plugin script related code into separate module 'script'. Modified Paths: -------------- trunk/atrinik.iml trunk/build.xml trunk/crossfire.iml trunk/daimonin.iml trunk/gridarta.iml trunk/gridarta.ipr Added Paths: ----------- trunk/script/ trunk/script/src/ trunk/script/src/app/ trunk/script/src/app/net/ trunk/script/src/app/net/sf/ trunk/script/src/app/net/sf/gridarta/ trunk/script/src/app/net/sf/gridarta/script/ trunk/script/src/test/ trunk/script.iml Removed Paths: ------------- trunk/src/app/net/sf/gridarta/script/ Modified: trunk/atrinik.iml =================================================================== --- trunk/atrinik.iml 2010-11-13 20:18:58 UTC (rev 8790) +++ trunk/atrinik.iml 2010-11-13 21:46:44 UTC (rev 8791) @@ -12,6 +12,7 @@ <orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="module" module-name="gridarta" /> <orderEntry type="module" module-name="model" /> + <orderEntry type="module" module-name="script" /> <orderEntry type="module" module-name="utils" /> <orderEntry type="module-library"> <library> Modified: trunk/build.xml =================================================================== --- trunk/build.xml 2010-11-13 20:18:58 UTC (rev 8790) +++ trunk/build.xml 2010-11-13 21:46:44 UTC (rev 8791) @@ -106,6 +106,14 @@ <pathelement location="${build.dir}/preferences/test"/> </path> + <path id="path.class.script.app"> + <pathelement location="${build.dir}/script/app"/> + </path> + <path id="path.class.script.test"> + <path refid="path.class.script.app"/> + <pathelement location="${build.dir}/script/test"/> + </path> + <path id="path.class.textedit.app"> <pathelement location="${build.dir}/textedit/app"/> </path> @@ -183,6 +191,7 @@ <fileset dir="${build.dir}/gridarta/app"/> <fileset dir="${build.dir}/model/app"/> <fileset dir="${build.dir}/preferences/app"/> + <fileset dir="${build.dir}/script/app"/> <fileset dir="${build.dir}/textedit/app"/> <fileset dir="${build.dir}/utils/app"/> <fileset dir="${build.dir}" includes="build.properties"/> @@ -220,6 +229,7 @@ <fileset dir="${build.dir}/gridarta/app"/> <fileset dir="${build.dir}/model/app"/> <fileset dir="${build.dir}/preferences/app"/> + <fileset dir="${build.dir}/script/app"/> <fileset dir="${build.dir}/textedit/app"/> <fileset dir="${build.dir}/utils/app"/> <fileset dir="${build.dir}" includes="build.properties"/> @@ -257,6 +267,7 @@ <fileset dir="${build.dir}/gridarta/app"/> <fileset dir="${build.dir}/model/app"/> <fileset dir="${build.dir}/preferences/app"/> + <fileset dir="${build.dir}/script/app"/> <fileset dir="${build.dir}/textedit/app"/> <fileset dir="${build.dir}/utils/app"/> <fileset dir="${build.dir}" includes="build.properties"/> @@ -304,12 +315,13 @@ </echoproperties> </target> - <target name="compile-atrinik" description="Compiles the atrinik module." depends="compile-gridarta,compile-model,compile-preferences,compile-utils"> + <target name="compile-atrinik" description="Compiles the atrinik module." depends="compile-gridarta,compile-model,compile-preferences,compile-script,compile-utils"> <mkdir dir="${build.dir}/atrinik/app"/> <javac srcdir="atrinik/src/app" destdir="${build.dir}/atrinik/app" encoding="${build.source.encoding}" source="${build.source.version}" target="${build.target.version}" includeantruntime="false" debug="${debug}"> <classpath> <path refid="path.class.gridarta.app"/> <path refid="path.class.model.app"/> + <path refid="path.class.script.app"/> <path refid="path.class.utils.app"/> <path refid="path.lib.annotations"/> <path refid="path.lib.japi-swing-action"/> @@ -337,12 +349,13 @@ </copy> </target> - <target name="compile-crossfire" description="Compiles the crossfire module." depends="compile-gridarta,compile-model,compile-preferences,compile-utils"> + <target name="compile-crossfire" description="Compiles the crossfire module." depends="compile-gridarta,compile-model,compile-preferences,compile-script,compile-utils"> <mkdir dir="${build.dir}/crossfire/app"/> <javac srcdir="crossfire/src/app" destdir="${build.dir}/crossfire/app" encoding="${build.source.encoding}" source="${build.source.version}" target="${build.target.version}" includeantruntime="false" debug="${debug}"> <classpath> <path refid="path.class.gridarta.app"/> <path refid="path.class.model.app"/> + <path refid="path.class.script.app"/> <path refid="path.class.utils.app"/> <path refid="path.lib.annotations"/> <path refid="path.lib.japi-swing-action"/> @@ -370,12 +383,13 @@ </copy> </target> - <target name="compile-daimonin" description="Compiles the daimonin module." depends="compile-gridarta,compile-model,compile-utils"> + <target name="compile-daimonin" description="Compiles the daimonin module." depends="compile-gridarta,compile-model,compile-script,compile-utils"> <mkdir dir="${build.dir}/daimonin/app"/> <javac srcdir="daimonin/src/app" destdir="${build.dir}/daimonin/app" encoding="${build.source.encoding}" source="${build.source.version}" target="${build.target.version}" includeantruntime="false" debug="${debug}"> <classpath> <path refid="path.class.gridarta.app"/> <path refid="path.class.model.app"/> + <path refid="path.class.script.app"/> <path refid="path.class.utils.app"/> <path refid="path.lib.annotations"/> <path refid="path.lib.japi-swing-action"/> @@ -401,12 +415,13 @@ </copy> </target> - <target name="compile-gridarta" description="Compiles the gridarta module." depends="compile-model,compile-preferences,compile-textedit,compile-utils"> + <target name="compile-gridarta" description="Compiles the gridarta module." depends="compile-model,compile-preferences,compile-script,compile-textedit,compile-utils"> <mkdir dir="${build.dir}/gridarta/app"/> <javac srcdir="src/app" destdir="${build.dir}/gridarta/app" encoding="${build.source.encoding}" source="${build.source.version}" target="${build.target.version}" includeantruntime="false" debug="${debug}"> <classpath> <path refid="path.class.model.app"/> <path refid="path.class.preferences.app"/> + <path refid="path.class.script.app"/> <path refid="path.class.textedit.app"/> <path refid="path.class.utils.app"/> <path refid="path.lib.annotations"/> @@ -496,6 +511,32 @@ </copy> </target> + <target name="compile-script" description="Compiles the script module." depends="compile-model,compile-utils"> + <mkdir dir="${build.dir}/script/app"/> + <javac srcdir="script/src/app" destdir="${build.dir}/script/app" encoding="${build.source.encoding}" source="${build.source.version}" target="${build.target.version}" includeantruntime="false" debug="${debug}"> + <classpath> + <path refid="path.class.model.app"/> + <path refid="path.class.utils.app"/> + <path refid="path.lib.annotations"/> + <path refid="path.lib.bsh-core"/> + <path refid="path.lib.bsh-util"/> + <path refid="path.lib.jdom"/> + <path refid="path.lib.log4j"/> + </classpath> + <compilerarg line="${javac.args}"/> + </javac> + <mkdir dir="${build.dir}/script/test"/> + <javac srcdir="script/src/test" destdir="${build.dir}/script/test" encoding="${build.source.encoding}" source="${build.source.version}" target="${build.target.version}" includeantruntime="false" debug="yes"> + <classpath> + <path refid="path.class.script.app"/> + </classpath> + <compilerarg line="${javac.args}"/> + </javac> + <copy todir="${build.dir}/script/app"> + <fileset dir="script/src/app" includes="**/*.properties"/> + </copy> + </target> + <target name="compile-textedit" description="Compiles the textedit module." depends="compile-utils"> <mkdir dir="${build.dir}/textedit/app"/> <javac srcdir="textedit/src/app" destdir="${build.dir}/textedit/app" encoding="${build.source.encoding}" source="${build.source.version}" target="${build.target.version}" includeantruntime="false" debug="${debug}"> @@ -605,6 +646,7 @@ <path refid="path.class.gridarta.test"/> <path refid="path.class.model.test"/> <path refid="path.class.preferences.test"/> + <path refid="path.class.script.test"/> <path refid="path.class.textedit.test"/> <path refid="path.class.utils.test"/> </sourcepath> @@ -620,6 +662,8 @@ <packageset dir="model/src/test" defaultexcludes="yes"/> <packageset dir="preferences/src/app" defaultexcludes="yes"/> <packageset dir="preferences/src/test" defaultexcludes="yes"/> + <packageset dir="script/src/app" defaultexcludes="yes"/> + <packageset dir="script/src/test" defaultexcludes="yes"/> <packageset dir="textedit/src/app" defaultexcludes="yes"/> <packageset dir="textedit/src/test" defaultexcludes="yes"/> <packageset dir="utils/src/app" defaultexcludes="yes"/> @@ -805,6 +849,8 @@ <fileset dir="model/src/test" includes="**/*.java"/> <fileset dir="preferences/src/app" includes="**/*.java"/> <fileset dir="preferences/src/test" includes="**/*.java"/> + <fileset dir="script/src/app" includes="**/*.java"/> + <fileset dir="script/src/test" includes="**/*.java"/> <fileset dir="textedit/src/app" includes="**/*.java"/> <fileset dir="textedit/src/test" includes="**/*.java"/> <fileset dir="utils/src/app" includes="**/*.java"/> @@ -843,6 +889,7 @@ <path refid="path.class.gridarta.test"/> <path refid="path.class.model.test"/> <path refid="path.class.preferences.test"/> + <path refid="path.class.script.test"/> <path refid="path.class.textedit.test"/> <path refid="path.class.utils.test"/> </sourcepath> @@ -858,6 +905,8 @@ <packageset dir="model/src/test" defaultexcludes="yes"/> <packageset dir="preferences/src/app" defaultexcludes="yes"/> <packageset dir="preferences/src/test" defaultexcludes="yes"/> + <packageset dir="script/src/app" defaultexcludes="yes"/> + <packageset dir="script/src/test" defaultexcludes="yes"/> <packageset dir="textedit/src/app" defaultexcludes="yes"/> <packageset dir="textedit/src/test" defaultexcludes="yes"/> <packageset dir="utils/src/app" defaultexcludes="yes"/> @@ -892,7 +941,7 @@ <target name="test" description="Executes all tests." depends="test-junit,test-mapvalidator-crossfire,test-mapvalidator-daimonin"/> - <target name="test-junit" description="Executes the junit tests." depends="test-atrinik,test-crossfire,test-daimonin,test-gridarta,test-model,test-preferences,test-textedit,test-utils"> + <target name="test-junit" description="Executes the junit tests." depends="test-atrinik,test-crossfire,test-daimonin,test-gridarta,test-model,test-preferences,test-script,test-textedit,test-utils"> <junitreport todir="${docs.dir}/test"> <fileset dir="${docs.dir}/test"> <include name="TEST-*.xml"/> @@ -1038,6 +1087,24 @@ </junit> </target> + <target name="test-script" depends="compile-script"> + <mkdir dir="${docs.dir}/test"/> + <junit printsummary="no" haltonfailure="yes"> + <classpath> + <path refid="path.class.script.test"/> + </classpath> + <formatter type="plain"/> + <formatter type="xml"/> + <batchtest todir="${docs.dir}/test"> + <fileset dir="${build.dir}/script/test"> + <include name="**/*Test.class"/> + <exclude name="**/*$*"/> + <exclude name="**/Abstract*Test.class"/> + </fileset> + </batchtest> + </junit> + </target> + <target name="test-textedit" depends="compile-textedit"> <mkdir dir="${docs.dir}/test"/> <junit printsummary="no" haltonfailure="yes"> Modified: trunk/crossfire.iml =================================================================== --- trunk/crossfire.iml 2010-11-13 20:18:58 UTC (rev 8790) +++ trunk/crossfire.iml 2010-11-13 21:46:44 UTC (rev 8791) @@ -13,6 +13,7 @@ <orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="module" module-name="gridarta" /> <orderEntry type="module" module-name="model" /> + <orderEntry type="module" module-name="script" /> <orderEntry type="module" module-name="utils" /> <orderEntry type="module-library"> <library> Modified: trunk/daimonin.iml =================================================================== --- trunk/daimonin.iml 2010-11-13 20:18:58 UTC (rev 8790) +++ trunk/daimonin.iml 2010-11-13 21:46:44 UTC (rev 8791) @@ -12,6 +12,7 @@ <orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="module" module-name="gridarta" /> <orderEntry type="module" module-name="model" /> + <orderEntry type="module" module-name="script" /> <orderEntry type="module" module-name="utils" /> <orderEntry type="module-library"> <library> Modified: trunk/gridarta.iml =================================================================== --- trunk/gridarta.iml 2010-11-13 20:18:58 UTC (rev 8790) +++ trunk/gridarta.iml 2010-11-13 21:46:44 UTC (rev 8791) @@ -20,6 +20,7 @@ <orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="module" module-name="model" /> <orderEntry type="module" module-name="preferences" /> + <orderEntry type="module" module-name="script" /> <orderEntry type="module" module-name="textedit" /> <orderEntry type="module" module-name="utils" /> <orderEntry type="module-library"> Modified: trunk/gridarta.ipr =================================================================== --- trunk/gridarta.ipr 2010-11-13 20:18:58 UTC (rev 8790) +++ trunk/gridarta.ipr 2010-11-13 21:46:44 UTC (rev 8791) @@ -1416,6 +1416,7 @@ <module fileurl="file://$PROJECT_DIR$/gridarta.iml" filepath="$PROJECT_DIR$/gridarta.iml" /> <module fileurl="file://$PROJECT_DIR$/model.iml" filepath="$PROJECT_DIR$/model.iml" /> <module fileurl="file://$PROJECT_DIR$/preferences.iml" filepath="$PROJECT_DIR$/preferences.iml" /> + <module fileurl="file://$PROJECT_DIR$/script.iml" filepath="$PROJECT_DIR$/script.iml" /> <module fileurl="file://$PROJECT_DIR$/textedit.iml" filepath="$PROJECT_DIR$/textedit.iml" /> <module fileurl="file://$PROJECT_DIR$/utils.iml" filepath="$PROJECT_DIR$/utils.iml" /> </modules> Added: trunk/script.iml =================================================================== --- trunk/script.iml (rev 0) +++ trunk/script.iml 2010-11-13 21:46:44 UTC (rev 8791) @@ -0,0 +1,60 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module type="JAVA_MODULE" version="4"> + <component name="NewModuleRootManager" inherit-compiler-output="true"> + <exclude-output /> + <content url="file://$MODULE_DIR$/script"> + <sourceFolder url="file://$MODULE_DIR$/script/src/app" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/script/src/test" isTestSource="true" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + <orderEntry type="module" module-name="model" /> + <orderEntry type="module" module-name="utils" /> + <orderEntry type="module-library"> + <library> + <CLASSES> + <root url="jar://$MODULE_DIR$/lib/annotations.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES /> + </library> + </orderEntry> + <orderEntry type="module-library"> + <library> + <CLASSES> + <root url="jar://$MODULE_DIR$/lib/jdom.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES /> + </library> + </orderEntry> + <orderEntry type="module-library"> + <library> + <CLASSES> + <root url="jar://$MODULE_DIR$/lib/log4j-1.2.13.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES /> + </library> + </orderEntry> + <orderEntry type="module-library"> + <library> + <CLASSES> + <root url="jar://$MODULE_DIR$/lib/bsh-core-2.0b4.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES /> + </library> + </orderEntry> + <orderEntry type="module-library"> + <library> + <CLASSES> + <root url="jar://$MODULE_DIR$/lib/bsh-util-2.0b4.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES /> + </library> + </orderEntry> + </component> +</module> + Property changes on: trunk/script.iml ___________________________________________________________________ Added: svn:mime-type + text/xml 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-11-13 20:19:04
|
Revision: 8790 http://gridarta.svn.sourceforge.net/gridarta/?rev=8790&view=rev Author: akirschbaum Date: 2010-11-13 20:18:58 +0000 (Sat, 13 Nov 2010) Log Message: ----------- Move some dependencies to bash package from net.sf.gridarta.gui.script to net.sf.gridarta.script. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/gui/script/ScriptController.java trunk/src/app/net/sf/gridarta/gui/script/ScriptView.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/script/ScriptConsole.java Modified: trunk/src/app/net/sf/gridarta/gui/script/ScriptController.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/script/ScriptController.java 2010-11-13 20:03:16 UTC (rev 8789) +++ trunk/src/app/net/sf/gridarta/gui/script/ScriptController.java 2010-11-13 20:18:58 UTC (rev 8790) @@ -19,7 +19,6 @@ package net.sf.gridarta.gui.script; -import bsh.ConsoleInterface; import java.awt.Component; import java.io.File; import java.io.FileOutputStream; @@ -34,6 +33,7 @@ import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; import net.sf.gridarta.script.Script; +import net.sf.gridarta.script.ScriptConsole; import net.sf.gridarta.script.ScriptExecException; import net.sf.gridarta.script.ScriptExecutor; import net.sf.gridarta.script.ScriptModel; @@ -311,7 +311,7 @@ return; } - final ConsoleInterface console = view.createConsole(clonedScript.getName()); + final ScriptConsole console = view.createConsole(clonedScript.getName()); try { scriptExecutor.doRunScript(clonedScript, console); // XXX: drops Thread } catch (final ScriptExecException ex) { Modified: trunk/src/app/net/sf/gridarta/gui/script/ScriptView.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/script/ScriptView.java 2010-11-13 20:03:16 UTC (rev 8789) +++ trunk/src/app/net/sf/gridarta/gui/script/ScriptView.java 2010-11-13 20:18:58 UTC (rev 8790) @@ -19,8 +19,6 @@ package net.sf.gridarta.gui.script; -import bsh.ConsoleInterface; -import bsh.util.JConsole; import java.awt.BorderLayout; import java.awt.Component; import java.awt.Container; @@ -44,6 +42,7 @@ import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; import net.sf.gridarta.script.Script; +import net.sf.gridarta.script.ScriptConsole; import net.sf.gridarta.script.ScriptModel; import net.sf.gridarta.script.ScriptModelListener; import net.sf.gridarta.script.parameter.PluginParameter; @@ -206,11 +205,11 @@ } @NotNull - public ConsoleInterface createConsole(@NotNull final String name) { + public ScriptConsole createConsole(@NotNull final String name) { showConsoleFrame(); - final JConsole bshConsole = new JConsole(); - consolePane.addCloseableTab(name, bshConsole, true); - return bshConsole; + final ScriptConsole scriptConsole = new ScriptConsole(); + consolePane.addCloseableTab(name, scriptConsole, true); + return scriptConsole; } public boolean getRunValues(@NotNull final Script<G, A, R> script, @NotNull final Component parent) { Added: trunk/src/app/net/sf/gridarta/script/ScriptConsole.java =================================================================== --- trunk/src/app/net/sf/gridarta/script/ScriptConsole.java (rev 0) +++ trunk/src/app/net/sf/gridarta/script/ScriptConsole.java 2010-11-13 20:18:58 UTC (rev 8790) @@ -0,0 +1,26 @@ +/* + * 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.script; + +import bsh.util.JConsole; + +public class ScriptConsole extends JConsole { + +} // class ScriptConsole Property changes on: trunk/src/app/net/sf/gridarta/script/ScriptConsole.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-11-13 20:03:23
|
Revision: 8789 http://gridarta.svn.sourceforge.net/gridarta/?rev=8789&view=rev Author: akirschbaum Date: 2010-11-13 20:03:16 +0000 (Sat, 13 Nov 2010) Log Message: ----------- Move some dependencies to bash package from net.sf.gridarta.gui.script to net.sf.gridarta.script. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/gui/script/ScriptController.java trunk/src/app/net/sf/gridarta/script/Script.java Modified: trunk/src/app/net/sf/gridarta/gui/script/ScriptController.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/script/ScriptController.java 2010-11-13 19:07:19 UTC (rev 8788) +++ trunk/src/app/net/sf/gridarta/gui/script/ScriptController.java 2010-11-13 20:03:16 UTC (rev 8789) @@ -20,8 +20,6 @@ package net.sf.gridarta.gui.script; import bsh.ConsoleInterface; -import bsh.EvalError; -import bsh.Interpreter; import java.awt.Component; import java.io.File; import java.io.FileOutputStream; @@ -43,7 +41,6 @@ import net.sf.gridarta.script.ScriptModelLoader; import net.sf.gridarta.script.ScriptModelParser; import net.sf.gridarta.script.ScriptParameters; -import net.sf.gridarta.script.ScriptRunMode; import net.sf.gridarta.script.parameter.PluginParameterFactory; import net.sf.gridarta.utils.ActionUtils; import net.sf.gridarta.utils.FileChooserUtils; @@ -140,14 +137,14 @@ final String filterName = "(s)" + script.getName(); if (script.isFilter()) { - final Filter<?, ?> filter = getScriptAsFilter(script); + final Filter<?, ?> filter = script.getScriptAsFilter(scriptParameters); if (filter != null) { filterControl.addFilter(filterName, filter); } } if (script.isAutoBoot()) { - autoRunScript(script); + script.runScript(scriptParameters); } } @@ -307,30 +304,6 @@ } } - private void autoRunScript(@NotNull final Script<?, ?, ?> script) { - final Interpreter runner = new Interpreter(); - try { - scriptParameters.setInterpreterValues(runner, ScriptRunMode.AUTO_RUN); - runner.eval(script.getCode()); - } catch (final EvalError e) { - log.warn("Evaluation error on (auto-run)" + script.getName(), e); - } - } - - @Nullable - private Filter<?, ?> getScriptAsFilter(@NotNull final Script<?, ?, ?> script) { - final Interpreter runner = new Interpreter(); - try { - scriptParameters.setInterpreterValues(runner, ScriptRunMode.FILTER); - return (Filter<?, ?>) runner.eval(script.getCode()); - } catch (final EvalError e) { - log.warn("Evaluation error on (filter)" + script.getName(), e); - } catch (final ClassCastException e) { - log.warn("Script did not return a net.sf.gridarta.model.filter.Filter object" + script.getName(), e); - } - return null; - } - public void runScript(@NotNull final Script<G, A, R> script) { final Script<G, A, R> clonedScript = script.cloneScript(); Modified: trunk/src/app/net/sf/gridarta/script/Script.java =================================================================== --- trunk/src/app/net/sf/gridarta/script/Script.java 2010-11-13 19:07:19 UTC (rev 8788) +++ trunk/src/app/net/sf/gridarta/script/Script.java 2010-11-13 20:03:16 UTC (rev 8789) @@ -19,6 +19,8 @@ package net.sf.gridarta.script; +import bsh.EvalError; +import bsh.Interpreter; import java.io.File; import java.util.ArrayList; import java.util.Collection; @@ -29,6 +31,7 @@ import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import net.sf.gridarta.model.archetype.Archetype; +import net.sf.gridarta.model.filter.Filter; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; import net.sf.gridarta.script.parameter.NoSuchParameterException; @@ -430,4 +433,28 @@ return Collections.unmodifiableList(parameters).iterator(); } + public void runScript(@NotNull final ScriptParameters scriptParameters) { + final Interpreter runner = new Interpreter(); + try { + scriptParameters.setInterpreterValues(runner, ScriptRunMode.AUTO_RUN); + runner.eval(code); + } catch (final EvalError e) { + log.warn("Evaluation error on (auto-run)" + name, e); + } + } + + @Nullable + public Filter<?, ?> getScriptAsFilter(@NotNull final ScriptParameters scriptParameters) { + final Interpreter runner = new Interpreter(); + try { + scriptParameters.setInterpreterValues(runner, ScriptRunMode.FILTER); + return (Filter<?, ?>) runner.eval(code); + } catch (final EvalError e) { + log.warn("Evaluation error on (filter)" + name, e); + } catch (final ClassCastException e) { + log.warn("Script did not return a net.sf.gridarta.model.filter.Filter object" + name, e); + } + return null; + } + } // class Script This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2010-11-13 19:07:25
|
Revision: 8788 http://gridarta.svn.sourceforge.net/gridarta/?rev=8788&view=rev Author: akirschbaum Date: 2010-11-13 19:07:19 +0000 (Sat, 13 Nov 2010) Log Message: ----------- Rewrite AbstractPluginParameter to remove dependency to javax.swing package. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/script/parameter/AbstractPluginParameter.java trunk/src/app/net/sf/gridarta/script/parameter/PluginParameter.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/script/parameter/PluginParameterListener.java Modified: trunk/src/app/net/sf/gridarta/script/parameter/AbstractPluginParameter.java =================================================================== --- trunk/src/app/net/sf/gridarta/script/parameter/AbstractPluginParameter.java 2010-11-13 18:39:15 UTC (rev 8787) +++ trunk/src/app/net/sf/gridarta/script/parameter/AbstractPluginParameter.java 2010-11-13 19:07:19 UTC (rev 8788) @@ -19,13 +19,10 @@ package net.sf.gridarta.script.parameter; -import java.util.Collection; -import java.util.HashSet; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; +import net.sf.gridarta.utils.EventListenerList2; import org.jdom.Element; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -49,7 +46,7 @@ private String name = "[name]"; @NotNull - private final Collection<ChangeListener> listeners = new HashSet<ChangeListener>(); + private final EventListenerList2<PluginParameterListener<G, A, R>> listeners = new EventListenerList2<PluginParameterListener<G, A, R>>(PluginParameterListener.class); protected AbstractPluginParameter() { } @@ -147,7 +144,7 @@ * {@inheritDoc} */ @Override - public void addChangeListener(@NotNull final ChangeListener listener) { + public void addPluginParameterListener(@NotNull final PluginParameterListener<G, A, R> listener) { listeners.add(listener); } @@ -155,14 +152,13 @@ * {@inheritDoc} */ @Override - public void removeChangeListener(@NotNull final ChangeListener listener) { + public void removePluginParameterListener(@NotNull final PluginParameterListener<G, A, R> listener) { listeners.remove(listener); } protected void fireDataChanged() { - final ChangeEvent e = new ChangeEvent(this); - for (final ChangeListener listener : listeners) { - listener.stateChanged(e); + for (final PluginParameterListener<G, A, R> listener : listeners.getListeners()) { + listener.stateChanged(this); } } Modified: trunk/src/app/net/sf/gridarta/script/parameter/PluginParameter.java =================================================================== --- trunk/src/app/net/sf/gridarta/script/parameter/PluginParameter.java 2010-11-13 18:39:15 UTC (rev 8787) +++ trunk/src/app/net/sf/gridarta/script/parameter/PluginParameter.java 2010-11-13 19:07:19 UTC (rev 8788) @@ -19,7 +19,6 @@ package net.sf.gridarta.script.parameter; -import javax.swing.event.ChangeListener; import net.sf.gridarta.model.archetype.Archetype; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.maparchobject.MapArchObject; @@ -62,9 +61,9 @@ @NotNull String getParameterType(); - void addChangeListener(@NotNull ChangeListener listener); + void addPluginParameterListener(@NotNull PluginParameterListener<G, A, R> listener); - void removeChangeListener(@NotNull ChangeListener listener); + void removePluginParameterListener(@NotNull PluginParameterListener<G, A, R> listener); void visit(@NotNull PluginParameterVisitor<G, A, R> visitor); Added: trunk/src/app/net/sf/gridarta/script/parameter/PluginParameterListener.java =================================================================== --- trunk/src/app/net/sf/gridarta/script/parameter/PluginParameterListener.java (rev 0) +++ trunk/src/app/net/sf/gridarta/script/parameter/PluginParameterListener.java 2010-11-13 19:07:19 UTC (rev 8788) @@ -0,0 +1,37 @@ +/* + * 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.script.parameter; + +import java.util.EventListener; +import net.sf.gridarta.model.archetype.Archetype; +import net.sf.gridarta.model.gameobject.GameObject; +import net.sf.gridarta.model.maparchobject.MapArchObject; +import org.jetbrains.annotations.NotNull; + +/** + * Interface for listeners interested in {@link PluginParameter} related + * events. + * @author Andreas Kirschbaum + */ +public interface PluginParameterListener<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends EventListener { + + void stateChanged(@NotNull PluginParameter<G, A, R> pluginParameter); + +} // interface PluginParameterListener Property changes on: trunk/src/app/net/sf/gridarta/script/parameter/PluginParameterListener.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-11-13 18:39:21
|
Revision: 8787 http://gridarta.svn.sourceforge.net/gridarta/?rev=8787&view=rev Author: akirschbaum Date: 2010-11-13 18:39:15 +0000 (Sat, 13 Nov 2010) Log Message: ----------- Remove InsertionModeSet.init(). Modified Paths: -------------- trunk/model/src/app/net/sf/gridarta/model/mapmodel/InsertionModeSet.java trunk/model/src/test/net/sf/gridarta/model/mapmodel/TestMapModelCreator.java trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java Modified: trunk/model/src/app/net/sf/gridarta/model/mapmodel/InsertionModeSet.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/mapmodel/InsertionModeSet.java 2010-11-13 18:30:20 UTC (rev 8786) +++ trunk/model/src/app/net/sf/gridarta/model/mapmodel/InsertionModeSet.java 2010-11-13 18:39:15 UTC (rev 8787) @@ -36,7 +36,7 @@ * The "auto" insertion mode. */ @NotNull - private InsertionMode<G, A, R> autoInsertionMode; + private final InsertionMode<G, A, R> autoInsertionMode; /** * The "topmost" insertion mode. @@ -48,13 +48,13 @@ * The "above floor" insertion mode. */ @NotNull - private InsertionMode<G, A, R> aboveFloorInsertionMode; + private final InsertionMode<G, A, R> aboveFloorInsertionMode; /** * The "below floor" insertion mode. */ @NotNull - private InsertionMode<G, A, R> belowFloorInsertionMode; + private final InsertionMode<G, A, R> belowFloorInsertionMode; /** * The "bottommost" insertion mode. @@ -65,13 +65,6 @@ /** * Creates a new instance. * @param topmostInsertionMode the "topmost" insertion mode - */ - public InsertionModeSet(@NotNull final InsertionMode<G, A, R> topmostInsertionMode) { - this.topmostInsertionMode = topmostInsertionMode; - } - - /** - * Creates a new instance. * @param floorGameObjectMatcher the game object matcher for selecting floor * game objects * @param wallGameObjectMatcher the game object matcher for selecting wall @@ -79,8 +72,8 @@ * @param belowFloorGameObjectMatcher the game object matcher for selecting * below floor game objects */ - @Deprecated - public void init(@Nullable final GameObjectMatcher floorGameObjectMatcher, @NotNull final GameObjectMatcher wallGameObjectMatcher, @NotNull final GameObjectMatcher belowFloorGameObjectMatcher) { + public InsertionModeSet(@NotNull final InsertionMode<G, A, R> topmostInsertionMode, @Nullable final GameObjectMatcher floorGameObjectMatcher, @NotNull final GameObjectMatcher wallGameObjectMatcher, @NotNull final GameObjectMatcher belowFloorGameObjectMatcher) { + this.topmostInsertionMode = topmostInsertionMode; autoInsertionMode = new AutoInsertionMode<G, A, R>(floorGameObjectMatcher, wallGameObjectMatcher, belowFloorGameObjectMatcher); aboveFloorInsertionMode = new AboveFloorInsertionMode<G, A, R>(floorGameObjectMatcher); belowFloorInsertionMode = new BelowFloorInsertionMode<G, A, R>(floorGameObjectMatcher); Modified: trunk/model/src/test/net/sf/gridarta/model/mapmodel/TestMapModelCreator.java =================================================================== --- trunk/model/src/test/net/sf/gridarta/model/mapmodel/TestMapModelCreator.java 2010-11-13 18:30:20 UTC (rev 8786) +++ trunk/model/src/test/net/sf/gridarta/model/mapmodel/TestMapModelCreator.java 2010-11-13 18:39:15 UTC (rev 8787) @@ -146,8 +146,7 @@ archetypeSet = new TestArchetypeSet(archetypeFactory, "archetypes", faceObjectProviders); gameObjectFactory = new TestGameObjectFactory(faceObjectProviders, animationObjects); topmostInsertionMode = new TopmostInsertionMode<TestGameObject, TestMapArchObject, TestArchetype>(); - insertionModeSet = new InsertionModeSet<TestGameObject, TestMapArchObject, TestArchetype>(topmostInsertionMode); - insertionModeSet.init(new TypeNrsGameObjectMatcher(), new TypeNrsGameObjectMatcher(), new TypeNrsGameObjectMatcher()); + insertionModeSet = new InsertionModeSet<TestGameObject, TestMapArchObject, TestArchetype>(topmostInsertionMode, new TypeNrsGameObjectMatcher(), new TypeNrsGameObjectMatcher(), new TypeNrsGameObjectMatcher()); } /** Modified: trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java 2010-11-13 18:30:20 UTC (rev 8786) +++ trunk/src/app/net/sf/gridarta/maincontrol/GUIMainControl.java 2010-11-13 18:39:15 UTC (rev 8787) @@ -462,7 +462,11 @@ final SelectedSquareActions<G, A, R> selectedSquareActions = new SelectedSquareActions<G, A, R>(selectedSquareModel); final SelectedSquareView<G, A, R> selectedSquareView = new SelectedSquareView<G, A, R>(selectedSquareModel, selectedSquareActions, mapManager, mapViewManager, mapViewSettings, compassIcon, faceObjectProviders, unknownSquareIcon); final SelectedSquareControl<G, A, R> selectedSquareControl = new SelectedSquareControl<G, A, R>(selectedSquareModel, gameObjectAttributesDialogFactory, objectChooser, selectedSquareView); - final InsertionModeSet<G, A, R> insertionModeSet = new InsertionModeSet<G, A, R>(topmostInsertionMode); + final GameObjectMatcher floorMatcher = gameObjectMatchers.getMatcher("system_floor", "floor"); + final GameObjectMatcher wallMatcher = gameObjectMatchers.getMatcher("system_wall", "wall"); + final ErrorViewCollector gameObjectMatchersErrorViewCollector = new ErrorViewCollector(errorView, new File(globalSettings.getConfigurationDirectory(), "GameObjectMatchers.xml")); + final GameObjectMatcher belowFloorMatcher = gameObjectMatchers.getMatcherWarn(gameObjectMatchersErrorViewCollector, "system_below_floor", "below_floor"); + final InsertionModeSet<G, A, R> insertionModeSet = new InsertionModeSet<G, A, R>(topmostInsertionMode, floorMatcher, wallMatcher, belowFloorMatcher); final CopyBuffer<G, A, R> copyBuffer = new CopyBuffer<G, A, R>(mapViewSettings, gameObjectFactory, mapArchObjectFactory, mapModelFactory, insertionModeSet); final ReplaceDialogManager<G, A, R> replaceDialogManager = new ReplaceDialogManager<G, A, R>(mainViewFrame, copyBuffer, objectChooser, mapViewManager, faceObjectProviders, insertionModeSet); exiter = new DefaultExiter(mainViewFrame); @@ -475,13 +479,8 @@ fileControl = new DefaultFileControl<G, A, R>(globalSettings, mapImageCache, mapManager, mapViewsManager, mainViewFrame, GuiFileFilters.mapFileFilter, scriptFileFilter, newMapDialogFactory, scriptExtension, scriptEditControl); pickmapChooserControl.setFileControl(fileControl); mapViewsManager.setFileControl(fileControl); - final GameObjectMatcher floorMatcher = gameObjectMatchers.getMatcher("system_floor", "floor"); - final GameObjectMatcher wallMatcher = gameObjectMatchers.getMatcher("system_wall", "wall"); - final ErrorViewCollector gameObjectMatchersErrorViewCollector = new ErrorViewCollector(errorView, new File(globalSettings.getConfigurationDirectory(), "GameObjectMatchers.xml")); final GameObjectMatcher monsterMatcherTmp = gameObjectMatchers.getMatcherWarn(gameObjectMatchersErrorViewCollector, "system_monster", "monster"); final GameObjectMatcher monsterMatcher = monsterMatcherTmp == null ? new TypeNrsGameObjectMatcher() : monsterMatcherTmp; - final GameObjectMatcher belowFloorMatcher = gameObjectMatchers.getMatcherWarn(gameObjectMatchersErrorViewCollector, "system_below_floor", "below_floor"); - insertionModeSet.init(floorMatcher, wallMatcher, belowFloorMatcher); final GameObjectMatcher exitGameObjectMatcherTmp = gameObjectMatchers.getMatcherWarn(gameObjectMatchersErrorViewCollector, "system_exit", "exit"); final GameObjectMatcher exitGameObjectMatcher = exitGameObjectMatcherTmp == null ? new TypeNrsGameObjectMatcher() : exitGameObjectMatcherTmp; final ExitMatcher<G, A, R> exitMatcher = new ExitMatcher<G, A, R>(exitGameObjectMatcher); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2010-11-13 18:30:26
|
Revision: 8786 http://gridarta.svn.sourceforge.net/gridarta/?rev=8786&view=rev Author: akirschbaum Date: 2010-11-13 18:30:20 +0000 (Sat, 13 Nov 2010) Log Message: ----------- Fix unchecked warning. Modified Paths: -------------- trunk/model/src/app/net/sf/gridarta/model/floodfill/FillUtils.java trunk/model/src/app/net/sf/gridarta/model/mapmodel/MapModel.java trunk/model/src/app/net/sf/gridarta/model/mapmodel/MapSquareGrid.java trunk/model/src/app/net/sf/gridarta/model/mapmodel/MapSquareIterator.java trunk/model/src/app/net/sf/gridarta/model/validation/checks/MapCheckerScriptChecker.java Modified: trunk/model/src/app/net/sf/gridarta/model/floodfill/FillUtils.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/floodfill/FillUtils.java 2010-11-13 18:11:37 UTC (rev 8785) +++ trunk/model/src/app/net/sf/gridarta/model/floodfill/FillUtils.java 2010-11-13 18:30:20 UTC (rev 8786) @@ -116,11 +116,9 @@ for (int dx = -1; dx < w + 1; dx++) { pos.x = p.x + dx; final MapSquare<G, A, R> mapSquare; - // This exception is expected at the border of the map. - //noinspection ProhibitedExceptionCaught try { mapSquare = mapModel.getMapSquare(pos); - } catch (final ArrayIndexOutOfBoundsException ignored) { + } catch (final IndexOutOfBoundsException ignored) { continue; } Modified: trunk/model/src/app/net/sf/gridarta/model/mapmodel/MapModel.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/mapmodel/MapModel.java 2010-11-13 18:11:37 UTC (rev 8785) +++ trunk/model/src/app/net/sf/gridarta/model/mapmodel/MapModel.java 2010-11-13 18:30:20 UTC (rev 8786) @@ -265,8 +265,8 @@ * Get the square at a specified location. * @param pos location to get square at * @return square at <var>p</var> - * @throws ArrayIndexOutOfBoundsException in case p specifies a location - * that's not valid within this map model + * @throws IndexOutOfBoundsException in case p specifies a location that's + * not valid within this map model */ @NotNull MapSquare<G, A, R> getMapSquare(@NotNull Point pos); @@ -350,8 +350,8 @@ * @param allowDouble whether overlapping multi-square arches should be * allowed (check is done using the archetype name) * @return whether the multi-arch would still fit on this map - * @retval <code>true</code> if the multi-square archetype would still fit on - * this map + * @retval <code>true</code> if the multi-square archetype would still fit + * on this map * @retval <code>false</code> otherwise */ boolean isMultiArchFittingToMap(@NotNull Archetype<G, A, R> archetype, @NotNull Point pos, boolean allowDouble); Modified: trunk/model/src/app/net/sf/gridarta/model/mapmodel/MapSquareGrid.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/mapmodel/MapSquareGrid.java 2010-11-13 18:11:37 UTC (rev 8785) +++ trunk/model/src/app/net/sf/gridarta/model/mapmodel/MapSquareGrid.java 2010-11-13 18:30:20 UTC (rev 8786) @@ -20,7 +20,9 @@ package net.sf.gridarta.model.mapmodel; import java.io.Serializable; +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; @@ -57,7 +59,7 @@ * @serial */ @NotNull - private MapSquare<G, A, R>[][] mapGrid; + private List<List<MapSquare<G, A, R>>> mapGrid; /** * Creates a new instance. @@ -70,7 +72,7 @@ mapGrid = newMapGrid(mapSize); for (int y = 0; y < mapSize.getHeight(); y++) { for (int x = 0; x < mapSize.getWidth(); x++) { - mapGrid[x][y] = new MapSquare<G, A, R>(mapModel, x, y); + mapGrid.get(x).set(y, new MapSquare<G, A, R>(mapModel, x, y)); } } } @@ -81,8 +83,18 @@ * @return the array */ @NotNull - private MapSquare<G, A, R>[][] newMapGrid(@NotNull final Size2D mapSize) { - return (MapSquare<G, A, R>[][]) new MapSquare<?, ?, ?>[mapSize.getWidth()][mapSize.getHeight()]; + private List<List<MapSquare<G, A, R>>> newMapGrid(@NotNull final Size2D mapSize) { + final ArrayList<List<MapSquare<G, A, R>>> result = new ArrayList<List<MapSquare<G, A, R>>>(mapSize.getWidth()); + for (int x = 0; x < mapSize.getWidth(); x++) { + final ArrayList<MapSquare<G, A, R>> column = new ArrayList<MapSquare<G, A, R>>(mapSize.getHeight()); + for (int y = 0; y < mapSize.getHeight(); y++) { + column.add(null); + } + column.trimToSize(); + result.add(column); + } + result.trimToSize(); + return result; } /** @@ -90,12 +102,11 @@ * @param x the location's x coordinate * @param y the location's y coordinate * @return the map square - * @throws ArrayIndexOutOfBoundsException if the location is not within - * bounds + * @throws IndexOutOfBoundsException if the location is not within bounds */ @NotNull public MapSquare<G, A, R> getMapSquare(final int x, final int y) { - return mapGrid[x][y]; + return mapGrid.get(x).get(y); } /** @@ -108,14 +119,15 @@ public void clearMap() { for (int x = 0; x < mapSize.getWidth(); x++) { for (int y = 0; y < mapSize.getHeight(); y++) { - if (mapGrid[x][y] == null) { - mapGrid[x][y] = new MapSquare<G, A, R>(mapModel, x, y); - } else if (!mapGrid[x][y].isEmpty()) { - mapGrid[x][y].beginSquareChange(); + final List<MapSquare<G, A, R>> column = mapGrid.get(x); + if (column.get(y) == null) { + column.set(y, new MapSquare<G, A, R>(mapModel, x, y)); + } else if (!column.get(y).isEmpty()) { + column.get(y).beginSquareChange(); try { - mapGrid[x][y] = new MapSquare<G, A, R>(mapModel, x, y); + column.set(y, new MapSquare<G, A, R>(mapModel, x, y)); } finally { - mapGrid[x][y].endSquareChange(); + column.get(y).endSquareChange(); } } } @@ -130,7 +142,7 @@ public boolean isEmpty() { for (int x = 0; x < mapSize.getWidth(); x++) { for (int y = 0; y < mapSize.getHeight(); y++) { - if (!mapGrid[x][y].isEmpty()) { + if (!mapGrid.get(x).get(y).isEmpty()) { return false; } } @@ -143,15 +155,15 @@ * @param newSize the new size */ public void resize(@NotNull final Size2D newSize) { - final MapSquare<G, A, R>[][] newGrid = newMapGrid(newSize); + final List<List<MapSquare<G, A, R>>> newGrid = newMapGrid(newSize); // relink all arches to the new grid for (int x = 0; x < newSize.getWidth(); x++) { for (int y = 0; y < newSize.getHeight(); y++) { if (x < mapSize.getWidth() && y < mapSize.getHeight()) { - newGrid[x][y] = mapGrid[x][y]; + newGrid.get(x).set(y, mapGrid.get(x).get(y)); } else { - newGrid[x][y] = new MapSquare<G, A, R>(mapModel, x, y); + newGrid.get(x).set(y, new MapSquare<G, A, R>(mapModel, x, y)); } } } @@ -172,7 +184,7 @@ public void collectHeads(final int minX, final int minY, final int maxX, final int maxY, @NotNull final Collection<GameObject<G, A, R>> objectsToDelete) { for (int x = minX; x < maxX; x++) { for (int y = minY; y < maxY; y++) { - for (final GameObject<G, A, R> node : mapGrid[x][y]) { + for (final GameObject<G, A, R> node : mapGrid.get(x).get(y)) { objectsToDelete.add(node.getHead()); } } Modified: trunk/model/src/app/net/sf/gridarta/model/mapmodel/MapSquareIterator.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/mapmodel/MapSquareIterator.java 2010-11-13 18:11:37 UTC (rev 8785) +++ trunk/model/src/app/net/sf/gridarta/model/mapmodel/MapSquareIterator.java 2010-11-13 18:30:20 UTC (rev 8786) @@ -90,13 +90,11 @@ */ @Override public MapSquare<G, A, R> next() { - //The exception is expected and handled - //noinspection ProhibitedExceptionCaught try { final MapSquare<G, A, R> square = mapModel.getMapSquare(new Point(point % mapWidth, point / mapWidth)); point++; return square; - } catch (final ArrayIndexOutOfBoundsException ignore) { + } catch (final IndexOutOfBoundsException ignore) { //There is no constructor that takes a cause. //noinspection ThrowInsideCatchBlockWhichIgnoresCaughtException throw new NoSuchElementException(); Modified: trunk/model/src/app/net/sf/gridarta/model/validation/checks/MapCheckerScriptChecker.java =================================================================== --- trunk/model/src/app/net/sf/gridarta/model/validation/checks/MapCheckerScriptChecker.java 2010-11-13 18:11:37 UTC (rev 8785) +++ trunk/model/src/app/net/sf/gridarta/model/validation/checks/MapCheckerScriptChecker.java 2010-11-13 18:30:20 UTC (rev 8786) @@ -190,10 +190,9 @@ } final String message = matcher.group(3); final MapSquare<G, A, R> mapSquare; - //noinspection ProhibitedExceptionCaught try { mapSquare = mapModel.getMapSquare(new Point(x, y)); - } catch (final ArrayIndexOutOfBoundsException ignored) { + } catch (final IndexOutOfBoundsException ignored) { errorCollector.collect(new MapCheckerScriptFailureError<G, A, R>(mapModel, command, "invalid map square in '" + line + "'")); continue; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |