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