Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/jfree/StickyAxisAnnotation.java @ 1751:27b8836abec9
Draw the text background and use orientation attribute.
flys-artifacts/trunk@3053 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Fri, 21 Oct 2011 08:21:45 +0000 |
parents | 6cdc7a77d3d4 |
children | b7b424ae32a8 |
comparison
equal
deleted
inserted
replaced
1750:415ec0223dff | 1751:27b8836abec9 |
---|---|
58 /** Theme attributes. */ | 58 /** Theme attributes. */ |
59 protected Color textColor; | 59 protected Color textColor; |
60 protected Color lineColor; | 60 protected Color lineColor; |
61 protected Font font; | 61 protected Font font; |
62 protected int lineWidth; | 62 protected int lineWidth; |
63 protected String textOrientation = "vertical"; | |
64 protected Color textBackground; | |
65 protected boolean showBackground; | |
63 | 66 |
64 | 67 |
65 /** | 68 /** |
66 * Trivial constructor. | 69 * Trivial constructor. |
67 * | 70 * |
117 * | 120 * |
118 * @param stickyAxis axis to stick to. | 121 * @param stickyAxis axis to stick to. |
119 */ | 122 */ |
120 public void setStickyAxis(SimpleAxis stickyAxis) { | 123 public void setStickyAxis(SimpleAxis stickyAxis) { |
121 this.stickyAxis = stickyAxis; | 124 this.stickyAxis = stickyAxis; |
122 if (stickyAxis == SimpleAxis.X_AXIS) { | 125 if (stickyAxis == SimpleAxis.X_AXIS){ |
123 this.setRotationAngle(270f * (Math.PI / 180f)); | 126 float o = 270f; |
127 if(textOrientation.equals("horizontal")) { | |
128 o = 0f; | |
129 } | |
130 logger.debug("orientation: " + o); | |
131 this.setRotationAngle(o * (Math.PI / 180f)); | |
124 this.setRotationAnchor(TextAnchor.CENTER_LEFT); | 132 this.setRotationAnchor(TextAnchor.CENTER_LEFT); |
125 this.setTextAnchor(TextAnchor.CENTER_LEFT); | 133 this.setTextAnchor(TextAnchor.CENTER_LEFT); |
126 } else { | 134 } else { |
127 this.setRotationAngle(0f * (Math.PI / 180f)); | 135 this.setRotationAngle(0f * (Math.PI / 180f)); |
128 this.setRotationAnchor(TextAnchor.CENTER_LEFT); | 136 this.setRotationAnchor(TextAnchor.CENTER_LEFT); |
286 float tempAnchor = anchorX; | 294 float tempAnchor = anchorX; |
287 anchorX = anchorY; | 295 anchorX = anchorY; |
288 anchorY = tempAnchor; | 296 anchorY = tempAnchor; |
289 } | 297 } |
290 | 298 |
291 // Always draw the small line at axis. | 299 //Call to apply orientation. |
292 setOutlineStroke(new BasicStroke((float) lineWidth)); | 300 setStickyAxis(stickyAxis); |
293 g2.setStroke(getOutlineStroke()); | 301 |
294 g2.setPaint(lineColor); | |
295 drawAxisMark(g2, dataArea, domainAxis, rangeAxis, domainEdge, | |
296 rangeEdge, orientation); | |
297 | |
298 g2.setPaint(textColor); | |
299 g2.setFont(font); | |
300 Shape hotspot = TextUtilities.calculateRotatedStringBounds( | 302 Shape hotspot = TextUtilities.calculateRotatedStringBounds( |
301 getText(), g2, anchorX, anchorY, getTextAnchor(), | 303 getText(), g2, anchorX, anchorY, getTextAnchor(), |
302 getRotationAngle(), getRotationAnchor()); | 304 getRotationAngle(), getRotationAnchor()); |
303 Rectangle2D hotspotBox = hotspot.getBounds2D(); | 305 Rectangle2D hotspotBox = hotspot.getBounds2D(); |
304 // Check for collisions with other XYAnnotations. | 306 // Check for collisions with other XYAnnotations. |
313 return; | 315 return; |
314 } | 316 } |
315 } | 317 } |
316 } | 318 } |
317 | 319 |
318 // Actuall drawing. | 320 // Draw the background. |
319 if (getBackgroundPaint() != null) { | 321 if (showBackground) { |
320 g2.setPaint(getBackgroundPaint()); | 322 g2.setStroke(new BasicStroke ((float) 1)); |
323 g2.setBackground(textBackground); | |
324 g2.setPaint(textBackground); | |
325 hotspot = TextUtilities.calculateRotatedStringBounds( | |
326 getText(), g2, anchorX, anchorY, getTextAnchor(), | |
327 getRotationAngle(), getRotationAnchor()); | |
321 g2.fill(hotspot); | 328 g2.fill(hotspot); |
322 } | 329 g2.draw(hotspot); |
330 } | |
331 | |
332 // Always draw the small line at axis. | |
333 setOutlineStroke(new BasicStroke((float) lineWidth)); | |
334 g2.setStroke(getOutlineStroke()); | |
335 g2.setPaint(lineColor); | |
336 drawAxisMark(g2, dataArea, domainAxis, rangeAxis, domainEdge, | |
337 rangeEdge, orientation); | |
338 | |
339 // Draw the text. | |
340 g2.setPaint(textColor); | |
341 g2.setFont(font); | |
323 TextUtilities.drawRotatedString(getText(), g2, anchorX, anchorY, | 342 TextUtilities.drawRotatedString(getText(), g2, anchorX, anchorY, |
324 getTextAnchor(), getRotationAngle(), getRotationAnchor()); | 343 getTextAnchor(), getRotationAngle(), getRotationAnchor()); |
325 // Draw outline. | |
326 if (false) { | |
327 g2.setStroke(getOutlineStroke()); | |
328 g2.setPaint(getOutlinePaint()); | |
329 g2.draw(hotspot); | |
330 } | |
331 | 344 |
332 // Add info that we have drawn this Annotation. | 345 // Add info that we have drawn this Annotation. |
333 addEntity(info, hotspot, rendererIndex, getToolTipText(), getURL()); | 346 addEntity(info, hotspot, rendererIndex, getToolTipText(), getURL()); |
334 } | 347 } |
335 | 348 |
337 public void applyTheme(Document theme) { | 350 public void applyTheme(Document theme) { |
338 lineWidth = ThemeUtil.parseLineWidth(theme); | 351 lineWidth = ThemeUtil.parseLineWidth(theme); |
339 lineColor = ThemeUtil.parseLineColorField(theme); | 352 lineColor = ThemeUtil.parseLineColorField(theme); |
340 textColor = ThemeUtil.parseTextColor(theme); | 353 textColor = ThemeUtil.parseTextColor(theme); |
341 font = ThemeUtil.parseTextFont(theme); | 354 font = ThemeUtil.parseTextFont(theme); |
355 textOrientation = ThemeUtil.parseTextOrientation(theme); | |
356 textBackground = ThemeUtil.parseTextBackground(theme); | |
357 showBackground = ThemeUtil.parseShowTextBackground(theme); | |
342 } | 358 } |
343 } | 359 } |
344 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 360 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |