Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/jfree/StyledAreaSeriesCollection.java @ 3468:f37e7e8907cb
merged flys-artifacts/2.8.1
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:39 +0200 |
parents | cd5eb8f5f6f1 |
children | 940cd2ef149f |
comparison
equal
deleted
inserted
replaced
3387:5ffad8bde8ad | 3468:f37e7e8907cb |
---|---|
1 package de.intevation.flys.jfree; | |
2 | |
3 import java.awt.BasicStroke; | |
4 import java.awt.Color; | |
5 import java.awt.Stroke; | |
6 | |
7 import org.apache.log4j.Logger; | |
8 import org.jfree.data.xy.XYSeriesCollection; | |
9 import org.w3c.dom.Document; | |
10 | |
11 import de.intevation.flys.themes.ThemeAccess; | |
12 import de.intevation.flys.utils.ThemeUtil; | |
13 | |
14 | |
15 /** | |
16 * One or more dataseries to draw a polygon (either "open up/downwards", or | |
17 * the area between two curves), a theme-document and further display options. | |
18 * The theme-document will later "style" the graphical representation. | |
19 * The display options can be used to control the z-order and the axis of the | |
20 * dataset. | |
21 */ | |
22 public class StyledAreaSeriesCollection extends XYSeriesCollection { | |
23 /** Mode, how to draw/which areas to fill. */ | |
24 public enum FILL_MODE {UNDER, ABOVE, BETWEEN}; | |
25 | |
26 /** MODE in use. */ | |
27 protected FILL_MODE mode; | |
28 | |
29 /** The theme-document with attributes about actual visual representation. */ | |
30 protected Document theme; | |
31 | |
32 /** Own logger. */ | |
33 private static final Logger logger = | |
34 Logger.getLogger(StyledAreaSeriesCollection.class); | |
35 | |
36 | |
37 /** | |
38 * @param theme the theme-document. | |
39 */ | |
40 public StyledAreaSeriesCollection(Document theme) { | |
41 this.theme = theme; | |
42 this.mode = FILL_MODE.BETWEEN; | |
43 } | |
44 | |
45 | |
46 /** Gets the Fill mode. */ | |
47 public FILL_MODE getMode() { | |
48 return this.mode; | |
49 } | |
50 | |
51 | |
52 /** Sets the Fill mode. */ | |
53 public void setMode(FILL_MODE fMode) { | |
54 this.mode = fMode; | |
55 } | |
56 | |
57 | |
58 /** | |
59 * Applies line color, size and type attributes to renderer, also | |
60 * whether to draw lines and/or points. | |
61 * @param renderer Renderer to apply theme to. | |
62 * @return \param renderer | |
63 */ | |
64 public StableXYDifferenceRenderer applyTheme( | |
65 StableXYDifferenceRenderer renderer | |
66 ) { | |
67 applyFillColor(renderer); | |
68 applyShowShape(renderer); | |
69 applyOutlineColor(renderer); | |
70 applyOutlineStyle(renderer); | |
71 applyShowArea(renderer); | |
72 if (mode == FILL_MODE.UNDER) { | |
73 renderer.setAreaCalculationMode(StableXYDifferenceRenderer.CALCULATE_NEGATIVE_AREA); | |
74 } | |
75 else if (mode == FILL_MODE.ABOVE) { | |
76 renderer.setAreaCalculationMode(StableXYDifferenceRenderer.CALCULATE_POSITIVE_AREA); | |
77 } | |
78 else { | |
79 renderer.setAreaCalculationMode(StableXYDifferenceRenderer.CALCULATE_ALL_AREA); | |
80 } | |
81 | |
82 // Apply text style. | |
83 new ThemeAccess(theme).parseTextStyle().apply(renderer); | |
84 return renderer; | |
85 } | |
86 | |
87 | |
88 /** | |
89 * Blindly (for now) apply the positivepaint of renderer. | |
90 */ | |
91 protected void applyFillColor(StableXYDifferenceRenderer renderer) { | |
92 // Get color. | |
93 Color paint = ThemeUtil.parseFillColorField(theme); | |
94 // Get half-transparency flag. | |
95 if (ThemeUtil.parseTransparency(theme)) { | |
96 paint = new Color(paint.getRed(), paint.getGreen(), paint.getBlue(), | |
97 128); | |
98 } | |
99 if (paint != null && this.getMode() == FILL_MODE.ABOVE) { | |
100 renderer.setPositivePaint(paint); | |
101 renderer.setNegativePaint(new Color(0,0,0,0)); | |
102 } | |
103 else if (paint != null && this.getMode() == FILL_MODE.UNDER) { | |
104 renderer.setNegativePaint(paint); | |
105 renderer.setPositivePaint(new Color(0,0,0,0)); | |
106 } | |
107 else { | |
108 if (paint == null) paint = new Color(177, 117, 102); | |
109 renderer.setPositivePaint(paint); | |
110 renderer.setNegativePaint(paint); | |
111 } | |
112 } | |
113 | |
114 /** | |
115 * Blindly (for now) apply the postiviepaint of renderer. | |
116 */ | |
117 protected void applyShowShape(StableXYDifferenceRenderer renderer) { | |
118 boolean show = ThemeUtil.parseShowBorder(theme); | |
119 renderer.setDrawOutline(show); | |
120 } | |
121 | |
122 | |
123 protected void applyShowLine(StableXYDifferenceRenderer renderer) { | |
124 boolean show = ThemeUtil.parseShowLine(theme); | |
125 renderer.setShapesVisible(show); | |
126 } | |
127 | |
128 | |
129 protected void applyOutlineColor(StableXYDifferenceRenderer renderer) { | |
130 Color c = ThemeUtil.parseLineColorField(theme); | |
131 renderer.setOutlinePaint(c); | |
132 } | |
133 | |
134 protected void applyOutlineWidth(StableXYDifferenceRenderer renderer) { | |
135 int size = ThemeUtil.parseLineWidth(theme); | |
136 } | |
137 | |
138 /** Inform renderer whether it should draw a label. */ | |
139 protected void applyShowArea(StableXYDifferenceRenderer renderer) { | |
140 renderer.setLabelArea(ThemeUtil.parseShowArea(theme)); | |
141 } | |
142 | |
143 protected void applyOutlineStyle(StableXYDifferenceRenderer renderer) { | |
144 float[] dashes = ThemeUtil.parseLineStyle(theme); | |
145 int size = ThemeUtil.parseLineWidth(theme); | |
146 | |
147 Stroke stroke = null; | |
148 | |
149 if (dashes.length <= 1) { | |
150 stroke = new BasicStroke(Integer.valueOf(size)); | |
151 } | |
152 else { | |
153 stroke = new BasicStroke(Integer.valueOf(size), | |
154 BasicStroke.CAP_BUTT, | |
155 BasicStroke.JOIN_ROUND, | |
156 1.0f, | |
157 dashes, | |
158 0.0f); | |
159 } | |
160 | |
161 renderer.setOutlineStroke(stroke); | |
162 } | |
163 } | |
164 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |