comparison artifacts/src/main/java/org/dive4elements/river/jfree/StyledXYSeries.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 28df64078f27
children
comparison
equal deleted inserted replaced
9554:33ce8eba9806 9555:ef5754ba5573
6 * documentation coming with Dive4Elements River for details. 6 * documentation coming with Dive4Elements River for details.
7 */ 7 */
8 8
9 package org.dive4elements.river.jfree; 9 package org.dive4elements.river.jfree;
10 10
11 import java.util.List; 11 import java.awt.Shape;
12 import java.util.Map; 12 import java.util.Map;
13 13
14 import org.apache.log4j.Logger; 14 import org.dive4elements.artifactdatabase.state.Facet;
15
16 import org.dive4elements.river.model.River;
17
18 import org.dive4elements.artifacts.Artifact; 15 import org.dive4elements.artifacts.Artifact;
19 import org.dive4elements.artifacts.CallContext; 16 import org.dive4elements.artifacts.CallContext;
20 import org.dive4elements.river.artifacts.D4EArtifact; 17 import org.dive4elements.river.artifacts.D4EArtifact;
21 import org.dive4elements.river.artifacts.access.RiverAccess; 18 import org.dive4elements.river.artifacts.access.RiverAccess;
22 import org.dive4elements.river.artifacts.resources.Resources; 19 import org.dive4elements.river.artifacts.resources.Resources;
20 import org.dive4elements.river.model.River;
23 import org.dive4elements.river.themes.ThemeDocument; 21 import org.dive4elements.river.themes.ThemeDocument;
24 22 import org.jfree.chart.LegendItem;
25 import org.jfree.data.xy.XYDataItem;
26 import org.jfree.data.xy.XYSeries; 23 import org.jfree.data.xy.XYSeries;
27
28 import java.awt.Shape;
29 24
30 /** 25 /**
31 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 26 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
32 */ 27 */
33 public class StyledXYSeries 28 public class StyledXYSeries extends XYSeries implements StyledSeries, HasLabel, XYMetaDataset {
34 extends XYSeries
35 implements StyledSeries, HasLabel, XYMetaDataset {
36 29
37 private static final Logger log = Logger.getLogger(StyledXYSeries.class); 30 private static final long serialVersionUID = 1L;
38 31
39 protected Style style; 32 private final Style style;
40 33
41 /** If this Series is to be labelled, use this String as label. */ 34 /** If this Series is to be labelled, use this String as label. */
42 protected String label; 35 private String label;
43 36
44 /** The meta data for this series. */ 37 /** The meta data for this series. */
45 protected Map<String, String> metaData; 38 private Map<String, String> metaData;
46 39
47 public StyledXYSeries(String key, ThemeDocument theme) { 40 /**
48 this(key, true, theme, (Shape)null); 41 * A 'type' that allows to categorize themes by it. Tyically this is simply the facet-name of the originating
42 * {@link Facet}.
43 * REMARK: stictly there should be a type per dataset, not per series, but flys uses (for line themes) generic datasets
44 * with one series.
45 */
46 private final String themeType;
47
48 public StyledXYSeries(final String facetName, final String key, final ThemeDocument theme) {
49 this(facetName, key, true, theme, (Shape) null);
49 } 50 }
50 51
51 52 public StyledXYSeries(final String facetName, final String key, final boolean sorted, final ThemeDocument theme) {
52 public StyledXYSeries( 53 this(facetName, key, sorted, theme, (Shape) null);
53 String key,
54 ThemeDocument theme,
55 XYSeries unstyledSeries
56 ) {
57 this(key, theme);
58 add(unstyledSeries);
59 } 54 }
60 55
61 public StyledXYSeries(String key, boolean sorted, ThemeDocument theme) { 56 public StyledXYSeries(final String facetName, final String key, final ThemeDocument theme, final Shape shape) {
62 this(key, sorted, theme, (Shape)null); 57 this(facetName, key, true, theme, shape);
63 }
64
65
66 public StyledXYSeries(String key, ThemeDocument theme, Shape shape) {
67 this(key, true, theme, shape);
68 } 58 }
69 59
70 /** 60 /**
71 * @param sorted whether or not to sort the points. Sorting will move NANs 61 * @param sorted
72 * to one extrema which can cause problems in certain 62 * whether or not to sort the points. Sorting will move NANs
73 * algorithms. 63 * to one extrema which can cause problems in certain
64 * algorithms.
74 */ 65 */
75 public StyledXYSeries( 66 public StyledXYSeries(final String facetName, final String key, final boolean sorted, final ThemeDocument theme, final Shape shape) {
76 String key,
77 boolean sorted,
78 ThemeDocument theme,
79 Shape shape
80 ) {
81 super(key, sorted); 67 super(key, sorted);
82 setStyle(new XYStyle(theme, shape)); 68
69 this.style = new XYStyle(theme, shape);
83 this.label = key.toString(); 70 this.label = key.toString();
71 this.themeType = facetName;
84 } 72 }
85 73
86 public StyledXYSeries( 74 public StyledXYSeries(final String themeType, final String key, final boolean sorted, final boolean allowDuplicateXValues, final ThemeDocument theme) {
87 String key, 75 this(themeType, key, sorted, allowDuplicateXValues, theme, (Shape) null);
88 boolean sorted,
89 boolean allowDuplicateXValues,
90 ThemeDocument theme
91 ) {
92 this(key, sorted, allowDuplicateXValues, theme, (Shape)null);
93 } 76 }
94 77
95 public StyledXYSeries( 78 public StyledXYSeries(final String themeType, final String key, final boolean sorted, final boolean allowDuplicateXValues, final ThemeDocument theme,
96 String key, 79 final Shape shape) {
97 boolean sorted,
98 boolean allowDuplicateXValues,
99 ThemeDocument theme,
100 Shape shape
101 ) {
102 super(key, sorted, allowDuplicateXValues); 80 super(key, sorted, allowDuplicateXValues);
103 setStyle(new XYStyle(theme, shape)); 81
82 this.style = new XYStyle(theme, shape);
104 this.label = key.toString(); 83 this.label = key.toString();
84 this.themeType = themeType;
105 } 85 }
106 86
107
108 @Override 87 @Override
109 public void setStyle(Style style) { 88 public String getThemeType() {
110 this.style = style; 89 return this.themeType;
111 } 90 }
112
113 91
114 @Override 92 @Override
115 public Style getStyle() { 93 public Style getStyle() {
116 return style; 94 return this.style;
117 } 95 }
118
119 96
120 @Override 97 @Override
121 public String getLabel() { 98 public String getLabel() {
122 return label; 99 return this.label;
123 } 100 }
124 101
125 @Override 102 @Override
126 public void setLabel(String label) { 103 public void setLabel(final String label) {
127 this.label = label; 104 this.label = label;
128 } 105 }
129 106
130 protected void add(XYSeries series) {
131 List<XYDataItem> items = series.getItems();
132 add(items);
133 }
134
135 protected void add(List<XYDataItem> items) {
136 for(XYDataItem item : items) {
137 add(item.getXValue(), item.getYValue());
138 }
139 }
140
141
142 @Override 107 @Override
143 public Map<String, String> getMetaData() { 108 public Map<String, String> getMetaData() {
144 return metaData; 109 return this.metaData;
145 } 110 }
146
147 111
148 @Override 112 @Override
149 // FIXME: bad! method with undocumented side-effects; given metadata will be changed inline 113 // FIXME: bad! method with undocumented side-effects; given metadata will be changed inline
150 public void putMetaData(Map<String, String> metaData, 114 public void putMetaData(final Map<String, String> metaData, final Artifact artifact, final CallContext context) {
151 Artifact artifact,
152 CallContext context) {
153 this.metaData = metaData; 115 this.metaData = metaData;
154 River river = new RiverAccess((D4EArtifact)artifact).getRiver(); 116 final River river = new RiverAccess((D4EArtifact) artifact).getRiver();
155 String rivername = ""; 117 String rivername = "";
156 String unit = ""; 118 String unit = "";
157 if (river != null) { 119 if (river != null) {
158 rivername = river.getName(); 120 rivername = river.getName();
159 // FIXME: this will always return the wst unit, regardless if the series is a water level or not! 121 // FIXME: this will always return the wst unit, regardless if the series is a water level or not!
160 unit = river.getWstUnit().getName(); 122 unit = river.getWstUnit().getName();
161 } 123 }
162 if (metaData.containsKey("X")) { 124 if (metaData.containsKey("X")) {
163 this.metaData.put("X", 125 this.metaData.put("X", Resources.getMsg(context.getMeta(), metaData.get("X"), new Object[] { rivername }));
164 Resources.getMsg(
165 context.getMeta(),
166 metaData.get("X"),
167 new Object[] { rivername }));
168 } 126 }
169 if (metaData.containsKey("Y")) { 127 if (metaData.containsKey("Y")) {
170 this.metaData.put("Y", 128 this.metaData.put("Y", Resources.getMsg(context.getMeta(), metaData.get("Y"), new Object[] { unit }));
171 Resources.getMsg(
172 context.getMeta(),
173 metaData.get("Y"), new Object[] { unit }));
174 } 129 }
175 } 130 }
131
132 @Override
133 public void applyAggregatedLegendTheme(final LegendItem item, final ThemeDocument theme) {
134 this.style.applyAggregatedLegendTheme(item, theme);
135 }
176 } 136 }
177 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org