changeset 1754:8e6615ad60b8

Added some simple caching for themes. Only used in sticky annotations by now. flys-artifacts/trunk@3057 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 21 Oct 2011 15:19:49 +0000
parents 741ba9e34c7d
children f7072039ad84
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/StyledXYSeries.java flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java flys-artifacts/src/main/java/de/intevation/flys/jfree/StickyAxisAnnotation.java flys-artifacts/src/main/java/de/intevation/flys/themes/ThemeAccess.java
diffstat 5 files changed, 124 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Fri Oct 21 14:02:07 2011 +0000
+++ b/flys-artifacts/ChangeLog	Fri Oct 21 15:19:49 2011 +0000
@@ -1,3 +1,17 @@
+2011-10-21	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/themes/ThemeAccess.java:
+	  New. Caching wrapper around an XML document theme. It uses ThemeUtil
+	  to access the values and stores them in instance variable.
+	  Background: ThemeUtil use XPath a lot which is expensive.
+
+	* src/main/java/de/intevation/flys/jfree/StickyAxisAnnotation.java,
+	  src/main/java/de/intevation/flys/exports/XYChartGenerator.java:
+	  Use ThemeAccess to style the annotations.
+
+	* src/main/java/de/intevation/flys/exports/StyledXYSeries.java:
+	  Removed some XPath strings. They are in ThemeUtil.
+
 2011-10-21  Raimund Renkert <raimund.renkert@intevation.de>
 
 	* src/main/java/de/intevation/flys/utils/ThemeUtil.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/StyledXYSeries.java	Fri Oct 21 14:02:07 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/StyledXYSeries.java	Fri Oct 21 15:19:49 2011 +0000
@@ -11,21 +11,11 @@
 import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
 import org.jfree.data.xy.XYSeries;
 
