comparison flys-artifacts/src/main/java/de/intevation/flys/jfree/StickyAxisAnnotation.java @ 2424:092e519ff461

merged flys-artifacts/2.6.1
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:26 +0200
parents 105097966111
children 7dc4681a2bed
comparison
equal deleted inserted replaced
2392:8112ec686a9a 2424:092e519ff461
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 String text;
34
35 /**
36 * Constructor with implicit sticky x-axis.
37 * @param text the text to display.
38 * @param pos the position at which to draw the text and mark.
39 */
40 public StickyAxisAnnotation(String text, float pos) {
41 this(text, pos, SimpleAxis.X_AXIS);
42 }
43
44
45 /**
46 * Constructor with given explicit axis.
47 * @param text the text to display.
48 * @param pos the position at which to draw the text and mark.
49 * @param stickyAxis the axis at which to stick (and to which 'pos' is
50 * relative).
51 * @param lineTo upto where to draw a line (NaN for none).
52 */
53 public StickyAxisAnnotation(String text, float pos, SimpleAxis stickAxis
54 ) {
55 this(text, pos, stickAxis, 0);
56 }
57
58 public StickyAxisAnnotation(String text, float pos, SimpleAxis stickAxis,
59 int axisSymbol
60 ) {
61 setStickyAxis(stickAxis);
62 this.text = text;
63 this.pos = pos;
64 this.axisSymbol = axisSymbol;
65 }
66
67
68 /**
69 * Sets the "sticky axis" (whether to draw annotations at the
70 * X- or the Y-Axis.
71 *
72 * @param stickyAxis axis to stick to.
73 */
74 public void setStickyAxis(SimpleAxis stickyAxis) {
75 this.stickyAxis = stickyAxis;
76 }
77
78
79 public float getPos() {
80 return this.pos;
81 }
82
83 public SimpleAxis getStickyAxis() {
84 return this.stickyAxis;
85 }
86
87 public boolean atX() {
88 return this.getStickyAxis() == SimpleAxis.X_AXIS;
89 }
90
91 public String getText() {
92 return this.text;
93 }
94
95 public int getAxisSymbol() {
96 return this.axisSymbol;
97 }
98 }
99 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org