comparison flys-artifacts/src/main/java/de/intevation/flys/exports/StyledXYSeries.java @ 1753:741ba9e34c7d

Apply the attributes 'showpoints' and 'showline'. flys-artifacts/trunk@3056 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Fri, 21 Oct 2011 14:02:07 +0000
parents 1bc926b5b435
children 8e6615ad60b8
comparison
equal deleted inserted replaced
1752:b7b424ae32a8 1753:741ba9e34c7d
1 package de.intevation.flys.exports; 1 package de.intevation.flys.exports;
2 2
3 import java.awt.BasicStroke; 3 import java.awt.BasicStroke;
4 import java.awt.Color; 4 import java.awt.Color;
5 import java.awt.geom.Ellipse2D;
5 6
6 import org.apache.log4j.Logger; 7 import org.apache.log4j.Logger;
7 8
8 import org.w3c.dom.Document; 9 import org.w3c.dom.Document;
9 10
10 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; 11 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
11 import org.jfree.data.xy.XYSeries; 12 import org.jfree.data.xy.XYSeries;
12 13
13 import de.intevation.artifacts.common.utils.XMLUtils; 14 import de.intevation.artifacts.common.utils.XMLUtils;
15 import de.intevation.flys.utils.ThemeUtil;
14 16
15 17
16 public class StyledXYSeries extends XYSeries { 18 public class StyledXYSeries extends XYSeries {
17 19
18 public static final String XPATH_LINE_COLOR = 20 public static final String XPATH_LINE_COLOR =
42 44
43 public XYLineAndShapeRenderer applyTheme(XYLineAndShapeRenderer r, int idx){ 45 public XYLineAndShapeRenderer applyTheme(XYLineAndShapeRenderer r, int idx){
44 applyLineColor(r, idx); 46 applyLineColor(r, idx);
45 applyLineSize(r, idx); 47 applyLineSize(r, idx);
46 applyLineType(r, idx); 48 applyLineType(r, idx);
47 49 applyShowLine(r, idx);
48 r.setSeriesLinesVisible(idx, true); 50 applyShowPoints(r, idx);
49 r.setSeriesShapesVisible(idx, false);
50 51
51 return r; 52 return r;
52 } 53 }
53 54
54 55
55 protected void applyLineColor(XYLineAndShapeRenderer r, int idx) { 56 protected void applyLineColor(XYLineAndShapeRenderer r, int idx) {
56 String color = XMLUtils.xpathString(theme, XPATH_LINE_COLOR, null); 57 Color c = ThemeUtil.parseLineColorField(theme);
57 58 r.setSeriesPaint(idx, c);
58 if (color == null || color.length() == 0) {
59 return;
60 }
61
62 String[] rgb = color.split(",");
63
64 try {
65 Color c = new Color(
66 Integer.valueOf(rgb[0].trim()),
67 Integer.valueOf(rgb[1].trim()),
68 Integer.valueOf(rgb[2].trim()));
69
70 logger.debug("Set series paint color: " + c.toString());
71
72 r.setSeriesPaint(idx, c);
73 }
74 catch (NumberFormatException nfe) {
75 logger.warn("Unable to set color from string: '" + color + "'");
76 }
77 } 59 }
78 60
79 61
80 protected void applyLineSize(XYLineAndShapeRenderer r, int idx) { 62 protected void applyLineSize(XYLineAndShapeRenderer r, int idx) {
81 String size = XMLUtils.xpathString(theme, XPATH_LINE_SIZE, null); 63 int size = ThemeUtil.parseLineWidth(theme);
82 64 r.setSeriesStroke(
83 if (size == null || size.length() == 0) { 65 idx,
84 return; 66 new BasicStroke(Integer.valueOf(size)));
85 }
86
87 try {
88 r.setSeriesStroke(
89 idx,
90 new BasicStroke(Integer.valueOf(size)));
91 }
92 catch (NumberFormatException nfe) {
93 logger.warn("Unable to set line size from string: '" + size + "'");
94 }
95 } 67 }
96 68
97 69
98 protected void applyLineType(XYLineAndShapeRenderer r, int idx) { 70 protected void applyLineType(XYLineAndShapeRenderer r, int idx) {
99 String dash = XMLUtils.xpathString(theme, XPATH_LINE_TYPE, null); 71 int size = ThemeUtil.parseLineWidth(theme);
100 String size = XMLUtils.xpathString(theme, XPATH_LINE_SIZE, null); 72 float[] dashes = ThemeUtil.parseLineStyle(theme);
101 73
102 if (dash == null || dash.length() == 0) { 74 // Do not apply the dashed style.
103 return; 75 if (dashes.length <= 1) {
104 }
105 if (size == null || size.length() == 0) {
106 return; 76 return;
107 } 77 }
108 78
109 String[] pattern = dash.split(","); 79 r.setSeriesStroke(
110 if(pattern.length == 1) { 80 idx,
111 return; 81 new BasicStroke(Integer.valueOf(size),
112 } 82 BasicStroke.CAP_BUTT,
83 BasicStroke.JOIN_ROUND,
84 1.0f,
85 dashes,
86 0.0f));
87 }
113 88
114 try {
115 float[] dashes = new float[pattern.length];
116 for (int i = 0; i < pattern.length; i++) {
117 dashes[i] = Float.parseFloat(pattern[i]);
118 }
119 89
120 r.setSeriesStroke( 90 protected void applyShowPoints(XYLineAndShapeRenderer r, int idx) {
121 idx, 91 boolean show = ThemeUtil.parseShowPoints(theme);
122 new BasicStroke(Integer.valueOf(size), 92 r.setSeriesShape(idx, new Ellipse2D.Double(-2.0, -2.0, 4.0, 4.0));
123 BasicStroke.CAP_BUTT, 93 r.setSeriesShapesVisible(idx, show);
124 BasicStroke.JOIN_ROUND, 94 r.setDrawOutlines(true);
125 1.0f, 95 }
126 dashes, 96
127 0.0f)); 97
128 } 98 protected void applyShowLine(XYLineAndShapeRenderer r, int idx) {
129 catch(NumberFormatException nfe) { 99 boolean show = ThemeUtil.parseShowLine(theme);
130 logger.warn("Unable to set dash from string: '" + dash + "'"); 100 r.setSeriesLinesVisible(idx, show);
131 }
132 } 101 }
133 } 102 }
134 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 103 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org