Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/jfree/AnnotationHelper.java @ 8856:5e38e2924c07 3.2.x
Fix code style.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 18 Jan 2018 20:12:01 +0100 |
parents | ebf74d92be38 |
children | 0a5239a1e46e |
rev | line source |
---|---|
7043
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
2 * Software engineering by Intevation GmbH |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
3 * |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
6 * documentation coming with Dive4Elements River for details. |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
7 */ |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
8 package org.dive4elements.river.jfree; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
9 |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
10 import org.dive4elements.river.themes.ThemeDocument; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
11 |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
12 import java.util.List; |
8341
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
13 import java.util.ArrayList; |
7043
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
14 import java.util.Map; |
8341
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
15 import java.util.SortedMap; |
7043
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
16 |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
17 import java.awt.BasicStroke; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
18 import java.awt.Color; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
19 import java.awt.Font; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
20 |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
21 import org.jfree.ui.TextAnchor; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
22 import org.jfree.chart.plot.XYPlot; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
23 import org.jfree.chart.LegendItem; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
24 import org.jfree.chart.LegendItemCollection; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
25 import org.jfree.chart.annotations.XYTextAnnotation; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
26 import org.jfree.chart.annotations.XYLineAnnotation; |
8341
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
27 import org.jfree.chart.renderer.xy.XYItemRenderer; |
7043
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
28 |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
29 import org.dive4elements.river.themes.LineStyle; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
30 import org.dive4elements.river.themes.TextStyle; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
31 import org.dive4elements.river.exports.ChartSettings; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
32 import org.dive4elements.river.exports.LegendSection; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
33 import org.dive4elements.river.exports.ChartArea; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
34 |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
35 import org.apache.log4j.Logger; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
36 |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
37 /** Annotation helper class, handles plotting of annotations. */ |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
38 public class AnnotationHelper { |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7910
diff
changeset
|
39 private static final Logger log = Logger.getLogger(AnnotationHelper.class); |
7043
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
40 |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
41 protected static float ANNOTATIONS_AXIS_OFFSET = 0.02f; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
42 |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
43 /* arr this would be better in chartsettings */ |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
44 public static final int DEFAULT_FONT_SIZE = 12; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
45 public static final String DEFAULT_FONT_NAME = "Tahoma"; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
46 |
8341
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
47 |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
48 public static void addYAnnotationsToRenderer( |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
49 SortedMap<Integer, RiverAnnotation> yAnnotations, |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
50 XYPlot plot, |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
51 ChartSettings settings, |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
52 Map<Integer, AxisDataset> datasets |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
53 ) { |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
54 List<RiverAnnotation> annotations = new ArrayList<RiverAnnotation>(); |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
55 |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
56 for (Map.Entry<Integer, RiverAnnotation> entry: |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
57 yAnnotations.entrySet()) { |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
58 int axis = entry.getKey(); |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
59 AxisDataset dataset = datasets.get(new Integer(axis)); |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
60 |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
61 if (dataset == null || dataset.getRange() == null) { |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
62 log.warn("No dataset available and active for axis " + axis); |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
63 } |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
64 else { |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
65 RiverAnnotation ya = entry.getValue(); |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
66 for (StickyAxisAnnotation sta: ya.getAxisTextAnnotations()) { |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
67 sta.setAxisSymbol(axis); |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
68 } |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
69 annotations.add(ya); |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
70 } |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
71 } |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
72 |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
73 addAnnotationsToRenderer(annotations, plot, settings, datasets); |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
74 } |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
75 |
7043
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
76 /** |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
77 * Add annotations (Sticky, Text and hyk zones) to a plot. |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
78 * @param annotations Annotations to add |
8341
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
79 * @param plot XYPlot to add annotations to. |
7043
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
80 * @param settings ChartSettings object for settings. |
8341
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
81 * @param datasets Map of axis index and datasets |
7043
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
82 */ |
8341
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
83 public static void addAnnotationsToRenderer( |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
84 List<RiverAnnotation> annotations, |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
85 XYPlot plot, |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
86 ChartSettings settings, |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
87 Map<Integer, AxisDataset> datasets |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
88 ) { |
7043
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
89 if (annotations == null || annotations.isEmpty()) { |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7910
diff
changeset
|
90 log.debug("addAnnotationsToRenderer: no annotations."); |
7043
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
91 return; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
92 } |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
93 |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
94 // OPTMIMIZE: Pre-calculate positions |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
95 ChartArea area = new ChartArea( |
8316
c086b06b81e5
Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents:
8202
diff
changeset
|
96 plot.getDomainAxis(0), |
c086b06b81e5
Make ChartArea and thus annotations sensible for logarithmic axes (plus some minor cleanup).
"Tom Gottfried <tom@intevation.de>"
parents:
8202
diff
changeset
|
97 plot.getRangeAxis()); |
7043
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
98 |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
99 // Walk over all Annotation sets. |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
100 for (RiverAnnotation fa: annotations) { |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
101 |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
102 // Access text styling, if any. |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
103 ThemeDocument theme = fa.getTheme(); |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
104 TextStyle textStyle = null; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
105 LineStyle lineStyle = null; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
106 |
8341
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
107 // Get Theming information and add legend item. |
7043
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
108 if (theme != null) { |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
109 textStyle = theme.parseComplexTextStyle(); |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
110 lineStyle = theme.parseComplexLineStyle(); |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
111 if (fa.getLabel() != null) { |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
112 // Legend handling, maybe misplaced? |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
113 LegendItemCollection lic = new LegendItemCollection(); |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
114 LegendItemCollection old = plot.getFixedLegendItems(); |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
115 |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
116 Color color = theme.parseLineColorField(); |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
117 if (color == null) { |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
118 color = Color.BLACK; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
119 } |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
120 |
7910
432addd00687
Added text color for annotation labels.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7088
diff
changeset
|
121 Color textColor = theme.parseTextColor(); |
432addd00687
Added text color for annotation labels.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7088
diff
changeset
|
122 if (textColor == null) { |
432addd00687
Added text color for annotation labels.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7088
diff
changeset
|
123 textColor = Color.BLACK; |
432addd00687
Added text color for annotation labels.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7088
diff
changeset
|
124 } |
432addd00687
Added text color for annotation labels.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7088
diff
changeset
|
125 |
7043
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
126 LegendItem newItem = new LegendItem(fa.getLabel(), color); |
7070 | 127 LegendSection ls = (settings != null ? |
128 settings.getLegendSection() : null); | |
7043
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
129 newItem.setLabelFont (new Font( |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
130 DEFAULT_FONT_NAME, |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
131 Font.PLAIN, |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
132 ls != null ? ls.getFontSize() : null) |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
133 ); |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
134 |
7910
432addd00687
Added text color for annotation labels.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7088
diff
changeset
|
135 newItem.setLabelPaint(textColor); |
432addd00687
Added text color for annotation labels.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
7088
diff
changeset
|
136 |
7043
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
137 lic.add(newItem); |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
138 // (Re-)Add prior legend entries. |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
139 if (old != null) { |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
140 old.addAll(lic); |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
141 } |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
142 else { |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
143 old = lic; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
144 } |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
145 plot.setFixedLegendItems(old); |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
146 } |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
147 } |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
148 |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
149 // The 'Sticky' Annotations (at axis, with line and text). |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
150 for (StickyAxisAnnotation sta: fa.getAxisTextAnnotations()) { |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
151 addStickyAnnotation( |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
152 sta, plot, area, lineStyle, textStyle, theme, |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
153 datasets.get(new Integer(sta.getAxisSymbol()))); |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
154 } |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
155 |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
156 // Other Text Annotations (e.g. labels of (manual) points). |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
157 for (XYTextAnnotation ta: fa.getTextAnnotations()) { |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
158 // Style the text. |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
159 if (textStyle != null) { |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
160 textStyle.apply(ta); |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
161 } |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
162 ta.setY(area.above(0.05d, ta.getY())); |
8856 | 163 plot.getRenderer().addAnnotation( |
164 ta, org.jfree.ui.Layer.FOREGROUND); | |
7043
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
165 } |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
166 } |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
167 } |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
168 |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
169 /** |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
170 * Add a text and a line annotation. |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
171 * @param area convenience to determine positions in plot. |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
172 * @param theme (optional) theme document |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
173 */ |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
174 public static void addStickyAnnotation( |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
175 StickyAxisAnnotation annotation, |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
176 XYPlot plot, |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
177 ChartArea area, |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
178 LineStyle lineStyle, |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
179 TextStyle textStyle, |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
180 ThemeDocument theme, |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
181 AxisDataset dataset |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
182 ) { |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
183 // OPTIMIZE pre-calculate area-related values |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
184 final float TEXT_OFF = 0.03f; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
185 |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
186 XYLineAnnotation lineAnnotation = null; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
187 XYTextAnnotation textAnnotation = null; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
188 |
8341
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
189 int axisIndex = annotation.getAxisSymbol(); |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
190 XYItemRenderer renderer = null; |
8365 | 191 if (dataset != null && dataset.getDatasets().length > 0) { |
8341
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
192 renderer = plot.getRendererForDataset(dataset.getDatasets()[0]); |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
193 } |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
194 else { |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
195 renderer = plot.getRenderer(); |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
196 } |
7043
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
197 |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
198 if (annotation.atX()) { |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
199 textAnnotation = new CollisionFreeXYTextAnnotation( |
8856 | 200 annotation.getText(), |
201 annotation.getPos(), | |
202 area.ofGround(TEXT_OFF)); | |
7043
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
203 // OPTIMIZE externalize the calculation involving PI. |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
204 //textAnnotation.setRotationAngle(270f*Math.PI/180f); |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
205 lineAnnotation = createGroundStickAnnotation( |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
206 area, annotation.getPos(), lineStyle); |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
207 textAnnotation.setRotationAnchor(TextAnchor.CENTER_LEFT); |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
208 textAnnotation.setTextAnchor(TextAnchor.CENTER_LEFT); |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
209 } |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
210 else { |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
211 // Stick to the "right" (opposed to left) Y-Axis. |
8341
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
212 if (axisIndex != 0 && plot.getRangeAxis(axisIndex) != null) { |
7043
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
213 // OPTIMIZE: Pass a different area to this function, |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
214 // do the adding to renderer outside (let this |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
215 // function return the annotations). |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
216 // Note that this path is travelled rarely. |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
217 textAnnotation = new CollisionFreeXYTextAnnotation( |
8341
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
218 annotation.getText(), |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
219 area.ofRight(TEXT_OFF), |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
220 annotation.getPos() |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
221 ); |
7043
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
222 textAnnotation.setRotationAnchor(TextAnchor.CENTER_RIGHT); |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
223 textAnnotation.setTextAnchor(TextAnchor.CENTER_RIGHT); |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
224 lineAnnotation = createRightStickAnnotation( |
8341
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
225 area, annotation.getPos(), lineStyle); |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
226 |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
227 // hit-lines for duration curve |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
228 ChartArea area2 = new ChartArea( |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
229 plot.getDomainAxis(), plot.getRangeAxis(axisIndex)); |
7043
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
230 if (!Float.isNaN(annotation.getHitPoint()) && theme != null) { |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
231 // New line annotation to hit curve. |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
232 if (theme.parseShowVerticalLine()) { |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
233 XYLineAnnotation hitLineAnnotation = |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
234 createStickyLineAnnotation( |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
235 StickyAxisAnnotation.SimpleAxis.X_AXIS, |
8856 | 236 annotation.getHitPoint(), annotation.getPos(), |
237 // annotation.getHitPoint(), | |
7043
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
238 area2, lineStyle); |
8341
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
239 renderer.addAnnotation(hitLineAnnotation, |
7043
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
240 org.jfree.ui.Layer.BACKGROUND); |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
241 } |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
242 if (theme.parseShowHorizontalLine()) { |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
243 XYLineAnnotation lineBackAnnotation = |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
244 createStickyLineAnnotation( |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
245 StickyAxisAnnotation.SimpleAxis.Y_AXIS2, |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
246 annotation.getPos(), annotation.getHitPoint(), |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
247 area2, lineStyle); |
8341
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
248 renderer.addAnnotation(lineBackAnnotation, |
7043
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
249 org.jfree.ui.Layer.BACKGROUND); |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
250 } |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
251 } |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
252 } |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
253 else { // Stick to the left y-axis. |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
254 textAnnotation = new CollisionFreeXYTextAnnotation( |
8856 | 255 annotation.getText(), |
256 area.ofLeft(TEXT_OFF), | |
257 annotation.getPos()); | |
7043
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
258 textAnnotation.setRotationAnchor(TextAnchor.CENTER_LEFT); |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
259 textAnnotation.setTextAnchor(TextAnchor.CENTER_LEFT); |
8856 | 260 lineAnnotation = createLeftStickAnnotation( |
261 area, annotation.getPos(), lineStyle); | |
7043
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
262 if (!Float.isNaN(annotation.getHitPoint()) && theme != null) { |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
263 // New line annotation to hit curve. |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
264 if (theme.parseShowHorizontalLine()) { |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
265 XYLineAnnotation hitLineAnnotation = |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
266 createStickyLineAnnotation( |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
267 StickyAxisAnnotation.SimpleAxis.Y_AXIS, |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
268 annotation.getPos(), annotation.getHitPoint(), |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
269 area, lineStyle); |
8341
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
270 renderer.addAnnotation(hitLineAnnotation, |
7043
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
271 org.jfree.ui.Layer.BACKGROUND); |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
272 } |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
273 if (theme.parseShowVerticalLine()) { |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
274 XYLineAnnotation lineBackAnnotation = |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
275 createStickyLineAnnotation( |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
276 StickyAxisAnnotation.SimpleAxis.X_AXIS, |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
277 annotation.getHitPoint(), annotation.getPos(), |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
278 area, lineStyle); |
8341
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
279 renderer.addAnnotation(lineBackAnnotation, |
7043
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
280 org.jfree.ui.Layer.BACKGROUND); |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
281 } |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
282 } |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
283 } |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
284 } |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
285 |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
286 // Style the text. |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
287 if (textStyle != null) { |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
288 textStyle.apply(textAnnotation); |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
289 } |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
290 |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
291 // Add the Annotations to renderer. |
8341
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
292 renderer.addAnnotation(textAnnotation, org.jfree.ui.Layer.FOREGROUND); |
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
293 renderer.addAnnotation(lineAnnotation, org.jfree.ui.Layer.FOREGROUND); |
7043
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
294 } |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
295 |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
296 /** |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
297 * Create annotation that sticks to "ground" (X) axis. |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
298 * @param area helper to calculate coordinates |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
299 * @param pos one-dimensional position (distance from axis) |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
300 * @param lineStyle the line style to use for the line. |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
301 */ |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
302 public static XYLineAnnotation createGroundStickAnnotation( |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
303 ChartArea area, float pos, LineStyle lineStyle |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
304 ) { |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
305 // Style the line. |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
306 if (lineStyle != null) { |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
307 return new XYLineAnnotation( |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
308 pos, area.atGround(), |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
309 pos, area.ofGround(ANNOTATIONS_AXIS_OFFSET), |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
310 new BasicStroke(lineStyle.getWidth()),lineStyle.getColor()); |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
311 } |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
312 else { |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
313 return new XYLineAnnotation( |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
314 pos, area.atGround(), |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
315 pos, area.ofGround(ANNOTATIONS_AXIS_OFFSET)); |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
316 } |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
317 } |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
318 |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
319 |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
320 /** |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
321 * Create annotation that sticks to the second Y axis ("right"). |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
322 * @param area helper to calculate coordinates |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
323 * @param pos one-dimensional position (distance from axis) |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
324 * @param lineStyle the line style to use for the line. |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
325 */ |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
326 public static XYLineAnnotation createRightStickAnnotation( |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
327 ChartArea area, float pos, LineStyle lineStyle |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
328 ) { |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
329 // Style the line. |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
330 if (lineStyle != null) { |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
331 return new XYLineAnnotation( |
8341
130160b8d245
Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents:
8316
diff
changeset
|
332 area.atRight(), pos, |
7043
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
333 area.ofRight(ANNOTATIONS_AXIS_OFFSET), pos, |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
334 new BasicStroke(lineStyle.getWidth()), lineStyle.getColor()); |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
335 } |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
336 else { |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
337 return new XYLineAnnotation( |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
338 area.atRight(), pos, |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
339 area.ofRight(ANNOTATIONS_AXIS_OFFSET), pos); |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
340 } |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
341 } |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
342 /** |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
343 * Create annotation that sticks to the first Y axis ("left"). |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
344 * @param area helper to calculate coordinates |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
345 * @param pos one-dimensional position (distance from axis) |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
346 * @param lineStyle the line style to use for the line. |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
347 */ |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
348 public static XYLineAnnotation createLeftStickAnnotation( |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
349 ChartArea area, float pos, LineStyle lineStyle |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
350 ) { |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
351 // Style the line. |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
352 if (lineStyle != null) { |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
353 return new XYLineAnnotation( |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
354 area.atLeft(), pos, |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
355 area.ofLeft(ANNOTATIONS_AXIS_OFFSET), pos, |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
356 new BasicStroke(lineStyle.getWidth()), lineStyle.getColor()); |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
357 } |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
358 else { |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
359 return new XYLineAnnotation( |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
360 area.atLeft(), pos, |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
361 area.ofLeft(ANNOTATIONS_AXIS_OFFSET), pos); |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
362 } |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
363 } |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
364 |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
365 |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
366 /** |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
367 * Create a line from a axis to a given point. |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
368 * @param axis The "simple" axis. |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
369 * @param fromD1 from-location in first dimension. |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
370 * @param toD2 to-location in second dimension. |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
371 * @param area helper to calculate offsets. |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
372 * @param lineStyle optional line style. |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
373 */ |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
374 public static XYLineAnnotation createStickyLineAnnotation( |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
375 StickyAxisAnnotation.SimpleAxis axis, float fromD1, float toD2, |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
376 ChartArea area, LineStyle lineStyle |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
377 ) { |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
378 double anchorX1 = 0d, anchorX2 = 0d, anchorY1 = 0d, anchorY2 = 0d; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
379 switch(axis) { |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
380 case X_AXIS: |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
381 anchorX1 = fromD1; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
382 anchorX2 = fromD1; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
383 anchorY1 = area.atGround(); |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
384 anchorY2 = toD2; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
385 break; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
386 case Y_AXIS: |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
387 anchorX1 = area.atLeft(); |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
388 anchorX2 = toD2; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
389 anchorY1 = fromD1; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
390 anchorY2 = fromD1; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
391 break; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
392 case Y_AXIS2: |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
393 anchorX1 = area.atRight(); |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
394 anchorX2 = toD2; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
395 anchorY1 = fromD1; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
396 anchorY2 = fromD1; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
397 break; |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
398 } |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
399 // Style the line. |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
400 if (lineStyle != null) { |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
401 return new XYLineAnnotation( |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
402 anchorX1, anchorY1, |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
403 anchorX2, anchorY2, |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
404 new BasicStroke(lineStyle.getWidth()), lineStyle.getColor()); |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
405 } |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
406 else { |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
407 return new XYLineAnnotation( |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
408 anchorX1, anchorY1, |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
409 anchorX2, anchorY2); |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
410 } |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
411 } |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
412 |
06a9a241faac
Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
413 }; |