Mercurial > dive4elements > river
changeset 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 | d26911cac2e4 |
children | 980d880c583c |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java flys-artifacts/src/main/java/de/intevation/flys/jfree/StickyAxisAnnotation.java flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java |
diffstat | 4 files changed, 105 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Wed Oct 19 11:00:13 2011 +0000 +++ b/flys-artifacts/ChangeLog Wed Oct 19 11:39:46 2011 +0000 @@ -1,3 +1,12 @@ +2011-10-19 Raimund Renkert <raimund.renkert@intevation.de> + + * src/main/java/de/intevation/flys/utils/ThemeUtil.java: + Added methods to parse text attributes from theme document. + + * src/main/java/de/intevation/flys/exports/XYChartGenerator.java, + src/main/java/de/intevation/flys/jfree/StickyAxisAnnotation.java: + Apply a theme to axis annotations. + 2011-10-19 Felix Wolfsteller <felix.wolfsteller@intevation.de> Create (data) Label from data string (client will be adjusted to send
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java Wed Oct 19 11:00:13 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java Wed Oct 19 11:39:46 2011 +0000 @@ -37,6 +37,7 @@ import de.intevation.flys.exports.ChartExportHelper; import de.intevation.flys.jfree.FLYSAnnotation; import de.intevation.flys.utils.ThemeUtil; +import de.intevation.flys.jfree.StickyAxisAnnotation; /** @@ -460,9 +461,16 @@ lic.add(new LegendItem(fa.getLabel(), color)); for (XYTextAnnotation ta: fa.getAnnotations()) { - ta.setPaint(color); - ta.setOutlineStroke(new BasicStroke((float) lineWidth)); - renderer.addAnnotation(ta); + if(ta instanceof StickyAxisAnnotation) { + StickyAxisAnnotation sta = (StickyAxisAnnotation)ta; + sta.applyTheme(theme); + renderer.addAnnotation(sta); + } + else { + ta.setPaint(color); + ta.setOutlineStroke(new BasicStroke((float) lineWidth)); + renderer.addAnnotation(ta); + } } plot.setFixedLegendItems(lic);
--- a/flys-artifacts/src/main/java/de/intevation/flys/jfree/StickyAxisAnnotation.java Wed Oct 19 11:00:13 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/StickyAxisAnnotation.java Wed Oct 19 11:39:46 2011 +0000 @@ -4,9 +4,14 @@ import java.util.Iterator; +import org.w3c.dom.Document; + import java.awt.Shape; import java.awt.geom.Rectangle2D; import java.awt.geom.Line2D; +import java.awt.Color; +import java.awt.Font; +import java.awt.BasicStroke; import org.jfree.chart.annotations.XYTextAnnotation; import org.jfree.chart.axis.ValueAxis; @@ -25,6 +30,7 @@ import org.jfree.ui.RectangleEdge; import org.jfree.ui.TextAnchor; +import de.intevation.flys.utils.ThemeUtil; /** * Custom Annotations class that is drawn only if no collisions with other @@ -49,6 +55,12 @@ /** The 1-dimensional position of this annotation. */ protected float pos; + /** Theme attributes. */ + protected Color textColor; + protected Color lineColor; + protected Font font; + protected int lineWidth; + /** * Trivial constructor. @@ -277,12 +289,14 @@ } // Always draw the small line at axis. + setOutlineStroke(new BasicStroke((float) lineWidth)); g2.setStroke(getOutlineStroke()); - g2.setPaint(getPaint()); + g2.setPaint(lineColor); drawAxisMark(g2, dataArea, domainAxis, rangeAxis, domainEdge, rangeEdge, orientation); - g2.setFont(getFont()); + g2.setPaint(textColor); + g2.setFont(font); Shape hotspot = TextUtilities.calculateRotatedStringBounds( getText(), g2, anchorX, anchorY, getTextAnchor(), getRotationAngle(), getRotationAnchor()); @@ -306,7 +320,6 @@ g2.setPaint(getBackgroundPaint()); g2.fill(hotspot); } - g2.setPaint(getPaint()); TextUtilities.drawRotatedString(getText(), g2, anchorX, anchorY, getTextAnchor(), getRotationAngle(), getRotationAnchor()); // Draw outline. @@ -319,5 +332,13 @@ // Add info that we have drawn this Annotation. addEntity(info, hotspot, rendererIndex, getToolTipText(), getURL()); } + + + public void applyTheme(Document theme) { + lineWidth = ThemeUtil.parseLineWidth(theme); + lineColor = ThemeUtil.parseLineColorField(theme); + textColor = ThemeUtil.parseTextColor(theme); + font = ThemeUtil.parseTextFont(theme); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java Wed Oct 19 11:00:13 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java Wed Oct 19 11:39:46 2011 +0000 @@ -1,6 +1,9 @@ package de.intevation.flys.utils; +import org.apache.log4j.Logger; + import java.awt.Color; +import java.awt.Font; import org.w3c.dom.Document; @@ -11,12 +14,24 @@ * Utility to deal with themes and their representations. */ public class ThemeUtil { + + private static Logger logger = + Logger.getLogger(ThemeUtil.class); + public final static String XPATH_LINE_COLOR = "/theme/field[@name='linecolor']/@default"; public static final String XPATH_LINE_SIZE = "/theme/field[@name='linesize']/@default"; + public final static String XPATH_TEXT_COLOR = + "/theme/field[@name='textcolor']/@default"; + + public final static String XPATH_TEXT_SIZE = + "/theme/field[@name='textsize']/@default"; + + public final static String XPATH_TEXT_FONT = + "/theme/field[@name='font']/@default"; /** * Parses line width, defaulting to 0. @@ -39,11 +54,57 @@ /** + * Parses text size, defaulting to 10. + * @param theme The theme. + */ + public static int parseTextSize(Document theme) { + String size = XMLUtils.xpathString(theme, XPATH_TEXT_SIZE, null); + if (size == null || size.length() == 0) { + return 10; + } + + try { + return Integer.valueOf(size); + } + catch (NumberFormatException nfe) { + } + return 10; + } + + + /** + * Parses text color. + * @param theme The theme. + */ + public static Color parseTextColor(Document theme) { + String color = XMLUtils.xpathString(theme, XPATH_TEXT_COLOR, null); + return parseRGB(color); + } + + + /** + * Parses the font. + * @param theme The theme. + */ + public static Font parseTextFont(Document theme) { + String font = XMLUtils.xpathString(theme, XPATH_TEXT_FONT, null); + if (font == null || font.length() == 0) { + return null; + } + + int size = parseTextSize(theme); + Font f = new Font (font, 0, size); + return f; + } + + + /** * Parse a string like "103, 100, 0" and return a corresping color. * @param rgbtext Color as string representation, e.g. "255,0,20". * @return Color, null in case of issues. */ public static Color parseRGB(String rgbtext) { + logger.debug("parseColor: " + rgbtext); if (rgbtext == null) { return null; }