comparison flys-artifacts/src/main/java/de/intevation/flys/jfree/StickyAxisAnnotation.java @ 2793:6310b1582f2d

merged flys-artifacts/2.7
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:30 +0200
parents 5016609663e2
children 703be13ffa74
comparison
equal deleted inserted replaced
2548:ada02bbd3b7f 2793:6310b1582f2d
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 }
23
24 /** The "symbolic" integer representing which axis to stick to. */
25 protected int axisSymbol;
26
27 /** Which axis to stick to. */
28 protected SimpleAxis stickyAxis = SimpleAxis.X_AXIS;
29
30 /** The 1-dimensional position of this annotation. */
31 protected float pos;
32
33 /**
34 * Optional field used when from axis a line should be drawn that
35 * hits a curve or something similar (current scenario: duration curves).
36 * This value is in the "other" dimension than the pos - field.
37 */
38 protected float hitPoint;
39
40 /** The text to display at axis. */
41 String text;
42
43
44 /**
45 * Constructor with implicit sticky x-axis.
46 * @param text the text to display.
47 * @param pos the position at which to draw the text and mark.
48 */
49 public StickyAxisAnnotation(String text, float pos) {
50 this(text, pos, SimpleAxis.X_AXIS);
51 }
52
53
54 /**
55 * Constructor with given explicit axis.
56 * @param text the text to display.
57 * @param pos the position at which to draw the text and mark.
58 * @param stickyAxis the axis at which to stick (and to which 'pos' is
59 * relative).
60 * @param lineTo upto where to draw a line (NaN for none).
61 */
62 public StickyAxisAnnotation(String text, float pos, SimpleAxis stickAxis
63 ) {
64 this(text, pos, stickAxis, 0);
65 }
66
67
68 public StickyAxisAnnotation(String text, float pos, SimpleAxis stickAxis,
69 int axisSymbol
70 ) {
71 setStickyAxis(stickAxis);
72 this.text = text;
73 this.pos = pos;
74 this.axisSymbol = axisSymbol;
75 this.hitPoint = Float.NaN;
76 }
77
78
79 /**
80 * Sets the "sticky axis" (whether to draw annotations at the
81 * X- or the Y-Axis.
82 *
83 * @param stickyAxis axis to stick to.
84 */
85 public void setStickyAxis(SimpleAxis stickyAxis) {
86 this.stickyAxis = stickyAxis;
87 }
88
89
90 public float getPos() {
91 return this.pos;
92 }
93
94 public SimpleAxis getStickyAxis() {
95 return this.stickyAxis;
96 }
97
98 public boolean atX() {
99 return this.getStickyAxis() == SimpleAxis.X_AXIS;
100 }
101
102 /** Get text to be displayed at axis. */
103 public String getText() {
104 return this.text;
105 }
106
107
108 public int getAxisSymbol() {
109 return this.axisSymbol;
110 }
111
112
113 /** Set where to hit a curve (if any). */
114 public void setHitPoint(float pos) {
115 this.hitPoint = pos;
116 }
117
118 /** Get where to hit a curve (if any). */
119 public float getHitPoint() {
120 return this.hitPoint;
121 }
122
123 /** Set sticky axis to the X axis if it is currently Y, and vice versa. */
124 public void flipStickyAxis() {
125 if (this.getStickyAxis() == SimpleAxis.X_AXIS) {
126 this.setStickyAxis(SimpleAxis.Y_AXIS);
127 }
128 else {
129 this.setStickyAxis(SimpleAxis.X_AXIS);
130 }
131 }
132 }
133 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org