ingo@924: package de.intevation.flys.exports; ingo@924: ingo@924: import java.awt.BasicStroke; ingo@924: import java.awt.Color; raimund@1753: import java.awt.geom.Ellipse2D; ingo@924: ingo@924: import org.apache.log4j.Logger; ingo@924: ingo@924: import org.w3c.dom.Document; ingo@924: ingo@924: import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; ingo@924: import org.jfree.data.xy.XYSeries; ingo@924: raimund@1753: import de.intevation.flys.utils.ThemeUtil; ingo@924: felix@1814: /** felix@2017: * Dataseries in two dimensions with additional theme-document and further felix@2017: * display options. felix@1814: * The theme-document will later "style" the graphical representation. felix@2017: * The display options can be used to control the z-order and the axis of the felix@2017: * dataseries. felix@1814: */ ingo@924: public class StyledXYSeries extends XYSeries { ingo@924: ingo@924: protected Document theme; ingo@924: ingo@924: private static final Logger logger = Logger.getLogger(StyledXYSeries.class); ingo@924: ingo@924: sascha@1741: public StyledXYSeries(String key, Document theme) { sascha@1741: this(key, true, theme); sascha@1741: } ingo@924: felix@1814: felix@1814: /** felix@1814: * @param sorted whether or not to sort the points. Sorting will move NANs felix@1814: * to one extrema which can cause problems in certain felix@1814: * algorithms. felix@1814: */ sascha@1741: public StyledXYSeries(String key, boolean sorted, Document theme) { sascha@1741: super(key, sorted); ingo@924: this.theme = theme; ingo@924: } ingo@924: ingo@924: felix@2017: /** felix@2017: * Applies line color, size and type attributes to renderer, also felix@2017: * whether to draw lines and/or points. felix@2017: */ ingo@924: public XYLineAndShapeRenderer applyTheme(XYLineAndShapeRenderer r, int idx){ ingo@924: applyLineColor(r, idx); ingo@924: applyLineSize(r, idx); raimund@1714: applyLineType(r, idx); raimund@1753: applyShowLine(r, idx); raimund@1753: applyShowPoints(r, idx); ingo@924: ingo@924: return r; ingo@924: } ingo@924: ingo@924: felix@2017: /** Set line color to renderer. */ ingo@924: protected void applyLineColor(XYLineAndShapeRenderer r, int idx) { raimund@1753: Color c = ThemeUtil.parseLineColorField(theme); raimund@1753: r.setSeriesPaint(idx, c); ingo@924: } ingo@924: ingo@924: ingo@924: protected void applyLineSize(XYLineAndShapeRenderer r, int idx) { raimund@1753: int size = ThemeUtil.parseLineWidth(theme); raimund@1753: r.setSeriesStroke( raimund@1753: idx, raimund@1753: new BasicStroke(Integer.valueOf(size))); ingo@924: } raimund@1714: raimund@1714: raimund@1714: protected void applyLineType(XYLineAndShapeRenderer r, int idx) { raimund@1753: int size = ThemeUtil.parseLineWidth(theme); raimund@1753: float[] dashes = ThemeUtil.parseLineStyle(theme); raimund@1714: raimund@1753: // Do not apply the dashed style. raimund@1753: if (dashes.length <= 1) { raimund@1714: return; raimund@1714: } raimund@1714: raimund@1753: r.setSeriesStroke( raimund@1753: idx, raimund@1753: new BasicStroke(Integer.valueOf(size), raimund@1753: BasicStroke.CAP_BUTT, raimund@1753: BasicStroke.JOIN_ROUND, raimund@1753: 1.0f, raimund@1753: dashes, raimund@1753: 0.0f)); raimund@1753: } raimund@1714: raimund@1753: felix@2017: /** felix@2017: * Sets form and visibility of points. felix@2017: */ raimund@1753: protected void applyShowPoints(XYLineAndShapeRenderer r, int idx) { raimund@1753: boolean show = ThemeUtil.parseShowPoints(theme); raimund@1963: int size = ThemeUtil.parseLineWidth(theme); raimund@1963: r.setSeriesShape(idx, new Ellipse2D.Double(- size, raimund@1963: - size, raimund@1963: 2 * size, raimund@1963: 2 * size)); raimund@1753: r.setSeriesShapesVisible(idx, show); raimund@1753: r.setDrawOutlines(true); raimund@1753: } raimund@1753: raimund@1753: raimund@1753: protected void applyShowLine(XYLineAndShapeRenderer r, int idx) { raimund@1753: boolean show = ThemeUtil.parseShowLine(theme); raimund@1753: r.setSeriesLinesVisible(idx, show); raimund@1714: } ingo@924: } ingo@924: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :