comparison flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java @ 3278:c27c4e06dd87

Re-add HYK rendering code to CrossSectionGenerator flys-artifacts/trunk@4924 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Christian Lins <christian.lins@intevation.de>
date Wed, 11 Jul 2012 09:24:07 +0000
parents 4ac581062c40
children d9af29a4bb85
comparison
equal deleted inserted replaced
3277:fc0d613e5073 3278:c27c4e06dd87
1 package de.intevation.flys.exports; 1 package de.intevation.flys.exports;
2 2
3 import de.intevation.artifactdatabase.state.ArtifactAndFacet; 3 import de.intevation.artifactdatabase.state.ArtifactAndFacet;
4 import de.intevation.artifactdatabase.state.Facet;
5 import de.intevation.artifactdatabase.state.Settings; 4 import de.intevation.artifactdatabase.state.Settings;
6
7 import de.intevation.artifacts.Artifact; 5 import de.intevation.artifacts.Artifact;
8 import de.intevation.artifacts.ArtifactNamespaceContext; 6 import de.intevation.artifacts.ArtifactNamespaceContext;
9 import de.intevation.artifacts.CallContext; 7 import de.intevation.artifacts.CallContext;
10 import de.intevation.artifacts.CallMeta; 8 import de.intevation.artifacts.CallMeta;
11 import de.intevation.artifacts.PreferredLocale; 9 import de.intevation.artifacts.PreferredLocale;
12
13 import de.intevation.artifacts.common.utils.XMLUtils; 10 import de.intevation.artifacts.common.utils.XMLUtils;
14
15 import de.intevation.flys.artifacts.FLYSArtifact; 11 import de.intevation.flys.artifacts.FLYSArtifact;
16
17 import de.intevation.flys.artifacts.resources.Resources; 12 import de.intevation.flys.artifacts.resources.Resources;
18
19 import de.intevation.flys.jfree.Bounds; 13 import de.intevation.flys.jfree.Bounds;
20 import de.intevation.flys.jfree.CollisionFreeXYTextAnnotation; 14 import de.intevation.flys.jfree.CollisionFreeXYTextAnnotation;
21 import de.intevation.flys.jfree.DoubleBounds; 15 import de.intevation.flys.jfree.DoubleBounds;
22 import de.intevation.flys.jfree.EnhancedLineAndShapeRenderer; 16 import de.intevation.flys.jfree.EnhancedLineAndShapeRenderer;
23 import de.intevation.flys.jfree.FLYSAnnotation; 17 import de.intevation.flys.jfree.FLYSAnnotation;
24 import de.intevation.flys.jfree.StableXYDifferenceRenderer; 18 import de.intevation.flys.jfree.StableXYDifferenceRenderer;
25 import de.intevation.flys.jfree.StickyAxisAnnotation; 19 import de.intevation.flys.jfree.StickyAxisAnnotation;
26 import de.intevation.flys.jfree.Style; 20 import de.intevation.flys.jfree.Style;
27 import de.intevation.flys.jfree.StyledAreaSeriesCollection; 21 import de.intevation.flys.jfree.StyledAreaSeriesCollection;
28 import de.intevation.flys.jfree.StyledSeries; 22 import de.intevation.flys.jfree.StyledSeries;
29
30 import de.intevation.flys.model.River; 23 import de.intevation.flys.model.River;
31
32 import de.intevation.flys.themes.ThemeAccess; 24 import de.intevation.flys.themes.ThemeAccess;
33
34 import de.intevation.flys.utils.FLYSUtils; 25 import de.intevation.flys.utils.FLYSUtils;
35 import de.intevation.flys.utils.ThemeUtil; 26 import de.intevation.flys.utils.ThemeUtil;
36 27
37 import java.awt.BasicStroke; 28 import java.awt.BasicStroke;
38 import java.awt.Color; 29 import java.awt.Color;
39 import java.awt.Font; 30 import java.awt.Font;
40 import java.awt.Paint; 31 import java.awt.Paint;
41 import java.awt.Stroke; 32 import java.awt.Stroke;
42 import java.awt.TexturePaint; 33 import java.awt.TexturePaint;
43
44 import java.awt.geom.Rectangle2D; 34 import java.awt.geom.Rectangle2D;
45
46 import java.awt.image.BufferedImage; 35 import java.awt.image.BufferedImage;
47
48 import java.io.IOException; 36 import java.io.IOException;
49 import java.io.OutputStream; 37 import java.io.OutputStream;
50
51 import java.util.ArrayList; 38 import java.util.ArrayList;
52 import java.util.List; 39 import java.util.List;
53 import java.util.Locale; 40 import java.util.Locale;
54 import java.util.Map; 41 import java.util.Map;
55 import java.util.SortedMap; 42 import java.util.SortedMap;
56 import java.util.TreeMap; 43 import java.util.TreeMap;
57 44
58 import javax.xml.xpath.XPathConstants; 45 import javax.xml.xpath.XPathConstants;
59 46
60 import org.apache.log4j.Logger; 47 import org.apache.log4j.Logger;
61
62 import org.jfree.chart.JFreeChart; 48 import org.jfree.chart.JFreeChart;
63 import org.jfree.chart.LegendItem; 49 import org.jfree.chart.LegendItem;
64 import org.jfree.chart.LegendItemCollection; 50 import org.jfree.chart.LegendItemCollection;
65
66 import org.jfree.chart.annotations.XYLineAnnotation; 51 import org.jfree.chart.annotations.XYLineAnnotation;
67 import org.jfree.chart.annotations.XYTextAnnotation; 52 import org.jfree.chart.annotations.XYTextAnnotation;
68
69 import org.jfree.chart.axis.NumberAxis; 53 import org.jfree.chart.axis.NumberAxis;
70
71 import org.jfree.chart.plot.XYPlot; 54 import org.jfree.chart.plot.XYPlot;
72
73 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; 55 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
74
75 import org.jfree.data.Range; 56 import org.jfree.data.Range;
76
77 import org.jfree.data.general.Series; 57 import org.jfree.data.general.Series;
78
79 import org.jfree.data.xy.XYDataset; 58 import org.jfree.data.xy.XYDataset;
80
81 import org.jfree.ui.RectangleInsets; 59 import org.jfree.ui.RectangleInsets;
82 import org.jfree.ui.TextAnchor; 60 import org.jfree.ui.TextAnchor;
83
84 import org.w3c.dom.Document; 61 import org.w3c.dom.Document;
85 import org.w3c.dom.Element; 62 import org.w3c.dom.Element;
86 63
87 64
88 /** 65 /**
135 112
136 /** Map of datasets ("index"). */ 113 /** Map of datasets ("index"). */
137 protected SortedMap<Integer, AxisDataset> datasets; 114 protected SortedMap<Integer, AxisDataset> datasets;
138 115
139 /** List of annotations to insert in plot. */ 116 /** List of annotations to insert in plot. */
140 protected List<FLYSAnnotation> annotations; 117 protected List<FLYSAnnotation> annotations = new ArrayList<FLYSAnnotation>();
141 118
142 /** 119 /**
143 * A mini interface that allows to walk over the YAXIS enums defined in 120 * A mini interface that allows to walk over the YAXIS enums defined in
144 * subclasses. 121 * subclasses.
145 */ 122 */
184 161
185 /** 162 /**
186 * Adds annotations to list. The given annotation will be visible. 163 * Adds annotations to list. The given annotation will be visible.
187 */ 164 */
188 public void addAnnotations(FLYSAnnotation annotation) { 165 public void addAnnotations(FLYSAnnotation annotation) {
189 if (annotations == null) {
190 annotations = new ArrayList<FLYSAnnotation>();
191 }
192
193 annotations.add(annotation); 166 annotations.add(annotation);
194 } 167 }
195 168
196 /** 169 /**
197 * Add a text and a line annotation. 170 * Add a text and a line annotation.
227 else { 200 else {
228 // Do the more complicated case where we stick to the Y-Axis. 201 // Do the more complicated case where we stick to the Y-Axis.
229 // There is one nasty case (duration curves, where annotations 202 // There is one nasty case (duration curves, where annotations
230 // might stick to the second y-axis). 203 // might stick to the second y-axis).
231 // FIXME: Remove dependency to XYChartGenerator here 204 // FIXME: Remove dependency to XYChartGenerator here
232 AxisDataset dataset = (XYChartGenerator.XYAxisDataset) getAxisDataset( 205 AxisDataset dataset = getAxisDataset(
233 new Integer(annotation.getAxisSymbol())); 206 new Integer(annotation.getAxisSymbol()));
234 if (dataset == null) { 207 if (dataset == null) {
235 logger.warn("Annotation should stick to unfindable y-axis: " 208 logger.warn("Annotation should stick to unfindable y-axis: "
236 + annotation.getAxisSymbol()); 209 + annotation.getAxisSymbol());
237 rendererIndex = 0; 210 rendererIndex = 0;
447 if (annotations == null || annotations.size() == 0) { 420 if (annotations == null || annotations.size() == 0) {
448 logger.debug("addAnnotationsToRenderer: no annotations."); 421 logger.debug("addAnnotationsToRenderer: no annotations.");
449 return; 422 return;
450 } 423 }
451 424
452 // Paints for the boxes/lines.
453 Stroke basicStroke = new BasicStroke(1.0f);
454
455 Paint linePaint = new Color(255, 0,0,60);
456 Paint fillPaint = new Color(0, 255,0,60);
457 Paint tranPaint = new Color(0, 0,0, 0);
458
459 // OPTMIMIZE: Pre-calculate positions 425 // OPTMIMIZE: Pre-calculate positions
460 ChartArea area = new ChartArea( 426 ChartArea area = new ChartArea(
461 plot.getDomainAxis(0).getRange(), 427 plot.getDomainAxis(0).getRange(),
462 plot.getRangeAxis().getRange()); 428 plot.getRangeAxis().getRange());
463 429
515 * @return a new instance of a JFreeChart. 481 * @return a new instance of a JFreeChart.
516 */ 482 */
517 public abstract JFreeChart generateChart(); 483 public abstract JFreeChart generateChart();
518 484
519 485
486 @Override
520 public abstract void doOut( 487 public abstract void doOut(
521 ArtifactAndFacet bundle, 488 ArtifactAndFacet bundle,
522 Document attr, 489 Document attr,
523 boolean visible); 490 boolean visible);
524 491
625 FLYSAnnotation annotations, 592 FLYSAnnotation annotations,
626 ArtifactAndFacet aandf, 593 ArtifactAndFacet aandf,
627 Document theme, 594 Document theme,
628 boolean visible 595 boolean visible
629 ){ 596 ){
630 // Running into trouble here.
631 logger.debug("doAnnotations"); 597 logger.debug("doAnnotations");
632 598
633 // Add all annotations to our annotation pool. 599 // Add all annotations to our annotation pool.
634 annotations.setTheme(theme); 600 annotations.setTheme(theme);
635 if (aandf != null) { 601 if (aandf != null) {
636 Facet facet = aandf.getFacet();
637 annotations.setLabel(aandf.getFacetDescription()); 602 annotations.setLabel(aandf.getFacetDescription());
638 } 603 }
639 else { 604 else {
640 logger.debug( 605 logger.debug(
641 "Art/Facet for Annotations is null. " + 606 "Art/Facet for Annotations is null. " +

http://dive4elements.wald.intevation.org