annotate src/java/de/intevation/mxd/reader/PictureLineSymbolReader.java @ 64:c73647bd71c0

Added picture line symbol reader.
author Raimund Renkert <rrenkert@intevation.de>
date Tue, 24 May 2011 17:32:43 +0200
parents
children 5ed9e720b6cd
rev   line source
64
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
1 package de.intevation.mxd.reader;
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
2
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
3 import java.io.IOException;
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
4
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
5 import java.awt.Color;
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
6 import java.awt.Image;
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
7
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
8 import org.apache.log4j.Logger;
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
9
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
10 import com.esri.arcgis.display.ISymbol;
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
11 import com.esri.arcgis.display.PictureLineSymbol;
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
12 import com.esri.arcgis.support.ms.stdole.Picture;
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
13 import com.esri.arcgis.display.esriSimpleLineStyle;
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
14 import com.esri.arcgis.display.IRgbColor;
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
15 import com.esri.arcgis.display.RgbColor;
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
16
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
17 import org.w3c.dom.Element;
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
18 import de.intevation.mxd.utils.MapToXMLUtils;
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
19
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
20 /**
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
21 * Reads picture line symbol information.
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
22 *
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
23 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
24 */
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
25 public class PictureLineSymbolReader implements ISymbolReader{
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
26
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
27 /**
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
28 * The logger.
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
29 */
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
30 private static final Logger logger =
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
31 Logger.getLogger(SimpleLineSymbolReader.class);
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
32
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
33 /**
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
34 * Private member.
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
35 */
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
36 private Element renderer;
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
37 private PictureLineSymbol symbol;
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
38 private MapToXMLUtils util;
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
39
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
40
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
41 public PictureLineSymbolReader(ISymbol symbol)
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
42 throws Exception {
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
43 logger.debug("contructor()");
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
44 if(symbol instanceof PictureLineSymbol) {
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
45 this.symbol = (PictureLineSymbol)symbol;
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
46 }
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
47 else {
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
48 throw new Exception("Not a PictureLineSymbol!");
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
49 }
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
50 }
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
51
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
52 /**
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
53 * Setter for the parent XML element.
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
54 *
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
55 * @param parent The XML parent node.
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
56 */
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
57 public void setParent(Element parent) {
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
58 this.renderer = parent;
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
59 }
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
60
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
61 /**
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
62 * Setter for XML document helper.
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
63 *
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
64 * @param util The helper class for storing map information.
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
65 */
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
66 public void setUtil(MapToXMLUtils util) {
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
67 this.util = util;
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
68 }
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
69
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
70 /**
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
71 * Reads the symbol attributes.
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
72 *
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
73 * @return The XML node.
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
74 */
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
75 public Element read()
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
76 throws IOException {
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
77 logger.debug("read()");
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
78 Element symbolElement;
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
79 try {
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
80 symbolElement = util.addSymbol(renderer);
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
81 }
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
82 catch(Exception e) {
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
83 e.printStackTrace();
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
84 return null;
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
85 }
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
86
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
87 symbolElement.setAttribute("name", symbol.getNameString());
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
88 symbolElement.setAttribute("style", "picture");
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
89 if(symbol.getColor() instanceof IRgbColor) {
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
90 IRgbColor color = (IRgbColor)symbol.getColor();
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
91 Color c = new Color (
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
92 color.getRed(),
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
93 color.getGreen(),
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
94 color.getBlue());
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
95 symbolElement.setAttribute("color", String.valueOf(c.getRGB()));
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
96 }
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
97 else {
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
98 RgbColor col = new RgbColor();
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
99 col.setRGB(symbol.getColor().getRGB());
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
100 Color c = new Color (
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
101 col.getRed(),
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
102 col.getGreen(),
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
103 col.getBlue());
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
104 symbolElement.setAttribute("color", String.valueOf(c.getRGB()));
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
105 }
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
106 symbolElement.setAttribute(
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
107 "offset",
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
108 String.valueOf(symbol.getOffset()));
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
109 symbolElement.setAttribute(
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
110 "x_scale",
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
111 String.valueOf(symbol.getXScale()));
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
112 symbolElement.setAttribute(
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
113 "y_scale",
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
114 String.valueOf(symbol.getYScale()));
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
115
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
116 symbolElement.setAttribute("width", String.valueOf(symbol.getWidth()));
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
117
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
118 Picture pic = symbol.getPicture();
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
119 Image im = pic.toImage();
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
120 //TODO Save the image.
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
121
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
122 return symbolElement;
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
123 }
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
124 }
c73647bd71c0 Added picture line symbol reader.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
125 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)