comparison artifacts/src/main/java/org/dive4elements/river/exports/ChartGenerator2.java @ 8076:e1b49fc9d2b5

Fixed sub title zoom stuff.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 07 Aug 2014 19:56:15 +0200
parents bd0dfa57b1fe
children e4606eae8ea5
comparison
equal deleted inserted replaced
8075:1cae4fc6bdd7 8076:e1b49fc9d2b5
14 import java.awt.Graphics2D; 14 import java.awt.Graphics2D;
15 import java.awt.Paint; 15 import java.awt.Paint;
16 import java.awt.Stroke; 16 import java.awt.Stroke;
17 import java.awt.TexturePaint; 17 import java.awt.TexturePaint;
18 import java.awt.Transparency; 18 import java.awt.Transparency;
19
20 import java.awt.geom.Rectangle2D; 19 import java.awt.geom.Rectangle2D;
21
22 import java.awt.image.BufferedImage; 20 import java.awt.image.BufferedImage;
23
24 import java.io.IOException; 21 import java.io.IOException;
25 import java.io.OutputStream; 22 import java.io.OutputStream;
26 23 import java.text.NumberFormat;
27 import java.util.ArrayList; 24 import java.util.ArrayList;
28 import java.util.List; 25 import java.util.List;
29 import java.util.Locale; 26 import java.util.Locale;
30 import java.util.Map; 27 import java.util.Map;
31 import java.util.SortedMap; 28 import java.util.SortedMap;
32 import java.util.TreeMap; 29 import java.util.TreeMap;
33 30
34 import javax.xml.xpath.XPathConstants; 31 import javax.xml.xpath.XPathConstants;
35 32
36 import org.apache.log4j.Logger; 33 import org.apache.log4j.Logger;
37
38 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; 34 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
39 import org.dive4elements.artifactdatabase.state.Settings; 35 import org.dive4elements.artifactdatabase.state.Settings;
40
41 import org.dive4elements.artifacts.Artifact; 36 import org.dive4elements.artifacts.Artifact;
42 import org.dive4elements.artifacts.ArtifactNamespaceContext; 37 import org.dive4elements.artifacts.ArtifactNamespaceContext;
43 import org.dive4elements.artifacts.CallContext; 38 import org.dive4elements.artifacts.CallContext;
44 import org.dive4elements.artifacts.CallMeta; 39 import org.dive4elements.artifacts.CallMeta;
45 import org.dive4elements.artifacts.PreferredLocale; 40 import org.dive4elements.artifacts.PreferredLocale;
46
47 import org.dive4elements.artifacts.common.utils.XMLUtils; 41 import org.dive4elements.artifacts.common.utils.XMLUtils;
48
49 import org.dive4elements.river.artifacts.D4EArtifact; 42 import org.dive4elements.river.artifacts.D4EArtifact;
50
51 import org.dive4elements.river.artifacts.access.RangeAccess; 43 import org.dive4elements.river.artifacts.access.RangeAccess;
52
53 import org.dive4elements.river.artifacts.resources.Resources; 44 import org.dive4elements.river.artifacts.resources.Resources;
54
55 import org.dive4elements.river.collections.D4EArtifactCollection; 45 import org.dive4elements.river.collections.D4EArtifactCollection;
56
57 import org.dive4elements.river.java2d.NOPGraphics2D; 46 import org.dive4elements.river.java2d.NOPGraphics2D;
58
59 import org.dive4elements.river.jfree.AxisDataset; 47 import org.dive4elements.river.jfree.AxisDataset;
60 import org.dive4elements.river.jfree.Bounds; 48 import org.dive4elements.river.jfree.Bounds;
61 import org.dive4elements.river.jfree.DoubleBounds; 49 import org.dive4elements.river.jfree.DoubleBounds;
62 import org.dive4elements.river.jfree.EnhancedLineAndShapeRenderer; 50 import org.dive4elements.river.jfree.EnhancedLineAndShapeRenderer;
63 import org.dive4elements.river.jfree.RiverAnnotation; 51 import org.dive4elements.river.jfree.RiverAnnotation;
64 import org.dive4elements.river.jfree.StableXYDifferenceRenderer; 52 import org.dive4elements.river.jfree.StableXYDifferenceRenderer;
65 import org.dive4elements.river.jfree.Style; 53 import org.dive4elements.river.jfree.Style;
66 import org.dive4elements.river.jfree.StyledAreaSeriesCollection; 54 import org.dive4elements.river.jfree.StyledAreaSeriesCollection;
67 import org.dive4elements.river.jfree.StyledSeries; 55 import org.dive4elements.river.jfree.StyledSeries;
68
69 import org.dive4elements.river.model.River; 56 import org.dive4elements.river.model.River;
70
71 import org.dive4elements.river.themes.ThemeDocument; 57 import org.dive4elements.river.themes.ThemeDocument;
72
73 import org.dive4elements.river.utils.Formatter; 58 import org.dive4elements.river.utils.Formatter;
74 import org.dive4elements.river.utils.RiverUtils; 59 import org.dive4elements.river.utils.RiverUtils;
75
76 import org.jfree.chart.ChartRenderingInfo; 60 import org.jfree.chart.ChartRenderingInfo;
77 import org.jfree.chart.JFreeChart; 61 import org.jfree.chart.JFreeChart;
78 import org.jfree.chart.LegendItem; 62 import org.jfree.chart.LegendItem;
79 import org.jfree.chart.LegendItemCollection; 63 import org.jfree.chart.LegendItemCollection;
80
81 import org.jfree.chart.axis.NumberAxis; 64 import org.jfree.chart.axis.NumberAxis;
82
83 import org.jfree.chart.plot.XYPlot; 65 import org.jfree.chart.plot.XYPlot;
84
85 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; 66 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
86
87 import org.jfree.chart.title.TextTitle; 67 import org.jfree.chart.title.TextTitle;
88
89 import org.jfree.data.Range; 68 import org.jfree.data.Range;
90
91 import org.jfree.data.general.Series; 69 import org.jfree.data.general.Series;
92
93 import org.jfree.data.xy.XYDataset; 70 import org.jfree.data.xy.XYDataset;
94
95 import org.jfree.ui.RectangleInsets; 71 import org.jfree.ui.RectangleInsets;
96
97 import org.w3c.dom.Document; 72 import org.w3c.dom.Document;
98 import org.w3c.dom.Element; 73 import org.w3c.dom.Element;
99 74
100 /** 75 /**
101 * Implementation of the OutGenerator interface for charts. 76 * Implementation of the OutGenerator interface for charts.
473 * @return a new <i>ChartSection</i>. 448 * @return a new <i>ChartSection</i>.
474 */ 449 */
475 protected ChartSection buildChartSection() { 450 protected ChartSection buildChartSection() {
476 ChartSection chartSection = new ChartSection(); 451 ChartSection chartSection = new ChartSection();
477 chartSection.setTitle(getChartTitle()); 452 chartSection.setTitle(getChartTitle());
478 chartSection.setSubtitle(getChartSubtitle()); 453 chartSection.setSubtitle(getChartSubtitlePure());
479 chartSection.setDisplayGrid(isGridVisible()); 454 chartSection.setDisplayGrid(isGridVisible());
480 chartSection.setDisplayLogo(showLogo()); 455 chartSection.setDisplayLogo(showLogo());
481 chartSection.setLogoVPlacement(logoVPlace()); 456 chartSection.setLogoVPlacement(logoVPlace());
482 chartSection.setLogoHPlacement(logoHPlace()); 457 chartSection.setLogoHPlacement(logoHPlace());
483 return chartSection; 458 return chartSection;
673 648
674 return getDefaultChartTitle(); 649 return getDefaultChartTitle();
675 } 650 }
676 651
677 protected String interpolateVariables(String s) { 652 protected String interpolateVariables(String s) {
678
679 Object radius = context.getContextValue("radius"); 653 Object radius = context.getContextValue("radius");
680 if (radius instanceof Double) { 654 if (radius instanceof Double) {
681 String txt = Resources.getMsg( 655 NumberFormat f = Formatter.getCSVFormatter(context);
682 context.getMeta(), 656 return s.replace("$RADIUS", f.format(radius));
683 I18N_SUBTITLE_RADIUS,
684 new Object[] { radius });
685
686 return s.replace("$RADIUS", txt);
687
688 } 657 }
689 return s; 658 return s;
690 } 659 }
691 660
692 /** 661 /**
695 * returns the chart title provided by those settings. Otherwise, this 664 * returns the chart title provided by those settings. Otherwise, this
696 * method returns getDefaultChartSubtitle(). 665 * method returns getDefaultChartSubtitle().
697 * 666 *
698 * @return the subtitle of a chart. 667 * @return the subtitle of a chart.
699 */ 668 */
669 protected String getChartSubtitlePure() {
670 ChartSettings chartSettings = getChartSettings();
671
672 String subTitle = chartSettings != null
673 ? getChartSubtitle(chartSettings)
674 : getDefaultChartSubtitle();
675
676 String defSubTitle = getDefaultChartSubtitle();
677
678 if (subTitle == null) {
679 subTitle = defSubTitle != null ? defSubTitle : "";
680 }
681
682 return subTitle;
683 }
684
700 protected String getChartSubtitle() { 685 protected String getChartSubtitle() {
701 ChartSettings chartSettings = getChartSettings(); 686 return interpolateVariables(getChartSubtitlePure());
702
703 if (chartSettings != null) {
704 String subTitle = getChartSubtitle(chartSettings);
705 if (subTitle == null) {
706 return getDefaultChartSubtitle();
707 }
708 String defSubTitle = getDefaultChartSubtitle();
709 if (defSubTitle != null
710 && !defSubTitle.isEmpty()
711 && !subTitle.equals(defSubTitle)) {
712 return interpolateVariables(defSubTitle);
713 }
714 return subTitle;
715 }
716
717 return getDefaultChartSubtitle();
718 } 687 }
719 688
720 689
721 /** 690 /**
722 * This method always returns null. Override it in subclasses that require 691 * This method always returns null. Override it in subclasses that require

http://dive4elements.wald.intevation.org