Mercurial > dive4elements > river
comparison 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 |
comparison
equal
deleted
inserted
replaced
9554:33ce8eba9806 | 9555:ef5754ba5573 |
---|---|
9 package org.dive4elements.river.themes; | 9 package org.dive4elements.river.themes; |
10 | 10 |
11 import java.util.HashMap; | 11 import java.util.HashMap; |
12 import java.util.Map; | 12 import java.util.Map; |
13 | 13 |
14 import org.dive4elements.artifacts.common.utils.XMLUtils; | |
15 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator; | |
14 import org.w3c.dom.Document; | 16 import org.w3c.dom.Document; |
15 import org.w3c.dom.Element; | 17 import org.w3c.dom.Element; |
16 import org.w3c.dom.Node; | 18 import org.w3c.dom.Node; |
17 | |
18 import org.dive4elements.artifacts.common.utils.XMLUtils; | |
19 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator; | |
20 | 19 |
21 | 20 |
22 /** | 21 /** |
23 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 22 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
24 */ | 23 */ |
25 public class DefaultTheme implements Theme { | 24 final class DefaultTheme implements Theme { |
26 | 25 |
27 /** The name of the theme.*/ | 26 /** The name of the theme.*/ |
28 protected String name; | 27 private final String name; |
29 | 28 |
30 /** The description of the theme.*/ | 29 private String facet; |
31 protected String description; | |
32 | 30 |
33 protected String facet; | 31 private int index; |
34 | |
35 protected int index; | |
36 | |
37 | 32 |
38 /** The map storing the fields of this theme.*/ | 33 /** The map storing the fields of this theme.*/ |
39 protected Map<String, ThemeField> fields; | 34 private final Map<String, ThemeField> fields; |
40 | 35 |
41 /** The map storing the attributes of this theme.*/ | 36 /** The map storing the attributes of this theme.*/ |
42 protected Map<String, String> attr; | 37 private final Map<String, String> attr; |
43 | 38 |
39 private final String description; | |
44 | 40 |
45 /** | 41 /** |
46 * Initializes the components of this Theme. | 42 * Initializes the components of this Theme. |
47 */ | 43 */ |
48 public DefaultTheme(String name, String description) { | 44 public DefaultTheme(final String name, final String description) { |
49 this.name = name; | 45 this.name = name; |
50 this.description = description; | 46 this.description = description; |
51 this.fields = new HashMap<String, ThemeField>(); | 47 this.fields = new HashMap<>(); |
52 this.attr = new HashMap<String, String>(); | 48 this.attr = new HashMap<>(); |
53 } | 49 } |
54 | 50 |
55 | 51 @Override |
56 public void init(Node config) { | 52 public String getName() { |
53 return this.name; | |
57 } | 54 } |
58 | 55 |
59 | 56 public String getDescription() { |
60 public String getName() { | 57 return this.description; |
61 return name; | |
62 } | 58 } |
63 | 59 |
64 | 60 @Override |
65 public String getDescription() { | 61 public void setFacet(final String facet) { |
66 return description; | |
67 } | |
68 | |
69 | |
70 public String getFacet() { | |
71 return facet; | |
72 } | |
73 | |
74 | |
75 public void setFacet(String facet) { | |
76 this.facet = facet; | 62 this.facet = facet; |
77 } | 63 } |
78 | 64 |
79 | 65 @Override |
80 public int getIndex() { | 66 public void setIndex(final int index) { |
81 return index; | |
82 } | |
83 | |
84 | |
85 public void setIndex(int index) { | |
86 this.index = index; | 67 this.index = index; |
87 } | 68 } |
88 | 69 |
89 | 70 public void addAttribute(final String name, final String value) { |
90 public void addAttribute(String name, String value) { | |
91 if (name != null && value != null) { | 71 if (name != null && value != null) { |
92 attr.put(name, value); | 72 this.attr.put(name, value); |
93 } | 73 } |
94 } | 74 } |
95 | 75 |
96 | 76 public void addField(final String name, final ThemeField field) { |
97 public String getAttribute(String name) { | |
98 return attr.get(name); | |
99 } | |
100 | |
101 | |
102 public void addField(String name, ThemeField field) { | |
103 if (name != null && field != null) { | 77 if (name != null && field != null) { |
104 fields.put(name, field); | 78 this.fields.put(name, field); |
105 } | 79 } |
106 } | 80 } |
107 | 81 |
82 @Override | |
83 public Document toXML() { | |
84 final Document doc = XMLUtils.newDocument(); | |
108 | 85 |
109 public void setFieldValue(String name, Object value) { | 86 final ElementCreator cr = new ElementCreator(doc, null, null); |
110 if (name != null && value != null) { | |
111 ThemeField field = fields.get(name); | |
112 | 87 |
113 if (field != null) { | 88 final Element theme = cr.create("theme"); |
114 field.setValue(value); | 89 theme.setAttribute("facet", this.facet); |
115 } | 90 theme.setAttribute("index", String.valueOf(this.index)); |
116 } | |
117 } | |
118 | |
119 | |
120 public ThemeField getField(String name) { | |
121 return fields.get(name); | |
122 } | |
123 | |
124 | |
125 public String getFieldType(String name) { | |
126 ThemeField field = fields.get(name); | |
127 | |
128 return field != null ? field.getType() : null; | |
129 } | |
130 | |
131 | |
132 public Object getFieldValue(String name) { | |
133 ThemeField field = fields.get(name); | |
134 | |
135 return field != null ? field.getValue() : null; | |
136 } | |
137 | |
138 | |
139 public Document toXML() { | |
140 Document doc = XMLUtils.newDocument(); | |
141 | |
142 ElementCreator cr = new ElementCreator(doc, null, null); | |
143 | |
144 Element theme = cr.create("theme"); | |
145 theme.setAttribute("facet", facet); | |
146 theme.setAttribute("index", String.valueOf(index)); | |
147 | 91 |
148 appendAttributes(cr, theme); | 92 appendAttributes(cr, theme); |
149 appendFields(cr, theme); | 93 appendFields(cr, theme); |
150 | 94 |
151 doc.appendChild(theme); | 95 doc.appendChild(theme); |
158 * Appends the attributes configured for this theme. | 102 * Appends the attributes configured for this theme. |
159 * | 103 * |
160 * @param cr The ElementCreator. | 104 * @param cr The ElementCreator. |
161 * @param theme The document root element. | 105 * @param theme The document root element. |
162 */ | 106 */ |
163 protected void appendAttributes(ElementCreator cr, Element theme) { | 107 protected void appendAttributes(final ElementCreator cr, final Element theme) { |
164 | 108 |
165 for (Map.Entry<String, String> entry: attr.entrySet()) { | 109 for (final Map.Entry<String, String> entry: this.attr.entrySet()) { |
166 String key = entry.getKey(); | 110 final String key = entry.getKey(); |
167 String val = entry.getValue(); | 111 final String val = entry.getValue(); |
168 | 112 |
169 if (key != null && val != null) { | 113 if (key != null && val != null) { |
170 cr.addAttr(theme, key, val); | 114 cr.addAttr(theme, key, val); |
171 } | 115 } |
172 } | 116 } |
177 * Appends the fields configured for this theme. | 121 * Appends the fields configured for this theme. |
178 * | 122 * |
179 * @param cr The ElementCreator. | 123 * @param cr The ElementCreator. |
180 * @param theme The document root element. | 124 * @param theme The document root element. |
181 */ | 125 */ |
182 protected void appendFields(ElementCreator cr, Element theme) { | 126 protected void appendFields(final ElementCreator cr, final Element theme) { |
183 | 127 |
184 for (ThemeField field: fields.values()) { | 128 for (final ThemeField field: this.fields.values()) { |
185 Document doc = field.toXML(); | 129 final Document doc = field.toXML(); |
186 Node root = doc.getFirstChild(); | 130 final Node root = doc.getFirstChild(); |
187 | 131 |
188 theme.appendChild(theme.getOwnerDocument().importNode(root, true)); | 132 theme.appendChild(theme.getOwnerDocument().importNode(root, true)); |
189 } | 133 } |
190 } | 134 } |
191 } | 135 } |
192 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |