Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/exports/StyledXYSeries.java @ 3814:8083f6384023
merged flys-artifacts/pre2.6-2012-01-04
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:56 +0200 |
parents | e384d78ff78b |
children | 4cdd9c4896f6 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/StyledXYSeries.java Fri Sep 28 12:14:56 2012 +0200 @@ -0,0 +1,116 @@ +package de.intevation.flys.exports; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.geom.Ellipse2D; + +import org.apache.log4j.Logger; + +import org.w3c.dom.Document; + +import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; +import org.jfree.data.xy.XYSeries; + +import de.intevation.flys.utils.ThemeUtil; + +/** + * Dataseries in two dimensions with additional theme-document and further + * display options. + * The theme-document will later "style" the graphical representation. + * The display options can be used to control the z-order and the axis of the + * dataseries. + */ +public class StyledXYSeries extends XYSeries { + + protected Document theme; + + private static final Logger logger = Logger.getLogger(StyledXYSeries.class); + + + public StyledXYSeries(String key, Document theme) { + this(key, true, theme); + } + + + /** + * @param sorted whether or not to sort the points. Sorting will move NANs + * to one extrema which can cause problems in certain + * algorithms. + */ + public StyledXYSeries(String key, boolean sorted, Document theme) { + super(key, sorted); + this.theme = theme; + } + + + /** + * Applies line color, size and type attributes to renderer, also + * whether to draw lines and/or points. + */ + public XYLineAndShapeRenderer applyTheme(XYLineAndShapeRenderer r, int idx){ + applyLineColor(r, idx); + applyLineSize(r, idx); + applyLineType(r, idx); + applyShowLine(r, idx); + applyShowPoints(r, idx); + + return r; + } + + + /** Set line color to renderer. */ + protected void applyLineColor(XYLineAndShapeRenderer r, int idx) { + Color c = ThemeUtil.parseLineColorField(theme); + r.setSeriesPaint(idx, c); + } + + + protected void applyLineSize(XYLineAndShapeRenderer r, int idx) { + int size = ThemeUtil.parseLineWidth(theme); + r.setSeriesStroke( + idx, + new BasicStroke(Integer.valueOf(size))); + } + + + protected void applyLineType(XYLineAndShapeRenderer r, int idx) { + int size = ThemeUtil.parseLineWidth(theme); + float[] dashes = ThemeUtil.parseLineStyle(theme); + + // Do not apply the dashed style. + if (dashes.length <= 1) { + return; + } + + r.setSeriesStroke( + idx, + new BasicStroke(Integer.valueOf(size), + BasicStroke.CAP_BUTT, + BasicStroke.JOIN_ROUND, + 1.0f, + dashes, + 0.0f)); + } + + + /** + * Sets form and visibility of points. + */ + protected void applyShowPoints(XYLineAndShapeRenderer r, int idx) { + boolean show = ThemeUtil.parseShowPoints(theme); + int size = ThemeUtil.parseLineWidth(theme); + r.setSeriesShape(idx, new Ellipse2D.Double(- size, + - size, + 2 * size, + 2 * size)); + r.setSeriesShapesVisible(idx, show); + r.setDrawOutlines(true); + } + + + protected void applyShowLine(XYLineAndShapeRenderer r, int idx) { + boolean show = ThemeUtil.parseShowLine(theme); + r.setSeriesLinesVisible(idx, show); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :