annotate flys-artifacts/src/main/java/de/intevation/flys/jfree/StickyAxisAnnotation.java @ 2161:c68f4f227c09

Somewhat unified Annotation handling, use jfreechart-house-toolkit instead of custom StickyAxisAnnotation. flys-artifacts/trunk@3747 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Mon, 23 Jan 2012 10:44:34 +0000
parents 59622ba800c8
children 105097966111
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
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
6 /**
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
7 * Custom Annotations class that is drawn only if no collisions with other
1759
c51089a84d13 Restored correct drawing behavior for Annotations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1754
diff changeset
8 * already drawn CustomAnnotations in current plot are found. A mark on
c51089a84d13 Restored correct drawing behavior for Annotations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1754
diff changeset
9 * the axis is shown in all cases, though.
1039
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
10 * 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
11 */
2161
c68f4f227c09 Somewhat unified Annotation handling, use jfreechart-house-toolkit instead of custom StickyAxisAnnotation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1962
diff changeset
12 public class StickyAxisAnnotation {
1039
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
13
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
14 /** Logger for this class. */
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
15 private static Logger logger =
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
16 Logger.getLogger(StickyAxisAnnotation.class);
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
17
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
18 /** Simplified view on axes. */
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
19 public static enum SimpleAxis {
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
20 X_AXIS, /** Usually "horizontal". */
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
21 Y_AXIS /** Usually "vertical". */
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
22 }
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
23
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
24 /** Which axis to stick to. */
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
25 protected SimpleAxis stickyAxis = SimpleAxis.X_AXIS;
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
26
1085
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
27 /** 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
28 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
29
2161
c68f4f227c09 Somewhat unified Annotation handling, use jfreechart-house-toolkit instead of custom StickyAxisAnnotation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1962
diff changeset
30 String text;
1085
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
31
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
32 /**
1089
e298c4d28927 Improved mainvalues rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1085
diff changeset
33 * Constructor with implicit sticky x-axis.
e298c4d28927 Improved mainvalues rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1085
diff changeset
34 * @param text the text to display.
e298c4d28927 Improved mainvalues rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1085
diff changeset
35 * @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
36 */
e298c4d28927 Improved mainvalues rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1085
diff changeset
37 public StickyAxisAnnotation(String text, float pos) {
2161
c68f4f227c09 Somewhat unified Annotation handling, use jfreechart-house-toolkit instead of custom StickyAxisAnnotation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1962
diff changeset
38 this(text, pos, SimpleAxis.X_AXIS);
1089
e298c4d28927 Improved mainvalues rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1085
diff changeset
39 }
e298c4d28927 Improved mainvalues rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1085
diff changeset
40
e298c4d28927 Improved mainvalues rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1085
diff changeset
41
e298c4d28927 Improved mainvalues rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1085
diff changeset
42 /**
1085
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
43 * 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
44 * @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
45 * @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
46 * @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
47 * relative).
2161
c68f4f227c09 Somewhat unified Annotation handling, use jfreechart-house-toolkit instead of custom StickyAxisAnnotation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1962
diff changeset
48 * @param lineTo upto where to draw a line (NaN for none).
1085
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
49 */
2161
c68f4f227c09 Somewhat unified Annotation handling, use jfreechart-house-toolkit instead of custom StickyAxisAnnotation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1962
diff changeset
50 public StickyAxisAnnotation(String text, float pos, SimpleAxis stickAxis
c68f4f227c09 Somewhat unified Annotation handling, use jfreechart-house-toolkit instead of custom StickyAxisAnnotation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1962
diff changeset
51 ) {
1085
07878836ee0d Plot "real" (respecting parameters) W and Q MainValues, yet in wrong scale.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1082
diff changeset
52 setStickyAxis(stickAxis);
2161
c68f4f227c09 Somewhat unified Annotation handling, use jfreechart-house-toolkit instead of custom StickyAxisAnnotation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1962
diff changeset
53 this.text = text;
c68f4f227c09 Somewhat unified Annotation handling, use jfreechart-house-toolkit instead of custom StickyAxisAnnotation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1962
diff changeset
54 this.pos = pos;
1082
f16b66839e59 Prepare StickyAxisAnnotation implementation to handle annotations at 'y' (vertical) axis.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1042
diff changeset
55 }
f16b66839e59 Prepare StickyAxisAnnotation implementation to handle annotations at 'y' (vertical) axis.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1042
diff changeset
56
f16b66839e59 Prepare StickyAxisAnnotation implementation to handle annotations at 'y' (vertical) axis.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1042
diff changeset
57
1039
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
58 /**
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
59 * 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
60 * X- or the Y-Axis.
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
61 *
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
62 * @param stickyAxis axis to stick to.
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
63 */
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
64 public void setStickyAxis(SimpleAxis stickyAxis) {
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
65 this.stickyAxis = stickyAxis;
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
66 }
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
2161
c68f4f227c09 Somewhat unified Annotation handling, use jfreechart-house-toolkit instead of custom StickyAxisAnnotation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1962
diff changeset
69 public float getPos() {
c68f4f227c09 Somewhat unified Annotation handling, use jfreechart-house-toolkit instead of custom StickyAxisAnnotation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1962
diff changeset
70 return this.pos;
1039
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
71 }
1738
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
72
2161
c68f4f227c09 Somewhat unified Annotation handling, use jfreechart-house-toolkit instead of custom StickyAxisAnnotation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1962
diff changeset
73 public SimpleAxis getStickyAxis() {
c68f4f227c09 Somewhat unified Annotation handling, use jfreechart-house-toolkit instead of custom StickyAxisAnnotation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1962
diff changeset
74 return this.stickyAxis;
c68f4f227c09 Somewhat unified Annotation handling, use jfreechart-house-toolkit instead of custom StickyAxisAnnotation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1962
diff changeset
75 }
1738
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
76
2161
c68f4f227c09 Somewhat unified Annotation handling, use jfreechart-house-toolkit instead of custom StickyAxisAnnotation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1962
diff changeset
77 public boolean atX() {
c68f4f227c09 Somewhat unified Annotation handling, use jfreechart-house-toolkit instead of custom StickyAxisAnnotation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1962
diff changeset
78 return this.getStickyAxis() == SimpleAxis.X_AXIS;
c68f4f227c09 Somewhat unified Annotation handling, use jfreechart-house-toolkit instead of custom StickyAxisAnnotation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1962
diff changeset
79 }
c68f4f227c09 Somewhat unified Annotation handling, use jfreechart-house-toolkit instead of custom StickyAxisAnnotation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1962
diff changeset
80
c68f4f227c09 Somewhat unified Annotation handling, use jfreechart-house-toolkit instead of custom StickyAxisAnnotation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1962
diff changeset
81 public String getText() {
c68f4f227c09 Somewhat unified Annotation handling, use jfreechart-house-toolkit instead of custom StickyAxisAnnotation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1962
diff changeset
82 return this.text;
1738
6cdc7a77d3d4 Apply theme attributes to axis annotation.
Raimund Renkert <raimund.renkert@intevation.de>
parents: 1711
diff changeset
83 }
1039
cf39205df113 Part of refactoring (see next commit).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
84 }
1711
f708120cb7bc Fix flys/issue363 (W-INFO/ Abflusskurve, Extremwert-Rendering).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1167
diff changeset
85 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org