changeset 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 6d9184c745dd
children a70e0cbc5e02
files flys-artifacts/ChangeLog flys-artifacts/doc/conf/themes.xml flys-artifacts/src/main/java/de/intevation/flys/exports/StyledXYSeries.java
diffstat 3 files changed, 50 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Mon Oct 17 11:04:53 2011 +0000
+++ b/flys-artifacts/ChangeLog	Mon Oct 17 13:00:24 2011 +0000
@@ -1,3 +1,11 @@
+2011-10-17  Raimund Renkert <raimund.renkert@intevation.de>
+
+	* src/main/java/de/intevation/flys/exports/StyledXYSeries.java:
+	  Added method to apply line type.
+
+	* doc/conf/themes.xml:
+	  Changed initial default value for line type.
+
 2011-10-17  Ingo Weinzierl <ingo@intevation.de>
 
 	flys/issue226 (W-INFO: Dauerlinienberechung /Abbbildung x-Achse)
--- a/flys-artifacts/doc/conf/themes.xml	Mon Oct 17 11:04:53 2011 +0000
+++ b/flys-artifacts/doc/conf/themes.xml	Mon Oct 17 13:00:24 2011 +0000
@@ -149,7 +149,7 @@
         <fields>
             <field name="showlines" type="boolean" display="Linie anzeigen" default="true"/>
             <field name="linesize"  type="int"     display="Liniendicke"    default="1"/>
-            <field name="linetype"  type="Dash"    display="Linienart"      default="new Dash()"/>
+            <field name="linetype"  type="Dash"    display="Linienart"      default="10"/>
         </fields>
     </theme>
 
@@ -169,7 +169,7 @@
         <fields>
             <field name="showlines" type="boolean" display="Linie anzeigen" default="true"        hints="h"/>
             <field name="linesize"  type="int"     display="Liniendicke"    default="1"           hints="h"/>
-            <field name="linetype"  type="Dash"    display="Linienart"      default="new Dash()"  hints="h"/>
+            <field name="linetype"  type="Dash"    display="Linienart"      default="10"  hints="h"/>
         </fields>
     </theme>
 
--- 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 :

http://dive4elements.wald.intevation.org