annotate artifacts/src/main/java/org/dive4elements/river/jfree/AnnotationHelper.java @ 8341:130160b8d245

Introduce annotations, which know to which axis they belong.
author Tom Gottfried <tom@intevation.de>
date Tue, 30 Sep 2014 11:50:43 +0200
parents c086b06b81e5
children 31272d799dad
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;
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
16 import java.util.TreeMap;
7043
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
17
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
18 import java.awt.BasicStroke;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
19 import java.awt.Color;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
20 import java.awt.Font;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
21
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
22 import org.jfree.ui.TextAnchor;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
23 import org.jfree.chart.plot.XYPlot;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
24 import org.jfree.chart.LegendItem;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
25 import org.jfree.chart.LegendItemCollection;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
26 import org.jfree.chart.annotations.XYTextAnnotation;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
27 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
28 import org.jfree.chart.renderer.xy.XYItemRenderer;
7043
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
29
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
30 import org.dive4elements.river.themes.LineStyle;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
31 import org.dive4elements.river.themes.TextStyle;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
32 import org.dive4elements.river.exports.ChartSettings;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
33 import org.dive4elements.river.exports.LegendSection;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
34 import org.dive4elements.river.exports.ChartArea;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
35
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
36 import org.apache.log4j.Logger;
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 {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7910
diff changeset
40 private static final Logger log = Logger.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()));
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
164 plot.getRenderer().addAnnotation(ta, org.jfree.ui.Layer.FOREGROUND);
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
165 }
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
166 }
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
167 }
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
168
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
169 /**
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
170 * Add a text and a line annotation.
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
171 * @param area convenience to determine positions in plot.
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
172 * @param theme (optional) theme document
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
173 */
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
174 public static void addStickyAnnotation(
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
175 StickyAxisAnnotation annotation,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
176 XYPlot plot,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
177 ChartArea area,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
178 LineStyle lineStyle,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
179 TextStyle textStyle,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
180 ThemeDocument theme,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
181 AxisDataset dataset
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
182 ) {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
183 // OPTIMIZE pre-calculate area-related values
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
184 final float TEXT_OFF = 0.03f;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
185
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
186 XYLineAnnotation lineAnnotation = null;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
187 XYTextAnnotation textAnnotation = null;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
188
8341
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
189 int axisIndex = annotation.getAxisSymbol();
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
190 XYItemRenderer renderer = null;
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
191 if (dataset.getDatasets().length > 0) {
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
192 renderer = plot.getRendererForDataset(dataset.getDatasets()[0]);
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
193 }
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
194 else {
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
195 renderer = plot.getRenderer();
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
196 }
7043
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
197
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
198 if (annotation.atX()) {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
199 textAnnotation = new CollisionFreeXYTextAnnotation(
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
200 annotation.getText(), annotation.getPos(), area.ofGround(TEXT_OFF));
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
201 // OPTIMIZE externalize the calculation involving PI.
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
202 //textAnnotation.setRotationAngle(270f*Math.PI/180f);
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
203 lineAnnotation = createGroundStickAnnotation(
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
204 area, annotation.getPos(), lineStyle);
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
205 textAnnotation.setRotationAnchor(TextAnchor.CENTER_LEFT);
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
206 textAnnotation.setTextAnchor(TextAnchor.CENTER_LEFT);
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
207 }
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
208 else {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
209 // 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
210 if (axisIndex != 0 && plot.getRangeAxis(axisIndex) != null) {
7043
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
211 // OPTIMIZE: Pass a different area to this function,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
212 // do the adding to renderer outside (let this
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
213 // function return the annotations).
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
214 // Note that this path is travelled rarely.
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
215 textAnnotation = new CollisionFreeXYTextAnnotation(
8341
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
216 annotation.getText(),
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
217 area.ofRight(TEXT_OFF),
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
218 annotation.getPos()
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
219 );
7043
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
220 textAnnotation.setRotationAnchor(TextAnchor.CENTER_RIGHT);
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
221 textAnnotation.setTextAnchor(TextAnchor.CENTER_RIGHT);
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
222 lineAnnotation = createRightStickAnnotation(
8341
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
223 area, annotation.getPos(), lineStyle);
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
224
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
225 // hit-lines for duration curve
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
226 ChartArea area2 = new ChartArea(
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
227 plot.getDomainAxis(), plot.getRangeAxis(axisIndex));
7043
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
228 if (!Float.isNaN(annotation.getHitPoint()) && theme != null) {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
229 // New line annotation to hit curve.
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
230 if (theme.parseShowVerticalLine()) {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
231 XYLineAnnotation hitLineAnnotation =
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
232 createStickyLineAnnotation(
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
233 StickyAxisAnnotation.SimpleAxis.X_AXIS,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
234 annotation.getHitPoint(), annotation.getPos(),// annotation.getHitPoint(),
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
235 area2, lineStyle);
8341
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
236 renderer.addAnnotation(hitLineAnnotation,
7043
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
237 org.jfree.ui.Layer.BACKGROUND);
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
238 }
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
239 if (theme.parseShowHorizontalLine()) {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
240 XYLineAnnotation lineBackAnnotation =
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
241 createStickyLineAnnotation(
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
242 StickyAxisAnnotation.SimpleAxis.Y_AXIS2,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
243 annotation.getPos(), annotation.getHitPoint(),
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
244 area2, lineStyle);
8341
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
245 renderer.addAnnotation(lineBackAnnotation,
7043
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
246 org.jfree.ui.Layer.BACKGROUND);
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 }
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
250 else { // Stick to the left y-axis.
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
251 textAnnotation = new CollisionFreeXYTextAnnotation(
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
252 annotation.getText(), area.ofLeft(TEXT_OFF), annotation.getPos());
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
253 textAnnotation.setRotationAnchor(TextAnchor.CENTER_LEFT);
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
254 textAnnotation.setTextAnchor(TextAnchor.CENTER_LEFT);
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
255 lineAnnotation = createLeftStickAnnotation(area, annotation.getPos(), lineStyle);
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
256 if (!Float.isNaN(annotation.getHitPoint()) && theme != null) {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
257 // New line annotation to hit curve.
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
258 if (theme.parseShowHorizontalLine()) {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
259 XYLineAnnotation hitLineAnnotation =
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
260 createStickyLineAnnotation(
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
261 StickyAxisAnnotation.SimpleAxis.Y_AXIS,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
262 annotation.getPos(), annotation.getHitPoint(),
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
263 area, lineStyle);
8341
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
264 renderer.addAnnotation(hitLineAnnotation,
7043
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
265 org.jfree.ui.Layer.BACKGROUND);
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
266 }
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
267 if (theme.parseShowVerticalLine()) {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
268 XYLineAnnotation lineBackAnnotation =
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
269 createStickyLineAnnotation(
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
270 StickyAxisAnnotation.SimpleAxis.X_AXIS,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
271 annotation.getHitPoint(), annotation.getPos(),
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
272 area, lineStyle);
8341
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
273 renderer.addAnnotation(lineBackAnnotation,
7043
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
274 org.jfree.ui.Layer.BACKGROUND);
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
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
280 // Style the text.
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
281 if (textStyle != null) {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
282 textStyle.apply(textAnnotation);
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 // 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
286 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
287 renderer.addAnnotation(lineAnnotation, org.jfree.ui.Layer.FOREGROUND);
7043
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 /**
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
291 * Create annotation that sticks to "ground" (X) axis.
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
292 * @param area helper to calculate coordinates
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
293 * @param pos one-dimensional position (distance from axis)
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
294 * @param lineStyle the line style to use for the line.
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 public static XYLineAnnotation createGroundStickAnnotation(
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
297 ChartArea area, float pos, LineStyle lineStyle
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
298 ) {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
299 // Style the line.
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
300 if (lineStyle != null) {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
301 return new XYLineAnnotation(
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
302 pos, area.atGround(),
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
303 pos, area.ofGround(ANNOTATIONS_AXIS_OFFSET),
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
304 new BasicStroke(lineStyle.getWidth()),lineStyle.getColor());
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 else {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
307 return new XYLineAnnotation(
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
308 pos, area.atGround(),
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
309 pos, area.ofGround(ANNOTATIONS_AXIS_OFFSET));
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
310 }
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 /**
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
315 * Create annotation that sticks to the second Y axis ("right").
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
316 * @param area helper to calculate coordinates
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
317 * @param pos one-dimensional position (distance from axis)
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
318 * @param lineStyle the line style to use for the line.
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 public static XYLineAnnotation createRightStickAnnotation(
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
321 ChartArea area, float pos, LineStyle lineStyle
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
322 ) {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
323 // Style the line.
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
324 if (lineStyle != null) {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
325 return new XYLineAnnotation(
8341
130160b8d245 Introduce annotations, which know to which axis they belong.
Tom Gottfried <tom@intevation.de>
parents: 8316
diff changeset
326 area.atRight(), pos,
7043
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
327 area.ofRight(ANNOTATIONS_AXIS_OFFSET), pos,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
328 new BasicStroke(lineStyle.getWidth()), lineStyle.getColor());
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 else {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
331 return new XYLineAnnotation(
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
332 area.atRight(), pos,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
333 area.ofRight(ANNOTATIONS_AXIS_OFFSET), pos);
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
334 }
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 /**
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
337 * Create annotation that sticks to the first Y axis ("left").
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
338 * @param area helper to calculate coordinates
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
339 * @param pos one-dimensional position (distance from axis)
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
340 * @param lineStyle the line style to use for the line.
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 public static XYLineAnnotation createLeftStickAnnotation(
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
343 ChartArea area, float pos, LineStyle lineStyle
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
344 ) {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
345 // Style the line.
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
346 if (lineStyle != null) {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
347 return new XYLineAnnotation(
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
348 area.atLeft(), pos,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
349 area.ofLeft(ANNOTATIONS_AXIS_OFFSET), pos,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
350 new BasicStroke(lineStyle.getWidth()), lineStyle.getColor());
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 else {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
353 return new XYLineAnnotation(
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
354 area.atLeft(), pos,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
355 area.ofLeft(ANNOTATIONS_AXIS_OFFSET), pos);
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
356 }
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 /**
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
361 * Create a line from a axis to a given point.
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
362 * @param axis The "simple" axis.
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
363 * @param fromD1 from-location in first dimension.
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
364 * @param toD2 to-location in second dimension.
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
365 * @param area helper to calculate offsets.
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
366 * @param lineStyle optional line style.
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 public static XYLineAnnotation createStickyLineAnnotation(
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
369 StickyAxisAnnotation.SimpleAxis axis, float fromD1, float toD2,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
370 ChartArea area, LineStyle lineStyle
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
371 ) {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
372 double anchorX1 = 0d, anchorX2 = 0d, anchorY1 = 0d, anchorY2 = 0d;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
373 switch(axis) {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
374 case X_AXIS:
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
375 anchorX1 = fromD1;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
376 anchorX2 = fromD1;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
377 anchorY1 = area.atGround();
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
378 anchorY2 = toD2;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
379 break;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
380 case Y_AXIS:
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
381 anchorX1 = area.atLeft();
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
382 anchorX2 = toD2;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
383 anchorY1 = fromD1;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
384 anchorY2 = fromD1;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
385 break;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
386 case Y_AXIS2:
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
387 anchorX1 = area.atRight();
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
388 anchorX2 = toD2;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
389 anchorY1 = fromD1;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
390 anchorY2 = fromD1;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
391 break;
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
392 }
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
393 // Style the line.
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
394 if (lineStyle != null) {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
395 return new XYLineAnnotation(
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
396 anchorX1, anchorY1,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
397 anchorX2, anchorY2,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
398 new BasicStroke(lineStyle.getWidth()), lineStyle.getColor());
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 else {
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
401 return new XYLineAnnotation(
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
402 anchorX1, anchorY1,
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
403 anchorX2, anchorY2);
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
404 }
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
06a9a241faac Factor out annotation handling code
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
407 };

http://dive4elements.wald.intevation.org