comparison flys-artifacts/src/main/java/de/intevation/flys/exports/StyledXYSeries.java @ 1714:004b1b0838d6

Apply line type to styled themes. flys-artifacts/trunk@2987 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Mon, 17 Oct 2011 13:00:24 +0000
parents f7761914f745
children 1bc926b5b435
comparison
equal deleted inserted replaced
1713:6d9184c745dd 1714:004b1b0838d6
19 "/theme/field[@name='linecolor']/@default"; 19 "/theme/field[@name='linecolor']/@default";
20 20
21 public static final String XPATH_LINE_SIZE = 21 public static final String XPATH_LINE_SIZE =
22 "/theme/field[@name='linesize']/@default"; 22 "/theme/field[@name='linesize']/@default";
23 23
24 public static final String XPATH_LINE_TYPE =
25 "/theme/field[@name='linetype']/@default";
24 26
25 protected Document theme; 27 protected Document theme;
26 28
27 29
28 private static final Logger logger = Logger.getLogger(StyledXYSeries.class); 30 private static final Logger logger = Logger.getLogger(StyledXYSeries.class);
36 38
37 39
38 public XYLineAndShapeRenderer applyTheme(XYLineAndShapeRenderer r, int idx){ 40 public XYLineAndShapeRenderer applyTheme(XYLineAndShapeRenderer r, int idx){
39 applyLineColor(r, idx); 41 applyLineColor(r, idx);
40 applyLineSize(r, idx); 42 applyLineSize(r, idx);
43 applyLineType(r, idx);
41 44
42 r.setSeriesLinesVisible(idx, true); 45 r.setSeriesLinesVisible(idx, true);
43 r.setSeriesShapesVisible(idx, false); 46 r.setSeriesShapesVisible(idx, false);
44 47
45 return r; 48 return r;
85 } 88 }
86 catch (NumberFormatException nfe) { 89 catch (NumberFormatException nfe) {
87 logger.warn("Unable to set line size from string: '" + size + "'"); 90 logger.warn("Unable to set line size from string: '" + size + "'");
88 } 91 }
89 } 92 }
93
94
95 protected void applyLineType(XYLineAndShapeRenderer r, int idx) {
96 String dash = XMLUtils.xpathString(theme, XPATH_LINE_TYPE, null);
97 String size = XMLUtils.xpathString(theme, XPATH_LINE_SIZE, null);
98
99 if (dash == null || dash.length() == 0) {
100 return;
101 }
102 if (size == null || size.length() == 0) {
103 return;
104 }
105
106 String[] pattern = dash.split(",");
107 if(pattern.length == 1) {
108 return;
109 }
110
111 try {
112 float[] dashes = new float[pattern.length];
113 for (int i = 0; i < pattern.length; i++) {
114 dashes[i] = Float.parseFloat(pattern[i]);
115 }
116
117 r.setSeriesStroke(
118 idx,
119 new BasicStroke(Integer.valueOf(size),
120 BasicStroke.CAP_BUTT,
121 BasicStroke.JOIN_ROUND,
122 1.0f,
123 dashes,
124 0.0f));
125 }
126 catch(NumberFormatException nfe) {
127 logger.warn("Unable to set dash from string: '" + dash + "'");
128 }
129 }
90 } 130 }
91 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 131 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org