felix@1039: package de.intevation.flys.jfree; felix@1039: felix@1039: import org.apache.log4j.Logger; felix@1039: felix@1039: felix@1039: /** felix@1039: * Custom Annotations class that is drawn only if no collisions with other felix@1759: * already drawn CustomAnnotations in current plot are found. A mark on felix@1759: * the axis is shown in all cases, though. felix@1039: * Draws a given text and a line to it from either axis. felix@1039: */ felix@2161: public class StickyAxisAnnotation { felix@1039: sascha@3076: /** Logger for this class. */ felix@1039: private static Logger logger = felix@1039: Logger.getLogger(StickyAxisAnnotation.class); felix@1039: felix@1039: /** Simplified view on axes. */ felix@1039: public static enum SimpleAxis { felix@1039: X_AXIS, /** Usually "horizontal". */ felix@2999: Y_AXIS, /** Usually "vertical". */ felix@2999: Y_AXIS2 felix@1039: } felix@1039: felix@2163: /** The "symbolic" integer representing which axis to stick to. */ felix@2163: protected int axisSymbol; felix@2163: felix@1039: /** Which axis to stick to. */ felix@1039: protected SimpleAxis stickyAxis = SimpleAxis.X_AXIS; felix@1039: felix@1085: /** The 1-dimensional position of this annotation. */ felix@1085: protected float pos; felix@1085: felix@2775: /** felix@2775: * Optional field used when from axis a line should be drawn that felix@2775: * hits a curve or something similar (current scenario: duration curves). felix@2775: * This value is in the "other" dimension than the pos - field. felix@2775: */ felix@2775: protected float hitPoint; felix@2775: felix@2775: /** The text to display at axis. */ felix@2161: String text; felix@1085: felix@2775: felix@1085: /** felix@1089: * Constructor with implicit sticky x-axis. felix@3269: * @param text the text to display. felix@3269: * @param pos the position at which to draw the text and mark. felix@1089: */ felix@1089: public StickyAxisAnnotation(String text, float pos) { felix@2161: this(text, pos, SimpleAxis.X_AXIS); felix@1089: } felix@1089: felix@1089: felix@1089: /** felix@1085: * Constructor with given explicit axis. felix@1085: * @param text the text to display. felix@1085: * @param pos the position at which to draw the text and mark. felix@3269: * @param stickAxis the axis at which to stick (and to which 'pos' is felix@1085: * relative). felix@2161: * @param lineTo upto where to draw a line (NaN for none). felix@1085: */ felix@2161: public StickyAxisAnnotation(String text, float pos, SimpleAxis stickAxis felix@2161: ) { felix@2163: this(text, pos, stickAxis, 0); felix@2163: } felix@2163: felix@2775: felix@2163: public StickyAxisAnnotation(String text, float pos, SimpleAxis stickAxis, felix@2163: int axisSymbol felix@2163: ) { felix@1085: setStickyAxis(stickAxis); felix@2161: this.text = text; felix@2161: this.pos = pos; felix@2163: this.axisSymbol = axisSymbol; felix@2775: this.hitPoint = Float.NaN; felix@1082: } felix@1082: felix@1082: felix@1039: /** felix@1039: * Sets the "sticky axis" (whether to draw annotations at the felix@1039: * X- or the Y-Axis. felix@1039: * felix@1039: * @param stickyAxis axis to stick to. felix@1039: */ felix@1039: public void setStickyAxis(SimpleAxis stickyAxis) { felix@1039: this.stickyAxis = stickyAxis; felix@1039: } felix@1039: felix@1039: felix@2161: public float getPos() { felix@2161: return this.pos; felix@1039: } raimund@1738: felix@2161: public SimpleAxis getStickyAxis() { felix@2161: return this.stickyAxis; felix@2161: } raimund@1738: felix@2161: public boolean atX() { felix@2161: return this.getStickyAxis() == SimpleAxis.X_AXIS; felix@2161: } felix@2161: felix@2775: /** Get text to be displayed at axis. */ felix@2161: public String getText() { felix@2161: return this.text; raimund@1738: } felix@2163: felix@2775: felix@2163: public int getAxisSymbol() { felix@2163: return this.axisSymbol; felix@2163: } felix@2766: felix@2775: felix@2775: /** Set where to hit a curve (if any). */ felix@2775: public void setHitPoint(float pos) { felix@2775: this.hitPoint = pos; felix@2775: } felix@2775: felix@2775: /** Get where to hit a curve (if any). */ felix@2775: public float getHitPoint() { felix@2775: return this.hitPoint; felix@2775: } felix@2775: felix@2766: /** Set sticky axis to the X axis if it is currently Y, and vice versa. */ felix@2766: public void flipStickyAxis() { felix@2766: if (this.getStickyAxis() == SimpleAxis.X_AXIS) { felix@2766: this.setStickyAxis(SimpleAxis.Y_AXIS); felix@2766: } felix@2766: else { felix@2766: this.setStickyAxis(SimpleAxis.X_AXIS); felix@2766: } felix@2766: } felix@1039: } felix@1711: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :