changeset 2071:fd95bfbb2ec2

Allow styling of outline of areas. flys-artifacts/trunk@3575 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 03 Jan 2012 13:14:42 +0000
parents 48fd8b06bce5
children 4cdd9c4896f6 8083f6384023
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/StyledAreaSeriesCollection.java flys-artifacts/src/main/java/de/intevation/flys/jfree/StableXYDifferenceRenderer.java
diffstat 3 files changed, 150 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Tue Jan 03 10:12:49 2012 +0000
+++ b/flys-artifacts/ChangeLog	Tue Jan 03 13:14:42 2012 +0000
@@ -1,3 +1,13 @@
+2011-01-02	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	Allow styling of outline of areas.
+
+	* src/main/java/de/intevation/flys/jfree/StableXYDifferenceRenderer.java:
+	  Allow styling of outline of areas.
+	
+	* src/main/java/de/intevation/flys/exports/StyledAreaSeriesCollection.java:
+	  Parse outline style for areas, apply it to renderer.
+
 2012-01-03  Ingo Weinzierl <ingo@intevation.de>
 
 	flys/issue104 (W-INFO: Wasserspiegellagenberechnung / Strecke)
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/StyledAreaSeriesCollection.java	Tue Jan 03 10:12:49 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/StyledAreaSeriesCollection.java	Tue Jan 03 13:14:42 2012 +0000
@@ -1,6 +1,8 @@
 package de.intevation.flys.exports;
 
 import java.awt.Color;
+import java.awt.Stroke;
+import java.awt.BasicStroke;
 
 import org.apache.log4j.Logger;
 
@@ -64,6 +66,8 @@
     ) {
         applyFillColor(renderer);
         applyShowShape(renderer);
+        applyOutlineColor(renderer);
+        applyOutlineStyle(renderer);
 
         return renderer;
     }
@@ -89,6 +93,7 @@
             renderer.setPositivePaint(new Color(0,0,0,0));
         }
         else {
+            if (paint == null) paint = new Color(177, 117, 102);
             renderer.setPositivePaint(paint);
             renderer.setNegativePaint(paint);
         }
@@ -99,7 +104,45 @@
      */
     protected void applyShowShape(StableXYDifferenceRenderer renderer) {
         boolean show = ThemeUtil.parseShowBorder(theme);
+        renderer.setDrawOutline(show);
+    }
+
+    protected void applyShowLine(StableXYDifferenceRenderer renderer) {
+        boolean show = ThemeUtil.parseShowLine(theme);
         renderer.setShapesVisible(show);
     }
