diff artifacts/src/main/java/org/dive4elements/river/jfree/XYStyle.java @ 9325:094ed9d1f2ad

Fixed: change of point style of interpolated data did not change in WQ chart of fixanalysis Fixed: change of point style of interpolated data did not change in dWt chart of fixanalysis; also had duplicate legend entries
author gernotbelger
date Fri, 27 Jul 2018 14:33:41 +0200
parents 5e38e2924c07
children ddcd52d239cd
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/jfree/XYStyle.java	Fri Jul 27 14:32:14 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/jfree/XYStyle.java	Fri Jul 27 14:33:41 2018 +0200
@@ -8,67 +8,57 @@
 
 package org.dive4elements.river.jfree;
 
-import org.dive4elements.river.themes.ThemeDocument;
-
 import java.awt.BasicStroke;
 import java.awt.Color;
 import java.awt.Shape;
 import java.awt.geom.Ellipse2D;
 
-import org.apache.log4j.Logger;
+import org.dive4elements.river.themes.ThemeDocument;
 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
 
-
 /**
  * Utility to apply theme-settings to a renderer.
+ *
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
  */
-public class XYStyle implements Style {
-
-    private static Logger log = Logger.getLogger(XYStyle.class);
-
-    protected ThemeDocument theme;
+public final class XYStyle implements Style {
 
-    protected XYLineAndShapeRenderer renderer;
+    private final ThemeDocument theme;
 
-    protected Shape shape;
+    private XYLineAndShapeRenderer renderer;
 
+    private final Shape shape;
 
-    public XYStyle(ThemeDocument theme) {
-        this.theme = theme;
+    public XYStyle(final ThemeDocument theme) {
+        this(theme, null);
     }
 
-    public XYStyle(ThemeDocument theme, Shape shape) {
+    public XYStyle(final ThemeDocument theme, final Shape shape) {
         this.theme = theme;
         this.shape = shape;
     }
 
-
     /**
      * Applies line color, size and type attributes to renderer, also
      * whether to draw lines and/or points.
      */
     @Override
-    public XYLineAndShapeRenderer applyTheme(
-        XYLineAndShapeRenderer r,
-        int idx
-    ) {
+    public XYLineAndShapeRenderer applyTheme(final XYLineAndShapeRenderer r, final int idx) {
         this.renderer = r;
-        if (shape != null) {
-            r.setShape(shape);
-        }
-        if (theme == null) {
-            // Hurray we already applied nothing :)
+
+        if (this.shape != null)
+            r.setShape(this.shape);
+
+        if (this.theme == null)
             return r;
-        }
-        applyUseFillPaint(r);
+
         applyLineColor(r, idx);
         applyLineSize(r, idx);
         applyLineType(r, idx);
         applyShowLine(r, idx);
-        applyShowPoints(r, idx);
-        applyPointSize(r, idx);
-        applyPointColor(r, idx);
+
+        applyPointStyles(r, idx);
+
         applyShowMinimum(r, idx);
         applyShowMaximum(r, idx);
 
@@ -83,177 +73,195 @@
         // TODO: Currently point label are annotations and
         // are not drawn this way
         /*
-        applyShowPointLabelBG(r, idx);
-        applyLinePointFont(r, idx);
-        applyLinePointColor(r, idx);
-        applyLinePointBGColor(r, idx);*/
+         * applyShowPointLabelBG(r, idx);
+         * applyLinePointFont(r, idx);
+         * applyLinePointColor(r, idx);
+         * applyLinePointBGColor(r, idx);
+         */
 
         return r;
     }
 
-    protected void applyUseFillPaint(XYLineAndShapeRenderer r) {
-        Boolean use = theme.parseUseFillPaint();
-        if (use != null) {
-            r.setUseFillPaint(use);
-        }
-    }
-
-
     /** Set line color to renderer. */
-    protected void applyLineColor(XYLineAndShapeRenderer r, int idx) {
-        Color c = theme.parseLineColorField();
+    private void applyLineColor(final XYLineAndShapeRenderer r, final int idx) {
+        final Color c = this.theme.parseLineColorField();
         if (c != null) {
             r.setSeriesPaint(idx, c);
         }
     }
 
-
     /** Tells the renderer whether or not to add a label to a line. */
-    protected void applyShowLineLabel(XYLineAndShapeRenderer r, int idx) {
-        if (!(r instanceof EnhancedLineAndShapeRenderer)) {
-            return;
-        }
-        boolean showLabelLine = theme.parseShowLineLabel();
-        boolean anyLabel = showLabelLine || theme.parseShowWidth() ||
-                           theme.parseShowLevel() ||
-                           theme.parseShowMiddleHeight();
-        ((EnhancedLineAndShapeRenderer)r).setShowLineLabel(anyLabel, idx);
-    }
-
-
-    /** Tells the renderer whether or not to fill the bg of a lines label. */
-    protected void applyShowLineLabelBG(XYLineAndShapeRenderer r, int idx) {
-        if (!(r instanceof EnhancedLineAndShapeRenderer)) {
-            return;
-        }
-        boolean showLabelLine = theme.parseLabelShowBackground();
-        ((EnhancedLineAndShapeRenderer)r).setShowLineLabelBG(
-            idx, showLabelLine);
-    }
-
-    /** Tell the renderer which font (and -size and -style) to use for
-     * linelabels. */
-    protected void applyLineLabelFont(XYLineAndShapeRenderer r, int idx) {
+    private void applyShowLineLabel(final XYLineAndShapeRenderer r, final int idx) {
         if (!(r instanceof EnhancedLineAndShapeRenderer)) {
             return;
         }
-        ((EnhancedLineAndShapeRenderer)r).setLineLabelFont(
-                theme.parseTextFont(), idx);
+        final boolean showLabelLine = this.theme.parseShowLineLabel();
+        final boolean anyLabel = showLabelLine || this.theme.parseShowWidth() || this.theme.parseShowLevel() || this.theme.parseShowMiddleHeight();
+        ((EnhancedLineAndShapeRenderer) r).setShowLineLabel(anyLabel, idx);
     }
 
-    /** Tell the renderer which color to use for
-     * linelabels. */
-    protected void applyLineLabelColor(XYLineAndShapeRenderer r, int idx) {
+    /** Tells the renderer whether or not to fill the bg of a lines label. */
+    private void applyShowLineLabelBG(final XYLineAndShapeRenderer r, final int idx) {
         if (!(r instanceof EnhancedLineAndShapeRenderer)) {
             return;
         }
-        ((EnhancedLineAndShapeRenderer)r).setLineLabelTextColor(
-                idx, theme.parseTextColor());
+        final boolean showLabelLine = this.theme.parseLabelShowBackground();
+        ((EnhancedLineAndShapeRenderer) r).setShowLineLabelBG(idx, showLabelLine);
     }
 
-    /** Tell the renderer which color to use for bg of
-     * linelabels. */
-    protected void applyLineLabelBGColor(XYLineAndShapeRenderer r, int idx) {
+    /**
+     * Tell the renderer which font (and -size and -style) to use for
+     * linelabels.
+     */
+    private void applyLineLabelFont(final XYLineAndShapeRenderer r, final int idx) {
         if (!(r instanceof EnhancedLineAndShapeRenderer)) {
             return;
         }
-        ((EnhancedLineAndShapeRenderer)r).setLineLabelBGColor(idx,
-            theme.parseTextBackground());
+        ((EnhancedLineAndShapeRenderer) r).setLineLabelFont(this.theme.parseTextFont(), idx);
+    }
+
+    /**
+     * Tell the renderer which color to use for
+     * linelabels.
+     */
+    private void applyLineLabelColor(final XYLineAndShapeRenderer r, final int idx) {
+        if (!(r instanceof EnhancedLineAndShapeRenderer)) {
+            return;
+        }
+        ((EnhancedLineAndShapeRenderer) r).setLineLabelTextColor(idx, this.theme.parseTextColor());
+    }
+
+    /**
+     * Tell the renderer which color to use for bg of
+     * linelabels.
+     */
+    private void applyLineLabelBGColor(final XYLineAndShapeRenderer r, final int idx) {
+        if (!(r instanceof EnhancedLineAndShapeRenderer)) {
+            return;
+        }
+        ((EnhancedLineAndShapeRenderer) r).setLineLabelBGColor(idx, this.theme.parseTextBackground());
     }
 
     /** Set stroke of series. */
-    protected void applyLineSize(XYLineAndShapeRenderer r, int idx) {
-        int size = theme.parseLineWidth();
-        r.setSeriesStroke(
-            idx,
-            new BasicStroke(size));
+    private void applyLineSize(final XYLineAndShapeRenderer r, final int idx) {
+        final int size = this.theme.parseLineWidth();
+        r.setSeriesStroke(idx, new BasicStroke(size));
     }
 
-
     /** Set stroke strength of series. */
-    protected void applyLineType(XYLineAndShapeRenderer r, int idx) {
-        int size = theme.parseLineWidth();
-        float[] dashes = theme.parseLineStyle();
+    private void applyLineType(final XYLineAndShapeRenderer r, final int idx) {
+        final int size = this.theme.parseLineWidth();
+        final float[] dashes = this.theme.parseLineStyle();
 
         // Do not apply the dashed style.
         if (dashes.length <= 1) {
             return;
         }
 
-        r.setSeriesStroke(
-            idx,
-            new BasicStroke(size,
-                            BasicStroke.CAP_BUTT,
-                            BasicStroke.JOIN_ROUND,
-                            1.0f,
-                            dashes,
-                            0.0f));
+        r.setSeriesStroke(idx, new BasicStroke(size, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 1.0f, dashes, 0.0f));
     }
 
+    private void applyPointStyles(final XYLineAndShapeRenderer r, final int idx) {
+        applyPointSize(r, idx);
 
-    protected void applyPointSize(XYLineAndShapeRenderer r, int idx) {
-        int size = theme.parsePointWidth();
-        int dim  = 2 * size;
+        final Color c = this.theme.parsePointColor();
+        final boolean show = this.theme.parseShowPoints();
+        final boolean showOutline = this.theme.parseShowPointsOutline();
+
+        if (c != null)
+            r.setSeriesFillPaint(idx, c);
+        r.setUseFillPaint(c!= null);
+        
+        r.setSeriesShapesFilled(idx, show);
+
+        r.setSeriesOutlinePaint(idx, c);
+        r.setDrawOutlines(showOutline);
+        r.setUseOutlinePaint(c != null);
+
+        r.setSeriesShapesVisible(idx, show || showOutline);
+
+        // applyShowPoints(r, idx);
+        // applyPointColor(r, idx);
+
+        // applyUseFillPaint(r);
+    }
+
+    private void applyPointSize(final XYLineAndShapeRenderer r, final int idx) {
+        final int size = this.theme.parsePointWidth();
+        final int dim = 2 * size;
 
         r.setSeriesShape(idx, new Ellipse2D.Double(-size, -size, dim, dim));
     }
 
-
-    protected void applyPointColor(XYLineAndShapeRenderer r, int idx) {
-        Color c = theme.parsePointColor();
+    private void applyPointColor(final XYLineAndShapeRenderer r, final int idx) {
+        final Color c = this.theme.parsePointColor();
 
-        if (c != null) {
+        boolean alt = false;
+        if (alt) {
+
+            if (c != null) {
+                r.setSeriesFillPaint(idx, c);
+
+                r.setUseFillPaint(true);
+                r.setDrawOutlines(false);
+            }
+        } else {
+            // if (c != null) {
             r.setSeriesFillPaint(idx, c);
-            r.setUseFillPaint(true);
-            r.setDrawOutlines(false);
+            r.setUseFillPaint(c != null);
+
+            r.setSeriesOutlinePaint(idx, c);
+            r.setDrawOutlines(c != null);
+            // }
         }
     }
 
-
     /**
      * Sets form and visibility of points.
      */
-    protected void applyShowPoints(XYLineAndShapeRenderer r, int idx) {
-        boolean show = theme.parseShowPoints();
+    private void applyShowPoints(final XYLineAndShapeRenderer r, final int idx) {
+        final boolean show = this.theme.parseShowPoints();
 
         r.setSeriesShapesVisible(idx, show);
         r.setDrawOutlines(true);
     }
 
+    // private void applyUseFillPaint(final XYLineAndShapeRenderer r) {
+    // final Boolean use = this.theme.parseUseFillPaint();
+    // if (use != null) {
+    // r.setUseFillPaint(use);
+    // }
+    // }
 
-    protected void applyShowLine(XYLineAndShapeRenderer r, int idx) {
-        boolean show = theme.parseShowLine();
+    private void applyShowLine(final XYLineAndShapeRenderer r, final int idx) {
+        final boolean show = this.theme.parseShowLine();
         r.setSeriesLinesVisible(idx, show);
     }
 
-
-    protected void applyShowMinimum(XYLineAndShapeRenderer r, int idx) {
+    private void applyShowMinimum(final XYLineAndShapeRenderer r, final int idx) {
         if (!(r instanceof EnhancedLineAndShapeRenderer)) {
             return;
         }
 
-        boolean visible = theme.parseShowMinimum();
+        final boolean visible = this.theme.parseShowMinimum();
 
-        EnhancedLineAndShapeRenderer er = (EnhancedLineAndShapeRenderer) r;
+        final EnhancedLineAndShapeRenderer er = (EnhancedLineAndShapeRenderer) r;
         er.setIsMinimumShapeVisisble(idx, visible);
     }
 
-
-    protected void applyShowMaximum(XYLineAndShapeRenderer r, int idx) {
+    private void applyShowMaximum(final XYLineAndShapeRenderer r, final int idx) {
         if (!(r instanceof EnhancedLineAndShapeRenderer)) {
             return;
         }
 
-        boolean visible = theme.parseShowMaximum();
+        final boolean visible = this.theme.parseShowMaximum();
 
-        EnhancedLineAndShapeRenderer er = (EnhancedLineAndShapeRenderer) r;
+        final EnhancedLineAndShapeRenderer er = (EnhancedLineAndShapeRenderer) r;
         er.setIsMaximumShapeVisible(idx, visible);
     }
 
-
     @Override
     public XYLineAndShapeRenderer getRenderer() {
         return this.renderer;
     }
-}
-// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
+}
\ No newline at end of file

http://dive4elements.wald.intevation.org