diff artifacts/src/main/java/org/dive4elements/river/themes/DefaultTheme.java @ 9555:ef5754ba5573

Implemented legend aggregation based on type of themes. Added theme-editor style configuration for aggregated legend entries. Only configured themes get aggregated.
author gernotbelger
date Tue, 23 Oct 2018 16:26:48 +0200
parents af13ceeba52a
children
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/themes/DefaultTheme.java	Mon Oct 22 18:26:05 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/themes/DefaultTheme.java	Tue Oct 23 16:26:48 2018 +0200
@@ -11,139 +11,83 @@
 import java.util.HashMap;
 import java.util.Map;
 
+import org.dive4elements.artifacts.common.utils.XMLUtils;
+import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 
-import org.dive4elements.artifacts.common.utils.XMLUtils;
-import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator;
-
 
 /**
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
  */
-public class DefaultTheme implements Theme {
+final class DefaultTheme implements Theme {
 
     /** The name of the theme.*/
-    protected String name;
+    private final String name;
 
-    /** The description of the theme.*/
-    protected String description;
+    private String facet;
 
-    protected String facet;
-
-    protected int index;
-
+    private int index;
 
     /** The map storing the fields of this theme.*/
-    protected Map<String, ThemeField> fields;
+    private final Map<String, ThemeField> fields;
 
     /** The map storing the attributes of this theme.*/
-    protected Map<String, String> attr;
+    private final Map<String, String> attr;
 
+    private final String description;
 
     /**
      * Initializes the components of this Theme.
      */
-    public DefaultTheme(String name, String description) {
+    public DefaultTheme(final String name, final String description) {
         this.name        = name;
         this.description = description;
-        this.fields      = new HashMap<String, ThemeField>();
-        this.attr        = new HashMap<String, String>();
-    }
-
-
-    public void init(Node config) {
+        this.fields      = new HashMap<>();
+        this.attr        = new HashMap<>();
     }
 
-
+    @Override
     public String getName() {
-        return name;
+        return this.name;
     }
 
-
     public String getDescription() {
-        return description;
+        return this.description;
     }
 
-
-    public String getFacet() {
-        return facet;
-    }
-
-
-    public void setFacet(String facet) {
+    @Override
+    public void setFacet(final String facet) {
         this.facet = facet;
     }
 
-
-    public int getIndex() {
-        return index;
-    }
-
-
-    public void setIndex(int index) {
+    @Override
+    public void setIndex(final int index) {
         this.index = index;
     }
 
-
-    public void addAttribute(String name, String value) {
+    public void addAttribute(final String name, final String value) {
         if (name != null && value != null) {
-            attr.put(name, value);
+            this.attr.put(name, value);
         }
     }
 
-
-    public String getAttribute(String name) {
-        return attr.get(name);
-    }
-
-
-    public void addField(String name, ThemeField field) {
+    public void addField(final String name, final ThemeField field) {
         if (name != null && field != null) {
-            fields.put(name, field);
-        }
-    }
-
-
-    public void setFieldValue(String name, Object value) {
-        if (name != null && value != null) {
-            ThemeField field = fields.get(name);
-
-            if (field != null) {
-                field.setValue(value);
-            }
+            this.fields.put(name, field);
         }
     }
 
-
-    public ThemeField getField(String name) {
-        return fields.get(name);
-    }
-
-
-    public String getFieldType(String name) {
-        ThemeField field = fields.get(name);
-
-        return field != null ? field.getType() : null;
-    }
-
+    @Override
+    public Document toXML() {
+        final Document doc = XMLUtils.newDocument();
 
-    public Object getFieldValue(String name) {
-        ThemeField field = fields.get(name);
-
-        return field != null ? field.getValue() : null;
-    }
-
+        final ElementCreator cr = new ElementCreator(doc, null, null);
 
-    public Document toXML() {
-        Document doc = XMLUtils.newDocument();
-
-        ElementCreator cr = new ElementCreator(doc, null, null);
-
-        Element theme = cr.create("theme");
-        theme.setAttribute("facet", facet);
-        theme.setAttribute("index", String.valueOf(index));
+        final Element theme = cr.create("theme");
+        theme.setAttribute("facet", this.facet);
+        theme.setAttribute("index", String.valueOf(this.index));
 
         appendAttributes(cr, theme);
         appendFields(cr, theme);
@@ -160,11 +104,11 @@
      * @param cr The ElementCreator.
      * @param theme The document root element.
      */
-    protected void appendAttributes(ElementCreator cr, Element theme) {
+    protected void appendAttributes(final ElementCreator cr, final Element theme) {
 
-        for (Map.Entry<String, String> entry: attr.entrySet()) {
-            String key = entry.getKey();
-            String val = entry.getValue();
+        for (final Map.Entry<String, String> entry: this.attr.entrySet()) {
+            final String key = entry.getKey();
+            final String val = entry.getValue();
 
             if (key != null && val != null) {
                 cr.addAttr(theme, key, val);
@@ -179,14 +123,13 @@
      * @param cr The ElementCreator.
      * @param theme The document root element.
      */
-    protected void appendFields(ElementCreator cr, Element theme) {
+    protected void appendFields(final ElementCreator cr, final Element theme) {
 
-        for (ThemeField field: fields.values()) {
-            Document doc = field.toXML();
-            Node    root = doc.getFirstChild();
+        for (final ThemeField field: this.fields.values()) {
+            final Document doc = field.toXML();
+            final Node    root = doc.getFirstChild();
 
             theme.appendChild(theme.getOwnerDocument().importNode(root, true));
         }
     }
-}
-// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
+}
\ No newline at end of file

http://dive4elements.wald.intevation.org