changeset 75:9ea64427ac7e

Added marker fill symbol reader.
author Raimund Renkert <rrenkert@intevation.de>
date Fri, 27 May 2011 12:04:19 +0200 (2011-05-27)
parents 7eba97e8201b
children 3087c89a5bb8
files ChangeLog src/java/de/intevation/mxd/reader/FillSymbolReader.java src/java/de/intevation/mxd/reader/MarkerFillSymbolReader.java src/java/de/intevation/mxd/reader/MarkerSymbolReader.java src/java/de/intevation/mxd/reader/MultiLayerFillSymbolReader.java src/java/de/intevation/mxd/reader/SimpleMarkerSymbolReader.java
diffstat 6 files changed, 296 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu May 26 18:11:29 2011 +0200
+++ b/ChangeLog	Fri May 27 12:04:19 2011 +0200
@@ -1,3 +1,16 @@
+2011-05-27  Raimund Renkert  <raimund.renkert@intevation.de>
+
+	Added marker fill symbol reader.
+
+	* src/java/de/intevation/mxd/reader/FillSymbolReader.java,
+	  src/java/de/intevation/mxd/reader/MarkerSymbolReader.java,
+	  src/java/de/intevation/mxd/reader/MultiLayerFillSymbolReader.java,
+	  src/java/de/intevation/mxd/reader/SimpleMarkerSymbolReader.java:
+	  Use the new reader to get marker fill symbol attributes.
+
+	* src/java/de/intevation/mxd/reader/MarkerFillSymbolReader.java:
+	  New.
+
 2011-05-26  Raimund Renkert  <raimund.renkert@intevation.de>
 
 	* src/java/de/intevation/mxd/reader/ArrowMarkerSymbolReader.java,
--- a/src/java/de/intevation/mxd/reader/FillSymbolReader.java	Thu May 26 18:11:29 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/FillSymbolReader.java	Fri May 27 12:04:19 2011 +0200
@@ -10,6 +10,7 @@
 import com.esri.arcgis.display.IFillSymbol;
 import com.esri.arcgis.display.MultiLayerFillSymbol;
 import com.esri.arcgis.display.SimpleFillSymbol;
