changeset 3090:22def36d37b7

Apply point color in XYStyle. flys-artifacts/trunk@4689 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 18 Jun 2012 12:29:29 +0000
parents 7e4c8590067a
children 179e38aa678d
files flys-artifacts/ChangeLog flys-artifacts/doc/conf/themes.xml flys-artifacts/src/main/java/de/intevation/flys/jfree/XYStyle.java flys-artifacts/src/main/java/de/intevation/flys/themes/ThemeAccess.java flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java
diffstat 5 files changed, 101 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Mon Jun 18 11:31:39 2012 +0000
+++ b/flys-artifacts/ChangeLog	Mon Jun 18 12:29:29 2012 +0000
@@ -1,3 +1,16 @@
+2012-06-18  Ingo Weinzierl <ingo@intevation.de>
+
+	* doc/conf/themes.xml: Fixed broken color strings.
+
+	* src/main/java/de/intevation/flys/utils/ThemeUtil.java: Added new functions
+	  that return colors for points.
+
+	* src/main/java/de/intevation/flys/themes/ThemeAccess.java: Added new
+	  function that returns the color for points.
+
+	* src/main/java/de/intevation/flys/jfree/XYStyle.java: Added new method to
+	  apply the color of points (independent of the specified line color).
+
 2012-06-18  Ingo Weinzierl <ingo@intevation.de>
 
 	* doc/conf/themes.xml: Added themes for SQ relation charts
--- a/flys-artifacts/doc/conf/themes.xml	Mon Jun 18 11:31:39 2012 +0000
+++ b/flys-artifacts/doc/conf/themes.xml	Mon Jun 18 12:29:29 2012 +0000
@@ -908,7 +908,7 @@
             </inherits>
             <fields>
                 <field name="showlines"  type="boolean" display="Linie anzeigen" default="false" hidden="true"/>
-                <field name="pointcolor" type="Color"   default="Color.BLACK"/>
+                <field name="pointcolor" type="Color"   default="#000000"/>
             </fields>
         </theme>
 
@@ -918,7 +918,7 @@
             </inherits>
             <fields>
                 <field name="showlines" type="boolean" display="Linie anzeigen" default="false" hidden="true"/>
-                <field name="pointcolor" type="Color"   default="Color.RED"/>
+                <field name="pointcolor" type="Color"   default="#CC0000"/>
             </fields>
         </theme>
 
@@ -927,7 +927,7 @@
                 <inherit from="HiddenColorLines"/>
             </inherits>
             <fields>
-                <field name="linecolor" type="Color" default="Color.BLUE"/>
+                <field name="linecolor" type="Color" default="#0000DD"/>
             </fields>
         </theme>
 
@@ -1795,12 +1795,20 @@
             <inherits>
                 <inherit from="ColorPoints"/>
             </inherits>
+            <fields>
+                <field name="showlines"  type="boolean" display="Linie anzeigen" default="false" hidden="true"/>
+                <field name="pointcolor" type="Color"   default="#000000"/>
+            </fields>
         </theme>
 
         <theme name="SQOutliers">
             <inherits>
                 <inherit from="ColorPoints"/>
             </inherits>
+            <fields>
+                <field name="showlines" type="boolean" display="Linie anzeigen" default="false" hidden="true"/>
+                <field name="pointcolor" type="Color"   default="#CC0000"/>
+            </fields>
         </theme>
 
         <theme name="SQCurve">
@@ -1808,7 +1816,7 @@
                 <inherit from="HiddenColorLines"/>
             </inherits>
             <fields>
-                <field name="linecolor" type="Color" default="Color.BLUE"/>
+                <field name="linecolor" type="Color" default="#0000DD"/>
             </fields>
         </theme>
 
@@ -2092,12 +2100,20 @@
             <inherits>
                 <inherit from="ColorPoints"/>
             </inherits>
+            <fields>
+                <field name="showlines"  type="boolean" display="Linie anzeigen" default="false" hidden="true"/>
+                <field name="pointcolor" type="Color"   default="#000000"/>
+            </fields>
         </theme>
 
         <theme name="SQOutliers">
             <inherits>
                 <inherit from="ColorPoints"/>
             </inherits>