+
+    /**
+     *
+     */
+    protected void applyOutlineColor(StableXYDifferenceRenderer renderer) {
+        Color c = ThemeUtil.parseLineColorField(theme);
+        renderer.setOutlinePaint(c);
+    }
+
+    protected void applyOutlineWidth(StableXYDifferenceRenderer renderer) {
+        int size = ThemeUtil.parseLineWidth(theme);
+    }
+
+    protected void applyOutlineStyle(StableXYDifferenceRenderer renderer) {
+        float[] dashes = ThemeUtil.parseLineStyle(theme);
+        int size       = ThemeUtil.parseLineWidth(theme);
+
+        Stroke stroke = null;
+
+        if (dashes.length <= 1) {
+            stroke = new BasicStroke(Integer.valueOf(size));
+        }
+        else {
+            stroke = new BasicStroke(Integer.valueOf(size),
+                BasicStroke.CAP_BUTT,
+                BasicStroke.JOIN_ROUND,
+                1.0f,
+                dashes,
+                0.0f);
+        }
+
+        renderer.setOutlineStroke(stroke);
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/jfree/StableXYDifferenceRenderer.java	Tue Jan 03 10:12:49 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/StableXYDifferenceRenderer.java	Tue Jan 03 13:14:42 2012 +0000
@@ -77,6 +77,7 @@
  */
 package de.intevation.flys.jfree;
 
+import java.awt.BasicStroke;
 import java.awt.Color;
 import java.awt.Graphics2D;
 import java.awt.Paint;
@@ -144,9 +145,20 @@
     /** Display shapes at each point? */
     private boolean shapesVisible;
 
+    /** Display shapes at each point? */
+    protected boolean drawOutline;
+
+    /** Which stroke to draw outline with? */
+    protected Stroke outlineStroke;
+
+    /** Which paint to draw outline with? */
+    protected Paint outlinePaint;
+
     /** The shape to display in the legend item. */
     private transient Shape legendShape;
 
+    protected boolean drawOriginalSeries;
+
     //private XYDatasetToZeroMapper mapper;
 
     /**
@@ -189,10 +201,64 @@
         this.positivePaint = positivePaint;
         this.negativePaint = negativePaint;
         this.shapesVisible = shapes;
-        this.legendShape = new Rectangle2D.Double(-3.0, -3.0, 10.0, 10.0);
+        this.legendShape   = new Rectangle2D.Double(-3.0, -3.0, 10.0, 10.0);
         this.roundXCoordinates = false;
+        this.drawOutline   = true;
+        this.outlineStroke = new BasicStroke(1);
+        this.outlinePaint  = Color.black;
+        this.drawOriginalSeries = false;
     }
 
+
+    /**
+     * Sets color that is used if drawOutline is true.
+     */
+    public void setOutlinePaint(Paint outlinePaint) {
+        this.outlinePaint = outlinePaint;
+    }
+
+
+    /**
+     * Gets color which is used if drawOutline is true.
+     */
+    public Paint getOutlinePaint() {
+        return this.outlinePaint;
+    }
+
+
+    /**
+     * Sets Stroke that is used if drawOutline is true.
+     */
+    public void setOutlineStroke(Stroke stroke) {
+        this.outlineStroke = stroke;
+    }
+
+
+    /**
+     * Returns Stroke that is used if drawOutline is true.
+     */
+    public Stroke getOutlineStroke() {
+        return this.outlineStroke;
+    }
+
+
+    /**
+     * Whether or not to draw the 'Shape' of the area (in contrast to
+     * shapes at data items).
+     */
+    public void setDrawOutline(boolean doDrawOutline) {
+        this.drawOutline = doDrawOutline;
+    }
+
+
+    /**
+     * Returns whether or not to draw the shape of the outline.
+     */
+    public boolean getDrawOutline() {
+        return this.drawOutline;
+    }
+
+
     /**
      * Returns the paint used to highlight positive differences.
      *
@@ -355,7 +421,6 @@
                 info);
         state.setProcessVisibleItemsOnly(false);
         return state;
-
     }
 
     /**
@@ -1193,6 +1258,7 @@
         double l_y1 = x_rangeAxis.valueToJava2D(l_y0, x_dataArea,
                 l_rangeAxisLocation);
 
+        // These are the shapes of the series items.
         if (getShapesVisible()) {
             Shape l_shape = getItemShape(x_series, x_item);
             if (l_orientation == PlotOrientation.HORIZONTAL) {
@@ -1206,9 +1272,16 @@
             if (l_shape.intersects(x_dataArea)) {
                 x_graphics.setPaint(getItemPaint(x_series, x_item));
                 x_graphics.fill(l_shape);
+                /* TODO We could draw the shapes of single items here.
+                if (drawOutline) {
+                    x_graphics.setPaint(this.outlinePaint);
+                    x_graphics.setStroke(this.outlineStroke);
+                    x_graphics.draw(l_shape);
+                }
+                */
             }
             l_entityArea = l_shape;
-        }
+        } // if (getShapesVisible())
 
         // add an entity for the item...
         if (null != l_entities) {
@@ -1265,7 +1338,11 @@
         if ((null != l_line) && l_line.intersects(x_dataArea)) {
             x_graphics.setPaint(getItemPaint(x_series, x_item));
             x_graphics.setStroke(getItemStroke(x_series, x_item));
-            x_graphics.draw(l_line);
+            if (drawOriginalSeries) {
+                x_graphics.setPaint(this.outlinePaint);
+                x_graphics.setStroke(this.outlineStroke);
+                x_graphics.draw(l_line);
+            }
         }
     }
 
@@ -1330,12 +1407,12 @@
      */
     private void createPolygon (Graphics2D x_graphics,
                                 Rectangle2D x_dataArea,
-                                XYPlot x_plot,
-                                ValueAxis x_domainAxis,
-                                ValueAxis x_rangeAxis,
-                                boolean x_positive,
-                                LinkedList x_xValues,
-                                LinkedList x_yValues) {
+                                XYPlot      x_plot,
+                                ValueAxis   x_domainAxis,
+                                ValueAxis   x_rangeAxis,
+                                boolean     x_positive,
+                                LinkedList  x_xValues,
+                                LinkedList  x_yValues) {
 
         PlotOrientation l_orientation      = x_plot.getOrientation();
         RectangleEdge l_domainAxisLocation = x_plot.getDomainAxisEdge();
@@ -1407,6 +1484,11 @@
             x_graphics.setPaint(x_positive ? getPositivePaint()
                     : getNegativePaint());
             x_graphics.fill(l_path);
+            if (drawOutline) {
+                x_graphics.setStroke(this.outlineStroke);
+                x_graphics.setPaint(this.outlinePaint);
+                x_graphics.draw(l_path);
+            }
         }
     }
 
@@ -1451,6 +1533,10 @@
                     //result = new LegendItem(label, description,
                     //        toolTipText, urlText, line, stroke, paint);
 
+                    if (drawOutline) {
+                        // TODO Include outline style in legenditem (there is a constructor for that)
+                    }
+
                     // Filled Shape ("Area-Style").
                     result = new LegendItem(label, description,
                             toolTipText, urlText, line, paint);
@@ -1550,3 +1636,4 @@
         this.legendShape = SerialUtilities.readShape(stream);
     }
 }
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org