+import com.esri.arcgis.display.MarkerFillSymbol;
 
 /**
  * Wrapper for fill symbol reader.
@@ -55,6 +56,9 @@
             else if(symbol instanceof MultiLayerFillSymbol) {
                 sreader = new MultiLayerFillSymbolReader(symbol);
             }
+            else if(symbol instanceof MarkerFillSymbol) {
+                sreader = new MarkerFillSymbolReader(symbol);
+            }
             else {
                 logger.debug("The reader for type " + symbol.getClass().toString() +
                              " is not implemented!");
@@ -68,6 +72,9 @@
             else if(fillSymbol instanceof MultiLayerFillSymbol) {
                 sreader = new MultiLayerFillSymbolReader(fillSymbol);
             }
+            else if(fillSymbol instanceof MarkerFillSymbol) {
+                sreader = new MarkerFillSymbolReader(fillSymbol);
+            }
             else {
                 logger.debug("The reader for type " +
                              fillSymbol.getClass().toString() +
@@ -98,6 +105,7 @@
 
     public boolean canRead(ISymbol sym) {
         if(sym instanceof SimpleFillSymbol ||
+           sym instanceof MarkerFillSymbol ||
            sym instanceof MultiLayerFillSymbol) {
             return true;
         }
@@ -108,6 +116,7 @@
 
     public boolean canRead(IFillSymbol sym) {
         if(sym instanceof SimpleFillSymbol ||
+           sym instanceof MarkerFillSymbol ||
            sym instanceof MultiLayerFillSymbol) {
             return true;
         }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/java/de/intevation/mxd/reader/MarkerFillSymbolReader.java	Fri May 27 12:04:19 2011 +0200
@@ -0,0 +1,180 @@
+package de.intevation.mxd.reader;
+
+import java.io.IOException;
+
+import java.awt.Color;
+
+import org.apache.log4j.Logger;
+
+import com.esri.arcgis.display.ISymbol;
+import com.esri.arcgis.display.IFillSymbol;
+import com.esri.arcgis.display.ILineSymbol;
+import com.esri.arcgis.display.IMarkerSymbol;
+import com.esri.arcgis.display.MarkerFillSymbol;
+import com.esri.arcgis.display.esriSimpleFillStyle;
+import com.esri.arcgis.display.MultiLayerMarkerSymbol;
+import com.esri.arcgis.display.IRgbColor;
+import com.esri.arcgis.display.RgbColor;
+
+import org.w3c.dom.Element;
+import de.intevation.mxd.utils.MapToXMLUtils;
+
+/**
+ * Reads marker line symbol information.
+ *
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+public class MarkerFillSymbolReader implements ISymbolReader{
+
+    /**
+     * The logger.
+     */
+    private static final Logger logger =
+        Logger.getLogger(MarkerFillSymbolReader.class);
+
+    /**
+     * Private member.
+     */
+    private Element renderer;
+    private MarkerFillSymbol symbol;
+    private MapToXMLUtils util;
+
+
+    public MarkerFillSymbolReader(ISymbol symbol)
+    throws Exception {
+        logger.debug("contructor()");
+        if(symbol instanceof MarkerFillSymbol) {
+            this.symbol = (MarkerFillSymbol)symbol;
+        }
+        else {
+            throw new Exception("Not a MarkerFillSymbol!");
+        }
+    }
+
+
+    public MarkerFillSymbolReader(IFillSymbol symbol)
+    throws Exception {
+        logger.debug("contructor()");
+        if(symbol instanceof MarkerFillSymbol) {
+            this.symbol = (MarkerFillSymbol)symbol;
+        }
+        else {
+            throw new Exception("Not a MarkerFillSymbol!");
+        }
+    }
+
+    /**
+     * Setter for the parent XML element.
+     *
+     * @param parent The XML parent node.
+     */
+    public void setParent(Element parent) {
+        this.renderer = parent;
+    }
+
+    /**
+     * Setter for XML document helper.
+     *
+     * @param util The helper class for storing map information.
+     */
+    public void setUtil(MapToXMLUtils util) {
+        this.util = util;
+    }
+
+    /**
+     * Reads the symbol attributes.
+     *
+     * @return The XML node.
+     */
+    public Element read()
+    throws Exception {
+        logger.debug("read()");
+
+        Element symbolElement = util.addSymbol(renderer);
+
+        symbolElement.setAttribute("name", symbol.getNameString());
+        symbolElement.setAttribute("style", "fill");
+        symbolElement.setAttribute(
+            "xoffset",
+            String.valueOf(symbol.getXOffset()));
+        symbolElement.setAttribute(
+            "yoffset",
+            String.valueOf(symbol.getYOffset()));
+        symbolElement.setAttribute(
+            "xseparation",
+            String.valueOf(symbol.getXSeparation()));
+        symbolElement.setAttribute(
+            "yseparation",
+            String.valueOf(symbol.getYSeparation()));
+
+        int style = symbol.getStyle();
+        switch(style) {
+            case esriSimpleFillStyle.esriSFSCross:
+                symbolElement.setAttribute("fillstyle", "cross"); break;
+            case esriSimpleFillStyle.esriSFSSolid:
+                symbolElement.setAttribute("fillstyle", "solid"); break;
+            case esriSimpleFillStyle.esriSFSVertical:
+                symbolElement.setAttribute("fillstyle", "vertical"); break;
+            case esriSimpleFillStyle.esriSFSHorizontal:
+                symbolElement.setAttribute("fillstyle", "horizontal"); break;
+            case esriSimpleFillStyle.esriSFSForwardDiagonal:
+                symbolElement.setAttribute("fillstyle", "fwdiagonal"); break;
+            case esriSimpleFillStyle.esriSFSBackwardDiagonal:
+                symbolElement.setAttribute("fillstyle", "bwdiagonal"); break;
+            case esriSimpleFillStyle.esriSFSDiagonalCross:
+                symbolElement.setAttribute("fillstyle", "diagonalcross");
+                break;
+            default: symbolElement.setAttribute("fillstyle", "empty");
+        }
+
+        if(symbol.getColor() instanceof IRgbColor) {
+            IRgbColor color = (IRgbColor)symbol.getColor();
+            Color c = new Color (
+                color.getRed(),
+                color.getGreen(),
+                color.getBlue());
+            symbolElement.setAttribute("color", String.valueOf(c.getRGB()));
+            symbolElement.setAttribute("transparency",
+                String.valueOf(color.getTransparency()));
+        }
+        else {
+            RgbColor col = new RgbColor();
+            col.setRGB(symbol.getColor().getRGB());
+            Color c = new Color (
+                col.getRed(),
+                col.getGreen(),
+                col.getBlue());
+            symbolElement.setAttribute("color", String.valueOf(c.getRGB()));
+            symbolElement.setAttribute("transparency",
+                String.valueOf(col.getTransparency()));
+        }
+
+        ILineSymbol ls = symbol.getOutline();
+        LineSymbolReader lsr = new LineSymbolReader();
+        if(lsr.canRead(ls)) {
+            lsr.setSymbol(ls);
+            lsr.setUtil(util);
+            lsr.setParent(symbolElement);
+            lsr.read();
+        }
+        else {
+            logger.debug("The type of " + ls.getClass().toString() +
+                         " is not implemented!");
+        }
+
+        IMarkerSymbol sym = symbol.getMarkerSymbol();
+        MarkerSymbolReader msr = new MarkerSymbolReader();
+        if(msr.canRead(sym)) {
+            msr.setSymbol(sym);
+            msr.setParent(symbolElement);
+            msr.setUtil(util);
+            msr.read();
+        }
+        else {
+            logger.debug("The type of " + sym.getClass().toString() +
+                         " is not implemented!");
+        }
+        return renderer;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/src/java/de/intevation/mxd/reader/MarkerSymbolReader.java	Thu May 26 18:11:29 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/MarkerSymbolReader.java	Fri May 27 12:04:19 2011 +0200
@@ -7,6 +7,7 @@
 import org.apache.log4j.Logger;
 
 import com.esri.arcgis.display.ISymbol;
+import com.esri.arcgis.display.IMarkerSymbol;
 import com.esri.arcgis.display.SimpleMarkerSymbol;
 import com.esri.arcgis.display.ArrowMarkerSymbol;
 import com.esri.arcgis.display.CharacterMarkerSymbol;
@@ -25,58 +26,96 @@
      * The logger.
      */
     private static final Logger logger =
-        Logger.getLogger(SimpleFillSymbolReader.class);
+        Logger.getLogger(MarkerSymbolReader.class);
 
     private ISymbol symbol;
+    private IMarkerSymbol markerSymbol;
 
     public MarkerSymbolReader(ISymbol symbol)
     throws Exception {
         logger.debug("contructor(ISymbol)");
         this.symbol = symbol;
+        this.markerSymbol = null;
+    }
+
+    public MarkerSymbolReader(IMarkerSymbol symbol)
+    throws Exception {
+        logger.debug("contructor(ISymbol)");
+        this.markerSymbol = symbol;
+        this.symbol = null;
     }
 
     public MarkerSymbolReader() {
         logger.debug("contructor()");
         this.symbol = null;
+        this.markerSymbol = null;
     }
 
     public Element read()
     throws Exception {
-        if(symbol == null) {
-            return parent;
-        }
-
+        logger.debug("read()");
         ISymbolReader sreader = null;
-        if(symbol instanceof SimpleMarkerSymbol) {
-            sreader = new SimpleMarkerSymbolReader(symbol);
-        }
-        else if(symbol instanceof ArrowMarkerSymbol) {
-            sreader = new ArrowMarkerSymbolReader(symbol);
+
+        if(symbol != null) {
+            if(symbol instanceof SimpleMarkerSymbol) {
+                sreader = new SimpleMarkerSymbolReader(symbol);
+            }
+            else if(symbol instanceof ArrowMarkerSymbol) {
+                sreader = new ArrowMarkerSymbolReader(symbol);
+            }
+            else if(symbol instanceof CharacterMarkerSymbol) {
+                sreader = new CharacterMarkerSymbolReader(symbol);
+            }
+            else if(symbol instanceof PictureMarkerSymbol) {
+                sreader = new PictureMarkerSymbolReader(symbol);
+            }
+            else if(symbol instanceof MultiLayerMarkerSymbol) {
+                sreader = new MultiLayerMarkerSymbolReader(symbol);
+            }
+            else {
+                logger.debug("The reader for type " + symbol.getClass().toString() +
+                             " is not implemented!");
+                return parent;
+            }
         }
-        else if(symbol instanceof CharacterMarkerSymbol) {
-            sreader = new CharacterMarkerSymbolReader(symbol);
-        }
-        else if(symbol instanceof PictureMarkerSymbol) {
-            sreader = new PictureMarkerSymbolReader(symbol);
-        }
-        else if(symbol instanceof MultiLayerMarkerSymbol) {
-            sreader = new MultiLayerMarkerSymbolReader(symbol);
-        }
-        else {
-            logger.debug("The reader for type " + symbol.getClass().toString() +
-                         " is not implemented!");
-            return parent;
+        else if(markerSymbol != null) {
+            if(markerSymbol instanceof SimpleMarkerSymbol) {
+                sreader = new SimpleMarkerSymbolReader(markerSymbol);
+            }
+            else if(markerSymbol instanceof ArrowMarkerSymbol) {
+                sreader = new ArrowMarkerSymbolReader(markerSymbol);
+            }
+            else if(markerSymbol instanceof CharacterMarkerSymbol) {
+                sreader = new CharacterMarkerSymbolReader(markerSymbol);
+            }
+            else if(markerSymbol instanceof PictureMarkerSymbol) {
+                sreader = new PictureMarkerSymbolReader(markerSymbol);
+            }
+            else if(markerSymbol instanceof MultiLayerMarkerSymbol) {
+                sreader = new MultiLayerMarkerSymbolReader(markerSymbol);
+            }
+            else {
+                logger.debug("The reader for type " + symbol.getClass().toString() +
+                             " is not implemented!");
+                return parent;
+            }
         }
         if (sreader != null) {
             sreader.setParent(parent);
             sreader.setUtil(util);
-            return sreader.read();
+            sreader.read();
         }
         return parent;
     }
 
     public void setSymbol(ISymbol sym) {
         this.symbol = sym;
+        this.markerSymbol = null;
+    }
+
+    public void setSymbol(IMarkerSymbol sym) {
+        this.markerSymbol = sym;
+        this.symbol = null;
     }
 
     public boolean canRead(ISymbol sym) {
@@ -92,4 +131,17 @@
         }
     }
 
+    public boolean canRead(IMarkerSymbol sym) {
+        if(sym instanceof SimpleMarkerSymbol ||
+           sym instanceof ArrowMarkerSymbol ||
+           sym instanceof PictureMarkerSymbol ||
+           sym instanceof CharacterMarkerSymbol ||
+           sym instanceof MultiLayerMarkerSymbol) {
+            return true;
+        }
+        else {
+            return false;
+        }
+    }
+
 }
--- a/src/java/de/intevation/mxd/reader/MultiLayerFillSymbolReader.java	Thu May 26 18:11:29 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/MultiLayerFillSymbolReader.java	Fri May 27 12:04:19 2011 +0200
@@ -92,11 +92,12 @@
         for(int i = 0; i < symbol.getLayerCount(); i++) {
             ISymbol sym = (ISymbol)symbol.getLayer(i);
 
-            if(sym instanceof SimpleFillSymbol) {
-                ISymbolReader sreader = new SimpleFillSymbolReader(sym);
-                sreader.setParent(renderer);
-                sreader.setUtil(util);
-                sreader.read();
+            FillSymbolReader fsr = new FillSymbolReader();
+            if(fsr.canRead(sym)) {
+                fsr.setSymbol(sym);
+                fsr.setParent(renderer);
+                fsr.setUtil(util);
+                fsr.read();
             }
             else {
                 logger.debug("The type of " + sym.getClass().toString() +
--- a/src/java/de/intevation/mxd/reader/SimpleMarkerSymbolReader.java	Thu May 26 18:11:29 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/SimpleMarkerSymbolReader.java	Fri May 27 12:04:19 2011 +0200
@@ -7,6 +7,7 @@
 import org.apache.log4j.Logger;
 
 import com.esri.arcgis.display.ISymbol;
+import com.esri.arcgis.display.IMarkerSymbol;
 import com.esri.arcgis.display.SimpleMarkerSymbol;
 import com.esri.arcgis.display.esriSimpleMarkerStyle;
 import com.esri.arcgis.display.IRgbColor;
@@ -35,8 +36,18 @@
      */
     private SimpleMarkerSymbol symbol;
 
+    public SimpleMarkerSymbolReader(ISymbol symbol)
+    throws Exception {
+        logger.debug("contructor()");
+        if(symbol instanceof SimpleMarkerSymbol) {
+            this.symbol = (SimpleMarkerSymbol)symbol;
+        }
+        else {
+            throw new Exception("Not a SimpleMarkerSymbol!");
+        }
+    }
 
-    public SimpleMarkerSymbolReader(ISymbol symbol)
+    public SimpleMarkerSymbolReader(IMarkerSymbol symbol)
     throws Exception {
         logger.debug("contructor()");
         if(symbol instanceof SimpleMarkerSymbol) {
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)