comparison flys-artifacts/src/main/java/de/intevation/flys/exports/minfo/BedQualityGenerator.java @ 3757:e8a90a5ce624

Added facets and chart generator for bed quality calculation. flys-artifacts/trunk@5454 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 13 Sep 2012 12:08:50 +0000
parents
children 0c978a80726a
comparison
equal deleted inserted replaced
3756:912a398968b6 3757:e8a90a5ce624
1 package de.intevation.flys.exports.minfo;
2
3 import org.apache.log4j.Logger;
4 import org.jfree.data.xy.XYSeries;
5 import org.w3c.dom.Document;
6
7 import de.intevation.artifactdatabase.state.ArtifactAndFacet;
8 import de.intevation.artifactdatabase.state.Facet;
9 import de.intevation.flys.artifacts.FLYSArtifact;
10 import de.intevation.flys.artifacts.model.FacetTypes;
11 import de.intevation.flys.artifacts.model.MiddleBedHeightData;
12 import de.intevation.flys.exports.ChartGenerator.YAxisWalker;
13 import de.intevation.flys.exports.StyledSeriesBuilder;
14 import de.intevation.flys.exports.XYChartGenerator;
15 import de.intevation.flys.jfree.FLYSAnnotation;
16 import de.intevation.flys.jfree.StyledXYSeries;
17 import de.intevation.flys.utils.FLYSUtils;
18
19
20 /**
21 * An OutGenerator that generates bed quality charts.
22 *
23 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
24 */
25 public class BedQualityGenerator extends XYChartGenerator implements FacetTypes {
26
27 public enum YAXIS {
28 W(0), P(1), D(2);
29
30 protected int idx;
31
32 private YAXIS(int c) {
33 idx = c;
34 }
35 }
36
37 /** The logger that is used in this generator. */
38 private static Logger logger = Logger.getLogger(BedQualityGenerator.class);
39
40 public static final String I18N_CHART_TITLE = "chart.bedquality.title";
41 public static final String I18N_XAXIS_LABEL = "chart.bedquality.xaxis.label";
42 public static final String I18N_YAXIS_LABEL = "chart.bedquality.yaxis.label";
43 public static final String I18N_SECOND_YAXIS_LABEL = "chart.bedquality.yaxis.label.porosity";
44 public static final String I18N_THIRD_YAXIS_LABEL = "chart.bedquality.yaxis.label.diameter";
45
46 public static final String I18N_CHART_TITLE_DEFAULT = "Sohlen Längsschnitt";
47 public static final String I18N_XAXIS_LABEL_DEFAULT = "Fluss-Km";
48 public static final String I18N_YAXIS_LABEL_DEFAULT = "Durchmesser [m]";
49 public static final String I18N_SECOND_YAXIS_LABEL_DEFAULT = "Porosität [%]";
50 public static final String I18N_THIRD_YAXIS_LABEL_DEFAULT = "Dichte [t/m^3]";
51
52 @Override
53 protected YAxisWalker getYAxisWalker() {
54 return new YAxisWalker() {
55
56 @Override
57 public int length() {
58 return YAXIS.values().length;
59 }
60
61 @Override
62 public String getId(int idx) {
63 YAXIS[] yaxes = YAXIS.values();
64 return yaxes[idx].toString();
65 }
66 };
67 }
68
69 /**
70 * Returns the default title for this chart.
71 *
72 * @return the default title for this chart.
73 */
74 @Override
75 public String getDefaultChartTitle() {
76 return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT);
77 }
78
79 /**
80 * Get internationalized label for the x axis.
81 */
82 @Override
83 protected String getDefaultXAxisLabel() {
84 return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT);
85 }
86
87 @Override
88 protected String getDefaultYAxisLabel(int index) {
89 String label = "default";
90
91 if (index == YAXIS.W.idx) {
92 label = getWAxisLabel();
93 }
94 else if (index == YAXIS.P.idx) {
95 label = getPAxisLabel();
96 }
97 else if (index == YAXIS.D.idx) {
98 label = getDAxisLabel();
99 }
100
101 return label;
102 }
103
104 /**
105 * Get internationalized label for the y axis displaying the diameter.
106 */
107 protected String getWAxisLabel() {
108 return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT);
109 }
110
111 /**
112 * Get internationalized label for the y axis displaying the porosity.
113 */
114 protected String getPAxisLabel() {
115 return msg(I18N_SECOND_YAXIS_LABEL, I18N_SECOND_YAXIS_LABEL_DEFAULT);
116 }
117
118 /**
119 * Get internationalized label for the y axis displaying the density.
120 */
121 protected String getDAxisLabel() {
122 return msg(I18N_THIRD_YAXIS_LABEL, I18N_THIRD_YAXIS_LABEL_DEFAULT);
123 }
124
125 /**
126 * Produce output.
127 *
128 * @param artifactAndFacet
129 * current facet.
130 * @param attr
131 * theme for facet
132 */
133 public void doOut(ArtifactAndFacet artifactAndFacet, Document attr,
134 boolean visible) {
135 String name = artifactAndFacet.getFacetName();
136
137 logger.debug("BedQualityGenerator.doOut: " + name);
138
139 if (name == null) {
140 logger.error("No facet name for doOut(). No output generated!");
141 return;
142 }
143
144 Facet facet = artifactAndFacet.getFacet();
145
146 if (facet == null) {
147 return;
148 }
149
150 if (name.equals(BED_QUALITY_BED_DIAMETER)) {
151 doBedDiameterOut(artifactAndFacet.getData(context), // TODO CAST TO
152 // SPECIFIC
153 // CLASS
154 artifactAndFacet, attr, visible);
155 }
156 else if (name.equals(BED_QUALITY_BEDLOAD_DIAMETER)) {
157 doBedloadDiameterOut(artifactAndFacet.getData(context), // TODO CAST
158 // TO
159 // SPECIFIC
160 // CLASS
161 artifactAndFacet, attr, visible);
162 }
163 else if (name.equals(BED_QUALITY_POROSITY)) {
164 doPorosityOut(artifactAndFacet.getData(context), // TODO CAST TO
165 // SPECIFIC CLASS
166 artifactAndFacet, attr, visible);
167 }
168 else if (name.equals(BED_QUALITY_SEDIMENT_DENSITY)) {
169 doDensityOut(artifactAndFacet.getData(context), // TODO CAST TO
170 // SPECIFIC CLASS
171 artifactAndFacet, attr, visible);
172 }
173 else if (FacetTypes.IS.MANUALPOINTS(name)) {
174 doPoints(artifactAndFacet.getData(context), artifactAndFacet, attr,
175 visible, YAXIS.W.idx);
176 }
177 else {
178 logger.warn("Unknown facet name: " + name);
179 return;
180 }
181 }
182
183 protected void doBedDiameterOut(Object data, ArtifactAndFacet aandf,
184 Document theme, boolean visible) {
185 logger.debug("BedQuality.doBedDiameterOut");
186
187 XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme);
188
189 // StyledSeriesBuilder.addPoints(series, data.getMiddleHeightsPoints(),
190 // true);
191
192 addAxisSeries(series, YAXIS.W.idx, visible);
193 }
194
195 protected void doBedloadDiameterOut(Object data, ArtifactAndFacet aandf,
196 Document theme, boolean visible) {
197 logger.debug("BedQuality.doBedloadDiameterOut");
198
199 XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme);
200
201 // StyledSeriesBuilder.addPoints(series, data.getMiddleHeightsPoints(),
202 // true);
203
204 addAxisSeries(series, YAXIS.W.idx, visible);
205 }
206
207 protected void doPorosityOut(Object data, ArtifactAndFacet aandf,
208 Document theme, boolean visible) {
209 logger.debug("BedQuality.doPorosityOut");
210
211 XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme);
212
213 // StyledSeriesBuilder.addPoints(series, data.getMiddleHeightsPoints(),
214 // true);
215
216 addAxisSeries(series, YAXIS.P.idx, visible);
217 }
218
219 protected void doDensityOut(Object data, ArtifactAndFacet aandf,
220 Document theme, boolean visible) {
221 logger.debug("BedQuality.doDensityOut");
222
223 XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme);
224
225 // StyledSeriesBuilder.addPoints(series, data.getMiddleHeightsPoints(),
226 // true);
227
228 addAxisSeries(series, YAXIS.D.idx, visible);
229 }
230 }
231 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org