annotate artifacts/src/main/java/org/dive4elements/river/jfree/AnnotationHelper.java @ 9726:0a5239a1e46e 3.2.x

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

http://dive4elements.wald.intevation.org