Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/jfree/StickyAxisAnnotation.java @ 5838:5aa05a7a34b7
Rename modules to more fitting names.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 15:23:37 +0200 |
parents | flys-artifacts/src/main/java/org/dive4elements/river/jfree/StickyAxisAnnotation.java@bd047b71ab37 |
children | 4897a58c8746 |
comparison
equal
deleted
inserted
replaced
5837:d9901a08d0a6 | 5838:5aa05a7a34b7 |
---|---|
1 package org.dive4elements.river.jfree; | |
2 | |
3 /** | |
4 * Text, position on axis, and maybe a hit-point in a class. | |
5 * | |
6 * Idea is to draw a given text and a line to it from either axis. | |
7 * This class just keeps the info. | |
8 */ | |
9 public class StickyAxisAnnotation { | |
10 | |
11 /** Simplified view on axes. */ | |
12 public static enum SimpleAxis { | |
13 X_AXIS, /** Usually "horizontal". */ | |
14 Y_AXIS, /** Usually "vertical". */ | |
15 Y_AXIS2 | |
16 } | |
17 | |
18 /** The "symbolic" integer representing which axis to stick to. */ | |
19 protected int axisSymbol; | |
20 | |
21 /** Which axis to stick to. */ | |
22 protected SimpleAxis stickyAxis = SimpleAxis.X_AXIS; | |
23 | |
24 /** The 1-dimensional position of this annotation. */ | |
25 protected float pos; | |
26 | |
27 /** | |
28 * Optional field used when from axis a line should be drawn that | |
29 * hits a curve or something similar (current scenario: duration curves). | |
30 * This value is in the "other" dimension than the pos - field. | |
31 */ | |
32 protected float hitPoint; | |
33 | |
34 /** The text to display at axis. */ | |
35 String text; | |
36 | |
37 | |
38 /** | |
39 * Constructor with implicit sticky x-axis. | |
40 * @param text the text to display. | |
41 * @param pos the position at which to draw the text and mark. | |
42 */ | |
43 public StickyAxisAnnotation(String text, float pos) { | |
44 this(text, pos, SimpleAxis.X_AXIS); | |
45 } | |
46 | |
47 | |
48 /** | |
49 * Constructor with given explicit axis. | |
50 * @param text the text to display. | |
51 * @param pos the position at which to draw the text and mark. | |
52 * @param stickAxis the axis at which to stick (and to which 'pos' is | |
53 * relative). | |
54 */ | |
55 public StickyAxisAnnotation(String text, float pos, SimpleAxis stickAxis | |
56 ) { | |
57 this(text, pos, stickAxis, 0); | |
58 } | |
59 | |
60 | |
61 /** | |
62 * Constructor with given explicit axis and axisSymbol | |
63 * @param text the text to display. | |
64 * @param pos the position at which to draw the text and mark. | |
65 * @param stickAxis the axis at which to stick (and to which 'pos' is | |
66 * relative). | |
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 : |