From: <chr...@us...> - 2006-12-30 18:29:25
|
Revision: 1342 http://svn.sourceforge.net/gridarta/?rev=1342&view=rev Author: christianhujer Date: 2006-12-30 10:29:25 -0800 (Sat, 30 Dec 2006) Log Message: ----------- Extracted common Spell class members. Modified Paths: -------------- trunk/crossfire/src/cfeditor/Spells.java trunk/daimonin/src/daieditor/Spells.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/Spells.java Modified: trunk/crossfire/src/cfeditor/Spells.java =================================================================== --- trunk/crossfire/src/cfeditor/Spells.java 2006-12-30 17:50:07 UTC (rev 1341) +++ trunk/crossfire/src/cfeditor/Spells.java 2006-12-30 18:29:25 UTC (rev 1342) @@ -33,76 +33,25 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; -import javax.swing.JFileChooser; -import javax.swing.filechooser.FileFilter; -import javax.xml.parsers.DocumentBuilder; import net.sf.gridarta.io.IOUtils; -import net.sf.japi.swing.ActionFactory; -import net.sf.japi.util.filter.file.FilenameFileFilter; -import net.sf.japi.xml.NodeListIterator; import org.apache.log4j.Logger; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.xml.sax.SAXException; /** * This class manages the spells and spell lists. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> * @todo move spell related stuff from CFArchTypeList to this class. */ -public final class Spells { +public final class Spells extends net.sf.gridarta.Spells { - /** Action Factory. */ - private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); - private static final Logger log = Logger.getLogger(Spells.class); - private String[] spellNames; // array of spell names (these all begin with a ' ' space!) - - private int[] spellNumbers; // array of spell numbers - - /** File filter for filtering spellist.h files. */ - private static final FileFilter SPELLIST_H_FILE_FILTER = new FilenameFileFilter(true, "spellist.h", "spellist.h"); - /** - * Opens a file chooser to select the spellist file, - * then import spells. - * @param mainControl main control - */ - public void importSpellsWanted(final CMainControl mainControl) { - // open a file chooser window - final JFileChooser fileChooser = new JFileChooser(); - fileChooser.setDialogTitle("Open CF Spellist File"); - fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); - fileChooser.setMultiSelectionEnabled(false); - fileChooser.setFileFilter(SPELLIST_H_FILE_FILTER); // apply file filter - final File cd = new File(System.getProperty("user.dir")); - final File sd = new File(cd, "../server/src/include"); - fileChooser.setCurrentDirectory(sd.exists() ? sd : cd); - - final int returnVal = fileChooser.showOpenDialog(mainControl.getMainView()); - - if (returnVal == JFileChooser.APPROVE_OPTION) { - // now import spells from selected file - final File spellfile = fileChooser.getSelectedFile(); - final int spnum = importSpells(spellfile); - if (spnum > 0) { - // yeah it worked - ACTION_FACTORY.showMessageDialog(mainControl.getMainView(), "importSpellsSuccess", spnum); - } else { - // spell collect failed - ACTION_FACTORY.showMessageDialog(mainControl.getMainView(), "importSpellsFailed"); - } - } - } - - /** * Read all spells from a Crossfire spellist file and write an * alphabetical list into "spells.def". * @param spellfile spellfile to read * @return number of successfully collected spells */ - private static int importSpells(final File spellfile) { + @Override protected int importSpells(final File spellfile) { List<String> list = null; // growable array of spellnames+numbers String tmp; // tmp String for spell names @@ -214,83 +163,9 @@ return 0; } - /** - * Returns the base directory to read the spells from. - * @return base directory to read the spells from. - */ - public String getSpellsBaseDir() { + /** {@inheritDoc} */ + @Override protected String getSpellsBaseDir() { return IGUIConstants.CONFIG_DIR; } - /** - * Read the spells from "spells.xml" into the arrays 'spellNames' - * and 'spellNumbers'. This method is called at startup. - * @param documentBuilder Document Builder to use for parsing - */ - public void loadSpellsFromXML(final DocumentBuilder documentBuilder) { - spellNames = null; - spellNumbers = null; - - try { - // open reading stream to the spells xml file - final String baseDir = getSpellsBaseDir(); - - // parse xml document - final Document doc = documentBuilder.parse(new File(baseDir, IGUIConstants.SPELL_FILE)); - - // retrieve the spell data from the xml - final Element root = doc.getDocumentElement(); - if (root == null || !"spells".equalsIgnoreCase(root.getNodeName())) { - log.warn("File '" + IGUIConstants.SPELL_FILE + "' lacks root element 'spells'."); - } else { - final List<String> tmpSpellNames = new ArrayList<String>(); - final List<Integer> tmpSpellNumbers = new ArrayList<Integer>(); - // initialize array with appropriate size - for (final Element spellElem : new NodeListIterator<Element>(root, "spell")) { - - 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 - tmpSpellNumbers.add(Integer.parseInt(spellElem.getAttribute("id"))); - tmpSpellNames.add(spellElem.getAttribute("name").trim()); - } catch (final NumberFormatException de) { - log.warn("Parsing error in '" + IGUIConstants.SPELL_FILE + "':\n spell id '" + spellElem.getAttribute("id") + "' is not an integer."); - } - } - } - - // loading successful - log.info("Loaded " + tmpSpellNames.size() + " defined spells from '" + IGUIConstants.SPELL_FILE + "'"); - if (tmpSpellNames.isEmpty()) { - log.warn("File '" + IGUIConstants.SPELL_FILE + "' has no content."); - } else { - tmpSpellNames.add(0, "<none>"); - tmpSpellNumbers.add(0, -1); - spellNames = tmpSpellNames.toArray(new String[tmpSpellNames.size()]); - spellNumbers = new int[tmpSpellNumbers.size()]; - // No good conversion in case of generics - for (int i = 0; i < tmpSpellNumbers.size(); i++) { - spellNumbers[i] = tmpSpellNumbers.get(i); - } - } - } - } catch (final SAXException e) { - log.error("Parsing error in '" + IGUIConstants.SPELL_FILE + "':\n" + e.getMessage() + '\n'); - } catch (final IOException e) { - log.error("Cannot read file '" + IGUIConstants.SPELL_FILE + "'!"); - } - } - - public String[] getSpellNames() { - return spellNames; - } - - public int[] getSpellNumbers() { - return spellNumbers; - } - } // class Spells Modified: trunk/daimonin/src/daieditor/Spells.java =================================================================== --- trunk/daimonin/src/daieditor/Spells.java 2006-12-30 17:50:07 UTC (rev 1341) +++ trunk/daimonin/src/daieditor/Spells.java 2006-12-30 18:29:25 UTC (rev 1342) @@ -30,81 +30,28 @@ import java.io.IOException; import java.io.OutputStreamWriter; import java.io.PrintWriter; -import java.util.ArrayList; import java.util.Date; -import java.util.List; import java.util.Map; import java.util.TreeMap; -import javax.swing.JFileChooser; -import javax.swing.filechooser.FileFilter; -import javax.xml.parsers.DocumentBuilder; import net.sf.gridarta.io.IOUtils; -import net.sf.japi.swing.ActionFactory; -import net.sf.japi.util.filter.file.FilenameFileFilter; -import net.sf.japi.xml.NodeListIterator; import org.apache.log4j.Logger; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.xml.sax.SAXException; /** * This class manages the spells and spell lists. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> * @todo move spell related stuff from CFArchTypeList to this class. */ -public final class Spells { +public final class Spells extends net.sf.gridarta.Spells { - /** Action Factory. */ - private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("daieditor"); - private static final Logger log = Logger.getLogger(Spells.class); - private String[] spellNames; // array of spell names (these all begin with a ' ' space!) - - private int[] spellNumbers; // array of spell numbers - - /** File filter for filtering spellist.h files. */ - private static final FileFilter SPELLIST_H_FILE_FILTER = new FilenameFileFilter(true, "spellist.h", "spellist.h"); - /** - * Opens a file chooser to select the spellist file, - * then import spells. - * @param mainControl main control - */ - public void importSpellsWanted(final CMainControl mainControl) { - // open a file chooser window - final JFileChooser fileChooser = new JFileChooser(); - fileChooser.setDialogTitle("Open CF Spellist File"); - fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); - fileChooser.setMultiSelectionEnabled(false); - fileChooser.setFileFilter(SPELLIST_H_FILE_FILTER); // apply file filter - final File cd = new File(System.getProperty("user.dir")); - final File sd = new File(cd, "../server/src/include"); - fileChooser.setCurrentDirectory(sd.exists() ? sd : cd); - - final int returnVal = fileChooser.showOpenDialog(mainControl.getMainView()); - - if (returnVal == JFileChooser.APPROVE_OPTION) { - // now import spells from selected file - final File spellfile = fileChooser.getSelectedFile(); - final int spnum = importSpells(spellfile); - if (spnum > 0) { - // yeah it worked - ACTION_FACTORY.showMessageDialog(mainControl.getMainView(), "importSpellsSuccess", spnum); - } else { - // spell collect failed - ACTION_FACTORY.showMessageDialog(mainControl.getMainView(), "importSpellsFailed"); - } - } - } - - /** * Read all spells from a Daimonin spellist file and write an * alphabetical list into "spells.def". * @param spellfile spellfile to read * @return number of successfully collected spells */ - private static int importSpells(final File spellfile) { + @Override protected int importSpells(final File spellfile) { final Map<String, String> spells = new TreeMap<String, String>(); if ("spellist.h".equalsIgnoreCase(spellfile.getName())) { try { @@ -187,83 +134,9 @@ return spells.size(); } - /** - * Returns the base directory to read the spells from. - * @return base directory to read the spells from. - */ - public String getSpellsBaseDir() { + /** {@inheritDoc} */ + @Override protected String getSpellsBaseDir() { return CMainControl.getInstance().getArchDefaultFolder() + "/" + IGUIConstants.CONFIG_DIR; } - /** - * Read the spells from "spells.xml" into the arrays 'spellNames' - * and 'spellNumbers'. This method is called at startup. - * @param documentBuilder Document Builder to use for parsing - */ - public void loadSpellsFromXML(final DocumentBuilder documentBuilder) { - spellNames = null; - spellNumbers = null; - - try { - // open reading stream to the spells xml file - final String baseDir = getSpellsBaseDir(); - - // parse xml document - final Document doc = documentBuilder.parse(new File(baseDir, IGUIConstants.SPELL_FILE)); - - // retrieve the spell data from the xml - final Element root = doc.getDocumentElement(); - if (root == null || !"spells".equalsIgnoreCase(root.getNodeName())) { - log.warn("File '" + IGUIConstants.SPELL_FILE + "' lacks root element 'spells'."); - } else { - final List<String> tmpSpellNames = new ArrayList<String>(); - final List<Integer> tmpSpellNumbers = new ArrayList<Integer>(); - // initialize array with appropriate size - for (final Element spellElem : new NodeListIterator<Element>(root, "spell")) { - - 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 - tmpSpellNumbers.add(Integer.parseInt(spellElem.getAttribute("id"))); - tmpSpellNames.add(spellElem.getAttribute("name").trim()); - } catch (final NumberFormatException de) { - log.warn("Parsing error in '" + IGUIConstants.SPELL_FILE + "':\n spell id '" + spellElem.getAttribute("id") + "' is not an integer."); - } - } - } - - // loading successful - log.info("Loaded " + tmpSpellNames.size() + " defined spells from '" + IGUIConstants.SPELL_FILE + "'"); - if (tmpSpellNames.isEmpty()) { - log.warn("File '" + IGUIConstants.SPELL_FILE + "' has no content."); - } else { - tmpSpellNames.add(0, "<none>"); - tmpSpellNumbers.add(0, -1); - spellNames = tmpSpellNames.toArray(new String[tmpSpellNames.size()]); - spellNumbers = new int[tmpSpellNumbers.size()]; - // No good conversion in case of generics - for (int i = 0; i < tmpSpellNumbers.size(); i++) { - spellNumbers[i] = tmpSpellNumbers.get(i); - } - } - } - } catch (final SAXException e) { - log.error("Parsing error in '" + IGUIConstants.SPELL_FILE + "':\n" + e.getMessage() + '\n'); - } catch (final IOException e) { - log.error("Cannot read file '" + IGUIConstants.SPELL_FILE + "'!"); - } - } - - public String[] getSpellNames() { - return spellNames; - } - - public int[] getSpellNumbers() { - return spellNumbers; - } - } // class Spells Added: trunk/src/app/net/sf/gridarta/Spells.java =================================================================== --- trunk/src/app/net/sf/gridarta/Spells.java (rev 0) +++ trunk/src/app/net/sf/gridarta/Spells.java 2006-12-30 18:29:25 UTC (rev 1342) @@ -0,0 +1,152 @@ +package net.sf.gridarta; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import javax.swing.JFileChooser; +import javax.swing.filechooser.FileFilter; +import javax.xml.parsers.DocumentBuilder; +import net.sf.japi.swing.ActionFactory; +import net.sf.japi.util.filter.file.FilenameFileFilter; +import net.sf.japi.xml.NodeListIterator; +import org.apache.log4j.Logger; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.xml.sax.SAXException; + +/** + * Common base class for spells and spell lists. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public abstract class Spells { + + /** Action Factory. */ + private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("daieditor"); + + /** Logger. */ + private static final Logger log = Logger.getLogger(Spells.class); + + private String[] spellNames; // array of spell names (these all begin with a ' ' space!) + + private int[] spellNumbers; // array of spell numbers + + /** File filter for filtering spellist.h files. */ + private static final FileFilter SPELLIST_H_FILE_FILTER = new FilenameFileFilter(true, "spellist.h", "spellist.h"); + + /** + * Opens a file chooser to select the spellist file, + * then import spells. + * @param mainControl main control + */ + public void importSpellsWanted(final MainControl mainControl) { + // open a file chooser window + final JFileChooser fileChooser = new JFileChooser(); + fileChooser.setDialogTitle("Open CF Spellist File"); + fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); + fileChooser.setMultiSelectionEnabled(false); + fileChooser.setFileFilter(SPELLIST_H_FILE_FILTER); // apply file filter + final File cd = new File(System.getProperty("user.dir")); + final File sd = new File(cd, "../server/src/include"); + fileChooser.setCurrentDirectory(sd.exists() ? sd : cd); + + final int returnVal = fileChooser.showOpenDialog(mainControl.getMainView()); + + if (returnVal == JFileChooser.APPROVE_OPTION) { + // now import spells from selected file + final File spellfile = fileChooser.getSelectedFile(); + final int spnum = importSpells(spellfile); + if (spnum > 0) { + // yeah it worked + ACTION_FACTORY.showMessageDialog(mainControl.getMainView(), "importSpellsSuccess", spnum); + } else { + // spell collect failed + ACTION_FACTORY.showMessageDialog(mainControl.getMainView(), "importSpellsFailed"); + } + } + } + /** + * Read all spells from a Crossfire spellist file and write an + * alphabetical list into "spells.def". + * @param spellfile spellfile to read + * @return number of successfully collected spells + */ + protected abstract int importSpells(final File spellfile); + + /** + * Returns the base directory to read the spells from. + * @return base directory to read the spells from. + */ + protected abstract String getSpellsBaseDir(); + + /** + * Read the spells from "spells.xml" into the arrays 'spellNames' + * and 'spellNumbers'. This method is called at startup. + * @param documentBuilder Document Builder to use for parsing + */ + public final void loadSpellsFromXML(final DocumentBuilder documentBuilder) { + spellNames = null; + spellNumbers = null; + + try { + // open reading stream to the spells xml file + final String baseDir = getSpellsBaseDir(); + + // parse xml document + final Document doc = documentBuilder.parse(new File(baseDir, CommonConstants.SPELL_FILE)); + + // retrieve the spell data from the xml + final Element root = doc.getDocumentElement(); + if (root == null || !"spells".equalsIgnoreCase(root.getNodeName())) { + log.warn("File '" + CommonConstants.SPELL_FILE + "' lacks root element 'spells'."); + } else { + final List<String> tmpSpellNames = new ArrayList<String>(); + final List<Integer> tmpSpellNumbers = new ArrayList<Integer>(); + // initialize array with appropriate size + for (final Element spellElem : new NodeListIterator<Element>(root, "spell")) { + + if (spellElem.getAttribute("id") == null) { + log.warn("In File '" + CommonConstants.SPELL_FILE + "': Found 'spell' element without 'id'"); + } else if (spellElem.getAttribute("name") == null) { + log.warn("In File '" + CommonConstants.SPELL_FILE + "': Found 'spell' element without 'name'"); + } else { + try { + // parse spell number and -name + tmpSpellNumbers.add(Integer.parseInt(spellElem.getAttribute("id"))); + tmpSpellNames.add(spellElem.getAttribute("name").trim()); + } catch (final NumberFormatException de) { + log.warn("Parsing error in '" + CommonConstants.SPELL_FILE + "':\n spell id '" + spellElem.getAttribute("id") + "' is not an integer."); + } + } + } + + // loading successful + log.info("Loaded " + tmpSpellNames.size() + " defined spells from '" + CommonConstants.SPELL_FILE + "'"); + if (tmpSpellNames.isEmpty()) { + log.warn("File '" + CommonConstants.SPELL_FILE + "' has no content."); + } else { + tmpSpellNames.add(0, "<none>"); + tmpSpellNumbers.add(0, -1); + spellNames = tmpSpellNames.toArray(new String[tmpSpellNames.size()]); + spellNumbers = new int[tmpSpellNumbers.size()]; + // No good conversion in case of generics + for (int i = 0; i < tmpSpellNumbers.size(); i++) { + spellNumbers[i] = tmpSpellNumbers.get(i); + } + } + } + } catch (final SAXException e) { + log.error("Parsing error in '" + CommonConstants.SPELL_FILE + "':\n" + e.getMessage() + '\n'); + } catch (final IOException e) { + log.error("Cannot read file '" + CommonConstants.SPELL_FILE + "'!"); + } + } + + public String[] getSpellNames() { + return spellNames; + } + + public int[] getSpellNumbers() { + return spellNumbers; + } +} // class Spells Property changes on: trunk/src/app/net/sf/gridarta/Spells.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-12-31 00:03:24
|
Revision: 1344 http://svn.sourceforge.net/gridarta/?rev=1344&view=rev Author: christianhujer Date: 2006-12-30 16:03:22 -0800 (Sat, 30 Dec 2006) Log Message: ----------- Added explanations to merge statistics. Modified Paths: -------------- trunk/build.xml trunk/src/doc/dev/mergeStats.xhtml Modified: trunk/build.xml =================================================================== --- trunk/build.xml 2006-12-30 18:32:15 UTC (rev 1343) +++ trunk/build.xml 2006-12-31 00:03:22 UTC (rev 1344) @@ -197,6 +197,7 @@ <include name="dtd/**/*.xml" /> <include name="**/*.css" /> <include name="**/*.png" /> + <include name="**/*.gif" /> <include name="robots.txt" /> <exclude name="**/.xvpics/*.png" /> </fileset> Modified: trunk/src/doc/dev/mergeStats.xhtml =================================================================== --- trunk/src/doc/dev/mergeStats.xhtml 2006-12-30 18:32:15 UTC (rev 1343) +++ trunk/src/doc/dev/mergeStats.xhtml 2006-12-31 00:03:22 UTC (rev 1344) @@ -15,5 +15,18 @@ <p> <img src="mergeDiagram.gif" alt="Diagram illustrating merge progress" /> </p> + <h2>Explanation</h2> + <p> + X-Axis: commit number. + <br /> + Y-Axis: raw lines of code, including comments and empty lines. + </p> + <p> + The measurement of Crossfire Code and Daimonin Code was done excluding textedit stuff. + </p> + <p> + <em>Note:</em> The X-Axis shows commit number. + It's invalid to interpret the X-Axis as a time line. + </p> </body> </html> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-31 01:04:30
|
Revision: 1345 http://svn.sourceforge.net/gridarta/?rev=1345&view=rev Author: christianhujer Date: 2006-12-30 17:04:31 -0800 (Sat, 30 Dec 2006) Log Message: ----------- Added CopyBuffer base class. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CopyBuffer.java trunk/daimonin/src/daieditor/CopyBuffer.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/CopyBuffer.java Modified: trunk/crossfire/src/cfeditor/CopyBuffer.java =================================================================== --- trunk/crossfire/src/cfeditor/CopyBuffer.java 2006-12-31 00:03:22 UTC (rev 1344) +++ trunk/crossfire/src/cfeditor/CopyBuffer.java 2006-12-31 01:04:31 UTC (rev 1345) @@ -45,24 +45,10 @@ * @author <a href="mailto:and...@gm...">Andreas Vogl</a> * @author Andreas Kirschbaum */ -public final class CopyBuffer { +public final class CopyBuffer extends net.sf.gridarta.CopyBuffer { private static final Logger log = Logger.getLogger(CopyBuffer.class); - /** Mode for operations. */ - private enum Mode { - - /** Clear the selection. */ - DO_CLEAR, - - /** Cut the selection. */ - DO_CUT, - - /** Copy the selection. */ - DO_COPY - - } // enum Mode - /** Reference to main control. */ private final CMainControl mainControl; Modified: trunk/daimonin/src/daieditor/CopyBuffer.java =================================================================== --- trunk/daimonin/src/daieditor/CopyBuffer.java 2006-12-31 00:03:22 UTC (rev 1344) +++ trunk/daimonin/src/daieditor/CopyBuffer.java 2006-12-31 01:04:31 UTC (rev 1345) @@ -47,24 +47,10 @@ * @author <a href="mailto:and...@gm...">Andreas Vogl</a> * @author Andreas Kirschbaum */ -public final class CopyBuffer { +public final class CopyBuffer extends net.sf.gridarta.CopyBuffer { private static final Logger log = Logger.getLogger(CopyBuffer.class); - /** Mode for operations. */ - private enum Mode { - - /** Clear the selection. */ - DO_CLEAR, - - /** Cut the selection. */ - DO_CUT, - - /** Copy the selection. */ - DO_COPY - - } // enum Mode - /** Reference to main control. */ private final CMainControl mainControl; Added: trunk/src/app/net/sf/gridarta/CopyBuffer.java =================================================================== --- trunk/src/app/net/sf/gridarta/CopyBuffer.java (rev 0) +++ trunk/src/app/net/sf/gridarta/CopyBuffer.java 2006-12-31 01:04:31 UTC (rev 1345) @@ -0,0 +1,25 @@ +package net.sf.gridarta; + +/** + * Common base implementation of CopyBuffer. + * The CopyBuffer is responsible for cut, copy, paste and related operations like filling. + * It is backed by an invisible MapModel. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public abstract class CopyBuffer { + + /** Mode for operations. */ + protected enum Mode { + + /** Clear the selection. */ + DO_CLEAR, + + /** Cut the selection. */ + DO_CUT, + + /** Copy the selection. */ + DO_COPY + + } // enum Mode + +} // class CopyBuffer Property changes on: trunk/src/app/net/sf/gridarta/CopyBuffer.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...> - 2007-01-01 01:43:40
|
Revision: 1348 http://svn.sourceforge.net/gridarta/?rev=1348&view=rev Author: christianhujer Date: 2006-12-31 17:43:39 -0800 (Sun, 31 Dec 2006) Log Message: ----------- Added gridarta CFArchType class for merging CFArchType. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CFArchType.java trunk/daimonin/src/daieditor/CFArchType.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/CFArchType.java Modified: trunk/crossfire/src/cfeditor/CFArchType.java =================================================================== --- trunk/crossfire/src/cfeditor/CFArchType.java 2006-12-31 16:51:21 UTC (rev 1347) +++ trunk/crossfire/src/cfeditor/CFArchType.java 2007-01-01 01:43:39 UTC (rev 1348) @@ -46,7 +46,7 @@ * @author <a href="mailto:and...@gm...">Andreas Vogl</a> * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ -public final class CFArchType { +public final class CFArchType extends net.sf.gridarta.CFArchType { private static final Logger log = Logger.getLogger(CFArchType.class); @@ -406,7 +406,7 @@ * Create the documentation to this GameObject-type. * @return the full html-text to be (parsed and) displayed */ - public String createHtmlDocu() { + @Override public String createHtmlDocu() { return ACTION_FACTORY.format("arcDoc.htmlText", typeName, desc != null ? desc.trim() : "", use != null ? use.trim() : ""); } @@ -419,23 +419,23 @@ * The number of attribute sections determine the number of tabs to be used. * @return number of attribute sections. */ - public int getSectionNum() { + @Override public int getSectionNum() { return sectionNum; } - public int getTypeNr() { + @Override public int getTypeNr() { return typenr; } - public String getTypeName() { + @Override public String getTypeName() { return typeName; } - public String[] getTypeAttr() { + @Override public String[] getTypeAttr() { return typeAttributes; } - public boolean matches(@NotNull final GameObject gameObject) { + @Override public boolean matches(@NotNull final GameObject gameObject) { if (getTypeNr() != gameObject.getArchTypNr()) { return false; } Modified: trunk/daimonin/src/daieditor/CFArchType.java =================================================================== --- trunk/daimonin/src/daieditor/CFArchType.java 2006-12-31 16:51:21 UTC (rev 1347) +++ trunk/daimonin/src/daieditor/CFArchType.java 2007-01-01 01:43:39 UTC (rev 1348) @@ -46,7 +46,7 @@ * @author <a href="mailto:and...@gm...">Andreas Vogl</a> * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ -public final class CFArchType { +public final class CFArchType extends net.sf.gridarta.CFArchType { private static final Logger log = Logger.getLogger(CFArchType.class); @@ -397,7 +397,7 @@ * Create the documentation to this GameObject-type. * @return the full html-text to be (parsed and) displayed */ - public String createHtmlDocu() { + @Override public String createHtmlDocu() { return ACTION_FACTORY.format("arcDoc.htmlText", typeName, desc != null ? desc.trim() : "", use != null ? use.trim() : ""); } @@ -410,23 +410,23 @@ * The number of attribute sections determine the number of tabs to be used. * @return number of attribute sections. */ - public int getSectionNum() { + @Override public int getSectionNum() { return sectionNum; } - public int getTypeNr() { + @Override public int getTypeNr() { return typenr; } - public String getTypeName() { + @Override public String getTypeName() { return typeName; } - public String[] getTypeAttr() { + @Override public String[] getTypeAttr() { return typeAttributes; } - public boolean matches(@NotNull final GameObject gameObject) { + @Override public boolean matches(@NotNull final GameObject gameObject) { if (getTypeNr() != gameObject.getArchTypNr()) { return false; } Added: trunk/src/app/net/sf/gridarta/CFArchType.java =================================================================== --- trunk/src/app/net/sf/gridarta/CFArchType.java (rev 0) +++ trunk/src/app/net/sf/gridarta/CFArchType.java 2007-01-01 01:43:39 UTC (rev 1348) @@ -0,0 +1,34 @@ +package net.sf.gridarta; + +import net.sf.gridarta.gameobject.GameObject; +import org.jetbrains.annotations.NotNull; + +/** + * Common base class for CFArchType. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + * @todo find a better name, eventually ObjectType or ArchetypeType. + */ +public abstract class CFArchType { + + /** + * Create the documentation to this GameObject-type. + * @return the full html-text to be (parsed and) displayed + */ + public abstract String createHtmlDocu(); + + /** + * Returns number of attribute sections. + * The number of attribute sections determine the number of tabs to be used. + * @return number of attribute sections. + */ + public abstract int getSectionNum(); + + public abstract int getTypeNr(); + + public abstract String getTypeName(); + + public abstract String[] getTypeAttr(); + + public abstract boolean matches(@NotNull GameObject gameObject); + +} // class CFArchType Property changes on: trunk/src/app/net/sf/gridarta/CFArchType.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...> - 2007-01-01 17:34:12
|
Revision: 1349 http://svn.sourceforge.net/gridarta/?rev=1349&view=rev Author: christianhujer Date: 2007-01-01 09:34:07 -0800 (Mon, 01 Jan 2007) Log Message: ----------- Replaced old IGUIConstants SPELLS with new CommonConstants SPELLS. Modified Paths: -------------- trunk/crossfire/src/cfeditor/IGUIConstants.java trunk/crossfire/src/cfeditor/Spells.java trunk/daimonin/src/daieditor/IGUIConstants.java trunk/daimonin/src/daieditor/Spells.java Modified: trunk/crossfire/src/cfeditor/IGUIConstants.java =================================================================== --- trunk/crossfire/src/cfeditor/IGUIConstants.java 2007-01-01 01:43:39 UTC (rev 1348) +++ trunk/crossfire/src/cfeditor/IGUIConstants.java 2007-01-01 17:34:07 UTC (rev 1349) @@ -24,7 +24,6 @@ package cfeditor; -import java.awt.Color; import java.awt.Insets; import javax.swing.border.Border; import javax.swing.border.EmptyBorder; @@ -134,9 +133,6 @@ */ String CONFIG_DIR = "resource/conf"; - // name of the configuration files: - String SPELL_FILE = "spells.xml"; // spell-numbers - String TYPEDEF_FILE = "types.xml"; // type-definitions String ARCH_FILE = "archetypes"; // file with all arches Modified: trunk/crossfire/src/cfeditor/Spells.java =================================================================== --- trunk/crossfire/src/cfeditor/Spells.java 2007-01-01 01:43:39 UTC (rev 1348) +++ trunk/crossfire/src/cfeditor/Spells.java 2007-01-01 17:34:07 UTC (rev 1349) @@ -33,6 +33,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import net.sf.gridarta.CommonConstants; import net.sf.gridarta.io.IOUtils; import org.apache.log4j.Logger; @@ -123,9 +124,9 @@ new File("resource").mkdir(); new File(IGUIConstants.CONFIG_DIR).mkdir(); } - dfile = new File(IGUIConstants.CONFIG_DIR, IGUIConstants.SPELL_FILE); + dfile = new File(IGUIConstants.CONFIG_DIR, CommonConstants.SPELL_FILE); } else { - dfile = new File(IGUIConstants.SPELL_FILE); + dfile = new File(CommonConstants.SPELL_FILE); } try { Modified: trunk/daimonin/src/daieditor/IGUIConstants.java =================================================================== --- trunk/daimonin/src/daieditor/IGUIConstants.java 2007-01-01 01:43:39 UTC (rev 1348) +++ trunk/daimonin/src/daieditor/IGUIConstants.java 2007-01-01 17:34:07 UTC (rev 1349) @@ -23,7 +23,6 @@ package daieditor; -import java.awt.Color; import java.awt.Insets; import javax.swing.border.Border; import javax.swing.border.EmptyBorder; @@ -132,9 +131,6 @@ */ String CONFIG_DIR = "dev/editor/conf"; - // name of the configuration files: - String SPELL_FILE = "spells.xml"; // spell-numbers - String TYPEDEF_FILE = "types.xml"; // type-definitions String ARCHDEF_FILE = "archdef.dat"; // position-data of multiparts Modified: trunk/daimonin/src/daieditor/Spells.java =================================================================== --- trunk/daimonin/src/daieditor/Spells.java 2007-01-01 01:43:39 UTC (rev 1348) +++ trunk/daimonin/src/daieditor/Spells.java 2007-01-01 17:34:07 UTC (rev 1349) @@ -33,6 +33,7 @@ import java.util.Date; import java.util.Map; import java.util.TreeMap; +import net.sf.gridarta.CommonConstants; import net.sf.gridarta.io.IOUtils; import org.apache.log4j.Logger; @@ -96,9 +97,9 @@ dir = new File(IGUIConstants.CONFIG_DIR); dir.mkdir(); } - dfile = new File(baseDir, IGUIConstants.SPELL_FILE); + dfile = new File(baseDir, CommonConstants.SPELL_FILE); } else { - dfile = new File(IGUIConstants.SPELL_FILE); + dfile = new File(CommonConstants.SPELL_FILE); } try { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2007-01-01 17:37:49
|
Revision: 1350 http://svn.sourceforge.net/gridarta/?rev=1350&view=rev Author: christianhujer Date: 2007-01-01 09:37:46 -0800 (Mon, 01 Jan 2007) Log Message: ----------- Some Spells unification. Modified Paths: -------------- trunk/crossfire/src/cfeditor/Spells.java trunk/daimonin/src/daieditor/Spells.java Modified: trunk/crossfire/src/cfeditor/Spells.java =================================================================== --- trunk/crossfire/src/cfeditor/Spells.java 2007-01-01 17:34:07 UTC (rev 1349) +++ trunk/crossfire/src/cfeditor/Spells.java 2007-01-01 17:37:46 UTC (rev 1350) @@ -115,16 +115,19 @@ // --------- now write the "spells.def" file --------- if (list != null && !list.isEmpty()) { + // FIXME: This should use DOM for writing the file. final File dfile; // create new file for writing (replaces old one if existent) if (IGUIConstants.CONFIG_DIR != null && IGUIConstants.CONFIG_DIR.length() > 0) { - final File dir = new File(IGUIConstants.CONFIG_DIR); - if (!dir.exists() || !dir.isDirectory()) { + final String baseDir = getSpellsBaseDir(); + + File dir = new File(baseDir); + if (!dir.exists() || !dir.isDirectory()) { // FIXME What if dir exists and is not a directory? mkdir will fail then! // create the config dir new File("resource").mkdir(); new File(IGUIConstants.CONFIG_DIR).mkdir(); } - dfile = new File(IGUIConstants.CONFIG_DIR, CommonConstants.SPELL_FILE); + dfile = new File(baseDir, CommonConstants.SPELL_FILE); } else { dfile = new File(CommonConstants.SPELL_FILE); } Modified: trunk/daimonin/src/daieditor/Spells.java =================================================================== --- trunk/daimonin/src/daieditor/Spells.java 2007-01-01 17:34:07 UTC (rev 1349) +++ trunk/daimonin/src/daieditor/Spells.java 2007-01-01 17:37:46 UTC (rev 1350) @@ -87,15 +87,13 @@ final File dfile; // create new file for writing (replaces old one if existent) if (IGUIConstants.CONFIG_DIR != null && IGUIConstants.CONFIG_DIR.length() > 0) { - final String baseDir = CMainControl.getInstance().getArchDefaultFolder() + "/" + IGUIConstants.CONFIG_DIR; + final String baseDir = getSpellsBaseDir(); File dir = new File(baseDir); if (!dir.exists() || !dir.isDirectory()) { // FIXME What if dir exists and is not a directory? mkdir will fail then! // create the config dir - dir = new File("resource"); - dir.mkdir(); - dir = new File(IGUIConstants.CONFIG_DIR); - dir.mkdir(); + new File("resource").mkdir(); + new File(IGUIConstants.CONFIG_DIR).mkdir(); } dfile = new File(baseDir, CommonConstants.SPELL_FILE); } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2007-01-01 17:43:23
|
Revision: 1351 http://svn.sourceforge.net/gridarta/?rev=1351&view=rev Author: christianhujer Date: 2007-01-01 09:43:23 -0800 (Mon, 01 Jan 2007) Log Message: ----------- Moved types.xml file name definition to CommonConstants. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CFArchAttrib.java trunk/crossfire/src/cfeditor/CFArchType.java trunk/crossfire/src/cfeditor/CFArchTypeList.java trunk/crossfire/src/cfeditor/IGUIConstants.java trunk/daimonin/src/daieditor/CFArchAttrib.java trunk/daimonin/src/daieditor/CFArchType.java trunk/daimonin/src/daieditor/CFArchTypeList.java trunk/daimonin/src/daieditor/IGUIConstants.java trunk/src/app/net/sf/gridarta/CommonConstants.java Modified: trunk/crossfire/src/cfeditor/CFArchAttrib.java =================================================================== --- trunk/crossfire/src/cfeditor/CFArchAttrib.java 2007-01-01 17:37:46 UTC (rev 1350) +++ trunk/crossfire/src/cfeditor/CFArchAttrib.java 2007-01-01 17:43:23 UTC (rev 1351) @@ -24,6 +24,7 @@ package cfeditor; +import net.sf.gridarta.CommonConstants; import net.sf.gridarta.gameobject.ArchAttribType; import org.apache.log4j.Logger; import org.w3c.dom.Attr; @@ -114,7 +115,7 @@ atype = a1.getValue().trim(); } else { // error: no type - log.error("In '" + IGUIConstants.TYPEDEF_FILE + "': Type " + typeName + " has attribute missing '" + XML_ATTR_TYPE + "'."); + log.error("In '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + " has attribute missing '" + XML_ATTR_TYPE + "'."); return false; } @@ -123,7 +124,7 @@ try { inputLength = Integer.parseInt(a1.getValue()); } catch (final NumberFormatException de) { - log.error("In '" + IGUIConstants.TYPEDEF_FILE + "': Type " + typeName + " has attribute with invalid length '" + a1.getValue() + "' (must be a number)."); + log.error("In '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + " has attribute with invalid length '" + a1.getValue() + "' (must be a number)."); } } @@ -138,7 +139,7 @@ a1 = root.getAttributeNode("true"); final Attr a2 = root.getAttributeNode("false"); if (a1 == null || a2 == null) { - log.error("In '" + IGUIConstants.TYPEDEF_FILE + "': Type " + typeName + " has bool_special attribute missing 'true' or 'false' value."); + log.error("In '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + " has bool_special attribute missing 'true' or 'false' value."); return false; } @@ -169,7 +170,7 @@ } if (nameOld == null || nameOld.length() == 0 || endingOld == null || endingOld.length() == 0) { - log.warn("In '" + IGUIConstants.TYPEDEF_FILE + "': Type " + typeName + " has text attribute missing '" + XML_KEY_ARCH_BEGIN + "' or '" + XML_KEY_ARCH_END + "'."); + log.warn("In '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + " has text attribute missing '" + XML_KEY_ARCH_BEGIN + "' or '" + XML_KEY_ARCH_END + "'."); return false; } } else if ("fixed".equalsIgnoreCase(atype)) { @@ -178,7 +179,7 @@ if ((a1 = root.getAttributeNode("value")) != null) { nameNew = a1.getValue().trim(); } else { - log.warn("In '" + IGUIConstants.TYPEDEF_FILE + "': Type " + typeName + " has fixed attribute missing 'value'."); + log.warn("In '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + " has fixed attribute missing 'value'."); return false; } } else if ("spell".equalsIgnoreCase(atype)) { @@ -205,7 +206,7 @@ misc = new String[1]; misc[0] = bitmaskName; // store bitmask name in misc[0] } else { - log.warn("In '" + IGUIConstants.TYPEDEF_FILE + "', type " + typeName + ": Bitmask \"" + bitmaskName + "\" is undefined."); + log.warn("In '" + CommonConstants.TYPEDEF_FILE + "', type " + typeName + ": Bitmask \"" + bitmaskName + "\" is undefined."); } } else if (atype.startsWith("list")) { // got a bitmask attribute @@ -216,7 +217,7 @@ misc = new String[1]; misc[0] = listName; // store list name in misc[0] } else { - log.warn("In '" + IGUIConstants.TYPEDEF_FILE + "', type " + typeName + ": List \"" + listName + "\" is undefined."); + log.warn("In '" + CommonConstants.TYPEDEF_FILE + "', type " + typeName + ": List \"" + listName + "\" is undefined."); log.error("Size of tlist: " + tlist.getListTable().size()); for (final String key : tlist.getListTable().keySet()) { log.error(key); @@ -228,7 +229,7 @@ final int seppos = listNames.indexOf(','); if (seppos == -1 || seppos == listNames.length() - 1) { - log.error("In '" + IGUIConstants.TYPEDEF_FILE + "': Type " + typeName + ", double list: '" + atype + "' does not contain two comma-separated lists."); + log.error("In '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + ", double list: '" + atype + "' does not contain two comma-separated lists."); return false; } @@ -242,13 +243,13 @@ misc[0] = listName1; // store list name in misc[0] misc[1] = listName2; // store list name in misc[1] } else { - log.error("In '" + IGUIConstants.TYPEDEF_FILE + "', type " + typeName + ": List \"" + listName1 + "\" or \"" + listName2 + "\" is undefined."); + log.error("In '" + CommonConstants.TYPEDEF_FILE + "', type " + typeName + ": List \"" + listName1 + "\" or \"" + listName2 + "\" is undefined."); } } else if ("treasurelist".equalsIgnoreCase(atype)) { dataType = ArchAttribType.TREASURE; } else { // unknown type - log.warn("In '" + IGUIConstants.TYPEDEF_FILE + "': Type " + typeName + " has an attribute with unknown type: '" + atype + "'."); + log.warn("In '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + " has an attribute with unknown type: '" + atype + "'."); return false; } Modified: trunk/crossfire/src/cfeditor/CFArchType.java =================================================================== --- trunk/crossfire/src/cfeditor/CFArchType.java 2007-01-01 17:37:46 UTC (rev 1350) +++ trunk/crossfire/src/cfeditor/CFArchType.java 2007-01-01 17:43:23 UTC (rev 1351) @@ -28,6 +28,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import net.sf.gridarta.CommonConstants; import net.sf.gridarta.gameobject.ArchAttribType; import net.sf.gridarta.gameobject.GameObject; import net.sf.japi.swing.ActionFactory; @@ -168,7 +169,7 @@ } } catch (final NumberFormatException e) { // parsing type number failed: - log.error("In " + IGUIConstants.TYPEDEF_FILE + ": Type " + typeName + " has invalid type number '" + root.getAttribute("number") + "'."); + log.error("In " + CommonConstants.TYPEDEF_FILE + ": Type " + typeName + " has invalid type number '" + root.getAttribute("number") + "'."); return false; } @@ -220,7 +221,7 @@ if ((elem = getFirstChild(root, XML_IMPORT_TYPE)) != null) { final Attr a1 = elem.getAttributeNode("name"); if (a1 == null) { - throw new RuntimeException("In file '" + IGUIConstants.TYPEDEF_FILE + "': Type " + typeName + " has " + XML_IMPORT_TYPE + " element without 'name'."); + throw new RuntimeException("In file '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + " has " + XML_IMPORT_TYPE + " element without 'name'."); } else { importName = a1.getValue().trim(); } @@ -240,7 +241,7 @@ final Attr a1 = elem.getAttributeNode("name"); final String section; if (a1 == null) { - log.warn("In " + IGUIConstants.TYPEDEF_FILE + ": Type " + typeName + " contains a " + XML_SECTION + " missing 'name'."); + log.warn("In " + CommonConstants.TYPEDEF_FILE + ": Type " + typeName + " contains a " + XML_SECTION + " missing 'name'."); section = "?"; inSection = false; // we'll treat the attributes as "sectionless" } else { @@ -321,7 +322,7 @@ } } } else { - log.error("Syntax Error in file '" + IGUIConstants.TYPEDEF_FILE + "' (" + typeName + "):"); + log.error("Syntax Error in file '" + CommonConstants.TYPEDEF_FILE + "' (" + typeName + "):"); log.error(" import type \"" + importName + "\" not found!"); } } Modified: trunk/crossfire/src/cfeditor/CFArchTypeList.java =================================================================== --- trunk/crossfire/src/cfeditor/CFArchTypeList.java 2007-01-01 17:37:46 UTC (rev 1350) +++ trunk/crossfire/src/cfeditor/CFArchTypeList.java 2007-01-01 17:43:23 UTC (rev 1351) @@ -39,6 +39,7 @@ import javax.xml.xpath.XPath; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; +import net.sf.gridarta.CommonConstants; import net.sf.japi.swing.JSAXErrorHandler; import net.sf.japi.xml.NodeListIterator; import static net.sf.japi.xml.NodeListIterator.getFirstChild; @@ -165,7 +166,7 @@ final String baseDir = IGUIConstants.CONFIG_DIR; // parse xml document - final Document doc = documentBuilder.parse(new File(baseDir, IGUIConstants.TYPEDEF_FILE)); + final Document doc = documentBuilder.parse(new File(baseDir, CommonConstants.TYPEDEF_FILE)); // start parsing the xml final Element root = doc.getDocumentElement(); @@ -176,12 +177,12 @@ parseTypes(root); if (log.isInfoEnabled()) { - log.info("Loaded " + archTypeList.size() + " types from '" + IGUIConstants.TYPEDEF_FILE + "\'"); + log.info("Loaded " + archTypeList.size() + " types from '" + CommonConstants.TYPEDEF_FILE + "\'"); } } catch (final SAXException e) { - log.error("Parsing error in '" + IGUIConstants.TYPEDEF_FILE + "':\n" + e.getMessage()); + log.error("Parsing error in '" + CommonConstants.TYPEDEF_FILE + "':\n" + e.getMessage()); } catch (final IOException e) { - log.error("Cannot read file '" + IGUIConstants.TYPEDEF_FILE + "'!"); + log.error("Cannot read file '" + CommonConstants.TYPEDEF_FILE + "'!"); } catch (final XPathExpressionException e) { log.error("XPath error: " + e.getMessage()); } @@ -196,7 +197,7 @@ private void parseLists(final Element root) throws XPathExpressionException { for (final Element elem : new NodeListIterator<Element>(xpath, root, "list|lists/list")) { if (elem.getAttribute("name") == null) { - throw new RuntimeException("In file '" + IGUIConstants.TYPEDEF_FILE + "': cannot load list element without 'name'."); + throw new RuntimeException("In file '" + CommonConstants.TYPEDEF_FILE + "': cannot load list element without 'name'."); } else { final List<?> list = parseListFromElement(elem); if (list != null && !list.isEmpty()) { @@ -222,7 +223,7 @@ list.add(Integer.valueOf(elem.getAttribute("value"))); list.add(" " + elem.getAttribute("name").trim()); } catch (final NumberFormatException ignore) { - throw new RuntimeException("In '" + IGUIConstants.TYPEDEF_FILE + "', list " + root.getAttribute("name") + ": value '" + elem.getAttribute("value") + "' is not an integer."); + throw new RuntimeException("In '" + CommonConstants.TYPEDEF_FILE + "', list " + root.getAttribute("name") + ": value '" + elem.getAttribute("value") + "' is not an integer."); } } return list; @@ -231,7 +232,7 @@ private void parseIgnoreLists(final Element root) throws XPathExpressionException { for (final Element elem : new NodeListIterator<Element>(xpath, root, "ignore_list|ignorelists/ignore_list")) { if (elem.getAttribute("name") == null) { - throw new RuntimeException("In file '" + IGUIConstants.TYPEDEF_FILE + "': cannot load ignore_list element without 'name'."); + throw new RuntimeException("In file '" + CommonConstants.TYPEDEF_FILE + "': cannot load ignore_list element without 'name'."); } else { final String lname = elem.getAttribute("name").trim(); final List<String> content = new ArrayList<String>(); @@ -240,7 +241,7 @@ if (a != null) { content.add(a.getValue().trim()); } else { - throw new RuntimeException("In file '" + IGUIConstants.TYPEDEF_FILE + "': ignore_list '" + lname + "' has " + CFArchType.XML_ATTRIBUTE + " missing '" + CFArchAttrib.XML_KEY_ARCH + "'."); + throw new RuntimeException("In file '" + CommonConstants.TYPEDEF_FILE + "': ignore_list '" + lname + "' has " + CFArchType.XML_ATTRIBUTE + " missing '" + CFArchAttrib.XML_KEY_ARCH + "'."); } } // now add the list vector to the ignoreListTable: @@ -255,7 +256,7 @@ // parse default type final Element el = getFirstChild(root, "default_type"); if (el == null) { - throw new RuntimeException("In file '" + IGUIConstants.TYPEDEF_FILE + "': default_type element is missing!"); + throw new RuntimeException("In file '" + CommonConstants.TYPEDEF_FILE + "': default_type element is missing!"); } else { defaultArchType.load(el, this); } Modified: trunk/crossfire/src/cfeditor/IGUIConstants.java =================================================================== --- trunk/crossfire/src/cfeditor/IGUIConstants.java 2007-01-01 17:37:46 UTC (rev 1350) +++ trunk/crossfire/src/cfeditor/IGUIConstants.java 2007-01-01 17:43:23 UTC (rev 1351) @@ -133,8 +133,6 @@ */ String CONFIG_DIR = "resource/conf"; - String TYPEDEF_FILE = "types.xml"; // type-definitions - String ARCH_FILE = "archetypes"; // file with all arches String PNG_FILE = "crossfire.0"; // file with all pngs Modified: trunk/daimonin/src/daieditor/CFArchAttrib.java =================================================================== --- trunk/daimonin/src/daieditor/CFArchAttrib.java 2007-01-01 17:37:46 UTC (rev 1350) +++ trunk/daimonin/src/daieditor/CFArchAttrib.java 2007-01-01 17:43:23 UTC (rev 1351) @@ -24,6 +24,7 @@ package daieditor; +import net.sf.gridarta.CommonConstants; import net.sf.gridarta.gameobject.ArchAttribType; import org.apache.log4j.Logger; import org.w3c.dom.Attr; @@ -114,7 +115,7 @@ atype = a1.getValue().trim(); } else { // error: no type - log.error("In '" + IGUIConstants.TYPEDEF_FILE + "': Type " + typeName + " has attribute missing '" + XML_ATTR_TYPE + "'."); + log.error("In '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + " has attribute missing '" + XML_ATTR_TYPE + "'."); return false; } @@ -123,7 +124,7 @@ try { inputLength = Integer.parseInt(a1.getValue()); } catch (final NumberFormatException de) { - log.error("In '" + IGUIConstants.TYPEDEF_FILE + "': Type " + typeName + " has attribute with invalid length '" + a1.getValue() + "' (must be a number)."); + log.error("In '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + " has attribute with invalid length '" + a1.getValue() + "' (must be a number)."); } } @@ -138,7 +139,7 @@ a1 = root.getAttributeNode("true"); final Attr a2 = root.getAttributeNode("false"); if (a1 == null || a2 == null) { - log.error("In '" + IGUIConstants.TYPEDEF_FILE + "': Type " + typeName + " has bool_special attribute missing 'true' or 'false' value."); + log.error("In '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + " has bool_special attribute missing 'true' or 'false' value."); return false; } @@ -169,7 +170,7 @@ } if (nameOld == null || nameOld.length() == 0 || endingOld == null || endingOld.length() == 0) { - log.warn("In '" + IGUIConstants.TYPEDEF_FILE + "': Type " + typeName + " has text attribute missing '" + XML_KEY_ARCH_BEGIN + "' or '" + XML_KEY_ARCH_END + "'."); + log.warn("In '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + " has text attribute missing '" + XML_KEY_ARCH_BEGIN + "' or '" + XML_KEY_ARCH_END + "'."); return false; } } else if ("fixed".equalsIgnoreCase(atype)) { @@ -178,7 +179,7 @@ if ((a1 = root.getAttributeNode("value")) != null) { nameNew = a1.getValue().trim(); } else { - log.warn("In '" + IGUIConstants.TYPEDEF_FILE + "': Type " + typeName + " has fixed attribute missing 'value'."); + log.warn("In '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + " has fixed attribute missing 'value'."); return false; } } else if ("spell".equalsIgnoreCase(atype)) { @@ -205,7 +206,7 @@ misc = new String[1]; misc[0] = bitmaskName; // store bitmask name in misc[0] } else { - log.warn("In '" + IGUIConstants.TYPEDEF_FILE + "', type " + typeName + ": Bitmask \"" + bitmaskName + "\" is undefined."); + log.warn("In '" + CommonConstants.TYPEDEF_FILE + "', type " + typeName + ": Bitmask \"" + bitmaskName + "\" is undefined."); } } else if (atype.startsWith("list")) { // got a bitmask attribute @@ -216,7 +217,7 @@ misc = new String[1]; misc[0] = listName; // store list name in misc[0] } else { - log.warn("In '" + IGUIConstants.TYPEDEF_FILE + "', type " + typeName + ": List \"" + listName + "\" is undefined."); + log.warn("In '" + CommonConstants.TYPEDEF_FILE + "', type " + typeName + ": List \"" + listName + "\" is undefined."); log.error("Size of tlist: " + tlist.getListTable().size()); for (final String key : tlist.getListTable().keySet()) { log.error(key); @@ -228,7 +229,7 @@ final int seppos = listNames.indexOf(','); if (seppos == -1 || seppos == listNames.length() - 1) { - log.error("In '" + IGUIConstants.TYPEDEF_FILE + "': Type " + typeName + ", double list: '" + atype + "' does not contain two comma-separated lists."); + log.error("In '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + ", double list: '" + atype + "' does not contain two comma-separated lists."); return false; } @@ -242,13 +243,13 @@ misc[0] = listName1; // store list name in misc[0] misc[1] = listName2; // store list name in misc[1] } else { - log.error("In '" + IGUIConstants.TYPEDEF_FILE + "', type " + typeName + ": List \"" + listName1 + "\" or \"" + listName2 + "\" is undefined."); + log.error("In '" + CommonConstants.TYPEDEF_FILE + "', type " + typeName + ": List \"" + listName1 + "\" or \"" + listName2 + "\" is undefined."); } } else if ("treasurelist".equalsIgnoreCase(atype)) { dataType = ArchAttribType.TREASURE; } else { // unknown type - log.warn("In '" + IGUIConstants.TYPEDEF_FILE + "': Type " + typeName + " has an attribute with unknown type: '" + atype + "'."); + log.warn("In '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + " has an attribute with unknown type: '" + atype + "'."); return false; } Modified: trunk/daimonin/src/daieditor/CFArchType.java =================================================================== --- trunk/daimonin/src/daieditor/CFArchType.java 2007-01-01 17:37:46 UTC (rev 1350) +++ trunk/daimonin/src/daieditor/CFArchType.java 2007-01-01 17:43:23 UTC (rev 1351) @@ -28,6 +28,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import net.sf.gridarta.CommonConstants; import net.sf.gridarta.gameobject.ArchAttribType; import net.sf.gridarta.gameobject.GameObject; import net.sf.japi.swing.ActionFactory; @@ -168,7 +169,7 @@ } } catch (final NumberFormatException e) { // parsing type number failed: - throw new RuntimeException("In " + IGUIConstants.TYPEDEF_FILE + ": Type " + typeName + " has invalid type number '" + root.getAttribute("number") + "'."); + throw new RuntimeException("In " + CommonConstants.TYPEDEF_FILE + ": Type " + typeName + " has invalid type number '" + root.getAttribute("number") + "'."); } // parse 'ignore' elements @@ -219,7 +220,7 @@ if ((elem = getFirstChild(root, XML_IMPORT_TYPE)) != null) { final Attr a1 = elem.getAttributeNode("name"); if (a1 == null) { - throw new RuntimeException("In file '" + IGUIConstants.TYPEDEF_FILE + "': Type " + typeName + " has " + XML_IMPORT_TYPE + " element without 'name'."); + throw new RuntimeException("In file '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + " has " + XML_IMPORT_TYPE + " element without 'name'."); } else { importName = a1.getValue().trim(); } @@ -237,7 +238,7 @@ if (elem.getNodeName().equalsIgnoreCase(XML_SECTION) && elem.hasChildNodes()) { final Attr a1 = elem.getAttributeNode("name"); if (a1 == null) { - throw new RuntimeException("In " + IGUIConstants.TYPEDEF_FILE + ": Type " + typeName + " contains a " + XML_SECTION + " missing 'name'."); + throw new RuntimeException("In " + CommonConstants.TYPEDEF_FILE + ": Type " + typeName + " contains a " + XML_SECTION + " missing 'name'."); }// get section name final String section = a1.getValue().trim(); sectionNum++; // increment number of valid sections @@ -313,7 +314,7 @@ } } } else { - throw new RuntimeException("Syntax Error in file '" + IGUIConstants.TYPEDEF_FILE + "' (" + typeName + "):\n import type \"" + importName + "\" not found!"); + throw new RuntimeException("Syntax Error in file '" + CommonConstants.TYPEDEF_FILE + "' (" + typeName + "):\n import type \"" + importName + "\" not found!"); } } Modified: trunk/daimonin/src/daieditor/CFArchTypeList.java =================================================================== --- trunk/daimonin/src/daieditor/CFArchTypeList.java 2007-01-01 17:37:46 UTC (rev 1350) +++ trunk/daimonin/src/daieditor/CFArchTypeList.java 2007-01-01 17:43:23 UTC (rev 1351) @@ -40,6 +40,7 @@ import javax.xml.xpath.XPath; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; +import net.sf.gridarta.CommonConstants; import net.sf.japi.swing.JSAXErrorHandler; import net.sf.japi.xml.NodeListIterator; import static net.sf.japi.xml.NodeListIterator.getFirstChild; @@ -169,7 +170,7 @@ final String baseDir = CMainControl.getInstance().getArchDefaultFolder() + "/" + IGUIConstants.CONFIG_DIR; // parse xml document - final Document doc = documentBuilder.parse(new File(baseDir, IGUIConstants.TYPEDEF_FILE)); + final Document doc = documentBuilder.parse(new File(baseDir, CommonConstants.TYPEDEF_FILE)); // start parsing the xml final Element root = doc.getDocumentElement(); @@ -180,12 +181,12 @@ parseTypes(root); if (log.isInfoEnabled()) { - log.info("Loaded " + archTypeList.size() + " types from '" + IGUIConstants.TYPEDEF_FILE + "\'"); + log.info("Loaded " + archTypeList.size() + " types from '" + CommonConstants.TYPEDEF_FILE + "\'"); } } catch (final SAXException e) { - log.error("Parsing error in '" + IGUIConstants.TYPEDEF_FILE + "':\n" + e.getMessage()); + log.error("Parsing error in '" + CommonConstants.TYPEDEF_FILE + "':\n" + e.getMessage()); } catch (final IOException e) { - log.error("Cannot read file '" + IGUIConstants.TYPEDEF_FILE + "'!"); + log.error("Cannot read file '" + CommonConstants.TYPEDEF_FILE + "'!"); } catch (final XPathExpressionException e) { log.error("XPath error: " + e.getMessage()); } @@ -200,7 +201,7 @@ private void parseLists(final Element root) throws XPathExpressionException { for (final Element elem : new NodeListIterator<Element>(xpath, root, "list|lists/list")) { if (elem.getAttribute("name") == null) { - throw new RuntimeException("In file '" + IGUIConstants.TYPEDEF_FILE + "': cannot load list element without 'name'."); + throw new RuntimeException("In file '" + CommonConstants.TYPEDEF_FILE + "': cannot load list element without 'name'."); } else { final List<?> list = parseListFromElement(elem); if (list != null && !list.isEmpty()) { @@ -226,7 +227,7 @@ list.add(Integer.valueOf(elem.getAttribute("value"))); list.add(" " + elem.getAttribute("name").trim()); } catch (final NumberFormatException ignore) { - throw new RuntimeException("In '" + IGUIConstants.TYPEDEF_FILE + "', list " + root.getAttribute("name") + ": value '" + elem.getAttribute("value") + "' is not an integer."); + throw new RuntimeException("In '" + CommonConstants.TYPEDEF_FILE + "', list " + root.getAttribute("name") + ": value '" + elem.getAttribute("value") + "' is not an integer."); } } return list; @@ -235,7 +236,7 @@ private void parseIgnoreLists(final Element root) throws XPathExpressionException { for (final Element elem : new NodeListIterator<Element>(xpath, root, "ignore_list|ignorelists/ignore_list")) { if (elem.getAttribute("name") == null) { - throw new RuntimeException("In file '" + IGUIConstants.TYPEDEF_FILE + "': cannot load ignore_list element without 'name'."); + throw new RuntimeException("In file '" + CommonConstants.TYPEDEF_FILE + "': cannot load ignore_list element without 'name'."); } else { final String lname = elem.getAttribute("name").trim(); final List<String> content = new ArrayList<String>(); @@ -244,7 +245,7 @@ if (a != null) { content.add(a.getValue().trim()); } else { - throw new RuntimeException("In file '" + IGUIConstants.TYPEDEF_FILE + "': ignore_list '" + lname + "' has " + CFArchType.XML_ATTRIBUTE + " missing '" + CFArchAttrib.XML_KEY_ARCH + "'."); + throw new RuntimeException("In file '" + CommonConstants.TYPEDEF_FILE + "': ignore_list '" + lname + "' has " + CFArchType.XML_ATTRIBUTE + " missing '" + CFArchAttrib.XML_KEY_ARCH + "'."); } } // now add the list vector to the ignoreListTable: @@ -259,7 +260,7 @@ // parse default type final Element el = getFirstChild(root, "default_type"); if (el == null) { - throw new RuntimeException("In file '" + IGUIConstants.TYPEDEF_FILE + "': default_type element is missing!"); + throw new RuntimeException("In file '" + CommonConstants.TYPEDEF_FILE + "': default_type element is missing!"); } else { defaultArchType.load(el, this); } Modified: trunk/daimonin/src/daieditor/IGUIConstants.java =================================================================== --- trunk/daimonin/src/daieditor/IGUIConstants.java 2007-01-01 17:37:46 UTC (rev 1350) +++ trunk/daimonin/src/daieditor/IGUIConstants.java 2007-01-01 17:43:23 UTC (rev 1351) @@ -131,8 +131,6 @@ */ String CONFIG_DIR = "dev/editor/conf"; - String TYPEDEF_FILE = "types.xml"; // type-definitions - String ARCHDEF_FILE = "archdef.dat"; // position-data of multiparts // name of the arch resource files (these get read and written in the arch dir) Modified: trunk/src/app/net/sf/gridarta/CommonConstants.java =================================================================== --- trunk/src/app/net/sf/gridarta/CommonConstants.java 2007-01-01 17:37:46 UTC (rev 1350) +++ trunk/src/app/net/sf/gridarta/CommonConstants.java 2007-01-01 17:43:23 UTC (rev 1351) @@ -49,6 +49,9 @@ /** Name of the files the spell information (names and numbers). */ public static final String SPELL_FILE = "spells.xml"; + public static final String TYPEDEF_FILE = "types.xml"; // type-definitions + + /** * Don't instanciate. */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2007-01-01 18:13:23
|
Revision: 1353 http://svn.sourceforge.net/gridarta/?rev=1353&view=rev Author: christianhujer Date: 2007-01-01 10:13:22 -0800 (Mon, 01 Jan 2007) Log Message: ----------- Created unified CFArchTypeList superclass. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CFArchTypeList.java trunk/daimonin/src/daieditor/CFArchTypeList.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/CFArchTypeList.java Modified: trunk/crossfire/src/cfeditor/CFArchTypeList.java =================================================================== --- trunk/crossfire/src/cfeditor/CFArchTypeList.java 2007-01-01 18:11:08 UTC (rev 1352) +++ trunk/crossfire/src/cfeditor/CFArchTypeList.java 2007-01-01 18:13:22 UTC (rev 1353) @@ -25,31 +25,22 @@ package cfeditor; import cfeditor.gameobject.GameObject; -import java.io.File; -import java.io.IOException; +import java.awt.Component; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; -import javax.xml.xpath.XPath; import javax.xml.xpath.XPathExpressionException; -import javax.xml.xpath.XPathFactory; import net.sf.gridarta.CommonConstants; -import net.sf.japi.swing.JSAXErrorHandler; import net.sf.japi.xml.NodeListIterator; import static net.sf.japi.xml.NodeListIterator.getFirstChild; import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.w3c.dom.Attr; -import org.w3c.dom.Document; import org.w3c.dom.Element; -import org.xml.sax.SAXException; /** * This class handles all the CFArchTypes and makes them conveniently @@ -57,18 +48,12 @@ * @author <a href="mailto:and...@gm...">Andreas Vogl</a> * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ -public final class CFArchTypeList implements Iterable<CFArchType> { +public final class CFArchTypeList extends net.sf.gridarta.CFArchTypeList<CFArchType, GameObject> { private static final Logger log = Logger.getLogger(CFArchTypeList.class); private static final Spells spells = new Spells(); - /** DocumentBuilder. */ - private DocumentBuilder documentBuilder; - - /** The XPath for using XPath. */ - private XPath xpath; - /** * Table with type numbers as keys (Integer), and type names as values (String). */ @@ -77,27 +62,11 @@ // table with type arch type name as keys (String), and arch type object as values (CFArchType) private final Map<String, CFArchType> archTypeNames = new HashMap<String, CFArchType>(); - private final CFArchType defaultArchType = new CFArchType(null); // contains default type - - private final List<CFArchType> archTypeList = new ArrayList<CFArchType>(); // All but the default ArchType - /** * Table with CAttribBitmask objects (value) accessible by name (key). */ private final Map<String, CAttribBitmask> bitmaskTable; - /** - * Table with List objects for lists (value) accessible by name (key). - * The value type of the list is <code><?></code> because the lists elements are altering Integers and Strings. - * @todo Refactor the List to contain Pairs or something like that so it doesn't contain two types. - */ - private final Map<String, List<?>> listTable; - - /** - * Table with List objects for ignore_lists (value) accessible by name (key). - */ - private Map<String, List<String>> ignoreListTable; - /** List of exit object types. (Integer values) */ private static final HashSet<Integer> EXIT_TYPES = new HashSet<Integer>(); @@ -129,8 +98,6 @@ CFArchTypeList() { // initialize the arrays of "special-data" bitmaskTable = new HashMap<String, CAttribBitmask>(); - listTable = new HashMap<String, List<?>>(); - ignoreListTable = new HashMap<String, List<String>>(); try { initXML(); spells.loadSpellsFromXML(documentBuilder); @@ -142,94 +109,28 @@ ignoreListTable = null; // this was only needed during load phase } - /** - * Initialize the XML engine. - * @throws ParserConfigurationException in case the xml parser couldn't be set up - */ - private void initXML() throws ParserConfigurationException { - // TODO: Change hard coded document builder factory to user configurable settings - final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - dbf.setCoalescing(true); - // dbf.setExpandEntityReferences(true); // true is default on this - dbf.setIgnoringComments(true); - dbf.setIgnoringElementContentWhitespace(true); - dbf.setNamespaceAware(true); - dbf.setValidating(true); - dbf.setXIncludeAware(true); - documentBuilder = dbf.newDocumentBuilder(); - documentBuilder.setErrorHandler(new JSAXErrorHandler(CMainControl.getInstance().getMainView())); - xpath = XPathFactory.newInstance().newXPath(); + /** {@inheritDoc} */ + @Override protected CFArchType createDefaultArchType() { + return new CFArchType(null); } - private void loadTypesFromXML() { - try { - final String baseDir = IGUIConstants.CONFIG_DIR; + /** {@inheritDoc} */ + @Override protected Component getViewToBlock() { + return CMainControl.getInstance().getMainView(); + } - // parse xml document - final Document doc = documentBuilder.parse(new File(baseDir, CommonConstants.TYPEDEF_FILE)); - - // start parsing the xml - final Element root = doc.getDocumentElement(); - parseBitmasks(root); - parseLists(root); - parseIgnoreLists(root); - parseDefaultType(root); - parseTypes(root); - - if (log.isInfoEnabled()) { - log.info("Loaded " + archTypeList.size() + " types from '" + CommonConstants.TYPEDEF_FILE + "\'"); - } - } catch (final SAXException e) { - log.error("Parsing error in '" + CommonConstants.TYPEDEF_FILE + "':\n" + e.getMessage()); - } catch (final IOException e) { - log.error("Cannot read file '" + CommonConstants.TYPEDEF_FILE + "'!"); - } catch (final XPathExpressionException e) { - log.error("XPath error: " + e.getMessage()); - } + /** {@inheritDoc} */ + @Override protected String getConfigurationDirectory() { + return IGUIConstants.CONFIG_DIR; } - private void parseBitmasks(final Element root) throws XPathExpressionException { + @Override protected void parseBitmasks(final Element root) throws XPathExpressionException { for (final Element elem : new NodeListIterator<Element>(xpath, root, "bitmask|bitmasks/bitmask")) { bitmaskTable.put(elem.getAttribute("name"), new CAttribBitmask(xpath, elem)); } } - private void parseLists(final Element root) throws XPathExpressionException { - for (final Element elem : new NodeListIterator<Element>(xpath, root, "list|lists/list")) { - if (elem.getAttribute("name") == null) { - throw new RuntimeException("In file '" + CommonConstants.TYPEDEF_FILE + "': cannot load list element without 'name'."); - } else { - final List<?> list = parseListFromElement(elem); - if (list != null && !list.isEmpty()) { - listTable.put(elem.getAttribute("name"), list); - } - } - } - } - - /** - * Parse a list vector from an xml list element. - * @param root element to parse - * @return List with data parsed from <var>root</var> - * @todo improve this comment - * @throws XPathExpressionException In case of XPath issues (should never happen). - */ - private List<?> parseListFromElement(final Element root) throws XPathExpressionException { - // XXX The list created here contains altering types: Integer for even, String for odd indices. - final List<Object> list = new ArrayList<Object>(); - for (final Element elem : new NodeListIterator<Element>(xpath, root, "entry|listentry")) { - // every list entry adds value (Integer) and name (String) to the vector - try { - list.add(Integer.valueOf(elem.getAttribute("value"))); - list.add(" " + elem.getAttribute("name").trim()); - } catch (final NumberFormatException ignore) { - throw new RuntimeException("In '" + CommonConstants.TYPEDEF_FILE + "', list " + root.getAttribute("name") + ": value '" + elem.getAttribute("value") + "' is not an integer."); - } - } - return list; - } - - private void parseIgnoreLists(final Element root) throws XPathExpressionException { + @Override protected void parseIgnoreLists(final Element root) throws XPathExpressionException { for (final Element elem : new NodeListIterator<Element>(xpath, root, "ignore_list|ignorelists/ignore_list")) { if (elem.getAttribute("name") == null) { throw new RuntimeException("In file '" + CommonConstants.TYPEDEF_FILE + "': cannot load ignore_list element without 'name'."); @@ -252,7 +153,7 @@ } } - private void parseDefaultType(final Element root) { + @Override protected void parseDefaultType(final Element root) { // parse default type final Element el = getFirstChild(root, "default_type"); if (el == null) { @@ -262,7 +163,7 @@ } } - private void parseTypes(final Element root) { + @Override protected void parseTypes(final Element root) { // parse all type elements for (final Element elem : new NodeListIterator<Element>(root, "type")) { if (!"no".equals(elem.getAttribute("available"))) { @@ -293,35 +194,6 @@ } /** - * Return the ignore list table which contains all definitions of ignore lists for arch attributes. - * @return ignore list table - */ - public Map<String, List<String>> getIgnoreListTable() { - return ignoreListTable; - } - - /** - * Returns the list table which contains all definitions of list types for arch attributes. - * @return list table - */ - public Map<String, List<?>> getListTable() { - return listTable; - } - - /** {@inheritDoc} */ - public Iterator<CFArchType> iterator() { - return archTypeList.iterator(); - } - - public CFArchType getArchType(final int n) { - return archTypeList.get(n); - } - - public int getArchTypeIndex(@NotNull final CFArchType archType) { - return archTypeList.indexOf(archType); - } - - /** * Lookup the name of an archtype. * @param typeNr type number * @return name of this type, as defined in "typenumbers.xml" @@ -330,85 +202,14 @@ return archTypeNumbers.containsKey(typeNr) ? archTypeNumbers.get(typeNr) : "*UNKNOWN" + typeNr + "*"; } - /** - * Returns the number of CFArchTypes in the list. - * The default type is not counted. - * @return Number of CFArchTypes in the list. - */ - public int getLength() { - return archTypeList.size(); - } - - /** - * Find and return the type-structure (<code>CFArchType</code>) that - * matches for the given arch. This is not only a comparison between - * type numbers - special type-attributes must also be dealt with. - * <p/> - * IMPORTANT: A similar-but-nonequal version of this code is used in - * GameObjectAttributesDialog. Hence, if modifying this method, the appropriate parts - * in GameObjectAttributesDialog must also be updated and vice-versa. - * @param arch the arch to find the type for - * @return the <code>CFArchType</code> which belongs to this arch, - * or the first (misc) type if no match is found. - */ - public CFArchType getTypeOfArch(final GameObject arch) { - // check if the type of the object is present in the definitions - for (final CFArchType tmp : archTypeList) { - if (tmp.getTypeNr() == arch.getArchTypNr()) { - if (tmp.getTypeAttr() == null) { - // no type-attributes, so we only compared type-numbers - return tmp; - } else { - // check if all the type-attributes match - - if (log.isDebugEnabled()) { - log.debug("# type: " + tmp.getTypeName()); - } - - final int numArgs = (int) (tmp.getTypeAttr().length / 2.0); - boolean match = true; - for (int t = 0, l = numArgs * 2; t < l && match; t += 2) { - final String archvalue = arch.getAttributeString(tmp.getTypeAttr()[t]); - if (!archvalue.equals(tmp.getTypeAttr()[t + 1]) && !(tmp.getTypeAttr()[t + 1].equals("0") && archvalue.length() == 0)) { - match = false; - } - } - - // we've got a match after all - if (match) { - return tmp; - } - } - } - } - // type of archobject not found - return first one (misc) - return archTypeList.get(0); - } - - /** - * Returns whether this typelist contains no data. - * @return <code>true</code> if this typelist contains no data, otherwise <code>false</code>. - */ - public boolean isEmpty() { - return archTypeList.isEmpty(); - } - - /** - * Find and return the type-structure (<code>CFArchType</code>) that - * matches the given 'typeName'. These type-names are "artificial" - * names, defined in "types.txt". They appear in the type selection box - * in the attribute-dialog. - * @param typeName Name of the type to get. - * @return the <code>CFArchType</code> that matches, - * or the first (misc) type if no match is found. - */ - public CFArchType getTypeByName(final String typeName) { + /** {@inheritDoc} */ + @Override public CFArchType getTypeByName(final String typeName) { // return: matching type or first type (misc) if no other found final CFArchType type = archTypeNames.get(typeName.trim()); return type == null ? archTypeList.get(0) : type; } - @Nullable public CFArchType getType(@NotNull final GameObject gameObject) { + @Nullable @Override public CFArchType getType(@NotNull final GameObject gameObject) { CFArchType result = null; for (final CFArchType type : archTypeList) { if (result == null) { Modified: trunk/daimonin/src/daieditor/CFArchTypeList.java =================================================================== --- trunk/daimonin/src/daieditor/CFArchTypeList.java 2007-01-01 18:11:08 UTC (rev 1352) +++ trunk/daimonin/src/daieditor/CFArchTypeList.java 2007-01-01 18:13:22 UTC (rev 1353) @@ -27,21 +27,16 @@ import daieditor.gameobject.GameObject; import daieditor.gameobject.match.GameObjectMatchers; import daieditor.gameobject.match.NamedGameObjectMatcher; +import java.awt.Component; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; -import javax.xml.xpath.XPath; import javax.xml.xpath.XPathExpressionException; -import javax.xml.xpath.XPathFactory; import net.sf.gridarta.CommonConstants; -import net.sf.japi.swing.JSAXErrorHandler; import net.sf.japi.xml.NodeListIterator; import static net.sf.japi.xml.NodeListIterator.getFirstChild; import org.apache.log4j.Logger; @@ -58,7 +53,7 @@ * @author <a href="mailto:and...@gm...">Andreas Vogl</a> * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ -public final class CFArchTypeList implements Iterable<CFArchType> { +public final class CFArchTypeList extends net.sf.gridarta.CFArchTypeList<CFArchType, GameObject> { private static final Logger log = Logger.getLogger(CFArchTypeList.class); @@ -70,12 +65,6 @@ private static final Spells spells = new Spells(); - /** DocumentBuilder. */ - private DocumentBuilder documentBuilder; - - /** The XPath for using XPath. */ - private XPath xpath; - /** * Table with type numbers as keys (Integer), and type names as values (String). */ @@ -87,28 +76,12 @@ // table with type arch type name as keys (String), and arch type object as values (CFArchType) private final Map<String, CFArchType> archTypeNames = new HashMap<String, CFArchType>(); - private final CFArchType defaultArchType = new CFArchType(null); // contains default type - - private final List<CFArchType> archTypeList = new ArrayList<CFArchType>(); // All but the default ArchType - /** * Table with CAttribBitmask objects (value) accessible by name (key). */ private final Map<String, CAttribBitmask> bitmaskTable; /** - * Table with List objects for lists (value) accessible by name (key). - * The value type of the list is <code><?></code> because the lists elements are altering Integers and Strings. - * @todo Refactor the List to contain Pairs or something like that so it doesn't contain two types. - */ - private final Map<String, List<?>> listTable; - - /** - * Table with List objects for ignore_lists (value) accessible by name (key). - */ - private Map<String, List<String>> ignoreListTable; - - /** * Check whether the GameObject is an exit. * @param arch GameObject to check * @return <code>true</code> if <var>arch</var> is an exit, otherwise <code>false</code> @@ -131,8 +104,6 @@ CFArchTypeList() { // initialize the arrays of "special-data" bitmaskTable = new HashMap<String, CAttribBitmask>(); - listTable = new HashMap<String, List<?>>(); - ignoreListTable = new HashMap<String, List<String>>(); try { initXML(); spells.loadSpellsFromXML(documentBuilder); @@ -146,94 +117,28 @@ ignoreListTable = null; // this was only needed during load phase } - /** - * Initialize the XML engine. - * @throws ParserConfigurationException in case the xml parser couldn't be set up - */ - private void initXML() throws ParserConfigurationException { - // TODO: Change hard coded document builder factory to user configurable settings - final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - dbf.setCoalescing(true); - // dbf.setExpandEntityReferences(true); // true is default on this - dbf.setIgnoringComments(true); - dbf.setIgnoringElementContentWhitespace(true); - dbf.setNamespaceAware(true); - dbf.setValidating(true); - dbf.setXIncludeAware(true); - documentBuilder = dbf.newDocumentBuilder(); - documentBuilder.setErrorHandler(new JSAXErrorHandler(CMainControl.getInstance().getMainView())); - xpath = XPathFactory.newInstance().newXPath(); + /** {@inheritDoc} */ + @Override protected CFArchType createDefaultArchType() { + return new CFArchType(null); } - private void loadTypesFromXML() { - try { - final String baseDir = CMainControl.getInstance().getArchDefaultFolder() + "/" + IGUIConstants.CONFIG_DIR; + /** {@inheritDoc} */ + @Override protected Component getViewToBlock() { + return CMainControl.getInstance().getMainView(); + } - // parse xml document - final Document doc = documentBuilder.parse(new File(baseDir, CommonConstants.TYPEDEF_FILE)); - - // start parsing the xml - final Element root = doc.getDocumentElement(); - parseBitmasks(root); - parseLists(root); - parseIgnoreLists(root); - parseDefaultType(root); - parseTypes(root); - - if (log.isInfoEnabled()) { - log.info("Loaded " + archTypeList.size() + " types from '" + CommonConstants.TYPEDEF_FILE + "\'"); - } - } catch (final SAXException e) { - log.error("Parsing error in '" + CommonConstants.TYPEDEF_FILE + "':\n" + e.getMessage()); - } catch (final IOException e) { - log.error("Cannot read file '" + CommonConstants.TYPEDEF_FILE + "'!"); - } catch (final XPathExpressionException e) { - log.error("XPath error: " + e.getMessage()); - } + /** {@inheritDoc} */ + @Override protected String getConfigurationDirectory() { + return CMainControl.getInstance().getArchDefaultFolder() + "/" + IGUIConstants.CONFIG_DIR; } - private void parseBitmasks(final Element root) throws XPathExpressionException { + @Override protected void parseBitmasks(final Element root) throws XPathExpressionException { for (final Element elem : new NodeListIterator<Element>(xpath, root, "bitmask|bitmasks/bitmask")) { bitmaskTable.put(elem.getAttribute("name"), new CAttribBitmask(xpath, elem)); } } - private void parseLists(final Element root) throws XPathExpressionException { - for (final Element elem : new NodeListIterator<Element>(xpath, root, "list|lists/list")) { - if (elem.getAttribute("name") == null) { - throw new RuntimeException("In file '" + CommonConstants.TYPEDEF_FILE + "': cannot load list element without 'name'."); - } else { - final List<?> list = parseListFromElement(elem); - if (list != null && !list.isEmpty()) { - listTable.put(elem.getAttribute("name"), list); - } - } - } - } - - /** - * Parse a list vector from an xml list element. - * @param root element to parse - * @return List with data parsed from <var>root</var> - * @todo improve this comment - * @throws XPathExpressionException In case of XPath issues (should never happen). - */ - private List<?> parseListFromElement(final Element root) throws XPathExpressionException { - // XXX The list created here contains altering types: Integer for even, String for odd indices. - final List<Object> list = new ArrayList<Object>(); - for (final Element elem : new NodeListIterator<Element>(xpath, root, "entry|listentry")) { - // every list entry adds value (Integer) and name (String) to the vector - try { - list.add(Integer.valueOf(elem.getAttribute("value"))); - list.add(" " + elem.getAttribute("name").trim()); - } catch (final NumberFormatException ignore) { - throw new RuntimeException("In '" + CommonConstants.TYPEDEF_FILE + "', list " + root.getAttribute("name") + ": value '" + elem.getAttribute("value") + "' is not an integer."); - } - } - return list; - } - - private void parseIgnoreLists(final Element root) throws XPathExpressionException { + @Override protected void parseIgnoreLists(final Element root) throws XPathExpressionException { for (final Element elem : new NodeListIterator<Element>(xpath, root, "ignore_list|ignorelists/ignore_list")) { if (elem.getAttribute("name") == null) { throw new RuntimeException("In file '" + CommonConstants.TYPEDEF_FILE + "': cannot load ignore_list element without 'name'."); @@ -256,7 +161,7 @@ } } - private void parseDefaultType(final Element root) { + @Override protected void parseDefaultType(final Element root) { // parse default type final Element el = getFirstChild(root, "default_type"); if (el == null) { @@ -266,7 +171,7 @@ } } - private void parseTypes(final Element root) { + @Override protected void parseTypes(final Element root) { // parse all type elements for (final Element elem : new NodeListIterator<Element>(root, "type")) { if (!"no".equals(elem.getAttribute("available"))) { @@ -322,35 +227,6 @@ } /** - * Return the ignore list table which contains all definitions of ignore lists for arch attributes. - * @return ignore list table - */ - public Map<String, List<String>> getIgnoreListTable() { - return ignoreListTable; - } - - /** - * Returns the list table which contains all definitions of list types for arch attributes. - * @return list table - */ - public Map<String, List<?>> getListTable() { - return listTable; - } - - /** {@inheritDoc} */ - public Iterator<CFArchType> iterator() { - return archTypeList.iterator(); - } - - public CFArchType getArchType(final int n) { - return archTypeList.get(n); - } - - public int getArchTypeIndex(@NotNull final CFArchType archType) { - return archTypeList.indexOf(archType); - } - - /** * Lookup the name of an archtype. * @param typeNr type number * @return name of this type, as defined in "typenumbers.xml" @@ -359,85 +235,14 @@ return archTypeNumbers.containsKey(typeNr) ? archTypeNumbers.get(typeNr) : "*UNKNOWN" + typeNr + "*"; } - /** - * Returns the number of CFArchTypes in the list. - * The default type is not counted. - * @return Number of CFArchTypes in the list. - */ - public int getLength() { - return archTypeList.size(); - } - - /** - * Find and return the type-structure (<code>CFArchType</code>) that - * matches for the given arch. This is not only a comparison between - * type numbers - special type-attributes must also be dealt with. - * <p/> - * IMPORTANT: A similar-but-nonequal version of this code is used in - * GameObjectAttributesDialog. Hence, if modifying this method, the appropriate parts - * in GameObjectAttributesDialog must also be updated and vice-versa. - * @param arch the arch to find the type for - * @return the <code>CFArchType</code> which belongs to this arch, - * or the first (misc) type if no match is found. - */ - public CFArchType getTypeOfArch(final GameObject arch) { - // check if the type of the object is present in the definitions - for (final CFArchType tmp : archTypeList) { - if (tmp.getTypeNr() == arch.getArchTypNr()) { - if (tmp.getTypeAttr() == null) { - // no type-attributes, so we only compared type-numbers - return tmp; - } else { - // check if all the type-attributes match - - if (log.isDebugEnabled()) { - log.debug("# type: " + tmp.getTypeName()); - } - - final int numArgs = (int) (tmp.getTypeAttr().length / 2.0); - boolean match = true; - for (int t = 0, l = numArgs * 2; t < l && match; t += 2) { - final String archvalue = arch.getAttributeString(tmp.getTypeAttr()[t]); - if (!archvalue.equals(tmp.getTypeAttr()[t + 1]) && !(tmp.getTypeAttr()[t + 1].equals("0") && archvalue.length() == 0)) { - match = false; - } - } - - // we've got a match after all - if (match) { - return tmp; - } - } - } - } - // type of archobject not found - return first one (misc) - return archTypeList.get(0); - } - - /** - * Returns whether this typelist contains no data. - * @return <code>true</code> if this typelist contains no data, otherwise <code>false</code>. - */ - public boolean isEmpty() { - return archTypeList.isEmpty(); - } - - /** - * Find and return the type-structure (<code>CFArchType</code>) that - * matches the given 'typeName'. These type-names are "artificial" - * names, defined in "types.txt". They appear in the type selection box - * in the attribute-dialog. - * @param typeName Name of the type to get. - * @return the <code>CFArchType</code> that matches, - * or the first (misc) type if no match is found. - */ - public CFArchType getTypeByName(final String typeName) { + /** {@inheritDoc} */ + @Override public CFArchType getTypeByName(final String typeName) { // return: matching type or first type (misc) if no other found final CFArchType type = archTypeNames.get(typeName.trim()); return type == null ? archTypeList.get(0) : type; } - @Nullable public CFArchType getType(@NotNull final GameObject gameObject) { + @Nullable @Override public CFArchType getType(@NotNull final GameObject gameObject) { for (final CFArchType type : archTypeList) { if (type.matches(gameObject)) { return type; Added: trunk/src/app/net/sf/gridarta/CFArchTypeList.java =================================================================== --- trunk/src/app/net/sf/gridarta/CFArchTypeList.java (rev 0) +++ trunk/src/app/net/sf/gridarta/CFArchTypeList.java 2007-01-01 18:13:22 UTC (rev 1353) @@ -0,0 +1,285 @@ +package net.sf.gridarta; + +import java.awt.Component; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; +import net.sf.gridarta.gameobject.GameObject; +import net.sf.japi.swing.JSAXErrorHandler; +import net.sf.japi.xml.NodeListIterator; +import org.apache.log4j.Logger; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.xml.sax.SAXException; + +/** + * Common base class for CFArchTypeList. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public abstract class CFArchTypeList<T extends CFArchType, G extends GameObject> implements Iterable<T> { + + private static final Logger log = Logger.getLogger(CFArchTypeList.class); + + /** DocumentBuilder. */ + protected DocumentBuilder documentBuilder; + + /** The XPath for using XPath. */ + protected XPath xpath; + + /** The default type. */ + protected final T defaultArchType; + + /** + * Lists with all CFArchTypes. + * Contains all but the default CFArchType. + * @todo verify whether the default CFArchType really is not included in this list. + */ + protected final List<T> archTypeList = new ArrayList<T>(); // All but the default ArchType + + /** + * Table with List objects for lists (value) accessible by name (key). + * The value type of the list is <code><?></code> because the lists elements are altering Integers and Strings. + * @todo Refactor the List to contain Pairs or something like that so it doesn't contain two types. + */ + protected final Map<String, List<?>> listTable; + + /** + * Table with List objects for ignore_lists (value) accessible by name (key). + */ + protected Map<String, List<String>> ignoreListTable; + + protected CFArchTypeList() { + //noinspection AbstractMethodCallInConstructor + defaultArchType = createDefaultArchType(); + listTable = new HashMap<String, List<?>>(); + ignoreListTable = new HashMap<String, List<String>>(); + } + + /** + * Creates the default arch type. + * Subclasses implement this method for creating the default arch type. + * @warning This method is called early during object construction, do not use any members, neither your own nor inherited ones. + * @return Newly created default arch type. + */ + protected abstract T createDefaultArchType(); + + /** + * Initialize the XML engine. + * @throws ParserConfigurationException in case the xml parser couldn't be set up + */ + protected final void initXML() throws ParserConfigurationException { + // TODO: Change hard coded document builder factory to user configurable settings + final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setCoalescing(true); + // dbf.setExpandEntityReferences(true); // true is default on this + dbf.setIgnoringComments(true); + dbf.setIgnoringElementContentWhitespace(true); + dbf.setNamespaceAware(true); + dbf.setValidating(true); + dbf.setXIncludeAware(true); + documentBuilder = dbf.newDocumentBuilder(); + documentBuilder.setErrorHandler(new JSAXErrorHandler(getViewToBlock())); + xpath = XPathFactory.newInstance().newXPath(); + } + + /** + * Returns the view to block. + * @return The view to block. + */ + protected abstract Component getViewToBlock(); + + /** + * Returns the configuration directory. + * @return The configuration directory. + */ + protected abstract String getConfigurationDirectory(); + + protected void loadTypesFromXML() { + try { + final String baseDir = getConfigurationDirectory(); + + // parse xml document + final Document doc = documentBuilder.parse(new File(baseDir, CommonConstants.TYPEDEF_FILE)); + + // start parsing the xml + final Element root = doc.getDocumentElement(); + parseBitmasks(root); + parseLists(root); + parseIgnoreLists(root); + parseDefaultType(root); + parseTypes(root); + + if (log.isInfoEnabled()) { + log.info("Loaded " + archTypeList.size() + " types from '" + CommonConstants.TYPEDEF_FILE + "\'"); + } + } catch (final SAXException e) { + log.error("Parsing error in '" + CommonConstants.TYPEDEF_FILE + "':\n" + e.getMessage()); + } catch (final IOException e) { + log.error("Cannot read file '" + CommonConstants.TYPEDEF_FILE + "'!"); + } catch (final XPathExpressionException e) { + log.error("XPath error: " + e.getMessage()); + } + } + + protected abstract void parseBitmasks(final Element root) throws XPathExpressionException; + + protected final void parseLists(final Element root) throws XPathExpressionException { + for (final Element elem : new NodeListIterator<Element>(xpath, root, "list|lists/list")) { + if (elem.getAttribute("name") == null) { + throw new RuntimeException("In file '" + CommonConstants.TYPEDEF_FILE + "': cannot load list element without 'name'."); + } else { + final List<?> list = parseListFromElement(elem); + if (list != null && !list.isEmpty()) { + listTable.put(elem.getAttribute("name"), list); + } + } + } + } + + /** + * Parse a list vector from an xml list element. + * @param root element to parse + * @return List with data parsed from <var>root</var> + * @todo improve this comment + * @throws XPathExpressionException In case of XPath issues (should never happen). + */ + protected final List<?> parseListFromElement(final Element root) throws XPathExpressionException { + // XXX The list created here contains altering types: Integer for even, String for odd indices. + final List<Object> list = new ArrayList<Object>(); + for (final Element elem : new NodeListIterator<Element>(xpath, root, "entry|listentry")) { + // every list entry adds value (Integer) and name (String) to the vector + try { + list.add(Integer.valueOf(elem.getAttribute("value"))); + list.add(" " + elem.getAttribute("name").trim()); + } catch (final NumberFormatException ignore) { + throw new RuntimeException("In '" + CommonConstants.TYPEDEF_FILE + "', list " + root.getAttribute("name") + ": value '" + elem.getAttribute("value") + "' is not an integer."); + } + } + return list; + } + + protected abstract void parseIgnoreLists(final Element root) throws XPathExpressionException; + + protected abstract void parseDefaultType(final Element root) throws XPathExpressionException; + + protected abstract void parseTypes(final Element root) throws XPathExpressionException; + + /** + * Return the ignore list table which contains all definitions of ignore lists for arch attributes. + * @return ignore list table + */ + public Map<String, List<String>> getIgnoreListTable() { + return ignoreListTable; + } + + /** + * Returns the list table which contains all definitions of list types for arch attributes. + * @return list table + */ + public Map<String, List<?>> getListTable() { + return listTable; + } + + /** {@inheritDoc} */ + public Iterator<T> iterator() { + return archTypeList.iterator(); + } + + public T getArchType(final int n) { + return archTypeList.get(n); + } + + public int getArchTypeIndex(@NotNull final T archType) { + return archTypeList.indexOf(archType); + } + + /** + * Returns the number of CFArchTypes in the list. + * The default type is not counted. + * @return Number of CFArchTypes in the list. + */ + public int getLength() { + return archTypeList.size(); + } + + /** + * Find and return the type-structure (<code>CFArchType</code>) that + * matches for the given arch. This is not only a comparison between + * type numbers - special type-attributes must also be dealt with. + * <p/> + * IMPORTANT: A similar-but-nonequal version of this code is used in + * GameObjectAttributesDialog. Hence, if modifying this method, the appropriate parts + * in GameObjectAttributesDialog must also be updated and vice-versa. + * @param arch the arch to find the type for + * @return the <code>CFArchType</code> which belongs to this arch, + * or the first (misc) type if no match is found. + */ + public T getTypeOfArch(final GameObject arch) { + // check if the type of the object is present in the definitions + for (final T tmp : archTypeList) { + if (tmp.getTypeNr() == arch.getArchTypNr()) { + if (tmp.getTypeAttr() == null) { + // no type-attributes, so we only compared type-numbers + return tmp; + } else { + // check if all the type-attributes match + + if (log.isDebugEnabled()) { + log.debug("# type: " + tmp.getTypeName()); + } + + final int numArgs = (int) (tmp.getTypeAttr().length / 2.0); + boolean match = true; + for (int t = 0, l = numArgs * 2; t < l && match; t += 2) { + final String archvalue = arch.getAttributeString(tmp.getTypeAttr()[t]); + if (!archvalue.equals(tmp.getTypeAttr()[t + 1]) && !(tmp.getTypeAttr()[t + 1].equals("0") && archvalue.length() == 0)) { + match = false; + } + } + + // we've got a match after all + if (match) { + return tmp; + } + } + } + } + // type of archobject not found - return first one (misc) + return archTypeList.get(0); + } + + /** + * Returns whether this typelist contains no data. + * @return <code>true</code> if this typelist contains no data, otherwise <code>false</code>. + */ + public boolean isEmpty() { + return archTypeList.isEmpty(); + } + + /** + * Find and return the type-structure (<code>CFArchType</code>) that + * matches the given 'typeName'. These type-names are "artificial" + * names, defined in "types.txt". They appear in the type selection box + * in the attribute-dialog. + * @param typeName Name of the type to get. + * @return the <code>CFArchType</code> that matches, + * or the first (misc) type if no match is found. + */ + public abstract CFArchType getTypeByName(final String typeName); + + // TODO: Javadoc + @Nullable public abstract CFArchType getType(@NotNull final G gameObject); + +} // class CFArchTypeList Property changes on: trunk/src/app/net/sf/gridarta/CFArchTypeList.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...> - 2007-01-01 18:15:16
|
Revision: 1354 http://svn.sourceforge.net/gridarta/?rev=1354&view=rev Author: christianhujer Date: 2007-01-01 10:15:16 -0800 (Mon, 01 Jan 2007) Log Message: ----------- Improved merge progress report, added shell script that creates that report. Modified Paths: -------------- trunk/src/doc/dev/mergeDiagram.png trunk/src/doc/dev/mergeStats.xhtml Added Paths: ----------- trunk/mergeProgressHistory.sh Added: trunk/mergeProgressHistory.sh =================================================================== --- trunk/mergeProgressHistory.sh (rev 0) +++ trunk/mergeProgressHistory.sh 2007-01-01 18:15:16 UTC (rev 1354) @@ -0,0 +1,41 @@ +#!/bin/sh +#echo "Revision;Date;Merged Code (excluding textedit);Merged Code (including textedit);Crossfire Code;Daimonin Code;Crossfire diff to Daimonin;Daimonin diff to Crossfire" >>mergeStatistics.csv +rm mergeStatistics.csv +rsync -av gridarta.svn.sourceforge.net::svn/gridarta/ repoBackup/ +rm -rf mergeMetrics +svn co -q file://$(pwd)/repoBackup/trunk/ mergeMetrics +cd mergeMetrics || exit 1 +recent=$(env -i svn info | grep Revision | cut -d ' ' -f 2) +for ((i = 1; i <= recent; i++)) +do + svn up -q -r $i + echo -ne "\r" $i/$recent + ( + find src/app -name "*.java" >common_src + find crossfire/src -name "*.java" >crossfire_src + find daimonin/src -name "*.java" >daimonin_src + diff -r -d -w -N -I '^package' -I '^import' -x '.svn' crossfire/src/cfeditor daimonin/src/daieditor >differences + echo -n $i +#echo -n ' ' +#echo -n $(svn info --xml | xql.pl '/info/entry/commit/date/text()') + echo -n ' ' + echo -n $(<common_src grep -v textedit | xargs cat | wc -l) + echo -n ' ' + echo -n $(<common_src xargs cat | wc -l) + echo -n ' ' + echo -n $(<crossfire_src grep -v textedit | xargs cat | wc -l) + echo -n ' ' + echo -n $(<crossfire_src xargs cat | wc -l) + echo -n ' ' + echo -n $(<daimonin_src grep -v textedit | xargs cat | wc -l) + echo -n ' ' + echo -n $(<daimonin_src xargs cat | wc -l) + echo -n ' ' + echo -n $(<differences grep '^<' | wc -l) + echo -n ' ' + echo -n $(<differences grep '^>' | wc -l) + echo + ) >>../mergeStatistics.csv 2>/dev/null +done +cd .. +gnuplot <src/mergeMetrics.gpl >src/doc/dev/mergeDiagram.png Property changes on: trunk/mergeProgressHistory.sh ___________________________________________________________________ Name: svn:executable + * Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: trunk/src/doc/dev/mergeDiagram.png =================================================================== (Binary files differ) Modified: trunk/src/doc/dev/mergeStats.xhtml =================================================================== --- trunk/src/doc/dev/mergeStats.xhtml 2007-01-01 18:13:22 UTC (rev 1353) +++ trunk/src/doc/dev/mergeStats.xhtml 2007-01-01 18:15:16 UTC (rev 1354) @@ -20,15 +20,13 @@ X-Axis: commit number. <br /> Y-Axis: raw lines of code, including comments and empty lines. - <br /> - Textedit stuff was excluded in measurements. </p> <p> All measurement was done on Java-files only. Properties files, HTML files (package documentation) or other files were not taken into account. </p> <p> - The measurements of Crossfire vs. Daimonin differences were done excluding and ignoring whitespace, package declarations and imports. + The measurements of Crossfire vs. Daimonin differences were done ignoring whitespace, package declarations and imports. </p> <p> <em>Note:</em> The X-Axis shows commit number. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2007-01-01 20:30:05
|
Revision: 1356 http://svn.sourceforge.net/gridarta/?rev=1356&view=rev Author: christianhujer Date: 2007-01-01 12:30:03 -0800 (Mon, 01 Jan 2007) Log Message: ----------- Updated merge stats script. Modified Paths: -------------- trunk/mergeProgressHistory.sh Added Paths: ----------- trunk/src/mergeMetrics.gpl Modified: trunk/mergeProgressHistory.sh =================================================================== --- trunk/mergeProgressHistory.sh 2007-01-01 20:28:03 UTC (rev 1355) +++ trunk/mergeProgressHistory.sh 2007-01-01 20:30:03 UTC (rev 1356) @@ -1,6 +1,6 @@ #!/bin/sh #echo "Revision;Date;Merged Code (excluding textedit);Merged Code (including textedit);Crossfire Code;Daimonin Code;Crossfire diff to Daimonin;Daimonin diff to Crossfire" >>mergeStatistics.csv -rm mergeStatistics.csv +rm mergeStatistics.dat rsync -av gridarta.svn.sourceforge.net::svn/gridarta/ repoBackup/ rm -rf mergeMetrics svn co -q file://$(pwd)/repoBackup/trunk/ mergeMetrics @@ -35,7 +35,7 @@ echo -n ' ' echo -n $(<differences grep '^>' | wc -l) echo - ) >>../mergeStatistics.csv 2>/dev/null + ) >>../mergeStatistics.dat 2>/dev/null done cd .. gnuplot <src/mergeMetrics.gpl >src/doc/dev/mergeDiagram.png Added: trunk/src/mergeMetrics.gpl =================================================================== --- trunk/src/mergeMetrics.gpl (rev 0) +++ trunk/src/mergeMetrics.gpl 2007-01-01 20:30:03 UTC (rev 1356) @@ -0,0 +1,16 @@ +set terminal png size 768,432 +#set terminal svg size 1200 600 dynamic +set grid +set nologscale x +set nologscale y +set xlabel 'revision' +set ylabel 'sloc' +set title 'Gridarta Merge Statistics' +plot 'mergeStatistics.dat' using 1:2 title "Merged Code (excluding textedit)" with lines, \ + 'mergeStatistics.dat' using 1:3 title "Merged Code (including textedit)" with lines, \ + 'mergeStatistics.dat' using 1:4 title "Crossfire Code (excluding textedit)" with lines, \ + 'mergeStatistics.dat' using 1:5 title "Crossfire Code (including textedit)" with lines, \ + 'mergeStatistics.dat' using 1:6 title "Daimonin Code (excluding textedit)" with lines, \ + 'mergeStatistics.dat' using 1:7 title "Daimonin Code (including textedit)" with lines, \ + 'mergeStatistics.dat' using 1:8 title "Crossfire diff to Daimonin" with lines, \ + 'mergeStatistics.dat' using 1:9 title "Daimonin diff to Crossfire" with lines Property changes on: trunk/src/mergeMetrics.gpl ___________________________________________________________________ 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...> - 2007-01-01 20:36:39
|
Revision: 1357 http://svn.sourceforge.net/gridarta/?rev=1357&view=rev Author: christianhujer Date: 2007-01-01 12:36:39 -0800 (Mon, 01 Jan 2007) Log Message: ----------- More CFArchTypeList unification. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CFArchTypeList.java trunk/daimonin/src/daieditor/CFArchTypeList.java trunk/src/app/net/sf/gridarta/CFArchTypeList.java trunk/src/app/net/sf/gridarta/Spells.java Modified: trunk/crossfire/src/cfeditor/CFArchTypeList.java =================================================================== --- trunk/crossfire/src/cfeditor/CFArchTypeList.java 2007-01-01 20:30:03 UTC (rev 1356) +++ trunk/crossfire/src/cfeditor/CFArchTypeList.java 2007-01-01 20:36:39 UTC (rev 1357) @@ -181,24 +181,13 @@ } } - /** - * Return the bitmask table which contains all definitions of bitmask types for arch attributes. - * @return bitmask table - */ - public Map<String, CAttribBitmask> getBitmaskTable() { + /** {@inheritDoc} */ + @Override public Map<String, CAttribBitmask> getBitmaskTable() { return bitmaskTable; } - public CFArchType getDefaultArchType() { - return defaultArchType; - } - - /** - * Lookup the name of an archtype. - * @param typeNr type number - * @return name of this type, as defined in "typenumbers.xml" - */ - public String getArchTypeName(final int typeNr) { + /** {@inheritDoc} */ + @Override public String getArchTypeName(final int typeNr) { return archTypeNumbers.containsKey(typeNr) ? archTypeNumbers.get(typeNr) : "*UNKNOWN" + typeNr + "*"; } Modified: trunk/daimonin/src/daieditor/CFArchTypeList.java =================================================================== --- trunk/daimonin/src/daieditor/CFArchTypeList.java 2007-01-01 20:30:03 UTC (rev 1356) +++ trunk/daimonin/src/daieditor/CFArchTypeList.java 2007-01-01 20:36:39 UTC (rev 1357) @@ -214,24 +214,13 @@ } } - /** - * Return the bitmask table which contains all definitions of bitmask types for arch attributes. - * @return bitmask table - */ - public Map<String, CAttribBitmask> getBitmaskTable() { + /** {@inheritDoc} */ + @Override public Map<String, CAttribBitmask> getBitmaskTable() { return bitmaskTable; } - public CFArchType getDefaultArchType() { - return defaultArchType; - } - - /** - * Lookup the name of an archtype. - * @param typeNr type number - * @return name of this type, as defined in "typenumbers.xml" - */ - public String getArchTypeName(final int typeNr) { + /** {@inheritDoc} */ + @Override public String getArchTypeName(final int typeNr) { return archTypeNumbers.containsKey(typeNr) ? archTypeNumbers.get(typeNr) : "*UNKNOWN" + typeNr + "*"; } Modified: trunk/src/app/net/sf/gridarta/CFArchTypeList.java =================================================================== --- trunk/src/app/net/sf/gridarta/CFArchTypeList.java 2007-01-01 20:30:03 UTC (rev 1356) +++ trunk/src/app/net/sf/gridarta/CFArchTypeList.java 2007-01-01 20:36:39 UTC (rev 1357) @@ -261,6 +261,27 @@ } /** + * Return the bitmask table which contains all definitions of bitmask types for arch attributes. + * @return bitmask table + */ + public abstract Map<String, ?> getBitmaskTable(); + + /** + * Returns the default arch type. + * @return The default arch type. + */ + public T getDefaultArchType() { + return defaultArchType; + } + + /** + * Lookup the name of an archtype. + * @param typeNr type number + * @return name of this type, as defined in "typenumbers.xml" + */ + public abstract String getArchTypeName(final int typeNr); + + /** * Returns whether this typelist contains no data. * @return <code>true</code> if this typelist contains no data, otherwise <code>false</code>. */ Modified: trunk/src/app/net/sf/gridarta/Spells.java =================================================================== --- trunk/src/app/net/sf/gridarta/Spells.java 2007-01-01 20:30:03 UTC (rev 1356) +++ trunk/src/app/net/sf/gridarta/Spells.java 2007-01-01 20:36:39 UTC (rev 1357) @@ -149,4 +149,5 @@ public int[] getSpellNumbers() { return spellNumbers; } + } // class Spells This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2007-01-01 20:44:29
|
Revision: 1358 http://svn.sourceforge.net/gridarta/?rev=1358&view=rev Author: christianhujer Date: 2007-01-01 12:44:30 -0800 (Mon, 01 Jan 2007) Log Message: ----------- Made CFArchAttrib independent of CFArchTypeList implementation. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CFArchAttrib.java trunk/daimonin/src/daieditor/CFArchAttrib.java Modified: trunk/crossfire/src/cfeditor/CFArchAttrib.java =================================================================== --- trunk/crossfire/src/cfeditor/CFArchAttrib.java 2007-01-01 20:36:39 UTC (rev 1357) +++ trunk/crossfire/src/cfeditor/CFArchAttrib.java 2007-01-01 20:44:30 UTC (rev 1358) @@ -24,6 +24,7 @@ package cfeditor; +import java.util.Set; import net.sf.gridarta.CommonConstants; import net.sf.gridarta.gameobject.ArchAttribType; import org.apache.log4j.Logger; @@ -93,7 +94,7 @@ * @param typeName (descriptive) name of the type this attribute belongs to (e.g. "Weapon") * @return true if the parsing was successful */ - public boolean load(final Element root, final CFArchTypeList tlist, final String typeName) { + public boolean load(final Element root, final net.sf.gridarta.CFArchTypeList tlist, final String typeName) { // parse the info text from the element's "body" parseText(root); @@ -219,7 +220,7 @@ } else { log.warn("In '" + CommonConstants.TYPEDEF_FILE + "', type " + typeName + ": List \"" + listName + "\" is undefined."); log.error("Size of tlist: " + tlist.getListTable().size()); - for (final String key : tlist.getListTable().keySet()) { + for (final String key : (Set<String>) tlist.getListTable().keySet()) { log.error(key); } } Modified: trunk/daimonin/src/daieditor/CFArchAttrib.java =================================================================== --- trunk/daimonin/src/daieditor/CFArchAttrib.java 2007-01-01 20:36:39 UTC (rev 1357) +++ trunk/daimonin/src/daieditor/CFArchAttrib.java 2007-01-01 20:44:30 UTC (rev 1358) @@ -24,6 +24,7 @@ package daieditor; +import java.util.Set; import net.sf.gridarta.CommonConstants; import net.sf.gridarta.gameobject.ArchAttribType; import org.apache.log4j.Logger; @@ -93,7 +94,7 @@ * @param typeName (descriptive) name of the type this attribute belongs to (e.g. "Weapon") * @return true if the parsing was successful */ - public boolean load(final Element root, final CFArchTypeList tlist, final String typeName) { + public boolean load(final Element root, final net.sf.gridarta.CFArchTypeList tlist, final String typeName) { // parse the info text from the element's "body" parseText(root); @@ -219,7 +220,7 @@ } else { log.warn("In '" + CommonConstants.TYPEDEF_FILE + "', type " + typeName + ": List \"" + listName + "\" is undefined."); log.error("Size of tlist: " + tlist.getListTable().size()); - for (final String key : tlist.getListTable().keySet()) { + for (final String key : (Set<String>) tlist.getListTable().keySet()) { log.error(key); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2007-01-01 21:59:22
|
Revision: 1361 http://svn.sourceforge.net/gridarta/?rev=1361&view=rev Author: christianhujer Date: 2007-01-01 13:59:23 -0800 (Mon, 01 Jan 2007) Log Message: ----------- Added spells getter as instance method. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CFArchAttrib.java trunk/crossfire/src/cfeditor/CFArchTypeList.java trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java trunk/daimonin/src/daieditor/CFArchAttrib.java trunk/daimonin/src/daieditor/CFArchTypeList.java trunk/daimonin/src/daieditor/gui/GameObjectAttributesDialog.java trunk/src/app/net/sf/gridarta/CFArchTypeList.java Modified: trunk/crossfire/src/cfeditor/CFArchAttrib.java =================================================================== --- trunk/crossfire/src/cfeditor/CFArchAttrib.java 2007-01-01 21:48:22 UTC (rev 1360) +++ trunk/crossfire/src/cfeditor/CFArchAttrib.java 2007-01-01 21:59:23 UTC (rev 1361) @@ -185,14 +185,14 @@ } } else if ("spell".equalsIgnoreCase(atype)) { // spell attribute - if (CFArchTypeList.getSpells().getSpellNumbers() == null) { + if (CFArchTypeList.getSpellsStatic().getSpellNumbers() == null) { dataType = ArchAttribType.INT; // if we have no spells, use an INT field instead } else { dataType = ArchAttribType.SPELL; } } else if ("nz_spell".equalsIgnoreCase(atype)) { // spell attribute - if (CFArchTypeList.getSpells().getSpellNumbers() == null) { + if (CFArchTypeList.getSpellsStatic().getSpellNumbers() == null) { dataType = ArchAttribType.INT; // if we have no spells, use an INT field instead } else { dataType = ArchAttribType.ZSPELL; Modified: trunk/crossfire/src/cfeditor/CFArchTypeList.java =================================================================== --- trunk/crossfire/src/cfeditor/CFArchTypeList.java 2007-01-01 21:48:22 UTC (rev 1360) +++ trunk/crossfire/src/cfeditor/CFArchTypeList.java 2007-01-01 21:59:23 UTC (rev 1361) @@ -87,11 +87,21 @@ return arch != null && EXIT_TYPES.contains(arch.getHead().getArchTypNr()); } - public static Spells getSpells() { + /** {@inheritDoc} */ + @Override public Spells getSpells() { return spells; } /** + * Returns the spells. + * @return The spells. + * @deprecated don't use the static method, use the instance method instead. + */ + @Deprecated public static Spells getSpellsStatic() { + return spells; + } + + /** * Constructor - Parsing all the data from the xml definitions file * 'types.xml'. */ Modified: trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java 2007-01-01 21:48:22 UTC (rev 1360) +++ trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java 2007-01-01 21:59:23 UTC (rev 1361) @@ -289,7 +289,7 @@ // first parse the spell-number value from gameObject int spnum = gameObject.getAttributeInt(attr.getNameOld()); // spell number - if (spnum < 0 || spnum >= CFArchTypeList.getSpells().getSpellNumbers().length - 1) { + if (spnum < 0 || spnum >= CFArchTypeList.getSpellsStatic().getSpellNumbers().length - 1) { spnum = 0; // undefined spellnumbers be zero } @@ -300,15 +300,15 @@ } else { // now look up the spell-number in the array of spells active = 0; - for (int i = 0; i < CFArchTypeList.getSpells().getSpellNumbers().length; i++) { - if (CFArchTypeList.getSpells().getSpellNumbers()[i] == spnum) { + for (int i = 0; i < CFArchTypeList.getSpellsStatic().getSpellNumbers().length; i++) { + if (CFArchTypeList.getSpellsStatic().getSpellNumbers()[i] == spnum) { active = i; // set selection - i = CFArchTypeList.getSpells().getSpellNumbers().length + 10; // end loop + i = CFArchTypeList.getSpellsStatic().getSpellNumbers().length + 10; // end loop } } } - final JComboBox spellsel = new JComboBox(CFArchTypeList.getSpells().getSpellNames()); // set "content" + final JComboBox spellsel = new JComboBox(CFArchTypeList.getSpellsStatic().getSpellNames()); // set "content" spellsel.setSelectedIndex(active); // set active selection spellsel.setMaximumRowCount(10); spellsel.setKeySelectionManager(new StringKeyManager(spellsel)); @@ -1166,7 +1166,7 @@ switch (dType) { case SPELL: case ZSPELL: - attrVal = CFArchTypeList.getSpells().getSpellNumbers()[((DialogAttrib<JComboBox>) attr).input.getSelectedIndex()]; + attrVal = CFArchTypeList.getSpellsStatic().getSpellNumbers()[((DialogAttrib<JComboBox>) attr).input.getSelectedIndex()]; break; case LIST: // get selected index of ComboBox Modified: trunk/daimonin/src/daieditor/CFArchAttrib.java =================================================================== --- trunk/daimonin/src/daieditor/CFArchAttrib.java 2007-01-01 21:48:22 UTC (rev 1360) +++ trunk/daimonin/src/daieditor/CFArchAttrib.java 2007-01-01 21:59:23 UTC (rev 1361) @@ -185,14 +185,14 @@ } } else if ("spell".equalsIgnoreCase(atype)) { // spell attribute - if (CFArchTypeList.getSpells().getSpellNumbers() == null) { + if (CFArchTypeList.getSpellsStatic().getSpellNumbers() == null) { dataType = ArchAttribType.INT; // if we have no spells, use an INT field instead } else { dataType = ArchAttribType.SPELL; } } else if ("nz_spell".equalsIgnoreCase(atype)) { // spell attribute - if (CFArchTypeList.getSpells().getSpellNumbers() == null) { + if (CFArchTypeList.getSpellsStatic().getSpellNumbers() == null) { dataType = ArchAttribType.INT; // if we have no spells, use an INT field instead } else { dataType = ArchAttribType.ZSPELL; Modified: trunk/daimonin/src/daieditor/CFArchTypeList.java =================================================================== --- trunk/daimonin/src/daieditor/CFArchTypeList.java 2007-01-01 21:48:22 UTC (rev 1360) +++ trunk/daimonin/src/daieditor/CFArchTypeList.java 2007-01-01 21:59:23 UTC (rev 1361) @@ -90,11 +90,21 @@ return arch != null && archObjectMatchersByIds.get("exits").isMatching(arch); } - public static Spells getSpells() { + /** {@inheritDoc} */ + @Override public Spells getSpells() { return spells; } /** + * Returns the spells. + * @return The spells. + * @deprecated don't use the static method, use the instance method instead. + */ + @Deprecated public static Spells getSpellsStatic() { + return spells; + } + + /** * Constructor - Parsing all the data from the xml definitions file * 'types.xml'. * @todo I consume too much time. Why? XPath is too slow. Let's hope Beta4 Modified: trunk/daimonin/src/daieditor/gui/GameObjectAttributesDialog.java =================================================================== --- trunk/daimonin/src/daieditor/gui/GameObjectAttributesDialog.java 2007-01-01 21:48:22 UTC (rev 1360) +++ trunk/daimonin/src/daieditor/gui/GameObjectAttributesDialog.java 2007-01-01 21:59:23 UTC (rev 1361) @@ -289,7 +289,7 @@ // first parse the spell-number value from gameObject int spnum = gameObject.getAttributeInt(attr.getNameOld()); // spell number - if (spnum < -1 || spnum >= CFArchTypeList.getSpells().getSpellNumbers().length - 1) { + if (spnum < -1 || spnum >= CFArchTypeList.getSpellsStatic().getSpellNumbers().length - 1) { spnum = 0; // undefined spellnumbers be -1 } @@ -299,11 +299,11 @@ active = 0; } else { // now look up the spell-number in the array of spells - final int[] spellNumbers = CFArchTypeList.getSpells().getSpellNumbers(); + final int[] spellNumbers = CFArchTypeList.getSpellsStatic().getSpellNumbers(); active = linearSearch(spnum, spellNumbers); } - final JComboBox spellsel = new JComboBox(CFArchTypeList.getSpells().getSpellNames()); // set "content" + final JComboBox spellsel = new JComboBox(CFArchTypeList.getSpellsStatic().getSpellNames()); // set "content" spellsel.setSelectedIndex(active); // set active selection spellsel.setMaximumRowCount(10); spellsel.setKeySelectionManager(new StringKeyManager(spellsel)); @@ -1155,7 +1155,7 @@ switch (dType) { case SPELL: case ZSPELL: - attrVal = CFArchTypeList.getSpells().getSpellNumbers()[((DialogAttrib<JComboBox>) attr).input.getSelectedIndex()]; + attrVal = CFArchTypeList.getSpellsStatic().getSpellNumbers()[((DialogAttrib<JComboBox>) attr).input.getSelectedIndex()]; break; case LIST: // get selected index of ComboBox Modified: trunk/src/app/net/sf/gridarta/CFArchTypeList.java =================================================================== --- trunk/src/app/net/sf/gridarta/CFArchTypeList.java 2007-01-01 21:48:22 UTC (rev 1360) +++ trunk/src/app/net/sf/gridarta/CFArchTypeList.java 2007-01-01 21:59:23 UTC (rev 1361) @@ -76,6 +76,12 @@ protected abstract T createDefaultArchType(); /** + * Returns the spells. + * @return The spells. + */ + public abstract Spells getSpells(); + + /** * Initialize the XML engine. * @throws ParserConfigurationException in case the xml parser couldn't be set up */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2007-01-01 22:05:49
|
Revision: 1362 http://svn.sourceforge.net/gridarta/?rev=1362&view=rev Author: christianhujer Date: 2007-01-01 14:05:49 -0800 (Mon, 01 Jan 2007) Log Message: ----------- Removed obsolete static spells getter. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CFArchAttrib.java trunk/crossfire/src/cfeditor/CFArchTypeList.java trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java trunk/daimonin/src/daieditor/CFArchAttrib.java trunk/daimonin/src/daieditor/CFArchTypeList.java trunk/daimonin/src/daieditor/gui/GameObjectAttributesDialog.java Modified: trunk/crossfire/src/cfeditor/CFArchAttrib.java =================================================================== --- trunk/crossfire/src/cfeditor/CFArchAttrib.java 2007-01-01 21:59:23 UTC (rev 1361) +++ trunk/crossfire/src/cfeditor/CFArchAttrib.java 2007-01-01 22:05:49 UTC (rev 1362) @@ -185,14 +185,14 @@ } } else if ("spell".equalsIgnoreCase(atype)) { // spell attribute - if (CFArchTypeList.getSpellsStatic().getSpellNumbers() == null) { + if (tlist.getSpells().getSpellNumbers() == null) { dataType = ArchAttribType.INT; // if we have no spells, use an INT field instead } else { dataType = ArchAttribType.SPELL; } } else if ("nz_spell".equalsIgnoreCase(atype)) { // spell attribute - if (CFArchTypeList.getSpellsStatic().getSpellNumbers() == null) { + if (tlist.getSpells().getSpellNumbers() == null) { dataType = ArchAttribType.INT; // if we have no spells, use an INT field instead } else { dataType = ArchAttribType.ZSPELL; Modified: trunk/crossfire/src/cfeditor/CFArchTypeList.java =================================================================== --- trunk/crossfire/src/cfeditor/CFArchTypeList.java 2007-01-01 21:59:23 UTC (rev 1361) +++ trunk/crossfire/src/cfeditor/CFArchTypeList.java 2007-01-01 22:05:49 UTC (rev 1362) @@ -93,15 +93,6 @@ } /** - * Returns the spells. - * @return The spells. - * @deprecated don't use the static method, use the instance method instead. - */ - @Deprecated public static Spells getSpellsStatic() { - return spells; - } - - /** * Constructor - Parsing all the data from the xml definitions file * 'types.xml'. */ Modified: trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java 2007-01-01 21:59:23 UTC (rev 1361) +++ trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java 2007-01-01 22:05:49 UTC (rev 1362) @@ -289,7 +289,7 @@ // first parse the spell-number value from gameObject int spnum = gameObject.getAttributeInt(attr.getNameOld()); // spell number - if (spnum < 0 || spnum >= CFArchTypeList.getSpellsStatic().getSpellNumbers().length - 1) { + if (spnum < 0 || spnum >= archTypeList.getSpells().getSpellNumbers().length - 1) { spnum = 0; // undefined spellnumbers be zero } @@ -300,15 +300,15 @@ } else { // now look up the spell-number in the array of spells active = 0; - for (int i = 0; i < CFArchTypeList.getSpellsStatic().getSpellNumbers().length; i++) { - if (CFArchTypeList.getSpellsStatic().getSpellNumbers()[i] == spnum) { + for (int i = 0; i < archTypeList.getSpells().getSpellNumbers().length; i++) { + if (archTypeList.getSpells().getSpellNumbers()[i] == spnum) { active = i; // set selection - i = CFArchTypeList.getSpellsStatic().getSpellNumbers().length + 10; // end loop + i = archTypeList.getSpells().getSpellNumbers().length + 10; // end loop } } } - final JComboBox spellsel = new JComboBox(CFArchTypeList.getSpellsStatic().getSpellNames()); // set "content" + final JComboBox spellsel = new JComboBox(archTypeList.getSpells().getSpellNames()); // set "content" spellsel.setSelectedIndex(active); // set active selection spellsel.setMaximumRowCount(10); spellsel.setKeySelectionManager(new StringKeyManager(spellsel)); @@ -1166,7 +1166,7 @@ switch (dType) { case SPELL: case ZSPELL: - attrVal = CFArchTypeList.getSpellsStatic().getSpellNumbers()[((DialogAttrib<JComboBox>) attr).input.getSelectedIndex()]; + attrVal = archTypeList.getSpells().getSpellNumbers()[((DialogAttrib<JComboBox>) attr).input.getSelectedIndex()]; break; case LIST: // get selected index of ComboBox Modified: trunk/daimonin/src/daieditor/CFArchAttrib.java =================================================================== --- trunk/daimonin/src/daieditor/CFArchAttrib.java 2007-01-01 21:59:23 UTC (rev 1361) +++ trunk/daimonin/src/daieditor/CFArchAttrib.java 2007-01-01 22:05:49 UTC (rev 1362) @@ -185,14 +185,14 @@ } } else if ("spell".equalsIgnoreCase(atype)) { // spell attribute - if (CFArchTypeList.getSpellsStatic().getSpellNumbers() == null) { + if (tlist.getSpells().getSpellNumbers() == null) { dataType = ArchAttribType.INT; // if we have no spells, use an INT field instead } else { dataType = ArchAttribType.SPELL; } } else if ("nz_spell".equalsIgnoreCase(atype)) { // spell attribute - if (CFArchTypeList.getSpellsStatic().getSpellNumbers() == null) { + if (tlist.getSpells().getSpellNumbers() == null) { dataType = ArchAttribType.INT; // if we have no spells, use an INT field instead } else { dataType = ArchAttribType.ZSPELL; Modified: trunk/daimonin/src/daieditor/CFArchTypeList.java =================================================================== --- trunk/daimonin/src/daieditor/CFArchTypeList.java 2007-01-01 21:59:23 UTC (rev 1361) +++ trunk/daimonin/src/daieditor/CFArchTypeList.java 2007-01-01 22:05:49 UTC (rev 1362) @@ -96,15 +96,6 @@ } /** - * Returns the spells. - * @return The spells. - * @deprecated don't use the static method, use the instance method instead. - */ - @Deprecated public static Spells getSpellsStatic() { - return spells; - } - - /** * Constructor - Parsing all the data from the xml definitions file * 'types.xml'. * @todo I consume too much time. Why? XPath is too slow. Let's hope Beta4 Modified: trunk/daimonin/src/daieditor/gui/GameObjectAttributesDialog.java =================================================================== --- trunk/daimonin/src/daieditor/gui/GameObjectAttributesDialog.java 2007-01-01 21:59:23 UTC (rev 1361) +++ trunk/daimonin/src/daieditor/gui/GameObjectAttributesDialog.java 2007-01-01 22:05:49 UTC (rev 1362) @@ -289,7 +289,7 @@ // first parse the spell-number value from gameObject int spnum = gameObject.getAttributeInt(attr.getNameOld()); // spell number - if (spnum < -1 || spnum >= CFArchTypeList.getSpellsStatic().getSpellNumbers().length - 1) { + if (spnum < -1 || spnum >= archTypeList.getSpells().getSpellNumbers().length - 1) { spnum = 0; // undefined spellnumbers be -1 } @@ -299,11 +299,11 @@ active = 0; } else { // now look up the spell-number in the array of spells - final int[] spellNumbers = CFArchTypeList.getSpellsStatic().getSpellNumbers(); + final int[] spellNumbers = archTypeList.getSpells().getSpellNumbers(); active = linearSearch(spnum, spellNumbers); } - final JComboBox spellsel = new JComboBox(CFArchTypeList.getSpellsStatic().getSpellNames()); // set "content" + final JComboBox spellsel = new JComboBox(archTypeList.getSpells().getSpellNames()); // set "content" spellsel.setSelectedIndex(active); // set active selection spellsel.setMaximumRowCount(10); spellsel.setKeySelectionManager(new StringKeyManager(spellsel)); @@ -1155,7 +1155,7 @@ switch (dType) { case SPELL: case ZSPELL: - attrVal = CFArchTypeList.getSpellsStatic().getSpellNumbers()[((DialogAttrib<JComboBox>) attr).input.getSelectedIndex()]; + attrVal = archTypeList.getSpells().getSpellNumbers()[((DialogAttrib<JComboBox>) attr).input.getSelectedIndex()]; break; case LIST: // get selected index of ComboBox This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2007-01-01 22:10:00
|
Revision: 1363 http://svn.sourceforge.net/gridarta/?rev=1363&view=rev Author: christianhujer Date: 2007-01-01 14:10:01 -0800 (Mon, 01 Jan 2007) Log Message: ----------- Turned spells field into an instance field. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CFArchTypeList.java trunk/daimonin/src/daieditor/CFArchTypeList.java Modified: trunk/crossfire/src/cfeditor/CFArchTypeList.java =================================================================== --- trunk/crossfire/src/cfeditor/CFArchTypeList.java 2007-01-01 22:05:49 UTC (rev 1362) +++ trunk/crossfire/src/cfeditor/CFArchTypeList.java 2007-01-01 22:10:01 UTC (rev 1363) @@ -52,7 +52,7 @@ private static final Logger log = Logger.getLogger(CFArchTypeList.class); - private static final Spells spells = new Spells(); + private final Spells spells = new Spells(); /** * Table with type numbers as keys (Integer), and type names as values (String). Modified: trunk/daimonin/src/daieditor/CFArchTypeList.java =================================================================== --- trunk/daimonin/src/daieditor/CFArchTypeList.java 2007-01-01 22:05:49 UTC (rev 1362) +++ trunk/daimonin/src/daieditor/CFArchTypeList.java 2007-01-01 22:10:01 UTC (rev 1363) @@ -63,7 +63,7 @@ */ private static final Map<String, NamedGameObjectMatcher> archObjectMatchersByIds = new HashMap<String, NamedGameObjectMatcher>(); - private static final Spells spells = new Spells(); + private final Spells spells = new Spells(); /** * Table with type numbers as keys (Integer), and type names as values (String). This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2007-01-01 22:14:36
|
Revision: 1364 http://svn.sourceforge.net/gridarta/?rev=1364&view=rev Author: christianhujer Date: 2007-01-01 14:14:35 -0800 (Mon, 01 Jan 2007) Log Message: ----------- Merged CFArchAttrib into gridarta. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CFArchType.java trunk/crossfire/src/cfeditor/CFArchTypeList.java trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java trunk/daimonin/src/daieditor/CFArchType.java trunk/daimonin/src/daieditor/CFArchTypeList.java trunk/daimonin/src/daieditor/gui/GameObjectAttributesDialog.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/CFArchAttrib.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/CFArchAttrib.java trunk/daimonin/src/daieditor/CFArchAttrib.java Deleted: trunk/crossfire/src/cfeditor/CFArchAttrib.java =================================================================== --- trunk/crossfire/src/cfeditor/CFArchAttrib.java 2007-01-01 22:10:01 UTC (rev 1363) +++ trunk/crossfire/src/cfeditor/CFArchAttrib.java 2007-01-01 22:14:35 UTC (rev 1364) @@ -1,347 +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 java.util.Set; -import net.sf.gridarta.CommonConstants; -import net.sf.gridarta.gameobject.ArchAttribType; -import org.apache.log4j.Logger; -import org.w3c.dom.Attr; -import org.w3c.dom.Element; - -/** - * This Class contains the data of one arch attribute. - * @author <a href="mailto:and...@gm...">Andreas Vogl</a> - */ -public final class CFArchAttrib implements Cloneable { - - private static final Logger log = Logger.getLogger(CFArchAttrib.class); - - // XML tag names - public static final String XML_KEY_ARCH = "arch"; - - public static final String XML_KEY_ARCH_BEGIN = "arch_begin"; - - public static final String XML_KEY_ARCH_END = "arch_end"; - - public static final String XML_KEY_EDITOR = "editor"; - - public static final String XML_ATTR_TYPE = "type"; - - public static final String XML_INPUT_LENGTH = "length"; - - private CFArchAttrib next; // next element in the list (/array) - - private String nameOld; // original attr. name (from the CF arches) - - private String endingOld; // for dataType = ArchAttribType.TEXT this is the terminating string - - // (example: 'endmsg' for arch message) - private String nameNew; // new attr. name (for the user-friendly GUI) - - private ArchAttribType dataType; // type of attribute data - - private String text; // descrption of this attr. - - private int inputLength; // optional attribute: set length for input JTextFields - - private String[] misc; // string array for misc. use - // ArchAttribType.BOOL_SPEC uses misc[0] = true value, misc[1] = false value - // ArchAttribType.BITMASK uses misc[0] = bitmask name - // ArchAttribType.LIST uses misc[0] = list name - - private int secId; // identifier of the section this attribute is in - - private String section; // name of the section this attribute is in - - /** - * Create a CFArchAttrib. - */ - public CFArchAttrib() { - nameOld = ""; - nameNew = ""; - endingOld = null; - misc = null; - inputLength = 0; // use default length - } - - /** - * Loading the data from an xml element into this object. - * @param root the xml 'attribute' element - * @param tlist the archtype list - * @param typeName (descriptive) name of the type this attribute belongs to (e.g. "Weapon") - * @return true if the parsing was successful - */ - public boolean load(final Element root, final net.sf.gridarta.CFArchTypeList tlist, final String typeName) { - - // parse the info text from the element's "body" - parseText(root); - - // arch syntax key - Attr a1; - if ((a1 = root.getAttributeNode(XML_KEY_ARCH)) != null) { - nameOld = a1.getValue().trim(); - } - - // editor syntax key - if ((a1 = root.getAttributeNode(XML_KEY_EDITOR)) != null) { - nameNew = a1.getValue().trim(); - } - - // type name - final String atype; - if ((a1 = root.getAttributeNode(XML_ATTR_TYPE)) != null) { - atype = a1.getValue().trim(); - } else { - // error: no type - log.error("In '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + " has attribute missing '" + XML_ATTR_TYPE + "'."); - return false; - } - - // input length (optional) - if ((a1 = root.getAttributeNode(XML_INPUT_LENGTH)) != null) { - try { - inputLength = Integer.parseInt(a1.getValue()); - } catch (final NumberFormatException de) { - log.error("In '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + " has attribute with invalid length '" + a1.getValue() + "' (must be a number)."); - } - } - - // which type of attribute is it? - if (atype.equalsIgnoreCase("bool")) { - dataType = ArchAttribType.BOOL; // normal bool - } else if (atype.equalsIgnoreCase("bool_special")) { - // customized boolean type: - dataType = ArchAttribType.BOOL_SPEC; - - // parse true and false values: - a1 = root.getAttributeNode("true"); - final Attr a2 = root.getAttributeNode("false"); - if (a1 == null || a2 == null) { - log.error("In '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + " has bool_special attribute missing 'true' or 'false' value."); - return false; - } - - misc = new String[2]; // 'misc' string contains the values - misc[0] = a1.getValue().trim(); // string for true - misc[1] = a2.getValue().trim(); // string for false - } else if (atype.equalsIgnoreCase("int")) { - dataType = ArchAttribType.INT; - } else if (atype.equalsIgnoreCase("long")) { - dataType = ArchAttribType.LONG; - } else if (atype.equalsIgnoreCase("float")) { - dataType = ArchAttribType.FLOAT; - } else if (atype.equalsIgnoreCase("string")) { - dataType = ArchAttribType.STRING; - } else if (atype.equalsIgnoreCase("facename")) { - dataType = ArchAttribType.FACENAME; - } else if (atype.equalsIgnoreCase("animname")) { - dataType = ArchAttribType.ANIMNAME; - } else if (atype.equalsIgnoreCase("text")) { - dataType = ArchAttribType.TEXT; - // for text data, the terminating string has to be read too - if ((a1 = root.getAttributeNode(XML_KEY_ARCH_BEGIN)) != null) { - nameOld = a1.getValue().trim(); - } - - if ((a1 = root.getAttributeNode(XML_KEY_ARCH_END)) != null) { - endingOld = a1.getValue().trim(); - } - - if (nameOld == null || nameOld.length() == 0 || endingOld == null || endingOld.length() == 0) { - log.warn("In '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + " has text attribute missing '" + XML_KEY_ARCH_BEGIN + "' or '" + XML_KEY_ARCH_END + "'."); - return false; - } - } else if ("fixed".equalsIgnoreCase(atype)) { - // fixed attribute - dataType = ArchAttribType.FIXED; - if ((a1 = root.getAttributeNode("value")) != null) { - nameNew = a1.getValue().trim(); - } else { - log.warn("In '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + " has fixed attribute missing 'value'."); - return false; - } - } else if ("spell".equalsIgnoreCase(atype)) { - // spell attribute - if (tlist.getSpells().getSpellNumbers() == null) { - dataType = ArchAttribType.INT; // if we have no spells, use an INT field instead - } else { - dataType = ArchAttribType.SPELL; - } - } else if ("nz_spell".equalsIgnoreCase(atype)) { - // spell attribute - if (tlist.getSpells().getSpellNumbers() == null) { - dataType = ArchAttribType.INT; // if we have no spells, use an INT field instead - } else { - dataType = ArchAttribType.ZSPELL; - } - } else if (atype.startsWith("bitmask")) { - // got a bitmask attribute - final String bitmaskName = atype.substring(8).trim(); - - if (tlist.getBitmaskTable().containsKey(bitmaskName)) { - // the bitmask is well defined - dataType = ArchAttribType.BITMASK; - misc = new String[1]; - misc[0] = bitmaskName; // store bitmask name in misc[0] - } else { - log.warn("In '" + CommonConstants.TYPEDEF_FILE + "', type " + typeName + ": Bitmask \"" + bitmaskName + "\" is undefined."); - } - } else if (atype.startsWith("list")) { - // got a bitmask attribute - final String listName = atype.substring(5).trim(); - if (tlist.getListTable().containsKey(listName)) { - // the list is well defined - dataType = ArchAttribType.LIST; - misc = new String[1]; - misc[0] = listName; // store list name in misc[0] - } else { - log.warn("In '" + CommonConstants.TYPEDEF_FILE + "', type " + typeName + ": List \"" + listName + "\" is undefined."); - log.error("Size of tlist: " + tlist.getListTable().size()); - for (final String key : (Set<String>) tlist.getListTable().keySet()) { - log.error(key); - } - } - } else if ("doublelist".startsWith(atype)) { - // got a doublelist attribute - final String listNames = atype.substring(11).trim(); - final int seppos = listNames.indexOf(','); - - if (seppos == -1 || seppos == listNames.length() - 1) { - log.error("In '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + ", double list: '" + atype + "' does not contain two comma-separated lists."); - return false; - } - - final String listName1 = listNames.substring(0, seppos); - final String listName2 = listNames.substring(seppos + 1); - - if (tlist.getListTable().containsKey(listName1) && tlist.getListTable().containsKey(listName2)) { - // the lists are well defined - dataType = ArchAttribType.DBLLIST; - misc = new String[2]; - misc[0] = listName1; // store list name in misc[0] - misc[1] = listName2; // store list name in misc[1] - } else { - log.error("In '" + CommonConstants.TYPEDEF_FILE + "', type " + typeName + ": List \"" + listName1 + "\" or \"" + listName2 + "\" is undefined."); - } - } else if ("treasurelist".equalsIgnoreCase(atype)) { - dataType = ArchAttribType.TREASURE; - } else { - // unknown type - log.warn("In '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + " has an attribute with unknown type: '" + atype + "'."); - return false; - } - - return true; - } - - /** - * This method reads the text out of the element's "body" and - * cuts off whitespaces at front/end of lines. - * This is a bit hacky but simple. Probably a more correct approach - * would be to display the info text in an html context. - * @param root xml attribute element - */ - private void parseText(final Element root) { - text = root.getTextContent().trim().replaceAll("\\s*\n\\s*", "\n"); - } - - /** - * Assign this attribute to a section. - * @param id section ID - * @param sname section name - */ - public void setSection(final int id, final String sname) { - secId = id; - section = sname; - } - - /** - * Get a new instance of this object with identical content. - * @return clone instance of this <code>CFArchAttrib</code> - */ - public CFArchAttrib getClone() { - final CFArchAttrib newattr = new CFArchAttrib(); - - newattr.next = next; - - newattr.nameOld = nameOld; - newattr.endingOld = endingOld; - newattr.nameNew = nameNew; - newattr.dataType = dataType; - newattr.inputLength = inputLength; - - newattr.text = text; - - // important: we don't create a new instance of 'misc', only a reference - newattr.misc = misc; - - newattr.secId = secId; - newattr.section = section; - - return newattr; - } - - public int getSecId() { - return secId; - } - - public void setSecId(final int newId) { - secId = newId; - } - - public String getSecName() { - return section; - } - - public String getNameOld() { - return nameOld; - } - - public String getNameNew() { - return nameNew; - } - - public ArchAttribType getDataType() { - return dataType; - } - - public String getText() { - return text; - } - - public String[] getMisc() { - return misc; - } - - public int getInputLength() { - return inputLength; - } - - public void setNext(final CFArchAttrib cfAttr) { - next = cfAttr; - } - -} // class CFArchAttrib Modified: trunk/crossfire/src/cfeditor/CFArchType.java =================================================================== --- trunk/crossfire/src/cfeditor/CFArchType.java 2007-01-01 22:10:01 UTC (rev 1363) +++ trunk/crossfire/src/cfeditor/CFArchType.java 2007-01-01 22:14:35 UTC (rev 1364) @@ -28,6 +28,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import net.sf.gridarta.CFArchAttrib; import net.sf.gridarta.CommonConstants; import net.sf.gridarta.gameobject.ArchAttribType; import net.sf.gridarta.gameobject.GameObject; Modified: trunk/crossfire/src/cfeditor/CFArchTypeList.java =================================================================== --- trunk/crossfire/src/cfeditor/CFArchTypeList.java 2007-01-01 22:10:01 UTC (rev 1363) +++ trunk/crossfire/src/cfeditor/CFArchTypeList.java 2007-01-01 22:14:35 UTC (rev 1364) @@ -33,6 +33,7 @@ import java.util.Map; import javax.xml.parsers.ParserConfigurationException; import javax.xml.xpath.XPathExpressionException; +import net.sf.gridarta.CFArchAttrib; import net.sf.gridarta.CommonConstants; import net.sf.japi.xml.NodeListIterator; import static net.sf.japi.xml.NodeListIterator.getFirstChild; Modified: trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java 2007-01-01 22:10:01 UTC (rev 1363) +++ trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java 2007-01-01 22:14:35 UTC (rev 1364) @@ -25,7 +25,6 @@ package cfeditor.gui; import cfeditor.CAttribBitmask; -import cfeditor.CFArchAttrib; import cfeditor.CFArchType; import cfeditor.CFArchTypeList; import cfeditor.CFTreasureListTree; @@ -86,6 +85,7 @@ import javax.swing.text.Style; import javax.swing.text.StyleConstants; import javax.swing.text.StyleContext; +import net.sf.gridarta.CFArchAttrib; import net.sf.gridarta.CommonConstants; import net.sf.gridarta.gameobject.ArchAttribType; import net.sf.gridarta.gameobject.Archetype; Deleted: trunk/daimonin/src/daieditor/CFArchAttrib.java =================================================================== --- trunk/daimonin/src/daieditor/CFArchAttrib.java 2007-01-01 22:10:01 UTC (rev 1363) +++ trunk/daimonin/src/daieditor/CFArchAttrib.java 2007-01-01 22:14:35 UTC (rev 1364) @@ -1,347 +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 java.util.Set; -import net.sf.gridarta.CommonConstants; -import net.sf.gridarta.gameobject.ArchAttribType; -import org.apache.log4j.Logger; -import org.w3c.dom.Attr; -import org.w3c.dom.Element; - -/** - * This Class contains the data of one arch attribute. - * @author <a href="mailto:and...@gm...">Andreas Vogl</a> - */ -public final class CFArchAttrib implements Cloneable { - - private static final Logger log = Logger.getLogger(CFArchAttrib.class); - - // XML tag names - public static final String XML_KEY_ARCH = "arch"; - - public static final String XML_KEY_ARCH_BEGIN = "arch_begin"; - - public static final String XML_KEY_ARCH_END = "arch_end"; - - public static final String XML_KEY_EDITOR = "editor"; - - public static final String XML_ATTR_TYPE = "type"; - - public static final String XML_INPUT_LENGTH = "length"; - - private CFArchAttrib next; // next element in the list (/array) - - private String nameOld; // original attr. name (from the CF arches) - - private String endingOld; // for dataType = ArchAttribType.TEXT this is the terminating string - - // (example: 'endmsg' for arch message) - private String nameNew; // new attr. name (for the user-friendly GUI) - - private ArchAttribType dataType; // type of attribute data - - private String text; // descrption of this attr. - - private int inputLength; // optional attribute: set length for input JTextFields - - private String[] misc; // string array for misc. use - // ArchAttribType.BOOL_SPEC uses misc[0] = true value, misc[1] = false value - // ArchAttribType.BITMASK uses misc[0] = bitmask name - // ArchAttribType.LIST uses misc[0] = list name - - private int secId; // identifier of the section this attribute is in - - private String section; // name of the section this attribute is in - - /** - * Create a CFArchAttrib. - */ - public CFArchAttrib() { - nameOld = ""; - nameNew = ""; - endingOld = null; - misc = null; - inputLength = 0; // use default length - } - - /** - * Loading the data from an xml element into this object. - * @param root the xml 'attribute' element - * @param tlist the archtype list - * @param typeName (descriptive) name of the type this attribute belongs to (e.g. "Weapon") - * @return true if the parsing was successful - */ - public boolean load(final Element root, final net.sf.gridarta.CFArchTypeList tlist, final String typeName) { - - // parse the info text from the element's "body" - parseText(root); - - // arch syntax key - Attr a1; - if ((a1 = root.getAttributeNode(XML_KEY_ARCH)) != null) { - nameOld = a1.getValue().trim(); - } - - // editor syntax key - if ((a1 = root.getAttributeNode(XML_KEY_EDITOR)) != null) { - nameNew = a1.getValue().trim(); - } - - // type name - final String atype; - if ((a1 = root.getAttributeNode(XML_ATTR_TYPE)) != null) { - atype = a1.getValue().trim(); - } else { - // error: no type - log.error("In '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + " has attribute missing '" + XML_ATTR_TYPE + "'."); - return false; - } - - // input length (optional) - if ((a1 = root.getAttributeNode(XML_INPUT_LENGTH)) != null) { - try { - inputLength = Integer.parseInt(a1.getValue()); - } catch (final NumberFormatException de) { - log.error("In '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + " has attribute with invalid length '" + a1.getValue() + "' (must be a number)."); - } - } - - // which type of attribute is it? - if (atype.equalsIgnoreCase("bool")) { - dataType = ArchAttribType.BOOL; // normal bool - } else if (atype.equalsIgnoreCase("bool_special")) { - // customized boolean type: - dataType = ArchAttribType.BOOL_SPEC; - - // parse true and false values: - a1 = root.getAttributeNode("true"); - final Attr a2 = root.getAttributeNode("false"); - if (a1 == null || a2 == null) { - log.error("In '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + " has bool_special attribute missing 'true' or 'false' value."); - return false; - } - - misc = new String[2]; // 'misc' string contains the values - misc[0] = a1.getValue().trim(); // string for true - misc[1] = a2.getValue().trim(); // string for false - } else if (atype.equalsIgnoreCase("int")) { - dataType = ArchAttribType.INT; - } else if (atype.equalsIgnoreCase("long")) { - dataType = ArchAttribType.LONG; - } else if (atype.equalsIgnoreCase("float")) { - dataType = ArchAttribType.FLOAT; - } else if (atype.equalsIgnoreCase("string")) { - dataType = ArchAttribType.STRING; - } else if (atype.equalsIgnoreCase("facename")) { - dataType = ArchAttribType.FACENAME; - } else if (atype.equalsIgnoreCase("animname")) { - dataType = ArchAttribType.ANIMNAME; - } else if (atype.equalsIgnoreCase("text")) { - dataType = ArchAttribType.TEXT; - // for text data, the terminating string has to be read too - if ((a1 = root.getAttributeNode(XML_KEY_ARCH_BEGIN)) != null) { - nameOld = a1.getValue().trim(); - } - - if ((a1 = root.getAttributeNode(XML_KEY_ARCH_END)) != null) { - endingOld = a1.getValue().trim(); - } - - if (nameOld == null || nameOld.length() == 0 || endingOld == null || endingOld.length() == 0) { - log.warn("In '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + " has text attribute missing '" + XML_KEY_ARCH_BEGIN + "' or '" + XML_KEY_ARCH_END + "'."); - return false; - } - } else if ("fixed".equalsIgnoreCase(atype)) { - // fixed attribute - dataType = ArchAttribType.FIXED; - if ((a1 = root.getAttributeNode("value")) != null) { - nameNew = a1.getValue().trim(); - } else { - log.warn("In '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + " has fixed attribute missing 'value'."); - return false; - } - } else if ("spell".equalsIgnoreCase(atype)) { - // spell attribute - if (tlist.getSpells().getSpellNumbers() == null) { - dataType = ArchAttribType.INT; // if we have no spells, use an INT field instead - } else { - dataType = ArchAttribType.SPELL; - } - } else if ("nz_spell".equalsIgnoreCase(atype)) { - // spell attribute - if (tlist.getSpells().getSpellNumbers() == null) { - dataType = ArchAttribType.INT; // if we have no spells, use an INT field instead - } else { - dataType = ArchAttribType.ZSPELL; - } - } else if (atype.startsWith("bitmask")) { - // got a bitmask attribute - final String bitmaskName = atype.substring(8).trim(); - - if (tlist.getBitmaskTable().containsKey(bitmaskName)) { - // the bitmask is well defined - dataType = ArchAttribType.BITMASK; - misc = new String[1]; - misc[0] = bitmaskName; // store bitmask name in misc[0] - } else { - log.warn("In '" + CommonConstants.TYPEDEF_FILE + "', type " + typeName + ": Bitmask \"" + bitmaskName + "\" is undefined."); - } - } else if (atype.startsWith("list")) { - // got a bitmask attribute - final String listName = atype.substring(5).trim(); - if (tlist.getListTable().containsKey(listName)) { - // the list is well defined - dataType = ArchAttribType.LIST; - misc = new String[1]; - misc[0] = listName; // store list name in misc[0] - } else { - log.warn("In '" + CommonConstants.TYPEDEF_FILE + "', type " + typeName + ": List \"" + listName + "\" is undefined."); - log.error("Size of tlist: " + tlist.getListTable().size()); - for (final String key : (Set<String>) tlist.getListTable().keySet()) { - log.error(key); - } - } - } else if ("doublelist".startsWith(atype)) { - // got a doublelist attribute - final String listNames = atype.substring(11).trim(); - final int seppos = listNames.indexOf(','); - - if (seppos == -1 || seppos == listNames.length() - 1) { - log.error("In '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + ", double list: '" + atype + "' does not contain two comma-separated lists."); - return false; - } - - final String listName1 = listNames.substring(0, seppos); - final String listName2 = listNames.substring(seppos + 1); - - if (tlist.getListTable().containsKey(listName1) && tlist.getListTable().containsKey(listName2)) { - // the lists are well defined - dataType = ArchAttribType.DBLLIST; - misc = new String[2]; - misc[0] = listName1; // store list name in misc[0] - misc[1] = listName2; // store list name in misc[1] - } else { - log.error("In '" + CommonConstants.TYPEDEF_FILE + "', type " + typeName + ": List \"" + listName1 + "\" or \"" + listName2 + "\" is undefined."); - } - } else if ("treasurelist".equalsIgnoreCase(atype)) { - dataType = ArchAttribType.TREASURE; - } else { - // unknown type - log.warn("In '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + " has an attribute with unknown type: '" + atype + "'."); - return false; - } - - return true; - } - - /** - * This method reads the text out of the element's "body" and - * cuts off whitespaces at front/end of lines. - * This is a bit hacky but simple. Probably a more correct approach - * would be to display the info text in an html context. - * @param root xml attribute element - */ - private void parseText(final Element root) { - text = root.getTextContent().trim().replaceAll("\\s*\n\\s*", "\n"); - } - - /** - * Assign this attribute to a section. - * @param id section ID - * @param sname section name - */ - public void setSection(final int id, final String sname) { - secId = id; - section = sname; - } - - /** - * Get a new instance of this object with identical content. - * @return clone instance of this <code>CFArchAttrib</code> - */ - public CFArchAttrib getClone() { - final CFArchAttrib newattr = new CFArchAttrib(); - - newattr.next = next; - - newattr.nameOld = nameOld; - newattr.endingOld = endingOld; - newattr.nameNew = nameNew; - newattr.dataType = dataType; - newattr.inputLength = inputLength; - - newattr.text = text; - - // important: we don't create a new instance of 'misc', only a reference - newattr.misc = misc; - - newattr.secId = secId; - newattr.section = section; - - return newattr; - } - - public int getSecId() { - return secId; - } - - public void setSecId(final int newId) { - secId = newId; - } - - public String getSecName() { - return section; - } - - public String getNameOld() { - return nameOld; - } - - public String getNameNew() { - return nameNew; - } - - public ArchAttribType getDataType() { - return dataType; - } - - public String getText() { - return text; - } - - public String[] getMisc() { - return misc; - } - - public int getInputLength() { - return inputLength; - } - - public void setNext(final CFArchAttrib cfAttr) { - next = cfAttr; - } - -} // class CFArchAttrib Modified: trunk/daimonin/src/daieditor/CFArchType.java =================================================================== --- trunk/daimonin/src/daieditor/CFArchType.java 2007-01-01 22:10:01 UTC (rev 1363) +++ trunk/daimonin/src/daieditor/CFArchType.java 2007-01-01 22:14:35 UTC (rev 1364) @@ -28,6 +28,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import net.sf.gridarta.CFArchAttrib; import net.sf.gridarta.CommonConstants; import net.sf.gridarta.gameobject.ArchAttribType; import net.sf.gridarta.gameobject.GameObject; Modified: trunk/daimonin/src/daieditor/CFArchTypeList.java =================================================================== --- trunk/daimonin/src/daieditor/CFArchTypeList.java 2007-01-01 22:10:01 UTC (rev 1363) +++ trunk/daimonin/src/daieditor/CFArchTypeList.java 2007-01-01 22:14:35 UTC (rev 1364) @@ -36,6 +36,7 @@ import java.util.Map; import javax.xml.parsers.ParserConfigurationException; import javax.xml.xpath.XPathExpressionException; +import net.sf.gridarta.CFArchAttrib; import net.sf.gridarta.CommonConstants; import net.sf.japi.xml.NodeListIterator; import static net.sf.japi.xml.NodeListIterator.getFirstChild; Modified: trunk/daimonin/src/daieditor/gui/GameObjectAttributesDialog.java =================================================================== --- trunk/daimonin/src/daieditor/gui/GameObjectAttributesDialog.java 2007-01-01 22:10:01 UTC (rev 1363) +++ trunk/daimonin/src/daieditor/gui/GameObjectAttributesDialog.java 2007-01-01 22:14:35 UTC (rev 1364) @@ -25,7 +25,6 @@ package daieditor.gui; import daieditor.CAttribBitmask; -import daieditor.CFArchAttrib; import daieditor.CFArchType; import daieditor.CFArchTypeList; import daieditor.CFTreasureListTree; @@ -85,6 +84,7 @@ import javax.swing.text.Style; import javax.swing.text.StyleConstants; import javax.swing.text.StyleContext; +import net.sf.gridarta.CFArchAttrib; import net.sf.gridarta.CommonConstants; import net.sf.gridarta.gameobject.ArchAttribType; import net.sf.gridarta.gameobject.Archetype; Copied: trunk/src/app/net/sf/gridarta/CFArchAttrib.java (from rev 1362, trunk/daimonin/src/daieditor/CFArchAttrib.java) =================================================================== --- trunk/src/app/net/sf/gridarta/CFArchAttrib.java (rev 0) +++ trunk/src/app/net/sf/gridarta/CFArchAttrib.java 2007-01-01 22:14:35 UTC (rev 1364) @@ -0,0 +1,346 @@ +/* + * 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 net.sf.gridarta; + +import java.util.Set; +import net.sf.gridarta.gameobject.ArchAttribType; +import org.apache.log4j.Logger; +import org.w3c.dom.Attr; +import org.w3c.dom.Element; + +/** + * This Class contains the data of one arch attribute. + * @author <a href="mailto:and...@gm...">Andreas Vogl</a> + */ +public final class CFArchAttrib implements Cloneable { + + private static final Logger log = Logger.getLogger(CFArchAttrib.class); + + // XML tag names + public static final String XML_KEY_ARCH = "arch"; + + public static final String XML_KEY_ARCH_BEGIN = "arch_begin"; + + public static final String XML_KEY_ARCH_END = "arch_end"; + + public static final String XML_KEY_EDITOR = "editor"; + + public static final String XML_ATTR_TYPE = "type"; + + public static final String XML_INPUT_LENGTH = "length"; + + private CFArchAttrib next; // next element in the list (/array) + + private String nameOld; // original attr. name (from the CF arches) + + private String endingOld; // for dataType = ArchAttribType.TEXT this is the terminating string + + // (example: 'endmsg' for arch message) + private String nameNew; // new attr. name (for the user-friendly GUI) + + private ArchAttribType dataType; // type of attribute data + + private String text; // descrption of this attr. + + private int inputLength; // optional attribute: set length for input JTextFields + + private String[] misc; // string array for misc. use + // ArchAttribType.BOOL_SPEC uses misc[0] = true value, misc[1] = false value + // ArchAttribType.BITMASK uses misc[0] = bitmask name + // ArchAttribType.LIST uses misc[0] = list name + + private int secId; // identifier of the section this attribute is in + + private String section; // name of the section this attribute is in + + /** + * Create a CFArchAttrib. + */ + public CFArchAttrib() { + nameOld = ""; + nameNew = ""; + endingOld = null; + misc = null; + inputLength = 0; // use default length + } + + /** + * Loading the data from an xml element into this object. + * @param root the xml 'attribute' element + * @param tlist the archtype list + * @param typeName (descriptive) name of the type this attribute belongs to (e.g. "Weapon") + * @return true if the parsing was successful + */ + public boolean load(final Element root, final net.sf.gridarta.CFArchTypeList tlist, final String typeName) { + + // parse the info text from the element's "body" + parseText(root); + + // arch syntax key + Attr a1; + if ((a1 = root.getAttributeNode(XML_KEY_ARCH)) != null) { + nameOld = a1.getValue().trim(); + } + + // editor syntax key + if ((a1 = root.getAttributeNode(XML_KEY_EDITOR)) != null) { + nameNew = a1.getValue().trim(); + } + + // type name + final String atype; + if ((a1 = root.getAttributeNode(XML_ATTR_TYPE)) != null) { + atype = a1.getValue().trim(); + } else { + // error: no type + log.error("In '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + " has attribute missing '" + XML_ATTR_TYPE + "'."); + return false; + } + + // input length (optional) + if ((a1 = root.getAttributeNode(XML_INPUT_LENGTH)) != null) { + try { + inputLength = Integer.parseInt(a1.getValue()); + } catch (final NumberFormatException de) { + log.error("In '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + " has attribute with invalid length '" + a1.getValue() + "' (must be a number)."); + } + } + + // which type of attribute is it? + if (atype.equalsIgnoreCase("bool")) { + dataType = ArchAttribType.BOOL; // normal bool + } else if (atype.equalsIgnoreCase("bool_special")) { + // customized boolean type: + dataType = ArchAttribType.BOOL_SPEC; + + // parse true and false values: + a1 = root.getAttributeNode("true"); + final Attr a2 = root.getAttributeNode("false"); + if (a1 == null || a2 == null) { + log.error("In '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + " has bool_special attribute missing 'true' or 'false' value."); + return false; + } + + misc = new String[2]; // 'misc' string contains the values + misc[0] = a1.getValue().trim(); // string for true + misc[1] = a2.getValue().trim(); // string for false + } else if (atype.equalsIgnoreCase("int")) { + dataType = ArchAttribType.INT; + } else if (atype.equalsIgnoreCase("long")) { + dataType = ArchAttribType.LONG; + } else if (atype.equalsIgnoreCase("float")) { + dataType = ArchAttribType.FLOAT; + } else if (atype.equalsIgnoreCase("string")) { + dataType = ArchAttribType.STRING; + } else if (atype.equalsIgnoreCase("facename")) { + dataType = ArchAttribType.FACENAME; + } else if (atype.equalsIgnoreCase("animname")) { + dataType = ArchAttribType.ANIMNAME; + } else if (atype.equalsIgnoreCase("text")) { + dataType = ArchAttribType.TEXT; + // for text data, the terminating string has to be read too + if ((a1 = root.getAttributeNode(XML_KEY_ARCH_BEGIN)) != null) { + nameOld = a1.getValue().trim(); + } + + if ((a1 = root.getAttributeNode(XML_KEY_ARCH_END)) != null) { + endingOld = a1.getValue().trim(); + } + + if (nameOld == null || nameOld.length() == 0 || endingOld == null || endingOld.length() == 0) { + log.warn("In '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + " has text attribute missing '" + XML_KEY_ARCH_BEGIN + "' or '" + XML_KEY_ARCH_END + "'."); + return false; + } + } else if ("fixed".equalsIgnoreCase(atype)) { + // fixed attribute + dataType = ArchAttribType.FIXED; + if ((a1 = root.getAttributeNode("value")) != null) { + nameNew = a1.getValue().trim(); + } else { + log.warn("In '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + " has fixed attribute missing 'value'."); + return false; + } + } else if ("spell".equalsIgnoreCase(atype)) { + // spell attribute + if (tlist.getSpells().getSpellNumbers() == null) { + dataType = ArchAttribType.INT; // if we have no spells, use an INT field instead + } else { + dataType = ArchAttribType.SPELL; + } + } else if ("nz_spell".equalsIgnoreCase(atype)) { + // spell attribute + if (tlist.getSpells().getSpellNumbers() == null) { + dataType = ArchAttribType.INT; // if we have no spells, use an INT field instead + } else { + dataType = ArchAttribType.ZSPELL; + } + } else if (atype.startsWith("bitmask")) { + // got a bitmask attribute + final String bitmaskName = atype.substring(8).trim(); + + if (tlist.getBitmaskTable().containsKey(bitmaskName)) { + // the bitmask is well defined + dataType = ArchAttribType.BITMASK; + misc = new String[1]; + misc[0] = bitmaskName; // store bitmask name in misc[0] + } else { + log.warn("In '" + CommonConstants.TYPEDEF_FILE + "', type " + typeName + ": Bitmask \"" + bitmaskName + "\" is undefined."); + } + } else if (atype.startsWith("list")) { + // got a bitmask attribute + final String listName = atype.substring(5).trim(); + if (tlist.getListTable().containsKey(listName)) { + // the list is well defined + dataType = ArchAttribType.LIST; + misc = new String[1]; + misc[0] = listName; // store list name in misc[0] + } else { + log.warn("In '" + CommonConstants.TYPEDEF_FILE + "', type " + typeName + ": List \"" + listName + "\" is undefined."); + log.error("Size of tlist: " + tlist.getListTable().size()); + for (final String key : (Set<String>) tlist.getListTable().keySet()) { + log.error(key); + } + } + } else if ("doublelist".startsWith(atype)) { + // got a doublelist attribute + final String listNames = atype.substring(11).trim(); + final int seppos = listNames.indexOf(','); + + if (seppos == -1 || seppos == listNames.length() - 1) { + log.error("In '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + ", double list: '" + atype + "' does not contain two comma-separated lists."); + return false; + } + + final String listName1 = listNames.substring(0, seppos); + final String listName2 = listNames.substring(seppos + 1); + + if (tlist.getListTable().containsKey(listName1) && tlist.getListTable().containsKey(listName2)) { + // the lists are well defined + dataType = ArchAttribType.DBLLIST; + misc = new String[2]; + misc[0] = listName1; // store list name in misc[0] + misc[1] = listName2; // store list name in misc[1] + } else { + log.error("In '" + CommonConstants.TYPEDEF_FILE + "', type " + typeName + ": List \"" + listName1 + "\" or \"" + listName2 + "\" is undefined."); + } + } else if ("treasurelist".equalsIgnoreCase(atype)) { + dataType = ArchAttribType.TREASURE; + } else { + // unknown type + log.warn("In '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + " has an attribute with unknown type: '" + atype + "'."); + return false; + } + + return true; + } + + /** + * This method reads the text out of the element's "body" and + * cuts off whitespaces at front/end of lines. + * This is a bit hacky but simple. Probably a more correct approach + * would be to display the info text in an html context. + * @param root xml attribute element + */ + private void parseText(final Element root) { + text = root.getTextContent().trim().replaceAll("\\s*\n\\s*", "\n"); + } + + /** + * Assign this attribute to a section. + * @param id section ID + * @param sname section name + */ + public void setSection(final int id, final String sname) { + secId = id; + section = sname; + } + + /** + * Get a new instance of this object with identical content. + * @return clone instance of this <code>CFArchAttrib</code> + */ + public CFArchAttrib getClone() { + final CFArchAttrib newattr = new CFArchAttrib(); + + newattr.next = next; + + newattr.nameOld = nameOld; + newattr.endingOld = endingOld; + newattr.nameNew = nameNew; + newattr.dataType = dataType; + newattr.inputLength = inputLength; + + newattr.text = text; + + // important: we don't create a new instance of 'misc', only a reference + newattr.misc = misc; + + newattr.secId = secId; + newattr.section = section; + + return newattr; + } + + public int getSecId() { + return secId; + } + + public void setSecId(final int newId) { + secId = newId; + } + + public String getSecName() { + return section; + } + + public String getNameOld() { + return nameOld; + } + + public String getNameNew() { + return nameNew; + } + + public ArchAttribType getDataType() { + return dataType; + } + + public String getText() { + return text; + } + + public String[] getMisc() { + return misc; + } + + public int getInputLength() { + return inputLength; + } + + public void setNext(final CFArchAttrib cfAttr) { + next = cfAttr; + } + +} // class CFArchAttrib Property changes on: trunk/src/app/net/sf/gridarta/CFArchAttrib.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...> - 2007-01-01 22:24:21
|
Revision: 1365 http://svn.sourceforge.net/gridarta/?rev=1365&view=rev Author: christianhujer Date: 2007-01-01 14:24:22 -0800 (Mon, 01 Jan 2007) Log Message: ----------- Made parameter type for dialog parent less specific. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CFTreasureListTree.java trunk/daimonin/src/daieditor/CFTreasureListTree.java Modified: trunk/crossfire/src/cfeditor/CFTreasureListTree.java =================================================================== --- trunk/crossfire/src/cfeditor/CFTreasureListTree.java 2007-01-01 22:14:35 UTC (rev 1364) +++ trunk/crossfire/src/cfeditor/CFTreasureListTree.java 2007-01-01 22:24:22 UTC (rev 1365) @@ -26,7 +26,6 @@ import cfeditor.gameobject.ArchetypeSet; import cfeditor.gameobject.GameObject; -import cfeditor.gui.GameObjectAttributesDialog; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; @@ -463,7 +462,7 @@ * @param input Textfield to show. * @param parent Parent frame (attribute dialog) */ - public synchronized void showDialog(final JTextField input, final GameObjectAttributesDialog parent) { + public synchronized void showDialog(final JTextField input, final Component parent) { this.input = input; // set textfield for input/output if (!hasBeenDisplayed) { Modified: trunk/daimonin/src/daieditor/CFTreasureListTree.java =================================================================== --- trunk/daimonin/src/daieditor/CFTreasureListTree.java 2007-01-01 22:14:35 UTC (rev 1364) +++ trunk/daimonin/src/daieditor/CFTreasureListTree.java 2007-01-01 22:24:22 UTC (rev 1365) @@ -25,7 +25,6 @@ package daieditor; import daieditor.gameobject.GameObject; -import daieditor.gui.GameObjectAttributesDialog; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; @@ -478,7 +477,7 @@ * @param input Textfield to show. * @param parent Parent frame (attribute dialog) */ - public synchronized void showDialog(final JTextField input, final GameObjectAttributesDialog parent) { + public synchronized void showDialog(final JTextField input, final Component parent) { this.input = input; // set textfield for input/output if (!hasBeenDisplayed) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2007-01-01 22:32:20
|
Revision: 1366 http://svn.sourceforge.net/gridarta/?rev=1366&view=rev Author: christianhujer Date: 2007-01-01 14:32:20 -0800 (Mon, 01 Jan 2007) Log Message: ----------- Some GameObjectAttributesDialog unification. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java trunk/daimonin/src/daieditor/gui/GameObjectAttributesDialog.java trunk/src/app/net/sf/gridarta/gui/AbstractGameObjectAttributesDialog.java Modified: trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java 2007-01-01 22:24:22 UTC (rev 1365) +++ trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java 2007-01-01 22:32:20 UTC (rev 1366) @@ -41,11 +41,7 @@ import java.awt.GridBagLayout; import java.awt.GridLayout; import java.awt.Insets; -import java.awt.Rectangle; import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.text.NumberFormat; @@ -103,7 +99,7 @@ * @author <a href="mailto:ch...@ri...">Christian Hujer</a> * @fixme I suck */ -public final class GameObjectAttributesDialog extends AbstractGameObjectAttributesDialog implements FocusListener { +public final class GameObjectAttributesDialog extends AbstractGameObjectAttributesDialog { private static final Logger log = Logger.getLogger(GameObjectAttributesDialog.class); @@ -877,15 +873,6 @@ } /** - * Spawns a popup-message to display the help text of an attribute. - * @param title name of attribute - * @param msg message text - */ - private void popupHelp(final String title, final String msg) { - showMessageDialog(this, msg, "Help: " + title, PLAIN_MESSAGE); - } - - /** * Action method for summary. Switches the cardlayout to the summary list * of all nonzero attributes. */ @@ -1397,35 +1384,6 @@ frame.setVisible(true); } - public void focusGained(final FocusEvent e) { - final JComponent c = (JComponent) e.getComponent(); - final JPanel p = (JPanel) c.getParent(); - final Rectangle r = c.getBounds(); - p.scrollRectToVisible(r); - } - - public void focusLost(final FocusEvent e) { - } - - /** A single Attribute, combining the CFArchAttrib with its input component(s). */ - private static class DialogAttrib<T> { - - /** Input component(s). */ - protected T input; - - /** Reference to the attribute data. */ - public final CFArchAttrib ref; // reference to the attribute data - - /** - * Create a DialogAttrib. - * @param ref reference to the attribute data - */ - private DialogAttrib(final CFArchAttrib ref) { - this.ref = ref; - } - - } // class DialogAttrib - /** DialogAttrib for types with bitmasks to choose from. */ public static final class BitmaskAttrib extends DialogAttrib<JTextComponent> { @@ -1466,35 +1424,6 @@ } // class BitmaskAttrib - /** ActionListener for help-buttons. */ - private final class HelpActionListener implements ActionListener { - - /** CFArchAttrib which contains help information. */ - private final CFArchAttrib attrib; // attribute structure - - /** - * Constructor. - * @param a the gameObject attribute where this help button belongs to - */ - private HelpActionListener(final CFArchAttrib a) { - if (a == null) { - throw new NullPointerException("HelpActionListener without context"); - } - attrib = a; - } - - /** {@inheritDoc} */ - public void actionPerformed(final ActionEvent e) { - if (attrib != null) { - popupHelp(attrib.getNameNew(), attrib.getText()); - } else { - assert false; - log.warn("Help without help context!"); - } - } - - } // class HelpActionListener - /** ActionListener for the change buttons of bitmasks. */ private static final class MaskChangeAL extends AbstractAction { @@ -1535,7 +1464,7 @@ private final DialogAttrib<JTextField> strAttr; // attribute structure - private final GameObjectAttributesDialog dialog; // reference to this dialog instance + private final AbstractGameObjectAttributesDialog dialog; // reference to this dialog instance /** * Constructor. Modified: trunk/daimonin/src/daieditor/gui/GameObjectAttributesDialog.java =================================================================== --- trunk/daimonin/src/daieditor/gui/GameObjectAttributesDialog.java 2007-01-01 22:24:22 UTC (rev 1365) +++ trunk/daimonin/src/daieditor/gui/GameObjectAttributesDialog.java 2007-01-01 22:32:20 UTC (rev 1366) @@ -40,11 +40,7 @@ import java.awt.GridBagLayout; import java.awt.GridLayout; import java.awt.Insets; -import java.awt.Rectangle; import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.text.NumberFormat; @@ -103,7 +99,7 @@ * @author <a href="mailto:ch...@ri...">Christian Hujer</a> * @fixme I suck */ -public final class GameObjectAttributesDialog extends AbstractGameObjectAttributesDialog implements FocusListener { +public final class GameObjectAttributesDialog extends AbstractGameObjectAttributesDialog { private static final Logger log = Logger.getLogger(GameObjectAttributesDialog.class); @@ -872,15 +868,6 @@ } /** - * Spawns a popup-message to display the help text of an attribute. - * @param title name of attribute - * @param msg message text - */ - private void popupHelp(final String title, final String msg) { - showMessageDialog(this, msg, "Help: " + title, PLAIN_MESSAGE); - } - - /** * Action method for summary. Switches the cardlayout to the summary list * of all nonzero attributes. */ @@ -1375,35 +1362,6 @@ frame.setVisible(true); } - public void focusGained(final FocusEvent e) { - final JComponent c = (JComponent) e.getComponent(); - final JPanel p = (JPanel) c.getParent(); - final Rectangle r = c.getBounds(); - p.scrollRectToVisible(r); - } - - public void focusLost(final FocusEvent e) { - } - - /** A single Attribute, combining the CFArchAttrib with its input component(s). */ - private static class DialogAttrib<T> { - - /** Input component(s). */ - protected T input; - - /** Reference to the attribute data. */ - public final CFArchAttrib ref; // reference to the attribute data - - /** - * Create a DialogAttrib. - * @param ref reference to the attribute data - */ - private DialogAttrib(final CFArchAttrib ref) { - this.ref = ref; - } - - } // class DialogAttrib - /** DialogAttrib for types with bitmasks to choose from. */ public static final class BitmaskAttrib extends DialogAttrib<JTextComponent> { @@ -1444,35 +1402,6 @@ } // class BitmaskAttrib - /** ActionListener for help-buttons. */ - private final class HelpActionListener implements ActionListener { - - /** CFArchAttrib which contains help information. */ - private final CFArchAttrib attrib; // attribute structure - - /** - * Constructor. - * @param a the gameObject attribute where this help button belongs to - */ - private HelpActionListener(final CFArchAttrib a) { - if (a == null) { - throw new NullPointerException("HelpActionListener without context"); - } - attrib = a; - } - - /** {@inheritDoc} */ - public void actionPerformed(final ActionEvent e) { - if (attrib != null) { - popupHelp(attrib.getNameNew(), attrib.getText()); - } else { - assert false; - log.warn("Help without help context!"); - } - } - - } // class HelpActionListener - /** ActionListener for the change buttons of bitmasks. */ private static final class MaskChangeAL extends AbstractAction { @@ -1513,7 +1442,7 @@ private final DialogAttrib<JTextField> strAttr; // attribute structure - private final GameObjectAttributesDialog dialog; // reference to this dialog instance + private final AbstractGameObjectAttributesDialog dialog; // reference to this dialog instance /** * Constructor. Modified: trunk/src/app/net/sf/gridarta/gui/AbstractGameObjectAttributesDialog.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/AbstractGameObjectAttributesDialog.java 2007-01-01 22:24:22 UTC (rev 1365) +++ trunk/src/app/net/sf/gridarta/gui/AbstractGameObjectAttributesDialog.java 2007-01-01 22:32:20 UTC (rev 1366) @@ -1,17 +1,23 @@ package net.sf.gridarta.gui; +import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.AbstractAction; import javax.swing.ComboBoxModel; import javax.swing.JButton; import javax.swing.JComboBox; +import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JOptionPane; +import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.JTextField; +import net.sf.gridarta.CFArchAttrib; import net.sf.gridarta.gameobject.GameObject; import net.sf.gridarta.gameobject.NamedObject; import net.sf.gridarta.gameobject.NamedObjects; @@ -21,11 +27,80 @@ * Common base class for game object attributes dialogs. * @author <a href="mailto:ch...@ri...">Christian Hujer</a> */ -public class AbstractGameObjectAttributesDialog extends JOptionPane { +public class AbstractGameObjectAttributesDialog extends JOptionPane implements FocusListener { private static final Logger log = Logger.getLogger(AbstractGameObjectAttributesDialog.class); + /** {@inheritDoc} */ + public void focusGained(final FocusEvent e) { + final JComponent c = (JComponent) e.getComponent(); + final JPanel p = (JPanel) c.getParent(); + final Rectangle r = c.getBounds(); + p.scrollRectToVisible(r); + } + + /** {@inheritDoc} */ + public void focusLost(final FocusEvent e) { + } + /** + * Spawns a popup-message to display the help text of an attribute. + * @param title name of attribute + * @param msg message text + */ + protected final void popupHelp(final String title, final String msg) { + showMessageDialog(this, msg, "Help: " + title, PLAIN_MESSAGE); + } + + /** A single Attribute, combining the CFArchAttrib with its input component(s). */ + public static class DialogAttrib<T> { + + /** Input component(s). */ + public T input; + + /** Reference to the attribute data. */ + public final CFArchAttrib ref; // reference to the attribute data + + /** + * Create a DialogAttrib. + * @param ref reference to the attribute data + */ + public DialogAttrib(final CFArchAttrib ref) { + this.ref = ref; + } + + } // class DialogAttrib + + /** ActionListener for help-buttons. */ + public final class HelpActionListener implements ActionListener { + + /** CFArchAttrib which contains help information. */ + private final CFArchAttrib attrib; // attribute structure + + /** + * Constructor. + * @param a the gameObject attribute where this help button belongs to + */ + public HelpActionListener(final CFArchAttrib a) { + if (a == null) { + throw new NullPointerException("HelpActionListener without context"); + } + attrib = a; + } + + /** {@inheritDoc} */ + public void actionPerformed(final ActionEvent e) { + if (attrib != null) { + popupHelp(attrib.getNameNew(), attrib.getText()); + } else { + assert false; + log.warn("Help without help context!"); + } + } + + } // class HelpActionListener + + /** * ActionListener for the buttons in the ConfirmErrors popup dialog and * also WindowListener for the closebox of the dialog (which would equal a * "keep all" button). This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2007-01-01 23:01:17
|
Revision: 1367 http://svn.sourceforge.net/gridarta/?rev=1367&view=rev Author: christianhujer Date: 2007-01-01 15:01:17 -0800 (Mon, 01 Jan 2007) Log Message: ----------- Merged CAttribBitmask. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CFArchTypeList.java trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java trunk/daimonin/src/daieditor/CFArchTypeList.java trunk/daimonin/src/daieditor/gui/GameObjectAttributesDialog.java trunk/src/app/net/sf/gridarta/gui/AbstractGameObjectAttributesDialog.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/CAttribBitmask.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/CAttribBitmask.java trunk/daimonin/src/daieditor/CAttribBitmask.java Deleted: trunk/crossfire/src/cfeditor/CAttribBitmask.java =================================================================== --- trunk/crossfire/src/cfeditor/CAttribBitmask.java 2007-01-01 22:32:20 UTC (rev 1366) +++ trunk/crossfire/src/cfeditor/CAttribBitmask.java 2007-01-01 23:01:17 UTC (rev 1367) @@ -1,160 +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.gui.GameObjectAttributesDialog; -import java.awt.Component; -import java.awt.GridLayout; -import javax.swing.JCheckBox; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathExpressionException; -import net.sf.japi.xml.NodeListIterator; -import org.apache.log4j.Logger; -import org.jetbrains.annotations.Nullable; -import org.w3c.dom.Element; - -/** - * This class manages bitmask values which appear in Crossfire arch attributes. - * Attacktype, spellpath and material are such bitmasks. They are disguised for - * the user, with the help of the attribute dialog. - * @author <a href="mailto:and...@gm...">Andreas Vogl</a> - * @author <a href="mailto:ch...@ri...">Christian Hujer</a> - */ -public final class CAttribBitmask { - - private static final Logger log = Logger.getLogger(CAttribBitmask.class); - - /** - * Maximum number of characters in a line before linebreak (see {@link - * #getText(int)}). - */ - private static final int MAX_CHARS_PER_LINE = 35; // 50 - - /** Names of the bitmask-entries. */ - private final String[] bitName; - - /** Maximum possible value. */ - private final int maxvalue; - - /** Number of bitmask entries (not counting zero). */ - private final int number; - - /** - * Constructor of a bitmask from XML element. - * @param xpath XPath for XPath evaluation - * @param bitmasksElement xml bitmask element - * @throws XPathExpressionException in case of XPath evaluation errors - */ - public CAttribBitmask(final XPath xpath, final Element bitmasksElement) throws XPathExpressionException { - final NodeListIterator<Element> entries = new NodeListIterator<Element>(xpath, bitmasksElement, "bmentry|entry"); - number = entries.size(); - bitName = new String[number + 1]; - maxvalue = (1 << (bitName.length + 1)) - 1; - bitName[0] = "<none>"; - for (final Element elem : entries) { - bitName[Integer.parseInt(elem.getAttribute("bit")) + 1] = elem.getAttribute("name"); - } - } - - /** - * Check whether the given bit-index is an active bit in the bitmask. - * @param index index of the bit to check (range from 1-'number') - * @param mask bitmask to check against - * @return <code>true</code> if the bit is active in mask, otherwise - * <code>false</code> - */ - private static boolean isActive(final int index, final int mask) { - final int bit = 1 << (index - 1); - return (mask & bit) == bit; - } - - /** - * Generate the text to be displayed for a given bitmask value. - * @param value bitmask value - * @return <code>String</code> with all entries belonging to the bitmask - */ - public String getText(final int value) { - if (value <= 0) { - return bitName[0]; - } - - // value too big? - if (value > maxvalue) { - log.warn("bitmask value " + value + " is too big."); - } - - final StringBuilder sb = new StringBuilder(); - boolean notFirst = false; - int linelength = 0; - for (int i = 1; i < bitName.length; i++) { - if (isActive(i, value)) { - if (notFirst) { - if (linelength + bitName[i].length() + 1 > MAX_CHARS_PER_LINE) { - sb.append(",\n"); - linelength = 0; - } else { - sb.append(", "); - linelength += 2; - } - } - linelength += bitName[i].length(); - sb.append(bitName[i]); - notFirst = true; - } - } - - return sb.toString(); - } - - /** - * Open a popup frame to select bitmask-entries via chooseboxes. - * @param parentComponent the parent component of this dialog - * @param guiAttr Bitmask attribute to update - * @return Integer with new value or <code>null</code> if the user cancelled the dialog - */ - @Nullable public Integer showBitmaskDialog(final Component parentComponent, final GameObjectAttributesDialog.BitmaskAttrib guiAttr) { - final String title = "Choose " + guiAttr.ref.getNameNew().substring(0, 1).toUpperCase() + guiAttr.ref.getNameNew().substring(1); - final JPanel gridPanel = new JPanel(new GridLayout(0, 2, 3, 3)); - final JCheckBox[] checkbox = new JCheckBox[number]; - for (int i = 0; i < number; i++) { - checkbox[i] = new JCheckBox(bitName[i + 1]); - checkbox[i].setSelected(isActive(i + 1, guiAttr.getValue())); - gridPanel.add(checkbox[i]); - } - if (JOptionPane.showConfirmDialog(parentComponent, gridPanel, title, JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE) == JOptionPane.OK_OPTION) { - int newValue = 0; - for (int i = 0; i < number; i++) { - if (checkbox[i].isSelected()) { - newValue |= 1 << i; - } - } - return newValue; - } - return null; - } - -} // class CAttribBitmask Modified: trunk/crossfire/src/cfeditor/CFArchTypeList.java =================================================================== --- trunk/crossfire/src/cfeditor/CFArchTypeList.java 2007-01-01 22:32:20 UTC (rev 1366) +++ trunk/crossfire/src/cfeditor/CFArchTypeList.java 2007-01-01 23:01:17 UTC (rev 1367) @@ -33,6 +33,7 @@ import java.util.Map; import javax.xml.parsers.ParserConfigurationException; import javax.xml.xpath.XPathExpressionException; +import net.sf.gridarta.CAttribBitmask; import net.sf.gridarta.CFArchAttrib; import net.sf.gridarta.CommonConstants; import net.sf.japi.xml.NodeListIterator; Modified: trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java 2007-01-01 22:32:20 UTC (rev 1366) +++ trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java 2007-01-01 23:01:17 UTC (rev 1367) @@ -24,7 +24,6 @@ package cfeditor.gui; -import cfeditor.CAttribBitmask; import cfeditor.CFArchType; import cfeditor.CFArchTypeList; import cfeditor.CFTreasureListTree; @@ -81,6 +80,7 @@ import javax.swing.text.Style; import javax.swing.text.StyleConstants; import javax.swing.text.StyleContext; +import net.sf.gridarta.CAttribBitmask; import net.sf.gridarta.CFArchAttrib; import net.sf.gridarta.CommonConstants; import net.sf.gridarta.gameobject.ArchAttribType; @@ -1384,46 +1384,6 @@ frame.setVisible(true); } - /** DialogAttrib for types with bitmasks to choose from. */ - public static final class BitmaskAttrib extends DialogAttrib<JTextComponent> { - - /** Active bitmask value. */ - private int value; - - /** Reference to the bitmask data. */ - private CAttribBitmask bitmask; - - /** - * Create a BitmaskAttrib. - * @param ref reference to the attribute data - */ - private BitmaskAttrib(final CFArchAttrib ref) { - super(ref); - } - - /** - * Get the active bitmask value. - * @return active bitmask value - */ - public int getValue() { - return value; - } - - /** - * Set the active bitmask value. - * @param value new active bitmask value - */ - void setValue(final int value) { - this.value = value; - if (bitmask != null) { - input.setText(bitmask.getText(value)); - } else { - System.err.println("null bitmask"); - } - } - - } // class BitmaskAttrib - /** ActionListener for the change buttons of bitmasks. */ private static final class MaskChangeAL extends AbstractAction { Deleted: trunk/daimonin/src/daieditor/CAttribBitmask.java =================================================================== --- trunk/daimonin/src/daieditor/CAttribBitmask.java 2007-01-01 22:32:20 UTC (rev 1366) +++ trunk/daimonin/src/daieditor/CAttribBitmask.java 2007-01-01 23:01:17 UTC (rev 1367) @@ -1,160 +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.gui.GameObjectAttributesDialog; -import java.awt.Component; -import java.awt.GridLayout; -import javax.swing.JCheckBox; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathExpressionException; -import net.sf.japi.xml.NodeListIterator; -import org.apache.log4j.Logger; -import org.jetbrains.annotations.Nullable; -import org.w3c.dom.Element; - -/** - * This class manages bitmask values which appear in Daimonin arch attributes. - * Attacktype, spellpath and material are such bitmasks. They are disguised for - * the user, with the help of the attribute dialog. - * @author <a href="mailto:and...@gm...">Andreas Vogl</a> - * @author <a href="mailto:ch...@ri...">Christian Hujer</a> - */ -public final class CAttribBitmask { - - private static final Logger log = Logger.getLogger(CAttribBitmask.class); - - /** - * Maximum number of characters in a line before linebreak (see {@link - * #getText(int)}). - */ - private static final int MAX_CHARS_PER_LINE = 35; // 50 - - /** Names of the bitmask-entries. */ - private final String[] bitName; - - /** Maximum possible value. */ - private final int maxvalue; - - /** Number of bitmask entries (not counting zero). */ - private final int number; - - /** - * Constructor of a bitmask from XML element. - * @param xpath XPath for XPath evaluation - * @param bitmasksElement xml bitmask element - * @throws XPathExpressionException in case of XPath evaluation errors - */ - public CAttribBitmask(final XPath xpath, final Element bitmasksElement) throws XPathExpressionException { - final NodeListIterator<Element> entries = new NodeListIterator<Element>(xpath, bitmasksElement, "bmentry|entry"); - number = entries.size(); - bitName = new String[number + 1]; - maxvalue = (1 << (bitName.length + 1)) - 1; - bitName[0] = "<none>"; - for (final Element elem : entries) { - bitName[Integer.parseInt(elem.getAttribute("bit")) + 1] = elem.getAttribute("name"); - } - } - - /** - * Check whether the given bit-index is an active bit in the bitmask. - * @param index index of the bit to check (range from 1-'number') - * @param mask bitmask to check against - * @return <code>true</code> if the bit is active in mask, otherwise - * <code>false</code> - */ - private static boolean isActive(final int index, final int mask) { - final int bit = 1 << (index - 1); - return (mask & bit) == bit; - } - - /** - * Generate the text to be displayed for a given bitmask value. - * @param value bitmask value - * @return <code>String</code> with all entries belonging to the bitmask - */ - public String getText(final int value) { - if (value <= 0) { - return bitName[0]; - } - - // value too big? - if (value > maxvalue) { - log.warn("bitmask value " + value + " is too big."); - } - - final StringBuilder sb = new StringBuilder(); - boolean notFirst = false; - int linelength = 0; - for (int i = 1; i < bitName.length; i++) { - if (isActive(i, value)) { - if (notFirst) { - if (linelength + bitName[i].length() + 1 > MAX_CHARS_PER_LINE) { - sb.append(",\n"); - linelength = 0; - } else { - sb.append(", "); - linelength += 2; - } - } - linelength += bitName[i].length(); - sb.append(bitName[i]); - notFirst = true; - } - } - - return sb.toString(); - } - - /** - * Open a popup frame to select bitmask-entries via chooseboxes. - * @param parentComponent the parent component of this dialog - * @param guiAttr Bitmask attribute to update - * @return Integer with new value or <code>null</code> if the user cancelled the dialog - */ - @Nullable public Integer showBitmaskDialog(final Component parentComponent, final GameObjectAttributesDialog.BitmaskAttrib guiAttr) { - final String title = "Choose " + guiAttr.ref.getNameNew().substring(0, 1).toUpperCase() + guiAttr.ref.getNameNew().substring(1); - final JPanel gridPanel = new JPanel(new GridLayout(0, 2, 3, 3)); - final JCheckBox[] checkbox = new JCheckBox[number]; - for (int i = 0; i < number; i++) { - checkbox[i] = new JCheckBox(bitName[i + 1]); - checkbox[i].setSelected(isActive(i + 1, guiAttr.getValue())); - gridPanel.add(checkbox[i]); - } - if (JOptionPane.showConfirmDialog(parentComponent, gridPanel, title, JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE) == JOptionPane.OK_OPTION) { - int newValue = 0; - for (int i = 0; i < number; i++) { - if (checkbox[i].isSelected()) { - newValue |= 1 << i; - } - } - return newValue; - } - return null; - } - -} // class CAttribBitmask Modified: trunk/daimonin/src/daieditor/CFArchTypeList.java =================================================================== --- trunk/daimonin/src/daieditor/CFArchTypeList.java 2007-01-01 22:32:20 UTC (rev 1366) +++ trunk/daimonin/src/daieditor/CFArchTypeList.java 2007-01-01 23:01:17 UTC (rev 1367) @@ -36,6 +36,7 @@ import java.util.Map; import javax.xml.parsers.ParserConfigurationException; import javax.xml.xpath.XPathExpressionException; +import net.sf.gridarta.CAttribBitmask; import net.sf.gridarta.CFArchAttrib; import net.sf.gridarta.CommonConstants; import net.sf.japi.xml.NodeListIterator; Modified: trunk/daimonin/src/daieditor/gui/GameObjectAttributesDialog.java =================================================================== --- trunk/daimonin/src/daieditor/gui/GameObjectAttributesDialog.java 2007-01-01 22:32:20 UTC (rev 1366) +++ trunk/daimonin/src/daieditor/gui/GameObjectAttributesDialog.java 2007-01-01 23:01:17 UTC (rev 1367) @@ -24,7 +24,6 @@ package daieditor.gui; -import daieditor.CAttribBitmask; import daieditor.CFArchType; import daieditor.CFArchTypeList; import daieditor.CFTreasureListTree; @@ -80,6 +79,7 @@ import javax.swing.text.Style; import javax.swing.text.StyleConstants; import javax.swing.text.StyleContext; +import net.sf.gridarta.CAttribBitmask; import net.sf.gridarta.CFArchAttrib; import net.sf.gridarta.CommonConstants; import net.sf.gridarta.gameobject.ArchAttribType; @@ -1362,46 +1362,6 @@ frame.setVisible(true); } - /** DialogAttrib for types with bitmasks to choose from. */ - public static final class BitmaskAttrib extends DialogAttrib<JTextComponent> { - - /** Active bitmask value. */ - private int value; - - /** Reference to the bitmask data. */ - private CAttribBitmask bitmask; - - /** - * Create a BitmaskAttrib. - * @param ref reference to the attribute data - */ - private BitmaskAttrib(final CFArchAttrib ref) { - super(ref); - } - - /** - * Get the active bitmask value. - * @return active bitmask value - */ - public int getValue() { - return value; - } - - /** - * Set the active bitmask value. - * @param value new active bitmask value - */ - void setValue(final int value) { - this.value = value; - if (bitmask != null) { - input.setText(bitmask.getText(value)); - } else { - System.err.println("null bitmask"); - } - } - - } // class BitmaskAttrib - /** ActionListener for the change buttons of bitmasks. */ private static final class MaskChangeAL extends AbstractAction { Copied: trunk/src/app/net/sf/gridarta/CAttribBitmask.java (from rev 1365, trunk/daimonin/src/daieditor/CAttribBitmask.java) =================================================================== --- trunk/src/app/net/sf/gridarta/CAttribBitmask.java (rev 0) +++ trunk/src/app/net/sf/gridarta/CAttribBitmask.java 2007-01-01 23:01:17 UTC (rev 1367) @@ -0,0 +1,160 @@ +/* + * 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 net.sf.gridarta; + +import java.awt.Component; +import java.awt.GridLayout; +import javax.swing.JCheckBox; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathExpressionException; +import net.sf.gridarta.gui.AbstractGameObjectAttributesDialog; +import net.sf.japi.xml.NodeListIterator; +import org.apache.log4j.Logger; +import org.jetbrains.annotations.Nullable; +import org.w3c.dom.Element; + +/** + * This class manages bitmask values which appear in Daimonin arch attributes. + * Attacktype, spellpath and material are such bitmasks. They are disguised for + * the user, with the help of the attribute dialog. + * @author <a href="mailto:and...@gm...">Andreas Vogl</a> + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public final class CAttribBitmask { + + private static final Logger log = Logger.getLogger(CAttribBitmask.class); + + /** + * Maximum number of characters in a line before linebreak (see {@link + * #getText(int)}). + */ + private static final int MAX_CHARS_PER_LINE = 35; // 50 + + /** Names of the bitmask-entries. */ + private final String[] bitName; + + /** Maximum possible value. */ + private final int maxvalue; + + /** Number of bitmask entries (not counting zero). */ + private final int number; + + /** + * Constructor of a bitmask from XML element. + * @param xpath XPath for XPath evaluation + * @param bitmasksElement xml bitmask element + * @throws XPathExpressionException in case of XPath evaluation errors + */ + public CAttribBitmask(final XPath xpath, final Element bitmasksElement) throws XPathExpressionException { + final NodeListIterator<Element> entries = new NodeListIterator<Element>(xpath, bitmasksElement, "bmentry|entry"); + number = entries.size(); + bitName = new String[number + 1]; + maxvalue = (1 << (bitName.length + 1)) - 1; + bitName[0] = "<none>"; + for (final Element elem : entries) { + bitName[Integer.parseInt(elem.getAttribute("bit")) + 1] = elem.getAttribute("name"); + } + } + + /** + * Check whether the given bit-index is an active bit in the bitmask. + * @param index index of the bit to check (range from 1-'number') + * @param mask bitmask to check against + * @return <code>true</code> if the bit is active in mask, otherwise + * <code>false</code> + */ + private static boolean isActive(final int index, final int mask) { + final int bit = 1 << (index - 1); + return (mask & bit) == bit; + } + + /** + * Generate the text to be displayed for a given bitmask value. + * @param value bitmask value + * @return <code>String</code> with all entries belonging to the bitmask + */ + public String getText(final int value) { + if (value <= 0) { + return bitName[0]; + } + + // value too big? + if (value > maxvalue) { + log.warn("bitmask value " + value + " is too big."); + } + + final StringBuilder sb = new StringBuilder(); + boolean notFirst = false; + int linelength = 0; + for (int i = 1; i < bitName.length; i++) { + if (isActive(i, value)) { + if (notFirst) { + if (linelength + bitName[i].length() + 1 > MAX_CHARS_PER_LINE) { + sb.append(",\n"); + linelength = 0; + } else { + sb.append(", "); + linelength += 2; + } + } + linelength += bitName[i].length(); + sb.append(bitName[i]); + notFirst = true; + } + } + + return sb.toString(); + } + + /** + * Open a popup frame to select bitmask-entries via chooseboxes. + * @param parentComponent the parent component of this dialog + * @param guiAttr Bitmask attribute to update + * @return Integer with new value or <code>null</code> if the user cancelled the dialog + */ + @Nullable public Integer showBitmaskDialog(final Component parentComponent, final AbstractGameObjectAttributesDialog.BitmaskAttrib guiAttr) { + final String title = "Choose " + guiAttr.ref.getNameNew().substring(0, 1).toUpperCase() + guiAttr.ref.getNameNew().substring(1); + final JPanel gridPanel = new JPanel(new GridLayout(0, 2, 3, 3)); + final JCheckBox[] checkbox = new JCheckBox[number]; + for (int i = 0; i < number; i++) { + checkbox[i] = new JCheckBox(bitName[i + 1]); + checkbox[i].setSelected(isActive(i + 1, guiAttr.getValue())); + gridPanel.add(checkbox[i]); + } + if (JOptionPane.showConfirmDialog(parentComponent, gridPanel, title, JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE) == JOptionPane.OK_OPTION) { + int newValue = 0; + for (int i = 0; i < number; i++) { + if (checkbox[i].isSelected()) { + newValue |= 1 << i; + } + } + return newValue; + } + return null; + } + +} // class CAttribBitmask Property changes on: trunk/src/app/net/sf/gridarta/CAttribBitmask.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: trunk/src/app/net/sf/gridarta/gui/AbstractGameObjectAttributesDialog.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/AbstractGameObjectAttributesDialog.java 2007-01-01 22:32:20 UTC (rev 1366) +++ trunk/src/app/net/sf/gridarta/gui/AbstractGameObjectAttributesDialog.java 2007-01-01 23:01:17 UTC (rev 1367) @@ -17,6 +17,8 @@ import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.JTextField; +import javax.swing.text.JTextComponent; +import net.sf.gridarta.CAttribBitmask; import net.sf.gridarta.CFArchAttrib; import net.sf.gridarta.gameobject.GameObject; import net.sf.gridarta.gameobject.NamedObject; @@ -71,6 +73,46 @@ } // class DialogAttrib + /** DialogAttrib for types with bitmasks to choose from. */ + public static final class BitmaskAttrib extends DialogAttrib<JTextComponent> { + + /** Active bitmask value. */ + private int value; + + /** Reference to the bitmask data. */ + public CAttribBitmask bitmask; + + /** + * Create a BitmaskAttrib. + * @param ref reference to the attribute data + */ + public BitmaskAttrib(final CFArchAttrib ref) { + super(ref); + } + + /** + * Get the active bitmask value. + * @return active bitmask value + */ + public int getValue() { + return value; + } + + /** + * Set the active bitmask value. + * @param value new active bitmask value + */ + public void setValue(final int value) { + this.value = value; + if (bitmask != null) { + input.setText(bitmask.getText(value)); + } else { + System.err.println("null bitmask"); + } + } + + } // class BitmaskAttrib + /** ActionListener for help-buttons. */ public final class HelpActionListener implements ActionListener { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2007-01-01 23:07:10
|
Revision: 1368 http://svn.sourceforge.net/gridarta/?rev=1368&view=rev Author: christianhujer Date: 2007-01-01 15:07:10 -0800 (Mon, 01 Jan 2007) Log Message: ----------- Some unification to CFTreasureListTree. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CFTreasureListTree.java trunk/daimonin/src/daieditor/CFTreasureListTree.java Modified: trunk/crossfire/src/cfeditor/CFTreasureListTree.java =================================================================== --- trunk/crossfire/src/cfeditor/CFTreasureListTree.java 2007-01-01 23:01:17 UTC (rev 1367) +++ trunk/crossfire/src/cfeditor/CFTreasureListTree.java 2007-01-01 23:07:10 UTC (rev 1368) @@ -732,8 +732,9 @@ public TreasureObj getTreasureObj() { return content; } - } + } // class TreasureTreeNode + /** * Subclass: UserObject (= content object) for nodes in the CFTreasureListTree * These can be either treasurelists (containers), arches, or yes/no containers. @@ -834,8 +835,9 @@ public String getName() { return name; } - } + } // class TreasureObj + /** * This cell renderer is responsible for drawing the treasure-object * cells in the JTree. @@ -947,6 +949,7 @@ return this; } + } // class TreasureCellRenderer } // class CFTreasureListTree Modified: trunk/daimonin/src/daieditor/CFTreasureListTree.java =================================================================== --- trunk/daimonin/src/daieditor/CFTreasureListTree.java 2007-01-01 23:01:17 UTC (rev 1367) +++ trunk/daimonin/src/daieditor/CFTreasureListTree.java 2007-01-01 23:07:10 UTC (rev 1368) @@ -379,7 +379,6 @@ * @param needLink List containing all sub-treasurelist nodes which need linking * @throws IOException in case of I/O problems reading from <var>reader</var>. */ - @SuppressWarnings({"LiteralAsArgToStringEquals"}) private void readInsideList(final TreasureTreeNode parentNode, final BufferedReader reader, final List<TreasureTreeNode> needLink) throws IOException { TreasureTreeNode node = null; @@ -407,6 +406,8 @@ } insideArch = true; + } else { + errorLog.append("in list ").append(parentNode.getTreasureObj().getName()).append(": unknown line:\n\"").append(line).append("\"\n"); } } else { // reading inside an arch-section @@ -454,6 +455,8 @@ // parse this subtree readInsideList(subNode, reader, needLink); + } else { + errorLog.append("in list ").append(parentNode.getTreasureObj().getName()).append(", arch ").append(node.getTreasureObj().getName()).append(": unexpected line:\n\"").append(line).append("\"\n"); } } } @@ -819,6 +822,10 @@ magic = value; } + public int getMagic() { + return magic; + } + public void setType(final int value) { type = value; } @@ -908,7 +915,7 @@ setForeground(Color.gray); setIcon(noIcon); } else if (content.getType() == TreasureObj.TREASURE_LIST) { - if ("none".equalsIgnoreCase(content.getName())) { + if (content.getName().equalsIgnoreCase("none")) { setIcon(null); setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0)); } else { @@ -916,7 +923,7 @@ setIcon(tlistIcon); } } else if (content.getType() == TreasureObj.TREASUREONE_LIST) { - if ("none".equalsIgnoreCase(content.getName())) { + if (content.getName().equalsIgnoreCase("none")) { setIcon(null); setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0)); } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2007-01-01 23:37:23
|
Revision: 1369 http://svn.sourceforge.net/gridarta/?rev=1369&view=rev Author: christianhujer Date: 2007-01-01 15:37:24 -0800 (Mon, 01 Jan 2007) Log Message: ----------- Added TODOs: it's not nice that CFTreasureListTree extends JTree. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CFTreasureListTree.java trunk/daimonin/src/daieditor/CFTreasureListTree.java Modified: trunk/crossfire/src/cfeditor/CFTreasureListTree.java =================================================================== --- trunk/crossfire/src/cfeditor/CFTreasureListTree.java 2007-01-01 23:07:10 UTC (rev 1368) +++ trunk/crossfire/src/cfeditor/CFTreasureListTree.java 2007-01-01 23:37:24 UTC (rev 1369) @@ -68,6 +68,7 @@ * The CFTreasureListTree class fully manages treasurelists. * CF datafile "treasures" gets parsed into a JTree structure. * @author Andreas Vogl + * @todo don't extend JTree, instead create a proper model */ public final class CFTreasureListTree extends JTree { Modified: trunk/daimonin/src/daieditor/CFTreasureListTree.java =================================================================== --- trunk/daimonin/src/daieditor/CFTreasureListTree.java 2007-01-01 23:07:10 UTC (rev 1368) +++ trunk/daimonin/src/daieditor/CFTreasureListTree.java 2007-01-01 23:37:24 UTC (rev 1369) @@ -70,6 +70,7 @@ * The CFTreasureListTree class fully manages treasurelists. * CF datafile "treasures" gets parsed into a JTree structure. * @author Andreas Vogl + * @todo don't extend JTree, instead create a proper model */ public final class CFTreasureListTree extends JTree { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2007-01-02 01:25:34
|
Revision: 1371 http://svn.sourceforge.net/gridarta/?rev=1371&view=rev Author: christianhujer Date: 2007-01-01 17:25:34 -0800 (Mon, 01 Jan 2007) Log Message: ----------- Some unification of CFArchType. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CFArchType.java trunk/daimonin/src/daieditor/CFArchType.java trunk/src/app/net/sf/gridarta/CFArchType.java Modified: trunk/crossfire/src/cfeditor/CFArchType.java =================================================================== --- trunk/crossfire/src/cfeditor/CFArchType.java 2007-01-01 23:40:36 UTC (rev 1370) +++ trunk/crossfire/src/cfeditor/CFArchType.java 2007-01-02 01:25:34 UTC (rev 1371) @@ -50,35 +50,12 @@ */ public final class CFArchType extends net.sf.gridarta.CFArchType { + /** Logger. */ private static final Logger log = Logger.getLogger(CFArchType.class); /** Action Factory. */ private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); - /** Attribute Element Name. */ - public static final String XML_ATTRIBUTE = "attribute"; - - /** Required Element Name. */ - public static final String XML_REQUIRED = "required"; - - /** Ignore Element Name. */ - public static final String XML_IGNORE = "ignore"; - - /** Import Type Element Name. */ - public static final String XML_IMPORT_TYPE = "import_type"; - - /** Value Element Name. */ - public static final String XML_VALUE = "value"; - - /** Description Element Name. */ - public static final String XML_DESC = "description"; - - /** Use Element Name. */ - public static final String XML_USE = "use"; - - /** Section Element Name. */ - public static final String XML_SECTION = "section"; - private int typenr = 0; // type number of this CF type private String typeName; // type name (artificial) Modified: trunk/daimonin/src/daieditor/CFArchType.java =================================================================== --- trunk/daimonin/src/daieditor/CFArchType.java 2007-01-01 23:40:36 UTC (rev 1370) +++ trunk/daimonin/src/daieditor/CFArchType.java 2007-01-02 01:25:34 UTC (rev 1371) @@ -50,35 +50,12 @@ */ public final class CFArchType extends net.sf.gridarta.CFArchType { + /** Logger. */ private static final Logger log = Logger.getLogger(CFArchType.class); /** Action Factory. */ private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("daieditor"); - /** Attribute Element Name. */ - public static final String XML_ATTRIBUTE = "attribute"; - - /** Required Element Name. */ - public static final String XML_REQUIRED = "required"; - - /** Ignore Element Name. */ - public static final String XML_IGNORE = "ignore"; - - /** Import Type Element Name. */ - public static final String XML_IMPORT_TYPE = "import_type"; - - /** Value Element Name. */ - public static final String XML_VALUE = "value"; - - /** Description Element Name. */ - public static final String XML_DESC = "description"; - - /** Use Element Name. */ - public static final String XML_USE = "use"; - - /** Section Element Name. */ - public static final String XML_SECTION = "section"; - private int typenr = 0; // type number of this CF type private String typeName; // type name (artificial) Modified: trunk/src/app/net/sf/gridarta/CFArchType.java =================================================================== --- trunk/src/app/net/sf/gridarta/CFArchType.java 2007-01-01 23:40:36 UTC (rev 1370) +++ trunk/src/app/net/sf/gridarta/CFArchType.java 2007-01-02 01:25:34 UTC (rev 1371) @@ -1,6 +1,7 @@ package net.sf.gridarta; import net.sf.gridarta.gameobject.GameObject; +import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; /** @@ -10,7 +11,40 @@ */ public abstract class CFArchType { + /** Logger. */ + private static final Logger log = Logger.getLogger(CFArchType.class); + + /** Attribute Element Name. */ + public static final String XML_ATTRIBUTE = "attribute"; + + /** Required Element Name. */ + public static final String XML_REQUIRED = "required"; + + /** Ignore Element Name. */ + public static final String XML_IGNORE = "ignore"; + + /** Import Type Element Name. */ + public static final String XML_IMPORT_TYPE = "import_type"; + + /** Value Element Name. */ + public static final String XML_VALUE = "value"; + + /** Description Element Name. */ + public static final String XML_DESC = "description"; + + /** Use Element Name. */ + public static final String XML_USE = "use"; + + /** Section Element Name. */ + public static final String XML_SECTION = "section"; + /** + * Create a CFArchType. + */ + protected CFArchType() { + } + + /** * Create the documentation to this GameObject-type. * @return the full html-text to be (parsed and) displayed */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2007-01-02 01:28:00
|
Revision: 1372 http://svn.sourceforge.net/gridarta/?rev=1372&view=rev Author: christianhujer Date: 2007-01-01 17:27:56 -0800 (Mon, 01 Jan 2007) Log Message: ----------- Optimized imports. Modified Paths: -------------- trunk/crossfire/src/cfeditor/gui/ArchetypeChooser.java trunk/crossfire/src/cfeditor/gui/map/LevelRenderer.java trunk/daimonin/src/daieditor/gui/ArchetypeChooser.java trunk/daimonin/src/daieditor/gui/map/LevelRenderer.java trunk/src/app/net/sf/gridarta/gui/ArchetypeChooser.java trunk/src/app/net/sf/gridarta/gui/map/LevelRenderer.java Modified: trunk/crossfire/src/cfeditor/gui/ArchetypeChooser.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/ArchetypeChooser.java 2007-01-02 01:25:34 UTC (rev 1371) +++ trunk/crossfire/src/cfeditor/gui/ArchetypeChooser.java 2007-01-02 01:27:56 UTC (rev 1372) @@ -26,30 +26,13 @@ package cfeditor.gui; import cfeditor.CMainControl; -import cfeditor.IGUIConstants; import cfeditor.gameobject.GameObject; -import java.awt.BorderLayout; import java.awt.Component; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.TreeSet; import javax.swing.DefaultListCellRenderer; -import javax.swing.DefaultListModel; -import javax.swing.JComboBox; import javax.swing.JList; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JViewport; -import javax.swing.ListSelectionModel; import javax.swing.ListCellRenderer; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; -import org.apache.log4j.Logger; -import org.jetbrains.annotations.NotNull; -import net.sf.gridarta.CommonConstants; import net.sf.gridarta.MainControl; +import org.apache.log4j.Logger; /** * Panel for Archetypes. Modified: trunk/crossfire/src/cfeditor/gui/map/LevelRenderer.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/map/LevelRenderer.java 2007-01-02 01:25:34 UTC (rev 1371) +++ trunk/crossfire/src/cfeditor/gui/map/LevelRenderer.java 2007-01-02 01:27:56 UTC (rev 1372) @@ -20,11 +20,7 @@ package cfeditor.gui.map; -import java.awt.Point; -import java.awt.image.BufferedImage; import javax.swing.JComponent; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; /** * A level renderer, mainly used as central point to iso and flat renderer. Modified: trunk/daimonin/src/daieditor/gui/ArchetypeChooser.java =================================================================== --- trunk/daimonin/src/daieditor/gui/ArchetypeChooser.java 2007-01-02 01:25:34 UTC (rev 1371) +++ trunk/daimonin/src/daieditor/gui/ArchetypeChooser.java 2007-01-02 01:27:56 UTC (rev 1372) @@ -26,35 +26,16 @@ package daieditor.gui; import daieditor.CMainControl; -import daieditor.IGUIConstants; import daieditor.gameobject.GameObject; -import java.awt.BorderLayout; import java.awt.Component; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.TreeSet; import javax.swing.DefaultListCellRenderer; -import javax.swing.DefaultListModel; import javax.swing.ImageIcon; -import javax.swing.JComboBox; import javax.swing.JList; -import javax.swing.JPanel; import javax.swing.JPopupMenu; -import javax.swing.JScrollPane; -import javax.swing.JViewport; -import javax.swing.ListSelectionModel; import javax.swing.ListCellRenderer; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; -import net.sf.japi.swing.ActionFactory; -import net.sf.gridarta.CommonConstants; import net.sf.gridarta.MainControl; +import net.sf.japi.swing.ActionFactory; import org.apache.log4j.Logger; -import org.jetbrains.annotations.NotNull; /** * Panel for Archetypes. Modified: trunk/daimonin/src/daieditor/gui/map/LevelRenderer.java =================================================================== --- trunk/daimonin/src/daieditor/gui/map/LevelRenderer.java 2007-01-02 01:25:34 UTC (rev 1371) +++ trunk/daimonin/src/daieditor/gui/map/LevelRenderer.java 2007-01-02 01:27:56 UTC (rev 1372) @@ -21,11 +21,7 @@ package daieditor.gui.map; -import java.awt.Point; -import java.awt.image.BufferedImage; import javax.swing.JComponent; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; /** * A level renderer, mainly used as central point to iso and flat renderer. Modified: trunk/src/app/net/sf/gridarta/gui/ArchetypeChooser.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/ArchetypeChooser.java 2007-01-02 01:25:34 UTC (rev 1371) +++ trunk/src/app/net/sf/gridarta/gui/ArchetypeChooser.java 2007-01-02 01:27:56 UTC (rev 1372) @@ -1,24 +1,24 @@ package net.sf.gridarta.gui; -import javax.swing.JPanel; +import java.awt.BorderLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.TreeSet; +import javax.swing.DefaultListModel; import javax.swing.JComboBox; -import javax.swing.DefaultListModel; import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JScrollPane; import javax.swing.JViewport; +import javax.swing.ListCellRenderer; import javax.swing.ListSelectionModel; -import javax.swing.JScrollPane; -import javax.swing.ListCellRenderer; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; +import net.sf.gridarta.CommonConstants; import net.sf.gridarta.MainControl; -import net.sf.gridarta.CommonConstants; import net.sf.gridarta.gameobject.GameObject; -import java.awt.BorderLayout; -import java.awt.event.ActionListener; -import java.awt.event.ActionEvent; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.TreeSet; import org.jetbrains.annotations.NotNull; /** Modified: trunk/src/app/net/sf/gridarta/gui/map/LevelRenderer.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/map/LevelRenderer.java 2007-01-02 01:25:34 UTC (rev 1371) +++ trunk/src/app/net/sf/gridarta/gui/map/LevelRenderer.java 2007-01-02 01:27:56 UTC (rev 1372) @@ -1,9 +1,9 @@ package net.sf.gridarta.gui.map; +import java.awt.Point; import java.awt.image.BufferedImage; -import java.awt.Point; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.annotations.NotNull; /** * Common interface for LevelRenderers. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2007-01-02 08:31:31
|
Revision: 1373 http://svn.sourceforge.net/gridarta/?rev=1373&view=rev Author: christianhujer Date: 2007-01-02 00:31:30 -0800 (Tue, 02 Jan 2007) Log Message: ----------- Some unification of CFArchType. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CFArchType.java trunk/crossfire/src/cfeditor/CFArchTypeList.java trunk/daimonin/src/daieditor/CFArchType.java trunk/daimonin/src/daieditor/CFArchTypeList.java trunk/src/app/net/sf/gridarta/CFArchType.java trunk/src/app/net/sf/gridarta/CFArchTypeList.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/ArchTypeParseException.java Modified: trunk/crossfire/src/cfeditor/CFArchType.java =================================================================== --- trunk/crossfire/src/cfeditor/CFArchType.java 2007-01-02 01:27:56 UTC (rev 1372) +++ trunk/crossfire/src/cfeditor/CFArchType.java 2007-01-02 08:31:30 UTC (rev 1373) @@ -28,6 +28,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import net.sf.gridarta.ArchTypeParseException; import net.sf.gridarta.CFArchAttrib; import net.sf.gridarta.CommonConstants; import net.sf.gridarta.gameobject.ArchAttribType; @@ -58,8 +59,6 @@ private int typenr = 0; // type number of this CF type - private String typeName; // type name (artificial) - private String[] typeAttributes = null; // list of aditional attributes that an object // must have, in order to be of this type: // typeAttributes[0] is attr. name, typeAttributes[1] is attr. value, ... @@ -70,8 +69,6 @@ private String use = null; // notes on usage of this type - private CFArchAttrib[] attr; // list of arch attributes (/array)) - /** * Number of attribute sections. * The number of attribute sections determine the number of tabs to be used. @@ -88,16 +85,8 @@ this.defaultArchType = defaultArchType; // set head of list } - /** - * Loading the data from an xml type element into this CFArchType. - * Since users are expected to edit the type definitions, I have tried - * to design the parser to be somewhat robust and provide error feedback. - * @param root the xml 'type' element which is going to be parsed - * @param tlist archtype list - * @return true if the object was parsed correctly and can be used - * @todo I'm sucking slow, improve me - */ - public boolean load(final Element root, final CFArchTypeList tlist) { + /** {@inheritDoc} */ + @Override public boolean load(final Element root, final net.sf.gridarta.CFArchTypeList tlist) throws ArchTypeParseException { // this vector is used to store a temporare linked list of attributes final List<CFArchAttrib> attrList = new ArrayList<CFArchAttrib>(); @@ -133,7 +122,7 @@ final Attr a1 = elem.getAttributeNode(CFArchAttrib.XML_KEY_ARCH); final Attr a2 = elem.getAttributeNode(XML_VALUE); if (a1 == null || a2 == null) { - log.error("In '" + XML_REQUIRED + "' element of type " + typeName + ": " + XML_ATTRIBUTE + " missing '" + CFArchAttrib.XML_KEY_ARCH + "' or '" + XML_VALUE + "'."); + throw new ArchTypeParseException("In '" + XML_REQUIRED + "' element of type " + typeName + ": " + XML_ATTRIBUTE + " missing '" + CFArchAttrib.XML_KEY_ARCH + "' or '" + XML_VALUE + "'."); } else { tmp.add(a1.getValue().trim()); tmp.add(a2.getValue().trim()); @@ -147,8 +136,7 @@ } } catch (final NumberFormatException e) { // parsing type number failed: - log.error("In " + CommonConstants.TYPEDEF_FILE + ": Type " + typeName + " has invalid type number '" + root.getAttribute("number") + "'."); - return false; + throw new ArchTypeParseException("In " + CommonConstants.TYPEDEF_FILE + ": Type " + typeName + " has invalid type number '" + root.getAttribute("number") + "'."); } // parse 'ignore' elements @@ -158,7 +146,7 @@ for (final Element elem : new NodeListIterator<Element>(signore, XML_ATTRIBUTE)) { final Attr a1 = elem.getAttributeNode(CFArchAttrib.XML_KEY_ARCH); if (a1 == null) { - log.error("In '" + XML_IGNORE + "' section of type " + typeName + ": " + XML_ATTRIBUTE + " missing '" + CFArchAttrib.XML_KEY_ARCH + "'."); + throw new ArchTypeParseException("In '" + XML_IGNORE + "' section of type " + typeName + ": " + XML_ATTRIBUTE + " missing '" + CFArchAttrib.XML_KEY_ARCH + "'."); } else { ignoreTable.put(a1.getValue().trim(), ""); } @@ -168,15 +156,15 @@ for (final Element elem : new NodeListIterator<Element>(signore, "ignore_list")) { final Attr a1 = elem.getAttributeNode("name"); if (a1 == null) { - log.error("In '" + XML_IGNORE + "' section of type " + typeName + ": ignore_list missing 'name'."); + throw new ArchTypeParseException("In '" + XML_IGNORE + "' section of type " + typeName + ": ignore_list missing 'name'."); } else if (tlist.getIgnoreListTable().containsKey(a1.getValue().trim())) { // just copy everything from ignorelist to this ignore section - final List<String> ignlist = tlist.getIgnoreListTable().get(a1.getValue().trim()); + final List<String> ignlist = (List<String>) tlist.getIgnoreListTable().get(a1.getValue().trim()); for (final String ignItem : ignlist) { ignoreTable.put(ignItem, ""); } } else { - log.error("In '" + XML_IGNORE + "' section of type " + typeName + ": ignore_list with name \"" + a1.getValue() + "\" is undefined."); + throw new RuntimeException("In '" + XML_IGNORE + "' section of type " + typeName + ": ignore_list with name \"" + a1.getValue() + "\" is undefined."); } } } @@ -207,7 +195,6 @@ } // now get all children and process them in order: - boolean inSection; for (final Element elem : new NodeListIterator<Element>(root, ELEMENT_NODE)) { // attribute directly in type element if (elem.getNodeName().equalsIgnoreCase(XML_ATTRIBUTE)) { @@ -217,23 +204,18 @@ // attributes in a section if (elem.getNodeName().equalsIgnoreCase(XML_SECTION) && elem.hasChildNodes()) { final Attr a1 = elem.getAttributeNode("name"); - final String section; if (a1 == null) { - log.warn("In " + CommonConstants.TYPEDEF_FILE + ": Type " + typeName + " contains a " + XML_SECTION + " missing 'name'."); - section = "?"; - inSection = false; // we'll treat the attributes as "sectionless" - } else { - // get section name - section = a1.getValue().trim(); - inSection = true; // we are now inside a section - sectionNum++; // increment number of valid sections - secNames.add(section); // tmp. store name + throw new ArchTypeParseException("In " + CommonConstants.TYPEDEF_FILE + ": Type " + typeName + " contains a " + XML_SECTION + " missing 'name'."); } + // get section name + final String section = a1.getValue().trim(); + sectionNum++; // increment number of valid sections + secNames.add(section); // tmp. store name // parse all attributes in the section for (final Element elem2 : new NodeListIterator<Element>(elem, XML_ATTRIBUTE)) { // got an attribute element possibly in a section - parseAttribute(elem2, secNames, inSection, section, attrList, tlist); + parseAttribute(elem2, secNames, true, section, attrList, tlist); } } } @@ -264,8 +246,8 @@ int importNum = 0; if (importName != null) { // search through all known types, looking for import type - CFArchType impType = null; - for (final CFArchType archType : tlist) { + net.sf.gridarta.CFArchType impType = null; + for (final net.sf.gridarta.CFArchType archType : (Iterable<net.sf.gridarta.CFArchType>) tlist) { if (archType == this) { continue; } @@ -300,8 +282,7 @@ } } } else { - log.error("Syntax Error in file '" + CommonConstants.TYPEDEF_FILE + "' (" + typeName + "):"); - log.error(" import type \"" + importName + "\" not found!"); + throw new ArchTypeParseException("Syntax Error in file '" + CommonConstants.TYPEDEF_FILE + "' (" + typeName + "):\n import type \"" + importName + "\" not found!"); } } @@ -345,7 +326,7 @@ * @param attrList linked list of attributes * @param tlist arch type list */ - private void parseAttribute(final Element elem, final List<String> secNames, final boolean inSection, final String section, final List<CFArchAttrib> attrList, final CFArchTypeList tlist) { + private void parseAttribute(final Element elem, final List<String> secNames, final boolean inSection, final String section, final List<CFArchAttrib> attrList, final net.sf.gridarta.CFArchTypeList tlist) { // create new instance final CFArchAttrib attrib = new CFArchAttrib(); Modified: trunk/crossfire/src/cfeditor/CFArchTypeList.java =================================================================== --- trunk/crossfire/src/cfeditor/CFArchTypeList.java 2007-01-02 01:27:56 UTC (rev 1372) +++ trunk/crossfire/src/cfeditor/CFArchTypeList.java 2007-01-02 08:31:30 UTC (rev 1373) @@ -33,6 +33,7 @@ import java.util.Map; import javax.xml.parsers.ParserConfigurationException; import javax.xml.xpath.XPathExpressionException; +import net.sf.gridarta.ArchTypeParseException; import net.sf.gridarta.CAttribBitmask; import net.sf.gridarta.CFArchAttrib; import net.sf.gridarta.CommonConstants; @@ -156,7 +157,7 @@ } } - @Override protected void parseDefaultType(final Element root) { + @Override protected void parseDefaultType(final Element root) throws ArchTypeParseException { // parse default type final Element el = getFirstChild(root, "default_type"); if (el == null) { @@ -166,7 +167,7 @@ } } - @Override protected void parseTypes(final Element root) { + @Override protected void parseTypes(final Element root) throws ArchTypeParseException { // parse all type elements for (final Element elem : new NodeListIterator<Element>(root, "type")) { if (!"no".equals(elem.getAttribute("available"))) { Modified: trunk/daimonin/src/daieditor/CFArchType.java =================================================================== --- trunk/daimonin/src/daieditor/CFArchType.java 2007-01-02 01:27:56 UTC (rev 1372) +++ trunk/daimonin/src/daieditor/CFArchType.java 2007-01-02 08:31:30 UTC (rev 1373) @@ -28,6 +28,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import net.sf.gridarta.ArchTypeParseException; import net.sf.gridarta.CFArchAttrib; import net.sf.gridarta.CommonConstants; import net.sf.gridarta.gameobject.ArchAttribType; @@ -58,8 +59,6 @@ private int typenr = 0; // type number of this CF type - private String typeName; // type name (artificial) - private String[] typeAttributes = null; // list of aditional attributes that an object // must have, in order to be of this type: // typeAttributes[0] is attr. name, typeAttributes[1] is attr. value, ... @@ -70,8 +69,6 @@ private String use = null; // notes on usage of this type - private CFArchAttrib[] attr; // list of arch attributes (/array)) - /** * Number of attribute sections. * The number of attribute sections determine the number of tabs to be used. @@ -88,16 +85,8 @@ this.defaultArchType = defaultArchType; // set head of list } - /** - * Loading the data from an xml type element into this CFArchType. - * Since users are expected to edit the type definitions, I have tried - * to design the parser to be somewhat robust and provide error feedback. - * @param root the xml 'type' element which is going to be parsed - * @param tlist archtype list - * @return true if the object was parsed correctly and can be used - * @todo I'm sucking slow, improve me - */ - public boolean load(final Element root, final CFArchTypeList tlist) { + /** {@inheritDoc} */ + @Override public boolean load(final Element root, final net.sf.gridarta.CFArchTypeList tlist) throws ArchTypeParseException { // this vector is used to store a temporare linked list of attributes final List<CFArchAttrib> attrList = new ArrayList<CFArchAttrib>(); @@ -133,7 +122,7 @@ final Attr a1 = elem.getAttributeNode(CFArchAttrib.XML_KEY_ARCH); final Attr a2 = elem.getAttributeNode(XML_VALUE); if (a1 == null || a2 == null) { - throw new RuntimeException("In '" + XML_REQUIRED + "' element of type " + typeName + ": " + XML_ATTRIBUTE + " missing '" + CFArchAttrib.XML_KEY_ARCH + "' or '" + XML_VALUE + "'."); + throw new ArchTypeParseException("In '" + XML_REQUIRED + "' element of type " + typeName + ": " + XML_ATTRIBUTE + " missing '" + CFArchAttrib.XML_KEY_ARCH + "' or '" + XML_VALUE + "'."); } else { tmp.add(a1.getValue().trim()); tmp.add(a2.getValue().trim()); @@ -147,7 +136,7 @@ } } catch (final NumberFormatException e) { // parsing type number failed: - throw new RuntimeException("In " + CommonConstants.TYPEDEF_FILE + ": Type " + typeName + " has invalid type number '" + root.getAttribute("number") + "'."); + throw new ArchTypeParseException("In " + CommonConstants.TYPEDEF_FILE + ": Type " + typeName + " has invalid type number '" + root.getAttribute("number") + "'."); } // parse 'ignore' elements @@ -157,7 +146,7 @@ for (final Element elem : new NodeListIterator<Element>(signore, XML_ATTRIBUTE)) { final Attr a1 = elem.getAttributeNode(CFArchAttrib.XML_KEY_ARCH); if (a1 == null) { - throw new RuntimeException("In '" + XML_IGNORE + "' section of type " + typeName + ": " + XML_ATTRIBUTE + " missing '" + CFArchAttrib.XML_KEY_ARCH + "'."); + throw new ArchTypeParseException("In '" + XML_IGNORE + "' section of type " + typeName + ": " + XML_ATTRIBUTE + " missing '" + CFArchAttrib.XML_KEY_ARCH + "'."); } else { ignoreTable.put(a1.getValue().trim(), ""); } @@ -167,10 +156,10 @@ for (final Element elem : new NodeListIterator<Element>(signore, "ignore_list")) { final Attr a1 = elem.getAttributeNode("name"); if (a1 == null) { - throw new RuntimeException("In '" + XML_IGNORE + "' section of type " + typeName + ": ignore_list missing 'name'."); + throw new ArchTypeParseException("In '" + XML_IGNORE + "' section of type " + typeName + ": ignore_list missing 'name'."); } else if (tlist.getIgnoreListTable().containsKey(a1.getValue().trim())) { // just copy everything from ignorelist to this ignore section - final List<String> ignlist = tlist.getIgnoreListTable().get(a1.getValue().trim()); + final List<String> ignlist = (List<String>) tlist.getIgnoreListTable().get(a1.getValue().trim()); for (final String ignItem : ignlist) { ignoreTable.put(ignItem, ""); } @@ -216,8 +205,9 @@ if (elem.getNodeName().equalsIgnoreCase(XML_SECTION) && elem.hasChildNodes()) { final Attr a1 = elem.getAttributeNode("name"); if (a1 == null) { - throw new RuntimeException("In " + CommonConstants.TYPEDEF_FILE + ": Type " + typeName + " contains a " + XML_SECTION + " missing 'name'."); - }// get section name + throw new ArchTypeParseException("In " + CommonConstants.TYPEDEF_FILE + ": Type " + typeName + " contains a " + XML_SECTION + " missing 'name'."); + } + // get section name final String section = a1.getValue().trim(); sectionNum++; // increment number of valid sections secNames.add(section); // tmp. store name @@ -256,8 +246,8 @@ int importNum = 0; if (importName != null) { // search through all known types, looking for import type - CFArchType impType = null; - for (final CFArchType archType : tlist) { + net.sf.gridarta.CFArchType impType = null; + for (final net.sf.gridarta.CFArchType archType : (Iterable<net.sf.gridarta.CFArchType>) tlist) { if (archType == this) { continue; } @@ -292,7 +282,7 @@ } } } else { - throw new RuntimeException("Syntax Error in file '" + CommonConstants.TYPEDEF_FILE + "' (" + typeName + "):\n import type \"" + importName + "\" not found!"); + throw new ArchTypeParseException("Syntax Error in file '" + CommonConstants.TYPEDEF_FILE + "' (" + typeName + "):\n import type \"" + importName + "\" not found!"); } } @@ -336,7 +326,7 @@ * @param attrList linked list of attributes * @param tlist arch type list */ - private void parseAttribute(final Element elem, final List<String> secNames, final boolean inSection, final String section, final List<CFArchAttrib> attrList, final CFArchTypeList tlist) { + private void parseAttribute(final Element elem, final List<String> secNames, final boolean inSection, final String section, final List<CFArchAttrib> attrList, final net.sf.gridarta.CFArchTypeList tlist) { // create new instance final CFArchAttrib attrib = new CFArchAttrib(); Modified: trunk/daimonin/src/daieditor/CFArchTypeList.java =================================================================== --- trunk/daimonin/src/daieditor/CFArchTypeList.java 2007-01-02 01:27:56 UTC (rev 1372) +++ trunk/daimonin/src/daieditor/CFArchTypeList.java 2007-01-02 08:31:30 UTC (rev 1373) @@ -36,6 +36,7 @@ import java.util.Map; import javax.xml.parsers.ParserConfigurationException; import javax.xml.xpath.XPathExpressionException; +import net.sf.gridarta.ArchTypeParseException; import net.sf.gridarta.CAttribBitmask; import net.sf.gridarta.CFArchAttrib; import net.sf.gridarta.CommonConstants; @@ -164,7 +165,7 @@ } } - @Override protected void parseDefaultType(final Element root) { + @Override protected void parseDefaultType(final Element root) throws ArchTypeParseException { // parse default type final Element el = getFirstChild(root, "default_type"); if (el == null) { @@ -174,7 +175,7 @@ } } - @Override protected void parseTypes(final Element root) { + @Override protected void parseTypes(final Element root) throws ArchTypeParseException { // parse all type elements for (final Element elem : new NodeListIterator<Element>(root, "type")) { if (!"no".equals(elem.getAttribute("available"))) { Added: trunk/src/app/net/sf/gridarta/ArchTypeParseException.java =================================================================== --- trunk/src/app/net/sf/gridarta/ArchTypeParseException.java (rev 0) +++ trunk/src/app/net/sf/gridarta/ArchTypeParseException.java 2007-01-02 08:31:30 UTC (rev 1373) @@ -0,0 +1,26 @@ +package net.sf.gridarta; + +import java.io.IOException; + +/** + * Thrown when parsing a CFArchType failed. + * @author <a href="mailto:ch...@ri...">Christian Hujer</a> + */ +public class ArchTypeParseException extends IOException { + + /** + * Create an ArchTypeParseException. + */ + public ArchTypeParseException() { + super(); + } + + /** + * Create an ArchTypeParseException. + * @param s The detail message. + */ + public ArchTypeParseException(final String s) { + super(s); + } + +} // class ArchTypeParseException Property changes on: trunk/src/app/net/sf/gridarta/ArchTypeParseException.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + LF Modified: trunk/src/app/net/sf/gridarta/CFArchType.java =================================================================== --- trunk/src/app/net/sf/gridarta/CFArchType.java 2007-01-02 01:27:56 UTC (rev 1372) +++ trunk/src/app/net/sf/gridarta/CFArchType.java 2007-01-02 08:31:30 UTC (rev 1373) @@ -3,6 +3,7 @@ import net.sf.gridarta.gameobject.GameObject; import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; +import org.w3c.dom.Element; /** * Common base class for CFArchType. @@ -38,13 +39,33 @@ /** Section Element Name. */ public static final String XML_SECTION = "section"; + /** Type name (artificial). */ + public String typeName; + /** + * List of Arch Attributes (array). + */ + public CFArchAttrib[] attr; + + /** * Create a CFArchType. */ protected CFArchType() { } /** + * Loading the data from an xml type element into this CFArchType. + * Since users are expected to edit the type definitions, I have tried + * to design the parser to be somewhat robust and provide error feedback. + * @param root the xml 'type' element which is going to be parsed + * @param tlist archtype list + * @return true if the object was parsed correctly and can be used + * @throws ArchTypeParseException In case <var>root</var> is malformed or contains bogus data. + * @todo I'm sucking slow, improve me + */ + public abstract boolean load(final Element root, final CFArchTypeList tlist) throws ArchTypeParseException; + + /** * Create the documentation to this GameObject-type. * @return the full html-text to be (parsed and) displayed */ Modified: trunk/src/app/net/sf/gridarta/CFArchTypeList.java =================================================================== --- trunk/src/app/net/sf/gridarta/CFArchTypeList.java 2007-01-02 01:27:56 UTC (rev 1372) +++ trunk/src/app/net/sf/gridarta/CFArchTypeList.java 2007-01-02 08:31:30 UTC (rev 1373) @@ -178,9 +178,9 @@ protected abstract void parseIgnoreLists(final Element root) throws XPathExpressionException; - protected abstract void parseDefaultType(final Element root) throws XPathExpressionException; + protected abstract void parseDefaultType(final Element root) throws XPathExpressionException, ArchTypeParseException; - protected abstract void parseTypes(final Element root) throws XPathExpressionException; + protected abstract void parseTypes(final Element root) throws XPathExpressionException, ArchTypeParseException; /** * Return the ignore list table which contains all definitions of ignore lists for arch attributes. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2007-01-02 08:54:22
|
Revision: 1374 http://svn.sourceforge.net/gridarta/?rev=1374&view=rev Author: christianhujer Date: 2007-01-02 00:54:23 -0800 (Tue, 02 Jan 2007) Log Message: ----------- Replaced CFArchType with unified version. Modified Paths: -------------- trunk/crossfire/src/cfeditor/CFArchTypeList.java trunk/crossfire/src/cfeditor/gameobject/GameObject.java trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java trunk/crossfire/src/cfeditor/gui/ObjectChoiceDisplay.java trunk/daimonin/src/daieditor/CFArchTypeList.java trunk/daimonin/src/daieditor/gameobject/GameObject.java trunk/daimonin/src/daieditor/gui/GameObjectAttributesDialog.java trunk/daimonin/src/daieditor/gui/ObjectChoiceDisplay.java trunk/src/app/net/sf/gridarta/CFArchType.java Removed Paths: ------------- trunk/crossfire/src/cfeditor/CFArchType.java trunk/daimonin/src/daieditor/CFArchType.java Deleted: trunk/crossfire/src/cfeditor/CFArchType.java =================================================================== --- trunk/crossfire/src/cfeditor/CFArchType.java 2007-01-02 08:31:30 UTC (rev 1373) +++ trunk/crossfire/src/cfeditor/CFArchType.java 2007-01-02 08:54:23 UTC (rev 1374) @@ -1,439 +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 java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import net.sf.gridarta.ArchTypeParseException; -import net.sf.gridarta.CFArchAttrib; -import net.sf.gridarta.CommonConstants; -import net.sf.gridarta.gameobject.ArchAttribType; -import net.sf.gridarta.gameobject.GameObject; -import net.sf.japi.swing.ActionFactory; -import net.sf.japi.xml.NodeListIterator; -import static net.sf.japi.xml.NodeListIterator.getFirstChild; -import org.apache.log4j.Logger; -import org.jetbrains.annotations.NotNull; -import org.w3c.dom.Attr; -import org.w3c.dom.Element; -import static org.w3c.dom.Node.ELEMENT_NODE; - -/** - * Contains the data of one Crossfire Object-Type. - * The data is read from a definitions file called 'types.txt'. - * It is mainly used as info-base for the arch-attribute GUI. - * @author <a href="mailto:and...@gm...">Andreas Vogl</a> - * @author <a href="mailto:ch...@ri...">Christian Hujer</a> - */ -public final class CFArchType extends net.sf.gridarta.CFArchType { - - /** Logger. */ - private static final Logger log = Logger.getLogger(CFArchType.class); - - /** Action Factory. */ - private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("cfeditor"); - - private int typenr = 0; // type number of this CF type - - private String[] typeAttributes = null; // list of aditional attributes that an object - // must have, in order to be of this type: - // typeAttributes[0] is attr. name, typeAttributes[1] is attr. value, ... - - private final CFArchType defaultArchType; // contains default attributes - - private String desc = null; // descrption of this type - - private String use = null; // notes on usage of this type - - /** - * Number of attribute sections. - * The number of attribute sections determine the number of tabs to be used. - */ - private int sectionNum; - - /** - * Constructor. - * @param defaultArchType default archetype - */ - public CFArchType(final CFArchType defaultArchType) { - typeName = ""; - sectionNum = 2; // there's always the "general" and "special" sections (even if empty) - this.defaultArchType = defaultArchType; // set head of list - } - - /** {@inheritDoc} */ - @Override public boolean load(final Element root, final net.sf.gridarta.CFArchTypeList tlist) throws ArchTypeParseException { - // this vector is used to store a temporare linked list of attributes - final List<CFArchAttrib> attrList = new ArrayList<CFArchAttrib>(); - - // for internal section handling: - final List<String> secNames = new ArrayList<String>(); // list of section names - final Map<String, String> ignoreTable = new HashMap<String, String>(); // ignore list - - if (root.getNodeName().equalsIgnoreCase("default_type")) { - // special case: default type (this one contains the default attribs) - typenr = -1; - typeName = "default"; - - if (log.isDebugEnabled()) { - log.debug("type: default"); - } - } else { - try { - // parse the type name - typeName = root.getAttribute("name").trim(); - - // parse the type number - typenr = Integer.parseInt(root.getAttribute("number").trim()); - - if (log.isDebugEnabled()) { - log.debug("reading type: " + typeName + ", " + typenr); - } - - // parse 'required' attributes - final Element required = getFirstChild(root, XML_REQUIRED); - if (required != null) { - final List<String> tmp = new ArrayList<String>(); - for (final Element elem : new NodeListIterator<Element>(required, XML_ATTRIBUTE)) { - final Attr a1 = elem.getAttributeNode(CFArchAttrib.XML_KEY_ARCH); - final Attr a2 = elem.getAttributeNode(XML_VALUE); - if (a1 == null || a2 == null) { - throw new ArchTypeParseException("In '" + XML_REQUIRED + "' element of type " + typeName + ": " + XML_ATTRIBUTE + " missing '" + CFArchAttrib.XML_KEY_ARCH + "' or '" + XML_VALUE + "'."); - } else { - tmp.add(a1.getValue().trim()); - tmp.add(a2.getValue().trim()); - } - } - - // create array and copy vector content into the array: (key1, value1, key2, value2, ...) - if (!tmp.isEmpty()) { - typeAttributes = tmp.toArray(new String[tmp.size()]); - } - } - } catch (final NumberFormatException e) { - // parsing type number failed: - throw new ArchTypeParseException("In " + CommonConstants.TYPEDEF_FILE + ": Type " + typeName + " has invalid type number '" + root.getAttribute("number") + "'."); - } - - // parse 'ignore' elements - final Element signore = getFirstChild(root, XML_IGNORE); - if (signore != null) { - // load all attributes in the ignore section - for (final Element elem : new NodeListIterator<Element>(signore, XML_ATTRIBUTE)) { - final Attr a1 = elem.getAttributeNode(CFArchAttrib.XML_KEY_ARCH); - if (a1 == null) { - throw new ArchTypeParseException("In '" + XML_IGNORE + "' section of type " + typeName + ": " + XML_ATTRIBUTE + " missing '" + CFArchAttrib.XML_KEY_ARCH + "'."); - } else { - ignoreTable.put(a1.getValue().trim(), ""); - } - } - - // load attributes from ignore lists - for (final Element elem : new NodeListIterator<Element>(signore, "ignore_list")) { - final Attr a1 = elem.getAttributeNode("name"); - if (a1 == null) { - throw new ArchTypeParseException("In '" + XML_IGNORE + "' section of type " + typeName + ": ignore_list missing 'name'."); - } else if (tlist.getIgnoreListTable().containsKey(a1.getValue().trim())) { - // just copy everything from ignorelist to this ignore section - final List<String> ignlist = (List<String>) tlist.getIgnoreListTable().get(a1.getValue().trim()); - for (final String ignItem : ignlist) { - ignoreTable.put(ignItem, ""); - } - } else { - throw new RuntimeException("In '" + XML_IGNORE + "' section of type " + typeName + ": ignore_list with name \"" + a1.getValue() + "\" is undefined."); - } - } - } - } - - String importName = null; - { - // load description - Element elem; - if ((elem = getFirstChild(root, XML_DESC)) != null) { - desc = elem.getTextContent().trim(); - } - - // load use - if ((elem = getFirstChild(root, XML_USE)) != null) { - use = elem.getTextContent().trim(); - } - - // load import_type - if ((elem = getFirstChild(root, XML_IMPORT_TYPE)) != null) { - final Attr a1 = elem.getAttributeNode("name"); - if (a1 == null) { - throw new RuntimeException("In file '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + " has " + XML_IMPORT_TYPE + " element without 'name'."); - } else { - importName = a1.getValue().trim(); - } - } - } - - // now get all children and process them in order: - for (final Element elem : new NodeListIterator<Element>(root, ELEMENT_NODE)) { - // attribute directly in type element - if (elem.getNodeName().equalsIgnoreCase(XML_ATTRIBUTE)) { - parseAttribute(elem, secNames, false, null, attrList, tlist); - } - - // attributes in a section - if (elem.getNodeName().equalsIgnoreCase(XML_SECTION) && elem.hasChildNodes()) { - final Attr a1 = elem.getAttributeNode("name"); - if (a1 == null) { - throw new ArchTypeParseException("In " + CommonConstants.TYPEDEF_FILE + ": Type " + typeName + " contains a " + XML_SECTION + " missing 'name'."); - } - // get section name - final String section = a1.getValue().trim(); - sectionNum++; // increment number of valid sections - secNames.add(section); // tmp. store name - - // parse all attributes in the section - for (final Element elem2 : new NodeListIterator<Element>(elem, XML_ATTRIBUTE)) { - // got an attribute element possibly in a section - parseAttribute(elem2, secNames, true, section, attrList, tlist); - } - } - } - - // ------ now generate the array of attributes: ------ - // calculate how many attributes we've got - - int j = attrList.size(); - - // don't forget about the default attribs - int numDef = 0; - if (defaultArchType != null && defaultArchType.attr != null && defaultArchType.attr.length > 0) { - // create an array to store the references to the default atrribs: - final CFArchAttrib[] defList = new CFArchAttrib[defaultArchType.attr.length]; - - for (final CFArchAttrib attrib : defaultArchType.attr) { - // add all attributes from the default_type which are not in the ignoreTable - if (!ignoreTable.containsKey(attrib.getNameOld())) { - defList[numDef] = attrib; - j++; - numDef++; - } - } - - // now also count the importet attribs - CFArchAttrib[] importList = null; // imported attribs array - - int importNum = 0; - if (importName != null) { - // search through all known types, looking for import type - net.sf.gridarta.CFArchType impType = null; - for (final net.sf.gridarta.CFArchType archType : (Iterable<net.sf.gridarta.CFArchType>) tlist) { - if (archType == this) { - continue; - } - if (archType.typeName.equalsIgnoreCase(importName)) { - impType = archType; - break; - } - } - - if (impType != null) { - // initialize array to store imported attribs - importList = new CFArchAttrib[impType.attr.length]; - - for (final CFArchAttrib attrib : impType.attr) { - if (!attrib.getSecName().equalsIgnoreCase("general")) { - // import this attrib: - if (!attrib.getSecName().equalsIgnoreCase("general") && !attrib.getSecName().equalsIgnoreCase("special") && !secNames.contains(attrib.getSecName())) { - sectionNum++; // increment number of valid sections - secNames.add(attrib.getSecName()); - } - - importList[importNum] = attrib.getClone(); - - // get section id - final int newId = secNames.indexOf(attrib.getSecName()); - if (newId >= 0) { - importList[importNum].setSecId(newId + 2); - } - - importNum++; - j++; - } - } - } else { - throw new ArchTypeParseException("Syntax Error in file '" + CommonConstants.TYPEDEF_FILE + "' (" + typeName + "):\n import type \"" + importName + "\" not found!"); - } - } - - attr = new CFArchAttrib[j]; // create array of appropriate size - - // first put in the references to the default attribs: - for (int k = numDef; k > 0; k--) { - attr[numDef - k] = defList[numDef - k]; - if (log.isDebugEnabled()) { - log.debug("*** (" + (numDef - k) + ") " + attr[numDef - k].getNameNew()); - } - } - - // next put in the references of imported arches (at end of array) - for (int k = 0; k < importNum; k++) { - attr[j - importNum + k] = importList[k]; - if (log.isDebugEnabled()) { - log.debug("*** (" + (j - importNum + k) + ") " + attr[j - importNum + k].getNameNew()); - } - } - } else { - attr = new CFArchAttrib[j]; // create array of appropriate size - } - - // put the list of the (non-default) CFArchAttribs into an array: - for (int i = 0; numDef < j && i < attrList.size(); numDef++, i++) { - attr[numDef] = attrList.get(i); - } - - return true; // archtype was parsed correctly - } - - /** - * Parse an xml attribute element. If parsing succeeds, the new CFArchAttrib is - * added to the temporare linked list provided by the parameters (see below). - * Assigment of sections to attributes also happens in this method. - * @param elem the xml attribute element - * @param secNames vector storing all section names - * @param inSection true if this attribute belongs to a (custom-defined) section - * @param section name of the section (only relevant if 'inSection'==true) - * @param attrList linked list of attributes - * @param tlist arch type list - */ - private void parseAttribute(final Element elem, final List<String> secNames, final boolean inSection, final String section, final List<CFArchAttrib> attrList, final net.sf.gridarta.CFArchTypeList tlist) { - // create new instance - final CFArchAttrib attrib = new CFArchAttrib(); - - // parse attribute - if (attrib.load(elem, tlist, typeName)) { - // add this attribute to the list: - if (!attrList.isEmpty()) { - attrList.get(attrList.size() - 1).setNext(attrib); - } - attrList.add(attrib); - - // parsing succeeded, now assign this attribute to a section - if (attrib.getDataType() == ArchAttribType.TEXT) { - // text attributes all have their own section - attrib.setSection(sectionNum, attrib.getNameNew()); - sectionNum++; - secNames.add(attrib.getNameNew()); // tmp. store name - } else if (inSection) { - // if the attribute is in a section, so be it: - attrib.setSection(sectionNum - 1, section); - } else if (typenr == -1) { - // default attributes go into the "General" section - attrib.setSection(0, "General"); - } else { - // sectionless stuff goes into the "Special" section - attrib.setSection(1, "Special"); - } - - if (log.isDebugEnabled()) { - final Attr a = elem.getAttributeNode("arch"); - log.debug("attribute " + (a == null ? "null" : a.getValue()) + ", section " + attrib.getSecId() + " = '" + attrib.getSecName() + "'"); - } - } - } - - /** - * Create the documentation to this GameObject-type. - * @return the full html-text to be (parsed and) displayed - */ - @Override public String createHtmlDocu() { - return ACTION_FACTORY.format("arcDoc.htmlText", typeName, desc != null ? desc.trim() : "", use != null ? use.trim() : ""); - } - - public CFArchAttrib[] getAttr() { - return attr; - } - - /** - * Returns number of attribute sections. - * The number of attribute sections determine the number of tabs to be used. - * @return number of attribute sections. - */ - @Override public int getSectionNum() { - return sectionNum; - } - - @Override public int getTypeNr() { - return typenr; - } - - @Override public String getTypeName() { - return typeName; - } - - @Override public String[] getTypeAttr() { - return typeAttributes; - } - - @Override public boolean matches(@NotNull final GameObject gameObject) { - if (getTypeNr() != gameObject.getArchTypNr()) { - return false; - } - - if (getTypeAttr() == null) { - // no type-attributes, so we only compared type-numbers - return true; - } - - // check if all the type-attributes match - final int numArgs = getTypeAttr().length / 2; - - if (log.isDebugEnabled()) { - log.debug("# type: " + getTypeName()); - } - - for (int t = 0, l = numArgs * 2; t < l; t += 2) { - final String attrValue = gameObject.getAttributeString(getTypeAttr()[t]); - - if (log.isDebugEnabled()) { - log.debug(" arch: '" + attrValue + "', type: '" + getTypeAttr()[t + 1] + "'"); - } - - if (!attrValue.equals(getTypeAttr()[t + 1]) && !(getTypeAttr()[t + 1].equals("0") && attrValue.length() == 0)) { - if (log.isDebugEnabled()) { - log.debug("-> attr: " + getTypeAttr()[t] + " NO match"); - } - - return false; - } - - if (log.isDebugEnabled()) { - log.debug("-> attr: " + getTypeAttr()[t] + " YES match"); - } - } - - // we've got a match after all - return true; - } - -} // class CFArchType Modified: trunk/crossfire/src/cfeditor/CFArchTypeList.java =================================================================== --- trunk/crossfire/src/cfeditor/CFArchTypeList.java 2007-01-02 08:31:30 UTC (rev 1373) +++ trunk/crossfire/src/cfeditor/CFArchTypeList.java 2007-01-02 08:54:23 UTC (rev 1374) @@ -36,6 +36,7 @@ import net.sf.gridarta.ArchTypeParseException; import net.sf.gridarta.CAttribBitmask; import net.sf.gridarta.CFArchAttrib; +import net.sf.gridarta.CFArchType; import net.sf.gridarta.CommonConstants; import net.sf.japi.xml.NodeListIterator; import static net.sf.japi.xml.NodeListIterator.getFirstChild; Modified: trunk/crossfire/src/cfeditor/gameobject/GameObject.java =================================================================== --- trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2007-01-02 08:31:30 UTC (rev 1373) +++ trunk/crossfire/src/cfeditor/gameobject/GameObject.java 2007-01-02 08:54:23 UTC (rev 1374) @@ -25,7 +25,6 @@ package cfeditor.gameobject; import cfeditor.AutojoinList; -import cfeditor.CFArchType; import cfeditor.CFArchTypeList; import cfeditor.IGUIConstants; import cfeditor.ScriptArchData; @@ -36,6 +35,7 @@ import java.util.Collections; import java.util.List; import javax.swing.JList; +import net.sf.gridarta.CFArchType; import net.sf.gridarta.gameobject.MultiArchData; import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; Modified: trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java 2007-01-02 08:31:30 UTC (rev 1373) +++ trunk/crossfire/src/cfeditor/gui/GameObjectAttributesDialog.java 2007-01-02 08:54:23 UTC (rev 1374) @@ -24,7 +24,6 @@ package cfeditor.gui; -import cfeditor.CFArchType; import cfeditor.CFArchTypeList; import cfeditor.CFTreasureListTree; import cfeditor.CMainControl; @@ -82,6 +81,7 @@ import javax.swing.text.StyleContext; import net.sf.gridarta.CAttribBitmask; import net.sf.gridarta.CFArchAttrib; +import net.sf.gridarta.CFArchType; import net.sf.gridarta.CommonConstants; import net.sf.gridarta.gameobject.ArchAttribType; import net.sf.gridarta.gameobject.Archetype; Modified: trunk/crossfire/src/cfeditor/gui/ObjectChoiceDisplay.java =================================================================== --- trunk/crossfire/src/cfeditor/gui/ObjectChoiceDisplay.java 2007-01-02 08:31:30 UTC (rev 1373) +++ trunk/crossfire/src/cfeditor/gui/ObjectChoiceDisplay.java 2007-01-02 08:54:23 UTC (rev 1374) @@ -24,7 +24,6 @@ package cfeditor.gui; -import cfeditor.CFArchType; import cfeditor.CMainControl; import cfeditor.ReplaceDialog; import cfeditor.gameobject.GameObject; @@ -33,6 +32,7 @@ import java.awt.GridBagLayout; import javax.swing.JLabel; import javax.swing.JPanel; +import net.sf.gridarta.CFArchType; import net.sf.gridarta.gameobject.Archetype; import org.jetbrains.annotations.Nullable; Deleted: trunk/daimonin/src/daieditor/CFArchType.java =================================================================== --- trunk/daimonin/src/daieditor/CFArchType.java 2007-01-02 08:31:30 UTC (rev 1373) +++ trunk/daimonin/src/daieditor/CFArchType.java 2007-01-02 08:54:23 UTC (rev 1374) @@ -1,439 +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 java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import net.sf.gridarta.ArchTypeParseException; -import net.sf.gridarta.CFArchAttrib; -import net.sf.gridarta.CommonConstants; -import net.sf.gridarta.gameobject.ArchAttribType; -import net.sf.gridarta.gameobject.GameObject; -import net.sf.japi.swing.ActionFactory; -import net.sf.japi.xml.NodeListIterator; -import static net.sf.japi.xml.NodeListIterator.getFirstChild; -import org.apache.log4j.Logger; -import org.jetbrains.annotations.NotNull; -import org.w3c.dom.Attr; -import org.w3c.dom.Element; -import static org.w3c.dom.Node.ELEMENT_NODE; - -/** - * Contains the data of one Daimonin Object-Type. - * The data is read from a definitions file called 'types.txt'. - * It is mainly used as info-base for the arch-attribute GUI. - * @author <a href="mailto:and...@gm...">Andreas Vogl</a> - * @author <a href="mailto:ch...@ri...">Christian Hujer</a> - */ -public final class CFArchType extends net.sf.gridarta.CFArchType { - - /** Logger. */ - private static final Logger log = Logger.getLogger(CFArchType.class); - - /** Action Factory. */ - private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("daieditor"); - - private int typenr = 0; // type number of this CF type - - private String[] typeAttributes = null; // list of aditional attributes that an object - // must have, in order to be of this type: - // typeAttributes[0] is attr. name, typeAttributes[1] is attr. value, ... - - private final CFArchType defaultArchType; // contains default attributes - - private String desc = null; // descrption of this type - - private String use = null; // notes on usage of this type - - /** - * Number of attribute sections. - * The number of attribute sections determine the number of tabs to be used. - */ - private int sectionNum; - - /** - * Constructor. - * @param defaultArchType default archetype - */ - public CFArchType(final CFArchType defaultArchType) { - typeName = ""; - sectionNum = 2; // there's always the "general" and "special" sections (even if empty) - this.defaultArchType = defaultArchType; // set head of list - } - - /** {@inheritDoc} */ - @Override public boolean load(final Element root, final net.sf.gridarta.CFArchTypeList tlist) throws ArchTypeParseException { - // this vector is used to store a temporare linked list of attributes - final List<CFArchAttrib> attrList = new ArrayList<CFArchAttrib>(); - - // for internal section handling: - final List<String> secNames = new ArrayList<String>(); // list of section names - final Map<String, String> ignoreTable = new HashMap<String, String>(); // ignore list - - if (root.getNodeName().equalsIgnoreCase("default_type")) { - // special case: default type (this one contains the default attribs) - typenr = -1; - typeName = "default"; - - if (log.isDebugEnabled()) { - log.debug("type: default"); - } - } else { - try { - // parse the type name - typeName = root.getAttribute("name").trim(); - - // parse the type number - typenr = Integer.parseInt(root.getAttribute("number").trim()); - - if (log.isDebugEnabled()) { - log.debug("reading type: " + typeName + ", " + typenr); - } - - // parse 'required' attributes - final Element required = getFirstChild(root, XML_REQUIRED); - if (required != null) { - final List<String> tmp = new ArrayList<String>(); - for (final Element elem : new NodeListIterator<Element>(required, XML_ATTRIBUTE)) { - final Attr a1 = elem.getAttributeNode(CFArchAttrib.XML_KEY_ARCH); - final Attr a2 = elem.getAttributeNode(XML_VALUE); - if (a1 == null || a2 == null) { - throw new ArchTypeParseException("In '" + XML_REQUIRED + "' element of type " + typeName + ": " + XML_ATTRIBUTE + " missing '" + CFArchAttrib.XML_KEY_ARCH + "' or '" + XML_VALUE + "'."); - } else { - tmp.add(a1.getValue().trim()); - tmp.add(a2.getValue().trim()); - } - } - - // create array and copy vector content into the array: (key1, value1, key2, value2, ...) - if (!tmp.isEmpty()) { - typeAttributes = tmp.toArray(new String[tmp.size()]); - } - } - } catch (final NumberFormatException e) { - // parsing type number failed: - throw new ArchTypeParseException("In " + CommonConstants.TYPEDEF_FILE + ": Type " + typeName + " has invalid type number '" + root.getAttribute("number") + "'."); - } - - // parse 'ignore' elements - final Element signore = getFirstChild(root, XML_IGNORE); - if (signore != null) { - // load all attributes in the ignore section - for (final Element elem : new NodeListIterator<Element>(signore, XML_ATTRIBUTE)) { - final Attr a1 = elem.getAttributeNode(CFArchAttrib.XML_KEY_ARCH); - if (a1 == null) { - throw new ArchTypeParseException("In '" + XML_IGNORE + "' section of type " + typeName + ": " + XML_ATTRIBUTE + " missing '" + CFArchAttrib.XML_KEY_ARCH + "'."); - } else { - ignoreTable.put(a1.getValue().trim(), ""); - } - } - - // load attributes from ignore lists - for (final Element elem : new NodeListIterator<Element>(signore, "ignore_list")) { - final Attr a1 = elem.getAttributeNode("name"); - if (a1 == null) { - throw new ArchTypeParseException("In '" + XML_IGNORE + "' section of type " + typeName + ": ignore_list missing 'name'."); - } else if (tlist.getIgnoreListTable().containsKey(a1.getValue().trim())) { - // just copy everything from ignorelist to this ignore section - final List<String> ignlist = (List<String>) tlist.getIgnoreListTable().get(a1.getValue().trim()); - for (final String ignItem : ignlist) { - ignoreTable.put(ignItem, ""); - } - } else { - throw new RuntimeException("In '" + XML_IGNORE + "' section of type " + typeName + ": ignore_list with name \"" + a1.getValue() + "\" is undefined."); - } - } - } - } - - String importName = null; - { - // load description - Element elem; - if ((elem = getFirstChild(root, XML_DESC)) != null) { - desc = elem.getTextContent().trim(); - } - - // load use - if ((elem = getFirstChild(root, XML_USE)) != null) { - use = elem.getTextContent().trim(); - } - - // load import_type - if ((elem = getFirstChild(root, XML_IMPORT_TYPE)) != null) { - final Attr a1 = elem.getAttributeNode("name"); - if (a1 == null) { - throw new RuntimeException("In file '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + " has " + XML_IMPORT_TYPE + " element without 'name'."); - } else { - importName = a1.getValue().trim(); - } - } - } - - // now get all children and process them in order: - for (final Element elem : new NodeListIterator<Element>(root, ELEMENT_NODE)) { - // attribute directly in type element - if (elem.getNodeName().equalsIgnoreCase(XML_ATTRIBUTE)) { - parseAttribute(elem, secNames, false, null, attrList, tlist); - } - - // attributes in a section - if (elem.getNodeName().equalsIgnoreCase(XML_SECTION) && elem.hasChildNodes()) { - final Attr a1 = elem.getAttributeNode("name"); - if (a1 == null) { - throw new ArchTypeParseException("In " + CommonConstants.TYPEDEF_FILE + ": Type " + typeName + " contains a " + XML_SECTION + " missing 'name'."); - } - // get section name - final String section = a1.getValue().trim(); - sectionNum++; // increment number of valid sections - secNames.add(section); // tmp. store name - - // parse all attributes in the section - for (final Element elem2 : new NodeListIterator<Element>(elem, XML_ATTRIBUTE)) { - // got an attribute element possibly in a section - parseAttribute(elem2, secNames, true, section, attrList, tlist); - } - } - } - - // ------ now generate the array of attributes: ------ - // calculate how many attributes we've got - - int j = attrList.size(); - - // don't forget about the default attribs - int numDef = 0; - if (defaultArchType != null && defaultArchType.attr != null && defaultArchType.attr.length > 0) { - // create an array to store the references to the default atrribs: - final CFArchAttrib[] defList = new CFArchAttrib[defaultArchType.attr.length]; - - for (final CFArchAttrib attrib : defaultArchType.attr) { - // add all attributes from the default_type which are not in the ignoreTable - if (!ignoreTable.containsKey(attrib.getNameOld())) { - defList[numDef] = attrib; - j++; - numDef++; - } - } - - // now also count the importet attribs - CFArchAttrib[] importList = null; // imported attribs array - - int importNum = 0; - if (importName != null) { - // search through all known types, looking for import type - net.sf.gridarta.CFArchType impType = null; - for (final net.sf.gridarta.CFArchType archType : (Iterable<net.sf.gridarta.CFArchType>) tlist) { - if (archType == this) { - continue; - } - if (archType.typeName.equalsIgnoreCase(importName)) { - impType = archType; - break; - } - } - - if (impType != null) { - // initialize array to store imported attribs - importList = new CFArchAttrib[impType.attr.length]; - - for (final CFArchAttrib attrib : impType.attr) { - if (!attrib.getSecName().equalsIgnoreCase("general")) { - // import this attrib: - if (!attrib.getSecName().equalsIgnoreCase("general") && !attrib.getSecName().equalsIgnoreCase("special") && !secNames.contains(attrib.getSecName())) { - sectionNum++; // increment number of valid sections - secNames.add(attrib.getSecName()); - } - - importList[importNum] = attrib.getClone(); - - // get section id - final int newId = secNames.indexOf(attrib.getSecName()); - if (newId >= 0) { - importList[importNum].setSecId(newId + 2); - } - - importNum++; - j++; - } - } - } else { - throw new ArchTypeParseException("Syntax Error in file '" + CommonConstants.TYPEDEF_FILE + "' (" + typeName + "):\n import type \"" + importName + "\" not found!"); - } - } - - attr = new CFArchAttrib[j]; // create array of appropriate size - - // first put in the references to the default attribs: - for (int k = numDef; k > 0; k--) { - attr[numDef - k] = defList[numDef - k]; - if (log.isDebugEnabled()) { - log.debug("*** (" + (numDef - k) + ") " + attr[numDef - k].getNameNew()); - } - } - - // next put in the references of imported arches (at end of array) - for (int k = 0; k < importNum; k++) { - attr[j - importNum + k] = importList[k]; - if (log.isDebugEnabled()) { - log.debug("*** (" + (j - importNum + k) + ") " + attr[j - importNum + k].getNameNew()); - } - } - } else { - attr = new CFArchAttrib[j]; // create array of appropriate size - } - - // put the list of the (non-default) CFArchAttribs into an array: - for (int i = 0; numDef < j && i < attrList.size(); numDef++, i++) { - attr[numDef] = attrList.get(i); - } - - return true; // archtype was parsed correctly - } - - /** - * Parse an xml attribute element. If parsing succeeds, the new CFArchAttrib is - * added to the temporare linked list provided by the parameters (see below). - * Assigment of sections to attributes also happens in this method. - * @param elem the xml attribute element - * @param secNames vector storing all section names - * @param inSection true if this attribute belongs to a (custom-defined) section - * @param section name of the section (only relevant if 'inSection'==true) - * @param attrList linked list of attributes - * @param tlist arch type list - */ - private void parseAttribute(final Element elem, final List<String> secNames, final boolean inSection, final String section, final List<CFArchAttrib> attrList, final net.sf.gridarta.CFArchTypeList tlist) { - // create new instance - final CFArchAttrib attrib = new CFArchAttrib(); - - // parse attribute - if (attrib.load(elem, tlist, typeName)) { - // add this attribute to the list: - if (!attrList.isEmpty()) { - attrList.get(attrList.size() - 1).setNext(attrib); - } - attrList.add(attrib); - - // parsing succeeded, now assign this attribute to a section - if (attrib.getDataType() == ArchAttribType.TEXT) { - // text attributes all have their own section - attrib.setSection(sectionNum, attrib.getNameNew()); - sectionNum++; - secNames.add(attrib.getNameNew()); // tmp. store name - } else if (inSection) { - // if the attribute is in a section, so be it: - attrib.setSection(sectionNum - 1, section); - } else if (typenr == -1) { - // default attributes go into the "General" section - attrib.setSection(0, "General"); - } else { - // sectionless stuff goes into the "Special" section - attrib.setSection(1, "Special"); - } - - if (log.isDebugEnabled()) { - final Attr a = elem.getAttributeNode("arch"); - log.debug("attribute " + (a == null ? "null" : a.getValue()) + ", section " + attrib.getSecId() + " = '" + attrib.getSecName() + "'"); - } - } - } - - /** - * Create the documentation to this GameObject-type. - * @return the full html-text to be (parsed and) displayed - */ - @Override public String createHtmlDocu() { - return ACTION_FACTORY.format("arcDoc.htmlText", typeName, desc != null ? desc.trim() : "", use != null ? use.trim() : ""); - } - - public CFArchAttrib[] getAttr() { - return attr; - } - - /** - * Returns number of attribute sections. - * The number of attribute sections determine the number of tabs to be used. - * @return number of attribute sections. - */ - @Override public int getSectionNum() { - return sectionNum; - } - - @Override public int getTypeNr() { - return typenr; - } - - @Override public String getTypeName() { - return typeName; - } - - @Override public String[] getTypeAttr() { - return typeAttributes; - } - - @Override public boolean matches(@NotNull final GameObject gameObject) { - if (getTypeNr() != gameObject.getArchTypNr()) { - return false; - } - - if (getTypeAttr() == null) { - // no type-attributes, so we only compared type-numbers - return true; - } - - // check if all the type-attributes match - final int numArgs = getTypeAttr().length / 2; - - if (log.isDebugEnabled()) { - log.debug("# type: " + getTypeName()); - } - - for (int t = 0, l = numArgs * 2; t < l; t += 2) { - final String attrValue = gameObject.getAttributeString(getTypeAttr()[t]); - - if (log.isDebugEnabled()) { - log.debug(" arch: '" + attrValue + "', type: '" + getTypeAttr()[t + 1] + "'"); - } - - if (!attrValue.equals(getTypeAttr()[t + 1]) && !(getTypeAttr()[t + 1].equals("0") && attrValue.length() == 0)) { - if (log.isDebugEnabled()) { - log.debug("-> attr: " + getTypeAttr()[t] + " NO match"); - } - - return false; - } - - if (log.isDebugEnabled()) { - log.debug("-> attr: " + getTypeAttr()[t] + " YES match"); - } - } - - // we've got a match after all - return true; - } - -} // class CFArchType Modified: trunk/daimonin/src/daieditor/CFArchTypeList.java =================================================================== --- trunk/daimonin/src/daieditor/CFArchTypeList.java 2007-01-02 08:31:30 UTC (rev 1373) +++ trunk/daimonin/src/daieditor/CFArchTypeList.java 2007-01-02 08:54:23 UTC (rev 1374) @@ -39,6 +39,7 @@ import net.sf.gridarta.ArchTypeParseException; import net.sf.gridarta.CAttribBitmask; import net.sf.gridarta.CFArchAttrib; +import net.sf.gridarta.CFArchType; import net.sf.gridarta.CommonConstants; import net.sf.japi.xml.NodeListIterator; import static net.sf.japi.xml.NodeListIterator.getFirstChild; Modified: trunk/daimonin/src/daieditor/gameobject/GameObject.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/GameObject.java 2007-01-02 08:31:30 UTC (rev 1373) +++ trunk/daimonin/src/daieditor/gameobject/GameObject.java 2007-01-02 08:54:23 UTC (rev 1374) @@ -25,7 +25,6 @@ package daieditor.gameobject; -import daieditor.CFArchType; import daieditor.CFArchTypeList; import daieditor.CMainControl; import daieditor.IGUIConstants; @@ -36,6 +35,7 @@ import java.io.Serializable; import javax.swing.ImageIcon; import javax.swing.JList; +import net.sf.gridarta.CFArchType; import net.sf.gridarta.gameobject.GameObjectContainer; import net.sf.gridarta.gameobject.MultiArchData; import org.apache.log4j.Logger; Modified: trunk/daimonin/src/daieditor/gui/GameObjectAttributesDialog.java =================================================================== --- trunk/daimonin/src/daieditor/gui/GameObjectAttributesDialog.java 2007-01-02 08:31:30 UTC (rev 1373) +++ trunk/daimonin/src/daieditor/gui/GameObjectAttributesDialog.java 2007-01-02 08:54:23 UTC (rev 1374) @@ -24,7 +24,6 @@ package daieditor.gui; -import daieditor.CFArchType; import daieditor.CFArchTypeList; import daieditor.CFTreasureListTree; import daieditor.CMainControl; @@ -81,6 +80,7 @@ import javax.swing.text.StyleContext; import net.sf.gridarta.CAttribBitmask; import net.sf.gridarta.CFArchAttrib; +import net.sf.gridarta.CFArchType; import net.sf.gridarta.CommonConstants; import net.sf.gridarta.gameobject.ArchAttribType; import net.sf.gridarta.gameobject.Archetype; Modified: trunk/daimonin/src/daieditor/gui/ObjectChoiceDisplay.java =================================================================== --- trunk/daimonin/src/daieditor/gui/ObjectChoiceDisplay.java 2007-01-02 08:31:30 UTC (rev 1373) +++ trunk/daimonin/src/daieditor/gui/ObjectChoiceDisplay.java 2007-01-02 08:54:23 UTC (rev 1374) @@ -24,7 +24,6 @@ package daieditor.gui; -import daieditor.CFArchType; import daieditor.CMainControl; import daieditor.ReplaceDialog; import daieditor.gameobject.GameObject; @@ -33,6 +32,7 @@ import java.awt.GridBagLayout; import javax.swing.JLabel; import javax.swing.JPanel; +import net.sf.gridarta.CFArchType; import net.sf.gridarta.gameobject.Archetype; import org.jetbrains.annotations.Nullable; Modified: trunk/src/app/net/sf/gridarta/CFArchType.java =================================================================== --- trunk/src/app/net/sf/gridarta/CFArchType.java 2007-01-02 08:31:30 UTC (rev 1373) +++ trunk/src/app/net/sf/gridarta/CFArchType.java 2007-01-02 08:54:23 UTC (rev 1374) @@ -1,20 +1,35 @@ package net.sf.gridarta; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import net.sf.gridarta.gameobject.ArchAttribType; import net.sf.gridarta.gameobject.GameObject; +import net.sf.japi.swing.ActionFactory; +import net.sf.japi.xml.NodeListIterator; import org.apache.log4j.Logger; import org.jetbrains.annotations.NotNull; +import org.w3c.dom.Attr; import org.w3c.dom.Element; +import org.w3c.dom.Node; /** - * Common base class for CFArchType. + * Contains the data of one Gridarta Object-Type. + * The data is read from a definitions file called 'types.xml'. + * It is mainly used as info-base for the arch-attribute GUI. + * @author <a href="mailto:and...@gm...">Andreas Vogl</a> * @author <a href="mailto:ch...@ri...">Christian Hujer</a> * @todo find a better name, eventually ObjectType or ArchetypeType. */ -public abstract class CFArchType { +public class CFArchType { /** Logger. */ private static final Logger log = Logger.getLogger(CFArchType.class); + /** Action Factory. */ + private static final ActionFactory ACTION_FACTORY = ActionFactory.getFactory("net.sf.gridarta"); + /** Attribute Element Name. */ public static final String XML_ATTRIBUTE = "attribute"; @@ -39,18 +54,52 @@ /** Section Element Name. */ public static final String XML_SECTION = "section"; + /** + * Default / parent CFArchType. + */ + public CFArchType defaultArchType; + /** Type name (artificial). */ public String typeName; + /** Type number. */ + public int typenr = 0; + + /** Description. */ + public String desc; + + /** Usage Notes. */ + public String use; + /** + * Number of attribute sections. + * The number of attribute sections determine the number of tabs to be used. + */ + public int sectionNum; + + /** * List of Arch Attributes (array). */ public CFArchAttrib[] attr; /** + * List of additional attriutes that an object must have in order to be of this type. + * The values are paired, even index = attribute name, odd index = attribute value. + * typeAttributes[0] = attribute name of first type attribute. + * typeAttributes[1] = attribute value of first type attribute. + * typeAttributes[2] = attribute name of second type attribute. + * ... + */ + public String[] typeAttributes = null; + + /** * Create a CFArchType. + * @param defaultArchType default archetype */ - protected CFArchType() { + public CFArchType(final CFArchType defaultArchType) { + typeName = ""; + sectionNum = 2; // there's always the "general" and "special" sections (even if empty) + this.defaultArchType = defaultArchType; // set head of list } /** @@ -63,27 +112,354 @@ * @throws ArchTypeParseException In case <var>root</var> is malformed or contains bogus data. * @todo I'm sucking slow, improve me */ - public abstract boolean load(final Element root, final CFArchTypeList tlist) throws ArchTypeParseException; + public boolean load(final Element root, final CFArchTypeList tlist) throws ArchTypeParseException { + // this vector is used to store a temporare linked list of attributes + final List<CFArchAttrib> attrList = new ArrayList<CFArchAttrib>(); + // for internal section handling: + final List<String> secNames = new ArrayList<String>(); // list of section names + final Map<String, String> ignoreTable = new HashMap<String, String>(); // ignore list + + if (root.getNodeName().equalsIgnoreCase("default_type")) { + // special case: default type (this one contains the default attribs) + typenr = -1; + typeName = "default"; + + if (log.isDebugEnabled()) { + log.debug("type: default"); + } + } else { + try { + // parse the type name + typeName = root.getAttribute("name").trim(); + + // parse the type number + typenr = Integer.parseInt(root.getAttribute("number").trim()); + + if (log.isDebugEnabled()) { + log.debug("reading type: " + typeName + ", " + typenr); + } + + // parse 'required' attributes + final Element required = NodeListIterator.getFirstChild(root, XML_REQUIRED); + if (required != null) { + final List<String> tmp = new ArrayList<String>(); + for (final Element elem : new NodeListIterator<Element>(required, XML_ATTRIBUTE)) { + final Attr a1 = elem.getAttributeNode(CFArchAttrib.XML_KEY_ARCH); + final Attr a2 = elem.getAttributeNode(XML_VALUE); + if (a1 == null || a2 == null) { + throw new ArchTypeParseException("In '" + XML_REQUIRED + "' element of type " + typeName + ": " + XML_ATTRIBUTE + " missing '" + CFArchAttrib.XML_KEY_ARCH + "' or '" + XML_VALUE + "'."); + } else { + tmp.add(a1.getValue().trim()); + tmp.add(a2.getValue().trim()); + } + } + + // create array and copy vector content into the array: (key1, value1, key2, value2, ...) + if (!tmp.isEmpty()) { + typeAttributes = tmp.toArray(new String[tmp.size()]); + } + } + } catch (final NumberFormatException e) { + // parsing type number failed: + throw new ArchTypeParseException("In " + CommonConstants.TYPEDEF_FILE + ": Type " + typeName + " has invalid type number '" + root.getAttribute("number") + "'."); + } + + // parse 'ignore' elements + final Element signore = NodeListIterator.getFirstChild(root, XML_IGNORE); + if (signore != null) { + // load all attributes in the ignore section + for (final Element elem : new NodeListIterator<Element>(signore, XML_ATTRIBUTE)) { + final Attr a1 = elem.getAttributeNode(CFArchAttrib.XML_KEY_ARCH); + if (a1 == null) { + throw new ArchTypeParseException("In '" + XML_IGNORE + "' section of type " + typeName + ": " + XML_ATTRIBUTE + " missing '" + CFArchAttrib.XML_KEY_ARCH + "'."); + } else { + ignoreTable.put(a1.getValue().trim(), ""); + } + } + + // load attributes from ignore lists + for (final Element elem : new NodeListIterator<Element>(signore, "ignore_list")) { + final Attr a1 = elem.getAttributeNode("name"); + if (a1 == null) { + throw new ArchTypeParseException("In '" + XML_IGNORE + "' section of type " + typeName + ": ignore_list missing 'name'."); + } else if (tlist.getIgnoreListTable().containsKey(a1.getValue().trim())) { + // just copy everything from ignorelist to this ignore section + final List<String> ignlist = (List<String>) tlist.getIgnoreListTable().get(a1.getValue().trim()); + for (final String ignItem : ignlist) { + ignoreTable.put(ignItem, ""); + } + } else { + throw new RuntimeException("In '" + XML_IGNORE + "' section of type " + typeName + ": ignore_list with name \"" + a1.getValue() + "\" is undefined."); + } + } + } + } + + String importName = null; + { + // load description + Element elem; + if ((elem = NodeListIterator.getFirstChild(root, XML_DESC)) != null) { + desc = elem.getTextContent().trim(); + } + + // load use + if ((elem = NodeListIterator.getFirstChild(root, XML_USE)) != null) { + use = elem.getTextContent().trim(); + } + + // load import_type + if ((elem = NodeListIterator.getFirstChild(root, XML_IMPORT_TYPE)) != null) { + final Attr a1 = elem.getAttributeNode("name"); + if (a1 == null) { + throw new RuntimeException("In file '" + CommonConstants.TYPEDEF_FILE + "': Type " + typeName + " has " + XML_IMPORT_TYPE + " element without 'name'."); + } else { + importName = a1.getValue().trim(); + } + } + } + + // now get all children and process them in order: + for (final Element elem : new NodeListIterator<Element>(root, Node.ELEMENT_NODE)) { + // attribute directly in type element + if (elem.getNodeName().equalsIgnoreCase(XML_ATTRIBUTE)) { + parseAttribute(elem, secNames, false, null, attrList, tlist); + } + + // attributes in a section + if (elem.getNodeName().equalsIgnoreCase(XML_SECTION) && elem.hasChildNodes()) { + final Attr a1 = elem.getAttributeNode("name"); + if (a1 == null) { + throw new ArchTypeParseException("In " + CommonConstants.TYPEDEF_FILE + ": Type " + typeName + " contains a " + XML_SECTION + " missing 'name'."); + } + // get section name + final String section = a1.getValue().trim(); + sectionNum++; // increment number of valid sections + secNames.add(section); // tmp. store name + + // parse all attributes in the section + for (final Element elem2 : new NodeListIterator<Element>(elem, XML_ATTRIBUTE)) { + // got an attribute element possibly in a section + parseAttribute(elem2, secNames, true, section, attrList, tlist); + } + } + } + + // ------ now generate the array of attributes: ------ + // calculate how many attributes we've got + + int j = attrList.size(); + + // don't forget about the default attribs + int numDef = 0; + if (defaultArchType != null && defaultArchType.attr != null && defaultArchType.attr.length > 0) { + // create an array to store the references to the default atrribs: + final CFArchAttrib[] defList = new CFArchAttrib[defaultArchType.attr.length]; + + for (final CFArchAttrib attrib : defaultArchType.attr) { + // add all attributes from the default_type which are not in the ignoreTable + if (!ignoreTable.containsKey(attrib.getNameOld())) { + defList[numDef] = attrib; + j++; + numDef++; + } + } + + // now also count the importet attribs + CFArchAttrib[] importList = null; // imported attribs array + + int importNum = 0; + if (importName != null) { + // search through all known types, looking for import type + net.sf.gridarta.CFArchType impType = null; + for (final net.sf.gridarta.CFArchType archType : (Iterable<net.sf.gridarta.CFArchType>) tlist) { + if (archType == this) { + continue; + } + if (archType.typeName.equalsIgnoreCase(importName)) { + impType = archType; + break; + } + } + + if (impType != null) { + // initialize array to store imported attribs + importList = new CFArchAttrib[impType.attr.length]; + + for (final CFArchAttrib attrib : impType.attr) { + if (!attrib.getSecName().equalsIgnoreCase("general")) { + // import this attrib: + if (!attrib.getSecName().equalsIgnoreCase("general") && !attrib.getSecName().equalsIgnoreCase("special") && !secNames.contains(attrib.getSecName())) { + sectionNum++; // increment number of valid sections + secNames.add(attrib.getSecName()); + } + + importList[importNum] = attrib.getClone(); + + // get section id + final int newId = secNames.indexOf(attrib.getSecName()); + if (newId >= 0) { + importList[importNum].setSecId(newId + 2); + } + + importNum++; + j++; + } + } + } else { + throw new ArchTypeParseException("Syntax Error in file '" + CommonConstants.TYPEDEF_FILE + "' (" + typeName + "):\n import type \"" + importName + "\" not found!"); + } + } + + attr = new CFArchAttrib[j]; // create array of appropriate size + + // first put in the references to the default attribs: + for (int k = numDef; k > 0; k--) { + attr[numDef - k] = defList[numDef - k]; + if (log.isDebugEnabled()) { + log.debug("*** (" + (numDef - k) + ") " + attr[numDef - k].getNameNew()); + } + } + + // next put in the references of imported arches (at end of array) + for (int k = 0; k < importNum; k++) { + attr[j - importNum + k] = importList[k]; + if (log.isDebugEnabled()) { + log.debug("*** (" + (j - importNum + k) + ") " + attr[j - importNum + k].getNameNew()); + } + } + } else { + attr = new CFArchAttrib[j]; // create array of appropriate size + } + + // put the list of the (non-default) CFArchAttribs into an array: + for (int i = ... [truncated message content] |