Mercurial > mxd2map
comparison src/java/de/intevation/mxd/writer/SymbolWriter.java @ 181:0bde090506f9
Added comments.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Mon, 11 Jul 2011 14:28:38 +0200 |
parents | d95dbd643add |
children | c79c3c6fc99a |
comparison
equal
deleted
inserted
replaced
180:f4eb506499f5 | 181:0bde090506f9 |
---|---|
25 /** | 25 /** |
26 * The Logger. | 26 * The Logger. |
27 */ | 27 */ |
28 private static final Logger logger = Logger.getLogger(SymbolWriter.class); | 28 private static final Logger logger = Logger.getLogger(SymbolWriter.class); |
29 | 29 |
30 /** | |
31 * Private member. | |
32 */ | |
30 private mapObj map; | 33 private mapObj map; |
31 private classObj cl; | 34 private classObj cl; |
32 | 35 |
36 /** | |
37 * Contructor with map object and class object. | |
38 * | |
39 * @param map The map object. | |
40 * @param cl The class object containing the style. | |
41 */ | |
33 public SymbolWriter (mapObj map, classObj cl) { | 42 public SymbolWriter (mapObj map, classObj cl) { |
34 this.map = map; | 43 this.map = map; |
35 this.cl = cl; | 44 this.cl = cl; |
36 } | 45 } |
37 | 46 |
38 /** | 47 /** |
39 * Write the content. | 48 * Write the content. |
49 * | |
50 * @param symbolElement DOM element containg the style and symbol | |
51 * attributes. | |
40 */ | 52 */ |
41 public boolean write(Element symbolElement) { | 53 public boolean write(Element symbolElement) { |
42 logger.debug("write(Element)"); | 54 logger.debug("write(Element)"); |
43 symbolSetObj symbolSet = map.getSymbolset(); | 55 symbolSetObj symbolSet = map.getSymbolset(); |
44 | 56 |
83 } | 95 } |
84 | 96 |
85 return true; | 97 return true; |
86 } | 98 } |
87 | 99 |
100 /** | |
101 * Create a simple point symbol. | |
102 * | |
103 * @param symbol The symbol object. | |
104 */ | |
88 private void writeSimple(symbolObj symbol) { | 105 private void writeSimple(symbolObj symbol) { |
89 logger.debug("writeSimple(symbolObj)"); | 106 logger.debug("writeSimple(symbolObj)"); |
90 lineObj points = new lineObj(); | 107 lineObj points = new lineObj(); |
91 points.add(new pointObj(1,1,0)); | 108 points.add(new pointObj(1,1,0)); |
92 symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_ELLIPSE.swigValue()); | 109 symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_ELLIPSE.swigValue()); |
93 symbol.setPoints(points); | 110 symbol.setPoints(points); |
94 symbol.setFilled(1); | 111 symbol.setFilled(1); |
95 } | 112 } |
96 | 113 |
114 /** | |
115 * Create an arrow symbol. | |
116 * | |
117 * @param symbol The symbol object. | |
118 * @param symbolElement DOM element containing symbol attributes. | |
119 */ | |
97 private void writeArrow(symbolObj symbol, Element symbolElement) { | 120 private void writeArrow(symbolObj symbol, Element symbolElement) { |
98 logger.debug("writeArrow(symbolObj, Element)"); | 121 logger.debug("writeArrow(symbolObj, Element)"); |
99 double len = 0; | 122 double len = 0; |
100 double width = 1; | 123 double width = 1; |
101 try { | 124 try { |
118 symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_VECTOR.swigValue()); | 141 symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_VECTOR.swigValue()); |
119 symbol.setPoints(points); | 142 symbol.setPoints(points); |
120 symbol.setFilled(1); | 143 symbol.setFilled(1); |
121 } | 144 } |
122 | 145 |
146 /** | |
147 * Create a character marker symbol. | |
148 * | |
149 * @param symbol The symbol object. | |
150 * @param symbolElement DOM element containing symbol attributes. | |
151 */ | |
123 private void writeCharacter(symbolObj symbol, Element symbolElement) { | 152 private void writeCharacter(symbolObj symbol, Element symbolElement) { |
124 logger.debug("writeCharacter(symbolObj, Element)"); | 153 logger.debug("writeCharacter(symbolObj, Element)"); |
125 //TODO Write the symbol correctly. See Issue 3885 on trac.osgeo.org | |
126 String font = symbolElement.getAttribute("font"); | 154 String font = symbolElement.getAttribute("font"); |
127 //Remove all blank character to match the mapserver fonts.txt. | 155 //Remove all blank character to match the mapserver fonts.txt. |
128 font = font.replaceAll(" ", ""); | 156 font = font.replaceAll(" ", ""); |
129 symbol.setName(symbolElement.getAttribute("name")); | 157 symbol.setName(symbolElement.getAttribute("name")); |
130 symbol.setFont(font); | 158 symbol.setFont(font); |
131 symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_TRUETYPE.swigValue()); | 159 symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_TRUETYPE.swigValue()); |
132 symbol.setAntialias(1); | 160 symbol.setAntialias(1); |
133 symbol.setCharacter("&#" + symbolElement.getAttribute("char") + ";"); | 161 symbol.setCharacter("&#" + symbolElement.getAttribute("char") + ";"); |
134 } | 162 } |
135 | 163 |
164 /** | |
165 * Create a hatch symbol for polygon fill. | |
166 * | |
167 * @param symbol The symbol object. | |
168 */ | |
136 private void writeHatch(symbolObj symbol) { | 169 private void writeHatch(symbolObj symbol) { |
137 logger.debug("writeHatch(symbolObj)"); | 170 logger.debug("writeHatch(symbolObj)"); |
138 symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_HATCH.swigValue()); | 171 symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_HATCH.swigValue()); |
139 } | 172 } |
140 | 173 |
174 /** | |
175 * Determine whether this writer can create the symbol. | |
176 * | |
177 * @param type The symbol type. | |
178 */ | |
141 public boolean canWrite(String type) { | 179 public boolean canWrite(String type) { |
142 if (type.equals("point") || | 180 if (type.equals("point") || |
143 type.equals("arrow") || | 181 type.equals("arrow") || |
144 type.equals("char") || | 182 type.equals("char") || |
145 type.equals("line")) { | 183 type.equals("line")) { |
148 else { | 186 else { |
149 return false; | 187 return false; |
150 } | 188 } |
151 } | 189 } |
152 | 190 |
191 /** | |
192 * Save the symbol set. | |
193 * | |
194 * @param symbols The symbol set object. | |
195 */ | |
153 private void saveSymbolSet(symbolSetObj symbols) | 196 private void saveSymbolSet(symbolSetObj symbols) |
154 throws Exception { | 197 throws Exception { |
155 String path = this.map.getMappath(); | 198 String path = this.map.getMappath(); |
156 String symbolPath = symbols.getFilename(); | 199 String symbolPath = symbols.getFilename(); |
157 if(path.equals("")) { | 200 if(path.equals("")) { |
176 path = path.replaceAll("\\\\", "/"); | 219 path = path.replaceAll("\\\\", "/"); |
177 symbols.save(path); | 220 symbols.save(path); |
178 this.map.setSymbolSet(symbolPath); | 221 this.map.setSymbolSet(symbolPath); |
179 } | 222 } |
180 | 223 |
224 /** | |
225 * Determine whether the symbol exists. | |
226 * | |
227 * @param elem DOM element containing the symbol attributes. | |
228 * | |
229 * @return Returns the symbol index if the symbol exists, else returns -1. | |
230 */ | |
181 private int symbolExists (Element elem) { | 231 private int symbolExists (Element elem) { |
182 symbolSetObj symbolSet = map.getSymbolset(); | 232 symbolSetObj symbolSet = map.getSymbolset(); |
183 for (int i = 0; i < symbolSet.getNumsymbols(); i++) { | 233 for (int i = 0; i < symbolSet.getNumsymbols(); i++) { |
184 symbolObj sym = symbolSet.getSymbol(i); | 234 symbolObj sym = symbolSet.getSymbol(i); |
185 int stype = sym.getType(); | 235 int stype = sym.getType(); |