comparison flys-artifacts/src/main/java/de/intevation/flys/jfree/StickyAxisAnnotation.java @ 3468:f37e7e8907cb

merged flys-artifacts/2.8.1
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:39 +0200
parents d9af29a4bb85
children 6ed8ebd48d6e
comparison
equal deleted inserted replaced
3387:5ffad8bde8ad 3468:f37e7e8907cb
1 package de.intevation.flys.jfree;
2
3 import org.apache.log4j.Logger;
4
5
6 /**
7 * Custom Annotations class that is drawn only if no collisions with other
8 * already drawn CustomAnnotations in current plot are found. A mark on
9 * the axis is shown in all cases, though.
10 * Draws a given text and a line to it from either axis.
11 */
12 public class StickyAxisAnnotation {
13
14 /** Logger for this class. */
15 private static Logger logger =
16 Logger.getLogger(StickyAxisAnnotation.class);
17
18 /** Simplified view on axes. */
19 public static enum SimpleAxis {
20 X_AXIS, /** Usually "horizontal". */
21 Y_AXIS, /** Usually "vertical". */
22 Y_AXIS2
23 }
24
25 /** The "symbolic" integer representing which axis to stick to. */
26 protected int axisSymbol;
27
28 /** Which axis to stick to. */
29 protected SimpleAxis stickyAxis = SimpleAxis.X_AXIS;
30
31 /** The 1-dimensional position of this annotation. */
32 protected float pos;
33
34 /**
35 * Optional field used when from axis a line should be drawn that
36 * hits a curve or something similar (current scenario: duration curves).
37 * This value is in the "other" dimension than the pos - field.
38 */
39 protected float hitPoint;
40
41 /** The text to display at axis. */
42 String text;
43
44
45 /**
46 * Constructor with implicit sticky x-axis.
47 * @param text the text to display.
48 * @param pos the position at which to draw the text and mark.
49 */
50 public StickyAxisAnnotation(String text, float pos) {
51 this(text, pos, SimpleAxis.X_AXIS);
52 }
53
54
55 /**
56 * Constructor with given explicit axis.
57 * @param text the text to display.
58 * @param pos the position at which to draw the text and mark.
59 * @param stickAxis the axis at which to stick (and to which 'pos' is
60 * relative).
61 */
62 public StickyAxisAnnotation(String text, float pos, SimpleAxis stickAxis
63 ) {
64 this(text, pos, stickAxis, 0);
65 }
66
67
68 /**
69 * Constructor with given explicit axis and axisSymbol
70 * @param text the text to display.
71 * @param pos the position at which to draw the text and mark.
72 * @param stickAxis the axis at which to stick (and to which 'pos' is
73 * relative).
74 */
75 public StickyAxisAnnotation(String text, float pos, SimpleAxis stickAxis,
76 int axisSymbol
77 ) {
78 setStickyAxis(stickAxis);
79 this.text = text;
80 this.pos = pos;
81 this.axisSymbol = axisSymbol;
82 this.hitPoint = Float.NaN;
83 }
84
85
86 /**
87 * Sets the "sticky axis" (whether to draw annotations at the
88 * X- or the Y-Axis.
89 *
90 * @param stickyAxis axis to stick to.
91 */
92 public void setStickyAxis(SimpleAxis stickyAxis) {
93 this.stickyAxis = stickyAxis;
94 }
95
96
97 public float getPos() {
98 return this.pos;
99 }
100
101 public SimpleAxis getStickyAxis() {
102 return this.stickyAxis;
103 }
104
105 public boolean atX() {
106 return this.getStickyAxis() == SimpleAxis.X_AXIS;
107 }
108
109 /** Get text to be displayed at axis. */
110 public String getText() {
111 return this.text;
112 }
113
114
115 public int getAxisSymbol() {
116 return this.axisSymbol;
117 }
118
119
120 /** Set where to hit a curve (if any). */
121 public void setHitPoint(float pos) {
122 this.hitPoint = pos;
123 }
124
125 /** Get where to hit a curve (if any). */
126 public float getHitPoint() {
127 return this.hitPoint;
128 }
129
130 /** Set sticky axis to the X axis if it is currently Y, and vice versa. */
131 public void flipStickyAxis() {
132 if (this.getStickyAxis() == SimpleAxis.X_AXIS) {
133 this.setStickyAxis(SimpleAxis.Y_AXIS);
134 }
135 else {
136 this.setStickyAxis(SimpleAxis.X_AXIS);
137 }
138 }
139 }
140 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org