annotate flys-artifacts/src/main/java/de/intevation/flys/jfree/StickyAxisAnnotation.java @ 1738:6cdc7a77d3d4

Apply theme attributes to axis annotation. flys-artifacts/trunk@3028 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Wed, 19 Oct 2011 11:39:46 +0000
parents f708120cb7bc
children 27b8836abec9
rev   line source
1039
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.jfree;
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
2
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
3 import org.apache.log4j.Logger;
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
4
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
5 import java.util.Iterator;
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
6
1738
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
7 import org.w3c.dom.Document;
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
8
1039
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
9 import java.awt.Shape;
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
10 import java.awt.geom.Rectangle2D;
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
11 import java.awt.geom.Line2D;
1738
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
12 import java.awt.Color;
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
13 import java.awt.Font;
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
14 import java.awt.BasicStroke;
1039
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
15
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
16 import org.jfree.chart.annotations.XYTextAnnotation;
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
17 import org.jfree.chart.axis.ValueAxis;
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
18 import org.jfree.chart.util.LineUtilities;
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
19 import org.jfree.chart.plot.PlotOrientation;
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
20 import org.jfree.chart.plot.XYPlot;
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
21 import org.jfree.chart.entity.XYAnnotationEntity;
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
22 import org.jfree.chart.plot.PlotRenderingInfo;
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
23 import org.jfree.chart.ChartRenderingInfo;
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
24 import org.jfree.chart.plot.Plot;
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
25
1085
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
26 import org.jfree.data.Range;
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
27
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
28 import org.jfree.text.TextUtilities;
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
29
1039
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
30 import org.jfree.ui.RectangleEdge;
1082
f16b66839e59 Prepare StickyAxisAnnotation implementation to handle annotations at 'y' (vertical) axis.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1042
diff changeset
31 import org.jfree.ui.TextAnchor;
1039
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
32
1738
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
33 import de.intevation.flys.utils.ThemeUtil;
1039
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
34
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
35 /**
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
36 * Custom Annotations class that is drawn only if no collisions with other
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
37 * already drawn CustomAnnotations in current plot are found.
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
38 * Draws a given text and a line to it from either axis.
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
39 */
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
40 public class StickyAxisAnnotation extends XYTextAnnotation {
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
41
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
42 /** Logger for this class. */
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
43 private static Logger logger =
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
44 Logger.getLogger(StickyAxisAnnotation.class);
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
45
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
46 /** Simplified view on axes. */
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
47 public static enum SimpleAxis {
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
48 X_AXIS, /** Usually "horizontal". */
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
49 Y_AXIS /** Usually "vertical". */
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
50 }
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
51
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
52 /** Which axis to stick to. */
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
53 protected SimpleAxis stickyAxis = SimpleAxis.X_AXIS;
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
54
1085
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
55 /** The 1-dimensional position of this annotation. */
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
56 protected float pos;
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
57
1738
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
58 /** Theme attributes. */
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
59 protected Color textColor;
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
60 protected Color lineColor;
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
61 protected Font font;
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
62 protected int lineWidth;
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
63
1039
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
64
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
65 /**
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
66 * Trivial constructor.
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
67 *
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
68 * @param text Text to display.
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
69 * @param x X-position in dataspace (typical horizontal, in km).
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
70 * @param y Y-position in dataspace (typical vertical, in m).
1085
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
71 * @deprecated
1039
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
72 */
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
73 public StickyAxisAnnotation(String text, float x, float y) {
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
74 super(text, x, y);
1082
f16b66839e59 Prepare StickyAxisAnnotation implementation to handle annotations at 'y' (vertical) axis.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1042
diff changeset
75 setStickyAxis(SimpleAxis.X_AXIS);
1039
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
76 }
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
77
1085
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
78
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
79 /**
1089
e298c4d28927 Improved mainvalues rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1085
diff changeset
80 * Constructor with implicit sticky x-axis.
e298c4d28927 Improved mainvalues rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1085
diff changeset
81 * @param text the text to display.
e298c4d28927 Improved mainvalues rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1085
diff changeset
82 * @param pos the position at which to draw the text and mark.
e298c4d28927 Improved mainvalues rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1085
diff changeset
83 */
e298c4d28927 Improved mainvalues rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1085
diff changeset
84 public StickyAxisAnnotation(String text, float pos) {
e298c4d28927 Improved mainvalues rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1085
diff changeset
85 this(text, pos, pos, SimpleAxis.X_AXIS);
e298c4d28927 Improved mainvalues rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1085
diff changeset
86 }
e298c4d28927 Improved mainvalues rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1085
diff changeset
87
e298c4d28927 Improved mainvalues rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1085
diff changeset
88
e298c4d28927 Improved mainvalues rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1085
diff changeset
89 /**
1085
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
90 * Constructor with given explicit axis.
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
91 * @param text the text to display.
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
92 * @param pos the position at which to draw the text and mark.
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
93 * @param stickyAxis the axis at which to stick (and to which 'pos' is
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
94 * relative).
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
95 */
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
96 public StickyAxisAnnotation(String text, float pos, SimpleAxis stickAxis) {
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
97 super(text, pos, pos);
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
98 setStickyAxis(stickAxis);
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
99 this.pos = pos;
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
100 }
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
101
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
102 /**
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
103 * Legacy-Constructor.
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
104 * @deprecated
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
105 */
1082
f16b66839e59 Prepare StickyAxisAnnotation implementation to handle annotations at 'y' (vertical) axis.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1042
diff changeset
106 public StickyAxisAnnotation(String text, float x, float y,
f16b66839e59 Prepare StickyAxisAnnotation implementation to handle annotations at 'y' (vertical) axis.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1042
diff changeset
107 SimpleAxis stickAxis) {
f16b66839e59 Prepare StickyAxisAnnotation implementation to handle annotations at 'y' (vertical) axis.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1042
diff changeset
108 super(text, x, y);
f16b66839e59 Prepare StickyAxisAnnotation implementation to handle annotations at 'y' (vertical) axis.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1042
diff changeset
109 setStickyAxis(stickAxis);
1085
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
110 this.pos = x;
1082
f16b66839e59 Prepare StickyAxisAnnotation implementation to handle annotations at 'y' (vertical) axis.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1042
diff changeset
111 }
f16b66839e59 Prepare StickyAxisAnnotation implementation to handle annotations at 'y' (vertical) axis.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1042
diff changeset
112
f16b66839e59 Prepare StickyAxisAnnotation implementation to handle annotations at 'y' (vertical) axis.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1042
diff changeset
113
1039
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
114 /**
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
115 * Sets the "sticky axis" (whether to draw annotations at the
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
116 * X- or the Y-Axis.
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
117 *
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
118 * @param stickyAxis axis to stick to.
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
119 */
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
120 public void setStickyAxis(SimpleAxis stickyAxis) {
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
121 this.stickyAxis = stickyAxis;
1082
f16b66839e59 Prepare StickyAxisAnnotation implementation to handle annotations at 'y' (vertical) axis.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1042
diff changeset
122 if (stickyAxis == SimpleAxis.X_AXIS) {
f16b66839e59 Prepare StickyAxisAnnotation implementation to handle annotations at 'y' (vertical) axis.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1042
diff changeset
123 this.setRotationAngle(270f * (Math.PI / 180f));
f16b66839e59 Prepare StickyAxisAnnotation implementation to handle annotations at 'y' (vertical) axis.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1042
diff changeset
124 this.setRotationAnchor(TextAnchor.CENTER_LEFT);
f16b66839e59 Prepare StickyAxisAnnotation implementation to handle annotations at 'y' (vertical) axis.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1042
diff changeset
125 this.setTextAnchor(TextAnchor.CENTER_LEFT);
1085
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
126 } else {
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
127 this.setRotationAngle(0f * (Math.PI / 180f));
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
128 this.setRotationAnchor(TextAnchor.CENTER_LEFT);
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
129 this.setTextAnchor(TextAnchor.CENTER_LEFT);
1082
f16b66839e59 Prepare StickyAxisAnnotation implementation to handle annotations at 'y' (vertical) axis.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1042
diff changeset
130 }
1039
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
131 }
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
132
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
133
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
134 /**
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
135 * Draws a small line at axis where this annotation resides.
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
136 *
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
137 * @param g2 the graphics device.
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
138 * @param dataArea the data area.
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
139 * @param domainAxis the domain axis.
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
140 * @param rangeAxis the range axis.
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
141 * @param domainEdge the domain edge.
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
142 * @param rangeEdge the range edge.
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
143 * @param orientation the plot orientation.
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
144 */
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
145 protected void drawAxisMark(
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
146 java.awt.Graphics2D g2,
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
147 java.awt.geom.Rectangle2D dataArea,
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
148 ValueAxis domainAxis,
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
149 ValueAxis rangeAxis,
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
150 RectangleEdge domainEdge,
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
151 RectangleEdge rangeEdge,
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
152 PlotOrientation orientation) {
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
153 float j2DX1 = 0.0f;
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
154 float j2DX2 = 0.0f;
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
155 float j2DY1 = 0.0f;
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
156 float j2DY2 = 0.0f;
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
157 float x = (float) getX();
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
158 float y = (float) getY();
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
159 /* When dependent on X/Y-Axis and orientation, following
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
160 can be used as a base:
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
161 if (orientation == PlotOrientation.VERTICAL) {
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
162 j2DX1 = (float) domainAxis.valueToJava2D(x, dataArea,
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
163 domainEdge);
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
164 j2DY1 = (float) rangeAxis.valueToJava2D(y, dataArea,
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
165 rangeEdge);
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
166 j2DX2 = (float) domainAxis.valueToJava2D(x, dataArea,
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
167 domainEdge);
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
168 j2DY2 = (float) rangeAxis.valueToJava2D(y, dataArea,
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
169 rangeEdge);
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
170 }
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
171 else if (orientation == PlotOrientation.HORIZONTAL) {
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
172 j2DY1 = (float) domainAxis.valueToJava2D(x, dataArea,
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
173 domainEdge);
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
174 j2DX1 = (float) rangeAxis.valueToJava2D(y, dataArea,
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
175 rangeEdge);
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
176 j2DY2 = (float) domainAxis.valueToJava2D(x, dataArea,
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
177 domainEdge);
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
178 j2DX2 = (float) rangeAxis.valueToJava2D(y, dataArea,
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
179 rangeEdge);
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
180 }
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
181
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
182 g2.setPaint(this.paint);
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
183 g2.setStroke(this.stroke);
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
184 */
1085
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
185 if (this.stickyAxis == SimpleAxis.X_AXIS) {
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
186 j2DY1 = (float) RectangleEdge.coordinate(dataArea, domainEdge);
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
187 double rangeLow = rangeAxis.getRange().getLowerBound();
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
188 // Line ends at 1.5% of full distance.
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
189 j2DY2 = (float) rangeAxis.valueToJava2D(
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
190 (1f - 0.015f) * rangeLow + 0.015f *
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
191 rangeAxis.getRange().getUpperBound(),
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
192 dataArea, rangeEdge);
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
193 j2DX1 = (float) domainAxis.valueToJava2D(x, dataArea, domainEdge);
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
194 j2DX2 = j2DX1;
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
195 } else {
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
196 j2DX1 = (float) RectangleEdge.coordinate(dataArea, rangeEdge);
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
197 Range domainRange = domainAxis.getRange();
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
198 double rangeLow = domainRange.getLowerBound();
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
199 // Line ends at 1.5% of full distance.
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
200 j2DX2 = (float) domainAxis.valueToJava2D(
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
201 (1f - 0.015f) * rangeLow + 0.015f *
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
202 domainRange.getUpperBound(),
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
203 dataArea, domainEdge);
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
204 j2DY1 = (float) rangeAxis.valueToJava2D(pos, dataArea, rangeEdge);
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
205 j2DY2 = j2DY1;
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
206 }
1039
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
207
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
208 Line2D line = new Line2D.Float(j2DX1, j2DY1, j2DX2, j2DY2);
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
209
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
210 // line is clipped to avoid JRE bug 6574155, for more info
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
211 // see JFreeChart bug 2221495
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
212 boolean visible = LineUtilities.clipLine(line, dataArea);
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
213 if (visible) {
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
214 g2.draw(line);
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
215 }
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
216 }
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
217
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
218
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
219 /**
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
220 * Draw the Annotiation if it does not collide with other already drawn
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
221 * Annotations.
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
222 *
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
223 * @param g2 the graphics device.
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
224 * @param plot the plot.
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
225 * @param dataArea the data area.
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
226 * @param domainAxis the domain axis.
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
227 * @param rangeAxis the range axis.
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
228 * @param rendererIndex the render index.
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
229 * @param info state information, escpecially collects info about
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
230 * already drawn shapes (and thus annotations), used
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
231 * for collision detection.
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
232 */
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
233 @Override
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
234 public void draw(
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
235 java.awt.Graphics2D g2,
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
236 XYPlot plot,
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
237 java.awt.geom.Rectangle2D dataArea,
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
238 ValueAxis domainAxis,
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
239 ValueAxis rangeAxis,
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
240 int rendererIndex,
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
241 PlotRenderingInfo info) {
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
242
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
243 if (info == null)
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
244 return;
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
245
1167
f1c9bfb07ba7 Fix crash when StickyAxisAnnotation should be drawn without proper axis
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1156
diff changeset
246 if (domainAxis == null || rangeAxis == null
f1c9bfb07ba7 Fix crash when StickyAxisAnnotation should be drawn without proper axis
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1156
diff changeset
247 || domainAxis.getRange() == null
f1c9bfb07ba7 Fix crash when StickyAxisAnnotation should be drawn without proper axis
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1156
diff changeset
248 || rangeAxis.getRange() == null
f1c9bfb07ba7 Fix crash when StickyAxisAnnotation should be drawn without proper axis
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1156
diff changeset
249 ) {
f1c9bfb07ba7 Fix crash when StickyAxisAnnotation should be drawn without proper axis
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1156
diff changeset
250 logger.error("Annotation cannot be drawn (missing axis).");
f1c9bfb07ba7 Fix crash when StickyAxisAnnotation should be drawn without proper axis
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1156
diff changeset
251 return;
f1c9bfb07ba7 Fix crash when StickyAxisAnnotation should be drawn without proper axis
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1156
diff changeset
252 }
f1c9bfb07ba7 Fix crash when StickyAxisAnnotation should be drawn without proper axis
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1156
diff changeset
253
1039
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
254 // Calculate the bounding box.
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
255 ChartRenderingInfo chartInfo = info.getOwner();
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
256
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
257 PlotOrientation orientation = plot.getOrientation();
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
258 RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
259 plot.getDomainAxisLocation(), orientation);
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
260 RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
261 plot.getRangeAxisLocation(), orientation);
1085
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
262 float anchorX = 0f;
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
263 float anchorY = 0.0f;
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
264 if (this.stickyAxis == SimpleAxis.X_AXIS) {
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
265 // Text starts at 1.5% of full distance.
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
266 float rangeLow = (float) rangeAxis.getRange().getLowerBound();
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
267 float y = rangeLow + 0.02f * ((float)
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
268 rangeAxis.getRange().getUpperBound() - rangeLow);
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
269 setY(y);
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
270
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
271 anchorX = (float) domainAxis.valueToJava2D(
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
272 getX(), dataArea, domainEdge);
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
273 anchorY = (float) rangeAxis.valueToJava2D(
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
274 getY(), dataArea, rangeEdge);
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
275 } else {
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
276 float rangeLow = (float) domainAxis.getRange().getLowerBound();
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
277 float x = rangeLow + 0.02f * ((float)
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
278 domainAxis.getRange().getUpperBound() - rangeLow);
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
279 setX(x);
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
280 anchorX = (float) domainAxis.valueToJava2D(
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
281 getX(), dataArea, domainEdge);
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
282 anchorY = (float) rangeAxis.valueToJava2D(
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
283 getY(), dataArea, rangeEdge);
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
284 }
1039
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
285 if (orientation == PlotOrientation.HORIZONTAL) {
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
286 float tempAnchor = anchorX;
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
287 anchorX = anchorY;
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
288 anchorY = tempAnchor;
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
289 }
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
290
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
291 // Always draw the small line at axis.
1738
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
292 setOutlineStroke(new BasicStroke((float) lineWidth));
1711
f708120cb7bc Fix flys/issue363 (W-INFO/ Abflusskurve, Extremwert-Rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1167
diff changeset
293 g2.setStroke(getOutlineStroke());
1738
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
294 g2.setPaint(lineColor);
1039
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
295 drawAxisMark(g2, dataArea, domainAxis, rangeAxis, domainEdge,
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
296 rangeEdge, orientation);
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
297
1738
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
298 g2.setPaint(textColor);
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
299 g2.setFont(font);
1039
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
300 Shape hotspot = TextUtilities.calculateRotatedStringBounds(
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
301 getText(), g2, anchorX, anchorY, getTextAnchor(),
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
302 getRotationAngle(), getRotationAnchor());
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
303 Rectangle2D hotspotBox = hotspot.getBounds2D();
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
304 // Check for collisions with other XYAnnotations.
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
305 for (Iterator i = chartInfo.getEntityCollection().iterator();
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
306 i.hasNext(); ) {
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
307 Object next = i.next();
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
308 // Collision with other stuff than XYAnnotations are okay.
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
309 if (next instanceof XYAnnotationEntity) {
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
310 XYAnnotationEntity drawnShape = (XYAnnotationEntity) next;
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
311 if (drawnShape.getArea().intersects(hotspotBox)) {
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
312 // Found collision, early stop.
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
313 return;
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
314 }
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
315 }
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
316 }
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
317
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
318 // Actuall drawing.
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
319 if (getBackgroundPaint() != null) {
1711
f708120cb7bc Fix flys/issue363 (W-INFO/ Abflusskurve, Extremwert-Rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1167
diff changeset
320 g2.setPaint(getBackgroundPaint());
1039
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
321 g2.fill(hotspot);
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
322 }
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
323 TextUtilities.drawRotatedString(getText(), g2, anchorX, anchorY,
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
324 getTextAnchor(), getRotationAngle(), getRotationAnchor());
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
325 // Draw outline.
1156
4da9f058fed6 Fix flys/issue280 (boundingboxes of annotation).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1089
diff changeset
326 if (false) {
1039
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
327 g2.setStroke(getOutlineStroke());
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
328 g2.setPaint(getOutlinePaint());
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
329 g2.draw(hotspot);
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
330 }
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
331
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
332 // Add info that we have drawn this Annotation.
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
333 addEntity(info, hotspot, rendererIndex, getToolTipText(), getURL());
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
334 }
1738
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
335
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
336
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
337 public void applyTheme(Document theme) {
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
338 lineWidth = ThemeUtil.parseLineWidth(theme);
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
339 lineColor = ThemeUtil.parseLineColorField(theme);
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
340 textColor = ThemeUtil.parseTextColor(theme);
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
341 font = ThemeUtil.parseTextFont(theme);
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
342 }
1039
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
343 }
1711
f708120cb7bc Fix flys/issue363 (W-INFO/ Abflusskurve, Extremwert-Rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1167
diff changeset
344 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org