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