+            <fields>
+                <field name="showlines" type="boolean" display="Linie anzeigen" default="false" hidden="true"/>
+                <field name="pointcolor" type="Color"   default="#CC0000"/>
+            </fields>
         </theme>
 
         <theme name="SQCurve">
@@ -2105,7 +2121,7 @@
                 <inherit from="HiddenColorLines"/>
             </inherits>
             <fields>
-                <field name="linecolor" type="Color" default="Color.BLUE"/>
+                <field name="linecolor" type="Color" default="#0000DD"/>
             </fields>
         </theme>
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/jfree/XYStyle.java	Mon Jun 18 11:31:39 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/XYStyle.java	Mon Jun 18 12:29:29 2012 +0000
@@ -37,6 +37,7 @@
         applyShowLine(r, idx);
         applyShowPoints(r, idx);
         applyPointSize(r, idx);
+        applyPointColor(r, idx);
         applyShowMinimum(r, idx);
         applyShowMaximum(r, idx);
         applyShowLineLabel(r, idx);
@@ -141,6 +142,17 @@
     }
 
 
+    protected void applyPointColor(XYLineAndShapeRenderer r, int idx) {
+        Color c = ThemeUtil.parsePointColor(theme);
+
+        if (c != null) {
+            r.setSeriesFillPaint(idx, c);
+            r.setUseFillPaint(true);
+            r.setDrawOutlines(false);
+        }
+    }
+
+
     /**
      * Sets form and visibility of points.
      */
--- a/flys-artifacts/src/main/java/de/intevation/flys/themes/ThemeAccess.java	Mon Jun 18 11:31:39 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/themes/ThemeAccess.java	Mon Jun 18 12:29:29 2012 +0000
@@ -23,6 +23,7 @@
     protected String  textOrientation;
     protected Color   textBackground;
     protected Boolean showTextBackground;
+    protected Color   pointColor;
 
 
     public ThemeAccess(Document theme) {
@@ -100,6 +101,19 @@
     }
 
 
+    public Color parsePointColor() {
+        if (pointColor == null) {
+            pointColor = ThemeUtil.parsePointColor(theme);
+
+            if (pointColor == null) {
+                return parseLineColorField();
+            }
+        }
+
+        return pointColor;
+    }
+
+
     public LineStyle parseLineStyle() {
         return new LineStyle(parseLineColorField(), Integer.valueOf(parseLineWidth()));
     }
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java	Mon Jun 18 11:31:39 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java	Mon Jun 18 12:29:29 2012 +0000
@@ -43,6 +43,9 @@
     public static final String XPATH_POINT_SIZE =
         "/theme/field[@name='pointsize']/@default";
 
+    public static final String XPATH_POINT_COLOR =
+        "/theme/field[@name='pointcolor']/@default";
+
     public final static String XPATH_SHOW_BORDER =
         "/theme/field[@name='showborder']/@default";
 
@@ -188,6 +191,13 @@
     }
 
 
+    public static Color parsePointColor(Document theme) {
+        String color = XMLUtils.xpathString(theme, XPATH_POINT_COLOR, null);
+
+        return parseColor(color);
+    }
+
+
     /**
      * Parses the line style, defaulting to '10'.
      * @param theme The theme.
@@ -458,6 +468,37 @@
         return parseBoolean(show, false);
     }
 
+
+    public static Color parseColor(String colorString) {
+        if (colorString == null || colorString.length() == 0) {
+            return null;
+        }
+        else if (colorString.indexOf("#") == 0) {
+            return parseHexColor(colorString);
+        }
+        else if (colorString.indexOf(",") >= 0) {
+            return parseRGB(colorString);
+        }
+
+        return null;
+    }
+
+
+    /**
+     * Parse a string like "#00CC22" and return the corresponding color.
+     *
+     * @param hex The hex color value.
+     *
+     * @return a Color or null, if <i>hex</i> is empty.
+     */
+    public static Color parseHexColor(String hex) {
+        if (hex == null) {
+            return null;
+        }
+
+        return Color.decode(hex);
+    }
+
     /**
      * Parse a string like "103, 100, 0" and return a corresping color.
      * @param rgbtext Color as string representation, e.g. "255,0,20".

http://dive4elements.wald.intevation.org