comparison flys-artifacts/src/main/java/de/intevation/flys/themes/ThemeAccess.java @ 2793:6310b1582f2d

merged flys-artifacts/2.7
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:30 +0200
parents b75681c09ef8
children 703be13ffa74
comparison
equal deleted inserted replaced
2548:ada02bbd3b7f 2793:6310b1582f2d
1 package de.intevation.flys.utils;
2
3 import java.awt.Color;
4 import java.awt.Font;
5
6 import org.w3c.dom.Document;
7
8 import de.intevation.flys.jfree.StableXYDifferenceRenderer;
9
10 import org.jfree.chart.annotations.XYTextAnnotation;
11
12
13 /** Undocumented. */
14 public class ThemeAccess
15 {
16 protected Document theme;
17
18 protected Integer lineWidth;
19
20 protected Color lineColor;
21 protected Color textColor;
22 protected Font font;
23 protected String textOrientation;
24 protected Color textBackground;
25 protected Boolean showTextBackground;
26
27
28 public ThemeAccess(Document theme) {
29 this.theme = theme;
30 }
31
32
33 public int parseLineWidth() {
34 if (lineWidth == null) {
35 lineWidth = ThemeUtil.parseLineWidth(theme);
36 }
37 return lineWidth;
38 }
39
40
41 public Color parseLineColorField() {
42 if (lineColor == null) {
43 lineColor = ThemeUtil.parseLineColorField(theme);
44 if (lineColor == null) {
45 lineColor = Color.BLACK;
46 }
47 }
48 return lineColor;
49 }
50
51
52 public Color parseTextColor() {
53 if (textColor == null) {
54 textColor = ThemeUtil.parseTextColor(theme);
55 if (textColor == null) {
56 textColor = Color.BLACK;
57 }
58 }
59 return textColor;
60 }
61
62
63 public Font parseTextFont() {
64 if (font == null) {
65 font = ThemeUtil.parseTextFont(theme);
66 if (font == null) {
67 font = new Font("Arial", Font.BOLD, 10);
68 }
69 }
70 return font;
71 }
72
73
74 public String parseTextOrientation() {
75 if (textOrientation == null) {
76 textOrientation = ThemeUtil.parseTextOrientation(theme);
77 if (textOrientation == null) {
78 textOrientation = "horizontal";
79 }
80 }
81 return textOrientation;
82 }
83
84
85 public Color parseTextBackground() {
86 if (textBackground == null) {
87 textBackground = ThemeUtil.parseTextBackground(theme);
88 if (textBackground == null) {
89 textBackground = Color.WHITE;
90 }
91 }
92 return textBackground;
93 }
94
95 public boolean parseShowTextBackground() {
96 if (showTextBackground == null) {
97 showTextBackground = ThemeUtil.parseShowTextBackground(theme);
98 }
99 return showTextBackground;
100 }
101
102 /**
103 more of this
104 */
105
106 public LineStyle parseLineStyle() {
107 return new LineStyle(parseLineColorField(), Integer.valueOf(parseLineWidth()));
108 }
109
110 public static class LineStyle {
111 protected Color lineColor;
112 protected int lineWidth;
113
114 public LineStyle(Color color, int width) {
115 this.lineColor = color;
116 this.lineWidth = width;
117 }
118
119 public int getWidth() {
120 return lineWidth;
121 }
122
123 public Color getColor() {
124 return lineColor;
125 }
126 }
127
128
129 public TextStyle parseTextStyle() {
130 return new TextStyle(parseTextColor(), parseTextFont(),
131 parseTextBackground(), parseShowTextBackground(),
132 !parseTextOrientation().equals("horizontal"));
133 }
134
135
136 public static class TextStyle {
137 protected Color textColor;
138 protected Font font;
139 protected Color bgColor;
140 protected boolean showBg;
141 protected boolean isVertical;
142
143 public TextStyle(Color fgColor, Font font, Color bgColor,
144 boolean showBg, boolean isVertical
145 ) {
146 this.textColor = fgColor;
147 this.font = font;
148 this.bgColor = bgColor;
149 this.showBg = showBg;
150 this.isVertical = isVertical;
151 }
152
153 public void apply(XYTextAnnotation ta) {
154 ta.setPaint(textColor);
155 ta.setFont(font);
156 if (this.showBg) {
157 ta.setBackgroundPaint(bgColor);
158 }
159 if (this.isVertical) {
160 ta.setRotationAngle(270f*Math.PI/180f);
161 }
162 else {
163 ta.setRotationAngle(0f*Math.PI/180f);
164 }
165 }
166
167 public void apply(StableXYDifferenceRenderer renderer) {
168 renderer.setLabelColor(textColor);
169 renderer.setLabelFont(font);
170 if (this.showBg) {
171 renderer.setLabelBGColor(bgColor);
172 }
173 }
174 }
175 }
176 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org