view flys-artifacts/src/main/java/de/intevation/flys/jfree/XYStyle.java @ 2791:c9815016a3bb

Merged revisions 4536 via svnmerge from file:///home/clients/bsh/bsh-generischer-viewer/Material/SVN/flys-artifacts/trunk ........ r4536 | ingo | 2012-05-27 15:35:15 +0200 (So, 27 Mai 2012) | 1 line Added more checks in CrossSectionFactory.isNewst() to prevent IndexOutOfBoundsExceptions. ........ flys-artifacts/tags/2.7@4538 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Sun, 27 May 2012 13:39:30 +0000
parents bdc86e61428c
children 22def36d37b7
line wrap: on
line source
package de.intevation.flys.jfree;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.geom.Ellipse2D;


import org.w3c.dom.Document;

import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;

import de.intevation.flys.utils.ThemeUtil;


/**
 * Utility to apply theme-settings to a renderer.
 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
 */
public class XYStyle implements Style {

    protected Document theme;


    public XYStyle(Document theme) {
        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);
        applyPointSize(r, idx);
        applyShowMinimum(r, idx);
        applyShowMaximum(r, idx);
        applyShowLineLabel(r, idx);
        applyLineLabelFont(r, idx);
        applyLineLabelColor(r, idx);
        applyShowLineLabelBG(r, idx);
        applyLineLabelBGColor(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);
    }


    /** Tells the renderer whether or not to add a label to a line. */
    protected void applyShowLineLabel(XYLineAndShapeRenderer r, int idx) {
        if (!(r instanceof EnhancedLineAndShapeRenderer)) {
            return;
        }
        boolean showLabelLine = ThemeUtil.parseShowLineLabel(theme);
        ((EnhancedLineAndShapeRenderer)r).setShowLineLabel(showLabelLine, idx);
    }


    /** Tells the renderer whether or not to fill the bg of a lines label. */
    protected void applyShowLineLabelBG(XYLineAndShapeRenderer r, int idx) {
        if (!(r instanceof EnhancedLineAndShapeRenderer)) {
            return;
        }
        boolean showLabelLine = ThemeUtil.parseShowLineLabelBG(theme);
        ((EnhancedLineAndShapeRenderer)r).setShowLineLabelBG(idx, showLabelLine);
    }

    /** Tell the renderer which font (and -size and -style) to use for
     * linelabels. */
    protected void applyLineLabelFont(XYLineAndShapeRenderer r, int idx) {
        if (!(r instanceof EnhancedLineAndShapeRenderer)) {
            return;
        }
        ((EnhancedLineAndShapeRenderer)r).setLineLabelFont(ThemeUtil.parseLineLabelFont(theme), idx);
    }

    /** Tell the renderer which color to use for
     * linelabels. */
    protected void applyLineLabelColor(XYLineAndShapeRenderer r, int idx) {
        if (!(r instanceof EnhancedLineAndShapeRenderer)) {
            return;
        }
        ((EnhancedLineAndShapeRenderer)r).setLineLabelTextColor(idx, ThemeUtil.parseLineLabelTextColor(theme));
    }

    /** Tell the renderer which color to use for bg of
     * linelabels. */
    protected void applyLineLabelBGColor(XYLineAndShapeRenderer r, int idx) {
        if (!(r instanceof EnhancedLineAndShapeRenderer)) {
            return;
        }
        ((EnhancedLineAndShapeRenderer)r).setLineLabelBGColor(idx,
            ThemeUtil.parseLineLabelBGColor(theme));
    }

    /** Set stroke of series. */
    protected void applyLineSize(XYLineAndShapeRenderer r, int idx) {
        int size = ThemeUtil.parseLineWidth(theme);
        r.setSeriesStroke(
            idx,
            new BasicStroke(Integer.valueOf(size)));
    }


    /** Set stroke strength of series. */
    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 applyPointSize(XYLineAndShapeRenderer r, int idx) {
        int size = ThemeUtil.parsePointWidth(theme);
        int dim  = 2 * size;

        r.setSeriesShape(idx, new Ellipse2D.Double(-size, -size, dim, dim));
    }


    /**
     * Sets form and visibility of points.
     */
    protected void applyShowPoints(XYLineAndShapeRenderer r, int idx) {
        boolean show = ThemeUtil.parseShowPoints(theme);

        r.setSeriesShapesVisible(idx, show);
        r.setDrawOutlines(true);
    }


    protected void applyShowLine(XYLineAndShapeRenderer r, int idx) {
        boolean show = ThemeUtil.parseShowLine(theme);
        r.setSeriesLinesVisible(idx, show);
    }


    protected void applyShowMinimum(XYLineAndShapeRenderer r, int idx) {
        if (!(r instanceof EnhancedLineAndShapeRenderer)) {
            return;
        }

        boolean visible = ThemeUtil.parseShowMinimum(theme);

        EnhancedLineAndShapeRenderer er = (EnhancedLineAndShapeRenderer) r;
        er.setIsMinimumShapeVisisble(idx, visible);
    }


    protected void applyShowMaximum(XYLineAndShapeRenderer r, int idx) {
        if (!(r instanceof EnhancedLineAndShapeRenderer)) {
            return;
        }

        boolean visible = ThemeUtil.parseShowMaximum(theme);

        EnhancedLineAndShapeRenderer er = (EnhancedLineAndShapeRenderer) r;
        er.setIsMaximumShapeVisible(idx, visible);
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org