view flys-artifacts/src/main/java/de/intevation/flys/themes/ThemeAccess.java @ 2418:899ca89f497e

Another partial fix for flys/issue499: Do the W to Q conversions needed for 'W am Pegel' correctly. flys-artifacts/trunk@4052 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 14 Feb 2012 16:48:13 +0000
parents 5144369d5961
children 6da7e064ae90
line wrap: on
line source
package de.intevation.flys.utils;

import java.awt.Color;
import java.awt.Font;

import org.w3c.dom.Document;

import org.jfree.chart.annotations.XYTextAnnotation;


/** Undocumented. */
public class ThemeAccess
{
    protected Document theme;

    protected Integer lineWidth;

    protected Color   lineColor;
    protected Color   textColor;
    protected Font    font;
    protected String  textOrientation;
    protected Color   textBackground;
    protected Boolean showTextBackground;


    public ThemeAccess(Document theme) {
        this.theme = theme;
    }


    public int parseLineWidth() {
        if (lineWidth == null) {
            lineWidth = ThemeUtil.parseLineWidth(theme);
        }
        return lineWidth;
    }


    public Color parseLineColorField() {
        if (lineColor == null) {
            lineColor = ThemeUtil.parseLineColorField(theme);
            if (lineColor == null) {
                lineColor = Color.BLACK;
            }
        }
        return lineColor;
    }

    
    public Color parseTextColor() {
        if (textColor == null) {
            textColor = ThemeUtil.parseTextColor(theme);
            if (textColor == null) {
                textColor = Color.BLACK;
            }
        }
        return textColor;
    }


    public Font parseTextFont() {
        if (font == null) {
            font = ThemeUtil.parseTextFont(theme);
            if (font == null) {
                font = new Font("Arial", Font.BOLD, 10);
            }
        }
        return font;
    }


    public String parseTextOrientation() {
        if (textOrientation == null) {
            textOrientation = ThemeUtil.parseTextOrientation(theme);
            if (textOrientation == null) {
                textOrientation = "horizontal";
            }
        }
        return textOrientation;
    }


    public Color parseTextBackground() {
        if (textBackground == null) {
            textBackground = ThemeUtil.parseTextBackground(theme);
            if (textBackground == null) {
                textBackground = Color.WHITE;
            }
        }
        return textBackground;
    }

    public boolean parseShowTextBackground() {
        if (showTextBackground == null) {
            showTextBackground = ThemeUtil.parseShowTextBackground(theme);
        }
        return showTextBackground;
    }

    /**
    more of this
    */

    public LineStyle parseLineStyle() {
        return new LineStyle(parseLineColorField(), Integer.valueOf(parseLineWidth()));
    }

    public static class LineStyle {
        protected Color lineColor;
        protected int   lineWidth;

        public LineStyle(Color color, int width) {
            this.lineColor = color;
            this.lineWidth = width;
        }

        public int getWidth() {
            return lineWidth;
        }

        public Color getColor() {
            return lineColor;
        }
    }


    public TextStyle parseTextStyle() {
        return new TextStyle(parseTextColor(), parseTextFont(),
            parseTextBackground(), parseShowTextBackground(),
            !parseTextOrientation().equals("horizontal"));
    }


    public static class TextStyle {
        protected Color   textColor;
        protected Font    font;
        protected Color   bgColor;
        protected boolean showBg;
        protected boolean isVertical;

        public TextStyle(Color fgColor, Font font, Color bgColor,
            boolean showBg, boolean isVertical
        ) {
            this.textColor  = fgColor;
            this.font       = font;
            this.bgColor    = bgColor;
            this.showBg     = showBg;
            this.isVertical = isVertical;
        }

        public void apply(XYTextAnnotation ta) {
            ta.setPaint(textColor);
            ta.setFont(font);
            if (this.showBg) {
                ta.setBackgroundPaint(bgColor);
            }
            if (this.isVertical) {
                ta.setRotationAngle(270f*Math.PI/180f);
            }
            else {
                ta.setRotationAngle(0f*Math.PI/180f);
            }
        }
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org