[vassalengine-svn] SF.net SVN: vassalengine: [3484] VASSAL-src/trunk/src/VASSAL
Brought to you by:
rodneykinney,
uckelman
From: <uck...@us...> - 2008-04-27 15:35:24
|
Revision: 3484 http://vassalengine.svn.sourceforge.net/vassalengine/?rev=3484&view=rev Author: uckelman Date: 2008-04-27 08:35:30 -0700 (Sun, 27 Apr 2008) Log Message: ----------- Merged swampwallaby-merge 3482. Streamline Metadata classes Add i18n support to Metadata and Module Manager display Fix unused imports in VASSAL.launch Modified Paths: -------------- VASSAL-src/trunk/src/VASSAL/Info.java VASSAL-src/trunk/src/VASSAL/build/module/ExtensionMetaData.java VASSAL-src/trunk/src/VASSAL/build/module/ModuleMetaData.java VASSAL-src/trunk/src/VASSAL/build/module/SaveMetaData.java VASSAL-src/trunk/src/VASSAL/i18n/Translation.java VASSAL-src/trunk/src/VASSAL/launch/Editor.java VASSAL-src/trunk/src/VASSAL/launch/EditorWindow.java VASSAL-src/trunk/src/VASSAL/launch/ExtensionEditorWindow.java VASSAL-src/trunk/src/VASSAL/launch/FirstTimeDialog.java VASSAL-src/trunk/src/VASSAL/launch/LaunchTourAction.java VASSAL-src/trunk/src/VASSAL/launch/LoadModuleAction.java VASSAL-src/trunk/src/VASSAL/launch/ModuleEditorWindow.java VASSAL-src/trunk/src/VASSAL/launch/ModuleManagerWindow.java VASSAL-src/trunk/src/VASSAL/launch/Player.java VASSAL-src/trunk/src/VASSAL/launch/PlayerWindow.java Added Paths: ----------- VASSAL-src/trunk/src/VASSAL/build/module/AbstractMetaData.java Removed Paths: ------------- VASSAL-src/trunk/src/VASSAL/build/module/MetaData.java Modified: VASSAL-src/trunk/src/VASSAL/Info.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/Info.java 2008-04-27 15:33:11 UTC (rev 3483) +++ VASSAL-src/trunk/src/VASSAL/Info.java 2008-04-27 15:35:30 UTC (rev 3484) @@ -33,7 +33,7 @@ * Class for storing release-related information */ public final class Info { - private static final String VERSION = "3.1.0-svn3473"; //$NON-NLS-1$ + private static final String VERSION = "3.1.0-svn3477"; //$NON-NLS-1$ private static File homeDir; private static final boolean isWindows; Copied: VASSAL-src/trunk/src/VASSAL/build/module/AbstractMetaData.java (from rev 3482, VASSAL-src/branches/swampwallaby-merge/src/VASSAL/build/module/AbstractMetaData.java) =================================================================== --- VASSAL-src/trunk/src/VASSAL/build/module/AbstractMetaData.java (rev 0) +++ VASSAL-src/trunk/src/VASSAL/build/module/AbstractMetaData.java 2008-04-27 15:35:30 UTC (rev 3484) @@ -0,0 +1,525 @@ +/* $Id$ + * + * Copyright (c) 2008 by Brent Easton and Joel Uckelman + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License (LGPL) as published by the Free Software Foundation. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, copies are available + * at http://www.opensource.org. + */ +package VASSAL.build.module; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.HashMap; +import java.util.Locale; +import java.util.zip.ZipEntry; +import java.util.zip.ZipException; +import java.util.zip.ZipFile; + +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.TransformerFactoryConfigurationError; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; +import org.xml.sax.helpers.DefaultHandler; + +import VASSAL.build.Configurable; +import VASSAL.build.GameModule; +import VASSAL.i18n.Translation; +import VASSAL.tools.ArchiveWriter; +import VASSAL.tools.BridgeStream; + +/** + * + * Base Class representing the metadata for a Saved Game, Module or Extension. + * A Base MetaData class is returned only for invalid files. + * + * @author Brent Easton + * @since 3.1.0 + * + */ +public abstract class AbstractMetaData { + + protected static final String TRUE = "true"; + protected static final String FALSE = "false"; + + protected static final String NAME_ATTR = "name"; + protected static final String VERSION_ATTR = "version"; + protected static final String VASSAL_VERSION_ATTR = "vassalVersion"; + protected static final String EXTENSION_ATTR = "extension"; + protected static final String MODULE_NAME_ATTR = "moduleName"; + protected static final String MODULE_VERSION_ATTR = "moduleVersion"; + protected static final String LANG_ATTR = "lang"; + + + protected static final String ROOT_ELEMENT = "data"; + protected static final String VERSION_ELEMENT = "version"; + protected static final String VASSAL_VERSION_ELEMENT = "VassalVersion"; + protected static final String MODULE_NAME_ELEMENT = "moduleName"; + protected static final String MODULE_VERSION_ELEMENT = "moduleVersion"; + protected static final String DESCRIPTION_ELEMENT = "description"; + protected static final String NAME_ELEMENT = "name"; + protected static final String DATE_SAVED_ELEMENT = "dateSaved"; + + protected static final String BUILDFILE_MODULE_ELEMENT1 = "VASSAL.launch.BasicModule"; + protected static final String BUILDFILE_MODULE_ELEMENT2 = "VASSAL.build.GameModule"; + protected static final String BUILDFILE_EXTENSION_ELEMENT = "VASSAL.build.module.ModuleExtension"; + + protected String version; + protected String vassalVersion; + protected Attribute descriptionAttr; + + public String getVersion() { + return version == null ? "" : version; + } + + public void setVersion(String s) { + version = s; + } + + public String getVassalVersion() { + return vassalVersion == null ? "" : vassalVersion; + } + + public void setVassalVersion(String s) { + vassalVersion = s; + } + + public void setDescription (Attribute desc) { + descriptionAttr = desc; + } + + public String getDescription() { + return descriptionAttr == null ? "" : descriptionAttr.getValue(); + } + + public String getLocalizedDescription() { + return descriptionAttr == null ? "" : descriptionAttr.getLocalizedValue(); + } + + /** + * Factory method to build and return an appropriate MetaData class based + * on the contents of the file. Return null of the file is not a Zip archive, + * or it is not a VASSAL Module, Extension or Save Game. + * + * @param file metadata file + * @return MetaData object + */ + public static AbstractMetaData buildMetaData(File file) { + + // Check the file exists and is a file + if (!file.exists() || !file.isFile()) { + return null; + } + + // Check it is a Zip file + ZipFile zip = null; + + try { + zip = new ZipFile(file); + } + catch (ZipException e) { + return null; + } + catch (IOException e) { + return null; + } + + // Check if it is a Save Game file + ZipEntry entry = zip.getEntry(GameState.SAVEFILE_ZIP_ENTRY); + if (entry != null) { + return new SaveMetaData(zip); + } + + // Check if it has a buildFile + ZipEntry buildFileEntry = zip.getEntry(GameModule.BUILDFILE); + if (buildFileEntry == null) { + closeZip(zip); + return null; + } + + // It's either a module or an Extension, check for existence of + // metadata + entry = zip.getEntry(ModuleMetaData.ZIP_ENTRY_NAME); + if (entry != null) { + return new ModuleMetaData(zip); + } + + entry = zip.getEntry(ExtensionMetaData.ZIP_ENTRY_NAME); + if (entry != null) { + return new ExtensionMetaData(zip); + } + + // read the first few lines of the buildFile + BufferedReader br = null; + try { + + br = new BufferedReader(new InputStreamReader(zip.getInputStream(buildFileEntry))); + for (int i = 0; i < 10; i++) { + String s = br.readLine(); + if (s.indexOf(BUILDFILE_MODULE_ELEMENT1) > 0 || s.indexOf(BUILDFILE_MODULE_ELEMENT2) > 0) { + br.close(); + return new ModuleMetaData(zip); + } + else if (s.indexOf(BUILDFILE_EXTENSION_ELEMENT) > 0) { + br.close(); + return new ExtensionMetaData(zip); + } + } + } + catch (IOException e) { + + } + finally { + if (br != null) { + try { + br.close(); + } + catch (IOException e) { + // No stacktrace + } + } + } + + closeZip(zip); + + return null; + } + + /** + * Quietly close a zip file, throw no errors. + */ + private static void closeZip(ZipFile zip) { + try { + zip.close(); + } + catch (IOException e) { + // No stack trace + } + return; + } + + /** + * Write common metadata to the specified Archive. Call addElements to + * add elements specific to particular concrete subclasses. + * + * @param archive + * Extension Archive + * @throws IOException + * If anything goes wrong + */ + public void save(ArchiveWriter archive) throws IOException { + Document doc = null; + Element e = null; + try { + doc = DocumentBuilderFactory.newInstance() + .newDocumentBuilder() + .newDocument(); + + final Element root = doc.createElement(ROOT_ELEMENT); + root.setAttribute(VERSION_ATTR, getMetaDataVersion()); + doc.appendChild(root); + + if (getVersion() != null) { + e = doc.createElement(VERSION_ELEMENT); + e.appendChild(doc.createTextNode(getVersion())); + root.appendChild(e); + } + + if (getVassalVersion() != null) { + e = doc.createElement(VASSAL_VERSION_ELEMENT); + e.appendChild(doc.createTextNode(getVassalVersion())); + root.appendChild(e); + } + + e = doc.createElement(DATE_SAVED_ELEMENT); + e.appendChild(doc.createTextNode(String.valueOf(System.currentTimeMillis()))); + root.appendChild(e); + + if (descriptionAttr != null) { + descriptionAttr.generateXML(doc, root, DESCRIPTION_ELEMENT); + } + + addElements(doc, root); + + } + catch (ParserConfigurationException ex) { + throw new IOException(ex.getMessage()); + } + + final BridgeStream out = new BridgeStream(); + try { + final Transformer xformer = TransformerFactory.newInstance() + .newTransformer(); + xformer.setOutputProperty(OutputKeys.INDENT, "yes"); + xformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", + "2"); + xformer.transform(new DOMSource(doc), new StreamResult(out)); + } + catch (TransformerConfigurationException ex) { + throw new IOException(ex.getMessage()); + } + catch (TransformerFactoryConfigurationError ex) { + throw new IOException(ex.getMessage()); + } + catch (TransformerException ex) { + throw new IOException(ex.getMessage()); + } + + archive.addFile(getZipEntryName(), out.toInputStream()); + } + + /** + * Return the Entry name for the metatdata file + * + * @return Zip Entry name + */ + public abstract String getZipEntryName(); + + /** + * Return the version of the metadata structure + * + * @return version + */ + public abstract String getMetaDataVersion(); + + /** + * Add elements specific to a MetaData subclass + * + * @param doc Document + * @param root Root element + */ + protected abstract void addElements(Document doc, Element root); + + /************************************************************************* + * Utility Exception class, used to cancel SAX parsing + * + */ + class SAXEndException extends SAXException { + private static final long serialVersionUID = 1L; + } + + /************************************************************************* + * Utility class representing a Configurable attribute and its translations + * + */ + class Attribute { + protected String attributeName; + protected String value; + protected HashMap<String, String> translations = new HashMap<String, String>(); + + /** + * Build Attribute class based on atrribute value and translations + * available in the current module + * + * @param c Target configurable + * @param name Attribute name + */ + public Attribute(Configurable target, String name) { + attributeName = name; + value = target.getAttributeValueString(attributeName); + String key = target.getI18nData().getFullPrefix(); + if (key.length()> 0) key += "."; + key += attributeName; + + for (Translation t : GameModule.getGameModule().getAllDescendantComponentsOf(Translation.class)) { + addTranslation(t.getLanguageCode(), t.translate(key)); + } + } + + public Attribute (String attributeName, String value) { + this.attributeName = attributeName; + this.value = value; + } + + public void addTranslation(String language, String value) { + if (value != null) { + translations.put(language, value); + } + } + + /** + * Return the untranslated value of this attribute + * + * @return value + */ + public String getValue() { + return value; + } + + /** + * Return the value of this attribute translated into the local + * language + * + * @return translated value + */ + public String getLocalizedValue() { + String lang = Locale.getDefault().getLanguage(); + String tx = translations.get(lang); + return tx == null ? getValue() : tx; + } + + /** + * Output metadata XML for this attribute, including translations + * + * @param doc Root document + * @param root Parent element + * @param prefix Attribute prefix + */ + public void generateXML(Document doc, Element root, String prefix) { + + if (value == null) { + return; + } + + Element e = null; + + e = doc.createElement(prefix); + e.appendChild(doc.createTextNode(value)); + root.appendChild(e); + + for (String lang : translations.keySet()) { + String tx = translations.get(lang); + e = doc.createElement(prefix); + e.setAttribute(LANG_ATTR, lang); + e.appendChild(doc.createTextNode(tx)); + root.appendChild(e); + } + } + } + + /************************************************************************* + * Base XML Handler for all metadata classes + * + */ + class XMLHandler extends DefaultHandler { + final StringBuilder accumulator = new StringBuilder(); + protected String language = ""; + + @Override + public void startElement(String uri, String localName, + String qName, Attributes attrs) { + // clear the content accumulator + accumulator.setLength(0); + + // Track language for localizable attributes + language = getAttr(attrs, LANG_ATTR); + + } + + protected String getAttr(Attributes attrs, String qName) { + final String value = attrs.getValue(qName); + return value == null ? "" : value; + } + + public void endElement(String uri, String localName, String qName) { + // handle all of the elements which have CDATA here + + String value = accumulator.toString().trim(); + + if (VERSION_ELEMENT.equals(qName)) { + setVersion(value); + } + else if (VASSAL_VERSION_ELEMENT.equals(qName)) { + setVassalVersion(value); + } + else if (DESCRIPTION_ELEMENT.equals(qName)) { + if (descriptionAttr == null) { + setDescription(new Attribute(DESCRIPTION_ELEMENT, value)); + } + else { + descriptionAttr.addTranslation(language, value); + } + } + } + + @Override + public void characters(char[] ch, int start, int length) { + accumulator.append(ch, start, length); + } + + @Override + public void warning(SAXParseException e) throws SAXException { + e.printStackTrace(); + } + + @Override + public void error(SAXParseException e) throws SAXException { + e.printStackTrace(); + } + + @Override + public void fatalError(SAXParseException e) throws SAXException { + throw e; + } + + } + + /************************************************************************* + * XML Handler for parsing a buildFile. Used to read minimal data from + * modules saved prior to 3.1.0. + */ + class BuildFileXMLHandler extends DefaultHandler { + final StringBuilder accumulator = new StringBuilder(); + + @Override + public void startElement(String uri, String localName, + String qName, Attributes attrs) + throws SAXEndException { + // clear the content accumulator + accumulator.setLength(0); + } + + protected String getAttr(Attributes attrs, String qName) { + final String value = attrs.getValue(qName); + return value == null ? "" : value; + } + + @Override + public void endElement(String uri, String localName, String qName) { + // handle all of the elements which have CDATA here + } + + @Override + public void characters(char[] ch, int start, int length) { + accumulator.append(ch, start, length); + } + + @Override + public void warning(SAXParseException e) throws SAXException { + e.printStackTrace(); + } + + @Override + public void error(SAXParseException e) throws SAXException { + e.printStackTrace(); + } + + @Override + public void fatalError(SAXParseException e) throws SAXException { + throw e; + } + } +} Modified: VASSAL-src/trunk/src/VASSAL/build/module/ExtensionMetaData.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/build/module/ExtensionMetaData.java 2008-04-27 15:33:11 UTC (rev 3483) +++ VASSAL-src/trunk/src/VASSAL/build/module/ExtensionMetaData.java 2008-04-27 15:35:30 UTC (rev 3484) @@ -22,33 +22,19 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipFile; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerConfigurationException; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.TransformerFactoryConfigurationError; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; - import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.Attributes; import org.xml.sax.InputSource; import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; import org.xml.sax.XMLReader; import org.xml.sax.helpers.DefaultHandler; import org.xml.sax.helpers.XMLReaderFactory; import VASSAL.Info; import VASSAL.build.GameModule; -import VASSAL.tools.ArchiveWriter; -import VASSAL.tools.BridgeStream; -public class ExtensionMetaData extends MetaData { +public class ExtensionMetaData extends AbstractMetaData { public static final String ZIP_ENTRY_NAME = "extensiondata"; public static final String DATA_VERSION = "1"; @@ -66,11 +52,11 @@ * Extension */ public ExtensionMetaData(ModuleExtension ext) { - version = ext.getVersion(); - description = ext.getDescription(); + setVersion(ext.getVersion()); + setVassalVersion(Info.getVersion()); + setDescription(new Attribute(ModuleExtension.DESCRIPTION, ext.getDescription())); moduleName = GameModule.getGameModule().getGameName(); moduleVersion = GameModule.getGameModule().getGameVersion(); - vassalVersion = Info.getVersion(); } /** @@ -83,70 +69,29 @@ read(zip); } + public String getZipEntryName() { + return ZIP_ENTRY_NAME; + } + + public String getMetaDataVersion() { + return DATA_VERSION; + } + /** - * Write Extension metadata to the specified Archive + * Add elements specific to an ExtensionMetaData * - * @param archive - * Extension Archive - * @throws IOException - * If anything goes wrong + * @param doc Document + * @param root Root element */ - public void save(ArchiveWriter archive) throws IOException { - Document doc = null; - try { - doc = DocumentBuilderFactory.newInstance().newDocumentBuilder() - .newDocument(); + protected void addElements(Document doc, Element root) { - final Element rootEl = doc.createElement(ROOT_ELEMENT); - rootEl.setAttribute(VERSION_ATTR, DATA_VERSION); - doc.appendChild(rootEl); - - Element e = doc.createElement(VERSION_ELEMENT); - e.appendChild(doc.createTextNode(getVersion())); - rootEl.appendChild(e); - - e = doc.createElement(VASSAL_VERSION_ELEMENT); - e.appendChild(doc.createTextNode(getVassalVersion())); - rootEl.appendChild(e); - - e = doc.createElement(MODULE_NAME_ELEMENT); + Element e = doc.createElement(MODULE_NAME_ELEMENT); e.appendChild(doc.createTextNode(moduleName)); - rootEl.appendChild(e); + root.appendChild(e); e = doc.createElement(MODULE_VERSION_ELEMENT); e.appendChild(doc.createTextNode(moduleVersion)); - rootEl.appendChild(e); - - e = doc.createElement(DESCRIPTION_ELEMENT); - e.appendChild(doc.createTextNode(getDescription())); - rootEl.appendChild(e); - // FIXME: Extend to include any translations of the description - - } - catch (ParserConfigurationException ex) { - throw new IOException(ex.getMessage()); - } - - final BridgeStream out = new BridgeStream(); - try { - final Transformer xformer = TransformerFactory.newInstance() - .newTransformer(); - xformer.setOutputProperty(OutputKeys.INDENT, "yes"); - xformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", - "2"); - xformer.transform(new DOMSource(doc), new StreamResult(out)); - } - catch (TransformerConfigurationException ex) { - throw new IOException(ex.getMessage()); - } - catch (TransformerFactoryConfigurationError ex) { - throw new IOException(ex.getMessage()); - } - catch (TransformerException ex) { - throw new IOException(ex.getMessage()); - } - - archive.addFile(ZIP_ENTRY_NAME, out.toInputStream()); + root.appendChild(e); } /** @@ -157,7 +102,7 @@ * @param file Module File */ public void read(ZipFile zip) { - description = version = moduleName = moduleVersion = ""; + version = moduleName = moduleVersion = ""; InputStream is = null; try { @@ -171,7 +116,7 @@ ZipEntry data = zip.getEntry(ZIP_ENTRY_NAME); if (data == null) { data = zip.getEntry(GameModule.BUILDFILE); - handler = new BuildFileXMLHandler(); + handler = new ExtensionBuildFileXMLHandler(); } else { handler = new MetadataXMLHandler(); @@ -220,69 +165,34 @@ /** * XML Handler for parsing an Extension metadata file */ - private class MetadataXMLHandler extends DefaultHandler { - final StringBuilder accumulator = new StringBuilder(); - + private class MetadataXMLHandler extends XMLHandler { + @Override - public void startElement(String uri, String localName, - String qName, Attributes attrs) { - // clear the content accumulator - accumulator.setLength(0); - - // handle element attributes we care about - } - - @Override public void endElement(String uri, String localName, String qName) { // handle all of the elements which have CDATA here - if (VERSION_ELEMENT.equals(qName)) { - version = accumulator.toString().trim(); - } - if (DESCRIPTION_ELEMENT.equals(qName)) { - description = accumulator.toString().trim(); - } - else if (MODULE_NAME_ELEMENT.equals(qName)) { + if (MODULE_NAME_ELEMENT.equals(qName)) { moduleName = accumulator.toString().trim(); } else if (MODULE_VERSION_ELEMENT.equals(qName)) { moduleVersion = accumulator.toString().trim(); } + else { + super.endElement(uri, localName, qName); + } } - - @Override - public void characters(char[] ch, int start, int length) { - accumulator.append(ch, start, length); - } - - @Override - public void warning(SAXParseException e) throws SAXException { - e.printStackTrace(); - } - - @Override - public void error(SAXParseException e) throws SAXException { - e.printStackTrace(); - } - - @Override - public void fatalError(SAXParseException e) throws SAXException { - throw e; - } } /** * XML Handle for parsing an extension buildFile. Used to read minimal data from * extensions saved prior to 3.1.0. */ - private class BuildFileXMLHandler extends DefaultHandler { - final StringBuilder accumulator = new StringBuilder(); + private class ExtensionBuildFileXMLHandler extends BuildFileXMLHandler { @Override public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXEndException { - // clear the content accumulator - accumulator.setLength(0); + super.startElement(uri, localName, qName, attrs); // handle element attributes we care about if (BUILDFILE_EXTENSION_ELEMENT.equals(qName)) { @@ -293,35 +203,5 @@ throw new SAXEndException(); } } - - private String getAttr(Attributes attrs, String qName) { - final String value = attrs.getValue(qName); - return value == null ? "" : value; - } - - @Override - public void endElement(String uri, String localName, String qName) { - // handle all of the elements which have CDATA here - } - - @Override - public void characters(char[] ch, int start, int length) { - accumulator.append(ch, start, length); - } - - @Override - public void warning(SAXParseException e) throws SAXException { - e.printStackTrace(); - } - - @Override - public void error(SAXParseException e) throws SAXException { - e.printStackTrace(); - } - - @Override - public void fatalError(SAXParseException e) throws SAXException { - throw e; - } } } \ No newline at end of file Deleted: VASSAL-src/trunk/src/VASSAL/build/module/MetaData.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/build/module/MetaData.java 2008-04-27 15:33:11 UTC (rev 3483) +++ VASSAL-src/trunk/src/VASSAL/build/module/MetaData.java 2008-04-27 15:35:30 UTC (rev 3484) @@ -1,194 +0,0 @@ -/* $Id$ - * - * Copyright (c) 2008 by Brent Easton and Joel Uckelman - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License (LGPL) as published by the Free Software Foundation. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, copies are available - * at http://www.opensource.org. - */ -package VASSAL.build.module; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.zip.ZipEntry; -import java.util.zip.ZipException; -import java.util.zip.ZipFile; -import java.util.zip.ZipInputStream; - -import org.xml.sax.SAXException; - -import VASSAL.build.GameModule; - -/** - * - * Base Class representing the metadata for a Saved Game, Module or Extension. - * A Base MetaData class is returned only for invalid files. - * - * @author Brent Easton - * @since 3.1.0 - * - */ -public class MetaData { - - public static final String ZIP_ENTRY_NAME = "metadata"; - public static final String DATA_VERSION = "1"; - - protected static final String TRUE = "true"; - protected static final String FALSE = "false"; - - protected static final String NAME_ATTR = "name"; - protected static final String VERSION_ATTR = "version"; - protected static final String VASSAL_VERSION_ATTR = "vassalVersion"; - protected static final String EXTENSION_ATTR = "extension"; - protected static final String MODULE_NAME_ATTR = "moduleName"; - protected static final String MODULE_VERSION_ATTR = "moduleVersion"; - - - protected static final String ROOT_ELEMENT = "data"; - protected static final String VERSION_ELEMENT = "version"; - protected static final String VASSAL_VERSION_ELEMENT = "VassalVersion"; - protected static final String MODULE_NAME_ELEMENT = "moduleName"; - protected static final String MODULE_VERSION_ELEMENT = "moduleVersion"; - protected static final String DESCRIPTION_ELEMENT = "description"; - protected static final String NAME_ELEMENT = "name"; - - protected static final String BUILDFILE_MODULE_ELEMENT1 = "VASSAL.launch.BasicModule"; - protected static final String BUILDFILE_MODULE_ELEMENT2 = "VASSAL.build.GameModule"; - protected static final String BUILDFILE_EXTENSION_ELEMENT = "VASSAL.build.module.ModuleExtension"; - - protected String version; - protected String vassalVersion; - protected String description; - - public String getVersion() { - return version; - } - - public String getVassalVersion() { - return vassalVersion; - } - - public String getDescription() { - return description; - } - - /** - * Build and return an appropriate MetaData class based on the - * contents of the file. - * - * @param file metadata file - * @return MetaData object - */ - public static MetaData buildMetaData(File file) { - - // Check the file exists and is a file - if (!file.exists() || !file.isFile()) { - return null; - } - - // Check it is a Zip file - ZipFile zip = null; - - try { - zip = new ZipFile(file); - } - catch (ZipException e) { - return null; - } - catch (IOException e) { - return null; - } - - // Check if it is a Save Game file - ZipEntry entry = zip.getEntry(GameState.SAVEFILE_ZIP_ENTRY); - if (entry != null) { - return new SaveMetaData(zip); - } - - // Check if it has a buildFile - ZipEntry buildFileEntry = zip.getEntry(GameModule.BUILDFILE); - if (buildFileEntry == null) { - closeZip(zip); - return null; - } - - // It's either a module or an Extension, check for existence of - // metadata - entry = zip.getEntry(ModuleMetaData.ZIP_ENTRY_NAME); - if (entry != null) { - return new ModuleMetaData(zip); - } - - entry = zip.getEntry(ExtensionMetaData.ZIP_ENTRY_NAME); - if (entry != null) { - return new ExtensionMetaData(zip); - } - - // read the first few lines of the buildFile - BufferedReader br = null; - try { - - br = new BufferedReader(new InputStreamReader(zip.getInputStream(buildFileEntry))); - for (int i = 0; i < 10; i++) { - String s = br.readLine(); - if (s.indexOf(BUILDFILE_MODULE_ELEMENT1) > 0 || s.indexOf(BUILDFILE_MODULE_ELEMENT2) > 0) { - br.close(); - return new ModuleMetaData(zip); - } - else if (s.indexOf(BUILDFILE_EXTENSION_ELEMENT) > 0) { - br.close(); - return new ExtensionMetaData(zip); - } - } - } - catch (IOException e) { - - } - finally { - if (br != null) { - try { - br.close(); - } - catch (IOException e) { - // No stacktrace - } - } - } - - closeZip(zip); - - return null; - } - - // Quietly close a zip file, throw no errors. - private static void closeZip(ZipFile zip) { - try { - zip.close(); - } - catch (IOException e) { - // No stack trace - } - return; - } - - /** - * Utility Exception class, used to cancel SAX parsing - * - */ - class SAXEndException extends SAXException { - private static final long serialVersionUID = 1L; - - } -} Modified: VASSAL-src/trunk/src/VASSAL/build/module/ModuleMetaData.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/build/module/ModuleMetaData.java 2008-04-27 15:33:11 UTC (rev 3483) +++ VASSAL-src/trunk/src/VASSAL/build/module/ModuleMetaData.java 2008-04-27 15:35:30 UTC (rev 3484) @@ -23,31 +23,17 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipFile; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerConfigurationException; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.TransformerFactoryConfigurationError; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; - import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.Attributes; import org.xml.sax.InputSource; import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; import org.xml.sax.XMLReader; import org.xml.sax.helpers.DefaultHandler; import org.xml.sax.helpers.XMLReaderFactory; import VASSAL.Info; import VASSAL.build.GameModule; -import VASSAL.tools.ArchiveWriter; -import VASSAL.tools.BridgeStream; /** * @@ -59,89 +45,51 @@ * @since 3.1.0 * */ -public class ModuleMetaData extends MetaData { +public class ModuleMetaData extends AbstractMetaData { public static final String ZIP_ENTRY_NAME = "moduledata"; public static final String DATA_VERSION = "1"; - protected String name; + protected Attribute nameAttr; public ModuleMetaData(ZipFile zip) { read(zip); } public ModuleMetaData(GameModule module) { - name = GameModule.getGameModule().getGameName(); - version = GameModule.getGameModule().getGameVersion(); - vassalVersion = Info.getVersion(); - description = GameModule.getGameModule().getAttributeValueString(GameModule.DESCRIPTION); + nameAttr = new Attribute(module, GameModule.MODULE_NAME); + setDescription(new Attribute(module, GameModule.DESCRIPTION)); + setVersion(module.getGameVersion()); + setVassalVersion(Info.getVersion()); } public String getName() { - return name; + return nameAttr.getValue(); } + + public String getLocalizedName() { + return nameAttr.getLocalizedValue(); + } + public String getZipEntryName() { + return ZIP_ENTRY_NAME; + } + + public String getMetaDataVersion() { + return DATA_VERSION; + } + /** - * Write Save Game metadata to the specified Archive - * @param archive Save game Archive - * @throws IOException If anything goes wrong + * Add elements specific to a ModuleMetaData + * + * @param doc Document + * @param root Root element */ - public void save(ArchiveWriter archive) throws IOException { - Document doc = null; - try { - doc = DocumentBuilderFactory.newInstance() - .newDocumentBuilder() - .newDocument(); - - final Element rootEl = doc.createElement(ROOT_ELEMENT); - rootEl.setAttribute(VERSION_ATTR, DATA_VERSION); - doc.appendChild(rootEl); - - Element e = doc.createElement(NAME_ELEMENT); - e.appendChild(doc.createTextNode(getName())); - rootEl.appendChild(e); - // FIXME: Extend to include any translations of the name - - e = doc.createElement(VERSION_ELEMENT); - e.appendChild(doc.createTextNode(getVersion())); - rootEl.appendChild(e); - - e = doc.createElement(VASSAL_VERSION_ELEMENT); - e.appendChild(doc.createTextNode(getVassalVersion())); - rootEl.appendChild(e); - - e = doc.createElement(DESCRIPTION_ELEMENT); - e.appendChild(doc.createTextNode(getDescription())); - rootEl.appendChild(e); - // FIXME: Extend to include any translations of the description - - } - catch (ParserConfigurationException ex) { - throw new IOException(ex.getMessage()); - } - - final BridgeStream out = new BridgeStream(); - try { - final Transformer xformer = - TransformerFactory.newInstance().newTransformer(); - xformer.setOutputProperty(OutputKeys.INDENT, "yes"); - xformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", - "2"); - xformer.transform(new DOMSource(doc), new StreamResult(out)); - } - catch (TransformerConfigurationException ex) { - throw new IOException(ex.getMessage()); - } - catch (TransformerFactoryConfigurationError ex) { - throw new IOException(ex.getMessage()); - } - catch (TransformerException ex) { - throw new IOException(ex.getMessage()); - } - - archive.addFile(ZIP_ENTRY_NAME, out.toInputStream()); + protected void addElements(Document doc, Element root) { + nameAttr.generateXML(doc, root, NAME_ELEMENT); } + /** * Read and validate a Module file. * - Check it has a Zip Entry named buildfile @@ -150,7 +98,7 @@ * @param file Module File */ public void read(ZipFile zip) { - description = name = version = ""; + version = ""; InputStream is = null; try { @@ -164,7 +112,7 @@ ZipEntry data = zip.getEntry(ZIP_ENTRY_NAME); if (data == null) { data = zip.getEntry(GameModule.BUILDFILE); - handler = new BuildFileXMLHandler(); + handler = new ModuleBuildFileXMLHandler(); } else { handler = new MetadataXMLHandler(); @@ -217,105 +165,45 @@ /** * XML Handler for parsing a Module/Extension metadata file */ - private class MetadataXMLHandler extends DefaultHandler { - final StringBuilder accumulator = new StringBuilder(); + private class MetadataXMLHandler extends XMLHandler { @Override - public void startElement(String uri, String localName, - String qName, Attributes attrs) { - // clear the content accumulator - accumulator.setLength(0); - - // handle element attributes we care about - } - - @Override public void endElement(String uri, String localName, String qName) { // handle all of the elements which have CDATA here if (NAME_ELEMENT.equals(qName)) { - name = accumulator.toString().trim(); + if (nameAttr == null) { + nameAttr = new Attribute(NAME_ELEMENT, accumulator.toString().trim()); + } + else { + nameAttr.addTranslation(language, accumulator.toString().trim()); + } } - else if (VERSION_ELEMENT.equals(qName)) { - version = accumulator.toString().trim(); + else { + super.endElement(uri, localName, qName); } - if (DESCRIPTION_ELEMENT.equals(qName)) { - description = accumulator.toString().trim(); - } } - - @Override - public void characters(char[] ch, int start, int length) { - accumulator.append(ch, start, length); - } - - @Override - public void warning(SAXParseException e) throws SAXException { - e.printStackTrace(); - } - - @Override - public void error(SAXParseException e) throws SAXException { - e.printStackTrace(); - } - - @Override - public void fatalError(SAXParseException e) throws SAXException { - throw e; - } } /** - * XML Handle for parsing a buildFile. Used to read minimal data from + * XML Handle for parsing a Module buildFile. Used to read minimal data from * modules saved prior to 3.1.0. */ - private class BuildFileXMLHandler extends DefaultHandler { - final StringBuilder accumulator = new StringBuilder(); + private class ModuleBuildFileXMLHandler extends BuildFileXMLHandler { @Override public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXEndException { - // clear the content accumulator - accumulator.setLength(0); + super.startElement(uri, localName, qName, attrs); // handle element attributes we care about if (BUILDFILE_MODULE_ELEMENT1.equals(qName) || BUILDFILE_MODULE_ELEMENT2.equals(qName)) { - name = getAttr(attrs, NAME_ATTR); - version = getAttr(attrs, VERSION_ATTR); - vassalVersion = getAttr(attrs, VASSAL_VERSION_ATTR); + nameAttr = new Attribute (NAME_ELEMENT, getAttr(attrs, NAME_ATTR)); + setVersion(getAttr(attrs, VERSION_ATTR)); + setVassalVersion(getAttr(attrs, VASSAL_VERSION_ATTR)); throw new SAXEndException(); } } - - private String getAttr(Attributes attrs, String qName) { - final String value = attrs.getValue(qName); - return value == null ? "" : value; - } - - @Override - public void endElement(String uri, String localName, String qName) { - // handle all of the elements which have CDATA here - } - - @Override - public void characters(char[] ch, int start, int length) { - accumulator.append(ch, start, length); - } - - @Override - public void warning(SAXParseException e) throws SAXException { - e.printStackTrace(); - } - - @Override - public void error(SAXParseException e) throws SAXException { - e.printStackTrace(); - } - - @Override - public void fatalError(SAXParseException e) throws SAXException { - throw e; - } } } Modified: VASSAL-src/trunk/src/VASSAL/build/module/SaveMetaData.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/build/module/SaveMetaData.java 2008-04-27 15:33:11 UTC (rev 3483) +++ VASSAL-src/trunk/src/VASSAL/build/module/SaveMetaData.java 2008-04-27 15:35:30 UTC (rev 3484) @@ -24,31 +24,17 @@ import java.util.zip.ZipFile; import javax.swing.JOptionPane; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerConfigurationException; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.TransformerFactoryConfigurationError; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Document; import org.w3c.dom.Element; -import org.xml.sax.Attributes; import org.xml.sax.InputSource; import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; import org.xml.sax.XMLReader; -import org.xml.sax.helpers.DefaultHandler; import org.xml.sax.helpers.XMLReaderFactory; import VASSAL.build.GameModule; import VASSAL.i18n.Resources; import VASSAL.tools.ArchiveWriter; -import VASSAL.tools.BridgeStream; /** * @@ -60,35 +46,29 @@ * @since 3.1.0 * */ -public class SaveMetaData extends MetaData { +public class SaveMetaData extends AbstractMetaData { public static final String ZIP_ENTRY_NAME = "savedata"; public static final String DATA_VERSION = "1"; - public static final String COMMENTS_ELEMENT = "comments"; - - protected String comments; protected ModuleMetaData moduleData; public SaveMetaData() { - comments = (String) JOptionPane.showInputDialog( + String comments = (String) JOptionPane.showInputDialog( GameModule.getGameModule().getFrame(), Resources.getString("BasicLogger.enter_comments"), Resources.getString("BasicLogger.log_file_comments"), JOptionPane.PLAIN_MESSAGE, null, null, - comments); + ""); + setDescription(new Attribute(DESCRIPTION_ELEMENT, comments)); } public SaveMetaData(ZipFile zip) { read(zip); } - public String getComments() { - return comments; - } - public String getModuleName() { return moduleData == null ? "" : moduleData.getName(); } @@ -96,6 +76,14 @@ public String getModuleVersion() { return moduleData == null ? "" : moduleData.getVersion(); } + + public String getZipEntryName() { + return ZIP_ENTRY_NAME; + } + + public String getMetaDataVersion() { + return DATA_VERSION; + } /** * Write Save Game metadata to the specified Archive @@ -103,48 +91,30 @@ * @throws IOException If anything goes wrong */ public void save(ArchiveWriter archive) throws IOException { - Document doc = null; + super.save(archive); + + // Also save a copy of the current module metadata in the save file. Copy + // module metadata from the module archive as it will contain full i18n + // information. + InputStream in = null; try { - doc = DocumentBuilderFactory.newInstance() - .newDocumentBuilder() - .newDocument(); - - final Element root = doc.createElement(ROOT_ELEMENT); - root.setAttribute(VERSION_ATTR, DATA_VERSION); - doc.appendChild(root); - - final Element comments = doc.createElement(COMMENTS_ELEMENT); - comments.appendChild(doc.createTextNode(getComments())); - root.appendChild(comments); + in = GameModule.getGameModule().getDataArchive().getFileStream(ModuleMetaData.ZIP_ENTRY_NAME); + archive.addFile(ModuleMetaData.ZIP_ENTRY_NAME, in); + in.close(); } - catch (ParserConfigurationException ex) { - throw new IOException(ex.getMessage()); + finally { + if (in != null) { + in.close(); + } } - - final BridgeStream out = new BridgeStream(); - try { - final Transformer xformer = - TransformerFactory.newInstance().newTransformer(); - xformer.setOutputProperty(OutputKeys.INDENT, "yes"); - xformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", - "2"); - xformer.transform(new DOMSource(doc), new StreamResult(out)); - } - catch (TransformerConfigurationException ex) { - throw new IOException(ex.getMessage()); - } - catch (TransformerFactoryConfigurationError ex) { - throw new IOException(ex.getMessage()); - } - catch (TransformerException ex) { - throw new IOException(ex.getMessage()); - } - - archive.addFile(ZIP_ENTRY_NAME, out.toInputStream()); - - // Also save a copy of the current module metadata in the save file - (new ModuleMetaData(GameModule.getGameModule())).save(archive); } + + /** + * Add Elements specific to SaveMetaData + */ + protected void addElements(Document doc, Element root) { + return; + } /** * Read and validate a Saved Game/Log file. @@ -154,7 +124,6 @@ * @param file Saved Game File */ public void read(ZipFile zip) { - comments = ""; InputStream is = null; try { @@ -207,57 +176,4 @@ } } } - - private class XMLHandler extends DefaultHandler { - final StringBuilder accumulator = new StringBuilder(); - String currentElement = null; - - @Override - public void startElement(String uri, String localName, - String qName, Attributes attrs) { - // clear the content accumulator - accumulator.setLength(0); - - // handle element attributes we care about -/* - else if (VASSAL_ELEMENT.equals(localName)) { - vassalVersion = attrs.getName(VERSION_ATTR); - } -*/ - currentElement = qName; - } - -// private String getAttr(Attributes attrs, String qName) { -// final String value = attrs.getValue(qName); -// return value == null ? "" : value; -// } - - @Override - public void endElement(String uri, String localName, String qName) { - // handle all of the elements which have CDATA here - if (COMMENTS_ELEMENT.equals(qName)) { - comments = accumulator.toString().trim(); - } - } - - @Override - public void characters(char[] ch, int start, int length) { - accumulator.append(ch, start, length); - } - - @Override - public void warning(SAXParseException e) throws SAXException { - e.printStackTrace(); - } - - @Override - public void error(SAXParseException e) throws SAXException { - e.printStackTrace(); - } - - @Override - public void fatalError(SAXParseException e) throws SAXException { - throw e; - } - } } Modified: VASSAL-src/trunk/src/VASSAL/i18n/Translation.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/i18n/Translation.java 2008-04-27 15:33:11 UTC (rev 3483) +++ VASSAL-src/trunk/src/VASSAL/i18n/Translation.java 2008-04-27 15:35:30 UTC (rev 3484) @@ -34,7 +34,7 @@ public class Translation extends AbstractConfigurable implements Comparable<Translation> { - protected static final String LOCALE = "locale"; //$NON-NLS-1$ + public static final String LOCALE = "locale"; //$NON-NLS-1$ protected Locale locale; protected boolean dirty = false; protected Properties localProperties; @@ -81,6 +81,10 @@ protected String getDescription() { return locale.getDisplayName(Locale.getDefault()); } + + public String getLanguageCode() { + return locale.getLanguage(); + } public String getConfigureName() { return getDescription(); Modified: VASSAL-src/trunk/src/VASSAL/launch/Editor.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/launch/Editor.java 2008-04-27 15:33:11 UTC (rev 3483) +++ VASSAL-src/trunk/src/VASSAL/launch/Editor.java 2008-04-27 15:35:30 UTC (rev 3484) @@ -30,11 +30,8 @@ import java.util.Observer; import java.util.Properties; -import javax.swing.Action; import javax.swing.JFrame; -import javax.swing.JMenu; import javax.swing.JMenuBar; -import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.SwingUtilities; @@ -46,9 +43,9 @@ import VASSAL.tools.ErrorLog; import VASSAL.tools.FileChooser; import VASSAL.tools.imports.ImportAction; +import VASSAL.tools.menu.MacOSXMenuManager; import VASSAL.tools.menu.MenuBarProxy; import VASSAL.tools.menu.MenuManager; -import VASSAL.tools.menu.MacOSXMenuManager; public class Editor { protected File moduleFile; Modified: VASSAL-src/trunk/src/VASSAL/launch/EditorWindow.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/launch/EditorWindow.java 2008-04-27 15:33:11 UTC (rev 3483) +++ VASSAL-src/trunk/src/VASSAL/launch/EditorWindow.java 2008-04-27 15:35:30 UTC (rev 3484) @@ -23,20 +23,16 @@ import java.awt.Dimension; import java.awt.Toolkit; import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.File; import java.net.MalformedURLException; import java.net.URL; -import java.util.HashMap; -import java.util.Map; + import javax.swing.AbstractAction; import javax.swing.Action; import javax.swing.JFrame; -import javax.swing.JMenu; -import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JPanel; import javax.swing.JScrollPane; @@ -56,11 +52,10 @@ import VASSAL.configure.ValidationReport; import VASSAL.configure.ValidationReportDialog; import VASSAL.i18n.Resources; -import VASSAL.i18n.TranslateVassalWindow; import VASSAL.tools.ErrorLog; import VASSAL.tools.menu.MenuBarProxy; -import VASSAL.tools.menu.MenuProxy; import VASSAL.tools.menu.MenuManager; +import VASSAL.tools.menu.MenuProxy; /** * EditorWindow is the base class for the three top-level component Modified: VASSAL-src/trunk/src/VASSAL/launch/ExtensionEditorWindow.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/launch/ExtensionEditorWindow.java 2008-04-27 15:33:11 UTC (rev 3483) +++ VASSAL-src/trunk/src/VASSAL/launch/ExtensionEditorWindow.java 2008-04-27 15:35:30 UTC (rev 3484) @@ -19,7 +19,6 @@ import java.io.IOException; import javax.swing.JDialog; -import javax.swing.JFrame; import javax.swing.JOptionPane; import VASSAL.build.GameModule; Modified: VASSAL-src/trunk/src/VASSAL/launch/FirstTimeDialog.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/launch/FirstTimeDialog.java 2008-04-27 15:33:11 UTC (rev 3483) +++ VASSAL-src/trunk/src/VASSAL/launch/FirstTimeDialog.java 2008-04-27 15:35:30 UTC (rev 3484) @@ -20,7 +20,6 @@ import java.awt.Color; import java.awt.Component; -import java.awt.Container; import java.awt.Font; import java.awt.Frame; import java.awt.event.ActionEvent; @@ -30,6 +29,7 @@ import java.io.File; import java.net.MalformedURLException; import java.util.Locale; + import javax.swing.DefaultListCellRenderer; import javax.swing.ImageIcon; import javax.swing.JButton; @@ -37,20 +37,14 @@ import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JList; -import javax.swing.JOptionPane; import javax.swing.JPanel; -// FIXME: switch to these once we move to Java 1.6 -//import javax.swing.GroupLayout; -//import javax.swing.LayoutStyle; import org.jdesktop.layout.GroupLayout; import org.jdesktop.layout.LayoutStyle; -import VASSAL.build.GameModule; import VASSAL.build.module.Documentation; import VASSAL.configure.ShowHelpAction; import VASSAL.i18n.Resources; -import VASSAL.tools.DataArchive; /** * A dialog for first-time users. Modified: VASSAL-src/trunk/src/VASSAL/launch/LaunchTourAction.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/launch/LaunchTourAction.java 2008-04-27 15:33:11 UTC (rev 3483) +++ VASSAL-src/trunk/src/VASSAL/launch/LaunchTourAction.java 2008-04-27 15:35:30 UTC (rev 3484) @@ -21,7 +21,6 @@ import java.awt.Window; import java.io.File; -import javax.swing.Action; import VASSAL.build.module.Documentation; import VASSAL.i18n.Resources; Modified: VASSAL-src/trunk/src/VASSAL/launch/LoadModuleAction.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/launch/LoadModuleAction.java 2008-04-27 15:33:11 UTC (rev 3483) +++ VASSAL-src/trunk/src/VASSAL/launch/LoadModuleAction.java 2008-04-27 15:35:30 UTC (rev 3484) @@ -19,20 +19,18 @@ package VASSAL.launch; import java.awt.Component; -import java.awt.Cursor; import java.awt.event.ActionEvent; import java.io.File; import java.io.IOException; -import javax.swing.JFrame; import VASSAL.build.GameModule; import VASSAL.build.module.ExtensionsLoader; import VASSAL.configure.DirectoryConfigurer; import VASSAL.i18n.Localization; import VASSAL.i18n.Resources; +import VASSAL.preferences.Prefs; import VASSAL.tools.DataArchive; import VASSAL.tools.FileChooser; -import VASSAL.preferences.Prefs; /** * Loads a module in play mode Modified: VASSAL-src/trunk/src/VASSAL/launch/ModuleEditorWindow.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/launch/ModuleEditorWindow.java 2008-04-27 15:33:11 UTC (rev 3483) +++ VASSAL-src/trunk/src/VASSAL/launch/ModuleEditorWindow.java 2008-04-27 15:35:30 UTC (rev 3484) @@ -17,12 +17,9 @@ package VASSAL.launch; import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; + import javax.swing.AbstractAction; import javax.swing.Action; -import javax.swing.JFrame; -import javax.swing.JMenu; -import javax.swing.JMenuItem; import VASSAL.build.GameModule; import VASSAL.configure.ConfigureTree; Modified: VASSAL-src/trunk/src/VASSAL/launch/ModuleManagerWindow.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/launch/ModuleManagerWindow.java 2008-04-27 15:33:11 UTC (rev 3483) +++ VASSAL-src/trunk/src/VASSAL/launch/ModuleManagerWindow.java 2008-04-27 15:35:30 UTC (rev 3484) @@ -76,7 +76,7 @@ import VASSAL.build.module.Documentation; import VASSAL.build.module.ExtensionMetaData; import VASSAL.build.module.ExtensionsManager; -import VASSAL.build.module.MetaData; +import VASSAL.build.module.AbstractMetaData; import VASSAL.build.module.ModuleMetaData; import VASSAL.build.module.SaveMetaData; import VASSAL.chat.CgiServerStatus; @@ -854,7 +854,7 @@ public ModuleInfo(File f) { super(f, moduleIcon); - MetaData data = MetaData.buildMetaData(file); + AbstractMetaData data = AbstractMetaData.buildMetaData(file); if (data != null && data instanceof ModuleMetaData) { setValid(true); metadata = (ModuleMetaData) data; @@ -876,7 +876,7 @@ SequenceEncoder.Decoder sd = new SequenceEncoder.Decoder(s, ';'); setFile(new File(sd.nextToken())); setIcon(moduleIcon); - MetaData data = MetaData.buildMetaData(getFile()); + AbstractMetaData data = AbstractMetaData.buildMetaData(getFile()); if (data != null && data instanceof ModuleMetaData) { setValid(true); metadata = (ModuleMetaData) data; @@ -989,8 +989,8 @@ return metadata.getVersion(); } - public String getDescription() { - return metadata.getDescription(); + public String getLocalizedDescription() { + return metadata.getLocalizedDescription(); } public String getModuleName() { @@ -998,11 +998,11 @@ } public String toString() { - return metadata.getName(); + return metadata.getLocalizedName(); } public String getValueAt(int column) { - return column == SPARE_COLUMN ? getDescription() : super.getValueAt(column); + return column == SPARE_COLUMN ? getLocalizedDescription() : super.getValueAt(column); } } @@ -1019,7 +1019,7 @@ super(file, active ? activeExtensionIcon : inactiveExtensionIcon); this.active = active; moduleInfo = module; - MetaData data = MetaData.buildMetaData(file); + AbstractMetaData data = AbstractMetaData.buildMetaData(file); if (data != null && data instanceof ExtensionMetaData) { setValid(true); metadata = (ExtensionMetaData) data; @@ -1185,7 +1185,7 @@ public SaveFileInfo(File f, GameFolderInfo folder) { super(f, fileIcon); folderInfo = folder; - MetaData data = MetaData.buildMetaData(file); + AbstractMetaData data = AbstractMetaData.buildMetaData(file); if (data != null && data instanceof SaveMetaData) { metadata = (SaveMetaData) data; setValid(true); @@ -1222,7 +1222,7 @@ comments = "[" + metadata.getModuleName() + "] "; } } - comments += metadata.getComments(); + comments += metadata.getDescription(); return comments; } @@ -1239,10 +1239,6 @@ return metadata.getModuleVersion(); } - public String getComments() { - return metadata.getComments(); - } - } /** ************************************************************************* Modified: VASSAL-src/trunk/src/VASSAL/launch/Player.java =================================================================== --- VASSAL-src/trunk/src/VASSAL/launch/Player.java 2008-04-27 15:33:11 UTC (rev 3483) +++ VASSAL-src/trunk/src/VASSAL/launch/Player.java 2008-04-27 15:35:30 UTC (rev 3484) @@ -19,7 +19,6 @@ package VASSAL.launch; -import java.awt.Cursor; import java.awt.event.ActionEvent; import java.io.File; import java.io.IOExcept... [truncated message content] |