diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/StickyAxisAnnotation.java	Fri Sep 28 12:14:26 2012 +0200
@@ -0,0 +1,99 @@
+package de.intevation.flys.jfree;
+
+import org.apache.log4j.Logger;
+
+
+/**
+ * Custom Annotations class that is drawn only if no collisions with other
+ * already drawn CustomAnnotations in current plot are found. A mark on
+ * the axis is shown in all cases, though.
+ * Draws a given text and a line to it from either axis.
+ */
+public class StickyAxisAnnotation {
+
+    /** Logger for this class. */    
+    private static Logger logger =
+        Logger.getLogger(StickyAxisAnnotation.class);
+
+    /** Simplified view on axes. */
+    public static enum SimpleAxis {
+        X_AXIS, /** Usually "horizontal". */
+        Y_AXIS  /** Usually "vertical". */
+    }
+
+    /** The "symbolic" integer representing which axis to stick to. */
+    protected int axisSymbol;
+
+    /** Which axis to stick to. */
+    protected SimpleAxis stickyAxis = SimpleAxis.X_AXIS;
+
+    /** The 1-dimensional position of this annotation. */
+    protected float pos;
+
+    String text;
+
+    /**
+     * Constructor with implicit sticky x-axis.
+     * @param text       the text to display.
+     * @param pos        the position at which to draw the text and mark.
+     */
+    public StickyAxisAnnotation(String text, float pos) {
+        this(text, pos, SimpleAxis.X_AXIS);
+    }
+
+
+    /**
+     * Constructor with given explicit axis.
+     * @param text       the text to display.
+     * @param pos        the position at which to draw the text and mark.
+     * @param stickyAxis the axis at which to stick (and to which 'pos' is
+     *                   relative).
+     * @param lineTo     upto where to draw a line (NaN for none).
+     */
+    public StickyAxisAnnotation(String text, float pos, SimpleAxis stickAxis
+    ) {
+        this(text, pos, stickAxis, 0);
+    }
+
+    public StickyAxisAnnotation(String text, float pos, SimpleAxis stickAxis,
+            int axisSymbol
+    ) {
+        setStickyAxis(stickAxis);
+        this.text   = text;
+        this.pos    = pos;
+        this.axisSymbol = axisSymbol;
+    }
+
+
+    /**
+     * Sets the "sticky axis" (whether to draw annotations at the
+     * X- or the Y-Axis.
+     *
+     * @param stickyAxis axis to stick to.
+     */
+    public void setStickyAxis(SimpleAxis stickyAxis) {
+        this.stickyAxis = stickyAxis;
+    }
+
+
+    public float getPos() {
+        return this.pos;
+    }
+
+    public SimpleAxis getStickyAxis() {
+        return this.stickyAxis;
+    }
+
+    public boolean atX() {
+        return this.getStickyAxis() == SimpleAxis.X_AXIS;
+    }
+
+    public String getText() {
+        return this.text;
+    }
+
+    public int getAxisSymbol() {
+        return this.axisSymbol;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org