Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java @ 1111:b96ce07ba56c
Added dummy sceleton for Cross Sections.
flys-artifacts/trunk@2617 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Wed, 31 Aug 2011 10:24:49 +0000 |
parents | |
children | 5b38cdf65307 |
comparison
equal
deleted
inserted
replaced
1110:563e015f0f22 | 1111:b96ce07ba56c |
---|---|
1 package de.intevation.flys.exports; | |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.List; | |
5 | |
6 import org.apache.log4j.Logger; | |
7 | |
8 import org.jfree.chart.JFreeChart; | |
9 import org.jfree.chart.axis.NumberAxis; | |
10 import org.jfree.chart.axis.ValueAxis; | |
11 import org.jfree.chart.plot.XYPlot; | |
12 import org.jfree.chart.title.TextTitle; | |
13 import org.jfree.data.Range; | |
14 import org.jfree.data.xy.XYSeries; | |
15 import org.jfree.data.xy.XYSeriesCollection; | |
16 import org.jfree.ui.TextAnchor; | |
17 | |
18 import org.w3c.dom.Document; | |
19 | |
20 import de.intevation.artifacts.Artifact; | |
21 | |
22 import de.intevation.artifactdatabase.state.Facet; | |
23 | |
24 import de.intevation.flys.artifacts.FLYSArtifact; | |
25 | |
26 import de.intevation.flys.artifacts.model.FacetTypes; | |
27 import de.intevation.flys.artifacts.model.WQKms; | |
28 | |
29 import de.intevation.flys.model.Annotation; | |
30 import de.intevation.flys.jfree.StickyAxisAnnotation; | |
31 | |
32 | |
33 /** | |
34 * An OutGenerator that generates cross section graphs. | |
35 */ | |
36 public class CrossSectionGenerator | |
37 extends XYChartGenerator | |
38 implements FacetTypes | |
39 { | |
40 /** The logger that is used in this generator. */ | |
41 private static Logger logger = | |
42 Logger.getLogger(CrossSectionGenerator.class); | |
43 | |
44 public static final String I18N_CHART_TITLE = | |
45 "chart.cross_section.title"; | |
46 | |
47 public static final String I18N_CHART_SUBTITLE = | |
48 "chart.cross_section.subtitle"; | |
49 | |
50 public static final String I18N_XAXIS_LABEL = | |
51 "chart.cross_section.xaxis.label"; | |
52 | |
53 public static final String I18N_YAXIS_LABEL = | |
54 "chart.cross_section.yaxis.label"; | |
55 | |
56 public static final String I18N_CHART_TITLE_DEFAULT = "Querschnittt"; | |
57 public static final String I18N_XAXIS_LABEL_DEFAULT = "m"; | |
58 public static final String I18N_YAXIS_LABEL_DEFAULT = "W [NN + m]"; | |
59 | |
60 | |
61 protected boolean inverted; | |
62 | |
63 | |
64 /** Trivial Constructor. */ | |
65 public CrossSectionGenerator() { | |
66 super(); | |
67 } | |
68 | |
69 | |
70 protected String getChartTitle() { | |
71 return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT); | |
72 } | |
73 | |
74 public boolean isInverted() { | |
75 return inverted; | |
76 } | |
77 | |
78 public void setInverted(boolean inverted) { | |
79 this.inverted = inverted; | |
80 } | |
81 | |
82 @Override | |
83 protected void addSubtitles(JFreeChart chart) { | |
84 double[] dist = getRange(); | |
85 | |
86 Object[] args = new Object[] { | |
87 getRiverName(), | |
88 dist[0], | |
89 dist[1] | |
90 }; | |
91 | |
92 //String subtitle = msg(I18N_CHART_SUBTITLE, "", args); | |
93 String subtitle = "bogus"; | |
94 chart.addSubtitle(new TextTitle(subtitle)); | |
95 } | |
96 | |
97 @Override | |
98 public JFreeChart generateChart() { | |
99 JFreeChart c = super.generateChart(); | |
100 XYPlot p = (XYPlot) c.getPlot(); | |
101 | |
102 return c; | |
103 } | |
104 | |
105 | |
106 protected String getXAxisLabel() { | |
107 return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT); | |
108 } | |
109 | |
110 | |
111 protected String getYAxisLabel() { | |
112 return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT); | |
113 } | |
114 | |
115 | |
116 protected void adjustAxes(XYPlot plot) { | |
117 super.adjustAxes(plot); | |
118 | |
119 NumberAxis qAxis = new NumberAxis( | |
120 msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT)); | |
121 | |
122 plot.setRangeAxis(1, qAxis); | |
123 | |
124 invertXAxis(plot.getDomainAxis()); | |
125 } | |
126 | |
127 | |
128 /** | |
129 * This method overrides the XYChartGenerators zoomY method to include the 0 | |
130 * value on the Q axis. | |
131 */ | |
132 @Override | |
133 protected boolean zoomY(XYPlot plot, ValueAxis axis, Range range, Range x) { | |
134 if (plot.getRangeAxisIndex(axis) == 1) { | |
135 // we want the Q axis to start at 0 if no zooming has been done | |
136 range = new Range(0d, range.getUpperBound()); | |
137 } | |
138 | |
139 return super.zoomY(plot, axis, range, x); | |
140 } | |
141 | |
142 | |
143 /** | |
144 * This method inverts the x-axis based on the kilometer information of the | |
145 * selected river. If the head of the river is at kilometer 0, the axis is | |
146 * not inverted, otherwise it is. | |
147 * | |
148 * @param xaxis The domain axis. | |
149 */ | |
150 protected void invertXAxis(ValueAxis xaxis) { | |
151 | |
152 if (inverted) { | |
153 logger.debug("Invert X-Axis."); | |
154 xaxis.setInverted(true); | |
155 } | |
156 } | |
157 | |
158 | |
159 public void doOut(Artifact artifact, Facet facet, Document attr) { | |
160 String name = facet.getName(); | |
161 | |
162 logger.debug("CrossSectionGenerator.doOut: " + name); | |
163 | |
164 if (name == null) { | |
165 logger.error("No facet name for doOut(). No output generated!"); | |
166 return; | |
167 } | |
168 | |
169 FLYSArtifact flys = (FLYSArtifact) artifact; | |
170 Facet f = flys.getNativeFacet(facet); | |
171 | |
172 if (f == null) { | |
173 return; | |
174 } | |
175 | |
176 if (name.equals(CROSS_SECTION)) { | |
177 doCrossSectionOut(f.getData(artifact, context), attr); | |
178 } | |
179 else { | |
180 logger.warn("CrossSection.doOut: Unknown facet name: " + name); | |
181 return; | |
182 } | |
183 } | |
184 | |
185 | |
186 /** | |
187 * Register annotations available for the diagram. | |
188 * | |
189 * @param o list of annotations (data of facet). | |
190 * @param theme yet ignored. | |
191 */ | |
192 protected void doCrossSectionOut(Object o, Document theme) { | |
193 logger.debug("LongitudinalSectionGenerator.doCrossSectionOut"); | |
194 | |
195 /*Object[] args = new Object[] {getRiverName()}; | |
196 String label = msg(I18N_ANNOTATIONS_LABEL, "", args); | |
197 pseudoAnnotationData.addSeries(new StyledXYSeries(label, theme));*/ | |
198 } | |
199 | |
200 | |
201 /** | |
202 * Get name of series (displayed in legend). | |
203 * @return name of the series. | |
204 */ | |
205 protected String getSeriesName(WQKms wqkms, String mode) { | |
206 String name = wqkms.getName(); | |
207 String prefix = name != null && name.indexOf(mode) >= 0 ? null : mode; | |
208 | |
209 return prefix != null && prefix.length() > 0 | |
210 ? prefix + "(" + name +")" | |
211 : name; | |
212 } | |
213 } | |
214 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | |
215 |