From: <chr...@us...> - 2007-01-04 21:39:44
|
Revision: 1432 http://svn.sourceforge.net/gridarta/?rev=1432&view=rev Author: christianhujer Date: 2007-01-04 13:39:42 -0800 (Thu, 04 Jan 2007) Log Message: ----------- Added some @Nullable annotations where null is returned always. Modified Paths: -------------- trunk/crossfire/src/cfeditor/AutojoinList.java trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/gameobject/GameObject.java trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java trunk/daimonin/src/daieditor/gameobject/GameObject.java trunk/daimonin/src/daieditor/gui/GameObjectAttributesDialog.java trunk/src/app/net/sf/gridarta/gameobject/GameObject.java trunk/src/app/net/sf/gridarta/gui/maptilelist/MapTileSelectionCache.java Modified: trunk/crossfire/src/cfeditor/AutojoinList.java =================================================================== --- trunk/crossfire/src/cfeditor/AutojoinList.java 2007-01-04 20:46:09 UTC (rev 1431) +++ trunk/crossfire/src/cfeditor/AutojoinList.java 2007-01-04 21:39:42 UTC (rev 1432) @@ -194,7 +194,7 @@ * @return the archetype name of the (default) arch to be inserted at point * <code>null</code> if there's already an arch of this list on point */ - public String joinInsert(final MapModel map, final Point point) { + @Nullable public String joinInsert(final MapModel map, final Point point) { int newIndex = 0; // return value, see above // if there already is an arch of this list at point -> abort Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2007-01-04 20:46:09 UTC (rev 1431) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2007-01-04 21:39:42 UTC (rev 1432) @@ -1794,7 +1794,7 @@ * @return the value of the given parameter name, or <code>null</code> if * the parameter does not exist */ - private static String getRandomMapParameter(final GameObject exit, final String parameterName) { + @Nullable private static String getRandomMapParameter(final GameObject exit, final String parameterName) { final String msg = exit.getMsgText(); if (msg == null) { return null; Modified: trunk/crossfire/src/cfeditor/gameobject/GameObject.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2007-01-04 20:46:09 UTC (rev 1431) +++ trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2007-01-04 21:39:42 UTC (rev 1432) @@ -322,6 +322,8 @@ // face name public void setFaceName(final String name) { final String newFaceName = name != null ? name.intern() : null; + // Using == on these Strings is okay, they are both interned. + //noinspection StringEquality if (faceName == newFaceName) { return; } Modified: trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java 2007-01-04 20:46:09 UTC (rev 1431) +++ trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java 2007-01-04 21:39:42 UTC (rev 1432) @@ -345,7 +345,7 @@ final String inline = ((JTextComponent) attr.input).getText().trim(); // input string if (inline != null) { - final boolean isNone = inline.equals(CFTreasureListTree.NONE_SYM) || inline.length() == 0; + final boolean isNone = inline.equals(net.sf.gridarta.CFTreasureListTree.NONE_SYM) || inline.length() == 0; if (!isNone && !CFTreasureListTree.containsTreasureList(inline) && !inline.equalsIgnoreCase(archetype.getAttributeString(attr.ref.getNameOld()))) { // The user has specified a WRONG treasurelist name, and it does not come Modified: trunk/daimonin/src/daieditor/gameobject/GameObject.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/GameObject.java 2007-01-04 20:46:09 UTC (rev 1431) +++ trunk/daimonin/src/daieditor/gameobject/GameObject.java 2007-01-04 21:39:42 UTC (rev 1432) @@ -289,6 +289,8 @@ // face name private void setFaceObjName(final String faceObjName) { final String newFaceObjName = faceObjName != null ? faceObjName.intern() : null; + // Using == on these Strings is okay, they are both interned. + //noinspection StringEquality if (this.faceObjName == newFaceObjName) { return; } @@ -304,6 +306,8 @@ // face name public void setFaceRealName(final String faceRealName) { final String newFaceRealName = faceRealName != null ? faceRealName.intern() : null; + // Using == on these Strings is okay, they are both interned. + //noinspection StringEquality if (this.faceRealName == newFaceRealName) { return; } @@ -489,6 +493,8 @@ */ public void setAnimName(final String animName) { final String newAnimName = animName != null ? animName.intern() : null; + // Using == on these Strings is okay, they are both interned. + //noinspection StringEquality if (this.animName == newAnimName) { return; } Modified: trunk/daimonin/src/daieditor/gui/GameObjectAttributesDialog.java =================================================================== --- trunk/daimonin/src/daieditor/gui/GameObjectAttributesDialog.java 2007-01-04 20:46:09 UTC (rev 1431) +++ trunk/daimonin/src/daieditor/gui/GameObjectAttributesDialog.java 2007-01-04 21:39:42 UTC (rev 1432) @@ -338,7 +338,7 @@ final String inline = ((JTextComponent) attr.input).getText().trim(); // input string if (inline != null) { - final boolean isNone = inline.equals(CFTreasureListTree.NONE_SYM) || inline.length() == 0; + final boolean isNone = inline.equals(net.sf.gridarta.CFTreasureListTree.NONE_SYM) || inline.length() == 0; if (!isNone && !CFTreasureListTree.containsTreasureList(inline) && !inline.equalsIgnoreCase(archetype.getAttributeString(attr.ref.getNameOld()))) { // The user has specified a WRONG treasurelist name, and it does not come Modified: trunk/src/app/net/sf/gridarta/gameobject/GameObject.java =================================================================== --- trunk/src/app/net/sf/gridarta/gameobject/GameObject.java 2007-01-04 20:46:09 UTC (rev 1431) +++ trunk/src/app/net/sf/gridarta/gameobject/GameObject.java 2007-01-04 21:39:42 UTC (rev 1432) @@ -866,13 +866,15 @@ * @param objName the name of this object. */ public void setObjName(@Nullable final String objName) { - final String newObjName = objName != null ? objName.intern() : null; - if (this.objName == newObjName) { - return; - } + final String newObjName = objName != null ? objName.intern() : null; + // Using == on these Strings is okay, they are both interned. + //noinspection StringEquality + if (this.objName == newObjName) { + return; + } - this.objName = newObjName; - squareChanged(); + this.objName = newObjName; + squareChanged(); } /** Modified: trunk/src/app/net/sf/gridarta/gui/maptilelist/MapTileSelectionCache.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/maptilelist/MapTileSelectionCache.java 2007-01-04 20:46:09 UTC (rev 1431) +++ trunk/src/app/net/sf/gridarta/gui/maptilelist/MapTileSelectionCache.java 2007-01-04 21:39:42 UTC (rev 1432) @@ -34,7 +34,7 @@ * @return the associated map tile selection instance, or <code>null</code> * if <code>null</code> was passed in */ - public MapTileSelection<G, C> findOrCreate(@Nullable final C mapControl) { + @Nullable public MapTileSelection<G, C> findOrCreate(@Nullable final C mapControl) { if (mapControl == null) { return null; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2007-01-04 23:35:27
|
Revision: 1433 http://svn.sourceforge.net/gridarta/?rev=1433&view=rev Author: christianhujer Date: 2007-01-04 15:35:26 -0800 (Thu, 04 Jan 2007) Log Message: ----------- Fixed xml-related bugs. Modified Paths: -------------- trunk/crossfire/build.xml trunk/src/app/net/sf/gridarta/CFArchTypeList.java trunk/src/app/net/sf/gridarta/Spells.java trunk/src/app/net/sf/gridarta/io/IOUtils.java Added Paths: ----------- trunk/crossfire/src/log4j.properties Removed Paths: ------------- trunk/crossfire/resource/log4j.properties Modified: trunk/crossfire/build.xml =================================================================== --- trunk/crossfire/build.xml 2007-01-04 21:39:42 UTC (rev 1432) +++ trunk/crossfire/build.xml 2007-01-04 23:35:26 UTC (rev 1433) @@ -98,19 +98,16 @@ <delete dir="${build.dir}/META-INF" /> <!-- copy the resource files into the build dir --> - <copy todir="${build.dir}"> + <copy todir="${build.dir}/${resource.dir}"> <fileset dir="${resource.dir}"> <exclude name="**/.xvpics/**"/> </fileset> </copy> <copy todir="${build.dir}"> - <fileset dir="${build.dir}/conf" /> - </copy> - <copy todir="${build.dir}"> <fileset dir="../src/app" excludes="**/*.java,**/package.html,**/overview.html" /> </copy> + <move file="${build.dir}/${resource.dir}/icons" todir="${build.dir}" /> <delete dir="${build.dir}/pickmaps" /> - <delete dir="${build.dir}/conf" /> <jar destfile = "${jarname}" Deleted: trunk/crossfire/resource/log4j.properties =================================================================== --- trunk/crossfire/resource/log4j.properties 2007-01-04 21:39:42 UTC (rev 1432) +++ trunk/crossfire/resource/log4j.properties 2007-01-04 23:35:26 UTC (rev 1433) @@ -1,9 +0,0 @@ -# Set root logger level to INFO and its only appender to A1. -log4j.rootLogger=INFO, A1 - -# A1 is set to be a ConsoleAppender. -log4j.appender.A1=org.apache.log4j.ConsoleAppender - -# A1 uses PatternLayout. -log4j.appender.A1.layout=org.apache.log4j.PatternLayout -log4j.appender.A1.layout.ConversionPattern=%-5p(%t) %-30c %x - %m%n Copied: trunk/crossfire/src/log4j.properties (from rev 1432, trunk/crossfire/resource/log4j.properties) =================================================================== --- trunk/crossfire/src/log4j.properties (rev 0) +++ trunk/crossfire/src/log4j.properties 2007-01-04 23:35:26 UTC (rev 1433) @@ -0,0 +1,9 @@ +# Set root logger level to INFO and its only appender to A1. +log4j.rootLogger=INFO, A1 + +# A1 is set to be a ConsoleAppender. +log4j.appender.A1=org.apache.log4j.ConsoleAppender + +# A1 uses PatternLayout. +log4j.appender.A1.layout=org.apache.log4j.PatternLayout +log4j.appender.A1.layout.ConversionPattern=%-5p(%t) %-30c %x - %m%n Modified: trunk/src/app/net/sf/gridarta/CFArchTypeList.java =================================================================== --- trunk/src/app/net/sf/gridarta/CFArchTypeList.java 2007-01-04 21:39:42 UTC (rev 1432) +++ trunk/src/app/net/sf/gridarta/CFArchTypeList.java 2007-01-04 23:35:26 UTC (rev 1433) @@ -15,6 +15,7 @@ import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; import net.sf.gridarta.gameobject.GameObject; +import net.sf.gridarta.io.IOUtils; import net.sf.japi.swing.JSAXErrorHandler; import net.sf.japi.xml.NodeListIterator; import org.apache.log4j.Logger; @@ -117,7 +118,7 @@ final String baseDir = getConfigurationDirectory(); // parse xml document - final Document doc = documentBuilder.parse(new File(baseDir, CommonConstants.TYPEDEF_FILE)); + final Document doc = documentBuilder.parse(IOUtils.getResourceURLAsString(baseDir, CommonConstants.TYPEDEF_FILE)); // start parsing the xml final Element root = doc.getDocumentElement(); Modified: trunk/src/app/net/sf/gridarta/Spells.java =================================================================== --- trunk/src/app/net/sf/gridarta/Spells.java 2007-01-04 21:39:42 UTC (rev 1432) +++ trunk/src/app/net/sf/gridarta/Spells.java 2007-01-04 23:35:26 UTC (rev 1433) @@ -10,6 +10,7 @@ import net.sf.japi.swing.ActionFactory; import net.sf.japi.util.filter.file.FilenameFileFilter; import net.sf.japi.xml.NodeListIterator; +import net.sf.gridarta.io.IOUtils; import org.apache.log4j.Logger; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -93,7 +94,7 @@ final String baseDir = getSpellsBaseDir(); // parse xml document - final Document doc = documentBuilder.parse(new File(baseDir, CommonConstants.SPELL_FILE)); + final Document doc = documentBuilder.parse(IOUtils.getResourceURLAsString(baseDir, CommonConstants.SPELL_FILE)); // retrieve the spell data from the xml final Element root = doc.getDocumentElement(); Modified: trunk/src/app/net/sf/gridarta/io/IOUtils.java =================================================================== --- trunk/src/app/net/sf/gridarta/io/IOUtils.java 2007-01-04 21:39:42 UTC (rev 1432) +++ trunk/src/app/net/sf/gridarta/io/IOUtils.java 2007-01-04 23:35:26 UTC (rev 1433) @@ -12,6 +12,8 @@ import java.io.Reader; import java.io.UnsupportedEncodingException; import java.net.URI; +import java.net.MalformedURLException; +import java.net.URL; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -49,6 +51,58 @@ } /** + * Get the URL of a resource as String. + * @param dname directory name to read from + * @param fname file name of the file to read + * @return URL for reading from <var>fname</var> + * @throws FileNotFoundException In case all tries getting a URL to the file failed + */ + @NotNull public static String getResourceURLAsString(@Nullable final String dname, @NotNull final String fname) throws FileNotFoundException { + try { // 1st try normal file relative to specified directory + final File file = new File(dname, fname); + if (file.exists()) { + return file.toURI().toURL().toString(); + } + } catch (final MalformedURLException e) { + // ignore + } + try { // 2nd try binary file relative to user's current working directory + final File file = new File(fname); + if (file.exists()) { + return file.toURI().toURL().toString(); + } + } catch (final MalformedURLException e) { + // ignore + } + final URI currentDir = new File(System.getProperty("user.dir")).toURI(); + final String relWithDir = currentDir.relativize(new File(dname, fname).toURI()).toString(); + final String relPlain = currentDir.relativize(new File(fname).toURI()).toString(); + final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); + @Nullable URL url; + // 3rd try context class loader relative to specified directory + url = contextClassLoader.getResource(relWithDir); + if (url != null) { + return url.toString(); + } + // 4th try context class loader relative to class loader's top level directory + url = contextClassLoader.getResource(relPlain); + if (url != null) { + return url.toString(); + } + // 5th try system class loader relative to specified directory + url = ClassLoader.getSystemResource(relWithDir); + if (url != null) { + return url.toString(); + } + // 6th try system class loader relative to class loader's top level directory + url = ClassLoader.getSystemResource(relPlain); + if (url != null) { + return url.toString(); + } + throw new FileNotFoundException("couldn't find " + new File(dname, fname) + "."); + } + + /** * Open the resource file for reading. * @param dname directory name to read from * @param fname file name of file to read This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2007-01-05 00:52:58
|
Revision: 1434 http://svn.sourceforge.net/gridarta/?rev=1434&view=rev Author: christianhujer Date: 2007-01-04 16:52:59 -0800 (Thu, 04 Jan 2007) Log Message: ----------- Declared several, especially private methods static when they could be static. Modified Paths: -------------- trunk/crossfire/src/cfeditor/AutojoinList.java trunk/crossfire/src/cfeditor/CGUIUtils.java trunk/crossfire/src/cfeditor/CMainView.java trunk/crossfire/src/cfeditor/CScriptController.java trunk/crossfire/src/cfeditor/JarResources.java trunk/crossfire/src/cfeditor/gui/map/MapPropertiesDialog.java trunk/crossfire/src/cfeditor/map/DefaultMapModel.java trunk/crossfire/src/cfeditor/map/MapArchObject.java trunk/crossfire/src/cfeditor/parameter/ArchParameter.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/gui/map/MapPreviewAccessory.java Modified: trunk/crossfire/src/cfeditor/AutojoinList.java =================================================================== --- trunk/crossfire/src/cfeditor/AutojoinList.java 2007-01-04 23:35:26 UTC (rev 1433) +++ trunk/crossfire/src/cfeditor/AutojoinList.java 2007-01-05 00:52:59 UTC (rev 1434) @@ -296,7 +296,7 @@ * @param direction Direction to check for being contained in the bitmask. * @return <code>true</code> if the bitmask contains the direction, otherwise <code>false</code>. */ - private boolean hasDir(final int index, final int direction) { + private static boolean hasDir(final int index, final int direction) { return (index & direction) != 0; } @@ -306,7 +306,7 @@ * @param direction Direction to add. * @return Index / bitmask with <var>direction</var> added.. */ - private int addDir(final int index, final int direction) { + private static int addDir(final int index, final int direction) { return index | direction; } @@ -316,7 +316,7 @@ * @param direction Direction to remove. * @return Index / bitmask with <var>direction</var> removed. */ - private int removeDir(final int index, final int direction) { + private static int removeDir(final int index, final int direction) { return index & ~direction; } Modified: trunk/crossfire/src/cfeditor/CGUIUtils.java =================================================================== --- trunk/crossfire/src/cfeditor/CGUIUtils.java 2007-01-04 23:35:26 UTC (rev 1433) +++ trunk/crossfire/src/cfeditor/CGUIUtils.java 2007-01-05 00:52:59 UTC (rev 1434) @@ -49,9 +49,6 @@ private static final Logger log = Logger.getLogger(CGUIUtils.class); - /** The instance of GUI utils used internally. */ - private static final CGUIUtils staticInstance = new CGUIUtils(); - private static final Map<String, ImageIcon> imageCache = new HashMap<String, ImageIcon>(); /** Do not subclass. */ @@ -59,14 +56,6 @@ } /** - * Returns the singleton instance of this class. - * @return The singleton instance of this class. - */ - public static CGUIUtils getInstance() { - return staticInstance; - } - - /** * Returns the image icon for the given icon name. Loads every icon * only once and uses hashtable to return the same instance if same * icon name is given. @@ -139,7 +128,7 @@ */ public static ImageIcon getGrayScaled(final ImageIcon icon) { // Use the static instance to do the grayscaling - return staticInstance.getGrayScaledImpl(icon); + return getGrayScaledImpl(icon); } public static JComponent getBox(final JComponent c) { @@ -153,7 +142,7 @@ * @param icon The colour icon to be grayscaled. * @return The given icon as grayscaled version. */ - private ImageIcon getGrayScaledImpl(final ImageIcon icon) { + private static ImageIcon getGrayScaledImpl(final ImageIcon icon) { final CGrayScaleFilter filter = new CGrayScaleFilter(); final ImageProducer imageProducer = new FilteredImageSource(icon.getImage().getSource(), filter); final Image grayIcon = Toolkit.getDefaultToolkit().createImage(imageProducer); Modified: trunk/crossfire/src/cfeditor/CMainView.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainView.java 2007-01-04 23:35:26 UTC (rev 1433) +++ trunk/crossfire/src/cfeditor/CMainView.java 2007-01-05 00:52:59 UTC (rev 1434) @@ -728,7 +728,7 @@ * * @param menu the menu to update */ - private void updateBshMenu(final JMenu menu) { + private static void updateBshMenu(final JMenu menu) { mainControl.getScriptController().getView().updateMenuEntries(menu); } Modified: trunk/crossfire/src/cfeditor/CScriptController.java =================================================================== --- trunk/crossfire/src/cfeditor/CScriptController.java 2007-01-04 23:35:26 UTC (rev 1433) +++ trunk/crossfire/src/cfeditor/CScriptController.java 2007-01-05 00:52:59 UTC (rev 1434) @@ -318,7 +318,7 @@ return mainControl; } - private void unRegister(final String name) { + private static void unRegister(final String name) { final String filterName = "(s)" + name; CFilterControl.getDefaultFilter().removeFilter(filterName); } Modified: trunk/crossfire/src/cfeditor/JarResources.java =================================================================== --- trunk/crossfire/src/cfeditor/JarResources.java 2007-01-04 23:35:26 UTC (rev 1433) +++ trunk/crossfire/src/cfeditor/JarResources.java 2007-01-05 00:52:59 UTC (rev 1434) @@ -166,7 +166,7 @@ * @param ze a ZipEntry * @return String with information on the supplied ZipEntry. */ - private String dumpZipEntry(final ZipEntry ze) { + private static String dumpZipEntry(final ZipEntry ze) { final StringBuilder sb = new StringBuilder(); if (ze.isDirectory()) { sb.append("d "); Modified: trunk/crossfire/src/cfeditor/gui/map/MapPropertiesDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/map/MapPropertiesDialog.java 2007-01-04 23:35:26 UTC (rev 1433) +++ trunk/crossfire/src/cfeditor/gui/map/MapPropertiesDialog.java 2007-01-05 00:52:59 UTC (rev 1434) @@ -514,7 +514,7 @@ * @return value of String 's', zero if 's' is empty * @throws GridderException when parsing fails */ - private int parseProperty(final String s, final String label) throws GridderException { + private static int parseProperty(final String s, final String label) throws GridderException { final int r; // return value if (s.length() == 0) { @@ -545,7 +545,7 @@ * @return value of String 's', zero if 's' is empty * @throws GridderException when parsing fails */ - private double parsePropertyToDouble(final String s, final String label) throws GridderException { + private static double parsePropertyToDouble(final String s, final String label) throws GridderException { final double r; // return value if (s.length() == 0) { Modified: trunk/crossfire/src/cfeditor/map/DefaultMapModel.java =================================================================== --- trunk/crossfire/src/cfeditor/map/DefaultMapModel.java 2007-01-04 23:35:26 UTC (rev 1433) +++ trunk/crossfire/src/cfeditor/map/DefaultMapModel.java 2007-01-05 00:52:59 UTC (rev 1434) @@ -368,7 +368,7 @@ * @param gameObject GameObject to search for. * @return The specified GameObject, or <code>null</code> if not found. */ - @Nullable public GameObject findInvObject(@NotNull final GameObject node, final GameObject gameObject) { + @Nullable private static GameObject findInvObject(@NotNull final GameObject node, final GameObject gameObject) { for (final GameObject arch : node.getHead()) { if (arch == gameObject) { return arch; @@ -413,7 +413,7 @@ * container itself, remove the whole inventory and all sub containers too. * @param node object to be deleted */ - public void deleteInvObject(final GameObject node) { + private static void deleteInvObject(final GameObject node) { node.removeAll(); node.remove(); } Modified: trunk/crossfire/src/cfeditor/map/MapArchObject.java =================================================================== --- trunk/crossfire/src/cfeditor/map/MapArchObject.java 2007-01-04 23:35:26 UTC (rev 1433) +++ trunk/crossfire/src/cfeditor/map/MapArchObject.java 2007-01-05 00:52:59 UTC (rev 1434) @@ -477,7 +477,7 @@ return 0; } - private double getLineValueAsDouble(final String s) { + private static double getLineValueAsDouble(final String s) { try { if (s.lastIndexOf(" ") > 0) { return Double.valueOf(s.substring(s.lastIndexOf(" ") + 1)); Modified: trunk/crossfire/src/cfeditor/parameter/ArchParameter.java =================================================================== --- trunk/crossfire/src/cfeditor/parameter/ArchParameter.java 2007-01-04 23:35:26 UTC (rev 1433) +++ trunk/crossfire/src/cfeditor/parameter/ArchParameter.java 2007-01-05 00:52:59 UTC (rev 1434) @@ -24,7 +24,7 @@ parameterType = getParameterType(); } - @Nullable private GameObject locateArchetype(final String archetypeName) { + @Nullable private static GameObject locateArchetype(final String archetypeName) { final ArchetypeSet archetypeSet = CMainControl.getInstance().getArchetypeSet(); if (CMainControl.getInstance().getArchetypeSet().getLoadStatus() != ArchetypeSet.LoadStatus.COMPLETE) { return null; Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2007-01-04 23:35:26 UTC (rev 1433) +++ trunk/daimonin/src/daieditor/CMainControl.java 2007-01-05 00:52:59 UTC (rev 1434) @@ -328,7 +328,7 @@ * Initializes the map validators. * @return A MapValidator that delegates to other map validators. */ - private DelegatingMapValidator createMapValidators() { + private static DelegatingMapValidator createMapValidators() { final DelegatingMapValidator mapValidators = new DelegatingMapValidator(); mapValidators.add( new BlockedMobOrSpawnPointChecker(), Modified: trunk/daimonin/src/daieditor/gui/map/MapPreviewAccessory.java =================================================================== --- trunk/daimonin/src/daieditor/gui/map/MapPreviewAccessory.java 2007-01-04 23:35:26 UTC (rev 1433) +++ trunk/daimonin/src/daieditor/gui/map/MapPreviewAccessory.java 2007-01-05 00:52:59 UTC (rev 1434) @@ -167,7 +167,7 @@ } } - @Nullable private MapControl getMapControl(final File file) { + @Nullable private static MapControl getMapControl(final File file) { if (!MapFileFilter.getInstance().accept(file)) { return null; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2007-01-05 00:56:41
|
Revision: 1436 http://svn.sourceforge.net/gridarta/?rev=1436&view=rev Author: christianhujer Date: 2007-01-04 16:56:42 -0800 (Thu, 04 Jan 2007) Log Message: ----------- Updated merge progress to include sum of cf / dai + merged code. Modified Paths: -------------- trunk/mergeProgressHistory.sh trunk/src/mergeMetrics1.gpl trunk/src/mergeMetrics2.gpl trunk/src/mergeMetrics3.gpl trunk/src/mergeMetrics4.gpl trunk/src/mergeMetrics5.gpl trunk/src/mergeMetrics6.gpl Modified: trunk/mergeProgressHistory.sh =================================================================== --- trunk/mergeProgressHistory.sh 2007-01-05 00:55:56 UTC (rev 1435) +++ trunk/mergeProgressHistory.sh 2007-01-05 00:56:42 UTC (rev 1436) @@ -18,6 +18,8 @@ find crossfire/src -name "*.java" >crossfire_src find daimonin/src -name "*.java" >daimonin_src cat common_src crossfire_src daimonin_src >all_src + cat common_src crossfire_src >crossfire_all_src + cat common_src daimonin_src >daimonin_all_src diff -r -d -w -N -I '^package' -I '^import' -x '.svn' crossfire/src/cfeditor daimonin/src/daieditor >differences echo -n $i echo -n ' ' @@ -35,13 +37,21 @@ echo -n ' ' echo -n $(<daimonin_src xargs cat | wc -l) echo -n ' ' - echo -n $(<differences grep '^<' | wc -l) + echo -n $(<crossfire_all_src grep -v textedit | xargs cat | wc -l) echo -n ' ' - echo -n $(<differences grep '^>' | wc -l) + echo -n $(<crossfire_all_src xargs cat | wc -l) echo -n ' ' + echo -n $(<daimonin_all_src grep -v textedit | xargs cat | wc -l) + echo -n ' ' + echo -n $(<daimonin_all_src xargs cat | wc -l) + echo -n ' ' echo -n $(<all_src grep -v textedit | xargs cat | wc -l) echo -n ' ' echo -n $(<all_src xargs cat | wc -l) + echo -n ' ' + echo -n $(<differences grep '^<' | wc -l) + echo -n ' ' + echo -n $(<differences grep '^>' | wc -l) echo ) >>../mergeStatistics.dat 2>/dev/null done Modified: trunk/src/mergeMetrics1.gpl =================================================================== --- trunk/src/mergeMetrics1.gpl 2007-01-05 00:55:56 UTC (rev 1435) +++ trunk/src/mergeMetrics1.gpl 2007-01-05 00:56:42 UTC (rev 1436) @@ -8,11 +8,15 @@ plot \ 'mergeStatistics.dat' using 1:3 title "Merged Code (excluding textedit)" with lines, \ 'mergeStatistics.dat' using 1:4 title "Merged Code (including textedit)" with lines, \ - 'mergeStatistics.dat' using 1:5 title "Crossfire Code (excluding textedit)" with lines, \ - 'mergeStatistics.dat' using 1:6 title "Crossfire Code (including textedit)" with lines, \ - 'mergeStatistics.dat' using 1:7 title "Daimonin Code (excluding textedit)" with lines, \ - 'mergeStatistics.dat' using 1:8 title "Daimonin Code (including textedit)" with lines, \ - 'mergeStatistics.dat' using 1:9 title "Crossfire diff to Daimonin" with lines, \ - 'mergeStatistics.dat' using 1:10 title "Daimonin diff to Crossfire" with lines, \ - 'mergeStatistics.dat' using 1:11 title "Complete Code (excluding textedit)" with lines, \ - 'mergeStatistics.dat' using 1:12 title "Complete Code (including textedit)" with lines + 'mergeStatistics.dat' using 1:5 title "Crossfire Only Code (excluding textedit)" with lines, \ + 'mergeStatistics.dat' using 1:6 title "Crossfire Only Code (including textedit)" with lines, \ + 'mergeStatistics.dat' using 1:7 title "Daimonin Only Code (excluding textedit)" with lines, \ + 'mergeStatistics.dat' using 1:8 title "Daimonin Only Code (including textedit)" with lines, \ + 'mergeStatistics.dat' using 1:9 title "Crossfire + Merged Code (excluding textedit)" with lines, \ + 'mergeStatistics.dat' using 1:10 title "Crossfire + Merged Code (including textedit)" with lines, \ + 'mergeStatistics.dat' using 1:11 title "Daimonin + Merged Code (excluding textedit)" with lines, \ + 'mergeStatistics.dat' using 1:12 title "Daimonin + Merged Code (including textedit)" with lines, \ + 'mergeStatistics.dat' using 1:13 title "Complete Code (excluding textedit)" with lines, \ + 'mergeStatistics.dat' using 1:14 title "Complete Code (including textedit)" with lines, \ + 'mergeStatistics.dat' using 1:15 title "Crossfire diff to Daimonin" with lines, \ + 'mergeStatistics.dat' using 1:16 title "Daimonin diff to Crossfire" with lines Modified: trunk/src/mergeMetrics2.gpl =================================================================== --- trunk/src/mergeMetrics2.gpl 2007-01-05 00:55:56 UTC (rev 1435) +++ trunk/src/mergeMetrics2.gpl 2007-01-05 00:56:42 UTC (rev 1436) @@ -7,8 +7,10 @@ set key below plot \ 'mergeStatistics.dat' using 1:4 title "Merged Code (including textedit)" with lines, \ - 'mergeStatistics.dat' using 1:6 title "Crossfire Code (including textedit)" with lines, \ - 'mergeStatistics.dat' using 1:8 title "Daimonin Code (including textedit)" with lines, \ - 'mergeStatistics.dat' using 1:9 title "Crossfire diff to Daimonin" with lines, \ - 'mergeStatistics.dat' using 1:10 title "Daimonin diff to Crossfire" with lines, \ - 'mergeStatistics.dat' using 1:12 title "Complete Code (including textedit)" with lines + 'mergeStatistics.dat' using 1:6 title "Crossfire Only Code (including textedit)" with lines, \ + 'mergeStatistics.dat' using 1:8 title "Daimonin Only Code (including textedit)" with lines, \ + 'mergeStatistics.dat' using 1:10 title "Crossfire + Merged Code (including textedit)" with lines, \ + 'mergeStatistics.dat' using 1:12 title "Daimonin + Merged Code (including textedit)" with lines, \ + 'mergeStatistics.dat' using 1:14 title "Complete Code (including textedit)" with lines, \ + 'mergeStatistics.dat' using 1:15 title "Crossfire diff to Daimonin" with lines, \ + 'mergeStatistics.dat' using 1:16 title "Daimonin diff to Crossfire" with lines Modified: trunk/src/mergeMetrics3.gpl =================================================================== --- trunk/src/mergeMetrics3.gpl 2007-01-05 00:55:56 UTC (rev 1435) +++ trunk/src/mergeMetrics3.gpl 2007-01-05 00:56:42 UTC (rev 1436) @@ -7,8 +7,10 @@ set key below plot \ 'mergeStatistics.dat' using 1:3 title "Merged Code (excluding textedit)" with lines, \ - 'mergeStatistics.dat' using 1:5 title "Crossfire Code (excluding textedit)" with lines, \ - 'mergeStatistics.dat' using 1:7 title "Daimonin Code (excluding textedit)" with lines, \ - 'mergeStatistics.dat' using 1:9 title "Crossfire diff to Daimonin" with lines, \ - 'mergeStatistics.dat' using 1:10 title "Daimonin diff to Crossfire" with lines, \ - 'mergeStatistics.dat' using 1:11 title "Complete Code (excluding textedit)" with lines + 'mergeStatistics.dat' using 1:5 title "Crossfire Only Code (excluding textedit)" with lines, \ + 'mergeStatistics.dat' using 1:7 title "Daimonin Only Code (excluding textedit)" with lines, \ + 'mergeStatistics.dat' using 1:9 title "Crossfire + Merged Code (excluding textedit)" with lines, \ + 'mergeStatistics.dat' using 1:11 title "Daimonin + Merged Code (excluding textedit)" with lines, \ + 'mergeStatistics.dat' using 1:13 title "Complete Code (excluding textedit)" with lines, \ + 'mergeStatistics.dat' using 1:15 title "Crossfire diff to Daimonin" with lines, \ + 'mergeStatistics.dat' using 1:16 title "Daimonin diff to Crossfire" with lines Modified: trunk/src/mergeMetrics4.gpl =================================================================== --- trunk/src/mergeMetrics4.gpl 2007-01-05 00:55:56 UTC (rev 1435) +++ trunk/src/mergeMetrics4.gpl 2007-01-05 00:56:42 UTC (rev 1436) @@ -11,11 +11,15 @@ plot \ 'mergeStatistics.dat' using 2:3 title "Merged Code (excluding textedit)" with lines, \ 'mergeStatistics.dat' using 2:4 title "Merged Code (including textedit)" with lines, \ - 'mergeStatistics.dat' using 2:5 title "Crossfire Code (excluding textedit)" with lines, \ - 'mergeStatistics.dat' using 2:6 title "Crossfire Code (including textedit)" with lines, \ - 'mergeStatistics.dat' using 2:7 title "Daimonin Code (excluding textedit)" with lines, \ - 'mergeStatistics.dat' using 2:8 title "Daimonin Code (including textedit)" with lines, \ - 'mergeStatistics.dat' using 2:9 title "Crossfire diff to Daimonin" with lines, \ - 'mergeStatistics.dat' using 2:10 title "Daimonin diff to Crossfire" with lines, \ - 'mergeStatistics.dat' using 2:11 title "Complete Code (excluding textedit)" with lines, \ - 'mergeStatistics.dat' using 2:12 title "Complete Code (including textedit)" with lines + 'mergeStatistics.dat' using 2:5 title "Crossfire Only Code (excluding textedit)" with lines, \ + 'mergeStatistics.dat' using 2:6 title "Crossfire Only Code (including textedit)" with lines, \ + 'mergeStatistics.dat' using 2:7 title "Daimonin Only Code (excluding textedit)" with lines, \ + 'mergeStatistics.dat' using 2:8 title "Daimonin Only Code (including textedit)" with lines, \ + 'mergeStatistics.dat' using 2:9 title "Crossfire + Merged Code (excluding textedit)" with lines, \ + 'mergeStatistics.dat' using 2:10 title "Crossfire + Merged Code (including textedit)" with lines, \ + 'mergeStatistics.dat' using 2:11 title "Daimonin + Merged Code (excluding textedit)" with lines, \ + 'mergeStatistics.dat' using 2:12 title "Daimonin + Merged Code (including textedit)" with lines, \ + 'mergeStatistics.dat' using 2:13 title "Complete Code (excluding textedit)" with lines, \ + 'mergeStatistics.dat' using 2:14 title "Complete Code (including textedit)" with lines, \ + 'mergeStatistics.dat' using 2:15 title "Crossfire diff to Daimonin" with lines, \ + 'mergeStatistics.dat' using 2:16 title "Daimonin diff to Crossfire" with lines Modified: trunk/src/mergeMetrics5.gpl =================================================================== --- trunk/src/mergeMetrics5.gpl 2007-01-05 00:55:56 UTC (rev 1435) +++ trunk/src/mergeMetrics5.gpl 2007-01-05 00:56:42 UTC (rev 1436) @@ -10,8 +10,10 @@ set key below plot \ 'mergeStatistics.dat' using 2:4 title "Merged Code (including textedit)" with lines, \ - 'mergeStatistics.dat' using 2:6 title "Crossfire Code (including textedit)" with lines, \ - 'mergeStatistics.dat' using 2:8 title "Daimonin Code (including textedit)" with lines, \ - 'mergeStatistics.dat' using 2:9 title "Crossfire diff to Daimonin" with lines, \ - 'mergeStatistics.dat' using 2:10 title "Daimonin diff to Crossfire" with lines, \ - 'mergeStatistics.dat' using 2:12 title "Complete Code (including textedit)" with lines + 'mergeStatistics.dat' using 2:6 title "Crossfire Only Code (including textedit)" with lines, \ + 'mergeStatistics.dat' using 2:8 title "Daimonin Only Code (including textedit)" with lines, \ + 'mergeStatistics.dat' using 2:10 title "Crossfire + Merged Code (including textedit)" with lines, \ + 'mergeStatistics.dat' using 2:12 title "Daimonin + Merged Code (including textedit)" with lines, \ + 'mergeStatistics.dat' using 2:14 title "Complete Code (including textedit)" with lines, \ + 'mergeStatistics.dat' using 2:15 title "Crossfire diff to Daimonin" with lines, \ + 'mergeStatistics.dat' using 2:16 title "Daimonin diff to Crossfire" with lines Modified: trunk/src/mergeMetrics6.gpl =================================================================== --- trunk/src/mergeMetrics6.gpl 2007-01-05 00:55:56 UTC (rev 1435) +++ trunk/src/mergeMetrics6.gpl 2007-01-05 00:56:42 UTC (rev 1436) @@ -10,8 +10,10 @@ set key below plot \ 'mergeStatistics.dat' using 2:3 title "Merged Code (excluding textedit)" with lines, \ - 'mergeStatistics.dat' using 2:5 title "Crossfire Code (excluding textedit)" with lines, \ - 'mergeStatistics.dat' using 2:7 title "Daimonin Code (excluding textedit)" with lines, \ - 'mergeStatistics.dat' using 2:9 title "Crossfire diff to Daimonin" with lines, \ - 'mergeStatistics.dat' using 2:10 title "Daimonin diff to Crossfire" with lines, \ - 'mergeStatistics.dat' using 2:11 title "Complete Code (excluding textedit)" with lines + 'mergeStatistics.dat' using 2:5 title "Crossfire Only Code (excluding textedit)" with lines, \ + 'mergeStatistics.dat' using 2:7 title "Daimonin Only Code (excluding textedit)" with lines, \ + 'mergeStatistics.dat' using 2:9 title "Crossfire + Merged Code (excluding textedit)" with lines, \ + 'mergeStatistics.dat' using 2:11 title "Daimonin + Merged Code (excluding textedit)" with lines, \ + 'mergeStatistics.dat' using 2:13 title "Complete Code (excluding textedit)" with lines, \ + 'mergeStatistics.dat' using 2:15 title "Crossfire diff to Daimonin" with lines, \ + 'mergeStatistics.dat' using 2:16 title "Daimonin diff to Crossfire" with lines This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2007-01-05 07:21:45
|
Revision: 1440 http://svn.sourceforge.net/gridarta/?rev=1440&view=rev Author: akirschbaum Date: 2007-01-04 23:21:46 -0800 (Thu, 04 Jan 2007) Log Message: ----------- Unify code. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/GameObject.java trunk/daimonin/src/daieditor/gameobject/GameObject.java Modified: trunk/crossfire/src/cfeditor/gameobject/GameObject.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2007-01-05 01:37:30 UTC (rev 1439) +++ trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2007-01-05 07:21:46 UTC (rev 1440) @@ -534,8 +534,6 @@ clone.setMapX(posx); clone.setMapY(posy); - // If 'this' arch is a container, we have to create clones - // of the whole inventory (recursively) and link them in: for (final GameObject invItem : inv) { clone.addLast(invItem.createClone(posx, posy)); } Modified: trunk/daimonin/src/daieditor/gameobject/GameObject.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/GameObject.java 2007-01-05 01:37:30 UTC (rev 1439) +++ trunk/daimonin/src/daieditor/gameobject/GameObject.java 2007-01-05 07:21:46 UTC (rev 1440) @@ -552,8 +552,9 @@ clone.script = new ScriptArchData(clone); // Script data clone.setMapX(posx); clone.setMapY(posy); - for (final GameObject tmp : this) { // Inventory - clone.addLast(tmp.createClone(-1, -1)); + + for (final GameObject invItem : this) { // Inventory + clone.addLast(invItem.createClone(-1, -1)); } return clone; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2007-01-05 07:41:06
|
Revision: 1442 http://svn.sourceforge.net/gridarta/?rev=1442&view=rev Author: akirschbaum Date: 2007-01-04 23:41:03 -0800 (Thu, 04 Jan 2007) Log Message: ----------- Remove useless comments. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/GameObject.java trunk/daimonin/src/daieditor/gameobject/GameObject.java Modified: trunk/crossfire/src/cfeditor/gameobject/GameObject.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2007-01-05 07:35:59 UTC (rev 1441) +++ trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2007-01-05 07:41:03 UTC (rev 1442) @@ -512,7 +512,7 @@ clone.multiY = multiY; if (script != null) { - clone.script = script.getClone(); // clone scripting data + clone.script = script.getClone(); } clone.setArchetype(getArchetype()); // default arch Modified: trunk/daimonin/src/daieditor/gameobject/GameObject.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/GameObject.java 2007-01-05 07:35:59 UTC (rev 1441) +++ trunk/daimonin/src/daieditor/gameobject/GameObject.java 2007-01-05 07:41:03 UTC (rev 1442) @@ -549,11 +549,11 @@ clone.multiX = multiX; clone.multiY = multiY; - clone.script = new ScriptArchData(clone); // Script data + clone.script = new ScriptArchData(clone); clone.setMapX(posx); clone.setMapY(posy); - for (final GameObject invItem : this) { // Inventory + for (final GameObject invItem : this) { clone.addLast(invItem.createClone(-1, -1)); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2007-01-05 12:19:19
|
Revision: 1443 http://svn.sourceforge.net/gridarta/?rev=1443&view=rev Author: christianhujer Date: 2007-01-05 04:19:20 -0800 (Fri, 05 Jan 2007) Log Message: ----------- Adding test for MapArchObject. Modified Paths: -------------- trunk/gridarta.ipr trunk/src/app/net/sf/gridarta/map/AbstractMapArchObject.java Added Paths: ----------- trunk/daimonin/src/test/daieditor/map/MapArchObjectTest.java trunk/daimonin/src/test/daieditor/map/noAttributes.testdata trunk/daimonin/src/test/daieditor/map/package.html Added: trunk/daimonin/src/test/daieditor/map/MapArchObjectTest.java =================================================================== --- trunk/daimonin/src/test/daieditor/map/MapArchObjectTest.java (rev 0) +++ trunk/daimonin/src/test/daieditor/map/MapArchObjectTest.java 2007-01-05 12:19:20 UTC (rev 1443) @@ -0,0 +1,46 @@ +package test.daieditor.map; + +import daieditor.map.MapArchObject; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import net.sf.gridarta.Size2D; +import net.sf.gridarta.map.AbstractMapArchObject; +import org.junit.Assert; +import org.junit.Test; + +/** + * Test for {@link MapArchObject}. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public class MapArchObjectTest { + + /** + * Test for {@link MapArchObject#parseMapArch(java.io.BufferedReader, String)}. + * @throws IOException (unexpected) + */ + @Test public void testParseMapArchNoAttributes() throws IOException { + final MapArchObject mao = new MapArchObject(); + final BufferedReader in = openTestDataReader("noAttributes.testdata"); + try { + mao.parseMapArch(in, "noAttributes.testdata"); + } finally { + in.close(); + } + Assert.assertEquals(mao.getMapName(), AbstractMapArchObject.MAP_NAME_UNNAMED); + Assert.assertEquals(mao.getMapSize(), Size2D.ONE); + } + + /** + * Reads test data. + * @param testDataName Name of the test data to open + * @return BufferedReader for reading from testDataName. + */ + private BufferedReader openTestDataReader(final String testDataName) { + final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); + final InputStream in = contextClassLoader.getResourceAsStream(getClass().getPackage().getName().replace('.', '/') + "/" + testDataName); + return new BufferedReader(new InputStreamReader(in)); + } + +} // class MapArchObjectTest Property changes on: trunk/daimonin/src/test/daieditor/map/MapArchObjectTest.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Added: trunk/daimonin/src/test/daieditor/map/noAttributes.testdata =================================================================== --- trunk/daimonin/src/test/daieditor/map/noAttributes.testdata (rev 0) +++ trunk/daimonin/src/test/daieditor/map/noAttributes.testdata 2007-01-05 12:19:20 UTC (rev 1443) @@ -0,0 +1,2 @@ +arch map +end \ No newline at end of file Property changes on: trunk/daimonin/src/test/daieditor/map/noAttributes.testdata ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Added: trunk/daimonin/src/test/daieditor/map/package.html =================================================================== --- trunk/daimonin/src/test/daieditor/map/package.html (rev 0) +++ trunk/daimonin/src/test/daieditor/map/package.html 2007-01-05 12:19:20 UTC (rev 1443) @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de"> + <head> + <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" /> + <title></title> + </head> + <body> + <p> + Tests for package {@link daieditor.map}. + </p> + </body> +</html> Property changes on: trunk/daimonin/src/test/daieditor/map/package.html ___________________________________________________________________ Name: svn:mime-type + text/html Name: svn:eol-style + LF Modified: trunk/gridarta.ipr =================================================================== --- trunk/gridarta.ipr 2007-01-05 07:41:03 UTC (rev 1442) +++ trunk/gridarta.ipr 2007-01-05 12:19:20 UTC (rev 1443) @@ -70,6 +70,7 @@ <entry name="?*.html" /> <entry name="?*.dtd" /> <entry name="?*.tld" /> + <entry name="?*.testdata" /> </wildcardResourcePatterns> </component> <component name="DataSourceManagerImpl" /> Modified: trunk/src/app/net/sf/gridarta/map/AbstractMapArchObject.java =================================================================== --- trunk/src/app/net/sf/gridarta/map/AbstractMapArchObject.java 2007-01-05 07:41:03 UTC (rev 1442) +++ trunk/src/app/net/sf/gridarta/map/AbstractMapArchObject.java 2007-01-05 12:19:20 UTC (rev 1443) @@ -9,11 +9,14 @@ */ public abstract class AbstractMapArchObject implements MapArchObject { + /** Name of an unnamed map. */ + @NotNull public static final String MAP_NAME_UNNAMED = "<unnamed>"; + /** The size of the map reflected by this MapArchObject. */ @NotNull private Size2D mapSize = Size2D.ONE; /** The name of this map. */ - @NotNull private String mapName = "<unnamed>"; + @NotNull private String mapName = MAP_NAME_UNNAMED; /** The filename of this map. */ // TODO: Rename because the filename is a URI now. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2007-01-05 17:50:13
|
Revision: 1445 http://svn.sourceforge.net/gridarta/?rev=1445&view=rev Author: akirschbaum Date: 2007-01-05 09:50:13 -0800 (Fri, 05 Jan 2007) Log Message: ----------- Fix typo. Modified Paths: -------------- trunk/crossfire/src/cfeditor/ScriptArchData.java trunk/daimonin/src/daieditor/ScriptArchData.java Modified: trunk/crossfire/src/cfeditor/ScriptArchData.java =================================================================== --- trunk/crossfire/src/cfeditor/ScriptArchData.java 2007-01-05 14:23:17 UTC (rev 1444) +++ trunk/crossfire/src/cfeditor/ScriptArchData.java 2007-01-05 17:50:13 UTC (rev 1445) @@ -791,7 +791,7 @@ } /** - * Set event path and plgin name according to user input from popup + * Set event path and plugin name according to user input from popup * dialog. */ public void modifyEventPath() { Modified: trunk/daimonin/src/daieditor/ScriptArchData.java =================================================================== --- trunk/daimonin/src/daieditor/ScriptArchData.java 2007-01-05 14:23:17 UTC (rev 1444) +++ trunk/daimonin/src/daieditor/ScriptArchData.java 2007-01-05 17:50:13 UTC (rev 1445) @@ -724,7 +724,7 @@ } /** - * Set event path and plgin name according to user input from popup + * Set event path and plugin name according to user input from popup * dialog. */ public void modifyEventPath() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2007-01-05 17:53:31
|
Revision: 1446 http://svn.sourceforge.net/gridarta/?rev=1446&view=rev Author: akirschbaum Date: 2007-01-05 09:53:28 -0800 (Fri, 05 Jan 2007) Log Message: ----------- Remove unused code. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/CMainView.java trunk/crossfire/src/cfeditor/IGUIConstants.java trunk/crossfire/src/cfeditor/gui/selectedsquare/SelectedSquareControl.java trunk/crossfire/src/cfeditor/map/MapControl.java trunk/daimonin/src/daieditor/gui/map/tools/DeletionTool.java trunk/daimonin/src/daieditor/gui/selectedsquare/SelectedSquareControl.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2007-01-05 17:50:13 UTC (rev 1445) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2007-01-05 17:53:28 UTC (rev 1446) @@ -1267,14 +1267,6 @@ } } - public boolean isTileShow() { - return currentMap.isTileShow(); - } - - public void setTileShow(final boolean tileShow) { - currentMap.setTileShow(tileShow); - } - private PreferencesGroup prefsGroup; public void options() { @@ -1634,11 +1626,6 @@ mainView.refreshMenusAndToolbars(); } - /** Relayouts and repaints the main view. */ - public void refreshMainView() { - mainView.refresh(); - } - /** * Returns whether a level is being edited or not. * @return true if a level is being edited or false if not Modified: trunk/crossfire/src/cfeditor/CMainView.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainView.java 2007-01-05 17:50:13 UTC (rev 1445) +++ trunk/crossfire/src/cfeditor/CMainView.java 2007-01-05 17:53:28 UTC (rev 1446) @@ -472,12 +472,6 @@ mapArchPanel.refresh(); } - /** Refresh the arch panel (left window). */ - void refreshArchPanel() { - archPanel.invalidate(); - archPanel.refresh(); - } - public void setRevertMenuEnabled(final boolean state) { aRevert.setEnabled(state && mainControl.isPlainSaveEnabled()); aSave.setEnabled(state && mainControl.isPlainSaveEnabled()); @@ -491,15 +485,6 @@ } /** - * Relayouts and repaints the main view and - * all its components. - */ - void refresh() { - refresh3(); - repaint(); - } - - /** * Adds the level view. * @param mapView the map view to add */ Modified: trunk/crossfire/src/cfeditor/IGUIConstants.java =================================================================== --- trunk/crossfire/src/cfeditor/IGUIConstants.java 2007-01-05 17:50:13 UTC (rev 1445) +++ trunk/crossfire/src/cfeditor/IGUIConstants.java 2007-01-05 17:53:28 UTC (rev 1446) @@ -159,12 +159,6 @@ String SAVE_LEVEL_AS_ICON = "SaveLevelAsIcon.gif"; - String UNDO_ICON = "UndoIcon.gif"; - - String REDO_ICON = "RedoIcon.gif"; - - String REVERT_ICON = "RevertIcon.gif"; - String NEXT_WINDOW_ICON = "NextWindowIcon.gif"; String PREVIOUS_WINDOW_ICON = "PrevWindowIcon.gif"; Modified: trunk/crossfire/src/cfeditor/gui/selectedsquare/SelectedSquareControl.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/selectedsquare/SelectedSquareControl.java 2007-01-05 17:50:13 UTC (rev 1445) +++ trunk/crossfire/src/cfeditor/gui/selectedsquare/SelectedSquareControl.java 2007-01-05 17:53:28 UTC (rev 1446) @@ -241,16 +241,6 @@ } /** - * Set the display to the currently selected map tile. - * @param mapControl Map to get display for (includes selection information) - * @param gameObject selected GameObject - */ - public void setMapTileList(final MapControl mapControl, final GameObject gameObject) { - // refresh the MapArchPanel to display the new arch - mainView.refreshMapArchPanel(); - } - - /** * Return the view for this controller. * * @return the view for this controller Modified: trunk/crossfire/src/cfeditor/map/MapControl.java =================================================================== --- trunk/crossfire/src/cfeditor/map/MapControl.java 2007-01-05 17:50:13 UTC (rev 1445) +++ trunk/crossfire/src/cfeditor/map/MapControl.java 2007-01-05 17:53:28 UTC (rev 1446) @@ -83,22 +83,6 @@ private final boolean isPickmap; /** - * Flag that indicates whether the tile maps surrounding current one - * must be displayed. - */ - private boolean showTiles = false; - - /** - * surrounding tiles. - * In order: north-west, north, north-east, west, east, south-west, south, south-east - */ - private MapModel tileModel[]; - - private int northHeight, southHeight; - - private int westWidth, eastWidth; - - /** * Constructs a new Map. * @param mainControl the CMainControl * @param maparch the <code>MapArchObject</code> of the map @@ -480,13 +464,8 @@ * Return the width of the level + neighbors tile maps if any. * @return global width */ - // TODO implement this int getDisplayMapWidth() { - if (showTiles) { - return mapModel.getMapSize().getWidth() + eastWidth + westWidth; - } else { - return mapModel.getMapSize().getWidth(); - } + return mapModel.getMapSize().getWidth(); } /** @@ -494,35 +473,9 @@ * @return global height */ int getDisplayMapHeight() { - if (showTiles) { - return mapModel.getMapSize().getHeight() + northHeight + southHeight; - } else { - return mapModel.getMapSize().getHeight(); - } + return mapModel.getMapSize().getHeight(); } - public boolean isTileShow() { - return showTiles; - } - - public void setTileShow(final boolean show) { - showTiles = show; - if (show) { - /*Do the tile maps loading :)*/ - final String north = mapModel.getMapArchObject().getTilePath(IGUIConstants.NORTH); - final String west = mapModel.getMapArchObject().getTilePath(IGUIConstants.WEST); - final String east = mapModel.getMapArchObject().getTilePath(IGUIConstants.EAST); - final String south = mapModel.getMapArchObject().getTilePath(IGUIConstants.SOUTH); - /*tileModel = new DefaultMapModel[8]; - CMapFileDecode loader; - MapControl tmp; - loader = new CMapFileDecode(); - loader.decodeMapFile() - tmp = new MapControl() - tileModel[1] = new DefaultMapModel()*/ - } - } - /* {@inheritDoc} */ public boolean isPointValid(final Point pos) { return mapModel.isPointValid(pos); Modified: trunk/daimonin/src/daieditor/gui/map/tools/DeletionTool.java =================================================================== --- trunk/daimonin/src/daieditor/gui/map/tools/DeletionTool.java 2007-01-05 17:50:13 UTC (rev 1445) +++ trunk/daimonin/src/daieditor/gui/map/tools/DeletionTool.java 2007-01-05 17:53:28 UTC (rev 1446) @@ -58,7 +58,6 @@ if (mapCursor.setLocationSafe(mapLoc)) { // delete the topmost arch (matching the view settings) on that square and redraw the map deleteArch(mapLoc, mapControl); - //mainControl.getMainView().setMapTileList(mainControl.getCurrentMap(), null); } } Modified: trunk/daimonin/src/daieditor/gui/selectedsquare/SelectedSquareControl.java =================================================================== --- trunk/daimonin/src/daieditor/gui/selectedsquare/SelectedSquareControl.java 2007-01-05 17:50:13 UTC (rev 1445) +++ trunk/daimonin/src/daieditor/gui/selectedsquare/SelectedSquareControl.java 2007-01-05 17:53:28 UTC (rev 1446) @@ -261,16 +261,6 @@ } /** - * Set the display to the currently selected map tile. - * @param mapControl Map to get display for (includes selection information) - * @param gameObject selected GameObject - */ - public void setMapTileList(final MapControl mapControl, final GameObject gameObject) { - // refresh the MapArchPanel to display the new arch - mainView.refreshMapArchPanel(); - } - - /** * Return the view for this controller. * * @return the view for this controller This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2007-01-05 17:55:31
|
Revision: 1447 http://svn.sourceforge.net/gridarta/?rev=1447&view=rev Author: akirschbaum Date: 2007-01-05 09:55:32 -0800 (Fri, 05 Jan 2007) Log Message: ----------- Add final modifier/rename variable names. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gui/GameObjectAttributesPanel.java trunk/daimonin/src/daieditor/gui/GameObjectAttributesPanel.java Modified: trunk/crossfire/src/cfeditor/gui/GameObjectAttributesPanel.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/GameObjectAttributesPanel.java 2007-01-05 17:53:28 UTC (rev 1446) +++ trunk/crossfire/src/cfeditor/gui/GameObjectAttributesPanel.java 2007-01-05 17:55:32 UTC (rev 1447) @@ -865,30 +865,27 @@ * @param task Script type to edit (?). */ public void editScriptWanted(final int task) { - GameObject gameObject = mainControl.getMainView().getMapTileSelection(); // get selected gameObject + final GameObject gameObject = mainControl.getMainView().getMapTileSelection(); // get selected gameObject if (gameObject == null) { return; } - gameObject = gameObject.getHead(); - // check for a valid selection in the event list if (eventList.getModel() != null && eventList.getModel().getSize() > 0 && eventList.getSelectedIndex() >= 0) { // there String eventType = (String) eventList.getSelectedValue(); if (eventType != null && eventType.length() > 0) { eventType = eventType.trim(); - gameObject.modifyEventScript(eventType, task, eventList, this); + gameObject.getHead().modifyEventScript(eventType, task, eventList, this); } } } /** This method is invoked when the user pressed the "new script" button. */ public void addNewScriptWanted() { - GameObject arch = mainControl.getMainView().getMapTileSelection(); // get selected arch - if (arch != null) { - arch = arch.getHead(); - arch.addEventScript(eventList, this); + final GameObject gameObject = mainControl.getMainView().getMapTileSelection(); // get selected arch + if (gameObject != null) { + gameObject.getHead().addEventScript(eventList, this); } } Modified: trunk/daimonin/src/daieditor/gui/GameObjectAttributesPanel.java =================================================================== --- trunk/daimonin/src/daieditor/gui/GameObjectAttributesPanel.java 2007-01-05 17:53:28 UTC (rev 1446) +++ trunk/daimonin/src/daieditor/gui/GameObjectAttributesPanel.java 2007-01-05 17:55:32 UTC (rev 1447) @@ -981,29 +981,26 @@ * @param task Script type to edit (?). */ public void editScriptWanted(final int task) { - GameObject gameObject = mainControl.getMainView().getMapTileSelection(); // get selected gameObject + final GameObject gameObject = mainControl.getMainView().getMapTileSelection(); // get selected gameObject if (gameObject == null) { return; } - gameObject = gameObject.getHead(); - // check for a valid selection in the event list if (eventList.getModel() != null && eventList.getModel().getSize() > 0 && eventList.getSelectedIndex() >= 0) { // there final int index = eventList.getSelectedIndex(); if (index >= 0) { - gameObject.modifyEventScript(index, task, eventList, this); + gameObject.getHead().modifyEventScript(index, task, eventList, this); } } } /** This method is invoked when the user pressed the "new script" button. */ public void addNewScriptWanted() { - GameObject arch = mainControl.getMainView().getMapTileSelection(); // get selected arch - if (arch != null) { - arch = arch.getHead(); - arch.addEventScript(eventList, this); + final GameObject gameObject = mainControl.getMainView().getMapTileSelection(); // get selected arch + if (gameObject != null) { + gameObject.getHead().addEventScript(eventList, this); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2007-01-05 18:00:18
|
Revision: 1448 http://svn.sourceforge.net/gridarta/?rev=1448&view=rev Author: akirschbaum Date: 2007-01-05 10:00:17 -0800 (Fri, 05 Jan 2007) Log Message: ----------- Various code unifications. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CGUIUtils.java trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/CMainView.java trunk/crossfire/src/cfeditor/CMapViewBasic.java trunk/crossfire/src/cfeditor/CopyBuffer.java trunk/crossfire/src/cfeditor/gui/GameObjectAttributesPanel.java trunk/crossfire/src/cfeditor/gui/map/MapPropertiesDialog.java trunk/crossfire/src/cfeditor/io/CMapReader.java trunk/crossfire/src/cfeditor/map/MapControl.java trunk/crossfire/src/cfeditor/parameter/MapParameter.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/CMainView.java trunk/daimonin/src/daieditor/MapViewIFrame.java trunk/daimonin/src/daieditor/gameobject/ArchetypeParser.java trunk/daimonin/src/daieditor/gui/ArchetypeChooser.java trunk/daimonin/src/daieditor/gui/map/MapPropertiesDialog.java trunk/daimonin/src/daieditor/map/MapArchObject.java trunk/daimonin/src/daieditor/map/MapControl.java Modified: trunk/crossfire/src/cfeditor/CGUIUtils.java =================================================================== --- trunk/crossfire/src/cfeditor/CGUIUtils.java 2007-01-05 17:55:32 UTC (rev 1447) +++ trunk/crossfire/src/cfeditor/CGUIUtils.java 2007-01-05 18:00:17 UTC (rev 1448) @@ -53,6 +53,7 @@ /** Do not subclass. */ private CGUIUtils() { + /* nothing to do - never invoked. */ } /** Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2007-01-05 17:55:32 UTC (rev 1447) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2007-01-05 18:00:17 UTC (rev 1448) @@ -370,8 +370,7 @@ } /** - * Returns whether a tileEdit value is set. - * In case a tileEdit value is set, not all tiles should be displayed. + * Returns whether a tileEdit value is set so that not all tiles are displayed. * @return <code>true</code> if a tileEdit value is set, otherwise <code>false</code>. */ public boolean isTileEditSet() { @@ -656,7 +655,7 @@ for (final MapControl level : levels) { level.getMapViewFrame().updateLookAndFeel(); if (log.isDebugEnabled()) { - log.debug("map " + level.getMapArch().getMapName()); + log.debug("map " + level.getMapArchObject().getMapName()); } } } @@ -821,7 +820,7 @@ } if (!forced && level.isLevelChanged()) { - final int result = ACTION_FACTORY.showConfirmDialog(mainView, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, "confirmSaveChanges", level.getMapArch().getMapDisplayName()); + final int result = ACTION_FACTORY.showConfirmDialog(mainView, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, "confirmSaveChanges", level.getMapArchObject().getMapDisplayName()); if (result == JOptionPane.YES_OPTION) { if (level.isPlainSaveEnabled()) { level.save(); @@ -1411,7 +1410,7 @@ * @param direction the direction to go (see MapArchObject: 'tile_path') */ public void enterTileWanted(final int direction) { - final String path = currentMap.getMapTilePath(direction); + final String path = currentMap.getMapArchObject().getTilePath(direction); if (path == null || path.length() == 0) { // tile direction not set (due to disabled menus this should normally not happen) ACTION_FACTORY.showMessageDialog(mainView, "enterTileNoTile"); Modified: trunk/crossfire/src/cfeditor/CMainView.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainView.java 2007-01-05 17:55:32 UTC (rev 1447) +++ trunk/crossfire/src/cfeditor/CMainView.java 2007-01-05 18:00:17 UTC (rev 1448) @@ -158,10 +158,6 @@ /** <code>true</code> when archpanel is merged into the bottom panel. */ private boolean mapTileListBottom = true; - private AggregateMenuLocation mainLocation; - - private AggregateMenuLocation currentmapLocation; - /** * Constructs the main view and registers the given main controller. */ @@ -500,7 +496,6 @@ } else { mapView.setBounds(0, 0, mapDesktop.getWidth() - 2, mapDesktop.getHeight() - 2); } - //mapView.setBounds(0, 0, 320, 240); mapView.setVisible(true); setCurrentLevelView(mapView); } @@ -509,10 +504,8 @@ * Removes (closes) the level view. * @param mapView the map view to be removed (closed) */ - void removeLevelView(final MapViewIFrame mapView) { - if (!mapViews.contains(mapView)) { - return; - } + public void removeLevelView(final MapViewIFrame mapView) { + assert mapViews.contains(mapView); mapViews.remove(mapView); mapDesktop.remove(mapView); @@ -613,8 +606,8 @@ mapViews.remove(view); mapViews.add(view); refreshMenusAndToolbars(); + updateFocus(false); } - updateFocus(false); } /** Gives focus to the previous window. */ @@ -624,8 +617,8 @@ mapViews.remove(view); mapViews.add(0, view); refreshMenusAndToolbars(); + updateFocus(false); } - updateFocus(false); } /** @@ -642,7 +635,8 @@ view.setIcon(false); view.show(); return; - } catch (final PropertyVetoException cantUniconify) { + } catch (final PropertyVetoException e) { + log.warn(ACTION_FACTORY.format("unexpectedException", e)); } } updateFocus(true); @@ -892,7 +886,7 @@ //aTileShow.setEnabled(mapState); aMapProperties.setEnabled(mapState); for (int direction = 0; direction < directionsMap.length; direction++) { - final String mtp = mapState ? mainControl.getCurrentMap().getMapArch().getTilePath(direction) : null; + final String mtp = mapState ? mainControl.getCurrentMap().getMapArchObject().getTilePath(direction) : null; ACTION_FACTORY.getAction(directionsMap[direction]).setEnabled(mtp != null && mtp.length() > 0); } aEnterExit.setEnabled(selState); @@ -912,12 +906,9 @@ } private void buildAggregates() { - mainLocation = new AggregateMenuLocation("main"); - final AggregateMenuLocation toolbarLocation = new AggregateMenuLocation("toolbar"); - currentmapLocation = new AggregateMenuLocation("currentmap"); - MenuManager.getMenuManager().addMenuLocation(mainLocation); - MenuManager.getMenuManager().addMenuLocation(toolbarLocation); - MenuManager.getMenuManager().addMenuLocation(currentmapLocation); + MenuManager.getMenuManager().addMenuLocation(new AggregateMenuLocation("main")); + MenuManager.getMenuManager().addMenuLocation(new AggregateMenuLocation("toolbar")); + MenuManager.getMenuManager().addMenuLocation(new AggregateMenuLocation("currentmap")); } public SelectedSquareControl getMapTileListControl() { Modified: trunk/crossfire/src/cfeditor/CMapViewBasic.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapViewBasic.java 2007-01-05 17:55:32 UTC (rev 1447) +++ trunk/crossfire/src/cfeditor/CMapViewBasic.java 2007-01-05 18:00:17 UTC (rev 1448) @@ -127,7 +127,6 @@ * @param fi MapView. */ CMapViewBasic(final CMainControl mainControl, final MapControl mapControl, final MapView fi, final Point initial) { - //super("Map ["+control.getMapFileName()+"]", true, true, true, true); super(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); this.mapControl = mapControl; mapModel = mapControl.getMapModel(); @@ -185,7 +184,7 @@ * Get MapGrid of this view. * @return MapGrid of this view. */ - public MapGrid getMapGrid() { + @NotNull public MapGrid getMapGrid() { return mapGrid; } @@ -197,10 +196,6 @@ return mapCursor; } - @Nullable public Point getCursorPosition() { - return mapCursor.getLocation(); - } - public boolean isPickmap() { return mapControl.isPickmap(); } @@ -213,6 +208,12 @@ return gridVisible; } + public void setGridVisible(final boolean gridVisible) { + this.gridVisible = gridVisible; + + modelChanged(); + } + /** Update for a new look and feel (-> view menu). */ public void updateLookAndFeel() { renderer.updateLookAndFeel(); @@ -234,12 +235,6 @@ return mapControl; } - public void setGridVisible(final boolean gridVisible) { - this.gridVisible = gridVisible; - - modelChanged(); - } - /** * Returns the controller of this view. * @return The controller of this view. @@ -254,11 +249,22 @@ * This method is mainly useful for creating a submap for copy/paste operations. * @return selected Rectangle */ - public Rectangle getSelectionRec() { + @Nullable public Rectangle getSelectionRec() { return mapGrid.getSelectedRec(); } /** + * Get the cursor position. + * The cursor position does not neccessarily mark a selection. + * Selection is independent of the cursor. + * @return cursor position + * @see #getCursorSquare() + */ + @Nullable public Point getCursorPosition() { + return mapCursor.getLocation(); + } + + /** * Set the cursor position. * @param cursorPosition cursor position * @see #getCursorPosition() @@ -301,6 +307,10 @@ return mapGrid.getSelectedRec() != null; } + /** + * Get the selection. + * @return selection + */ public Point[] getSelection() { final List<Point> selection = new ArrayList<Point>(); final Size2D mapSize = mapModel.getMapSize(); Modified: trunk/crossfire/src/cfeditor/CopyBuffer.java =================================================================== --- trunk/crossfire/src/cfeditor/CopyBuffer.java 2007-01-05 17:55:32 UTC (rev 1447) +++ trunk/crossfire/src/cfeditor/CopyBuffer.java 2007-01-05 18:00:17 UTC (rev 1448) @@ -154,8 +154,6 @@ // delete the gameObject if we have a "cut" or "clear" command // again, arches that don't match the view settings are ignored if ((mode == Mode.DO_CLEAR || mode == Mode.DO_CUT) && mainControl.isTileEdit(gameObject)) { - // store next arch in tmp - // delete gameObject (without redrawing the map) // For CUT we don't delete multi tails of multis which are left or // above the head (we would miss to copy them otherwise). Modified: trunk/crossfire/src/cfeditor/gui/GameObjectAttributesPanel.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/GameObjectAttributesPanel.java 2007-01-05 17:55:32 UTC (rev 1447) +++ trunk/crossfire/src/cfeditor/gui/GameObjectAttributesPanel.java 2007-01-05 18:00:17 UTC (rev 1448) @@ -307,6 +307,7 @@ final GameObject archetype = gameObject.getArchetype(); if (archetype == null) { // hm, this should NOT happen + System.err.println("trying to change a GameObject with null Archetype"); // TODO: use logging return; } @@ -542,8 +543,8 @@ } /** - * Set up the script panel tab. - * @return Newly created script panel. + * Creates a script panel. + * @return newly created script panel. */ private JPanel createScriptPanel() { eventList = new JList(); Modified: trunk/crossfire/src/cfeditor/gui/map/MapPropertiesDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/map/MapPropertiesDialog.java 2007-01-05 17:55:32 UTC (rev 1447) +++ trunk/crossfire/src/cfeditor/gui/map/MapPropertiesDialog.java 2007-01-05 18:00:17 UTC (rev 1448) @@ -149,7 +149,7 @@ this.mainControl = mainControl; this.mapControl = mapControl; - final MapArchObject map = mapControl.getMapArch(); + final MapArchObject map = mapControl.getMapArchObject(); final JTabbedPane tabs = new JTabbedPane(); tabs.setBorder(new EmptyBorder(10, 4, 4, 4)); @@ -452,7 +452,7 @@ // now that all is well, write the new values into the maparch - final MapArchObject map = mapControl.getMapArch(); + final MapArchObject map = mapControl.getMapArchObject(); mapControl.getMapModel().beginTransaction("Map properties"); // TODO: I18N/L10N @@ -569,7 +569,7 @@ /** Reset all map properties to the saved values in the maparch. */ private void restoreMapProperties() { - final MapArchObject map = mapControl.getMapArch(); + final MapArchObject map = mapControl.getMapArchObject(); mapDescription.setText(map.getText()); mapLore.setText(map.getLore()); @@ -610,7 +610,7 @@ /** * Open a popup and ask user to confirm his map-resizing selection. This * popup dialog disables all other windows (and threads). - * @param size New size. + * @param size New size for the map. * @return true if user confirmed, false if user cancelled resize */ private boolean askConfirmResize(final Size2D size) { @@ -625,7 +625,7 @@ */ public static void showDialog(final CMainView mainView, final CMainControl mainControl, final MapControl level) { final MapPropertiesDialog pane = new MapPropertiesDialog(mainControl, level); - final JDialog dialog = pane.createDialog(mainView, ACTION_FACTORY.format("mapTitle", level.getMapArch().getMapDisplayName(), level.getMapFileName())); + final JDialog dialog = pane.createDialog(mainView, ACTION_FACTORY.format("mapTitle", level.getMapArchObject().getMapDisplayName(), level.getMapFileName())); dialog.getRootPane().setDefaultButton(pane.okButton); dialog.setResizable(true); dialog.setModal(false); Modified: trunk/crossfire/src/cfeditor/io/CMapReader.java =================================================================== --- trunk/crossfire/src/cfeditor/io/CMapReader.java 2007-01-05 17:55:32 UTC (rev 1447) +++ trunk/crossfire/src/cfeditor/io/CMapReader.java 2007-01-05 18:00:17 UTC (rev 1448) @@ -54,7 +54,7 @@ * @param uri URI of resource to open. * @throws FileNotFoundException in case the resource was not found. */ - public CMapReader(final String uri) throws FileNotFoundException { + public CMapReader(@NotNull final String uri) throws FileNotFoundException { super(uri); } @@ -63,7 +63,7 @@ * @param file File to open. * @throws FileNotFoundException in case the file was not found. */ - public CMapReader(final File file) throws FileNotFoundException { + public CMapReader(@NotNull final File file) throws FileNotFoundException { super(file); } Modified: trunk/crossfire/src/cfeditor/map/MapControl.java =================================================================== --- trunk/crossfire/src/cfeditor/map/MapControl.java 2007-01-05 17:55:32 UTC (rev 1447) +++ trunk/crossfire/src/cfeditor/map/MapControl.java 2007-01-05 18:00:17 UTC (rev 1448) @@ -52,8 +52,6 @@ */ private final CMainControl mainControl; - private final MapArchObject mapArch; - /** * model (= map data of this level). */ @@ -92,7 +90,6 @@ */ public MapControl(final CMainControl mainControl, final List<GameObject> objects, final MapArchObject maparch, final boolean isPickmap, final Point initial) { this.mainControl = mainControl; - mapArch = maparch; activeEditType = 0; // start with no edit types (saves time) this.isPickmap = isPickmap; // is this a pickmap? // we create model (= data) @@ -231,16 +228,16 @@ } public String getMapFileName() { - return mapArch.getFileName(); + return mapModel.getMapArchObject().getFileName(); } public void setMapFileName(final String fname) { if (mapViewFrame != null) { - final String title = fname + " [ " + mapArch.getMapName() + " ]"; + final String title = fname + " [ " + mapModel.getMapArchObject().getMapName() + " ]"; assert mapViewFrame != null; mapViewFrame.setTitle(title); } - mapArch.setFileName(fname); + mapModel.getMapArchObject().setFileName(fname); } public boolean containsArchObject(final Point pos) { @@ -531,7 +528,7 @@ mapFile = file; } - public MapArchObject getMapArch() { + public MapArchObject getMapArchObject() { return mapModel.getMapArchObject(); } Modified: trunk/crossfire/src/cfeditor/parameter/MapParameter.java =================================================================== --- trunk/crossfire/src/cfeditor/parameter/MapParameter.java 2007-01-05 17:55:32 UTC (rev 1447) +++ trunk/crossfire/src/cfeditor/parameter/MapParameter.java 2007-01-05 18:00:17 UTC (rev 1448) @@ -65,7 +65,7 @@ super.setValue(null); } else { final MapControl map = (MapControl) value; - super.setValue(map.getMapArch().getMapName()); + super.setValue(map.getMapArchObject().getMapName()); } } Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2007-01-05 17:55:32 UTC (rev 1447) +++ trunk/daimonin/src/daieditor/CMainControl.java 2007-01-05 18:00:17 UTC (rev 1448) @@ -992,7 +992,7 @@ } if (!forced && level.isLevelChanged()) { - final int result = ACTION_FACTORY.showConfirmDialog(mainView, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, "confirmSaveChanges", level.getMapArch().getMapDisplayName()); + final int result = ACTION_FACTORY.showConfirmDialog(mainView, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, "confirmSaveChanges", level.getMapArchObject().getMapDisplayName()); if (result == JOptionPane.YES_OPTION) { if (level.isPlainSaveEnabled()) { level.save(); @@ -1210,7 +1210,7 @@ newMap.setActiveEditType(tileEdit); // map is loaded with current view settings if (view) { refreshMenusAndToolbars(); - addRecent(currentMap.getMapArch().getMapDisplayName(), file.toString()); + addRecent(currentMap.getMapArchObject().getMapDisplayName(), file.toString()); } return newMap; } finally { @@ -1605,7 +1605,7 @@ * @param direction the direction to go (see MapArchObject: 'tile_path') */ public void enterTileWanted(final int direction) { - final String path = currentMap.getMapArch().getTilePath(direction); + final String path = currentMap.getMapArchObject().getTilePath(direction); if (path == null || path.length() == 0) { // tile direction not set (due to disabled menus this should normally not happen) ACTION_FACTORY.showMessageDialog(mainView, "enterTileNoTile"); @@ -2340,7 +2340,7 @@ } else { pmap = PickmapChooser.getInstance().getCurrentPickmap(); if (pmap != null) { - title.append("with pickmap ").append(pmap.getMapArch().getMapName()); + title.append("with pickmap ").append(pmap.getMapArchObject().getMapName()); } else { // ok ,we have a problem here: arch == null, pmap == null... // XXX but shouldn't be something told to the user? // Not even a logging? Modified: trunk/daimonin/src/daieditor/CMainView.java =================================================================== --- trunk/daimonin/src/daieditor/CMainView.java 2007-01-05 17:55:32 UTC (rev 1447) +++ trunk/daimonin/src/daieditor/CMainView.java 2007-01-05 18:00:17 UTC (rev 1448) @@ -442,7 +442,6 @@ */ void refreshMenusAndToolbars() { archPanel.refresh(); - //selectedSquareControl.refresh(); mapArchPanel.refresh(); statusBar.refresh(); @@ -808,7 +807,7 @@ aMapCreateView.setEnabled(mapState); aMapProperties.setEnabled(mapState); for (int direction = 0; direction < 8; direction++) { - final String mtp = mapState ? mainControl.getCurrentMap().getMapArch().getTilePath(direction) : null; + final String mtp = mapState ? mainControl.getCurrentMap().getMapArchObject().getTilePath(direction) : null; ACTION_FACTORY.getAction(directionsMap[direction]).setEnabled(mtp != null && mtp.length() > 0); } aEnterExit.setEnabled(selState); Modified: trunk/daimonin/src/daieditor/MapViewIFrame.java =================================================================== --- trunk/daimonin/src/daieditor/MapViewIFrame.java 2007-01-05 17:55:32 UTC (rev 1447) +++ trunk/daimonin/src/daieditor/MapViewIFrame.java 2007-01-05 18:00:17 UTC (rev 1448) @@ -74,7 +74,7 @@ */ public MapViewIFrame(final CMainControl mainControl, final MapControl mapControl, final int number) { // set title - super(mapControl.getMapFileName() + " [ " + mapControl.getMapArch().getMapDisplayName() + " ] ("+ number + ')', true, true, true, true); + super(mapControl.getMapFileName() + " [ " + mapControl.getMapArchObject().getMapDisplayName() + " ] ("+ number + ')', true, true, true, true); this.mapControl = mapControl; this.mainControl = mainControl; Modified: trunk/daimonin/src/daieditor/gameobject/ArchetypeParser.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/ArchetypeParser.java 2007-01-05 17:55:32 UTC (rev 1447) +++ trunk/daimonin/src/daieditor/gameobject/ArchetypeParser.java 2007-01-05 18:00:17 UTC (rev 1448) @@ -152,8 +152,6 @@ parsearch = true; if (!archmore) { firstArch = null; - } else { - // System.err.println("multi part object: part "+ archmore_count); } if (archName == null) { @@ -194,7 +192,9 @@ log.warn(ACTION_FACTORY.format("inventoryInDefArch", thisLine)); } else if (thisLine.startsWith("end")) { //if (arch.getArchTypNr() == 0) { - //System.err.println("Arch "+ arch.getArchetypeName()+" has no type info!"); + if (log.isDebugEnabled()) { + log.debug("Arch " + archetype.getArchetypeName() + " has no type info!"); + } //} // we got full arch parsearch = false; // we write this sucker @@ -263,13 +263,21 @@ animflag = true; animText = new StringBuilder(); } else if (thisLine.startsWith("visibility ")) { - // System.err.println("Remove visibility: "+arch.getArchetypeName()); + if (log.isDebugEnabled()) { + log.debug("Remove visibility: " + archetype.getArchetypeName()); + } } else if (thisLine.startsWith("magicmap ")) { - // System.err.println("Remove magicmap: "+arch.getArchetypeName()); + if (log.isDebugEnabled()) { + log.debug("Remove magicmap: " + archetype.getArchetypeName()); + } } else if (thisLine.startsWith("color_fg ")) { - // System.err.println("Remove color_fg: "+arch.getArchetypeName()); + if (log.isDebugEnabled()) { + log.debug("Remove color_fg: " + archetype.getArchetypeName()); + } } else if (thisLine.startsWith("color_bg ")) { - // System.err.println("Remove color_bg: "+arch.getArchetypeName()); + if (log.isDebugEnabled()) { + log.debug("Remove color_bg: " + archetype.getArchetypeName()); + } } else if (thisLine.startsWith("x ")) { if (!archmore && !archetype.getArchetypeName().equals(STARTARCH_NAME)) { log.warn(ACTION_FACTORY.format("foundCoordInDefArchSingleTileOrHead", "x", archetype.getArchetypeName())); @@ -337,7 +345,9 @@ } else { archetype.addObjectText(thisLine); } - //System.err.println("add String: "+thisLine); + if (log.isDebugEnabled()) { + log.debug("add String: " + thisLine); + } } } thisLine2 = in.readLine(); @@ -356,7 +366,6 @@ final GameObject archetype = gameObject.getArchetype(); gameObject.resetObjectText(); - // so, lets check the stuff a last time for (int i = 0, s = 0; i < len; i++) { if (text.charAt(i) == '\n') { Modified: trunk/daimonin/src/daieditor/gui/ArchetypeChooser.java =================================================================== --- trunk/daimonin/src/daieditor/gui/ArchetypeChooser.java 2007-01-05 17:55:32 UTC (rev 1447) +++ trunk/daimonin/src/daieditor/gui/ArchetypeChooser.java 2007-01-05 18:00:17 UTC (rev 1448) @@ -61,23 +61,6 @@ super(controlPanel, mainControl); } - /*@Override public void finishBuildProcess() { - super.finishBuildProcess(); - // listening for mouse-click events in the ArchPanel list - archList.addMouseListener(new MouseAdapter() { - @Override public void mousePressed(final MouseEvent e) { - if (e.getButton() == MouseEvent.BUTTON3) { - //this will display the future arch editor. - //Because editing default arches is not yet possible, this line is commented in production. - //menu.show((Component) e.getSource(), e.getX(), e.getY()); - } - } - }); - - - //archList.setComponentPopupMenu(menu); - }*/ - private JPopupMenu createListPopupMenu() { final JPopupMenu menu = new JPopupMenu(); menu.add(ACTION_FACTORY.createAction(false, "editPopup", this)); Modified: trunk/daimonin/src/daieditor/gui/map/MapPropertiesDialog.java =================================================================== --- trunk/daimonin/src/daieditor/gui/map/MapPropertiesDialog.java 2007-01-05 17:55:32 UTC (rev 1447) +++ trunk/daimonin/src/daieditor/gui/map/MapPropertiesDialog.java 2007-01-05 18:00:17 UTC (rev 1448) @@ -150,7 +150,7 @@ this.mainControl = mainControl; this.mapControl = mapControl; - final MapArchObject map = mapControl.getMapArch(); + final MapArchObject map = mapControl.getMapArchObject(); final JTabbedPane tabs = new JTabbedPane(); tabs.setBorder(new EmptyBorder(10, 4, 4, 4)); @@ -449,7 +449,7 @@ // now that all is well, write the new values into the maparch - final MapArchObject map = mapControl.getMapArch(); + final MapArchObject map = mapControl.getMapArchObject(); final String mapNameString = mapName.getText() + (mapSound.getText().length() > 0 ? '§' + mapSound.getText() + "|0|-1" : ""); mapControl.getMapModel().resizeMap(mapSize); @@ -503,7 +503,7 @@ /** Reset all map properties to the saved values in the maparch. */ private void restoreMapProperties() { - final MapArchObject map = mapControl.getMapArch(); + final MapArchObject map = mapControl.getMapArchObject(); mapDescription.setText(map.getText()); mapName.setText(map.getMapDisplayName()); @@ -550,7 +550,7 @@ */ public static void showDialog(final CMainView mainView, final CMainControl mainControl, final MapControl level) { final MapPropertiesDialog pane = new MapPropertiesDialog(mainControl, level); - final JDialog dialog = pane.createDialog(mainView, ACTION_FACTORY.format("mapTitle", level.getMapArch().getMapDisplayName(), level.getMapFileName())); + final JDialog dialog = pane.createDialog(mainView, ACTION_FACTORY.format("mapTitle", level.getMapArchObject().getMapDisplayName(), level.getMapFileName())); dialog.getRootPane().setDefaultButton(pane.okButton); dialog.setResizable(true); dialog.setModal(false); Modified: trunk/daimonin/src/daieditor/map/MapArchObject.java =================================================================== --- trunk/daimonin/src/daieditor/map/MapArchObject.java 2007-01-05 17:55:32 UTC (rev 1447) +++ trunk/daimonin/src/daieditor/map/MapArchObject.java 2007-01-05 18:00:17 UTC (rev 1448) @@ -284,7 +284,7 @@ while (!endReached && (line = reader.readLine()) != null) { line = line.trim(); - if (archflag) { // ARCH: found + if (archflag) { // we are inside the map arch if (msgflag) { // reading the map message: @@ -388,7 +388,7 @@ System.err.println("Unknown map arch attrib line:" + line); } } - } else { // ARCH: not found yet + } else { // looking for the map arch if (line.toLowerCase().regionMatches(0, "arch ", 0, 5) && line.toLowerCase().endsWith(" map")) { archflag = true; Modified: trunk/daimonin/src/daieditor/map/MapControl.java =================================================================== --- trunk/daimonin/src/daieditor/map/MapControl.java 2007-01-05 17:55:32 UTC (rev 1447) +++ trunk/daimonin/src/daieditor/map/MapControl.java 2007-01-05 18:00:17 UTC (rev 1448) @@ -70,8 +70,6 @@ */ private final CMainControl mainControl; - private final MapArchObject mapArch; - /** * model (= map data of this level). */ @@ -147,7 +145,6 @@ */ public MapControl(final CMainControl mainControl, final List<GameObject> objects, final MapArchObject maparch, final boolean isPickmap, final boolean createView) { this.mainControl = mainControl; - mapArch = maparch; activeEditType = 0; // start with no edit types (saves time) this.isPickmap = isPickmap; // is this a pickmap? // we create model (= data) @@ -280,16 +277,16 @@ // TODO: Rename because the filename is a URI now. public String getMapFileName() { - return mapArch.getFileName(); + return mapModel.getMapArchObject().getFileName(); } public void setMapFileName(final String fname) { if (mapViewFrame != null) { - final String title = fname + " [ " + mapArch.getMapDisplayName() + " ]"; + final String title = fname + " [ " + mapModel.getMapArchObject().getMapDisplayName() + " ]"; assert mapViewFrame != null; mapViewFrame.setTitle(title); } - mapArch.setFileName(fname); + mapModel.getMapArchObject().setFileName(fname); } /** @@ -310,7 +307,7 @@ // we need to link the full path & save the map at creation time // so the pickmap menu can handle it right try { - mapArch.setFileName(mapFile.getCanonicalPath()); + mapModel.getMapArchObject().setFileName(mapFile.getCanonicalPath()); } catch (final IOException e) { // TODO } @@ -645,8 +642,8 @@ isPickmap = pickmap; } - public MapArchObject getMapArch() { - return mapArch; + public MapArchObject getMapArchObject() { + return mapModel.getMapArchObject(); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2007-01-06 11:09:04
|
Revision: 1449 http://svn.sourceforge.net/gridarta/?rev=1449&view=rev Author: akirschbaum Date: 2007-01-06 03:09:04 -0800 (Sat, 06 Jan 2007) Log Message: ----------- Add missing message to cfeditor. Modified Paths: -------------- trunk/daimonin/src/daieditor/messages.properties trunk/src/app/net/sf/gridarta/messages.properties Modified: trunk/daimonin/src/daieditor/messages.properties =================================================================== --- trunk/daimonin/src/daieditor/messages.properties 2007-01-05 18:00:17 UTC (rev 1448) +++ trunk/daimonin/src/daieditor/messages.properties 2007-01-06 11:09:04 UTC (rev 1449) @@ -787,7 +787,6 @@ canonIOE=IOException while canonizing path: {0} exitWithExit=Exiting with System.exit(). exitWithoutExit=Trying to exit without System.exit(). -unexpectedException=Unexpected exception: {0} archfileNotFound=Archfile {0} could not be found faceObjectWithoutOriginalName=No originalName for {0}! duplicateAnimation=Duplicate Animation: {0} Modified: trunk/src/app/net/sf/gridarta/messages.properties =================================================================== --- trunk/src/app/net/sf/gridarta/messages.properties 2007-01-05 18:00:17 UTC (rev 1448) +++ trunk/src/app/net/sf/gridarta/messages.properties 2007-01-06 11:09:04 UTC (rev 1449) @@ -193,6 +193,7 @@ # Various Log Messages saveLevelAsWithNull=DEBUG: CMainControl.saveLevelAsWanted(CMapControl level) invoked with null argument. imageCreated=Created image "{0}" of map "{1}". +unexpectedException=Unexpected exception: {0} # Edit undo.text=Undo This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2007-01-06 15:12:47
|
Revision: 1459 http://svn.sourceforge.net/gridarta/?rev=1459&view=rev Author: akirschbaum Date: 2007-01-06 07:12:46 -0800 (Sat, 06 Jan 2007) Log Message: ----------- Add support for map arch object event listeners. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gui/map/MapPropertiesDialog.java trunk/crossfire/src/cfeditor/map/MapArchObject.java trunk/daimonin/src/daieditor/gui/map/MapPropertiesDialog.java trunk/daimonin/src/daieditor/map/MapArchObject.java trunk/src/app/net/sf/gridarta/map/AbstractMapArchObject.java trunk/src/app/net/sf/gridarta/map/MapArchObject.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/map/MapArchObjectListener.java Modified: trunk/crossfire/src/cfeditor/gui/map/MapPropertiesDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/map/MapPropertiesDialog.java 2007-01-06 14:41:31 UTC (rev 1458) +++ trunk/crossfire/src/cfeditor/gui/map/MapPropertiesDialog.java 2007-01-06 15:12:46 UTC (rev 1459) @@ -455,6 +455,7 @@ final MapArchObject map = mapControl.getMapArchObject(); mapControl.getMapModel().beginTransaction("Map properties"); // TODO: I18N/L10N + map.beginTransaction(); final String mapNameString = mapName.getText(); mapControl.getMapModel().resizeMap(mapSize); @@ -495,6 +496,7 @@ map.setTilePath(i, fieldTilePath[i].getText()); } + map.endTransaction(); mapControl.getMapModel().endTransaction(); mainControl.refreshMenusAndToolbars(); mapControl.notifyViews(); Modified: trunk/crossfire/src/cfeditor/map/MapArchObject.java =================================================================== --- trunk/crossfire/src/cfeditor/map/MapArchObject.java 2007-01-06 14:41:31 UTC (rev 1458) +++ trunk/crossfire/src/cfeditor/map/MapArchObject.java 2007-01-06 15:12:46 UTC (rev 1459) @@ -2,6 +2,7 @@ * Crossfire Java Editor. * Copyright (C) 2000 Michael Toennies * Copyright (C) 2001 Andreas Vogl + * Copyright (C) 2007 The Gridarta Developers * * (code based on: Gridder. 2D grid based level editor. (C) 2000 Pasi Keränen) * @@ -36,9 +37,10 @@ * the map-arch, at the very beginning of the map file. The map metadata is * information like mapSize, difficulty level, darkness etc.). * @author <a href="mailto:and...@gm...">Andreas Vogl</a> + * @author Andreas Kirschbaum */ @SuppressWarnings({"HardcodedLineSeparator"}) -public final class MapArchObject extends AbstractMapArchObject { +public final class MapArchObject extends AbstractMapArchObject<MapArchObject> { // tags which appear in the map header private static final String TAG_START_LORE = "maplore"; @@ -137,7 +139,12 @@ * @param unique whether this map should be unique */ public void setUnique(final boolean unique) { + if (this.unique == unique) { + return; + } + this.unique = unique; + setModified(); } public boolean isTemplate() { @@ -145,7 +152,12 @@ } public void setTemplate(final boolean template) { + if (this.template == template) { + return; + } + this.template = template; + setModified(); } public boolean isOutdoor() { @@ -153,7 +165,12 @@ } public void setOutdoor(final boolean outdoor) { + if (this.outdoor == outdoor) { + return; + } + this.outdoor = outdoor; + setModified(); } public boolean isNosmooth() { @@ -161,7 +178,12 @@ } public void setNosmooth(final boolean nosmooth) { + if (this.nosmooth == nosmooth) { + return; + } + this.nosmooth = nosmooth; + setModified(); } @NotNull public String getTilePath(final int direction) { @@ -169,7 +191,12 @@ } public void setTilePath(final int direction, @NotNull final String tilePath) { + if (tilePaths[direction].equals(tilePath)) { + return; + } + tilePaths[direction] = tilePath; + setModified(); } @NotNull public String getRegion() { @@ -177,7 +204,12 @@ } public void setRegion(@NotNull final String region) { + if (this.region.equals(region)) { + return; + } + this.region = region; + setModified(); } @NotNull public String getShopItems() { @@ -185,7 +217,12 @@ } public void setShopItems(@NotNull final String shopItems) { + if (this.shopItems.equals(shopItems)) { + return; + } + this.shopItems = shopItems; + setModified(); } @NotNull public String getShopRace() { @@ -193,7 +230,12 @@ } public void setShopRace(@NotNull final String shopRace) { + if (this.shopRace.equals(shopRace)) { + return; + } + this.shopRace = shopRace; + setModified(); } public int getShopMin() { @@ -201,7 +243,12 @@ } public void setShopMin(final int shopMin) { + if (this.shopMin == shopMin) { + return; + } + this.shopMin = shopMin; + setModified(); } public int getShopMax() { @@ -209,7 +256,12 @@ } public void setShopMax(final int shopMax) { + if (this.shopMax == shopMax) { + return; + } + this.shopMax = shopMax; + setModified(); } public double getShopGreed() { @@ -217,7 +269,12 @@ } public void setShopGreed(final double shopGreed) { + if (this.shopGreed == shopGreed) { + return; + } + this.shopGreed = shopGreed; + setModified(); } public int getTemp() { @@ -225,7 +282,12 @@ } public void setTemp(final int temp) { + if (this.temp == temp) { + return; + } + this.temp = temp; + setModified(); } public int getPressure() { @@ -233,7 +295,12 @@ } public void setPressure(final int pressure) { + if (this.pressure == pressure) { + return; + } + this.pressure = pressure; + setModified(); } public int getHumid() { @@ -241,7 +308,12 @@ } public void setHumid(final int humid) { + if (this.humid == humid) { + return; + } + this.humid = humid; + setModified(); } public int getWindspeed() { @@ -249,7 +321,12 @@ } public void setWindspeed(final int windspeed) { + if (this.windspeed == windspeed) { + return; + } + this.windspeed = windspeed; + setModified(); } public int getWinddir() { @@ -257,7 +334,12 @@ } public void setWinddir(final int winddir) { + if (this.winddir == winddir) { + return; + } + this.winddir = winddir; + setModified(); } public int getSky() { @@ -265,7 +347,12 @@ } public void setSky(final int sky) { + if (this.sky == sky) { + return; + } + this.sky = sky; + setModified(); } /** @@ -273,7 +360,12 @@ * @param text string to add */ public void addText(@NotNull final String text) { + if (text.equals("")) { + return; + } + msgText.append(text); + setModified(); } /** @@ -281,13 +373,23 @@ * @param text the new map text */ public void setText(final String text) { + if (msgText.toString().equals(text)) { + return; + } + msgText.delete(0, msgText.length()); msgText.append(text); + setModified(); } /** Delete maptext. */ public void resetText() { + if (msgText.length() == 0) { + return; + } + msgText.delete(0, msgText.length()); + setModified(); } /** @@ -299,12 +401,30 @@ } /** + * Append 'text' to the lore text. + * @param text string to add + */ + public void addLore(@NotNull final String text) { + if (text.equals("")) { + return; + } + + loreText.append(text); + setModified(); + } + + /** * Set 'text' = lore. * @param text string to set */ public void setLore(@NotNull final String text) { + if (loreText.toString().equals(text)) { + return; + } + loreText.delete(0, loreText.length()); loreText.append(text); + setModified(); } /** @@ -346,9 +466,9 @@ msgflag = false; } else { if (msgText.length() > 0) { - msgText.append('\n'); + addText("\n"); } - msgText.append(line2); + addText(line2); } } else if (loreflag) { // reading lore text: @@ -356,9 +476,9 @@ loreflag = false; } else { if (loreText.length() > 0) { - loreText.append("\n"); + addLore("\n"); } - loreText.append(line2); + addLore(line2); } } else { // inside map arch, outside message @@ -372,7 +492,7 @@ } else if (line.startsWith("name")) { setMapName(line.substring(line.indexOf(" ") + 1).trim()); } else if (line.startsWith("region")) { - region = line.substring(line.indexOf(" ") + 1).trim(); + setRegion(line.substring(line.indexOf(" ") + 1).trim()); } else if (line.startsWith("width") || line.startsWith("x ")) { width = getLineValue(line); } else if (line.startsWith("height") || line.startsWith("y ")) { @@ -399,48 +519,48 @@ } } else if (line.startsWith("template")) { if (getLineValue(line) != 0) { - template = true; + setTemplate(true); } } else if (line.startsWith("outdoor")) { if (getLineValue(line) != 0) { - outdoor = true; + setOutdoor(true); } } else if (line.startsWith("nosmooth")) { if (getLineValue(line) != 0) { - nosmooth = true; + setNosmooth(true); } } else if (line.startsWith("tile_path_")) { // get tile path try { final int i = Integer.valueOf(line.substring(10, 11)); if (i > 0 && i <= MAX_TILE && line.lastIndexOf(" ") > 0) { - tilePaths[i - 1] = line.substring(line.lastIndexOf(" ") + 1); + setTilePath(i - 1, line.substring(line.lastIndexOf(" ") + 1)); } } catch (final NumberFormatException e) { /* ignore (really?) */ } } else if (line.startsWith("shopitems")) { - shopItems = line.substring(line.indexOf(" ") + 1).trim(); + setShopItems(line.substring(line.indexOf(" ") + 1).trim()); } else if (line.startsWith("shoprace")) { - shopRace = line.substring(line.indexOf(" ") + 1).trim(); + setShopRace(line.substring(line.indexOf(" ") + 1).trim()); } else if (line.startsWith("shopmin")) { - shopMin = getLineValue(line); + setShopMin(getLineValue(line)); } else if (line.startsWith("shopmax")) { - shopMax = getLineValue(line); + setShopMax(getLineValue(line)); } else if (line.startsWith("shopgreed")) { - shopGreed = getLineValueAsDouble(line); + setShopGreed(getLineValueAsDouble(line)); } else if (line.startsWith("temp")) { - temp = getLineValue(line); + setTemp(getLineValue(line)); } else if (line.startsWith("pressure")) { - pressure = getLineValue(line); + setPressure(getLineValue(line)); } else if (line.startsWith("humid")) { - humid = getLineValue(line); + setHumid(getLineValue(line)); } else if (line.startsWith("windspeed")) { - windspeed = getLineValue(line); + setWindspeed(getLineValue(line)); } else if (line.startsWith("winddir")) { - winddir = getLineValue(line); + setWinddir(getLineValue(line)); } else if (line.startsWith("sky")) { - sky = getLineValue(line); + setSky(getLineValue(line)); } } } else { Modified: trunk/daimonin/src/daieditor/gui/map/MapPropertiesDialog.java =================================================================== --- trunk/daimonin/src/daieditor/gui/map/MapPropertiesDialog.java 2007-01-06 14:41:31 UTC (rev 1458) +++ trunk/daimonin/src/daieditor/gui/map/MapPropertiesDialog.java 2007-01-06 15:12:46 UTC (rev 1459) @@ -451,6 +451,8 @@ final MapArchObject map = mapControl.getMapArchObject(); + map.beginTransaction(); + final String mapNameString = mapName.getText() + (mapSound.getText().length() > 0 ? '§' + mapSound.getText() + "|0|-1" : ""); mapControl.getMapModel().resizeMap(mapSize); map.setText(mapDescription.getText()); @@ -478,6 +480,8 @@ mapTilePane.modifyMapProperties(); + map.endTransaction(); + return true; } Modified: trunk/daimonin/src/daieditor/map/MapArchObject.java =================================================================== --- trunk/daimonin/src/daieditor/map/MapArchObject.java 2007-01-06 14:41:31 UTC (rev 1458) +++ trunk/daimonin/src/daieditor/map/MapArchObject.java 2007-01-06 15:12:46 UTC (rev 1459) @@ -2,6 +2,7 @@ * Daimonin Java Editor. * Copyright (C) 2000 Michael Toennies * Copyright (C) 2001 Andreas Vogl + * Copyright (C) 2007 The Gridarta Developers * * (code based on: Gridder. 2D grid based level editor. (C) 2000 Pasi Keränen) * @@ -39,6 +40,7 @@ * information like mapSize, difficulty level, darkness etc.). * @author <a href="mailto:and...@gm...">Andreas Vogl</a> * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @author Andreas Kirschbaum * @note Though this class is named MapArchObject, it is <strong>not a subclass * of GameObject</strong>; the name is for technical reasons, not for semantic * / inheritance! @@ -46,7 +48,7 @@ * generic way like arch attributes. */ @SuppressWarnings({"HardcodedLineSeparator"}) -public final class MapArchObject extends AbstractMapArchObject implements Serializable { +public final class MapArchObject extends AbstractMapArchObject<MapArchObject> implements Serializable { /** Serial Version. */ private static final long serialVersionUID = 1L; @@ -140,7 +142,12 @@ } public void setOutdoor(final boolean outdoor) { + if (this.outdoor == outdoor) { + return; + } + this.outdoor = outdoor; + setModified(); } public String getTilePath(final int n) { @@ -148,7 +155,12 @@ } public void setTilePath(final int n, @Nullable final String tilePath) { + if (tilePaths[n] == null ? tilePath == null : tilePaths[n].equals(tilePath)) { + return; + } + tilePaths[n] = tilePath; + setModified(); } public boolean isNoSave() { @@ -156,7 +168,12 @@ } public void setNoSave(final boolean noSave) { + if (this.noSave == noSave) { + return; + } + this.noSave = noSave; + setModified(); } public boolean isNoMagic() { @@ -164,7 +181,12 @@ } public void setNoMagic(final boolean noMagic) { + if (this.noMagic == noMagic) { + return; + } + this.noMagic = noMagic; + setModified(); } public boolean isNoPriest() { @@ -172,7 +194,12 @@ } public void setNoPriest(final boolean noPriest) { + if (this.noPriest == noPriest) { + return; + } + this.noPriest = noPriest; + setModified(); } public boolean isNoSummon() { @@ -180,7 +207,12 @@ } public void setNoSummon(final boolean noSummon) { + if (this.noSummon == noSummon) { + return; + } + this.noSummon = noSummon; + setModified(); } public boolean isNoHarm() { @@ -188,7 +220,12 @@ } public void setNoHarm(final boolean noHarm) { + if (this.noHarm == noHarm) { + return; + } + this.noHarm = noHarm; + setModified(); } public boolean isFixedLogin() { @@ -196,7 +233,12 @@ } public void setFixedLogin(final boolean fixedLogin) { + if (this.fixedLogin == fixedLogin) { + return; + } + this.fixedLogin = fixedLogin; + setModified(); } public boolean isPermDeath() { @@ -204,7 +246,12 @@ } public void setPermDeath(final boolean permDeath) { + if (this.permDeath == permDeath) { + return; + } + this.permDeath = permDeath; + setModified(); } public boolean isUltraDeath() { @@ -212,7 +259,12 @@ } public void setUltraDeath(final boolean ultraDeath) { + if (this.ultraDeath == ultraDeath) { + return; + } + this.ultraDeath = ultraDeath; + setModified(); } public boolean isUltimateDeath() { @@ -220,7 +272,12 @@ } public void setUltimateDeath(final boolean ultimateDeath) { + if (this.ultimateDeath == ultimateDeath) { + return; + } + this.ultimateDeath = ultimateDeath; + setModified(); } public boolean isPvp() { @@ -228,15 +285,64 @@ } public void setPvp(final boolean pvp) { + if (this.pvp == pvp) { + return; + } + this.pvp = pvp; + setModified(); } + public int getTilesetId() { + return tilesetId; + } + + public void setTilesetId(final int tilesetId) { + if (this.tilesetId == tilesetId) { + return; + } + + this.tilesetId = tilesetId; + setModified(); + } + + public int getTilesetX() { + return tilesetX; + } + + public void setTilesetX(final int tilesetX) { + if (this.tilesetX == tilesetX) { + return; + } + + this.tilesetX = tilesetX; + setModified(); + } + + public int getTilesetY() { + return tilesetY; + } + + public void setTilesetY(final int tilesetY) { + if (this.tilesetY == tilesetY) { + return; + } + + this.tilesetY = tilesetY; + setModified(); + } + /** * Append 'text' to the map text. * @param text string to add */ public void addText(@NotNull final String text) { + if (text.equals("")) { + return; + } + msgText.append(text); + setModified(); } /** @@ -244,13 +350,23 @@ * @param text the new map text */ public void setText(final String text) { + if (msgText.toString().equals(text)) { + return; + } + msgText.delete(0, msgText.length()); msgText.append(text); + setModified(); } /** Delete maptext. */ public void resetText() { + if (msgText.length() == 0) { + return; + } + msgText.delete(0, msgText.length()); + setModified(); } /** @@ -292,9 +408,9 @@ msgflag = false; } else { if (msgText.length() > 0) { - msgText.append('\n'); + addText("\n"); } - msgText.append(line); + addText(line); } } else { // inside map arch, outside message @@ -326,64 +442,64 @@ } } else if (line.startsWith("outdoor ")) { if (getLineValue(line) != 0) { - outdoor = true; + setOutdoor(true); } } else if (line.startsWith("tile_path_")) { // get tile path try { final int i = Integer.valueOf(line.substring(10, 11)); if (i > 0 && i < 9 && line.lastIndexOf(" ") > 0) { - tilePaths[i - 1] = line.substring(line.lastIndexOf(" ") + 1); + setTilePath(i - 1, line.substring(line.lastIndexOf(" ") + 1)); } } catch (final NumberFormatException e) { /* ignore (really?) */ } } else if (line.startsWith("no_save")) { if (getLineValue(line) != 0) { - noSave = true; + setNoSave(true); } } else if (line.startsWith("no_magic")) { if (getLineValue(line) != 0) { - noMagic = true; + setNoMagic(true); } } else if (line.startsWith("no_priest")) { if (getLineValue(line) != 0) { - noPriest = true; + setNoPriest(true); } } else if (line.startsWith("no_summon")) { if (getLineValue(line) != 0) { - noSummon = true; + setNoSummon(true); } } else if (line.startsWith("no_harm")) { if (getLineValue(line) != 0) { - noHarm = true; + setNoHarm(true); } } else if (line.startsWith("fixed_login")) { if (getLineValue(line) != 0) { - fixedLogin = true; + setFixedLogin(true); } } else if (line.startsWith("perm_death")) { if (getLineValue(line) != 0) { - permDeath = true; + setPermDeath(true); } } else if (line.startsWith("ultra_death")) { if (getLineValue(line) != 0) { - ultraDeath = true; + setUltraDeath(true); } } else if (line.startsWith("ultimate_death")) { if (getLineValue(line) != 0) { - ultimateDeath = true; + setUltimateDeath(true); } } else if (line.startsWith("pvp")) { if (getLineValue(line) != 0) { - pvp = true; + setPvp(true); } } else if (line.startsWith("tileset_id")) { - tilesetId = getLineValue(line); + setTilesetId(getLineValue(line)); } else if (line.startsWith("tileset_x")) { - tilesetX = getLineValue(line); + setTilesetX(getLineValue(line)); } else if (line.startsWith("tileset_y")) { - tilesetY = getLineValue(line); + setTilesetY(getLineValue(line)); } else { System.err.println("Unknown map arch attrib line:" + line); } Modified: trunk/src/app/net/sf/gridarta/map/AbstractMapArchObject.java =================================================================== --- trunk/src/app/net/sf/gridarta/map/AbstractMapArchObject.java 2007-01-06 14:41:31 UTC (rev 1458) +++ trunk/src/app/net/sf/gridarta/map/AbstractMapArchObject.java 2007-01-06 15:12:46 UTC (rev 1459) @@ -1,13 +1,36 @@ +/* + * Gridarta Map Editor. + * Copyright (C) 2007 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., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + package net.sf.gridarta.map; +import javax.swing.event.EventListenerList; import net.sf.gridarta.Size2D; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * Base implementation of {@link MapArchObject} that covers similarities between Crossfire maps and Daimonin maps. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @author Andreas Kirschbaum */ -public abstract class AbstractMapArchObject implements MapArchObject { +public abstract class AbstractMapArchObject<M extends MapArchObject<M>> implements MapArchObject<M> { /** Name of an unnamed map. */ @NotNull public static final String MAP_NAME_UNNAMED = "<unnamed>"; @@ -53,7 +76,34 @@ */ private int darkness; + /** The registered event listeners. */ + private EventListenerList listenerList = new EventListenerList(); + /** + * The transaction depth. + * A value of 0 means there's no transaction going on. + * A value > 0 means there's a transaction going on and denotes the nesting level. + * @invariant transactionDepth >= 0 + */ + private int transactionDepth = 0; + + /** + * The thread that performs the current transaction. + * @invariant transactionDepth > 0 || transactionThread == null + */ + @Nullable private Thread transactionThread; + + /** + * Set if any attribute has changed since last saving. + */ + private boolean modified = false; + + /** + * Set if {@link #modified} has changed inside the current transactions. + */ + private boolean modifiedHasChanged = false; + + /** * Create an AbstractMapArchObject. */ protected AbstractMapArchObject() { @@ -66,7 +116,12 @@ /** {@inheritDoc} */ public final void setMapSize(@NotNull final Size2D mapSize) { + if (this.mapSize.equals(mapSize)) { + return; + } + this.mapSize = mapSize; + setModified(); } /** {@inheritDoc} */ @@ -76,7 +131,12 @@ /** {@inheritDoc} */ public final void setMapName(@NotNull final String name) { + if (this.mapName.equals(name)) { + return; + } + this.mapName = name; + setModified(); } /** {@inheritDoc} */ @@ -87,7 +147,12 @@ /** {@inheritDoc} */ public final void setFileName(@NotNull final String fileName) { + if (this.fileName.equals(fileName)) { + return; + } + this.fileName = fileName; + setModified(); } /** {@inheritDoc} */ @@ -97,7 +162,12 @@ /** {@inheritDoc} */ public final void setEnterX(final int enterX) { + if (this.enterX == enterX) { + return; + } + this.enterX = enterX; + setModified(); } /** {@inheritDoc} */ @@ -107,7 +177,12 @@ /** {@inheritDoc} */ public final void setEnterY(final int enterY) { + if (this.enterY == enterY) { + return; + } + this.enterY = enterY; + setModified(); } /** {@inheritDoc} */ @@ -117,7 +192,12 @@ /** {@inheritDoc} */ public void setResetTimeout(final int resetTimeout) { + if (this.resetTimeout == resetTimeout) { + return; + } + this.resetTimeout = resetTimeout; + setModified(); } /** {@inheritDoc} */ @@ -127,7 +207,12 @@ /** {@inheritDoc} */ public void setSwapTime(final int swapTime) { + if (this.swapTime == swapTime) { + return; + } + this.swapTime = swapTime; + setModified(); } /** {@inheritDoc} */ @@ -137,7 +222,12 @@ /** {@inheritDoc} */ public void setDifficulty(final int difficulty) { + if (this.difficulty == (difficulty < 1 ? 1 : difficulty)) { + return; + } + this.difficulty = difficulty < 1 ? 1 : difficulty; + setModified(); } /** {@inheritDoc} */ @@ -147,7 +237,12 @@ /** {@inheritDoc} */ public void setFixedReset(final boolean fixedReset) { + if (this.fixedReset == fixedReset) { + return; + } + this.fixedReset = fixedReset; + setModified(); } /** {@inheritDoc} */ @@ -157,7 +252,101 @@ /** {@inheritDoc} */ public void setDarkness(final int darkness) { + if (this.darkness == darkness) { + return; + } + this.darkness = darkness; + setModified(); } + /** {@inheritDoc} */ + public void addMapArchObjectListener(@NotNull final MapArchObjectListener<M> listener) { + listenerList.add(MapArchObjectListener.class, listener); + } + + /** {@inheritDoc} */ + public void removeMapArchObjectListener(@NotNull final MapArchObjectListener<M> listener) { + listenerList.remove(MapArchObjectListener.class, listener); + } + + /** + * Method to notify the map arch object that it has changed. The map arch + * object then notifies the registered listeners of the change at the end + * of the transaction. + */ + protected void setModified() { + if (!modified) { + modified = true; + modifiedHasChanged = true; + } + } + + /** {@inheritDoc} */ + public void resetModified() { + if (modified) { + modified = false; + modifiedHasChanged = true; + } + } + + /** {@inheritDoc} */ + public final void beginTransaction() { + if (transactionDepth == 0) { + modifiedHasChanged = false; + transactionThread = Thread.currentThread(); + } else { + // == is okay for threads. + //noinspection ObjectEquality + if (transactionThread != Thread.currentThread()) { + throw new IllegalStateException("A transaction must only be used by one thread."); + } + } + transactionDepth++; + } + + /** {@inheritDoc} */ + public final void endTransaction() { + endTransaction(false); + } + + /** {@inheritDoc} */ + public final void endTransaction(final boolean fireEvent) { + if (transactionDepth <= 0) { + throw new IllegalStateException("Tried to end a transaction but no transaction was open."); + } + transactionDepth--; + assert transactionDepth >= 0; + if (transactionDepth == 0) { + commitTransaction(); + } else if (fireEvent && transactionDepth > 0) { + if (modifiedHasChanged) { + fireModifiedChangedEvent(); + } + } + } + + /** + * Performs ending a transaction. + * Resets all transaction states and fires an event. + */ + private void commitTransaction() { + transactionDepth = 0; + transactionThread = null; + if (modifiedHasChanged) { + fireModifiedChangedEvent(); + modifiedHasChanged = false; + } + } + + /** + * Fire a MapSquaresChangedEvent. + * @param squares Squares to fire event for + */ + private void fireModifiedChangedEvent() { + for (final MapArchObjectListener listener : listenerList.getListeners(MapArchObjectListener.class)) { + listener.modifiedChanged(this); + } + } + } // class AbstractMapArchObject Modified: trunk/src/app/net/sf/gridarta/map/MapArchObject.java =================================================================== --- trunk/src/app/net/sf/gridarta/map/MapArchObject.java 2007-01-06 14:41:31 UTC (rev 1458) +++ trunk/src/app/net/sf/gridarta/map/MapArchObject.java 2007-01-06 15:12:46 UTC (rev 1459) @@ -1,3 +1,23 @@ +/* + * Gridarta Map Editor. + * Copyright (C) 2007 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., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + package net.sf.gridarta.map; import java.io.BufferedReader; @@ -10,8 +30,9 @@ * <h4>Enter coordinates</h4> * Enter coordinates ({@link #getEnterX()}, {@link #setEnterX(int)}, {@link #getEnterY()}, {@link #setEnterY(int)}) determines where a player enters this map from another map when using an exit. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @author Andreas Kirschbaum */ -public interface MapArchObject { +public interface MapArchObject<M extends MapArchObject<M>> { /** String which starts the message section. */ String TAG_START_TEXT = "msg"; @@ -173,4 +194,70 @@ */ void writeMapArch(final Appendable appendable) throws IOException; + /** + * Register an event listener. + * @param listener MapArchObjectListener to register + */ + void addMapArchObjectListener(@NotNull MapArchObjectListener<M> listener); + + /** + * Unregister an event listener. + * @param listener MapArchObjectListener to unregsiter + */ + void removeMapArchObjectListener(@NotNull MapArchObjectListener<M> listener); + + /** + * Mark the map arch object as not modified from its initial state. + */ + void resetModified(); + + /** + * Start a new transaction. + * Transactions may be nested. + * Transactions serve the purpose of firing events to the views when more changes are known to come before the view is really required to update. + * Each invocation of {@link #beginTransaction()} requires its own invocation of {@link #endTransaction()}. + * <p /> + * Beginning a nested transaction is a cheap operation. + * @see #beginTransaction() + * @see #endTransaction() + * @see #endTransaction(boolean) + */ + void beginTransaction(); + + /** + * End a transaction. + * Invoking this method will reduce the transaction depth by only 1. + * <p /> + * Ending a nested operation is a cheap operation. + * Ending a transaction without changes also is a cheap operation. + * <p /> + * If the last transaction is ended, the changes are committed. + * <p /> + * Same as {@link #endTransaction(boolean) endTransaction(false)}. + * @see #beginTransaction() + * @see #endTransaction() + * @see #endTransaction(boolean) + */ + void endTransaction(); + + /** + * End a transaction. + * Invoking this method will reduce the transaction depth by only 1. + * <p /> + * Ending a nested operation is a cheap operation. + * Ending a transaction without changes also is a cheap operation. + * <p /> + * If the last transaction is ended, the changes are committed. + * <p /> + * An example where setting <var>fireEvent</var> to <code>true</code> is useful even though the outermost transaction is not ended is when during painting the UI should be updated though painting is not finnished. + * @param fireEvent <code>true</code> if an event should be fired even in case this doesn't end the outermost transaction. + * @note If the outermost transaction is ended, <var>fireEvent</var> is ignored and the event is always fired. + * @note An event is never fired when there were no changes, no matter whether the outermost transaction is ended or <var>fireEvent</var> is set to <code>true</code>. + * @note If the event is fired, the internal change list is not cleared. + * @see #beginTransaction() + * @see #endTransaction() + * @see #endTransaction(boolean) + */ + void endTransaction(boolean fireEvent); + } // interface MapArchObject Added: trunk/src/app/net/sf/gridarta/map/MapArchObjectListener.java =================================================================== --- trunk/src/app/net/sf/gridarta/map/MapArchObjectListener.java (rev 0) +++ trunk/src/app/net/sf/gridarta/map/MapArchObjectListener.java 2007-01-06 15:12:46 UTC (rev 1459) @@ -0,0 +1,40 @@ +/* + * Gridarta Map Editor. + * Copyright (C) 2007 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., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +package net.sf.gridarta.map; + +import java.util.EventListener; +import org.jetbrains.annotations.NotNull; + +/** + * Interface for listeners listening on map arch object changes. + * + * @author Andreas Kirschbaum + */ +public interface MapArchObjectListener<M extends MapArchObject> extends EventListener { + + /** + * The modified state has changed. + * + * @param mapArchObject the map arch object that has changed + */ + void modifiedChanged(@NotNull M mapArchObject); + +} // interface MapArchObjectListener Property changes on: trunk/src/app/net/sf/gridarta/map/MapArchObjectListener.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: 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...> - 2007-01-06 20:58:21
|
Revision: 1461 http://svn.sourceforge.net/gridarta/?rev=1461&view=rev Author: akirschbaum Date: 2007-01-06 12:58:22 -0800 (Sat, 06 Jan 2007) Log Message: ----------- Use callbacks to reflect model changes into map window title. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/CMapViewBasic.java trunk/crossfire/src/cfeditor/MapViewIFrame.java trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java trunk/crossfire/src/cfeditor/gui/GameObjectAttributesPanel.java trunk/crossfire/src/cfeditor/gui/MapView.java trunk/crossfire/src/cfeditor/gui/PickmapChooser.java trunk/crossfire/src/cfeditor/gui/map/DefaultLevelRenderer.java trunk/crossfire/src/cfeditor/gui/map/MapPropertiesDialog.java trunk/crossfire/src/cfeditor/gui/selectedsquare/SelectedSquareControl.java trunk/crossfire/src/cfeditor/gui/selectedsquare/SelectedSquareView.java trunk/crossfire/src/cfeditor/map/DefaultMapModel.java trunk/crossfire/src/cfeditor/map/MapControl.java trunk/crossfire/src/cfeditor/map/MapModel.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/CMainView.java trunk/daimonin/src/daieditor/CMapViewBasic.java trunk/daimonin/src/daieditor/MapViewIFrame.java trunk/daimonin/src/daieditor/gui/PickmapChooser.java trunk/daimonin/src/daieditor/gui/selectedsquare/SelectedSquareView.java trunk/daimonin/src/daieditor/map/MapControl.java trunk/src/app/net/sf/gridarta/gui/AbstractGameObjectAttributesDialog.java trunk/src/app/net/sf/gridarta/gui/connectionview/ConnectionView.java trunk/src/app/net/sf/gridarta/map/AbstractMapArchObject.java trunk/src/app/net/sf/gridarta/map/AbstractMapModel.java trunk/src/app/net/sf/gridarta/map/MapArchObjectListener.java trunk/src/app/net/sf/gridarta/map/MapControl.java trunk/src/app/net/sf/gridarta/map/MapModel.java trunk/src/app/net/sf/gridarta/map/MapModelListener.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/map/AbstractMapControl.java trunk/src/app/net/sf/gridarta/map/MapControlListener.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2007-01-06 19:58:22 UTC (rev 1460) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2007-01-06 20:58:22 UTC (rev 1461) @@ -782,7 +782,7 @@ ACTION_FACTORY.showMessageDialog(mainView, "closePickmapNoPickmaps"); } else { // if pickmap was modified, ask for confirmation: - if (!activePickmap.isLevelChanged() || ACTION_FACTORY.showQuestionDialog(mainView, "confirmClosePickmap", activePickmap.getMapFileName())) { + if (!activePickmap.isModified() || ACTION_FACTORY.showQuestionDialog(mainView, "confirmClosePickmap", activePickmap.getMapFileName())) { final File pickmapFile = activePickmap.getMapFile(); // close pickmap closeLevel(activePickmap, true); @@ -819,7 +819,7 @@ return false; } - if (!forced && level.isLevelChanged()) { + if (!forced && level.isModified()) { final int result = ACTION_FACTORY.showConfirmDialog(mainView, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, "confirmSaveChanges", level.getMapArchObject().getMapDisplayName()); if (result == JOptionPane.YES_OPTION) { if (level.isPlainSaveEnabled()) { @@ -990,7 +990,7 @@ // finally, show the map and refresh toolbars currentMap.setMapFile(file); currentMap.setActiveEditType(tileEdit); // map is loaded with current view settings - currentMap.getMapModel().resetLevelChangedFlag(); + currentMap.resetModified(); refreshMenusAndToolbars(); } @@ -1568,7 +1568,7 @@ if (activePickmap == null) { ACTION_FACTORY.showMessageDialog(mainView, "revertPickmapNoPickmaps"); } else { - if (!activePickmap.isLevelChanged() || ACTION_FACTORY.showQuestionDialog(mainView, "confirmRevertPickmap", activePickmap.getMapFileName())) { + if (!activePickmap.isModified() || ACTION_FACTORY.showQuestionDialog(mainView, "confirmRevertPickmap", activePickmap.getMapFileName())) { final File mfile = activePickmap.getMapFile(); // store file if (!mfile.exists()) { ACTION_FACTORY.showMessageDialog(mainView, "revertPickmapGone", activePickmap.getMapFileName()); @@ -1630,7 +1630,7 @@ * @return true if a level is being edited or false if not */ boolean isLevelEdited() { - return currentMap != null && currentMap.isLevelChanged(); + return currentMap != null && currentMap.isModified(); } /** Modified: trunk/crossfire/src/cfeditor/CMapViewBasic.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapViewBasic.java 2007-01-06 19:58:22 UTC (rev 1460) +++ trunk/crossfire/src/cfeditor/CMapViewBasic.java 2007-01-06 20:58:22 UTC (rev 1461) @@ -27,6 +27,7 @@ import cfeditor.gameobject.GameObject; import cfeditor.gui.MapView; import cfeditor.gui.map.DefaultLevelRenderer; +import cfeditor.map.MapArchObject; import cfeditor.map.MapControl; import cfeditor.map.MapModel; import java.awt.Point; @@ -79,7 +80,7 @@ * @author <a href="mailto:mic...@no...">Michael Toennies</a> * @author <a href="mailto:and...@gm...">Andreas Vogl</a> */ -public final class CMapViewBasic extends JScrollPane implements MapModelListener, MapCursorListener { +public final class CMapViewBasic extends JScrollPane implements MapModelListener<GameObject, MapArchObject>, MapCursorListener { private static final Logger log = Logger.getLogger(CMapViewBasic.class); @@ -101,8 +102,6 @@ /** The tile palette renderer. */ private final DefaultLevelRenderer renderer; - private boolean changed = false; - private boolean gridVisible = false; @NotNull private final MapCursor mapCursor; @@ -172,14 +171,6 @@ setFocusable(true); } - public boolean isChanged() { - return changed; - } - - public void setChangedFlag(final boolean state) { - changed = state; - } - /** * Get MapGrid of this view. * @return MapGrid of this view. @@ -285,7 +276,6 @@ /** Refreshes the data in the view from the model. */ void refreshDataFromModel() { log.debug("refreshDataFromModel"); - changedFlagNotify(); renderer.modelChanged(); } @@ -293,12 +283,6 @@ renderer.modelChanged(); } - /** Notifies that the level changed flag has been changed. */ - void changedFlagNotify() { - changed = mapControl.isLevelChanged(); - frame.updateTitle(); - } - /** * Get whether a selection exists. * @return <code>true</code> if a selection exists, otherwise <code>false</code> @@ -371,7 +355,6 @@ /** {@inheritDoc} */ @Override public void mousePressed(final MouseEvent e) { requestFocus(); - changedFlagNotify(); // set flag: map has changed final Point clickPoint = e.getPoint(); final Point mapLoc = renderer.getTileLocationAt(clickPoint, null); previewRect = null; @@ -446,8 +429,6 @@ /** {@inheritDoc} */ public void mouseDragged(final MouseEvent e) { - changedFlagNotify(); - final Point dragPoint = e.getPoint(); // Mouse pointer final Point temp = renderer.getTileLocationAt(dragPoint, null); // tile under Mouse pointer @@ -625,7 +606,7 @@ } /** {@inheritDoc} */ - public void mapMetaChanged(final MapModelEvent e) { + public void mapMetaChanged(final MapArchObject mapArchObject) { // ignore } Modified: trunk/crossfire/src/cfeditor/MapViewIFrame.java =================================================================== --- trunk/crossfire/src/cfeditor/MapViewIFrame.java 2007-01-06 19:58:22 UTC (rev 1460) +++ trunk/crossfire/src/cfeditor/MapViewIFrame.java 2007-01-06 20:58:22 UTC (rev 1461) @@ -24,6 +24,7 @@ package cfeditor; +import cfeditor.gameobject.GameObject; import cfeditor.gui.MapView; import cfeditor.map.MapControl; import java.awt.BorderLayout; @@ -38,6 +39,10 @@ import static javax.swing.KeyStroke.getKeyStroke; import net.sf.gridarta.gui.map.MapCursorListener; import net.sf.gridarta.gui.map.MapGridListener; +import net.sf.gridarta.map.MapArchObject; +import net.sf.gridarta.map.MapControlListener; +import net.sf.gridarta.map.MapModelEvent; +import net.sf.gridarta.map.MapModelListener; import net.sf.japi.swing.ActionFactory; import org.jetbrains.annotations.NotNull; @@ -69,6 +74,47 @@ private final CMapViewBasic view; /** + * The {@link MapModelListener} used to detect changes in the map model + * that should be reflected in the window title. + */ + private final MapModelListener<GameObject, MapArchObject> mapModelListener = new MapModelListener<GameObject, MapArchObject>() { + + /** {@inheritDoc} */ + public void mapSizeChanged(final MapModelEvent e) { + // ignore + } + + /** {@inheritDoc} */ + public void mapSquaresChanged(final MapModelEvent e) { + // ignore + } + + /** {@inheritDoc} */ + public void mapObjectsChanged(final MapModelEvent e) { + // ignore + } + + /** {@inheritDoc} */ + public void mapMetaChanged(final MapArchObject mapArchObject) { + updateTitle(); + } + + }; + + /** + * The {@link MapControlListener} used to detect changes in the map control + * that should be reflected in the window title. + */ + private final MapControlListener<MapControl> mapControlListener = new MapControlListener<MapControl>() { + + /** {@inheritDoc} */ + public void modifiedChanged(@NotNull final MapControl mapControl) { + updateTitle(); + } + + }; + + /** * Constructs a level view. * @param mainControl the main controller * @param mapControl the controller of this view @@ -77,7 +123,7 @@ */ public MapViewIFrame(final CMainControl mainControl, final MapControl mapControl, final Point initial) { // set title - super("Map [" + mapControl.getMapFileName() + "]", true, true, true, true); + super(mapControl.getMapFileName() + " [ " + mapControl.getMapArchObject().getMapDisplayName() + " ]" + (mapControl.isModified() ? " *" : ""), true, true, true, true); this.mapControl = mapControl; this.mainControl = mainControl; @@ -88,9 +134,20 @@ getContentPane().setLayout(new BorderLayout()); getContentPane().add(view, BorderLayout.CENTER); setJMenuBar(ACTION_FACTORY.createMenuBar(true, "mapwindow")); + + mapControl.addMapControlListener(mapControlListener); + mapControl.addMapModelListener(mapModelListener); } /** + * This function must be called when the view is closed. + */ + public void closeNotify() { + mapControl.removeMapControlListener(mapControlListener); + mapControl.removeMapModelListener(mapModelListener); + } + + /** * Okay, this is a bit of a hack. True seperation of mapview and * frame-component would really mess up the code, or maybe make it * "cleaner" but blow things up tenfold. @@ -101,14 +158,14 @@ } /** Update the Map-Window Title (according to name and changeFlag). */ - public void updateTitle() { - String strTitle = "Map [" + mapControl.getMapFileName() + "]"; + private void updateTitle() { + setTitle(mapControl.getMapFileName() + " [ " + mapControl.getMapArchObject().getMapDisplayName() + " ]" + (mapControl.isModified() ? " *" : "")); - if (view != null && view.isChanged()) { - strTitle += "*"; // * map has changed + // disable menu file->revert to revert the map + // XXX: should not be here + if (mainControl.getCurrentMap() == mapControl) { + mainControl.getMainView().setRevertMenuEnabled(mapControl.isModified()); } - - setTitle(strTitle); // display new title } // following a bunch of wrapper methods which just pass access @@ -168,10 +225,6 @@ view.modelChanged(); } - public void changedFlagNotify() { - view.changedFlagNotify(); - } - /** * Return the Action for selecting this window. * @return the Action for selecting this window Modified: trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java 2007-01-06 19:58:22 UTC (rev 1460) +++ trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java 2007-01-06 20:58:22 UTC (rev 1461) @@ -452,14 +452,6 @@ } } - // if the archtext changed, set the map changed flag - if ((oldArchText != null && !oldArchText.equals(gameObject.getObjectText())) || - (oldArchText == null && gameObject.getObjectText() != null) || - (oldMsg != null && !oldMsg.equals(gameObject.getMsgText())) || - (oldMsg == null && gameObject.getMsgText() != null)) { - ((CMainControl) mainControl).getCurrentMap().setLevelChangedFlag(); - } - // recalculate the editType value gameObject.calculateEditType(((CMainControl) mainControl).getCurrentMap().getActiveEditType()); @@ -467,9 +459,4 @@ return true; // apply succeeded } - /** Notify of changes. */ - @Override protected void changeNotify() { - ((CMainControl) mainControl).getCurrentMap().setLevelChangedFlag(); - } - } // class GameObjectAttributesDialog Modified: trunk/crossfire/src/cfeditor/gui/GameObjectAttributesPanel.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/GameObjectAttributesPanel.java 2007-01-06 19:58:22 UTC (rev 1460) +++ trunk/crossfire/src/cfeditor/gui/GameObjectAttributesPanel.java 2007-01-06 20:58:22 UTC (rev 1461) @@ -282,13 +282,8 @@ mainControl.getArchetypeParser().postParseGameObject(invnew, 0); inv.addLast(invnew); - mainControl.getCurrentMap().setLevelChangedFlag(); // the map has been modified } - public void updateMapTileList() { - mainControl.getCurrentMap().setLevelChangedFlag(); // the map has been modified - } - /** * When the "apply"-button on the ArchPanel (at the bottom of the window) * is pressed, this function updates the active arch object. @@ -422,20 +417,10 @@ // Recalculate the editType value. It shall stay 100% accurate ;) gameObject.calculateEditType(mainControl.getCurrentMap().getActiveEditType()); - // if the archtext changed, set the map changed flag - if ((oldArchText != null && !oldArchText.equals(gameObject.getObjectText())) || - (oldArchText == null && gameObject.getObjectText() != null) || - (oldMsg != null && !oldMsg.equals(gameObject.getMsgText())) || - (oldMsg == null && gameObject.getMsgText() != null)) { - mainControl.getCurrentMap().setLevelChangedFlag(); - } - // there we go!!!!! // now here will be the special panels added! refresh(); - updateMapTileList(); - // if needed (due to face changes), we also redraw the map if (needRedraw) { mainControl.getCurrentMap().repaint(); Modified: trunk/crossfire/src/cfeditor/gui/MapView.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/MapView.java 2007-01-06 19:58:22 UTC (rev 1460) +++ trunk/crossfire/src/cfeditor/gui/MapView.java 2007-01-06 20:58:22 UTC (rev 1461) @@ -34,7 +34,4 @@ */ public interface MapView { - /** Update the title on the frame. */ - void updateTitle(); - } // interface MapView Modified: trunk/crossfire/src/cfeditor/gui/PickmapChooser.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/PickmapChooser.java 2007-01-06 19:58:22 UTC (rev 1460) +++ trunk/crossfire/src/cfeditor/gui/PickmapChooser.java 2007-01-06 20:58:22 UTC (rev 1461) @@ -235,7 +235,7 @@ pickmaps.put(mapFile.getName(), mapControl); currentPickMap = mapControl; - mapControl.getMapModel().resetLevelChangedFlag(); + mapControl.resetModified(); return mapControl.getMapViewFrame().getBasicView(); } Modified: trunk/crossfire/src/cfeditor/gui/map/DefaultLevelRenderer.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/map/DefaultLevelRenderer.java 2007-01-06 19:58:22 UTC (rev 1460) +++ trunk/crossfire/src/cfeditor/gui/map/DefaultLevelRenderer.java 2007-01-06 20:58:22 UTC (rev 1461) @@ -29,6 +29,7 @@ import cfeditor.CMapViewBasic; import cfeditor.gameobject.ArchetypeSet; import cfeditor.gameobject.GameObject; +import cfeditor.map.MapArchObject; import cfeditor.map.MapControl; import cfeditor.map.MapModel; import java.awt.Color; @@ -57,7 +58,7 @@ * @author unknown * @author Andreas Kirschbaum */ -public final class DefaultLevelRenderer extends LevelRenderer implements MapGridListener, MapModelListener { +public final class DefaultLevelRenderer extends LevelRenderer implements MapGridListener, MapModelListener<GameObject, MapArchObject> { private static final Logger log = Logger.getLogger(DefaultLevelRenderer.class); @@ -414,7 +415,7 @@ } /** {@inheritDoc} */ - public void mapMetaChanged(final MapModelEvent e) { + public void mapMetaChanged(final MapArchObject mapArchObject) { // ignore } Modified: trunk/crossfire/src/cfeditor/gui/map/MapPropertiesDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/map/MapPropertiesDialog.java 2007-01-06 19:58:22 UTC (rev 1460) +++ trunk/crossfire/src/cfeditor/gui/map/MapPropertiesDialog.java 2007-01-06 20:58:22 UTC (rev 1461) @@ -501,9 +501,6 @@ mainControl.refreshMenusAndToolbars(); mapControl.notifyViews(); - // set flag that map has changed - mapControl.setLevelChangedFlag(); - return true; } Modified: trunk/crossfire/src/cfeditor/gui/selectedsquare/SelectedSquareControl.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/selectedsquare/SelectedSquareControl.java 2007-01-06 19:58:22 UTC (rev 1460) +++ trunk/crossfire/src/cfeditor/gui/selectedsquare/SelectedSquareControl.java 2007-01-06 20:58:22 UTC (rev 1461) @@ -254,9 +254,6 @@ } view.setSelectedGameObject(insertedGameObject); currentMapControl.getMapModel().endTransaction(); - - // refresh - currentMapControl.setLevelChangedFlag(); // the map has been modified } /** Modified: trunk/crossfire/src/cfeditor/gui/selectedsquare/SelectedSquareView.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/selectedsquare/SelectedSquareView.java 2007-01-06 19:58:22 UTC (rev 1460) +++ trunk/crossfire/src/cfeditor/gui/selectedsquare/SelectedSquareView.java 2007-01-06 20:58:22 UTC (rev 1461) @@ -49,6 +49,7 @@ import net.sf.gridarta.gui.map.MapCursorListener; import net.sf.gridarta.gui.maptilelist.MapTileSelection; import net.sf.gridarta.gui.maptilelist.MapTileSelectionCache; +import net.sf.gridarta.map.MapArchObject; import net.sf.gridarta.map.MapModelEvent; import net.sf.gridarta.map.MapModelListener; import net.sf.gridarta.map.MapSquare; @@ -64,7 +65,7 @@ * @author <a href="mailto:and...@gm...">Andreas Vogl</a> * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ -public final class SelectedSquareView extends JPanel implements MainControlListener<MapControl>, MapCursorListener, MapModelListener<GameObject> { +public final class SelectedSquareView extends JPanel implements MainControlListener<MapControl>, MapCursorListener, MapModelListener<GameObject, MapArchObject> { /** Serial Version UID. */ private static final long serialVersionUID = 1L; @@ -389,7 +390,7 @@ } /** {@inheritDoc} */ - public void mapMetaChanged(final MapModelEvent e) { + public void mapMetaChanged(final MapArchObject mapArchObject) { // ignore } Modified: trunk/crossfire/src/cfeditor/map/DefaultMapModel.java =================================================================== --- trunk/crossfire/src/cfeditor/map/DefaultMapModel.java 2007-01-06 19:58:22 UTC (rev 1460) +++ trunk/crossfire/src/cfeditor/map/DefaultMapModel.java 2007-01-06 20:58:22 UTC (rev 1461) @@ -50,9 +50,6 @@ /** Logger. */ private static final Logger log = Logger.getLogger(DefaultMapModel.class); - /** Flag that indicates if the level has been changed since last save. */ - private boolean levelChanged = false; - /** * The CMainControl used for various operations. * @deprecated it's not a good idea to require the MapModel implementation to know such a heavy-weight strongly UI-related glue class like {@link CMainControl}. @@ -84,55 +81,6 @@ } /** - * Reset the level changed flag to false. - */ - public void resetLevelChangedFlag() { - if (!levelChanged) { - return; - } - - // change status and update title bar - levelChanged = false; - if (mapControl.getMapViewFrame() != null) { - mapControl.getMapViewFrame().changedFlagNotify(); - } - - // disable menu file->revert to revert the map - if (mainControl.getCurrentMap() == mapControl) { - mainControl.getMainView().setRevertMenuEnabled(false); - } - } - - /** - * Set the level changed flag to true. - */ - public void setLevelChangedFlag() { - if (levelChanged) { - return; - } - - // change status and update title bar - levelChanged = true; - if (mapControl.getMapViewFrame() != null) { - mapControl.getMapViewFrame().changedFlagNotify(); - } - - // enable menu file->revert to revert the map - if (mainControl.getCurrentMap() == mapControl) { - mainControl.getMainView().setRevertMenuEnabled(true); - } - } - - /** - * Return whether the level has changed since it was last saved or not. - * @return <code>true</code> if level has changed, <code>false</code> if - * not. - */ - public boolean isLevelChanged() { - return levelChanged; - } - - /** * Return the bottom {@link GameObject} in the given location. * @param pos Position of the map square to get the bottom GameObject from. * @return the GameObject, or null if no object is present @@ -237,8 +185,6 @@ mainControl.getArchetypeParser().postParseGameObject(part, mapControl.getActiveEditType()); } - // Level data has changed - setLevelChangedFlag(); return true; } @@ -306,7 +252,6 @@ mainControl.getArchetypeParser().postParseGameObject(newGameObject, mapControl.getActiveEditType()); } - setLevelChangedFlag(); // the map has been modified return newGameObject; } @@ -335,8 +280,6 @@ } else if (mapControl.getActiveEditType() != 0) { gameObject.setEditType(gameObject.calculateEditType(mapControl.getActiveEditType())); // calculate new } - - setLevelChangedFlag(); // Level data has changed } /** {@inheritDoc} */ @@ -405,7 +348,6 @@ break; } } - setLevelChangedFlag(); // the map has been modified } /** @@ -431,12 +373,6 @@ return null; } - /** {@inheritDoc} */ - @Override public void resizeMap(@NotNull final Size2D newSize) { - super.resizeMap(newSize); - setLevelChangedFlag(); // the map changed for sure! - } - /** * Scan the elements at a given square and check the match status of * default named filter for that square. Modified: trunk/crossfire/src/cfeditor/map/MapControl.java =================================================================== --- trunk/crossfire/src/cfeditor/map/MapControl.java 2007-01-06 19:58:22 UTC (rev 1460) +++ trunk/crossfire/src/cfeditor/map/MapControl.java 2007-01-06 20:58:22 UTC (rev 1461) @@ -36,6 +36,7 @@ import net.sf.gridarta.gui.map.MapCursorListener; import net.sf.gridarta.gui.map.MapGrid; import net.sf.gridarta.gui.map.MapGridListener; +import net.sf.gridarta.map.AbstractMapControl; import net.sf.gridarta.map.MapModelListener; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -45,7 +46,7 @@ * @author <a href="mailto:mic...@no...">Michael Toennies</a> * @author <a href="mailto:and...@gm...">Andreas Vogl</a> */ -public final class MapControl implements net.sf.gridarta.map.MapControl<GameObject, MapArchObject> { +public final class MapControl extends AbstractMapControl<GameObject, MapArchObject> { /** * The main controller of this subcontroller. @@ -96,6 +97,7 @@ mapModel = new DefaultMapModel(mainControl, this, objects, maparch); // and create a view (= window) mapViewFrame = new MapViewIFrame(mainControl, this, initial); + init(); } /** {@inheritDoc} */ @@ -156,7 +158,9 @@ } public void levelCloseNotify() { + super.levelCloseNotify(); levelClosing = true; + mapViewFrame.closeNotify(); } /** @@ -253,15 +257,6 @@ } /** - * Return whether the level has changed since it was last saved or not. - * @return <code>true</code> if level has changed, <code>false</code> if - * not - */ - public boolean isLevelChanged() { - return mapModel.isLevelChanged(); - } - - /** * Return whether the level can be just saved (true) or does it need to be * saved as (false). * @return <code>true</code> if level can be just saved, <code>false</code> @@ -486,10 +481,6 @@ mapModel.resizeMap(size); } - public void setLevelChangedFlag() { - mapModel.setLevelChangedFlag(); - } - /** * Get the last used view of this level. * @return the last used view @@ -509,8 +500,7 @@ } assert mapFile != null; mainControl.encodeMapFile(mapFile, mapModel); - mapModel.resetLevelChangedFlag(); - mapViewFrame.changedFlagNotify(); + resetModified(); } /** @@ -520,8 +510,7 @@ public void saveAs(@NotNull final File file) { mainControl.setStatusText("Saving the map to a file..."); mainControl.encodeMapFile(file, mapModel); - mapModel.resetLevelChangedFlag(); - mapViewFrame.changedFlagNotify(); + resetModified(); } public void setMapFile(final File file) { @@ -576,18 +565,12 @@ mapViewFrame.removeMapCursorListener(listener); } - /** - * Register a MapModelListener. - * @param listener MapModelListener to register - */ + /** {@inheritDoc} */ public void addMapModelListener(@NotNull final MapModelListener listener) { mapModel.addMapModelListener(listener); } - /** - * Unregister a MapModelListener. - * @param listener MapModelListener to unregister - */ + /** {@inheritDoc} */ public void removeMapModelListener(@NotNull final MapModelListener listener) { mapModel.removeMapModelListener(listener); } Modified: trunk/crossfire/src/cfeditor/map/MapModel.java =================================================================== --- trunk/crossfire/src/cfeditor/map/MapModel.java 2007-01-06 19:58:22 UTC (rev 1460) +++ trunk/crossfire/src/cfeditor/map/MapModel.java 2007-01-06 20:58:22 UTC (rev 1461) @@ -99,23 +99,4 @@ */ boolean containsArchObject(Point pos); - /** - * Reset the level changed flag to false. - * @todo this probably belongs to CMapControl instead - */ - void resetLevelChangedFlag(); - - /** - * Set the level changed flag to true. - * @todo this probably belongs to CMapControl instead - */ - void setLevelChangedFlag(); - - /** - * Return whether the level has changed since it was last saved or not. - * @return <code>true</code> if level has changed, <code>false</code> if not. - * @todo this probably belongs to CMapControl instead - */ - boolean isLevelChanged(); - } // interface MapModel Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2007-01-06 19:58:22 UTC (rev 1460) +++ trunk/daimonin/src/daieditor/CMainControl.java 2007-01-06 20:58:22 UTC (rev 1461) @@ -135,7 +135,7 @@ * @author Andreas Kirschbaum * @fixme I'm 2200 lines long, therefor I suck. */ -public final class CMainControl extends AbstractMainControl<GameObject> implements ThrowableHandler, MapModelListener { +public final class CMainControl extends AbstractMainControl<GameObject> implements ThrowableHandler, MapModelListener<GameObject, MapArchObject> { /** Action Factory. */ private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("daieditor"); @@ -954,7 +954,7 @@ ACTION_FACTORY.showMessageDialog(mainView, "closePickmapNoPickmaps"); } else { // if pickmap was modified, ask for confirmation: - if (!activePickmap.isLevelChanged() || ACTION_FACTORY.showQuestionDialog(mainView, "confirmClosePickmap", activePickmap.getMapFileName())) { + if (!activePickmap.isModified() || ACTION_FACTORY.showQuestionDialog(mainView, "confirmClosePickmap", activePickmap.getMapFileName())) { final File pickmapFile = activePickmap.getMapFile(); // close pickmap closeLevel(activePickmap, true); @@ -991,7 +991,7 @@ return false; } - if (!forced && level.isLevelChanged()) { + if (!forced && level.isModified()) { final int result = ACTION_FACTORY.showConfirmDialog(mainView, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, "confirmSaveChanges", level.getMapArchObject().getMapDisplayName()); if (result == JOptionPane.YES_OPTION) { if (level.isPlainSaveEnabled()) { @@ -1208,6 +1208,7 @@ // finally, show the map and refresh toolbars newMap.setMapFile(file); newMap.setActiveEditType(tileEdit); // map is loaded with current view settings + newMap.resetModified(); if (view) { refreshMenusAndToolbars(); addRecent(currentMap.getMapArchObject().getMapDisplayName(), file.toString()); @@ -1768,7 +1769,7 @@ if (activePickmap == null) { ACTION_FACTORY.showMessageDialog(mainView, "revertPickmapNoPickmaps"); } else { - if (!activePickmap.isLevelChanged() || ACTION_FACTORY.showQuestionDialog(mainView, "confirmRevertPickmap", activePickmap.getMapFileName())) { + if (!activePickmap.isModified() || ACTION_FACTORY.showQuestionDialog(mainView, "confirmRevertPickmap", activePickmap.getMapFileName())) { final File mfile = activePickmap.getMapFile(); // store file if (!mfile.exists()) { ACTION_FACTORY.showMessageDialog(mainView, "revertPickmapGone", activePickmap.getMapFileName()); @@ -2014,7 +2015,7 @@ } /** {@inheritDoc} */ - public void mapMetaChanged(final MapModelEvent e) { + public void mapMetaChanged(final MapArchObject mapArchObject) { // ignore } Modified: trunk/daimonin/src/daieditor/CMainView.java =================================================================== --- trunk/daimonin/src/daieditor/CMainView.java 2007-01-06 19:58:22 UTC (rev 1460) +++ trunk/daimonin/src/daieditor/CMainView.java 2007-01-06 20:58:22 UTC (rev 1461) @@ -454,7 +454,8 @@ } public void setRevertMenuEnabled(final boolean state) { - aRevert.setEnabled(state); + aRevert.setEnabled(state && mainControl.isPlainSaveEnabled()); + aSave.setEnabled(state && mainControl.isPlainSaveEnabled()); } /** Refresh the state of the menu only. */ @@ -811,7 +812,7 @@ ACTION_FACTORY.getAction(directionsMap[direction]).setEnabled(mtp != null && mtp.length() > 0); } aEnterExit.setEnabled(selState); - //aRevert.setEnabled(mapState && mainControl.getCurrentMap().isLevelChanged()); + aRevert.setEnabled(mapState && fLevelEdited && mainControl.isPlainSaveEnabled()); //aGridToggle.setEnabled(mapState); //((ToggleAction) aGridToggle).setSelected(mapState && mainControl.isGridVisible()); // FIXME IMPORTANT!!! rebuildWindowMenu(); Modified: trunk/daimonin/src/daieditor/CMapViewBasic.java =================================================================== --- trunk/daimonin/src/daieditor/CMapViewBasic.java 2007-01-06 19:58:22 UTC (rev 1460) +++ trunk/daimonin/src/daieditor/CMapViewBasic.java 2007-01-06 20:58:22 UTC (rev 1461) @@ -28,6 +28,7 @@ import daieditor.gui.map.DefaultLevelRenderer; import daieditor.gui.map.LevelRenderer; import daieditor.gui.map.MapUserListener; +import daieditor.map.MapArchObject; import daieditor.map.MapControl; import daieditor.map.MapModel; import daieditor.map.validation.ErrorCollector; @@ -83,7 +84,7 @@ * @author <a href="mailto:ch...@ri...">Christian Hujer</a> * @author <a href="mailto:dlv...@gm...">Daniel Viegas</a> */ -public final class CMapViewBasic extends JScrollPane implements ErrorHandler, MapModelListener, MapCursorListener { +public final class CMapViewBasic extends JScrollPane implements ErrorHandler, MapModelListener<GameObject, MapArchObject>, MapCursorListener { private static final Logger log = Logger.getLogger(CMapViewBasic.class); @@ -370,7 +371,7 @@ } /** {@inheritDoc} */ - public void mapMetaChanged(final MapModelEvent e) { + public void mapMetaChanged(final MapArchObject mapArchObject) { // ignore } Modified: trunk/daimonin/src/daieditor/MapViewIFrame.java =================================================================== --- trunk/daimonin/src/daieditor/MapViewIFrame.java 2007-01-06 19:58:22 UTC (rev 1460) +++ trunk/daimonin/src/daieditor/MapViewIFrame.java 2007-01-06 20:58:22 UTC (rev 1461) @@ -24,6 +24,7 @@ package daieditor; +import daieditor.gameobject.GameObject; import daieditor.map.MapControl; import java.awt.BorderLayout; import java.awt.Image; @@ -39,6 +40,10 @@ import static javax.swing.KeyStroke.getKeyStroke; import net.sf.gridarta.gui.map.MapCursorListener; import net.sf.gridarta.gui.map.MapGridListener; +import net.sf.gridarta.map.MapArchObject; +import net.sf.gridarta.map.MapControlListener; +import net.sf.gridarta.map.MapModelEvent; +import net.sf.gridarta.map.MapModelListener; import org.jetbrains.annotations.NotNull; /** @@ -63,10 +68,54 @@ /** The controller of this view. */ private final CMainControl mainControl; + /** View number. */ + private final int number; + /** The underlying mapview object. */ private final CMapViewBasic view; /** + * The {@link MapModelListener} used to detect changes in the map model + * that should be reflected in the window title. + */ + private final MapModelListener<GameObject, MapArchObject> mapModelListener = new MapModelListener<GameObject, MapArchObject>() { + + /** {@inheritDoc} */ + public void mapSizeChanged(final MapModelEvent e) { + // ignore + } + + /** {@inheritDoc} */ + public void mapSquaresChanged(final MapModelEvent e) { + // ignore + } + + /** {@inheritDoc} */ + public void mapObjectsChanged(final MapModelEvent e) { + // ignore + } + + /** {@inheritDoc} */ + public void mapMetaChanged(final MapArchObject mapArchObject) { + updateTitle(); + } + + }; + + /** + * The {@link MapControlListener} used to detect changes in the map control + * that should be reflected in the window title. + */ + private final MapControlListener<MapControl> mapControlListener = new MapControlListener<MapControl>() { + + /** {@inheritDoc} */ + public void modifiedChanged(@NotNull final MapControl mapControl) { + updateTitle(); + } + + }; + + /** * Constructs a level view. * @param mainControl the main controller * @param mapControl the controller of this view @@ -77,6 +126,7 @@ super(mapControl.getMapFileName() + " [ " + mapControl.getMapArchObject().getMapDisplayName() + " ] (" + number + ')', true, true, true, true); this.mapControl = mapControl; this.mainControl = mainControl; + this.number = number; setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); @@ -88,9 +138,20 @@ if (img != null) { setFrameIcon(new ImageIcon(img)); } + + mapControl.addMapControlListener(mapControlListener); + mapControl.addMapModelListener(mapModelListener); } /** + * This function must be called when the view is closed. + */ + public void closeNotify() { + mapControl.removeMapControlListener(mapControlListener); + mapControl.removeMapModelListener(mapModelListener); + } + + /** * Okay, this is a bit of a hack. True seperation of mapview and * frame-component would really mess up the code, or maybe make it * "cleaner" but blow things up tenfold. @@ -100,6 +161,17 @@ return view; } + /** Update the Map-Window Title (according to name and changeFlag). */ + private void updateTitle() { + setTitle(mapControl.getMapFileName() + " [ " + mapControl.getMapArchObject().getMapDisplayName() + " ] (" + number + ")" + (mapControl.isModified() ? " *" : "")); + + // disable menu file->revert to revert the map + // XXX: should not be here + if (mainControl.getCurrentMap() == mapControl) { + mainControl.getMainView().setRevertMenuEnabled(mapControl.isModified()); + } + } + // following a bunch of wrapper methods which just pass access // to the basic mapview object 'view': Modified: trunk/daimonin/src/daieditor/gui/PickmapChooser.java =================================================================== --- trunk/daimonin/src/daieditor/gui/PickmapChooser.java 2007-01-06 19:58:22 UTC (rev 1460) +++ trunk/daimonin/src/daieditor/gui/PickmapChooser.java 2007-01-06 20:58:22 UTC (rev 1461) @@ -230,6 +230,8 @@ pickmaps.add(index, mapControl); } currentPickMap = mapControl; + mapControl.resetModified(); + return mapControl.getMapViewFrame().getBasicView(); } Modified: trunk/daimonin/src/daieditor/gui/selectedsquare/SelectedSquareView.java =================================================================== --- trunk/daimonin/src/daieditor/gui/selectedsquare/SelectedSquareView.java 2007-01-06 19:58:22 UTC (rev 1460) +++ trunk/daimonin/src/daieditor/gui/selectedsquare/SelectedSquareView.java 2007-01-06 20:58:22 UTC (rev 1461) @@ -52,6 +52,7 @@ import net.sf.gridarta.gui.map.MapCursorListener; import net.sf.gridarta.gui.maptilelist.MapTileSelection; import net.sf.gridarta.gui.maptilelist.MapTileSelectionCache; +import net.sf.gridarta.map.MapArchObject; import net.sf.gridarta.map.MapModelEvent; import net.sf.gridarta.map.MapModelListener; import net.sf.gridarta.map.MapSquare; @@ -68,7 +69,7 @@ * @author <a href="mailto:ch...@ri...">Christian Hujer</a> * @todo turn this into a tree */ -public final class SelectedSquareView extends JPanel implements MainControlListener<MapControl>, MapCursorListener, MapModelListener<GameObject> { +public final class SelectedSquareView extends JPanel implements MainControlListener<MapControl>, MapCursorListener, MapModelListener<GameObject, MapArchObject> { /** Serial Version UID. */ private static final long serialVersionUID = 1L; @@ -392,7 +393,7 @@ } /** {@inheritDoc} */ - public void mapMetaChanged(final MapModelEvent e) { + public void mapMetaChanged(final MapArchObject mapArchObject) { // ignore } Modified: trunk/daimonin/src/daieditor/map/MapControl.java =================================================================== --- trunk/daimonin/src/daieditor/map/MapControl.java 2007-01-06 19:58:22 UTC (rev 1460) +++ trunk/daimonin/src/daieditor/map/MapControl.java 2007-01-06 20:58:22 UTC (rev 1461) @@ -50,6 +50,7 @@ import net.sf.gridarta.gui.map.MapCursorListener; import net.sf.gridarta.gui.map.MapGrid; import net.sf.gridarta.gui.map.MapGridListener; +import net.sf.gridarta.map.AbstractMapControl; import net.sf.gridarta.map.MapModelEvent; import net.sf.gridarta.map.MapModelListener; import net.sf.gridarta.map.MapSquare; @@ -63,7 +64,7 @@ * @author <a href="mailto:and...@gm...">Andreas Vogl</a> * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ -public final class MapControl implements MapModelListener, net.sf.gridarta.map.MapControl { +public final class MapControl extends AbstractMapControl<GameObject, MapArchObject> { /** * The main controller of this subcontroller. @@ -129,13 +130,6 @@ private BufferedImage previewImage; /** - * Keep track of changes. - * This field is <code>true</code> if the map was changed after the last save / load operation. - * Therefore this class implements {@link net.sf.gridarta.map.MapModelListener}. - */ - private boolean changed; - - /** * Constructs a new Map. * @param mainControl the CMainControl * @param maparch the <code>MapArchObject</code> of the map @@ -149,10 +143,10 @@ this.isPickmap = isPickmap; // is this a pickmap? // we create model (= data) mapModel = new DefaultMapModel(mainControl, this, objects, maparch); - mapModel.addMapModelListener(this); if (createView) { createView(); } + init(); } /** {@inheritDoc} */ @@ -213,6 +207,7 @@ } public void levelCloseNotify() { + super.levelCloseNotify(); levelClosing = true; } @@ -225,15 +220,6 @@ } /** - * Return whether the level has changed since it was last saved or not. - * @return <code>true</code> if level has changed, <code>false</code> if - * not - */ - public boolean isLevelChanged() { - return changed; - } - - /** * Return whether the level can be just saved (true) or does it need to be * saved as (false). * @return <code>true</code> if level can be just saved, <code>false</code> @@ -331,7 +317,7 @@ if (!isPickmap) { saveImages(); } - changed = false; + resetModified(); } /** @@ -365,6 +351,7 @@ public void saveAs(final File file) { mainControl.setStatusText("Saving the map to a file..."); mainControl.encodeMapFile(file, mapModel); + resetModified(); } public void setMapFile(final File file) { @@ -632,6 +619,7 @@ * @param mapViewIFrame the view to be closed */ public void closeView(final MapViewIFrame mapViewIFrame) { + mapViewIFrame.closeNotify(); mapViewIFrames.remove(mapViewIFrame); mainControl.getMainView().removeLevelView(mapViewIFrame); final int size = mapViewIFrames.size(); @@ -662,26 +650,6 @@ return mapModel; } - /** {@inheritDoc} */ - public void mapSizeChanged(final MapModelEvent e) { - changed = true; - } - - /** {@inheritDoc} */ - public void mapSquaresChanged(final MapModelEvent e) { - changed = true; - } - - /** {@inheritDoc} */ - public void mapObjectsChanged(final MapModelEvent e) { - changed = true; - } - - /** {@inheritDoc} */ - public void mapMetaChanged(final MapModelEvent e) { - changed = true; - } - /** * Determines if this map has an active selection. * @@ -726,18 +694,12 @@ mapViewFrame.removeMapCursorListener(listener); } - /** - * Register a MapModelListener. - * @param listener MapModelListener to register - */ + /** {@inheritDoc} */ public void addMapModelListener(@NotNull final MapModelListener listener) { mapModel.addMapModelListener(listener); } - /** - * Unregister a MapModelListener. - * @param listener MapModelListener to unregister - */ + /** {@inheritDoc} */ public void removeMapModelListener(@NotNull final MapModelListener listener) { mapModel.removeMapModelListener(listener); } Modified: trunk/src/app/net/sf/gridarta/gui/AbstractGameObjectAttributesDialog.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/AbstractGameObjectAttributesDialog.java 2007-01-06 19:58:22 UTC (rev 1460) +++ trunk/src/app/net/sf/gridarta/gui/AbstractGameObjectAttributesDialog.java 2007-01-06 20:58:22 UTC (rev 1461) @@ -1385,7 +1385,6 @@ gameObject.calculateEditType(mainControl.getCurrentMap().getActiveEditType()); // also update the gameObject panel (bottom) mainControl.getMainView().refreshMapArchPanel(); - changeNotify(); } else { // change not wanted -> reset the choosebox ignoreEvent = true; // ignore events thrown by the forced reset @@ -1397,8 +1396,4 @@ } // class TypesBoxAL - /** Notify of changes. */ - protected void changeNotify() { - } - } // class AbstractGameObjectAttributesDialog Modified: trunk/src/app/net/sf/gridarta/gui/connectionview/ConnectionView.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/connectionview/ConnectionView.java 2007-01-06 19:58:22 UTC (rev 1460) +++ trunk/src/app/net/sf/gridarta/gui/connectionview/ConnectionView.java 2007-01-06 20:58:22 UTC (rev 1461) @@ -126,7 +126,7 @@ } /** {@inheritDoc} */ - public void mapMetaChanged(final MapModelEvent e) { + public void mapMetaChanged(final MapArchObject mapArchObject) { // ignore } Modified: trunk/src/app/net/sf/gridarta/map/AbstractMapArchObject.java =================================================================== --- trunk/src/app/net/sf/gridarta/map/AbstractMapArchObject.java 2007-01-06 19:58:22 UTC (rev 1460) +++ trunk/src/app/net/sf/gridarta/map/AbstractMapArchObject.java 2007-01-06 20:58:22 UTC (rev 1461) @@ -99,9 +99,9 @@ private boolean modified = false; /** - * Set if {@link #modified} has changed inside the current transactions. + * Set if any attribute has changed inside the current transaction. */ - private boolean modifiedHasChanged = false; + private boolean attributeHasChanged = false; /** * Create an AbstractMapArchObject. @@ -276,24 +276,20 @@ * of the transaction. */ protected void setModified() { - if (!modified) { - modified = true; - modifiedHasChanged = true; - } + modified = true; + attributeHasChanged = true; } /** {@inheritDoc} */ public void resetModified() { - if (modified) { - modified = false; - modifiedHasChanged = true; - } + modified = false; + attributeHasChanged = true; } /** {@inheritDoc} */ public final void beginTransaction() { if (transactionDepth == 0) { - modifiedHasChanged = false; + attributeHasChanged = false; transactionThread = Thread.currentThread(); } else { // == is okay for threads. @@ -320,8 +316,8 @@ if (transactionDepth == 0) { commitTransaction(); } else if (fireEvent && transactionDepth > 0) { - if (modifiedHasChanged) { - fireModifiedChangedEvent(); + if (attributeHasChanged) { + fireMetaChangedEvent(); } } } @@ -333,19 +329,19 @@ private void commitTransaction() { transactionDepth = 0; transactionThread = null; - if (modifiedHasChanged) { - fireModifiedChangedEvent(); - modifiedHasChanged = false; + if (attributeHasChanged) { + fireMetaChangedEvent(); + attributeHasChanged = false; } } /** - * Fire a MapSquaresChangedEvent. + * Fire a MapMetaChangedEvent. * @param squares Squares to fire event for */ - private void fireModifiedChangedEvent() { + private void fireMetaChangedEvent() { for (final MapArchObjectListener listener : listenerList.getListeners(MapArchObjectListener.class)) { - listener.modifiedChanged(this); + listener.mapMetaChanged(this); } } Added: trunk/src/app/net/sf/gridarta/map/AbstractMapControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/map/AbstractMapControl.java (rev 0) +++ trunk/src/app/net/sf/gridarta/map/AbstractMapControl.java 2007-01-06 20:58:22 UTC (rev 1461) @@ -0,0 +1,140 @@ +/* + * Gridarta Map Editor. + * Copyright (C) 2007 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., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +package net.sf.gridarta.map; + +import javax.swing.event.EventListenerList; +import net.sf.gridarta.gameobject.GameObject; +import org.apache.log4j.Logger; +import org.jetbrains.annotations.NotNull; + +/** + * The class <code>AbstractMapControl</code> implements common code between + * crossfire and daimonin <code>MapControl</code>. + * + * @author Andreas Kirschbaum + */ +public abstract class AbstractMapControl<G extends GameObject<G>, A extends MapArchObject> implements MapControl<G, A> { + + /** The Logger for printing log messages. */ + private static final Logger log = Logger.getLogger(AbstractMapControl.class); + + /** The registered event listeners. */ + private EventListenerList listenerList = new EventListenerList(); + + /** + * Set if the map has changed since last save. + */ + private boolean modified = false; + + /** + * The {@link MapModelListener} used to detect changes in the underlying + * map model and set the {@link #modified} flag accordingly. + */ + private final MapModelListener<G, A> mapModelListener = new MapModelListener<G, A>() { + + /** {@inheritDoc} */ + public void mapSizeChanged(final MapModelEvent<G> e) { + setModified(); + } + + /** {@inheritDoc} */ + public void mapSquaresChanged(final MapModelEvent<G> e) { + setModified(); + } + + /** {@inheritDoc} */ + public void mapObjectsChanged(final MapModelEvent<G> e) { + setModified(); + } + + /** {@inheritDoc} */ + public void mapMetaChanged(final A e) { + setModified(); + } + + }; + + /** + * Create a new instance + */ + protected AbstractMapControl() { + } + + /** + * Finish initialization. This function must be called from the constructor + * of all implementing classes. + */ + protected void init() { + addMapModelListener(mapModelListener); + } + + /** + * This function must be called if this instance is freed. + */ + protected void levelCloseNotify() { + removeMapModelListener(mapModelListener); + } + + /** {@inheritDoc} */ + public boolean isModified() { + return modified; + } + + /** {@inheritDoc} */ + public void resetModified() { + if (!modified) { + return; + } + + modified = false; + fireModifiedChanged(); + } + + /** + * Set the level changed flag to true. + */ + private void setModified() { + if (modified) { + return; + } + + modified = true; + fireModifiedChanged(); + } + + /** {@inheritDoc} */ + public void addMapControlListener(@NotNull MapControlListener<? extends MapControl> listener) { + listenerList.add(MapControlListener.class, listener); + } + + /** {@inheritDoc} */ + public void removeMapControlListener(@NotNull MapControlListener<? extends MapControl> listener) { + listenerList.remove(MapControlListener.class, listener); + } + + /** Fire a map size changed event. */ + private void fireModifiedChanged() { + for (final MapControlListener listener : listenerList.getListeners(MapControlListener.class)) { + listener.modifiedChanged(this); + } + } + +} Property changes on: trunk/src/app/net/sf/gridarta/map/AbstractMapControl.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: trunk/src/app/net/sf/gridarta/map/AbstractMapModel.java =================================================================== --- trunk/src/app/net/sf/gridarta/map/AbstractMapModel.java 2007-01-06 19:58:22 UTC (rev 1460) +++ trunk/src/app/net/sf/gridarta/map/AbstractMapModel.java 2007-01-06 20:58:22 UTC (rev 1461) @@ -237,13 +237,15 @@ } /** {@inheritDoc} */ - public void addMapModelListener(@NotNull final MapModelListener<G> listener) { + public void addMapModelListener(@NotNull final MapModelListener<G, A> listener) { listenerList.add(MapModelListener.class, listener); + mapArchObject.addMapArchObjectListener(listener); } /** {@inheritDoc} */ - public void removeMapModelListener(@NotNull final MapModelListener<G> listener) { + public void removeMapModelListener(@NotNull final MapModelListener<G, A> listener) { listenerList.remove(MapModelListener.class, listener); + mapArchObject.removeMapArchObjectListener(listener); } /** {@inheritDoc} */ Modified: trunk/src/app/net/sf/gridarta/map/MapArchObjectListener.java =================================================================== --- trunk/src/app/net/sf/gridarta/map/MapArchObjectListener.java 2007-01-06 19:58:22 UTC (rev 1460) +++ trunk/src/app/net/sf/gridarta/map/MapArchObjectListener.java 2007-01-06 20:58:22 UTC (rev 1461) @@ -28,13 +28,12 @@ * * @author Andreas Kirschbaum */ -public interface MapArchObjectListener<M extends MapArchObject> extends EventListener { +public interface MapArchObjectListener<A extends MapArchObject> extends EventListener { /** - * The modified state has changed. - * + * Meta information of a map has changed. * @param mapArchObject the map arch object that has changed */ - void modifiedChanged(@NotNull M mapArchObject); + void mapMetaChanged(@NotNull A mapArchObject); } // interface MapArchObjectListener Modified: trunk/src/app/net/sf/gridarta/map/MapControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/map/MapControl.java 2007-01-06 19:58:22 UTC (rev 1460) +++ trunk/src/app/net/sf/gridarta/map/MapControl.java 2007-01-06 20:58:22 UTC (rev 1461) @@ -53,4 +53,34 @@ */ @Deprecated int getActiveEditType(); + /** + * Return whether the map has been modified from the on-disk state. + * @return<code>true</code> if the map has been modified from the on-disk state + */ + boolean isModified(); + + /** + * Register a map control listener. + * @param listener MapControlListener to register + */ + void addMapControlListener(@NotNull MapControlListener<? extends MapControl> listener); + + /** + * Unregister a map listener. + * @param listener MapModelListener to unregsiter + */ + void removeMapControlListener(@NotNull MapControlListener<? extends MapControl> listener); + + /** + * Register a MapModelListener. + * @param listener MapModelListener to register + */ + void addMapModelListener(@NotNull MapModelListener listener); + + /** + * Unregister a MapModelListener. + * @param listener MapModelListener to unregister + */ + void removeMapModelListener(@NotNull MapModelListener listener); + } // interface MapControl Added: trunk/src/app/net/sf/gridarta/map/MapControlListener.java =================================================================== --- trunk/src/app/net/sf/gridarta/map/MapControlListener.java (rev 0) +++ trunk/src/app/net/sf/gridarta/map/MapControlListener.java 2007-01-06 20:58:22 UTC (rev 1461) @@ -0,0 +1,42 @@ +/* + * Gridarta Map Editor. + * Copyright (C) 2007 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., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +package net.sf.gridarta.map; + +import java.util.EventListener; +import net.sf.gridarta.gameobject.GameObject; +import org.jetbrains.annotations.NotNull; + +/** + * Interface for listeners listening on changes in {@link MapControl} + * instances. + * + * @author Andreas Kirschbaum + */ +public interface MapControlListener<M extends MapControl> extends EventListener { + + /** + * The modified flag has changed. + * + * @param mapControl the map control that has changed + */ + void modifiedChanged(@NotNull M mapControl); + +} // interface MapControlListener Property changes on: trunk/src/app/net/sf/gridarta/map/MapControlListener.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: trunk/src/app/net/sf/gridarta/map/MapModel.java =================================================================== --- trunk/src/app/net/sf/gridarta/map/MapModel.java 2007-01-06 19:58:22 UTC (rev 1460) +++ trunk/src/app/net/sf/gridarta/map/MapModel.java 2007-01-06 20:58:22 UTC (rev 1461) @@ -90,13 +90,13 @@ * Register a map listener. * @param listener MapModelL... [truncated message content] |
From: <aki...@us...> - 2007-01-07 00:07:40
|
Revision: 1462 http://svn.sourceforge.net/gridarta/?rev=1462&view=rev Author: akirschbaum Date: 2007-01-06 16:07:40 -0800 (Sat, 06 Jan 2007) Log Message: ----------- Fix some unchecked warnings. Modified Paths: -------------- trunk/crossfire/src/cfeditor/AutojoinList.java trunk/crossfire/src/cfeditor/CFArchTypeList.java trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/CMapViewBasic.java trunk/crossfire/src/cfeditor/CopyBuffer.java trunk/crossfire/src/cfeditor/MapViewIFrame.java trunk/crossfire/src/cfeditor/ReplaceDialog.java trunk/crossfire/src/cfeditor/gameobject/ArchetypeParser.java trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java trunk/crossfire/src/cfeditor/gameobject/GameObject.java trunk/crossfire/src/cfeditor/gui/ArchetypeChooser.java trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java trunk/crossfire/src/cfeditor/gui/InsertionObjectChooser.java trunk/crossfire/src/cfeditor/gui/ObjectChoiceDisplay.java trunk/crossfire/src/cfeditor/gui/map/DefaultLevelRenderer.java trunk/crossfire/src/cfeditor/gui/selectedsquare/CellRenderer.java trunk/crossfire/src/cfeditor/gui/selectedsquare/SelectedSquareControl.java trunk/crossfire/src/cfeditor/gui/selectedsquare/SelectedSquareView.java trunk/crossfire/src/cfeditor/io/CMapWriter.java trunk/daimonin/src/daieditor/CFArchTypeList.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/CMapViewBasic.java trunk/daimonin/src/daieditor/CopyBuffer.java trunk/daimonin/src/daieditor/MapViewIFrame.java trunk/daimonin/src/daieditor/ReplaceDialog.java trunk/daimonin/src/daieditor/gameobject/ArchetypeParser.java trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java trunk/daimonin/src/daieditor/gameobject/GameObject.java trunk/daimonin/src/daieditor/gui/ArchetypeChooser.java trunk/daimonin/src/daieditor/gui/GameObjectAttributesDialog.java trunk/daimonin/src/daieditor/gui/InsertionObjectChooser.java trunk/daimonin/src/daieditor/gui/ObjectChoiceDisplay.java trunk/daimonin/src/daieditor/gui/map/DefaultLevelRenderer.java trunk/daimonin/src/daieditor/gui/map/SimpleLevelRenderer.java trunk/daimonin/src/daieditor/gui/map/tools/DeletionTool.java trunk/daimonin/src/daieditor/gui/selectedsquare/SelectedSquareControl.java trunk/daimonin/src/daieditor/gui/selectedsquare/SelectedSquareView.java trunk/daimonin/src/daieditor/io/CMapWriter.java trunk/daimonin/src/daieditor/map/DefaultMapModel.java trunk/daimonin/src/daieditor/map/MapControl.java trunk/daimonin/src/daieditor/map/MapModel.java trunk/daimonin/src/daieditor/map/validation/DelegatingMapValidator.java trunk/daimonin/src/daieditor/map/validation/GameObjectsValidationError.java trunk/daimonin/src/daieditor/map/validation/SquareValidationError.java trunk/daimonin/src/daieditor/map/validation/SquareValidator.java trunk/daimonin/src/daieditor/map/validation/ValidationError.java trunk/daimonin/src/daieditor/map/validation/checks/BlockedMobOrSpawnPointChecker.java trunk/daimonin/src/daieditor/map/validation/checks/BlockedMobOrSpawnPointError.java trunk/daimonin/src/daieditor/map/validation/checks/BlockedSquareChecker.java trunk/daimonin/src/daieditor/map/validation/checks/BlockedSquareError.java trunk/daimonin/src/daieditor/map/validation/checks/DoubleLayerChecker.java trunk/daimonin/src/daieditor/map/validation/checks/DoubleLayerError.java trunk/daimonin/src/daieditor/map/validation/checks/DoubleTypeChecker.java trunk/daimonin/src/daieditor/map/validation/checks/DoubleTypeError.java trunk/daimonin/src/daieditor/map/validation/checks/SquareWithoutFloorChecker.java trunk/daimonin/src/daieditor/map/validation/checks/SquareWithoutFloorError.java trunk/src/app/net/sf/gridarta/AbstractMainControl.java trunk/src/app/net/sf/gridarta/CFArchTypeList.java trunk/src/app/net/sf/gridarta/MainControl.java trunk/src/app/net/sf/gridarta/gameobject/AbstractArchetypeParser.java trunk/src/app/net/sf/gridarta/gameobject/AbstractArchetypeSet.java trunk/src/app/net/sf/gridarta/gameobject/Archetype.java trunk/src/app/net/sf/gridarta/gameobject/ArchetypeParser.java trunk/src/app/net/sf/gridarta/gameobject/ArchetypeSet.java trunk/src/app/net/sf/gridarta/gameobject/GameObject.java trunk/src/app/net/sf/gridarta/gameobject/GameObjectContainer.java trunk/src/app/net/sf/gridarta/gameobject/MultiArchData.java trunk/src/app/net/sf/gridarta/gameobject/RecursiveGameObjectIterator.java trunk/src/app/net/sf/gridarta/gui/AbstractGameObjectAttributesDialog.java trunk/src/app/net/sf/gridarta/gui/ArchetypeChooser.java trunk/src/app/net/sf/gridarta/gui/InsertionObjectChooser.java trunk/src/app/net/sf/gridarta/gui/connectionview/ConnectionView.java trunk/src/app/net/sf/gridarta/gui/maptilelist/MapTileSelection.java trunk/src/app/net/sf/gridarta/gui/maptilelist/MapTileSelectionCache.java trunk/src/app/net/sf/gridarta/io/AbstractMapWriter.java trunk/src/app/net/sf/gridarta/map/AbstractMapControl.java trunk/src/app/net/sf/gridarta/map/AbstractMapModel.java trunk/src/app/net/sf/gridarta/map/MapControl.java trunk/src/app/net/sf/gridarta/map/MapModel.java trunk/src/app/net/sf/gridarta/map/MapModelEvent.java trunk/src/app/net/sf/gridarta/map/MapModelListener.java trunk/src/app/net/sf/gridarta/map/MapSquare.java Modified: trunk/crossfire/src/cfeditor/AutojoinList.java =================================================================== --- trunk/crossfire/src/cfeditor/AutojoinList.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/crossfire/src/cfeditor/AutojoinList.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -26,6 +26,7 @@ import cfeditor.gameobject.ArchetypeSet; import cfeditor.gameobject.GameObject; +import cfeditor.map.MapArchObject; import cfeditor.map.MapModel; import java.awt.Point; import java.io.BufferedReader; @@ -145,7 +146,7 @@ } else if (count < 16) { // add a new archid to the buffer - final Archetype<GameObject> archetype = archstack.getArchetype(line); + final Archetype<GameObject, MapArchObject> archetype = archstack.getArchetype(line); if (archetype != null) { nbuf[count] = line; Modified: trunk/crossfire/src/cfeditor/CFArchTypeList.java =================================================================== --- trunk/crossfire/src/cfeditor/CFArchTypeList.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/crossfire/src/cfeditor/CFArchTypeList.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -25,6 +25,7 @@ package cfeditor; import cfeditor.gameobject.GameObject; +import cfeditor.map.MapArchObject; import java.awt.Component; import java.util.ArrayList; import java.util.HashMap; @@ -52,7 +53,7 @@ * @author <a href="mailto:and...@gm...">Andreas Vogl</a> * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ -public final class CFArchTypeList extends net.sf.gridarta.CFArchTypeList<CFArchType, GameObject> { +public final class CFArchTypeList extends net.sf.gridarta.CFArchTypeList<CFArchType, GameObject, MapArchObject> { private static final Logger log = Logger.getLogger(CFArchTypeList.class); Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -86,7 +86,7 @@ * @author <a href="mailto:and...@gm...">Andreas Vogl</a> * @author Andreas Kirschbaum */ -public final class CMainControl extends AbstractMainControl<GameObject> implements ThrowableHandler { +public final class CMainControl extends AbstractMainControl<GameObject, MapArchObject> implements ThrowableHandler { /** Action Factory. */ private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); Modified: trunk/crossfire/src/cfeditor/CMapViewBasic.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapViewBasic.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/crossfire/src/cfeditor/CMapViewBasic.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -313,8 +313,8 @@ * Get the selected squares. * @return selected squares */ - public List<MapSquare<GameObject>> getSelectedSquares() { - final List<MapSquare<GameObject>> selection = new ArrayList<MapSquare<GameObject>>(); + public List<MapSquare<GameObject, MapArchObject>> getSelectedSquares() { + final List<MapSquare<GameObject, MapArchObject>> selection = new ArrayList<MapSquare<GameObject, MapArchObject>>(); final Size2D mapSize = mapModel.getMapSize(); final Point pos = new Point(); for (pos.x = 0; pos.x < mapSize.getWidth(); pos.x++) { Modified: trunk/crossfire/src/cfeditor/CopyBuffer.java =================================================================== --- trunk/crossfire/src/cfeditor/CopyBuffer.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/crossfire/src/cfeditor/CopyBuffer.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -138,7 +138,7 @@ mapControl.getMapModel().beginTransaction("Cut / Clear"); // TODO: I18N/L10N final HashSet<GameObject> gameObjectsToDelete = new HashSet<GameObject>(); - for (final MapSquare<GameObject> square : mapControl.getMapViewFrame().getView().getSelectedSquares()) { + for (final MapSquare<GameObject, MapArchObject> square : mapControl.getMapViewFrame().getView().getSelectedSquares()) { final int posx = square.getMapX(); final int posy = square.getMapY(); for (final GameObject gameObject : square) { @@ -182,7 +182,7 @@ mapControl.getMapModel().beginTransaction("Paste"); // TODO: I18N/L10N final Point pos = new Point(); assert copyMap != null; - for (final MapSquare<GameObject> square : copyMap) { + for (final MapSquare<GameObject, MapArchObject> square : copyMap) { pos.setLocation(startp.x + square.getMapX(), startp.y + square.getMapY()); if (mapControl.isPointValid(pos)) { for (final GameObject gameObject : square) { @@ -195,7 +195,7 @@ } assert copyMapCtrl != null; - for (final MapSquare<GameObject> square : copyMapCtrl.getMapModel()) { + for (final MapSquare<GameObject, MapArchObject> square : copyMapCtrl.getMapModel()) { pos.setLocation(startp); pos.translate(square.getMapX(), square.getMapY()); if (mapControl.isPointValid(pos)) { Modified: trunk/crossfire/src/cfeditor/MapViewIFrame.java =================================================================== --- trunk/crossfire/src/cfeditor/MapViewIFrame.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/crossfire/src/cfeditor/MapViewIFrame.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -26,6 +26,7 @@ import cfeditor.gameobject.GameObject; import cfeditor.gui.MapView; +import cfeditor.map.MapArchObject; import cfeditor.map.MapControl; import java.awt.BorderLayout; import java.awt.Dimension; @@ -39,7 +40,6 @@ import static javax.swing.KeyStroke.getKeyStroke; import net.sf.gridarta.gui.map.MapCursorListener; import net.sf.gridarta.gui.map.MapGridListener; -import net.sf.gridarta.map.MapArchObject; import net.sf.gridarta.map.MapControlListener; import net.sf.gridarta.map.MapModelEvent; import net.sf.gridarta.map.MapModelListener; Modified: trunk/crossfire/src/cfeditor/ReplaceDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/ReplaceDialog.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/crossfire/src/cfeditor/ReplaceDialog.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -25,6 +25,7 @@ package cfeditor; import cfeditor.gameobject.GameObject; +import cfeditor.map.MapArchObject; import cfeditor.map.MapControl; import java.awt.FlowLayout; import java.awt.Point; @@ -291,7 +292,7 @@ int replaceCount = 0; final ArrayList<GameObject> objectsToReplace = new ArrayList<GameObject>(); mapControl.getMapModel().beginTransaction("Replace"); // TODO: I18N/L10N - for (final MapSquare<GameObject> square : entireMap ? mapControl.getMapModel() : mapViewIFrame.getView().getSelectedSquares()) { + for (final MapSquare<GameObject, MapArchObject> square : entireMap ? mapControl.getMapModel() : mapViewIFrame.getView().getSelectedSquares()) { // find objects to replace objectsToReplace.clear(); for (final GameObject node : square) { Modified: trunk/crossfire/src/cfeditor/gameobject/ArchetypeParser.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/ArchetypeParser.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/crossfire/src/cfeditor/gameobject/ArchetypeParser.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -25,6 +25,7 @@ package cfeditor.gameobject; import cfeditor.CMainControl; +import cfeditor.map.MapArchObject; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; @@ -44,7 +45,7 @@ * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ @SuppressWarnings({"HardcodedFileSeparator"}) -public final class ArchetypeParser extends AbstractArchetypeParser<GameObject> { +public final class ArchetypeParser extends AbstractArchetypeParser<GameObject, MapArchObject> { /** Logger. */ private static final Logger log = Logger.getLogger(ArchetypeParser.class); Modified: trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/crossfire/src/cfeditor/gameobject/ArchetypeSet.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -31,6 +31,7 @@ import cfeditor.gameobject.face.FaceObject; import cfeditor.gameobject.face.FaceObjects; import cfeditor.gui.PickmapChooser; +import cfeditor.map.MapArchObject; import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.DataOutputStream; @@ -61,7 +62,7 @@ * @author <a href="mailto:and...@gm...">Andreas Vogl</a> * @todo move face storage to {@link FaceObjects}. */ -public final class ArchetypeSet extends AbstractArchetypeSet<GameObject> { +public final class ArchetypeSet extends AbstractArchetypeSet<GameObject, MapArchObject> { private static final Logger log = Logger.getLogger(ArchetypeSet.class); @@ -694,7 +695,7 @@ } // finally we need to get the "map"-arch, which is not in the panels - final Archetype<GameObject> maparch = getArchetype(net.sf.gridarta.gameobject.ArchetypeParser.STARTARCH_NAME); + final Archetype<GameObject, MapArchObject> maparch = getArchetype(net.sf.gridarta.gameobject.ArchetypeParser.STARTARCH_NAME); if (maparch != null) { count++; Modified: trunk/crossfire/src/cfeditor/gameobject/GameObject.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -28,6 +28,7 @@ import cfeditor.IGUIConstants; import cfeditor.ScriptArchData; import cfeditor.gui.GameObjectAttributesPanel; +import cfeditor.map.MapArchObject; import java.io.BufferedReader; import java.io.IOException; import java.io.StringReader; @@ -44,7 +45,7 @@ * @author <a href="mailto:mic...@no...">Michael Toennies</a> * @author <a href="mailto:and...@gm...">Andreas Vogl</a> */ -public class GameObject extends net.sf.gridarta.gameobject.GameObject<GameObject> implements Cloneable, Iterable<GameObject> { +public class GameObject extends net.sf.gridarta.gameobject.GameObject<GameObject, MapArchObject> implements Cloneable, Iterable<GameObject> { /** Logger. */ private static final Logger log = Logger.getLogger(GameObject.class); Modified: trunk/crossfire/src/cfeditor/gui/ArchetypeChooser.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/ArchetypeChooser.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/crossfire/src/cfeditor/gui/ArchetypeChooser.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -27,6 +27,7 @@ import cfeditor.CMainControl; import cfeditor.gameobject.GameObject; +import cfeditor.map.MapArchObject; import java.awt.Component; import javax.swing.DefaultListCellRenderer; import javax.swing.JList; @@ -39,7 +40,7 @@ * @author unknown * @author Andreas Kirschbaum */ -public final class ArchetypeChooser extends net.sf.gridarta.gui.ArchetypeChooser<GameObject> { +public final class ArchetypeChooser extends net.sf.gridarta.gui.ArchetypeChooser<GameObject, MapArchObject> { private static final Logger log = Logger.getLogger(ArchetypeChooser.class); Modified: trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -29,6 +29,7 @@ import cfeditor.CMainControl; import cfeditor.gameobject.ArchetypeSet; import cfeditor.gameobject.GameObject; +import cfeditor.map.MapArchObject; import java.util.List; import javax.swing.ImageIcon; import javax.swing.JCheckBox; @@ -52,7 +53,7 @@ * @author <a href="mailto:ch...@ri...">Christian Hujer</a> * @fixme I suck */ -public final class GameObjectAttributesDialog extends AbstractGameObjectAttributesDialog<GameObject> { +public final class GameObjectAttributesDialog extends AbstractGameObjectAttributesDialog<GameObject, MapArchObject> { /** Logger. */ private static final Logger log = Logger.getLogger(GameObjectAttributesDialog.class); Modified: trunk/crossfire/src/cfeditor/gui/InsertionObjectChooser.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/InsertionObjectChooser.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/crossfire/src/cfeditor/gui/InsertionObjectChooser.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -29,6 +29,7 @@ import cfeditor.CSettings; import cfeditor.IGUIConstants; import cfeditor.gameobject.GameObject; +import cfeditor.map.MapArchObject; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.Toolkit; @@ -49,7 +50,7 @@ * @author <a href="mailto:and...@gm...">Andreas Vogl</a> * @author Andreas Kirschbaum */ -public final class InsertionObjectChooser extends JPanel implements net.sf.gridarta.gui.InsertionObjectChooser<GameObject> { +public final class InsertionObjectChooser extends JPanel implements net.sf.gridarta.gui.InsertionObjectChooser<GameObject, MapArchObject> { private static final String ARCHPANEL_LOCATION_KEY = "MainWindowArchPanel.dividerLocation"; Modified: trunk/crossfire/src/cfeditor/gui/ObjectChoiceDisplay.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/ObjectChoiceDisplay.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/crossfire/src/cfeditor/gui/ObjectChoiceDisplay.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -27,6 +27,7 @@ import cfeditor.CMainControl; import cfeditor.ReplaceDialog; import cfeditor.gameobject.GameObject; +import cfeditor.map.MapArchObject; import java.awt.Color; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; @@ -115,7 +116,7 @@ final GameObject headObject = gameObject.getHead(); String objName = headObject.getObjName(); if (objName == null || objName.length() == 0) { - final Archetype<GameObject> archetype = headObject.getArchetype(); + final Archetype<GameObject, MapArchObject> archetype = headObject.getArchetype(); if (archetype == null || archetype == headObject) { objName = null; } else if ((objName = archetype.getObjName()) != null && objName.length() != 0) { Modified: trunk/crossfire/src/cfeditor/gui/map/DefaultLevelRenderer.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/map/DefaultLevelRenderer.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/crossfire/src/cfeditor/gui/map/DefaultLevelRenderer.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -378,7 +378,7 @@ /** {@inheritDoc} */ public void mapSquaresChanged(final MapModelEvent e) { - final MapSquare<GameObject>[] squares = e.getSquares(); + final MapSquare<GameObject, MapArchObject>[] squares = e.getSquares(); int minX = bufferedSize.width; int minY = bufferedSize.height; int maxX = 0; Modified: trunk/crossfire/src/cfeditor/gui/selectedsquare/CellRenderer.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/selectedsquare/CellRenderer.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/crossfire/src/cfeditor/gui/selectedsquare/CellRenderer.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -25,6 +25,7 @@ import cfeditor.CMainControl; import cfeditor.gameobject.ArchetypeSet; import cfeditor.gameobject.GameObject; +import cfeditor.map.MapArchObject; import java.awt.Component; import javax.swing.BorderFactory; import javax.swing.DefaultListCellRenderer; @@ -94,7 +95,7 @@ int indent = 0; for (;;) { - final GameObjectContainer<GameObject> env = arch.getContainer(); + final GameObjectContainer<GameObject, MapArchObject> env = arch.getContainer(); if (env == null || !(env instanceof GameObject)) { break; } Modified: trunk/crossfire/src/cfeditor/gui/selectedsquare/SelectedSquareControl.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/selectedsquare/SelectedSquareControl.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/crossfire/src/cfeditor/gui/selectedsquare/SelectedSquareControl.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -29,6 +29,7 @@ import cfeditor.CMainView; import cfeditor.IGUIConstants; import cfeditor.gameobject.GameObject; +import cfeditor.map.MapArchObject; import cfeditor.map.MapControl; import cfeditor.map.MapModel; import java.awt.Point; @@ -195,7 +196,7 @@ return; } - final MapSquare<GameObject> mapSquare = view.getCurrentMapSquare(); + final MapSquare<GameObject, MapArchObject> mapSquare = view.getCurrentMapSquare(); if (mapSquare == null) { return; } @@ -239,7 +240,7 @@ return; } - final MapSquare<GameObject> currentMapSquare = view.getCurrentMapSquare(); + final MapSquare<GameObject, MapArchObject> currentMapSquare = view.getCurrentMapSquare(); if (currentMapSquare == null) { return; } Modified: trunk/crossfire/src/cfeditor/gui/selectedsquare/SelectedSquareView.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/selectedsquare/SelectedSquareView.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/crossfire/src/cfeditor/gui/selectedsquare/SelectedSquareView.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -28,6 +28,7 @@ import cfeditor.CMainControl; import cfeditor.IGUIConstants; import cfeditor.gameobject.GameObject; +import cfeditor.map.MapArchObject; import cfeditor.map.MapControl; import java.awt.BorderLayout; import java.awt.Color; @@ -49,7 +50,6 @@ import net.sf.gridarta.gui.map.MapCursorListener; import net.sf.gridarta.gui.maptilelist.MapTileSelection; import net.sf.gridarta.gui.maptilelist.MapTileSelectionCache; -import net.sf.gridarta.map.MapArchObject; import net.sf.gridarta.map.MapModelEvent; import net.sf.gridarta.map.MapModelListener; import net.sf.gridarta.map.MapSquare; @@ -89,12 +89,12 @@ /** * The cache to store selections for each map control. */ - @NotNull private final MapTileSelectionCache<GameObject, MapControl> mapTileSelectionCache = new MapTileSelectionCache<GameObject, MapControl>(); + @NotNull private final MapTileSelectionCache<GameObject, MapArchObject, MapControl> mapTileSelectionCache = new MapTileSelectionCache<GameObject, MapArchObject, MapControl>(); /** * The currently selected map tile. */ - @Nullable private MapTileSelection<GameObject, MapControl> selectedMapTile = null; + @Nullable private MapTileSelection<GameObject, MapArchObject, MapControl> selectedMapTile = null; /** * Create a new instance. @@ -160,7 +160,7 @@ * @return the currently selected map square, or <code>null</code> if no * tile is selected */ - @Nullable public MapSquare<GameObject> getCurrentMapSquare() { + @Nullable public MapSquare<GameObject, MapArchObject> getCurrentMapSquare() { return selectedMapTile == null ? null : selectedMapTile.getMapSquare(); } @@ -212,7 +212,7 @@ */ private void refresh() { final MapControl mapControl; - final MapSquare<GameObject> mapSquare; + final MapSquare<GameObject, MapArchObject> mapSquare; final GameObject gameObject; if (selectedMapTile == null) { mapControl = null; @@ -318,7 +318,7 @@ mapControl.removeMapModelListener(this); mapControl.removeMapCursorListener(this); - final MapTileSelection<GameObject, MapControl> closedMapTile = mapTileSelectionCache.find(mapControl); + final MapTileSelection<GameObject, MapArchObject, MapControl> closedMapTile = mapTileSelectionCache.find(mapControl); if (selectedMapTile != null && selectedMapTile == closedMapTile) { if (setSelectedMapTile(null)) { refresh(); @@ -354,14 +354,14 @@ } /** {@inheritDoc} */ - public void mapSizeChanged(final MapModelEvent<GameObject> e) { + public void mapSizeChanged(final MapModelEvent<GameObject, MapArchObject> e) { if (selectedMapTile != null && selectedMapTile.getMapControl().getMapModel() == e.getMapModel() && selectedMapTile.validateMapSquare()) { refresh(); } } /** {@inheritDoc} */ - public void mapSquaresChanged(final MapModelEvent<GameObject> e) { + public void mapSquaresChanged(final MapModelEvent<GameObject, MapArchObject> e) { if (selectedMapTile == null) { return; } @@ -375,7 +375,7 @@ } /** {@inheritDoc} */ - public void mapObjectsChanged(final MapModelEvent<GameObject> e) { + public void mapObjectsChanged(final MapModelEvent<GameObject, MapArchObject> e) { if (selectedMapTile == null) { return; } @@ -401,7 +401,7 @@ * * @return <code>true</code> if the selected map tile has changed */ - private boolean setSelectedMapTile(@Nullable final MapTileSelection<GameObject, MapControl> mapTileSelection) { + private boolean setSelectedMapTile(@Nullable final MapTileSelection<GameObject, MapArchObject, MapControl> mapTileSelection) { if (mapTileSelection == selectedMapTile) { return false; } @@ -458,7 +458,7 @@ } if (gameObject != null) { - final MapSquare<GameObject> mapSquare = gameObject.getTopContainer().getMapSquare(); + final MapSquare<GameObject, MapArchObject> mapSquare = gameObject.getTopContainer().getMapSquare(); if (mapSquare == null) { log.warn("setSelectedGameObject: gameObject " + gameObject + " is not part of a map"); return; Modified: trunk/crossfire/src/cfeditor/io/CMapWriter.java =================================================================== --- trunk/crossfire/src/cfeditor/io/CMapWriter.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/crossfire/src/cfeditor/io/CMapWriter.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -70,7 +70,7 @@ * @throws IOException in case of I/O problems */ @Override protected void writeGameObject(@NotNull final GameObject gameObject, final int x, final int y) throws IOException { - final Archetype<GameObject> archetype = gameObject.getArchetype(); + final Archetype<GameObject, MapArchObject> archetype = gameObject.getArchetype(); // Collect all fields to write. final Map<String, String> fields = new TreeMap<String, String>(keyOrderComparator); // String key -> String value Modified: trunk/daimonin/src/daieditor/CFArchTypeList.java =================================================================== --- trunk/daimonin/src/daieditor/CFArchTypeList.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/daimonin/src/daieditor/CFArchTypeList.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -27,6 +27,7 @@ import daieditor.gameobject.GameObject; import daieditor.gameobject.match.GameObjectMatchers; import daieditor.gameobject.match.NamedGameObjectMatcher; +import daieditor.map.MapArchObject; import java.awt.Component; import java.io.File; import java.io.IOException; @@ -57,7 +58,7 @@ * @author <a href="mailto:and...@gm...">Andreas Vogl</a> * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ -public final class CFArchTypeList extends net.sf.gridarta.CFArchTypeList<CFArchType, GameObject> { +public final class CFArchTypeList extends net.sf.gridarta.CFArchTypeList<CFArchType, GameObject, MapArchObject> { private static final Logger log = Logger.getLogger(CFArchTypeList.class); Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/daimonin/src/daieditor/CMainControl.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -135,7 +135,7 @@ * @author Andreas Kirschbaum * @fixme I'm 2200 lines long, therefor I suck. */ -public final class CMainControl extends AbstractMainControl<GameObject> implements ThrowableHandler, MapModelListener<GameObject, MapArchObject> { +public final class CMainControl extends AbstractMainControl<GameObject, MapArchObject> implements ThrowableHandler, MapModelListener<GameObject, MapArchObject> { /** Action Factory. */ private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("daieditor"); @@ -1991,7 +1991,7 @@ /** {@inheritDoc} */ public void mapSquaresChanged(final MapModelEvent e) { if (prefs.getBoolean(PREFS_VALIDATOR_AUTO, PREFS_VALIDATOR_AUTO_DEFAULT)) { - final MapSquare<GameObject>[] squares = e.getSquares(); + final MapSquare<GameObject, MapArchObject>[] squares = e.getSquares(); if (squares != null) { final ErrorCollector errorCollector = new DefaultErrorCollector(); validators.validate(squares, errorCollector); Modified: trunk/daimonin/src/daieditor/CMapViewBasic.java =================================================================== --- trunk/daimonin/src/daieditor/CMapViewBasic.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/daimonin/src/daieditor/CMapViewBasic.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -108,7 +108,7 @@ @NotNull private final MapGrid mapGrid; /** The MapSquares that are known to contain errors. */ - private Map<MapSquare<? extends net.sf.gridarta.gameobject.GameObject>, ValidationError> erraneousMapSquares = new HashMap<MapSquare<? extends net.sf.gridarta.gameobject.GameObject>, ValidationError>(); + private Map<MapSquare<? extends net.sf.gridarta.gameobject.GameObject, ? extends net.sf.gridarta.map.MapArchObject>, ValidationError> erraneousMapSquares = new HashMap<MapSquare<? extends net.sf.gridarta.gameobject.GameObject, ? extends net.sf.gridarta.map.MapArchObject>, ValidationError>(); /** The ArchObjects that are known to contain errors. */ private Map<net.sf.gridarta.gameobject.GameObject,ValidationError> erraneousArchObjects = new HashMap<net.sf.gridarta.gameobject.GameObject,ValidationError>(); @@ -246,7 +246,7 @@ * @return cursor square or <code>null</code> if no current cursor * @see #getCursorPosition() */ - @Nullable public MapSquare<GameObject> getCursorSquare() { + @Nullable public MapSquare<GameObject, MapArchObject> getCursorSquare() { try { return mapModel.getMapSquare(getCursorPosition()); } catch (final ArrayIndexOutOfBoundsException e) { @@ -284,8 +284,8 @@ * Get the selected squares. * @return selected squares */ - public List<MapSquare<GameObject>> getSelectedSquares() { - final List<MapSquare<GameObject>> selection = new ArrayList<MapSquare<GameObject>>(); + public List<MapSquare<GameObject, MapArchObject>> getSelectedSquares() { + final List<MapSquare<GameObject, MapArchObject>> selection = new ArrayList<MapSquare<GameObject, MapArchObject>>(); final Size2D mapSize = mapModel.getMapSize(); final Point pos = new Point(); for (pos.x = 0; pos.x < mapSize.getWidth(); pos.x++) { @@ -389,7 +389,7 @@ erraneousArchObjects.clear(); mapGrid.clearErrors(); for (ValidationError validationError : errors.getErrors()) { - final MapSquare<? extends net.sf.gridarta.gameobject.GameObject> mapSquare = validationError.getMapSquare(); + final MapSquare<? extends net.sf.gridarta.gameobject.GameObject, ? extends net.sf.gridarta.map.MapArchObject> mapSquare = validationError.getMapSquare(); final net.sf.gridarta.gameobject.GameObject archObject = validationError.getGameObject(); if (mapSquare != null) { erraneousMapSquares.put(mapSquare, validationError); Modified: trunk/daimonin/src/daieditor/CopyBuffer.java =================================================================== --- trunk/daimonin/src/daieditor/CopyBuffer.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/daimonin/src/daieditor/CopyBuffer.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -140,7 +140,7 @@ mapControl.getMapModel().beginTransaction("Cut / Clear"); // TODO: I18N/L10N final HashSet<GameObject> gameObjectsToDelete = new HashSet<GameObject>(); - for (final MapSquare<GameObject> square : mapControl.getMapViewFrame().getView().getSelectedSquares()) { + for (final MapSquare<GameObject, MapArchObject> square : mapControl.getMapViewFrame().getView().getSelectedSquares()) { final int posx = square.getMapX(); final int posy = square.getMapY(); for (final GameObject gameObject : square) { @@ -184,7 +184,7 @@ mapControl.getMapModel().beginTransaction("Paste"); // TODO: I18N/L10N final Point pos = new Point(); assert copyMap != null; - for (final MapSquare<GameObject> square : copyMap) { + for (final MapSquare<GameObject, MapArchObject> square : copyMap) { pos.setLocation(startp.x + square.getMapX(), startp.y + square.getMapY()); if (mapControl.isPointValid(pos)) { for (final GameObject gameObject : square) { @@ -196,7 +196,7 @@ } assert copyMapCtrl != null; - for (final MapSquare<GameObject> square : copyMapCtrl.getMapModel()) { + for (final MapSquare<GameObject, MapArchObject> square : copyMapCtrl.getMapModel()) { pos.setLocation(startp); pos.translate(square.getMapX(), square.getMapY()); if (mapControl.isPointValid(pos)) { @@ -311,11 +311,11 @@ return null; } final MapViewIFrame mapViewIFrame = mapControl.getMapViewFrame(); - final Iterable<MapSquare<GameObject>> mapSquares; + final Iterable<MapSquare<GameObject, MapArchObject>> mapSquares; if (mapViewIFrame == null) { mapSquares = mapControl.getAllSquares(); } else { - final List<MapSquare<GameObject>> selectedMapSquares = mapViewIFrame.getView().getSelectedSquares(); + final List<MapSquare<GameObject, MapArchObject>> selectedMapSquares = mapViewIFrame.getView().getSelectedSquares(); if (selectedMapSquares.isEmpty()) { mapSquares = mapControl.getAllSquares(); } else { @@ -323,7 +323,7 @@ } } final List<GameObject> objects = new ArrayList<GameObject>(max); - for (final MapSquare<GameObject> mapSquare : mapSquares) { + for (final MapSquare<GameObject, MapArchObject> mapSquare : mapSquares) { for (final GameObject node : mapSquare) { if (!node.isTail()) { objects.add(node); Modified: trunk/daimonin/src/daieditor/MapViewIFrame.java =================================================================== --- trunk/daimonin/src/daieditor/MapViewIFrame.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/daimonin/src/daieditor/MapViewIFrame.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -25,6 +25,7 @@ package daieditor; import daieditor.gameobject.GameObject; +import daieditor.map.MapArchObject; import daieditor.map.MapControl; import java.awt.BorderLayout; import java.awt.Image; @@ -40,7 +41,6 @@ import static javax.swing.KeyStroke.getKeyStroke; import net.sf.gridarta.gui.map.MapCursorListener; import net.sf.gridarta.gui.map.MapGridListener; -import net.sf.gridarta.map.MapArchObject; import net.sf.gridarta.map.MapControlListener; import net.sf.gridarta.map.MapModelEvent; import net.sf.gridarta.map.MapModelListener; Modified: trunk/daimonin/src/daieditor/ReplaceDialog.java =================================================================== --- trunk/daimonin/src/daieditor/ReplaceDialog.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/daimonin/src/daieditor/ReplaceDialog.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -26,6 +26,7 @@ package daieditor; import daieditor.gameobject.GameObject; +import daieditor.map.MapArchObject; import daieditor.map.MapControl; import java.awt.FlowLayout; import java.awt.event.ItemEvent; @@ -319,7 +320,7 @@ int replaceCount = 0; final int replaceListSize = replaceList == null ? 0 : replaceList.size(); mapControl.getMapModel().beginTransaction("Replace"); // TODO: I18N/L10N - for (final MapSquare<GameObject> square : entireMap ? mapControl.getMapModel() : mapViewIFrame.getView().getSelectedSquares()) { + for (final MapSquare<GameObject, MapArchObject> square : entireMap ? mapControl.getMapModel() : mapViewIFrame.getView().getSelectedSquares()) { for (final GameObject node : square) { if (!node.isMulti() && (matchCriteria == MATCH_ARCH_NAME && node.getArchetypeName() != null && node.getArchetypeName().equalsIgnoreCase(matchString) || matchCriteria == MATCH_OBJ_NAME && node.getBestName().equalsIgnoreCase(matchString))) { if (replaceListSize > 0 && !deleteOnly) { Modified: trunk/daimonin/src/daieditor/gameobject/ArchetypeParser.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/ArchetypeParser.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/daimonin/src/daieditor/gameobject/ArchetypeParser.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -27,6 +27,7 @@ import daieditor.CMainControl; import daieditor.MultiPositionData; +import daieditor.map.MapArchObject; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; @@ -49,7 +50,7 @@ * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ @SuppressWarnings({"HardcodedFileSeparator"}) -public final class ArchetypeParser extends AbstractArchetypeParser<GameObject> { +public final class ArchetypeParser extends AbstractArchetypeParser<GameObject, MapArchObject> { /** Logger. */ private static final Logger log = Logger.getLogger(ArchetypeParser.class); Modified: trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/daimonin/src/daieditor/gameobject/ArchetypeSet.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -34,6 +34,7 @@ import daieditor.gameobject.face.DuplicateFaceException; import daieditor.gameobject.face.FaceObjects; import daieditor.gui.PickmapChooser; +import daieditor.map.MapArchObject; import java.awt.BorderLayout; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -72,7 +73,7 @@ * @author <a href="mailto:and...@gm...">Andreas Vogl</a> * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ -public final class ArchetypeSet extends AbstractArchetypeSet<GameObject> { +public final class ArchetypeSet extends AbstractArchetypeSet<GameObject, MapArchObject> { private static final Logger log = Logger.getLogger(ArchetypeSet.class); Modified: trunk/daimonin/src/daieditor/gameobject/GameObject.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/GameObject.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/daimonin/src/daieditor/gameobject/GameObject.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -31,6 +31,7 @@ import daieditor.gameobject.anim.AnimationObject; import daieditor.gameobject.anim.AnimationObjects; import daieditor.gui.GameObjectAttributesPanel; +import daieditor.map.MapArchObject; import java.io.Serializable; import javax.swing.ImageIcon; import javax.swing.JList; @@ -53,7 +54,7 @@ * normal arches. * @todo this class is not always the best place for multipart object handling, see also {@link GameObjectContainer} for issues about this */ -public final class GameObject /*extends AbstractNamedObject*/ extends net.sf.gridarta.gameobject.GameObject<GameObject> implements Cloneable, Serializable { +public final class GameObject /*extends AbstractNamedObject*/ extends net.sf.gridarta.gameobject.GameObject<GameObject, MapArchObject> implements Cloneable, Serializable { /** Logger. */ private static final Logger log = Logger.getLogger(GameObject.class); Modified: trunk/daimonin/src/daieditor/gui/ArchetypeChooser.java =================================================================== --- trunk/daimonin/src/daieditor/gui/ArchetypeChooser.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/daimonin/src/daieditor/gui/ArchetypeChooser.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -27,6 +27,7 @@ import daieditor.CMainControl; import daieditor.gameobject.GameObject; +import daieditor.map.MapArchObject; import java.awt.Component; import javax.swing.DefaultListCellRenderer; import javax.swing.ImageIcon; @@ -42,7 +43,7 @@ * @author unknown * @author Andreas Kirschbaum */ -public final class ArchetypeChooser extends net.sf.gridarta.gui.ArchetypeChooser<GameObject> { +public final class ArchetypeChooser extends net.sf.gridarta.gui.ArchetypeChooser<GameObject, MapArchObject> { private static final Logger log = Logger.getLogger(ArchetypeChooser.class); Modified: trunk/daimonin/src/daieditor/gui/GameObjectAttributesDialog.java =================================================================== --- trunk/daimonin/src/daieditor/gui/GameObjectAttributesDialog.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/daimonin/src/daieditor/gui/GameObjectAttributesDialog.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -28,6 +28,7 @@ import daieditor.CFTreasureListTree; import daieditor.CMainControl; import daieditor.gameobject.GameObject; +import daieditor.map.MapArchObject; import java.util.List; import javax.swing.ImageIcon; import javax.swing.JCheckBox; @@ -52,7 +53,7 @@ * @author <a href="mailto:ch...@ri...">Christian Hujer</a> * @fixme I suck */ -public final class GameObjectAttributesDialog extends AbstractGameObjectAttributesDialog<GameObject> { +public final class GameObjectAttributesDialog extends AbstractGameObjectAttributesDialog<GameObject, MapArchObject> { /** Logger. */ private static final Logger log = Logger.getLogger(GameObjectAttributesDialog.class); Modified: trunk/daimonin/src/daieditor/gui/InsertionObjectChooser.java =================================================================== --- trunk/daimonin/src/daieditor/gui/InsertionObjectChooser.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/daimonin/src/daieditor/gui/InsertionObjectChooser.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -29,6 +29,7 @@ import daieditor.IGUIConstants; import daieditor.gameobject.GameObject; import daieditor.gui.map.tools.ToolPalette; +import daieditor.map.MapArchObject; import java.awt.BorderLayout; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; @@ -55,7 +56,7 @@ * @author <a href="mailto:ch...@ri...">Christian Hujer</a> * @author Andreas Kirschbaum */ -public final class InsertionObjectChooser extends JPanel implements net.sf.gridarta.gui.InsertionObjectChooser<GameObject> { +public final class InsertionObjectChooser extends JPanel implements net.sf.gridarta.gui.InsertionObjectChooser<GameObject, MapArchObject> { /** Serial Version UID. */ private static final long serialVersionUID = 1L; Modified: trunk/daimonin/src/daieditor/gui/ObjectChoiceDisplay.java =================================================================== --- trunk/daimonin/src/daieditor/gui/ObjectChoiceDisplay.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/daimonin/src/daieditor/gui/ObjectChoiceDisplay.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -27,6 +27,7 @@ import daieditor.CMainControl; import daieditor.ReplaceDialog; import daieditor.gameobject.GameObject; +import daieditor.map.MapArchObject; import java.awt.Color; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; @@ -120,7 +121,7 @@ final GameObject headObject = gameObject.getHead(); String objName = headObject.getObjName(); if (objName == null || objName.length() == 0) { - final Archetype<GameObject> archetype = headObject.getArchetype(); + final Archetype<GameObject, MapArchObject> archetype = headObject.getArchetype(); if (archetype == null || archetype == headObject) { objName = null; } else if ((objName = archetype.getObjName()) != null && objName.length() != 0) { Modified: trunk/daimonin/src/daieditor/gui/map/DefaultLevelRenderer.java =================================================================== --- trunk/daimonin/src/daieditor/gui/map/DefaultLevelRenderer.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/daimonin/src/daieditor/gui/map/DefaultLevelRenderer.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -28,6 +28,7 @@ import daieditor.IGUIConstants; import daieditor.MultiPositionData; import daieditor.gameobject.GameObject; +import daieditor.map.MapArchObject; import daieditor.map.MapControl; import daieditor.map.MapModel; import daieditor.map.validation.ValidationError; @@ -89,7 +90,7 @@ private final MapGrid mapGrid; /** The MapSquares that are known to contain errors. */ - private Map<MapSquare<? extends net.sf.gridarta.gameobject.GameObject>,ValidationError> erraneousMapSquares; + private Map<MapSquare<? extends net.sf.gridarta.gameobject.GameObject, ? extends net.sf.gridarta.map.MapArchObject>, ValidationError> erraneousMapSquares; /** Used to avoid creation millions of points. */ private final Point tmpPoint = new Point(); @@ -165,7 +166,7 @@ return null; } if (mapGrid.hasError(mapLocation)) { - final MapSquare<GameObject> mapSquare = mapModel.getMapSquare(mapLocation); + final MapSquare<GameObject, MapArchObject> mapSquare = mapModel.getMapSquare(mapLocation); if (erraneousMapSquares.containsKey(mapSquare)) { final ValidationError error = erraneousMapSquares.get(mapSquare); @@ -257,7 +258,7 @@ int ystart = origin.y + (pos.y + rec.x) * IGUIConstants.TILE_ISO_YLEN2; for (pos.x = rec.x; pos.x < endPos.x; pos.x++) { if (grfx.hitClip(xstart, ystart - (IGUIConstants.TILE_ISO_YLEN << 2), IGUIConstants.TILE_ISO_XLEN, IGUIConstants.TILE_ISO_YLEN * 5)) { - final MapSquare<GameObject> square = mapModel.getMapSquare(pos); + final MapSquare<GameObject, MapArchObject> square = mapModel.getMapSquare(pos); if (square.isEmpty()) { // empty square: Draw unknown tile icon if not a pickmap if (!isPickmap) { @@ -481,7 +482,7 @@ * Sets the MapSquares that are known to contain errors. * @param erraneousMapSquares the MapSquares that are known to contain errors */ - public void setErraneousMapSquares(final Map<MapSquare<? extends net.sf.gridarta.gameobject.GameObject>, ValidationError> erraneousMapSquares) { + public void setErraneousMapSquares(final Map<MapSquare<? extends net.sf.gridarta.gameobject.GameObject, ? extends net.sf.gridarta.map.MapArchObject>, ValidationError> erraneousMapSquares) { this.erraneousMapSquares = erraneousMapSquares; } Modified: trunk/daimonin/src/daieditor/gui/map/SimpleLevelRenderer.java =================================================================== --- trunk/daimonin/src/daieditor/gui/map/SimpleLevelRenderer.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/daimonin/src/daieditor/gui/map/SimpleLevelRenderer.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -29,6 +29,7 @@ import daieditor.IGUIConstants; import daieditor.MultiPositionData; import daieditor.gameobject.GameObject; +import daieditor.map.MapArchObject; import daieditor.map.MapModel; import java.awt.Color; import java.awt.Graphics; @@ -112,7 +113,7 @@ int ystart = origin.y + (pos.y + rec.x) * IGUIConstants.TILE_ISO_YLEN2; for (pos.x = rec.x; pos.x < endPos.x; pos.x++) { if (grfx.hitClip(xstart, ystart - (IGUIConstants.TILE_ISO_YLEN << 2), IGUIConstants.TILE_ISO_XLEN, IGUIConstants.TILE_ISO_YLEN * 5)) { - final MapSquare<GameObject> square = mapModel.getMapSquare(pos); + final MapSquare<GameObject, MapArchObject> square = mapModel.getMapSquare(pos); if (square.isEmpty()) { // empty square: Draw unknown tile icon if not a pickmap // grfx.drawImage(unknownTileIcon.getImage(), xstart, ystart, unknownTileIcon.getImageObserver()); Modified: trunk/daimonin/src/daieditor/gui/map/tools/DeletionTool.java =================================================================== --- trunk/daimonin/src/daieditor/gui/map/tools/DeletionTool.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/daimonin/src/daieditor/gui/map/tools/DeletionTool.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -3,6 +3,7 @@ import daieditor.CMainControl; import daieditor.gameobject.GameObject; import daieditor.gui.map.event.MouseOpEvent; +import daieditor.map.MapArchObject; import daieditor.map.MapControl; import java.awt.Component; import java.awt.Point; @@ -68,7 +69,7 @@ */ private void deleteArch(final Point mapLoc, final MapControl mapControl) { GameObject delArch = null; - final MapSquare<GameObject> mapSquare = mapControl.getMapModel().getMapSquare(mapLoc); + final MapSquare<GameObject, MapArchObject> mapSquare = mapControl.getMapModel().getMapSquare(mapLoc); for (final GameObject searchArch : deleteBelow ? mapSquare : mapSquare.reverse()) { if (CMainControl.getInstance().isTileEdit(searchArch)) { delArch = searchArch; Modified: trunk/daimonin/src/daieditor/gui/selectedsquare/SelectedSquareControl.java =================================================================== --- trunk/daimonin/src/daieditor/gui/selectedsquare/SelectedSquareControl.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/daimonin/src/daieditor/gui/selectedsquare/SelectedSquareControl.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -31,6 +31,7 @@ import daieditor.CopyBuffer; import daieditor.gameobject.GameObject; import daieditor.gui.PickmapChooser; +import daieditor.map.MapArchObject; import daieditor.map.MapControl; import daieditor.map.MapModel; import java.awt.Point; @@ -194,7 +195,7 @@ return; } - final MapSquare<GameObject> mapSquare = view.getCurrentMapSquare(); + final MapSquare<GameObject, MapArchObject> mapSquare = view.getCurrentMapSquare(); if (mapSquare == null) { return; } @@ -243,7 +244,7 @@ return; } - final MapSquare<GameObject> currentMapSquare = view.getCurrentMapSquare(); + final MapSquare<GameObject, MapArchObject> currentMapSquare = view.getCurrentMapSquare(); if (currentMapSquare == null) { return; } Modified: trunk/daimonin/src/daieditor/gui/selectedsquare/SelectedSquareView.java =================================================================== --- trunk/daimonin/src/daieditor/gui/selectedsquare/SelectedSquareView.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/daimonin/src/daieditor/gui/selectedsquare/SelectedSquareView.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -30,6 +30,7 @@ import daieditor.CMainControl; import daieditor.IGUIConstants; import daieditor.gameobject.GameObject; +import daieditor.map.MapArchObject; import daieditor.map.MapControl; import java.awt.BorderLayout; import java.awt.Color; @@ -52,7 +53,6 @@ import net.sf.gridarta.gui.map.MapCursorListener; import net.sf.gridarta.gui.maptilelist.MapTileSelection; import net.sf.gridarta.gui.maptilelist.MapTileSelectionCache; -import net.sf.gridarta.map.MapArchObject; import net.sf.gridarta.map.MapModelEvent; import net.sf.gridarta.map.MapModelListener; import net.sf.gridarta.map.MapSquare; @@ -93,12 +93,12 @@ /** * The cache to store selections for each map control. */ - @NotNull private final MapTileSelectionCache<GameObject, MapControl> mapTileSelectionCache = new MapTileSelectionCache<GameObject, MapControl>(); + @NotNull private final MapTileSelectionCache<GameObject, MapArchObject, MapControl> mapTileSelectionCache = new MapTileSelectionCache<GameObject, MapArchObject, MapControl>(); /** * The currently selected map tile. */ - @Nullable private MapTileSelection<GameObject, MapControl> selectedMapTile = null; + @Nullable private MapTileSelection<GameObject, MapArchObject, MapControl> selectedMapTile = null; /** * Create a new instance. @@ -163,7 +163,7 @@ * @return the currently selected map square, or <code>null</code> if no * tile is selected */ - @Nullable public MapSquare<GameObject> getCurrentMapSquare() { + @Nullable public MapSquare<GameObject, MapArchObject> getCurrentMapSquare() { return selectedMapTile == null ? null : selectedMapTile.getMapSquare(); } @@ -215,7 +215,7 @@ */ private void refresh() { final MapControl mapControl; - final MapSquare<GameObject> mapSquare; + final MapSquare<GameObject, MapArchObject> mapSquare; final GameObject gameObject; if (selectedMapTile == null) { mapControl = null; @@ -321,7 +321,7 @@ mapControl.removeMapModelListener(this); mapControl.removeMapCursorListener(this); - final MapTileSelection<GameObject, MapControl> closedMapTile = mapTileSelectionCache.find(mapControl); + final MapTileSelection<GameObject, MapArchObject, MapControl> closedMapTile = mapTileSelectionCache.find(mapControl); if (selectedMapTile != null && selectedMapTile == closedMapTile) { if (setSelectedMapTile(null)) { refresh(); @@ -357,14 +357,14 @@ } /** {@inheritDoc} */ - public void mapSizeChanged(final MapModelEvent<GameObject> e) { + public void mapSizeChanged(final MapModelEvent<GameObject, MapArchObject> e) { if (selectedMapTile != null && selectedMapTile.getMapControl().getMapModel() == e.getMapModel() && selectedMapTile.validateMapSquare()) { refresh(); } } /** {@inheritDoc} */ - public void mapSquaresChanged(final MapModelEvent<GameObject> e) { + public void mapSquaresChanged(final MapModelEvent<GameObject, MapArchObject> e) { if (selectedMapTile == null) { return; } @@ -378,7 +378,7 @@ } /** {@inheritDoc} */ - public void mapObjectsChanged(final MapModelEvent<GameObject> e) { + public void mapObjectsChanged(final MapModelEvent<GameObject, MapArchObject> e) { if (selectedMapTile == null) { return; } @@ -404,7 +404,7 @@ * * @return <code>true</code> if the selected map tile has changed */ - private boolean setSelectedMapTile(@Nullable final MapTileSelection<GameObject, MapControl> mapTileSelection) { + private boolean setSelectedMapTile(@Nullable final MapTileSelection<GameObject, MapArchObject, MapControl> mapTileSelection) { if (mapTileSelection == selectedMapTile) { return false; } @@ -461,7 +461,7 @@ } if (gameObject != null) { - final MapSquare<GameObject> mapSquare = gameObject.getTopContainer().getMapSquare(); + final MapSquare<GameObject, MapArchObject> mapSquare = gameObject.getTopContainer().getMapSquare(); if (mapSquare == null) { log.warn("setSelectedGameObject: gameObject " + gameObject + " is not part of a map"); return; Modified: trunk/daimonin/src/daieditor/io/CMapWriter.java =================================================================== --- trunk/daimonin/src/daieditor/io/CMapWriter.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/daimonin/src/daieditor/io/CMapWriter.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -72,7 +72,7 @@ * @throws IOException in case of I/O problems */ @Override protected void writeGameObject(@NotNull final GameObject gameObject, final int x, final int y) throws IOException { - final Archetype<GameObject> archetype = gameObject.getArchetype(); + final Archetype<GameObject, MapArchObject> archetype = gameObject.getArchetype(); // ok, we start with the standard parts... this is valid for all types format.format("arch %s\n", gameObject.getArchetypeName()); Modified: trunk/daimonin/src/daieditor/map/DefaultMapModel.java =================================================================== --- trunk/daimonin/src/daieditor/map/DefaultMapModel.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/daimonin/src/daieditor/map/DefaultMapModel.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -94,7 +94,7 @@ * {@inheritDoc} * @todo This method should be moved to the view. */ - @Deprecated @Nullable public MapSquare<GameObject> getMouseRightPosObject() { + @Deprecated @Nullable public MapSquare<GameObject, MapArchObject> getMouseRightPosObject() { final Point p = mapControl.getMapCursor().getLocation(); return p == null ? null : mapGrid[p.x][p.y]; } Modified: trunk/daimonin/src/daieditor/map/MapControl.java =================================================================== --- trunk/daimonin/src/daieditor/map/MapControl.java 2007-01-06 20:58:22 UTC (rev 1461) +++ trunk/daimonin/src/daieditor/map/MapControl.java 2007-01-07 00:07:40 UTC (rev 1462) @@ -646,7 +646,7 @@ * Get Iterable of all MapSquares. * @return Iterable of all MapSquares */ - public Iterable<MapSquare<GameObject>> getAllSquares() { + public Iterable<MapSquare<GameObject, MapArchObject>> getAllSquares() { return mapModel; } Modified: trunk/daimonin/src/daieditor/map/MapModel.java =================================================================== -... [truncated message content] |
From: <aki...@us...> - 2007-01-07 00:24:17
|
Revision: 1463 http://svn.sourceforge.net/gridarta/?rev=1463&view=rev Author: akirschbaum Date: 2007-01-06 16:24:16 -0800 (Sat, 06 Jan 2007) Log Message: ----------- Fix some unchecked warnings. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java trunk/daimonin/src/daieditor/gui/GameObjectAttributesDialog.java trunk/src/app/net/sf/gridarta/CFArchType.java trunk/src/app/net/sf/gridarta/CFArchTypeList.java trunk/src/app/net/sf/gridarta/gui/AbstractGameObjectAttributesDialog.java Modified: trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java 2007-01-07 00:07:40 UTC (rev 1462) +++ trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java 2007-01-07 00:24:16 UTC (rev 1463) @@ -53,7 +53,7 @@ * @author <a href="mailto:ch...@ri...">Christian Hujer</a> * @fixme I suck */ -public final class GameObjectAttributesDialog extends AbstractGameObjectAttributesDialog<GameObject, MapArchObject> { +public final class GameObjectAttributesDialog extends AbstractGameObjectAttributesDialog<CFArchType, GameObject, MapArchObject> { /** Logger. */ private static final Logger log = Logger.getLogger(GameObjectAttributesDialog.class); Modified: trunk/daimonin/src/daieditor/gui/GameObjectAttributesDialog.java =================================================================== --- trunk/daimonin/src/daieditor/gui/GameObjectAttributesDialog.java 2007-01-07 00:07:40 UTC (rev 1462) +++ trunk/daimonin/src/daieditor/gui/GameObjectAttributesDialog.java 2007-01-07 00:24:16 UTC (rev 1463) @@ -53,7 +53,7 @@ * @author <a href="mailto:ch...@ri...">Christian Hujer</a> * @fixme I suck */ -public final class GameObjectAttributesDialog extends AbstractGameObjectAttributesDialog<GameObject, MapArchObject> { +public final class GameObjectAttributesDialog extends AbstractGameObjectAttributesDialog<CFArchType, GameObject, MapArchObject> { /** Logger. */ private static final Logger log = Logger.getLogger(GameObjectAttributesDialog.class); Modified: trunk/src/app/net/sf/gridarta/CFArchType.java =================================================================== --- trunk/src/app/net/sf/gridarta/CFArchType.java 2007-01-07 00:07:40 UTC (rev 1462) +++ trunk/src/app/net/sf/gridarta/CFArchType.java 2007-01-07 00:24:16 UTC (rev 1463) @@ -6,6 +6,7 @@ import java.util.Map; import net.sf.gridarta.gameobject.ArchAttribType; import net.sf.gridarta.gameobject.GameObject; +import net.sf.gridarta.map.MapArchObject; import net.sf.japi.swing.ActionFactory; import net.sf.japi.xml.NodeListIterator; import org.apache.log4j.Logger; @@ -112,7 +113,7 @@ * @throws ArchTypeParseException In case <var>root</var> is malformed or contains bogus data. * @todo I'm sucking slow, improve me */ - public boolean load(final Element root, final CFArchTypeList tlist) throws ArchTypeParseException { + public boolean load(final Element root, final CFArchTypeList<? extends CFArchType, ? extends GameObject, ? extends MapArchObject> tlist) throws ArchTypeParseException { // this vector is used to store a temporare linked list of attributes final List<CFArchAttrib> attrList = new ArrayList<CFArchAttrib>(); @@ -185,7 +186,7 @@ throw new ArchTypeParseException("In '" + XML_IGNORE + "' section of type " + typeName + ": ignore_list missing 'name'."); } else if (tlist.getIgnoreListTable().containsKey(a1.getValue().trim())) { // just copy everything from ignorelist to this ignore section - final List<String> ignlist = (List<String>) tlist.getIgnoreListTable().get(a1.getValue().trim()); + final List<String> ignlist = tlist.getIgnoreListTable().get(a1.getValue().trim()); for (final String ignItem : ignlist) { ignoreTable.put(ignItem, ""); } @@ -273,7 +274,7 @@ if (importName != null) { // search through all known types, looking for import type net.sf.gridarta.CFArchType impType = null; - for (final net.sf.gridarta.CFArchType archType : (Iterable<net.sf.gridarta.CFArchType>) tlist) { + for (final net.sf.gridarta.CFArchType archType : tlist) { if (archType == this) { continue; } Modified: trunk/src/app/net/sf/gridarta/CFArchTypeList.java =================================================================== --- trunk/src/app/net/sf/gridarta/CFArchTypeList.java 2007-01-07 00:07:40 UTC (rev 1462) +++ trunk/src/app/net/sf/gridarta/CFArchTypeList.java 2007-01-07 00:24:16 UTC (rev 1463) @@ -306,9 +306,9 @@ * @return the <code>CFArchType</code> that matches, * or the first (misc) type if no match is found. */ - public abstract CFArchType getTypeByName(final String typeName); + public abstract T getTypeByName(final String typeName); // TODO: Javadoc - @Nullable public abstract CFArchType getType(@NotNull final G gameObject); + @Nullable public abstract T getType(@NotNull final G gameObject); } // class CFArchTypeList Modified: trunk/src/app/net/sf/gridarta/gui/AbstractGameObjectAttributesDialog.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/AbstractGameObjectAttributesDialog.java 2007-01-07 00:07:40 UTC (rev 1462) +++ trunk/src/app/net/sf/gridarta/gui/AbstractGameObjectAttributesDialog.java 2007-01-07 00:24:16 UTC (rev 1463) @@ -83,7 +83,7 @@ * Common base class for game object attributes dialogs. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ -public abstract class AbstractGameObjectAttributesDialog<G extends GameObject<G, A>, A extends MapArchObject> extends JOptionPane implements FocusListener { +public abstract class AbstractGameObjectAttributesDialog<T extends CFArchType, G extends GameObject<G, A>, A extends MapArchObject> extends JOptionPane implements FocusListener { /** Logger. */ private static final Logger log = Logger.getLogger(AbstractGameObjectAttributesDialog.class); @@ -97,7 +97,7 @@ public static final int TEXTFIELD_COLUMNS = 18; /** Reference to the list of CFArchTypes. */ - protected final CFArchTypeList archTypeList; + protected final CFArchTypeList<T, G, A> archTypeList; /** Reference to MainControl. */ protected final MainControl mainControl; @@ -113,7 +113,7 @@ protected final Archetype<G, A> archetype; - protected CFArchType type; // reference to the type data + protected T type; // reference to the type data // this differs from the GameObject if the type is undefined private int listNr; // the position of this type in the type list @@ -154,7 +154,7 @@ * @param gameObject GameObject to show dialog for. * @param mainControl MainControl, for retrieving AnimationObjects, FaceObjects etc.. */ - protected AbstractGameObjectAttributesDialog(final CFArchTypeList archTypeList, @NotNull final G gameObject, @NotNull final MainControl mainControl) { + protected AbstractGameObjectAttributesDialog(final CFArchTypeList<T, G, A> archTypeList, @NotNull final G gameObject, @NotNull final MainControl mainControl) { this.archTypeList = archTypeList; this.gameObject = gameObject.getHead(); this.mainControl = mainControl; @@ -216,7 +216,7 @@ // read all type names int i = 0; - for (final CFArchType tmp : (Iterable<CFArchType>) archTypeList) { + for (final T tmp : archTypeList) { namelist[i++] = " " + tmp.getTypeName(); } @@ -1358,7 +1358,7 @@ } else if (e.getStateChange() == ItemEvent.SELECTED && !e.getItem().equals(deselected)) { // new type was selected // first, get new type structure - final CFArchType newType = archTypeList.getTypeByName((String) e.getItem()); + final T newType = archTypeList.getTypeByName((String) e.getItem()); frame.typesel.hidePopup(); frame.update(frame.getGraphics()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2007-01-07 00:40:00
|
Revision: 1466 http://svn.sourceforge.net/gridarta/?rev=1466&view=rev Author: akirschbaum Date: 2007-01-06 16:40:00 -0800 (Sat, 06 Jan 2007) Log Message: ----------- Fix some unchecked warnings. Modified Paths: -------------- trunk/crossfire/src/cfeditor/map/MapControl.java trunk/daimonin/src/daieditor/map/MapControl.java trunk/src/app/net/sf/gridarta/map/MapControl.java Modified: trunk/crossfire/src/cfeditor/map/MapControl.java =================================================================== --- trunk/crossfire/src/cfeditor/map/MapControl.java 2007-01-07 00:30:02 UTC (rev 1465) +++ trunk/crossfire/src/cfeditor/map/MapControl.java 2007-01-07 00:40:00 UTC (rev 1466) @@ -566,12 +566,12 @@ } /** {@inheritDoc} */ - public void addMapModelListener(@NotNull final MapModelListener listener) { + public void addMapModelListener(@NotNull final MapModelListener<GameObject, MapArchObject> listener) { mapModel.addMapModelListener(listener); } /** {@inheritDoc} */ - public void removeMapModelListener(@NotNull final MapModelListener listener) { + public void removeMapModelListener(@NotNull final MapModelListener<GameObject, MapArchObject> listener) { mapModel.removeMapModelListener(listener); } Modified: trunk/daimonin/src/daieditor/map/MapControl.java =================================================================== --- trunk/daimonin/src/daieditor/map/MapControl.java 2007-01-07 00:30:02 UTC (rev 1465) +++ trunk/daimonin/src/daieditor/map/MapControl.java 2007-01-07 00:40:00 UTC (rev 1466) @@ -695,12 +695,12 @@ } /** {@inheritDoc} */ - public void addMapModelListener(@NotNull final MapModelListener listener) { + public void addMapModelListener(@NotNull final MapModelListener<GameObject, MapArchObject> listener) { mapModel.addMapModelListener(listener); } /** {@inheritDoc} */ - public void removeMapModelListener(@NotNull final MapModelListener listener) { + public void removeMapModelListener(@NotNull final MapModelListener<GameObject, MapArchObject> listener) { mapModel.removeMapModelListener(listener); } Modified: trunk/src/app/net/sf/gridarta/map/MapControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/map/MapControl.java 2007-01-07 00:30:02 UTC (rev 1465) +++ trunk/src/app/net/sf/gridarta/map/MapControl.java 2007-01-07 00:40:00 UTC (rev 1466) @@ -75,12 +75,12 @@ * Register a MapModelListener. * @param listener MapModelListener to register */ - void addMapModelListener(@NotNull MapModelListener listener); + void addMapModelListener(@NotNull MapModelListener<G, A> listener); /** * Unregister a MapModelListener. * @param listener MapModelListener to unregister */ - void removeMapModelListener(@NotNull MapModelListener listener); + void removeMapModelListener(@NotNull MapModelListener<G, A> listener); } // interface MapControl This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2007-01-07 01:41:21
|
Revision: 1474 http://svn.sourceforge.net/gridarta/?rev=1474&view=rev Author: akirschbaum Date: 2007-01-06 17:41:21 -0800 (Sat, 06 Jan 2007) Log Message: ----------- Fix some unchecked warnings. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/daimonin/src/daieditor/CMainControl.java trunk/src/app/net/sf/gridarta/AbstractMainControl.java trunk/src/app/net/sf/gridarta/MainControl.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2007-01-07 01:27:05 UTC (rev 1473) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2007-01-07 01:41:21 UTC (rev 1474) @@ -86,7 +86,7 @@ * @author <a href="mailto:and...@gm...">Andreas Vogl</a> * @author Andreas Kirschbaum */ -public final class CMainControl extends AbstractMainControl<GameObject, MapArchObject> implements ThrowableHandler { +public final class CMainControl extends AbstractMainControl<GameObject, MapArchObject, MapControl> implements ThrowableHandler { /** Action Factory. */ private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); @@ -1508,7 +1508,7 @@ * @param mapControl the created map */ private void fireMapCreatedEvent(@NotNull final MapControl mapControl) { - for (final MainControlListener listener : listenerList.getListeners(MainControlListener.class)) { + for (final MainControlListener<MapControl> listener : listenerList.getListeners(MainControlListener.class)) { listener.mapCreated(mapControl); } } @@ -1518,7 +1518,7 @@ * @param mapControl MapControl that's being closed. */ private void fireMapClosingEvent(@NotNull final MapControl mapControl) { - for (final MainControlListener listener : listenerList.getListeners(MainControlListener.class)) { + for (final MainControlListener<MapControl> listener : listenerList.getListeners(MainControlListener.class)) { listener.mapClosing(mapControl); } } @@ -1527,18 +1527,18 @@ * Notify all listeners about a changed current map. */ private void fireCurrentMapChangedEvent() { - for (final MainControlListener listener : listenerList.getListeners(MainControlListener.class)) { + for (final MainControlListener<MapControl> listener : listenerList.getListeners(MainControlListener.class)) { listener.currentMapChanged(currentMap); } } /** {@inheritDoc} */ - public void addMainControlListener(@NotNull final MainControlListener listener) { + public void addMainControlListener(@NotNull final MainControlListener<MapControl> listener) { listenerList.add(MainControlListener.class, listener); } /** {@inheritDoc} */ - public void removeMainControlListener(@NotNull final MainControlListener listener) { + public void removeMainControlListener(@NotNull final MainControlListener<MapControl> listener) { listenerList.remove(MainControlListener.class, listener); } @@ -1813,7 +1813,7 @@ /** * Encapsulates actions and related functions. */ - public static final class MainActions implements MainControlListener, MapCursorListener, MapGridListener { + public static final class MainActions implements MainControlListener<MapControl>, MapCursorListener, MapGridListener { /** The MainControl. */ private final CMainControl mainControl; @@ -1880,17 +1880,17 @@ } /* {@inheritDoc} */ - public void currentMapChanged(@Nullable final net.sf.gridarta.map.MapControl mapControl) { + public void currentMapChanged(@Nullable final MapControl mapControl) { refreshMenus(); } /** {@inheritDoc} */ - public void mapCreated(@NotNull final net.sf.gridarta.map.MapControl mapControl) { + public void mapCreated(@NotNull final MapControl mapControl) { // ignore: a current map changed event will be generated } /** {@inheritDoc} */ - public void mapClosing(@NotNull final net.sf.gridarta.map.MapControl mapControl) { + public void mapClosing(@NotNull final MapControl mapControl) { // ignore: a current map changed event will be generated } Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2007-01-07 01:27:05 UTC (rev 1473) +++ trunk/daimonin/src/daieditor/CMainControl.java 2007-01-07 01:41:21 UTC (rev 1474) @@ -135,7 +135,7 @@ * @author Andreas Kirschbaum * @fixme I'm 2200 lines long, therefor I suck. */ -public final class CMainControl extends AbstractMainControl<GameObject, MapArchObject> implements ThrowableHandler, MapModelListener<GameObject, MapArchObject> { +public final class CMainControl extends AbstractMainControl<GameObject, MapArchObject, MapControl> implements ThrowableHandler, MapModelListener<GameObject, MapArchObject> { /** Action Factory. */ private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("daieditor"); @@ -1710,7 +1710,7 @@ * @param mapControl the created map */ private void fireMapCreatedEvent(@NotNull final MapControl mapControl) { - for (final MainControlListener listener : listenerList.getListeners(MainControlListener.class)) { + for (final MainControlListener<MapControl> listener : listenerList.getListeners(MainControlListener.class)) { listener.mapCreated(mapControl); } } @@ -1720,7 +1720,7 @@ * @param mapControl MapControl that's being closed. */ private void fireMapClosingEvent(@NotNull final MapControl mapControl) { - for (final MainControlListener listener : listenerList.getListeners(MainControlListener.class)) { + for (final MainControlListener<MapControl> listener : listenerList.getListeners(MainControlListener.class)) { listener.mapClosing(mapControl); } } @@ -1729,18 +1729,18 @@ * Notify all listeners about a changed current map. */ private void fireCurrentMapChangedEvent() { - for (final MainControlListener listener : listenerList.getListeners(MainControlListener.class)) { + for (final MainControlListener<MapControl> listener : listenerList.getListeners(MainControlListener.class)) { listener.currentMapChanged(currentMap); } } /** {@inheritDoc} */ - public void addMainControlListener(@NotNull final MainControlListener listener) { + public void addMainControlListener(@NotNull final MainControlListener<MapControl> listener) { listenerList.add(MainControlListener.class, listener); } /** {@inheritDoc} */ - public void removeMainControlListener(@NotNull final MainControlListener listener) { + public void removeMainControlListener(@NotNull final MainControlListener<MapControl> listener) { listenerList.remove(MainControlListener.class, listener); } @@ -1981,7 +1981,7 @@ } /** {@inheritDoc} */ - public void mapSizeChanged(final MapModelEvent e) { + public void mapSizeChanged(final MapModelEvent<GameObject, MapArchObject> e) { // This event is ignored here because MapGrid needs to be resized // before #validateMap(MapModel) can set error flags on the grid. // #mapSizeChanged(MapModel) will be called from CMapViewBasic#mapSizeChanged() @@ -1989,7 +1989,7 @@ } /** {@inheritDoc} */ - public void mapSquaresChanged(final MapModelEvent e) { + public void mapSquaresChanged(final MapModelEvent<GameObject, MapArchObject> e) { if (prefs.getBoolean(PREFS_VALIDATOR_AUTO, PREFS_VALIDATOR_AUTO_DEFAULT)) { final MapSquare<GameObject, MapArchObject>[] squares = e.getSquares(); if (squares != null) { @@ -2002,7 +2002,7 @@ } /** {@inheritDoc} */ - public void mapObjectsChanged(final MapModelEvent e) { + public void mapObjectsChanged(final MapModelEvent<GameObject, MapArchObject> e) { if (prefs.getBoolean(PREFS_VALIDATOR_AUTO, PREFS_VALIDATOR_AUTO_DEFAULT)) { final net.sf.gridarta.gameobject.GameObject[] arches = e.getGameObjects(); if (arches != null) { @@ -2149,7 +2149,7 @@ /** * Encapsulates actions and related functions. */ - public static final class MainActions implements MainControlListener, MapCursorListener, MapGridListener { + public static final class MainActions implements MainControlListener<MapControl>, MapCursorListener, MapGridListener { /** The MainControl. */ private final CMainControl mainControl; @@ -2216,17 +2216,17 @@ } /** {@inheritDoc} */ - public void mapCreated(@NotNull final net.sf.gridarta.map.MapControl mapControl) { + public void mapCreated(@NotNull final MapControl mapControl) { // ignore: a current map changed event will be generated } /** {@inheritDoc} */ - public void mapClosing(@NotNull final net.sf.gridarta.map.MapControl mapControl) { + public void mapClosing(@NotNull final MapControl mapControl) { // ignore: a current map changed event will be generated } /* {@inheritDoc} */ - public void currentMapChanged(@Nullable final net.sf.gridarta.map.MapControl mapControl) { + public void currentMapChanged(@Nullable final MapControl mapControl) { refreshMenus(); } Modified: trunk/src/app/net/sf/gridarta/AbstractMainControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/AbstractMainControl.java 2007-01-07 01:27:05 UTC (rev 1473) +++ trunk/src/app/net/sf/gridarta/AbstractMainControl.java 2007-01-07 01:41:21 UTC (rev 1474) @@ -2,6 +2,7 @@ import net.sf.gridarta.gameobject.GameObject; import net.sf.gridarta.map.MapArchObject; +import net.sf.gridarta.map.MapControl; import net.sf.japi.swing.ActionFactory; import org.apache.log4j.Logger; @@ -9,7 +10,7 @@ * MainControl is a central class that's used for access on global data structures / collections and global functions. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ -public abstract class AbstractMainControl<G extends GameObject<G, A>, A extends MapArchObject> implements MainControl<G, A> { +public abstract class AbstractMainControl<G extends GameObject<G, A>, A extends MapArchObject, C extends MapControl<G, A>> implements MainControl<G, A, C> { /** Action Factory. */ private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); Modified: trunk/src/app/net/sf/gridarta/MainControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/MainControl.java 2007-01-07 01:27:05 UTC (rev 1473) +++ trunk/src/app/net/sf/gridarta/MainControl.java 2007-01-07 01:41:21 UTC (rev 1474) @@ -17,7 +17,7 @@ * It should become obsolete after a while. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ -public interface MainControl<G extends GameObject<G, A>, A extends MapArchObject> { +public interface MainControl<G extends GameObject<G, A>, A extends MapArchObject, C extends MapControl<G, A>> { /** * Global random number generator. @@ -104,13 +104,13 @@ * Register a MainControlListener. * @param listener MainControlListener to register */ - void addMainControlListener(@NotNull MainControlListener listener); + void addMainControlListener(@NotNull MainControlListener<C> listener); /** * Remove a MainControlListener. * @param listener MainControlListener to remove */ - void removeMainControlListener(@NotNull MainControlListener listener); + void removeMainControlListener(@NotNull MainControlListener<C> listener); void showArchPanelQuickObject(G gameObject); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2007-01-07 02:18:19
|
Revision: 1476 http://svn.sourceforge.net/gridarta/?rev=1476&view=rev Author: akirschbaum Date: 2007-01-06 18:18:16 -0800 (Sat, 06 Jan 2007) Log Message: ----------- Move ReplaceDialog to gui package. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/gui/ObjectChoiceDisplay.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/gui/ObjectChoiceDisplay.java Added Paths: ----------- trunk/crossfire/src/cfeditor/gui/ReplaceDialog.java trunk/daimonin/src/daieditor/gui/ReplaceDialog.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/ReplaceDialog.java trunk/daimonin/src/daieditor/ReplaceDialog.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2007-01-07 01:50:37 UTC (rev 1475) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2007-01-07 02:18:16 UTC (rev 1476) @@ -33,6 +33,7 @@ import cfeditor.gui.GameObjectAttributesDialog; import cfeditor.gui.NewMapDialog; import cfeditor.gui.PickmapChooser; +import cfeditor.gui.ReplaceDialog; import cfeditor.gui.map.MapCursorControl; import cfeditor.gui.map.MapPropertiesDialog; import cfeditor.gui.prefs.GUIPrefs; Deleted: trunk/crossfire/src/cfeditor/ReplaceDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/ReplaceDialog.java 2007-01-07 01:50:37 UTC (rev 1475) +++ trunk/crossfire/src/cfeditor/ReplaceDialog.java 2007-01-07 02:18:16 UTC (rev 1476) @@ -1,417 +0,0 @@ -/* - * Crossfire Java Editor. - * Copyright (C) 2000 Michael Toennies - * Copyright (C) 2001 Andreas Vogl - * - * (code based on: Gridder. 2D grid based level editor. (C) 2000 Pasi Keränen) - * - * 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., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - * - */ - -package cfeditor; - -import cfeditor.gameobject.GameObject; -import cfeditor.map.MapArchObject; -import cfeditor.map.MapControl; -import java.awt.FlowLayout; -import java.awt.Point; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import java.util.ArrayList; -import java.util.Iterator; -import javax.swing.BorderFactory; -import javax.swing.Box; -import javax.swing.BoxLayout; -import javax.swing.Icon; -import javax.swing.JButton; -import javax.swing.JComboBox; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JTextField; -import javax.swing.WindowConstants; -import net.sf.gridarta.map.MapSquare; -import net.sf.japi.swing.ActionFactory; - -/** - * This dialog manages the replace action. - * @author <a href="mailto:and...@gm...">Andreas Vogl</a> - */ -public final class ReplaceDialog extends JOptionPane { - - /** Serial Version UID. */ - private static final long serialVersionUID = 1L; - - /** Action Factory. */ - private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); - - // matching criteria - public static final int MATCH_ARCH_NAME = 0; - - public static final int MATCH_OBJ_NAME = 1; - - /** Singleton Instance. */ - private static ReplaceDialog instance = null; - - /** Dialog. */ - private JDialog dialog; - - private final CMainControl mainControl; - - private boolean isBuilt = false; - - private MapControl mapControl; - - private GameObject replaceArch = null; // objects will be replaced by this arch - - private JLabel rfHeading; - - private JLabel rfArchName = null; - - private JLabel iconLabel; - - private JLabel colonLabel; - - private JComboBox replaceCriteria; - - private JComboBox replaceWithBox; - - private JComboBox replaceEntireBox; - - private JTextField replaceInput1; - - private int lastSelectedIndex; - - /** - * Construct instance. - * @param mainControl MainControl - */ - private ReplaceDialog(final CMainControl mainControl) { - dialog = createDialog(mainControl.getMainView(), ACTION_FACTORY.getString("replaceTitle")); - dialog.setModal(false); - dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); - this.mainControl = mainControl; - } - - /** - * Returns whether this frame has been fully built. - * @return <code>true</code> if this frame has been fully built, otherwise <code>false</code> - */ - public static boolean isBuilt() { - return instance != null && instance.isBuilt; - } - - public static ReplaceDialog getInstance() { - if (instance == null) { - instance = new ReplaceDialog(CMainControl.getInstance()); - } - return instance; - } - - /** - * Replace objects on the map. - * @param mapControl MapControl of the active map where the action was invoked - */ - public void display(final MapControl mapControl) { - replaceArch = mainControl.getArchPanelHighlight(); // highlighted arch - - if (!isBuilt) { - this.mapControl = mapControl; - final JPanel mainPanel = new JPanel(); - mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); - mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 2, 5)); - - // first line: heading - final JPanel line1 = new JPanel(new FlowLayout(FlowLayout.LEFT)); - final JLabel labelon = new JLabel(ACTION_FACTORY.getString("replaceOn")); - line1.add(labelon); - line1.add(Box.createVerticalStrut(3)); - replaceEntireBox = new JComboBox(new String[]{ACTION_FACTORY.getString("replaceOnMap"), ACTION_FACTORY.getString("replaceOnSelection")}); - final MapViewIFrame mapViewIFrame = mapControl.getMapViewFrame(); - if (mapViewIFrame != null && mapViewIFrame.isHighlight()) { - replaceEntireBox.setSelectedIndex(1); - } else { - replaceEntireBox.setSelectedIndex(0); - } - line1.add(replaceEntireBox); - line1.add(Box.createVerticalStrut(3)); - rfHeading = new JLabel("\"" + mapControl.getMapFileName() + "\":"); - line1.add(rfHeading); - mainPanel.add(line1); - - // second line: replace what? - final JPanel line2 = new JPanel(new FlowLayout(FlowLayout.LEFT)); - final JLabel label1 = new JLabel(ACTION_FACTORY.getString("replaceDelete")); - line2.add(label1); - line2.add(Box.createVerticalStrut(5)); - - replaceCriteria = new JComboBox(new String[]{"default arch", "name"}); - replaceCriteria.setSelectedIndex(0); - line2.add(replaceCriteria); - line2.add(Box.createVerticalStrut(5)); - - replaceInput1 = new JTextField(20); - line2.add(replaceInput1); - mainPanel.add(line2); - - // third line: replace by? - final JPanel line3 = new JPanel(new FlowLayout(FlowLayout.LEFT)); - final JLabel label2 = new JLabel(ACTION_FACTORY.getString("replaceBy")); - line3.add(label2); - line3.add(Box.createVerticalStrut(5)); - replaceWithBox = new JComboBox(new String[]{ACTION_FACTORY.getString("replaceByObject"), - ACTION_FACTORY.getString("replaceByNothing")}); - if (replaceArch == null) { - replaceWithBox.setSelectedIndex(1); - } else { - replaceWithBox.setSelectedIndex(0); - } - replaceWithBox.addItemListener(new ReplaceWithBoxItemListener()); - lastSelectedIndex = replaceWithBox.getSelectedIndex(); - line3.add(replaceWithBox); - - iconLabel = new JLabel(); - if (replaceArch != null) { - colonLabel = new JLabel(":"); - iconLabel.setIcon(mainControl.getArchetypeSet().getFace(replaceArch)); - rfArchName = new JLabel(" " + replaceArch.getBestName()); - } else { - colonLabel = new JLabel(""); - rfArchName = new JLabel(""); - } - line3.add(colonLabel); - line3.add(Box.createVerticalStrut(5)); - line3.add(iconLabel); - line3.add(rfArchName); - mainPanel.add(line3); - - final JButton okButton = new JButton(ACTION_FACTORY.createAction(false, "replaceOk", this)); - final JButton cancelButton = new JButton(ACTION_FACTORY.createAction(false, "replaceCancel", this)); - - setMessage(mainPanel); - setOptions(new Object[]{okButton, cancelButton}); - dialog.getRootPane().setDefaultButton(okButton); - dialog.pack(); - dialog.setLocationRelativeTo(mainControl.getMainView()); - dialog.setVisible(true); - isBuilt = true; - } else { - // just set fields and show - rfHeading.setText("\"" + mapControl.getMapFileName() + "\":"); - replaceInput1.setText(""); - - this.mapControl = mapControl; - if (replaceArch == null) { - replaceWithBox.setSelectedIndex(1); - iconLabel.setIcon(null); - rfArchName.setText(""); - colonLabel.setText(""); - } else { - replaceWithBox.setSelectedIndex(0); - iconLabel.setIcon(mainControl.getArchetypeSet().getFace(replaceArch)); - rfArchName.setText(" " + replaceArch.getBestName()); - colonLabel.setText(":"); - } - - final MapViewIFrame mapViewIFrame = mapControl.getMapViewFrame(); - if (mapViewIFrame != null && mapViewIFrame.isHighlight()) { - replaceEntireBox.setSelectedIndex(1); // selected squares - } else { - replaceEntireBox.setSelectedIndex(0); // entire map - } - - dialog.pack(); - dialog.toFront(); - dialog.setVisible(true); - } - } - - /** - * Update which arch is displayed as replace object. - * @param newArch the new 'replaceArch' to be shown and stored - * @param alwaysPack if false, the frame is packed only when icon size - * changed if true, the frame is always packed (packing - * resizes but also causes flicker) - */ - public void updateArchSelection(final GameObject newArch, final boolean alwaysPack) { - if (isShowing() && replaceWithBox.getSelectedIndex() == 0) { - replaceArch = newArch; - if (newArch != null) { - final Icon oldIcon = iconLabel.getIcon(); - - iconLabel.setIcon(mainControl.getArchetypeSet().getFace(newArch)); - rfArchName.setText(" " + newArch.getBestName()); - colonLabel.setText(":"); - - // pack frame only if height of icon changed - if (alwaysPack || (oldIcon == null && iconLabel.getIcon() != null) || (oldIcon != null && iconLabel.getIcon() == null) || (oldIcon != iconLabel.getIcon() && oldIcon != null && oldIcon.getIconHeight() != iconLabel.getIcon().getIconHeight())) { - dialog.pack(); - } - } else { - replaceWithBox.setSelectedIndex(1); - iconLabel.setIcon(null); - rfArchName.setText(""); - colonLabel.setText(""); - } - } - } - - /** - * This method performs the actual replace action on a map. - * @param matchCriteria matching criteria for replace - * @param matchString this is what to search for - * @param entireMap if true, the entire map is affected - if false, - * only highlighted area - * @param deleteOnly if true matching arches get only deleted and not - * replaced - * @return number of arches that have been replaced - */ - private int doReplace(final int matchCriteria, final String matchString, final boolean entireMap, final boolean deleteOnly) { - if (mapControl == null) { - return 0; - } - - - final MapViewIFrame mapViewIFrame = mapControl.getMapViewFrame(); - assert mapViewIFrame != null; - int replaceCount = 0; - final ArrayList<GameObject> objectsToReplace = new ArrayList<GameObject>(); - mapControl.getMapModel().beginTransaction("Replace"); // TODO: I18N/L10N - for (final MapSquare<GameObject, MapArchObject> square : entireMap ? mapControl.getMapModel() : mapViewIFrame.getView().getSelectedSquares()) { - // find objects to replace - objectsToReplace.clear(); - for (final GameObject node : square) { - if (node.isHead() && ((matchCriteria == MATCH_ARCH_NAME && node.getArchetypeName() != null && node.getArchetypeName().equalsIgnoreCase(matchString)) || (matchCriteria == MATCH_OBJ_NAME && node.getBestName().equalsIgnoreCase(matchString)))) { - objectsToReplace.add(node); - } - } - - // actually replace the objects - for (final GameObject objectToDelete : objectsToReplace) { - final Iterator<GameObject> it = square.iterator(); - GameObject prevArch = null; - GameObject node = null; - while (it.hasNext()) { - node = it.next(); - - if (node == objectToDelete) { - break; - } - - prevArch = node; - } - assert node != null; - - // first, delete the old arch - node.remove(); - - if (replaceArch != null && !deleteOnly) { - // insert replacement object - if (replaceArch.isMulti()) { - // multi's cannot be inserted properly, so we just put them ontop - replaceArch = replaceArch.getHead(); - mapControl.addArchToMap(replaceArch.getArchetypeName(), new Point(square.getMapX(), square.getMapY()), false, false); - - // TODO: if from pickmap it could have special attributes -> copy them - } else { - mapControl.insertArchToMap(replaceArch, null, prevArch, new Point(square.getMapX(), square.getMapY()), false); - } - } - replaceCount++; - } - } - - mapControl.getMapModel().endTransaction(); - return replaceCount; - } - - /** Item-listener for the "replace with"-selection box. */ - private class ReplaceWithBoxItemListener implements ItemListener { - - /** {@inheritDoc} */ - public void itemStateChanged(final ItemEvent e) { - final int selectedIndex = replaceWithBox.getSelectedIndex(); - if (e.getStateChange() == ItemEvent.SELECTED && lastSelectedIndex != selectedIndex) { - switch (selectedIndex) { - case 0: - // replace with arch - replaceArch = mainControl.getArchPanelHighlight(); // selected arch - updateArchSelection(replaceArch, true); - break; - - case 1: - // replace with nothing - iconLabel.setIcon(null); - rfArchName.setText(""); - colonLabel.setText(""); - dialog.pack(); - break; - } - lastSelectedIndex = selectedIndex; - } - } - - } // class ReplaceWithBoxItemListener - - /** - * Action method for Ok button. - */ - public void replaceOk() { - final String matchString = replaceInput1.getText().trim(); - final boolean deleteOnly = replaceWithBox.getSelectedIndex() == 1; - final boolean entireMap = replaceEntireBox.getSelectedIndex() == 0; - - final MapViewIFrame mapViewIFrame = mapControl.getMapViewFrame(); - if (mapControl == null || mapControl.isClosing()) { - setVisible(false); - ACTION_FACTORY.showMessageDialog(this, "replaceMapGone", mapControl.getMapFileName()); - } else if (!entireMap && (mapViewIFrame == null || !mapViewIFrame.isHighlight())) { - // user selected "replace highlighted" but nothing is highlighted - ACTION_FACTORY.showMessageDialog(this, "replaceMapNoSelection", mapControl.getMapFileName()); - } else { - final int matchCriteria; - if (replaceCriteria.getSelectedIndex() == 0) { - matchCriteria = MATCH_ARCH_NAME; - } else if (replaceCriteria.getSelectedIndex() == 1) { - matchCriteria = MATCH_OBJ_NAME; - } else { - matchCriteria = 0; - } - - final int replaceCount = doReplace(matchCriteria, matchString, entireMap, deleteOnly); - if (replaceCount > 0) { - dialog.setVisible(false); - if (replaceCount == 1) { - ACTION_FACTORY.showMessageDialog(this, "replacedOne"); - } else { - ACTION_FACTORY.showMessageDialog(this, "replacedMany", replaceCount); - } - } else { - ACTION_FACTORY.showMessageDialog(this, "replacedZero"); - } - } - } - - /** - * Action method for Cancel button. - */ - public void replaceCancel() { - dialog.setVisible(false); - } - -} // class ReplaceDialog Modified: trunk/crossfire/src/cfeditor/gui/ObjectChoiceDisplay.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/ObjectChoiceDisplay.java 2007-01-07 01:50:37 UTC (rev 1475) +++ trunk/crossfire/src/cfeditor/gui/ObjectChoiceDisplay.java 2007-01-07 02:18:16 UTC (rev 1476) @@ -25,7 +25,6 @@ package cfeditor.gui; import cfeditor.CMainControl; -import cfeditor.ReplaceDialog; import cfeditor.gameobject.GameObject; import cfeditor.map.MapArchObject; import java.awt.Color; Copied: trunk/crossfire/src/cfeditor/gui/ReplaceDialog.java (from rev 1475, trunk/crossfire/src/cfeditor/ReplaceDialog.java) =================================================================== --- trunk/crossfire/src/cfeditor/gui/ReplaceDialog.java (rev 0) +++ trunk/crossfire/src/cfeditor/gui/ReplaceDialog.java 2007-01-07 02:18:16 UTC (rev 1476) @@ -0,0 +1,419 @@ +/* + * Crossfire Java Editor. + * Copyright (C) 2000 Michael Toennies + * Copyright (C) 2001 Andreas Vogl + * + * (code based on: Gridder. 2D grid based level editor. (C) 2000 Pasi Keränen) + * + * 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., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + */ + +package cfeditor.gui; + +import cfeditor.CMainControl; +import cfeditor.MapViewIFrame; +import cfeditor.gameobject.GameObject; +import cfeditor.map.MapArchObject; +import cfeditor.map.MapControl; +import java.awt.FlowLayout; +import java.awt.Point; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.util.ArrayList; +import java.util.Iterator; +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.Icon; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.WindowConstants; +import net.sf.gridarta.map.MapSquare; +import net.sf.japi.swing.ActionFactory; + +/** + * This dialog manages the replace action. + * @author <a href="mailto:and...@gm...">Andreas Vogl</a> + */ +public final class ReplaceDialog extends JOptionPane { + + /** Serial Version UID. */ + private static final long serialVersionUID = 1L; + + /** Action Factory. */ + private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); + + // matching criteria + public static final int MATCH_ARCH_NAME = 0; + + public static final int MATCH_OBJ_NAME = 1; + + /** Singleton Instance. */ + private static ReplaceDialog instance = null; + + /** Dialog. */ + private JDialog dialog; + + private final CMainControl mainControl; + + private boolean isBuilt = false; + + private MapControl mapControl; + + private GameObject replaceArch = null; // objects will be replaced by this arch + + private JLabel rfHeading; + + private JLabel rfArchName = null; + + private JLabel iconLabel; + + private JLabel colonLabel; + + private JComboBox replaceCriteria; + + private JComboBox replaceWithBox; + + private JComboBox replaceEntireBox; + + private JTextField replaceInput1; + + private int lastSelectedIndex; + + /** + * Construct instance. + * @param mainControl MainControl + */ + private ReplaceDialog(final CMainControl mainControl) { + dialog = createDialog(mainControl.getMainView(), ACTION_FACTORY.getString("replaceTitle")); + dialog.setModal(false); + dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); + this.mainControl = mainControl; + } + + /** + * Returns whether this frame has been fully built. + * @return <code>true</code> if this frame has been fully built, otherwise <code>false</code> + */ + public static boolean isBuilt() { + return instance != null && instance.isBuilt; + } + + public static ReplaceDialog getInstance() { + if (instance == null) { + instance = new ReplaceDialog(CMainControl.getInstance()); + } + return instance; + } + + /** + * Replace objects on the map. + * @param mapControl MapControl of the active map where the action was invoked + */ + public void display(final MapControl mapControl) { + replaceArch = mainControl.getArchPanelHighlight(); // highlighted arch + + if (!isBuilt) { + this.mapControl = mapControl; + final JPanel mainPanel = new JPanel(); + mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); + mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 2, 5)); + + // first line: heading + final JPanel line1 = new JPanel(new FlowLayout(FlowLayout.LEFT)); + final JLabel labelon = new JLabel(ACTION_FACTORY.getString("replaceOn")); + line1.add(labelon); + line1.add(Box.createVerticalStrut(3)); + replaceEntireBox = new JComboBox(new String[]{ACTION_FACTORY.getString("replaceOnMap"), ACTION_FACTORY.getString("replaceOnSelection")}); + final MapViewIFrame mapViewIFrame = mapControl.getMapViewFrame(); + if (mapViewIFrame != null && mapViewIFrame.isHighlight()) { + replaceEntireBox.setSelectedIndex(1); + } else { + replaceEntireBox.setSelectedIndex(0); + } + line1.add(replaceEntireBox); + line1.add(Box.createVerticalStrut(3)); + rfHeading = new JLabel("\"" + mapControl.getMapFileName() + "\":"); + line1.add(rfHeading); + mainPanel.add(line1); + + // second line: replace what? + final JPanel line2 = new JPanel(new FlowLayout(FlowLayout.LEFT)); + final JLabel label1 = new JLabel(ACTION_FACTORY.getString("replaceDelete")); + line2.add(label1); + line2.add(Box.createVerticalStrut(5)); + + replaceCriteria = new JComboBox(new String[]{"default arch", "name"}); + replaceCriteria.setSelectedIndex(0); + line2.add(replaceCriteria); + line2.add(Box.createVerticalStrut(5)); + + replaceInput1 = new JTextField(20); + line2.add(replaceInput1); + mainPanel.add(line2); + + // third line: replace by? + final JPanel line3 = new JPanel(new FlowLayout(FlowLayout.LEFT)); + final JLabel label2 = new JLabel(ACTION_FACTORY.getString("replaceBy")); + line3.add(label2); + line3.add(Box.createVerticalStrut(5)); + replaceWithBox = new JComboBox(new String[]{ACTION_FACTORY.getString("replaceByObject"), + ACTION_FACTORY.getString("replaceByNothing")}); + if (replaceArch == null) { + replaceWithBox.setSelectedIndex(1); + } else { + replaceWithBox.setSelectedIndex(0); + } + replaceWithBox.addItemListener(new ReplaceWithBoxItemListener()); + lastSelectedIndex = replaceWithBox.getSelectedIndex(); + line3.add(replaceWithBox); + + iconLabel = new JLabel(); + if (replaceArch != null) { + colonLabel = new JLabel(":"); + iconLabel.setIcon(mainControl.getArchetypeSet().getFace(replaceArch)); + rfArchName = new JLabel(" " + replaceArch.getBestName()); + } else { + colonLabel = new JLabel(""); + rfArchName = new JLabel(""); + } + line3.add(colonLabel); + line3.add(Box.createVerticalStrut(5)); + line3.add(iconLabel); + line3.add(rfArchName); + mainPanel.add(line3); + + final JButton okButton = new JButton(ACTION_FACTORY.createAction(false, "replaceOk", this)); + final JButton cancelButton = new JButton(ACTION_FACTORY.createAction(false, "replaceCancel", this)); + + setMessage(mainPanel); + setOptions(new Object[]{okButton, cancelButton}); + dialog.getRootPane().setDefaultButton(okButton); + dialog.pack(); + dialog.setLocationRelativeTo(mainControl.getMainView()); + dialog.setVisible(true); + isBuilt = true; + } else { + // just set fields and show + rfHeading.setText("\"" + mapControl.getMapFileName() + "\":"); + replaceInput1.setText(""); + + this.mapControl = mapControl; + if (replaceArch == null) { + replaceWithBox.setSelectedIndex(1); + iconLabel.setIcon(null); + rfArchName.setText(""); + colonLabel.setText(""); + } else { + replaceWithBox.setSelectedIndex(0); + iconLabel.setIcon(mainControl.getArchetypeSet().getFace(replaceArch)); + rfArchName.setText(" " + replaceArch.getBestName()); + colonLabel.setText(":"); + } + + final MapViewIFrame mapViewIFrame = mapControl.getMapViewFrame(); + if (mapViewIFrame != null && mapViewIFrame.isHighlight()) { + replaceEntireBox.setSelectedIndex(1); // selected squares + } else { + replaceEntireBox.setSelectedIndex(0); // entire map + } + + dialog.pack(); + dialog.toFront(); + dialog.setVisible(true); + } + } + + /** + * Update which arch is displayed as replace object. + * @param newArch the new 'replaceArch' to be shown and stored + * @param alwaysPack if false, the frame is packed only when icon size + * changed if true, the frame is always packed (packing + * resizes but also causes flicker) + */ + public void updateArchSelection(final GameObject newArch, final boolean alwaysPack) { + if (isShowing() && replaceWithBox.getSelectedIndex() == 0) { + replaceArch = newArch; + if (newArch != null) { + final Icon oldIcon = iconLabel.getIcon(); + + iconLabel.setIcon(mainControl.getArchetypeSet().getFace(newArch)); + rfArchName.setText(" " + newArch.getBestName()); + colonLabel.setText(":"); + + // pack frame only if height of icon changed + if (alwaysPack || (oldIcon == null && iconLabel.getIcon() != null) || (oldIcon != null && iconLabel.getIcon() == null) || (oldIcon != iconLabel.getIcon() && oldIcon != null && oldIcon.getIconHeight() != iconLabel.getIcon().getIconHeight())) { + dialog.pack(); + } + } else { + replaceWithBox.setSelectedIndex(1); + iconLabel.setIcon(null); + rfArchName.setText(""); + colonLabel.setText(""); + } + } + } + + /** + * This method performs the actual replace action on a map. + * @param matchCriteria matching criteria for replace + * @param matchString this is what to search for + * @param entireMap if true, the entire map is affected - if false, + * only highlighted area + * @param deleteOnly if true matching arches get only deleted and not + * replaced + * @return number of arches that have been replaced + */ + private int doReplace(final int matchCriteria, final String matchString, final boolean entireMap, final boolean deleteOnly) { + if (mapControl == null) { + return 0; + } + + + final MapViewIFrame mapViewIFrame = mapControl.getMapViewFrame(); + assert mapViewIFrame != null; + int replaceCount = 0; + final ArrayList<GameObject> objectsToReplace = new ArrayList<GameObject>(); + mapControl.getMapModel().beginTransaction("Replace"); // TODO: I18N/L10N + for (final MapSquare<GameObject, MapArchObject> square : entireMap ? mapControl.getMapModel() : mapViewIFrame.getView().getSelectedSquares()) { + // find objects to replace + objectsToReplace.clear(); + for (final GameObject node : square) { + if (node.isHead() && ((matchCriteria == MATCH_ARCH_NAME && node.getArchetypeName() != null && node.getArchetypeName().equalsIgnoreCase(matchString)) || (matchCriteria == MATCH_OBJ_NAME && node.getBestName().equalsIgnoreCase(matchString)))) { + objectsToReplace.add(node); + } + } + + // actually replace the objects + for (final GameObject objectToDelete : objectsToReplace) { + final Iterator<GameObject> it = square.iterator(); + GameObject prevArch = null; + GameObject node = null; + while (it.hasNext()) { + node = it.next(); + + if (node == objectToDelete) { + break; + } + + prevArch = node; + } + assert node != null; + + // first, delete the old arch + node.remove(); + + if (replaceArch != null && !deleteOnly) { + // insert replacement object + if (replaceArch.isMulti()) { + // multi's cannot be inserted properly, so we just put them ontop + replaceArch = replaceArch.getHead(); + mapControl.addArchToMap(replaceArch.getArchetypeName(), new Point(square.getMapX(), square.getMapY()), false, false); + + // TODO: if from pickmap it could have special attributes -> copy them + } else { + mapControl.insertArchToMap(replaceArch, null, prevArch, new Point(square.getMapX(), square.getMapY()), false); + } + } + replaceCount++; + } + } + + mapControl.getMapModel().endTransaction(); + return replaceCount; + } + + /** Item-listener for the "replace with"-selection box. */ + private class ReplaceWithBoxItemListener implements ItemListener { + + /** {@inheritDoc} */ + public void itemStateChanged(final ItemEvent e) { + final int selectedIndex = replaceWithBox.getSelectedIndex(); + if (e.getStateChange() == ItemEvent.SELECTED && lastSelectedIndex != selectedIndex) { + switch (selectedIndex) { + case 0: + // replace with arch + replaceArch = mainControl.getArchPanelHighlight(); // selected arch + updateArchSelection(replaceArch, true); + break; + + case 1: + // replace with nothing + iconLabel.setIcon(null); + rfArchName.setText(""); + colonLabel.setText(""); + dialog.pack(); + break; + } + lastSelectedIndex = selectedIndex; + } + } + + } // class ReplaceWithBoxItemListener + + /** + * Action method for Ok button. + */ + public void replaceOk() { + final String matchString = replaceInput1.getText().trim(); + final boolean deleteOnly = replaceWithBox.getSelectedIndex() == 1; + final boolean entireMap = replaceEntireBox.getSelectedIndex() == 0; + + final MapViewIFrame mapViewIFrame = mapControl.getMapViewFrame(); + if (mapControl == null || mapControl.isClosing()) { + setVisible(false); + ACTION_FACTORY.showMessageDialog(this, "replaceMapGone", mapControl.getMapFileName()); + } else if (!entireMap && (mapViewIFrame == null || !mapViewIFrame.isHighlight())) { + // user selected "replace highlighted" but nothing is highlighted + ACTION_FACTORY.showMessageDialog(this, "replaceMapNoSelection", mapControl.getMapFileName()); + } else { + final int matchCriteria; + if (replaceCriteria.getSelectedIndex() == 0) { + matchCriteria = MATCH_ARCH_NAME; + } else if (replaceCriteria.getSelectedIndex() == 1) { + matchCriteria = MATCH_OBJ_NAME; + } else { + matchCriteria = 0; + } + + final int replaceCount = doReplace(matchCriteria, matchString, entireMap, deleteOnly); + if (replaceCount > 0) { + dialog.setVisible(false); + if (replaceCount == 1) { + ACTION_FACTORY.showMessageDialog(this, "replacedOne"); + } else { + ACTION_FACTORY.showMessageDialog(this, "replacedMany", replaceCount); + } + } else { + ACTION_FACTORY.showMessageDialog(this, "replacedZero"); + } + } + } + + /** + * Action method for Cancel button. + */ + public void replaceCancel() { + dialog.setVisible(false); + } + +} // class ReplaceDialog Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2007-01-07 01:50:37 UTC (rev 1475) +++ trunk/daimonin/src/daieditor/CMainControl.java 2007-01-07 02:18:16 UTC (rev 1476) @@ -39,6 +39,7 @@ import daieditor.gui.MapFileFilter; import daieditor.gui.NewMapDialog; import daieditor.gui.PickmapChooser; +import daieditor.gui.ReplaceDialog; import daieditor.gui.map.MapCursorControl; import daieditor.gui.map.MapPreviewAccessory; import daieditor.gui.map.MapPropertiesDialog; Deleted: trunk/daimonin/src/daieditor/ReplaceDialog.java =================================================================== --- trunk/daimonin/src/daieditor/ReplaceDialog.java 2007-01-07 01:50:37 UTC (rev 1475) +++ trunk/daimonin/src/daieditor/ReplaceDialog.java 2007-01-07 02:18:16 UTC (rev 1476) @@ -1,456 +0,0 @@ -/* - * Daimonin Java Editor. - * Copyright (C) 2000 Michael Toennies - * Copyright (C) 2001 Andreas Vogl - * Copyright (C) 2005 Christian Hujer - * - * (code based on: Gridder. 2D grid based level editor. (C) 2000 Pasi Keränen) - * - * 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., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - * - */ - -package daieditor; - -import daieditor.gameobject.GameObject; -import daieditor.map.MapArchObject; -import daieditor.map.MapControl; -import java.awt.FlowLayout; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import java.util.ArrayList; -import java.util.List; -import javax.swing.BorderFactory; -import javax.swing.Box; -import javax.swing.BoxLayout; -import javax.swing.Icon; -import javax.swing.JButton; -import javax.swing.JComboBox; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JTextField; -import javax.swing.WindowConstants; -import net.sf.gridarta.MainControl; -import net.sf.gridarta.map.MapSquare; -import net.sf.japi.swing.ActionFactory; - -/** - * This dialog manages the replace action. - * @author <a href="mailto:and...@gm...">Andreas Vogl</a> - * @author <a href="mailto:ch...@ri...">Christian.Hujer</a> - */ -public final class ReplaceDialog extends JOptionPane { - - /** Serial Version UID. */ - private static final long serialVersionUID = 1L; - - /** Action Factory. */ - private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("daieditor"); - - // matching criteria - public static final int MATCH_ARCH_NAME = 0; - - public static final int MATCH_OBJ_NAME = 1; - - /** Singleton Instance. */ - private static ReplaceDialog instance = null; - - /** Dialog. */ - private JDialog dialog; - - private final CMainControl mainControl; - - private boolean isBuilt = false; - - private MapControl mapControl; - - private GameObject replaceArch = null; // objects will be replaced by this arch - - private List<GameObject> replaceCopyBuffer; // objects in CopyBuffer - - private List<GameObject> replacePickmap; // selected objects in pickmap or all if none is selected - - private JLabel rfHeading; - - private JLabel rfArchName = null; - - private JLabel iconLabel; - - private JLabel colonLabel; - - private JComboBox replaceCriteria; - - private JComboBox replaceWithBox; - - private JComboBox replaceEntireBox; - - private JTextField replaceInput1; - - private int lastSelectedIndex; - - /** - * Construct instance. - * @param mainControl MainControl - */ - private ReplaceDialog(final CMainControl mainControl) { - dialog = createDialog(mainControl.getMainView(), ACTION_FACTORY.getString("replaceTitle")); - dialog.setModal(false); - dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); - this.mainControl = mainControl; - } - - /** - * Returns whether this frame has been fully built. - * @return <code>true</code> if this frame has been fully built, otherwise <code>false</code> - */ - public static boolean isBuilt() { - return instance != null && instance.isBuilt; - } - - public static ReplaceDialog getInstance() { - if (instance == null) { - instance = new ReplaceDialog(CMainControl.getInstance()); - } - return instance; - } - - /** - * Replace objects on the map. - * @param mapControl MapControl of the active map where the action was invoked - */ - public void display(final MapControl mapControl) { - replaceArch = mainControl.getArchPanelHighlight(); // highlighted arch - replacePickmap = mainControl.getArchPanelSelection(); // selected arches - replaceCopyBuffer = CopyBuffer.getMapArchList(mainControl.getCopyMapCtrl(), 100); - - if (!isBuilt) { - this.mapControl = mapControl; - final JPanel mainPanel = new JPanel(); - mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); - mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 2, 5)); - - // first line: heading - final JPanel line1 = new JPanel(new FlowLayout(FlowLayout.LEFT)); - final JLabel labelon = new JLabel(ACTION_FACTORY.getString("replaceOn")); - line1.add(labelon); - line1.add(Box.createVerticalStrut(3)); - replaceEntireBox = new JComboBox(new String[]{ACTION_FACTORY.getString("replaceOnMap"), ACTION_FACTORY.getString("replaceOnSelection")}); - final MapViewIFrame mapViewIFrame = mapControl.getMapViewFrame(); - if (mapViewIFrame != null && mapViewIFrame.isHighlight()) { - replaceEntireBox.setSelectedIndex(1); - } else { - replaceEntireBox.setSelectedIndex(0); - } - line1.add(replaceEntireBox); - line1.add(Box.createVerticalStrut(3)); - rfHeading = new JLabel("\"" + mapControl.getMapFileName() + "\":"); - line1.add(rfHeading); - mainPanel.add(line1); - - // second line: replace what? - final JPanel line2 = new JPanel(new FlowLayout(FlowLayout.LEFT)); - final JLabel label1 = new JLabel(ACTION_FACTORY.getString("replaceDelete")); - line2.add(label1); - line2.add(Box.createVerticalStrut(5)); - - replaceCriteria = new JComboBox(new String[]{"default arch", "name"}); - replaceCriteria.setSelectedIndex(0); - line2.add(replaceCriteria); - line2.add(Box.createVerticalStrut(5)); - - replaceInput1 = new JTextField(20); - line2.add(replaceInput1); - mainPanel.add(line2); - - // third line: replace by? - final JPanel line3 = new JPanel(new FlowLayout(FlowLayout.LEFT)); - final JLabel label2 = new JLabel(ACTION_FACTORY.getString("replaceBy")); - line3.add(label2); - line3.add(Box.createVerticalStrut(5)); - replaceWithBox = new JComboBox(new String[]{ACTION_FACTORY.getString("replaceByObject"), - ACTION_FACTORY.getString("replaceByCopyBuffer"), - ACTION_FACTORY.getString("replaceByPickmap"), - ACTION_FACTORY.getString("replaceByNothing")}); - if (replaceArch == null) { - replaceWithBox.setSelectedIndex(3); - } else { - replaceWithBox.setSelectedIndex(0); - } - replaceWithBox.addItemListener(new ReplaceWithBoxItemListener()); - lastSelectedIndex = replaceWithBox.getSelectedIndex(); - line3.add(replaceWithBox); - - iconLabel = new JLabel(); - if (replaceArch != null) { - colonLabel = new JLabel(":"); - iconLabel.setIcon(mainControl.getArchetypeSet().getFace(replaceArch.getFaceObjName())); - rfArchName = new JLabel(" " + replaceArch.getBestName()); - } else { - colonLabel = new JLabel(""); - rfArchName = new JLabel(""); - } - line3.add(colonLabel); - line3.add(Box.createVerticalStrut(5)); - line3.add(iconLabel); - line3.add(rfArchName); - mainPanel.add(line3); - - final JButton okButton = new JButton(ACTION_FACTORY.createAction(false, "replaceOk", this)); - final JButton cancelButton = new JButton(ACTION_FACTORY.createAction(false, "replaceCancel", this)); - - setMessage(mainPanel); - setOptions(new Object[]{okButton, cancelButton}); - dialog.getRootPane().setDefaultButton(okButton); - dialog.pack(); - dialog.setLocationRelativeTo(mainControl.getMainView()); - dialog.setVisible(true); - isBuilt = true; - } else { - // just set fields and show - rfHeading.setText("\"" + mapControl.getMapFileName() + "\":"); - replaceInput1.setText(""); - - this.mapControl = mapControl; - if (replaceArch == null) { - replaceWithBox.setSelectedIndex(1); - iconLabel.setIcon(null); - rfArchName.setText(""); - colonLabel.setText(""); - } else { - replaceWithBox.setSelectedIndex(0); - iconLabel.setIcon(mainControl.getArchetypeSet().getFace(replaceArch.getFaceObjName())); - rfArchName.setText(" " + replaceArch.getBestName()); - colonLabel.setText(":"); - } - - final MapViewIFrame mapViewIFrame = mapControl.getMapViewFrame(); - if (mapViewIFrame != null && mapViewIFrame.isHighlight()) { - replaceEntireBox.setSelectedIndex(1); // selected squares - } else { - replaceEntireBox.setSelectedIndex(0); // entire map - } - - dialog.pack(); - dialog.toFront(); - dialog.setVisible(true); - } - } - - /** - * Update which arch is displayed as replace object. - * @param newArch the new 'replaceArch' to be shown and stored - * @param alwaysPack if false, the frame is packed only when icon size - * changed if true, the frame is always packed (packing - * resizes but also causes flicker) - */ - public void updateArchSelection(final GameObject newArch, final boolean alwaysPack) { - if (isShowing() && replaceWithBox.getSelectedIndex() == 0) { - replaceArch = newArch; - if (newArch != null) { - final Icon oldIcon = iconLabel.getIcon(); - - iconLabel.setIcon(mainControl.getArchetypeSet().getFace(newArch.getFaceObjName())); - rfArchName.setText(" " + newArch.getBestName()); - colonLabel.setText(":"); - - // pack frame only if height of icon changed - if (alwaysPack || (oldIcon == null && iconLabel.getIcon() != null) || (oldIcon != null && iconLabel.getIcon() == null) || (oldIcon != iconLabel.getIcon() && oldIcon != null && oldIcon.getIconHeight() != iconLabel.getIcon().getIconHeight())) { - dialog.pack(); - } - } else { - replaceWithBox.setSelectedIndex(1); - iconLabel.setIcon(null); - rfArchName.setText(""); - colonLabel.setText(""); - } - } - } - - /** - * This method performs the actual replace action on a map. - * @param matchCriteria matching criteria for replace - * @param matchString this is what to search for - * @param entireMap if true, the entire map is affected - if false, - * only highlighted area - * @param deleteOnly if true matching arches get only deleted and not - * replaced - * @return number of arches that have been replaced - */ - private int doReplace(final int matchCriteria, final String matchString, final boolean entireMap, final boolean deleteOnly) { - final List<GameObject> replaceList; - switch (lastSelectedIndex) { - case 0: - if (replaceArch == null) { - replaceList = null; - } else { - replaceList = new ArrayList<GameObject>(1); - replaceList.add(replaceArch); - } - break; - - case 1: - replaceList = replaceCopyBuffer; - break; - - case 2: - replaceList = replacePickmap; - break; - - default: - replaceList = null; - break; - } - final MapViewIFrame mapViewIFrame = mapControl.getMapViewFrame(); - assert mapViewIFrame != null; - int replaceCount = 0; - final int replaceListSize = replaceList == null ? 0 : replaceList.size(); - mapControl.getMapModel().beginTransaction("Replace"); // TODO: I18N/L10N - for (final MapSquare<GameObject, MapArchObject> square : entireMap ? mapControl.getMapModel() : mapViewIFrame.getView().getSelectedSquares()) { - for (final GameObject node : square) { - if (!node.isMulti() && (matchCriteria == MATCH_ARCH_NAME && node.getArchetypeName() != null && node.getArchetypeName().equalsIgnoreCase(matchString) || matchCriteria == MATCH_OBJ_NAME && node.getBestName().equalsIgnoreCase(matchString))) { - if (replaceListSize > 0 && !deleteOnly) { - GameObject randomArch; - if (replaceListSize == 1) { - randomArch = replaceList.get(0); - } else { - randomArch = replaceList.get(MainControl.rnd.nextInt(replaceList.size())); - } - if (randomArch.isMulti()) { - // multi's cannot be inserted properly, so we just put them ontop - randomArch = randomArch.getHead(); - } - randomArch = randomArch.createArch(); - node.replace(randomArch); - } else { - node.remove(); - } - replaceCount++; - } - } - } - - mapControl.getMapModel().endTransaction(); - // now the map and toolbars must be redrawn - mapControl.repaint(); - return replaceCount; - } - - /** Item-listener for the "replace with"-selection box. */ - private class ReplaceWithBoxItemListener implements ItemListener { - - /** {@inheritDoc} */ - public void itemStateChanged(final ItemEvent e) { - final int selectedIndex = replaceWithBox.getSelectedIndex(); - if (e.getStateChange() == ItemEvent.SELECTED && lastSelectedIndex != selectedIndex) { - final int size; - switch (selectedIndex) { - case 0: - // replace with arch - replaceArch = mainControl.getArchPanelHighlight(); // selected arch - updateArchSelection(replaceArch, true); - break; - - case 1: - // replace with CopyBuffer - replaceCopyBuffer = CopyBuffer.getMapArchList(mainControl.getCopyMapCtrl(), 100); - iconLabel.setIcon(null); - if (replaceCopyBuffer == null) { - size = 0; - } else { - size = replaceCopyBuffer.size(); - } - rfArchName.setText(String.valueOf(size)); - colonLabel.setText(":"); - dialog.pack(); - break; - - case 2: - // replace with pickmap - replacePickmap = mainControl.getArchPanelSelection(); // selected arches - iconLabel.setIcon(null); - if (replacePickmap == null) { - size = 0; - } else { - size = replacePickmap.size(); - } - rfArchName.setText(String.valueOf(size)); - colonLabel.setText(":"); - dialog.pack(); - break; - - case 3: - // replace with nothing - iconLabel.setIcon(null); - rfArchName.setText(""); - colonLabel.setText(""); - dialog.pack(); - break; - } - lastSelectedIndex = selectedIndex; - } - } - - } // class ReplaceWithBoxItemListener - - /** - * Action method for Ok button. - */ - public void replaceOk() { - final String matchString = replaceInput1.getText().trim(); - final boolean deleteOnly = replaceWithBox.getSelectedIndex() == 3; - final boolean entireMap = replaceEntireBox.getSelectedIndex() == 0; - - final MapViewIFrame mapViewIFrame = mapControl.getMapViewFrame(); - if (mapControl == null || mapControl.isClosing()) { - setVisible(false); - ACTION_FACTORY.showMessageDialog(this, "replaceMapGone", mapControl.getMapFileName()); - } else if (!entireMap && (mapViewIFrame == null || !mapViewIFrame.isHighlight())) { - // user selected "replace highlighted" but nothing is highlighted - ACTION_FACTORY.showMessageDialog(this, "replaceMapNoSelection", mapControl.getMapFileName()); - } else { - final int matchCriteria; - if (replaceCriteria.getSelectedIndex() == 0) { - matchCriteria = MATCH_ARCH_NAME; - } else if (replaceCriteria.getSelectedIndex() == 1) { - matchCriteria = MATCH_OBJ_NAME; - } else { - matchCriteria = 0; - } - - final int replaceCount = doReplace(matchCriteria, matchString, entireMap, deleteOnly); - if (replaceCount > 0) { - dialog.setVisible(false); - if (replaceCount == 1) { - ACTION_FACTORY.showMessageDialog(this, "replacedOne"); - } else { - ACTION_FACTORY.showMessageDialog(this, "replacedMany", replaceCount); - } - } else { - ACTION_FACTORY.showMessageDialog(this, "replacedZero"); - } - } - } - - /** - * Action method for Cancel button. - */ - public void replaceCancel() { - dialog.setVisible(false); - } - -} // class ReplaceDialog Modified: trunk/daimonin/src/daieditor/gui/ObjectChoiceDisplay.java =================================================================== --- trunk/daimonin/src/daieditor/gui/ObjectChoiceDisplay.java 2007-01-07 01:50:37 UTC (rev 1475) +++ trunk/daimonin/src/daieditor/gui/ObjectChoiceDisplay.java 2007-01-07 02:18:16 UTC (rev 1476) @@ -25,7 +25,6 @@ package daieditor.gui; import daieditor.CMainControl; -import daieditor.ReplaceDialog; import daieditor.gameobject.GameObject; import daieditor.map.MapArchObject; import java.awt.Color; Copied: trunk/daimonin/src/daieditor/gui/ReplaceDialog.java (from rev 1475, trunk/daimonin/src/daieditor/ReplaceDialog.java) =================================================================== --- trunk/daimonin/src/daieditor/gui/ReplaceDialog.java (rev 0) +++ trunk/daimonin/src/daieditor/gui/ReplaceDialog.java 2007-01-07 02:18:16 UTC (rev 1476) @@ -0,0 +1,459 @@ +/* + * Daimonin Java Editor. + * Copyright (C) 2000 Michael Toennies + * Copyright (C) 2001 Andreas Vogl + * Copyright (C) 2005 Christian Hujer + * + * (code based on: Gridder. 2D grid based level editor. (C) 2000 Pasi Keränen) + * + * 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., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + */ + +package daieditor.gui; + +import daieditor.CMainControl; +import daieditor.CopyBuffer; +import daieditor.MapViewIFrame; +import daieditor.gameobject.GameObject; +import daieditor.map.MapArchObject; +import daieditor.map.MapControl; +import java.awt.FlowLayout; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.util.ArrayList; +import java.util.List; +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.Icon; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.WindowConstants; +import net.sf.gridarta.MainControl; +import net.sf.gridarta.map.MapSquare; +import net.sf.japi.swing.ActionFactory; + +/** + * This dialog manages the replace action. + * @author <a href="mailto:and...@gm...">Andreas Vogl</a> + * @author <a href="mailto:ch...@ri...">Christian.Hujer</a> + */ +public final class ReplaceDialog extends JOptionPane { + + /** Serial Version UID. */ + private static final long serialVersionUID = 1L; + + /** Action Factory. */ + private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("daieditor"); + + // matching criteria + public static final int MATCH_ARCH_NAME = 0; + + public static final int MATCH_OBJ_NAME = 1; + + /** Singleton Instance. */ + private static ReplaceDialog instance = null; + + /** Dialog. */ + private JDialog dialog; + + private final CMainControl mainControl; + + private boolean isBuilt = false; + + private MapControl mapControl; + + private GameObject replaceArch = null; // objects will be replaced by this arch + + private List<GameObject> replaceCopyBuffer; // objects in CopyBuffer + + private List<GameObject> replacePickmap; // selected objects in pickmap or all if none is selected + + private JLabel rfHeading; + + private JLabel rfArchName = null; + + private JLabel iconLabel; + + private JLabel colonLabel; + + private JComboBox replaceCriteria; + + private JComboBox replaceWithBox; + + private JComboBox replaceEntireBox; + + private JTextField replaceInput1; + + private int lastSelectedIndex; + + /** + * Construct instance. + * @param mainControl MainControl + */ + private ReplaceDialog(final CMainControl mainControl) { + dialog = createDialog(mainControl.getMainView(), ACTION_FACTORY.getString("replaceTitle")); + dialog.setModal(false); + dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); + this.mainControl = mainControl; + } + + /** + * Returns whether this frame has been fully built. + * @return <code>true</code> if this frame has been fully built, otherwise <code>false</code> + */ ... [truncated message content] |
From: <aki...@us...> - 2007-01-07 02:28:53
|
Revision: 1477 http://svn.sourceforge.net/gridarta/?rev=1477&view=rev Author: akirschbaum Date: 2007-01-06 18:28:53 -0800 (Sat, 06 Jan 2007) Log Message: ----------- Move ScriptArchData to gameobject.scripts package. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/GameObject.java trunk/daimonin/src/daieditor/gameobject/GameObject.java Added Paths: ----------- trunk/crossfire/src/cfeditor/gameobject/scripts/ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java trunk/daimonin/src/daieditor/gameobject/scripts/ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/ScriptArchData.java trunk/daimonin/src/daieditor/ScriptArchData.java Deleted: trunk/crossfire/src/cfeditor/ScriptArchData.java =================================================================== --- trunk/crossfire/src/cfeditor/ScriptArchData.java 2007-01-07 02:18:16 UTC (rev 1476) +++ trunk/crossfire/src/cfeditor/ScriptArchData.java 2007-01-07 02:28:53 UTC (rev 1477) @@ -1,901 +0,0 @@ -/* - * Crossfire Java Editor. - * Copyright (C) 2000 Michael Toennies - * Copyright (C) 2001 Andreas Vogl - * - * (code based on: Gridder. 2D grid based level editor. (C) 2000 Pasi Keränen) - * - * 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., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - * - */ - -package cfeditor; - -import cfeditor.gameobject.GameObject; -import cfeditor.gui.GameObjectAttributesPanel; -import java.awt.Color; -import java.awt.FlowLayout; -import java.awt.Insets; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import javax.swing.BorderFactory; -import javax.swing.Box; -import javax.swing.BoxLayout; -import javax.swing.JButton; -import javax.swing.JComboBox; -import javax.swing.JDialog; -import javax.swing.JFileChooser; -import javax.swing.JLabel; -import javax.swing.JList; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JTextField; -import javax.swing.WindowConstants; -import static javax.swing.WindowConstants.HIDE_ON_CLOSE; -import net.sf.gridarta.textedit.scripteditor.ScriptEditControl; -import net.sf.japi.swing.ActionFactory; -import net.sf.japi.util.Arrays2; -import org.apache.log4j.Logger; -import org.jetbrains.annotations.Nullable; - -/** - * Stores and manages information about scripted events. - * This data is only needed for those arches with one or more events defined. - * @author <a href="mailto:and...@gm...">Andreas Vogl</a> - * @XXX This class is designed very badly, as it combines model and presentation. - */ -public final class ScriptArchData { - - /** Logger. */ - private static final Logger log = Logger.getLogger(ScriptArchData.class); - - // constants for addEventData() parameters - public static final int EDATA_PLUGIN_NAME = 0; - - public static final int EDATA_FILE_PATH = 1; - - public static final int EDATA_EVENT_OPTIONS = 2; - - /** Action Factory. */ - private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); - - // popup frame to edit script paths: - private static JDialog pathFrame; - - private static JTextField inputFPath; - - private static JTextField inputPlName; - - private static JTextField inputEEOptions; - - private static PathButtonListener ccListener; - - private static PathButtonListener okListener; - - // popup frame for new scripts: - private static JDialog newScriptFrame; - - private static JLabel nsHeading; - - private static PathButtonListener nsOkListener; - - private static JComboBox eventTypeBox; - - private static JComboBox pluginNameBox; - - private static JTextField inputNFPath; - - private static JTextField inputEventOptions; - - // FIXME: This should NOT BE HERE. Instead, it should be read from types.xml. - private static final String[] allEventTypes = new String[]{" apply", " attack", " close", " death", " drop", " pickup", " say", " stop", " time", " throw", " trigger"}; - - private final List<ScriptedEvent> eventList; // contains list of ScriptedEvents - - /** Create a ScriptArchData. */ - public ScriptArchData() { - eventList = new ArrayList<ScriptedEvent>(); - if (eventTypeBox == null) { - initEventTypeBoxes(); - } - } - - /** Initialize the JComboBox with the event types. */ - private static synchronized void initEventTypeBoxes() { - pluginNameBox = new JComboBox(new String[]{" Python"}); - pluginNameBox.setSelectedIndex(0); - - eventTypeBox = new JComboBox(allEventTypes); - eventTypeBox.setSelectedIndex(Arrays2.linearEqualitySearch(" say", allEventTypes)); - } - - /** - * Add given data to a ScriptedEvent. If no event of given type exists, a - * new one is created. - * @param eventType event type ("say", "attack", "death", ...) - * @param eventData new data about the ScriptedEvent, kind of data is - * defined by 'dataType' - * @param dataType 0: pluginData = "plugin name" - * 1: pluginData = "file path" - */ - public synchronized void addEventData(final String eventType, final String eventData, final int dataType) { - // first try to find an existing event - final ScriptedEvent event; - final int index = getScriptedEvent(eventType); - - // if none exists yet, create new - else take the existing one - if (index == -1) { - event = new ScriptedEvent(eventType); - } else { - event = eventList.get(index); - } - - // set new event data: - if (dataType == EDATA_PLUGIN_NAME) { - event.setPluginName(eventData.trim()); // set plugin name - } else if (dataType == EDATA_FILE_PATH) { - event.setFilePath(eventData.trim()); // set plugin name - } else if (dataType == EDATA_EVENT_OPTIONS) { - event.setEventOptions(eventData.trim()); // set event options - } - - // save changes: - if (index == -1) { - eventList.add(event); - } else { - eventList.set(index, event); - } - } - - /** - * Search 'eventList' for an existing ScriptedEvent of the specified event - * type. - * @param eventType look for a ScriptedEvent of this type - * @return index of ScriptedEvent in 'eventList' if found, -1 if not found - */ - private int getScriptedEvent(final String eventType) { - if (eventList != null && !eventList.isEmpty()) { - for (int i = 0; i < eventList.size(); i++) { - final ScriptedEvent se = eventList.get(i); - if (se.getEventType().equalsIgnoreCase(eventType)) { - // we found a matching ScriptedEvent! - return i; - } - } - } - - return -1; // didn't find a matching event - } - - /** - * This method is called for each arch after loading a map. It checks - * whether all events have enough data to be valid. Invalid or insufficient - * ScriptedEvent objects get removed. - * @return true when at least one valid event remains, false when all - * events were invalid (and deleted) - */ - public boolean validateAllEvents() { - if (eventList != null && !eventList.isEmpty()) { - int numEvents = eventList.size(); - - for (int i = 0; i < numEvents; i++) { - final ScriptedEvent se = eventList.get(i); - // validate this event - if (!se.isValid()) { - // this event is invalid - if (log.isInfoEnabled()) { - log.info("-> Deleting invalid event..."); - } - eventList.remove(i); - numEvents--; // adjust indices for removed element - i--; - } - } - - if (!eventList.isEmpty()) { - return true; // there is at least one remaining valid event - } - } - return false; - } - - /** - * This method is called from CMapFileEncode.writeMapArch(). - * @return text for all scripted events, how it is written in a mapfile - * (the String is expected to end with '\n', unless empty) - */ - public String getMapArchEventData() { - final StringBuilder buff = new StringBuilder(); - - if (eventList != null && !eventList.isEmpty()) { - for (final ScriptedEvent se : eventList) { - buff.append(se.getMapArchText()); - } - } - - return buff.toString(); - } - - /** - * Set all ScriptedEvents to appear in the given JList This method should - * be fast because it may be executed when user clicks on map objects. - * @param list JList - */ - public void addEventsToJList(final JList list) { - final String[] content = new String[eventList.size()]; - for (int i = 0; i < eventList.size(); i++) { - content[i] = " " + eventList.get(i).getEventType(); - } - - list.setListData(content); - list.setSelectedIndex(0); - } - - /** - * Create a new ScriptArchData instance, identical to this one. - * @return a cloned instance of this ScriptArchData object - */ - @Nullable public ScriptArchData getClone() { - if (eventList != null && !eventList.isEmpty()) { - final ScriptArchData clone = new ScriptArchData(); // new instance - - for (int i = 0; i < eventList.size(); i++) { - // clone every ScriptedEvent in the event list - clone.eventList.add(eventList.get(i).getClone()); - } - - return clone; - } else { - return null; - } - } - - public static JDialog getPathFrame() { - return pathFrame; - } - - /** - * If there is a scripted event of the specified type, the script pad is - * opened and the appropriate script displayed. - * @param eventType type of event - * @param task ID number for task (open script/ edit path/ remove) - * @param panelList JList from the MapArchPanel (script tab) which displays - * the events - */ - public void modifyEventScript(final String eventType, final int task, final JList panelList) { - final int index = getScriptedEvent(eventType); - - if (index >= 0) { - final ScriptedEvent event = eventList.get(index); - // now decide what to do: - if (task == GameObjectAttributesPanel.SCRIPT_OPEN) { - event.openScript(); - } else if (task == GameObjectAttributesPanel.SCRIPT_EDIT_PATH) { - // show popup to edit file path and plugin name - event.editScriptPath(); - eventList.set(index, event); // save changes - } else if (task == GameObjectAttributesPanel.SCRIPT_REMOVE) { - // first ask for confirmation - if (JOptionPane.showConfirmDialog(panelList, "Are you sure you want to remove this \"" + eventType + "\" event which is\n" + "linked to the script: '" + event.getFilePath() + "'?\n" + "(The script file itself is not going to be deleted)", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) { - // remove this event from the GameObject - eventList.remove(index); - addEventsToJList(panelList); // update panel JList - } - } - } else { - log.error("Error in modifyEventScript(): No event for '" + eventType + "'"); - } - } - - /** - * Try to create a reasonable default script name for lazy users. - * @param archName the best suitable name for the arch (see GameObject.getBestName()) - * @return a nice default script name without whitespaces - */ - private static String chooseDefaultScriptName(final String archName) { - String defScriptName = archName.trim(); - final int i; - if ((i = defScriptName.indexOf(" ")) >= 0) { - if (defScriptName.length() > 12 || defScriptName.lastIndexOf(" ") != i) { - // if there are several whitespaces or the name is too long, just cut off the end - defScriptName = defScriptName.substring(0, i); - } else { - // if there is only one whitespace in a short name, remove whitespace - defScriptName = defScriptName.substring(0, i) + defScriptName.substring(i + 1, i + 2).toUpperCase() + defScriptName.substring(i + 2); - } - } - if (defScriptName.length() >= 3) { - defScriptName = defScriptName.substring(0, 1).toUpperCase() + defScriptName.substring(1); - } - defScriptName += "Script.py"; - - return defScriptName; - } - - /** - * This method is called when the user selects a new event to be created. - * The path relative to the map dir is calculated, and if reasonable, - * a relative path is created (relative to the map the event is on). - * @param f script file - * @return local event path - */ - private static String localizeEventPath(final File f) { - final CMainControl mainControl = CMainControl.getInstance(); // main control - final File localMapDir = mainControl.getCurrentMap().getMapFile().getParentFile(); // local map directory - final File mapDir = new File(mainControl.getMapDefaultFolder()); // global map directory - - if (!mapDir.exists()) { - log.warn("Map directory '" + mapDir.getAbsolutePath() + "' does not exist!"); - return f.getName(); - } - - // find out if the scriptfile is in a subdirectory of the map file - File tmp; - for (tmp = f.getParentFile(); tmp != null && !tmp.getAbsolutePath().equalsIgnoreCase(localMapDir.getAbsolutePath()); tmp = tmp.getParentFile()) { - ; - } - - String path; - if (tmp == null) { - // scriptfile is NOT in a subirectory of mapfile -> absolute path - path = f.getAbsolutePath().substring(mapDir.getAbsolutePath().length()); - path = path.replace('\\', '/'); - if (!path.startsWith("/")) { - path = "/" + path; // leading slash - } - } else { - // scriptfile is in a subirectory of mapfile -> relative path - path = f.getAbsolutePath().substring(localMapDir.getAbsolutePath().length()); - path = path.replace('\\', '/'); - while (path.length() > 0 && path.startsWith("/")) { - path = path.substring(1); // no leading slash - } - } - return path; - } - - /** - * A popup is opened and the user can create a new scripting event - * which gets attached to this gameObject. - * @param panelList JList from the MapArchPanel (script tab) which displays the events - * @param gameObject GameObject that's name should be used for creating a reasonable default script name - */ - public void addEventScript(final JList panelList, final GameObject gameObject) { - final String archName = gameObject.getBestName(); - // create a reasonable default script name for lazy users :-) - final String defScriptName = chooseDefaultScriptName(archName); - - if (newScriptFrame == null) { - // initialize popup frame - newScriptFrame = new JDialog(CMainControl.getInstance().getMainView(), "New Scripted Event", true); - newScriptFrame.setDefaultCloseOperation(HIDE_ON_CLOSE); - - final JPanel mainPanel = new JPanel(); - mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); - mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 2, 5)); - - // first line: heading - final JPanel line1 = new JPanel(new FlowLayout(FlowLayout.LEFT)); - nsHeading = new JLabel("New scripted event for \"" + archName + "\":"); - nsHeading.setForeground(Color.black); - line1.add(nsHeading); - mainPanel.add(line1); - - // event type - mainPanel.add(Box.createVerticalStrut(10)); - final JPanel line2 = new JPanel(new FlowLayout(FlowLayout.LEFT)); - final JLabel tlabel1 = new JLabel("Event Type: "); - line2.add(tlabel1); - line2.add(eventTypeBox); - //mainPanel.add(line2); - line2.add(Box.createHorizontalStrut(10)); - - // plugin name - final JLabel tlabel2 = new JLabel("Plugin: "); - line2.add(tlabel2); - line2.add(pluginNameBox); - mainPanel.add(line2); - - // path - mainPanel.add(Box.createVerticalStrut(5)); - final JPanel line3 = new JPanel(new FlowLayout(FlowLayout.LEFT)); - final JLabel tlabel3 = new JLabel("Script File:"); - line3.add(tlabel3); - final int diff = tlabel1.getPreferredSize().width - tlabel3.getPreferredSize().width - 5; - if (diff > 0) { - line3.add(Box.createHorizontalStrut(diff)); - } - - mainPanel.add(line3); - inputNFPath = new JTextField(defScriptName, 20); - final JButton browseb = new JButton("..."); - browseb.setMargin(new Insets(0, 10, 0, 10)); - browseb.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - final File home = CMainControl.getInstance().getCurrentMap().getMapFile().getParentFile(); // map dir - - final JFileChooser fileChooser = new JFileChooser(); - fileChooser.setDialogTitle("Select Script File"); - fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); - fileChooser.setCurrentDirectory(home); - fileChooser.setMultiSelectionEnabled(false); - fileChooser.setFileFilter(CMainControl.getInstance().getScriptFileFilter()); - - if (fileChooser.showOpenDialog(newScriptFrame) == JFileChooser.APPROVE_OPTION) { - // user has selected a file - final File f = fileChooser.getSelectedFile(); - inputNFPath.setText(localizeEventPath(f)); - } - } - }); - line3.add(inputNFPath); - line3.add(browseb); - mainPanel.add(line3); - - // description - final JPanel line4 = new JPanel(new FlowLayout(FlowLayout.LEFT)); - final JPanel textPanel = new JPanel(); - textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.Y_AXIS)); - final JLabel tlabel4 = new JLabel("When you specify an existing file, the new event will be linked"); - textPanel.add(tlabel4); - final JLabel tlabel5 = new JLabel("to that existing script. Otherwise a new script file is created."); - textPanel.add(tlabel5); - line4.add(textPanel); - mainPanel.add(line4); - - // event options input - mainPanel.add(Box.createVerticalStrut(10)); - final JPanel line5 = new JPanel(new FlowLayout(FlowLayout.LEFT)); - final JLabel tlabel6 = new JLabel("Event Options: "); - line5.add(tlabel6); - inputEventOptions = new JTextField(25); - line5.add(inputEventOptions); - mainPanel.add(line5); - - // button panel: - mainPanel.add(Box.createVerticalStrut(10)); - final JPanel line6 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - final JButton nsOkButton = new JButton("OK"); - nsOkListener = new PathButtonListener(true, newScriptFrame, this); - nsOkButton.addActionListener(nsOkListener); - line6.add(nsOkButton); - - final JButton cancelButton = new JButton("Cancel"); - cancelButton.addActionListener(new PathButtonListener(false, newScriptFrame, null)); - line6.add(cancelButton); - mainPanel.add(line6); - - newScriptFrame.getContentPane().add(mainPanel); - newScriptFrame.pack(); - newScriptFrame.setLocationRelativeTo(CMainControl.getInstance().getMainView()); - newScriptFrame.setVisible(true); - } else { - // just set fields and show - nsHeading.setText("New scripted event for \"" + archName + "\":"); - inputNFPath.setText(defScriptName); - inputEventOptions.setText(""); - nsOkListener.setScriptArchData(this); - newScriptFrame.toFront(); - newScriptFrame.setVisible(true); - } - } - - /** - * The user has chosen to create a new event, now it is to be done. - * @param frame the parent window of the create-new-event dialog - */ - public void createNewEvent(final JDialog frame) { - final CMainControl mainControl = CMainControl.getInstance(); // main control - String scriptPath = inputNFPath.getText().trim(); - final String eventType = ((String) (eventTypeBox.getSelectedItem())).trim(); - final String pluginName = ((String) (pluginNameBox.getSelectedItem())).trim(); - final String eventOptions = inputEventOptions.getText().trim(); - - final File localMapDir = mainControl.getCurrentMap().getMapFile().getParentFile(); // local map directory - - // first check if that event type is not already in use - final int replaceIndex = getScriptedEvent(eventType); - if (replaceIndex != -1) { - // collision with existing event -> ask user: replace? - if (JOptionPane.showConfirmDialog(frame, "An event of type \"" + eventType + "\" already exists for this object.\n" + "Do you want to replace the existing event?", "Event exists", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.NO_OPTION) { - // bail out - return; - } - } - - // convert localized scriptPath into real, absolute path - scriptPath = scriptPath.replace('\\', '/'); - String absScriptPath; - if (scriptPath.startsWith("/")) { - // script path is absolute - final File mapDir = new File(mainControl.getMapDefaultFolder()); // global map directory - if (mapDir.exists()) { - absScriptPath = mapDir.getAbsolutePath() + scriptPath; - } else { - // if map dir doesn't exist, this is not going to work - frame.setVisible(false); - ACTION_FACTORY.showMessageDialog(frame, "mapDirDoesntExist", mapDir); - return; - } - } else { - // script path is relative - absScriptPath = localMapDir.getAbsolutePath() + "/" + scriptPath; - } - - // now check if the specified path points to an existing script - File newScriptFile = new File(absScriptPath); - if (!newScriptFile.exists() && !absScriptPath.endsWith(".py")) { - absScriptPath += ".py"; - scriptPath += ".py"; - newScriptFile = new File(absScriptPath); - } - - if (newScriptFile.exists()) { - if (newScriptFile.isFile()) { - // file exists -> link it to the event - final ScriptedEvent event = new ScriptedEvent(eventType, pluginName, scriptPath, eventOptions); - if (replaceIndex == -1) { - eventList.add(event); - } else { - eventList.set(replaceIndex, event); - } - frame.setVisible(false); // close dialog - } - } else { - if (!absScriptPath.endsWith(".py")) { - absScriptPath += ".py"; - scriptPath += ".py"; - newScriptFile = new File(absScriptPath); - } - - // file does not exist -> aks user: create new file? - if (JOptionPane.showConfirmDialog(frame, "Create new script '" + newScriptFile.getName() + "'?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.YES_OPTION) { - // okay, create new script file and open it - boolean couldCreateFile = false; // true when file creation successful - try { - // try to create new empty file - couldCreateFile = newScriptFile.createNewFile(); - } catch (final IOException e) { - } - - if (couldCreateFile) { - // file has been created, now link it to the event - final ScriptedEvent event = new ScriptedEvent(eventType, pluginName, scriptPath, eventOptions); - if (replaceIndex != -1) { - eventList.set(replaceIndex, event); - } else { - eventList.add(event); - } - frame.setVisible(false); // close dialog - - // open new script file - ScriptEditControl.getInstance().openScriptFile(newScriptFile.getAbsolutePath()); - } else { - JOptionPane.showMessageDialog(frame, "File '" + newScriptFile.getName() + "' could not be created.\n" + - "Please check your path and write premissions.", - "Cannot create file", JOptionPane.ERROR_MESSAGE); - } - } - } - } - - /** - * Returns whether this ScriptArchData is empty (contains no events). - * (Note that empty ScriptArchData objects always are removed ASAP) - * @return <code>true</code> if this ScriptArchData contains no events, otherwise <code>false</code>. - */ - public boolean isEmpty() { - return eventList == null || eventList.isEmpty(); - } - - /** Inner class which stores information about one scripted event. */ - private final class ScriptedEvent { - - private String pluginName; // name of plugin ("Python" expected) - - private String eventType; // name of event type (e.g. "say", "death", "attack"...) - - private String eventOptions; // event options - - private String filePath; // path to scriptfile (can be a relative or absolute path) - - /** - * Construct a ScriptedEvent of given type (This is used for map-loading). - * @param eventType Type of the event. - */ - ScriptedEvent(final String eventType) { - this.eventType = eventType; - pluginName = null; - filePath = null; - } - - /** - * Creates a fully initialized ScriptedEvent. - * @param eventType Type of the event. - * @param pluginName Name of the plugin. - * @param filePath Path the the script. - * @param eventOptions Options for the Event. - */ - ScriptedEvent(final String eventType, final String pluginName, final String filePath, final String eventOptions) { - this.eventType = eventType; - this.pluginName = pluginName; - this.filePath = filePath; - this.eventOptions = eventOptions; - } - - /** - * Validate this event object: Check if there is sufficient data. - * @return true if this object is valid, otherwise false - */ - public boolean isValid() { - if (filePath == null || filePath.length() <= 0) { - log.error("Map Error: Found event_" + eventType + " without file name!"); - return false; - } - - if (pluginName == null || pluginName.length() <= 0) { - pluginName = "Python"; - if (log.isInfoEnabled()) { - log.info("Found event_" + eventType + " without plugin name. Setting to \"Python\"."); - } - } - - filePath = filePath.replace('\\', '/'); // just make sure there are only slashes: '/' - - return true; - } - - /** - * Returns the text that has to be written to a map file for this ScriptedEvent. - * @return Event text for the map file. - */ - public String getMapArchText() { - final StringBuilder buff = new StringBuilder(""); - buff.append("event_").append(eventType).append("_plugin ").append(pluginName).append("\n"); - buff.append("event_").append(eventType).append(" ").append(filePath).append("\n"); - if (eventOptions != null && eventOptions.trim().length() > 0) { - buff.append("event_").append(eventType).append("_options ").append(eventOptions).append("\n"); - } - return buff.toString(); - } - - /** - * Creates a clone of this object. - * @return Clone of this object. - * @todo instead override {@link Object#clone()}. - */ - public ScriptedEvent getClone() { - final ScriptedEvent clone = new ScriptedEvent(eventType); - clone.pluginName = pluginName; - clone.filePath = filePath; - clone.eventOptions = eventOptions; - - return clone; - } - - /** Opens the script pad to display the script for this event. */ - public void openScript() { - final CMainControl mainControl = CMainControl.getInstance(); // reference to main control - - // trying to get the absolute path to scriptfile: - String path; - if (filePath.startsWith("/")) { - // filepath is absolue (to map base directory): - path = mainControl.getMapDefaultFolder(); - path += filePath; - } else { - // file path is relative to map dir - path = mainControl.getCurrentMap().getMapFile().getParentFile().getAbsolutePath(); // map dir - if (!path.endsWith("/")) { - path += '/'; // append slash to map dir - } - path += filePath; // append relative path to map dir - path = path.replace('\\', '/'); // make sure there's only one kind of slash - } - - // now see if that file really exists: - final File scriptFile = new File(path); - if (scriptFile.exists() && scriptFile.isFile()) { - ScriptEditControl.getInstance().openScriptFile(scriptFile.getAbsolutePath()); - } else { - // file does not exist! - ACTION_FACTORY.showMessageDialog(mainControl.getMainView(), "openScriptNotFound", path); - } - } - - /** - * Edit path and plugin name for this event. A popup dialog is shown - * with input textfields for file path and plugin name. - */ - public void editScriptPath() { - if (pathFrame == null) { - // initialize popup frame - pathFrame = new JDialog(CMainControl.getInstance().getMainView(), "Edit Parameters", true); - pathFrame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); - - final JPanel mainPanel = new JPanel(); - mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); - mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 2, 5)); - - // input line: script path - final JPanel line1 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - final JLabel text1 = new JLabel("Script:"); - line1.add(text1); - inputFPath = new JTextField(filePath, 20); - line1.add(inputFPath); - mainPanel.add(line1); - - // input line: plugin name - final JPanel line2 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - final JLabel text2 = new JLabel("Plugin Name:"); - line2.add(text2); - inputPlName = new JTextField(pluginName, 20); - line2.add(inputPlName); - mainPanel.add(line2); - - // input line: event options - final JPanel line3 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - final JLabel text3 = new JLabel("Event Options:"); - line3.add(text3); - inputEEOptions = new JTextField(eventOptions, 20); - line3.add(inputEEOptions); - mainPanel.add(line3); - mainPanel.add(Box.createVerticalStrut(5)); - - // button panel: - final JPanel line4 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - final JButton okButton = new JButton("OK"); - okListener = new PathButtonListener(true, pathFrame, null); - okListener.setTargetEvent(this); - okButton.addActionListener(okListener); - line4.add(okButton); - - final JButton cancelButton = new JButton("Cancel"); - ccListener = new PathButtonListener(false, pathFrame, null); - ccListener.setTargetEvent(this); - cancelButton.addActionListener(ccListener); - line4.add(cancelButton); - mainPanel.add(line4); - - pathFrame.getContentPane().add(mainPanel); - pathFrame.pack(); - pathFrame.setLocationRelativeTo(CMainControl.getInstance().getMainView()); - pathFrame.setVisible(true); - } else { - // just set fields and show - okListener.setTargetEvent(this); - ccListener.setTargetEvent(this); - inputFPath.setText(filePath); - inputPlName.setText(pluginName); - inputEEOptions.setText(eventOptions); - pathFrame.toFront(); - pathFrame.setVisible(true); - } - } - - /** - * Set event path and plugin name according to user input from popup - * dialog. - */ - public void modifyEventPath() { - final String newPath = inputFPath.getText().trim(); - final String newPlName = inputPlName.getText().trim(); - final String newEvOptions = inputEEOptions.getText().trim(); - if (newPath.length() > 0) { - filePath = newPath; - } - if (newPlName.length() > 0) { - pluginName = newPlName; - } - eventOptions = newEvOptions; // unlike the above two, event options can be empty - } - - // GET/SET methods - public String getEventType() { - return eventType; - } - - public String getPluginName() { - return pluginName; - } - - public String getFilePath() { - return filePath; - } - - public void setPluginName(final String name) { - pluginName = name; - } - - public void setFilePath(final String path) { - filePath = path; - } - - public void setEventOptions(final String options) { - eventOptions = options; - } - - } // class ScriptedEvent - - /** - * Small class, listening for button-press events in the popup frame for - * script paths or create-new-event frame. - */ - private static final class PathButtonListener implements ActionListener { - - private final JDialog frame; - - private final boolean isOkButton; - - /** - * The target event to script. - */ - private ScriptedEvent scriptedEvent; // target event - - /** - * The ScriptArchData to operate on. - */ - private ScriptArchData scriptArchData; - - /** - * Create a PathButtonListener. - * @param isOkButton true for ok-buttons - * @param frame frame this listener belongs to - * @param scriptArchData this is only set for the ok-button of "create new" frame, otherwise null - */ - PathButtonListener(final boolean isOkButton, final JDialog frame, @Nullable final ScriptArchData scriptArchData) { - this.isOkButton = isOkButton; - this.frame = frame; - this.scriptArchData = scriptArchData; - } - - /** - * Set the target event to script. - * @param scriptedEvent new target event to script. - */ - public void setTargetEvent(final ScriptedEvent scriptedEvent) { - this.scriptedEvent = scriptedEvent; - } - - /** - * Set the ScriptArchData to operate on. - * @param scriptArchData ScriptArchData to operate on. - */ - public void setScriptArchData(final ScriptArchData scriptArchData) { - this.scriptArchData = scriptArchData; - } - - /** {@inheritDoc} */ - public void actionPerformed(final ActionEvent e) { - if (isOkButton && scriptArchData == null && scriptedEvent != null) { - scriptedEvent.modifyEventPath(); // ok button for modifying path - } - - if (isOkButton && scriptArchData != null) { - // ok button for creating a new event/script - scriptArchData.createNewEvent(frame); - } else { - frame.setVisible(false); // hide dialog - } - } - - } // class PathButtonListener - -} // class ScriptArchData Modified: trunk/crossfire/src/cfeditor/gameobject/GameObject.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2007-01-07 02:18:16 UTC (rev 1476) +++ trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2007-01-07 02:28:53 UTC (rev 1477) @@ -26,7 +26,7 @@ import cfeditor.AutojoinList; import cfeditor.IGUIConstants; -import cfeditor.ScriptArchData; +import cfeditor.gameobject.scripts.ScriptArchData; import cfeditor.gui.GameObjectAttributesPanel; import cfeditor.map.MapArchObject; import java.io.BufferedReader; Copied: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java (from rev 1475, trunk/crossfire/src/cfeditor/ScriptArchData.java) =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java (rev 0) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2007-01-07 02:28:53 UTC (rev 1477) @@ -0,0 +1,902 @@ +/* + * Crossfire Java Editor. + * Copyright (C) 2000 Michael Toennies + * Copyright (C) 2001 Andreas Vogl + * + * (code based on: Gridder. 2D grid based level editor. (C) 2000 Pasi Keränen) + * + * 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., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + */ + +package cfeditor.gameobject.scripts; + +import cfeditor.CMainControl; +import cfeditor.gameobject.GameObject; +import cfeditor.gui.GameObjectAttributesPanel; +import java.awt.Color; +import java.awt.FlowLayout; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JDialog; +import javax.swing.JFileChooser; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.WindowConstants; +import static javax.swing.WindowConstants.HIDE_ON_CLOSE; +import net.sf.gridarta.textedit.scripteditor.ScriptEditControl; +import net.sf.japi.swing.ActionFactory; +import net.sf.japi.util.Arrays2; +import org.apache.log4j.Logger; +import org.jetbrains.annotations.Nullable; + +/** + * Stores and manages information about scripted events. + * This data is only needed for those arches with one or more events defined. + * @author <a href="mailto:and...@gm...">Andreas Vogl</a> + * @XXX This class is designed very badly, as it combines model and presentation. + */ +public final class ScriptArchData { + + /** Logger. */ + private static final Logger log = Logger.getLogger(ScriptArchData.class); + + // constants for addEventData() parameters + public static final int EDATA_PLUGIN_NAME = 0; + + public static final int EDATA_FILE_PATH = 1; + + public static final int EDATA_EVENT_OPTIONS = 2; + + /** Action Factory. */ + private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); + + // popup frame to edit script paths: + private static JDialog pathFrame; + + private static JTextField inputFPath; + + private static JTextField inputPlName; + + private static JTextField inputEEOptions; + + private static PathButtonListener ccListener; + + private static PathButtonListener okListener; + + // popup frame for new scripts: + private static JDialog newScriptFrame; + + private static JLabel nsHeading; + + private static PathButtonListener nsOkListener; + + private static JComboBox eventTypeBox; + + private static JComboBox pluginNameBox; + + private static JTextField inputNFPath; + + private static JTextField inputEventOptions; + + // FIXME: This should NOT BE HERE. Instead, it should be read from types.xml. + private static final String[] allEventTypes = new String[]{" apply", " attack", " close", " death", " drop", " pickup", " say", " stop", " time", " throw", " trigger"}; + + private final List<ScriptedEvent> eventList; // contains list of ScriptedEvents + + /** Create a ScriptArchData. */ + public ScriptArchData() { + eventList = new ArrayList<ScriptedEvent>(); + if (eventTypeBox == null) { + initEventTypeBoxes(); + } + } + + /** Initialize the JComboBox with the event types. */ + private static synchronized void initEventTypeBoxes() { + pluginNameBox = new JComboBox(new String[]{" Python"}); + pluginNameBox.setSelectedIndex(0); + + eventTypeBox = new JComboBox(allEventTypes); + eventTypeBox.setSelectedIndex(Arrays2.linearEqualitySearch(" say", allEventTypes)); + } + + /** + * Add given data to a ScriptedEvent. If no event of given type exists, a + * new one is created. + * @param eventType event type ("say", "attack", "death", ...) + * @param eventData new data about the ScriptedEvent, kind of data is + * defined by 'dataType' + * @param dataType 0: pluginData = "plugin name" + * 1: pluginData = "file path" + */ + public synchronized void addEventData(final String eventType, final String eventData, final int dataType) { + // first try to find an existing event + final ScriptedEvent event; + final int index = getScriptedEvent(eventType); + + // if none exists yet, create new - else take the existing one + if (index == -1) { + event = new ScriptedEvent(eventType); + } else { + event = eventList.get(index); + } + + // set new event data: + if (dataType == EDATA_PLUGIN_NAME) { + event.setPluginName(eventData.trim()); // set plugin name + } else if (dataType == EDATA_FILE_PATH) { + event.setFilePath(eventData.trim()); // set plugin name + } else if (dataType == EDATA_EVENT_OPTIONS) { + event.setEventOptions(eventData.trim()); // set event options + } + + // save changes: + if (index == -1) { + eventList.add(event); + } else { + eventList.set(index, event); + } + } + + /** + * Search 'eventList' for an existing ScriptedEvent of the specified event + * type. + * @param eventType look for a ScriptedEvent of this type + * @return index of ScriptedEvent in 'eventList' if found, -1 if not found + */ + private int getScriptedEvent(final String eventType) { + if (eventList != null && !eventList.isEmpty()) { + for (int i = 0; i < eventList.size(); i++) { + final ScriptedEvent se = eventList.get(i); + if (se.getEventType().equalsIgnoreCase(eventType)) { + // we found a matching ScriptedEvent! + return i; + } + } + } + + return -1; // didn't find a matching event + } + + /** + * This method is called for each arch after loading a map. It checks + * whether all events have enough data to be valid. Invalid or insufficient + * ScriptedEvent objects get removed. + * @return true when at least one valid event remains, false when all + * events were invalid (and deleted) + */ + public boolean validateAllEvents() { + if (eventList != null && !eventList.isEmpty()) { + int numEvents = eventList.size(); + + for (int i = 0; i < numEvents; i++) { + final ScriptedEvent se = eventList.get(i); + // validate this event + if (!se.isValid()) { + // this event is invalid + if (log.isInfoEnabled()) { + log.info("-> Deleting invalid event..."); + } + eventList.remove(i); + numEvents--; // adjust indices for removed element + i--; + } + } + + if (!eventList.isEmpty()) { + return true; // there is at least one remaining valid event + } + } + return false; + } + + /** + * This method is called from CMapFileEncode.writeMapArch(). + * @return text for all scripted events, how it is written in a mapfile + * (the String is expected to end with '\n', unless empty) + */ + public String getMapArchEventData() { + final StringBuilder buff = new StringBuilder(); + + if (eventList != null && !eventList.isEmpty()) { + for (final ScriptedEvent se : eventList) { + buff.append(se.getMapArchText()); + } + } + + return buff.toString(); + } + + /** + * Set all ScriptedEvents to appear in the given JList This method should + * be fast because it may be executed when user clicks on map objects. + * @param list JList + */ + public void addEventsToJList(final JList list) { + final String[] content = new String[eventList.size()]; + for (int i = 0; i < eventList.size(); i++) { + content[i] = " " + eventList.get(i).getEventType(); + } + + list.setListData(content); + list.setSelectedIndex(0); + } + + /** + * Create a new ScriptArchData instance, identical to this one. + * @return a cloned instance of this ScriptArchData object + */ + @Nullable public ScriptArchData getClone() { + if (eventList != null && !eventList.isEmpty()) { + final ScriptArchData clone = new ScriptArchData(); // new instance + + for (int i = 0; i < eventList.size(); i++) { + // clone every ScriptedEvent in the event list + clone.eventList.add(eventList.get(i).getClone()); + } + + return clone; + } else { + return null; + } + } + + public static JDialog getPathFrame() { + return pathFrame; + } + + /** + * If there is a scripted event of the specified type, the script pad is + * opened and the appropriate script displayed. + * @param eventType type of event + * @param task ID number for task (open script/ edit path/ remove) + * @param panelList JList from the MapArchPanel (script tab) which displays + * the events + */ + public void modifyEventScript(final String eventType, final int task, final JList panelList) { + final int index = getScriptedEvent(eventType); + + if (index >= 0) { + final ScriptedEvent event = eventList.get(index); + // now decide what to do: + if (task == GameObjectAttributesPanel.SCRIPT_OPEN) { + event.openScript(); + } else if (task == GameObjectAttributesPanel.SCRIPT_EDIT_PATH) { + // show popup to edit file path and plugin name + event.editScriptPath(); + eventList.set(index, event); // save changes + } else if (task == GameObjectAttributesPanel.SCRIPT_REMOVE) { + // first ask for confirmation + if (JOptionPane.showConfirmDialog(panelList, "Are you sure you want to remove this \"" + eventType + "\" event which is\n" + "linked to the script: '" + event.getFilePath() + "'?\n" + "(The script file itself is not going to be deleted)", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) { + // remove this event from the GameObject + eventList.remove(index); + addEventsToJList(panelList); // update panel JList + } + } + } else { + log.error("Error in modifyEventScript(): No event for '" + eventType + "'"); + } + } + + /** + * Try to create a reasonable default script name for lazy users. + * @param archName the best suitable name for the arch (see GameObject.getBestName()) + * @return a nice default script name without whitespaces + */ + private static String chooseDefaultScriptName(final String archName) { + String defScriptName = archName.trim(); + final int i; + if ((i = defScriptName.indexOf(" ")) >= 0) { + if (defScriptName.length() > 12 || defScriptName.lastIndexOf(" ") != i) { + // if there are several whitespaces or the name is too long, just cut off the end + defScriptName = defScriptName.substring(0, i); + } else { + // if there is only one whitespace in a short name, remove whitespace + defScriptName = defScriptName.substring(0, i) + defScriptName.substring(i + 1, i + 2).toUpperCase() + defScriptName.substring(i + 2); + } + } + if (defScriptName.length() >= 3) { + defScriptName = defScriptName.substring(0, 1).toUpperCase() + defScriptName.substring(1); + } + defScriptName += "Script.py"; + + return defScriptName; + } + + /** + * This method is called when the user selects a new event to be created. + * The path relative to the map dir is calculated, and if reasonable, + * a relative path is created (relative to the map the event is on). + * @param f script file + * @return local event path + */ + private static String localizeEventPath(final File f) { + final CMainControl mainControl = CMainControl.getInstance(); // main control + final File localMapDir = mainControl.getCurrentMap().getMapFile().getParentFile(); // local map directory + final File mapDir = new File(mainControl.getMapDefaultFolder()); // global map directory + + if (!mapDir.exists()) { + log.warn("Map directory '" + mapDir.getAbsolutePath() + "' does not exist!"); + return f.getName(); + } + + // find out if the scriptfile is in a subdirectory of the map file + File tmp; + for (tmp = f.getParentFile(); tmp != null && !tmp.getAbsolutePath().equalsIgnoreCase(localMapDir.getAbsolutePath()); tmp = tmp.getParentFile()) { + ; + } + + String path; + if (tmp == null) { + // scriptfile is NOT in a subirectory of mapfile -> absolute path + path = f.getAbsolutePath().substring(mapDir.getAbsolutePath().length()); + path = path.replace('\\', '/'); + if (!path.startsWith("/")) { + path = "/" + path; // leading slash + } + } else { + // scriptfile is in a subirectory of mapfile -> relative path + path = f.getAbsolutePath().substring(localMapDir.getAbsolutePath().length()); + path = path.replace('\\', '/'); + while (path.length() > 0 && path.startsWith("/")) { + path = path.substring(1); // no leading slash + } + } + return path; + } + + /** + * A popup is opened and the user can create a new scripting event + * which gets attached to this gameObject. + * @param panelList JList from the MapArchPanel (script tab) which displays the events + * @param gameObject GameObject that's name should be used for creating a reasonable default script name + */ + public void addEventScript(final JList panelList, final GameObject gameObject) { + final String archName = gameObject.getBestName(); + // create a reasonable default script name for lazy users :-) + final String defScriptName = chooseDefaultScriptName(archName); + + if (newScriptFrame == null) { + // initialize popup frame + newScriptFrame = new JDialog(CMainControl.getInstance().getMainView(), "New Scripted Event", true); + newScriptFrame.setDefaultCloseOperation(HIDE_ON_CLOSE); + + final JPanel mainPanel = new JPanel(); + mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); + mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 2, 5)); + + // first line: heading + final JPanel line1 = new JPanel(new FlowLayout(FlowLayout.LEFT)); + nsHeading = new JLabel("New scripted event for \"" + archName + "\":"); + nsHeading.setForeground(Color.black); + line1.add(nsHeading); + mainPanel.add(line1); + + // event type + mainPanel.add(Box.createVerticalStrut(10)); + final JPanel line2 = new JPanel(new FlowLayout(FlowLayout.LEFT)); + final JLabel tlabel1 = new JLabel("Event Type: "); + line2.add(tlabel1); + line2.add(eventTypeBox); + //mainPanel.add(line2); + line2.add(Box.createHorizontalStrut(10)); + + // plugin name + final JLabel tlabel2 = new JLabel("Plugin: "); + line2.add(tlabel2); + line2.add(pluginNameBox); + mainPanel.add(line2); + + // path + mainPanel.add(Box.createVerticalStrut(5)); + final JPanel line3 = new JPanel(new FlowLayout(FlowLayout.LEFT)); + final JLabel tlabel3 = new JLabel("Script File:"); + line3.add(tlabel3); + final int diff = tlabel1.getPreferredSize().width - tlabel3.getPreferredSize().width - 5; + if (diff > 0) { + line3.add(Box.createHorizontalStrut(diff)); + } + + mainPanel.add(line3); + inputNFPath = new JTextField(defScriptName, 20); + final JButton browseb = new JButton("..."); + browseb.setMargin(new Insets(0, 10, 0, 10)); + browseb.addActionListener(new ActionListener() { + public void actionPerformed(final ActionEvent e) { + final File home = CMainControl.getInstance().getCurrentMap().getMapFile().getParentFile(); // map dir + + final JFileChooser fileChooser = new JFileChooser(); + fileChooser.setDialogTitle("Select Script File"); + fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); + fileChooser.setCurrentDirectory(home); + fileChooser.setMultiSelectionEnabled(false); + fileChooser.setFileFilter(CMainControl.getInstance().getScriptFileFilter()); + + if (fileChooser.showOpenDialog(newScriptFrame) == JFileChooser.APPROVE_OPTION) { + // user has selected a file + final File f = fileChooser.getSelectedFile(); + inputNFPath.setText(localizeEventPath(f)); + } + } + }); + line3.add(inputNFPath); + line3.add(browseb); + mainPanel.add(line3); + + // description + final JPanel line4 = new JPanel(new FlowLayout(FlowLayout.LEFT)); + final JPanel textPanel = new JPanel(); + textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.Y_AXIS)); + final JLabel tlabel4 = new JLabel("When you specify an existing file, the new event will be linked"); + textPanel.add(tlabel4); + final JLabel tlabel5 = new JLabel("to that existing script. Otherwise a new script file is created."); + textPanel.add(tlabel5); + line4.add(textPanel); + mainPanel.add(line4); + + // event options input + mainPanel.add(Box.createVerticalStrut(10)); + final JPanel line5 = new JPanel(new FlowLayout(FlowLayout.LEFT)); + final JLabel tlabel6 = new JLabel("Event Options: "); + line5.add(tlabel6); + inputEventOptions = new JTextField(25); + line5.add(inputEventOptions); + mainPanel.add(line5); + + // button panel: + mainPanel.add(Box.createVerticalStrut(10)); + final JPanel line6 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + final JButton nsOkButton = new JButton("OK"); + nsOkListener = new PathButtonListener(true, newScriptFrame, this); + nsOkButton.addActionListener(nsOkListener); + line6.add(nsOkButton); + + final JButton cancelButton = new JButton("Cancel"); + cancelButton.addActionListener(new PathButtonListener(false, newScriptFrame, null)); + line6.add(cancelButton); + mainPanel.add(line6); + + newScriptFrame.getContentPane().add(mainPanel); + newScriptFrame.pack(); + newScriptFrame.setLocationRelativeTo(CMainControl.getInstance().getMainView()); + newScriptFrame.setVisible(true); + } else { + // just set fields and show + nsHeading.setText("New scripted event for \"" + archName + "\":"); + inputNFPath.setText(defScriptName); + inputEventOptions.setText(""); + nsOkListener.setScriptArchData(this); + newScriptFrame.toFront(); + newScriptFrame.se... [truncated message content] |
From: <aki...@us...> - 2007-01-07 10:14:41
|
Revision: 1478 http://svn.sourceforge.net/gridarta/?rev=1478&view=rev Author: akirschbaum Date: 2007-01-07 02:14:39 -0800 (Sun, 07 Jan 2007) Log Message: ----------- Extract inner class to separate file. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java Added Paths: ----------- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2007-01-07 02:28:53 UTC (rev 1477) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2007-01-07 10:14:39 UTC (rev 1478) @@ -48,7 +48,6 @@ import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; -import javax.swing.WindowConstants; import static javax.swing.WindowConstants.HIDE_ON_CLOSE; import net.sf.gridarta.textedit.scripteditor.ScriptEditControl; import net.sf.japi.swing.ActionFactory; @@ -77,19 +76,6 @@ /** Action Factory. */ private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); - // popup frame to edit script paths: - private static JDialog pathFrame; - - private static JTextField inputFPath; - - private static JTextField inputPlName; - - private static JTextField inputEEOptions; - - private static PathButtonListener ccListener; - - private static PathButtonListener okListener; - // popup frame for new scripts: private static JDialog newScriptFrame; @@ -268,10 +254,6 @@ } } - public static JDialog getPathFrame() { - return pathFrame; - } - /** * If there is a scripted event of the specified type, the script pad is * opened and the appropriate script displayed. @@ -606,240 +588,11 @@ return eventList == null || eventList.isEmpty(); } - /** Inner class which stores information about one scripted event. */ - private final class ScriptedEvent { - - private String pluginName; // name of plugin ("Python" expected) - - private String eventType; // name of event type (e.g. "say", "death", "attack"...) - - private String eventOptions; // event options - - private String filePath; // path to scriptfile (can be a relative or absolute path) - - /** - * Construct a ScriptedEvent of given type (This is used for map-loading). - * @param eventType Type of the event. - */ - ScriptedEvent(final String eventType) { - this.eventType = eventType; - pluginName = null; - filePath = null; - } - - /** - * Creates a fully initialized ScriptedEvent. - * @param eventType Type of the event. - * @param pluginName Name of the plugin. - * @param filePath Path the the script. - * @param eventOptions Options for the Event. - */ - ScriptedEvent(final String eventType, final String pluginName, final String filePath, final String eventOptions) { - this.eventType = eventType; - this.pluginName = pluginName; - this.filePath = filePath; - this.eventOptions = eventOptions; - } - - /** - * Validate this event object: Check if there is sufficient data. - * @return true if this object is valid, otherwise false - */ - public boolean isValid() { - if (filePath == null || filePath.length() <= 0) { - log.error("Map Error: Found event_" + eventType + " without file name!"); - return false; - } - - if (pluginName == null || pluginName.length() <= 0) { - pluginName = "Python"; - if (log.isInfoEnabled()) { - log.info("Found event_" + eventType + " without plugin name. Setting to \"Python\"."); - } - } - - filePath = filePath.replace('\\', '/'); // just make sure there are only slashes: '/' - - return true; - } - - /** - * Returns the text that has to be written to a map file for this ScriptedEvent. - * @return Event text for the map file. - */ - public String getMapArchText() { - final StringBuilder buff = new StringBuilder(""); - buff.append("event_").append(eventType).append("_plugin ").append(pluginName).append("\n"); - buff.append("event_").append(eventType).append(" ").append(filePath).append("\n"); - if (eventOptions != null && eventOptions.trim().length() > 0) { - buff.append("event_").append(eventType).append("_options ").append(eventOptions).append("\n"); - } - return buff.toString(); - } - - /** - * Creates a clone of this object. - * @return Clone of this object. - * @todo instead override {@link Object#clone()}. - */ - public ScriptedEvent getClone() { - final ScriptedEvent clone = new ScriptedEvent(eventType); - clone.pluginName = pluginName; - clone.filePath = filePath; - clone.eventOptions = eventOptions; - - return clone; - } - - /** Opens the script pad to display the script for this event. */ - public void openScript() { - final CMainControl mainControl = CMainControl.getInstance(); // reference to main control - - // trying to get the absolute path to scriptfile: - String path; - if (filePath.startsWith("/")) { - // filepath is absolue (to map base directory): - path = mainControl.getMapDefaultFolder(); - path += filePath; - } else { - // file path is relative to map dir - path = mainControl.getCurrentMap().getMapFile().getParentFile().getAbsolutePath(); // map dir - if (!path.endsWith("/")) { - path += '/'; // append slash to map dir - } - path += filePath; // append relative path to map dir - path = path.replace('\\', '/'); // make sure there's only one kind of slash - } - - // now see if that file really exists: - final File scriptFile = new File(path); - if (scriptFile.exists() && scriptFile.isFile()) { - ScriptEditControl.getInstance().openScriptFile(scriptFile.getAbsolutePath()); - } else { - // file does not exist! - ACTION_FACTORY.showMessageDialog(mainControl.getMainView(), "openScriptNotFound", path); - } - } - - /** - * Edit path and plugin name for this event. A popup dialog is shown - * with input textfields for file path and plugin name. - */ - public void editScriptPath() { - if (pathFrame == null) { - // initialize popup frame - pathFrame = new JDialog(CMainControl.getInstance().getMainView(), "Edit Parameters", true); - pathFrame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); - - final JPanel mainPanel = new JPanel(); - mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); - mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 2, 5)); - - // input line: script path - final JPanel line1 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - final JLabel text1 = new JLabel("Script:"); - line1.add(text1); - inputFPath = new JTextField(filePath, 20); - line1.add(inputFPath); - mainPanel.add(line1); - - // input line: plugin name - final JPanel line2 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - final JLabel text2 = new JLabel("Plugin Name:"); - line2.add(text2); - inputPlName = new JTextField(pluginName, 20); - line2.add(inputPlName); - mainPanel.add(line2); - - // input line: event options - final JPanel line3 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - final JLabel text3 = new JLabel("Event Options:"); - line3.add(text3); - inputEEOptions = new JTextField(eventOptions, 20); - line3.add(inputEEOptions); - mainPanel.add(line3); - mainPanel.add(Box.createVerticalStrut(5)); - - // button panel: - final JPanel line4 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - final JButton okButton = new JButton("OK"); - okListener = new PathButtonListener(true, pathFrame, null); - okListener.setTargetEvent(this); - okButton.addActionListener(okListener); - line4.add(okButton); - - final JButton cancelButton = new JButton("Cancel"); - ccListener = new PathButtonListener(false, pathFrame, null); - ccListener.setTargetEvent(this); - cancelButton.addActionListener(ccListener); - line4.add(cancelButton); - mainPanel.add(line4); - - pathFrame.getContentPane().add(mainPanel); - pathFrame.pack(); - pathFrame.setLocationRelativeTo(CMainControl.getInstance().getMainView()); - pathFrame.setVisible(true); - } else { - // just set fields and show - okListener.setTargetEvent(this); - ccListener.setTargetEvent(this); - inputFPath.setText(filePath); - inputPlName.setText(pluginName); - inputEEOptions.setText(eventOptions); - pathFrame.toFront(); - pathFrame.setVisible(true); - } - } - - /** - * Set event path and plugin name according to user input from popup - * dialog. - */ - public void modifyEventPath() { - final String newPath = inputFPath.getText().trim(); - final String newPlName = inputPlName.getText().trim(); - final String newEvOptions = inputEEOptions.getText().trim(); - if (newPath.length() > 0) { - filePath = newPath; - } - if (newPlName.length() > 0) { - pluginName = newPlName; - } - eventOptions = newEvOptions; // unlike the above two, event options can be empty - } - - // GET/SET methods - public String getEventType() { - return eventType; - } - - public String getPluginName() { - return pluginName; - } - - public String getFilePath() { - return filePath; - } - - public void setPluginName(final String name) { - pluginName = name; - } - - public void setFilePath(final String path) { - filePath = path; - } - - public void setEventOptions(final String options) { - eventOptions = options; - } - - } // class ScriptedEvent - /** * Small class, listening for button-press events in the popup frame for * script paths or create-new-event frame. */ - private static final class PathButtonListener implements ActionListener { + public static final class PathButtonListener implements ActionListener { private final JDialog frame; Added: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java (rev 0) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java 2007-01-07 10:14:39 UTC (rev 1478) @@ -0,0 +1,289 @@ +/* + * Gridarta Map Editor. + * Copyright (C) 2007 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., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +package cfeditor.gameobject.scripts; + +import cfeditor.CMainControl; +import java.io.File; +import java.awt.FlowLayout; +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.WindowConstants; +import net.sf.gridarta.textedit.scripteditor.ScriptEditControl; +import net.sf.japi.swing.ActionFactory; +import org.apache.log4j.Logger; + +/** Class which stores information about one scripted event. */ +public final class ScriptedEvent { + + /** Logger. */ + private static final Logger log = Logger.getLogger(ScriptedEvent.class); + + /** Action Factory. */ + private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); + + private static JTextField inputFPath; + + private static JTextField inputPlName; + + private static JTextField inputEEOptions; + + private static ScriptArchData.PathButtonListener ccListener; + + private static ScriptArchData.PathButtonListener okListener; + + private String pluginName; // name of plugin ("Python" expected) + + private String eventType; // name of event type (e.g. "say", "death", "attack"...) + + private String eventOptions; // event options + + private String filePath; // path to scriptfile (can be a relative or absolute path) + + // popup frame to edit script paths: + private static JDialog pathFrame; + + /** + * Construct a ScriptedEvent of given type (This is used for map-loading). + * @param eventType Type of the event. + */ + ScriptedEvent(final String eventType) { + this.eventType = eventType; + pluginName = null; + filePath = null; + } + + /** + * Creates a fully initialized ScriptedEvent. + * @param eventType Type of the event. + * @param pluginName Name of the plugin. + * @param filePath Path the the script. + * @param eventOptions Options for the Event. + */ + ScriptedEvent(final String eventType, final String pluginName, final String filePath, final String eventOptions) { + this.eventType = eventType; + this.pluginName = pluginName; + this.filePath = filePath; + this.eventOptions = eventOptions; + } + + /** + * Validate this event object: Check if there is sufficient data. + * @return true if this object is valid, otherwise false + */ + public boolean isValid() { + if (filePath == null || filePath.length() <= 0) { + log.error("Map Error: Found event_" + eventType + " without file name!"); + return false; + } + + if (pluginName == null || pluginName.length() <= 0) { + pluginName = "Python"; + if (log.isInfoEnabled()) { + log.info("Found event_" + eventType + " without plugin name. Setting to \"Python\"."); + } + } + + filePath = filePath.replace('\\', '/'); // just make sure there are only slashes: '/' + + return true; + } + + /** + * Returns the text that has to be written to a map file for this ScriptedEvent. + * @return Event text for the map file. + */ + public String getMapArchText() { + final StringBuilder buff = new StringBuilder(""); + buff.append("event_").append(eventType).append("_plugin ").append(pluginName).append("\n"); + buff.append("event_").append(eventType).append(" ").append(filePath).append("\n"); + if (eventOptions != null && eventOptions.trim().length() > 0) { + buff.append("event_").append(eventType).append("_options ").append(eventOptions).append("\n"); + } + return buff.toString(); + } + + /** + * Creates a clone of this object. + * @return Clone of this object. + * @todo instead override {@link Object#clone()}. + */ + public ScriptedEvent getClone() { + final ScriptedEvent clone = new ScriptedEvent(eventType); + clone.pluginName = pluginName; + clone.filePath = filePath; + clone.eventOptions = eventOptions; + + return clone; + } + + /** Opens the script pad to display the script for this event. */ + public void openScript() { + final CMainControl mainControl = CMainControl.getInstance(); // reference to main control + + // trying to get the absolute path to scriptfile: + String path; + if (filePath.startsWith("/")) { + // filepath is absolue (to map base directory): + path = mainControl.getMapDefaultFolder(); + path += filePath; + } else { + // file path is relative to map dir + path = mainControl.getCurrentMap().getMapFile().getParentFile().getAbsolutePath(); // map dir + if (!path.endsWith("/")) { + path += '/'; // append slash to map dir + } + path += filePath; // append relative path to map dir + path = path.replace('\\', '/'); // make sure there's only one kind of slash + } + + // now see if that file really exists: + final File scriptFile = new File(path); + if (scriptFile.exists() && scriptFile.isFile()) { + ScriptEditControl.getInstance().openScriptFile(scriptFile.getAbsolutePath()); + } else { + // file does not exist! + ACTION_FACTORY.showMessageDialog(mainControl.getMainView(), "openScriptNotFound", path); + } + } + + /** + * Edit path and plugin name for this event. A popup dialog is shown + * with input textfields for file path and plugin name. + */ + public void editScriptPath() { + if (pathFrame == null) { + // initialize popup frame + pathFrame = new JDialog(CMainControl.getInstance().getMainView(), "Edit Parameters", true); + pathFrame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); + + final JPanel mainPanel = new JPanel(); + mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); + mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 2, 5)); + + // input line: script path + final JPanel line1 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + final JLabel text1 = new JLabel("Script:"); + line1.add(text1); + inputFPath = new JTextField(filePath, 20); + line1.add(inputFPath); + mainPanel.add(line1); + + // input line: plugin name + final JPanel line2 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + final JLabel text2 = new JLabel("Plugin Name:"); + line2.add(text2); + inputPlName = new JTextField(pluginName, 20); + line2.add(inputPlName); + mainPanel.add(line2); + + // input line: event options + final JPanel line3 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + final JLabel text3 = new JLabel("Event Options:"); + line3.add(text3); + inputEEOptions = new JTextField(eventOptions, 20); + line3.add(inputEEOptions); + mainPanel.add(line3); + mainPanel.add(Box.createVerticalStrut(5)); + + // button panel: + final JPanel line4 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + final JButton okButton = new JButton("OK"); + okListener = new ScriptArchData.PathButtonListener(true, pathFrame, null); + okListener.setTargetEvent(this); + okButton.addActionListener(okListener); + line4.add(okButton); + + final JButton cancelButton = new JButton("Cancel"); + ccListener = new ScriptArchData.PathButtonListener(false, pathFrame, null); + ccListener.setTargetEvent(this); + cancelButton.addActionListener(ccListener); + line4.add(cancelButton); + mainPanel.add(line4); + + pathFrame.getContentPane().add(mainPanel); + pathFrame.pack(); + pathFrame.setLocationRelativeTo(CMainControl.getInstance().getMainView()); + pathFrame.setVisible(true); + } else { + // just set fields and show + okListener.setTargetEvent(this); + ccListener.setTargetEvent(this); + inputFPath.setText(filePath); + inputPlName.setText(pluginName); + inputEEOptions.setText(eventOptions); + pathFrame.toFront(); + pathFrame.setVisible(true); + } + } + + /** + * Set event path and plugin name according to user input from popup + * dialog. + */ + public void modifyEventPath() { + final String newPath = inputFPath.getText().trim(); + final String newPlName = inputPlName.getText().trim(); + final String newEvOptions = inputEEOptions.getText().trim(); + if (newPath.length() > 0) { + filePath = newPath; + } + if (newPlName.length() > 0) { + pluginName = newPlName; + } + eventOptions = newEvOptions; // unlike the above two, event options can be empty + } + + // GET/SET methods + public String getEventType() { + return eventType; + } + + public String getPluginName() { + return pluginName; + } + + public String getFilePath() { + return filePath; + } + + public void setPluginName(final String name) { + pluginName = name; + } + + public void setFilePath(final String path) { + filePath = path; + } + + public void setEventOptions(final String options) { + eventOptions = options; + } + + public static JDialog getPathFrame() { + return pathFrame; + } + +} // class ScriptedEvent Property changes on: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2007-01-07 02:28:53 UTC (rev 1477) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2007-01-07 10:14:39 UTC (rev 1478) @@ -73,19 +73,6 @@ /** Action Factory. */ private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("daieditor"); - // popup frame to edit script paths: - private static JDialog pathFrame; - - private static JTextField inputFPath; - - private static JTextField inputPlName; - - private static JTextField inputPlOptions; - - private static PathButtonListener ccListener; - - private static PathButtonListener okListener; - // popup frame for new scripts: private static JDialog newScriptFrame; @@ -556,7 +543,7 @@ return true; } - private static String typeName(final int eventType) { + public static String typeName(final int eventType) { if (eventType > 0 && eventType <= allEventTypes.length) { return allEventTypes[eventType - 1]; } else { @@ -564,239 +551,11 @@ } } - /** Inner class which stores information about one scripted event. */ - private static final class ScriptedEvent { - - private final GameObject event; // Our event object - - /** - * Creates a ScriptedEvent of given type (This is used for map-loading). - * @param event GameObject that describes the event. - */ - ScriptedEvent(final GameObject event) { - this.event = event; - } - - /** - * Creates a fully initialized ScriptedEvent. - * @param eventType Type of the event. - * @param pluginName Name of the plugin. - * @param filePath Path to the file for this event. - * @param options Options for this event. - */ - ScriptedEvent(final int eventType, final String pluginName, final String filePath, final String options) { - event = new GameObject(); // FIXME: This arch has no default arch - event.setArchTypNr(118); - event.setArchetypeName("event_obj"); - event.setArchetype(CMainControl.getInstance().getArchetypeSet().getArchetype("event_obj")); - event.setObjectFace(); - setEventData(eventType, pluginName, filePath, options); - } - - /** - * Validate this event object: Check if there is sufficient data. - * @return true if this object is valid, otherwise false - */ - public boolean isValid() { - final String options = getOptions(); - String filePath = getFilePath(); - String pluginName = getPluginName(); - final int eventType = getEventType(); - - if (filePath == null || filePath.length() <= 0) { - log.error("Map Error: Found " + typeName(eventType) + " event without file name!"); - return false; - } - - if (pluginName == null || pluginName.length() <= 0) { - pluginName = "Python"; - if (log.isInfoEnabled()) { - log.info("Found " + typeName(eventType) + " without plugin name. Setting to \"Python\"."); - } - } - - filePath = filePath.replace('\\', '/'); // just make sure there are only slashes: '/' - - setEventData(eventType, pluginName, filePath, options); - - return true; - } - - /** Opens the script pad to display the script for this event. */ - public void openScript() { - final CMainControl mainControl = CMainControl.getInstance(); // reference to main control - final String filePath = getFilePath(); - - // trying to get the absolute path to scriptfile: - String path; - if (filePath.startsWith("/")) { - // filepath is absolue (to map base directory): - path = mainControl.getMapDefaultFolder(); - path += filePath; - } else { - // file path is relative to map dir - path = mainControl.getCurrentMap().getMapFile().getParentFile().getAbsolutePath(); // map dir - if (!path.endsWith("/")) { - path += '/'; // append slash to map dir - } - path += filePath; // append relative path to map dir - path = path.replace('\\', '/'); // make sure there's only one kind of slash - } - - // now see if that file really exists: - final File scriptFile = new File(path); - if (scriptFile.exists() && scriptFile.isFile()) { - ScriptEditControl.getInstance().openScriptFile(scriptFile.getAbsolutePath()); - } else { - // file does not exist! - ACTION_FACTORY.showMessageDialog(mainControl.getMainView(), "openScriptNotFound", path); - } - } - - /** - * Edit path and plugin name for this event. A popup dialog is shown - * with input textfields for file path and plugin name. - */ - public void editScriptPath() { - if (pathFrame == null) { - // initialize popup frame - pathFrame = new JDialog(CMainControl.getInstance().getMainView(), "Script Path", true); - pathFrame.setDefaultCloseOperation(HIDE_ON_CLOSE); - - final JPanel mainPanel = new JPanel(); - mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); - mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 2, 5)); - - // input line: script path - final JPanel line1 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - final JLabel text1 = new JLabel("Script:"); - line1.add(text1); - inputFPath = new JTextField(getFilePath(), 20); - line1.add(inputFPath); - mainPanel.add(line1); - - // input line: plugin options - final JPanel line2 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - final JLabel text2 = new JLabel("Script options:"); - line2.add(text2); - inputPlOptions = new JTextField(getOptions(), 20); - line2.add(inputPlOptions); - mainPanel.add(line2); - mainPanel.add(Box.createVerticalStrut(5)); - - // input line: plugin name - final JPanel line3 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - final JLabel text3 = new JLabel("Plugin name:"); - line3.add(text3); - inputPlName = new JTextField(getPluginName(), 20); - line3.add(inputPlName); - mainPanel.add(line3); - mainPanel.add(Box.createVerticalStrut(5)); - - // button panel: - final JPanel line4 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); - final JButton okButton = new JButton("OK"); - okListener = new PathButtonListener(true, pathFrame, null); - okListener.setTargetEvent(this); - okButton.addActionListener(okListener); - line4.add(okButton); - - final JButton cancelButton = new JButton("Cancel"); - ccListener = new PathButtonListener(false, pathFrame, null); - ccListener.setTargetEvent(this); - cancelButton.addActionListener(ccListener); - line4.add(cancelButton); - mainPanel.add(line4); - - pathFrame.getContentPane().add(mainPanel); - pathFrame.pack(); - pathFrame.setLocationRelativeTo(CMainControl.getInstance().getMainView()); - pathFrame.setVisible(true); - } else { - // just set fields and show - okListener.setTargetEvent(this); - ccListener.setTargetEvent(this); - inputFPath.setText(getFilePath()); - inputPlName.setText(getPluginName()); - inputPlOptions.setText(getOptions()); - pathFrame.toFront(); - pathFrame.setVisible(true); - } - } - - /** - * Set event path and plugin name according to user input from popup - * dialog. - */ - public void modifyEventPath() { - final String newPath = inputFPath.getText().trim(); - final String newPlName = inputPlName.getText().trim(); - final String newPlOptions = inputPlOptions.getText().trim(); - - if (newPath.length() > 0) { - setFilePath(newPath); - } - if (newPlName.length() > 0) { - setPluginName(newPlName); - } - if (newPlOptions.length() > 0) { - setOptions(newPlOptions); - } - } - - // GET/SET methods - public GameObject getEventArch() { - return event; - } - - public int getEventType() { - return event.getAttributeInt("sub_type"); - } - - public String getPluginName() { - return event.getBestName(); - } - - public String getFilePath() { - return event.getAttributeString("race"); - } - - public String getOptions() { - return event.getAttributeString("slaying"); - } - - public void setPluginName(final String name) { - setEventData(getEventType(), name, getFilePath(), getOptions()); - } - - public void setFilePath(final String path) { - setEventData(getEventType(), getPluginName(), path, getOptions()); - } - - public void setOptions(final String opts) { - setEventData(getEventType(), getPluginName(), getFilePath(), opts); - } - - private void setEventData(final int eventType, final String pluginName, final String filePath, final String options) { - event.resetObjectText(); - if (pluginName != null && pluginName.length() > 0) { - event.setObjName(pluginName); - } - if (filePath != null && filePath.length() > 0) { - event.addObjectText("race " + filePath); - } - if (options != null && options.length() > 0) { - event.addObjectText("slaying " + options); - } - event.addObjectText("sub_type " + eventType); - } - } // class ScriptedEvent - /** * Small class, listening for button-press events in the popup frame for * script paths or create-new-event frame. */ - private static final class PathButtonListener implements ActionListener { + public static final class PathButtonListener implements ActionListener { private final JDialog frame; Added: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java (rev 0) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java 2007-01-07 10:14:39 UTC (rev 1478) @@ -0,0 +1,286 @@ +/* + * Gridarta Map Editor. + * Copyright (C) 2007 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., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +package daieditor.gameobject.scripts; + +import daieditor.CMainControl; +import daieditor.gameobject.GameObject; +import java.awt.FlowLayout; +import java.io.File; +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; +import static javax.swing.WindowConstants.HIDE_ON_CLOSE; +import net.sf.gridarta.textedit.scripteditor.ScriptEditControl; +import net.sf.japi.swing.ActionFactory; +import org.apache.log4j.Logger; + +/** Class which stores information about one scripted event. */ +public final class ScriptedEvent { + + /** Logger. */ + private static final Logger log = Logger.getLogger(ScriptedEvent.class); + + /** Action Factory. */ + private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("daieditor"); + + private final GameObject event; // Our event object + + private static JTextField inputFPath; + + private static JTextField inputPlName; + + private static JTextField inputPlOptions; + + private static ScriptArchData.PathButtonListener ccListener; + + private static ScriptArchData.PathButtonListener okListener; + + // popup frame to edit script paths: + private static JDialog pathFrame; + + /** + * Creates a ScriptedEvent of given type (This is used for map-loading). + * @param event GameObject that describes the event. + */ + ScriptedEvent(final GameObject event) { + this.event = event; + } + + /** + * Creates a fully initialized ScriptedEvent. + * @param eventType Type of the event. + * @param pluginName Name of the plugin. + * @param filePath Path to the file for this event. + * @param options Options for this event. + */ + ScriptedEvent(final int eventType, final String pluginName, final String filePath, final String options) { + event = new GameObject(); // FIXME: This arch has no default arch + event.setArchTypNr(118); + event.setArchetypeName("event_obj"); + event.setArchetype(CMainControl.getInstance().getArchetypeSet().getArchetype("event_obj")); + event.setObjectFace(); + setEventData(eventType, pluginName, filePath, options); + } + + /** + * Validate this event object: Check if there is sufficient data. + * @return true if this object is valid, otherwise false + */ + public boolean isValid() { + final String options = getOptions(); + String filePath = getFilePath(); + String pluginName = getPluginName(); + final int eventType = getEventType(); + + if (filePath == null || filePath.length() <= 0) { + log.error("Map Error: Found " + ScriptArchData.typeName(eventType) + " event without file name!"); + return false; + } + + if (pluginName == null || pluginName.length() <= 0) { + pluginName = "Python"; + if (log.isInfoEnabled()) { + log.info("Found " + ScriptArchData.typeName(eventType) + " without plugin name. Setting to \"Python\"."); + } + } + + filePath = filePath.replace('\\', '/'); // just make sure there are only slashes: '/' + + setEventData(eventType, pluginName, filePath, options); + + return true; + } + + /** Opens the script pad to display the script for this event. */ + public void openScript() { + final CMainControl mainControl = CMainControl.getInstance(); // reference to main control + final String filePath = getFilePath(); + + // trying to get the absolute path to scriptfile: + String path; + if (filePath.startsWith("/")) { + // filepath is absolue (to map base directory): + path = mainControl.getMapDefaultFolder(); + path += filePath; + } else { + // file path is relative to map dir + path = mainControl.getCurrentMap().getMapFile().getParentFile().getAbsolutePath(); // map dir + if (!path.endsWith("/")) { + path += '/'; // append slash to map dir + } + path += filePath; // append relative path to map dir + path = path.replace('\\', '/'); // make sure there's only one kind of slash + } + + // now see if that file really exists: + final File scriptFile = new File(path); + if (scriptFile.exists() && scriptFile.isFile()) { + ScriptEditControl.getInstance().openScriptFile(scriptFile.getAbsolutePath()); + } else { + // file does not exist! + ACTION_FACTORY.showMessageDialog(mainControl.getMainView(), "openScriptNotFound", path); + } + } + + /** + * Edit path and plugin name for this event. A popup dialog is shown + * with input textfields for file path and plugin name. + */ + public void editScriptPath() { + if (pathFrame == null) { + // initialize popup frame + pathFrame = new JDialog(CMainControl.getInstance().getMainView(), "Script Path", true); + pathFrame.setDefaultCloseOperation(HIDE_ON_CLOSE); + + final JPanel mainPanel = new JPanel(); + mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); + mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 2, 5)); + + // input line: script path + final JPanel line1 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + final JLabel text1 = new JLabel("Script:"); + line1.add(text1); + inputFPath = new JTextField(getFilePath(), 20); + line1.add(inputFPath); + mainPanel.add(line1); + + // input line: plugin options + final JPanel line2 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + final JLabel text2 = new JLabel("Script options:"); + line2.add(text2); + inputPlOptions = new JTextField(getOptions(), 20); + line2.add(inputPlOptions); + mainPanel.add(line2); + mainPanel.add(Box.createVerticalStrut(5)); + + // input line: plugin name + final JPanel line3 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + final JLabel text3 = new JLabel("Plugin name:"); + line3.add(text3); + inputPlName = new JTextField(getPluginName(), 20); + line3.add(inputPlName); + mainPanel.add(line3); + mainPanel.add(Box.createVerticalStrut(5)); + + // button panel: + final JPanel line4 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); + final JButton okButton = new JButton("OK"); + okListener = new ScriptArchData.PathButtonListener(true, pathFrame, null); + okListener.setTargetEvent(this); + okButton.addActionListener(okListener); + line4.add(okButton); + + final JButton cancelButton = new JButton("Cancel"); + ccListener = new ScriptArchData.PathButtonListener(false, pathFrame, null); + ccListener.setTargetEvent(this); + cancelButton.addActionListener(ccListener); + line4.add(cancelButton); + mainPanel.add(line4); + + pathFrame.getContentPane().add(mainPanel); + pathFrame.pack(); + pathFrame.setLocationRelativeTo(CMainControl.getInstance().getMainView()); + pathFrame.setVisible(true); + } else { + // just set fields and show + okListener.setTargetEvent(this); + ccListener.setTargetEvent(this); + inputFPath.setText(getFilePath()); + inputPlName.setText(getPluginName()); + inputPlOptions.setText(getOptions()); + pathFrame.toFront(); + pathFrame.setVisible(true); + } + } + + /** + * Set event path and plugin name according to user input from popup + * dialog. + */ + public void modifyEventPath() { + final String newPath = inputFPath.getText().trim(); + final String newPlName = inputPlName.getText().trim(); + final String newPlOptions = inputPlOptions.getText().trim(); + + if (newPath.length() > 0) { + setFilePath(newPath); + } + if (newPlName.length() > 0) { + setPluginName(newPlName); + } + if (newPlOptions.length() > 0) { + setOptions(newPlOptions); + } + } + + // GET/SET methods + public GameObject getEventArch() { + return event; + } + + public int getEventType() { + return event.getAttributeInt("sub_type"); + } + + public String getPluginName() { + return event.getBestName(); + } + + public String getFilePath() { + return event.getAttributeString("race"); + } + + public String getOptions() { + return event.getAttributeString("slaying"); + } + + public void setPluginName(final String name) { + setEventData(getEventType(), name, getFilePath(), getOptions()); + } + + public void setFilePath(final String path) { + setEventData(getEventType(), getPluginName(), path, getOptions()); + } + + public void setOptions(final String opts) { + setEventData(getEventType(), getPluginName(), getFilePath(), opts); + } + + private void setEventData(final int eventType, final String pluginName, final String filePath, final String options) { + event.resetObjectText(); + if (pluginName != null && pluginName.length() > 0) { + event.setObjName(pluginName); + } + if (filePath != null && filePath.length() > 0) { + event.addObjectText("race " + filePath); + } + if (options != null && options.length() > 0) { + event.addObjectText("slaying " + options); + } + event.addObjectText("sub_type " + eventType); + } + +} // class ScriptedEvent Property changes on: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: 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...> - 2007-01-07 10:23:57
|
Revision: 1479 http://svn.sourceforge.net/gridarta/?rev=1479&view=rev Author: akirschbaum Date: 2007-01-07 02:23:57 -0800 (Sun, 07 Jan 2007) Log Message: ----------- Extract inner class to separate file. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java Added Paths: ----------- trunk/crossfire/src/cfeditor/gameobject/scripts/PathButtonListener.java trunk/daimonin/src/daieditor/gameobject/scripts/PathButtonListener.java Added: trunk/crossfire/src/cfeditor/gameobject/scripts/PathButtonListener.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/PathButtonListener.java (rev 0) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/PathButtonListener.java 2007-01-07 10:23:57 UTC (rev 1479) @@ -0,0 +1,90 @@ +/* + * Gridarta Map Editor. + * Copyright (C) 2007 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., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +package cfeditor.gameobject.scripts; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.JDialog; +import org.jetbrains.annotations.Nullable; + +/** + * Small class, listening for button-press events in the popup frame for + * script paths or create-new-event frame. + */ +public final class PathButtonListener implements ActionListener { + + private final JDialog frame; + + private final boolean isOkButton; + + /** + * The target event to script. + */ + private ScriptedEvent scriptedEvent; // target event + + /** + * The ScriptArchData to operate on. + */ + private ScriptArchData scriptArchData; + + /** + * Create a PathButtonListener. + * @param isOkButton true for ok-buttons + * @param frame frame this listener belongs to + * @param scriptArchData this is only set for the ok-button of "create new" frame, otherwise null + */ + PathButtonListener(final boolean isOkButton, final JDialog frame, @Nullable final ScriptArchData scriptArchData) { + this.isOkButton = isOkButton; + this.frame = frame; + this.scriptArchData = scriptArchData; + } + + /** + * Set the target event to script. + * @param scriptedEvent new target event to script. + */ + public void setTargetEvent(final ScriptedEvent scriptedEvent) { + this.scriptedEvent = scriptedEvent; + } + + /** + * Set the ScriptArchData to operate on. + * @param scriptArchData ScriptArchData to operate on. + */ + public void setScriptArchData(final ScriptArchData scriptArchData) { + this.scriptArchData = scriptArchData; + } + + /** {@inheritDoc} */ + public void actionPerformed(final ActionEvent e) { + if (isOkButton && scriptArchData == null && scriptedEvent != null) { + scriptedEvent.modifyEventPath(); // ok button for modifying path + } + + if (isOkButton && scriptArchData != null) { + // ok button for creating a new event/script + scriptArchData.createNewEvent(frame); + } else { + frame.setVisible(false); // hide dialog + } + } + +} // class PathButtonListener Property changes on: trunk/crossfire/src/cfeditor/gameobject/scripts/PathButtonListener.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2007-01-07 10:14:39 UTC (rev 1478) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2007-01-07 10:23:57 UTC (rev 1479) @@ -588,68 +588,4 @@ return eventList == null || eventList.isEmpty(); } - /** - * Small class, listening for button-press events in the popup frame for - * script paths or create-new-event frame. - */ - public static final class PathButtonListener implements ActionListener { - - private final JDialog frame; - - private final boolean isOkButton; - - /** - * The target event to script. - */ - private ScriptedEvent scriptedEvent; // target event - - /** - * The ScriptArchData to operate on. - */ - private ScriptArchData scriptArchData; - - /** - * Create a PathButtonListener. - * @param isOkButton true for ok-buttons - * @param frame frame this listener belongs to - * @param scriptArchData this is only set for the ok-button of "create new" frame, otherwise null - */ - PathButtonListener(final boolean isOkButton, final JDialog frame, @Nullable final ScriptArchData scriptArchData) { - this.isOkButton = isOkButton; - this.frame = frame; - this.scriptArchData = scriptArchData; - } - - /** - * Set the target event to script. - * @param scriptedEvent new target event to script. - */ - public void setTargetEvent(final ScriptedEvent scriptedEvent) { - this.scriptedEvent = scriptedEvent; - } - - /** - * Set the ScriptArchData to operate on. - * @param scriptArchData ScriptArchData to operate on. - */ - public void setScriptArchData(final ScriptArchData scriptArchData) { - this.scriptArchData = scriptArchData; - } - - /** {@inheritDoc} */ - public void actionPerformed(final ActionEvent e) { - if (isOkButton && scriptArchData == null && scriptedEvent != null) { - scriptedEvent.modifyEventPath(); // ok button for modifying path - } - - if (isOkButton && scriptArchData != null) { - // ok button for creating a new event/script - scriptArchData.createNewEvent(frame); - } else { - frame.setVisible(false); // hide dialog - } - } - - } // class PathButtonListener - } // class ScriptArchData Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java 2007-01-07 10:14:39 UTC (rev 1478) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java 2007-01-07 10:23:57 UTC (rev 1479) @@ -51,9 +51,9 @@ private static JTextField inputEEOptions; - private static ScriptArchData.PathButtonListener ccListener; + private static PathButtonListener ccListener; - private static ScriptArchData.PathButtonListener okListener; + private static PathButtonListener okListener; private String pluginName; // name of plugin ("Python" expected) @@ -212,13 +212,13 @@ // button panel: final JPanel line4 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); final JButton okButton = new JButton("OK"); - okListener = new ScriptArchData.PathButtonListener(true, pathFrame, null); + okListener = new PathButtonListener(true, pathFrame, null); okListener.setTargetEvent(this); okButton.addActionListener(okListener); line4.add(okButton); final JButton cancelButton = new JButton("Cancel"); - ccListener = new ScriptArchData.PathButtonListener(false, pathFrame, null); + ccListener = new PathButtonListener(false, pathFrame, null); ccListener.setTargetEvent(this); cancelButton.addActionListener(ccListener); line4.add(cancelButton); Added: trunk/daimonin/src/daieditor/gameobject/scripts/PathButtonListener.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/PathButtonListener.java (rev 0) +++ trunk/daimonin/src/daieditor/gameobject/scripts/PathButtonListener.java 2007-01-07 10:23:57 UTC (rev 1479) @@ -0,0 +1,91 @@ +/* + * Gridarta Map Editor. + * Copyright (C) 2007 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., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +package daieditor.gameobject.scripts; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.JDialog; +import org.jetbrains.annotations.Nullable; + +/** + * Small class, listening for button-press events in the popup frame for + * script paths or create-new-event frame. + */ +public final class PathButtonListener implements ActionListener { + + private final JDialog frame; + + private final boolean isOkButton; + + /** + * The target event to script. + */ + private ScriptedEvent scriptedEvent; // target event + + /** + * The ScriptArchData to operate on. + */ + private ScriptArchData scriptArchData; + + /** + * Creates a PathbuttonListener. + * @param isOkButton true for ok-buttons + * @param frame frame this listener belongs to + * @param scriptArchData this is only set for the ok-button of "create new" frame, otherwise null + */ + PathButtonListener(final boolean isOkButton, final JDialog frame, @Nullable final ScriptArchData scriptArchData) { + this.isOkButton = isOkButton; + this.frame = frame; + this.scriptArchData = scriptArchData; + } + + /** + * Set the target event to script. + * @param scriptedEvent new target event to script. + */ + public void setTargetEvent(final ScriptedEvent scriptedEvent) { + this.scriptedEvent = scriptedEvent; + } + + /** + * Set the ScriptArchData to operate on. + * @param scriptArchData ScriptArchData to operate on. + */ + public void setScriptArchData(final ScriptArchData scriptArchData) { + this.scriptArchData = scriptArchData; + } + + /** {@inheritDoc} */ + public void actionPerformed(final ActionEvent e) { + if (isOkButton && scriptArchData == null && scriptedEvent != null) { + scriptedEvent.modifyEventPath(); // ok button for modifying path + } + + if (isOkButton && scriptArchData != null) { + // ok button for creating a new event/script + scriptArchData.createNewEvent(frame); + scriptArchData.changed = true; + } else { + frame.setVisible(false); // hide dialog + } + } + +} // class PathButtonListener Property changes on: trunk/daimonin/src/daieditor/gameobject/scripts/PathButtonListener.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2007-01-07 10:14:39 UTC (rev 1478) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2007-01-07 10:23:57 UTC (rev 1479) @@ -93,7 +93,7 @@ private final GameObject owner; - private boolean changed; + boolean changed; /** * Creates a ScriptArchData. @@ -551,69 +551,4 @@ } } - /** - * Small class, listening for button-press events in the popup frame for - * script paths or create-new-event frame. - */ - public static final class PathButtonListener implements ActionListener { - - private final JDialog frame; - - private final boolean isOkButton; - - /** - * The target event to script. - */ - private ScriptedEvent scriptedEvent; // target event - - /** - * The ScriptArchData to operate on. - */ - private ScriptArchData scriptArchData; - - /** - * Creates a PathbuttonListener. - * @param isOkButton true for ok-buttons - * @param frame frame this listener belongs to - * @param scriptArchData this is only set for the ok-button of "create new" frame, otherwise null - */ - PathButtonListener(final boolean isOkButton, final JDialog frame, @Nullable final ScriptArchData scriptArchData) { - this.isOkButton = isOkButton; - this.frame = frame; - this.scriptArchData = scriptArchData; - } - - /** - * Set the target event to script. - * @param scriptedEvent new target event to script. - */ - public void setTargetEvent(final ScriptedEvent scriptedEvent) { - this.scriptedEvent = scriptedEvent; - } - - /** - * Set the ScriptArchData to operate on. - * @param scriptArchData ScriptArchData to operate on. - */ - public void setScriptArchData(final ScriptArchData scriptArchData) { - this.scriptArchData = scriptArchData; - } - - /** {@inheritDoc} */ - public void actionPerformed(final ActionEvent e) { - if (isOkButton && scriptArchData == null && scriptedEvent != null) { - scriptedEvent.modifyEventPath(); // ok button for modifying path - } - - if (isOkButton && scriptArchData != null) { - // ok button for creating a new event/script - scriptArchData.createNewEvent(frame); - scriptArchData.changed = true; - } else { - frame.setVisible(false); // hide dialog - } - } - - } // class PathButtonListener - } // class ScriptArchData Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java 2007-01-07 10:14:39 UTC (rev 1478) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java 2007-01-07 10:23:57 UTC (rev 1479) @@ -54,9 +54,9 @@ private static JTextField inputPlOptions; - private static ScriptArchData.PathButtonListener ccListener; + private static PathButtonListener ccListener; - private static ScriptArchData.PathButtonListener okListener; + private static PathButtonListener okListener; // popup frame to edit script paths: private static JDialog pathFrame; @@ -188,13 +188,13 @@ // button panel: final JPanel line4 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); final JButton okButton = new JButton("OK"); - okListener = new ScriptArchData.PathButtonListener(true, pathFrame, null); + okListener = new PathButtonListener(true, pathFrame, null); okListener.setTargetEvent(this); okButton.addActionListener(okListener); line4.add(okButton); final JButton cancelButton = new JButton("Cancel"); - ccListener = new ScriptArchData.PathButtonListener(false, pathFrame, null); + ccListener = new PathButtonListener(false, pathFrame, null); ccListener.setTargetEvent(this); cancelButton.addActionListener(ccListener); line4.add(cancelButton); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2007-01-07 10:43:43
|
Revision: 1480 http://svn.sourceforge.net/gridarta/?rev=1480&view=rev Author: akirschbaum Date: 2007-01-07 02:43:44 -0800 (Sun, 07 Jan 2007) Log Message: ----------- Unify comments. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/scripts/PathButtonListener.java trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java trunk/daimonin/src/daieditor/gameobject/scripts/PathButtonListener.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/PathButtonListener.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/PathButtonListener.java 2007-01-07 10:23:57 UTC (rev 1479) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/PathButtonListener.java 2007-01-07 10:43:44 UTC (rev 1480) @@ -47,9 +47,9 @@ /** * Create a PathButtonListener. - * @param isOkButton true for ok-buttons - * @param frame frame this listener belongs to - * @param scriptArchData this is only set for the ok-button of "create new" frame, otherwise null + * @param isOkButton true for ok-buttons + * @param frame frame this listener belongs to + * @param scriptArchData this is only set for the ok-button of "create new" frame, otherwise null */ PathButtonListener(final boolean isOkButton, final JDialog frame, @Nullable final ScriptArchData scriptArchData) { this.isOkButton = isOkButton; Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2007-01-07 10:23:57 UTC (rev 1479) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2007-01-07 10:43:44 UTC (rev 1480) @@ -96,7 +96,9 @@ private final List<ScriptedEvent> eventList; // contains list of ScriptedEvents - /** Create a ScriptArchData. */ + /** + * Create a ScriptArchData. + */ public ScriptArchData() { eventList = new ArrayList<ScriptedEvent>(); if (eventTypeBox == null) { @@ -257,10 +259,10 @@ /** * If there is a scripted event of the specified type, the script pad is * opened and the appropriate script displayed. - * @param eventType type of event - * @param task ID number for task (open script/ edit path/ remove) - * @param panelList JList from the MapArchPanel (script tab) which displays - * the events + * @param eventType type of event + * @param task ID number for task (open script/ edit path/ remove) + * @param panelList JList from the MapArchPanel (script tab) which + * displays the events */ public void modifyEventScript(final String eventType, final int task, final JList panelList) { final int index = getScriptedEvent(eventType); @@ -581,8 +583,8 @@ /** * Returns whether this ScriptArchData is empty (contains no events). - * (Note that empty ScriptArchData objects always are removed ASAP) - * @return <code>true</code> if this ScriptArchData contains no events, otherwise <code>false</code>. + * (Note that empty ScriptArchData objects always are removed ASAP.) + * @return <code>true</code> if this ScriptArchData contains no events, otherwise <code>false</code> */ public boolean isEmpty() { return eventList == null || eventList.isEmpty(); Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java 2007-01-07 10:23:57 UTC (rev 1479) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java 2007-01-07 10:43:44 UTC (rev 1480) @@ -67,7 +67,7 @@ private static JDialog pathFrame; /** - * Construct a ScriptedEvent of given type (This is used for map-loading). + * Create a ScriptedEvent of given type (This is used for map-loading). * @param eventType Type of the event. */ ScriptedEvent(final String eventType) { @@ -78,10 +78,10 @@ /** * Creates a fully initialized ScriptedEvent. - * @param eventType Type of the event. - * @param pluginName Name of the plugin. - * @param filePath Path the the script. - * @param eventOptions Options for the Event. + * @param eventType type of the event + * @param pluginName name of the plugin + * @param filePath path to the file for this event + * @param eventOptions options for this event */ ScriptedEvent(final String eventType, final String pluginName, final String filePath, final String eventOptions) { this.eventType = eventType; Modified: trunk/daimonin/src/daieditor/gameobject/scripts/PathButtonListener.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/PathButtonListener.java 2007-01-07 10:23:57 UTC (rev 1479) +++ trunk/daimonin/src/daieditor/gameobject/scripts/PathButtonListener.java 2007-01-07 10:43:44 UTC (rev 1480) @@ -46,10 +46,10 @@ private ScriptArchData scriptArchData; /** - * Creates a PathbuttonListener. - * @param isOkButton true for ok-buttons - * @param frame frame this listener belongs to - * @param scriptArchData this is only set for the ok-button of "create new" frame, otherwise null + * Create a PathButtonListener. + * @param isOkButton true for ok-buttons + * @param frame frame this listener belongs to + * @param scriptArchData this is only set for the ok-button of "create new" frame, otherwise null */ PathButtonListener(final boolean isOkButton, final JDialog frame, @Nullable final ScriptArchData scriptArchData) { this.isOkButton = isOkButton; Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2007-01-07 10:23:57 UTC (rev 1479) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2007-01-07 10:43:44 UTC (rev 1480) @@ -96,7 +96,7 @@ boolean changed; /** - * Creates a ScriptArchData. + * Create a ScriptArchData. * @param owner Owner of this ScriptArchData. */ public ScriptArchData(final GameObject owner) { @@ -531,8 +531,9 @@ } /** - * (Note that empty ScriptArchData objects always are removed ASAP). - * @return true when this ScriptArchData contains no events + * Returns whether this ScriptArchData is empty (contains no events). + * (Note that empty ScriptArchData objects always are removed ASAP.) + * @return <code>true</code> if this ScriptArchData contains no events, otherwise <code>false</code> */ public boolean isEmpty() { for (final GameObject tmp : owner) { Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java 2007-01-07 10:23:57 UTC (rev 1479) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java 2007-01-07 10:43:44 UTC (rev 1480) @@ -62,7 +62,7 @@ private static JDialog pathFrame; /** - * Creates a ScriptedEvent of given type (This is used for map-loading). + * Create a ScriptedEvent of given type (This is used for map-loading). * @param event GameObject that describes the event. */ ScriptedEvent(final GameObject event) { @@ -71,10 +71,10 @@ /** * Creates a fully initialized ScriptedEvent. - * @param eventType Type of the event. - * @param pluginName Name of the plugin. - * @param filePath Path to the file for this event. - * @param options Options for this event. + * @param eventType type of the event + * @param pluginName name of the plugin + * @param filePath path to the file for this event + * @param options options for this event */ ScriptedEvent(final int eventType, final String pluginName, final String filePath, final String options) { event = new GameObject(); // FIXME: This arch has no default arch This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2007-01-07 11:14:33
|
Revision: 1481 http://svn.sourceforge.net/gridarta/?rev=1481&view=rev Author: akirschbaum Date: 2007-01-07 03:14:32 -0800 (Sun, 07 Jan 2007) Log Message: ----------- Rename identifier names. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2007-01-07 10:43:44 UTC (rev 1480) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2007-01-07 11:14:32 UTC (rev 1481) @@ -87,9 +87,9 @@ private static JComboBox pluginNameBox; - private static JTextField inputNFPath; + private static JTextField inputScriptPath; - private static JTextField inputEventOptions; + private static JTextField inputOptions; // FIXME: This should NOT BE HERE. Instead, it should be read from types.xml. private static final String[] allEventTypes = new String[]{" apply", " attack", " close", " death", " drop", " pickup", " say", " stop", " time", " throw", " trigger"}; @@ -140,9 +140,9 @@ if (dataType == EDATA_PLUGIN_NAME) { event.setPluginName(eventData.trim()); // set plugin name } else if (dataType == EDATA_FILE_PATH) { - event.setFilePath(eventData.trim()); // set plugin name + event.setScriptPath(eventData.trim()); // set plugin name } else if (dataType == EDATA_EVENT_OPTIONS) { - event.setEventOptions(eventData.trim()); // set event options + event.setOptions(eventData.trim()); // set event options } // save changes: @@ -278,7 +278,7 @@ eventList.set(index, event); // save changes } else if (task == GameObjectAttributesPanel.SCRIPT_REMOVE) { // first ask for confirmation - if (JOptionPane.showConfirmDialog(panelList, "Are you sure you want to remove this \"" + eventType + "\" event which is\n" + "linked to the script: '" + event.getFilePath() + "'?\n" + "(The script file itself is not going to be deleted)", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) { + if (JOptionPane.showConfirmDialog(panelList, "Are you sure you want to remove this \"" + eventType + "\" event which is\n" + "linked to the script: '" + event.getScriptPath() + "'?\n" + "(The script file itself is not going to be deleted)", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) { // remove this event from the GameObject eventList.remove(index); addEventsToJList(panelList); // update panel JList @@ -409,7 +409,7 @@ } mainPanel.add(line3); - inputNFPath = new JTextField(defScriptName, 20); + inputScriptPath = new JTextField(defScriptName, 20); final JButton browseb = new JButton("..."); browseb.setMargin(new Insets(0, 10, 0, 10)); browseb.addActionListener(new ActionListener() { @@ -426,11 +426,11 @@ if (fileChooser.showOpenDialog(newScriptFrame) == JFileChooser.APPROVE_OPTION) { // user has selected a file final File f = fileChooser.getSelectedFile(); - inputNFPath.setText(localizeEventPath(f)); + inputScriptPath.setText(localizeEventPath(f)); } } }); - line3.add(inputNFPath); + line3.add(inputScriptPath); line3.add(browseb); mainPanel.add(line3); @@ -450,8 +450,8 @@ final JPanel line5 = new JPanel(new FlowLayout(FlowLayout.LEFT)); final JLabel tlabel6 = new JLabel("Event Options: "); line5.add(tlabel6); - inputEventOptions = new JTextField(25); - line5.add(inputEventOptions); + inputOptions = new JTextField(25); + line5.add(inputOptions); mainPanel.add(line5); // button panel: @@ -474,8 +474,8 @@ } else { // just set fields and show nsHeading.setText("New scripted event for \"" + archName + "\":"); - inputNFPath.setText(defScriptName); - inputEventOptions.setText(""); + inputScriptPath.setText(defScriptName); + inputOptions.setText(""); nsOkListener.setScriptArchData(this); newScriptFrame.toFront(); newScriptFrame.setVisible(true); @@ -488,10 +488,10 @@ */ public void createNewEvent(final JDialog frame) { final CMainControl mainControl = CMainControl.getInstance(); // main control - String scriptPath = inputNFPath.getText().trim(); + String scriptPath = inputScriptPath.getText().trim(); final String eventType = ((String) (eventTypeBox.getSelectedItem())).trim(); final String pluginName = ((String) (pluginNameBox.getSelectedItem())).trim(); - final String eventOptions = inputEventOptions.getText().trim(); + final String options = inputOptions.getText().trim(); final File localMapDir = mainControl.getCurrentMap().getMapFile().getParentFile(); // local map directory @@ -535,7 +535,7 @@ if (newScriptFile.exists()) { if (newScriptFile.isFile()) { // file exists -> link it to the event - final ScriptedEvent event = new ScriptedEvent(eventType, pluginName, scriptPath, eventOptions); + final ScriptedEvent event = new ScriptedEvent(eventType, pluginName, scriptPath, options); if (replaceIndex == -1) { eventList.add(event); } else { @@ -562,7 +562,7 @@ if (couldCreateFile) { // file has been created, now link it to the event - final ScriptedEvent event = new ScriptedEvent(eventType, pluginName, scriptPath, eventOptions); + final ScriptedEvent event = new ScriptedEvent(eventType, pluginName, scriptPath, options); if (replaceIndex != -1) { eventList.set(replaceIndex, event); } else { Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java 2007-01-07 10:43:44 UTC (rev 1480) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptedEvent.java 2007-01-07 11:14:32 UTC (rev 1481) @@ -45,11 +45,11 @@ /** Action Factory. */ private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); - private static JTextField inputFPath; + private static JTextField inputScriptPath; - private static JTextField inputPlName; + private static JTextField inputPluginName; - private static JTextField inputEEOptions; + private static JTextField inputOptions; private static PathButtonListener ccListener; @@ -59,9 +59,9 @@ private String eventType; // name of event type (e.g. "say", "death", "attack"...) - private String eventOptions; // event options + private String options; // event options - private String filePath; // path to scriptfile (can be a relative or absolute path) + private String scriptPath; // path to scriptfile (can be a relative or absolute path) // popup frame to edit script paths: private static JDialog pathFrame; @@ -73,21 +73,21 @@ ScriptedEvent(final String eventType) { this.eventType = eventType; pluginName = null; - filePath = null; + scriptPath = null; } /** * Creates a fully initialized ScriptedEvent. * @param eventType type of the event * @param pluginName name of the plugin - * @param filePath path to the file for this event - * @param eventOptions options for this event + * @param scriptPath path to the file for this event + * @param options options for this event */ - ScriptedEvent(final String eventType, final String pluginName, final String filePath, final String eventOptions) { + ScriptedEvent(final String eventType, final String pluginName, final String scriptPath, final String options) { this.eventType = eventType; this.pluginName = pluginName; - this.filePath = filePath; - this.eventOptions = eventOptions; + this.scriptPath = scriptPath; + this.options = options; } /** @@ -95,7 +95,7 @@ * @return true if this object is valid, otherwise false */ public boolean isValid() { - if (filePath == null || filePath.length() <= 0) { + if (scriptPath == null || scriptPath.length() <= 0) { log.error("Map Error: Found event_" + eventType + " without file name!"); return false; } @@ -107,7 +107,7 @@ } } - filePath = filePath.replace('\\', '/'); // just make sure there are only slashes: '/' + scriptPath = scriptPath.replace('\\', '/'); // just make sure there are only slashes: '/' return true; } @@ -119,9 +119,9 @@ public String getMapArchText() { final StringBuilder buff = new StringBuilder(""); buff.append("event_").append(eventType).append("_plugin ").append(pluginName).append("\n"); - buff.append("event_").append(eventType).append(" ").append(filePath).append("\n"); - if (eventOptions != null && eventOptions.trim().length() > 0) { - buff.append("event_").append(eventType).append("_options ").append(eventOptions).append("\n"); + buff.append("event_").append(eventType).append(" ").append(scriptPath).append("\n"); + if (options != null && options.trim().length() > 0) { + buff.append("event_").append(eventType).append("_options ").append(options).append("\n"); } return buff.toString(); } @@ -134,8 +134,8 @@ public ScriptedEvent getClone() { final ScriptedEvent clone = new ScriptedEvent(eventType); clone.pluginName = pluginName; - clone.filePath = filePath; - clone.eventOptions = eventOptions; + clone.scriptPath = scriptPath; + clone.options = options; return clone; } @@ -146,17 +146,17 @@ // trying to get the absolute path to scriptfile: String path; - if (filePath.startsWith("/")) { + if (scriptPath.startsWith("/")) { // filepath is absolue (to map base directory): path = mainControl.getMapDefaultFolder(); - path += filePath; + path += scriptPath; } else { // file path is relative to map dir path = mainControl.getCurrentMap().getMapFile().getParentFile().getAbsolutePath(); // map dir if (!path.endsWith("/")) { path += '/'; // append slash to map dir } - path += filePath; // append relative path to map dir + path += scriptPath; // append relative path to map dir path = path.replace('\\', '/'); // make sure there's only one kind of slash } @@ -188,24 +188,24 @@ final JPanel line1 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); final JLabel text1 = new JLabel("Script:"); line1.add(text1); - inputFPath = new JTextField(filePath, 20); - line1.add(inputFPath); + inputScriptPath = new JTextField(scriptPath, 20); + line1.add(inputScriptPath); mainPanel.add(line1); // input line: plugin name final JPanel line2 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); final JLabel text2 = new JLabel("Plugin Name:"); line2.add(text2); - inputPlName = new JTextField(pluginName, 20); - line2.add(inputPlName); + inputPluginName = new JTextField(pluginName, 20); + line2.add(inputPluginName); mainPanel.add(line2); // input line: event options final JPanel line3 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); final JLabel text3 = new JLabel("Event Options:"); line3.add(text3); - inputEEOptions = new JTextField(eventOptions, 20); - line3.add(inputEEOptions); + inputOptions = new JTextField(options, 20); + line3.add(inputOptions); mainPanel.add(line3); mainPanel.add(Box.createVerticalStrut(5)); @@ -232,9 +232,9 @@ // just set fields and show okListener.setTargetEvent(this); ccListener.setTargetEvent(this); - inputFPath.setText(filePath); - inputPlName.setText(pluginName); - inputEEOptions.setText(eventOptions); + inputScriptPath.setText(scriptPath); + inputPluginName.setText(pluginName); + inputOptions.setText(options); pathFrame.toFront(); pathFrame.setVisible(true); } @@ -245,16 +245,16 @@ * dialog. */ public void modifyEventPath() { - final String newPath = inputFPath.getText().trim(); - final String newPlName = inputPlName.getText().trim(); - final String newEvOptions = inputEEOptions.getText().trim(); + final String newPath = inputScriptPath.getText().trim(); + final String newPluginName = inputPluginName.getText().trim(); + final String newOptions = inputOptions.getText().trim(); if (newPath.length() > 0) { - filePath = newPath; + scriptPath = newPath; } - if (newPlName.length() > 0) { - pluginName = newPlName; + if (newPluginName.length() > 0) { + pluginName = newPluginName; } - eventOptions = newEvOptions; // unlike the above two, event options can be empty + options = newOptions; // unlike the above two, event options can be empty } // GET/SET methods @@ -266,20 +266,20 @@ return pluginName; } - public String getFilePath() { - return filePath; + public String getScriptPath() { + return scriptPath; } - public void setPluginName(final String name) { - pluginName = name; + public void setPluginName(final String pluginName) { + this.pluginName = pluginName; } - public void setFilePath(final String path) { - filePath = path; + public void setScriptPath(final String scriptPath) { + this.scriptPath = scriptPath; } - public void setEventOptions(final String options) { - eventOptions = options; + public void setOptions(final String options) { + this.options = options; } public static JDialog getPathFrame() { Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2007-01-07 10:43:44 UTC (rev 1480) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2007-01-07 11:14:32 UTC (rev 1481) @@ -84,9 +84,9 @@ private static JComboBox pluginNameBox; - private static JTextField inputNFPath; + private static JTextField inputScriptPath; - private static JTextField inputNFOptions; + private static JTextField inputOptions; // FIXME: This should NOT BE HERE. Instead, it should be read from types.xml. private static final String[] allEventTypes = new String[]{" apply", " attack", " death", " drop", " pickup", " say", " stop", " time (don't use)", " throw", " trigger", " close", " examine", " talk"}; @@ -212,8 +212,8 @@ event.editScriptPath(); } else if (task == GameObjectAttributesPanel.SCRIPT_REMOVE) { // first ask for confirmation - //boolean breakpath = (event.getFilePath().length() > 15); - if (JOptionPane.showConfirmDialog(panelList, "Are you sure you want to remove this \"" + typeName(event.getEventType()) + "\" event which is\n" + "linked to the script: '" + event.getFilePath() + "'?\n" + "(The script file itself is not going to be deleted)", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) { + //boolean breakpath = (event.getScriptPath().length() > 15); + if (JOptionPane.showConfirmDialog(panelList, "Are you sure you want to remove this \"" + typeName(event.getEventType()) + "\" event which is\n" + "linked to the script: '" + event.getScriptPath() + "'?\n" + "(The script file itself is not going to be deleted)", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) { // remove this event from the GameObject oldEvent.remove(); addEventsToJList(panelList); // update panel JList @@ -353,7 +353,7 @@ final JLabel tlabel3 = new JLabel("Script File:"); line3.add(tlabel3); mainPanel.add(line3); - inputNFPath = new JTextField(defScriptName, 20); + inputScriptPath = new JTextField(defScriptName, 20); final JButton browseb = new JButton("..."); browseb.setMargin(new Insets(0, 10, 0, 10)); browseb.addActionListener(new ActionListener() { @@ -370,11 +370,11 @@ if (fileChooser.showOpenDialog(newScriptFrame) == JFileChooser.APPROVE_OPTION) { // user has selected a file final File f = fileChooser.getSelectedFile(); - inputNFPath.setText(localizeEventPath(f)); + inputScriptPath.setText(localizeEventPath(f)); } } }); - line3.add(inputNFPath); + line3.add(inputScriptPath); line3.add(browseb); mainPanel.add(line3); @@ -382,8 +382,8 @@ mainPanel.add(Box.createVerticalStrut(5)); final JPanel line4 = new JPanel(new FlowLayout(FlowLayout.LEFT)); line4.add(new JLabel("Script Options:")); - inputNFOptions = new JTextField("", 20); - line4.add(inputNFOptions); + inputOptions = new JTextField("", 20); + line4.add(inputOptions); mainPanel.add(line4); // description @@ -417,7 +417,7 @@ } else { // just set fields and show nsHeading.setText("New scripted event for \"" + archName + "\":"); - inputNFPath.setText(defScriptName); + inputScriptPath.setText(defScriptName); nsOkListener.setScriptArchData(this); newScriptFrame.toFront(); newScriptFrame.setVisible(true); @@ -431,8 +431,8 @@ */ public boolean createNewEvent(final JDialog frame) { final CMainControl mainControl = CMainControl.getInstance(); // main control - String scriptPath = inputNFPath.getText().trim(); - final String scriptOptions = inputNFOptions.getText().trim(); + String scriptPath = inputScriptPath.getText().trim(); + final String options = inputOptions.getText().trim(); final int eventType = eventTypeBox.getSelectedIndex() + 1; final String pluginName = ((String) pluginNameBox.getSelectedItem()).trim(); @@ -486,7 +486,7 @@ if (newScriptFile.exists()) { if (newScriptFile.isFile()) { // file exists -> link it to the event - final ScriptedEvent event = new ScriptedEvent(eventType, pluginName, scriptPath, scriptOptions); + final ScriptedEvent event = new ScriptedEvent(eventType, pluginName, scriptPath, options); if (replaceObject != null) { replaceObject.remove(); } @@ -514,7 +514,7 @@ "Cannot create file", JOptionPane.ERROR_MESSAGE); } else { // file has been created, now link it to the event - final ScriptedEvent event = new ScriptedEvent(eventType, pluginName, scriptPath, scriptOptions); + final ScriptedEvent event = new ScriptedEvent(eventType, pluginName, scriptPath, options); if (replaceObject != null) { replaceObject.remove(); } Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java 2007-01-07 10:43:44 UTC (rev 1480) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java 2007-01-07 11:14:32 UTC (rev 1481) @@ -48,11 +48,11 @@ private final GameObject event; // Our event object - private static JTextField inputFPath; + private static JTextField inputScriptPath; - private static JTextField inputPlName; + private static JTextField inputPluginName; - private static JTextField inputPlOptions; + private static JTextField inputOptions; private static PathButtonListener ccListener; @@ -73,16 +73,16 @@ * Creates a fully initialized ScriptedEvent. * @param eventType type of the event * @param pluginName name of the plugin - * @param filePath path to the file for this event + * @param scriptPath path to the file for this event * @param options options for this event */ - ScriptedEvent(final int eventType, final String pluginName, final String filePath, final String options) { + ScriptedEvent(final int eventType, final String pluginName, final String scriptPath, final String options) { event = new GameObject(); // FIXME: This arch has no default arch event.setArchTypNr(118); event.setArchetypeName("event_obj"); event.setArchetype(CMainControl.getInstance().getArchetypeSet().getArchetype("event_obj")); event.setObjectFace(); - setEventData(eventType, pluginName, filePath, options); + setEventData(eventType, pluginName, scriptPath, options); } /** @@ -91,11 +91,11 @@ */ public boolean isValid() { final String options = getOptions(); - String filePath = getFilePath(); + String scriptPath = getScriptPath(); String pluginName = getPluginName(); final int eventType = getEventType(); - if (filePath == null || filePath.length() <= 0) { + if (scriptPath == null || scriptPath.length() <= 0) { log.error("Map Error: Found " + ScriptArchData.typeName(eventType) + " event without file name!"); return false; } @@ -107,9 +107,9 @@ } } - filePath = filePath.replace('\\', '/'); // just make sure there are only slashes: '/' + scriptPath = scriptPath.replace('\\', '/'); // just make sure there are only slashes: '/' - setEventData(eventType, pluginName, filePath, options); + setEventData(eventType, pluginName, scriptPath, options); return true; } @@ -117,21 +117,21 @@ /** Opens the script pad to display the script for this event. */ public void openScript() { final CMainControl mainControl = CMainControl.getInstance(); // reference to main control - final String filePath = getFilePath(); + final String scriptPath = getScriptPath(); // trying to get the absolute path to scriptfile: String path; - if (filePath.startsWith("/")) { + if (scriptPath.startsWith("/")) { // filepath is absolue (to map base directory): path = mainControl.getMapDefaultFolder(); - path += filePath; + path += scriptPath; } else { // file path is relative to map dir path = mainControl.getCurrentMap().getMapFile().getParentFile().getAbsolutePath(); // map dir if (!path.endsWith("/")) { path += '/'; // append slash to map dir } - path += filePath; // append relative path to map dir + path += scriptPath; // append relative path to map dir path = path.replace('\\', '/'); // make sure there's only one kind of slash } @@ -163,16 +163,16 @@ final JPanel line1 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); final JLabel text1 = new JLabel("Script:"); line1.add(text1); - inputFPath = new JTextField(getFilePath(), 20); - line1.add(inputFPath); + inputScriptPath = new JTextField(getScriptPath(), 20); + line1.add(inputScriptPath); mainPanel.add(line1); // input line: plugin options final JPanel line2 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); final JLabel text2 = new JLabel("Script options:"); line2.add(text2); - inputPlOptions = new JTextField(getOptions(), 20); - line2.add(inputPlOptions); + inputOptions = new JTextField(getOptions(), 20); + line2.add(inputOptions); mainPanel.add(line2); mainPanel.add(Box.createVerticalStrut(5)); @@ -180,8 +180,8 @@ final JPanel line3 = new JPanel(new FlowLayout(FlowLayout.RIGHT)); final JLabel text3 = new JLabel("Plugin name:"); line3.add(text3); - inputPlName = new JTextField(getPluginName(), 20); - line3.add(inputPlName); + inputPluginName = new JTextField(getPluginName(), 20); + line3.add(inputPluginName); mainPanel.add(line3); mainPanel.add(Box.createVerticalStrut(5)); @@ -208,9 +208,9 @@ // just set fields and show okListener.setTargetEvent(this); ccListener.setTargetEvent(this); - inputFPath.setText(getFilePath()); - inputPlName.setText(getPluginName()); - inputPlOptions.setText(getOptions()); + inputScriptPath.setText(getScriptPath()); + inputPluginName.setText(getPluginName()); + inputOptions.setText(getOptions()); pathFrame.toFront(); pathFrame.setVisible(true); } @@ -221,18 +221,18 @@ * dialog. */ public void modifyEventPath() { - final String newPath = inputFPath.getText().trim(); - final String newPlName = inputPlName.getText().trim(); - final String newPlOptions = inputPlOptions.getText().trim(); + final String newPath = inputScriptPath.getText().trim(); + final String newPluginName = inputPluginName.getText().trim(); + final String newOptions = inputOptions.getText().trim(); if (newPath.length() > 0) { - setFilePath(newPath); + setScriptPath(newPath); } - if (newPlName.length() > 0) { - setPluginName(newPlName); + if (newPluginName.length() > 0) { + setPluginName(newPluginName); } - if (newPlOptions.length() > 0) { - setOptions(newPlOptions); + if (newOptions.length() > 0) { + setOptions(newOptions); } } @@ -249,7 +249,7 @@ return event.getBestName(); } - public String getFilePath() { + public String getScriptPath() { return event.getAttributeString("race"); } @@ -257,25 +257,25 @@ return event.getAttributeString("slaying"); } - public void setPluginName(final String name) { - setEventData(getEventType(), name, getFilePath(), getOptions()); + public void setPluginName(final String pluginName) { + setEventData(getEventType(), pluginName, getScriptPath(), getOptions()); } - public void setFilePath(final String path) { - setEventData(getEventType(), getPluginName(), path, getOptions()); + public void setScriptPath(final String scriptPath) { + setEventData(getEventType(), getPluginName(), scriptPath, getOptions()); } - public void setOptions(final String opts) { - setEventData(getEventType(), getPluginName(), getFilePath(), opts); + public void setOptions(final String options) { + setEventData(getEventType(), getPluginName(), getScriptPath(), options); } - private void setEventData(final int eventType, final String pluginName, final String filePath, final String options) { + private void setEventData(final int eventType, final String pluginName, final String scriptPath, final String options) { event.resetObjectText(); if (pluginName != null && pluginName.length() > 0) { event.setObjName(pluginName); } - if (filePath != null && filePath.length() > 0) { - event.addObjectText("race " + filePath); + if (scriptPath != null && scriptPath.length() > 0) { + event.addObjectText("race " + scriptPath); } if (options != null && options.length() > 0) { event.addObjectText("slaying " + options); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2007-01-07 11:24:58
|
Revision: 1483 http://svn.sourceforge.net/gridarta/?rev=1483&view=rev Author: akirschbaum Date: 2007-01-07 03:24:59 -0800 (Sun, 07 Jan 2007) Log Message: ----------- Remove static import statements. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java Modified: trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2007-01-07 11:21:37 UTC (rev 1482) +++ trunk/crossfire/src/cfeditor/gameobject/scripts/ScriptArchData.java 2007-01-07 11:24:59 UTC (rev 1483) @@ -48,7 +48,7 @@ import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; -import static javax.swing.WindowConstants.HIDE_ON_CLOSE; +import javax.swing.WindowConstants; import net.sf.gridarta.textedit.scripteditor.ScriptEditControl; import net.sf.japi.swing.ActionFactory; import net.sf.japi.util.Arrays2; @@ -370,7 +370,7 @@ if (newScriptFrame == null) { // initialize popup frame newScriptFrame = new JDialog(CMainControl.getInstance().getMainView(), "New Scripted Event", true); - newScriptFrame.setDefaultCloseOperation(HIDE_ON_CLOSE); + newScriptFrame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); final JPanel mainPanel = new JPanel(); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2007-01-07 11:21:37 UTC (rev 1482) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptArchData.java 2007-01-07 11:24:59 UTC (rev 1483) @@ -48,7 +48,7 @@ import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; -import static javax.swing.WindowConstants.HIDE_ON_CLOSE; +import javax.swing.WindowConstants; import net.sf.gridarta.io.PathManager; import net.sf.gridarta.textedit.scripteditor.ScriptEditControl; import net.sf.japi.swing.ActionFactory; @@ -319,7 +319,7 @@ if (newScriptFrame == null) { // initialize popup frame newScriptFrame = new JDialog(CMainControl.getInstance().getMainView(), "New Scripted Event", true); - newScriptFrame.setDefaultCloseOperation(HIDE_ON_CLOSE); + newScriptFrame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); final JPanel mainPanel = new JPanel(); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); Modified: trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java 2007-01-07 11:21:37 UTC (rev 1482) +++ trunk/daimonin/src/daieditor/gameobject/scripts/ScriptedEvent.java 2007-01-07 11:24:59 UTC (rev 1483) @@ -32,7 +32,7 @@ import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; -import static javax.swing.WindowConstants.HIDE_ON_CLOSE; +import javax.swing.WindowConstants; import net.sf.gridarta.textedit.scripteditor.ScriptEditControl; import net.sf.japi.swing.ActionFactory; import org.apache.log4j.Logger; @@ -153,7 +153,7 @@ if (pathFrame == null) { // initialize popup frame pathFrame = new JDialog(CMainControl.getInstance().getMainView(), "Script Path", true); - pathFrame.setDefaultCloseOperation(HIDE_ON_CLOSE); + pathFrame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); final JPanel mainPanel = new JPanel(); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |