From: <chr...@us...> - 2006-07-03 20:36:51
|
Revision: 231 Author: christianhujer Date: 2006-07-03 13:36:22 -0700 (Mon, 03 Jul 2006) ViewCVS: http://svn.sourceforge.net/gridarta/?rev=231&view=rev Log Message: ----------- Some unification of ArchObject. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CAttribDialog.java trunk/crossfire/src/cfeditor/CMainControl.java trunk/crossfire/src/cfeditor/CMapArchPanel.java trunk/crossfire/src/cfeditor/arch/ArchObject.java trunk/daimonin/src/daieditor/CMainControl.java trunk/daimonin/src/daieditor/arch/ArchObject.java trunk/daimonin/src/daieditor/arch/ArchObjectStack.java trunk/daimonin/src/daieditor/arch/anim/AnimationObjects.java trunk/src/app/net/sf/gridarta/arch/ArchObject.java Modified: trunk/crossfire/src/cfeditor/CAttribDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/CAttribDialog.java 2006-07-02 22:09:54 UTC (rev 230) +++ trunk/crossfire/src/cfeditor/CAttribDialog.java 2006-07-03 20:36:22 UTC (rev 231) @@ -376,7 +376,7 @@ private JComboBox buildSpellBox(final CFArchAttrib attr) { // first parse the spell-number value from arch - int spnum = arch.getAttributeValue(attr.getNameOld(), defarch); // spell number + int spnum = arch.getAttributeInt(attr.getNameOld(), defarch); // spell number if (spnum < 0 || spnum >= typelist.getSpellNum().length - 1) { spnum = 0; // undefined spellnumbers be zero @@ -419,7 +419,7 @@ // build the array of list-items final String []array = new String[(int) (listData.size() / 2.)]; boolean hasSelection = false; - int active = arch.getAttributeValue(attr.getNameOld(), defarch); + int active = arch.getAttributeInt(attr.getNameOld(), defarch); for (int i = 0; i < array.length; i++) { array[i] = (String) listData.elementAt(i * 2 + 1); // put string to array @@ -454,7 +454,7 @@ */ private void buildBitmask(final CFArchAttrib attr, final BitmaskAttrib guiAttr, final CAttribBitmask bitmask, final JPanel mainPanel) { // initialize bitmask value - guiAttr.setValue(arch.getAttributeValue(attr.getNameOld(), defarch)); + guiAttr.setValue(arch.getAttributeInt(attr.getNameOld(), defarch)); guiAttr.bitmask = bitmask; // add button @@ -684,7 +684,7 @@ final JCheckBox input; if (dType == CFArchAttrib.T_BOOL) { // normal bool - input = new JCheckBox(" " + type.getAttr()[i].getNameNew(), (arch.getAttributeValue(type.getAttr()[i].getNameOld(), defarch) == 1)); + input = new JCheckBox(" " + type.getAttr()[i].getNameNew(), (arch.getAttributeInt(type.getAttr()[i].getNameOld(), defarch) == 1)); } else { // parse values for customized bool final String trueVal = type.getAttr()[i].getMisc()[0]; @@ -725,7 +725,7 @@ // parse value from arch final int fieldLength = (type.getAttr()[i].getInputLength() == 0 ? textFieldColumns : type.getAttr()[i].getInputLength()); - final int attrval = arch.getAttributeValue(type.getAttr()[i].getNameOld(), defarch); + final int attrval = arch.getAttributeInt(type.getAttr()[i].getNameOld(), defarch); if (attrval != 0) { input = new JTextField(String.valueOf(attrval), fieldLength); } else { @@ -1199,7 +1199,7 @@ if (dType == CFArchAttrib.T_BOOL) { // a boolean attribute (flag) if (((BoolAttrib) attr).input.isSelected() != - (defarch.getAttributeValue(attr.ref.getNameOld(), null) == 1)) { + (defarch.getAttributeInt(attr.ref.getNameOld(), null) == 1)) { newArchText = newArchText + attr.ref.getNameOld() + " " + (((BoolAttrib) attr).input.isSelected() ? 1 : 0) + "\n"; } @@ -1219,7 +1219,7 @@ dType == CFArchAttrib.T_FLOAT) { // an int attribute if (dType == CFArchAttrib.T_INT && ((IntAttrib) attr).input.getText().trim().length() == 0) { - if (defarch.getAttributeValue(attr.ref.getNameOld(), null) != 0) { + if (defarch.getAttributeInt(attr.ref.getNameOld(), null) != 0) { newArchText = newArchText + attr.ref.getNameOld() + " 0\n"; } } else if (dType == CFArchAttrib.T_FLOAT && ((FloatAttrib) attr).input.getText().trim().length() == 0) { @@ -1230,7 +1230,7 @@ try { if (dType == CFArchAttrib.T_INT) { final int value = Integer.parseInt(((IntAttrib) attr).input.getText().trim()); - if (defarch.getAttributeValue(attr.ref.getNameOld(), null) != value) { + if (defarch.getAttributeInt(attr.ref.getNameOld(), null) != value) { newArchText = newArchText + attr.ref.getNameOld() + " " + value + "\n"; } } else { @@ -1308,19 +1308,19 @@ if (attrVal == -1 || (attrVal == 0 && dType != CFArchAttrib.T_SPELL && dType != CFArchAttrib.T_ZSPELL)) { - if (defarch.getAttributeValue(attr.ref.getNameOld(), null) != 0) { + if (defarch.getAttributeInt(attr.ref.getNameOld(), null) != 0) { newArchText = newArchText + attr.ref.getNameOld() + " 0\n"; } } else if (attrVal == 0) { newArchText = newArchText + attr.ref.getNameOld() + " 0\n"; - } else if (defarch.getAttributeValue(attr.ref.getNameOld(), null) != attrVal) { + } else if (defarch.getAttributeInt(attr.ref.getNameOld(), null) != attrVal) { newArchText = newArchText + attr.ref.getNameOld() + " " + attrVal + "\n"; } } else if (dType == CFArchAttrib.T_BITMASK) { // a bitmask attribute (similar to integer, but easier because no parsing needed) final int value = ((BitmaskAttrib) attr).getValue(); // get bitmask value - if (defarch.getAttributeValue(attr.ref.getNameOld(), null) != value) { + if (defarch.getAttributeInt(attr.ref.getNameOld(), null) != value) { newArchText = newArchText + attr.ref.getNameOld() + " " + value + "\n"; } } else if (dType == CFArchAttrib.T_TREASURE) { Modified: trunk/crossfire/src/cfeditor/CMainControl.java =================================================================== --- trunk/crossfire/src/cfeditor/CMainControl.java 2006-07-02 22:09:54 UTC (rev 230) +++ trunk/crossfire/src/cfeditor/CMainControl.java 2006-07-03 20:36:22 UTC (rev 231) @@ -1316,8 +1316,8 @@ final String path = exit.getAttributeString("slaying", getArch(exit.getNodeNr())); final Point exitPos = new Point(); - exitPos.x = exit.getAttributeValue("hp", getArch(exit.getNodeNr())); - exitPos.y = exit.getAttributeValue("sp", getArch(exit.getNodeNr())); + exitPos.x = exit.getAttributeInt("hp", getArch(exit.getNodeNr())); + exitPos.y = exit.getAttributeInt("sp", getArch(exit.getNodeNr())); if (path.length() == 0 || (currentMap.getMapFile() != null && path.equals(currentMap.getMapFile().getName()))) { Modified: trunk/crossfire/src/cfeditor/CMapArchPanel.java =================================================================== --- trunk/crossfire/src/cfeditor/CMapArchPanel.java 2006-07-02 22:09:54 UTC (rev 230) +++ trunk/crossfire/src/cfeditor/CMapArchPanel.java 2006-07-03 20:36:22 UTC (rev 231) @@ -428,7 +428,7 @@ // we look for 'type' in the ArchText. In future maybe type should get // a seperate textfield if (arch.getAttributeString("type", null).length() > 0) { - arch.setArchTypNr(arch.getAttributeValue("type", null)); // specified type + arch.setArchTypNr(arch.getAttributeInt("type", null)); // specified type } // Recalculate the editType value. It shall stay 100% accurate ;) Modified: trunk/crossfire/src/cfeditor/arch/ArchObject.java =================================================================== --- trunk/crossfire/src/cfeditor/arch/ArchObject.java 2006-07-02 22:09:54 UTC (rev 230) +++ trunk/crossfire/src/cfeditor/arch/ArchObject.java 2006-07-03 20:36:22 UTC (rev 231) @@ -49,7 +49,7 @@ * @author <a href="mailto:mic...@no...">Michael Toennies</a> * @author <a href="mailto:and...@gm...">Andreas Vogl</a> */ -public class ArchObject implements Cloneable, net.sf.gridarta.arch.ArchObject { +public class ArchObject implements Cloneable, net.sf.gridarta.arch.ArchObject, Iterable<ArchObject> { private static final Logger LOG = Logger.getLogger(ArchObject.class); @@ -71,6 +71,7 @@ private String archName; // arch Name + /** The name of this object. */ private String objName; /** @@ -104,6 +105,9 @@ private int nodenr; // we are (internal) arch nr in node list // the nodenr determines the (default) archetype + /** The default arch. */ + private ArchObject defaultArch; + /** Map x position if on map. */ private int mapx; @@ -213,7 +217,7 @@ * @return the default <code>ArchObject</code> for this arch */ public ArchObject getDefaultArch() { - return archstack.getArch(nodenr); + return defaultArch; } /** @@ -222,7 +226,7 @@ * the {@link ArchObjectStack}), otherwise <code>false</code> */ public boolean isDefaultArch() { - return archstack.getArch(nodenr) == this; + return defaultArch == this; } /** @@ -232,12 +236,11 @@ * @return new editType for this arch */ public int calculateEditType(final int checkType) { - final ArchObject defarch = getDefaultArch(); // default arch - + // ATTENTION! BE VERY CAREFUL WHEN YOU TRY TO UNIFY MORE OF THIS WITH DAIMONIN! /* if one of the types in checkType already is in editType, // we exclude that one - if ((checkType&editType) != 0) { - checkType -= (checkType&editType); + if ((checkType & editType) != 0) { + checkType -= (checkType & editType); } */ @@ -254,25 +257,25 @@ } if ((checkType & IGUIConstants.TILE_EDIT_BACKGROUND) != 0 - && getAttributeValue("is_floor", defarch) == 1 - && getAttributeValue("no_pick", defarch) == 1) { + && getAttributeInt("is_floor", true) == 1 + && getAttributeInt("no_pick", true) == 1) { // Backgroud: floors editType |= IGUIConstants.TILE_EDIT_BACKGROUND; } if ((checkType & IGUIConstants.TILE_EDIT_MONSTER) != 0 - && getAttributeValue("alive", defarch) == 1 - && (getAttributeValue("monster", defarch) == 1 || getAttributeValue("generator", defarch) == 1)) { + && getAttributeInt("alive", true) == 1 + && (getAttributeInt("monster", true) == 1 || getAttributeInt("generator", true) == 1)) { // Monster: monsters/npcs/generators editType |= IGUIConstants.TILE_EDIT_MONSTER; } if ((checkType & IGUIConstants.TILE_EDIT_WALL) != 0 && archType == 0 - && getAttributeValue("no_pass", defarch) == 1) { + && getAttributeInt("no_pass", true) == 1) { // Walls editType |= IGUIConstants.TILE_EDIT_WALL; } if ((checkType & IGUIConstants.TILE_EDIT_CONNECTED) != 0 - && getAttributeValue("connected", defarch) != 0) { + && getAttributeInt("connected", true) != 0) { // Connected Objects editType |= IGUIConstants.TILE_EDIT_CONNECTED; } @@ -282,7 +285,7 @@ editType |= IGUIConstants.TILE_EDIT_EXIT; } if ((checkType & IGUIConstants.TILE_EDIT_TREASURE) != 0 - && getAttributeValue("no_pick", defarch) == 0 + && getAttributeInt("no_pick", true) == 0 && (archType == 4 || archType == 5 || archType == 36 || archType == 60 || archType == 85 || archType == 111 || archType == 123 || archType == 124 || archType == 130)) { // Treasure: randomtreasure/money/gems/potions/spellbooks/scrolls editType |= IGUIConstants.TILE_EDIT_TREASURE; @@ -293,8 +296,8 @@ editType |= IGUIConstants.TILE_EDIT_DOOR; } if ((checkType & IGUIConstants.TILE_EDIT_EQUIP) != 0 - && getAttributeValue("no_pick", defarch) == 0 - && ((archType >= 13 && archType <= 16) || archType == 33 || archType == 34 || archType == 35 || archType == 39 || archType == 70 || archType == 87 || archType == 99 || archType == 100 || archType == 104 || archType == 109 || archType == 113 || archType == 122 || archType == 3)) { + && getAttributeInt("no_pick", true) == 0 + && (archType >= 13 && archType <= 16 || archType == 33 || archType == 34 || archType == 35 || archType == 39 || archType == 70 || archType == 87 || archType == 99 || archType == 100 || archType == 104 || archType == 109 || archType == 113 || archType == 122 || archType == 3)) { // Equipment: weapons/armour/wands/rods editType |= IGUIConstants.TILE_EDIT_EQUIP; } @@ -303,52 +306,6 @@ } /** - * Get the value of an arch attribute from the archText both of the arch - * itself and if n.e. in it's default arch. If the attribute doesn't exist - * in either one, or the value is not a number, zero is returned. - * @param attr search for "attr <value>" - * @param defarch default arch of this arch, or <code>null</code> if this - * arch is a default arch or the default arch should be ignored - * @return <value>, zero if not found - */ - public int getAttributeValue(String attr, final ArchObject defarch) { - String aText = archText.toString(); // The "real" Archtext from arch & defarch - int j; - - // Add all attributes from defarch that don't already exist in aText - if (defarch != null) { - aText = aText + diffArchText(defarch.getArchText(), true); - } - - if (!aText.endsWith("\n")) { - aText = aText.concat("\n"); // string should end with '\n', see below - } - - attr = attr.trim() + " "; // attr must be followed by space - - // Check line by line for the string 'attr' - int i; - int result = 0; - for (i = 0, j = 0; i < aText.length(); i++) { - if (aText.charAt(i) == '\n') { - final String line = aText.substring(j, i).trim(); - - try { - // try to read the value behind 'attr' - if (line.startsWith(attr)) { - result = Integer.parseInt(line.substring(attr.length()).trim()); - } - } catch (NumberFormatException e) { - result = 0; - } - - j = i + 1; - } - } - return result; - } - - /** * Get the String of an arch attribute from the archText both of the arch * itself and if n.e. in it's default arch. If the attribute doesn't exist * in either one, an empty String "" is returned. @@ -357,7 +314,7 @@ * arch is a default arch or the default arch should be ignored * @return <string>, "" if not found */ - public String getAttributeString(String attr, @Nullable final ArchObject defarch) { + public String getAttributeString(String attr, @Nullable final net.sf.gridarta.arch.ArchObject defarch) { String aText = archText.toString(); // The "real" Archtext from arch & defarch int j; attr = attr.trim() + " "; // attr must be followed by space @@ -401,7 +358,7 @@ /** {@inheritDoc} */ public String getAttributeString(final String attr, final boolean useDefArch) { - return getAttributeString(attr, useDefArch ? getDefaultArch() : null); + return getAttributeString(attr, useDefArch ? defaultArch : null); } /** {@inheritDoc} */ @@ -409,7 +366,110 @@ return getAttributeString(attr, true); } + /** {@inheritDoc} */ + public int getAttributeInt(final String attr, final net.sf.gridarta.arch.ArchObject defarch) { + String aText = archText.toString(); // The "real" Archtext from arch & defarch + // Add all attributes from defarch that don't already exist in aText + if (defarch != null) { + aText += diffArchText(defarch.getArchText(), true); + } + assert aText.endsWith("\n"); + final String attr2 = attr.trim() + ' '; + int result = 0; + for (final String line : aText.split("\\s*\n")) { + if (line.startsWith(attr2)) { + try { + result = Integer.parseInt(line.substring(attr2.length()).trim()); + } catch (final NumberFormatException e) { + result = 0; + } + } + } + return result; + } + + /** {@inheritDoc} */ + public int getAttributeInt(final String attr, final boolean useDefArch) { + return getAttributeInt(attr, useDefArch ? defaultArch : null); + } + + /** {@inheritDoc} */ + public long getAttributeLong(final String attr, final net.sf.gridarta.arch.ArchObject defarch) { + String aText = archText.toString(); + // Add all attributes from defarch that don't already exist in aText + if (defarch != null) { + aText += diffArchText(defarch.getArchText(), true); + } + final String attr2 = attr.trim() + ' '; + long result = 0; + for (final String line : aText.split("\\s*\n")) { + if (line.startsWith(attr2)) { + try { + result = Long.parseLong(line.substring(attr2.length())); + } catch (final NumberFormatException e) { + result = 0; + } + } + } + return result; + } + + /** {@inheritDoc} */ + public long getAttributeLong(final String attr, final boolean useDefArch) { + return getAttributeLong(attr, useDefArch ? defaultArch : null); + } + /** + * Get the value of an arch attribute from the archText both of the arch + * itself and eventually its default arch. If the attribute doesn't exist + * in either one, or the value is not a number, zero is returned. + * @param attr search for "attr <value>" + * @param defarch default arch of this arch, or <code>null</code> if this + * arch is a default arch or the default arch should be ignored + * @return <value>, zero if not found + */ + public double getAttributeDouble(final String attr, final net.sf.gridarta.arch.ArchObject defarch) { + String aText = archText.toString(); + // Add all attributes from defarch that don't already exist in aText + if (defarch != null) { + aText += diffArchText(defarch.getArchText(), true); + } + final String attr2 = attr.trim() + ' '; + double result = 0; + for (String line : aText.split("\\s*\n")) { + if (line.startsWith(attr2)) { + try { + result = Double.parseDouble(line.substring(attr2.length())); + } catch (final NumberFormatException e) { + result = 0; + } + } + } + return result; + } + + /** + * Get the value of an arch attribute from the archText both of the arch + * itself and eventually its default arch. If the attribute doesn't exist + * in either one, or the value is not a number, zero is returned. + * @param attr search for "attr <value>" + * @param useDefArch <code>true</code> if the default arch of this + * ArchObject should be queried as well, <code>false</code> to ignore it + * @return <value>, zero if not found + */ + public double getAttributeDouble(final String attr, final boolean useDefArch) { + return getAttributeDouble(attr, useDefArch ? defaultArch : null); + } + + /** + * Sets edit Type. + * @param editType edit Type. + */ + public void setEditType(final int editType) { + this.editType = editType; + } + + /** * Set the String of an arch attribute in the archText. * @param attr search for "attr <string>" * @param value value to set @@ -506,10 +566,6 @@ } } - public void setEditType(final int t) { - editType = t; - } - public int getMyID() { return myId; } @@ -604,14 +660,12 @@ } } - /** - * browse through the inventory tree and count all elements - * @return number of objects in the inventory - */ + /** {@inheritDoc} */ public int countInvObjects() { - int count = inv.size(); - for (final ArchObject anInv : inv) { - count += anInv.countInvObjects(); + int count = 0; + for (final ArchObject arch : this) { + count++; + count += arch.countInvObjects(); } return count; } @@ -922,6 +976,7 @@ /* Set Node number. Node number is the index of the default arch node list */ public void setNodeNr(final int nr) { nodenr = nr; + defaultArch = archstack.getArch(nodenr); } /* Get Node number. Node number is the index of the default arch node list */ @@ -952,24 +1007,31 @@ * @return best suitable descriptive name */ public String getBestName(final ArchObject defaultArch) { - if (getObjName() != null && getObjName().length() > 0) { - return getObjName(); - } else if (defaultArch != null && defaultArch.getObjName() != null && defaultArch.getObjName().length() > 0) { - return defaultArch.getObjName(); - } else if (getArchName() != null && getArchName().length() > 0) { - return getArchName(); - } else if (defaultArch != null && defaultArch.getArchName() != null) { - return defaultArch.getArchName(); + if (objName != null && objName.length() > 0) { + return objName; + } else if (defaultArch != null && defaultArch.objName != null && defaultArch.objName.length() > 0) { + return defaultArch.objName; + } else if (archName != null && archName.length() > 0) { + return archName; + } else if (defaultArch != null && defaultArch.archName != null) { + return defaultArch.archName; } return "???"; // this case should actually never happen } - // Obj name + /** + * Sets the name of this object. + * @param objName the name of this object. + */ public void setObjName(final String objName) { this.objName = objName != null ? objName.intern() : null; } + /** + * Returns the name of this object. + * @return the name of this object. + */ public String getObjName() { return objName; } @@ -1001,10 +1063,7 @@ clearCachedAttributeValue(); } - /** - * Returns the arch text of this arch as String. - * @return the arch text - */ + /** {@inheritDoc} */ public String getArchText() { return archText.toString(); } @@ -1243,6 +1302,7 @@ } clone.nodenr = nodenr; // node of the default arch + clone.defaultArch = defaultArch; // default arch clone.noface = noface; // if true, arch has no face as default clone.facenr = facenr; // the index of faceImages[] @@ -1498,4 +1558,9 @@ return (String) cachedAttribute.get(name); } + /** {@inheritDoc} */ + public Iterator<ArchObject> iterator() { + return inv.iterator(); + } + } // class ArchObject Modified: trunk/daimonin/src/daieditor/CMainControl.java =================================================================== --- trunk/daimonin/src/daieditor/CMainControl.java 2006-07-02 22:09:54 UTC (rev 230) +++ trunk/daimonin/src/daieditor/CMainControl.java 2006-07-03 20:36:22 UTC (rev 231) @@ -431,7 +431,6 @@ mapFileDecoder = new CMapFileDecode(); mapFileEncoder = new CMapFileEncode(); - ArchObject.setMControl(this); // our global object parser archObjectParser = new ArchObjectParser(this); animationObjects = new AnimationObjects(ACTION_FACTORY.getString("nameOfAnimationObject")); Modified: trunk/daimonin/src/daieditor/arch/ArchObject.java =================================================================== --- trunk/daimonin/src/daieditor/arch/ArchObject.java 2006-07-02 22:09:54 UTC (rev 230) +++ trunk/daimonin/src/daieditor/arch/ArchObject.java 2006-07-03 20:36:22 UTC (rev 231) @@ -36,8 +36,7 @@ import daieditor.arch.anim.AnimationObjects; import daieditor.arch.face.FaceObject; import daieditor.map.MapSquare; -import java.lang.ref.SoftReference; -import java.util.ArrayList; +import java.util.Collections; import java.util.List; import javax.swing.ImageIcon; import javax.swing.JList; @@ -57,18 +56,12 @@ */ public final class ArchObject /*extends NamedObject*/ extends ArchObjectContainer implements Cloneable, net.sf.gridarta.arch.ArchObject { - /** Reference to main control. */ - private static CMainControl mainControl; - /** Special constant that's used if an arch has no arch type set. */ public static final int TYPE_UNSET = -666; /** Static reference to the typeList (find syntax errors). */ private static CFArchTypeList typeList; - /** Collection with all ArchObjects. */ - private static List<SoftReference<ArchObject>> allObjects = new ArrayList<SoftReference<ArchObject>>(); - /** Face name, can be from animation or face. */ private String faceObjName; @@ -81,7 +74,7 @@ /** Arch name. */ private String archName; - /** TODO. */ + /** The name of this object. */ private String objName; /** Object animation <code>animation <var>animName</var></code>. */ @@ -162,7 +155,6 @@ /** The transparent face. */ private ImageIcon transFace; - private static final List<ArchObject> emptyList = new ArrayList<ArchObject>(); /** Create an ArchObject. */ public ArchObject() { @@ -170,22 +162,12 @@ faceobjdesc = FaceDesc.FACE_NOT_FOUND; archType = TYPE_UNSET; // type must be set script = new ScriptArchData(this); - allObjects.add(new SoftReference<ArchObject>(this)); } - /** Clear the faces of all ArchObjects. */ - public static void clear() { - // TODO - } - public static void setTypeList(final CFArchTypeList tlist) { typeList = tlist; } - public static void setMControl(final CMainControl mainControl) { - ArchObject.mainControl = mainControl; - } - /** * Returns edit Type. * @return edit Type @@ -254,6 +236,7 @@ * @todo use arch object matchers, eventually deprecated this method and remove it */ public int calculateEditType(final int checkType) { + // ATTENTION! BE VERY CAREFUL WHEN YOU TRY TO UNIFY MORE OF THIS WITH CROSSFIRE! /* if one of the types in checkType already is in editType, // we exclude that one if ((checkType & editType) != 0) { @@ -322,26 +305,54 @@ } /** - * Get the value of an arch attribute from the archText both of the arch + * Get the String of an arch attribute from the archText both of the arch * itself and if n.e. in it's default arch. If the attribute doesn't exist - * in either one, or the value is not a number, zero is returned. + * in either one, an empty String "" is returned. * @param attr search for "attr <value>" * @param defarch default arch of this arch, or <code>null</code> if this * arch is a default arch or the default arch should be ignored - * @return <value>, zero if not found + * @return <string>, "" if not found */ - public int getAttributeInt(final String attr, final ArchObject defarch) { + public String getAttributeString(final String attr, final net.sf.gridarta.arch.ArchObject defarch) { String aText = archText.toString(); // The "real" Archtext from arch & defarch // Add all attributes from defarch that don't already exist in aText if (defarch != null) { aText += diffArchText(defarch.getArchText(), true); } + final String attr2 = attr.trim() + ' '; // attr must be followed by space + String result = ""; // returned String + for (final String line : aText.split("\\s*\n")) { + if (line.startsWith(attr2)) { + result = line.substring(attr2.length()); + } + } + return result; + } + + /** {@inheritDoc} */ + public String getAttributeString(final String attr, final boolean useDefArch) { + return getAttributeString(attr, useDefArch ? defaultArch : null); + } + + /** {@inheritDoc} */ + public String getAttributeString(final String attr) { + return getAttributeString(attr, true); + } + + /** {@inheritDoc} */ + public int getAttributeInt(final String attr, final net.sf.gridarta.arch.ArchObject defarch) { + String aText = archText.toString(); // The "real" Archtext from arch & defarch + // Add all attributes from defarch that don't already exist in aText + if (defarch != null) { + aText += diffArchText(defarch.getArchText(), true); + } + assert aText.endsWith("\n"); final String attr2 = attr.trim() + ' '; - int result = 0; // returned value + int result = 0; for (final String line : aText.split("\\s*\n")) { if (line.startsWith(attr2)) { try { - result = Integer.parseInt(line.substring(attr2.length())); + result = Integer.parseInt(line.substring(attr2.length()).trim()); } catch (final NumberFormatException e) { result = 0; } @@ -350,29 +361,13 @@ return result; } - /** - * Get the value of an arch attribute from the archText both of the arch - * itself and if n.e. in it's default arch. If the attribute doesn't exist - * in either one, or the value is not a number, zero is returned. - * @param attr search for "attr <value>" - * @param useDefArch <code>true</code> if the default arch of this - * ArchObject should be queried as well, <code>false</code> to ignore it - * @return <value>, zero if not found - */ + /** {@inheritDoc} */ public int getAttributeInt(final String attr, final boolean useDefArch) { return getAttributeInt(attr, useDefArch ? defaultArch : null); } - /** - * Get the value of an arch attribute from the archText both of the arch - * itself and eventually its default arch. If the attribute doesn't exist - * in either one, or the value is not a number, zero is returned. - * @param attr search for "attr <value>" - * @param defarch default arch of this arch, or <code>null</code> if this - * arch is a default arch or the default arch should be ignored - * @return <value>, zero if not found - */ - public long getAttributeLong(final String attr, final ArchObject defarch) { + /** {@inheritDoc} */ + public long getAttributeLong(final String attr, final net.sf.gridarta.arch.ArchObject defarch) { String aText = archText.toString(); // Add all attributes from defarch that don't already exist in aText if (defarch != null) { @@ -392,15 +387,7 @@ return result; } - /** - * Get the value of an arch attribute from the archText both of the arch - * itself and eventually its default arch. If the attribute doesn't exist - * in either one, or the value is not a number, zero is returned. - * @param attr search for "attr <value>" - * @param useDefArch <code>true</code> if the default arch of this - * ArchObject should be queried as well, <code>false</code> to ignore it - * @return <value>, zero if not found - */ + /** {@inheritDoc} */ public long getAttributeLong(final String attr, final boolean useDefArch) { return getAttributeLong(attr, useDefArch ? defaultArch : null); } @@ -414,7 +401,7 @@ * arch is a default arch or the default arch should be ignored * @return <value>, zero if not found */ - public double getAttributeDouble(final String attr, final ArchObject defarch) { + public double getAttributeDouble(final String attr, final net.sf.gridarta.arch.ArchObject defarch) { String aText = archText.toString(); // Add all attributes from defarch that don't already exist in aText if (defarch != null) { @@ -448,47 +435,11 @@ } /** - * Get the String of an arch attribute from the archText both of the arch - * itself and if n.e. in it's default arch. If the attribute doesn't exist - * in either one, an empty String "" is returned. - * @param attr search for "attr <value>" - * @param defarch default arch of this arch, or <code>null</code> if this - * arch is a default arch or the default arch should be ignored - * @return <string>, "" if not found - */ - public String getAttributeString(final String attr, final ArchObject defarch) { - String aText = archText.toString(); // The "real" Archtext from arch & defarch - // Add all attributes from defarch that don't already exist in aText - if (defarch != null) { - aText += diffArchText(defarch.getArchText(), true); - } - final String attr2 = attr.trim() + ' '; // attr must be followed by space - String result = ""; // returned String - for (final String line : aText.split("\\s*\n")) { - if (line.startsWith(attr2)) { - result = line.substring(attr2.length()); - } - } - return result; - } - - /** {@inheritDoc} */ - public String getAttributeString(final String attr, final boolean useDefArch) { - return getAttributeString(attr, useDefArch ? defaultArch : null); - } - - /** {@inheritDoc} */ - public String getAttributeString(final String attr) { - return getAttributeString(attr, true); - } - - /** * Sets edit Type. - * - * @param t edit Type. + * @param editType edit Type. */ - public void setEditType(final int t) { - editType = t; + public void setEditType(final int editType) { + this.editType = editType; } public void setContainer(final ArchObjectContainer container) { @@ -601,15 +552,12 @@ add(this, node, next); } - /** - * browse through the inventory tree and count all elements - * @return number of objects in the inventory - */ + /** {@inheritDoc} */ public int countInvObjects() { int count = 0; - for (ArchObject arch : this) { - count++; // we have one in... to through his chain - count += arch.countInvObjects(); // count his inventory + for (final ArchObject arch : this) { + count++; + count += arch.countInvObjects(); } return count; } @@ -813,7 +761,7 @@ } public List<ArchObject> getTailList() { - return multi != null ? multi.getTailList() : emptyList; + return multi != null ? multi.getTailList() : Collections.EMPTY_LIST; } public void setTailList(final List<ArchObject> tails) { @@ -961,11 +909,18 @@ return "???"; // this case should actually never happen } - // Obj name + /** + * Sets the name of this object. + * @param objName the name of this object. + */ public void setObjName(final String objName) { this.objName = objName != null ? objName.intern() : null; } + /** + * Returns the name of this object. + * @return the name of this object. + */ public String getObjName() { return objName; } @@ -974,7 +929,7 @@ private void setFaceObjName(final String faceObjName) { if (faceObjName != null) { this.faceObjName = faceObjName.intern(); - faceObject = mainControl.getFaceObjects().get(this.faceObjName); + faceObject = CMainControl.getInstance().getFaceObjects().get(this.faceObjName); } else { this.faceObjName = null; faceObject = null; @@ -1012,19 +967,11 @@ this.archText.append(archText); } - /** - * Returns the arch text of this arch as String. - * @return the arch text - */ + /** {@inheritDoc} */ public String getArchText() { return archText.toString(); } - /** Clears the arch text of this arch. */ - public void resetArchText() { - archText.delete(0, archText.length()); - } - /** * Set The "face >name>" field of a object. We need this for fast * access. We set here the string name, the face number and we will handle @@ -1069,7 +1016,7 @@ String effectiveFaceObjName; if (effectiveAnimName != null) { // we have a animation - get the frame picture - final AnimationObjects animationObjects = mainControl.getAnimationObjects(); + final AnimationObjects animationObjects = CMainControl.getInstance().getAnimationObjects(); final AnimationObject animationObject = animationObjects.get(effectiveAnimName); if (animationObject != null) { noface = false; @@ -1154,6 +1101,11 @@ return null; } + /** Clears the arch text of this arch. */ + public void resetArchText() { + archText.delete(0, archText.length()); + } + /** * Get all entries from the given archtext 'atxt' that don't exist in * 'this' archtext. Modified: trunk/daimonin/src/daieditor/arch/ArchObjectStack.java =================================================================== --- trunk/daimonin/src/daieditor/arch/ArchObjectStack.java 2006-07-02 22:09:54 UTC (rev 230) +++ trunk/daimonin/src/daieditor/arch/ArchObjectStack.java 2006-07-03 20:36:22 UTC (rev 231) @@ -457,7 +457,7 @@ */ private void loadAnimsFromFiles() { final AnimationObjects anims = mainControl.getAnimationObjects(); - for (File animFile : animFiles) { + for (final File animFile : animFiles) { try { anims.loadAnims(animFile); } catch (final DuplicateAnimationException e) { @@ -475,22 +475,21 @@ /** Loading all animations from the big collected animations file. */ private void loadAllDaimoninAnimationsFromCollect() { - Reader in = null; try { - in = new CFileReader(mainControl.getArchDefaultFolder(), "animations"); - mainControl.getAnimationObjects().loadAnims(in, null); + final Reader in = new CFileReader(mainControl.getArchDefaultFolder(), "animations"); + try { + mainControl.getAnimationObjects().loadAnims(in, null); + } finally { + in.close(); + } + } catch (final FileNotFoundException e) { + mainControl.handleThrowable(e); } catch (final DuplicateAnimationException e) { mainControl.handleThrowable(e); } catch (final IOException e) { mainControl.handleThrowable(e); } catch (final AnimationParseException e) { mainControl.handleThrowable(new AnimationParseException(e, new File("animations"))); - } finally { - try { - in.close(); - } catch (final Exception e) { /* ignore */ } finally { - in = null; - } } } Modified: trunk/daimonin/src/daieditor/arch/anim/AnimationObjects.java =================================================================== --- trunk/daimonin/src/daieditor/arch/anim/AnimationObjects.java 2006-07-02 22:09:54 UTC (rev 230) +++ trunk/daimonin/src/daieditor/arch/anim/AnimationObjects.java 2006-07-03 20:36:22 UTC (rev 231) @@ -102,17 +102,12 @@ * @throws DuplicateAnimationException in case an animation was not unique */ public void loadAnims(final File animFile) throws FileNotFoundException, IOException, AnimationParseException, DuplicateAnimationException { - Reader in = null; + final Reader in = new InputStreamReader(new FileInputStream(animFile), MAP_ENCODING); try { - in = new InputStreamReader(new FileInputStream(animFile), MAP_ENCODING); final String path = (new File(PathManager.getArchPath(animFile.getPath()))).getParent().replace('\\', '/'); loadAnims(in, path); } finally { - try { - in.close(); - } catch (final Exception e) { /* ignore */ } finally { - in = null; - } + in.close(); } } @@ -185,16 +180,11 @@ * @throws FileNotFoundException in case the file couldn't be opened */ public void loadAnimTree(final File animTreeFile) throws FileNotFoundException, IOException { - Reader in = null; + final Reader in = new InputStreamReader(new FileInputStream(animTreeFile), MAP_ENCODING); try { - in = new InputStreamReader(new FileInputStream(animTreeFile), MAP_ENCODING); loadAnimTree(in); } finally { - try { - in.close(); - } catch (final Exception e) { /* ignore */ } finally { - in = null; - } + in.close(); } } Modified: trunk/src/app/net/sf/gridarta/arch/ArchObject.java =================================================================== --- trunk/src/app/net/sf/gridarta/arch/ArchObject.java 2006-07-02 22:09:54 UTC (rev 230) +++ trunk/src/app/net/sf/gridarta/arch/ArchObject.java 2006-07-03 20:36:22 UTC (rev 231) @@ -8,6 +8,30 @@ public interface ArchObject { /** + * Count the number of all inventory items (recursively). + * The returned value does not include this ArchObject. + * @return number of objects in the inventory (recursively) + */ + int countInvObjects(); + + /** + * Returns the arch text of this arch as String. + * @return the arch text + */ + String getArchText(); + + /** + * Get the String of an arch attribute from the archText both of the arch + * itself and if n.e. in it's default arch. If the attribute doesn't exist + * in either one, an empty String "" is returned. + * @param attr search for "attr <value>" + * @param defarch default arch of this arch, or <code>null</code> if this + * arch is a default arch or the default arch should be ignored + * @return <string>, "" if not found + */ + String getAttributeString(String attr, ArchObject defarch); + + /** * Get the value of an attribute of this ArchObject. * @param attr attribute name to get value for * @param useDefArch <code>true</code> if the default arch of this ArchObject should be queried as well, <code>false</code> to ignore it @@ -26,4 +50,70 @@ */ String getAttributeString(String attr); + /** + * Get the value of an arch attribute from the archText both of the arch + * itself and if n.e. in it's default arch. If the attribute doesn't exist + * in either one, or the value is not a number, zero is returned. + * @param attr search for <code>attr <var>value</var></code> + * @param defarch default arch of this arch, or <code>null</code> if this + * arch is a default arch or the default arch should be ignored + * @return <code><var>value</var></code>, zero if not found + */ + int getAttributeInt(String attr, ArchObject defarch); + + /** + * Get the value of an arch attribute from the archText both of the arch + * itself and if n.e. in it's default arch. If the attribute doesn't exist + * in either one, or the value is not a number, zero is returned. + * @param attr search for "attr <value>" + * @param useDefArch <code>true</code> if the default arch of this + * ArchObject should be queried as well, <code>false</code> to ignore it + * @return <value>, zero if not found + */ + int getAttributeInt(String attr, boolean useDefArch); + + /** + * Get the value of an arch attribute from the archText both of the arch + * itself and eventually its default arch. If the attribute doesn't exist + * in either one, or the value is not a number, zero is returned. + * @param attr search for "attr <value>" + * @param defarch default arch of this arch, or <code>null</code> if this + * arch is a default arch or the default arch should be ignored + * @return <value>, zero if not found + */ + long getAttributeLong(String attr, ArchObject defarch); + + /** + * Get the value of an arch attribute from the archText both of the arch + * itself and eventually its default arch. If the attribute doesn't exist + * in either one, or the value is not a number, zero is returned. + * @param attr search for "attr <value>" + * @param useDefArch <code>true</code> if the default arch of this + * ArchObject should be queried as well, <code>false</code> to ignore it + * @return <value>, zero if not found + */ + long getAttributeLong(String attr, boolean useDefArch); + + /** + * Get the value of an arch attribute from the archText both of the arch + * itself and eventually its default arch. If the attribute doesn't exist + * in either one, or the value is not a number, zero is returned. + * @param attr search for "attr <value>" + * @param defarch default arch of this arch, or <code>null</code> if this + * arch is a default arch or the default arch should be ignored + * @return <value>, zero if not found + */ + double getAttributeDouble(String attr, ArchObject defarch); + + /** + * Get the value of an arch attribute from the archText both of the arch + * itself and eventually its default arch. If the attribute doesn't exist + * in either one, or the value is not a number, zero is returned. + * @param attr search for "attr <value>" + * @param useDefArch <code>true</code> if the default arch of this + * ArchObject should be queried as well, <code>false</code> to ignore it + * @return <value>, zero if not found + */ + double getAttributeDouble(String attr, boolean useDefArch); + } // interface ArchObject This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |