comparison flys-artifacts/src/main/java/de/intevation/flys/jfree/StickyAxisAnnotation.java @ 1738:6cdc7a77d3d4

Apply theme attributes to axis annotation. flys-artifacts/trunk@3028 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Wed, 19 Oct 2011 11:39:46 +0000
parents f708120cb7bc
children 27b8836abec9
comparison
equal deleted inserted replaced
1737:d26911cac2e4 1738:6cdc7a77d3d4
1 package de.intevation.flys.jfree; 1 package de.intevation.flys.jfree;
2 2
3 import org.apache.log4j.Logger; 3 import org.apache.log4j.Logger;
4 4
5 import java.util.Iterator; 5 import java.util.Iterator;
6
7 import org.w3c.dom.Document;
6 8
7 import java.awt.Shape; 9 import java.awt.Shape;
8 import java.awt.geom.Rectangle2D; 10 import java.awt.geom.Rectangle2D;
9 import java.awt.geom.Line2D; 11 import java.awt.geom.Line2D;
12 import java.awt.Color;
13 import java.awt.Font;
14 import java.awt.BasicStroke;
10 15
11 import org.jfree.chart.annotations.XYTextAnnotation; 16 import org.jfree.chart.annotations.XYTextAnnotation;
12 import org.jfree.chart.axis.ValueAxis; 17 import org.jfree.chart.axis.ValueAxis;
13 import org.jfree.chart.util.LineUtilities; 18 import org.jfree.chart.util.LineUtilities;
14 import org.jfree.chart.plot.PlotOrientation; 19 import org.jfree.chart.plot.PlotOrientation;
23 import org.jfree.text.TextUtilities; 28 import org.jfree.text.TextUtilities;
24 29
25 import org.jfree.ui.RectangleEdge; 30 import org.jfree.ui.RectangleEdge;
26 import org.jfree.ui.TextAnchor; 31 import org.jfree.ui.TextAnchor;
27 32
33 import de.intevation.flys.utils.ThemeUtil;
28 34
29 /** 35 /**
30 * Custom Annotations class that is drawn only if no collisions with other 36 * Custom Annotations class that is drawn only if no collisions with other
31 * already drawn CustomAnnotations in current plot are found. 37 * already drawn CustomAnnotations in current plot are found.
32 * Draws a given text and a line to it from either axis. 38 * Draws a given text and a line to it from either axis.
46 /** Which axis to stick to. */ 52 /** Which axis to stick to. */
47 protected SimpleAxis stickyAxis = SimpleAxis.X_AXIS; 53 protected SimpleAxis stickyAxis = SimpleAxis.X_AXIS;
48 54
49 /** The 1-dimensional position of this annotation. */ 55 /** The 1-dimensional position of this annotation. */
50 protected float pos; 56 protected float pos;
57
58 /** Theme attributes. */
59 protected Color textColor;
60 protected Color lineColor;
61 protected Font font;
62 protected int lineWidth;
51 63
52 64
53 /** 65 /**
54 * Trivial constructor. 66 * Trivial constructor.
55 * 67 *
275 anchorX = anchorY; 287 anchorX = anchorY;
276 anchorY = tempAnchor; 288 anchorY = tempAnchor;
277 } 289 }
278 290
279 // Always draw the small line at axis. 291 // Always draw the small line at axis.
292 setOutlineStroke(new BasicStroke((float) lineWidth));
280 g2.setStroke(getOutlineStroke()); 293 g2.setStroke(getOutlineStroke());
281 g2.setPaint(getPaint()); 294 g2.setPaint(lineColor);
282 drawAxisMark(g2, dataArea, domainAxis, rangeAxis, domainEdge, 295 drawAxisMark(g2, dataArea, domainAxis, rangeAxis, domainEdge,
283 rangeEdge, orientation); 296 rangeEdge, orientation);
284 297
285 g2.setFont(getFont()); 298 g2.setPaint(textColor);
299 g2.setFont(font);
286 Shape hotspot = TextUtilities.calculateRotatedStringBounds( 300 Shape hotspot = TextUtilities.calculateRotatedStringBounds(
287 getText(), g2, anchorX, anchorY, getTextAnchor(), 301 getText(), g2, anchorX, anchorY, getTextAnchor(),
288 getRotationAngle(), getRotationAnchor()); 302 getRotationAngle(), getRotationAnchor());
289 Rectangle2D hotspotBox = hotspot.getBounds2D(); 303 Rectangle2D hotspotBox = hotspot.getBounds2D();
290 // Check for collisions with other XYAnnotations. 304 // Check for collisions with other XYAnnotations.
304 // Actuall drawing. 318 // Actuall drawing.
305 if (getBackgroundPaint() != null) { 319 if (getBackgroundPaint() != null) {
306 g2.setPaint(getBackgroundPaint()); 320 g2.setPaint(getBackgroundPaint());
307 g2.fill(hotspot); 321 g2.fill(hotspot);
308 } 322 }
309 g2.setPaint(getPaint());
310 TextUtilities.drawRotatedString(getText(), g2, anchorX, anchorY, 323 TextUtilities.drawRotatedString(getText(), g2, anchorX, anchorY,
311 getTextAnchor(), getRotationAngle(), getRotationAnchor()); 324 getTextAnchor(), getRotationAngle(), getRotationAnchor());
312 // Draw outline. 325 // Draw outline.
313 if (false) { 326 if (false) {
314 g2.setStroke(getOutlineStroke()); 327 g2.setStroke(getOutlineStroke());
317 } 330 }
318 331
319 // Add info that we have drawn this Annotation. 332 // Add info that we have drawn this Annotation.
320 addEntity(info, hotspot, rendererIndex, getToolTipText(), getURL()); 333 addEntity(info, hotspot, rendererIndex, getToolTipText(), getURL());
321 } 334 }
335
336
337 public void applyTheme(Document theme) {
338 lineWidth = ThemeUtil.parseLineWidth(theme);
339 lineColor = ThemeUtil.parseLineColorField(theme);
340 textColor = ThemeUtil.parseTextColor(theme);
341 font = ThemeUtil.parseTextFont(theme);
342 }
322 } 343 }
323 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 344 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org