Mercurial > dive4elements > river
diff 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 |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/StyledXYSeries.java Mon Oct 17 11:04:53 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/StyledXYSeries.java Mon Oct 17 13:00:24 2011 +0000 @@ -21,6 +21,8 @@ public static final String XPATH_LINE_SIZE = "/theme/field[@name='linesize']/@default"; + public static final String XPATH_LINE_TYPE = + "/theme/field[@name='linetype']/@default"; protected Document theme; @@ -38,6 +40,7 @@ public XYLineAndShapeRenderer applyTheme(XYLineAndShapeRenderer r, int idx){ applyLineColor(r, idx); applyLineSize(r, idx); + applyLineType(r, idx); r.setSeriesLinesVisible(idx, true); r.setSeriesShapesVisible(idx, false); @@ -87,5 +90,42 @@ logger.warn("Unable to set line size from string: '" + size + "'"); } } + + + protected void applyLineType(XYLineAndShapeRenderer r, int idx) { + String dash = XMLUtils.xpathString(theme, XPATH_LINE_TYPE, null); + String size = XMLUtils.xpathString(theme, XPATH_LINE_SIZE, null); + + if (dash == null || dash.length() == 0) { + return; + } + if (size == null || size.length() == 0) { + return; + } + + String[] pattern = dash.split(","); + if(pattern.length == 1) { + return; + } + + try { + float[] dashes = new float[pattern.length]; + for (int i = 0; i < pattern.length; i++) { + dashes[i] = Float.parseFloat(pattern[i]); + } + + r.setSeriesStroke( + idx, + new BasicStroke(Integer.valueOf(size), + BasicStroke.CAP_BUTT, + BasicStroke.JOIN_ROUND, + 1.0f, + dashes, + 0.0f)); + } + catch(NumberFormatException nfe) { + logger.warn("Unable to set dash from string: '" + dash + "'"); + } + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :