You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(103) |
Jun
(121) |
Jul
(16) |
Aug
(67) |
Sep
(126) |
Oct
(161) |
Nov
(164) |
Dec
(588) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(394) |
Feb
(181) |
Mar
(131) |
Apr
(180) |
May
(255) |
Jun
(11) |
Jul
(79) |
Aug
(70) |
Sep
(274) |
Oct
(138) |
Nov
(195) |
Dec
(8) |
2008 |
Jan
(3) |
Feb
(142) |
Mar
(162) |
Apr
(124) |
May
(148) |
Jun
(157) |
Jul
(425) |
Aug
(373) |
Sep
(264) |
Oct
(315) |
Nov
(225) |
Dec
(6) |
2009 |
Jan
(67) |
Feb
(78) |
Mar
(279) |
Apr
(294) |
May
(92) |
Jun
(65) |
Jul
(134) |
Aug
(41) |
Sep
(138) |
Oct
(125) |
Nov
(126) |
Dec
(122) |
2010 |
Jan
(15) |
Feb
(48) |
Mar
(9) |
Apr
(195) |
May
(373) |
Jun
(507) |
Jul
(42) |
Aug
(16) |
Sep
(38) |
Oct
(81) |
Nov
(64) |
Dec
(18) |
2011 |
Jan
(13) |
Feb
(12) |
Mar
(39) |
Apr
(1) |
May
(2) |
Jun
(27) |
Jul
(27) |
Aug
(31) |
Sep
(14) |
Oct
(102) |
Nov
(20) |
Dec
(37) |
2012 |
Jan
(22) |
Feb
(1) |
Mar
(1) |
Apr
(2) |
May
(2) |
Jun
(18) |
Jul
(6) |
Aug
(1) |
Sep
(1) |
Oct
|
Nov
|
Dec
|
2013 |
Jan
(1) |
Feb
(2) |
Mar
(1) |
Apr
(1) |
May
(47) |
Jun
(7) |
Jul
(107) |
Aug
|
Sep
|
Oct
(112) |
Nov
(31) |
Dec
(17) |
2014 |
Jan
(29) |
Feb
(111) |
Mar
(34) |
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
(18) |
Dec
(10) |
From: <chr...@us...> - 2006-09-17 19:48:18
|
Revision: 334 http://svn.sourceforge.net/gridarta/?rev=334&view=rev Author: christianhujer Date: 2006-09-17 12:46:54 -0700 (Sun, 17 Sep 2006) Log Message: ----------- Fixed errors in I/O handling of cfeditor.CMapFileDecode. Moved encoding declaration from CMainControl to CFileReader. Changed cfeditor.CMapFileDecode.decodeMapFile to throw IOException and FileNotFoundException instead of GridderException. Fixed documentation of daieditor.CMapFileDecode. Moved CFileInputStream and CFileReader to Gridarta. Improved cfeditor MultiPositionData I/O code. Changed storage location of Daieditor's python menu definition. Unified script editor and moved it to Gridarta. Improved CFileInputStream's file lookup. It now should create paths correctly and thus find files in the jar again. cfpython_menu.def is now included in Gridarta and stored in all three jars (crossfire editor, daimonin editor and yet unused common gridarta jar). Sorry for the large changeset, I did these changes during a LAN party that had no Internet Access. Modified Paths: -------------- trunk/build.xml trunk/crossfire/build.xml trunk/crossfire/src/cfeditor/AutojoinList.java trunk/crossfire/src/cfeditor/CFArchTypeList.java trunk/crossfire/src/cfeditor/CFTreasureListTree.java trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/CMainMenu.java trunk/crossfire/src/cfeditor/CMapFileDecode.java trunk/crossfire/src/cfeditor/CMapFileEncode.java trunk/crossfire/src/cfeditor/CPickmapPanel.java trunk/crossfire/src/cfeditor/FaceObject.java trunk/crossfire/src/cfeditor/IGUIConstants.java trunk/crossfire/src/cfeditor/MultiPositionData.java trunk/crossfire/src/cfeditor/ScriptArchData.java trunk/crossfire/src/cfeditor/arch/ArchObjectParser.java trunk/crossfire/src/cfeditor/arch/ArchObjectStack.java trunk/daimonin/build.xml trunk/daimonin/src/daieditor/CFTreasureListTree.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/CMapFileDecode.java trunk/daimonin/src/daieditor/CMapFileEncode.java trunk/daimonin/src/daieditor/IGUIConstants.java trunk/daimonin/src/daieditor/MultiPositionData.java trunk/daimonin/src/daieditor/ScriptArchData.java trunk/daimonin/src/daieditor/Spells.java trunk/daimonin/src/daieditor/arch/ArchObjectStack.java trunk/daimonin/src/daieditor/arch/anim/AnimationObjects.java trunk/daimonin/src/daieditor/gui/map/MapTilePane.java trunk/src/app/net/sf/gridarta/CommonConstants.java trunk/src/app/net/sf/gridarta/MainControl.java trunk/src/app/net/sf/gridarta/textedit/scripteditor/CFPythonPopup.java trunk/src/app/net/sf/gridarta/textedit/scripteditor/ScriptEditControl.java trunk/src/app/net/sf/gridarta/textedit/scripteditor/ScriptEditMenuBar.java trunk/src/app/net/sf/gridarta/textedit/scripteditor/ScriptEditView.java trunk/src/app/net/sf/gridarta/textedit/textarea/CTokenMarker.java trunk/src/app/net/sf/gridarta/textedit/textarea/DefaultInputHandler.java trunk/src/app/net/sf/gridarta/textedit/textarea/HTMLTokenMarker.java trunk/src/app/net/sf/gridarta/textedit/textarea/InputHandler.java trunk/src/app/net/sf/gridarta/textedit/textarea/JEditTextArea.java trunk/src/app/net/sf/gridarta/textedit/textarea/JavaScriptTokenMarker.java trunk/src/app/net/sf/gridarta/textedit/textarea/KeywordMap.java trunk/src/app/net/sf/gridarta/textedit/textarea/LuaTokenMarker.java trunk/src/app/net/sf/gridarta/textedit/textarea/SyntaxDocument.java trunk/src/app/net/sf/gridarta/textedit/textarea/SyntaxStyle.java trunk/src/app/net/sf/gridarta/textedit/textarea/SyntaxUtilities.java trunk/src/app/net/sf/gridarta/textedit/textarea/TextAreaDefaults.java trunk/src/app/net/sf/gridarta/textedit/textarea/TextAreaPainter.java trunk/src/app/net/sf/gridarta/textedit/textarea/TextUtilities.java trunk/src/app/net/sf/gridarta/textedit/textarea/Token.java trunk/src/app/net/sf/gridarta/textedit/textarea/TokenMarker.java trunk/src/app/net/sf/gridarta/textedit/textarea/XMLTokenMarker.java Added Paths: ----------- trunk/lib/annotations.jar trunk/src/app/cfpython_menu.def trunk/src/app/net/sf/gridarta/io/ trunk/src/app/net/sf/gridarta/io/CFileInputStream.java trunk/src/app/net/sf/gridarta/io/CFileReader.java trunk/src/app/net/sf/gridarta/io/package.html trunk/src/app/net/sf/gridarta/textedit/ trunk/src/app/net/sf/gridarta/textedit/scripteditor/ trunk/src/app/net/sf/gridarta/textedit/textarea/ trunk/src/app/net/sf/gridarta/textedit/textarea/PythonTokenMarker.java Removed Paths: ------------- trunk/crossfire/resource/conf/cfpython_menu.def trunk/crossfire/src/cfeditor/CFileInputStream.java trunk/crossfire/src/cfeditor/CFileReader.java trunk/crossfire/src/cfeditor/textedit/scripteditor/ trunk/crossfire/src/cfeditor/textedit/textarea/ trunk/daimonin/src/daieditor/CFileInputStream.java trunk/daimonin/src/daieditor/CFileReader.java trunk/daimonin/src/daieditor/textedit/scripteditor/ trunk/daimonin/src/daieditor/textedit/textarea/ Modified: trunk/build.xml =================================================================== --- trunk/build.xml 2006-09-14 21:33:23 UTC (rev 333) +++ trunk/build.xml 2006-09-17 19:46:54 UTC (rev 334) @@ -110,11 +110,12 @@ <classpath> <fileset dir="lib" includes="annotations.jar" /> <fileset dir="lib" includes="japi.jar" /> + <fileset dir="lib" includes="log4j-1.2.13.jar" /> </classpath> <compilerarg line="${javac.args}" /> </javac> <copy todir="dest/app"> - <fileset dir="src/app" includes="**/*.properties" /> + <fileset dir="src/app" includes="**/*.properties,cfpython_menu.def" /> </copy> </target> @@ -299,7 +300,6 @@ <property name="distLib" value="dist/gridarta-${project.version}.lib" /> <jar destfile="${distLib}.jar"> <zipfileset dir="dest/app"/> - <zipfileset src="lib/annotations.jar"/> <manifest> <attribute name="Implementation-Title" value="Gridarta" /> <attribute name="Implementation-Vendor" value="The Gridarta Developers" /> Modified: trunk/crossfire/build.xml =================================================================== --- trunk/crossfire/build.xml 2006-09-14 21:33:23 UTC (rev 333) +++ trunk/crossfire/build.xml 2006-09-17 19:46:54 UTC (rev 334) @@ -107,6 +107,9 @@ <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> <delete dir="${build.dir}/pickmaps" /> <delete dir="${build.dir}/conf" /> Deleted: trunk/crossfire/resource/conf/cfpython_menu.def =================================================================== --- trunk/crossfire/resource/conf/cfpython_menu.def 2006-09-14 21:33:23 UTC (rev 333) +++ trunk/crossfire/resource/conf/cfpython_menu.def 2006-09-17 19:46:54 UTC (rev 334) @@ -1,194 +0,0 @@ -############################################################ -# This file contains all python commands of the CFPython # -# package. These get displayed in the popup menu when # -# typing "CFPython" on the script pad. # -############################################################ - -AcquireSpell(object who, int spellid) : void -ActivateRune(object who, object what) : void -Apply(object who, object what, int flags) : int -BlocksView(object who) : int -CastAbility(object who, int spellid, int direction, string options) : void -CheckTrigger(object who, object what) : void -CastSpell(object who, int spellid, int direction, string options) : void -CheckInvisibleObjectInside(object who, string id) : object -CreateInvisibleObjectInside() -CreateObjectInside() -CheckMap() -CheckInventory() -CreateObject() -CanSeeInvisible(object who) : int -CanRoll(object who) : int -CanPassThru(object who) : int -CanPickUp(object who) : int -CanCastSpell(object who) : int -CanUseScroll(object who) : int -CanUseWand(object who) : int -CanUseBow(object who) : int -CanUseArmour(object who) : int -CanUseWeapon(object who) : int -CanUseRing(object who) : int -CanUseSkill(object who) : int -CanUseRod(object who) : int -CanUseHorn(object who) : int -CanSeeInDark(object who) : int -Drop() -DirectionN() : int -DirectionNE() : int -DirectionE() : int -DirectionSE() : int -DirectionS() : int -DirectionSW() : int -DirectionW() : int -DirectionNW() : int -DoKnowSpell() -FindPlayer() -FixObject() -ForgetSpell() -GetMapDirectory() : string -GetUniqueDirectory() : string -GetTempDirectory() : string -GetConfigurationDirectory() : string -GetDataDirectory() : string -GetLocalDirectory() : string -GetPlayerDirectory() : string -GetSkillExperience() -GetMapPath() -GetMapObject() -GetMessage(object who) : string -GetGod(object who) : string -GetWeight(object who) : int -GetMap() -GetNextObject() -GetPreviousObject() -GetFirstObjectOnSquare() -GetQuantity() -GetExperience(object who) : int -GetSpeed(object who) -GetFood(object who) : int -GetGrace(object who) : int -GetReturnValue() -GetDirection() -GetLastSP(object who) : int -GetLastGrace(object who) : int -GetAttackType() -GetDamage(object who) : int -GetName(object who) -GetEventOptions() -GetEventPlugin() -GetType(object who) : int -GetEventHandler() -GetIP() -GetInventory() -GetInternalName() -GetAC(object who) : int -GetCha(object who) : int -GetCon(object who) : int -GetDex(object who) : int -GetHP(object who) : int -GetInt(object who) : int -GetPow(object who) : int -GetSP(object who) : int -GetStr(object who) : int -GetWis(object who) : int -GetMaxHP(object who) : int -GetMaxSP(object who) : int -GetXPos() : int -GetYPos() : int -HitBack() -HasXRays() -HasStealth() -HasBeenApplied() -IsOutOfMap() -IsCanBePicked(object who) : int -InsertObjectInside() -IsInvisible(object who) : int -IsAlive(object who) : int -IsWiz(object who) : int -IsApplied(object who) : int -IsUnpaid(object who) : int -IsFlying(object who) : int -IsMonster(object who) : int -IsFriendly(object who) : int -IsGenerator(object who) : int -IsThrown(object who) : int -IsTurnable(object who) : int -IsUsedUp(object who) : int -IsIdentified(object who) : int -IsSplitting(object who) : int -IsUndead(object who) : int -IsScared(object who) : int -IsUnaggressive(object who) : int -IsOfType() -IsRunningAway(object who) : int -IsUnique(object who) : int -IsFloor(object who) : int -IsLifeSaver(object who) : int -IsSleeping(object who) : int -IsConfused(object who) : int -IsCursed(object who) : int -IsDamned(object who) : int -IsKnownMagical(object who) : int -IsKnownCursed(object who) : int -IsBlind(object who) : int -KillObject() -LoadObject() -MatchString() -Message() -MakeInvisible() -OnlyAttack() -PickUp() -ReadyMap() -ReflectMissiles() -ReflectSpells() -RemoveObject() -RegisterCommand() -SetQuantity() -SetName() -SetMessage() -SetSkillExperience() -SetCursed() -SetUnaggressive() -SetGod() -SetWeight() -Say() -SetInvisible() -SetSpeed() -SetFood() -SetGrace() -SetReturnValue() -SetDirection() -SetLastSP() -SetLastGrace() -SetFace() -SetAttackType() -SetDamage() -SetBeenApplied() -SetIdentified() -SaveObject() -SetEventHandler() -SetEventPlugin() -SetEventOptions() -SetPosition() -SetNickname() -SetAC() -SetCha() -SetCon() -SetDex() -SetHP() -SetInt() -SetMaxHP() -SetMaxSP() -SetPow() -SetSP() -SetStr() -SetWis() -StandStill() -Take() -Teleport() -WhoAmI() -WhoIsActivator() -WhatIsMessage() -Write() -WhoIsOther() -WasWiz() Modified: trunk/crossfire/src/cfeditor/AutojoinList.java =================================================================== --- trunk/crossfire/src/cfeditor/AutojoinList.java 2006-09-14 21:33:23 UTC (rev 333) +++ trunk/crossfire/src/cfeditor/AutojoinList.java 2006-09-17 19:46:54 UTC (rev 334) @@ -32,6 +32,7 @@ import java.io.IOException; import org.apache.log4j.Logger; import org.jetbrains.annotations.Nullable; +import net.sf.gridarta.io.CFileReader; /** * The <code>AutojoinList</code> class contains a list of (typically wall-)arches which Modified: trunk/crossfire/src/cfeditor/CFArchTypeList.java =================================================================== --- trunk/crossfire/src/cfeditor/CFArchTypeList.java 2006-09-14 21:33:23 UTC (rev 333) +++ trunk/crossfire/src/cfeditor/CFArchTypeList.java 2006-09-17 19:46:54 UTC (rev 334) @@ -46,6 +46,7 @@ import org.jdom.Element; import org.jdom.JDOMException; import org.jdom.input.SAXBuilder; +import net.sf.gridarta.io.CFileReader; /** * This class handles all the CFArchTypes and makes them conveniently Modified: trunk/crossfire/src/cfeditor/CFTreasureListTree.java =================================================================== --- trunk/crossfire/src/cfeditor/CFTreasureListTree.java 2006-09-14 21:33:23 UTC (rev 333) +++ trunk/crossfire/src/cfeditor/CFTreasureListTree.java 2006-09-17 19:46:54 UTC (rev 334) @@ -54,6 +54,7 @@ import javax.swing.tree.TreePath; import cfeditor.GridderException; import net.sf.gridarta.help.Help; +import net.sf.gridarta.io.CFileReader; import org.apache.log4j.Logger; import org.jetbrains.annotations.Nullable; Deleted: trunk/crossfire/src/cfeditor/CFileInputStream.java =================================================================== --- trunk/crossfire/src/cfeditor/CFileInputStream.java 2006-09-14 21:33:23 UTC (rev 333) +++ trunk/crossfire/src/cfeditor/CFileInputStream.java 2006-09-17 19:46:54 UTC (rev 334) @@ -1,122 +0,0 @@ -/* - * Crossfire 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 cfeditor; - -import java.io.BufferedInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.InputStream; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * Class for opening and reading a buffered stream to a BINARY resource-file. - * If no such file is found, the file is loaded from the jar archive. - * This class is very similar to {@link CFileReader}. - * The file is tried to open in the following order: - * <ol> - * <li>Try opening it with the given directory. The directory path is relative - * to the current working directory, the file path relative to that - * directory..</li> - * <li>Try opening it without the given directory. The file path is relative to - * the current working directory.</li> - * <li>Try opening the file as a system resource through the class loader.</li> - * </ol> - * Only if all tries failed, creating the stream fails. - * @author <a href="mailto:and...@gm...">Andreas Vogl</a> - * @author <a href="mailto:ch...@ri...">Christian Hujer</a> - * @see CFileReader - */ -public final class CFileInputStream extends BufferedInputStream { - - /** - * Creates a new CFileInputStream to a specified resource file. - * @param dname name of directory that the file is in (<code>null</code> - * means the file is located in the editor root dir) - * @param fname name of the resource file - * @throws FileNotFoundException In case all three tries to open the file failed - */ - public CFileInputStream(@Nullable final String dname, @NotNull final String fname) throws FileNotFoundException { - super(createStream(dname, fname)); - } - - /** - * Open the resource file for reading. - * @param dname directory name to read from - * @param fname file name of file to read - * @return Stream for reading from <var>fname</var> - * @throws FileNotFoundException In case all tries to open the file failed - */ - @SuppressWarnings({"MethodWithMultipleReturnPoints", "MethodWithMoreThanThreeNegations"}) - @NotNull private static InputStream createStream(@Nullable final String dname, @NotNull final String fname) throws FileNotFoundException { - try { // 1st try normal binary file relative to specified directory - return new FileInputStream(new File(dname, fname)); - } catch (final Exception e) { - // ignore - } - try { // 2nd try binary file relative to user's current working directory - return new FileInputStream(fname); - } catch (final Exception e) { // 3rd try via system resource from class loader - // ignore - } - final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); - try { // 3rd try context class loader relative to specified directory - @Nullable final InputStream stream = contextClassLoader.getResourceAsStream(new File(dname, fname).toURL().toURI().toString()); - if (stream != null) { - return stream; - } - } catch (final Exception e) { - // ignore - } - try { // 4th try context class loader relative to class loader's top level directory - @Nullable final InputStream stream = contextClassLoader.getResourceAsStream(new File(fname).toURL().toURI().toString()); - if (stream != null) { - return stream; - } - } catch (final Exception e) { - // ignore - } - try { // 5th try system class loader relative to specified directory - @Nullable final InputStream stream = ClassLoader.getSystemResourceAsStream(new File(dname, fname).toURL().toURI().toString()); - if (stream != null) { - return stream; - } - } catch (final Exception e) { - // ignore - } - try { // 6th try system class loader relative to class loader's top level directory - @Nullable final InputStream stream = ClassLoader.getSystemResourceAsStream(new File(fname).toURL().toURI().toString()); - if (stream != null) { - return stream; - } - } catch (final Exception e) { - // ignore - } - throw new FileNotFoundException("CFileInputStream couldn't find " + new File(dname, fname) + "."); - } - -} // class CFileInputStream Deleted: trunk/crossfire/src/cfeditor/CFileReader.java =================================================================== --- trunk/crossfire/src/cfeditor/CFileReader.java 2006-09-14 21:33:23 UTC (rev 333) +++ trunk/crossfire/src/cfeditor/CFileReader.java 2006-09-17 19:46:54 UTC (rev 334) @@ -1,177 +0,0 @@ -/* - * Crossfire 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 cfeditor; - -import java.io.BufferedReader; -import java.io.EOFException; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.Reader; -import java.io.UnsupportedEncodingException; - -/** - * Class for opening and reading a buffered stream to an ASCII resource-file. - * If no such file is found, the file is loaded from the jar archive. - * This class is very similar to {@link CFileInputStream}. - * The file is tried to open in the following order: - * <ol> - * <li>Try opening it with the given directory. The directory path is relative to the current working directory, the file path relative to that - * directory..</li> - * <li>Try opening it without the given directory. The file path is relative to the current working directory.</li> - * <li>Try opening the file as a system resource through the class loader.</li> - * </ol> - * Only if all tries failed, creating the stream fails. - * @author <a href="mailto:and...@gm...">Andreas Vogl</a> - * @author <a href="mailto:ch...@ri...">Christian Hujer</a> - * @todo eventually remove readUntil - this is afaik only used for reading arches and such, and since there should be an integrated arch editor... - * @see CFileInputStream - */ -public final class CFileReader extends BufferedReader { - - /** Maximum number of characters to read in readUntil. */ - private static final long READ_MAX = 10000L; - - /** - * Open an ascii-stream to the specified resource file. - * @param dname name of directory that the file is in (<code>null</code> means the file is located in the editor root dir) - * @param fname name of the resource file - * @throws FileNotFoundException in case all three tries to open the file failed - */ - public CFileReader(final String dname, final String fname) throws FileNotFoundException { - super(createReader(dname, fname)); - } - - /** - * Open the resource file for reading. - * @param dname name of directory that the file is in (null means the file is located in the editor root dir) - * @param fname name of the resource file - * @return Stream for reading from <var>fname</var> - * @throws FileNotFoundException In case all three tries to open the file failed - */ - private static Reader createReader(final String dname, final String fname) throws FileNotFoundException { - try { - return new InputStreamReader(new CFileInputStream(dname, fname), CMainControl.MAP_ENCODING); - } catch (final UnsupportedEncodingException e) { - throw new Error(e); - } - } - - /** - * Reads characters from the BufferedReader stream till 'tag' is found. If - * found, the method returns with stream pointing right after the - * appearance of 'tag'. - * @param stream ascii input stream to read from - * @param tag stop reading at the string 'tag' - * @param abort throw <code>EOFException</code> at string 'abort' (this can be null) - * @throws IOException an I/O-error occurred while reading the file - * @throws EOFException the end of file was reached, or the 'abort' string - * has been encountered - * @todo Should the encounter of the abort string before the tag really be - * an EOFException? That's semantically wrong, but current usage code - * relies on this :( - */ - public static void readUntil(final BufferedReader stream, final String tag, final String abort) throws IOException { - int c; // character value, read from the stream - int t = 0; // tag index - int a = 0; // abort index - - if (abort != null) { - // look both for 'tag' and 'abort' - do { - c = stream.read(); - if (c == tag.charAt(t)) { - t++; - } else { - t = 0; - } - if (c == abort.charAt(a)) { - a++; - } else { - a = 0; - } - } while (t < tag.length() && a < abort.length() && c != -1); - } else { - // look only for 'tag' - do { - c = stream.read(); - if (c == tag.charAt(t)) { - t++; - } else { - t = 0; - } - } while (t < tag.length() && c != -1); - } - - // if we did not find the tag, an EOFException is thrown - if (c == -1) { - throw new EOFException(); - } - - // if we found the string 'abort', throw EOFException as well - if (abort != null && a == abort.length()) { - throw new EOFException(); - } - } - - /** - * Reads characters from the BufferedReader stream till 'tag' is found. - * Similar to readUntil(), except that the read String is returned. 'tag' - * is not included in the returned String. - * @param stream ascii input stream to read from - * @param tag stop reading at the string 'tag' - * @return the string between the starting pos. of 'stream' (inclusive) and - * the first character of 'tag' (exclusive). - * @throws IOException an I/O-error occurred while reading the file - * @throws EOFException the end of file was reached - */ - public static String readUntil(final BufferedReader stream, final String tag) throws IOException { - final StringBuilder sb = new StringBuilder(); - int c; // character value, read from the stream - int t = 0; // index - - long count = 0; // counter (to realize when shooting past EOF) - final long maxCount = READ_MAX; // bail out when counter exceeds this value - - do { - c = stream.read(); // read one character - sb.append((char) c); - if (c == tag.charAt(t)) { - t++; - } else { - t = 0; - } - } while (t < tag.length() && c != -1 && count++ < maxCount); - - // if we did not find the tag, an EOFException is thrown - if (c == -1 || count >= maxCount) { - throw new EOFException(); - } - // cut 'tag' off, at the end of the string - return sb.substring(0, sb.length() - tag.length()); - } - -} // class CFileReader Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-09-14 21:33:23 UTC (rev 333) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-09-17 19:46:54 UTC (rev 334) @@ -31,13 +31,13 @@ import cfeditor.map.MapArchObject; import cfeditor.map.MapControl; import cfeditor.map.MapModel; -import cfeditor.textedit.scripteditor.ScriptEditControl; import java.awt.Font; import java.awt.Point; import java.awt.Rectangle; import java.awt.Toolkit; import java.io.File; import java.io.IOException; +import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Enumeration; import java.util.Iterator; @@ -57,6 +57,8 @@ import net.sf.gridarta.Size2D; import net.sf.gridarta.MainControl; import net.sf.gridarta.CUndoStack; +import net.sf.gridarta.textedit.scripteditor.ScriptEditControl; +import net.sf.gridarta.gui.HideFileFilterProxy; import net.sf.japi.swing.ActionFactory; import static net.sf.japi.swing.ActionFactory.getFactory; import net.sf.japi.util.filter.file.EndingFileFilter; @@ -83,15 +85,6 @@ /** Singleton instance reference. */ private static CMainControl instance; - /** - * Encoding to use for maps and other data. - * The encoding given here is used for reading and writing maps. - * You shouldn't change this only because you use an UTF-8 system or so, since the encoding used here MUST be compatible with the server and the - * client. The paragraph sign § is the critical character. - * @todo once the mailing list decided on the § character, eventually replace by "us-ascii". - */ - public static final String MAP_ENCODING = "iso-8859-1"; - public static final String DOCU_VERSION_KEY = "docuVersion"; public static final String MAP_DIR_KEY = "mapDirectory"; @@ -522,8 +515,8 @@ refreshMenusAndToolbars(); } - /** Swing FileFilter for Lua scripts. */ - public static final FileFilter pythonFileFilter = new net.sf.gridarta.gui.HideFileFilterProxy(new EndingFileFilter(true, ACTION_FACTORY.getString("fileDialog.filter.python"), ".py")); + /** Swing FileFilter for Python scripts. */ + public static final FileFilter pythonFileFilter = new HideFileFilterProxy(new EndingFileFilter(true, ACTION_FACTORY.getString("fileDialog.filter.python"), ".py")); public String getMapDefaultFolder() { return strMapDir; @@ -572,6 +565,16 @@ return comp; } + /** {@inheritDoc} */ + public FileFilter getScriptFileFilter() { + return pythonFileFilter; + } + + /** {@inheritDoc} */ + public String getScriptSuffix() { + return ".py"; + } + /** * set plain font to the given component * @param comp component @@ -973,11 +976,11 @@ try { objects = mapFileDecoder.decodeMapFile(file); // parse mapfile maparch = mapFileDecoder.getMapArch(); // get map arch - } catch (GridderException e) { + } catch (final IOException e) { // popup display showMessage("Couldn't load Map", e.getMessage()); return null; - } catch (OutOfMemoryError e) { + } catch (final OutOfMemoryError e) { // out of memory!! - display error showMessage("Out of Memory", "Not enough memory available to open more maps!\n" + "You can increase the memory limit by using the '-mx' runtime flag.\n" + @@ -1031,7 +1034,14 @@ * @param mapModel MapModel to save */ public void encodeMapFile(@NotNull final File file, final MapModel mapModel) { - mapFileEncoder.encodeMapFile(file, mapModel); + final String fname = file.getAbsolutePath(); + try { + mapFileEncoder.encodeMapFile(file, mapModel); + } catch (final FileNotFoundException e) { + showMessage("Error Save Map", "Error writing file " + fname + "\n"); + } catch (final IOException e) { + showMessage("Error Save Map", "Error writing file " + fname + "\n"); + } } /** Modified: trunk/crossfire/src/cfeditor/CMainMenu.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainMenu.java 2006-09-14 21:33:23 UTC (rev 333) +++ trunk/crossfire/src/cfeditor/CMainMenu.java 2006-09-17 19:46:54 UTC (rev 334) @@ -33,7 +33,6 @@ import cfeditor.menu.MenuManager; import cfeditor.menu.SimpleMenuEntry; import cfeditor.menu.SimpleMenuLocation; -import cfeditor.textedit.scripteditor.ScriptEditControl; import java.awt.Event; import java.awt.Font; import java.awt.event.ActionEvent; Modified: trunk/crossfire/src/cfeditor/CMapFileDecode.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapFileDecode.java 2006-09-14 21:33:23 UTC (rev 333) +++ trunk/crossfire/src/cfeditor/CMapFileDecode.java 2006-09-17 19:46:54 UTC (rev 334) @@ -28,23 +28,27 @@ import cfeditor.map.MapArchObject; import java.io.BufferedReader; import java.io.File; -import java.io.FileReader; import java.io.IOException; +import java.io.InputStreamReader; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.List; -import cfeditor.GridderException; import org.apache.log4j.Logger; import org.jetbrains.annotations.Nullable; +import net.sf.gridarta.io.CFileReader; /** * This class handles the reading of a mapfile and parsing the data * into a list of ArchObjects. * @author <a href="mailto:mic...@no...">Michael Toennies</a> * @author <a href="mailto:and...@gm...">Andreas Vogl</a> + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @todo change to classical IO class style */ public final class CMapFileDecode { - private static final Logger log = Logger.getLogger(CMapFileDecode.class); + private static final Logger LOG = Logger.getLogger(CMapFileDecode.class); private int maxxlen, maxylen; @@ -66,14 +70,13 @@ * This method returns a list of arches, connected with the temp pointers. * @param file mapfile * @return first <code>ArchObject</code> in the list - * @throws GridderException when file content invalid + * @throws FileNotFoundException in case the requested map file was not found + * @throws IOException in case the file couldn't be read or is in wrong format + * @todo create a separate exception for the wrong format */ - public List<ArchObject> decodeMapFile(final File file) throws GridderException { - + public List<ArchObject> decodeMapFile(final File file) throws FileNotFoundException, IOException { + final BufferedReader myInput = new BufferedReader(new InputStreamReader(new FileInputStream(file), CFileReader.MAP_ENCODING)); try { - final FileReader fr = new FileReader(file); - final BufferedReader myInput = new BufferedReader(fr); - maxxlen = 0; maxylen = 0; objects = new ArrayList<ArchObject>(); @@ -81,24 +84,17 @@ // first of all we read the map arch (if that fails we throw an exception) maparch = new MapArchObject(); if (!maparch.parseMapArch(myInput, file.getName())) { - throw new GridderException("The file '" + file.getName() + "' does not\n" + - "contain a valid Crossfire map format!\n"); + throw new IOException("The file '" + file.getName() + "' does not contain a valid Crossfire map format!\n"); } //maparch.setName(file.getName()); // now we read all the ArchObjects - String thisLine; - while ((thisLine = myInput.readLine()) != null) { + for (String thisLine; (thisLine = myInput.readLine()) != null;) { readArch(myInput, thisLine, null); // all these are map arches } + } finally { myInput.close(); - fr.close(); - } catch (final IOException e) { - log.debug("Error Loading file " + file.getName(), e); - - throw new GridderException("The file '" + file.getName() + "' cannot be loaded: " + e.getMessage()); } - // finally... here we go // last action: if the map is bigger than the specified size in // the maparch, we set the true size: the maxxlen/maxylen counters. @@ -192,20 +188,20 @@ // now we test for a new arch - thats stuf in inventory // or the end... thats the end of this shit } else if (thisLine.startsWith("arch ")) { - if (log.isDebugEnabled()) { - log.debug("GO INVENTORY: " + arch + " - " + thisLine); + if (LOG.isDebugEnabled()) { + LOG.debug("GO INVENTORY: " + arch + " - " + thisLine); } readArch(myInput, thisLine, arch); - if (log.isDebugEnabled()) { - log.debug("GO INVENTORY2: " + arch + " - " + thisLine); + if (LOG.isDebugEnabled()) { + LOG.debug("GO INVENTORY2: " + arch + " - " + thisLine); } } else if (thisLine.startsWith("end")) { objects.add(arch); archflag = false; archmore = false; - if (log.isDebugEnabled()) { - log.debug("LEAVE!: " + arch + " - " + thisLine); + if (LOG.isDebugEnabled()) { + LOG.debug("LEAVE!: " + arch + " - " + thisLine); } return arch; } else if (thisLine.regionMatches(0, "msg", 0, 3)) { @@ -245,7 +241,7 @@ arch.addEventScript(type, path); } } else { - log.warn("Arch " + arch.getArchName() + " has incorrect event code '" + thisLine + "'"); + LOG.warn("Arch " + arch.getArchName() + " has incorrect event code '" + thisLine + "'"); arch.addArchText(thisLine + "\n"); // keep line, it might have a meaning after all } } else if (thisLine.regionMatches(0, "x ", 0, 2)) { @@ -287,7 +283,7 @@ thisLine2 = myInput.readLine(); } } catch (final IOException e) { - log.error("Read Error while trying to load map: " + maparch.getFileName(), e); + LOG.error("Read Error while trying to load map: " + maparch.getFileName(), e); throw e; // we simply pass this exception to the calling function } Modified: trunk/crossfire/src/cfeditor/CMapFileEncode.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapFileEncode.java 2006-09-14 21:33:23 UTC (rev 333) +++ trunk/crossfire/src/cfeditor/CMapFileEncode.java 2006-09-17 19:46:54 UTC (rev 334) @@ -39,6 +39,7 @@ import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; +import java.util.Map; import net.sf.gridarta.Size2D; import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; @@ -52,8 +53,6 @@ private static final Logger log = Logger.getLogger(CMapFileEncode.class); - private FileWriter fileWriter; - private BufferedWriter bufferedWriter; private final CMainControl mainControl; @@ -70,13 +69,12 @@ * @param file mapfile * @param mapModel the MapModel to encode */ - public void encodeMapFile(@NotNull final File file, final MapModel mapModel) { + public void encodeMapFile(@NotNull final File file, final MapModel mapModel) throws FileNotFoundException, IOException { final MapArchObject map = mapModel.getMapArchObject(); try { fname = file.getAbsolutePath(); - fileWriter = new FileWriter(file); - bufferedWriter = new BufferedWriter(fileWriter); + bufferedWriter = new BufferedWriter(new FileWriter(file)); //ArchObject multi; // write map header: map arch @@ -129,13 +127,9 @@ } // node } // y } // x - + } finally { bufferedWriter.close(); - fileWriter.close(); - } catch (final FileNotFoundException e) { - mainControl.showMessage("Error Save Map", "Error writing file " + fname + "\n"); - } catch (final IOException e) { - mainControl.showMessage("Error Save Map", "Error writing file " + fname + "\n"); + bufferedWriter = null; } } @@ -159,7 +153,7 @@ final ArchObject defarch = arch.getDefaultArch(); // Collect all fields to write. - final HashMap fields = new HashMap(); // String key -> String value + final Map<String, String> fields = new HashMap<String, String>(); // String key -> String value final String name = arch.getObjName(); if (name != null) { @@ -175,10 +169,10 @@ final String events = arch.getMapArchEventData(); if (!events.equals("")) { final String[] tmp = events.split("\n"); - for (int i = 0; i < tmp.length; i++) { - final String[] line = tmp[i].split(" +", 2); + for (final String aTmp : tmp) { + final String[] line = aTmp.split(" +", 2); if (line.length != 2) { - log.warn("writeMapArch: ignoring invalid event line: " + tmp[i]); + log.warn("writeMapArch: ignoring invalid event line: " + aTmp); } else { fields.put(line[0], line[1]); } @@ -246,10 +240,10 @@ final String text = arch.getArchText(); if (!text.equals("")) { final String[] tmp = text.split("\n"); - for (int i = 0; i < tmp.length; i++) { - final String[] line = tmp[i].split(" +", 2); + for (final String aTmp : tmp) { + final String[] line = aTmp.split(" +", 2); if (line.length != 2) { - log.warn("writeMapArch: ignoring invalid arch line: " + tmp[i]); + log.warn("writeMapArch: ignoring invalid arch line: " + aTmp); } else { fields.put(line[0], line[1]); } @@ -302,20 +296,21 @@ * Comparator to compare two object fields. The comparator sorts the fields * in the order in which they should be written to disk. */ - private final Comparator keyOrderComparator = new Comparator() { - public int compare(final Object o1, final Object o2) { - final String s1 = (String) o1; - final String s2 = (String) o2; - final Integer i1 = (Integer) keys.get(s1); - final Integer i2 = (Integer) keys.get(s2); - final int v1 = i1 == null ? 10000 : i1.intValue(); - final int v2 = i2 == null ? 10000 : i2.intValue(); + private static final Comparator<String> keyOrderComparator = new Comparator<String>() { + + /** {@inheritDoc} */ + public int compare(final String o1, final String o2) { + final Integer i1 = keys.get(o1); + final Integer i2 = keys.get(o2); + final int v1 = i1 == null ? Integer.MAX_VALUE : i1.intValue(); + final int v2 = i2 == null ? Integer.MAX_VALUE : i2.intValue(); if (v1 < v2) { return -1; } if (v1 > v2) { return +1; } + assert v1 == v2; return 0; } }; @@ -325,7 +320,7 @@ * the field name, the value is an Integer that describes the order. Lower * values are written first. */ - private static final HashMap keys = new HashMap(); + private static final Map<String, Integer> keys = new HashMap<String, Integer>(); /* * Initialize {@link keys} array. @@ -570,7 +565,7 @@ * the order in which the objects fields are written out. */ private static void addKey(final String key) { - keys.put(key, new Integer(idKey++)); + keys.put(key, idKey++); } } // class CMapFileEncode Modified: trunk/crossfire/src/cfeditor/CPickmapPanel.java =================================================================== --- trunk/crossfire/src/cfeditor/CPickmapPanel.java 2006-09-14 21:33:23 UTC (rev 333) +++ trunk/crossfire/src/cfeditor/CPickmapPanel.java 2006-09-17 19:46:54 UTC (rev 334) @@ -29,6 +29,7 @@ import cfeditor.map.MapArchObject; import cfeditor.map.MapControl; import java.io.File; +import java.io.IOException; import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; @@ -159,7 +160,7 @@ tabpane.insertTab(mapFile.getName(), null, bmapview, null, i); return true; } - } catch (final GridderException e) { + } catch (final IOException e) { // loading failed - could be a system file in that directory, // or something else. Doesn't deserve more attention than a printout. if (!mapFile.getName().startsWith(".")) { Modified: trunk/crossfire/src/cfeditor/FaceObject.java =================================================================== --- trunk/crossfire/src/cfeditor/FaceObject.java 2006-09-14 21:33:23 UTC (rev 333) +++ trunk/crossfire/src/cfeditor/FaceObject.java 2006-09-17 19:46:54 UTC (rev 334) @@ -33,6 +33,7 @@ import javax.swing.ImageIcon; import org.apache.log4j.Logger; import org.jetbrains.annotations.Nullable; +import net.sf.gridarta.io.CFileInputStream; /** * The <code>FaceObject</code> Modified: trunk/crossfire/src/cfeditor/IGUIConstants.java =================================================================== --- trunk/crossfire/src/cfeditor/IGUIConstants.java 2006-09-14 21:33:23 UTC (rev 333) +++ trunk/crossfire/src/cfeditor/IGUIConstants.java 2006-09-17 19:46:54 UTC (rev 334) @@ -141,8 +141,6 @@ String TREASURES_FILE = "treasures"; // treasurelists file - String PYTHONMENU_FILE = "cfpython_menu.def"; // file with cfpython commands - String BMAPS_FILE = ""; // dummy (only used for iso view) String ARCHDEF_FILE = ""; Modified: trunk/crossfire/src/cfeditor/MultiPositionData.java =================================================================== --- trunk/crossfire/src/cfeditor/MultiPositionData.java 2006-09-14 21:33:23 UTC (rev 333) +++ trunk/crossfire/src/cfeditor/MultiPositionData.java 2006-09-17 19:46:54 UTC (rev 334) @@ -29,6 +29,7 @@ import java.io.IOException; import java.util.StringTokenizer; import org.apache.log4j.Logger; +import net.sf.gridarta.io.CFileReader; /** * The MultiPositionData class stores an array of numbers which is required @@ -71,55 +72,56 @@ * the file don't match expected array dimensions. */ private void load() { - final CFileReader reader; - // read datafile line by line, parsing numbers into the array try { - reader = new CFileReader(CMainControl.getInstance().getArchDefaultFolder() + File.separator + IGUIConstants.CONFIG_DIR, IGUIConstants.ARCHDEF_FILE); - String line = null; // read line of file - String num; // number, still in string format - int xp = 0; // x-index in the data array - int yp = 0; // y-index in the data array + final CFileReader reader = new CFileReader(CMainControl.getInstance().getArchDefaultFolder() + File.separator + IGUIConstants.CONFIG_DIR, IGUIConstants.ARCHDEF_FILE); + try { + String num; // number, still in string format + int xp = 0; // x-index in the data array + int yp = 0; // y-index in the data array - // read the whole file line by line - while ((line = reader.readLine()) != null) { - line = line.trim(); - if (line.length() > 0 && !line.startsWith("#") && yp < Y_DIM) { - final StringTokenizer s = new StringTokenizer(line, " ", false); - while (s != null && s.hasMoreTokens()) { - num = s.nextToken(); // get one number - if (num.length() > 0 && xp < X_DIM) { - try { - // parse and store it as integer - data[yp][xp] = Integer.parseInt(num); - xp++; // increase index - } catch (final NumberFormatException e) { + // read the whole file line by line + for (String line; (line = reader.readLine()) != null;) { + line = line.trim(); + if (line.length() > 0 && !line.startsWith("#") && yp < Y_DIM) { + final StringTokenizer s = new StringTokenizer(line, " ", false); + while (s != null && s.hasMoreTokens()) { + num = s.nextToken(); // get one number + if (num.length() > 0 && xp < X_DIM) { + try { + // parse and store it as integer + data[yp][xp] = Integer.parseInt(num); + xp++; // increase index + } catch (final NumberFormatException e) { + } } } - } - // report if there haven't been enough numbers in this row - if (xp < X_DIM) { - log.warn("In file " + IGUIConstants.ARCHDEF_FILE + ": Missing " + (X_DIM - xp) + " numbers in row " + (yp + 1) + "."); + // report if there haven't been enough numbers in this row + if (xp < X_DIM) { + log.warn("In file " + IGUIConstants.ARCHDEF_FILE + ": Missing " + (X_DIM - xp) + " numbers in row " + (yp + 1) + "."); + } + + xp = 0; // prepare indices for next row + yp++; } + } + if (yp < Y_DIM) { + log.warn("In file " + IGUIConstants.ARCHDEF_FILE + ": Missing " + (Y_DIM - yp) + " entire rows of data."); + } - xp = 0; // prepare indices for next row - yp++; - } + } finally { + reader.close(); // close filereader } - reader.close(); // close filereader - // report if there haven't been enough rows in the file - if (yp < Y_DIM) { - log.warn("In file " + IGUIConstants.ARCHDEF_FILE + ": Missing " + (Y_DIM - yp) + " entire rows of data."); - } - // confirm load process if (log.isInfoEnabled()) { log.info("Loaded multipart position data from '" + IGUIConstants.ARCHDEF_FILE + "'"); } } catch (final FileNotFoundException e) { + /* TODO ignore (really?) */ } catch (final IOException e) { + /* TODO ignore (really?) */ } } Modified: trunk/crossfire/src/cfeditor/ScriptArchData.java =================================================================== --- trunk/crossfire/src/cfeditor/ScriptArchData.java 2006-09-14 21:33:23 UTC (rev 333) +++ trunk/crossfire/src/cfeditor/ScriptArchData.java 2006-09-17 19:46:54 UTC (rev 334) @@ -25,7 +25,6 @@ package cfeditor; import cfeditor.arch.ArchObject; -import cfeditor.textedit.scripteditor.ScriptEditControl; import java.awt.Color; import java.awt.FlowLayout; import java.awt.Insets; @@ -49,6 +48,7 @@ import javax.swing.JTextField; import static javax.swing.WindowConstants.HIDE_ON_CLOSE; import net.sf.japi.util.Arrays2; +import net.sf.gridarta.textedit.scripteditor.ScriptEditControl; import org.apache.log4j.Logger; import org.jetbrains.annotations.Nullable; Modified: trunk/crossfire/src/cfeditor/arch/ArchObjectParser.java =================================================================== --- trunk/crossfire/src/cfeditor/arch/ArchObjectParser.java 2006-09-14 21:33:23 UTC (rev 333) +++ trunk/crossfire/src/cfeditor/arch/ArchObjectParser.java 2006-09-17 19:46:54 UTC (rev 334) @@ -24,7 +24,6 @@ package cfeditor.arch; -import cfeditor.CFileReader; import cfeditor.CMainControl; import cfeditor.IGUIConstants; import cfeditor.MultiPositionData; @@ -46,6 +45,7 @@ import org.jdom.JDOMException; import org.jdom.input.SAXBuilder; import org.jetbrains.annotations.Nullable; +import net.sf.gridarta.io.CFileReader; /** * The <code>ArchObjectParser</code> class handles the parsing of arches. It is Modified: trunk/crossfire/src/cfeditor/arch/ArchObjectStack.java =================================================================== --- trunk/crossfire/src/cfeditor/arch/ArchObjectStack.java 2006-09-14 21:33:23 UTC (rev 333) +++ trunk/crossfire/src/cfeditor/arch/ArchObjectStack.java 2006-09-17 19:46:54 UTC (rev 334) @@ -27,8 +27,6 @@ import cfeditor.CArchPanel; import cfeditor.CFTreasureListTree; -import cfeditor.CFileInputStream; -import cfeditor.CFileReader; import cfeditor.CMainControl; import cfeditor.CMainStatusbar; import cfeditor.CPickmapPanel; @@ -59,6 +57,8 @@ import javax.swing.SwingConstants; import org.apache.log4j.Logger; import org.jetbrains.annotations.Nullable; +import net.sf.gridarta.io.CFileInputStream; +import net.sf.gridarta.io.CFileReader; /** * The <code>ArchObjectStack</code> contains all the default arches. Modified: trunk/daimonin/build.xml =================================================================== --- trunk/daimonin/build.xml 2006-09-14 21:33:23 UTC (rev 333) +++ trunk/daimonin/build.xml 2006-09-17 19:46:54 UTC (rev 334) @@ -102,6 +102,9 @@ <exclude name="**/.xvpics/**"/> </fileset> </copy> + <copy todir="${build.dir}"> + <fileset dir="../src/app" excludes="**/*.java,**/package.html,**/overview.html" /> + </copy> <!--copy todir="${build.dir}"> <fileset dir="${config.dir}" /> </copy--> Modified: trunk/daimonin/src/daieditor/CFTreasureListTree.java =================================================================== --- trunk/daimonin/src/daieditor/CFTreasureListTree.java 2006-09-14 21:33:23 UTC (rev 333) +++ trunk/daimonin/src/daieditor/CFTreasureListTree.java 2006-09-17 19:46:54 UTC (rev 334) @@ -64,6 +64,7 @@ import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.TreePath; import net.sf.gridarta.help.Help; +import net.sf.gridarta.io.CFileReader; import net.sf.japi.util.EnumerationIterator; import org.jetbrains.annotations.Nullable; Deleted: trunk/daimonin/src/daieditor/CFileInputStream.java =================================================================== --- trunk/daimonin/src/daieditor/CFileInputStream.java 2006-09-14 21:33:23 UTC (rev 333) +++ trunk/daimonin/src/daieditor/CFileInputStream.java 2006-09-17 19:46:54 UTC (rev 334) @@ -1,122 +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 java.io.BufferedInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.InputStream; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -/** - * Class for opening and reading a buffered stream to a BINARY resource-file. - * If no such file is found, the file is loaded from the jar archive. - * This class is very similar to {@link CFileReader}. - * The file is tried to open in the following order: - * <ol> - * <li>Try opening it with the given directory. The directory path is relative - * to the current working directory, the file path relative to that - * directory..</li> - * <li>Try opening it without the given directory. The file path is relative to - * the current working directory.</li> - * <li>Try opening the file as a system resource through the class loader.</li> - * </ol> - * Only if all tries failed, creating the stream fails. - * @author <a href="mailto:and...@gm...">Andreas Vogl</a> - * @author <a href="mailto:ch...@ri...">Christian Hujer</a> - * @see CFileReader - */ -public final class CFileInputStream extends BufferedInputStream { - - /** - * Creates a new CFileInputStream to a specified resource file. - * @param dname name of directory that the file is in (<code>null</code> - * means the file is located in the editor root dir) - * @param fname name of the resource file - * @throws FileNotFoundException In case all three tries to open the file failed - */ - public CFileInputStream(@Nullable final String dname, @NotNull final String fname) throws FileNotFoundException { - super(createStream(dname, fname)); - } - - /** - * Open the resource file for reading. - * @param dname directory name to read from - * @param fname file name of file to read - * @return Stream for reading from <var>fname</var> - * @throws FileNotFoundException In case all tries to open the file failed - */ - @SuppressWarnings({"MethodWithMultipleReturnPoints", "MethodWithMoreThanThreeNegations"}) - @NotNull private static InputStream createStream(@Nullable final String dname, @NotNull final String fname) throws FileNotFoundException { - try { // 1st try normal binary file relative to specified directory - return new FileInputStream(new File(dname, fname)); - } catch (final Exception e) { - // ignore - } - try { // 2nd try binary file relative to user's current working directory - return new FileInputStream(fname); - } catch (final Exception e) { // 3rd try via system resource from class loader - // ignore - } - final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); - try { // 3rd try context class loader relative to specified directory - @Nullable final InputStream stream = contextClassLoader.getResourceAsStream(new File(dname, fname).toURL().toURI().toString()); - if (stream != null) { - return stream; - } - } catch (final Exception e) { - // ignore - } - try { // 4th try context class loader relative to class loader's top level directory - @Nullable final InputStream stream = contextClassLoader.getResourceAsStream(new File(fname).toURL().toURI().toString()); - if (stream != null) { - return stream; - } - } catch (final Exception e) { - // ignore - } - try { // 5th try system class loader relative to specified directory - @Nullable final InputStream stream = ClassLoader.getSystemResourceAsStream(new File(dname, fname).toURL().toURI().toString()); - if (stream != null) { - return stream; - } - } catch (final Exception e) { - // ignore - } - try { // 6th try system class loader relative to class loader's top level directory - @Nullable final InputStream stream = ClassLoader.getSystemResourceAsStream(new File(fname).toURL().toURI().toString()); - if (stream != null) { - return stream; - } - } catch (final Exception e) { - // ignore - } - throw new FileNotFoundException("CFileInputStream couldn't find " + new File(dname, fname) + "."); - } - -} // class CFileInputStream Deleted: trunk/daimonin/src/daieditor/CFileReader.java =================================================================== --- trunk/daimonin/src/daieditor/CFileReader.java 2006-09-14 21:33:23 UTC (rev 333) +++ trunk/daimonin/src/daieditor/CFileReader.java 2006-09-17 19:46:54 UTC (rev 334) @@ -1,177 +0,0 @@ -/* - * Daimonin Java Editor. - * Copyright (C) 2000 Michael Toennies - * C... [truncated message content] |
From: <aki...@us...> - 2006-09-14 21:33:34
|
Revision: 333 http://svn.sourceforge.net/gridarta/?rev=333&view=rev Author: akirschbaum Date: 2006-09-14 14:33:23 -0700 (Thu, 14 Sep 2006) Log Message: ----------- Move common code into a function. Modified Paths: -------------- trunk/crossfire/src/cfeditor/map/DefaultMapModel.java trunk/daimonin/src/daieditor/map/DefaultMapModel.java Modified: trunk/crossfire/src/cfeditor/map/DefaultMapModel.java =================================================================== --- trunk/crossfire/src/cfeditor/map/DefaultMapModel.java 2006-09-13 23:12:31 UTC (rev 332) +++ trunk/crossfire/src/cfeditor/map/DefaultMapModel.java 2006-09-14 21:33:23 UTC (rev 333) @@ -322,11 +322,11 @@ * @param intern ??? */ private boolean testArchToMap(final int archnr, final int xx, final int yy, final int intern) { - final int count = mainControl.getArchObjectStack().getArch(archnr).getMultiRefCount(); // count of multi tile. 0= single tile + final int count = getDefaultArch(archnr).getMultiRefCount(); // count of multi tile. 0= single tile for (int c = 0; c <= count; c++) { - final int mapx = xx + mainControl.getArchObjectStack().getArch(archnr + c).getMultiRefX(); - final int mapy = yy + mainControl.getArchObjectStack().getArch(archnr + c).getMultiRefY(); + final int mapx = xx + getDefaultArch(archnr + c).getMultiRefX(); + final int mapy = yy + getDefaultArch(archnr + c).getMultiRefY(); if (!isPointValid(mapx, mapy)) { // outside map return false; @@ -463,7 +463,7 @@ return false; } - newarch = mainControl.getArchObjectStack().getArch(archnr); // temp. store this arch + newarch = getDefaultArch(archnr); // temp. store this arch if (mainControl.getAutojoin() && join == JOIN_ENABLE && mainControl.getJoinlist() != null && newarch.getJoinList() != null && !newarch.isMulti()) { // do autojoining if enabled @@ -473,13 +473,13 @@ } } - final int count = mainControl.getArchObjectStack().getArch(archnr).getMultiRefCount(); // count of multi tile. 0= single tile + final int count = getDefaultArch(archnr).getMultiRefCount(); // count of multi tile. 0= single tile oldarch = null; startarch = null; for (int c = 0; c <= count; c++) { - final int mapx = pos.x + mainControl.getArchObjectStack().getArch(archnr + c).getMultiRefX(); - final int mapy = pos.y + mainControl.getArchObjectStack().getArch(archnr + c).getMultiRefY(); + final int mapx = pos.x + getDefaultArch(archnr + c).getMultiRefX(); + final int mapy = pos.y + getDefaultArch(archnr + c).getMultiRefY(); newarch = mainControl.getArchObjectStack().newArchObjectInstance(archnr + c); if (oldarch != null) { newarch.setMapMultiHead(startarch); @@ -755,7 +755,7 @@ it.remove(); // do autojoining - final ArchObject temp = mainControl.getArchObjectStack().getArch(node.getNodeNr()); // get defarch + final ArchObject temp = getDefaultArch(node.getNodeNr()); // get defarch if (mainControl.getAutojoin() && join == JOIN_ENABLE && mainControl.getJoinlist() != null && temp.getJoinList() != null && !temp.isMulti()) { // remove connections to the deleted arch @@ -1191,4 +1191,16 @@ } */ + /** + * Get a default {@link ArchObject} instance. + * + * @param archnr arch object identification id + * + * @return the default arch object instance corresponding to + * <code>archnr</code>, or <code>null</code> if it does not exist + */ + private ArchObject getDefaultArch(final int archnr) { + return mainControl.getArchObjectStack().getArch(archnr); + } + } // class DefaultMapModel Modified: trunk/daimonin/src/daieditor/map/DefaultMapModel.java =================================================================== --- trunk/daimonin/src/daieditor/map/DefaultMapModel.java 2006-09-13 23:12:31 UTC (rev 332) +++ trunk/daimonin/src/daieditor/map/DefaultMapModel.java 2006-09-14 21:33:23 UTC (rev 333) @@ -218,7 +218,7 @@ /** {@inheritDoc} */ public boolean isMultiArchFittingToMap(final String archname, final Point pos, final boolean allowDouble) { - final ArchObject head = mainControl.getArchObjectStack().getArch(archname); + final ArchObject head = getDefaultArch(archname); final Point mapH = new Point(head.getMultiRefX(), head.getMultiRefY()); mapH.translate(pos.x, pos.y); if (!isPointValid(mapH)) { @@ -252,7 +252,7 @@ return false; } - final ArchObject defaultArch = mainControl.getArchObjectStack().getArch(archname); + final ArchObject defaultArch = getDefaultArch(archname); // FIXME: Check maximum RefX and RefY to check whether the multitile arch fits on the map. if (pos.x + defaultArch.getRefMaxX() > mapSize.getWidth() @@ -335,7 +335,7 @@ archname = newarch.getArchName(); } // create a new copy of a default arch - invnew = mainControl.getArchObjectStack().getArch(archname).createArch(); + invnew = getDefaultArch(archname).createArch(); } else { // create clone from a pickmap if (!newarch.isMulti()) { @@ -607,4 +607,16 @@ } } + /** + * Get a default {@link ArchObject} instance. + * + * @param archName the archetype name + * + * @return the default arch object instance corresponding to + * <code>archName</code>, or <code>null</code> if it does not exist + */ + private ArchObject getDefaultArch(final String archName) { + return mainControl.getArchObjectStack().getArch(archName); + } + } // class DefaultMapModel This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-09-13 23:12:37
|
Revision: 332 http://svn.sourceforge.net/gridarta/?rev=332&view=rev Author: christianhujer Date: 2006-09-13 16:12:31 -0700 (Wed, 13 Sep 2006) Log Message: ----------- Added CIA link to homepage. Modified Paths: -------------- trunk/src/doc/start.xhtml Modified: trunk/src/doc/start.xhtml =================================================================== --- trunk/src/doc/start.xhtml 2006-09-13 23:01:36 UTC (rev 331) +++ trunk/src/doc/start.xhtml 2006-09-13 23:12:31 UTC (rev 332) @@ -53,6 +53,7 @@ <ul> <li><a href="http://sourceforge.net/projects/gridarta/">Gridarta SourceForge Project Page</a> (Forum, Bug Tracker, Feature Request Tracker, Web access to the SVN repository and more)</li> <li><a href="http://freshmeat.net/projects/gridarta/">Gridarta FreshMeat Project Page</a></li> + <li><a href="http://cia.navi.cx/stats/project/gridarta">Gridarta CIA project page</a></li> </ul> </body> </html> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-09-13 23:01:42
|
Revision: 331 http://svn.sourceforge.net/gridarta/?rev=331&view=rev Author: christianhujer Date: 2006-09-13 16:01:36 -0700 (Wed, 13 Sep 2006) Log Message: ----------- Released new update version, committing next build number. Modified Paths: -------------- trunk/daimonin/nextBuildNumber.properties Modified: trunk/daimonin/nextBuildNumber.properties =================================================================== --- trunk/daimonin/nextBuildNumber.properties 2006-09-13 21:56:39 UTC (rev 330) +++ trunk/daimonin/nextBuildNumber.properties 2006-09-13 23:01:36 UTC (rev 331) @@ -1,3 +1,3 @@ #Build Number for ANT. Do not edit! -#Fri Jun 30 02:27:53 CEST 2006 -build.number=2928 +#Thu Sep 14 00:54:43 CEST 2006 +build.number=2929 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-09-13 21:56:46
|
Revision: 330 http://svn.sourceforge.net/gridarta/?rev=330&view=rev Author: christianhujer Date: 2006-09-13 14:56:39 -0700 (Wed, 13 Sep 2006) Log Message: ----------- Removed dead code. Modified Paths: -------------- trunk/daimonin/src/daieditor/textedit/scripteditor/ScriptEditControl.java Modified: trunk/daimonin/src/daieditor/textedit/scripteditor/ScriptEditControl.java =================================================================== --- trunk/daimonin/src/daieditor/textedit/scripteditor/ScriptEditControl.java 2006-09-13 20:59:47 UTC (rev 329) +++ trunk/daimonin/src/daieditor/textedit/scripteditor/ScriptEditControl.java 2006-09-13 21:56:39 UTC (rev 330) @@ -355,8 +355,4 @@ getInstance().openScriptFile("maps/GuildMage.lua"); } - public ScriptEditView getView() { - return view; - } - } // class ScriptEditControl This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-09-13 21:00:01
|
Revision: 329 http://svn.sourceforge.net/gridarta/?rev=329&view=rev Author: christianhujer Date: 2006-09-13 13:59:47 -0700 (Wed, 13 Sep 2006) Log Message: ----------- Fix for SF #1558187 divider size handled wrong - zero size for daieditor Modified Paths: -------------- trunk/src/app/net/sf/gridarta/gui/GSplitPane.java Modified: trunk/src/app/net/sf/gridarta/gui/GSplitPane.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/GSplitPane.java 2006-09-13 01:44:31 UTC (rev 328) +++ trunk/src/app/net/sf/gridarta/gui/GSplitPane.java 2006-09-13 20:59:47 UTC (rev 329) @@ -58,7 +58,9 @@ final int dividerSizeBackup = getDividerSize(); super.updateUI(); setDividerLocation(dividerLocationBackup); - setDividerSize(dividerSizeBackup); + if (dividerSizeBackup > 0) { + setDividerSize(dividerSizeBackup); + } } } // class DSplitPane This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-09-13 01:44:56
|
Revision: 328 http://svn.sourceforge.net/gridarta/?rev=328&view=rev Author: christianhujer Date: 2006-09-12 18:44:31 -0700 (Tue, 12 Sep 2006) Log Message: ----------- Unified I/O. It's late and it might be bogus, please test it. It's unified enough to move it to the common code base, but I'm too tired right now. Maybe tomorrow. Modified Paths: -------------- trunk/crossfire/src/cfeditor/AutojoinList.java trunk/crossfire/src/cfeditor/CFArchTypeList.java trunk/crossfire/src/cfeditor/CFTreasureListTree.java trunk/crossfire/src/cfeditor/CFileInputStream.java trunk/crossfire/src/cfeditor/CFileReader.java trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/FaceObject.java trunk/crossfire/src/cfeditor/MultiPositionData.java trunk/crossfire/src/cfeditor/arch/ArchObjectParser.java trunk/crossfire/src/cfeditor/arch/ArchObjectStack.java trunk/crossfire/src/cfeditor/textedit/scripteditor/CFPythonPopup.java trunk/daimonin/src/daieditor/CFileInputStream.java trunk/daimonin/src/daieditor/CFileReader.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/TrackedBufferedInputStream.java Modified: trunk/crossfire/src/cfeditor/AutojoinList.java =================================================================== --- trunk/crossfire/src/cfeditor/AutojoinList.java 2006-09-12 20:50:47 UTC (rev 327) +++ trunk/crossfire/src/cfeditor/AutojoinList.java 2006-09-13 01:44:31 UTC (rev 328) @@ -98,7 +98,7 @@ final CFileReader stream = new CFileReader(baseDir, filename); // read the file - while ((line = stream.getReader().readLine()) != null) { + while ((line = stream.readLine()) != null) { if (!line.startsWith("#") && line.length() > 0) { line = line.trim(); // remove whitespace at both ends Modified: trunk/crossfire/src/cfeditor/CFArchTypeList.java =================================================================== --- trunk/crossfire/src/cfeditor/CFArchTypeList.java 2006-09-12 20:50:47 UTC (rev 327) +++ trunk/crossfire/src/cfeditor/CFArchTypeList.java 2006-09-13 01:44:31 UTC (rev 328) @@ -78,7 +78,6 @@ CFArchTypeList() { CFArchType cfType = head; // index of CFArchType list final boolean headLoaded = false; // true when the default type (=head) is loaded - CFileReader fread = null; // file reader for "types.txt" // initialize the arrays of "special-data" bitmaskTable = new HashMap(); @@ -90,111 +89,115 @@ try { // open ascii filestream to the xml data final String baseDir = IGUIConstants.CONFIG_DIR; - fread = new CFileReader(baseDir, IGUIConstants.TYPEDEF_FILE); + final CFileReader fread = new CFileReader(baseDir, IGUIConstants.TYPEDEF_FILE); + try { - // parse xml document - final SAXBuilder builder = new SAXBuilder(); - builder.setValidation(true); - final Document doc = builder.build(fread.getReader()); + // parse xml document + final SAXBuilder builder = new SAXBuilder(); + builder.setValidation(true); + final Document doc = builder.build(fread); - // start parsing the xml - final Element root = doc.getRootElement(); - Element elem; - Attribute a; - if (root == null || !root.getName().equalsIgnoreCase("types")) { - LOG.warn("File '" + IGUIConstants.TYPEDEF_FILE + "' lacks root element 'types'."); - } else { - List children; - // parse all bitmask elements - children = root.getChildren("bitmask"); - for (int i = 0; children != null && i < children.size(); i++) { - elem = (Element) children.get(i); - if (elem.getAttribute("name") == null) { - LOG.warn("In file '" + IGUIConstants.TYPEDEF_FILE + "': cannot load bitmask element without 'name'."); - } else { - bitmaskTable.put(elem.getAttribute("name").getValue(), new CAttribBitmask(elem)); + // start parsing the xml + final Element root = doc.getRootElement(); + Element elem; + Attribute a; + if (root == null || !root.getName().equalsIgnoreCase("types")) { + LOG.warn("File '" + IGUIConstants.TYPEDEF_FILE + "' lacks root element 'types'."); + } else { + List children; + // parse all bitmask elements + children = root.getChildren("bitmask"); + for (int i = 0; children != null && i < children.size(); i++) { + elem = (Element) children.get(i); + if (elem.getAttribute("name") == null) { + LOG.warn("In file '" + IGUIConstants.TYPEDEF_FILE + "': cannot load bitmask element without 'name'."); + } else { + bitmaskTable.put(elem.getAttribute("name").getValue(), new CAttribBitmask(elem)); + } } - } - // parse all list elements - children = root.getChildren("list"); - for (int i = 0; children != null && i < children.size(); i++) { - elem = (Element) children.get(i); - if (elem.getAttribute("name") == null) { - LOG.warn("In file '" + IGUIConstants.TYPEDEF_FILE + "': cannot load list element without 'name'."); - } else { - final Vector list = parseListFromElement(elem); - if (list != null && list.size() > 0) { - listTable.put(elem.getAttribute("name").getValue(), list); + // parse all list elements + children = root.getChildren("list"); + for (int i = 0; children != null && i < children.size(); i++) { + elem = (Element) children.get(i); + if (elem.getAttribute("name") == null) { + LOG.warn("In file '" + IGUIConstants.TYPEDEF_FILE + "': cannot load list element without 'name'."); + } else { + final Vector list = parseListFromElement(elem); + if (list != null && list.size() > 0) { + listTable.put(elem.getAttribute("name").getValue(), list); + } } } - } - // parse default type - elem = root.getChild("default_type"); - if (elem == null) { - LOG.warn("In file '" + IGUIConstants.TYPEDEF_FILE + "': default_type element is missing!"); - } else { - // create a new CFArchType element - final CFArchType newType = new CFArchType(head); + // parse default type + elem = root.getChild("default_type"); + if (elem == null) { + LOG.warn("In file '" + IGUIConstants.TYPEDEF_FILE + "': default_type element is missing!"); + } else { + // create a new CFArchType element + final CFArchType newType = new CFArchType(head); - // attach the new CFArchType element to the list - // if we manage to parse it properly from the file - if (head.load(elem, this)) { - cfType = head; - //length++; // our list is now one element longer + // attach the new CFArchType element to the list + // if we manage to parse it properly from the file + if (head.load(elem, this)) { + cfType = head; + //length++; // our list is now one element longer + } } - } - // parse ignore lists - children = root.getChildren("ignore_list"); - for (int i = 0; children != null && i < children.size(); i++) { - elem = (Element) children.get(i); - if (elem.getAttribute("name") == null) { - LOG.warn("In file '" + IGUIConstants.TYPEDEF_FILE + "': cannot load ignore_list element without 'name'."); - } else { - final String lname = elem.getAttribute("name").getValue().trim(); - final List children2 = elem.getChildren(CFArchType.XML_ATTRIBUTE); - if (children2 != null && children2.size() > 0) { - // load all attribute entries - final Vector content = new Vector(); - for (int k = 0; k < children2.size(); k++) { - elem = (Element) children2.get(k); - if ((a = elem.getAttribute(CFArchAttrib.XML_KEY_ARCH)) != null) { - content.addElement(a.getValue().trim()); - } else { - LOG.warn("In file '" + IGUIConstants.TYPEDEF_FILE + "': ignore_list '" + lname + "' has " + CFArchType.XML_ATTRIBUTE + " missing '" + CFArchAttrib.XML_KEY_ARCH + "'."); + // parse ignore lists + children = root.getChildren("ignore_list"); + for (int i = 0; children != null && i < children.size(); i++) { + elem = (Element) children.get(i); + if (elem.getAttribute("name") == null) { + LOG.warn("In file '" + IGUIConstants.TYPEDEF_FILE + "': cannot load ignore_list element without 'name'."); + } else { + final String lname = elem.getAttribute("name").getValue().trim(); + final List children2 = elem.getChildren(CFArchType.XML_ATTRIBUTE); + if (children2 != null && children2.size() > 0) { + // load all attribute entries + final Vector content = new Vector(); + for (int k = 0; k < children2.size(); k++) { + elem = (Element) children2.get(k); + if ((a = elem.getAttribute(CFArchAttrib.XML_KEY_ARCH)) != null) { + content.addElement(a.getValue().trim()); + } else { + LOG.warn("In file '" + IGUIConstants.TYPEDEF_FILE + "': ignore_list '" + lname + "' has " + CFArchType.XML_ATTRIBUTE + " missing '" + CFArchAttrib.XML_KEY_ARCH + "'."); + } } + // now add the list vector to the ignoreListTable: + ignoreListTable.put(lname, content); } - // now add the list vector to the ignoreListTable: - ignoreListTable.put(lname, content); } } - } - // parse all type elements - children = root.getChildren("type"); - for (int i = 0; children != null && i < children.size(); i++) { - elem = (Element) children.get(i); - if (elem.getAttribute("name") == null || elem.getAttribute("number") == null) { - LOG.warn("In file '" + IGUIConstants.TYPEDEF_FILE + "': found type element without 'name' or 'number'."); - } else { - // create a new CFArchType element - final CFArchType newType = new CFArchType(head); + // parse all type elements + children = root.getChildren("type"); + for (int i = 0; children != null && i < children.size(); i++) { + elem = (Element) children.get(i); + if (elem.getAttribute("name") == null || elem.getAttribute("number") == null) { + LOG.warn("In file '" + IGUIConstants.TYPEDEF_FILE + "': found type element without 'name' or 'number'."); + } else { + // create a new CFArchType element + final CFArchType newType = new CFArchType(head); - // attach the new CFArchType element to the list - // if we manage to parse it properly from the file - if (newType.load(elem, this)) { - cfType.setNext(newType); - cfType = cfType.getNext(); - length++; // our list is now one element longer + // attach the new CFArchType element to the list + // if we manage to parse it properly from the file + if (newType.load(elem, this)) { + cfType.setNext(newType); + cfType = cfType.getNext(); + length++; // our list is now one element longer + } } } - } - if (LOG.isInfoEnabled()) { - LOG.info("Loaded " + length + " types from '" + IGUIConstants.TYPEDEF_FILE + "'"); + if (LOG.isInfoEnabled()) { + LOG.info("Loaded " + length + " types from '" + IGUIConstants.TYPEDEF_FILE + "'"); + } } + } finally { + fread.close(); } } catch (JDOMException e) { LOG.error("Parsing error in '" + IGUIConstants.TYPEDEF_FILE, e); @@ -202,10 +205,6 @@ LOG.error("Cannot read file '" + IGUIConstants.TYPEDEF_FILE + "'!", e); } - // close data stream - if (fread != null) { - fread.close(); - } ignoreListTable = null; // this was only needed during load phase } @@ -284,77 +283,76 @@ public void loadSpellsFromXML() { spellName = null; spellNum = null; - CFileReader reader = null; // input reader final int spnum = 0; // number of spells try { // open reading stream to the spells xml file final String baseDir = IGUIConstants.CONFIG_DIR; - reader = new CFileReader(baseDir, IGUIConstants.SPELL_FILE); + final CFileReader reader = new CFileReader(baseDir, IGUIConstants.SPELL_FILE); + try { + // parse xml document + final SAXBuilder builder = new SAXBuilder(); + final Document doc = builder.build(reader); - // parse xml document - final SAXBuilder builder = new SAXBuilder(); - final Document doc = builder.build(reader.getReader()); - - // retrieve the spell data from the xml - final Element root = doc.getRootElement(); - Element spellElem; - Attribute a; - if (root == null || !root.getName().equalsIgnoreCase("spells")) { - LOG.warn("File '" + IGUIConstants.SPELL_FILE + "' lacks root element 'spells'."); - } else { - final List spells = root.getChildren("spell"); - if (spells == null || spells.size() == 0) { - LOG.warn("File '" + IGUIConstants.SPELL_FILE + "' has no content."); + // retrieve the spell data from the xml + final Element root = doc.getRootElement(); + Element spellElem; + Attribute a; + if (root == null || !root.getName().equalsIgnoreCase("spells")) { + LOG.warn("File '" + IGUIConstants.SPELL_FILE + "' lacks root element 'spells'."); } else { - // initialize array with appropriate size - spellName = new String[spells.size() + 1]; - spellNum = new int[spells.size() + 1]; + final List spells = root.getChildren("spell"); + if (spells == null || spells.size() == 0) { + LOG.warn("File '" + IGUIConstants.SPELL_FILE + "' has no content."); + } else { + // initialize array with appropriate size + spellName = new String[spells.size() + 1]; + spellNum = new int[spells.size() + 1]; - // first element is <none> - spellName[0] = " <none>"; - spellNum[0] = -1; + // first element is <none> + spellName[0] = " <none>"; + spellNum[0] = -1; - int i; - int j; - for (j = 0, i = 1; j < spells.size(); j++) { - spellElem = (Element) spells.get(j); + int i; + int j; + for (j = 0, i = 1; j < spells.size(); j++) { + spellElem = (Element) spells.get(j); - if (spellElem.getAttribute("id") == null) { - LOG.warn("In File '" + IGUIConstants.SPELL_FILE + "': Found 'spell' element without 'id'"); - } else if (spellElem.getAttribute("name") == null) { - LOG.warn("In File '" + IGUIConstants.SPELL_FILE + "': Found 'spell' element without 'name'"); - } else { - try { - // parse spell number and -name - spellNum[i] = spellElem.getAttribute("id").getIntValue(); - spellName[i] = spellElem.getAttribute("name").getValue().trim(); - i++; - } catch (DataConversionException de) { - LOG.error("in '" + IGUIConstants.SPELL_FILE + "': spell id '" + spellElem.getAttribute("id").getValue() + "' is not an integer."); + if (spellElem.getAttribute("id") == null) { + LOG.warn("In File '" + IGUIConstants.SPELL_FILE + "': Found 'spell' element without 'id'"); + } else if (spellElem.getAttribute("name") == null) { + LOG.warn("In File '" + IGUIConstants.SPELL_FILE + "': Found 'spell' element without 'name'"); + } else { + try { + // parse spell number and -name + spellNum[i] = spellElem.getAttribute("id").getIntValue(); + spellName[i] = spellElem.getAttribute("name").getValue().trim(); + i++; + } catch (DataConversionException de) { + LOG.error("in '" + IGUIConstants.SPELL_FILE + "': spell id '" + spellElem.getAttribute("id").getValue() + "' is not an integer."); + } } } - } - // loading successful - i--; - if (LOG.isInfoEnabled()) { - if (i == spells.size()) { - LOG.info("Loaded " + i + " spells from '" + IGUIConstants.SPELL_FILE + "'"); - } else { - LOG.info("Loaded " + i + " of " + spells.size() + " defined spells from '" + IGUIConstants.SPELL_FILE + "'"); + // loading successful + i--; + if (LOG.isInfoEnabled()) { + if (i == spells.size()) { + LOG.info("Loaded " + i + " spells from '" + IGUIConstants.SPELL_FILE + "'"); + } else { + LOG.info("Loaded " + i + " of " + spells.size() + " defined spells from '" + IGUIConstants.SPELL_FILE + "'"); + } } } } + } finally { + reader.close(); } } catch (JDOMException e) { LOG.error("Parsing error in '" + IGUIConstants.SPELL_FILE + "'", e); } catch (IOException e) { LOG.error("Cannot read file '" + IGUIConstants.SPELL_FILE + "'!"); } - if (reader != null) { - reader.close(); - } } /** Modified: trunk/crossfire/src/cfeditor/CFTreasureListTree.java =================================================================== --- trunk/crossfire/src/cfeditor/CFTreasureListTree.java 2006-09-12 20:50:47 UTC (rev 327) +++ trunk/crossfire/src/cfeditor/CFTreasureListTree.java 2006-09-13 01:44:31 UTC (rev 328) @@ -252,7 +252,7 @@ // read the whole file line by line TreasureTreeNode node = null; - while ((line = reader.getReader().readLine()) != null) { + while ((line = reader.readLine()) != null) { line = line.trim(); if (line.length() > 0 && !line.startsWith("#")) { // reading outside of treasurelist @@ -265,7 +265,7 @@ tListCount++; // read this treasurelist till the very end - readInsideList(node, reader.getReader(), needLink); + readInsideList(node, reader, needLink); } else { errorLog.append("After treasurelist " + node.getTreasureObj().getName() + ": unexpected line:\n\"" + line + "\"\n"); Modified: trunk/crossfire/src/cfeditor/CFileInputStream.java =================================================================== --- trunk/crossfire/src/cfeditor/CFileInputStream.java 2006-09-12 20:50:47 UTC (rev 327) +++ trunk/crossfire/src/cfeditor/CFileInputStream.java 2006-09-13 01:44:31 UTC (rev 328) @@ -2,6 +2,7 @@ * Crossfire 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) * @@ -24,126 +25,98 @@ package cfeditor; +import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.IOException; import java.io.InputStream; -import org.apache.log4j.Logger; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * Class for opening and reading a buffered stream to a BINARY resource-file. * If no such file is found, the file is loaded from the jar archive. * This class is very similar to {@link CFileReader}. + * The file is tried to open in the following order: + * <ol> + * <li>Try opening it with the given directory. The directory path is relative + * to the current working directory, the file path relative to that + * directory..</li> + * <li>Try opening it without the given directory. The file path is relative to + * the current working directory.</li> + * <li>Try opening the file as a system resource through the class loader.</li> + * </ol> + * Only if all tries failed, creating the stream fails. * @author <a href="mailto:and...@gm...">Andreas Vogl</a> + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @see CFileReader */ -public final class CFileInputStream { +public final class CFileInputStream extends BufferedInputStream { - private static final Logger LOG = Logger.getLogger(CFileInputStream.class); - - private final String filename; // name of the resource file - - private final String filedir; // directory of the resource file - - private boolean isBinfile = false; // true if the resource was opened as binary file - - private boolean isJar = false; // true if resource was opened from jar archive - - // streams - private FileInputStream fileInput; // binary file input stream - - private InputStream inStream; // basic binary input stream - - private TrackedBufferedInputStream stream; // buffered stream - /** - * Constructor: Open a byte-stream to the specified resource file. - * @param dname name of directory that the file is in - * (null means the file is located in the editor root dir) + * Creates a new CFileInputStream to a specified resource file. + * @param dname name of directory that the file is in (<code>null</code> + * means the file is located in the editor root dir) * @param fname name of the resource file + * @throws FileNotFoundException In case all three tries to open the file failed */ - public CFileInputStream(final String dname, final String fname) throws FileNotFoundException { - filename = fname; - filedir = dname; - fileInput = null; - inStream = null; - stream = null; - - // now try to open the file - open(); + public CFileInputStream(@Nullable final String dname, @NotNull final String fname) throws FileNotFoundException { + super(createStream(dname, fname)); } - /** open the resource file for reading */ - private void open() throws FileNotFoundException { - try { - // first we look if the resource is available as normal binary-file - // in the specified directory - fileInput = new FileInputStream(filedir + File.separator + filename); - stream = new TrackedBufferedInputStream(fileInput); - isBinfile = true; - } catch (final FileNotFoundException e) { - try { - // second we look if the resource is available as normal binary-file - // in the editor's root directory - fileInput = new FileInputStream(filename); - stream = new TrackedBufferedInputStream(fileInput); - isBinfile = true; - } catch (final FileNotFoundException ex) { - // if there is no binary file at all, we try to load it from - // the system-jar-archive: - inStream = ClassLoader.getSystemResourceAsStream(filename); - if (inStream != null) { - stream = new TrackedBufferedInputStream(inStream); - isJar = true; - } - } + /** + * Open the resource file for reading. + * @param dname directory name to read from + * @param fname file name of file to read + * @return Stream for reading from <var>fname</var> + * @throws FileNotFoundException In case all tries to open the file failed + */ + @SuppressWarnings({"MethodWithMultipleReturnPoints", "MethodWithMoreThanThreeNegations"}) + @NotNull private static InputStream createStream(@Nullable final String dname, @NotNull final String fname) throws FileNotFoundException { + try { // 1st try normal binary file relative to specified directory + return new FileInputStream(new File(dname, fname)); + } catch (final Exception e) { + // ignore } - - if (!isBinfile && !isJar) { - if (LOG.isInfoEnabled()) { - LOG.info("File \"" + filename + "\" was not found!"); + try { // 2nd try binary file relative to user's current working directory + return new FileInputStream(fname); + } catch (final Exception e) { // 3rd try via system resource from class loader + // ignore + } + final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); + try { // 3rd try context class loader relative to specified directory + @Nullable final InputStream stream = contextClassLoader.getResourceAsStream(new File(dname, fname).toURL().toURI().toString()); + if (stream != null) { + return stream; } - throw new FileNotFoundException(); + } catch (final Exception e) { + // ignore } - } - - /** @return <code>BufferedInputStream</code> to the resource file */ - public TrackedBufferedInputStream getBufferedStream() { - return stream; - } - - /** - * Read one byte from the stream - * (Wrapper method for <code>BufferedInputStream.read()</code>) - * @return one read byte-character - */ - public int read() throws IOException { - return stream.read(); - } - - /** close all open streams, print errormessages if closing failed */ - public void close() { - if (stream != null) { - try { - stream.close(); - } catch (final IOException e) { - LOG.warn("Couldn't close BufferedInputStream for \"" + filename + "\"."); + try { // 4th try context class loader relative to class loader's top level directory + @Nullable final InputStream stream = contextClassLoader.getResourceAsStream(new File(fname).toURL().toURI().toString()); + if (stream != null) { + return stream; } + } catch (final Exception e) { + // ignore } - if (inStream != null) { - try { - inStream.close(); - } catch (final IOException e) { - LOG.warn("Couldn't close InputStream for \"" + filename + "\"."); + try { // 5th try system class loader relative to specified directory + @Nullable final InputStream stream = ClassLoader.getSystemResourceAsStream(new File(dname, fname).toURL().toURI().toString()); + if (stream != null) { + return stream; } + } catch (final Exception e) { + // ignore } - if (fileInput != null) { - try { - fileInput.close(); - } catch (final IOException e) { - LOG.warn("Couldn't close FileInputStream for \"" + filename + "\"."); + try { // 6th try system class loader relative to class loader's top level directory + @Nullable final InputStream stream = ClassLoader.getSystemResourceAsStream(new File(fname).toURL().toURI().toString()); + if (stream != null) { + return stream; } + } catch (final Exception e) { + // ignore } + throw new FileNotFoundException("CFileInputStream couldn't find " + new File(dname, fname) + "."); } } // class CFileInputStream Modified: trunk/crossfire/src/cfeditor/CFileReader.java =================================================================== --- trunk/crossfire/src/cfeditor/CFileReader.java 2006-09-12 20:50:47 UTC (rev 327) +++ trunk/crossfire/src/cfeditor/CFileReader.java 2006-09-13 01:44:31 UTC (rev 328) @@ -2,6 +2,7 @@ * Crossfire 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) * @@ -26,40 +27,31 @@ import java.io.BufferedReader; import java.io.EOFException; -import java.io.File; import java.io.FileNotFoundException; -import java.io.FileReader; import java.io.IOException; -import java.io.InputStream; import java.io.InputStreamReader; -import org.apache.log4j.Logger; +import java.io.Reader; +import java.io.UnsupportedEncodingException; /** * Class for opening and reading a buffered stream to an ASCII resource-file. * If no such file is found, the file is loaded from the jar archive. + * This class is very similar to {@link CFileInputStream}. + * The file is tried to open in the following order: + * <ol> + * <li>Try opening it with the given directory. The directory path is relative to the current working directory, the file path relative to that + * directory..</li> + * <li>Try opening it without the given directory. The file path is relative to the current working directory.</li> + * <li>Try opening the file as a system resource through the class loader.</li> + * </ol> + * Only if all tries failed, creating the stream fails. * @author <a href="mailto:and...@gm...">Andreas Vogl</a> + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @todo eventually remove readUntil - this is afaik only used for reading arches and such, and since there should be an integrated arch editor... + * @see CFileInputStream */ -public final class CFileReader { +public final class CFileReader extends BufferedReader { - private static final Logger LOG = Logger.getLogger(CFileReader.class); - - private final String filename; // name of the resource file - - private final String filedir; // directory of the resource file - - private boolean isAscii = false; // true if the resource was opened as ascii file - - private boolean isJar = false; // true if resource was opened from jar archive - - // streams - private FileReader fileRead; - - private InputStream inStream; - - private InputStreamReader streamRead; - - private BufferedReader read; - /** Maximum number of characters to read in readUntil. */ private static final long READ_MAX = 10000L; @@ -70,58 +62,24 @@ * @throws FileNotFoundException in case all three tries to open the file failed */ public CFileReader(final String dname, final String fname) throws FileNotFoundException { - filename = fname; - filedir = dname; - fileRead = null; - inStream = null; - streamRead = null; - read = null; - - // now try to open the file - open(); + super(createReader(dname, fname)); } - /** open the resource file for reading */ - private void open() throws FileNotFoundException { + /** + * Open the resource file for reading. + * @param dname name of directory that the file is in (null means the file is located in the editor root dir) + * @param fname name of the resource file + * @return Stream for reading from <var>fname</var> + * @throws FileNotFoundException In case all three tries to open the file failed + */ + private static Reader createReader(final String dname, final String fname) throws FileNotFoundException { try { - // first we look if the resource is available as normal ascii-file - // in the specified directory - fileRead = new FileReader(filedir + File.separator + filename); - isAscii = true; - } catch (final FileNotFoundException e) { - try { - // second we look if the resource is available as normal ascii-file - // in the editor's root directory - fileRead = new FileReader(filename); - isAscii = true; - } catch (final FileNotFoundException ex) { - // if there is no ascii file at all, we try to load it from - // the system-jar-archive: - inStream = ClassLoader.getSystemResourceAsStream(filename); - if (inStream != null) { - streamRead = new InputStreamReader(inStream); - isJar = true; - } - } + return new InputStreamReader(new CFileInputStream(dname, fname), CMainControl.MAP_ENCODING); + } catch (final UnsupportedEncodingException e) { + throw new Error(e); } - - if (isAscii) { - read = new BufferedReader(fileRead); - } else if (isJar) { - read = new BufferedReader(streamRead); - } else { - if (LOG.isInfoEnabled()) { - LOG.info("File \"" + filename + "\" was not found!"); - } - throw new FileNotFoundException(); - } } - /** @return <code>BufferedReader</code> to the resource file */ - public BufferedReader getReader() { - return read; - } - /** * Reads characters from the BufferedReader stream till 'tag' is found. If * found, the method returns with stream pointing right after the @@ -216,46 +174,4 @@ return sb.substring(0, sb.length() - tag.length()); } - // wrapper method for readUntil, using BufferReader from 'this' - public void readUntil(final String tag, final String abort) throws IOException { - readUntil(read, tag, abort); - } - - // wrapper method for readUntil, using BufferReader from 'this' - public String readUntil(final String tag) throws IOException { - return readUntil(read, tag); - } - - /** close all open streams, print errormessages if closing failed */ - public void close() { - if (read != null) { - try { - read.close(); - } catch (final IOException e) { - LOG.warn("Couldn't close BufferedReader for \"" + filename + "\".", e); - } - } - if (fileRead != null) { - try { - fileRead.close(); - } catch (IOException e) { - LOG.warn("Couldn't close FileReader for \"" + filename + "\".", e); - } - } - if (streamRead != null) { - try { - streamRead.close(); - } catch (final IOException e) { - LOG.warn("Couldn't close InputStreamReader for \"" + filename + "\".", e); - } - } - if (inStream != null) { - try { - inStream.close(); - } catch (final IOException e) { - LOG.warn("Couldn't close InputStream for \"" + filename + "\".", e); - } - } - } - } // class CFileReader Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-09-12 20:50:47 UTC (rev 327) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-09-13 01:44:31 UTC (rev 328) @@ -80,8 +80,18 @@ /** Logger. */ private static final Logger log = Logger.getLogger(CMainControl.class); - private static CMainControl instance = null; + /** Singleton instance reference. */ + private static CMainControl instance; + /** + * Encoding to use for maps and other data. + * The encoding given here is used for reading and writing maps. + * You shouldn't change this only because you use an UTF-8 system or so, since the encoding used here MUST be compatible with the server and the + * client. The paragraph sign § is the critical character. + * @todo once the mailing list decided on the § character, eventually replace by "us-ascii". + */ + public static final String MAP_ENCODING = "iso-8859-1"; + public static final String DOCU_VERSION_KEY = "docuVersion"; public static final String MAP_DIR_KEY = "mapDirectory"; Modified: trunk/crossfire/src/cfeditor/FaceObject.java =================================================================== --- trunk/crossfire/src/cfeditor/FaceObject.java 2006-09-12 20:50:47 UTC (rev 327) +++ trunk/crossfire/src/cfeditor/FaceObject.java 2006-09-13 01:44:31 UTC (rev 328) @@ -98,12 +98,11 @@ log.debug("Lazy loading " + name); } final CFileInputStream fi = new CFileInputStream(ressourceDirectory, ressourceName); - final BufferedInputStream bis = fi.getBufferedStream(); if (dataStartIndex > 0) { - bis.skip(dataStartIndex); + fi.skip(dataStartIndex); } final byte[] data = new byte[dataSize]; - bis.read(data); + fi.read(data); final PngImage png = new PngImage(new ByteArrayInputStream(data)); // read png data from bytestream png.setFlushAfterNextProduction(true); final ImageIcon im = new ImageIcon(Toolkit.getDefaultToolkit().createImage(png)); Modified: trunk/crossfire/src/cfeditor/MultiPositionData.java =================================================================== --- trunk/crossfire/src/cfeditor/MultiPositionData.java 2006-09-12 20:50:47 UTC (rev 327) +++ trunk/crossfire/src/cfeditor/MultiPositionData.java 2006-09-13 01:44:31 UTC (rev 328) @@ -82,7 +82,7 @@ int yp = 0; // y-index in the data array // read the whole file line by line - while ((line = reader.getReader().readLine()) != null) { + while ((line = reader.readLine()) != null) { line = line.trim(); if (line.length() > 0 && !line.startsWith("#") && yp < Y_DIM) { final StringTokenizer s = new StringTokenizer(line, " ", false); Deleted: trunk/crossfire/src/cfeditor/TrackedBufferedInputStream.java =================================================================== --- trunk/crossfire/src/cfeditor/TrackedBufferedInputStream.java 2006-09-12 20:50:47 UTC (rev 327) +++ trunk/crossfire/src/cfeditor/TrackedBufferedInputStream.java 2006-09-13 01:44:31 UTC (rev 328) @@ -1,94 +0,0 @@ -/* - * Created on 12 janv. 2005 - * - * TODO To change the template for this generated file go to - * Window - Preferences - Java - Code Style - Code Templates - */ - -package cfeditor; - -import java.io.BufferedInputStream; -import java.io.IOException; -import java.io.InputStream; -import org.apache.log4j.Logger; - -/** - * A BufferedInputStream that keeps track of its current position. - * @author tchize - */ -public final class TrackedBufferedInputStream extends BufferedInputStream { - - private static final Logger log = Logger.getLogger(TrackedBufferedInputStream.class); - - private long position = 0; - - private long lastPosition = -1; - - public TrackedBufferedInputStream(final InputStream stream) { - super(stream); - } - - public TrackedBufferedInputStream(final InputStream stream, final int size) { - super(stream, size); - } - - /* (non-Javadoc) - * @see java.io.InputStream#mark(int) - */ - @Override public synchronized void mark(final int max) { - // TODO Auto-generated method stub - super.mark(max); - lastPosition = position; - } - - /* (non-Javadoc) - * @see java.io.InputStream#read() - */ - @Override public synchronized int read() throws IOException { - // TODO Auto-generated method stub - final int result = super.read(); - if (result >= 0) { - position++; - } - return result; - } - - /* (non-Javadoc) - * @see java.io.InputStream#read(byte[], int, int) - */ - @Override public synchronized int read(final byte[] data, final int offset, final int length) - throws IOException { - // TODO Auto-generated method stub - final int result = super.read(data, offset, length); - if (result > 0) { - position += result; - } - return result; - } - - /* (non-Javadoc) - * @see java.io.InputStream#reset() - */ - @Override public synchronized void reset() throws IOException { - // TODO Auto-generated method stub - super.reset(); - position = lastPosition; - } - - /* (non-Javadoc) - * @see java.io.InputStream#skip(long) - */ - @Override public synchronized long skip(final long count) throws IOException { - // TODO Auto-generated method stub - final long realSkipped = super.skip(count); - position += realSkipped; - return realSkipped; - } - - public long getPosition() { - if (log.isDebugEnabled()) { - log.debug("getPosition : " + position); - } - return position; - } -} Modified: trunk/crossfire/src/cfeditor/arch/ArchObjectParser.java =================================================================== --- trunk/crossfire/src/cfeditor/arch/ArchObjectParser.java 2006-09-12 20:50:47 UTC (rev 327) +++ trunk/crossfire/src/cfeditor/arch/ArchObjectParser.java 2006-09-13 01:44:31 UTC (rev 328) @@ -94,7 +94,7 @@ // parse xml document final SAXBuilder builder = new SAXBuilder(); builder.setValidation(true); - final Document doc = builder.build(reader.getReader()); + final Document doc = builder.build(reader); // retrieve the spell data from the xml final Element root = doc.getRootElement(); @@ -131,8 +131,6 @@ } } } - } catch (final IOException e) { - LOG.error("Error while reading file '" + IGUIConstants.TYPENR_FILE + "'!", e); } finally { reader.close(); } @@ -140,6 +138,8 @@ LOG.error("Parsing error in '" + IGUIConstants.TYPENR_FILE + "'", e); } catch (final FileNotFoundException e) { LOG.error("Cannot read file '" + IGUIConstants.TYPENR_FILE + "'!", e); + } catch (final IOException e) { + LOG.error("Error while reading file '" + IGUIConstants.TYPENR_FILE + "'!", e); } } Modified: trunk/crossfire/src/cfeditor/arch/ArchObjectStack.java =================================================================== --- trunk/crossfire/src/cfeditor/arch/ArchObjectStack.java 2006-09-12 20:50:47 UTC (rev 327) +++ trunk/crossfire/src/cfeditor/arch/ArchObjectStack.java 2006-09-13 01:44:31 UTC (rev 328) @@ -294,18 +294,19 @@ try { // open the resource file - final String baseDir = IGUIConstants.CONFIG_DIR; - final CFileReader stream = new CFileReader(baseDir, IGUIConstants.ARCH_FILE); - - // load all arches - mainControl.getArchObjectParser().parseDefArchFromStream(stream.getReader(), 0); - - // close filestream - stream.close(); - + final CFileReader stream = new CFileReader(IGUIConstants.CONFIG_DIR, IGUIConstants.ARCH_FILE); + try { + // load all arches + mainControl.getArchObjectParser().parseDefArchFromStream(stream, 0); + } finally { + // close filestream + stream.close(); + } loadAllCrossfirePNGFromCollect(); } catch (final FileNotFoundException e) { // no need for a message here, CFileReader takes care of this + } catch (final IOException e) { + LOG.error("Error:", e); } } @@ -437,7 +438,7 @@ /** Loading all pngs from the big collected png file */ private void loadAllCrossfirePNGFromCollect() { - + int filePosition = 0; try { // open a bytestream to the resource file final String baseDir = IGUIConstants.CONFIG_DIR; @@ -457,6 +458,7 @@ for (t = 0; t < 3; t++) { do { r = stream.read(); + filePosition++; } while (r != -1 && (char) r != ' '); } @@ -466,6 +468,7 @@ do { while ((c != '.' || face.length() < 3) && r != -1) { r = stream.read(); + filePosition++; c = (char) r; face += String.valueOf(c); } @@ -474,8 +477,10 @@ if (r != -1) { for (t = 0; t < 3; t++) { face += String.valueOf((char) stream.read()); + filePosition++; } final char l = (char) stream.read(); + filePosition++; if (face.indexOf("/") >= 0) { face = face.substring(face.lastIndexOf("/") + 1); @@ -500,11 +505,12 @@ if (r != -1) { // now we try to figure the size of the png data in byte, // later we jump back to the beginning position and read those bytes - stream.getBufferedStream().mark(100000); // mark position + stream.mark(100000); // mark position t = 0; int size = 0; do { r = stream.read(); // read one character + // don't add to filePosition because we marked and will reset. c = (char) r; size++; // count overall bytesize if (c == tag.charAt(t)) { @@ -523,10 +529,11 @@ // for all other pngs, must subtract the size of next starting tag size -= tag.length(); } - stream.getBufferedStream().reset(); // jump to beginning of png data + stream.reset(); // jump to beginning of png data - faceObjects[faceListCount] = new FaceObject(baseDir, IGUIConstants.PNG_FILE, stream.getBufferedStream().getPosition(), size); // lazy load object - stream.getBufferedStream().skip(size); + faceObjects[faceListCount] = new FaceObject(baseDir, IGUIConstants.PNG_FILE, filePosition, size); // lazy load object + stream.skip(size); + filePosition += size; // put this png into the list of faces faceObjects[faceListCount].setName(face); faceObjects[faceListCount].setPath("null"); @@ -548,13 +555,13 @@ // make sure we free all unneeded memory System.runFinalization(); System.gc(); - } catch (final IOException e) { - LOG.warn("Read error in file '" + IGUIConstants.PNG_FILE + "'.", e); } finally { stream.close(); } } catch (final FileNotFoundException e) { LOG.warn("file " + IGUIConstants.PNG_FILE + " not found!"); + } catch (final IOException e) { + LOG.warn("Read error in file '" + IGUIConstants.PNG_FILE + "'.", e); } } Modified: trunk/crossfire/src/cfeditor/textedit/scripteditor/CFPythonPopup.java =================================================================== --- trunk/crossfire/src/cfeditor/textedit/scripteditor/CFPythonPopup.java 2006-09-12 20:50:47 UTC (rev 327) +++ trunk/crossfire/src/cfeditor/textedit/scripteditor/CFPythonPopup.java 2006-09-13 01:44:31 UTC (rev 328) @@ -114,7 +114,7 @@ final CFileReader reader = new CFileReader(baseDir, IGUIConstants.PYTHONMENU_FILE); try { // read file into the cmdList vector: - for (String line; (line = reader.getReader().readLine()) != null;) { + for (String line; (line = reader.readLine()) != null;) { line = line.trim(); if (line.length() > 0 && !line.startsWith("#")) { // ATM, the descriptive info about method headers is cut out Modified: trunk/daimonin/src/daieditor/CFileInputStream.java =================================================================== --- trunk/daimonin/src/daieditor/CFileInputStream.java 2006-09-12 20:50:47 UTC (rev 327) +++ trunk/daimonin/src/daieditor/CFileInputStream.java 2006-09-13 01:44:31 UTC (rev 328) @@ -30,8 +30,6 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; -import java.net.URISyntaxException; -import java.net.MalformedURLException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -62,7 +60,7 @@ * @param fname name of the resource file * @throws FileNotFoundException In case all three tries to open the file failed */ - public CFileInputStream(final String dname, final String fname) throws FileNotFoundException { + public CFileInputStream(@Nullable final String dname, @NotNull final String fname) throws FileNotFoundException { super(createStream(dname, fname)); } @@ -71,41 +69,54 @@ * @param dname directory name to read from * @param fname file name of file to read * @return Stream for reading from <var>fname</var> - * @throws FileNotFoundException In case all three tries to open the file failed + * @throws FileNotFoundException In case all tries to open the file failed */ - @NotNull private static InputStream createStream(final String dname, final String fname) throws FileNotFoundException { + @SuppressWarnings({"MethodWithMultipleReturnPoints", "MethodWithMoreThanThreeNegations"}) + @NotNull private static InputStream createStream(@Nullable final String dname, @NotNull final String fname) throws FileNotFoundException { try { // 1st try normal binary file relative to specified directory return new FileInputStream(new File(dname, fname)); - } catch (final FileNotFoundException e) { - System.err.println(e); - try { // 2nd try binary file relative to user's current working directory - return new FileInputStream(fname); - } catch (final FileNotFoundException ex) { // 3rd try via system resource from class loader - System.err.println(ex); - @Nullable InputStream stream = null; - try { - ClassLoader.getSystemResourceAsStream(new File(fname).toURL().toURI().toString()); - } catch (final URISyntaxException e1) { - /* ignore */ - } catch (final MalformedURLException e1) { - /* ignore */ - } - if (stream == null) { - try { - stream = ClassLoader.getSystemResourceAsStream(new File(dname, fname).toURL().toURI().toString()); - } catch (final URISyntaxException e1) { - /* ignore */ - } catch (final MalformedURLException e1) { - /* ignore */ - } - } - if (stream == null) { - System.err.println("File \"" + fname + "\" was not found!"); - throw new FileNotFoundException("File \"" + fname + "\" was not found!"); - } + } catch (final Exception e) { + // ignore + } + try { // 2nd try binary file relative to user's current working directory + return new FileInputStream(fname); + } catch (final Exception e) { // 3rd try via system resource from class loader + // ignore + } + final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); + try { // 3rd try context class loader relative to specified directory + @Nullable final InputStream stream = contextClassLoader.getResourceAsStream(new File(dname, fname).toURL().toURI().toString()); + if (stream != null) { return stream; } + } catch (final Exception e) { + // ignore } + try { // 4th try context class loader relative to class loader's top level directory + @Nullable final InputStream stream = contextClassLoader.getResourceAsStream(new File(fname).toURL().toURI().toString()); + if (stream != null) { + return stream; + } + } catch (final Exception e) { + // ignore + } + try { // 5th try system class loader relative to specified directory + @Nullable final InputStream stream = ClassLoader.getSystemResourceAsStream(new File(dname, fname).toURL().toURI().toString()); + if (stream != null) { + return stream; + } + } catch (final Exception e) { + // ignore + } + try { // 6th try system class loader relative to class loader's top level directory + @Nullable final InputStream stream = ClassLoader.getSystemResourceAsStream(new File(fname).toURL().toURI().toString()); + if (stream != null) { + return stream; + } + } catch (final Exception e) { + // ignore + } + throw new FileNotFoundException("CFileInputStream couldn't find " + new File(dname, fname) + "."); } } // class CFileInputStream Modified: trunk/daimonin/src/daieditor/CFileReader.java =================================================================== --- trunk/daimonin/src/daieditor/CFileReader.java 2006-09-12 20:50:47 UTC (rev 327) +++ trunk/daimonin/src/daieditor/CFileReader.java 2006-09-13 01:44:31 UTC (rev 328) @@ -33,7 +33,6 @@ import java.io.Reader; import java.io.UnsupportedEncodingException; - /** * Class for opening and reading a buffered stream to an ASCII resource-file. * If no such file is found, the file is loaded from the jar archive. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-09-12 20:50:52
|
Revision: 327 http://svn.sourceforge.net/gridarta/?rev=327&view=rev Author: christianhujer Date: 2006-09-12 13:50:47 -0700 (Tue, 12 Sep 2006) Log Message: ----------- Unified readUntil method of CFileReader. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CFileReader.java Modified: trunk/crossfire/src/cfeditor/CFileReader.java =================================================================== --- trunk/crossfire/src/cfeditor/CFileReader.java 2006-09-12 20:24:42 UTC (rev 326) +++ trunk/crossfire/src/cfeditor/CFileReader.java 2006-09-12 20:50:47 UTC (rev 327) @@ -132,6 +132,9 @@ * @throws IOException an I/O-error occurred while reading the file * @throws EOFException the end of file was reached, or the 'abort' string * has been encountered + * @todo Should the encounter of the abort string before the tag really be + * an EOFException? That's semantically wrong, but current usage code + * relies on this :( */ public static void readUntil(final BufferedReader stream, final String tag, final String abort) throws IOException { int c; // character value, read from the stream @@ -188,7 +191,7 @@ * @throws EOFException the end of file was reached */ public static String readUntil(final BufferedReader stream, final String tag) throws IOException { - String r = ""; // returned string + final StringBuilder sb = new StringBuilder(); int c; // character value, read from the stream int t = 0; // index @@ -197,8 +200,8 @@ do { c = stream.read(); // read one character - r += String.valueOf((char) c); // add character 'c' to the string - if ((char) c == tag.charAt(t)) { + sb.append((char) c); + if (c == tag.charAt(t)) { t++; } else { t = 0; @@ -206,14 +209,11 @@ } while (t < tag.length() && c != -1 && count++ < maxCount); // if we did not find the tag, an EOFException is thrown - if (c == -1 || count++ >= maxCount) { + if (c == -1 || count >= maxCount) { throw new EOFException(); - } else { - // cut 'tag' off, at the end of the string - r = r.substring(0, r.length() - tag.length()); } - - return r; + // cut 'tag' off, at the end of the string + return sb.substring(0, sb.length() - tag.length()); } // wrapper method for readUntil, using BufferReader from 'this' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-09-12 20:24:57
|
Revision: 326 http://svn.sourceforge.net/gridarta/?rev=326&view=rev Author: christianhujer Date: 2006-09-12 13:24:42 -0700 (Tue, 12 Sep 2006) Log Message: ----------- Commented icon setting so code less depends on which editor is run. Modified Paths: -------------- trunk/crossfire/src/cfeditor/textedit/scripteditor/ScriptEditView.java trunk/daimonin/src/daieditor/textedit/scripteditor/ScriptEditView.java Modified: trunk/crossfire/src/cfeditor/textedit/scripteditor/ScriptEditView.java =================================================================== --- trunk/crossfire/src/cfeditor/textedit/scripteditor/ScriptEditView.java 2006-09-12 20:17:15 UTC (rev 325) +++ trunk/crossfire/src/cfeditor/textedit/scripteditor/ScriptEditView.java 2006-09-12 20:24:42 UTC (rev 326) @@ -23,7 +23,6 @@ package cfeditor.textedit.scripteditor; -import cfeditor.CGUIUtils; import cfeditor.textedit.textarea.JEditTextArea; import cfeditor.textedit.textarea.PythonTokenMarker; import cfeditor.textedit.textarea.SyntaxDocument; @@ -38,7 +37,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JTabbedPane; @@ -49,7 +47,7 @@ import org.jetbrains.annotations.Nullable; /** - * The Python script editor frame. This class should only exist in + * The script editor frame. This class should only exist in * ScriptEditControl. No other class should refer to it. * @author <a href="mailto:and...@gm...">Andreas Vogl</a> */ @@ -92,11 +90,11 @@ tabPane = new JTabbedPane(JTabbedPane.TOP); // init tab pane tabPane.addChangeListener(new EditTabListener(this)); - // set the window icon - final ImageIcon icon = CGUIUtils.getIcon("Script.gif"); - if (icon != null) { - setIconImage(icon.getImage()); - } +// // set the window icon +// final ImageIcon icon = CGUIUtils.getIcon("Script.gif"); +// if (icon != null) { +// setIconImage(icon.getImage()); +// } getContentPane().add(tabPane); addWindowListener(new EditWindowListener(control)); // add listener for close box Modified: trunk/daimonin/src/daieditor/textedit/scripteditor/ScriptEditView.java =================================================================== --- trunk/daimonin/src/daieditor/textedit/scripteditor/ScriptEditView.java 2006-09-12 20:17:15 UTC (rev 325) +++ trunk/daimonin/src/daieditor/textedit/scripteditor/ScriptEditView.java 2006-09-12 20:24:42 UTC (rev 326) @@ -23,7 +23,6 @@ package daieditor.textedit.scripteditor; -import daieditor.CGUIUtils; import daieditor.textedit.textarea.JEditTextArea; import daieditor.textedit.textarea.LuaTokenMarker; import daieditor.textedit.textarea.SyntaxDocument; @@ -38,7 +37,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JTabbedPane; @@ -49,7 +47,7 @@ import org.jetbrains.annotations.Nullable; /** - * The Lua script editor frame. This class should only exist in + * The script editor frame. This class should only exist in * ScriptEditControl. No other class should refer to it. * @author <a href="mailto:and...@gm...">Andreas Vogl</a> */ @@ -92,11 +90,11 @@ tabPane = new JTabbedPane(JTabbedPane.TOP); // init tab pane tabPane.addChangeListener(new EditTabListener(this)); - // set the window icon - final ImageIcon icon = CGUIUtils.getIcon("Script.gif"); - if (icon != null) { - setIconImage(icon.getImage()); - } +// // set the window icon +// final ImageIcon icon = CGUIUtils.getIcon("Script.gif"); +// if (icon != null) { +// setIconImage(icon.getImage()); +// } getContentPane().add(tabPane); addWindowListener(new EditWindowListener(control)); // add listener for close box This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-09-12 20:17:36
|
Revision: 325 http://svn.sourceforge.net/gridarta/?rev=325&view=rev Author: christianhujer Date: 2006-09-12 13:17:15 -0700 (Tue, 12 Sep 2006) Log Message: ----------- More script edit unification. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/CMainMenu.java trunk/crossfire/src/cfeditor/textedit/scripteditor/ScriptEditControl.java trunk/crossfire/src/cfeditor/textedit/scripteditor/ScriptEditMenuBar.java trunk/crossfire/src/cfeditor/textedit/scripteditor/ScriptEditView.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/textedit/scripteditor/ScriptEditControl.java trunk/daimonin/src/daieditor/textedit/scripteditor/ScriptEditMenuBar.java trunk/daimonin/src/daieditor/textedit/scripteditor/ScriptEditView.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-09-12 19:43:21 UTC (rev 324) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-09-12 20:17:15 UTC (rev 325) @@ -1659,7 +1659,6 @@ /** Notifies that the application is about to exit. */ void appExitNotify() { mainView.appExitNotify(); // notify main view - ScriptEditControl.getInstance().appExitNotify(); // notify scriptpad controller if (currentMap != null) { mainView.setMapTileList(null, -1); Modified: trunk/crossfire/src/cfeditor/CMainMenu.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainMenu.java 2006-09-12 19:43:21 UTC (rev 324) +++ trunk/crossfire/src/cfeditor/CMainMenu.java 2006-09-12 20:17:15 UTC (rev 325) @@ -541,7 +541,6 @@ mainControl.getMainView().updateStatusBarFont(); mainControl.getMainView().updateArchPanelFont(); CFTreasureListTree.getInstance().updateFont(); - ScriptEditControl.getInstance().updateGlobalFont(); } else { // update fonts mainControl.newPlainFont(JFontChooser.getDefaultFont()); @@ -553,7 +552,6 @@ mainControl.getMainView().updateStatusBarFont(); mainControl.getMainView().updateArchPanelFont(); CFTreasureListTree.getInstance().updateFont(); - ScriptEditControl.getInstance().updateGlobalFont(); // revert to default fonts mainControl.newPlainFont(null); Modified: trunk/crossfire/src/cfeditor/textedit/scripteditor/ScriptEditControl.java =================================================================== --- trunk/crossfire/src/cfeditor/textedit/scripteditor/ScriptEditControl.java 2006-09-12 19:43:21 UTC (rev 324) +++ trunk/crossfire/src/cfeditor/textedit/scripteditor/ScriptEditControl.java 2006-09-12 20:17:15 UTC (rev 325) @@ -23,9 +23,6 @@ package cfeditor.textedit.scripteditor; -import cfeditor.CMainControl; -import cfeditor.CSettings; -import cfeditor.IGUIConstants; import cfeditor.textedit.textarea.JEditTextArea; import java.io.File; import java.io.FileWriter; @@ -60,7 +57,7 @@ // default directory to store new scripts in. also used as starting dir for 'open' command private static String defaultScriptDir; - private final MainControl mainControl; // cfeditor main control (is null in stand-alone configuration!) + private final MainControl mainControl; // gridarta main control (is null in stand-alone configuration!) private final ScriptEditView view; // view (window with textareas) @@ -78,7 +75,7 @@ * called before once using this class. * @param mapDefFolder map default folder */ - public static void init(final String mapDefFolder, final CMainControl mainControl) { + public static void init(final String mapDefFolder, final MainControl mainControl) { if (instance == null) { isStandAlone = false; instance = new ScriptEditControl(mainControl); @@ -109,18 +106,13 @@ } /** - * @return instance of cfeditor main control (is null for stand-alone + * @return instance of gridarta main control (is null for stand-alone * configuration!) */ - final MainControl getMainControl() { + @Nullable final MainControl getMainControl() { return mainControl; } - /** Notifies that the application is about to exit. */ - public final void appExitNotify() { - view.appExitNotify(); // notify view - } - /** * Register last active popup. When the script pad frame is hidden, this * popup will be closed (if still open). @@ -131,7 +123,7 @@ } /** - * Open a new empty Python script document. + * Open a new empty script document. */ public final void openScriptNew() { opened.add("<>"); // this script has no filename assigned yet @@ -139,7 +131,7 @@ } /** - * Open a new empty Python script document. + * Open a new empty script document. */ public final void openScriptFile(final String pathname) { final File file = new File(pathname); @@ -169,7 +161,7 @@ // set default folder for new scripts final File baseDir = new File(defaultScriptDir); - if (baseDir != null && baseDir.exists() && baseDir.isDirectory()) { + if (baseDir.exists() && baseDir.isDirectory()) { fileChooser.setCurrentDirectory(baseDir); } @@ -202,11 +194,7 @@ } view.setVisible(false); if (isStandAlone()) { - // if running in stand-alone mode, the application gets terminated at this point - appExitNotify(); - // save settings - CSettings.getInstance(IGUIConstants.APP_NAME).saveSettings(); - System.exit(0); // exit + System.exit(0); //FIXME: replace by proper disposal } } } @@ -279,8 +267,6 @@ // set new path opened.set(tabIndex, file.getAbsolutePath()); view.setTitleAt(tabIndex, file.getName()); - - view.refreshMenuBar(); } } } @@ -358,13 +344,6 @@ } /** - * Global font has been changed, update the menu bar. - */ - public void updateGlobalFont() { - view.updateGlobalFont(); - } - - /** * Main method for testing purpose. * @param args */ @@ -372,9 +351,7 @@ init(System.getProperty("user.dir")); getInstance().openScriptNew(); getInstance().openScriptNew(); - getInstance().openScriptFile("maps\\GuildMage.py"); - - getInstance().view.refreshMenuBar(); + getInstance().openScriptFile("maps/GuildMage.py"); } /** Modified: trunk/crossfire/src/cfeditor/textedit/scripteditor/ScriptEditMenuBar.java =================================================================== --- trunk/crossfire/src/cfeditor/textedit/scripteditor/ScriptEditMenuBar.java 2006-09-12 19:43:21 UTC (rev 324) +++ trunk/crossfire/src/cfeditor/textedit/scripteditor/ScriptEditMenuBar.java 2006-09-12 20:17:15 UTC (rev 325) @@ -33,7 +33,6 @@ import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.KeyStroke; -import org.apache.log4j.Logger; /** * This class implements the MenuBar of the script editor. @@ -41,46 +40,13 @@ */ public final class ScriptEditMenuBar extends JMenuBar { - private static final Logger log = Logger.getLogger(ScriptEditMenuBar.class); - /** Serial Version UID. */ private static final long serialVersionUID = 1L; private final ScriptEditControl control; // controler object - // File menu: - private JMenu menuFile; - - private JMenuItem miNew; - - private JMenuItem miOpen; - - private JMenuItem miSaveAs; - private JMenuItem miSave; - private JMenuItem miClose; - - private JMenuItem miCloseAll; - - // Edit menu: - private JMenu menuEdit; - - private JMenuItem miCut; - - private JMenuItem miCopy; - - private JMenuItem miPaste; - - private JMenuItem miFind; - - // Edit menu: - private JMenu menuSettings; - - private JMenuItem miFont; - - private JMenuItem miColors; - /** * Constructor - Builds the MenuBar. * @param control @@ -89,7 +55,6 @@ this.control = control; // reference to ScriptEditControl control buildFileMenu(); buildEditMenu(); - buildSettingsMenu(); refresh(); } @@ -97,9 +62,9 @@ * Build File menu. */ private void buildFileMenu() { - menuFile = new JMenu("File"); + final JMenu menuFile = new JMenu("File"); - miNew = new JMenuItem("New Script"); + final JMenuItem miNew = new JMenuItem("New Script"); miNew.setMnemonic('N'); miNew.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent event) { @@ -109,7 +74,7 @@ }); menuFile.add(miNew); - miOpen = new JMenuItem("Open"); + final JMenuItem miOpen = new JMenuItem("Open"); miOpen.setMnemonic('O'); miOpen.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent event) { @@ -121,7 +86,7 @@ menuFile.addSeparator(); // ------ - miSaveAs = new JMenuItem("Save As..."); + final JMenuItem miSaveAs = new JMenuItem("Save As..."); //miSaveAs.setIcon(CGUIUtils.getIcon(IGUIConstants.SAVE_LEVEL_SMALLICON)); miSaveAs.setMnemonic('v'); miSaveAs.addActionListener(new ActionListener() { @@ -146,7 +111,7 @@ menuFile.addSeparator(); // ------ - miClose = new JMenuItem("Close"); + final JMenuItem miClose = new JMenuItem("Close"); miClose.setMnemonic('C'); miClose.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, Event.CTRL_MASK)); miClose.addActionListener(new ActionListener() { @@ -157,7 +122,7 @@ }); menuFile.add(miClose); - miCloseAll = new JMenuItem("Close All"); + final JMenuItem miCloseAll = new JMenuItem("Close All"); miCloseAll.setMnemonic('l'); miCloseAll.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent event) { @@ -174,9 +139,9 @@ * Build Edit Menu. */ private void buildEditMenu() { - menuEdit = new JMenu("Edit"); + final JMenu menuEdit = new JMenu("Edit"); - miCut = new JMenuItem("Cut"); + final JMenuItem miCut = new JMenuItem("Cut"); miCut.setMnemonic('t'); miCut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, Event.CTRL_MASK)); miCut.addActionListener(new ActionListener() { @@ -190,7 +155,7 @@ }); menuEdit.add(miCut); - miCopy = new JMenuItem("Copy"); + final JMenuItem miCopy = new JMenuItem("Copy"); miCopy.setMnemonic('C'); miCopy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, Event.CTRL_MASK)); miCopy.addActionListener(new ActionListener() { @@ -204,7 +169,7 @@ }); menuEdit.add(miCopy); - miPaste = new JMenuItem("Paste"); + final JMenuItem miPaste = new JMenuItem("Paste"); miPaste.setMnemonic('P'); miPaste.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, Event.CTRL_MASK)); miPaste.addActionListener(new ActionListener() { @@ -218,98 +183,15 @@ }); menuEdit.add(miPaste); - menuEdit.addSeparator(); // ------ - - miFind = new JMenuItem("Find"); - miFind.setMnemonic('F'); - miFind.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, Event.CTRL_MASK)); - miFind.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent event) { - // find - if (log.isInfoEnabled()) { - log.info("find..."); - } - } - }); - menuEdit.add(miFind); - add(menuEdit); } /** - * Build Edit Menu. - */ - private void buildSettingsMenu() { - menuSettings = new JMenu("Settings"); - - miFont = new JMenuItem("Font"); - miFont.setMnemonic('F'); - miFont.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent event) { - // set font - } - }); - menuSettings.add(miFont); - - miColors = new JMenuItem("Colors"); - miColors.setMnemonic('C'); - miColors.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent event) { - // set colors - } - }); - menuSettings.add(miColors); - - add(menuSettings); - } - - /** * Refreshes the enable/disable state of all menus. */ public final void refresh() { - miFind.setEnabled(false); - miColors.setEnabled(false); - miFont.setEnabled(false); - // see if there is a path for direct 'save' miSave.setEnabled(control.getActiveFilePath() != null); } - /** - * Redraws the whole menu with latest custom fonts. - * @param doRedraw if true, menu is redrawn at the end - */ - public void updateFont(final boolean doRedraw) { - if (!control.isStandAlone()) { - // File menu: - control.getMainControl().setBoldFont(menuFile); - control.getMainControl().setBoldFont(miNew); - control.getMainControl().setBoldFont(miOpen); - control.getMainControl().setBoldFont(miSaveAs); - control.getMainControl().setBoldFont(miSave); - control.getMainControl().setBoldFont(miClose); - control.getMainControl().setBoldFont(miCloseAll); - - // Edit menu: - control.getMainControl().setBoldFont(menuEdit); - control.getMainControl().setBoldFont(miCut); - control.getMainControl().setBoldFont(miCopy); - control.getMainControl().setBoldFont(miPaste); - control.getMainControl().setBoldFont(miFind); - - // Edit menu: - control.getMainControl().setBoldFont(menuSettings); - control.getMainControl().setBoldFont(miFont); - control.getMainControl().setBoldFont(miColors); - } - - if (doRedraw) { - // redraw the menu bar - refresh(); - if (getGraphics() != null) { - update(getGraphics()); - } - } - } - } // class ScriptEditMenuBar Modified: trunk/crossfire/src/cfeditor/textedit/scripteditor/ScriptEditView.java =================================================================== --- trunk/crossfire/src/cfeditor/textedit/scripteditor/ScriptEditView.java 2006-09-12 19:43:21 UTC (rev 324) +++ trunk/crossfire/src/cfeditor/textedit/scripteditor/ScriptEditView.java 2006-09-12 20:17:15 UTC (rev 325) @@ -24,13 +24,10 @@ package cfeditor.textedit.scripteditor; import cfeditor.CGUIUtils; -import cfeditor.CSettings; -import cfeditor.IGUIConstants; import cfeditor.textedit.textarea.JEditTextArea; import cfeditor.textedit.textarea.PythonTokenMarker; import cfeditor.textedit.textarea.SyntaxDocument; import java.awt.Dimension; -import java.awt.Rectangle; import java.awt.Toolkit; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; @@ -75,8 +72,6 @@ /** key used to store the main windows height to settings-file. */ private static final String WINDOW_HEIGHT = "ScriptPadWindow.height"; - private final ScriptEditControl control; - private final ScriptEditMenuBar menuBar; // the menu bar private final JTabbedPane tabPane; // tab pane @@ -90,7 +85,6 @@ super("Script Pad"); // window title setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); - this.control = control; textAreas = new ArrayList<JEditTextArea>(); menuBar = new ScriptEditMenuBar(control); // build menu bar setJMenuBar(menuBar); // add menu bar to frame @@ -109,17 +103,11 @@ // calculate some default values in case there is no settings file final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); - final int defwidth = (int) (0.6 * screen.getWidth()); - final int defheight = (int) (0.8 * screen.getHeight()); - - // get the old location and size - final CSettings settings = CSettings.getInstance(IGUIConstants.APP_NAME); - final int x = Integer.parseInt(settings.getProperty(WINDOW_X, "" + (int) ((screen.getWidth() - defwidth) / 2.))); - final int y = Integer.parseInt(settings.getProperty(WINDOW_Y, "" + (int) ((screen.getHeight() - defheight) / 2.))); - final int width = Integer.parseInt(settings.getProperty(WINDOW_WIDTH, "" + defwidth)); - final int height = Integer.parseInt(settings.getProperty(WINDOW_HEIGHT, "" + defheight)); - - this.setBounds(x, y, width, height); + final int width = (int) (0.6 * screen.getWidth()); + final int height = (int) (0.8 * screen.getHeight()); + final int x = (int) (0.2 * screen.getWidth()); + final int y = (int) (0.1 * screen.getWidth()); + setBounds(x, y, width, height); } /** @@ -132,12 +120,9 @@ //ta.setFont(new Font("Courier New", Font.PLAIN, 12)); ta.setDocument(new SyntaxDocument()); ta.getDocument().setTokenMarker(new PythonTokenMarker()); - boolean isFirstTimeShowing = false; // true when frame was hidden and now is showing - tabPane.addTab(title, ta); if (getTabCount() <= 1 || !isShowing()) { setVisible(true); - isFirstTimeShowing = true; } tabPane.setSelectedIndex(getTabCount() - 1); @@ -145,7 +130,7 @@ // very important: There must be a drawing update after showing the frame, to make // sure the graphics context is fully initialized before calling 'setEditingFocus()' //if (isFirstTimeShowing) { - this.update(this.getGraphics()); + update(getGraphics()); //} textAreas.add(ta); @@ -153,29 +138,24 @@ if (file != null && file.exists()) { // print file into this document try { - // open ascii streams - final FileReader fread = new FileReader(file); - final BufferedReader bfread = new BufferedReader(fread); - - boolean firstLine = true; - final StringBuffer buff = new StringBuffer(""); - String line = bfread.readLine(); - while (line != null) { - if (!firstLine) { - buff.append('\n'); - } else { - firstLine = false; + final BufferedReader in = new BufferedReader(new FileReader(file)); + try { + boolean firstLine = true; + final StringBuffer buff = new StringBuffer(""); + String line; + while ((line = in.readLine()) != null) { + if (!firstLine) { + buff.append('\n'); + } else { + firstLine = false; + } + buff.append(line); } - buff.append(line); - line = bfread.readLine(); + ta.getDocument().insertString(0, buff.toString(), null); + } finally { + in.close(); } - - // close filestreams - bfread.close(); - fread.close(); - // insert buffer into the document - ta.getDocument().insertString(0, buff.toString(), null); } catch (final FileNotFoundException e) { log.info("addTab(): File '" + file.getName() + "' not found."); } catch (final IOException e) { @@ -189,7 +169,6 @@ //ta.scrollToCaret(); // make sure the window shows caret (top left corner) toFront(); // bring window to front - refreshMenuBar(); } /** @@ -240,24 +219,6 @@ } /** - * Refresh the menu bar (update enable/disable state of all menus). - */ - public void refreshMenuBar() { - menuBar.updateFont(true); - } - - /** - * Update the global fonts (-> menu bar and tab labels). - */ - public void updateGlobalFont() { - if (!control.isStandAlone()) { - control.getMainControl().setBoldFont(tabPane); - } - - menuBar.updateFont(true); - } - - /** * Shows the given confirmation message as popup frame. The message is a * yes/no option. The parent frame is disabled until the user picks an * answer. @@ -285,22 +246,6 @@ } /** - * Notifies that the application is about to exit. The window settings get - * saved to the settings file here. - */ - final void appExitNotify() { - // store location and size - final CSettings settings = CSettings.getInstance(IGUIConstants.APP_NAME); - final Rectangle bounds = getBounds(); // window frame bounds - settings.setProperty(WINDOW_X, "" + bounds.x); - settings.setProperty(WINDOW_Y, "" + bounds.y); - settings.setProperty(WINDOW_WIDTH, "" + bounds.width); - settings.setProperty(WINDOW_HEIGHT, "" + bounds.height); - } - - // -------------------------------------- - - /** * Inner class: Listener for ChangeEvents in the tabPane. */ private final class EditTabListener implements ChangeListener { Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2006-09-12 19:43:21 UTC (rev 324) +++ trunk/daimonin/src/daieditor/CMainControl.java 2006-09-12 20:17:15 UTC (rev 325) @@ -1970,7 +1970,6 @@ /** Notifies that the application is about to exit. */ void appExitNotify() { mainView.appExitNotify(); // notify main view - ScriptEditControl.getInstance().appExitNotify(); // notify scriptpad controller if (currentMap != null) { mainView.setMapTileList(null, null); Modified: trunk/daimonin/src/daieditor/textedit/scripteditor/ScriptEditControl.java =================================================================== --- trunk/daimonin/src/daieditor/textedit/scripteditor/ScriptEditControl.java 2006-09-12 19:43:21 UTC (rev 324) +++ trunk/daimonin/src/daieditor/textedit/scripteditor/ScriptEditControl.java 2006-09-12 20:17:15 UTC (rev 325) @@ -58,7 +58,7 @@ // default directory to store new scripts in. also used as starting dir for 'open' command private static String defaultScriptDir; - private final MainControl mainControl; // daieditor main control (is null in stand-alone configuration!) + private final MainControl mainControl; // gridarta main control (is null in stand-alone configuration!) private final ScriptEditView view; // view (window with textareas) @@ -76,7 +76,7 @@ * called before once using this class. * @param mapDefFolder map default folder */ - public static void init(final String mapDefFolder, final CMainControl mainControl) { + public static void init(final String mapDefFolder, final MainControl mainControl) { if (instance == null) { isStandAlone = false; instance = new ScriptEditControl(mainControl); @@ -107,18 +107,13 @@ } /** - * @return instance of daieditor main control (is null for stand-alone + * @return instance of gridarta main control (is null for stand-alone * configuration!) */ - final MainControl getMainControl() { + @Nullable final MainControl getMainControl() { return mainControl; } - /** Notifies that the application is about to exit. */ - public final void appExitNotify() { - view.appExitNotify(); // notify view - } - /** * Register last active popup. When the script pad frame is hidden, this * popup will be closed (if still open). @@ -129,7 +124,7 @@ } /** - * Open a new empty Lua script document. + * Open a new empty script document. */ public final void openScriptNew() { opened.add("<>"); // this script has no filename assigned yet @@ -137,7 +132,7 @@ } /** - * Open a new empty Lua script document. + * Open a new empty script document. */ public final void openScriptFile(final String pathname) { final File file = new File(pathname); @@ -200,9 +195,7 @@ } view.setVisible(false); if (isStandAlone()) { - // if running in stand-alone mode, the application gets terminated at this point - appExitNotify(); - System.exit(0); // exit + System.exit(0); //FIXME: replace by proper disposal } } } @@ -352,15 +345,6 @@ } /** - * This calls the showMessage funtion from view - * @param strTitle String - * @param strMessage String - */ - public final void showMessage(final String strTitle, final String strMessage) { - view.showMessage(strTitle, strMessage); - } - - /** * Main method for testing purpose. * @param args */ @@ -368,7 +352,7 @@ init(System.getProperty("user.dir")); getInstance().openScriptNew(); getInstance().openScriptNew(); - getInstance().openScriptFile("maps\\GuildMage.lua"); + getInstance().openScriptFile("maps/GuildMage.lua"); } public ScriptEditView getView() { Modified: trunk/daimonin/src/daieditor/textedit/scripteditor/ScriptEditMenuBar.java =================================================================== --- trunk/daimonin/src/daieditor/textedit/scripteditor/ScriptEditMenuBar.java 2006-09-12 19:43:21 UTC (rev 324) +++ trunk/daimonin/src/daieditor/textedit/scripteditor/ScriptEditMenuBar.java 2006-09-12 20:17:15 UTC (rev 325) @@ -33,7 +33,6 @@ import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.KeyStroke; -import net.sf.gridarta.help.Help; /** * This class implements the MenuBar of the script editor. @@ -48,12 +47,6 @@ private JMenuItem miSave; - private JMenuItem miFind; - - private JMenuItem miFont; - - private JMenuItem miColors; - /** * Constructor - Builds the MenuBar. * @param control @@ -62,8 +55,6 @@ this.control = control; // reference to ScriptEditControl control buildFileMenu(); buildEditMenu(); - buildSettingsMenu(); - buildHelpMenu(); refresh(); } @@ -192,95 +183,15 @@ }); menuEdit.add(miPaste); - menuEdit.addSeparator(); // ------ - - miFind = new JMenuItem("Find"); - miFind.setMnemonic('F'); - miFind.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, Event.CTRL_MASK)); - miFind.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent event) { - // find - // TODO - System.err.print("find..."); - } - }); - menuEdit.add(miFind); - add(menuEdit); } /** - * Build Edit Menu. - */ - private void buildSettingsMenu() { - final JMenu menuSettings = new JMenu("Settings"); - - miFont = new JMenuItem("Font"); - miFont.setMnemonic('F'); - miFont.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent event) { - // set font - } - }); - menuSettings.add(miFont); - - miColors = new JMenuItem("Colors"); - miColors.setMnemonic('C'); - miColors.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent event) { - // set colors - } - }); - menuSettings.add(miColors); - - add(menuSettings); - } - - /** - * This builds the help menu. - */ - private void buildHelpMenu() { - final JMenu menuHelp = new JMenu("Help"); - final JMenuItem miOnlineHelp = new JMenuItem("Online Help"); - miOnlineHelp.setMnemonic('H'); - miOnlineHelp.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent event) { - // FIXME: "pystart.html" shouldn't be hardcoded - new Help(control.getView(), "pystart.html").setVisible(true); - } - }); - menuHelp.add(miOnlineHelp); - -// final JMenuItem miAbout = new JMenuItem("About"); -// miAbout.setMnemonic('A'); -// miAbout.addActionListener(new ActionListener() { -// public void actionPerformed(final ActionEvent event) { -// control.showMessage("About " + IGUIConstants.APP_NAME, -// " Version " + IGUIConstants.VERSION + '\n' -// + "(c) 2005 Michael Toennies\n" -// + " Andreas Vogl\n" -// + " Peter Plischewsky\n" -// + " Gecko\n"); -// } -// }); -// menuHelp.add(miAbout); - add(menuHelp); - } - - /** * Refreshes the enable/disable state of all menus. */ - public void refresh() { - miFind.setEnabled(false); - miColors.setEnabled(false); - miFont.setEnabled(false); - + public final void refresh() { // see if there is a path for direct 'save' - if (control.getActiveFilePath() != null) { - miSave.setEnabled(true); - } else { - miSave.setEnabled(false); - } + miSave.setEnabled(control.getActiveFilePath() != null); } } // class ScriptEditMenuBar Modified: trunk/daimonin/src/daieditor/textedit/scripteditor/ScriptEditView.java =================================================================== --- trunk/daimonin/src/daieditor/textedit/scripteditor/ScriptEditView.java 2006-09-12 19:43:21 UTC (rev 324) +++ trunk/daimonin/src/daieditor/textedit/scripteditor/ScriptEditView.java 2006-09-12 20:17:15 UTC (rev 325) @@ -28,7 +28,6 @@ import daieditor.textedit.textarea.LuaTokenMarker; import daieditor.textedit.textarea.SyntaxDocument; import java.awt.Dimension; -import java.awt.Rectangle; import java.awt.Toolkit; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; @@ -39,8 +38,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import java.util.prefs.Preferences; -import static java.util.prefs.Preferences.userNodeForPackage; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JOptionPane; @@ -48,6 +45,7 @@ import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.text.BadLocationException; +import org.apache.log4j.Logger; import org.jetbrains.annotations.Nullable; /** @@ -57,6 +55,8 @@ */ public final class ScriptEditView extends JFrame { + private static final Logger log = Logger.getLogger(ScriptEditView.class); + /** Serial Version UID. */ private static final long serialVersionUID = 1L; @@ -103,16 +103,10 @@ // calculate some default values in case there is no settings file final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); - final int defwidth = (int) (0.6 * screen.getWidth()); - final int defheight = (int) (0.8 * screen.getHeight()); - - // get the old location and size - final Preferences prefs = userNodeForPackage(ScriptEditView.class); - final int x = prefs.getInt(WINDOW_X, screen.width - defwidth >> 1); - final int y = prefs.getInt(WINDOW_Y, screen.height - defheight >> 1); - final int width = prefs.getInt(WINDOW_WIDTH, defwidth); - final int height = prefs.getInt(WINDOW_HEIGHT, defheight); - + final int width = (int) (0.6 * screen.getWidth()); + final int height = (int) (0.8 * screen.getHeight()); + final int x = (int) (0.2 * screen.getWidth()); + final int y = (int) (0.1 * screen.getWidth()); setBounds(x, y, width, height); } @@ -143,40 +137,31 @@ if (file != null && file.exists()) { // print file into this document - BufferedReader in = null; try { - // open ascii streams - in = new BufferedReader(new FileReader(file)); - - boolean firstLine = true; - final StringBuffer buff = new StringBuffer(""); - String line; - while ((line = in.readLine()) != null) { - if (!firstLine) { - buff.append('\n'); - } else { - firstLine = false; + final BufferedReader in = new BufferedReader(new FileReader(file)); + try { + boolean firstLine = true; + final StringBuffer buff = new StringBuffer(""); + String line; + while ((line = in.readLine()) != null) { + if (!firstLine) { + buff.append('\n'); + } else { + firstLine = false; + } + buff.append(line); } - buff.append(line); + ta.getDocument().insertString(0, buff.toString(), null); + } finally { + in.close(); } - - // close filestreams - in.close(); - // insert buffer into the document - ta.getDocument().insertString(0, buff.toString(), null); } catch (final FileNotFoundException e) { - System.err.println("ScriptEditView.addTab(): File '" + file.getName() + "' not found."); + log.info("addTab(): File '" + file.getName() + "' not found."); } catch (final IOException e) { - System.err.println("ScriptEditView.addTab(): I/O-Error while reading '" + file.getName() + "'."); + log.info("addTab(): I/O-Error while reading '" + file.getName() + "'."); } catch (final BadLocationException e) { - System.err.println("ScriptEditView.addTab(): Bad Location in Document!"); - } finally { - try { - in.close(); - } catch (final Exception e) { /* ignore */ } finally { - in = null; - } + log.info("addTab(): Bad Location in Document!"); } } @@ -261,22 +246,6 @@ } /** - * Notifies that the application is about to exit. The window settings get - * saved to the settings file here. - */ - final void appExitNotify() { - // store location and size - final Preferences prefs = userNodeForPackage(ScriptEditView.class); - final Rectangle bounds = getBounds(); // window frame bounds - prefs.putInt(WINDOW_X, bounds.x); - prefs.putInt(WINDOW_Y, bounds.y); - prefs.putInt(WINDOW_WIDTH, bounds.width); - prefs.putInt(WINDOW_HEIGHT, bounds.height); - } - - // -------------------------------------- - - /** * Inner class: Listener for ChangeEvents in the tabPane. */ private final class EditTabListener implements ChangeListener { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <der...@us...> - 2006-09-12 19:43:26
|
Revision: 324 http://svn.sourceforge.net/gridarta/?rev=324&view=rev Author: derdanny Date: 2006-09-12 12:43:21 -0700 (Tue, 12 Sep 2006) Log Message: ----------- getFirst() and getLast() return null if container is empty. Modified Paths: -------------- trunk/daimonin/src/daieditor/arch/ArchObjectContainer.java Modified: trunk/daimonin/src/daieditor/arch/ArchObjectContainer.java =================================================================== --- trunk/daimonin/src/daieditor/arch/ArchObjectContainer.java 2006-09-12 16:48:43 UTC (rev 323) +++ trunk/daimonin/src/daieditor/arch/ArchObjectContainer.java 2006-09-12 19:43:21 UTC (rev 324) @@ -130,7 +130,7 @@ * @return first object contained or <code>null</code> if {@link #isEmpty()} returns <code>true</code> */ @Nullable public final ArchObject getFirst() { - return contents.get(0); + return contents.isEmpty() ? null : contents.get(0); } /** @@ -139,7 +139,7 @@ * @return last object contained or <code>null</code> if {@link #isEmpty()} returns <code>true</code> */ @Nullable public final ArchObject getLast() { - return contents.get(contents.size() - 1); + return contents.isEmpty() ? null : contents.get(contents.size() - 1); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2006-09-12 16:48:55
|
Revision: 323 http://svn.sourceforge.net/gridarta/?rev=323&view=rev Author: akirschbaum Date: 2006-09-12 09:48:43 -0700 (Tue, 12 Sep 2006) Log Message: ----------- Use isPointValid() where possible. Modified Paths: -------------- trunk/crossfire/src/cfeditor/map/DefaultMapModel.java trunk/daimonin/src/daieditor/map/DefaultMapModel.java Modified: trunk/crossfire/src/cfeditor/map/DefaultMapModel.java =================================================================== --- trunk/crossfire/src/cfeditor/map/DefaultMapModel.java 2006-09-10 22:49:14 UTC (rev 322) +++ trunk/crossfire/src/cfeditor/map/DefaultMapModel.java 2006-09-12 16:48:43 UTC (rev 323) @@ -327,7 +327,7 @@ for (int c = 0; c <= count; c++) { final int mapx = xx + mainControl.getArchObjectStack().getArch(archnr + c).getMultiRefX(); final int mapy = yy + mainControl.getArchObjectStack().getArch(archnr + c).getMultiRefY(); - if (mapx < 0 || mapy < 0 || mapx >= mapSize.getWidth()|| mapy >= mapSize.getHeight()) { + if (!isPointValid(mapx, mapy)) { // outside map return false; } @@ -688,7 +688,7 @@ * @return the specified arch, or null if not found */ @Nullable public ArchObject getMapArch(final int id, final Point pos) { - if (mapGrid == null || pos.x < 0 || pos.x >= mapSize.getWidth() || pos.y < 0 || pos.y >= mapSize.getHeight()) { + if (mapGrid == null || !isPointValid(pos)) { return null; } @@ -937,7 +937,7 @@ @Nullable public ArchObject getExit() { final Point hspot = mapControl.getMapView().getHighlightStart(); // selected spot - if (hspot.x < 0 || hspot.y < 0) { + if (!isPointValid(hspot)) { return null; // out of map } @@ -1102,7 +1102,7 @@ * @return whether a match was found */ public boolean filterSquare(final Filter filter, final FilterConfig config, final int x, final int y) { - if (x < 0 || y < 0 || x >= mapSize.getWidth() || y >= mapSize.getHeight()) { + if (!isPointValid(x, y)) { return false; } Modified: trunk/daimonin/src/daieditor/map/DefaultMapModel.java =================================================================== --- trunk/daimonin/src/daieditor/map/DefaultMapModel.java 2006-09-10 22:49:14 UTC (rev 322) +++ trunk/daimonin/src/daieditor/map/DefaultMapModel.java 2006-09-12 16:48:43 UTC (rev 323) @@ -221,14 +221,14 @@ final ArchObject head = mainControl.getArchObjectStack().getArch(archname); final Point mapH = new Point(head.getMultiRefX(), head.getMultiRefY()); mapH.translate(pos.x, pos.y); - if (mapH.x < 0 || mapH.y < 0 || mapH.x >= mapSize.getWidth() || mapH.y >= mapSize.getHeight()) { + if (!isPointValid(mapH)) { return false; } for (final ArchObject tail : head.getTailList()) { final Point mapT = new Point(tail.getMultiRefX(), tail.getMultiRefY()); mapT.translate(pos.x, pos.y); // outside map - if (mapT.x < 0 || mapT.y < 0 || mapT.x >= mapSize.getWidth() || mapT.y >= mapSize.getHeight()) { + if (!isPointValid(mapT)) { return false; } @@ -364,7 +364,7 @@ final int mapx = arch.getMapX(); final int mapy = arch.getMapY(); - if (mapx >= mapSize.getWidth() || mapx < 0 || mapy >= mapSize.getHeight() || mapy < 0) { + if (!isPointValid(new Point(mapx, mapy))) { // TODO: // Think about how this could be handled via an exception and caught much earlier, perhaps already while reading the map, not after it // already has been read. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-09-10 22:49:36
|
Revision: 322 http://svn.sourceforge.net/gridarta/?rev=322&view=rev Author: christianhujer Date: 2006-09-10 15:49:14 -0700 (Sun, 10 Sep 2006) Log Message: ----------- Some Script editor unification. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/textedit/scripteditor/CFPythonPopup.java trunk/crossfire/src/cfeditor/textedit/scripteditor/ScriptEditControl.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/textedit/scripteditor/CFPythonPopup.java trunk/daimonin/src/daieditor/textedit/scripteditor/ScriptEditControl.java trunk/src/app/net/sf/gridarta/MainControl.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-09-10 22:21:43 UTC (rev 321) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-09-10 22:49:14 UTC (rev 322) @@ -519,6 +519,7 @@ return strMapDir; } + /** {@inheritDoc} */ public String getArchDefaultFolder() { return strArchDir; } @@ -553,11 +554,7 @@ mainView.showArchPanelQuickObject(arch); } - /** - * set bold font to the given component - * @param comp component - * @return same component from parameter (but now with accurate font) - */ + /** {@inheritDoc} */ public JComponent setBoldFont(final JComponent comp) { if (boldFont != null) { comp.setFont(boldFont); Modified: trunk/crossfire/src/cfeditor/textedit/scripteditor/CFPythonPopup.java =================================================================== --- trunk/crossfire/src/cfeditor/textedit/scripteditor/CFPythonPopup.java 2006-09-10 22:21:43 UTC (rev 321) +++ trunk/crossfire/src/cfeditor/textedit/scripteditor/CFPythonPopup.java 2006-09-10 22:49:14 UTC (rev 322) @@ -108,51 +108,43 @@ * Load the list of CFPython commands from the datafile. */ public static void loadCommandlist() { - CFileReader reader = null; // file reader final List<String> cmdList = new ArrayList<String>(); // temporare list to store commands - + final String baseDir = IGUIConstants.CONFIG_DIR; try { - String isoArchDefFolder = ""; - - final String baseDir = IGUIConstants.CONFIG_DIR; - reader = new CFileReader(baseDir, IGUIConstants.PYTHONMENU_FILE); - - // read file into the cmdList vector: - String line; - while ((line = reader.getReader().readLine()) != null) { - line = line.trim(); - if (line.length() > 0 && !line.startsWith("#")) { - // ATM, the descriptive info about method headers is cut out - // (TODO: parse and show the full info in a statusbar) - final int k = line.indexOf("("); - if (k > 0) { - line = line.substring(0, k) + "()"; - } else { - System.err.println("Parse error in " + IGUIConstants.PYTHONMENU_FILE + ":"); - System.err.println(" \"" + line + "\" missing '()'"); - line += "()"; // that line is probably garbage, but will work + final CFileReader reader = new CFileReader(baseDir, IGUIConstants.PYTHONMENU_FILE); + try { + // read file into the cmdList vector: + for (String line; (line = reader.getReader().readLine()) != null;) { + line = line.trim(); + if (line.length() > 0 && !line.startsWith("#")) { + // ATM, the descriptive info about method headers is cut out + // (TODO: parse and show the full info in a statusbar) + final int k = line.indexOf("("); + if (k > 0) { + line = line.substring(0, k) + "()"; + } else { + System.err.println("Parse error in " + IGUIConstants.PYTHONMENU_FILE + ":"); + System.err.println(" \"" + line + "\" missing '()'"); + line += "()"; // that line is probably garbage, but will work + } + cmdList.add(line); } - cmdList.add(line); } - } - sort(cmdList, CASE_INSENSITIVE_ORDER); + sort(cmdList, CASE_INSENSITIVE_ORDER); - // now create the 'menuEntries' array - if (cmdList.size() > 0) { - menuEntries = cmdList.toArray(new String[cmdList.size()]); + // now create the 'menuEntries' array + if (cmdList.size() > 0) { + menuEntries = cmdList.toArray(new String[cmdList.size()]); + } + } finally { + reader.close(); } - - // close file reader - reader.close(); } catch (final FileNotFoundException e) { System.err.println("File '" + IGUIConstants.PYTHONMENU_FILE + "' not found."); - return; } catch (final EOFException e) { - // end of file/spell struct reached - reader.close(); + // expected exception, do not handle: end of file/spell struct reached } catch (final IOException e) { System.err.println("Cannot read file '" + IGUIConstants.PYTHONMENU_FILE + "'!"); - return; } } @@ -171,7 +163,7 @@ public final void setCaretPosition(final int pos) { caretPos = pos; getMenu().requestFocus(); - control.registerActivePopup(this); + ScriptEditControl.registerActivePopup(this); } public final CFPythonPopupMenu getMenu() { @@ -225,11 +217,8 @@ */ private static final long serialVersionUID = 1L; - final JComboBox comboBox; - public CFPythonPopupMenu(final JComboBox box) { super(box); - this.comboBox = box; //this.addMouseListener(new ListenerMenuClick()); setPreferredSize(new Dimension(220, 200)); } Modified: trunk/crossfire/src/cfeditor/textedit/scripteditor/ScriptEditControl.java =================================================================== --- trunk/crossfire/src/cfeditor/textedit/scripteditor/ScriptEditControl.java 2006-09-10 22:21:43 UTC (rev 321) +++ trunk/crossfire/src/cfeditor/textedit/scripteditor/ScriptEditControl.java 2006-09-10 22:49:14 UTC (rev 322) @@ -37,6 +37,7 @@ import javax.swing.filechooser.FileFilter; import org.apache.log4j.Logger; import org.jetbrains.annotations.Nullable; +import net.sf.gridarta.MainControl; /** * ScriptEditControl - Manages events and dataflow for the script editor entity. @@ -59,14 +60,14 @@ // default directory to store new scripts in. also used as starting dir for 'open' command private static String defaultScriptDir; - private final CMainControl mainControl; // cfeditor main control (is null in stand-alone configuration!) + private final MainControl mainControl; // cfeditor main control (is null in stand-alone configuration!) private final ScriptEditView view; // view (window with textareas) private final List<String> opened; // open tabs, contains absolute filenames (or "<>") in order left to right /** Constructor is private, instance is created by calling 'init()' */ - private ScriptEditControl(final CMainControl mainControl) { + private ScriptEditControl(final MainControl mainControl) { opened = new ArrayList<String>(); // start with empty vector this.mainControl = mainControl; view = new ScriptEditView(this); // initialize window @@ -111,7 +112,7 @@ * @return instance of cfeditor main control (is null for stand-alone * configuration!) */ - final CMainControl getMainControl() { + final MainControl getMainControl() { return mainControl; } Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2006-09-10 22:21:43 UTC (rev 321) +++ trunk/daimonin/src/daieditor/CMainControl.java 2006-09-10 22:49:14 UTC (rev 322) @@ -98,6 +98,7 @@ import javax.swing.AbstractAction; import javax.swing.ImageIcon; import javax.swing.JFileChooser; +import javax.swing.JComponent; import static javax.swing.JOptionPane.CANCEL_OPTION; import static javax.swing.JOptionPane.CLOSED_OPTION; import static javax.swing.JOptionPane.ERROR_MESSAGE; @@ -754,10 +755,19 @@ return strMapDir; } + /** {@inheritDoc} */ public String getArchDefaultFolder() { return strArchDir; } + /** + * {@inheritDoc} + * This implementation does nothing. + */ + public JComponent setBoldFont(final JComponent comp) { + return comp; + } + public String getScriptDefaultFolder() { return strScriptDir; } Modified: trunk/daimonin/src/daieditor/textedit/scripteditor/CFPythonPopup.java =================================================================== --- trunk/daimonin/src/daieditor/textedit/scripteditor/CFPythonPopup.java 2006-09-10 22:21:43 UTC (rev 321) +++ trunk/daimonin/src/daieditor/textedit/scripteditor/CFPythonPopup.java 2006-09-10 22:49:14 UTC (rev 322) @@ -109,40 +109,41 @@ * Load the list of CFPython commands from the datafile. */ public static void loadCommandlist() { - CFileReader reader = null; // file reader final List<String> cmdList = new ArrayList<String>(); // temporare list to store commands - try { - final String isoArchDefFolder = ScriptEditControl.isStandAlone() ? - userNodeForPackage(CMainControl.class).get(ResourceFileManager.ARCH_DIR_KEY, ResourceFileManager.DEFAULT_ARCH_DIR) : - control.getMainControl().getArchDefaultFolder(); + final String isoArchDefFolder = ScriptEditControl.isStandAlone() ? + userNodeForPackage(CMainControl.class).get(ResourceFileManager.ARCH_DIR_KEY, ResourceFileManager.DEFAULT_ARCH_DIR) : + control.getMainControl().getArchDefaultFolder(); - final String baseDir = isoArchDefFolder + File.separator + IGUIConstants.CONFIG_DIR; - reader = new CFileReader(baseDir, IGUIConstants.PYTHONMENU_FILE); - - // read file into the cmdList vector: - String line; - while ((line = reader.readLine()) != null) { - line = line.trim(); - if (line.length() > 0 && !line.startsWith("#")) { - // ATM, the descriptive info about method headers is cut out - // (TODO: parse and show the full info in a statusbar) - final int k = line.indexOf("("); - if (k > 0) { - line = line.substring(0, k) + "()"; - } else { - System.err.println("Parse error in " + IGUIConstants.PYTHONMENU_FILE + ":"); - System.err.println(" \"" + line + "\" missing '()'"); - line += "()"; // that line is probably garbage, but will work + final String baseDir = isoArchDefFolder + File.separator + IGUIConstants.CONFIG_DIR; + try { + final CFileReader reader = new CFileReader(baseDir, IGUIConstants.PYTHONMENU_FILE); + try { + // read file into the cmdList vector: + for (String line; (line = reader.readLine()) != null;) { + line = line.trim(); + if (line.length() > 0 && !line.startsWith("#")) { + // ATM, the descriptive info about method headers is cut out + // (TODO: parse and show the full info in a statusbar) + final int k = line.indexOf("("); + if (k > 0) { + line = line.substring(0, k) + "()"; + } else { + System.err.println("Parse error in " + IGUIConstants.PYTHONMENU_FILE + ":"); + System.err.println(" \"" + line + "\" missing '()'"); + line += "()"; // that line is probably garbage, but will work + } + cmdList.add(line); } - cmdList.add(line); } - } - sort(cmdList, CASE_INSENSITIVE_ORDER); + sort(cmdList, CASE_INSENSITIVE_ORDER); - // now create the 'menuEntries' array - if (cmdList.size() > 0) { - menuEntries = cmdList.toArray(new String[cmdList.size()]); + // now create the 'menuEntries' array + if (cmdList.size() > 0) { + menuEntries = cmdList.toArray(new String[cmdList.size()]); + } + } finally { + reader.close(); } } catch (final FileNotFoundException e) { System.err.println("File '" + IGUIConstants.PYTHONMENU_FILE + "' not found."); @@ -150,12 +151,6 @@ // expected exception, do not handle: end of file/spell struct reached } catch (final IOException e) { System.err.println("Cannot read file '" + IGUIConstants.PYTHONMENU_FILE + "'!"); - } finally { - try { - reader.close(); - } catch (final Exception e) { /* ignore */ } finally { - reader = null; - } } } Modified: trunk/daimonin/src/daieditor/textedit/scripteditor/ScriptEditControl.java =================================================================== --- trunk/daimonin/src/daieditor/textedit/scripteditor/ScriptEditControl.java 2006-09-10 22:21:43 UTC (rev 321) +++ trunk/daimonin/src/daieditor/textedit/scripteditor/ScriptEditControl.java 2006-09-10 22:49:14 UTC (rev 322) @@ -35,6 +35,7 @@ import javax.swing.filechooser.FileFilter; import org.apache.log4j.Logger; import org.jetbrains.annotations.Nullable; +import net.sf.gridarta.MainControl; /** * ScriptEditControl - Manages events and dataflow for the script editor entity. @@ -57,14 +58,14 @@ // default directory to store new scripts in. also used as starting dir for 'open' command private static String defaultScriptDir; - private final CMainControl mainControl; // daieditor main control (is null in stand-alone configuration!) + private final MainControl mainControl; // daieditor main control (is null in stand-alone configuration!) private final ScriptEditView view; // view (window with textareas) private final List<String> opened; // open tabs, contains absolute filenames (or "<>") in order left to right /** Constructor is private, instance is created by calling 'init()' */ - private ScriptEditControl(final CMainControl mainControl) { + private ScriptEditControl(final MainControl mainControl) { opened = new ArrayList<String>(); // start with empty vector this.mainControl = mainControl; view = new ScriptEditView(this); // initialize window @@ -109,7 +110,7 @@ * @return instance of daieditor main control (is null for stand-alone * configuration!) */ - final CMainControl getMainControl() { + final MainControl getMainControl() { return mainControl; } Modified: trunk/src/app/net/sf/gridarta/MainControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/MainControl.java 2006-09-10 22:21:43 UTC (rev 321) +++ trunk/src/app/net/sf/gridarta/MainControl.java 2006-09-10 22:49:14 UTC (rev 322) @@ -1,5 +1,7 @@ package net.sf.gridarta; +import javax.swing.JComponent; + /** * This interface is only for unification. * It should become obsolete after a while. @@ -14,4 +16,17 @@ */ void refreshMenusAndToolbars(); + /** + * Get the default folder of arches. + * @return default folder of arches. + */ + String getArchDefaultFolder(); + + /** + * Set bold font to the given component. + * @param comp component + * @return same component from parameter (but now with accurate font) + */ + JComponent setBoldFont(JComponent comp); + } // interface MainControl This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-09-10 22:22:09
|
Revision: 321 http://svn.sourceforge.net/gridarta/?rev=321&view=rev Author: christianhujer Date: 2006-09-10 15:21:43 -0700 (Sun, 10 Sep 2006) Log Message: ----------- Unified UndoStack (well it's not used, but any unification helps ;-) Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/map/MapControl.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/map/MapControl.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/CUndoStack.java trunk/src/app/net/sf/gridarta/MainControl.java trunk/src/app/net/sf/gridarta/map/MapControl.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/CUndoStack.java trunk/daimonin/src/daieditor/CUndoStack.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-09-10 22:08:50 UTC (rev 320) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-09-10 22:21:43 UTC (rev 321) @@ -55,6 +55,8 @@ import javax.swing.filechooser.FileFilter; import cfeditor.GridderException; import net.sf.gridarta.Size2D; +import net.sf.gridarta.MainControl; +import net.sf.gridarta.CUndoStack; import net.sf.japi.swing.ActionFactory; import static net.sf.japi.swing.ActionFactory.getFactory; import net.sf.japi.util.filter.file.EndingFileFilter; @@ -67,7 +69,7 @@ * @author <a href="mailto:mic...@no...">Michael Toennies</a> * @author <a href="mailto:and...@gm...">Andreas Vogl</a> */ -public final class CMainControl extends JFrame { +public final class CMainControl extends JFrame implements MainControl { /** ActionFactory. */ private static final ActionFactory ACTION_FACTORY = getFactory("cfeditor"); Deleted: trunk/crossfire/src/cfeditor/CUndoStack.java =================================================================== --- trunk/crossfire/src/cfeditor/CUndoStack.java 2006-09-10 22:08:50 UTC (rev 320) +++ trunk/crossfire/src/cfeditor/CUndoStack.java 2006-09-10 22:21:43 UTC (rev 321) @@ -1,197 +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.map.MapControl; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.WeakHashMap; -import net.sf.gridarta.Undoable; - -/** - * The undo/redo stack that is used when undoing/redoing operations. - * Every operation should add itself to the stack using the add() method. - * @author <a href="mailto:mic...@no...">Michael Toennies</a> - */ -public final class CUndoStack { - - /** The controller of the undo stack model. */ - private static CMainControl mainControl; - - /** The shared hashtable that maps levels to undo stacks. */ - private static final Map<MapControl, CUndoStack> hashFromLevelToStack = new WeakHashMap<MapControl, CUndoStack>(); - - /** The undo stack. Contains all undoable operations. */ - private final List<Undoable> undoStack = new ArrayList<Undoable>(); - - /** The redo stack. Contains all redoable operations. */ - private final List<Undoable> redoStack = new ArrayList<Undoable>(); - - /** The maximum size of the stacks. */ - private int maxStackSize = 10; - - /** - * Returns the undo stack for the given level controller. - * @param mapControl the level whose undo/redo stack is to be returned - * @return the undo/redo stack for the given level - */ - public static CUndoStack getInstance(final MapControl mapControl) { - if (hashFromLevelToStack.containsKey(mapControl)) { - return hashFromLevelToStack.get(mapControl); - } - - final CUndoStack instance = new CUndoStack(); - hashFromLevelToStack.put(mapControl, instance); - return instance; - } - - /** - * Sets the main controller of all undo/redo stack models. - * @param mainControl the controller of all undo/redo stacks - */ - public static void setMainControl(final CMainControl mainControl) { - CUndoStack.mainControl = mainControl; - } - - /** Constructs an undo/redo stack. */ - private CUndoStack() { - } - - /** - * Returns the maximum stack size. - * @return the maximum stack size - */ - int getMaxStackSize() { - return maxStackSize; - } - - /** - * Sets the maximum stack size. - * @param size the new maximum stack size - */ - void setMaxStackSize(final int size) { - maxStackSize = size; - } - - /** - * Adds a new undoable/redoable operation to the undo/redo stack. - * @param undoOp the new operation to be added to the stack - */ - public void add(final Undoable undoOp) { - undoStack.add(undoOp); - redoStack.clear(); - if (undoStack.size() > maxStackSize) { - undoStack.remove(0); - } - - if (mainControl != null) { - mainControl.refreshMenusAndToolbars(); - } - } - - /** - * Returns whether the last operation in the undo stack can be undone. - * @return <code>true</code> if the last operation in the undo stack can be - * undone, <code>false</code> if not - */ - public boolean canUndo() { - if (undoStack.size() > 0) { - final Undoable op = undoStack.get(undoStack.size() - 1); - return op.isUndoable(); - } - - return false; - } - - /** - * Returns the name of the last operation in the undo stack. - * @return the name of the last operation in the undo stack - */ - public String getUndoName() { - if (canUndo()) { - final Undoable op = undoStack.get(undoStack.size() - 1); - return op.getName(); - } - - return ""; - } - - /** Undoes the last operation in the undo stack. */ - public void undo() { - if (canUndo()) { - final Undoable op = undoStack.get(undoStack.size() - 1); - undoStack.remove(op); - op.undo(); - redoStack.add(op); - - if (mainControl != null) { - mainControl.refreshMenusAndToolbars(); - } - } - } - - /** - * Returns whether the last operation in the redo stack can be redone. - * @return <code>true</code> if the last operation in the redo stack can be - * redone, <code>false</code> if not - */ - public boolean canRedo() { - if (redoStack.size() > 0) { - final Undoable op = redoStack.get(redoStack.size() - 1); - return op.isRedoable(); - } - - return false; - } - - /** - * Returns the name of the last operation in the redo stack. - * @return the name of the last operation in the redo stack - */ - public String getRedoName() { - if (canRedo()) { - final Undoable op = redoStack.get(redoStack.size() - 1); - return op.getName(); - } - - return ""; - } - - /** Redoes the last operation in the redo stack. */ - public void redo() { - if (canRedo()) { - final Undoable op = redoStack.get(redoStack.size() - 1); - redoStack.remove(op); - op.redo(); - undoStack.add(op); - - if (mainControl != null) { - mainControl.refreshMenusAndToolbars(); - } - } - } - -} // class CUndoStack Modified: trunk/crossfire/src/cfeditor/map/MapControl.java =================================================================== --- trunk/crossfire/src/cfeditor/map/MapControl.java 2006-09-10 22:08:50 UTC (rev 320) +++ trunk/crossfire/src/cfeditor/map/MapControl.java 2006-09-10 22:21:43 UTC (rev 321) @@ -28,7 +28,7 @@ import cfeditor.CMainStatusbar; import cfeditor.CMapViewBasic; import cfeditor.MapViewIFrame; -import cfeditor.CUndoStack; +import net.sf.gridarta.CUndoStack; import cfeditor.IGUIConstants; import cfeditor.GridderException; import cfeditor.arch.ArchObject; @@ -46,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 { +public final class MapControl implements net.sf.gridarta.map.MapControl { /** * The main controller of this subcontroller. Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2006-09-10 22:08:50 UTC (rev 320) +++ trunk/daimonin/src/daieditor/CMainControl.java 2006-09-10 22:21:43 UTC (rev 321) @@ -114,6 +114,8 @@ import static javax.swing.KeyStroke.getKeyStroke; import javax.swing.filechooser.FileFilter; import net.sf.gridarta.gui.HideFileFilterProxy; +import net.sf.gridarta.MainControl; +import net.sf.gridarta.CUndoStack; import net.sf.japi.swing.ActionFactory; import static net.sf.japi.swing.ActionFactory.getFactory; import net.sf.japi.swing.ActionMethod; @@ -134,7 +136,7 @@ * @author <a href="mailto:ch...@ri...">Christian.Hujer</a> * @fixme I'm 2200 lines long, therefor I suck. */ -public final class CMainControl implements ThrowableHandler, MapModelListener { +public final class CMainControl implements ThrowableHandler, MapModelListener, MainControl { /** ActionFactory. */ private static final ActionFactory ACTION_FACTORY = getFactory("daieditor"); Deleted: trunk/daimonin/src/daieditor/CUndoStack.java =================================================================== --- trunk/daimonin/src/daieditor/CUndoStack.java 2006-09-10 22:08:50 UTC (rev 320) +++ trunk/daimonin/src/daieditor/CUndoStack.java 2006-09-10 22:21:43 UTC (rev 321) @@ -1,197 +0,0 @@ -/* - * Daimonin 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 daieditor; - -import daieditor.map.MapControl; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.WeakHashMap; -import net.sf.gridarta.Undoable; - -/** - * The undo/redo stack that is used when undoing/redoing operations. - * Every operation should add itself to the stack using the add() method. - * @author <a href="mailto:mic...@no...">Michael Toennies</a> - */ -public final class CUndoStack { - - /** The controller of the undo stack model. */ - private static CMainControl mainControl; - - /** The shared hashtable that maps levels to undo stacks. */ - private static final Map<MapControl, CUndoStack> hashFromLevelToStack = new WeakHashMap<MapControl, CUndoStack>(); - - /** The undo stack. Contains all undoable operations. */ - private final List<Undoable> undoStack = new ArrayList<Undoable>(); - - /** The redo stack. Contains all redoable operations. */ - private final List<Undoable> redoStack = new ArrayList<Undoable>(); - - /** The maximum size of the stacks. */ - private int maxStackSize = 10; - - /** - * Returns the undo stack for the given level controller. - * @param mapControl the level whose undo/redo stack is to be returned - * @return the undo/redo stack for the given level - */ - public static CUndoStack getInstance(final MapControl mapControl) { - if (hashFromLevelToStack.containsKey(mapControl)) { - return hashFromLevelToStack.get(mapControl); - } - - final CUndoStack instance = new CUndoStack(); - hashFromLevelToStack.put(mapControl, instance); - return instance; - } - - /** - * Sets the main controller of all undo/redo stack models. - * @param mainControl the controller of all undo/redo stacks - */ - public static void setMainControl(final CMainControl mainControl) { - CUndoStack.mainControl = mainControl; - } - - /** Constructs an undo/redo stack. */ - private CUndoStack() { - } - - /** - * Returns the maximum stack size. - * @return the maximum stack size - */ - int getMaxStackSize() { - return maxStackSize; - } - - /** - * Sets the maximum stack size. - * @param size the new maximum stack size - */ - void setMaxStackSize(final int size) { - maxStackSize = size; - } - - /** - * Adds a new undoable/redoable operation to the undo/redo stack. - * @param undoOp the new operation to be added to the stack - */ - public void add(final Undoable undoOp) { - undoStack.add(undoOp); - redoStack.clear(); - if (undoStack.size() > maxStackSize) { - undoStack.remove(0); - } - - if (mainControl != null) { - mainControl.refreshMenusAndToolbars(); - } - } - - /** - * Returns whether the last operation in the undo stack can be undone. - * @return <code>true</code> if the last operation in the undo stack can be - * undone, <code>false</code> if not - */ - public boolean canUndo() { - if (undoStack.size() > 0) { - final Undoable op = undoStack.get(undoStack.size() - 1); - return op.isUndoable(); - } - - return false; - } - - /** - * Returns the name of the last operation in the undo stack. - * @return the name of the last operation in the undo stack - */ - public String getUndoName() { - if (canUndo()) { - final Undoable op = undoStack.get(undoStack.size() - 1); - return op.getName(); - } - - return ""; - } - - /** Undoes the last operation in the undo stack. */ - public void undo() { - if (canUndo()) { - final Undoable op = undoStack.get(undoStack.size() - 1); - undoStack.remove(op); - op.undo(); - redoStack.add(op); - - if (mainControl != null) { - mainControl.refreshMenusAndToolbars(); - } - } - } - - /** - * Returns whether the last operation in the redo stack can be redone. - * @return <code>true</code> if the last operation in the redo stack can be - * redone, <code>false</code> if not - */ - public boolean canRedo() { - if (redoStack.size() > 0) { - final Undoable op = redoStack.get(redoStack.size() - 1); - return op.isRedoable(); - } - - return false; - } - - /** - * Returns the name of the last operation in the redo stack. - * @return the name of the last operation in the redo stack - */ - public String getRedoName() { - if (canRedo()) { - final Undoable op = redoStack.get(redoStack.size() - 1); - return op.getName(); - } - - return ""; - } - - /** Redoes the last operation in the redo stack. */ - public void redo() { - if (canRedo()) { - final Undoable op = redoStack.get(redoStack.size() - 1); - redoStack.remove(op); - op.redo(); - undoStack.add(op); - - if (mainControl != null) { - mainControl.refreshMenusAndToolbars(); - } - } - } - -} // class CUndoStack Modified: trunk/daimonin/src/daieditor/map/MapControl.java =================================================================== --- trunk/daimonin/src/daieditor/map/MapControl.java 2006-09-10 22:08:50 UTC (rev 320) +++ trunk/daimonin/src/daieditor/map/MapControl.java 2006-09-10 22:21:43 UTC (rev 321) @@ -27,7 +27,6 @@ import daieditor.CMainControl; import daieditor.MapViewIFrame; import daieditor.CPickmapPanel; -import daieditor.CUndoStack; import daieditor.CopyBuffer; import daieditor.IGUIConstants; import daieditor.arch.ArchObject; @@ -47,6 +46,7 @@ import javax.imageio.ImageIO; import javax.swing.ImageIcon; import net.sf.gridarta.Size2D; +import net.sf.gridarta.CUndoStack; import net.sf.gridarta.gui.map.MapCursor; import net.sf.gridarta.gui.map.MapGrid; import net.sf.japi.swing.ActionFactory; @@ -59,7 +59,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 { +public final class MapControl implements MapModelListener, net.sf.gridarta.map.MapControl { /** * The main controller of this subcontroller. Copied: trunk/src/app/net/sf/gridarta/CUndoStack.java (from rev 320, trunk/crossfire/src/cfeditor/CUndoStack.java) =================================================================== --- trunk/src/app/net/sf/gridarta/CUndoStack.java (rev 0) +++ trunk/src/app/net/sf/gridarta/CUndoStack.java 2006-09-10 22:21:43 UTC (rev 321) @@ -0,0 +1,196 @@ +/* + * 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 net.sf.gridarta; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.WeakHashMap; +import net.sf.gridarta.map.MapControl; + +/** + * The undo/redo stack that is used when undoing/redoing operations. + * Every operation should add itself to the stack using the add() method. + * @author <a href="mailto:mic...@no...">Michael Toennies</a> + */ +public final class CUndoStack { + + /** The controller of the undo stack model. */ + private static MainControl mainControl; + + /** The shared hashtable that maps levels to undo stacks. */ + private static final Map<MapControl, CUndoStack> hashFromLevelToStack = new WeakHashMap<MapControl, CUndoStack>(); + + /** The undo stack. Contains all undoable operations. */ + private final List<Undoable> undoStack = new ArrayList<Undoable>(); + + /** The redo stack. Contains all redoable operations. */ + private final List<Undoable> redoStack = new ArrayList<Undoable>(); + + /** The maximum size of the stacks. */ + private int maxStackSize = 10; + + /** + * Returns the undo stack for the given level controller. + * @param mapControl the level whose undo/redo stack is to be returned + * @return the undo/redo stack for the given level + */ + public static CUndoStack getInstance(final MapControl mapControl) { + if (hashFromLevelToStack.containsKey(mapControl)) { + return hashFromLevelToStack.get(mapControl); + } + + final CUndoStack instance = new CUndoStack(); + hashFromLevelToStack.put(mapControl, instance); + return instance; + } + + /** + * Sets the main controller of all undo/redo stack models. + * @param mainControl the controller of all undo/redo stacks + */ + public static void setMainControl(final MainControl mainControl) { + CUndoStack.mainControl = mainControl; + } + + /** Constructs an undo/redo stack. */ + private CUndoStack() { + } + + /** + * Returns the maximum stack size. + * @return the maximum stack size + */ + int getMaxStackSize() { + return maxStackSize; + } + + /** + * Sets the maximum stack size. + * @param size the new maximum stack size + */ + void setMaxStackSize(final int size) { + maxStackSize = size; + } + + /** + * Adds a new undoable/redoable operation to the undo/redo stack. + * @param undoOp the new operation to be added to the stack + */ + public void add(final Undoable undoOp) { + undoStack.add(undoOp); + redoStack.clear(); + if (undoStack.size() > maxStackSize) { + undoStack.remove(0); + } + + if (mainControl != null) { + mainControl.refreshMenusAndToolbars(); + } + } + + /** + * Returns whether the last operation in the undo stack can be undone. + * @return <code>true</code> if the last operation in the undo stack can be + * undone, <code>false</code> if not + */ + public boolean canUndo() { + if (undoStack.size() > 0) { + final Undoable op = undoStack.get(undoStack.size() - 1); + return op.isUndoable(); + } + + return false; + } + + /** + * Returns the name of the last operation in the undo stack. + * @return the name of the last operation in the undo stack + */ + public String getUndoName() { + if (canUndo()) { + final Undoable op = undoStack.get(undoStack.size() - 1); + return op.getName(); + } + + return ""; + } + + /** Undoes the last operation in the undo stack. */ + public void undo() { + if (canUndo()) { + final Undoable op = undoStack.get(undoStack.size() - 1); + undoStack.remove(op); + op.undo(); + redoStack.add(op); + + if (mainControl != null) { + mainControl.refreshMenusAndToolbars(); + } + } + } + + /** + * Returns whether the last operation in the redo stack can be redone. + * @return <code>true</code> if the last operation in the redo stack can be + * redone, <code>false</code> if not + */ + public boolean canRedo() { + if (redoStack.size() > 0) { + final Undoable op = redoStack.get(redoStack.size() - 1); + return op.isRedoable(); + } + + return false; + } + + /** + * Returns the name of the last operation in the redo stack. + * @return the name of the last operation in the redo stack + */ + public String getRedoName() { + if (canRedo()) { + final Undoable op = redoStack.get(redoStack.size() - 1); + return op.getName(); + } + + return ""; + } + + /** Redoes the last operation in the redo stack. */ + public void redo() { + if (canRedo()) { + final Undoable op = redoStack.get(redoStack.size() - 1); + redoStack.remove(op); + op.redo(); + undoStack.add(op); + + if (mainControl != null) { + mainControl.refreshMenusAndToolbars(); + } + } + } + +} // class CUndoStack Property changes on: trunk/src/app/net/sf/gridarta/CUndoStack.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Added: trunk/src/app/net/sf/gridarta/MainControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/MainControl.java (rev 0) +++ trunk/src/app/net/sf/gridarta/MainControl.java 2006-09-10 22:21:43 UTC (rev 321) @@ -0,0 +1,17 @@ +package net.sf.gridarta; + +/** + * This interface is only for unification. + * It should become obsolete after a while. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @deprecated don't intentionally use this for other than unification purposes. + */ +@Deprecated public interface MainControl { + + /** + * Refresh menus and toolbars. + * @deprecated This method is bullshit for being a severe violation of MVC and therefore MUST be removed some day. Do not use it for other than unification purposes. + */ + void refreshMenusAndToolbars(); + +} // interface MainControl Property changes on: trunk/src/app/net/sf/gridarta/MainControl.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Added: trunk/src/app/net/sf/gridarta/map/MapControl.java =================================================================== --- trunk/src/app/net/sf/gridarta/map/MapControl.java (rev 0) +++ trunk/src/app/net/sf/gridarta/map/MapControl.java 2006-09-10 22:21:43 UTC (rev 321) @@ -0,0 +1,9 @@ +package net.sf.gridarta.map; + +/** + * Currently nothing more than a marker interface for unification. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public interface MapControl { + +} // interface MapControl Property changes on: trunk/src/app/net/sf/gridarta/map/MapControl.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: <chr...@us...> - 2006-09-10 22:09:00
|
Revision: 320 http://svn.sourceforge.net/gridarta/?rev=320&view=rev Author: christianhujer Date: 2006-09-10 15:08:50 -0700 (Sun, 10 Sep 2006) Log Message: ----------- Sorted imports. Modified Paths: -------------- trunk/crossfire/src/cfeditor/map/DefaultMapModel.java trunk/daimonin/src/daieditor/map/DefaultMapModel.java Modified: trunk/crossfire/src/cfeditor/map/DefaultMapModel.java =================================================================== --- trunk/crossfire/src/cfeditor/map/DefaultMapModel.java 2006-09-10 21:58:29 UTC (rev 319) +++ trunk/crossfire/src/cfeditor/map/DefaultMapModel.java 2006-09-10 22:08:50 UTC (rev 320) @@ -40,8 +40,8 @@ import java.util.List; import net.sf.gridarta.Size2D; import org.apache.log4j.Logger; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.annotations.NotNull; /** * The level model that represents a level. Modified: trunk/daimonin/src/daieditor/map/DefaultMapModel.java =================================================================== --- trunk/daimonin/src/daieditor/map/DefaultMapModel.java 2006-09-10 21:58:29 UTC (rev 319) +++ trunk/daimonin/src/daieditor/map/DefaultMapModel.java 2006-09-10 22:08:50 UTC (rev 320) @@ -36,14 +36,12 @@ import java.util.Iterator; import java.util.List; import java.util.NoSuchElementException; -import java.io.IOException; -import java.io.ObjectInputStream; import javax.swing.event.EventListenerList; import net.sf.gridarta.Size2D; import net.sf.japi.swing.ActionFactory; import static net.sf.japi.swing.ActionFactory.getFactory; -import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * The level model that represents a level. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-09-10 21:58:34
|
Revision: 319 http://svn.sourceforge.net/gridarta/?rev=319&view=rev Author: christianhujer Date: 2006-09-10 14:58:29 -0700 (Sun, 10 Sep 2006) Log Message: ----------- Changed embedded HTML to be lowercase only (conforming to XHTML). Modified Paths: -------------- trunk/crossfire/src/cfeditor/JFontChooser.java Modified: trunk/crossfire/src/cfeditor/JFontChooser.java =================================================================== --- trunk/crossfire/src/cfeditor/JFontChooser.java 2006-09-10 20:30:15 UTC (rev 318) +++ trunk/crossfire/src/cfeditor/JFontChooser.java 2006-09-10 21:58:29 UTC (rev 319) @@ -346,11 +346,11 @@ String new_msg = ""; // return value: new message with html tags while (msg.indexOf("\n") >= 0) { new_msg = new_msg + "<html><font color=black size=\"" + getHtmlSize(f.getSize()) + - "\" face=\"" + f.getFontName() + "\"><B>" + msg.substring(0, msg.indexOf("\n")) + "</B></font></html>§"; + "\" face=\"" + f.getFontName() + "\"><b>" + msg.substring(0, msg.indexOf("\n")) + "</b></font></html>§"; msg = msg.substring(msg.indexOf("\n") + 1); } new_msg = new_msg + "<html><font color=black size=\"" + getHtmlSize(f.getSize()) + - "\" face=\"" + f.getFontName() + "\"><B>" + msg + "</B></font></html>"; + "\" face=\"" + f.getFontName() + "\"><b>" + msg + "</b></font></html>"; new_msg = new_msg.replace('§', '\n'); return new_msg; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-09-10 20:30:31
|
Revision: 318 http://svn.sourceforge.net/gridarta/?rev=318&view=rev Author: christianhujer Date: 2006-09-10 13:30:15 -0700 (Sun, 10 Sep 2006) Log Message: ----------- Updated test cases to JUnit 4.0 (IntelliJ IDEA users update to IntelliJ IDEA 6.0). Modified Paths: -------------- trunk/src/test/net/sf/gridarta/Size2DTest.java trunk/src/test/net/sf/gridarta/gui/HideFileFilterProxyTest.java Modified: trunk/src/test/net/sf/gridarta/Size2DTest.java =================================================================== --- trunk/src/test/net/sf/gridarta/Size2DTest.java 2006-09-10 20:28:25 UTC (rev 317) +++ trunk/src/test/net/sf/gridarta/Size2DTest.java 2006-09-10 20:30:15 UTC (rev 318) @@ -1,33 +1,25 @@ package test.net.sf.gridarta; import net.sf.gridarta.Size2D; -import junit.framework.TestCase; +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; /** * Test for {@link Size2D}. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ -public class Size2DTest extends TestCase { +public class Size2DTest { - /** {@inheritDoc} */ - @Override public void setUp() throws Exception { - super.setUp(); - } - - /** {@inheritDoc} */ - @Override public void tearDown() throws Exception { - super.tearDown(); - } - /** Test case for {@link Size2D#Size2D(int, int)}. */ - public void testSize2D() throws Exception { + @Test public void testSize2D() { final Size2D size = new Size2D(100, 200); assertEquals("width MUST be stored", 100, size.getWidth()); assertEquals("height MUST be stored", 200, size.getHeight()); } /** Test case for {@link Size2D#equals(Object)}. */ - public void testEquals() throws Exception { + @Test public void testEquals() { final Size2D size1 = new Size2D(100, 200); final Size2D size2 = new Size2D(100, 200); final Size2D size3 = new Size2D(100, 200); @@ -46,20 +38,20 @@ } /** Test case for {@link Size2D#hashCode()}. */ - public void testHashCode() throws Exception { + @Test public void testHashCode() { final Size2D size1 = new Size2D(100, 200); final Size2D size2 = new Size2D(100, 200); assertEquals("Equal sizes MUST return the same hashCode.", size1.hashCode(), size2.hashCode()); } /** Test case for {@link Size2D#getWidth()}. */ - public void testGetWidth() throws Exception { + @Test public void testGetWidth() { final Size2D size = new Size2D(100, 200); assertEquals("width MUST be stored", 100, size.getWidth()); } /** Test case for {@link Size2D#getHeight()}. */ - public void testGetHeight() throws Exception { + @Test public void testGetHeight() { final Size2D size = new Size2D(100, 200); assertEquals("height MUST be stored", 200, size.getHeight()); } Modified: trunk/src/test/net/sf/gridarta/gui/HideFileFilterProxyTest.java =================================================================== --- trunk/src/test/net/sf/gridarta/gui/HideFileFilterProxyTest.java 2006-09-10 20:28:25 UTC (rev 317) +++ trunk/src/test/net/sf/gridarta/gui/HideFileFilterProxyTest.java 2006-09-10 20:30:15 UTC (rev 318) @@ -1,44 +1,32 @@ package test.net.sf.gridarta.gui; import java.io.File; -import junit.framework.TestCase; import net.sf.gridarta.gui.HideFileFilterProxy; import net.sf.japi.util.filter.file.AbstractFileFilter; +import org.junit.Test; +import static org.junit.Assert.fail; /** * Test for {@link HideFileFilterProxy}. - * * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ -public class HideFileFilterProxyTest extends TestCase { +public class HideFileFilterProxyTest { /** Object Under Test: A HideFileFilterProxy. */ private HideFileFilterProxy oUT; - /** {@inheritDoc} */ - @Override public void setUp() throws Exception { - super.setUp(); - //oUT = new HideFileFilterProxy(); - } - - /** {@inheritDoc} */ - @Override public void tearDown() throws Exception { - super.tearDown(); - oUT = null; - } - /** Test case for {@link HideFileFilterProxy#HideFileFilterProxy(AbstractFileFilter)}. */ - public void testHideFileFilterProxy() throws Exception { + @Test public void testHideFileFilterProxy() throws Exception { fail("Test is not implemented"); // TODO: Test goes here... } /** Test case for {@link HideFileFilterProxy#getDescription()}. */ - public void testGetDescription() throws Exception { + @Test public void testGetDescription() throws Exception { fail("Test is not implemented"); // TODO: Test goes here... } /** Test case for {@link HideFileFilterProxy#accept(File)}. */ - public void testAccept() throws Exception { + @Test public void testAccept() throws Exception { fail("Test is not implemented"); // TODO: Test goes here... } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-09-10 20:28:30
|
Revision: 317 http://svn.sourceforge.net/gridarta/?rev=317&view=rev Author: christianhujer Date: 2006-09-10 13:28:25 -0700 (Sun, 10 Sep 2006) Log Message: ----------- More specific type for getMapArch(). Modified Paths: -------------- trunk/src/app/net/sf/gridarta/map/MapModel.java Modified: trunk/src/app/net/sf/gridarta/map/MapModel.java =================================================================== --- trunk/src/app/net/sf/gridarta/map/MapModel.java 2006-09-10 18:32:58 UTC (rev 316) +++ trunk/src/app/net/sf/gridarta/map/MapModel.java 2006-09-10 20:28:25 UTC (rev 317) @@ -44,6 +44,6 @@ * Returns the Map Arch Object with the meta information about the map. * @return the Map Arch Object with the meta information about the map */ - Object getMapArchObject(); + MapArchObject getMapArchObject(); } // interface MapModel This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-09-10 18:33:17
|
Revision: 316 http://svn.sourceforge.net/gridarta/?rev=316&view=rev Author: christianhujer Date: 2006-09-10 11:32:58 -0700 (Sun, 10 Sep 2006) Log Message: ----------- More MapArchObject unification. Modified Paths: -------------- trunk/crossfire/src/cfeditor/map/MapArchObject.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 Modified: trunk/crossfire/src/cfeditor/map/MapArchObject.java =================================================================== --- trunk/crossfire/src/cfeditor/map/MapArchObject.java 2006-09-10 16:21:15 UTC (rev 315) +++ trunk/crossfire/src/cfeditor/map/MapArchObject.java 2006-09-10 18:32:58 UTC (rev 316) @@ -30,7 +30,6 @@ import java.io.IOException; import net.sf.gridarta.Size2D; import net.sf.gridarta.map.AbstractMapArchObject; -import org.jetbrains.annotations.NotNull; /** * MapArchObject contains the specific meta data about a map that is stored in @@ -39,7 +38,7 @@ * ordinary ArchObject, but that's just no longer appropriate. * @author <a href="mailto:and...@gm...">Andreas Vogl</a> */ -public final class MapArchObject extends AbstractMapArchObject { +@SuppressWarnings({"HardcodedLineSeparator"}) public final class MapArchObject extends AbstractMapArchObject { // tags which appear in the map header private static final String TAG_START_LORE = "maplore"; @@ -53,34 +52,6 @@ private final StringBuffer loreText = new StringBuffer(""); // lore text buffer - /** Number of seconds that need to elapse before this map will be reset. */ - private int resetTimeout; - - /** - * Number of ticks that must elapse after tha map has not been used before - * it gets swapped out. - */ - private int swapTime; - - /** - * Map difficulty. If zero, server calculates something. - */ - private int difficulty; - - /** - * If nonzero, the map reset time will not be updated when someone enters / - * exits the map. - */ - private boolean fixedReset; - - /** - * Light / darkness of map (overall). Zero means fully bright. - */ - private int darkness; - - /** If set, this entire map is unique. */ - private boolean unique; - /** If set, this entire map is a template map. */ private boolean template; @@ -137,21 +108,12 @@ * All fields will be set to reasonable default values. */ public MapArchObject() { - resetTimeout = 0; - swapTime = 0; - difficulty = 0; - darkness = 0; for (int i = 0; i < MAX_TILE; i++) { tilePaths[i] = ""; } - - fixedReset = false; - unique = false; template = false; outdoor = false; nosmooth = false; - - // iso flags } /** @@ -173,54 +135,6 @@ setMapSize(mapSize); } - public int getResetTimeout() { - return resetTimeout; - } - - public void setResetTimeout(final int resetTimeout) { - this.resetTimeout = resetTimeout; - } - - public int getSwapTime() { - return swapTime; - } - - public void setSwapTime(final int swapTime) { - this.swapTime = swapTime; - } - - public int getDifficulty() { - return difficulty; - } - - public void setDifficulty(final int difficulty) { - this.difficulty = difficulty; - } - - public boolean isFixedReset() { - return fixedReset; - } - - public void setFixedReset(final boolean fixedReset) { - this.fixedReset = fixedReset; - } - - public int getDarkness() { - return darkness; - } - - public void setDarkness(final int darkness) { - this.darkness = darkness; - } - - public boolean isUnique() { - return unique; - } - - public void setUnique(final boolean unique) { - this.unique = unique; - } - public boolean isTemplate() { return template; } @@ -457,20 +371,20 @@ } else if (line.startsWith("enter_y") || line.startsWith("sp")) { setEnterY(getLineValue(line)); } else if (line.startsWith("reset_timeout") || line.startsWith("weight")) { - resetTimeout = getLineValue(line); + setResetTimeout(getLineValue(line)); } else if (line.startsWith("swap_time") || line.startsWith("value")) { - swapTime = getLineValue(line); + setSwapTime(getLineValue(line)); } else if (line.startsWith("difficulty") || line.startsWith("level")) { - difficulty = getLineValue(line); + setDifficulty(getLineValue(line)); } else if (line.startsWith("darkness") || line.startsWith("invisible")) { - darkness = getLineValue(line); + setDarkness(getLineValue(line)); } else if (line.startsWith("fixed_resettime") || line.startsWith("stand_still")) { if (getLineValue(line) != 0) { - fixedReset = true; + setFixedReset(true); } } else if (line.startsWith("unique")) { if (getLineValue(line) != 0) { - unique = true; + setUnique(true); } } else if (line.startsWith("template")) { if (getLineValue(line) != 0) { @@ -574,60 +488,60 @@ stream.append("arch map\n"); if (getMapName().length() > 0) { - stream.append("name " + getMapName() + "\n"); + stream.append("name ").append(getMapName()).append("\n"); } - if (swapTime > 0) { - stream.append("swap_time " + swapTime + "\n"); + if (getSwapTime() > 0) { + stream.append("swap_time ").append(String.valueOf(getSwapTime())).append("\n"); } - if (resetTimeout > 0) { - stream.append("reset_timeout " + resetTimeout + "\n"); + if (getResetTimeout() > 0) { + stream.append("reset_timeout ").append(String.valueOf(getResetTimeout())).append("\n"); } - if (fixedReset) { + if (isFixedReset()) { stream.append("fixed_resettime 1\n"); } - if (difficulty > 0) { - stream.append("difficulty " + difficulty + "\n"); + if (getDifficulty() > 0) { + stream.append("difficulty ").append(String.valueOf(getDifficulty())).append("\n"); } if (region.length() > 0) { - stream.append("region " + region + "\n"); + stream.append("region ").append(region).append("\n"); } if (shopitems.length() > 0) { - stream.append("shopitems " + shopitems + "\n"); + stream.append("shopitems ").append(shopitems).append("\n"); } if (shopgreed != 0) { - stream.append("shopgreed " + shopgreed + "\n"); + stream.append("shopgreed ").append(String.valueOf(shopgreed)).append("\n"); } if (shopmin != 0) { - stream.append("shopmin " + shopmin + "\n"); + stream.append("shopmin ").append(String.valueOf(shopmin)).append("\n"); } if (shopmax != 0) { - stream.append("shopmax " + shopmax + "\n"); + stream.append("shopmax ").append(String.valueOf(shopmax)).append("\n"); } if (shoprace.length() > 0) { - stream.append("shoprace " + shoprace + "\n"); + stream.append("shoprace ").append(shoprace).append("\n"); } - if (darkness > 0) { - stream.append("darkness " + darkness + "\n"); + if (getDarkness() > 0) { + stream.append("darkness ").append(String.valueOf(getDarkness())).append("\n"); } - stream.append("width " + getMapSize().getWidth() + "\n"); - stream.append("height " + getMapSize().getHeight() + "\n"); + stream.append("width ").append(String.valueOf(getMapSize().getWidth())).append("\n"); + stream.append("height ").append(String.valueOf(getMapSize().getHeight())).append("\n"); if (getEnterX() > 0) { - stream.append("enter_x " + getEnterX() + "\n"); + stream.append("enter_x ").append(String.valueOf(getEnterX())).append("\n"); } if (getEnterY() > 0) { - stream.append("enter_y " + getEnterY() + "\n"); + stream.append("enter_y ").append(String.valueOf(getEnterY())).append("\n"); } if (msgText.length() > 0 && msgText.toString().trim().length() > 0) { stream.append(TAG_START_TEXT + "\n"); - stream.append(msgText.toString().trim() + "\n"); + stream.append(msgText.toString().trim()).append("\n"); stream.append(TAG_END_TEXT + "\n"); } if (loreText.length() > 0 && loreText.toString().trim().length() > 0) { stream.append(TAG_START_LORE + "\n"); - stream.append(loreText.toString().trim() + "\n"); + stream.append(loreText.toString().trim()).append("\n"); stream.append(TAG_END_LORE + "\n"); } - if (unique) { + if (isUnique()) { stream.append("unique 1\n"); } if (template) { @@ -637,26 +551,26 @@ stream.append("outdoor 1\n"); } if (temp != 0) { - stream.append("temp " + temp + "\n"); + stream.append("temp ").append(String.valueOf(temp)).append("\n"); } if (pressure != 0) { - stream.append("pressure " + pressure + "\n"); + stream.append("pressure ").append(String.valueOf(pressure)).append("\n"); } if (humid != 0) { - stream.append("humid " + humid + "\n"); + stream.append("humid ").append(String.valueOf(humid)).append("\n"); } if (windspeed != 0) { - stream.append("windspeed " + windspeed + "\n"); + stream.append("windspeed ").append(String.valueOf(windspeed)).append("\n"); } if (winddir != 0) { - stream.append("winddir " + winddir + "\n"); + stream.append("winddir ").append(String.valueOf(winddir)).append("\n"); } if (sky != 0) { - stream.append("sky " + sky + "\n"); + stream.append("sky ").append(String.valueOf(sky)).append("\n"); } for (i = 0; i < MAX_TILE; i++) { if (tilePaths[i].length() > 0) { - stream.append("tile_path_" + (i + 1) + " " + tilePaths[i] + "\n"); + stream.append("tile_path_").append(String.valueOf(i + 1)).append(" ").append(tilePaths[i]).append("\n"); } } if (nosmooth) { Modified: trunk/daimonin/src/daieditor/map/MapArchObject.java =================================================================== --- trunk/daimonin/src/daieditor/map/MapArchObject.java 2006-09-10 16:21:15 UTC (rev 315) +++ trunk/daimonin/src/daieditor/map/MapArchObject.java 2006-09-10 18:32:58 UTC (rev 316) @@ -24,7 +24,6 @@ package daieditor.map; -import static daieditor.IGUIConstants.DEF_MAPFNAME; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; @@ -46,7 +45,7 @@ * @todo This class should be changed so map attributes are reflected in a more * generic way like arch attributes. */ -public final class MapArchObject extends AbstractMapArchObject implements Serializable { +@SuppressWarnings({"HardcodedLineSeparator"}) public final class MapArchObject extends AbstractMapArchObject implements Serializable { /** Serial Version. */ private static final long serialVersionUID = 1L; @@ -54,34 +53,6 @@ // map attributes: private final StringBuffer msgText = new StringBuffer(); // map-msg text buffer - /** Number of seconds that need to elapse before this map will be reset. */ - private int resetTimeout; - - /** - * Number of ticks that must elapse after tha map has not been used before - * it gets swapped out. - */ - private int swapTime; - - /** - * Map difficulty. If zero, server calculates something. - */ - private int difficulty; - - /** - * If nonzero, the map reset time will not be updated when someone enters / - * exits the map. - */ - private boolean fixedReset; - - /** - * Light / darkness of map (overall). Zero means fully bright. - */ - private int darkness = -1; - - /** If set, this entire map is unique. */ - private boolean unique; - /** If set, this is an outdoor map. */ private boolean outdoor; @@ -163,54 +134,6 @@ return t1 > 0 && t2 > t1 ? getMapName().substring(t1 + 1, t2) : null; } - public int getResetTimeout() { - return resetTimeout; - } - - public void setResetTimeout(final int resetTimeout) { - this.resetTimeout = resetTimeout; - } - - public int getSwapTime() { - return swapTime; - } - - public void setSwapTime(final int swapTime) { - this.swapTime = swapTime; - } - - public int getDifficulty() { - return difficulty; - } - - public void setDifficulty(final int difficulty) { - this.difficulty = difficulty < 1 ? 1 : difficulty; - } - - public boolean isFixedReset() { - return fixedReset; - } - - public void setFixedReset(final boolean fixedReset) { - this.fixedReset = fixedReset; - } - - public int getDarkness() { - return darkness; - } - - public void setDarkness(final int darkness) { - this.darkness = darkness; - } - - public boolean isUnique() { - return unique; - } - - public void setUnique(final boolean unique) { - this.unique = unique; - } - public boolean isOutdoor() { return outdoor; } @@ -376,20 +299,20 @@ } else if (line.startsWith("enter_y ")) { setEnterY(getLineValue(line)); } else if (line.startsWith("reset_timeout ")) { - resetTimeout = getLineValue(line); + setResetTimeout(getLineValue(line)); } else if (line.startsWith("swap_time ")) { - swapTime = getLineValue(line); + setSwapTime(getLineValue(line)); } else if (line.startsWith("difficulty ")) { setDifficulty(getLineValue(line)); } else if (line.startsWith("darkness ")) { - darkness = getLineValue(line); + setDarkness(getLineValue(line)); } else if (line.startsWith("fixed_resettime ")) { if (getLineValue(line) != 0) { - fixedReset = true; + setFixedReset(true); } } else if (line.startsWith("unique ")) { if (getLineValue(line) != 0) { - unique = true; + setUnique(true); } } else if (line.startsWith("outdoor ")) { if (getLineValue(line) != 0) { @@ -495,39 +418,39 @@ stream.append("arch map\n"); if (getMapName().length() > 0) { - stream.append("name " + getMapName() + '\n'); + stream.append("name ").append(getMapName()).append('\n'); } // maptext stream.append(TAG_START_TEXT + '\n'); - stream.append(msgText.toString().trim() + '\n'); + stream.append(msgText.toString().trim()).append('\n'); stream.append(TAG_END_TEXT + '\n'); - stream.append("width " + getMapSize().getWidth() + '\n'); - stream.append("height " + getMapSize().getHeight() + '\n'); + stream.append("width ").append(String.valueOf(getMapSize().getWidth())).append('\n'); + stream.append("height ").append(String.valueOf(getMapSize().getHeight())).append('\n'); if (getEnterX() > 0) { - stream.append("enter_x " + getEnterX() + '\n'); + stream.append("enter_x ").append(String.valueOf(getEnterX())).append('\n'); } if (getEnterY() > 0) { - stream.append("enter_y " + getEnterY() + '\n'); + stream.append("enter_y ").append(String.valueOf(getEnterY())).append('\n'); } - if (resetTimeout > 0) { - stream.append("resetTimeout " + resetTimeout + '\n'); + if (getResetTimeout() > 0) { + stream.append("resetTimeout ").append(String.valueOf(getResetTimeout())).append('\n'); } - if (swapTime > 0) { - stream.append("swap_time " + swapTime + '\n'); + if (getSwapTime() > 0) { + stream.append("swap_time ").append(String.valueOf(getSwapTime())).append('\n'); } - if (difficulty > 0) { - stream.append("difficulty " + difficulty + '\n'); + if (getDifficulty() > 0) { + stream.append("difficulty ").append(String.valueOf(getDifficulty())).append('\n'); } - if (darkness >= 0) { - stream.append("darkness " + darkness + '\n'); + if (getDarkness() >= 0) { + stream.append("darkness ").append(String.valueOf(getDarkness())).append('\n'); } - if (fixedReset) { + if (isFixedReset()) { stream.append("fixed_resettime 1\n"); } - if (unique) { + if (isUnique()) { stream.append("unique 1\n"); } if (outdoor) { Modified: trunk/src/app/net/sf/gridarta/map/AbstractMapArchObject.java =================================================================== --- trunk/src/app/net/sf/gridarta/map/AbstractMapArchObject.java 2006-09-10 16:21:15 UTC (rev 315) +++ trunk/src/app/net/sf/gridarta/map/AbstractMapArchObject.java 2006-09-10 18:32:58 UTC (rev 316) @@ -10,13 +10,13 @@ public abstract class AbstractMapArchObject implements MapArchObject { /** The size of the map reflected by this MapArchObject. */ - private Size2D mapSize = Size2D.ONE; + @NotNull private Size2D mapSize = Size2D.ONE; /** The name of this map. */ - private String mapName = "<unnamed>"; + @NotNull private String mapName = "<unnamed>"; /** The filename of this map. */ - private String fileName = "<new map>"; + @NotNull private String fileName = "<new map>"; /** The x coordinate for entering the map. */ private int enterX; @@ -24,6 +24,40 @@ /** The y coordinate for entering the map. */ private int enterY; + /** Number of seconds that need to elapse before this map will be reset. */ + private int resetTimeout; + + /** + * Number of ticks that must elapse after tha map has not been used before + * it gets swapped out. + */ + private int swapTime; + + /** + * Map difficulty. If zero, server calculates something. + */ + private int difficulty; + + /** + * If nonzero, the map reset time will not be updated when someone enters / + * exits the map. + */ + private boolean fixedReset; + + /** + * Light / darkness of map (overall). Zero means fully bright. + */ + private int darkness; + + /** If set, this entire map is unique. */ + private boolean unique; + + /** + * Create an AbstractMapArchObject. + */ + protected AbstractMapArchObject() { + } + /** {@inheritDoc} */ @NotNull public final Size2D getMapSize() { return mapSize; @@ -45,12 +79,12 @@ } /** {@inheritDoc} */ - public final String getFileName() { + @NotNull public final String getFileName() { return fileName; } /** {@inheritDoc} */ - public final void setFileName(final String fileName) { + public final void setFileName(@NotNull final String fileName) { this.fileName = fileName; } @@ -74,4 +108,64 @@ this.enterY = enterY; } + /** {@inheritDoc} */ + public int getResetTimeout() { + return resetTimeout; + } + + /** {@inheritDoc} */ + public void setResetTimeout(final int resetTimeout) { + this.resetTimeout = resetTimeout; + } + + /** {@inheritDoc} */ + public int getSwapTime() { + return swapTime; + } + + /** {@inheritDoc} */ + public void setSwapTime(final int swapTime) { + this.swapTime = swapTime; + } + + /** {@inheritDoc} */ + public int getDifficulty() { + return difficulty; + } + + /** {@inheritDoc} */ + public void setDifficulty(final int difficulty) { + this.difficulty = difficulty < 1 ? 1 : difficulty; + } + + /** {@inheritDoc} */ + public boolean isFixedReset() { + return fixedReset; + } + + /** {@inheritDoc} */ + public void setFixedReset(final boolean fixedReset) { + this.fixedReset = fixedReset; + } + + /** {@inheritDoc} */ + public int getDarkness() { + return darkness; + } + + /** {@inheritDoc} */ + public void setDarkness(final int darkness) { + this.darkness = darkness; + } + + /** {@inheritDoc} */ + public boolean isUnique() { + return unique; + } + + /** {@inheritDoc} */ + public void setUnique(final boolean unique) { + this.unique = unique; + } + } // class AbstractMapArchObject Modified: trunk/src/app/net/sf/gridarta/map/MapArchObject.java =================================================================== --- trunk/src/app/net/sf/gridarta/map/MapArchObject.java 2006-09-10 16:21:15 UTC (rev 315) +++ trunk/src/app/net/sf/gridarta/map/MapArchObject.java 2006-09-10 18:32:58 UTC (rev 316) @@ -54,15 +54,16 @@ * Get the map filename. * @return map filename * @deprecated the filename isn't really an attribute of the MapArchObject. Only use MapControl for this. + * @todo if this remains here, think whether the fileName is really not null or whether a nullable filename makes more sense. */ - String getFileName(); + @NotNull String getFileName(); /** * Set the map fileName. * @param fileName new map fileName * @deprecated the fileName isn't really an attribute of the MapArchObject. Only use MapControl for this. */ - void setFileName(String fileName); + void setFileName(@NotNull String fileName); /** * Get enter x coordinate. @@ -88,4 +89,77 @@ */ void setEnterY(int enterY); + /** + * Get the reset timeout (in seconds). + * @return reset timeout (in seconds). + */ + int getResetTimeout(); + + /** + * Set the reset timeout (in seconds). + * @param resetTimeout new reset timeout (in seconds) + */ + void setResetTimeout(int resetTimeout); + + /** + * Get the swap time (in ticks). + * @return swap time (in ticks). + */ + int getSwapTime(); + + /** + * Set the swap time (in ticks). + * @param swapTime (in ticks) + */ + void setSwapTime(int swapTime); + + /** + * Get the map's difficulty. + * @return map's difficulty. + */ + int getDifficulty(); + + /** + * Set the map's difficulty. + * @param difficulty new difficulty for this map + */ + void setDifficulty(int difficulty); + + /** + * Get whether this map uses a fixed reset. + * @return whether this map uses a fixed reset. + */ + boolean isFixedReset(); + + /** + * Set whether this map uses a fixed reset. + * @param fixedReset whether this map should use a fixed reset + */ + void setFixedReset(boolean fixedReset); + + /** + * Get the light / darkness of this map. + * (0 means fully bright) + * @return light / darkness of this map + */ + int getDarkness(); + + /** + * Set the light / darkness of this map. + * @param darkness new light / darkness of this map + */ + void setDarkness(int darkness); + + /** + * Get whether this map is unique. + * @return whether this map is unique + */ + boolean isUnique(); + + /** + * Set whether this map is unique. + * @param unique whether this map should be unique + */ + void setUnique(boolean unique); + } // interface MapArchObject This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-09-10 16:21:22
|
Revision: 315 http://svn.sourceforge.net/gridarta/?rev=315&view=rev Author: christianhujer Date: 2006-09-10 09:21:15 -0700 (Sun, 10 Sep 2006) Log Message: ----------- Improved documentation of Size2D: Documented invariants. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/Size2D.java Modified: trunk/src/app/net/sf/gridarta/Size2D.java =================================================================== --- trunk/src/app/net/sf/gridarta/Size2D.java 2006-09-10 13:51:40 UTC (rev 314) +++ trunk/src/app/net/sf/gridarta/Size2D.java 2006-09-10 16:21:15 UTC (rev 315) @@ -24,6 +24,8 @@ /** * The class Size2D represents a 2d rectangular area. + * Sizes always are positive. + * This class doesn't allow zero or negative sizes. */ public final class Size2D implements Serializable { @@ -36,12 +38,14 @@ /** * The width of the area. * It is always greater than zero. + * @invariant width > 0 */ private final int width; /** * The height of the area. * It is always greater than zero. + * @invariant height > 0 */ private final int height; @@ -49,6 +53,7 @@ * Create a new Size2D. * @param width the width of the area; must be greater than zero * @param height the height of the area; must be greater than zero + * @throws IllegalArgumentException in case <var>width</var> or <var>height</var> is less than 1. */ public Size2D(final int width, final int height) { if (width < 1) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-09-10 13:51:47
|
Revision: 314 http://svn.sourceforge.net/gridarta/?rev=314&view=rev Author: christianhujer Date: 2006-09-10 06:51:40 -0700 (Sun, 10 Sep 2006) Log Message: ----------- Fixed bug during application loading. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/Size2D.java trunk/src/app/net/sf/gridarta/map/AbstractMapArchObject.java Modified: trunk/src/app/net/sf/gridarta/Size2D.java =================================================================== --- trunk/src/app/net/sf/gridarta/Size2D.java 2006-09-10 08:05:13 UTC (rev 313) +++ trunk/src/app/net/sf/gridarta/Size2D.java 2006-09-10 13:51:40 UTC (rev 314) @@ -31,7 +31,7 @@ private static final long serialVersionUID = 1L; /** Zero size object. */ - public static final Size2D ZERO = new Size2D(0, 0); + public static final Size2D ONE = new Size2D(1, 1); /** * The width of the area. Modified: trunk/src/app/net/sf/gridarta/map/AbstractMapArchObject.java =================================================================== --- trunk/src/app/net/sf/gridarta/map/AbstractMapArchObject.java 2006-09-10 08:05:13 UTC (rev 313) +++ trunk/src/app/net/sf/gridarta/map/AbstractMapArchObject.java 2006-09-10 13:51:40 UTC (rev 314) @@ -2,7 +2,6 @@ import org.jetbrains.annotations.NotNull; import net.sf.gridarta.Size2D; -import net.sf.gridarta.CommonConstants; /** * Base implementation of {@link MapArchObject} that covers similarities between Crossfire maps and Daimonin maps. @@ -11,7 +10,7 @@ public abstract class AbstractMapArchObject implements MapArchObject { /** The size of the map reflected by this MapArchObject. */ - private Size2D mapSize = Size2D.ZERO; + private Size2D mapSize = Size2D.ONE; /** The name of this map. */ private String mapName = "<unnamed>"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2006-09-10 08:05:17
|
Revision: 313 http://svn.sourceforge.net/gridarta/?rev=313&view=rev Author: akirschbaum Date: 2006-09-10 01:05:13 -0700 (Sun, 10 Sep 2006) Log Message: ----------- Whitespace fixes. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMapFileEncode.java Modified: trunk/crossfire/src/cfeditor/CMapFileEncode.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapFileEncode.java 2006-09-09 18:13:24 UTC (rev 312) +++ trunk/crossfire/src/cfeditor/CMapFileEncode.java 2006-09-10 08:05:13 UTC (rev 313) @@ -175,7 +175,7 @@ final String events = arch.getMapArchEventData(); if (!events.equals("")) { final String[] tmp = events.split("\n"); - for (int i = 0; i < tmp. length; i++) { + for (int i = 0; i < tmp.length; i++) { final String[] line = tmp[i].split(" +", 2); if (line.length != 2) { log.warn("writeMapArch: ignoring invalid event line: " + tmp[i]); @@ -246,7 +246,7 @@ final String text = arch.getArchText(); if (!text.equals("")) { final String[] tmp = text.split("\n"); - for (int i = 0; i < tmp. length; i++) { + for (int i = 0; i < tmp.length; i++) { final String[] line = tmp[i].split(" +", 2); if (line.length != 2) { log.warn("writeMapArch: ignoring invalid arch line: " + tmp[i]); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-09-09 18:13:55
|
Revision: 312 http://svn.sourceforge.net/gridarta/?rev=312&view=rev Author: christianhujer Date: 2006-09-09 11:13:24 -0700 (Sat, 09 Sep 2006) Log Message: ----------- MapArchObject unification. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/map/DefaultMapModel.java trunk/crossfire/src/cfeditor/map/MapArchObject.java trunk/crossfire/src/cfeditor/map/MapControl.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/MapViewIFrame.java trunk/daimonin/src/daieditor/gui/map/MapPropertiesDialog.java trunk/daimonin/src/daieditor/map/MapArchObject.java trunk/daimonin/src/daieditor/map/MapControl.java trunk/src/app/net/sf/gridarta/Size2D.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/map/AbstractMapArchObject.java trunk/src/app/net/sf/gridarta/map/MapArchObject.java Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-09-09 18:07:45 UTC (rev 311) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-09-09 18:13:24 UTC (rev 312) @@ -733,7 +733,7 @@ */ public MapControl newLevel(final List<ArchObject> objects, final MapArchObject maparch, final boolean show, final Point initial) { // Create a new level control and set the level view from that - CMainStatusbar.getInstance().setText(" Creating new map " + maparch.getMapName()); + CMainStatusbar.getInstance().setText(" Creating new map " + maparch.getMapDisplayName()); final MapControl map = new MapControl(this, objects, maparch, false, initial); if (show) { Modified: trunk/crossfire/src/cfeditor/map/DefaultMapModel.java =================================================================== --- trunk/crossfire/src/cfeditor/map/DefaultMapModel.java 2006-09-09 18:07:45 UTC (rev 311) +++ trunk/crossfire/src/cfeditor/map/DefaultMapModel.java 2006-09-09 18:13:24 UTC (rev 312) @@ -900,12 +900,12 @@ * @return the map name */ public String getMapName() { - return mapArch.getMapName(); + return mapArch.getMapDisplayName(); } /** ??? */ public String getMapNameWithoutMusic() { - return mapArch.getMapNameWithoutMusic(); + return mapArch.getMapDisplayName(); } /** Modified: trunk/crossfire/src/cfeditor/map/MapArchObject.java =================================================================== --- trunk/crossfire/src/cfeditor/map/MapArchObject.java 2006-09-09 18:07:45 UTC (rev 311) +++ trunk/crossfire/src/cfeditor/map/MapArchObject.java 2006-09-09 18:13:24 UTC (rev 312) @@ -29,6 +29,8 @@ import java.io.BufferedWriter; import java.io.IOException; import net.sf.gridarta.Size2D; +import net.sf.gridarta.map.AbstractMapArchObject; +import org.jetbrains.annotations.NotNull; /** * MapArchObject contains the specific meta data about a map that is stored in @@ -37,47 +39,20 @@ * ordinary ArchObject, but that's just no longer appropriate. * @author <a href="mailto:and...@gm...">Andreas Vogl</a> */ -public final class MapArchObject { +public final class MapArchObject extends AbstractMapArchObject { // tags which appear in the map header - private static final String TAG_START_TEXT = "msg"; - - private static final String TAG_END_TEXT = "endmsg"; - private static final String TAG_START_LORE = "maplore"; private static final String TAG_END_LORE = "endmaplore"; - // map name to display if a map has none - private static final String DEFAULT_MAP_NAME = "<untitled>"; - public static final int MAX_TILE = IGUIConstants.DIRECTIONS; - public static final int TILE_NORTH = IGUIConstants.NORTH; - - public static final int TILE_EAST = IGUIConstants.EAST; - - public static final int TILE_SOUTH = IGUIConstants.SOUTH; - - public static final int TILE_WEST = IGUIConstants.WEST; - - public static final int TILE_TOP = IGUIConstants.TOP; - - public static final int TILE_BOTTOM = IGUIConstants.BOTTOM; - // map attributes: private final StringBuffer msgText = new StringBuffer(""); // map-msg text buffer private final StringBuffer loreText = new StringBuffer(""); // lore text buffer - /** - * Map size. - */ - private Size2D mapSize = new Size2D(1, 1); - - /** Default enter coordinates (usage not recommended). */ - private int enterX, enterY; - /** Number of seconds that need to elapse before this map will be reset. */ private int resetTimeout; @@ -148,42 +123,6 @@ /** The maximum price the shop will trade for. */ private int shopmax; - /** No magic spells. */ - private boolean noMagic; - - /** No prayers. */ - private boolean noPriest; - - /** No harmful spells allowed. */ - private boolean noHarm; - - /** No summoning allowed. */ - private boolean noSummon; - - /** Check map reset status after re-login. */ - private boolean fixedLogin; - - /** Permanent death with revivable corpses. */ - private boolean permDeath; - - /** Permament death with corpses temporarily available. */ - private boolean ultraDeath; - - /** Permanent death with instant character deletion. */ - private boolean ultimateDeath; - - /** Player vs Player combat allowed. */ - private boolean pvp; - - /** Map name (this is the name that appears in the game). */ - private String name; - - /** - * Name of the map file. - * @todo check whether this is redundant. - */ - private String filename; - /** The region the map is in. */ private String region = ""; @@ -198,8 +137,6 @@ * All fields will be set to reasonable default values. */ public MapArchObject() { - enterX = 0; - enterY = 0; resetTimeout = 0; swapTime = 0; difficulty = 0; @@ -207,8 +144,6 @@ for (int i = 0; i < MAX_TILE; i++) { tilePaths[i] = ""; } - name = DEFAULT_MAP_NAME; // map creation enforces setting a real map name - filename = IGUIConstants.DEF_MAPFNAME; // default map file name fixedReset = false; unique = false; @@ -217,98 +152,27 @@ nosmooth = false; // iso flags - noMagic = false; - noPriest = false; - noSummon = false; - fixedLogin = false; - permDeath = false; - ultraDeath = false; - ultimateDeath = false; - pvp = false; } /** - * Get the map name without the background music that is attached to the - * map name. (This is for Daimonin only.) - * @return map name without attached music string + * {@inheritDoc} + * @note Crossfire currently doesn't store additional information in a map name. */ - public String getMapNameWithoutMusic() { - return name; + public String getMapDisplayName() { + return getMapName(); } /** - * Set map size. - * @param mapSize new map size - */ - public void setMapSize(final Size2D mapSize) { - if (mapSize == null) { - throw new IllegalArgumentException("No map size set"); - } - - this.mapSize = mapSize; - } - - /** * Ensure that the map size is at least the given size. * @param width the new minimum map width * @param height the new minimum map height */ public void ensureMapSize(final int width, final int height) { + Size2D mapSize = getMapSize(); mapSize = new Size2D(Math.max(mapSize.getWidth(), width), Math.max(mapSize.getHeight(), height)); + setMapSize(mapSize); } - public Size2D getMapSize() { - return mapSize; - } - - /** - * Get the map name. - * @return map name - */ - public String getMapName() { - return name; - } - - /** - * Set the map name. - * @param name new map name - */ - public void setMapName(final String name) { - this.name = name; - } - - /** - * Get the map filename. - * @return map filename - */ - public String getFileName() { - return filename; - } - - /** - * Set the map filename. - * @param filename new map filename - */ - public void setFileName(final String filename) { - this.filename = filename; - } - - public int getEnterX() { - return enterX; - } - - public void setEnterX(final int enterX) { - this.enterX = enterX; - } - - public int getEnterY() { - return enterY; - } - - public void setEnterY(final int enterY) { - this.enterY = enterY; - } - public int getResetTimeout() { return resetTimeout; } @@ -485,78 +349,6 @@ sky = t; } - public boolean isNoMagic() { - return noMagic; - } - - public void setNoMagic(final boolean noMagic) { - this.noMagic = noMagic; - } - - public boolean isNoPriest() { - return noPriest; - } - - public void setNoPriest(final boolean noPriest) { - this.noPriest = noPriest; - } - - public boolean isNoSummon() { - return noSummon; - } - - public void setNoSummon(final boolean noSummon) { - this.noSummon = noSummon; - } - - public boolean isNoHarm() { - return noHarm; - } - - public void setNoHarm(final boolean noHarm) { - this.noHarm = noHarm; - } - - public boolean isFixedLogin() { - return fixedLogin; - } - - public void setFixedLogin(final boolean fixedLogin) { - this.fixedLogin = fixedLogin; - } - - public boolean isPermDeath() { - return permDeath; - } - - public void setPermDeath(final boolean permDeath) { - this.permDeath = permDeath; - } - - public boolean isUltraDeath() { - return ultraDeath; - } - - public void setUltraDeath(final boolean ultraDeath) { - this.ultraDeath = ultraDeath; - } - - public boolean isUltimateDeath() { - return ultimateDeath; - } - - public void setUltimateDeath(final boolean ultimateDeath) { - this.ultimateDeath = ultimateDeath; - } - - public boolean isPvp() { - return pvp; - } - - public void setPvp(final boolean pvp) { - this.pvp = pvp; - } - /** * Append 'text' to the map text. * @param text string to add @@ -608,7 +400,7 @@ * otherwise false */ public boolean parseMapArch(final BufferedReader reader, final String fname) { - filename = fname; // store file name + setFileName(fname); String line2; // input line, includes leading and trailing white space boolean loreflag = false; // flag for lore-text boolean archflag = false; // flag for arch<->end @@ -653,7 +445,7 @@ } else if (line.equalsIgnoreCase("end")) { endReached = true; } else if (line.startsWith("name")) { - name = line.substring(line.indexOf(" ") + 1).trim(); + setMapName(line.substring(line.indexOf(" ") + 1).trim()); } else if (line.startsWith("region")) { region = line.substring(line.indexOf(" ") + 1).trim(); } else if (line.startsWith("width") || line.startsWith("x ")) { @@ -661,9 +453,9 @@ } else if (line.startsWith("height") || line.startsWith("y ")) { height = getLineValue(line); } else if (line.startsWith("enter_x") || line.startsWith("hp")) { - enterX = getLineValue(line); + setEnterX(getLineValue(line)); } else if (line.startsWith("enter_y") || line.startsWith("sp")) { - enterY = getLineValue(line); + setEnterY(getLineValue(line)); } else if (line.startsWith("reset_timeout") || line.startsWith("weight")) { resetTimeout = getLineValue(line); } else if (line.startsWith("swap_time") || line.startsWith("value")) { @@ -738,7 +530,7 @@ return false; } - mapSize = new Size2D(Math.max(1, width), Math.max(1, height)); + setMapSize(new Size2D(Math.max(1, width), Math.max(1, height))); return archflag; } @@ -781,8 +573,8 @@ int i; stream.append("arch map\n"); - if (name.length() > 0 && !name.equals(DEFAULT_MAP_NAME)) { - stream.append("name " + name + "\n"); + if (getMapName().length() > 0) { + stream.append("name " + getMapName() + "\n"); } if (swapTime > 0) { stream.append("swap_time " + swapTime + "\n"); @@ -817,13 +609,13 @@ if (darkness > 0) { stream.append("darkness " + darkness + "\n"); } - stream.append("width " + mapSize.getWidth() + "\n"); - stream.append("height " + mapSize.getHeight() + "\n"); - if (enterX > 0) { - stream.append("enter_x " + enterX + "\n"); + stream.append("width " + getMapSize().getWidth() + "\n"); + stream.append("height " + getMapSize().getHeight() + "\n"); + if (getEnterX() > 0) { + stream.append("enter_x " + getEnterX() + "\n"); } - if (enterY > 0) { - stream.append("enter_y " + enterY + "\n"); + if (getEnterY() > 0) { + stream.append("enter_y " + getEnterY() + "\n"); } if (msgText.length() > 0 && msgText.toString().trim().length() > 0) { stream.append(TAG_START_TEXT + "\n"); Modified: trunk/crossfire/src/cfeditor/map/MapControl.java =================================================================== --- trunk/crossfire/src/cfeditor/map/MapControl.java 2006-09-09 18:07:45 UTC (rev 311) +++ trunk/crossfire/src/cfeditor/map/MapControl.java 2006-09-09 18:13:24 UTC (rev 312) @@ -476,10 +476,10 @@ showTiles = show; if (show) { /*Do the tile maps loading :)*/ - final String north = mapModel.getMapArchObject().getTilePath(MapArchObject.TILE_NORTH); - final String west = mapModel.getMapArchObject().getTilePath(MapArchObject.TILE_WEST); - final String east = mapModel.getMapArchObject().getTilePath(MapArchObject.TILE_EAST); - final String south = mapModel.getMapArchObject().getTilePath(MapArchObject.TILE_SOUTH); + 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; Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2006-09-09 18:07:45 UTC (rev 311) +++ trunk/daimonin/src/daieditor/CMainControl.java 2006-09-09 18:13:24 UTC (rev 312) @@ -1009,7 +1009,7 @@ } if (!forced && level.isLevelChanged()) { - final int result = ACTION_FACTORY.showConfirmDialog(mainView, YES_NO_CANCEL_OPTION, WARNING_MESSAGE, "confirmSaveChanges", level.getMapArch().getMapNameWithoutMusic()); + final int result = ACTION_FACTORY.showConfirmDialog(mainView, YES_NO_CANCEL_OPTION, WARNING_MESSAGE, "confirmSaveChanges", level.getMapArch().getMapDisplayName()); if (result == YES_OPTION) { if (level.isPlainSaveEnabled()) { level.save(); @@ -1225,7 +1225,7 @@ newMap.setActiveEditType(tileEdit); // map is loaded with current view settings if (view) { refreshMenusAndToolbars(); - addRecent(currentMap.getMapArch().getMapNameWithoutMusic(), file.toString()); + addRecent(currentMap.getMapArch().getMapDisplayName(), file.toString()); } return newMap; } catch (final FileNotFoundException e) { Modified: trunk/daimonin/src/daieditor/MapViewIFrame.java =================================================================== --- trunk/daimonin/src/daieditor/MapViewIFrame.java 2006-09-09 18:07:45 UTC (rev 311) +++ trunk/daimonin/src/daieditor/MapViewIFrame.java 2006-09-09 18:13:24 UTC (rev 312) @@ -74,7 +74,7 @@ */ public MapViewIFrame(final CMainControl mainControl, final MapControl mapControl, final int number) { // set title - super(mapControl.getMapFileName() + " [ " + mapControl.getMapArch().getMapNameWithoutMusic() + " ] ("+ number + ')', true, true, true, true); + super(mapControl.getMapFileName() + " [ " + mapControl.getMapArch().getMapDisplayName() + " ] ("+ number + ')', true, true, true, true); this.mapControl = mapControl; this.mainControl = mainControl; viewNumber = number; @@ -109,7 +109,7 @@ } final StringBuilder strTitle = new StringBuilder(); - strTitle.append(mapControl.getMapFileName()).append(" [ ").append(mapControl.getMapArch().getMapNameWithoutMusic()).append(" ] ("); + strTitle.append(mapControl.getMapFileName()).append(" [ ").append(mapControl.getMapArch().getMapDisplayName()).append(" ] ("); strTitle.append(viewNumber).append(')'); if (view.isChanged()) { Modified: trunk/daimonin/src/daieditor/gui/map/MapPropertiesDialog.java =================================================================== --- trunk/daimonin/src/daieditor/gui/map/MapPropertiesDialog.java 2006-09-09 18:07:45 UTC (rev 311) +++ trunk/daimonin/src/daieditor/gui/map/MapPropertiesDialog.java 2006-09-09 18:13:24 UTC (rev 312) @@ -274,7 +274,7 @@ mapPanel.add(new JLabel(ACTION_FACTORY.getString("mapName")), labelGbc); mapName.setColumns(16); - mapName.setText(mapControl.getMapArch().getMapNameWithoutMusic()); + mapName.setText(mapControl.getMapArch().getMapDisplayName()); mapPanel.add(mapName, gbc); mapPanel.add(new JLabel(ACTION_FACTORY.getString("mapSound")), labelGbc); @@ -497,7 +497,7 @@ final MapArchObject map = mapControl.getMapModel().getMapArchObject(); // map arch object mapDescription.setText(mapArch.getText()); - mapName.setText(mapControl.getMapArch().getMapNameWithoutMusic()); + mapName.setText(mapControl.getMapArch().getMapDisplayName()); mapSound.setText(mapControl.getMapArch().getBackgroundMusic()); levelWidthField.setText(Integer.toString(map.getMapSize().getWidth())); levelHeightField.setText(Integer.toString(map.getMapSize().getHeight())); @@ -541,7 +541,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().getMapNameWithoutMusic(), level.getMapFileName())); + final JDialog dialog = pane.createDialog(mainView, ACTION_FACTORY.format("mapTitle", level.getMapArch().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 2006-09-09 18:07:45 UTC (rev 311) +++ trunk/daimonin/src/daieditor/map/MapArchObject.java 2006-09-09 18:13:24 UTC (rev 312) @@ -30,6 +30,7 @@ import java.io.IOException; import java.io.Serializable; import net.sf.gridarta.Size2D; +import net.sf.gridarta.map.AbstractMapArchObject; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -45,28 +46,14 @@ * @todo This class should be changed so map attributes are reflected in a more * generic way like arch attributes. */ -public final class MapArchObject implements Serializable { +public final class MapArchObject extends AbstractMapArchObject implements Serializable { /** Serial Version. */ private static final long serialVersionUID = 1L; - // tags which appear in the map header - private static final String TAG_START_TEXT = "msg"; - - private static final String TAG_END_TEXT = "endmsg"; - // map attributes: private final StringBuffer msgText = new StringBuffer(); // map-msg text buffer - /** - * Map size. - * @fixme this is redundant with {@link DefaultMapModel}. - m */ - @NotNull private Size2D mapSize = new Size2D(1, 1); - - /** Default enter coordinates (usage not recommended). */ - private int enterX, enterY; - /** Number of seconds that need to elapse before this map will be reset. */ private int resetTimeout; @@ -128,16 +115,7 @@ /** Player vs Player combat allowed. */ private boolean pvp; - /** Map name (this is the name that appears in the game). */ - private String name; - /** - * Name of the map file. - * @todo check whether this is redundant. - */ - private String filename; - - /** * The map tile paths used for map tiling. * 0 = north, 1 = east, 2 = south, 3 = west. * 4 = northeast, 5 = southeast, 6 = southwest, 7 = northwest @@ -164,18 +142,15 @@ for (int i = 0; i < 8; i++) { tilePaths[i] = ""; } - name = "<untitled>"; // map creation enforces setting a real map name - filename = DEF_MAPFNAME; // default map file name } /** - * Get the map name without the background music that is attached to the - * map name. - * @return map name without attached music string + * {@inheritDoc} + * @note Daimonin stores background music information in the map name. */ - public String getMapNameWithoutMusic() { - final int t = name.indexOf("§"); - return t > 0 ? name.substring(0, t) : name; + public String getMapDisplayName() { + final int t = getMapName().indexOf("§"); + return t > 0 ? getMapName().substring(0, t) : getMapName(); } /** @@ -183,71 +158,11 @@ * @return background music or <code>null</code> if no background music */ public String getBackgroundMusic() { - final int t1 = name.indexOf("§"); - final int t2 = name.indexOf("|"); - return t1 > 0 && t2 > t1 ? name.substring(t1 + 1, t2) : null; + final int t1 = getMapName().indexOf("§"); + final int t2 = getMapName().indexOf("|"); + return t1 > 0 && t2 > t1 ? getMapName().substring(t1 + 1, t2) : null; } - /** - * Set map size. - * @param mapSize new map size - */ - public void setMapSize(@NotNull final Size2D mapSize) { - this.mapSize = mapSize; - } - - @NotNull public Size2D getMapSize() { - return mapSize; - } - - /** - * Get the map name. - * @return map name - */ - public String getMapName() { - return name; - } - - /** - * Set the map name. - * @param name new map name - */ - public void setMapName(final String name) { - this.name = name; - } - - /** - * Get the map filename. - * @return map filename - */ - public String getFileName() { - return filename; - } - - /** - * Set the map filename. - * @param filename new map filename - */ - public void setFileName(final String filename) { - this.filename = filename; - } - - public int getEnterX() { - return enterX; - } - - public void setEnterX(final int enterX) { - this.enterX = enterX; - } - - public int getEnterY() { - return enterY; - } - - public void setEnterY(final int enterY) { - this.enterY = enterY; - } - public int getResetTimeout() { return resetTimeout; } @@ -421,7 +336,7 @@ * @throws IOException in case of I/O problems */ public boolean parseMapArch(@NotNull final BufferedReader reader, @NotNull final String fname) throws IOException { - filename = fname; // store file name + setFileName(fname); boolean archflag = false; // flag for arch<->end int width = 0; int height = 0; @@ -451,15 +366,15 @@ } else if ("end".equalsIgnoreCase(line)) { endReached = true; } else if (line.startsWith("name")) { - name = line.substring(line.indexOf(" ") + 1).trim(); + setMapName(line.substring(line.indexOf(" ") + 1).trim()); } else if (line.startsWith("width ")) { width = getLineValue(line); } else if (line.startsWith("height ")) { height = getLineValue(line); } else if (line.startsWith("enter_x ")) { - enterX = getLineValue(line); + setEnterX(getLineValue(line)); } else if (line.startsWith("enter_y ")) { - enterY = getLineValue(line); + setEnterY(getLineValue(line)); } else if (line.startsWith("reset_timeout ")) { resetTimeout = getLineValue(line); } else if (line.startsWith("swap_time ")) { @@ -549,7 +464,7 @@ } } - mapSize = new Size2D(Math.max(1, width), Math.max(1, height)); + setMapSize(new Size2D(Math.max(1, width), Math.max(1, height))); return archflag; } @@ -579,8 +494,8 @@ public void writeMapArch(@NotNull final BufferedWriter stream) throws IOException { stream.append("arch map\n"); - if (name.length() > 0) { - stream.append("name " + name + '\n'); + if (getMapName().length() > 0) { + stream.append("name " + getMapName() + '\n'); } // maptext @@ -588,13 +503,13 @@ stream.append(msgText.toString().trim() + '\n'); stream.append(TAG_END_TEXT + '\n'); - stream.append("width " + mapSize.getWidth() + '\n'); - stream.append("height " + mapSize.getHeight() + '\n'); - if (enterX > 0) { - stream.append("enter_x " + enterX + '\n'); + stream.append("width " + getMapSize().getWidth() + '\n'); + stream.append("height " + getMapSize().getHeight() + '\n'); + if (getEnterX() > 0) { + stream.append("enter_x " + getEnterX() + '\n'); } - if (enterY > 0) { - stream.append("enter_y " + enterY + '\n'); + if (getEnterY() > 0) { + stream.append("enter_y " + getEnterY() + '\n'); } if (resetTimeout > 0) { Modified: trunk/daimonin/src/daieditor/map/MapControl.java =================================================================== --- trunk/daimonin/src/daieditor/map/MapControl.java 2006-09-09 18:07:45 UTC (rev 311) +++ trunk/daimonin/src/daieditor/map/MapControl.java 2006-09-09 18:13:24 UTC (rev 312) @@ -328,7 +328,7 @@ public void setMapFileName(final String fname) { if (mapViewFrame != null) { - final String title = fname + " [ " + mapArch.getMapNameWithoutMusic() + " ]"; + final String title = fname + " [ " + mapArch.getMapDisplayName() + " ]"; assert mapViewFrame != null; mapViewFrame.setTitle(title); } Modified: trunk/src/app/net/sf/gridarta/Size2D.java =================================================================== --- trunk/src/app/net/sf/gridarta/Size2D.java 2006-09-09 18:07:45 UTC (rev 311) +++ trunk/src/app/net/sf/gridarta/Size2D.java 2006-09-09 18:13:24 UTC (rev 312) @@ -30,6 +30,9 @@ /** Serial Version. */ private static final long serialVersionUID = 1L; + /** Zero size object. */ + public static final Size2D ZERO = new Size2D(0, 0); + /** * The width of the area. * It is always greater than zero. Added: trunk/src/app/net/sf/gridarta/map/AbstractMapArchObject.java =================================================================== --- trunk/src/app/net/sf/gridarta/map/AbstractMapArchObject.java (rev 0) +++ trunk/src/app/net/sf/gridarta/map/AbstractMapArchObject.java 2006-09-09 18:13:24 UTC (rev 312) @@ -0,0 +1,78 @@ +package net.sf.gridarta.map; + +import org.jetbrains.annotations.NotNull; +import net.sf.gridarta.Size2D; +import net.sf.gridarta.CommonConstants; + +/** + * Base implementation of {@link MapArchObject} that covers similarities between Crossfire maps and Daimonin maps. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public abstract class AbstractMapArchObject implements MapArchObject { + + /** The size of the map reflected by this MapArchObject. */ + private Size2D mapSize = Size2D.ZERO; + + /** The name of this map. */ + private String mapName = "<unnamed>"; + + /** The filename of this map. */ + private String fileName = "<new map>"; + + /** The x coordinate for entering the map. */ + private int enterX; + + /** The y coordinate for entering the map. */ + private int enterY; + + /** {@inheritDoc} */ + @NotNull public final Size2D getMapSize() { + return mapSize; + } + + /** {@inheritDoc} */ + public final void setMapSize(@NotNull final Size2D mapSize) { + this.mapSize = mapSize; + } + + /** {@inheritDoc} */ + @NotNull public final String getMapName() { + return mapName; + } + + /** {@inheritDoc} */ + public final void setMapName(@NotNull final String name) { + this.mapName = name; + } + + /** {@inheritDoc} */ + public final String getFileName() { + return fileName; + } + + /** {@inheritDoc} */ + public final void setFileName(final String fileName) { + this.fileName = fileName; + } + + /** {@inheritDoc} */ + public final int getEnterX() { + return enterX; + } + + /** {@inheritDoc} */ + public final void setEnterX(final int enterX) { + this.enterX = enterX; + } + + /** {@inheritDoc} */ + public final int getEnterY() { + return enterY; + } + + /** {@inheritDoc} */ + public final void setEnterY(final int enterY) { + this.enterY = enterY; + } + +} // class AbstractMapArchObject Property changes on: trunk/src/app/net/sf/gridarta/map/AbstractMapArchObject.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Added: trunk/src/app/net/sf/gridarta/map/MapArchObject.java =================================================================== --- trunk/src/app/net/sf/gridarta/map/MapArchObject.java (rev 0) +++ trunk/src/app/net/sf/gridarta/map/MapArchObject.java 2006-09-09 18:13:24 UTC (rev 312) @@ -0,0 +1,91 @@ +package net.sf.gridarta.map; + +import org.jetbrains.annotations.NotNull; +import net.sf.gridarta.Size2D; + +/** + * Interface for MapArchObjects. + * <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> + */ +public interface MapArchObject { + + /** String which starts the message section. */ + String TAG_START_TEXT = "msg"; + + /** String which ends the message section. */ + String TAG_END_TEXT = "endmsg"; + + /** + * Get the map name as seen by the player. + * For games encode additional information in the map name, e.g. the background music, which should be hidden from the user. + * This method returns the map name without such additional information. + * @return map name as it should be shown to the user + */ + String getMapDisplayName(); + + /** + * Set map size. + * @param mapSize new map size + * @xxx this does not change the size of the underlying MapModel. We eventually should change that so a map size isn't stored twice. + */ + void setMapSize(@NotNull Size2D mapSize); + + /** + * Get the map size. + * @return size of the map reflected by this MapArchObject + */ + @NotNull Size2D getMapSize(); + + /** + * Get the map name. + * @return map name + */ + @NotNull String getMapName(); + + /** + * Set the map name. + * @param name new map name + */ + void setMapName(@NotNull String name); + + /** + * Get the map filename. + * @return map filename + * @deprecated the filename isn't really an attribute of the MapArchObject. Only use MapControl for this. + */ + String getFileName(); + + /** + * Set the map fileName. + * @param fileName new map fileName + * @deprecated the fileName isn't really an attribute of the MapArchObject. Only use MapControl for this. + */ + void setFileName(String fileName); + + /** + * Get enter x coordinate. + * @return enter x coordinate. + */ + int getEnterX(); + + /** + * Set enter x coordinate. + * @param enterX new enter x coordinate + */ + void setEnterX(int enterX); + + /** + * Get enter y coordinate. + * @return enter y coordinate. + */ + int getEnterY(); + + /** + * Set enter y coordinate. + * @param enterY new enter y coordinate + */ + void setEnterY(int enterY); + +} // interface MapArchObject Property changes on: trunk/src/app/net/sf/gridarta/map/MapArchObject.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...> - 2006-09-09 18:07:56
|
Revision: 311 http://svn.sourceforge.net/gridarta/?rev=311&view=rev Author: akirschbaum Date: 2006-09-09 11:07:45 -0700 (Sat, 09 Sep 2006) Log Message: ----------- Fix typo in comment. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMapArchPanel.java trunk/crossfire/src/cfeditor/map/DefaultMapModel.java trunk/daimonin/src/daieditor/map/DefaultMapModel.java Modified: trunk/crossfire/src/cfeditor/CMapArchPanel.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapArchPanel.java 2006-09-04 18:14:06 UTC (rev 310) +++ trunk/crossfire/src/cfeditor/CMapArchPanel.java 2006-09-09 18:07:45 UTC (rev 311) @@ -283,7 +283,7 @@ final ArchObject invnew; if (arch.isDefaultArch()) { - // create a new copy of a defautl arch + // create a new copy of a default arch invnew = mainControl.getArchObjectStack().newArchObjectInstance(arch.getNodeNr()); } else { // create clone from a pickmap Modified: trunk/crossfire/src/cfeditor/map/DefaultMapModel.java =================================================================== --- trunk/crossfire/src/cfeditor/map/DefaultMapModel.java 2006-09-04 18:14:06 UTC (rev 310) +++ trunk/crossfire/src/cfeditor/map/DefaultMapModel.java 2006-09-09 18:07:45 UTC (rev 311) @@ -596,7 +596,7 @@ if (newarch != null && newarch.isDefaultArch()) { archnr = newarch.getNodeNr(); } - // create a new copy of a defautl arch + // create a new copy of a default arch invnew = mainControl.getArchObjectStack().newArchObjectInstance(archnr); } else { // create clone from a pickmap Modified: trunk/daimonin/src/daieditor/map/DefaultMapModel.java =================================================================== --- trunk/daimonin/src/daieditor/map/DefaultMapModel.java 2006-09-04 18:14:06 UTC (rev 310) +++ trunk/daimonin/src/daieditor/map/DefaultMapModel.java 2006-09-09 18:07:45 UTC (rev 311) @@ -336,7 +336,7 @@ if (newarch != null && newarch.isDefaultArch()) { archname = newarch.getArchName(); } - // create a new copy of a defautl arch + // create a new copy of a default arch invnew = mainControl.getArchObjectStack().getArch(archname).createArch(); } else { // create clone from a pickmap This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <aki...@us...> - 2006-09-04 18:14:14
|
Revision: 310 http://svn.sourceforge.net/gridarta/?rev=310&view=rev Author: akirschbaum Date: 2006-09-04 11:14:06 -0700 (Mon, 04 Sep 2006) Log Message: ----------- Fix typo in comment. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CMapTileList.java trunk/daimonin/src/daieditor/CMapTileList.java Modified: trunk/crossfire/src/cfeditor/CMapTileList.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapTileList.java 2006-09-04 17:32:02 UTC (rev 309) +++ trunk/crossfire/src/cfeditor/CMapTileList.java 2006-09-04 18:14:06 UTC (rev 310) @@ -362,7 +362,7 @@ } /** - * Add Inventory Objects to an arch in the MapTileList recursively. + * Add inventory objects to an arch in the MapTileList recursively. * @param node the arch where the inventory gets added * @param x map location of 'node' as strings * @param y map location of 'node' as strings Modified: trunk/daimonin/src/daieditor/CMapTileList.java =================================================================== --- trunk/daimonin/src/daieditor/CMapTileList.java 2006-09-04 17:32:02 UTC (rev 309) +++ trunk/daimonin/src/daieditor/CMapTileList.java 2006-09-04 18:14:06 UTC (rev 310) @@ -373,7 +373,7 @@ } /** - * Add Inventory Objects to an arch in the MapTileList recursively. + * Add inventory objects to an arch in the MapTileList recursively. * @param node the arch where the inventory gets added * @param selArch selected ArchObject * @return <code>-1</code> if <var>selArch</var> was found, else <var>listCounter</var> of the arch This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |