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