You can subscribe to this list here.
| 2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(103) |
Jun
(121) |
Jul
(16) |
Aug
(67) |
Sep
(126) |
Oct
(161) |
Nov
(164) |
Dec
(588) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2007 |
Jan
(394) |
Feb
(181) |
Mar
(131) |
Apr
(180) |
May
(255) |
Jun
(11) |
Jul
(79) |
Aug
(70) |
Sep
(274) |
Oct
(138) |
Nov
(195) |
Dec
(8) |
| 2008 |
Jan
(3) |
Feb
(142) |
Mar
(162) |
Apr
(124) |
May
(148) |
Jun
(157) |
Jul
(425) |
Aug
(373) |
Sep
(264) |
Oct
(315) |
Nov
(225) |
Dec
(6) |
| 2009 |
Jan
(67) |
Feb
(78) |
Mar
(279) |
Apr
(294) |
May
(92) |
Jun
(65) |
Jul
(134) |
Aug
(41) |
Sep
(138) |
Oct
(125) |
Nov
(126) |
Dec
(122) |
| 2010 |
Jan
(15) |
Feb
(48) |
Mar
(9) |
Apr
(195) |
May
(373) |
Jun
(507) |
Jul
(42) |
Aug
(16) |
Sep
(38) |
Oct
(81) |
Nov
(64) |
Dec
(18) |
| 2011 |
Jan
(13) |
Feb
(12) |
Mar
(39) |
Apr
(1) |
May
(2) |
Jun
(27) |
Jul
(27) |
Aug
(31) |
Sep
(14) |
Oct
(102) |
Nov
(20) |
Dec
(37) |
| 2012 |
Jan
(22) |
Feb
(1) |
Mar
(1) |
Apr
(2) |
May
(2) |
Jun
(18) |
Jul
(6) |
Aug
(1) |
Sep
(1) |
Oct
|
Nov
|
Dec
|
| 2013 |
Jan
(1) |
Feb
(2) |
Mar
(1) |
Apr
(1) |
May
(47) |
Jun
(7) |
Jul
(107) |
Aug
|
Sep
|
Oct
(112) |
Nov
(31) |
Dec
(17) |
| 2014 |
Jan
(29) |
Feb
(111) |
Mar
(34) |
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
(18) |
Dec
(10) |
|
From: <aki...@us...> - 2014-03-09 01:37:53
|
Revision: 9685
http://sourceforge.net/p/gridarta/code/9685
Author: akirschbaum
Date: 2014-03-09 01:37:47 +0000 (Sun, 09 Mar 2014)
Log Message:
-----------
Simplify code.
Modified Paths:
--------------
trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParser.java
Modified: trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParser.java
===================================================================
--- trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParser.java 2014-03-09 01:33:12 UTC (rev 9684)
+++ trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParser.java 2014-03-09 01:37:47 UTC (rev 9685)
@@ -77,7 +77,9 @@
parseLists(archetypeTypeSet, XmlUtils.getChild(rootElement, Constants.XML_ELEMENT_LISTS), errorViewCollector);
final IgnorelistsDefinition ignorelistsDefinition = parseIgnoreLists(XmlUtils.getChild(rootElement, Constants.XML_ELEMENT_IGNORELISTS), errorViewCollector);
final Elements attributeOrderElements = rootElement.getChildElements(Constants.XML_ELEMENT_ATTRIBUTE_ORDER);
- parseAttributeOrder(archetypeTypeSet, attributeOrderElements.size() == 0 ? null : attributeOrderElements.get(0), errorViewCollector);
+ if (attributeOrderElements.size() > 0) {
+ parseAttributeOrder(archetypeTypeSet, attributeOrderElements.get(0), errorViewCollector);
+ }
final ArchetypeType defaultArchetypeType = parseDefaultType(archetypeTypeSet, XmlUtils.getChild(rootElement, Constants.XML_ELEMENT_DEFAULT_TYPE), errorViewCollector, ignorelistsDefinition);
for (final Element element : new ElementsIterable(rootElement.getChildElements(Constants.XML_ELEMENT_TYPE))) {
@@ -287,16 +289,14 @@
* Parses the {@link Constants#XML_ELEMENT_ATTRIBUTE_ORDER} section of a
* types.xml file.
* @param archetypeTypeSet the archetype types being loaded
- * @param attributeOrderElement the element to parse or {@code null}
+ * @param attributeOrderElement the element to parse
* @param errorViewCollector the error view collector for reporting errors
*/
- private static void parseAttributeOrder(@NotNull final ArchetypeTypeSet archetypeTypeSet, @Nullable final Node attributeOrderElement, @NotNull final ErrorViewCollector errorViewCollector) {
- if (attributeOrderElement != null) {
- for (final String value : StringUtils.PATTERN_WHITESPACE_NEWLINE.split(attributeOrderElement.getValue())) {
- if (!value.isEmpty()) {
- if (archetypeTypeSet.addAttributeOrder(value)) {
- errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, value + ": duplicate attribute name");
- }
+ private static void parseAttributeOrder(@NotNull final ArchetypeTypeSet archetypeTypeSet, @NotNull final Node attributeOrderElement, @NotNull final ErrorViewCollector errorViewCollector) {
+ for (final String value : StringUtils.PATTERN_WHITESPACE_NEWLINE.split(attributeOrderElement.getValue())) {
+ if (!value.isEmpty()) {
+ if (archetypeTypeSet.addAttributeOrder(value)) {
+ errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, value + ": duplicate attribute name");
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <aki...@us...> - 2014-03-09 01:33:19
|
Revision: 9684
http://sourceforge.net/p/gridarta/code/9684
Author: akirschbaum
Date: 2014-03-09 01:33:12 +0000 (Sun, 09 Mar 2014)
Log Message:
-----------
Inline function.
Modified Paths:
--------------
trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeParser.java
trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParser.java
trunk/src/utils/src/main/java/net/sf/gridarta/utils/XmlUtils.java
Modified: trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeParser.java
===================================================================
--- trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeParser.java 2014-03-09 01:26:51 UTC (rev 9683)
+++ trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeParser.java 2014-03-09 01:33:12 UTC (rev 9684)
@@ -25,11 +25,10 @@
import net.sf.gridarta.model.errorview.ErrorViewCategory;
import net.sf.gridarta.model.errorview.ErrorViewCollector;
import net.sf.gridarta.utils.StringUtils;
-import net.sf.gridarta.utils.XmlUtils;
import net.sf.gridarta.utils.xml.ElementsIterable;
import nu.xom.Attribute;
import nu.xom.Element;
-import nu.xom.Node;
+import nu.xom.Elements;
import org.apache.log4j.Category;
import org.apache.log4j.Logger;
import org.jetbrains.annotations.NotNull;
@@ -369,8 +368,9 @@
private static ArchetypeAttributesDefinition parseTypeAttributes(@NotNull final Element typeElement, @NotNull final String typeName, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final Collection<String> ignoreTable, @NotNull final IgnorelistsDefinition ignorelistsDefinition) {
final ArchetypeAttributesDefinition typeAttributes = parseRequiredAttribute(typeElement, typeName, errorViewCollector);
- final Element ignoreElement = XmlUtils.getChildOptional(typeElement, Constants.XML_ELEMENT_IGNORE);
- if (ignoreElement != null) {
+ final Elements ignoreElements = typeElement.getChildElements(Constants.XML_ELEMENT_IGNORE);
+ if (ignoreElements.size() > 0) {
+ final Element ignoreElement = ignoreElements.get(0);
parseAttributeAttributes(ignoreElement, typeName, errorViewCollector, ignoreTable);
parseIgnoreListAttribute(ignoreElement, typeName, errorViewCollector, ignoreTable, ignorelistsDefinition);
}
@@ -388,9 +388,9 @@
@NotNull
private static ArchetypeAttributesDefinition parseRequiredAttribute(@NotNull final Element typeElement, @NotNull final String typeName, @NotNull final ErrorViewCollector errorViewCollector) {
final ArchetypeAttributesDefinition attributes = new ArchetypeAttributesDefinition();
- final Element requiredElement = XmlUtils.getChildOptional(typeElement, Constants.XML_ELEMENT_REQUIRED);
- if (requiredElement != null) {
- for (final Element attributeElement : new ElementsIterable(requiredElement.getChildElements(Constants.XML_ELEMENT_ATTRIBUTE))) {
+ final Elements requiredElements = typeElement.getChildElements(Constants.XML_ELEMENT_REQUIRED);
+ if (requiredElements.size() > 0) {
+ for (final Element attributeElement : new ElementsIterable(requiredElements.get(0).getChildElements(Constants.XML_ELEMENT_ATTRIBUTE))) {
final Attribute archAttribute = attributeElement.getAttribute(Constants.XML_ATTRIBUTE_ARCH);
if (archAttribute == null) {
errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, Constants.XML_ELEMENT_REQUIRED + ": element of type " + typeName + ": " + Constants.XML_ELEMENT_ATTRIBUTE + " missing '" + Constants.XML_ATTRIBUTE_ARCH + "'.");
@@ -480,8 +480,8 @@
*/
@Nullable
private static String parseDescription(@NotNull final Element root) {
- final Node elem = XmlUtils.getChildOptional(root, Constants.XML_DESCRIPTION);
- return elem == null ? null : elem.getValue().trim();
+ final Elements elements = root.getChildElements(Constants.XML_DESCRIPTION);
+ return elements.size() == 0 ? null : elements.get(0).getValue().trim();
}
/**
@@ -491,8 +491,8 @@
*/
@Nullable
private static String parseUse(@NotNull final Element root) {
- final Node elem = XmlUtils.getChildOptional(root, Constants.XML_USE);
- return elem == null ? null : elem.getValue().trim();
+ final Elements elements = root.getChildElements(Constants.XML_USE);
+ return elements.size() == 0 ? null : elements.get(0).getValue().trim();
}
/**
Modified: trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParser.java
===================================================================
--- trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParser.java 2014-03-09 01:26:51 UTC (rev 9683)
+++ trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParser.java 2014-03-09 01:33:12 UTC (rev 9684)
@@ -28,6 +28,7 @@
import nu.xom.Attribute;
import nu.xom.Document;
import nu.xom.Element;
+import nu.xom.Elements;
import nu.xom.Node;
import org.apache.log4j.Category;
import org.apache.log4j.Logger;
@@ -75,7 +76,8 @@
parseBitmasks(archetypeTypeSet, XmlUtils.getChild(rootElement, Constants.XML_ELEMENT_BITMASKS), errorViewCollector);
parseLists(archetypeTypeSet, XmlUtils.getChild(rootElement, Constants.XML_ELEMENT_LISTS), errorViewCollector);
final IgnorelistsDefinition ignorelistsDefinition = parseIgnoreLists(XmlUtils.getChild(rootElement, Constants.XML_ELEMENT_IGNORELISTS), errorViewCollector);
- parseAttributeOrder(archetypeTypeSet, XmlUtils.getChildOptional(rootElement, Constants.XML_ELEMENT_ATTRIBUTE_ORDER), errorViewCollector);
+ final Elements attributeOrderElements = rootElement.getChildElements(Constants.XML_ELEMENT_ATTRIBUTE_ORDER);
+ parseAttributeOrder(archetypeTypeSet, attributeOrderElements.size() == 0 ? null : attributeOrderElements.get(0), errorViewCollector);
final ArchetypeType defaultArchetypeType = parseDefaultType(archetypeTypeSet, XmlUtils.getChild(rootElement, Constants.XML_ELEMENT_DEFAULT_TYPE), errorViewCollector, ignorelistsDefinition);
for (final Element element : new ElementsIterable(rootElement.getChildElements(Constants.XML_ELEMENT_TYPE))) {
Modified: trunk/src/utils/src/main/java/net/sf/gridarta/utils/XmlUtils.java
===================================================================
--- trunk/src/utils/src/main/java/net/sf/gridarta/utils/XmlUtils.java 2014-03-09 01:26:51 UTC (rev 9683)
+++ trunk/src/utils/src/main/java/net/sf/gridarta/utils/XmlUtils.java 2014-03-09 01:33:12 UTC (rev 9684)
@@ -22,7 +22,6 @@
import nu.xom.Element;
import nu.xom.Elements;
import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
/**
* XML related utility functions.
@@ -52,16 +51,4 @@
return elements.get(0);
}
- /**
- * Returns a child {@link Element} of a parent element.
- * @param parentElement the parent element
- * @param childName the name of the child element
- * @return the child element or {@code null}
- */
- @Nullable
- public static Element getChildOptional(@NotNull final Element parentElement, @NotNull final String childName) {
- final Elements elements = parentElement.getChildElements(childName);
- return elements.size() == 0 ? null : elements.get(0);
- }
-
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <aki...@us...> - 2014-03-09 01:26:58
|
Revision: 9683
http://sourceforge.net/p/gridarta/code/9683
Author: akirschbaum
Date: 2014-03-09 01:26:51 +0000 (Sun, 09 Mar 2014)
Log Message:
-----------
Fix parser for types.xml. [Atrinik, Daimonin]
Modified Paths:
--------------
trunk/src/model/src/test/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParserTest.java
trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java
trunk/src/utils/src/main/java/net/sf/gridarta/utils/xml/ParseUtils.java
Modified: trunk/src/model/src/test/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParserTest.java
===================================================================
--- trunk/src/model/src/test/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParserTest.java 2014-03-08 22:49:36 UTC (rev 9682)
+++ trunk/src/model/src/test/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParserTest.java 2014-03-09 01:26:51 UTC (rev 9683)
@@ -23,6 +23,8 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.net.URISyntaxException;
+import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -32,6 +34,7 @@
import net.sf.gridarta.model.errorview.TestErrorView;
import net.sf.gridarta.utils.xml.ParseUtils;
import nu.xom.ParsingException;
+import nu.xom.xinclude.XIncludeException;
import org.jetbrains.annotations.NotNull;
import org.junit.Assert;
import org.junit.Test;
@@ -60,9 +63,11 @@
* @throws IOException if the test fails
* @throws ParsingException if the test fails
* @throws SAXException if the test fails
+ * @throws URISyntaxException if the test fails
+ * @throws XIncludeException if the test fails
*/
@Test
- public void test1() throws IOException, ParsingException, SAXException {
+ public void test1() throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException {
check("test1");
}
@@ -71,9 +76,11 @@
* @throws IOException if the test fails
* @throws ParsingException if the test fails
* @throws SAXException if the test fails
+ * @throws URISyntaxException if the test fails
+ * @throws XIncludeException if the test fails
*/
@Test
- public void testImport1() throws IOException, ParsingException, SAXException {
+ public void testImport1() throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException {
check("import1");
}
@@ -82,9 +89,11 @@
* @throws IOException if the test fails
* @throws ParsingException if the test fails
* @throws SAXException if the test fails
+ * @throws URISyntaxException if the test fails
+ * @throws XIncludeException if the test fails
*/
@Test
- public void testImport2() throws IOException, ParsingException, SAXException {
+ public void testImport2() throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException {
check("import2");
}
@@ -93,9 +102,11 @@
* @throws IOException if the test fails
* @throws ParsingException if the test fails
* @throws SAXException if the test fails
+ * @throws URISyntaxException if the test fails
+ * @throws XIncludeException if the test fails
*/
@Test
- public void testIgnoreDefaultAttribute1() throws IOException, ParsingException, SAXException {
+ public void testIgnoreDefaultAttribute1() throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException {
check("ignoreDefaultAttribute1");
}
@@ -104,9 +115,11 @@
* @throws IOException if the test fails
* @throws ParsingException if the test fails
* @throws SAXException if the test fails
+ * @throws URISyntaxException if the test fails
+ * @throws XIncludeException if the test fails
*/
@Test
- public void testIgnoreImportAttribute1() throws IOException, ParsingException, SAXException {
+ public void testIgnoreImportAttribute1() throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException {
check("ignoreImportAttribute1");
}
@@ -115,9 +128,11 @@
* @throws IOException if the test fails
* @throws ParsingException if the test fails
* @throws SAXException if the test fails
+ * @throws URISyntaxException if the test fails
+ * @throws XIncludeException if the test fails
*/
@Test
- public void testIgnoreDefinedAttribute1() throws IOException, ParsingException, SAXException {
+ public void testIgnoreDefinedAttribute1() throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException {
check("ignoreDefinedAttribute1");
}
@@ -126,9 +141,11 @@
* @throws IOException if the test fails
* @throws ParsingException if the test fails
* @throws SAXException if the test fails
+ * @throws URISyntaxException if the test fails
+ * @throws XIncludeException if the test fails
*/
@Test
- public void testMsgDefault1() throws IOException, ParsingException, SAXException {
+ public void testMsgDefault1() throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException {
check("msgDefault1");
}
@@ -137,9 +154,11 @@
* @throws IOException if the test fails
* @throws ParsingException if the test fails
* @throws SAXException if the test fails
+ * @throws URISyntaxException if the test fails
+ * @throws XIncludeException if the test fails
*/
@Test
- public void testMsgDefault2() throws IOException, ParsingException, SAXException {
+ public void testMsgDefault2() throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException {
check("msgDefault2");
}
@@ -148,9 +167,11 @@
* @throws IOException if the test fails
* @throws ParsingException if the test fails
* @throws SAXException if the test fails
+ * @throws URISyntaxException if the test fails
+ * @throws XIncludeException if the test fails
*/
@Test
- public void testMsgDefault3() throws IOException, ParsingException, SAXException {
+ public void testMsgDefault3() throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException {
check("msgDefault3");
}
@@ -160,9 +181,11 @@
* @throws IOException if the test fails
* @throws ParsingException if the test fails
* @throws SAXException if the test fails
+ * @throws URISyntaxException if the test fails
+ * @throws XIncludeException if the test fails
*/
@Test
- public void testArchetypeOrder1() throws IOException, ParsingException, SAXException {
+ public void testArchetypeOrder1() throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException {
final ArchetypeTypeSet typeSet = loadArchetypeTypeSet("attributeOrder1");
Assert.assertFalse(errorView.hasErrors());
final List<String> keys = new ArrayList<String>(Arrays.asList("a", "b", "c", "d"));
@@ -175,9 +198,11 @@
* @throws IOException if the test fails
* @throws ParsingException if the test fails
* @throws SAXException if the test fails
+ * @throws URISyntaxException if the test fails
+ * @throws XIncludeException if the test fails
*/
@Test
- public void testArchetypeOrder2() throws IOException, ParsingException, SAXException {
+ public void testArchetypeOrder2() throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException {
final ArchetypeTypeSet typeSet = loadArchetypeTypeSet("attributeOrder2");
Assert.assertFalse(errorView.hasErrors());
final List<String> keys = new ArrayList<String>(Arrays.asList("a", "b", "c", "d"));
@@ -191,9 +216,11 @@
* @throws IOException if the test fails
* @throws ParsingException if the test fails
* @throws SAXException if the test fails
+ * @throws URISyntaxException if the test fails
+ * @throws XIncludeException if the test fails
*/
@Test
- public void testArchetypeOrder3() throws IOException, ParsingException, SAXException {
+ public void testArchetypeOrder3() throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException {
final ArchetypeTypeSet typeSet = loadArchetypeTypeSet("attributeOrder3");
Assert.assertFalse(errorView.hasErrors());
final List<String> keys = new ArrayList<String>(Arrays.asList("a", "b", "c", "d"));
@@ -207,9 +234,11 @@
* @throws IOException if the test fails
* @throws ParsingException if the test fails
* @throws SAXException if the test fails
+ * @throws URISyntaxException if the test fails
+ * @throws XIncludeException if the test fails
*/
@Test
- public void testArchetypeOrder4() throws IOException, ParsingException, SAXException {
+ public void testArchetypeOrder4() throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException {
final ArchetypeTypeSet typeSet = loadArchetypeTypeSet("attributeOrder4");
Assert.assertFalse(errorView.hasErrors());
final List<String> keys = new ArrayList<String>(Arrays.asList("a", "b", "c", "d"));
@@ -223,8 +252,10 @@
* @throws IOException if the test fails
* @throws ParsingException if the test fails
* @throws SAXException if the test fails
+ * @throws URISyntaxException if the test fails
+ * @throws XIncludeException if the test fails
*/
- private void check(@NotNull final String name) throws IOException, ParsingException, SAXException {
+ private void check(@NotNull final String name) throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException {
final ArchetypeTypeSet archetypeTypeSet = loadArchetypeTypeSet(name);
final InputStream is = getClass().getResourceAsStream("ArchetypeTypeSetParserTest-" + name + "-result.txt");
Assert.assertNotNull(is);
@@ -248,15 +279,17 @@
* @throws IOException if the file cannot be read
* @throws ParsingException if the file cannot be read
* @throws SAXException if the file cannot be read
+ * @throws URISyntaxException if the test fails
+ * @throws XIncludeException if the file cannot be read
*/
@NotNull
- private ArchetypeTypeSet loadArchetypeTypeSet(@NotNull final String name) throws IOException, ParsingException, SAXException {
+ private ArchetypeTypeSet loadArchetypeTypeSet(@NotNull final String name) throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException {
final ArchetypeTypeSetParser parser = createArchetypeTypeSetParser();
- final InputStream typesXml = getClass().getResourceAsStream("ArchetypeTypeSetParserTest-" + name + "-types.xml");
+ final URL typesXml = getClass().getResource("ArchetypeTypeSetParserTest-" + name + "-types.xml");
System.out.println("ArchetypeTypeSetParserTest-" + name + "-types.xml");
Assert.assertNotNull(typesXml);
- return parser.loadTypesFromXML(errorViewCollector, ParseUtils.readXmlStream(typesXml, "types", "types.dtd", "/system/dtd/types.dtd", null));
+ return parser.loadTypesFromXML(errorViewCollector, ParseUtils.readXmlUrl(typesXml, "types", "types.dtd", "/system/dtd/types.dtd", null));
}
/**
Modified: trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java
===================================================================
--- trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java 2014-03-08 22:49:36 UTC (rev 9682)
+++ trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java 2014-03-09 01:26:51 UTC (rev 9683)
@@ -22,6 +22,7 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.net.URISyntaxException;
import java.net.URL;
import java.util.Collections;
import java.util.Map;
@@ -111,6 +112,7 @@
import net.sf.japi.swing.action.ActionBuilderFactory;
import nu.xom.Document;
import nu.xom.ParsingException;
+import nu.xom.xinclude.XIncludeException;
import org.apache.log4j.Category;
import org.apache.log4j.Logger;
import org.jetbrains.annotations.NotNull;
@@ -269,6 +271,10 @@
errorView.addWarning(ErrorViewCategory.TYPES_FILE_INVALID, CommonConstants.TYPEDEF_FILE + ": " + ex.getMessage());
} catch (final SAXException ex) {
errorView.addWarning(ErrorViewCategory.TYPES_FILE_INVALID, CommonConstants.TYPEDEF_FILE + ": " + ex.getMessage());
+ } catch (final URISyntaxException ex) {
+ errorView.addWarning(ErrorViewCategory.TYPES_FILE_INVALID, CommonConstants.TYPEDEF_FILE + ": " + ex.getMessage());
+ } catch (final XIncludeException ex) {
+ errorView.addWarning(ErrorViewCategory.TYPES_FILE_INVALID, CommonConstants.TYPEDEF_FILE + ": " + ex.getMessage());
}
return new ArchetypeTypeSet();
}
@@ -319,6 +325,10 @@
gameObjectMatchersErrorViewCollector.addWarning(ErrorViewCategory.GAMEOBJECTMATCHERS_FILE_INVALID, ex.getMessage());
} catch (final SAXException ex) {
gameObjectMatchersErrorViewCollector.addWarning(ErrorViewCategory.GAMEOBJECTMATCHERS_FILE_INVALID, ex.getMessage());
+ } catch (final URISyntaxException ex) {
+ gameObjectMatchersErrorViewCollector.addWarning(ErrorViewCategory.GAMEOBJECTMATCHERS_FILE_INVALID, ex.getMessage());
+ } catch (final XIncludeException ex) {
+ gameObjectMatchersErrorViewCollector.addWarning(ErrorViewCategory.GAMEOBJECTMATCHERS_FILE_INVALID, ex.getMessage());
}
return gameObjectMatchers;
}
@@ -415,6 +425,10 @@
errorView.addWarning(ErrorViewCategory.SPELLS_FILE_INVALID, spellFile + ": " + ex.getMessage());
} catch (final SAXException ex) {
errorView.addWarning(ErrorViewCategory.SPELLS_FILE_INVALID, spellFile + ": " + ex.getMessage());
+ } catch (final URISyntaxException ex) {
+ errorView.addWarning(ErrorViewCategory.SPELLS_FILE_INVALID, spellFile + ": " + ex.getMessage());
+ } catch (final XIncludeException ex) {
+ errorView.addWarning(ErrorViewCategory.SPELLS_FILE_INVALID, spellFile + ": " + ex.getMessage());
}
numberSpells.sort();
return numberSpells;
@@ -438,6 +452,12 @@
} catch (final SAXException ex) {
treasureListsErrorViewCollector.addWarning(ErrorViewCategory.TREASURES_FILE_INVALID, ex.getMessage());
specialTreasureLists = Collections.emptyMap();
+ } catch (final URISyntaxException ex) {
+ treasureListsErrorViewCollector.addWarning(ErrorViewCategory.TREASURES_FILE_INVALID, ex.getMessage());
+ specialTreasureLists = Collections.emptyMap();
+ } catch (final XIncludeException ex) {
+ treasureListsErrorViewCollector.addWarning(ErrorViewCategory.TREASURES_FILE_INVALID, ex.getMessage());
+ specialTreasureLists = Collections.emptyMap();
}
} catch (final FileNotFoundException ex) {
errorView.addWarning(ErrorViewCategory.TREASURES_FILE_INVALID, "TreasureLists.xml: " + ex.getMessage());
Modified: trunk/src/utils/src/main/java/net/sf/gridarta/utils/xml/ParseUtils.java
===================================================================
--- trunk/src/utils/src/main/java/net/sf/gridarta/utils/xml/ParseUtils.java 2014-03-08 22:49:36 UTC (rev 9682)
+++ trunk/src/utils/src/main/java/net/sf/gridarta/utils/xml/ParseUtils.java 2014-03-09 01:26:51 UTC (rev 9683)
@@ -21,11 +21,14 @@
import java.io.IOException;
import java.io.InputStream;
+import java.net.URISyntaxException;
import java.net.URL;
import nu.xom.Builder;
import nu.xom.DocType;
import nu.xom.Document;
import nu.xom.ParsingException;
+import nu.xom.xinclude.XIncludeException;
+import nu.xom.xinclude.XIncluder;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.xml.sax.ErrorHandler;
@@ -58,12 +61,14 @@
* @throws IOException if the XML file cannot be read
* @throws ParsingException if parsing the XML file fails
* @throws SAXException the parsing the XML file fails
+ * @throws URISyntaxException if an include cannot be resolved
+ * @throws XIncludeException if parsing of the XML file fails
*/
@NotNull
- public static Document readXmlUrl(@NotNull final URL url, @NotNull final String rootElement, @NotNull final String systemId, @NotNull final String resourceName, @Nullable final ErrorHandler errorHandler) throws IOException, ParsingException, SAXException {
+ public static Document readXmlUrl(@NotNull final URL url, @NotNull final String rootElement, @NotNull final String systemId, @NotNull final String resourceName, @Nullable final ErrorHandler errorHandler) throws IOException, ParsingException, SAXException, URISyntaxException, XIncludeException {
final InputStream inputStream = url.openStream();
try {
- return readXmlStream(inputStream, rootElement, systemId, resourceName, errorHandler);
+ return readXmlStream(inputStream, url.toURI().toASCIIString(), rootElement, systemId, resourceName, errorHandler);
} finally {
inputStream.close();
}
@@ -72,6 +77,7 @@
/**
* Reads an XML file.
* @param inputStream the XML file to read
+ * @param baseURI the base URI for resolving includes
* @param rootElement the tag name of the root element in the DOCTYPE
* declaration
* @param systemId the system ID of the doctype declaration
@@ -82,9 +88,10 @@
* @throws IOException if the XML file cannot be read
* @throws ParsingException if parsing the XML file fails
* @throws SAXException the parsing the XML file fails
+ * @throws XIncludeException if parsing of the XML file fails
*/
@NotNull
- public static Document readXmlStream(@NotNull final InputStream inputStream, @NotNull final String rootElement, @NotNull final String systemId, @NotNull final String resourceName, @Nullable final ErrorHandler errorHandler) throws IOException, ParsingException, SAXException {
+ public static Document readXmlStream(@NotNull final InputStream inputStream, @NotNull final String baseURI, @NotNull final String rootElement, @NotNull final String systemId, @NotNull final String resourceName, @Nullable final ErrorHandler errorHandler) throws IOException, ParsingException, SAXException, XIncludeException {
final XMLReader xmlReader = XMLReaderFactory.createXMLReader();
xmlReader.setEntityResolver(new FixedDtdEntityResolver(systemId, resourceName));
if (errorHandler != null) {
@@ -94,7 +101,7 @@
final Document document;
final InputStream in2 = new FixedDtdInputStream(inputStream, rootElement, systemId);
try {
- document = builder.build(in2);
+ document = builder.build(in2, baseURI);
} finally {
in2.close();
}
@@ -114,6 +121,7 @@
if (!documentRootElement.equals(rootElement)) {
throw new ParsingException("root element in DOCTYPE declaration is '" + documentRootElement + "'; expecting '" + rootElement + "'");
}
+ XIncluder.resolveInPlace(document, builder);
return document;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <aki...@us...> - 2014-03-08 22:49:42
|
Revision: 9682
http://sourceforge.net/p/gridarta/code/9682
Author: akirschbaum
Date: 2014-03-08 22:49:36 +0000 (Sat, 08 Mar 2014)
Log Message:
-----------
Fix incorrect assert statement.
Modified Paths:
--------------
trunk/src/model/src/main/java/net/sf/gridarta/model/match/GameObjectMatcherParser.java
Modified: trunk/src/model/src/main/java/net/sf/gridarta/model/match/GameObjectMatcherParser.java
===================================================================
--- trunk/src/model/src/main/java/net/sf/gridarta/model/match/GameObjectMatcherParser.java 2014-03-08 22:40:13 UTC (rev 9681)
+++ trunk/src/model/src/main/java/net/sf/gridarta/model/match/GameObjectMatcherParser.java 2014-03-08 22:49:36 UTC (rev 9682)
@@ -175,7 +175,6 @@
@Nullable
private static String getLanguageTitle(@NotNull final Node el, @NotNull final String language) {
final Nodes nodes = el.query("title[lang('" + language + "')]");
- assert nodes.size() <= 1;
return nodes.size() == 0 ? null : nodes.get(0).getValue();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <aki...@us...> - 2014-03-08 22:40:18
|
Revision: 9681
http://sourceforge.net/p/gridarta/code/9681
Author: akirschbaum
Date: 2014-03-08 22:40:13 +0000 (Sat, 08 Mar 2014)
Log Message:
-----------
Rewrite parser for spells.xml.
Modified Paths:
--------------
trunk/src/model/src/main/java/net/sf/gridarta/model/spells/XMLSpellLoader.java
trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java
Removed Paths:
-------------
trunk/src/utils/src/main/java/net/sf/gridarta/utils/XmlHelper.java
Modified: trunk/src/model/src/main/java/net/sf/gridarta/model/spells/XMLSpellLoader.java
===================================================================
--- trunk/src/model/src/main/java/net/sf/gridarta/model/spells/XMLSpellLoader.java 2014-03-08 22:18:53 UTC (rev 9680)
+++ trunk/src/model/src/main/java/net/sf/gridarta/model/spells/XMLSpellLoader.java 2014-03-08 22:40:13 UTC (rev 9681)
@@ -19,20 +19,14 @@
package net.sf.gridarta.model.spells;
-import java.io.IOException;
-import java.net.URL;
-import java.util.Iterator;
-import javax.xml.parsers.DocumentBuilder;
import net.sf.gridarta.model.errorview.ErrorViewCategory;
import net.sf.gridarta.model.errorview.ErrorViewCollector;
-import net.sf.japi.xml.NodeListIterator;
+import net.sf.gridarta.utils.xml.ElementsIterable;
+import nu.xom.Document;
+import nu.xom.Element;
import org.apache.log4j.Category;
import org.apache.log4j.Logger;
import org.jetbrains.annotations.NotNull;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
/**
* Load spell definitions from an XML file.
@@ -55,49 +49,38 @@
/**
* Load an XML spell definitions file.
* @param errorViewCollector the error view collector for reporting errors
- * @param url the URL of the spell definitions file
- * @param documentBuilder the Document Builder to use for parsing
+ * @param document the document of the spell definitions file
* @param spells the {@code Spells} instance to add the spells to
*/
- public static void load(@NotNull final ErrorViewCollector errorViewCollector, @NotNull final URL url, @NotNull final DocumentBuilder documentBuilder, @NotNull final Spells<NumberSpell> spells) {
- try {
- final Document doc = documentBuilder.parse(new InputSource(url.toString()));
-
- // retrieve the spell data from the xml
- final Element root = doc.getDocumentElement();
- if (root == null || !"spells".equalsIgnoreCase(root.getNodeName())) {
- errorViewCollector.addWarning(ErrorViewCategory.SPELLS_ENTRY_INVALID, "root element 'spells' is missing");
- } else {
- // initialize array with appropriate size
- int numSpells = 0;
- final Iterator<Element> it = new NodeListIterator<Element>(root, "spell");
- while (it.hasNext()) {
- final Element spellElem = it.next();
- if (spellElem.getAttribute("id") == null) {
- errorViewCollector.addWarning(ErrorViewCategory.SPELLS_ENTRY_INVALID, "found 'spell' element without 'id'");
- } else if (spellElem.getAttribute("name") == null) {
- errorViewCollector.addWarning(ErrorViewCategory.SPELLS_ENTRY_INVALID, "found 'spell' element without 'name'");
- } else {
- try {
- // parse spell number and -name
- spells.add(new NumberSpell(spellElem.getAttribute("name").trim(), Integer.parseInt(spellElem.getAttribute("id"))));
- numSpells++;
- } catch (final NumberFormatException ignored) {
- errorViewCollector.addWarning(ErrorViewCategory.SPELLS_ENTRY_INVALID, "parsing error: spell id '" + spellElem.getAttribute("id") + "' is not an integer.");
- }
+ public static void load(@NotNull final ErrorViewCollector errorViewCollector, @NotNull final Document document, @NotNull final Spells<NumberSpell> spells) {
+ // retrieve the spell data from the xml
+ final Element root = document.getRootElement();
+ if (root == null || !root.getLocalName().equals("spells")) {
+ errorViewCollector.addWarning(ErrorViewCategory.SPELLS_ENTRY_INVALID, "root element 'spells' is missing");
+ } else {
+ // initialize array with appropriate size
+ int numSpells = 0;
+ for (final Element spellElem : new ElementsIterable(root.getChildElements("spell"))) {
+ if (spellElem.getAttribute("id") == null) {
+ errorViewCollector.addWarning(ErrorViewCategory.SPELLS_ENTRY_INVALID, "found 'spell' element without 'id'");
+ } else if (spellElem.getAttribute("name") == null) {
+ errorViewCollector.addWarning(ErrorViewCategory.SPELLS_ENTRY_INVALID, "found 'spell' element without 'name'");
+ } else {
+ try {
+ // parse spell number and -name
+ spells.add(new NumberSpell(spellElem.getAttribute("name").getValue().trim(), Integer.parseInt(spellElem.getAttribute("id").getValue())));
+ numSpells++;
+ } catch (final NumberFormatException ignored) {
+ errorViewCollector.addWarning(ErrorViewCategory.SPELLS_ENTRY_INVALID, "parsing error: spell id '" + spellElem.getAttribute("id") + "' is not an integer.");
}
}
+ }
- // loading successful
- LOG.info("Loaded " + numSpells + " defined spells from '" + url + "'");
- if (numSpells == 0) {
- errorViewCollector.addWarning(ErrorViewCategory.SPELLS_FILE_INVALID, "no content");
- }
+ // loading successful
+ LOG.info("Loaded " + numSpells + " defined spells.");
+ if (numSpells == 0) {
+ errorViewCollector.addWarning(ErrorViewCategory.SPELLS_FILE_INVALID, "no content");
}
- } catch (final SAXException ex) {
- errorViewCollector.addWarning(ErrorViewCategory.SPELLS_FILE_INVALID, "parsing error:" + ex.getMessage());
- } catch (final IOException ex) {
- errorViewCollector.addWarning(ErrorViewCategory.SPELLS_FILE_INVALID, ex.getMessage());
}
}
Modified: trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java
===================================================================
--- trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java 2014-03-08 22:18:53 UTC (rev 9680)
+++ trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java 2014-03-08 22:40:13 UTC (rev 9681)
@@ -25,9 +25,6 @@
import java.net.URL;
import java.util.Collections;
import java.util.Map;
-import java.util.MissingResourceException;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.ParserConfigurationException;
import net.sf.gridarta.model.anim.AnimationObjects;
import net.sf.gridarta.model.anim.DefaultAnimationObjects;
import net.sf.gridarta.model.archetype.Archetype;
@@ -109,7 +106,6 @@
import net.sf.gridarta.utils.IOUtils;
import net.sf.gridarta.utils.ResourceIcons;
import net.sf.gridarta.utils.StringUtils;
-import net.sf.gridarta.utils.XmlHelper;
import net.sf.gridarta.utils.xml.ParseUtils;
import net.sf.japi.swing.action.ActionBuilder;
import net.sf.japi.swing.action.ActionBuilderFactory;
@@ -209,16 +205,7 @@
public ProjectModel(@NotNull final ErrorView errorView, @NotNull final ProjectSettings projectSettings, @NotNull final ProjectFactory<G, A, R> projectFactory, @NotNull final ResourceIcons resourceIcons, @NotNull final ConfigSource configSource) {
this.projectSettings = projectSettings;
- final XmlHelper xmlHelper;
- try {
- xmlHelper = new XmlHelper();
- } catch (final ParserConfigurationException ex) {
- LOG.fatal("Cannot create XML parser: " + ex.getMessage());
- //noinspection ThrowInsideCatchBlockWhichIgnoresCaughtException
- throw new MissingResourceException("Cannot create XML parser: " + ex.getMessage(), null, null);
- }
-
- archetypeTypeSet = loadArchetypeTypeSet(errorView, projectSettings, xmlHelper);
+ archetypeTypeSet = loadArchetypeTypeSet(errorView, projectSettings);
final int doubleFaceOffset = projectFactory.getDoubleFaceOffset();
faceObjects = new DefaultFaceObjects(projectFactory.getIncludeFaceNumbers());
smoothFaces = new SmoothFaces(faceObjects);
@@ -255,7 +242,7 @@
mapManager = new DefaultMapManager<G, A, R>(mapReaderFactory, mapControlFactory, projectSettings, faceObjectProviders, pathManager);
pickmapManager = new DefaultPickmapManager<G, A, R>(mapReaderFactory, mapControlFactory, projectSettings, faceObjectProviders, pathManager);
gameObjectSpells = loadArchetypeSpells(projectFactory.getSpellType(), gameObjectFactory, archetypeSet);
- numberSpells = loadSpellFile(projectFactory.getSpellFile(), errorView, projectSettings, xmlHelper);
+ numberSpells = loadSpellFile(projectFactory.getSpellFile(), errorView, projectSettings);
scriptsFile = new File(projectSettings.getMapsDirectory(), projectFactory.getScriptsDir());
final Map<String, TreasureTreeNode> specialTreasureLists = loadSpecialTreasureLists(errorView, projectSettings);
treasureTree = TreasureLoader.parseTreasures(errorView, specialTreasureLists, configSource, projectSettings);
@@ -266,7 +253,7 @@
}
@NotNull
- private static ArchetypeTypeSet loadArchetypeTypeSet(@NotNull final ErrorView errorView, @NotNull final ProjectSettings projectSettings, @NotNull final XmlHelper xmlHelper) {
+ private static ArchetypeTypeSet loadArchetypeTypeSet(@NotNull final ErrorView errorView, @NotNull final ProjectSettings projectSettings) {
final ArchetypeAttributeFactory archetypeAttributeFactory = new DefaultArchetypeAttributeFactory();
final ArchetypeAttributeParser archetypeAttributeParser = new ArchetypeAttributeParser(archetypeAttributeFactory);
final ArchetypeTypeParser archetypeTypeParser = new ArchetypeTypeParser(archetypeAttributeParser);
@@ -411,7 +398,7 @@
}
@NotNull
- public static Spells<NumberSpell> loadSpellFile(@Nullable final String spellFile, @NotNull final ErrorView errorView, @NotNull final ProjectSettings projectSettings, @NotNull final XmlHelper xmlHelper) {
+ public static Spells<NumberSpell> loadSpellFile(@Nullable final String spellFile, @NotNull final ErrorView errorView, @NotNull final ProjectSettings projectSettings) {
@NotNull final Spells<NumberSpell> numberSpells = new Spells<NumberSpell>();
if (spellFile == null) {
return numberSpells;
@@ -420,15 +407,14 @@
try {
final URL url = IOUtils.getResource(projectSettings.getConfigurationDirectory(), spellFile);
final ErrorViewCollector errorViewCollector = new ErrorViewCollector(errorView, url);
- final DocumentBuilder documentBuilder = xmlHelper.getDocumentBuilder();
- documentBuilder.setErrorHandler(new ErrorViewCollectorErrorHandler(errorViewCollector, ErrorViewCategory.SPELLS_FILE_INVALID));
- try {
- XMLSpellLoader.load(errorViewCollector, url, documentBuilder, numberSpells);
- } finally {
- documentBuilder.setErrorHandler(null);
- }
- } catch (final FileNotFoundException ex) {
+ final Document document = ParseUtils.readXmlUrl(url, "spells", "spells.dtd", "/system/dtd/spells.dtd", new ErrorViewCollectorErrorHandler(errorViewCollector, ErrorViewCategory.SPELLS_FILE_INVALID));
+ XMLSpellLoader.load(errorViewCollector, document, numberSpells);
+ } catch (final IOException ex) {
errorView.addWarning(ErrorViewCategory.SPELLS_FILE_INVALID, spellFile + ": " + ex.getMessage());
+ } catch (final ParsingException ex) {
+ errorView.addWarning(ErrorViewCategory.SPELLS_FILE_INVALID, spellFile + ": " + ex.getMessage());
+ } catch (final SAXException ex) {
+ errorView.addWarning(ErrorViewCategory.SPELLS_FILE_INVALID, spellFile + ": " + ex.getMessage());
}
numberSpells.sort();
return numberSpells;
Deleted: trunk/src/utils/src/main/java/net/sf/gridarta/utils/XmlHelper.java
===================================================================
--- trunk/src/utils/src/main/java/net/sf/gridarta/utils/XmlHelper.java 2014-03-08 22:18:53 UTC (rev 9680)
+++ trunk/src/utils/src/main/java/net/sf/gridarta/utils/XmlHelper.java 2014-03-08 22:40:13 UTC (rev 9681)
@@ -1,114 +0,0 @@
-/*
- * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
- * Copyright (C) 2000-2010 The Gridarta Developers.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-package net.sf.gridarta.utils;
-
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.regex.Pattern;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-import org.xml.sax.EntityResolver;
-import org.xml.sax.InputSource;
-
-/**
- * Little helper class for XML that holds a {@link DocumentBuilder} that is
- * setup for Gridarta.
- * @author Andreas Kirschbaum
- */
-public class XmlHelper {
-
- /**
- * The {@link Pattern} for matching the directory part of a system ID.
- */
- @NotNull
- private static final Pattern PATTERN_DIRECTORY_PART = Pattern.compile(".*/");
-
- /**
- * DocumentBuilder.
- */
- private final DocumentBuilder documentBuilder;
-
- /**
- * Initialize the XML engine.
- * @throws ParserConfigurationException in case the xml parser couldn't be
- * set up
- */
- public XmlHelper() 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.setEntityResolver(new GridartaEntityResolver());
- }
-
- /**
- * Return the DocumentBuilder.
- * @return the document builder
- */
- public DocumentBuilder getDocumentBuilder() {
- return documentBuilder;
- }
-
- /**
- * Implements an {@link EntityResolver} for looking up built-in .dtd files.
- */
- private static class GridartaEntityResolver implements EntityResolver {
-
- @Nullable
- @Override
- public InputSource resolveEntity(final String publicId, final String systemId) throws IOException {
- if (systemId.endsWith(".xml")) {
- return null;
- }
-
- InputSource inputSource = null;
- final URL url = IOUtils.getResource(new File("system/dtd"), PATTERN_DIRECTORY_PART.matcher(systemId).replaceAll(""));
- final InputStream inputStream = url.openStream();
- try {
- final BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
- try {
- inputSource = new InputSource(bufferedInputStream);
- } finally {
- if (inputSource == null) {
- bufferedInputStream.close();
- }
- }
- } finally {
- if (inputSource == null) {
- inputStream.close();
- }
- }
- return inputSource;
- }
- }
-
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <aki...@us...> - 2014-03-08 22:18:58
|
Revision: 9680
http://sourceforge.net/p/gridarta/code/9680
Author: akirschbaum
Date: 2014-03-08 22:18:53 +0000 (Sat, 08 Mar 2014)
Log Message:
-----------
Rewrite parser for types.xml.
Modified Paths:
--------------
trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeAttributeParser.java
trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeParser.java
trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParser.java
trunk/src/model/src/test/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParserTest.java
trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java
trunk/src/utils/src/main/java/net/sf/gridarta/utils/XmlUtils.java
Modified: trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeAttributeParser.java
===================================================================
--- trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeAttributeParser.java 2014-03-08 22:17:01 UTC (rev 9679)
+++ trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeAttributeParser.java 2014-03-08 22:18:53 UTC (rev 9680)
@@ -22,11 +22,11 @@
import java.util.regex.Pattern;
import net.sf.gridarta.model.errorview.ErrorViewCategory;
import net.sf.gridarta.model.errorview.ErrorViewCollector;
+import nu.xom.Attribute;
+import nu.xom.Element;
+import nu.xom.Node;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
/**
* Utility class for parsing {@link ArchetypeAttribute ArchetypeAttributes}.
@@ -187,7 +187,7 @@
*/
@NotNull
private static String parseText(@NotNull final Node attributeElement) {
- final String tmp = attributeElement.getTextContent().trim();
+ final String tmp = attributeElement.getValue().trim();
return LINE_BREAK.matcher(tmp).replaceAll(tmp.startsWith("<html>") ? " " : "\n");
}
@@ -200,9 +200,9 @@
*/
@NotNull
private static String getAttributeValue(@NotNull final Element element, @NotNull final String attributeKey) throws MissingAttributeException {
- final Attr attr = element.getAttributeNode(attributeKey);
+ final Attribute attr = element.getAttribute(attributeKey);
if (attr == null) {
- throw new MissingAttributeException(element.getTagName(), attributeKey);
+ throw new MissingAttributeException(element.getLocalName(), attributeKey);
}
return attr.getValue().trim();
@@ -217,7 +217,7 @@
*/
@Nullable
private static String getAttributeValueOptional(@NotNull final Element element, @NotNull final String attributeKey) {
- final Attr attr = element.getAttributeNode(attributeKey);
+ final Attribute attr = element.getAttribute(attributeKey);
return attr == null ? null : attr.getValue().trim();
}
Modified: trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeParser.java
===================================================================
--- trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeParser.java 2014-03-08 22:17:01 UTC (rev 9679)
+++ trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeParser.java 2014-03-08 22:18:53 UTC (rev 9680)
@@ -21,19 +21,19 @@
import java.util.Collection;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.LinkedHashSet;
import net.sf.gridarta.model.errorview.ErrorViewCategory;
import net.sf.gridarta.model.errorview.ErrorViewCollector;
import net.sf.gridarta.utils.StringUtils;
-import net.sf.japi.xml.NodeListIterator;
+import net.sf.gridarta.utils.XmlUtils;
+import net.sf.gridarta.utils.xml.ElementsIterable;
+import nu.xom.Attribute;
+import nu.xom.Element;
+import nu.xom.Node;
import org.apache.log4j.Category;
import org.apache.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
/**
* Utility class for parsing {@link ArchetypeType} instances.
@@ -87,7 +87,8 @@
LOG.debug("loadAttributeList: " + typeName);
}
final int typeNo = parseTypeNo(typeElement, isDefaultType, typeName, errorViewCollector);
- final String display = typeElement.getAttribute(Constants.XML_TYPE_DISPLAY);
+ final Attribute typeElementAttribute = typeElement.getAttribute(Constants.XML_TYPE_DISPLAY);
+ final String display = typeElementAttribute == null ? "" : typeElementAttribute.getValue();
final boolean map = parseMap(typeElement);
final int[] inv = parseInv(typeElement, typeName, errorViewCollector);
final boolean allowsAllInv = parseAllowsAllInv(typeElement);
@@ -95,9 +96,7 @@
final ArchetypeAttributesDefinition typeAttributes = isDefaultType ? new ArchetypeAttributesDefinition() : parseTypeAttributes(typeElement, typeName, errorViewCollector, ignoreTable, ignorelistsDefinition);
final Collection<String> importTypes = new LinkedHashSet<String>();
- final Iterator<Element> importTypeIterator = new NodeListIterator<Element>(typeElement, Constants.XML_ELEMENT_IMPORT_TYPE);
- while (importTypeIterator.hasNext()) {
- final Element importTypeElement = importTypeIterator.next();
+ for (final Element importTypeElement : new ElementsIterable(typeElement.getChildElements(Constants.XML_ELEMENT_IMPORT_TYPE))) {
final String importType = parseImportType(importTypeElement, typeName, errorViewCollector);
if (importType != null && !importTypes.add(importType)) {
errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, "type " + typeName + " has duplicate import for '" + importType + "'.");
@@ -251,7 +250,7 @@
*/
@Nullable
private static String parseImportType(@NotNull final Element importTypeElement, @NotNull final String typeName, @NotNull final ErrorViewCollector errorViewCollector) {
- final Attr nameAttribute = importTypeElement.getAttributeNode(Constants.XML_IMPORT_TYPE_NAME);
+ final Attribute nameAttribute = importTypeElement.getAttribute(Constants.XML_IMPORT_TYPE_NAME);
if (nameAttribute == null) {
errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, "type " + typeName + " has " + Constants.XML_ELEMENT_IMPORT_TYPE + " element without '" + Constants.XML_IMPORT_TYPE_NAME + "'.");
return null;
@@ -275,7 +274,7 @@
*/
@NotNull
private static String parseTypeName(@NotNull final Element typeElement, final boolean isDefaultType) {
- return isDefaultType ? "default" : typeElement.getAttribute(Constants.XML_TYPE_NAME);
+ return isDefaultType ? "default" : typeElement.getAttribute(Constants.XML_TYPE_NAME).getValue();
}
/**
@@ -291,7 +290,7 @@
return -1;
}
- final String number = typeElement.getAttribute(Constants.XML_TYPE_NUMBER);
+ final String number = typeElement.getAttribute(Constants.XML_TYPE_NUMBER).getValue();
try {
return Integer.parseInt(number);
} catch (final NumberFormatException ignored) {
@@ -306,8 +305,8 @@
* @return whether this archetype is allowed on maps
*/
private static boolean parseMap(@NotNull final Element typeElement) {
- final String map = typeElement.getAttribute(Constants.XML_TYPE_MAP);
- return map.equals("yes");
+ final Attribute attribute = typeElement.getAttribute(Constants.XML_TYPE_MAP);
+ return attribute != null && attribute.getValue().equals("yes");
}
/**
@@ -320,11 +319,12 @@
*/
@Nullable
private static int[] parseInv(@NotNull final Element typeElement, @NotNull final String typeName, @NotNull final ErrorViewCollector errorViewCollector) {
- if (!typeElement.hasAttribute(Constants.XML_TYPE_INV)) {
+ final Attribute attribute = typeElement.getAttribute(Constants.XML_TYPE_INV);
+ if (attribute == null) {
return null;
}
- final String inv = typeElement.getAttribute(Constants.XML_TYPE_INV);
+ final String inv = attribute.getValue();
if (inv.isEmpty()) {
return EMPTY_INT_ARRAY;
}
@@ -351,8 +351,8 @@
* @return whether this archetype allows all inventory game objects
*/
private static boolean parseAllowsAllInv(@NotNull final Element typeElement) {
- final String allowsAllInv = typeElement.getAttribute(Constants.XML_TYPE_ALLOWS_ALL_INV);
- return allowsAllInv.equals("yes");
+ final Attribute attribute = typeElement.getAttribute(Constants.XML_TYPE_ALLOWS_ALL_INV);
+ return attribute != null && attribute.getValue().equals("yes");
}
/**
@@ -369,7 +369,7 @@
private static ArchetypeAttributesDefinition parseTypeAttributes(@NotNull final Element typeElement, @NotNull final String typeName, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final Collection<String> ignoreTable, @NotNull final IgnorelistsDefinition ignorelistsDefinition) {
final ArchetypeAttributesDefinition typeAttributes = parseRequiredAttribute(typeElement, typeName, errorViewCollector);
- final Element ignoreElement = NodeListIterator.getFirstChild(typeElement, Constants.XML_ELEMENT_IGNORE);
+ final Element ignoreElement = XmlUtils.getChildOptional(typeElement, Constants.XML_ELEMENT_IGNORE);
if (ignoreElement != null) {
parseAttributeAttributes(ignoreElement, typeName, errorViewCollector, ignoreTable);
parseIgnoreListAttribute(ignoreElement, typeName, errorViewCollector, ignoreTable, ignorelistsDefinition);
@@ -388,13 +388,10 @@
@NotNull
private static ArchetypeAttributesDefinition parseRequiredAttribute(@NotNull final Element typeElement, @NotNull final String typeName, @NotNull final ErrorViewCollector errorViewCollector) {
final ArchetypeAttributesDefinition attributes = new ArchetypeAttributesDefinition();
- final Element requiredElement = NodeListIterator.getFirstChild(typeElement, Constants.XML_ELEMENT_REQUIRED);
+ final Element requiredElement = XmlUtils.getChildOptional(typeElement, Constants.XML_ELEMENT_REQUIRED);
if (requiredElement != null) {
- final Iterator<Element> attributeIterator = new NodeListIterator<Element>(requiredElement, Constants.XML_ELEMENT_ATTRIBUTE);
- while (attributeIterator.hasNext()) {
- final Element attributeElement = attributeIterator.next();
-
- final Attr archAttribute = attributeElement.getAttributeNode(Constants.XML_ATTRIBUTE_ARCH);
+ for (final Element attributeElement : new ElementsIterable(requiredElement.getChildElements(Constants.XML_ELEMENT_ATTRIBUTE))) {
+ final Attribute archAttribute = attributeElement.getAttribute(Constants.XML_ATTRIBUTE_ARCH);
if (archAttribute == null) {
errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, Constants.XML_ELEMENT_REQUIRED + ": element of type " + typeName + ": " + Constants.XML_ELEMENT_ATTRIBUTE + " missing '" + Constants.XML_ATTRIBUTE_ARCH + "'.");
continue;
@@ -405,7 +402,7 @@
continue;
}
- final Attr valueAttribute = attributeElement.getAttributeNode(Constants.XML_ATTRIBUTE_VALUE);
+ final Attribute valueAttribute = attributeElement.getAttribute(Constants.XML_ATTRIBUTE_VALUE);
if (valueAttribute == null) {
errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, Constants.XML_ELEMENT_REQUIRED + ": element of type " + typeName + ": " + Constants.XML_ELEMENT_ATTRIBUTE + " missing '" + Constants.XML_ATTRIBUTE_VALUE + "'.");
continue;
@@ -430,11 +427,8 @@
* @param ignoreTable the ignore table to add to
*/
private static void parseAttributeAttributes(@NotNull final Element ignoreElement, @NotNull final String typeName, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final Collection<String> ignoreTable) {
- final Iterator<Element> attributeIterator = new NodeListIterator<Element>(ignoreElement, Constants.XML_ELEMENT_ATTRIBUTE);
- while (attributeIterator.hasNext()) {
- final Element attributeElement = attributeIterator.next();
-
- final Attr archAttribute = attributeElement.getAttributeNode(Constants.XML_ATTRIBUTE_ARCH);
+ for (final Element attributeElement : new ElementsIterable(ignoreElement.getChildElements(Constants.XML_ELEMENT_ATTRIBUTE))) {
+ final Attribute archAttribute = attributeElement.getAttribute(Constants.XML_ATTRIBUTE_ARCH);
if (archAttribute == null) {
errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, Constants.XML_ELEMENT_IGNORE + ": section of type " + typeName + ": " + Constants.XML_ELEMENT_ATTRIBUTE + " missing '" + Constants.XML_ATTRIBUTE_ARCH + "'.");
continue;
@@ -459,11 +453,8 @@
* @param ignorelistsDefinition the ignore lists to use
*/
private static void parseIgnoreListAttribute(@NotNull final Element ignoreElement, @NotNull final String typeName, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final Collection<String> ignoreTable, @NotNull final IgnorelistsDefinition ignorelistsDefinition) {
- final Iterator<Element> ignoreListIterator = new NodeListIterator<Element>(ignoreElement, Constants.XML_ELEMENT_IGNORE_LIST);
- while (ignoreListIterator.hasNext()) {
- final Element ignoreListElement = ignoreListIterator.next();
-
- final Attr nameAttribute = ignoreListElement.getAttributeNode(Constants.XML_IGNORE_LIST_NAME);
+ for (final Element ignoreListElement : new ElementsIterable(ignoreElement.getChildElements(Constants.XML_ELEMENT_IGNORE_LIST))) {
+ final Attribute nameAttribute = ignoreListElement.getAttribute(Constants.XML_IGNORE_LIST_NAME);
if (nameAttribute == null) {
errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, Constants.XML_ELEMENT_IGNORE + ": section of type " + typeName + ": " + Constants.XML_ELEMENT_IGNORE_LIST + " missing '" + Constants.XML_IGNORE_LIST_NAME + "'.");
continue;
@@ -489,8 +480,8 @@
*/
@Nullable
private static String parseDescription(@NotNull final Element root) {
- final Node elem = NodeListIterator.getFirstChild(root, Constants.XML_DESCRIPTION);
- return elem == null ? null : elem.getTextContent().trim();
+ final Node elem = XmlUtils.getChildOptional(root, Constants.XML_DESCRIPTION);
+ return elem == null ? null : elem.getValue().trim();
}
/**
@@ -500,8 +491,8 @@
*/
@Nullable
private static String parseUse(@NotNull final Element root) {
- final Node elem = NodeListIterator.getFirstChild(root, Constants.XML_USE);
- return elem == null ? null : elem.getTextContent().trim();
+ final Node elem = XmlUtils.getChildOptional(root, Constants.XML_USE);
+ return elem == null ? null : elem.getValue().trim();
}
/**
@@ -519,15 +510,13 @@
@NotNull
private Iterable<ArchetypeAttributeSection> addAttributeList(@NotNull final Element typeElement, @NotNull final ArchetypeAttributeSection defaultAttributeSection, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final String typeName, @NotNull final ArchetypeTypeSet archetypeTypeSet) {
final ArchetypeAttributeSections sections = new ArchetypeAttributeSections();
- final Iterator<Element> childIterator = new NodeListIterator<Element>(typeElement, Node.ELEMENT_NODE);
- while (childIterator.hasNext()) {
- final Element childElement = childIterator.next();
- final String childName = childElement.getNodeName();
+ for (final Element childElement : new ElementsIterable(typeElement.getChildElements())) {
+ final String childName = childElement.getLocalName();
if (childName.equals(Constants.XML_ELEMENT_ATTRIBUTE)) {
parseAttribute(childElement, errorViewCollector, typeName, archetypeTypeSet, sections, defaultAttributeSection.getSectionName());
- } else if (childName.equals(Constants.XML_ELEMENT_SECTION) && childElement.hasChildNodes()) {
- final Attr nameAttribute = childElement.getAttributeNode(Constants.XML_SECTION_NAME);
+ } else if (childName.equals(Constants.XML_ELEMENT_SECTION) && childElement.getChildElements().size() > 0) {
+ final Attribute nameAttribute = childElement.getAttribute(Constants.XML_SECTION_NAME);
if (nameAttribute == null) {
errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, "type " + typeName + " contains a " + Constants.XML_ELEMENT_SECTION + " missing '" + Constants.XML_SECTION_NAME + "'.");
continue;
@@ -539,9 +528,8 @@
continue;
}
- final Iterator<Element> attributeIterator = new NodeListIterator<Element>(childElement, Constants.XML_ELEMENT_ATTRIBUTE);
- while (attributeIterator.hasNext()) {
- parseAttribute(attributeIterator.next(), errorViewCollector, typeName, archetypeTypeSet, sections, sectionName);
+ for (final Element element : new ElementsIterable(childElement.getChildElements(Constants.XML_ELEMENT_ATTRIBUTE))) {
+ parseAttribute(element, errorViewCollector, typeName, archetypeTypeSet, sections, sectionName);
}
}
}
Modified: trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParser.java
===================================================================
--- trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParser.java 2014-03-08 22:17:01 UTC (rev 9679)
+++ trunk/src/model/src/main/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParser.java 2014-03-08 22:18:53 UTC (rev 9680)
@@ -19,25 +19,20 @@
package net.sf.gridarta.model.archetypetype;
-import java.io.IOException;
-import java.util.Iterator;
-import javax.xml.parsers.DocumentBuilder;
import net.sf.gridarta.model.errorview.ErrorViewCategory;
import net.sf.gridarta.model.errorview.ErrorViewCollector;
import net.sf.gridarta.utils.StringUtils;
import net.sf.gridarta.utils.SyntaxErrorException;
import net.sf.gridarta.utils.XmlUtils;
-import net.sf.japi.xml.NodeListIterator;
+import net.sf.gridarta.utils.xml.ElementsIterable;
+import nu.xom.Attribute;
+import nu.xom.Document;
+import nu.xom.Element;
+import nu.xom.Node;
import org.apache.log4j.Category;
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.w3c.dom.Node;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
/**
* Parser for {@link ArchetypeTypeSet ArchetypeTypeSets} ("types.xml" files).
@@ -53,12 +48,6 @@
private static final Category LOG = Logger.getLogger(ArchetypeTypeSetParser.class);
/**
- * The {@link DocumentBuilder} to use.
- */
- @NotNull
- private final DocumentBuilder documentBuilder;
-
- /**
* The {@link ArchetypeTypeParser} }to use.
*/
@NotNull
@@ -66,61 +55,35 @@
/**
* Creates a new instance.
- * @param documentBuilder the document builder to use
* @param archetypeTypeParser the archetype type parser to use
*/
- public ArchetypeTypeSetParser(@NotNull final DocumentBuilder documentBuilder, @NotNull final ArchetypeTypeParser archetypeTypeParser) {
- this.documentBuilder = documentBuilder;
+ public ArchetypeTypeSetParser(@NotNull final ArchetypeTypeParser archetypeTypeParser) {
this.archetypeTypeParser = archetypeTypeParser;
}
/**
* Loads a types.xml file.
* @param errorViewCollector the error view collector for reporting errors
- * @param inputSource the input source providing the contents of the
- * types.xml file
- * @return the loaded archetype types
- */
- @NotNull
- public ArchetypeTypeSet loadTypesFromXML(@NotNull final ErrorViewCollector errorViewCollector, @NotNull final InputSource inputSource) {
- final Document doc;
- try {
- doc = documentBuilder.parse(inputSource);
- } catch (final SAXException e) {
- errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, "parsing error: " + e.getMessage());
- return new ArchetypeTypeSet();
- } catch (final IOException e) {
- errorViewCollector.addWarning(ErrorViewCategory.TYPES_FILE_INVALID, e.getMessage());
- return new ArchetypeTypeSet();
- }
- return loadTypesFromXML(errorViewCollector, inputSource.getSystemId(), doc);
- }
-
- /**
- * Loads a types.xml file.
- * @param errorViewCollector the error view collector for reporting errors
- * @param filename the filename of the types.xml file for error messages
* @param document the document containing the contents of the types.xml
* file
* @return the loaded archetype types
*/
@NotNull
- public ArchetypeTypeSet loadTypesFromXML(@NotNull final ErrorViewCollector errorViewCollector, @NotNull final String filename, @NotNull final Document document) {
+ public ArchetypeTypeSet loadTypesFromXML(@NotNull final ErrorViewCollector errorViewCollector, @NotNull final Document document) {
final ArchetypeTypeSet archetypeTypeSet = new ArchetypeTypeSet();
- final Element rootElement = document.getDocumentElement();
+ final Element rootElement = document.getRootElement();
parseBitmasks(archetypeTypeSet, XmlUtils.getChild(rootElement, Constants.XML_ELEMENT_BITMASKS), errorViewCollector);
parseLists(archetypeTypeSet, XmlUtils.getChild(rootElement, Constants.XML_ELEMENT_LISTS), errorViewCollector);
final IgnorelistsDefinition ignorelistsDefinition = parseIgnoreLists(XmlUtils.getChild(rootElement, Constants.XML_ELEMENT_IGNORELISTS), errorViewCollector);
- parseAttributeOrder(archetypeTypeSet, NodeListIterator.getFirstChild(rootElement, Constants.XML_ELEMENT_ATTRIBUTE_ORDER), errorViewCollector);
+ parseAttributeOrder(archetypeTypeSet, XmlUtils.getChildOptional(rootElement, Constants.XML_ELEMENT_ATTRIBUTE_ORDER), errorViewCollector);
final ArchetypeType defaultArchetypeType = parseDefaultType(archetypeTypeSet, XmlUtils.getChild(rootElement, Constants.XML_ELEMENT_DEFAULT_TYPE), errorViewCollector, ignorelistsDefinition);
- final Iterator<Element> typeElements = new NodeListIterator<Element>(rootElement, Constants.XML_ELEMENT_TYPE);
- while (typeElements.hasNext()) {
- parseTypes(archetypeTypeSet, typeElements.next(), errorViewCollector, defaultArchetypeType, ignorelistsDefinition);
+ for (final Element element : new ElementsIterable(rootElement.getChildElements(Constants.XML_ELEMENT_TYPE))) {
+ parseTypes(archetypeTypeSet, element, errorViewCollector, defaultArchetypeType, ignorelistsDefinition);
}
if (LOG.isInfoEnabled()) {
- LOG.info("Loaded " + archetypeTypeSet.getArchetypeTypeCount() + " types from '" + filename + "\'");
+ LOG.info("Loaded " + archetypeTypeSet.getArchetypeTypeCount() + " types.");
}
return archetypeTypeSet;
}
@@ -133,11 +96,8 @@
* @param errorViewCollector the error view collector for reporting errors
*/
private static void parseBitmasks(@NotNull final ArchetypeTypeSet archetypeTypeSet, @NotNull final Element bitmasksElement, @NotNull final ErrorViewCollector errorViewCollector) {
- final Iterator<Element> bitmaskIterator = new NodeListIterator<Element>(bitmasksElement, Constants.XML_ELEMENT_BITMASK);
- while (bitmaskIterator.hasNext()) {
- final Element bitmaskElement = bitmaskIterator.next();
-
- final String name = bitmaskElement.getAttribute(Constants.XML_BITMASK_NAME);
+ for (final Element bitmaskElement : new ElementsIterable(bitmasksElement.getChildElements(Constants.XML_ELEMENT_BITMASK))) {
+ final String name = bitmaskElement.getAttribute(Constants.XML_BITMASK_NAME).getValue();
final AttributeBitmask attributeBitmask = parseBitmask(bitmaskElement, name, errorViewCollector);
if (attributeBitmask != null) {
archetypeTypeSet.addBitmask(name, attributeBitmask);
@@ -156,12 +116,11 @@
*/
@Nullable
private static AttributeBitmask parseBitmask(@NotNull final Element bitmaskElement, @NotNull final String name, @NotNull final ErrorViewCollector errorViewCollector) {
- final boolean isNamed = bitmaskElement.getAttribute(Constants.XML_BITMASK_IS_NAMED).equals("yes");
+ final boolean isNamed = bitmaskElement.getAttribute(Constants.XML_BITMASK_IS_NAMED).getValue().equals("yes");
final AttributeBitmask attributeBitmask = new AttributeBitmask(isNamed);
- final NodeListIterator<Element> entries = new NodeListIterator<Element>(bitmaskElement, Constants.XML_ELEMENT_BMENTRY);
- while (entries.hasNext()) {
- parseBmentry(entries.next(), errorViewCollector, name, isNamed, attributeBitmask);
+ for (final Element element : new ElementsIterable(bitmaskElement.getChildElements(Constants.XML_ELEMENT_BMENTRY))) {
+ parseBmentry(element, errorViewCollector, name, isNamed, attributeBitmask);
}
if (attributeBitmask.getNumber() <= 0) {
errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, name + ": no '" + Constants.XML_BMENTRY_BIT + "' entries");
@@ -191,15 +150,17 @@
* @param attributeBitmask the bitmask attribute to update
*/
private static void parseBmentry(@NotNull final Element bmentryElement, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final String bitmaskName, final boolean isNamed, @NotNull final AttributeBitmask attributeBitmask) {
- final String bitAttribute = bmentryElement.getAttribute(Constants.XML_BMENTRY_BIT);
+ final Attribute tmpBitAttribute = bmentryElement.getAttribute(Constants.XML_BMENTRY_BIT);
+ final String bitAttribute = tmpBitAttribute == null ? "" : tmpBitAttribute.getValue();
- final String valueAttribute = bmentryElement.getAttribute(Constants.XML_BMENTRY_VALUE);
- if (bitAttribute.length() != 0 && valueAttribute.length() != 0) {
+ final Attribute tmpValueAttribute = bmentryElement.getAttribute(Constants.XML_BMENTRY_VALUE);
+ final String valueAttribute = tmpValueAttribute == null ? "" : tmpValueAttribute.getValue();
+ if (!bitAttribute.isEmpty() && !valueAttribute.isEmpty()) {
errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, bitmaskName + ": element contains both '" + Constants.XML_BMENTRY_BIT + "' and '" + Constants.XML_BMENTRY_VALUE + "' attributes");
return;
}
- final String name = bmentryElement.getAttribute(Constants.XML_BMENTRY_NAME);
+ final String name = bmentryElement.getAttribute(Constants.XML_BMENTRY_NAME).getValue();
final int value;
if (bitAttribute.isEmpty()) {
@@ -234,7 +195,8 @@
attributeBitmask.addName(name, value);
- final String encoding = bmentryElement.getAttribute(Constants.XML_BMENTRY_ENCODING);
+ final Attribute tmpEncodingAttribute = bmentryElement.getAttribute(Constants.XML_BMENTRY_ENCODING);
+ final String encoding = tmpEncodingAttribute == null ? "" : tmpEncodingAttribute.getValue();
if (isNamed) {
if (encoding.isEmpty()) {
errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, bitmaskName + ": missing '" + Constants.XML_BMENTRY_ENCODING + "' attribute");
@@ -258,9 +220,8 @@
* @param errorViewCollector the error view collector for reporting errors
*/
private static void parseLists(@NotNull final ArchetypeTypeSet archetypeTypeSet, @NotNull final Element listsElement, @NotNull final ErrorViewCollector errorViewCollector) {
- final Iterator<Element> listIterator = new NodeListIterator<Element>(listsElement, Constants.XML_ELEMENT_LIST);
- while (listIterator.hasNext()) {
- parseList(archetypeTypeSet, listIterator.next(), errorViewCollector);
+ for (final Element element : new ElementsIterable(listsElement.getChildElements(Constants.XML_ELEMENT_LIST))) {
+ parseList(archetypeTypeSet, element, errorViewCollector);
}
}
@@ -273,11 +234,10 @@
*/
private static void parseList(@NotNull final ArchetypeTypeSet archetypeTypeSet, @NotNull final Element listElement, @NotNull final ErrorViewCollector errorViewCollector) {
final ArchetypeTypeList list = new ArchetypeTypeList();
- final Iterator<Element> listentryIterator = new NodeListIterator<Element>(listElement, Constants.XML_ELEMENT_LISTENTRY);
- while (listentryIterator.hasNext()) {
- parseListEntry(listentryIterator.next(), errorViewCollector, list);
+ for (final Element element : new ElementsIterable(listElement.getChildElements(Constants.XML_ELEMENT_LISTENTRY))) {
+ parseListEntry(element, errorViewCollector, list);
}
- final String name = listElement.getAttribute(Constants.XML_LIST_NAME);
+ final String name = listElement.getAttribute(Constants.XML_LIST_NAME).getValue();
archetypeTypeSet.addList(name, list);
}
@@ -289,8 +249,8 @@
* @param list the archetype type list to add to
*/
private static void parseListEntry(@NotNull final Element listentryElement, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final ArchetypeTypeList list) {
- final String name = listentryElement.getAttribute(Constants.XML_LISTENTRY_NAME);
- final String valueString = listentryElement.getAttribute(Constants.XML_LISTENTRY_VALUE);
+ final String name = listentryElement.getAttribute(Constants.XML_LISTENTRY_NAME).getValue();
+ final String valueString = listentryElement.getAttribute(Constants.XML_LISTENTRY_VALUE).getValue();
final int value;
try {
value = Integer.valueOf(valueString);
@@ -314,10 +274,9 @@
*/
@NotNull
private static IgnorelistsDefinition parseIgnoreLists(@NotNull final Element ignorelistsElement, @NotNull final ErrorViewCollector errorViewCollector) {
- final Iterator<Element> ignoreListIterator = new NodeListIterator<Element>(ignorelistsElement, Constants.XML_ELEMENT_IGNORE_LIST);
final IgnorelistsDefinition ignorelistsDefinition = new IgnorelistsDefinition();
- while (ignoreListIterator.hasNext()) {
- parseIgnoreList(ignoreListIterator.next(), errorViewCollector, ignorelistsDefinition);
+ for (final Element element : new ElementsIterable(ignorelistsElement.getChildElements(Constants.XML_ELEMENT_IGNORE_LIST))) {
+ parseIgnoreList(element, errorViewCollector, ignorelistsDefinition);
}
return ignorelistsDefinition;
}
@@ -331,7 +290,7 @@
*/
private static void parseAttributeOrder(@NotNull final ArchetypeTypeSet archetypeTypeSet, @Nullable final Node attributeOrderElement, @NotNull final ErrorViewCollector errorViewCollector) {
if (attributeOrderElement != null) {
- for (final String value : StringUtils.PATTERN_WHITESPACE_NEWLINE.split(attributeOrderElement.getTextContent())) {
+ for (final String value : StringUtils.PATTERN_WHITESPACE_NEWLINE.split(attributeOrderElement.getValue())) {
if (!value.isEmpty()) {
if (archetypeTypeSet.addAttributeOrder(value)) {
errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, value + ": duplicate attribute name");
@@ -349,15 +308,13 @@
* @param ignorelistsDefinition the ignore lists definition to update
*/
private static void parseIgnoreList(@NotNull final Element ignoreListElement, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final IgnorelistsDefinition ignorelistsDefinition) {
- final String name = ignoreListElement.getAttribute(Constants.XML_IGNORE_LIST_NAME);
+ final String name = ignoreListElement.getAttribute(Constants.XML_IGNORE_LIST_NAME).getValue();
if (ignorelistsDefinition.containsKey(name)) {
errorViewCollector.addWarning(ErrorViewCategory.TYPES_ENTRY_INVALID, name + ": duplicate name");
}
- final Iterator<Element> attributeIterator = new NodeListIterator<Element>(ignoreListElement, Constants.XML_ELEMENT_ATTRIBUTE);
- while (attributeIterator.hasNext()) {
- final Element attributeElement = attributeIterator.next();
- final Attr archAttribute = attributeElement.getAttributeNode(Constants.XML_ATTRIBUTE_ARCH);
+ for (final Element attributeElement : new ElementsIterable(ignoreListElement.getChildElements(Constants.XML_ELEMENT_ATTRIBUTE))) {
+ final Attribute archAttribute = attributeElement.getAttribute(Constants.XML_ATTRIBUTE_ARCH);
if (archAttribute != null) {
try {
ignorelistsDefinition.put(name, archAttribute.getValue());
@@ -401,7 +358,7 @@
* @param ignorelistsDefinition the contents of the "ignorelists" section
*/
private void parseTypes(@NotNull final ArchetypeTypeSet archetypeTypeSet, @NotNull final Element typeElement, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final ArchetypeType defaultArchetypeType, @NotNull final IgnorelistsDefinition ignorelistsDefinition) {
- if (!typeElement.getAttribute(Constants.XML_TYPE_AVAILABLE).equals("no")) {
+ if (!typeElement.getAttribute(Constants.XML_TYPE_AVAILABLE).getValue().equals("no")) {
archetypeTypeSet.addArchetypeType(archetypeTypeParser.loadAttributeList(typeElement, errorViewCollector, defaultArchetypeType, archetypeTypeSet, ignorelistsDefinition, false));
}
}
@@ -414,7 +371,7 @@
*/
private static void rejectAttributes(@NotNull final Element element, @NotNull final String... attributes) throws SyntaxErrorException {
for (final String attribute : attributes) {
- if (element.hasAttribute(attribute)) {
+ if (element.getAttribute(attribute) != null) {
throw new SyntaxErrorException("unexpected attribute '" + attribute + "'");
}
}
Modified: trunk/src/model/src/test/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParserTest.java
===================================================================
--- trunk/src/model/src/test/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParserTest.java 2014-03-08 22:17:01 UTC (rev 9679)
+++ trunk/src/model/src/test/java/net/sf/gridarta/model/archetypetype/ArchetypeTypeSetParserTest.java 2014-03-08 22:18:53 UTC (rev 9680)
@@ -27,15 +27,15 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
-import javax.xml.parsers.ParserConfigurationException;
import net.sf.gridarta.model.errorview.ErrorView;
import net.sf.gridarta.model.errorview.ErrorViewCollector;
import net.sf.gridarta.model.errorview.TestErrorView;
-import net.sf.gridarta.utils.XmlHelper;
+import net.sf.gridarta.utils.xml.ParseUtils;
+import nu.xom.ParsingException;
import org.jetbrains.annotations.NotNull;
import org.junit.Assert;
import org.junit.Test;
-import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
/**
* Regression tests for {@link ArchetypeTypeSetParser}.
@@ -57,101 +57,112 @@
/**
* Read a simple types.xml file.
- * @throws ParserConfigurationException if the test fails
* @throws IOException if the test fails
+ * @throws ParsingException if the test fails
+ * @throws SAXException if the test fails
*/
@Test
- public void test1() throws ParserConfigurationException, IOException {
+ public void test1() throws IOException, ParsingException, SAXException {
check("test1");
}
/**
* Checks that imports do work.
- * @throws ParserConfigurationException if the test fails
* @throws IOException if the test fails
+ * @throws ParsingException if the test fails
+ * @throws SAXException if the test fails
*/
@Test
- public void testImport1() throws ParserConfigurationException, IOException {
+ public void testImport1() throws IOException, ParsingException, SAXException {
check("import1");
}
/**
* Checks that multi-imports do work.
- * @throws ParserConfigurationException if the test fails
* @throws IOException if the test fails
+ * @throws ParsingException if the test fails
+ * @throws SAXException if the test fails
*/
@Test
- public void testImport2() throws ParserConfigurationException, IOException {
+ public void testImport2() throws IOException, ParsingException, SAXException {
check("import2");
}
/**
* Checks that ignoring default attributes do work.
- * @throws ParserConfigurationException if the test fails
* @throws IOException if the test fails
+ * @throws ParsingException if the test fails
+ * @throws SAXException if the test fails
*/
@Test
- public void testIgnoreDefaultAttribute1() throws ParserConfigurationException, IOException {
+ public void testIgnoreDefaultAttribute1() throws IOException, ParsingException, SAXException {
check("ignoreDefaultAttribute1");
}
/**
* Checks that ignoring import attributes do work.
- * @throws ParserConfigurationException if the test fails
* @throws IOException if the test fails
+ * @throws ParsingException if the test fails
+ * @throws SAXException if the test fails
*/
@Test
- public void testIgnoreImportAttribute1() throws ParserConfigurationException, IOException {
+ public void testIgnoreImportAttribute1() throws IOException, ParsingException, SAXException {
check("ignoreImportAttribute1");
}
/**
* Checks that ignoring defined attributes do work.
- * @throws ParserConfigurationException if the test fails
* @throws IOException if the test fails
+ * @throws ParsingException if the test fails
+ * @throws SAXException if the test fails
*/
@Test
- public void testIgnoreDefinedAttribute1() throws ParserConfigurationException, IOException {
+ public void testIgnoreDefinedAttribute1() throws IOException, ParsingException, SAXException {
check("ignoreDefinedAttribute1");
}
/**
* Checks that a "msg" field in default_type does work.
- * @throws ParserConfigurationException if the test fails
* @throws IOException if the test fails
+ * @throws ParsingException if the test fails
+ * @throws SAXException if the test fails
*/
@Test
- public void testMsgDefault1() throws ParserConfigurationException, IOException {
+ public void testMsgDefault1() throws IOException, ParsingException, SAXException {
check("msgDefault1");
}
/**
* Checks that a "msg" field in default_type does work.
- * @throws ParserConfigurationException if the test fails
* @throws IOException if the test fails
+ * @throws ParsingException if the test fails
+ * @throws SAXException if the test fails
*/
@Test
- public void testMsgDefault2() throws ParserConfigurationException, IOException {
+ public void testMsgDefault2() throws IOException, ParsingException, SAXException {
check("msgDefault2");
}
/**
* Checks that a "msg" field in default_type CAN BE "ignored".
- * @throws ParserConfigurationException if the test fails
* @throws IOException if the test fails
+ * @throws ParsingException if the test fails
+ * @throws SAXException if the test fails
*/
@Test
- public void testMsgDefault3() throws ParserConfigurationException, IOException {
+ public void testMsgDefault3() throws IOException, ParsingException, SAXException {
check("msgDefault3");
}
/**
* Checks that a "archetype_order" is parsed correctly: missing
* attribute_order element.
- * @throws ParserConfigurationException if the test fails
+ * @throws IOException if the test fails
+ * @throws ParsingException if the test fails
+ * @throws SAXException if the test fails
*/
@Test
- public void testArchetypeOrder1() throws ParserConfigurationException {
+ public void testArchetypeOrder1() throws IOException, ParsingException, SAXException {
final ArchetypeTypeSet typeSet = loadArchetypeTypeSet("attributeOrder1");
Assert.assertFalse(errorView.hasErrors());
final List<String> keys = new ArrayList<String>(Arrays.asList("a", "b", "c", "d"));
@@ -161,10 +172,12 @@
/**
* Checks that a "archetype_order" is parsed correctly: empty element.
- * @throws ParserConfigurationException if the test fails
+ * @throws IOException if the test fails
+ * @throws ParsingException if the test fails
+ * @throws SAXException if the test fails
*/
@Test
- public void testArchetypeOrder2() throws ParserConfigurationException {
+ public void testArchetypeOrder2() throws IOException, ParsingException, SAXException {
final ArchetypeTypeSet typeSet = loadArchetypeTypeSet("attributeOrder2");
Assert.assertFalse(errorView.hasErrors());
final List<String> keys = new ArrayList<String>(Arrays.asList("a", "b", "c", "d"));
@@ -175,10 +188,12 @@
/**
* Checks that a "archetype_order" is parsed correctly: all attributes
* specified.
- * @throws ParserConfigurationException if the test fails
+ * @throws IOException if the test fails
+ * @throws ParsingException if the test fails
+ * @throws SAXException if the test fails
*/
@Test
- public void testArchetypeOrder3() throws ParserConfigurationException {
+ public void testArchetypeOrder3() throws IOException, ParsingException, SAXException {
final ArchetypeTypeSet typeSet = loadArchetypeTypeSet("attributeOrder3");
Assert.assertFalse(errorView.hasErrors());
final List<String> keys = new ArrayList<String>(Arrays.asList("a", "b", "c", "d"));
@@ -189,10 +204,12 @@
/**
* Checks that a "archetype_order" is parsed correctly: some attributes
* missing.
- * @throws ParserConfigurationException if the test fails
+ * @throws IOException if the test fails
+ * @throws ParsingException if the test fails
+ * @throws SAXException if the test fails
*/
@Test
- public void testArchetypeOrder4() throws ParserConfigurationException {
+ public void testArchetypeOrder4() throws IOException, ParsingException, SAXException {
final ArchetypeTypeSet typeSet = loadArchetypeTypeSet("attributeOrder4");
Assert.assertFalse(errorView.hasErrors());
final List<String> keys = new ArrayList<String>(Arrays.asList("a", "b", "c", "d"));
@@ -203,10 +220,11 @@
/**
* Checks that a types.xml file can be read.
* @param name the base name of the resources to load
- * @throws ParserConfigurationException if the test fails
* @throws IOException if the test fails
+ * @throws ParsingException if the test fails
+ * @throws SAXException if the test fails
*/
- private void check(@NotNull final String name) throws ParserConfigurationException, IOException {
+ private void check(@NotNull final String name) throws IOException, ParsingException, SAXException {
final ArchetypeTypeSet archetypeTypeSet = loadArchetypeTypeSet(name);
final InputStream is = getClass().getResourceAsStream("ArchetypeTypeSetParserTest-" + name + "-result.txt");
Assert.assertNotNull(is);
@@ -227,33 +245,30 @@
* Loads a types.xml file from resources.
* @param name the base name of the resources to load
* @return the archetype type set
- * @throws ParserConfigurationException if the file cannot be read
+ * @throws IOException if the file cannot be read
+ * @throws ParsingException if the file cannot be read
+ * @throws SAXException if the file cannot be read
*/
@NotNull
- private ArchetypeTypeSet loadArchetypeTypeSet(@NotNull final String name) throws ParserConfigurationException {
+ private ArchetypeTypeSet loadArchetypeTypeSet(@NotNull final String name) throws IOException, ParsingException, SAXException {
final ArchetypeTypeSetParser parser = createArchetypeTypeSetParser();
final InputStream typesXml = getClass().getResourceAsStream("ArchetypeTypeSetParserTest-" + name + "-types.xml");
System.out.println("ArchetypeTypeSetParserTest-" + name + "-types.xml");
Assert.assertNotNull(typesXml);
- final InputSource inputSource = new InputSource(typesXml);
- inputSource.setSystemId("types.dtd");
-
- return parser.loadTypesFromXML(errorViewCollector, inputSource);
+ return parser.loadTypesFromXML(errorViewCollector, ParseUtils.readXmlStream(typesXml, "types", "types.dtd", "/system/dtd/types.dtd", null));
}
/**
* Creates a new {@link ArchetypeTypeSetParser} instance.
* @return the archetype type set parser instance
- * @throws ParserConfigurationException if the parser cannot be created
*/
@NotNull
- private static ArchetypeTypeSetParser createArchetypeTypeSetParser() throws ParserConfigurationException {
- final XmlHelper xmlHelper = new XmlHelper();
+ private static ArchetypeTypeSetParser createArchetypeTypeSetParser() {
final ArchetypeAttributeFactory archetypeAttributeFactory = new TestArchetypeAttributeFactory();
final ArchetypeAttributeParser archetypeAttributeParser = new ArchetypeAttributeParser(archetypeAttributeFactory);
final ArchetypeTypeParser archetypeTypeParser = new ArchetypeTypeParser(archetypeAttributeParser);
- return new ArchetypeTypeSetParser(xmlHelper.getDocumentBuilder(), archetypeTypeParser);
+ return new ArchetypeTypeSetParser(archetypeTypeParser);
}
}
Modified: trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java
===================================================================
--- trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java 2014-03-08 22:17:01 UTC (rev 9679)
+++ trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java 2014-03-08 22:18:53 UTC (rev 9680)
@@ -119,7 +119,6 @@
import org.apache.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
/**
@@ -274,15 +273,15 @@
try {
final URL url = IOUtils.getResource(projectSettings.getConfigurationDirectory(), CommonConstants.TYPEDEF_FILE);
final ErrorViewCollector typesErrorViewCollector = new ErrorViewCollector(errorView, url);
- xmlHelper.getDocumentBuilder().setErrorHandler(new ErrorViewCollectorErrorHandler(typesErrorViewCollector, ErrorViewCategory.GAMEOBJECTMATCHERS_FILE_INVALID));
- try {
- final ArchetypeTypeSetParser archetypeTypeSetParser = new ArchetypeTypeSetParser(xmlHelper.getDocumentBuilder(), archetypeTypeParser);
- return archetypeTypeSetParser.loadTypesFromXML(typesErrorViewCollector, new InputSource(url.toString()));
- } finally {
- xmlHelper.getDocumentBuilder().setErrorHandler(null);
- }
- } catch (final FileNotFoundException ex) {
+ final Document document = ParseUtils.readXmlUrl(url, "types", "types.dtd", "/system/dtd/types.dtd", new ErrorViewCollectorErrorHandler(typesErrorViewCollector, ErrorViewCategory.GAMEOBJECTMATCHERS_FILE_INVALID));
+ final ArchetypeTypeSetParser archetypeTypeSetParser = new ArchetypeTypeSetParser(archetypeTypeParser);
+ return archetypeTypeSetParser.loadTypesFromXML(typesErrorViewCollector, document);
+ } catch (final IOException ex) {
errorView.addWarning(ErrorViewCategory.TYPES_FILE_INVALID, CommonConstants.TYPEDEF_FILE + ": " + ex.getMessage());
+ } catch (final ParsingException ex) {
+ errorView.addWarning(ErrorViewCategory.TYPES_FILE_INVALID, CommonConstants.TYPEDEF_FILE + ": " + ex.getMessage());
+ } catch (final SAXException ex) {
+ errorView.addWarning(ErrorViewCategory.TYPES_FILE_INVALID, CommonConstants.TYPEDEF_FILE + ": " + ex.getMessage());
}
return new ArchetypeTypeSet();
}
Modified: trunk/src/utils/src/main/java/net/sf/gridarta/utils/XmlUtils.java
===================================================================
--- trunk/src/utils/src/main/java/net/sf/gridarta/utils/XmlUtils.java 2014-03-08 22:17:01 UTC (rev 9679)
+++ trunk/src/utils/src/main/java/net/sf/gridarta/utils/XmlUtils.java 2014-03-08 22:18:53 UTC (rev 9680)
@@ -19,9 +19,10 @@
package net.sf.gridarta.utils;
-import net.sf.japi.xml.NodeListIterator;
+import nu.xom.Element;
+import nu.xom.Elements;
import org.jetbrains.annotations.NotNull;
-import org.w3c.dom.Element;
+import org.jetbrains.annotations.Nullable;
/**
* XML related utility functions.
@@ -44,11 +45,23 @@
*/
@NotNull
public static Element getChild(@NotNull final Element parentElement, @NotNull final String childName) {
- final Element element = NodeListIterator.getFirstChild(parentElement, childName);
- if (element == null) {
+ final Elements elements = parentElement.getChildElements(childName);
+ if (elements.size() == 0) {
throw new IllegalArgumentException("child element '" + childName + "' does not exist");
}
- return element;
+ return elements.get(0);
}
+ /**
+ * Returns a child {@link Element} of a parent element.
+ * @param parentElement the parent element
+ * @param childName the name of the child element
+ * @return the child element or {@code null}
+ */
+ @Nullable
+ public static Element getChildOptional(@NotNull final Element parentElement, @NotNull final String childName) {
+ final Elements elements = parentElement.getChildElements(childName);
+ return elements.size() == 0 ? null : elements.get(0);
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <aki...@us...> - 2014-03-08 22:17:05
|
Revision: 9679
http://sourceforge.net/p/gridarta/code/9679
Author: akirschbaum
Date: 2014-03-08 22:17:01 +0000 (Sat, 08 Mar 2014)
Log Message:
-----------
Fix incorrect resource name.
Modified Paths:
--------------
trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java
Modified: trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java
===================================================================
--- trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java 2014-03-08 21:02:06 UTC (rev 9678)
+++ trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java 2014-03-08 22:17:01 UTC (rev 9679)
@@ -442,7 +442,7 @@
final URL url = IOUtils.getResource(projectSettings.getConfigurationDirectory(), "TreasureLists.xml");
final ErrorViewCollector treasureListsErrorViewCollector = new ErrorViewCollector(errorView, url);
try {
- final Document specialTreasureListsDocument = ParseUtils.readXmlUrl(url, "lists", "TreasureLists.dtd", "/sys/dtd/TreasureLists.dtd", new ErrorViewCollectorErrorHandler(treasureListsErrorViewCollector, ErrorViewCategory.TREASURES_FILE_INVALID));
+ final Document specialTreasureListsDocument = ParseUtils.readXmlUrl(url, "lists", "TreasureLists.dtd", "/system/dtd/TreasureLists.dtd", new ErrorViewCollectorErrorHandler(treasureListsErrorViewCollector, ErrorViewCategory.TREASURES_FILE_INVALID));
specialTreasureLists = TreasureListsParser.parseTreasureLists(specialTreasureListsDocument);
} catch (final IOException ex) {
treasureListsErrorViewCollector.addWarning(ErrorViewCategory.TREASURES_FILE_INVALID, ex.getMessage());
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <aki...@us...> - 2014-03-08 21:02:11
|
Revision: 9678
http://sourceforge.net/p/gridarta/code/9678
Author: akirschbaum
Date: 2014-03-08 21:02:06 +0000 (Sat, 08 Mar 2014)
Log Message:
-----------
Extract duplicated code into function.
Modified Paths:
--------------
trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java
trunk/src/utils/src/main/java/net/sf/gridarta/utils/xml/ParseUtils.java
Modified: trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java
===================================================================
--- trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java 2014-03-08 20:14:48 UTC (rev 9677)
+++ trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java 2014-03-08 21:02:06 UTC (rev 9678)
@@ -22,7 +22,6 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
-import java.io.InputStream;
import java.net.URL;
import java.util.Collections;
import java.util.Map;
@@ -326,13 +325,7 @@
}
final ErrorViewCollector gameObjectMatchersErrorViewCollector = new ErrorViewCollector(errorView, url);
try {
- final Document document;
- final InputStream inputStream = url.openStream();
- try {
- document = ParseUtils.readXmlStream(inputStream, "GameObjectMatchers", "GameObjectMatchers.dtd", "/system/dtd/GameObjectMatchers.dtd", new ErrorViewCollectorErrorHandler(gameObjectMatchersErrorViewCollector, ErrorViewCategory.GAMEOBJECTMATCHERS_FILE_INVALID));
- } finally {
- inputStream.close();
- }
+ final Document document = ParseUtils.readXmlUrl(url, "GameObjectMatchers", "GameObjectMatchers.dtd", "/system/dtd/GameObjectMatchers.dtd", new ErrorViewCollectorErrorHandler(gameObjectMatchersErrorViewCollector, ErrorViewCategory.GAMEOBJECTMATCHERS_FILE_INVALID));
GameObjectMatchersParser.readGameObjectMatchers(document, gameObjectMatchers, gameObjectMatchersErrorViewCollector);
} catch (final IOException ex) {
gameObjectMatchersErrorViewCollector.addWarning(ErrorViewCategory.GAMEOBJECTMATCHERS_FILE_INVALID, ex.getMessage());
@@ -449,13 +442,8 @@
final URL url = IOUtils.getResource(projectSettings.getConfigurationDirectory(), "TreasureLists.xml");
final ErrorViewCollector treasureListsErrorViewCollector = new ErrorViewCollector(errorView, url);
try {
- final InputStream inputStream = url.openStream();
- try {
- final Document specialTreasureListsDocument = ParseUtils.readXmlStream(inputStream, "lists", "TreasureLists.dtd", "/sys/dtd/TreasureLists.dtd", new ErrorViewCollectorErrorHandler(treasureListsErrorViewCollector, ErrorViewCategory.TREASURES_FILE_INVALID));
- specialTreasureLists = TreasureListsParser.parseTreasureLists(specialTreasureListsDocument);
- } finally {
- inputStream.close();
- }
+ final Document specialTreasureListsDocument = ParseUtils.readXmlUrl(url, "lists", "TreasureLists.dtd", "/sys/dtd/TreasureLists.dtd", new ErrorViewCollectorErrorHandler(treasureListsErrorViewCollector, ErrorViewCategory.TREASURES_FILE_INVALID));
+ specialTreasureLists = TreasureListsParser.parseTreasureLists(specialTreasureListsDocument);
} catch (final IOException ex) {
treasureListsErrorViewCollector.addWarning(ErrorViewCategory.TREASURES_FILE_INVALID, ex.getMessage());
specialTreasureLists = Collections.emptyMap();
Modified: trunk/src/utils/src/main/java/net/sf/gridarta/utils/xml/ParseUtils.java
===================================================================
--- trunk/src/utils/src/main/java/net/sf/gridarta/utils/xml/ParseUtils.java 2014-03-08 20:14:48 UTC (rev 9677)
+++ trunk/src/utils/src/main/java/net/sf/gridarta/utils/xml/ParseUtils.java 2014-03-08 21:02:06 UTC (rev 9678)
@@ -21,6 +21,7 @@
import java.io.IOException;
import java.io.InputStream;
+import java.net.URL;
import nu.xom.Builder;
import nu.xom.DocType;
import nu.xom.Document;
@@ -45,6 +46,30 @@
}
/**
+ * Reads an XML file from an {@link URL}.
+ * @param url the URL to read
+ * @param rootElement the tag name of the root element in the DOCTYPE
+ * declaration
+ * @param systemId the system ID of the doctype declaration
+ * @param resourceName the name of the resource that contains the DTD
+ * contents
+ * @param errorHandler the error handler to use or {@code null}
+ * @return the document for the XML file
+ * @throws IOException if the XML file cannot be read
+ * @throws ParsingException if parsing the XML file fails
+ * @throws SAXException the parsing the XML file fails
+ */
+ @NotNull
+ public static Document readXmlUrl(@NotNull final URL url, @NotNull final String rootElement, @NotNull final String systemId, @NotNull final String resourceName, @Nullable final ErrorHandler errorHandler) throws IOException, ParsingException, SAXException {
+ final InputStream inputStream = url.openStream();
+ try {
+ return readXmlStream(inputStream, rootElement, systemId, resourceName, errorHandler);
+ } finally {
+ inputStream.close();
+ }
+ }
+
+ /**
* Reads an XML file.
* @param inputStream the XML file to read
* @param rootElement the tag name of the root element in the DOCTYPE
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <aki...@us...> - 2014-03-08 20:14:53
|
Revision: 9677
http://sourceforge.net/p/gridarta/code/9677
Author: akirschbaum
Date: 2014-03-08 20:14:48 +0000 (Sat, 08 Mar 2014)
Log Message:
-----------
Rewrite parser for TreasureLists.xml.
Modified Paths:
--------------
trunk/src/model/src/main/java/net/sf/gridarta/model/treasurelist/TreasureListsParser.java
trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java
Modified: trunk/src/model/src/main/java/net/sf/gridarta/model/treasurelist/TreasureListsParser.java
===================================================================
--- trunk/src/model/src/main/java/net/sf/gridarta/model/treasurelist/TreasureListsParser.java 2014-03-08 19:53:12 UTC (rev 9676)
+++ trunk/src/model/src/main/java/net/sf/gridarta/model/treasurelist/TreasureListsParser.java 2014-03-08 20:14:48 UTC (rev 9677)
@@ -20,12 +20,11 @@
package net.sf.gridarta.model.treasurelist;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
-import net.sf.japi.xml.NodeListIterator;
+import net.sf.gridarta.utils.xml.ElementsIterable;
+import nu.xom.Document;
+import nu.xom.Element;
import org.jetbrains.annotations.NotNull;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
/**
* Utility class for loadings the TreasureLists.xml file.
@@ -51,21 +50,17 @@
public static Map<String, TreasureTreeNode> parseTreasureLists(@NotNull final Document specialTreasureListsDocument) {
final Map<String, TreasureTreeNode> specialTreasureLists = new HashMap<String, TreasureTreeNode>();
- final Element rootElement = specialTreasureListsDocument.getDocumentElement();
- assert rootElement != null && rootElement.getNodeName().equalsIgnoreCase("lists");
+ final Element rootElement = specialTreasureListsDocument.getRootElement();
+ assert rootElement != null && rootElement.getLocalName().equalsIgnoreCase("lists");
- final NodeListIterator<Element> it = new NodeListIterator<Element>(rootElement, "list");
- while (it.hasNext()) {
- final Element list = it.next();
- final String listName = list.getAttribute("name");
+ for (final Element list : new ElementsIterable(rootElement.getChildElements("list"))) {
+ final String listName = list.getAttribute("name").getValue();
assert listName != null;
final TreasureTreeNode folder = new TreasureTreeNode(new FolderTreasureObj(listName));
- final Iterator<Element> it2 = new NodeListIterator<Element>(list, "entry");
- while (it2.hasNext()) {
- final Element entry = it2.next();
- final String entryName = entry.getAttribute("name");
+ for (final Element entry : new ElementsIterable(list.getChildElements("entry"))) {
+ final String entryName = entry.getAttribute("name").getValue();
assert entryName != null;
specialTreasureLists.put(entryName, folder);
Modified: trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java
===================================================================
--- trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java 2014-03-08 19:53:12 UTC (rev 9676)
+++ trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java 2014-03-08 20:14:48 UTC (rev 9677)
@@ -114,12 +114,12 @@
import net.sf.gridarta.utils.xml.ParseUtils;
import net.sf.japi.swing.action.ActionBuilder;
import net.sf.japi.swing.action.ActionBuilderFactory;
+import nu.xom.Document;
import nu.xom.ParsingException;
import org.apache.log4j.Category;
import org.apache.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
@@ -259,7 +259,7 @@
gameObjectSpells = loadArchetypeSpells(projectFactory.getSpellType(), gameObjectFactory, archetypeSet);
numberSpells = loadSpellFile(projectFactory.getSpellFile(), errorView, projectSettings, xmlHelper);
scriptsFile = new File(projectSettings.getMapsDirectory(), projectFactory.getScriptsDir());
- final Map<String, TreasureTreeNode> specialTreasureLists = loadSpecialTreasureLists(errorView, xmlHelper.getDocumentBuilder(), projectSettings);
+ final Map<String, TreasureTreeNode> specialTreasureLists = loadSpecialTreasureLists(errorView, projectSettings);
treasureTree = TreasureLoader.parseTreasures(errorView, specialTreasureLists, configSource, projectSettings);
final NamedFilter defaultFilterList = new NamedFilter(Collections.<NamedGameObjectMatcher>emptyList());
final PluginParameterFactory<G, A, R> pluginParameterFactory = new PluginParameterFactory<G, A, R>(archetypeSet, mapManager, projectSettings, pathManager);
@@ -326,7 +326,7 @@
}
final ErrorViewCollector gameObjectMatchersErrorViewCollector = new ErrorViewCollector(errorView, url);
try {
- final nu.xom.Document document;
+ final Document document;
final InputStream inputStream = url.openStream();
try {
document = ParseUtils.readXmlStream(inputStream, "GameObjectMatchers", "GameObjectMatchers.dtd", "/system/dtd/GameObjectMatchers.dtd", new ErrorViewCollectorErrorHandler(gameObjectMatchersErrorViewCollector, ErrorViewCategory.GAMEOBJECTMATCHERS_FILE_INVALID));
@@ -443,7 +443,7 @@
}
@NotNull
- public static Map<String, TreasureTreeNode> loadSpecialTreasureLists(@NotNull final ErrorView errorView, @NotNull final DocumentBuilder documentBuilder, @NotNull final ProjectSettings projectSettings) {
+ public static Map<String, TreasureTreeNode> loadSpecialTreasureLists(@NotNull final ErrorView errorView, @NotNull final ProjectSettings projectSettings) {
Map<String, TreasureTreeNode> specialTreasureLists;
try {
final URL url = IOUtils.getResource(projectSettings.getConfigurationDirectory(), "TreasureLists.xml");
@@ -451,19 +451,17 @@
try {
final InputStream inputStream = url.openStream();
try {
- documentBuilder.setErrorHandler(new ErrorViewCollectorErrorHandler(treasureListsErrorViewCollector, ErrorViewCategory.TREASURES_FILE_INVALID));
- try {
- final Document specialTreasureListsDocument = documentBuilder.parse(new InputSource(inputStream));
- specialTreasureLists = TreasureListsParser.parseTreasureLists(specialTreasureListsDocument);
- } finally {
- documentBuilder.setErrorHandler(null);
- }
+ final Document specialTreasureListsDocument = ParseUtils.readXmlStream(inputStream, "lists", "TreasureLists.dtd", "/sys/dtd/TreasureLists.dtd", new ErrorViewCollectorErrorHandler(treasureListsErrorViewCollector, ErrorViewCategory.TREASURES_FILE_INVALID));
+ specialTreasureLists = TreasureListsParser.parseTreasureLists(specialTreasureListsDocument);
} finally {
inputStream.close();
}
} catch (final IOException ex) {
treasureListsErrorViewCollector.addWarning(ErrorViewCategory.TREASURES_FILE_INVALID, ex.getMessage());
specialTreasureLists = Collections.emptyMap();
+ } catch (final ParsingException ex) {
+ treasureListsErrorViewCollector.addWarning(ErrorViewCategory.TREASURES_FILE_INVALID, ex.getMessage());
+ specialTreasureLists = Collections.emptyMap();
} catch (final SAXException ex) {
treasureListsErrorViewCollector.addWarning(ErrorViewCategory.TREASURES_FILE_INVALID, ex.getMessage());
specialTreasureLists = Collections.emptyMap();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <aki...@us...> - 2014-03-08 19:53:18
|
Revision: 9676
http://sourceforge.net/p/gridarta/code/9676
Author: akirschbaum
Date: 2014-03-08 19:53:12 +0000 (Sat, 08 Mar 2014)
Log Message:
-----------
Rewrite parser for GameObjectMatchers.xml.
Modified Paths:
--------------
trunk/gridarta.ipr
trunk/src/model/build.gradle
trunk/src/model/model.iml
trunk/src/model/src/main/java/net/sf/gridarta/model/match/GameObjectMatcherParser.java
trunk/src/model/src/main/java/net/sf/gridarta/model/match/GameObjectMatchersParser.java
trunk/src/project/build.gradle
trunk/src/project/project.iml
trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java
trunk/src/utils/build.gradle
trunk/src/utils/src/main/java/net/sf/gridarta/utils/XmlHelper.java
trunk/src/utils/utils.iml
Added Paths:
-----------
trunk/repo/xom/
trunk/repo/xom/1.2.10/
trunk/repo/xom/1.2.10/xom-1.2.10.jar
trunk/repo/xom/1.2.10/xom-1.2.10.jar-LICENSE
trunk/src/utils/src/main/java/net/sf/gridarta/utils/xml/
trunk/src/utils/src/main/java/net/sf/gridarta/utils/xml/ElementsIterable.java
trunk/src/utils/src/main/java/net/sf/gridarta/utils/xml/ElementsIterator.java
trunk/src/utils/src/main/java/net/sf/gridarta/utils/xml/FixedDtdEntityResolver.java
trunk/src/utils/src/main/java/net/sf/gridarta/utils/xml/FixedDtdInputStream.java
trunk/src/utils/src/main/java/net/sf/gridarta/utils/xml/ParseUtils.java
Modified: trunk/gridarta.ipr
===================================================================
--- trunk/gridarta.ipr 2014-03-08 17:01:21 UTC (rev 9675)
+++ trunk/gridarta.ipr 2014-03-08 19:53:12 UTC (rev 9676)
@@ -2419,6 +2419,13 @@
<JAVADOC />
<SOURCES />
</library>
+ <library name="xom">
+ <CLASSES>
+ <root url="jar://$PROJECT_DIR$/repo/xom/1.2.10/xom-1.2.10.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
</component>
<component name="uidesigner-configuration">
<option name="INSTRUMENT_CLASSES" value="false" />
Added: trunk/repo/xom/1.2.10/xom-1.2.10.jar
===================================================================
(Binary files differ)
Index: trunk/repo/xom/1.2.10/xom-1.2.10.jar
===================================================================
--- trunk/repo/xom/1.2.10/xom-1.2.10.jar 2014-03-08 17:01:21 UTC (rev 9675)
+++ trunk/repo/xom/1.2.10/xom-1.2.10.jar 2014-03-08 19:53:12 UTC (rev 9676)
Property changes on: trunk/repo/xom/1.2.10/xom-1.2.10.jar
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Added: trunk/repo/xom/1.2.10/xom-1.2.10.jar-LICENSE
===================================================================
--- trunk/repo/xom/1.2.10/xom-1.2.10.jar-LICENSE (rev 0)
+++ trunk/repo/xom/1.2.10/xom-1.2.10.jar-LICENSE 2014-03-08 19:53:12 UTC (rev 9676)
@@ -0,0 +1,504 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL. It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+ This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it. You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations below.
+
+ When we speak of free software, we are referring to freedom of use,
+not price. Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+ To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights. These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+ For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you. You must make sure that they, too, receive or can get the source
+code. If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it. And you must show them these terms so they know their rights.
+
+ We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+ To protect each distributor, we want to make it very clear that
+there is no warranty for the free library. Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+
+ Finally, software patents pose a constant threat to the existence of
+any free program. We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder. Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+ Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License. This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License. We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+ When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library. The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom. The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+ We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License. It also provides other free software developers Less
+of an advantage over competing non-free programs. These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries. However, the Lesser license provides advantages in certain
+special circumstances.
+
+ For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it becomes
+a de-facto standard. To achieve this, non-free programs must be
+allowed to use the library. A more frequent case is that a free
+library does the same job as widely used non-free libraries. In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+ In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software. For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+ Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+ The precise terms and conditions for copying, distribution and
+modification follow. Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library". The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+
+ GNU LESSER GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+ A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+ The "Library", below, refers to any such software library or work
+which has been distributed under these terms. A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language. (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+ "Source code" for a work means the preferred form of the work for
+making modifications to it. For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+ Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it). Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+ 1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+ You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+
+ 2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) The modified work must itself be a software library.
+
+ b) You must cause the files modified to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ c) You must cause the whole of the work to be licensed at no
+ charge to all third parties under the terms of this License.
+
+ d) If a facility in the modified Library refers to a function or a
+ table of data to be supplied by an application program that uses
+ the facility, other than as an argument passed when the facility
+ is invoked, then you must make a good faith effort to ensure that,
+ in the event an application does not supply such function or
+ table, the facility still operates, and performs whatever part of
+ its purpose remains meaningful.
+
+ (For example, a function in a library to compute square roots has
+ a purpose that is entirely well-defined independent of the
+ application. Therefore, Subsection 2d requires that any
+ application-supplied function or table used by this function must
+ be optional: if the application does not supply it, the square
+ root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library. To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License. (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.) Do not make any other change in
+these notices.
+
+ Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+ This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+ 4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+ If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library". Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+ However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library". The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+ When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library. The
+threshold for this to be true is not precisely defined by law.
+
+ If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work. (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+ Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+ 6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+ You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License. You must supply a copy of this License. If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License. Also, you must do one
+of these things:
+
+ a) Accompany the work with the complete corresponding
+ machine-readable source code for the Library including whatever
+ changes were used in the work (which must be distributed under
+ Sections 1 and 2 above); and, if the work is an executable linked
+ with the Library, with the complete machine-readable "work that
+ uses the Library", as object code and/or source code, so that the
+ user can modify the Library and then relink to produce a modified
+ executable containing the modified Library. (It is understood
+ that the user who changes the contents of definitions files in the
+ Library will not necessarily be able to recompile the application
+ to use the modified definitions.)
+
+ b) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (1) uses at run time a
+ copy of the library already present on the user's computer system,
+ rather than copying library functions into the executable, and (2)
+ will operate properly with a modified version of the library, if
+ the user installs one, as long as the modified version is
+ interface-compatible with the version that the work was made with.
+
+ c) Accompany the work with a written offer, valid for at
+ least three years, to give the same user the materials
+ specified in Subsection 6a, above, for a charge no more
+ than the cost of performing this distribution.
+
+ d) If distribution of the work is made by offering access to copy
+ from a designated place, offer equivalent access to copy the above
+ specified materials from the same place.
+
+ e) Verify that the user has already received a copy of these
+ materials or that you have already sent this user a copy.
+
+ For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it. However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+ It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system. Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+ 7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+ a) Accompany the combined library with a copy of the same work
+ based on the Library, uncombined with any other library
+ facilities. This must be distributed under the terms of the
+ Sections above.
+
+ b) Give prominent notice with the combined library of the fact
+ that part of it is a work based on the Library, and explaining
+ where to find the accompanying uncombined form of the same work.
+
+ 8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License. Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License. However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+ 9. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Library or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+ 10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+
+ 11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all. For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded. In such case, this License incorporates the limitation as if
+written in the body of this License.
+
+ 13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation. If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+ 14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission. For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this. Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+ NO WARRANTY
+
+ 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Libraries
+
+ If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change. You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms of the
+ordinary General Public License).
+
+ To apply these terms, attach the following notices to the library. It is
+safest to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least the
+"copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the library's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the library, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the
+ library `Frob' (a library for tweaking knobs) written by James Random Hacker.
+
+ <signature of Ty Coon>, 1 April 1990
+ Ty Coon, President of Vice
+
+That's all there is to it!
+
+
Property changes on: trunk/repo/xom/1.2.10/xom-1.2.10.jar-LICENSE
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/src/model/build.gradle
===================================================================
--- trunk/src/model/build.gradle 2014-03-08 17:01:21 UTC (rev 9675)
+++ trunk/src/model/build.gradle 2014-03-08 19:53:12 UTC (rev 9676)
@@ -9,6 +9,7 @@
compile name: 'japi-lib-swing-misc', version: 'trunk-1398', group: 'japi-lib'
compile name: 'jdom', version: '1.0'
compile name: 'log4j', version: '1.2.13'
+ compile name: 'xom', version: '1.2.10'
compile project(':src:utils')
testCompile name: 'junit', version: '4.2'
testCompile project(':src:utils').sourceSets.test.output
Modified: trunk/src/model/model.iml
===================================================================
--- trunk/src/model/model.iml 2014-03-08 17:01:21 UTC (rev 9675)
+++ trunk/src/model/model.iml 2014-03-08 19:53:12 UTC (rev 9676)
@@ -20,6 +20,7 @@
<orderEntry type="library" name="jdom" level="project" />
<orderEntry type="library" name="junit" level="project" />
<orderEntry type="library" name="log4j" level="project" />
+ <orderEntry type="library" name="xom" level="project" />
</component>
</module>
Modified: trunk/src/model/src/main/java/net/sf/gridarta/model/match/GameObjectMatcherParser.java
===================================================================
--- trunk/src/model/src/main/java/net/sf/gridarta/model/match/GameObjectMatcherParser.java 2014-03-08 17:01:21 UTC (rev 9675)
+++ trunk/src/model/src/main/java/net/sf/gridarta/model/match/GameObjectMatcherParser.java 2014-03-08 19:53:12 UTC (rev 9676)
@@ -23,15 +23,12 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Locale;
-import javax.xml.xpath.XPath;
-import javax.xml.xpath.XPathConstants;
-import javax.xml.xpath.XPathExpressionException;
import net.sf.gridarta.utils.StringUtils;
+import nu.xom.Element;
+import nu.xom.Node;
+import nu.xom.Nodes;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
/**
* Class for some default {@link GameObjectMatcher GameObjectMatchers}.
@@ -124,17 +121,9 @@
private static final String XML_TYPENRS_ATTRIBUTE_NUMBERS = "numbers";
/**
- * {@link XPath} to use.
+ * Private constructor to prevent instantiation.
*/
- @NotNull
- private final XPath xpath;
-
- /**
- * Creates a {@code GameObjectMatcherParser}.
- * @param xpath the {@code XPath} to use
- */
- public GameObjectMatcherParser(@NotNull final XPath xpath) {
- this.xpath = xpath;
+ private GameObjectMatcherParser() {
}
/**
@@ -145,13 +134,13 @@
* @throws ParsingException if a parsing error occurs
*/
@NotNull
- public NamedGameObjectMatcher parseMatcher(@NotNull final Element el, final int editType) throws ParsingException {
+ public static NamedGameObjectMatcher parseMatcher(@NotNull final Element el, final int editType) throws ParsingException {
final String currentLanguage = Locale.getDefault().getLanguage();
final String localName = el.getLocalName();
if (localName == null || !localName.equals("GameObjectMatcher")) {
throw new ParsingException("wrong local element name: expected \"GameObjectMatcher\" but got \"" + localName + "\"");
}
- final String id = el.getAttribute(XML_MATCHER_ATTRIBUTE_ID);
+ final String id = el.getAttribute(XML_MATCHER_ATTRIBUTE_ID).getValue();
String title = getLanguageTitle(el, currentLanguage);
if (title == null || title.isEmpty()) {
title = getLanguageTitle(el, "en");
@@ -159,7 +148,7 @@
if (title == null || title.isEmpty()) {
title = id;
}
- final boolean systemMatcher = el.getAttribute(XML_MATCHER_ATTRIBUTE_SYSTEM).equals("true");
+ final boolean systemMatcher = el.getAttribute(XML_MATCHER_ATTRIBUTE_SYSTEM).getValue().equals("true");
final Node content = xpathEvaluate(el, "*[last()]");
assert content != null;
@@ -172,7 +161,7 @@
envGameObjectMatcher = null;
}
- assert content.getNodeType() == Node.ELEMENT_NODE;
+ //XXX:assert content.getNodeType() == Node.ELEMENT_NODE;
final GameObjectMatcher matcher = createMatcher((Element) content);
return new NamedGameObjectMatcher(systemMatcher ? 0 : editType, id, title, systemMatcher, envGameObjectMatcher, matcher);
}
@@ -184,12 +173,10 @@
* @return the title
*/
@Nullable
- private String getLanguageTitle(@NotNull final Node el, @NotNull final String language) {
- try {
- return (String) xpath.evaluate("title[lang('" + language + "')]", el, XPathConstants.STRING);
- } catch (final XPathExpressionException ex) {
- throw new AssertionError(ex);
- }
+ private static String getLanguageTitle(@NotNull final Node el, @NotNull final String language) {
+ final Nodes nodes = el.query("title[lang('" + language + "')]");
+ assert nodes.size() <= 1;
+ return nodes.size() == 0 ? null : nodes.get(0).getValue();
}
/**
@@ -249,10 +236,9 @@
@NotNull
private static Collection<GameObjectMatcher> getChildMatchers(@NotNull final Node el) throws ParsingException {
final Collection<GameObjectMatcher> childMatchers = new ArrayList<GameObjectMatcher>();
- final NodeList childNodes = el.getChildNodes();
- for (int i = 0; i < childNodes.getLength(); i++) {
- final Node childNode = childNodes.item(i);
- if (childNode.getNodeType() == Node.ELEMENT_NODE) {
+ for (int i = 0; i < el.getChildCount(); i++) {
+ final Node childNode = el.getChild(i);
+ if (childNode instanceof Element) {
childMatchers.add(createMatcher((Element) childNode));
}
}
@@ -267,11 +253,11 @@
*/
@NotNull
private static GameObjectMatcher createAttributeArchObjectMatcher(@NotNull final Element el) throws ParsingException {
- final String type = el.getAttribute(XML_ATTRIB_ATTRIBUTE_TYPE);
+ final String type = el.getAttribute(XML_ATTRIB_ATTRIBUTE_TYPE).getValue();
if (type.equals("string")) {
- return new StringAttributeGameObjectMatcher(el.getAttribute(XML_ATTRIB_ATTRIBUTE_NAME), Enum.valueOf(Operation.class, el.getAttribute(XML_ATTRIB_ATTRIBUTE_OP)), el.getAttribute(XML_ATTRIB_ATTRIBUTE_VALUE), Boolean.valueOf(el.getAttribute(XML_ATTRIB_ATTRIBUTE_USEARCHETYPE)));
+ return new StringAttributeGameObjectMatcher(el.getAttribute(XML_ATTRIB_ATTRIBUTE_NAME).getValue(), Enum.valueOf(Operation.class, el.getAttribute(XML_ATTRIB_ATTRIBUTE_OP).getValue()), el.getAttribute(XML_ATTRIB_ATTRIBUTE_VALUE).getValue(), el.getAttribute(XML_ATTRIB_ATTRIBUTE_USEARCHETYPE).getValue().equals("true"));
} else if (type.equals("int")) {
- return new IntAttributeGameObjectMatcher(el.getAttribute(XML_ATTRIB_ATTRIBUTE_NAME), Enum.valueOf(Operation.class, el.getAttribute(XML_ATTRIB_ATTRIBUTE_OP)), el.getAttribute(XML_ATTRIB_ATTRIBUTE_VALUE), Boolean.valueOf(el.getAttribute(XML_ATTRIB_ATTRIBUTE_USEARCHETYPE)));
+ return new IntAttributeGameObjectMatcher(el.getAttribute(XML_ATTRIB_ATTRIBUTE_NAME).getValue(), Enum.valueOf(Operation.class, el.getAttribute(XML_ATTRIB_ATTRIBUTE_OP).getValue()), el.getAttribute(XML_ATTRIB_ATTRIBUTE_VALUE).getValue(), el.getAttribute(XML_ATTRIB_ATTRIBUTE_USEARCHETYPE).getValue().equals("true"));
} else {
throw new AssertionError("impossible value '" + type + "' for XML_ATTRIB_ATTRIBUTE_TYPE");
}
@@ -285,7 +271,7 @@
*/
@NotNull
private static GameObjectMatcher createTypeNrsArchObjectMatcher(@NotNull final Element el) throws ParsingException {
- final CharSequence numbers = el.getAttribute(XML_TYPENRS_ATTRIBUTE_NUMBERS);
+ final CharSequence numbers = el.getAttribute(XML_TYPENRS_ATTRIBUTE_NUMBERS).getValue();
final String[] typeNrs = StringUtils.PATTERN_WHITESPACE.split(numbers, 0);
final int[] types = new int[typeNrs.length];
for (int i = 0; i < types.length; i++) {
@@ -306,12 +292,10 @@
* @return the result node
*/
@Nullable
- private Node xpathEvaluate(@NotNull final Node el, @NotNull final String xpathExpression) {
- try {
- return (Node) xpath.evaluate(xpathExpression, el, XPathConstants.NODE);
- } catch (final XPathExpressionException ex) {
- throw new AssertionError(ex);
- }
+ private static Node xpathEvaluate(@NotNull final Node el, @NotNull final String xpathExpression) {
+ final Nodes nodes = el.query(xpathExpression);
+ assert nodes.size() <= 1;
+ return nodes.size() == 0 ? null : nodes.get(0);
}
}
Modified: trunk/src/model/src/main/java/net/sf/gridarta/model/match/GameObjectMatchersParser.java
===================================================================
--- trunk/src/model/src/main/java/net/sf/gridarta/model/match/GameObjectMatchersParser.java 2014-03-08 17:01:21 UTC (rev 9675)
+++ trunk/src/model/src/main/java/net/sf/gridarta/model/match/GameObjectMatchersParser.java 2014-03-08 19:53:12 UTC (rev 9676)
@@ -19,21 +19,14 @@
package net.sf.gridarta.model.match;
-import java.io.IOException;
-import java.net.URL;
-import java.util.Iterator;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.xpath.XPath;
import net.sf.gridarta.model.errorview.ErrorViewCategory;
import net.sf.gridarta.model.errorview.ErrorViewCollector;
-import net.sf.japi.xml.NodeListIterator;
+import net.sf.gridarta.utils.xml.ElementsIterable;
+import nu.xom.Document;
+import nu.xom.Element;
import org.apache.log4j.Category;
import org.apache.log4j.Logger;
import org.jetbrains.annotations.NotNull;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
/**
* Parser for the GameObjectMatchers.xml file.
@@ -48,51 +41,25 @@
private static final Category LOG = Logger.getLogger(GameObjectMatchersParser.class);
/**
- * DocumentBuilder.
+ * Private constructor to prevent instantiation.
*/
- @NotNull
- private final DocumentBuilder documentBuilder;
-
- /**
- * The XPath for using XPath.
- */
- @NotNull
- private final XPath xpath;
-
- /**
- * Creates a new instance.
- * @param documentBuilder the {@code DocumentBuilder} to use for parsing
- * XML
- * @param xpath the XPath to use for applying for XPath expressions
- */
- public GameObjectMatchersParser(@NotNull final DocumentBuilder documentBuilder, @NotNull final XPath xpath) {
- this.documentBuilder = documentBuilder;
- this.xpath = xpath;
+ private GameObjectMatchersParser() {
}
/**
* Parses a .xml file defining game object matchers.
- * @param url the URL to parse
+ * @param document the document parse
* @param gameObjectMatchers the game object matchers to update
* @param errorViewCollector the error view collector to use
- * @throws IOException if the file cannot be parsed
*/
- public void readGameObjectMatchers(@NotNull final URL url, @NotNull final GameObjectMatchers gameObjectMatchers, @NotNull final ErrorViewCollector errorViewCollector) throws IOException {
- final GameObjectMatcherParser aom = new GameObjectMatcherParser(xpath);
- final Document doc;
- try {
- doc = documentBuilder.parse(new InputSource(url.toString()));
- } catch (final SAXException ex) {
- throw new IOException("sax exception: " + ex.getMessage(), ex);
- }
+ public static void readGameObjectMatchers(@NotNull final Document document, @NotNull final GameObjectMatchers gameObjectMatchers, @NotNull final ErrorViewCollector errorViewCollector) {
int count = 0;
int editType = 1;
- final Iterator<Element> it = new NodeListIterator<Element>(doc.getElementsByTagName("GameObjectMatcher"));
- while (it.hasNext()) {
- final Element node = it.next();
+ final Element rootElement = document.getRootElement();
+ for (final Element node : new ElementsIterable(rootElement.getChildElements("GameObjectMatcher"))) {
final NamedGameObjectMatcher archObjectMatcher;
try {
- archObjectMatcher = aom.parseMatcher(node, editType);
+ archObjectMatcher = GameObjectMatcherParser.parseMatcher(node, editType);
} catch (final ParsingException ex) {
errorViewCollector.addWarning(ErrorViewCategory.GAMEOBJECTMATCHERS_ENTRY_INVALID, node.getAttribute("id") + ": " + ex.getMessage());
continue;
@@ -107,7 +74,7 @@
}
}
if (LOG.isInfoEnabled()) {
- LOG.info("Loaded " + count + " GameObjectMatchers from '" + url + "'.");
+ LOG.info("Loaded " + count + " GameObjectMatchers.");
}
}
Modified: trunk/src/project/build.gradle
===================================================================
--- trunk/src/project/build.gradle 2014-03-08 17:01:21 UTC (rev 9675)
+++ trunk/src/project/build.gradle 2014-03-08 19:53:12 UTC (rev 9676)
@@ -6,6 +6,7 @@
compile name: 'annotations', version: '0.0'
compile name: 'japi-lib-swing-action', version: '0.1.0', group: 'japi-lib'
compile name: 'log4j', version: '1.2.13'
+ compile name: 'xom', version: '1.2.10'
compile project(':src:model')
compile project(':src:plugin')
compile project(':src:utils')
Modified: trunk/src/project/project.iml
===================================================================
--- trunk/src/project/project.iml 2014-03-08 17:01:21 UTC (rev 9675)
+++ trunk/src/project/project.iml 2014-03-08 19:53:12 UTC (rev 9676)
@@ -18,6 +18,7 @@
<orderEntry type="library" name="japi-lib-swing-action" level="project" />
<orderEntry type="library" name="log4j" level="project" />
<orderEntry type="library" name="junit" level="project" />
+ <orderEntry type="library" name="xom" level="project" />
</component>
</module>
Modified: trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java
===================================================================
--- trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java 2014-03-08 17:01:21 UTC (rev 9675)
+++ trunk/src/project/src/main/java/net/sf/gridarta/project/ProjectModel.java 2014-03-08 19:53:12 UTC (rev 9676)
@@ -111,8 +111,10 @@
import net.sf.gridarta.utils.ResourceIcons;
import net.sf.gridarta.utils.StringUtils;
import net.sf.gridarta.utils.XmlHelper;
+import net.sf.gridarta.utils.xml.ParseUtils;
import net.sf.japi.swing.action.ActionBuilder;
import net.sf.japi.swing.action.ActionBuilderFactory;
+import nu.xom.ParsingException;
import org.apache.log4j.Category;
import org.apache.log4j.Logger;
import org.jetbrains.annotations.NotNull;
@@ -246,7 +248,7 @@
mapReaderFactory = new DefaultMapReaderFactory<G, A, R>(mapArchObjectFactory, mapArchObjectParserFactory, gameObjectParserFactory);
final MapWriter<G, A, R> mapWriter = new DefaultMapWriter<G, A, R>(mapArchObjectParserFactory, gameObjectParser);
final ValidatorPreferences validatorPreferences = new DefaultValidatorPreferences();
- gameObjectMatchers = loadGameObjectMatchers(xmlHelper, errorView, projectSettings);
+ gameObjectMatchers = loadGameObjectMatchers(errorView, projectSettings);
validators = loadValidators(errorView, projectFactory, projectSettings, gameObjectMatchers, archetypeTypeSet, validatorPreferences, mapWriter);
final AutojoinLists<G, A, R> autojoinLists = AutojoinListsParser.loadList(errorView, archetypeSet, projectSettings.getConfigurationDirectory());
mapModelFactory = new MapModelFactory<G, A, R>(archetypeChooserModel, autojoinLists, gameObjectFactory, gameObjectMatchers, topmostInsertionMode);
@@ -313,26 +315,31 @@
}
@NotNull
- public static GameObjectMatchers loadGameObjectMatchers(@NotNull final XmlHelper xmlHelper, @NotNull final ErrorView errorView, @NotNull final ProjectSettings projectSettings) {
+ public static GameObjectMatchers loadGameObjectMatchers(@NotNull final ErrorView errorView, @NotNull final ProjectSettings projectSettings) {
final GameObjectMatchers gameObjectMatchers = new GameObjectMatchers();
final URL url;
try {
url = IOUtils.getResource(projectSettings.getConfigurationDirectory(), "GameObjectMatchers.xml");
- } catch (final FileNotFoundException ex) {
+ } catch (final IOException ex) {
errorView.addWarning(ErrorViewCategory.GAMEOBJECTMATCHERS_FILE_INVALID, "GameObjectMatchers.xml: " + ex.getMessage());
return gameObjectMatchers;
}
final ErrorViewCollector gameObjectMatchersErrorViewCollector = new ErrorViewCollector(errorView, url);
try {
- xmlHelper.getDocumentBuilder().setErrorHandler(new ErrorViewCollectorErrorHandler(gameObjectMatchersErrorViewCollector, ErrorViewCategory.GAMEOBJECTMATCHERS_FILE_INVALID));
+ final nu.xom.Document document;
+ final InputStream inputStream = url.openStream();
try {
- final GameObjectMatchersParser gameObjectMatchersParser = new GameObjectMatchersParser(xmlHelper.getDocumentBuilder(), xmlHelper.getXPath());
- gameObjectMatchersParser.readGameObjectMatchers(url, gameObjectMatchers, gameObjectMatchersErrorViewCollector);
+ document = ParseUtils.readXmlStream(inputStream, "GameObjectMatchers", "GameObjectMatchers.dtd", "/system/dtd/GameObjectMatchers.dtd", new ErrorViewCollectorErrorHandler(gameObjectMatchersErrorViewCollector, ErrorViewCategory.GAMEOBJECTMATCHERS_FILE_INVALID));
} finally {
- xmlHelper.getDocumentBuilder().setErrorHandler(null);
+ inputStream.close();
}
+ GameObjectMatchersParser.readGameObjectMatchers(document, gameObjectMatchers, gameObjectMatchersErrorViewCollector);
} catch (final IOException ex) {
gameObjectMatchersErrorViewCollector.addWarning(ErrorViewCategory.GAMEOBJECTMATCHERS_FILE_INVALID, ex.getMessage());
+ } catch (final ParsingException ex) {
+ gameObjectMatchersErrorViewCollector.addWarning(ErrorViewCategory.GAMEOBJECTMATCHERS_FILE_INVALID, ex.getMessage());
+ } catch (final SAXException ex) {
+ gameObjectMatchersErrorViewCollector.addWarning(ErrorViewCategory.GAMEOBJECTMATCHERS_FILE_INVALID, ex.getMessage());
}
return gameObjectMatchers;
}
Modified: trunk/src/utils/build.gradle
===================================================================
--- trunk/src/utils/build.gradle 2014-03-08 17:01:21 UTC (rev 9675)
+++ trunk/src/utils/build.gradle 2014-03-08 19:53:12 UTC (rev 9676)
@@ -8,5 +8,6 @@
compile name: 'japi-lib-util', version: 'trunk-1410', group: 'japi-lib'
compile name: 'japi-lib-xml', version: '0.1.0', group: 'japi-lib'
compile name: 'log4j', version: '1.2.13'
+ compile name: 'xom', version: '1.2.10'
testCompile name: 'junit', version: '4.2'
}
Modified: trunk/src/utils/src/main/java/net/sf/gridarta/utils/XmlHelper.java
===================================================================
--- trunk/src/utils/src/main/java/net/sf/gridarta/utils/XmlHelper.java 2014-03-08 17:01:21 UTC (rev 9675)
+++ trunk/src/utils/src/main/java/net/sf/gridarta/utils/XmlHelper.java 2014-03-08 19:53:12 UTC (rev 9676)
@@ -28,16 +28,14 @@
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.xpath.XPath;
-import javax.xml.xpath.XPathFactory;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
/**
- * Little helper class for XML, holds a {@link DocumentBuilder} and an {@link
- * XPath} that are setup for Gridarta.
+ * Little helper class for XML that holds a {@link DocumentBuilder} that is
+ * setup for Gridarta.
* @author Andreas Kirschbaum
*/
public class XmlHelper {
@@ -54,11 +52,6 @@
private final DocumentBuilder documentBuilder;
/**
- * The XPath for using XPath.
- */
- private final XPath xpath;
-
- /**
* Initialize the XML engine.
* @throws ParserConfigurationException in case the xml parser couldn't be
* set up
@@ -75,7 +68,6 @@
dbf.setXIncludeAware(true);
documentBuilder = dbf.newDocumentBuilder();
documentBuilder.setEntityResolver(new GridartaEntityResolver());
- xpath = XPathFactory.newInstance().newXPath();
}
/**
@@ -87,14 +79,6 @@
}
/**
- * Return the XPath for using XPath.
- * @return the XPath
- */
- public XPath getXPath() {
- return xpath;
- }
-
- /**
* Implements an {@link EntityResolver} for looking up built-in .dtd files.
*/
private static class GridartaEntityResolver implements EntityResolver {
Added: trunk/src/utils/src/main/java/net/sf/gridarta/utils/xml/ElementsIterable.java
===================================================================
--- trunk/src/utils/src/main/java/net/sf/gridarta/utils/xml/ElementsIterable.java (rev 0)
+++ trunk/src/utils/src/main/java/net/sf/gridarta/utils/xml/ElementsIterable.java 2014-03-08 19:53:12 UTC (rev 9676)
@@ -0,0 +1,48 @@
+/*
+ * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
+ * Copyright (C) 2000-2011 The Gridarta Developers.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package net.sf.gridarta.utils.xml;
+
+import java.util.Iterator;
+import nu.xom.Element;
+import nu.xom.Elements;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * @author Andreas Kirschbaum
+ */
+public class ElementsIterable implements Iterable<Element> {
+
+ @NotNull
+ private final Elements elements;
+
+ public ElementsIterable(@NotNull final Elements elements) {
+ this.elements = elements;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @NotNull
+ @Override
+ public Iterator<Element> iterator() {
+ return new ElementsIterator(elements);
+ }
+
+}
Property changes on: trunk/src/utils/src/main/java/net/sf/gridarta/utils/xml/ElementsIterable.java
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: trunk/src/utils/src/main/java/net/sf/gridarta/utils/xml/ElementsIterator.java
===================================================================
--- trunk/src/utils/src/main/java/net/sf/gridarta/utils/xml/ElementsIterator.java (rev 0)
+++ trunk/src/utils/src/main/java/net/sf/gridarta/utils/xml/ElementsIterator.java 2014-03-08 19:53:12 UTC (rev 9676)
@@ -0,0 +1,69 @@
+/*
+ * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
+ * Copyright (C) 2000-2011 The Gridarta Developers.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package net.sf.gridarta.utils.xml;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+import nu.xom.Element;
+import nu.xom.Elements;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * @author Andreas Kirschbaum
+ */
+public class ElementsIterator implements Iterator<Element> {
+
+ @NotNull
+ private final Elements elements;
+
+ private int pos;
+
+ public ElementsIterator(@NotNull final Elements elements) {
+ this.elements = elements;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean hasNext() {
+ return pos < elements.size();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Element next() {
+ if (pos >= elements.size()) {
+ throw new NoSuchElementException();
+ }
+ return elements.get(pos++);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+}
Property changes on: trunk/src/utils/src/main/java/net/sf/gridarta/utils/xml/ElementsIterator.java
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: trunk/src/utils/src/main/java/net/sf/gridarta/utils/xml/FixedDtdEntityResolver.java
===================================================================
--- trunk/src/utils/src/main/java/net/sf/gridarta/utils/xml/FixedDtdEntityResolver.java (rev 0)
+++ trunk/src/utils/src/main/java/net/sf/gridarta/utils/xml/FixedDtdEntityResolver.java 2014-03-08 19:53:12 UTC (rev 9676)
@@ -0,0 +1,57 @@
+package net.sf.gridarta.utils.xml;
+
+import java.io.IOException;
+import java.io.InputStream;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+/**
+ * An {@code EntityResolver} that rejects all entities except for a given DTD.
+ * This DTD is resolved against a resource.
+ * @author Andreas Kirschbaum
+ */
+public class FixedDtdEntityResolver implements EntityResolver {
+
+ /**
+ * The expected system ID.
+ */
+ @NotNull
+ private final String systemId;
+
+ /**
+ * The name of the resource to return for {@link #systemId}.
+ */
+ @NotNull
+ private final String resourceName;
+
+ /**
+ * Creates a new instance.
+ * @param systemId the expected system ID
+ * @param resourceName the name of the resource to return for {@code
+ * systemId}
+ */
+ public FixedDtdEntityResolver(@NotNull final String systemId, @NotNull final String resourceName) {
+ this.systemId = systemId;
+ this.resourceName = resourceName;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @NotNull
+ @Override
+ public InputSource resolveEntity(@Nullable final String publicId, @NotNull final String systemId) throws SAXException, IOException {
+ if (!systemId.equals(this.systemId) && !systemId.endsWith("/" + this.systemId)) {
+ throw new SAXException("unsupported system ID '" + systemId + "'");
+ }
+ final InputStream inputStream = FixedDtdEntityResolver.class.getResourceAsStream(resourceName);
+ if (inputStream == null) {
+ throw new IOException("the resource '" + resourceName + "' does not exist");
+ }
+ return new InputSource(inputStream);
+ }
+
+}
Property changes on: trunk/src/utils/src/main/java/net/sf/gridarta/utils/xml/FixedDtdEntityResolver.java
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: trunk/src/utils/src/main/java/net/sf/gridarta/utils/xml/FixedDtdInputStream.java
===================================================================
--- trunk/src/utils/src/main/java/net/sf/gridarta/utils/xml/FixedDtdInputStream.java (rev 0)
+++ trunk/src/utils/src/main/java/net/sf/gridarta/utils/xml/FixedDtdInputStream.java 2014-03-08 19:53:12 UTC (rev 9676)
@@ -0,0 +1,199 @@
+/*
+ * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
+ * Copyright (C) 2000-2011 The Gridarta Developers.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package net.sf.gridarta.utils.xml;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Injects a <!DOCTYPE...> declaration into an {@code InputStream} if it
+ * does not contain one. The input stream should contain XML.
+ * @author Andreas Kirschbaum
+ */
+public class FixedDtdInputStream extends InputStream {
+
+ /**
+ * The {@link In...
[truncated message content] |
|
From: <aki...@us...> - 2014-03-08 17:01:26
|
Revision: 9675
http://sourceforge.net/p/gridarta/code/9675
Author: akirschbaum
Date: 2014-03-08 17:01:21 +0000 (Sat, 08 Mar 2014)
Log Message:
-----------
Fix incorrect DTD for GameObjectMatchers.xml.
Modified Paths:
--------------
trunk/src/model/src/main/resources/system/dtd/GameObjectMatchers.dtd
Modified: trunk/src/model/src/main/resources/system/dtd/GameObjectMatchers.dtd
===================================================================
--- trunk/src/model/src/main/resources/system/dtd/GameObjectMatchers.dtd 2014-03-08 16:54:00 UTC (rev 9674)
+++ trunk/src/model/src/main/resources/system/dtd/GameObjectMatchers.dtd 2014-03-08 17:01:21 UTC (rev 9675)
@@ -24,7 +24,7 @@
<!ELEMENT GameObjectMatchers (GameObjectMatcher+)>
<!ELEMENT GameObjectMatcher (title+,Env?,%Match;)>
<!ATTLIST GameObjectMatcher
- id CDATA #IMPLIED
+ id CDATA #REQUIRED
system (true|false) 'false'
>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <aki...@us...> - 2014-03-08 16:54:06
|
Revision: 9674
http://sourceforge.net/p/gridarta/code/9674
Author: akirschbaum
Date: 2014-03-08 16:54:00 +0000 (Sat, 08 Mar 2014)
Log Message:
-----------
Fix incorrect error message.
Modified Paths:
--------------
trunk/src/model/src/main/java/net/sf/gridarta/model/match/GameObjectMatcherParser.java
Modified: trunk/src/model/src/main/java/net/sf/gridarta/model/match/GameObjectMatcherParser.java
===================================================================
--- trunk/src/model/src/main/java/net/sf/gridarta/model/match/GameObjectMatcherParser.java 2014-03-01 08:50:27 UTC (rev 9673)
+++ trunk/src/model/src/main/java/net/sf/gridarta/model/match/GameObjectMatcherParser.java 2014-03-08 16:54:00 UTC (rev 9674)
@@ -149,7 +149,7 @@
final String currentLanguage = Locale.getDefault().getLanguage();
final String localName = el.getLocalName();
if (localName == null || !localName.equals("GameObjectMatcher")) {
- throw new ParsingException("wrong local element name: expected \"GameObjectMatcher\" but got \" + localName + \"");
+ throw new ParsingException("wrong local element name: expected \"GameObjectMatcher\" but got \"" + localName + "\"");
}
final String id = el.getAttribute(XML_MATCHER_ATTRIBUTE_ID);
String title = getLanguageTitle(el, currentLanguage);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <aki...@us...> - 2014-03-01 08:50:35
|
Revision: 9673
http://sourceforge.net/p/gridarta/code/9673
Author: akirschbaum
Date: 2014-03-01 08:50:27 +0000 (Sat, 01 Mar 2014)
Log Message:
-----------
Extract common code from EditorAction implementations into EditorActionManager.
Modified Paths:
--------------
trunk/src/atrinik/src/main/java/net/sf/gridarta/var/atrinik/actions/AtrinikServerActions.java
trunk/src/atrinik/src/main/java/net/sf/gridarta/var/atrinik/maincontrol/DefaultEditorFactory.java
trunk/src/crossfire/src/main/java/net/sf/gridarta/var/crossfire/maincontrol/DefaultEditorFactory.java
trunk/src/daimonin/src/main/java/net/sf/gridarta/var/daimonin/maincontrol/DefaultEditorFactory.java
trunk/src/gridarta/src/main/java/net/sf/gridarta/action/AbstractMapCursorAction.java
trunk/src/gridarta/src/main/java/net/sf/gridarta/action/AbstractSelectionAction.java
trunk/src/gridarta/src/main/java/net/sf/gridarta/action/AddBookmarkAction.java
trunk/src/gridarta/src/main/java/net/sf/gridarta/action/AddToSelectionAction.java
trunk/src/gridarta/src/main/java/net/sf/gridarta/action/ArchAttributesAction.java
trunk/src/gridarta/src/main/java/net/sf/gridarta/action/DeleteArchAction.java
trunk/src/gridarta/src/main/java/net/sf/gridarta/action/GoLocationAction.java
trunk/src/gridarta/src/main/java/net/sf/gridarta/action/GrowSelectionAction.java
trunk/src/gridarta/src/main/java/net/sf/gridarta/action/InsertArchAction.java
trunk/src/gridarta/src/main/java/net/sf/gridarta/action/ReleaseDragAction.java
trunk/src/gridarta/src/main/java/net/sf/gridarta/action/SelectArchAboveAction.java
trunk/src/gridarta/src/main/java/net/sf/gridarta/action/SelectArchBelowAction.java
trunk/src/gridarta/src/main/java/net/sf/gridarta/action/SelectSquareAction.java
trunk/src/gridarta/src/main/java/net/sf/gridarta/action/ShrinkSelectionAction.java
trunk/src/gridarta/src/main/java/net/sf/gridarta/action/StartStopDragAction.java
trunk/src/gridarta/src/main/java/net/sf/gridarta/action/SubFromSelectionAction.java
trunk/src/gridarta/src/main/java/net/sf/gridarta/actions/AbstractServerActions.java
trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/exitconnector/ExitConnectorController.java
trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/map/mapactions/MapActions.java
trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/mapcursor/MapCursorActions.java
trunk/src/gridarta/src/main/java/net/sf/gridarta/mainactions/MainActions.java
trunk/src/gridarta/src/main/java/net/sf/gridarta/maincontrol/EditorFactory.java
trunk/src/gridarta/src/main/java/net/sf/gridarta/maincontrol/GUIMainControl.java
Added Paths:
-----------
trunk/src/gridarta/src/main/java/net/sf/gridarta/maincontrol/EditorActionManager.java
Modified: trunk/src/atrinik/src/main/java/net/sf/gridarta/var/atrinik/actions/AtrinikServerActions.java
===================================================================
--- trunk/src/atrinik/src/main/java/net/sf/gridarta/var/atrinik/actions/AtrinikServerActions.java 2014-03-01 07:10:48 UTC (rev 9672)
+++ trunk/src/atrinik/src/main/java/net/sf/gridarta/var/atrinik/actions/AtrinikServerActions.java 2014-03-01 08:50:27 UTC (rev 9673)
@@ -24,7 +24,6 @@
import java.io.OutputStream;
import java.net.Socket;
import net.sf.gridarta.actions.AbstractServerActions;
-import net.sf.gridarta.gui.map.mapview.MapViewManager;
import net.sf.gridarta.model.mapmanager.FileControl;
import net.sf.gridarta.var.atrinik.model.archetype.Archetype;
import net.sf.gridarta.var.atrinik.model.gameobject.GameObject;
@@ -62,12 +61,10 @@
/**
* Creates a new instance.
- * @param mapViewManager the map view manager for tracking the current map
- * view
* @param fileControl the file control for saving maps
*/
- public AtrinikServerActions(@NotNull final MapViewManager<GameObject, MapArchObject, Archetype> mapViewManager, @NotNull final FileControl<GameObject, MapArchObject, Archetype> fileControl) {
- super(mapViewManager, fileControl);
+ public AtrinikServerActions(@NotNull final FileControl<GameObject, MapArchObject, Archetype> fileControl) {
+ super(fileControl);
}
/**
Modified: trunk/src/atrinik/src/main/java/net/sf/gridarta/var/atrinik/maincontrol/DefaultEditorFactory.java
===================================================================
--- trunk/src/atrinik/src/main/java/net/sf/gridarta/var/atrinik/maincontrol/DefaultEditorFactory.java 2014-03-01 07:10:48 UTC (rev 9672)
+++ trunk/src/atrinik/src/main/java/net/sf/gridarta/var/atrinik/maincontrol/DefaultEditorFactory.java 2014-03-01 08:50:27 UTC (rev 9673)
@@ -37,7 +37,6 @@
import net.sf.gridarta.gui.filter.FilterControl;
import net.sf.gridarta.gui.map.mapview.DefaultMapViewFactory;
import net.sf.gridarta.gui.map.mapview.MapViewFactory;
-import net.sf.gridarta.gui.map.mapview.MapViewManager;
import net.sf.gridarta.gui.map.mapview.MapViewsManager;
import net.sf.gridarta.gui.map.renderer.GridMapSquarePainter;
import net.sf.gridarta.gui.map.renderer.RendererFactory;
@@ -448,8 +447,8 @@
*/
@NotNull
@Override
- public EditorAction newServerActions(@NotNull final MapViewManager<GameObject, MapArchObject, Archetype> mapViewManager, @NotNull final FileControl<GameObject, MapArchObject, Archetype> fileControl) {
- return new AtrinikServerActions(mapViewManager, fileControl);
+ public EditorAction newServerActions(@NotNull final FileControl<GameObject, MapArchObject, Archetype> fileControl) {
+ return new AtrinikServerActions(fileControl);
}
/**
Modified: trunk/src/crossfire/src/main/java/net/sf/gridarta/var/crossfire/maincontrol/DefaultEditorFactory.java
===================================================================
--- trunk/src/crossfire/src/main/java/net/sf/gridarta/var/crossfire/maincontrol/DefaultEditorFactory.java 2014-03-01 07:10:48 UTC (rev 9672)
+++ trunk/src/crossfire/src/main/java/net/sf/gridarta/var/crossfire/maincontrol/DefaultEditorFactory.java 2014-03-01 08:50:27 UTC (rev 9673)
@@ -35,7 +35,6 @@
import net.sf.gridarta.gui.filter.FilterControl;
import net.sf.gridarta.gui.map.mapview.DefaultMapViewFactory;
import net.sf.gridarta.gui.map.mapview.MapViewFactory;
-import net.sf.gridarta.gui.map.mapview.MapViewManager;
import net.sf.gridarta.gui.map.mapview.MapViewsManager;
import net.sf.gridarta.gui.map.renderer.GridMapSquarePainter;
import net.sf.gridarta.gui.map.renderer.RendererFactory;
@@ -339,7 +338,7 @@
*/
@Nullable
@Override
- public EditorAction newServerActions(@NotNull final MapViewManager<GameObject, MapArchObject, Archetype> mapViewManager, @NotNull final FileControl<GameObject, MapArchObject, Archetype> fileControl) {
+ public EditorAction newServerActions(@NotNull final FileControl<GameObject, MapArchObject, Archetype> fileControl) {
return null; // action not supported
}
Modified: trunk/src/daimonin/src/main/java/net/sf/gridarta/var/daimonin/maincontrol/DefaultEditorFactory.java
===================================================================
--- trunk/src/daimonin/src/main/java/net/sf/gridarta/var/daimonin/maincontrol/DefaultEditorFactory.java 2014-03-01 07:10:48 UTC (rev 9672)
+++ trunk/src/daimonin/src/main/java/net/sf/gridarta/var/daimonin/maincontrol/DefaultEditorFactory.java 2014-03-01 08:50:27 UTC (rev 9673)
@@ -37,7 +37,6 @@
import net.sf.gridarta.gui.filter.FilterControl;
import net.sf.gridarta.gui.map.mapview.DefaultMapViewFactory;
import net.sf.gridarta.gui.map.mapview.MapViewFactory;
-import net.sf.gridarta.gui.map.mapview.MapViewManager;
import net.sf.gridarta.gui.map.mapview.MapViewsManager;
import net.sf.gridarta.gui.map.renderer.GridMapSquarePainter;
import net.sf.gridarta.gui.map.renderer.RendererFactory;
@@ -447,7 +446,7 @@
*/
@Nullable
@Override
- public EditorAction newServerActions(@NotNull final MapViewManager<GameObject, MapArchObject, Archetype> mapViewManager, @NotNull final FileControl<GameObject, MapArchObject, Archetype> fileControl) {
+ public EditorAction newServerActions(@NotNull final FileControl<GameObject, MapArchObject, Archetype> fileControl) {
return null; // action not supported
}
Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/action/AbstractMapCursorAction.java
===================================================================
--- trunk/src/gridarta/src/main/java/net/sf/gridarta/action/AbstractMapCursorAction.java 2014-03-01 07:10:48 UTC (rev 9672)
+++ trunk/src/gridarta/src/main/java/net/sf/gridarta/action/AbstractMapCursorAction.java 2014-03-01 08:50:27 UTC (rev 9673)
@@ -21,7 +21,6 @@
import java.awt.Point;
import net.sf.gridarta.gui.map.mapview.MapView;
-import net.sf.gridarta.gui.map.mapview.MapViewManager;
import net.sf.gridarta.gui.map.mapview.MapViewManagerListener;
import net.sf.gridarta.model.archetype.Archetype;
import net.sf.gridarta.model.gameobject.GameObject;
@@ -36,7 +35,7 @@
* Abstract base class for actions that have to track the current map cursor.
* @author Andreas Kirschbaum
*/
-public abstract class AbstractMapCursorAction<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> {
+public abstract class AbstractMapCursorAction<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements MapCursorListener<G, A, R>, MapViewManagerListener<G, A, R> {
/**
* The active map view, or {@code null} if no map view exists.
@@ -45,68 +44,6 @@
private MapView<G, A, R> currentMapView;
/**
- * The map view manager listener used to detect changed current maps.
- */
- @NotNull
- private final MapViewManagerListener<G, A, R> mapViewManagerListener = new MapViewManagerListener<G, A, R>() {
-
- @Override
- public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) {
- currentMapView = mapView;
- updateAction();
- }
-
- @Override
- public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) {
- mapView.getMapCursor().addMapCursorListener(mapCursorListener);
- }
-
- @Override
- public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) {
- mapView.getMapCursor().removeMapCursorListener(mapCursorListener);
- }
-
- };
-
- /**
- * The map cursor listener used to detect cursor state changes in {@link
- * #currentMapView}.
- */
- @NotNull
- private final MapCursorListener<G, A, R> mapCursorListener = new MapCursorListener<G, A, R>() {
-
- @Override
- public void mapCursorChangedPos(@NotNull final Point location) {
- updateAction();
- }
-
- @Override
- public void mapCursorChangedMode() {
- updateAction();
- }
-
- @Override
- public void mapCursorChangedGameObject(@Nullable final MapSquare<G, A, R> mapSquare, @Nullable final G gameObject) {
- // ignore
- }
-
- @Override
- public void mapCursorChangedSize() {
- // ignore
- }
-
- };
-
- /**
- * Creates a new instance.
- * @param mapViewManager the map view manager
- */
- protected AbstractMapCursorAction(@NotNull final MapViewManager<G, A, R> mapViewManager) {
- mapViewManager.addMapViewManagerListener(mapViewManagerListener);
- currentMapView = mapViewManager.getActiveMapView();
- }
-
- /**
* Return the map cursor of the current map view if it is active.
* @return the map cursor, or {@code null} if the cursor is not active, or
* if no map view exists
@@ -131,4 +68,65 @@
*/
protected abstract void updateAction();
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) {
+ currentMapView = mapView;
+ updateAction();
+ }
+
+ /**
+ * {@inheritDoc}
+ * @noinspection NoopMethodInAbstractClass
+ */
+ @Override
+ public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) {
+ // ignore
+ }
+
+ /**
+ * {@inheritDoc}
+ * @noinspection NoopMethodInAbstractClass
+ */
+ @Override
+ public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) {
+ // ignore
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void mapCursorChangedPos(@NotNull final Point location) {
+ updateAction();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void mapCursorChangedMode() {
+ updateAction();
+ }
+
+ /**
+ * {@inheritDoc}
+ * @noinspection NoopMethodInAbstractClass
+ */
+ @Override
+ public void mapCursorChangedGameObject(@Nullable final MapSquare<G, A, R> mapSquare, @Nullable final G gameObject) {
+ // ignore
+ }
+
+ /**
+ * {@inheritDoc}
+ * @noinspection NoopMethodInAbstractClass
+ */
+ @Override
+ public void mapCursorChangedSize() {
+ // ignore
+ }
+
}
Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/action/AbstractSelectionAction.java
===================================================================
--- trunk/src/gridarta/src/main/java/net/sf/gridarta/action/AbstractSelectionAction.java 2014-03-01 07:10:48 UTC (rev 9672)
+++ trunk/src/gridarta/src/main/java/net/sf/gridarta/action/AbstractSelectionAction.java 2014-03-01 08:50:27 UTC (rev 9673)
@@ -19,7 +19,6 @@
package net.sf.gridarta.action;
-import net.sf.gridarta.gui.map.mapview.MapViewManager;
import net.sf.gridarta.model.archetype.Archetype;
import net.sf.gridarta.model.gameobject.GameObject;
import net.sf.gridarta.model.maparchobject.MapArchObject;
@@ -34,14 +33,6 @@
public abstract class AbstractSelectionAction<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractMapCursorAction<G, A, R> {
/**
- * Creates a new instance.
- * @param mapViewManager the map view manager
- */
- protected AbstractSelectionAction(@NotNull final MapViewManager<G, A, R> mapViewManager) {
- super(mapViewManager);
- }
-
- /**
* Executes an action for changing the selection.
* @param performAction whether the action should be performed
* @param mode the type of action to perform
Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/action/AddBookmarkAction.java
===================================================================
--- trunk/src/gridarta/src/main/java/net/sf/gridarta/action/AddBookmarkAction.java 2014-03-01 07:10:48 UTC (rev 9672)
+++ trunk/src/gridarta/src/main/java/net/sf/gridarta/action/AddBookmarkAction.java 2014-03-01 08:50:27 UTC (rev 9673)
@@ -22,7 +22,6 @@
import javax.swing.Action;
import net.sf.gridarta.gui.dialog.bookmarks.EditBookmarkDialog;
import net.sf.gridarta.gui.map.mapview.MapView;
-import net.sf.gridarta.gui.map.mapview.MapViewManager;
import net.sf.gridarta.gui.map.mapview.MapViewManagerListener;
import net.sf.gridarta.gui.mapmenu.AbstractMapMenuPreferences;
import net.sf.gridarta.gui.mapmenu.MapMenuEntryMap;
@@ -41,7 +40,7 @@
* An {@link EditorAction} that creates a new bookmark for the current map.
* @author Andreas Kirschbaum
*/
-public class AddBookmarkAction<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction {
+public class AddBookmarkAction<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction, MapViewManagerListener<G, A, R> {
/**
* The {@link AbstractMapMenuPreferences} for adding new bookmarks.
@@ -50,10 +49,10 @@
private final AbstractMapMenuPreferences bookmarksMapMenuPreferences;
/**
- * The {@link MapViewManager} instance.
+ * The currently active {@link MapView} or {@code null} if none is active.
*/
- @NotNull
- private final MapViewManager<G, A, R> mapViewManager;
+ @Nullable
+ private MapView<G, A, R> currentMapView;
/**
* The action associated with this editor action. Set to {@code null} if no
@@ -66,28 +65,9 @@
* Creates a new instance.
* @param bookmarksMapMenuPreferences the map menu preferences defining the
* bookmarks menu entries
- * @param mapViewManager the map view manager instance
*/
- public AddBookmarkAction(@NotNull final AbstractMapMenuPreferences bookmarksMapMenuPreferences, @NotNull final MapViewManager<G, A, R> mapViewManager) {
+ public AddBookmarkAction(@NotNull final AbstractMapMenuPreferences bookmarksMapMenuPreferences) {
this.bookmarksMapMenuPreferences = bookmarksMapMenuPreferences;
- this.mapViewManager = mapViewManager;
- final MapViewManagerListener<G, A, R> mapViewManagerListener = new MapViewManagerListener<G, A, R>() {
-
- @Override
- public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) {
- updateAction();
- }
-
- @Override
- public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) {
- }
-
- @Override
- public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) {
- }
-
- };
- mapViewManager.addMapViewManagerListener(mapViewManagerListener);
}
/**
@@ -124,7 +104,7 @@
* @return whether the action has or can be performed
*/
private boolean doAddBookmark(final boolean performAction) {
- final MapView<G, A, R> mapView = mapViewManager.getActiveMapView();
+ final MapView<G, A, R> mapView = currentMapView;
if (mapView == null) {
return false;
}
@@ -148,4 +128,27 @@
return true;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) {
+ currentMapView = mapView;
+ updateAction();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) {
+ }
+
}
Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/action/AddToSelectionAction.java
===================================================================
--- trunk/src/gridarta/src/main/java/net/sf/gridarta/action/AddToSelectionAction.java 2014-03-01 07:10:48 UTC (rev 9672)
+++ trunk/src/gridarta/src/main/java/net/sf/gridarta/action/AddToSelectionAction.java 2014-03-01 08:50:27 UTC (rev 9673)
@@ -20,7 +20,6 @@
package net.sf.gridarta.action;
import javax.swing.Action;
-import net.sf.gridarta.gui.map.mapview.MapViewManager;
import net.sf.gridarta.model.archetype.Archetype;
import net.sf.gridarta.model.gameobject.GameObject;
import net.sf.gridarta.model.maparchobject.MapArchObject;
@@ -45,14 +44,6 @@
private Action action;
/**
- * Creates a new instance.
- * @param mapViewManager the map view manager
- */
- public AddToSelectionAction(@NotNull final MapViewManager<G, A, R> mapViewManager) {
- super(mapViewManager);
- }
-
- /**
* {@inheritDoc}
*/
@Override
Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/action/ArchAttributesAction.java
===================================================================
--- trunk/src/gridarta/src/main/java/net/sf/gridarta/action/ArchAttributesAction.java 2014-03-01 07:10:48 UTC (rev 9672)
+++ trunk/src/gridarta/src/main/java/net/sf/gridarta/action/ArchAttributesAction.java 2014-03-01 08:50:27 UTC (rev 9673)
@@ -23,7 +23,6 @@
import javax.swing.Action;
import net.sf.gridarta.gui.dialog.gameobjectattributes.GameObjectAttributesDialogFactory;
import net.sf.gridarta.gui.map.mapview.MapView;
-import net.sf.gridarta.gui.map.mapview.MapViewManager;
import net.sf.gridarta.gui.map.mapview.MapViewManagerListener;
import net.sf.gridarta.model.archetype.Archetype;
import net.sf.gridarta.model.gameobject.GameObject;
@@ -41,7 +40,7 @@
* currently selected game object.
* @author Andreas Kirschbaum
*/
-public class ArchAttributesAction<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction {
+public class ArchAttributesAction<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction, MapCursorListener<G, A, R>, MapViewManagerListener<G, A, R> {
/**
* The factory for creating game object attributes dialog instances.
@@ -63,68 +62,12 @@
private Action action;
/**
- * The map view manager listener used to detect changed current maps.
- */
- @NotNull
- private final MapViewManagerListener<G, A, R> mapViewManagerListener = new MapViewManagerListener<G, A, R>() {
-
- @Override
- public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) {
- currentMapView = mapView;
- updateActions();
- }
-
- @Override
- public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) {
- mapView.getMapCursor().addMapCursorListener(mapCursorListener);
- }
-
- @Override
- public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) {
- mapView.getMapCursor().removeMapCursorListener(mapCursorListener);
- }
-
- };
-
- /**
- * The map cursor listener used to detect cursor state changes in {@link
- * #currentMapView}.
- */
- @NotNull
- private final MapCursorListener<G, A, R> mapCursorListener = new MapCursorListener<G, A, R>() {
-
- @Override
- public void mapCursorChangedPos(@NotNull final Point location) {
- updateActions();
- }
-
- @Override
- public void mapCursorChangedMode() {
- // ignore
- }
-
- @Override
- public void mapCursorChangedGameObject(@Nullable final MapSquare<G, A, R> mapSquare, @Nullable final G gameObject) {
- // ignore
- }
-
- @Override
- public void mapCursorChangedSize() {
- // ignore
- }
-
- };
-
- /**
* Creates a new instance.
- * @param mapViewManager the map view manager
* @param gameObjectAttributesDialogFactory the factory for creating game
* object attributes dialog instances
*/
- public ArchAttributesAction(@NotNull final MapViewManager<G, A, R> mapViewManager, @NotNull final GameObjectAttributesDialogFactory<G, A, R> gameObjectAttributesDialogFactory) {
+ public ArchAttributesAction(@NotNull final GameObjectAttributesDialogFactory<G, A, R> gameObjectAttributesDialogFactory) {
this.gameObjectAttributesDialogFactory = gameObjectAttributesDialogFactory;
- mapViewManager.addMapViewManagerListener(mapViewManagerListener);
- currentMapView = mapViewManager.getActiveMapView();
updateActions();
}
@@ -177,4 +120,61 @@
return true;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) {
+ currentMapView = mapView;
+ updateActions();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) {
+ // ignore
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) {
+ // ignore
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void mapCursorChangedPos(@NotNull final Point location) {
+ updateActions();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void mapCursorChangedMode() {
+ // ignore
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void mapCursorChangedGameObject(@Nullable final MapSquare<G, A, R> mapSquare, @Nullable final G gameObject) {
+ // ignore
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void mapCursorChangedSize() {
+ // ignore
+ }
+
}
Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/action/DeleteArchAction.java
===================================================================
--- trunk/src/gridarta/src/main/java/net/sf/gridarta/action/DeleteArchAction.java 2014-03-01 07:10:48 UTC (rev 9672)
+++ trunk/src/gridarta/src/main/java/net/sf/gridarta/action/DeleteArchAction.java 2014-03-01 08:50:27 UTC (rev 9673)
@@ -20,7 +20,6 @@
package net.sf.gridarta.action;
import javax.swing.Action;
-import net.sf.gridarta.gui.map.mapview.MapViewManager;
import net.sf.gridarta.model.archetype.Archetype;
import net.sf.gridarta.model.gameobject.GameObject;
import net.sf.gridarta.model.maparchobject.MapArchObject;
@@ -52,11 +51,9 @@
/**
* Creates a new instance.
- * @param mapViewManager the map view manager
* @param mapViewSettings the map view settings for querying options
*/
- public DeleteArchAction(@NotNull final MapViewManager<G, A, R> mapViewManager, @NotNull final MapViewSettings mapViewSettings) {
- super(mapViewManager);
+ public DeleteArchAction(@NotNull final MapViewSettings mapViewSettings) {
this.mapViewSettings = mapViewSettings;
}
Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/action/GoLocationAction.java
===================================================================
--- trunk/src/gridarta/src/main/java/net/sf/gridarta/action/GoLocationAction.java 2014-03-01 07:10:48 UTC (rev 9672)
+++ trunk/src/gridarta/src/main/java/net/sf/gridarta/action/GoLocationAction.java 2014-03-01 08:50:27 UTC (rev 9673)
@@ -58,7 +58,6 @@
* @param mapViewManager the map view manager
*/
public GoLocationAction(@NotNull final MapViewManager<G, A, R> mapViewManager) {
- super(mapViewManager);
goLocationDialogManager = new GoLocationDialogManager<G, A, R>(mapViewManager);
}
Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/action/GrowSelectionAction.java
===================================================================
--- trunk/src/gridarta/src/main/java/net/sf/gridarta/action/GrowSelectionAction.java 2014-03-01 07:10:48 UTC (rev 9672)
+++ trunk/src/gridarta/src/main/java/net/sf/gridarta/action/GrowSelectionAction.java 2014-03-01 08:50:27 UTC (rev 9673)
@@ -23,7 +23,6 @@
import java.util.List;
import javax.swing.Action;
import net.sf.gridarta.gui.map.mapview.MapView;
-import net.sf.gridarta.gui.map.mapview.MapViewManager;
import net.sf.gridarta.gui.map.mapview.MapViewManagerListener;
import net.sf.gridarta.model.archetype.Archetype;
import net.sf.gridarta.model.gameobject.GameObject;
@@ -43,7 +42,7 @@
* An {@link EditorAction} that grows the current selection by one map square.
* @author Andreas Kirschbaum
*/
-public class GrowSelectionAction<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction {
+public class GrowSelectionAction<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction, MapViewManagerListener<G, A, R> {
/**
* The active map view, or {@code null} if no map view exists.
@@ -59,34 +58,6 @@
private Action action;
/**
- * The map view manager listener used to detect changed current maps.
- */
- @NotNull
- private final MapViewManagerListener<G, A, R> mapViewManagerListener = new MapViewManagerListener<G, A, R>() {
-
- @Override
- public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) {
- if (currentMapView != null) {
- currentMapView.getMapGrid().removeMapGridListener(mapGridListener);
- }
- currentMapView = mapView;
- if (currentMapView != null) {
- currentMapView.getMapGrid().addMapGridListener(mapGridListener);
- }
- updateAction();
- }
-
- @Override
- public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) {
- }
-
- @Override
- public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) {
- }
-
- };
-
- /**
* The {@link MapGridListener} attached to {@link #currentMapView}.
*/
@NotNull
@@ -105,18 +76,6 @@
};
/**
- * Creates a new instance.
- * @param mapViewManager the map view manager
- */
- public GrowSelectionAction(@NotNull final MapViewManager<G, A, R> mapViewManager) {
- mapViewManager.addMapViewManagerListener(mapViewManagerListener);
- currentMapView = mapViewManager.getActiveMapView();
- if (currentMapView != null) {
- currentMapView.getMapGrid().addMapGridListener(mapGridListener);
- }
- }
-
- /**
* Grows the current map selection by one map square.
*/
@ActionMethod
@@ -188,4 +147,33 @@
return true;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) {
+ if (currentMapView != null) {
+ currentMapView.getMapGrid().removeMapGridListener(mapGridListener);
+ }
+ currentMapView = mapView;
+ if (currentMapView != null) {
+ currentMapView.getMapGrid().addMapGridListener(mapGridListener);
+ }
+ updateAction();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) {
+ }
+
}
Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/action/InsertArchAction.java
===================================================================
--- trunk/src/gridarta/src/main/java/net/sf/gridarta/action/InsertArchAction.java 2014-03-01 07:10:48 UTC (rev 9672)
+++ trunk/src/gridarta/src/main/java/net/sf/gridarta/action/InsertArchAction.java 2014-03-01 08:50:27 UTC (rev 9673)
@@ -20,7 +20,6 @@
package net.sf.gridarta.action;
import javax.swing.Action;
-import net.sf.gridarta.gui.map.mapview.MapViewManager;
import net.sf.gridarta.gui.panel.objectchooser.ObjectChooser;
import net.sf.gridarta.model.archetype.Archetype;
import net.sf.gridarta.model.baseobject.BaseObject;
@@ -60,12 +59,10 @@
/**
* Creates a new instance.
- * @param mapViewManager the map view manager
* @param objectChooser the object chooser
* @param mapViewSettings the map view settings instance for looking up options
*/
- public InsertArchAction(@NotNull final MapViewManager<G, A, R> mapViewManager, @NotNull final ObjectChooser<G, A, R> objectChooser, @NotNull final MapViewSettings mapViewSettings) {
- super(mapViewManager);
+ public InsertArchAction(@NotNull final ObjectChooser<G, A, R> objectChooser, @NotNull final MapViewSettings mapViewSettings) {
this.objectChooser = objectChooser;
this.mapViewSettings = mapViewSettings;
}
Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/action/ReleaseDragAction.java
===================================================================
--- trunk/src/gridarta/src/main/java/net/sf/gridarta/action/ReleaseDragAction.java 2014-03-01 07:10:48 UTC (rev 9672)
+++ trunk/src/gridarta/src/main/java/net/sf/gridarta/action/ReleaseDragAction.java 2014-03-01 08:50:27 UTC (rev 9673)
@@ -21,7 +21,6 @@
import java.awt.Point;
import javax.swing.Action;
-import net.sf.gridarta.gui.map.mapview.MapViewManager;
import net.sf.gridarta.model.archetype.Archetype;
import net.sf.gridarta.model.gameobject.GameObject;
import net.sf.gridarta.model.maparchobject.MapArchObject;
@@ -46,14 +45,6 @@
private Action action;
/**
- * Creates a new instance.
- * @param mapViewManager the map view manager
- */
- public ReleaseDragAction(@NotNull final MapViewManager<G, A, R> mapViewManager) {
- super(mapViewManager);
- }
-
- /**
* {@inheritDoc}
*/
@Override
Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/action/SelectArchAboveAction.java
===================================================================
--- trunk/src/gridarta/src/main/java/net/sf/gridarta/action/SelectArchAboveAction.java 2014-03-01 07:10:48 UTC (rev 9672)
+++ trunk/src/gridarta/src/main/java/net/sf/gridarta/action/SelectArchAboveAction.java 2014-03-01 08:50:27 UTC (rev 9673)
@@ -20,7 +20,6 @@
package net.sf.gridarta.action;
import javax.swing.Action;
-import net.sf.gridarta.gui.map.mapview.MapViewManager;
import net.sf.gridarta.model.archetype.Archetype;
import net.sf.gridarta.model.gameobject.GameObject;
import net.sf.gridarta.model.maparchobject.MapArchObject;
@@ -45,14 +44,6 @@
private Action action;
/**
- * Creates a new instance.
- * @param mapViewManager the map view manager
- */
- public SelectArchAboveAction(@NotNull final MapViewManager<G, A, R> mapViewManager) {
- super(mapViewManager);
- }
-
- /**
* {@inheritDoc}
*/
@Override
Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/action/SelectArchBelowAction.java
===================================================================
--- trunk/src/gridarta/src/main/java/net/sf/gridarta/action/SelectArchBelowAction.java 2014-03-01 07:10:48 UTC (rev 9672)
+++ trunk/src/gridarta/src/main/java/net/sf/gridarta/action/SelectArchBelowAction.java 2014-03-01 08:50:27 UTC (rev 9673)
@@ -20,7 +20,6 @@
package net.sf.gridarta.action;
import javax.swing.Action;
-import net.sf.gridarta.gui.map.mapview.MapViewManager;
import net.sf.gridarta.model.archetype.Archetype;
import net.sf.gridarta.model.gameobject.GameObject;
import net.sf.gridarta.model.maparchobject.MapArchObject;
@@ -45,14 +44,6 @@
private Action action;
/**
- * Creates a new instance.
- * @param mapViewManager the map view manager
- */
- public SelectArchBelowAction(@NotNull final MapViewManager<G, A, R> mapViewManager) {
- super(mapViewManager);
- }
-
- /**
* {@inheritDoc}
*/
@Override
Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/action/SelectSquareAction.java
===================================================================
--- trunk/src/gridarta/src/main/java/net/sf/gridarta/action/SelectSquareAction.java 2014-03-01 07:10:48 UTC (rev 9672)
+++ trunk/src/gridarta/src/main/java/net/sf/gridarta/action/SelectSquareAction.java 2014-03-01 08:50:27 UTC (rev 9673)
@@ -20,7 +20,6 @@
package net.sf.gridarta.action;
import javax.swing.Action;
-import net.sf.gridarta.gui.map.mapview.MapViewManager;
import net.sf.gridarta.model.archetype.Archetype;
import net.sf.gridarta.model.gameobject.GameObject;
import net.sf.gridarta.model.maparchobject.MapArchObject;
@@ -45,14 +44,6 @@
private Action action;
/**
- * Creates a new instance.
- * @param mapViewManager the map view manager
- */
- public SelectSquareAction(@NotNull final MapViewManager<G, A, R> mapViewManager) {
- super(mapViewManager);
- }
-
- /**
* {@inheritDoc}
*/
@Override
Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/action/ShrinkSelectionAction.java
===================================================================
--- trunk/src/gridarta/src/main/java/net/sf/gridarta/action/ShrinkSelectionAction.java 2014-03-01 07:10:48 UTC (rev 9672)
+++ trunk/src/gridarta/src/main/java/net/sf/gridarta/action/ShrinkSelectionAction.java 2014-03-01 08:50:27 UTC (rev 9673)
@@ -25,7 +25,6 @@
import java.util.Map;
import javax.swing.Action;
import net.sf.gridarta.gui.map.mapview.MapView;
-import net.sf.gridarta.gui.map.mapview.MapViewManager;
import net.sf.gridarta.gui.map.mapview.MapViewManagerListener;
import net.sf.gridarta.model.archetype.Archetype;
import net.sf.gridarta.model.gameobject.GameObject;
@@ -46,7 +45,7 @@
* square.
* @author Andreas Kirschbaum
*/
-public class ShrinkSelectionAction<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction {
+public class ShrinkSelectionAction<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction, MapViewManagerListener<G, A, R> {
/**
* The active map view, or {@code null} if no map view exists.
@@ -62,34 +61,6 @@
private Action action;
/**
- * The map view manager listener used to detect changed current maps.
- */
- @NotNull
- private final MapViewManagerListener<G, A, R> mapViewManagerListener = new MapViewManagerListener<G, A, R>() {
-
- @Override
- public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) {
- if (currentMapView != null) {
- currentMapView.getMapGrid().removeMapGridListener(mapGridListener);
- }
- currentMapView = mapView;
- if (currentMapView != null) {
- currentMapView.getMapGrid().addMapGridListener(mapGridListener);
- }
- updateAction();
- }
-
- @Override
- public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) {
- }
-
- @Override
- public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) {
- }
-
- };
-
- /**
* The {@link MapGridListener} attached to {@link #currentMapView}.
*/
@NotNull
@@ -108,18 +79,6 @@
};
/**
- * Creates a new instance.
- * @param mapViewManager the map view manager
- */
- public ShrinkSelectionAction(@NotNull final MapViewManager<G, A, R> mapViewManager) {
- mapViewManager.addMapViewManagerListener(mapViewManagerListener);
- currentMapView = mapViewManager.getActiveMapView();
- if (currentMapView != null) {
- currentMapView.getMapGrid().addMapGridListener(mapGridListener);
- }
- }
-
- /**
* Grows the current map selection by one map square.
*/
@ActionMethod
@@ -200,4 +159,35 @@
return true;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) {
+ if (currentMapView != null) {
+ currentMapView.getMapGrid().removeMapGridListener(mapGridListener);
+ }
+ currentMapView = mapView;
+ if (currentMapView != null) {
+ currentMapView.getMapGrid().addMapGridListener(mapGridListener);
+ }
+ updateAction();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) {
+ // ignore
+ }
+
+ @Override
+ /**
+ * {@inheritDoc}
+ */
+ public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) {
+ // ignore
+ }
+
}
Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/action/StartStopDragAction.java
===================================================================
--- trunk/src/gridarta/src/main/java/net/sf/gridarta/action/StartStopDragAction.java 2014-03-01 07:10:48 UTC (rev 9672)
+++ trunk/src/gridarta/src/main/java/net/sf/gridarta/action/StartStopDragAction.java 2014-03-01 08:50:27 UTC (rev 9673)
@@ -20,7 +20,6 @@
package net.sf.gridarta.action;
import javax.swing.Action;
-import net.sf.gridarta.gui.map.mapview.MapViewManager;
import net.sf.gridarta.model.archetype.Archetype;
import net.sf.gridarta.model.gameobject.GameObject;
import net.sf.gridarta.model.maparchobject.MapArchObject;
@@ -45,14 +44,6 @@
private Action action;
/**
- * Creates a new instance.
- * @param mapViewManager the map view manager
- */
- public StartStopDragAction(@NotNull final MapViewManager<G, A, R> mapViewManager) {
- super(mapViewManager);
- }
-
- /**
* {@inheritDoc}
*/
@Override
Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/action/SubFromSelectionAction.java
===================================================================
--- trunk/src/gridarta/src/main/java/net/sf/gridarta/action/SubFromSelectionAction.java 2014-03-01 07:10:48 UTC (rev 9672)
+++ trunk/src/gridarta/src/main/java/net/sf/gridarta/action/SubFromSelectionAction.java 2014-03-01 08:50:27 UTC (rev 9673)
@@ -20,7 +20,6 @@
package net.sf.gridarta.action;
import javax.swing.Action;
-import net.sf.gridarta.gui.map.mapview.MapViewManager;
import net.sf.gridarta.model.archetype.Archetype;
import net.sf.gridarta.model.gameobject.GameObject;
import net.sf.gridarta.model.maparchobject.MapArchObject;
@@ -45,14 +44,6 @@
private Action action;
/**
- * Creates a new instance.
- * @param mapViewManager the map view manager
- */
- public SubFromSelectionAction(@NotNull final MapViewManager<G, A, R> mapViewManager) {
- super(mapViewManager);
- }
-
- /**
* {@inheritDoc}
*/
@Override
Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/actions/AbstractServerActions.java
===================================================================
--- trunk/src/gridarta/src/main/java/net/sf/gridarta/actions/AbstractServerActions.java 2014-03-01 07:10:48 UTC (rev 9672)
+++ trunk/src/gridarta/src/main/java/net/sf/gridarta/actions/AbstractServerActions.java 2014-03-01 08:50:27 UTC (rev 9673)
@@ -23,7 +23,6 @@
import java.io.IOException;
import javax.swing.Action;
import net.sf.gridarta.gui.map.mapview.MapView;
-import net.sf.gridarta.gui.map.mapview.MapViewManager;
import net.sf.gridarta.gui.map.mapview.MapViewManagerListener;
import net.sf.gridarta.model.archetype.Archetype;
import net.sf.gridarta.model.gameobject.GameObject;
@@ -42,7 +41,7 @@
* @author Andreas Kirschbaum
* @noinspection AbstractClassWithOnlyOneDirectInheritor
*/
-public abstract class AbstractServerActions<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction {
+public abstract class AbstractServerActions<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction, MapViewManagerListener<G, A, R> {
/**
* The currently active map or {@code null} if no map is active.
@@ -64,41 +63,11 @@
private Action aOpenInClient;
/**
- * The map manager listener which is attached to the current map if the
- * current map is tracked. Otherwise it is unused.
- * @noinspection FieldCanBeLocal
- */
- @NotNull
- private final MapViewManagerListener<G, A, R> mapViewManagerListener = new MapViewManagerListener<G, A, R>() {
-
- @Override
- public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) {
- currentMapView = mapView;
- updateActions();
- }
-
- @Override
- public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) {
- // ignore
- }
-
- @Override
- public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) {
- // ignore
- }
-
- };
-
- /**
* Creates a new instance.
- * @param mapViewManager the map view manager for tracking the current map
- * view
* @param fileControl the file control for saving maps
*/
- protected AbstractServerActions(@NotNull final MapViewManager<G, A, R> mapViewManager, @NotNull final FileControl<G, A, R> fileControl) {
+ protected AbstractServerActions(@NotNull final FileControl<G, A, R> fileControl) {
this.fileControl = fileControl;
- mapViewManager.addMapViewManagerListener(mapViewManagerListener);
- currentMapView = mapViewManager.getActiveMapView();
}
/**
@@ -174,4 +143,31 @@
updateActions();
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) {
+ currentMapView = mapView;
+ updateActions();
+ }
+
+ /**
+ * {@inheritDoc}
+ * @noinspection NoopMethodInAbstractClass
+ */
+ @Override
+ public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) {
+ // ignore
+ }
+
+ /**
+ * {@inheritDoc}
+ * @noinspection NoopMethodInAbstractClass
+ */
+ @Override
+ public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) {
+ // ignore
+ }
+
}
Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/exitconnector/ExitConnectorController.java
===================================================================
--- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/exitconnector/ExitConnectorController.java 2014-03-01 07:10:48 UTC (rev 9672)
+++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/exitconnector/ExitConnectorController.java 2014-03-01 08:50:27 UTC (rev 9673)
@@ -23,7 +23,6 @@
import javax.swing.Action;
import net.sf.gridarta.actions.ExitConnectorActions;
import net.sf.gridarta.gui.map.mapview.MapView;
-import net.sf.gridarta.gui.map.mapview.MapViewManager;
import net.sf.gridarta.gui.map.mapview.MapViewManagerListener;
import net.sf.gridarta.model.archetype.Archetype;
import net.sf.gridarta.model.exitconnector.ExitConnectorModel;
@@ -40,7 +39,7 @@
* The controller of the exit connector.
* @author Andreas Kirschbaum
*/
-public class ExitConnectorController<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction {
+public class ExitConnectorController<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction, MapViewManagerListener<G, A, R> {
/**
* The actions for this controller.
@@ -101,39 +100,13 @@
};
/**
- * The {@link MapViewManagerListener} used to track the current map.
- */
- @NotNull
- private final MapViewManagerListener<G, A, R> mapViewManagerListener = new MapViewManagerListener<G, A, R>() {
-
- @Override
- public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) {
- setCurrentMapView(mapView);
- }
-
- @Override
- public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) {
- // ignore
- }
-
- @Override
- public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) {
- // ignore
- }
-
- };
-
- /**
* Creates a new instance.
* @param exitConnectorActions the exit connector actions to use
* @param exitConnectorModel the model for this controller
- * @param mapViewManager the map view manager to track
*/
- public ExitConnectorController(@NotNull final ExitConnectorActions<G, A, R> exitConnectorActions, @NotNull final ExitConnectorModel exitConnectorModel, @NotNull final MapViewManager<G, A, R> mapViewManager) {
+ public ExitConnectorController(@NotNull final ExitConnectorActions<G, A, R> exitConnectorActions, @NotNull final ExitConnectorModel exitConnectorModel) {
this.exitConnectorActions = exitConnectorActions;
- mapViewManager.addMapViewManagerListener(mapViewManagerListener);
exitConnectorModel.addExitConnectorModelListener(exitConnectorModelListener);
- setCurrentMapView(mapViewManager.getActiveMapView());
}
/**
@@ -161,16 +134,6 @@
}
/**
- * Updates {@link #currentMapView}, registering or de-registering listeners
- * as needed.
- * @param currentMapView the new current map view
- */
- private void setCurrentMapView(@Nullable final MapView<G, A, R> currentMapView) {
- this.currentMapView = currentMapView;
- refreshActions();
- }
-
- /**
* Updates the enabled state of all actions.
*/
private void refreshActions() {
@@ -251,4 +214,29 @@
refreshActions();
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) {
+ currentMapView = mapView;
+ refreshActions();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) {
+ // ignore
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) {
+ // ignore
+ }
+
}
Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/map/mapactions/MapActions.java
===================================================================
--- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/map/mapactions/MapActions.java 2014-03-01 07:10:48 UTC (rev 9672)
+++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/map/mapactions/MapActions.java 2014-03-01 08:50:27 UTC (rev 9673)
@@ -62,7 +62,7 @@
* Manages actions in the "map" menu.
* @author Andreas Kirschbaum
*/
-public class MapActions<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction {
+public class MapActions<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction, MapCursorListener<G, A, R>, MapViewManagerListener<G, A, R> {
/**
* Possible directions for "enter xxx map".
@@ -287,68 +287,6 @@
};
/**
- * The map view manager listener which is attached to the current map if the
- * current map is tracked. Otherwise it is unused.
- */
- private final MapViewManagerListener<G, A, R> mapViewManagerListener = new MapViewManagerListener<G, A, R>() {
-
- @Override
- public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) {
- if (currentMapView != null) {
- currentMapView.getMapCursor().removeMapCursorListener(mapCursorListener);
- assert currentMapView != null;
- currentMapView.getMapControl().getMapModel().getMapArchObject().removeMapArchObjectListener(mapArchObjectListener);
- }
- currentMapView = mapView;
- if (currentMapView != null) {
- currentMapView.getMapCursor().addMapCursorListener(mapCursorListener);
- assert currentMapView != null;
- currentMapView.getMapControl().getMapModel().getMapArchObject().addMapArchObjectListener(mapArchObjectListener);
- }
- updateActions();
- }
-
- @Override
- public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) {
- // ignore
- }
-
- @Override
- public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) {
- // ignore
- }
-
- };
-
- /**
- * The map cursor listener which is attached to {@link #currentMapView}.
- */
- @NotNull
- private final MapCursorListener<G, A, R> mapCursorListener = new MapCursorListener<G, A, R>() {
-
- @Override
- public void mapCursorChangedPos(@NotNull final Point location) {
- updateActions();
- }
-
- @Override
- public void mapCursorChangedMode() {
- // ignore
- }
-
- @Override
- public void mapCursorChangedGameObject(@Nullable final MapSquare<G, A, R> mapSquare, @Nullable final G gameObject) {
- // ignore
- }
-
- @Override
- public void mapCursorChangedSize() {
- // ignore
- }
-
- };
-
- /**
* The {@link MapArchObjectListener} attached to {@link #currentMapView}.
*/
@NotNull
@@ -394,15 +332,7 @@
this.mapViewsManager = mapViewsManager;
shrinkMapSizeDialogManager = new ShrinkMapSizeDialogManager<G, A, R>(mapViewManager);
mapViewSettings.addMapViewSettingsListener(mapViewSettingsListener);
-
mapManager.addMapManagerListener(mapManagerListener);
- mapViewManager.addMapViewManagerListener(mapViewManagerListener);
- currentMapView = mapViewManager.getActiveMapView();
- if (currentMapView != null) {
- currentMapView.getMapCursor().addMapCursorListener(mapCursorListener);
- assert currentMapView != null;
- currentMapView.getMapControl().getMapModel().getMapArchObject().addMapArchObjectListener(mapArchObjectListener);
- }
}
/**
@@ -1025,4 +955,67 @@
updateActions();
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) {
+ if (currentMapView != null) {
+ currentMapView.getMapControl().getMapModel().getMapArchObject().removeMapArchObjectListener(mapArchObjectListener);
+ }
+ currentMapView = mapView;
+ if (currentMapView != null) {
+ currentMapView.getMapControl().getMapModel().getMapArchObject().addMapArchObjectListener(mapArchObjectListener);
+ }
+ updateActions();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) {
+ // ignore
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) {
+ // ignore
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void mapCursorChangedPos(@NotNull final Point location) {
+ updateActions();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void mapCursorChangedMode() {
+ // ignore
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void mapCursorChangedGameObject(@Nullable final MapSquare<G, A, R> mapSquare, @Nullable final G gameObject) {
+ // ignore
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void mapCursorChangedSize() {
+ // ignore
+ }
+
}
Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/mapcursor/MapCursorActions.java
===================================================================
--- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/mapcursor/MapCursorActions.java 2014-03-01 07:10:48 UTC (rev 9672)
+++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/mapcursor/MapCursorActions.java 2014-03-01 08:50:27 UTC (rev 9673)
@@ -24,7 +24,6 @@
import javax.swing.Action;
import net.sf.gridarta.gui.map.mapactions.MapActions;
import net.sf.gridarta.gui.map.mapview.MapView;
-import net.sf.gridarta.gui.map.mapview.MapViewManager;
import net.sf.gridarta.gui.map.mapview.MapViewManagerListener;
import net.sf.gridarta.gui.map.renderer.MapRenderer;
import net.sf.gridarta.model.archetype.Archetype;
@@ -47,7 +46,7 @@
* Cursor related actions.
* @author Andreas Kirschbaum
*/
-public class MapCursorActions<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction {
+public class MapCursorActions<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction, MapCursorListener<G, A, R>, MapViewManagerListener<G, A, R> {
/**
* The visible border around the cursor. Whenever the cursor moves, the map
@@ -77,61 +76,6 @@
private MapView<G, A, R> currentMapView;
/**
- * The map view manager listener used to detect changed current maps.
- */
- @NotNull
- private final MapViewManagerListener<G, A, R> mapViewManagerListener = new MapViewManagerListener<G, A, R>() {
-
- @Override
- public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) {
- currentMapView = mapView;
- refreshActions();
- }
-
- @Override
- public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) {
- mapView.getMapCursor().addMapCursorListener(mapCursorListener);
- mapView.getMapControl().getMapModel().addMapModelListener(mapModelListener);
- }
-
- @Override
- public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) {
- mapView.getMapCursor().removeMapCursorListener(mapCursorListener);
- mapView.getMapControl().getMapModel().removeMapModelListener(mapModelListener);
- }
-
- };
-
- /**
- * The map cursor listener used to detect cursor state changes in {@link
- * #currentMapView}.
- */
- @NotNull
- private final MapCursorListener<G, A, R> mapCursorListener = new MapCursorListener<G, A, R>() {
-
- @Override
- public void mapCursorChangedPos(@NotNull final Point location) {
- refreshActions();
- }
-
- @Override
- public void mapCursorChangedMode() {
- // ignore
- }
-
- @Override
- public void mapCursorChangedGameObject(@Nullable final MapSquare<G, A, R> mapSquare, @Nullable final G gameObject) {
- // ignore
- }
-
- @Override
- public void mapCursorChangedSize() {
- refreshActions();
- }
-
- };
-
- /**
* The map model listener used to detect map size changes in {@link
* #currentMapView}.
*/
@@ -171,14 +115,11 @@
};
/**
- * Create a new instance.
- * @param mapViewManager the map view manager
+ * Creates a new instance.
*/
- public MapCursorActions(@NotNull final MapViewManager<G, A, R> mapViewManager, @NotNull final MapActions<G, A, R> mapActions) {
+ public MapCursorActions(@NotNull final MapActions<G, A, R> mapActions) {
this.mapActions = mapActions;
aMoveCursor = new Action[DIRECTIONS.length];
- mapViewManager.addMapViewManagerListener(mapViewManagerListener);
- currentMapView = mapViewManager.getActiveMapView();
refreshActions();
}
@@ -308,4 +249,61 @@
refreshActions();
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) {
+ currentMapView = mapView;
+ refreshActions();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) {
+ mapView.getMapControl().getMapModel().addMapModelListener(mapModelListener);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) {
+ mapView.getMapControl().getMapModel().removeMapModelListener(mapModelListener);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void mapCursorChangedPos(@NotNull final Point location) {
+ refreshActions();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void mapCursorChangedMode() {
+ // ignore
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void mapCursorChangedGameObject(@Nullable final MapSquare<G, A, R> mapSquare, @Nullable final G gameObject) {
+ // ignore
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void mapCursorChangedSize() {
+ refreshActions();
+ }
+
}
Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/mainactions/MainActions.java
===================================================================
--- trunk/src/gridarta/src/main/java/net/sf/gridarta/mainactions/MainActions.java 2014-03-01 07:10:48 UTC (rev 9672)
+++ trunk/src/gridarta/src/main/java/net/sf/gridarta/mainactions/MainActions.java 2014-03-01 08:50:27 UTC (rev 9673)
@@ -31,7 +31,6 @@
import net.sf.gridarta.gui.dialog.find.FindDialogManager;
import net.sf.gridarta.gui.dialog.replace.ReplaceDialogManager;
import net.sf.gridarta.gui.map.mapview.MapView;
-import net.sf.gridarta.gui.map.mapview.MapViewManager;
import net.sf.gridarta.gui.map.mapview.MapViewManagerListener;
import net.sf.gridarta.gui.misc.ShiftProcessor;
import net.sf.gridarta.gui.panel.objectchooser.ObjectChooser;
@@ -67,7 +66,7 @@
* Encapsulates actions and related functions.
* @author Andreas Kirschbaum
*/
-public class MainActions<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction {
+public class MainActions<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R ...
[truncated message content] |
|
From: <aki...@us...> - 2014-03-01 07:10:55
|
Revision: 9672
http://sourceforge.net/p/gridarta/code/9672
Author: akirschbaum
Date: 2014-03-01 07:10:48 +0000 (Sat, 01 Mar 2014)
Log Message:
-----------
Remove fully qualified class name.
Modified Paths:
--------------
trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/panel/pickmapchooser/PickmapChooserModel.java
Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/panel/pickmapchooser/PickmapChooserModel.java
===================================================================
--- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/panel/pickmapchooser/PickmapChooserModel.java 2014-03-01 07:10:09 UTC (rev 9671)
+++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/panel/pickmapchooser/PickmapChooserModel.java 2014-03-01 07:10:48 UTC (rev 9672)
@@ -35,6 +35,7 @@
import net.sf.gridarta.model.gameobject.GameObject;
import net.sf.gridarta.model.maparchobject.MapArchObject;
import net.sf.gridarta.model.mapcontrol.MapControl;
+import net.sf.gridarta.model.mapmodel.MapFile;
import net.sf.gridarta.model.mapmodel.MapModel;
import net.sf.gridarta.model.mapmodel.MapModelListener;
import net.sf.gridarta.model.mapmodel.MapSquare;
@@ -276,7 +277,7 @@
}
@Override
- public void mapFileChanged(@Nullable final net.sf.gridarta.model.mapmodel.MapFile oldMapFile) {
+ public void mapFileChanged(@Nullable final MapFile oldMapFile) {
// ignore
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <aki...@us...> - 2014-03-01 07:10:14
|
Revision: 9671
http://sourceforge.net/p/gridarta/code/9671
Author: akirschbaum
Date: 2014-03-01 07:10:09 +0000 (Sat, 01 Mar 2014)
Log Message:
-----------
Properly update pickmap view after map modifications. Reload pickmaps from disk when the pickmap folder is changed.
Modified Paths:
--------------
trunk/src/atrinik/ChangeLog
trunk/src/crossfire/ChangeLog
trunk/src/daimonin/ChangeLog
trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/panel/pickmapchooser/PickmapChooserModel.java
Modified: trunk/src/atrinik/ChangeLog
===================================================================
--- trunk/src/atrinik/ChangeLog 2014-02-28 20:55:32 UTC (rev 9670)
+++ trunk/src/atrinik/ChangeLog 2014-03-01 07:10:09 UTC (rev 9671)
@@ -1,3 +1,8 @@
+2014-03-01 Andreas Kirschbaum
+
+ * Properly update pickmap view after map modifications. Reload
+ pickmaps from disk when the pickmap folder is changed.
+
2014-02-23 Andreas Kirschbaum
* Add missing library which broke the settings dialog.
Modified: trunk/src/crossfire/ChangeLog
===================================================================
--- trunk/src/crossfire/ChangeLog 2014-02-28 20:55:32 UTC (rev 9670)
+++ trunk/src/crossfire/ChangeLog 2014-03-01 07:10:09 UTC (rev 9671)
@@ -1,3 +1,8 @@
+2014-03-01 Andreas Kirschbaum
+
+ * Properly update pickmap view after map modifications. Reload
+ pickmaps from disk when the pickmap folder is changed.
+
2014-02-23 Andreas Kirschbaum
* Add missing library which broke the settings dialog.
Modified: trunk/src/daimonin/ChangeLog
===================================================================
--- trunk/src/daimonin/ChangeLog 2014-02-28 20:55:32 UTC (rev 9670)
+++ trunk/src/daimonin/ChangeLog 2014-03-01 07:10:09 UTC (rev 9671)
@@ -1,3 +1,8 @@
+2014-03-01 Andreas Kirschbaum
+
+ * Properly update pickmap view after map modifications. Reload
+ pickmaps from disk when the pickmap folder is changed.
+
2014-02-23 Andreas Kirschbaum
* Add missing library which broke the settings dialog.
Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/panel/pickmapchooser/PickmapChooserModel.java
===================================================================
--- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/panel/pickmapchooser/PickmapChooserModel.java 2014-02-28 20:55:32 UTC (rev 9670)
+++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/panel/pickmapchooser/PickmapChooserModel.java 2014-03-01 07:10:09 UTC (rev 9671)
@@ -169,6 +169,7 @@
public void clear() {
for (final PickmapState<G, A, R> pickmapState : pickmapStates) {
removeMapModelListener(pickmapState.getPickmap());
+ pickmapState.freePickmap();
}
pickmapStates.clear();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <aki...@us...> - 2014-02-28 20:55:36
|
Revision: 9670
http://sourceforge.net/p/gridarta/code/9670
Author: akirschbaum
Date: 2014-02-28 20:55:32 +0000 (Fri, 28 Feb 2014)
Log Message:
-----------
Fix NullPointerException in attribute edit dialogs.
Modified Paths:
--------------
trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.java
trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/TextAreaPainter.java
Modified: trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.java
===================================================================
--- trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.java 2014-02-28 20:49:32 UTC (rev 9669)
+++ trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.java 2014-02-28 20:55:32 UTC (rev 9670)
@@ -163,6 +163,7 @@
selection = new TextAreaSelection(document);
config = new TextAreaConfig(defaults.getEditable(), defaults.getElectricScroll());
painter = new TextAreaPainter(this, selection, caret, defaults, brackets, config, paintInvalid);
+ painter.recalculateVisibleLines();
documentHandler = new DocumentHandler();
// Initialize the GUI
Modified: trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/TextAreaPainter.java
===================================================================
--- trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/TextAreaPainter.java 2014-02-28 20:49:32 UTC (rev 9669)
+++ trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/TextAreaPainter.java 2014-02-28 20:55:32 UTC (rev 9670)
@@ -245,7 +245,9 @@
setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
- setFont(new Font("Monospaced", Font.PLAIN, 14));
+ final Font font = new Font("Monospaced", Font.PLAIN, 14);
+ super.setFont(font);
+ fontMetrics = getFontMetrics(font);
setForeground(Color.black);
setBackground(Color.white);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <aki...@us...> - 2014-02-28 20:49:37
|
Revision: 9669
http://sourceforge.net/p/gridarta/code/9669
Author: akirschbaum
Date: 2014-02-28 20:49:32 +0000 (Fri, 28 Feb 2014)
Log Message:
-----------
Move code from JEditTextArea to TextAreaPainter.
Modified Paths:
--------------
trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.java
trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/TextAreaPainter.java
Modified: trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.java
===================================================================
--- trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.java 2014-02-28 20:33:33 UTC (rev 9668)
+++ trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.java 2014-02-28 20:49:32 UTC (rev 9669)
@@ -13,7 +13,6 @@
import java.awt.AWTEvent;
import java.awt.Adjustable;
import java.awt.Font;
-import java.awt.FontMetrics;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
@@ -37,7 +36,6 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashSet;
-import java.util.List;
import java.util.Set;
import javax.swing.JComponent;
import javax.swing.JPopupMenu;
@@ -49,12 +47,10 @@
import javax.swing.event.DocumentListener;
import javax.swing.text.BadLocationException;
import javax.swing.text.Segment;
-import javax.swing.text.Utilities;
import javax.swing.undo.AbstractUndoableEdit;
import javax.swing.undo.CannotRedoException;
import javax.swing.undo.CannotUndoException;
import javax.swing.undo.UndoableEdit;
-import net.sf.gridarta.textedit.textarea.tokenmarker.TokenMarker;
import org.apache.log4j.Category;
import org.apache.log4j.Logger;
import org.jetbrains.annotations.NotNull;
@@ -138,7 +134,7 @@
private final DocumentListener documentHandler;
@NotNull
- private final Segment lineSegment;
+ private final Segment lineSegment = new Segment();
@NotNull
private final TextAreaSelection selection;
@@ -168,7 +164,6 @@
config = new TextAreaConfig(defaults.getEditable(), defaults.getElectricScroll());
painter = new TextAreaPainter(this, selection, caret, defaults, brackets, config, paintInvalid);
documentHandler = new DocumentHandler();
- lineSegment = new Segment();
// Initialize the GUI
setLayout(new ScrollLayout(this));
@@ -446,7 +441,7 @@
}
}
- final int x = offsetToX2(line, offset);
+ final int x = painter.offsetToX2(line, offset);
final int width = painter.getFontMetrics().charWidth('w');
if (x < 0) {
@@ -467,25 +462,13 @@
}
/**
- * Converts a y co-ordinate to a line index.
- * @param y the y co-ordinate
- */
- public int yToLine(final int y) {
- final FontMetrics fm = painter.getFontMetrics();
- final int height = fm.getHeight();
- return Math.max(0, Math.min(selection.getLineCount() - 1, y / height + painter.getFirstLine()));
- }
-
- /**
* Converts an offset in a line into an x co-ordinate. This is a slow
* version that can be used any time.
* @param line the line
* @param offset the offset, from the start of the line
*/
public int offsetToX(final int line, final int offset) {
- // don't use cached tokens
- painter.setCurrentLineTokens(null);
- return offsetToX2(line, offset);
+ return painter.offsetToX(line, offset);
}
/**
@@ -496,55 +479,7 @@
* @param offset the offset, from the start of the line
*/
public int offsetToX2(final int line, final int offset) {
- final TokenMarker tokenMarker = selection.getTokenMarker();
-
- /* Use painter's cached info for speed */
- FontMetrics fm = painter.getFontMetrics();
-
- selection.getLineText(line, lineSegment);
-
- final int segmentOffset = lineSegment.offset;
- int x = painter.getHorizontalOffset();
-
- /* If syntax coloring is disabled, do simple translation */
- if (tokenMarker == null) {
- lineSegment.count = offset;
- return x + Utilities.getTabbedTextWidth(lineSegment, fm, x, painter, 0);
- } else {
- /* If syntax coloring is enabled, we have to do this because
- * tokens can vary in width */
- final List<Token> tokens;
- if (painter.getCurrentLineIndex() == line && painter.getCurrentLineTokens() != null) {
- tokens = painter.getCurrentLineTokens();
- } else {
- painter.setCurrentLineIndex(line);
- tokens = tokenMarker.markTokens(lineSegment, line);
- painter.setCurrentLineTokens(tokens);
- }
-
- final Font defaultFont = painter.getFont();
- final SyntaxStyles styles = painter.getStyles();
-
- for (final Token token : tokens) {
- final byte id = token.getId();
- if (id == Token.NULL) {
- fm = painter.getFontMetrics();
- } else {
- fm = styles.getStyle(id).getFontMetrics(defaultFont, painter.getGraphics());
- }
-
- final int length = token.getLength();
-
- if (offset + segmentOffset < lineSegment.offset + length) {
- lineSegment.count = offset - (lineSegment.offset - segmentOffset);
- return x + Utilities.getTabbedTextWidth(lineSegment, fm, x, painter, 0);
- }
- lineSegment.count = length;
- x += Utilities.getTabbedTextWidth(lineSegment, fm, x, painter, 0);
- lineSegment.offset += length;
- }
- return x;
- }
+ return painter.offsetToX2(line, offset);
}
/**
@@ -553,107 +488,10 @@
* @param x the x co-ordinate
*/
public int xToOffset(final int line, final int x) {
- final TokenMarker tokenMarker = selection.getTokenMarker();
-
- /* Use painter's cached info for speed */
- FontMetrics fm = painter.getFontMetrics();
-
- selection.getLineText(line, lineSegment);
-
- final char[] segmentArray = lineSegment.array;
- final int segmentOffset = lineSegment.offset;
- final int segmentCount = lineSegment.count;
-
- int width = painter.getHorizontalOffset();
-
- if (tokenMarker == null) {
- for (int i = 0; i < segmentCount; i++) {
- final char c = segmentArray[i + segmentOffset];
- final int charWidth;
- if (c == '\t') {
- charWidth = (int) painter.nextTabStop((float) width, i) - width;
- } else {
- charWidth = fm.charWidth(c);
- }
-
- if (painter.isBlockCaretEnabled()) {
- if (x - charWidth <= width) {
- return i;
- }
- } else {
- if (x - charWidth / 2 <= width) {
- return i;
- }
- }
-
- width += charWidth;
- }
-
- return segmentCount;
- } else {
- final List<Token> tokens;
- if (painter.getCurrentLineIndex() == line && painter.getCurrentLineTokens() != null) {
- tokens = painter.getCurrentLineTokens();
- } else {
- painter.setCurrentLineIndex(line);
- tokens = tokenMarker.markTokens(lineSegment, line);
- painter.setCurrentLineTokens(tokens);
- }
-
- int offset = 0;
- final Font defaultFont = painter.getFont();
- final SyntaxStyles styles = painter.getStyles();
-
- for (final Token token : tokens) {
- final byte id = token.getId();
- if (id == Token.NULL) {
- fm = painter.getFontMetrics();
- } else {
- fm = styles.getStyle(id).getFontMetrics(defaultFont, painter.getGraphics());
- }
-
- final int length = token.getLength();
-
- for (int i = 0; i < length; i++) {
- final char c = segmentArray[segmentOffset + offset + i];
- final int charWidth;
- if (c == '\t') {
- charWidth = (int) painter.nextTabStop((float) width, offset + i) - width;
- } else {
- charWidth = fm.charWidth(c);
- }
-
- if (painter.isBlockCaretEnabled()) {
- if (x - charWidth <= width) {
- return offset + i;
- }
- } else {
- if (x - charWidth / 2 <= width) {
- return offset + i;
- }
- }
-
- width += charWidth;
- }
-
- offset += length;
- }
- return offset;
- }
+ return painter.xToOffset(line, x);
}
/**
- * Converts a point to an offset, from the start of the text.
- * @param x the x co-ordinate of the point
- * @param y the y co-ordinate of the point
- */
- public int xyToOffset(final int x, final int y) {
- final int line = yToLine(y);
- final int start = selection.getLineStartOffset(line);
- return start + xToOffset(line, x);
- }
-
- /**
* Returns the document this text area is editing.
*/
@NotNull
@@ -1258,7 +1096,7 @@
}
setSelectionRectangular((e.getModifiers() & InputEvent.CTRL_MASK) != 0);
- select(selection.getMarkPosition(), xyToOffset(e.getX(), e.getY()));
+ select(selection.getMarkPosition(), painter.xyToOffset(e.getX(), e.getY()));
}
@Override
@@ -1301,7 +1139,7 @@
return;
}
- final int line = yToLine(e.getY());
+ final int line = painter.yToLine(e.getY());
final int offset = xToOffset(line, e.getX());
final int dot = selection.getLineStartOffset(line) + offset;
Modified: trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/TextAreaPainter.java
===================================================================
--- trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/TextAreaPainter.java 2014-02-28 20:33:33 UTC (rev 9668)
+++ trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/TextAreaPainter.java 2014-02-28 20:49:32 UTC (rev 9669)
@@ -218,6 +218,9 @@
private int horizontalOffset;
+ @NotNull
+ private final Segment lineSegment = new Segment();
+
/**
* Creates a new repaint manager. This should be not be called directly.
* @param textArea the associated text area that is painted
@@ -585,18 +588,18 @@
final int x2;
if (selection.isSelectionRectangular()) {
final int lineLen = selection.getLineLength(line);
- x1 = textArea.offsetToX2(line, Math.min(lineLen, selectionStart - selection.getLineStartOffset(selectionStartLine)));
- final int x3 = textArea.offsetToX2(line, Math.min(lineLen, selectionEnd - selection.getLineStartOffset(selectionEndLine)));
+ x1 = offsetToX2(line, Math.min(lineLen, selectionStart - selection.getLineStartOffset(selectionStartLine)));
+ final int x3 = offsetToX2(line, Math.min(lineLen, selectionEnd - selection.getLineStartOffset(selectionEndLine)));
x2 = x3 + (x1 == x3 ? 1 : 0);
} else if (selectionStartLine == selectionEndLine) {
- x1 = textArea.offsetToX2(line, selectionStart - lineStart);
- x2 = textArea.offsetToX2(line, selectionEnd - lineStart);
+ x1 = offsetToX2(line, selectionStart - lineStart);
+ x2 = offsetToX2(line, selectionEnd - lineStart);
} else if (line == selectionStartLine) {
- x1 = textArea.offsetToX2(line, selectionStart - lineStart);
+ x1 = offsetToX2(line, selectionStart - lineStart);
x2 = getWidth();
} else if (line == selectionEndLine) {
x1 = 0;
- x2 = textArea.offsetToX2(line, selectionEnd - lineStart);
+ x2 = offsetToX2(line, selectionEnd - lineStart);
} else {
x1 = 0;
x2 = getWidth();
@@ -620,7 +623,7 @@
}
final int yy = y + fontMetrics.getLeading() + fontMetrics.getMaxDescent();
- final int xx = textArea.offsetToX2(line, position);
+ final int xx = offsetToX2(line, position);
gfx.setColor(bracketHighlightColor);
// Hack!!! Since there is no fast way to get the character
// from the bracket matching routine, we use ( since all
@@ -637,7 +640,7 @@
private void paintCaret(@NotNull final Graphics gfx, final int line, final int y) {
if (caret.isCaretVisible()) {
final int offset = selection.getCaretPosition() - selection.getLineStartOffset(line);
- final int caretX = textArea.offsetToX2(line, offset);
+ final int caretX = offsetToX2(line, offset);
final int caretWidth = blockCaret || config.isOverwrite() ? fontMetrics.charWidth('w') : 1;
final int yy = y + fontMetrics.getLeading() + fontMetrics.getMaxDescent();
final int height = fontMetrics.getHeight();
@@ -755,4 +758,187 @@
return true;
}
+ /**
+ * Converts an offset in a line into an x co-ordinate. This is a fast
+ * version that should only be used if no changes were made to the text
+ * since the last repaint.
+ * @param line the line
+ * @param offset the offset, from the start of the line
+ */
+ public int offsetToX2(final int line, final int offset) {
+ final TokenMarker tokenMarker = selection.getTokenMarker();
+
+ /* Use painter's cached info for speed */
+ FontMetrics fm = fontMetrics;
+
+ selection.getLineText(line, lineSegment);
+
+ final int segmentOffset = lineSegment.offset;
+ int x = horizontalOffset;
+
+ /* If syntax coloring is disabled, do simple translation */
+ if (tokenMarker == null) {
+ lineSegment.count = offset;
+ return x + Utilities.getTabbedTextWidth(lineSegment, fm, x, this, 0);
+ } else {
+ /* If syntax coloring is enabled, we have to do this because
+ * tokens can vary in width */
+ final List<Token> tokens;
+ if (currentLineIndex == line && getCurrentLineTokens() != null) {
+ tokens = getCurrentLineTokens();
+ } else {
+ currentLineIndex = line;
+ tokens = tokenMarker.markTokens(lineSegment, line);
+ setCurrentLineTokens(tokens);
+ }
+
+ final Font defaultFont = getFont();
+ for (final Token token : tokens) {
+ final byte id = token.getId();
+ if (id == Token.NULL) {
+ fm = fontMetrics;
+ } else {
+ fm = styles.getStyle(id).getFontMetrics(defaultFont, getGraphics());
+ }
+
+ final int length = token.getLength();
+
+ if (offset + segmentOffset < lineSegment.offset + length) {
+ lineSegment.count = offset - (lineSegment.offset - segmentOffset);
+ return x + Utilities.getTabbedTextWidth(lineSegment, fm, x, this, 0);
+ }
+ lineSegment.count = length;
+ x += Utilities.getTabbedTextWidth(lineSegment, fm, x, this, 0);
+ lineSegment.offset += length;
+ }
+ return x;
+ }
+ }
+
+ /**
+ * Converts an offset in a line into an x co-ordinate. This is a slow
+ * version that can be used any time.
+ * @param line the line
+ * @param offset the offset, from the start of the line
+ */
+ public int offsetToX(final int line, final int offset) {
+ // don't use cached tokens
+ setCurrentLineTokens(null);
+ return offsetToX2(line, offset);
+ }
+
+ /**
+ * Converts a y co-ordinate to a line index.
+ * @param y the y co-ordinate
+ */
+ public int yToLine(final int y) {
+ final FontMetrics fm = fontMetrics;
+ final int height = fm.getHeight();
+ return Math.max(0, Math.min(selection.getLineCount() - 1, y / height + firstLine));
+ }
+
+ /**
+ * Converts an x co-ordinate to an offset within a line.
+ * @param line the line
+ * @param x the x co-ordinate
+ */
+ public int xToOffset(final int line, final int x) {
+ final TokenMarker tokenMarker = selection.getTokenMarker();
+
+ /* Use painter's cached info for speed */
+ FontMetrics fm = fontMetrics;
+
+ selection.getLineText(line, lineSegment);
+
+ final char[] segmentArray = lineSegment.array;
+ final int segmentOffset = lineSegment.offset;
+ final int segmentCount = lineSegment.count;
+
+ int width = horizontalOffset;
+
+ if (tokenMarker == null) {
+ for (int i = 0; i < segmentCount; i++) {
+ final char c = segmentArray[i + segmentOffset];
+ final int charWidth;
+ if (c == '\t') {
+ charWidth = (int) nextTabStop((float) width, i) - width;
+ } else {
+ charWidth = fm.charWidth(c);
+ }
+
+ if (blockCaret) {
+ if (x - charWidth <= width) {
+ return i;
+ }
+ } else {
+ if (x - charWidth / 2 <= width) {
+ return i;
+ }
+ }
+
+ width += charWidth;
+ }
+
+ return segmentCount;
+ } else {
+ final List<Token> tokens;
+ if (currentLineIndex == line && getCurrentLineTokens() != null) {
+ tokens = getCurrentLineTokens();
+ } else {
+ currentLineIndex = line;
+ tokens = tokenMarker.markTokens(lineSegment, line);
+ setCurrentLineTokens(tokens);
+ }
+
+ int offset = 0;
+ final Font defaultFont = getFont();
+ for (final Token token : tokens) {
+ final byte id = token.getId();
+ if (id == Token.NULL) {
+ fm = fontMetrics;
+ } else {
+ fm = styles.getStyle(id).getFontMetrics(defaultFont, getGraphics());
+ }
+
+ final int length = token.getLength();
+
+ for (int i = 0; i < length; i++) {
+ final char c = segmentArray[segmentOffset + offset + i];
+ final int charWidth;
+ if (c == '\t') {
+ charWidth = (int) nextTabStop((float) width, offset + i) - width;
+ } else {
+ charWidth = fm.charWidth(c);
+ }
+
+ if (blockCaret) {
+ if (x - charWidth <= width) {
+ return offset + i;
+ }
+ } else {
+ if (x - charWidth / 2 <= width) {
+ return offset + i;
+ }
+ }
+
+ width += charWidth;
+ }
+
+ offset += length;
+ }
+ return offset;
+ }
+ }
+
+ /**
+ * Converts a point to an offset, from the start of the text.
+ * @param x the x co-ordinate of the point
+ * @param y the y co-ordinate of the point
+ */
+ public int xyToOffset(final int x, final int y) {
+ final int line = yToLine(y);
+ final int start = selection.getLineStartOffset(line);
+ return start + xToOffset(line, x);
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <aki...@us...> - 2014-02-28 20:33:39
|
Revision: 9668
http://sourceforge.net/p/gridarta/code/9668
Author: akirschbaum
Date: 2014-02-28 20:33:33 +0000 (Fri, 28 Feb 2014)
Log Message:
-----------
Inline variable.
Modified Paths:
--------------
trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/scripteditor/ScriptEditView.java
Modified: trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/scripteditor/ScriptEditView.java
===================================================================
--- trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/scripteditor/ScriptEditView.java 2014-02-28 20:33:06 UTC (rev 9667)
+++ trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/scripteditor/ScriptEditView.java 2014-02-28 20:33:33 UTC (rev 9668)
@@ -274,8 +274,7 @@
final int oldIndex = tabPane.getSelectedIndex();
final int newIndex = oldIndex >= tabPane.getTabCount() - 1 ? oldIndex - 1 : oldIndex;
tabPane.setSelectedIndex(newIndex);
- final JEditTextArea textArea = textAreas.get(oldIndex);
- scriptEditUndoActions.removeDocument(textArea.getDocument());
+ scriptEditUndoActions.removeDocument(textAreas.get(oldIndex).getDocument());
textAreas.remove(oldIndex);
tabPane.remove(oldIndex);
actions.refresh();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <aki...@us...> - 2014-02-28 20:33:09
|
Revision: 9667
http://sourceforge.net/p/gridarta/code/9667
Author: akirschbaum
Date: 2014-02-28 20:33:06 +0000 (Fri, 28 Feb 2014)
Log Message:
-----------
Remove unused code.
Modified Paths:
--------------
trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.java
Modified: trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.java
===================================================================
--- trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.java 2014-02-28 20:29:25 UTC (rev 9666)
+++ trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.java 2014-02-28 20:33:06 UTC (rev 9667)
@@ -697,14 +697,6 @@
}
/**
- * Returns the length of the specified line.
- * @param line the line
- */
- public int getLineLength(final int line) {
- return selection.getLineLength(line);
- }
-
- /**
* Returns the entire text of this text area.
*/
@NotNull
@@ -752,15 +744,6 @@
}
/**
- * Copies the text on the specified line into a segment. If the line is
- * invalid, the segment will contain a null string.
- * @param lineIndex the line
- */
- public void getLineText(final int lineIndex, @NotNull final Segment segment) {
- selection.getLineText(lineIndex, segment);
- }
-
- /**
* Returns the selection start offset.
*/
public int getSelectionStart() {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <aki...@us...> - 2014-02-28 20:29:31
|
Revision: 9666
http://sourceforge.net/p/gridarta/code/9666
Author: akirschbaum
Date: 2014-02-28 20:29:25 +0000 (Fri, 28 Feb 2014)
Log Message:
-----------
Remove some calls to JEditTextArea.getDocument().
Modified Paths:
--------------
trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/AttributesPaneBuilder.java
trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/scripteditor/ScriptEditView.java
Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/AttributesPaneBuilder.java
===================================================================
--- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/AttributesPaneBuilder.java 2014-02-28 20:25:24 UTC (rev 9665)
+++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/AttributesPaneBuilder.java 2014-02-28 20:29:25 UTC (rev 9666)
@@ -483,8 +483,9 @@
} else {
text = "";
}
- final JEditTextArea input = new JEditTextArea(textAreaDefaults, new SyntaxDocument(), false);
- input.getDocument().setTokenMarker(TokenMarkerFactory.createTokenMarker(archetypeAttribute.getFileExtension()));
+ final SyntaxDocument document = new SyntaxDocument();
+ document.setTokenMarker(TokenMarkerFactory.createTokenMarker(archetypeAttribute.getFileExtension()));
+ final JEditTextArea input = new JEditTextArea(textAreaDefaults, document, false);
input.setText(text == null ? "" : text);
input.setCaretPosition(0);
input.setBorder(BorderFactory.createEmptyBorder(3, 7, 0, 0));
Modified: trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/scripteditor/ScriptEditView.java
===================================================================
--- trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/scripteditor/ScriptEditView.java 2014-02-28 20:25:24 UTC (rev 9665)
+++ trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/scripteditor/ScriptEditView.java 2014-02-28 20:29:25 UTC (rev 9666)
@@ -192,10 +192,10 @@
*/
public void addTab(@NotNull final String title, @Nullable final File file) {
final SyntaxDocument syntaxDocument = new SyntaxDocument();
+ syntaxDocument.setTokenMarker(TokenMarkerFactory.createTokenMarker(file));
final JEditTextArea ta = new JEditTextArea(textAreaDefaults, syntaxDocument, textAreaDefaults.getPaintInvalid()); // open new TextArea
//ta.setFont(new Font("Courier New", Font.PLAIN, 12));
textAreas.add(ta);
- ta.getDocument().setTokenMarker(TokenMarkerFactory.createTokenMarker(file));
scriptEditUndoActions.addDocument(syntaxDocument);
tabPane.addTab(title, ta);
if (getTabCount() <= 1 || !isShowing()) {
@@ -235,7 +235,7 @@
}
buff.append(line);
}
- ta.getDocument().insertString(0, buff.toString(), null);
+ syntaxDocument.insertString(0, buff.toString(), null);
} finally {
in.close();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <aki...@us...> - 2014-02-28 20:25:30
|
Revision: 9665
http://sourceforge.net/p/gridarta/code/9665
Author: akirschbaum
Date: 2014-02-28 20:25:24 +0000 (Fri, 28 Feb 2014)
Log Message:
-----------
Remove JEditTextArea.getPainter().
Modified Paths:
--------------
trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/AttributesPaneBuilder.java
trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/scripteditor/ScriptEditView.java
trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.java
trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/TextAreaPainter.java
Modified: trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/AttributesPaneBuilder.java
===================================================================
--- trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/AttributesPaneBuilder.java 2014-02-28 20:19:40 UTC (rev 9664)
+++ trunk/src/gridarta/src/main/java/net/sf/gridarta/gui/dialog/gameobjectattributes/AttributesPaneBuilder.java 2014-02-28 20:25:24 UTC (rev 9665)
@@ -483,12 +483,11 @@
} else {
text = "";
}
- final JEditTextArea input = new JEditTextArea(textAreaDefaults, new SyntaxDocument());
+ final JEditTextArea input = new JEditTextArea(textAreaDefaults, new SyntaxDocument(), false);
input.getDocument().setTokenMarker(TokenMarkerFactory.createTokenMarker(archetypeAttribute.getFileExtension()));
input.setText(text == null ? "" : text);
input.setCaretPosition(0);
input.setBorder(BorderFactory.createEmptyBorder(3, 7, 0, 0));
- input.getPainter().setInvalidLinesPainted(false);
guiInfo = new GuiInfoGlue<G, A, R, ArchetypeAttributeText>(new DialogAttributeText<G, A, R>(archetypeAttribute, input), input);
}
Modified: trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/scripteditor/ScriptEditView.java
===================================================================
--- trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/scripteditor/ScriptEditView.java 2014-02-28 20:19:40 UTC (rev 9664)
+++ trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/scripteditor/ScriptEditView.java 2014-02-28 20:25:24 UTC (rev 9665)
@@ -192,7 +192,7 @@
*/
public void addTab(@NotNull final String title, @Nullable final File file) {
final SyntaxDocument syntaxDocument = new SyntaxDocument();
- final JEditTextArea ta = new JEditTextArea(textAreaDefaults, syntaxDocument); // open new TextArea
+ final JEditTextArea ta = new JEditTextArea(textAreaDefaults, syntaxDocument, textAreaDefaults.getPaintInvalid()); // open new TextArea
//ta.setFont(new Font("Courier New", Font.PLAIN, 12));
textAreas.add(ta);
ta.getDocument().setTokenMarker(TokenMarkerFactory.createTokenMarker(file));
Modified: trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.java
===================================================================
--- trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.java 2014-02-28 20:19:40 UTC (rev 9664)
+++ trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.java 2014-02-28 20:25:24 UTC (rev 9665)
@@ -155,8 +155,10 @@
/**
* Creates a new JEditTextArea with the specified settings.
* @param defaults the default settings
+ * @param paintInvalid whether invalid lines should be painted as red
+ * tildes
*/
- public JEditTextArea(@NotNull final TextAreaDefaults defaults, @NotNull final SyntaxDocument document) {
+ public JEditTextArea(@NotNull final TextAreaDefaults defaults, @NotNull final SyntaxDocument document, final boolean paintInvalid) {
// Enable the necessary events
enableEvents(AWTEvent.KEY_EVENT_MASK);
@@ -164,7 +166,7 @@
caret = new TextAreaCaret(defaults.getCaretVisible(), defaults.getCaretBlinks());
selection = new TextAreaSelection(document);
config = new TextAreaConfig(defaults.getEditable(), defaults.getElectricScroll());
- painter = new TextAreaPainter(this, selection, caret, defaults, brackets, config);
+ painter = new TextAreaPainter(this, selection, caret, defaults, brackets, config, paintInvalid);
documentHandler = new DocumentHandler();
lineSegment = new Segment();
@@ -259,14 +261,6 @@
}
/**
- * Returns the object responsible for painting this text area.
- */
- @NotNull
- public TextAreaPainter getPainter() {
- return painter;
- }
-
- /**
* Returns the input handler.
*/
@NotNull
Modified: trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/TextAreaPainter.java
===================================================================
--- trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/TextAreaPainter.java 2014-02-28 20:19:40 UTC (rev 9664)
+++ trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/TextAreaPainter.java 2014-02-28 20:25:24 UTC (rev 9665)
@@ -143,7 +143,7 @@
* Whether invalid lines should be painted as red tildes.
* @serial
*/
- private boolean paintInvalid;
+ private final boolean paintInvalid;
/**
* The color for painting eol markers.
@@ -224,8 +224,10 @@
* @param defaults the text attributes to use
* @param brackets the brackets to paint
* @param config the text area configuration options to use
+ * @param paintInvalid whether invalid lines should be painted as red
+ * tildes
*/
- public TextAreaPainter(@NotNull final JEditTextArea textArea, @NotNull final TextAreaSelection selection, @NotNull final TextAreaCaret caret, @NotNull final TextAreaDefaults defaults, @NotNull final TextAreaBrackets brackets, @NotNull final TextAreaConfig config) {
+ public TextAreaPainter(@NotNull final JEditTextArea textArea, @NotNull final TextAreaSelection selection, @NotNull final TextAreaCaret caret, @NotNull final TextAreaDefaults defaults, @NotNull final TextAreaBrackets brackets, @NotNull final TextAreaConfig config, final boolean paintInvalid) {
this.textArea = textArea;
this.selection = selection;
this.caret = caret;
@@ -254,7 +256,7 @@
lineHighlight = defaults.getLineHighlight();
bracketHighlightColor = defaults.getBracketHighlightColor();
bracketHighlight = defaults.getBracketHighlight();
- paintInvalid = defaults.getPaintInvalid();
+ this.paintInvalid = paintInvalid;
eolMarkerColor = defaults.getEolMarkerColor();
eolMarkers = defaults.getEolMarkers();
}
@@ -333,15 +335,6 @@
}
/**
- * Sets whether invalid lines are to be painted as red tildes.
- * @param paintInvalid whether invalid lines should be drawn
- */
- public void setInvalidLinesPainted(final boolean paintInvalid) {
- this.paintInvalid = paintInvalid;
- repaint();
- }
-
- /**
* Returns the font metrics used by this component.
* @return the font metrics
*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <aki...@us...> - 2014-02-28 20:19:45
|
Revision: 9664
http://sourceforge.net/p/gridarta/code/9664
Author: akirschbaum
Date: 2014-02-28 20:19:40 +0000 (Fri, 28 Feb 2014)
Log Message:
-----------
Remove some calls from TextAreaPainter to JEditTextArea.
Modified Paths:
--------------
trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.java
trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/TextAreaPainter.java
Modified: trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.java
===================================================================
--- trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.java 2014-02-28 20:15:28 UTC (rev 9663)
+++ trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.java 2014-02-28 20:19:40 UTC (rev 9664)
@@ -163,7 +163,8 @@
// Initialize some misc. stuff
caret = new TextAreaCaret(defaults.getCaretVisible(), defaults.getCaretBlinks());
selection = new TextAreaSelection(document);
- painter = new TextAreaPainter(this, selection, caret, defaults, brackets);
+ config = new TextAreaConfig(defaults.getEditable(), defaults.getElectricScroll());
+ painter = new TextAreaPainter(this, selection, caret, defaults, brackets, config);
documentHandler = new DocumentHandler();
lineSegment = new Segment();
@@ -197,7 +198,6 @@
// We don't seem to get the initial focus event?
focusedComponent = this;
- config = new TextAreaConfig(defaults.getEditable(), defaults.getElectricScroll());
}
/**
Modified: trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/TextAreaPainter.java
===================================================================
--- trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/TextAreaPainter.java 2014-02-28 20:15:28 UTC (rev 9663)
+++ trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/TextAreaPainter.java 2014-02-28 20:19:40 UTC (rev 9664)
@@ -75,6 +75,12 @@
private final TextAreaBrackets brackets;
/**
+ * The {@link TextAreaConfig} options to use.
+ */
+ @NotNull
+ private final TextAreaConfig config;
+
+ /**
* Whether the caret should be wide even in insert mode.
* @serial
*/
@@ -217,12 +223,14 @@
* @param textArea the associated text area that is painted
* @param defaults the text attributes to use
* @param brackets the brackets to paint
+ * @param config the text area configuration options to use
*/
- public TextAreaPainter(@NotNull final JEditTextArea textArea, @NotNull final TextAreaSelection selection, @NotNull final TextAreaCaret caret, @NotNull final TextAreaDefaults defaults, @NotNull final TextAreaBrackets brackets) {
+ public TextAreaPainter(@NotNull final JEditTextArea textArea, @NotNull final TextAreaSelection selection, @NotNull final TextAreaCaret caret, @NotNull final TextAreaDefaults defaults, @NotNull final TextAreaBrackets brackets, @NotNull final TextAreaConfig config) {
this.textArea = textArea;
this.selection = selection;
this.caret = caret;
this.brackets = brackets;
+ this.config = config;
setAutoscrolls(true);
setDoubleBuffered(true);
@@ -637,13 +645,13 @@
if (caret.isCaretVisible()) {
final int offset = selection.getCaretPosition() - selection.getLineStartOffset(line);
final int caretX = textArea.offsetToX2(line, offset);
- final int caretWidth = blockCaret || textArea.isOverwriteEnabled() ? fontMetrics.charWidth('w') : 1;
+ final int caretWidth = blockCaret || config.isOverwrite() ? fontMetrics.charWidth('w') : 1;
final int yy = y + fontMetrics.getLeading() + fontMetrics.getMaxDescent();
final int height = fontMetrics.getHeight();
gfx.setColor(caretColor);
- if (textArea.isOverwriteEnabled()) {
+ if (config.isOverwrite()) {
gfx.fillRect(caretX, yy + height - 1, caretWidth, 1);
} else {
if (caretWidth <= 1) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <aki...@us...> - 2014-02-28 20:15:33
|
Revision: 9663
http://sourceforge.net/p/gridarta/code/9663
Author: akirschbaum
Date: 2014-02-28 20:15:28 +0000 (Fri, 28 Feb 2014)
Log Message:
-----------
Extract TextAreaConfig from JEditTextArea.
Modified Paths:
--------------
trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.java
Added Paths:
-----------
trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/TextAreaConfig.java
Modified: trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.java
===================================================================
--- trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.java 2014-02-28 20:01:14 UTC (rev 9662)
+++ trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.java 2014-02-28 20:15:28 UTC (rev 9663)
@@ -120,10 +120,6 @@
@NotNull
private final TextAreaCaret caret;
- private final boolean editable;
-
- private final int electricScroll;
-
@NotNull
private final JScrollBar vertical = new JScrollBar(Adjustable.VERTICAL);
@@ -150,10 +146,12 @@
@NotNull
private final TextAreaBrackets brackets = new TextAreaBrackets();
- private int magicCaret;
+ /**
+ * The {@link TextAreaConfig} for this instance.
+ */
+ @NotNull
+ private final TextAreaConfig config;
- private boolean overwrite;
-
/**
* Creates a new JEditTextArea with the specified settings.
* @param defaults the default settings
@@ -191,8 +189,6 @@
document.addDocumentListener(documentHandler);
select(0, 0);
updateScrollBars();
- editable = defaults.getEditable();
- electricScroll = defaults.getElectricScroll();
popup = defaults.getPopup();
@@ -201,6 +197,7 @@
// We don't seem to get the initial focus event?
focusedComponent = this;
+ config = new TextAreaConfig(defaults.getEditable(), defaults.getElectricScroll());
}
/**
@@ -300,7 +297,7 @@
* are always visible.
*/
public int getElectricScroll() {
- return electricScroll;
+ return config.getElectricScroll();
}
/**
@@ -433,6 +430,7 @@
// we can't do any proper scrolling then, so we have
// this hack...
final int visibleLines = getVisibleLines();
+ final int electricScroll = config.getElectricScroll();
if (visibleLines == 0) {
setFirstLine(Math.max(0, line - electricScroll));
return;
@@ -882,8 +880,7 @@
selection.disableSelectionIfEmpty();
- // Clear the `magic' caret position used by up/down
- magicCaret = -1;
+ config.setMagicCaret(-1); // Clear the `magic' caret position used by up/down
scrollToCaret();
}
@@ -901,7 +898,7 @@
* @param selectedText the replacement text for the selection
*/
public void setSelectedText(@NotNull final String selectedText) {
- if (!editable) {
+ if (!config.isEditable()) {
throw new InternalError("Text component read only");
}
@@ -914,7 +911,7 @@
* Returns true if this text area is editable, false otherwise.
*/
public boolean isEditable() {
- return editable;
+ return config.isEditable();
}
/**
@@ -922,7 +919,7 @@
* column position when moving up and down lines.
*/
public int getMagicCaretPosition() {
- return magicCaret;
+ return config.getMagicCaret();
}
/**
@@ -931,7 +928,7 @@
* @param magicCaret the magic caret position
*/
public void setMagicCaretPosition(final int magicCaret) {
- this.magicCaret = magicCaret;
+ config.setMagicCaret(magicCaret);
}
/**
@@ -943,7 +940,7 @@
*/
public void overwriteSetSelectedText(@NotNull final String str) {
// Don't overstrike if there is a selection
- if (!overwrite || selection.getSelectionStart() != selection.getSelectionEnd()) {
+ if (!config.isOverwrite() || selection.getSelectionStart() != selection.getSelectionEnd()) {
setSelectedText(str);
return;
}
@@ -970,19 +967,19 @@
}
/**
- * Returns true if overwrite mode is enabled, false otherwise.
+ * Returns whether overwrite mode is active.
+ * @return whether overwrite mode is active
*/
public boolean isOverwriteEnabled() {
- return overwrite;
+ return config.isOverwrite();
}
/**
- * Sets if overwrite mode should be enabled.
- * @param overwrite true if overwrite mode should be enabled, false
- * otherwise
+ * Sets whether overwrite mode is active.
+ * @param overwrite whether overwrite mode is active
*/
public void setOverwriteEnabled(final boolean overwrite) {
- this.overwrite = overwrite;
+ config.setOverwrite(overwrite);
painter.invalidateSelectedLines();
}
@@ -1008,7 +1005,7 @@
* clipboard.
*/
public void cut() {
- if (editable) {
+ if (config.isEditable()) {
copy();
setSelectedText("");
}
@@ -1037,7 +1034,7 @@
* Inserts the clipboard contents into the text.
*/
public void paste() {
- if (editable) {
+ if (config.isEditable()) {
final Clipboard clipboard = getToolkit().getSystemClipboard();
try {
// The MacOS MRJ doesn't convert \r to \n,
Added: trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/TextAreaConfig.java
===================================================================
--- trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/TextAreaConfig.java (rev 0)
+++ trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/TextAreaConfig.java 2014-02-28 20:15:28 UTC (rev 9663)
@@ -0,0 +1,78 @@
+/*
+ * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
+ * Copyright (C) 2000-2011 The Gridarta Developers.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package net.sf.gridarta.textedit.textarea;
+
+/**
+ * Miscellaneous configuration settings for {@link JEditTextArea}.
+ */
+public class TextAreaConfig {
+
+ /**
+ * Whether overwrite mode is active.
+ */
+ private boolean overwrite;
+
+ private int magicCaret = -1;
+
+ private final boolean editable;
+
+ private final int electricScroll;
+
+ /**
+ * Creates a new instance.
+ */
+ public TextAreaConfig(final boolean editable, final int electricScroll) {
+ this.editable = editable;
+ this.electricScroll = electricScroll;
+ }
+
+ /**
+ * Returns whether overwrite mode is active.
+ * @return whether overwrite mode is active
+ */
+ public boolean isOverwrite() {
+ return overwrite;
+ }
+
+ /**
+ * Sets whether overwrite mode is active.
+ * @param overwrite whether overwrite mode is active
+ */
+ public void setOverwrite(final boolean overwrite) {
+ this.overwrite = overwrite;
+ }
+
+ public int getMagicCaret() {
+ return magicCaret;
+ }
+
+ public void setMagicCaret(final int magicCaret) {
+ this.magicCaret = magicCaret;
+ }
+
+ public boolean isEditable() {
+ return editable;
+ }
+
+ public int getElectricScroll() {
+ return electricScroll;
+ }
+
+}
Property changes on: trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/TextAreaConfig.java
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <aki...@us...> - 2014-02-28 20:01:19
|
Revision: 9662
http://sourceforge.net/p/gridarta/code/9662
Author: akirschbaum
Date: 2014-02-28 20:01:14 +0000 (Fri, 28 Feb 2014)
Log Message:
-----------
Extract TextAreaBrackets from JEditTextArea.
Modified Paths:
--------------
trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.java
trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/TextAreaPainter.java
Added Paths:
-----------
trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/TextAreaBrackets.java
Modified: trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.java
===================================================================
--- trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.java 2014-02-28 09:11:05 UTC (rev 9661)
+++ trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.java 2014-02-28 20:01:14 UTC (rev 9662)
@@ -147,10 +147,9 @@
@NotNull
private final TextAreaSelection selection;
- private int bracketPosition;
+ @NotNull
+ private final TextAreaBrackets brackets = new TextAreaBrackets();
- private int bracketLine;
-
private int magicCaret;
private boolean overwrite;
@@ -166,11 +165,9 @@
// Initialize some misc. stuff
caret = new TextAreaCaret(defaults.getCaretVisible(), defaults.getCaretBlinks());
selection = new TextAreaSelection(document);
- painter = new TextAreaPainter(this, selection, caret, defaults);
+ painter = new TextAreaPainter(this, selection, caret, defaults, brackets);
documentHandler = new DocumentHandler();
lineSegment = new Segment();
- bracketLine = -1;
- bracketPosition = -1;
// Initialize the GUI
setLayout(new ScrollLayout(this));
@@ -860,13 +857,14 @@
final int newEndLine = selection.getLineOfOffset(newEnd);
if (painter.isBracketHighlightEnabled()) {
- if (bracketLine != -1) {
- painter.invalidateLine(bracketLine);
+ final int oldBracketLine = brackets.getBracketLine();
+ if (oldBracketLine != -1) {
+ painter.invalidateLine(oldBracketLine);
}
-
updateBracketHighlight(end);
- if (bracketLine != -1) {
- painter.invalidateLine(bracketLine);
+ final int newBracketLine = brackets.getBracketLine();
+ if (newBracketLine != -1) {
+ painter.invalidateLine(newBracketLine);
}
}
@@ -1006,22 +1004,6 @@
}
/**
- * Returns the position of the highlighted bracket (the bracket matching the
- * one before the caret).
- */
- public int getBracketPosition() {
- return bracketPosition;
- }
-
- /**
- * Returns the line of the highlighted bracket (the bracket matching the one
- * before the caret).
- */
- public int getBracketLine() {
- return bracketLine;
- }
-
- /**
* Deletes the selected text from the text area and places it into the
* clipboard.
*/
@@ -1113,29 +1095,28 @@
super.processKeyEvent(e);
}
- void updateBracketHighlight(final int newCaretPosition) {
+ private void updateBracketHighlight(final int newCaretPosition) {
if (newCaretPosition == 0) {
- bracketPosition = -1;
- bracketLine = -1;
+ brackets.clear();
return;
}
try {
final int offset = TextUtilities.findMatchingBracket(document, newCaretPosition - 1);
if (offset != -1) {
- bracketLine = selection.getLineOfOffset(offset);
- bracketPosition = offset - selection.getLineStartOffset(bracketLine);
+ final int bracketLine = selection.getLineOfOffset(offset);
+ final int bracketPosition = offset - selection.getLineStartOffset(bracketLine);
+ brackets.set(bracketPosition, bracketLine);
return;
}
} catch (final BadLocationException bl) {
bl.printStackTrace();
}
- bracketLine = -1;
- bracketPosition = -1;
+ brackets.clear();
}
- void documentChanged(@NotNull final DocumentEvent evt) {
+ private void documentChanged(@NotNull final DocumentEvent evt) {
final DocumentEvent.ElementChange ch = evt.getChange(document.getDefaultRootElement());
final int count;
Added: trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/TextAreaBrackets.java
===================================================================
--- trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/TextAreaBrackets.java (rev 0)
+++ trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/TextAreaBrackets.java 2014-02-28 20:01:14 UTC (rev 9662)
@@ -0,0 +1,75 @@
+/*
+ * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
+ * Copyright (C) 2000-2011 The Gridarta Developers.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package net.sf.gridarta.textedit.textarea;
+
+/**
+ * Maintains information about the highlighted pairs of brackets.
+ */
+public class TextAreaBrackets {
+
+ /**
+ * The position of the highlighted bracket (in characters).
+ */
+ private int bracketPosition = -1;
+
+ /**
+ * The position of the highlighted bracket (in lines).
+ */
+ private int bracketLine = -1;
+
+ /**
+ * Returns the position of the highlighted bracket (the bracket matching the
+ * one before the caret).
+ * @return the position in characters or {@code -1} if none should be
+ * highlighted
+ */
+ public int getBracketPosition() {
+ return bracketPosition;
+ }
+
+ /**
+ * Returns the line of the highlighted bracket (the bracket matching the one
+ * before the caret).
+ * @return the position in lines or {@code -1} if none should be
+ * highlighted
+ */
+ public int getBracketLine() {
+ return bracketLine;
+ }
+
+ /**
+ * Clears the highlighted bracket.
+ */
+ public void clear() {
+ bracketPosition = -1;
+ bracketLine = -1;
+ }
+
+ /**
+ * Sets the highlighted bracket.
+ * @param bracketPosition the position in characters or {@code -1} to clear
+ * @param bracketLine the position in lines or {@code -1} to clear
+ */
+ public void set(final int bracketPosition, final int bracketLine) {
+ this.bracketPosition = bracketPosition;
+ this.bracketLine = bracketLine;
+ }
+
+}
Property changes on: trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/TextAreaBrackets.java
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/TextAreaPainter.java
===================================================================
--- trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/TextAreaPainter.java 2014-02-28 09:11:05 UTC (rev 9661)
+++ trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/TextAreaPainter.java 2014-02-28 20:01:14 UTC (rev 9662)
@@ -69,6 +69,12 @@
private final TextAreaCaret caret;
/**
+ * The brackets to paint.
+ */
+ @NotNull
+ private final TextAreaBrackets brackets;
+
+ /**
* Whether the caret should be wide even in insert mode.
* @serial
*/
@@ -210,11 +216,13 @@
* Creates a new repaint manager. This should be not be called directly.
* @param textArea the associated text area that is painted
* @param defaults the text attributes to use
+ * @param brackets the brackets to paint
*/
- public TextAreaPainter(@NotNull final JEditTextArea textArea, @NotNull final TextAreaSelection selection, @NotNull final TextAreaCaret caret, @NotNull final TextAreaDefaults defaults) {
+ public TextAreaPainter(@NotNull final JEditTextArea textArea, @NotNull final TextAreaSelection selection, @NotNull final TextAreaCaret caret, @NotNull final TextAreaDefaults defaults, @NotNull final TextAreaBrackets brackets) {
this.textArea = textArea;
this.selection = selection;
this.caret = caret;
+ this.brackets = brackets;
setAutoscrolls(true);
setDoubleBuffered(true);
@@ -538,7 +546,7 @@
paintLineHighlight(gfx, line, y);
}
- if (bracketHighlight && line == textArea.getBracketLine()) {
+ if (bracketHighlight && line == brackets.getBracketLine()) {
paintBracketHighlight(gfx, line, y);
}
@@ -605,7 +613,7 @@
* @param y the y-offset for painting
*/
private void paintBracketHighlight(@NotNull final Graphics gfx, final int line, final int y) {
- final int position = textArea.getBracketPosition();
+ final int position = brackets.getBracketPosition();
if (position == -1) {
return;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <aki...@us...> - 2014-02-28 09:11:10
|
Revision: 9661
http://sourceforge.net/p/gridarta/code/9661
Author: akirschbaum
Date: 2014-02-28 09:11:05 +0000 (Fri, 28 Feb 2014)
Log Message:
-----------
Move code from JEditTextArea to TextAreaPainter.
Modified Paths:
--------------
trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.java
trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/TextAreaPainter.java
Modified: trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.java
===================================================================
--- trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.java 2014-02-28 09:04:07 UTC (rev 9660)
+++ trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/JEditTextArea.java 2014-02-28 09:11:05 UTC (rev 9661)
@@ -124,8 +124,6 @@
private final int electricScroll;
- private int horizontalOffset;
-
@NotNull
private final JScrollBar vertical = new JScrollBar(Adjustable.VERTICAL);
@@ -324,7 +322,7 @@
final int width = painter.getWidth();
if (width != 0) {
- horizontal.setValues(-horizontalOffset, width, 0, width * 5);
+ horizontal.setValues(-painter.getHorizontalOffset(), width, 0, width * 5);
//horizontal.setUnitIncrement(painter.getFontMetrics().charWidth('w'));
horizontal.setUnitIncrement(painter.getDefaultCharWidth());
horizontal.setBlockIncrement(width / 2);
@@ -361,23 +359,15 @@
}
/**
- * Returns the horizontal offset of drawn lines.
- */
- public int getHorizontalOffset() {
- return horizontalOffset;
- }
-
- /**
* Sets the horizontal offset of drawn lines. This can be used to implement
* horizontal scrolling.
* @param horizontalOffset offset The new horizontal offset
*/
public void setHorizontalOffset(final int horizontalOffset) {
- if (horizontalOffset == this.horizontalOffset) {
+ if (!painter.setHorizontalOffset(horizontalOffset)) {
return;
}
- this.horizontalOffset = horizontalOffset;
if (horizontalOffset != horizontal.getValue()) {
updateScrollBars();
}
@@ -393,8 +383,7 @@
public void setOrigin(final int firstLine, final int horizontalOffset) {
boolean changed = false;
- if (horizontalOffset != this.horizontalOffset) {
- this.horizontalOffset = horizontalOffset;
+ if (painter.setHorizontalOffset(horizontalOffset)) {
changed = true;
}
@@ -453,6 +442,7 @@
}
int newFirstLine = painter.getFirstLine();
+ final int horizontalOffset = painter.getHorizontalOffset();
int newHorizontalOffset = horizontalOffset;
if (line < newFirstLine + electricScroll) {
@@ -525,7 +515,7 @@
selection.getLineText(line, lineSegment);
final int segmentOffset = lineSegment.offset;
- int x = horizontalOffset;
+ int x = painter.getHorizontalOffset();
/* If syntax coloring is disabled, do simple translation */
if (tokenMarker == null) {
@@ -585,7 +575,7 @@
final int segmentOffset = lineSegment.offset;
final int segmentCount = lineSegment.count;
- int width = horizontalOffset;
+ int width = painter.getHorizontalOffset();
if (tokenMarker == null) {
for (int i = 0; i < segmentCount; i++) {
Modified: trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/TextAreaPainter.java
===================================================================
--- trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/TextAreaPainter.java 2014-02-28 09:04:07 UTC (rev 9660)
+++ trunk/src/textedit/src/main/java/net/sf/gridarta/textedit/textarea/TextAreaPainter.java 2014-02-28 09:11:05 UTC (rev 9661)
@@ -204,6 +204,8 @@
private int firstLine;
+ private int horizontalOffset;
+
/**
* Creates a new repaint manager. This should be not be called directly.
* @param textArea the associated text area that is painted
@@ -366,10 +368,9 @@
try {
final TokenMarker tokenMarker = selection.getDocument().getTokenMarker();
- final int x = textArea.getHorizontalOffset();
for (int line = firstInvalid; line <= lastInvalid; line++) {
- paintLine(g, tokenMarker, line, x);
+ paintLine(g, tokenMarker, line, horizontalOffset);
}
if (tokenMarker != null && tokenMarker.isNextLineRequested()) {
@@ -410,9 +411,8 @@
*/
@Override
public float nextTabStop(final float x, final int tabOffset) {
- final int offset = textArea.getHorizontalOffset();
- final int nTabs = ((int) x - offset) / tabSize;
- return (float) ((nTabs + 1) * tabSize + offset);
+ final int nTabs = ((int) x - horizontalOffset) / tabSize;
+ return (float) ((nTabs + 1) * tabSize + horizontalOffset);
}
/**
@@ -730,4 +730,20 @@
return (line - firstLine) * fontMetrics.getHeight() - (fontMetrics.getLeading() + fontMetrics.getMaxDescent());
}
+ /**
+ * Returns the horizontal offset of drawn lines.
+ */
+ public int getHorizontalOffset() {
+ return horizontalOffset;
+ }
+
+ public boolean setHorizontalOffset(final int horizontalOffset) {
+ if (this.horizontalOffset == horizontalOffset) {
+ return false;
+ }
+
+ this.horizontalOffset = horizontalOffset;
+ return true;
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|