view flys-artifacts/src/main/java/de/intevation/flys/exports/StyledXYSeries.java @ 1753:741ba9e34c7d

Apply the attributes 'showpoints' and 'showline'. flys-artifacts/trunk@3056 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Fri, 21 Oct 2011 14:02:07 +0000
parents 1bc926b5b435
children 8e6615ad60b8
line wrap: on
line source
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.artifacts.common.utils.XMLUtils;
import de.intevation.flys.utils.ThemeUtil;


public class StyledXYSeries extends XYSeries {

    public static final String XPATH_LINE_COLOR =
        "/theme/field[@name='linecolor']/@default";

    public static final String XPATH_LINE_SIZE =
        "/theme/field[@name='linesize']/@default";

    public static final String XPATH_LINE_TYPE =
        "/theme/field[@name='linetype']/@default";

    protected Document theme;


    private static final Logger logger = Logger.getLogger(StyledXYSeries.class);


    public StyledXYSeries(String key, Document theme) {
        this(key, true, theme);
    }

    public StyledXYSeries(String key, boolean sorted, Document theme) {
        super(key, sorted);
        this.theme = theme;
    }


    public XYLineAndShapeRenderer applyTheme(XYLineAndShapeRenderer r, int idx){
        applyLineColor(r, idx);
        applyLineSize(r, idx);
        applyLineType(r, idx);
        applyShowLine(r, idx);
        applyShowPoints(r, idx);

        return r;
    }


    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));
    }


    protected void applyShowPoints(XYLineAndShapeRenderer r, int idx) {
        boolean show = ThemeUtil.parseShowPoints(theme);
        r.setSeriesShape(idx, new Ellipse2D.Double(-2.0, -2.0, 4.0, 4.0));
        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 :

http://dive4elements.wald.intevation.org