annotate artifacts/src/main/java/org/dive4elements/river/jfree/AnnotationHelper.java @ 8365:ebf74d92be38

dataset can be null.
author Tom Gottfried <tom@intevation.de>
date Thu, 02 Oct 2014 10:13:31 +0200
parents 31272d799dad
children 5e38e2924c07
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
35aabc86566d Add NPE guard
Andre Heinecke <aheinecke@intevation.de>
parents: 7043
diff changeset
127 LegendSection ls = (settings != null ?
35aabc86566d Add NPE guard
Andre Heinecke <aheinecke@intevation.de>
parents: 7043
diff changeset
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()));
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
163 plot.getRenderer().addAnnotation(ta, org.jfree.ui.Layer.FOREGROUND);
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
164 }
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 * Add a text and a line annotation.
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
170 * @param area convenience to determine positions in plot.
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
171 * @param theme (optional) theme document
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
172 */
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
173 public static void addStickyAnnotation(
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
174 StickyAxisAnnotation annotation,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
175 XYPlot plot,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
176 ChartArea area,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
177 LineStyle lineStyle,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
178 TextStyle textStyle,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
179 ThemeDocument theme,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
180 AxisDataset dataset
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
181 ) {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
182 // OPTIMIZE pre-calculate area-related values
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
183 final float TEXT_OFF = 0.03f;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
184
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
185 XYLineAnnotation lineAnnotation = null;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
186 XYTextAnnotation textAnnotation = null;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
187
8341
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
188 int axisIndex = annotation.getAxisSymbol();
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
189 XYItemRenderer renderer = null;
8365
ebf74d92be38 dataset can be null.
Tom Gottfried <tom@intevation.de>
parents: 8346
diff changeset
190 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
191 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
192 }
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
193 else {
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
194 renderer = plot.getRenderer();
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
195 }
7043
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
196
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
197 if (annotation.atX()) {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
198 textAnnotation = new CollisionFreeXYTextAnnotation(
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
199 annotation.getText(), annotation.getPos(), area.ofGround(TEXT_OFF));
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
200 // OPTIMIZE externalize the calculation involving PI.
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
201 //textAnnotation.setRotationAngle(270f*Math.PI/180f);
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
202 lineAnnotation = createGroundStickAnnotation(
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
203 area, annotation.getPos(), lineStyle);
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
204 textAnnotation.setRotationAnchor(TextAnchor.CENTER_LEFT);
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
205 textAnnotation.setTextAnchor(TextAnchor.CENTER_LEFT);
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
206 }
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
207 else {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
208 // 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
209 if (axisIndex != 0 && plot.getRangeAxis(axisIndex) != null) {
7043
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
210 // OPTIMIZE: Pass a different area to this function,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
211 // do the adding to renderer outside (let this
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
212 // function return the annotations).
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
213 // Note that this path is travelled rarely.
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
214 textAnnotation = new CollisionFreeXYTextAnnotation(
8341
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
215 annotation.getText(),
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
216 area.ofRight(TEXT_OFF),
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
217 annotation.getPos()
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
218 );
7043
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
219 textAnnotation.setRotationAnchor(TextAnchor.CENTER_RIGHT);
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
220 textAnnotation.setTextAnchor(TextAnchor.CENTER_RIGHT);
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
221 lineAnnotation = createRightStickAnnotation(
8341
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
222 area, annotation.getPos(), lineStyle);
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
223
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
224 // hit-lines for duration curve
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
225 ChartArea area2 = new ChartArea(
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
226 plot.getDomainAxis(), plot.getRangeAxis(axisIndex));
7043
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
227 if (!Float.isNaN(annotation.getHitPoint()) && theme != null) {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
228 // New line annotation to hit curve.
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
229 if (theme.parseShowVerticalLine()) {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
230 XYLineAnnotation hitLineAnnotation =
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
231 createStickyLineAnnotation(
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
232 StickyAxisAnnotation.SimpleAxis.X_AXIS,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
233 annotation.getHitPoint(), annotation.getPos(),// annotation.getHitPoint(),
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
234 area2, lineStyle);
8341
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
235 renderer.addAnnotation(hitLineAnnotation,
7043
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
236 org.jfree.ui.Layer.BACKGROUND);
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
237 }
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
238 if (theme.parseShowHorizontalLine()) {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
239 XYLineAnnotation lineBackAnnotation =
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
240 createStickyLineAnnotation(
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
241 StickyAxisAnnotation.SimpleAxis.Y_AXIS2,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
242 annotation.getPos(), annotation.getHitPoint(),
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
243 area2, lineStyle);
8341
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
244 renderer.addAnnotation(lineBackAnnotation,
7043
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
245 org.jfree.ui.Layer.BACKGROUND);
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
246 }
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
247 }
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
248 }
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
249 else { // Stick to the left y-axis.
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
250 textAnnotation = new CollisionFreeXYTextAnnotation(
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
251 annotation.getText(), area.ofLeft(TEXT_OFF), annotation.getPos());
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
252 textAnnotation.setRotationAnchor(TextAnchor.CENTER_LEFT);
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
253 textAnnotation.setTextAnchor(TextAnchor.CENTER_LEFT);
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
254 lineAnnotation = createLeftStickAnnotation(area, annotation.getPos(), lineStyle);
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
255 if (!Float.isNaN(annotation.getHitPoint()) && theme != null) {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
256 // New line annotation to hit curve.
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
257 if (theme.parseShowHorizontalLine()) {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
258 XYLineAnnotation hitLineAnnotation =
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
259 createStickyLineAnnotation(
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
260 StickyAxisAnnotation.SimpleAxis.Y_AXIS,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
261 annotation.getPos(), annotation.getHitPoint(),
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
262 area, lineStyle);
8341
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
263 renderer.addAnnotation(hitLineAnnotation,
7043
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
264 org.jfree.ui.Layer.BACKGROUND);
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
265 }
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
266 if (theme.parseShowVerticalLine()) {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
267 XYLineAnnotation lineBackAnnotation =
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
268 createStickyLineAnnotation(
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
269 StickyAxisAnnotation.SimpleAxis.X_AXIS,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
270 annotation.getHitPoint(), annotation.getPos(),
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
271 area, lineStyle);
8341
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
272 renderer.addAnnotation(lineBackAnnotation,
7043
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
273 org.jfree.ui.Layer.BACKGROUND);
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
274 }
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
275 }
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
276 }
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
277 }
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
278
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
279 // Style the text.
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
280 if (textStyle != null) {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
281 textStyle.apply(textAnnotation);
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 // 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
285 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
286 renderer.addAnnotation(lineAnnotation, org.jfree.ui.Layer.FOREGROUND);
7043
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
287 }
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
288
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 * Create annotation that sticks to "ground" (X) axis.
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
291 * @param area helper to calculate coordinates
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
292 * @param pos one-dimensional position (distance from axis)
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
293 * @param lineStyle the line style to use for the line.
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 public static XYLineAnnotation createGroundStickAnnotation(
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
296 ChartArea area, float pos, LineStyle lineStyle
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
297 ) {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
298 // Style the line.
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
299 if (lineStyle != null) {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
300 return new XYLineAnnotation(
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
301 pos, area.atGround(),
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
302 pos, area.ofGround(ANNOTATIONS_AXIS_OFFSET),
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
303 new BasicStroke(lineStyle.getWidth()),lineStyle.getColor());
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 else {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
306 return new XYLineAnnotation(
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
307 pos, area.atGround(),
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
308 pos, area.ofGround(ANNOTATIONS_AXIS_OFFSET));
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
309 }
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
310 }
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
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
313 /**
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
314 * Create annotation that sticks to the second Y axis ("right").
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
315 * @param area helper to calculate coordinates
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
316 * @param pos one-dimensional position (distance from axis)
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
317 * @param lineStyle the line style to use for the line.
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 public static XYLineAnnotation createRightStickAnnotation(
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
320 ChartArea area, float pos, LineStyle lineStyle
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
321 ) {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
322 // Style the line.
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
323 if (lineStyle != null) {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
324 return new XYLineAnnotation(
8341
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
325 area.atRight(), pos,
7043
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
326 area.ofRight(ANNOTATIONS_AXIS_OFFSET), pos,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
327 new BasicStroke(lineStyle.getWidth()), lineStyle.getColor());
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 else {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
330 return new XYLineAnnotation(
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
331 area.atRight(), pos,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
332 area.ofRight(ANNOTATIONS_AXIS_OFFSET), pos);
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
333 }
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
334 }
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 * Create annotation that sticks to the first Y axis ("left").
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
337 * @param area helper to calculate coordinates
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
338 * @param pos one-dimensional position (distance from axis)
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
339 * @param lineStyle the line style to use for the line.
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 public static XYLineAnnotation createLeftStickAnnotation(
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
342 ChartArea area, float pos, LineStyle lineStyle
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
343 ) {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
344 // Style the line.
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
345 if (lineStyle != null) {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
346 return new XYLineAnnotation(
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
347 area.atLeft(), pos,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
348 area.ofLeft(ANNOTATIONS_AXIS_OFFSET), pos,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
349 new BasicStroke(lineStyle.getWidth()), lineStyle.getColor());
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 else {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
352 return new XYLineAnnotation(
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
353 area.atLeft(), pos,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
354 area.ofLeft(ANNOTATIONS_AXIS_OFFSET), pos);
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
355 }
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
356 }
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
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
359 /**
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
360 * Create a line from a axis to a given point.
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
361 * @param axis The "simple" axis.
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
362 * @param fromD1 from-location in first dimension.
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
363 * @param toD2 to-location in second dimension.
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
364 * @param area helper to calculate offsets.
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
365 * @param lineStyle optional line style.
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 public static XYLineAnnotation createStickyLineAnnotation(
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
368 StickyAxisAnnotation.SimpleAxis axis, float fromD1, float toD2,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
369 ChartArea area, LineStyle lineStyle
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
370 ) {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
371 double anchorX1 = 0d, anchorX2 = 0d, anchorY1 = 0d, anchorY2 = 0d;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
372 switch(axis) {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
373 case X_AXIS:
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
374 anchorX1 = fromD1;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
375 anchorX2 = fromD1;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
376 anchorY1 = area.atGround();
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
377 anchorY2 = toD2;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
378 break;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
379 case Y_AXIS:
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
380 anchorX1 = area.atLeft();
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
381 anchorX2 = toD2;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
382 anchorY1 = fromD1;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
383 anchorY2 = fromD1;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
384 break;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
385 case Y_AXIS2:
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
386 anchorX1 = area.atRight();
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
387 anchorX2 = toD2;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
388 anchorY1 = fromD1;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
389 anchorY2 = fromD1;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
390 break;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
391 }
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
392 // Style the line.
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
393 if (lineStyle != null) {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
394 return new XYLineAnnotation(
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
395 anchorX1, anchorY1,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
396 anchorX2, anchorY2,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
397 new BasicStroke(lineStyle.getWidth()), lineStyle.getColor());
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 else {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
400 return new XYLineAnnotation(
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
401 anchorX1, anchorY1,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
402 anchorX2, anchorY2);
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
403 }
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
404 }
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 };

http://dive4elements.wald.intevation.org