-import de.intevation.artifacts.common.utils.XMLUtils;
 import de.intevation.flys.utils.ThemeUtil;
 
 
 public class StyledXYSeries extends XYSeries {
 
-    public static final String XPATH_LINE_COLOR =
-        "/theme/field[@name='linecolor']/@default";
-
-    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;
 
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Fri Oct 21 14:02:07 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java	Fri Oct 21 15:19:49 2011 +0000
@@ -36,9 +36,9 @@
 
 import de.intevation.flys.exports.ChartExportHelper;
 import de.intevation.flys.jfree.FLYSAnnotation;
-import de.intevation.flys.utils.ThemeUtil;
 import de.intevation.flys.jfree.StickyAxisAnnotation;
 
+import de.intevation.flys.utils.ThemeAccess;
 
 /**
  * An abstract base class for creating XY charts.
@@ -446,24 +446,17 @@
         for (FLYSAnnotation fa: annotations) {
             Document theme = fa.getTheme();
 
-            Color color = theme != null
-                ? ThemeUtil.parseLineColorField(theme)
-                : null;
+            ThemeAccess themeAccess = new ThemeAccess(theme);
 
-            if (color == null) {
-                color = Color.black;
-            }
-
-            int lineWidth = theme != null
-                ? ThemeUtil.parseLineWidth(theme)
-                : 1;
+            Color color   = themeAccess.parseLineColorField();
+            int lineWidth = themeAccess.parseLineWidth();
 
             lic.add(new LegendItem(fa.getLabel(), color));
 
             for (XYTextAnnotation ta: fa.getAnnotations()) {
                 if(ta instanceof StickyAxisAnnotation) {
                     StickyAxisAnnotation sta = (StickyAxisAnnotation)ta;
-                    sta.applyTheme(theme);
+                    sta.applyTheme(themeAccess);
                     renderer.addAnnotation(sta);
                 }
                 else {
--- a/flys-artifacts/src/main/java/de/intevation/flys/jfree/StickyAxisAnnotation.java	Fri Oct 21 14:02:07 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/StickyAxisAnnotation.java	Fri Oct 21 15:19:49 2011 +0000
@@ -4,8 +4,6 @@
 
 import java.util.Iterator;
 
-import org.w3c.dom.Document;
-
 import java.awt.Shape;
 import java.awt.geom.Rectangle2D;
 import java.awt.geom.Line2D;
@@ -30,7 +28,7 @@
 import org.jfree.ui.RectangleEdge;
 import org.jfree.ui.TextAnchor;
 
-import de.intevation.flys.utils.ThemeUtil;
+import de.intevation.flys.utils.ThemeAccess;
 
 /**
  * Custom Annotations class that is drawn only if no collisions with other
@@ -346,14 +344,14 @@
     }
 
 
-    public void applyTheme(Document theme) {
-        lineWidth = ThemeUtil.parseLineWidth(theme);
-        lineColor = ThemeUtil.parseLineColorField(theme);
-        textColor = ThemeUtil.parseTextColor(theme);
-        font = ThemeUtil.parseTextFont(theme);
-        textOrientation = ThemeUtil.parseTextOrientation(theme);
-        textBackground = ThemeUtil.parseTextBackground(theme);
-        showBackground = ThemeUtil.parseShowTextBackground(theme);
+    public void applyTheme(ThemeAccess ta) {
+        lineWidth       = ta.parseLineWidth();
+        lineColor       = ta.parseLineColorField();
+        textColor       = ta.parseTextColor();
+        font            = ta.parseTextFont();
+        textOrientation = ta.parseTextOrientation();
+        textBackground  = ta.parseTextBackground();
+        showBackground  = ta.parseShowTextBackground();
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/themes/ThemeAccess.java	Fri Oct 21 15:19:49 2011 +0000
@@ -0,0 +1,96 @@
+package de.intevation.flys.utils;
+
+import java.awt.Color;
+import java.awt.Font;
+
+import org.w3c.dom.Document;
+
+
+public class ThemeAccess
+{
+    protected Document theme;
+
+    protected Integer lineWidth;
+
+    protected Color   lineColor;
+    protected Color   textColor;
+    protected Font    font;
+    protected String  textOrientation;
+    protected Color   textBackground;
+    protected Boolean showTextBackground;
+
+    public ThemeAccess(Document theme) {
+        this.theme = theme;
+    }
+
+    public int parseLineWidth() {
+        if (lineWidth == null) {
+            lineWidth = ThemeUtil.parseLineWidth(theme);
+        }
+        return lineWidth;
+    }
+
+    public Color parseLineColorField() {
+        if (lineColor == null) {
+            lineColor = ThemeUtil.parseLineColorField(theme);
+            if (lineColor == null) {
+                lineColor = Color.BLACK;
+            }
+        }
+        return lineColor;
+    }
+
+    public Color parseTextColor() {
+        if (textColor == null) {
+            textColor = ThemeUtil.parseTextColor(theme);
+            if (textColor == null) {
+                textColor = Color.BLACK;
+            }
+        }
+        return textColor;
+    }
+
+    public Font parseTextFont() {
+        if (font == null) {
+            font = ThemeUtil.parseTextFont(theme);
+            if (font == null) {
+                font = new Font("Arial", Font.BOLD, 10);
+            }
+        }
+        return font;
+    }
+
+    public String parseTextOrientation() {
+        if (textOrientation == null) {
+            textOrientation = ThemeUtil.parseTextOrientation(theme);
+            if (textOrientation == null) {
+                textOrientation = "horizontal";
+            }
+        }
+        return textOrientation;
+    }
+
+
+    public Color parseTextBackground() {
+        if (textBackground == null) {
+            textBackground = ThemeUtil.parseTextBackground(theme);
+            if (textBackground == null) {
+                textBackground = Color.WHITE;
+            }
+        }
+        return textBackground;
+    }
+
+    public boolean parseShowTextBackground() {
+        if (showTextBackground == null) {
+            showTextBackground = ThemeUtil.parseShowTextBackground(theme);
+        }
+        return showTextBackground;
+    }
+
+    /**
+    more of this
+    */
+
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org