root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / v02 / FSymbol.java @ 3591
History | View | Annotate | Download (26.7 KB)
1 |
/*
|
---|---|
2 |
* Created on 19-feb-2004
|
3 |
*
|
4 |
* To change the template for this generated file go to
|
5 |
* Window>Preferences>Java>Code Generation>Code and Comments
|
6 |
*/
|
7 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
8 |
*
|
9 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
10 |
*
|
11 |
* This program is free software; you can redistribute it and/or
|
12 |
* modify it under the terms of the GNU General Public License
|
13 |
* as published by the Free Software Foundation; either version 2
|
14 |
* of the License, or (at your option) any later version.
|
15 |
*
|
16 |
* This program is distributed in the hope that it will be useful,
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19 |
* GNU General Public License for more details.
|
20 |
*
|
21 |
* You should have received a copy of the GNU General Public License
|
22 |
* along with this program; if not, write to the Free Software
|
23 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
24 |
*
|
25 |
* For more information, contact:
|
26 |
*
|
27 |
* Generalitat Valenciana
|
28 |
* Conselleria d'Infraestructures i Transport
|
29 |
* Av. Blasco Ib??ez, 50
|
30 |
* 46010 VALENCIA
|
31 |
* SPAIN
|
32 |
*
|
33 |
* +34 963862235
|
34 |
* gvsig@gva.es
|
35 |
* www.gvsig.gva.es
|
36 |
*
|
37 |
* or
|
38 |
*
|
39 |
* IVER T.I. S.A
|
40 |
* Salamanca 50
|
41 |
* 46005 Valencia
|
42 |
* Spain
|
43 |
*
|
44 |
* +34 963163400
|
45 |
* dac@iver.es
|
46 |
*/
|
47 |
package com.iver.cit.gvsig.fmap.core.v02; |
48 |
|
49 |
import java.awt.BasicStroke; |
50 |
import java.awt.Color; |
51 |
import java.awt.Font; |
52 |
import java.awt.Graphics2D; |
53 |
import java.awt.Image; |
54 |
import java.awt.Paint; |
55 |
import java.awt.Rectangle; |
56 |
import java.awt.Stroke; |
57 |
import java.awt.image.BufferedImage; |
58 |
import java.net.MalformedURLException; |
59 |
import java.net.URI; |
60 |
import java.net.URISyntaxException; |
61 |
import java.util.StringTokenizer; |
62 |
|
63 |
import javax.swing.ImageIcon; |
64 |
|
65 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
66 |
import com.iver.cit.gvsig.fmap.core.FPolygon2D; |
67 |
import com.iver.cit.gvsig.fmap.core.FPolyline2D; |
68 |
import com.iver.cit.gvsig.fmap.core.FShape; |
69 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
70 |
import com.iver.cit.gvsig.fmap.core.ISLDCompatible; |
71 |
import com.iver.cit.gvsig.fmap.core.SLDTags; |
72 |
import com.iver.utiles.StringUtilities; |
73 |
import com.iver.utiles.XMLEntity; |
74 |
|
75 |
|
76 |
/**
|
77 |
* S?mbolo utilizado para guardar las caracter?sticas que se deben de aplicar a
|
78 |
* los Shapes a dibujar.
|
79 |
*
|
80 |
* @author Vicente Caballero Navarro
|
81 |
*/
|
82 |
public class FSymbol implements ISLDCompatible { |
83 |
private static BufferedImage img = new BufferedImage(1, 1, |
84 |
BufferedImage.TYPE_INT_ARGB);
|
85 |
private static Rectangle rect = new Rectangle(0, 0, 1, 1); |
86 |
private static Color selectionColor = Color.YELLOW; |
87 |
private int m_symbolType; |
88 |
private int m_Style; |
89 |
private boolean m_useOutline; |
90 |
private Color m_Color; |
91 |
private Color m_outlineColor; |
92 |
private Font m_Font; |
93 |
private Color m_FontColor; |
94 |
private float m_FontSize; |
95 |
private int rgb; |
96 |
|
97 |
/**
|
98 |
* Si <code>m_bUseFontSize</code> viene a false entonces m_FontSize viene
|
99 |
* en unidades de mapa (metros)
|
100 |
*/
|
101 |
private boolean m_bUseFontSizeInPixels; |
102 |
|
103 |
/**
|
104 |
* <code>m_bDrawShape</code> indica si queremos dibujar el shape de fondo.
|
105 |
* Es ?til cuando est?s etiquetando y no quieres que se dibuje el s?mbolo
|
106 |
* que te sirve de base para etiquetar.
|
107 |
*/
|
108 |
private boolean m_bDrawShape = true; |
109 |
private int m_Size; |
110 |
private Image m_Icon; |
111 |
private URI m_IconURI; |
112 |
private int m_Rotation; |
113 |
private Paint m_Fill; |
114 |
public String m_LinePattern = "0"; // Solo para poder mostrarlo cuando vamos a seleccionar un s?mbolo |
115 |
|
116 |
// En realidad lo podemos ver de BasicStroke, pero....
|
117 |
// ya veremos si luego lo quitamos.
|
118 |
private Stroke m_Stroke; |
119 |
|
120 |
//private float m_stroke=0;
|
121 |
// public int m_Transparency; // Ya la lleva dentro del Color
|
122 |
private boolean m_bUseSize; // Si est? a true, m_Size viene en coordenadas de mundo real. |
123 |
private int m_AlingVert; |
124 |
private int m_AlingHoriz; |
125 |
private String m_Descrip; |
126 |
public Color m_BackColor; |
127 |
public Paint m_BackFill; |
128 |
|
129 |
/**
|
130 |
* Converts the comma-delimited string into a List of trimmed strings.
|
131 |
*
|
132 |
* @param linePattern a String with comma-delimited values
|
133 |
* @param lineWidth DOCUMENT ME!
|
134 |
*
|
135 |
* @return a List of the Strings that were delimited by commas
|
136 |
*
|
137 |
* @throws IllegalArgumentException DOCUMENT ME!
|
138 |
*/
|
139 |
public static float[] toArray(String linePattern, float lineWidth) { |
140 |
StringTokenizer st = new StringTokenizer(linePattern, ","); |
141 |
int numTokens = st.countTokens();
|
142 |
|
143 |
float[] array = new float[numTokens]; |
144 |
|
145 |
for (int i = 0; i < numTokens; i++) { |
146 |
String string = st.nextToken();
|
147 |
array[i] = Float.parseFloat(string) * lineWidth;
|
148 |
|
149 |
if (array[i] <= 0) { |
150 |
return null; |
151 |
} |
152 |
} |
153 |
|
154 |
return array;
|
155 |
} |
156 |
|
157 |
/**
|
158 |
* Crea un nuevo FSymbol.
|
159 |
*/
|
160 |
FSymbol() { |
161 |
} |
162 |
|
163 |
/**
|
164 |
* Creates a new FSymbol object.
|
165 |
*
|
166 |
* @param tipoSymbol Tipo de s?mbolo.
|
167 |
* @param c Color.
|
168 |
*/
|
169 |
public FSymbol(int tipoSymbol, Color c) { |
170 |
createSymbol(tipoSymbol, c); |
171 |
} |
172 |
|
173 |
/**
|
174 |
* Crea un nuevo FSymbol.
|
175 |
*
|
176 |
* @param tipoSymbol Tipo de S?mbolo.
|
177 |
*/
|
178 |
public FSymbol(int tipoSymbol) { |
179 |
int numreg = (int) (Math.random() * 100); |
180 |
Color colorAleatorio = new Color(((numreg * numreg) + 100) % 255, |
181 |
(numreg + ((3 * numreg) + 100)) % 255, numreg % 255); |
182 |
|
183 |
createSymbol(tipoSymbol, colorAleatorio); |
184 |
} |
185 |
|
186 |
/**
|
187 |
* A partir de un s?mbolo devuelve otro similar pero con el color de
|
188 |
* selecci?n.
|
189 |
*
|
190 |
* @param sym S?mbolo a modificar.
|
191 |
*
|
192 |
* @return S?mbolo modificado.
|
193 |
*/
|
194 |
public static FSymbol getSymbolForSelection(FSymbol sym) { |
195 |
FSymbol selecSymbol = sym.fastCloneSymbol(); |
196 |
selecSymbol.setColor(getSelectionColor()); |
197 |
selecSymbol.setFill(null);
|
198 |
// 050215, jmorell: Si en los drivers cambiamos el estilo, aqu? tenemos que
|
199 |
// actualizar los cambios. SYMBOL_STYLE_MARKER_SQUARE --> SYMBOL_STYLE_DGNSPECIAL.
|
200 |
if ((selecSymbol.getStyle() == FConstant.SYMBOL_STYLE_FILL_TRANSPARENT)
|
201 |
|| (selecSymbol.getStyle() == FConstant.SYMBOL_STYLE_DGNSPECIAL)) |
202 |
selecSymbol.setStyle(FConstant.SYMBOL_STYLE_FILL_SOLID); |
203 |
selecSymbol.rgb = getSelectionColor().getRGB(); |
204 |
|
205 |
return selecSymbol;
|
206 |
} |
207 |
|
208 |
/**
|
209 |
* Clona el s?mbolo actual.
|
210 |
*
|
211 |
* @return Nuevo s?mbolo clonado.
|
212 |
*/
|
213 |
public FSymbol cloneSymbol() {
|
214 |
return createFromXML(getXMLEntity());
|
215 |
} |
216 |
|
217 |
/**
|
218 |
* Se usa para el s?mbolo de selecci?n. Es una forma
|
219 |
* r?pida de clonar un s?mbolo, sin hacerlo via XML.
|
220 |
* Vicente, no lo borres!!!
|
221 |
* @return
|
222 |
*/
|
223 |
public FSymbol fastCloneSymbol()
|
224 |
{ |
225 |
FSymbol nS = new FSymbol();
|
226 |
|
227 |
|
228 |
nS.m_symbolType = m_symbolType; |
229 |
nS.m_Style = m_Style; |
230 |
nS.m_useOutline = m_useOutline; |
231 |
nS.m_Color = m_Color; |
232 |
nS.m_outlineColor = m_outlineColor; |
233 |
nS.m_Font = m_Font; |
234 |
nS.m_FontColor = m_FontColor; |
235 |
nS.m_FontSize = m_FontSize; |
236 |
nS.m_bUseFontSizeInPixels = m_bUseFontSizeInPixels; |
237 |
nS.m_bDrawShape = m_bDrawShape; |
238 |
nS.m_Size = m_Size; |
239 |
nS.m_Icon = m_Icon; |
240 |
nS.m_IconURI = m_IconURI; |
241 |
nS.m_Rotation = m_Rotation; |
242 |
nS.m_Fill = m_Fill; |
243 |
nS.m_Stroke = m_Stroke; |
244 |
// nS.m_Transparency =m_Transparency ;
|
245 |
nS.m_bUseSize = m_bUseSize; |
246 |
nS.m_AlingVert = m_AlingVert; |
247 |
nS.m_AlingHoriz = m_AlingHoriz; |
248 |
nS.m_Descrip = m_Descrip; |
249 |
nS.m_BackColor = m_BackColor; |
250 |
nS.m_BackFill = m_BackFill; |
251 |
|
252 |
nS.m_LinePattern = m_LinePattern; |
253 |
|
254 |
return nS;
|
255 |
} |
256 |
|
257 |
|
258 |
/**
|
259 |
* Crea un s?mbolo a partir del tipo y el color.
|
260 |
*
|
261 |
* @param tipoSymbol Tipo de s?mbolo.
|
262 |
* @param c Color del s?mbolo a crear.
|
263 |
*/
|
264 |
private void createSymbol(int tipoSymbol, Color c) { |
265 |
// OJO: HE HECHO COINCIDIR LOS TIPOS DE SIMBOLO
|
266 |
//FConstant.SYMBOL_TYPE_POINT, LINE Y FILL CON
|
267 |
// FShape.POINT, LINE, POLYGON. EL .MULTI SE REFIERE
|
268 |
// A MULTIPLES TIPO DENTRO DEL SHAPE, AS? QUE SER? UN
|
269 |
// MULTISIMBOLO
|
270 |
// Tipo de simbolo
|
271 |
m_symbolType = tipoSymbol; // Para no recalcular el pixel, no usamos los set
|
272 |
|
273 |
// Ponemos un estilo por defecto
|
274 |
m_useOutline = true;
|
275 |
m_Color = c; |
276 |
m_Stroke = null;
|
277 |
m_Fill = null;
|
278 |
|
279 |
m_FontColor = Color.BLACK;
|
280 |
m_FontSize = 10;
|
281 |
m_bUseFontSizeInPixels = true;
|
282 |
|
283 |
m_Size = 2;
|
284 |
|
285 |
switch (getSymbolType()) {
|
286 |
case FConstant.SYMBOL_TYPE_POINT:
|
287 |
case FConstant.SYMBOL_TYPE_POINTZ:
|
288 |
case FConstant.SYMBOL_TYPE_MULTIPOINT:
|
289 |
m_bUseSize = true; // Esto es lo primero que hay que hacer siempre |
290 |
|
291 |
// para evitar un StackOverflow
|
292 |
m_useOutline = false;
|
293 |
setStyle(FConstant.SYMBOL_STYLE_MARKER_SQUARE); |
294 |
setSize(5); //pixels |
295 |
|
296 |
break;
|
297 |
|
298 |
case FConstant.SYMBOL_TYPE_LINE:
|
299 |
case FConstant.SYMBOL_TYPE_POLYLINEZ:
|
300 |
case FConstant.SYMBOL_TYPE_POLYGONZ:
|
301 |
setStroke(new BasicStroke()); |
302 |
setStyle(FConstant.SYMBOL_STYLE_LINE_SOLID); |
303 |
|
304 |
break;
|
305 |
|
306 |
case FConstant.SYMBOL_TYPE_FILL:
|
307 |
case FShape.MULTI:
|
308 |
setStroke(new BasicStroke()); |
309 |
setStyle(FConstant.SYMBOL_STYLE_FILL_SOLID); |
310 |
|
311 |
break;
|
312 |
} |
313 |
|
314 |
m_outlineColor = c.darker(); |
315 |
|
316 |
calculateRgb(); |
317 |
} |
318 |
|
319 |
/**
|
320 |
* Calcula el RGB del s?mbolo.
|
321 |
*/
|
322 |
public void calculateRgb() { |
323 |
// Recalculamos el RGB
|
324 |
Graphics2D g2 = img.createGraphics();
|
325 |
|
326 |
FGraphicUtilities.DrawSymbol(g2, g2.getTransform(), rect, this);
|
327 |
rgb = img.getRGB(0, 0); |
328 |
} |
329 |
|
330 |
/**
|
331 |
* Devuelve el rgb del s?mbolo.
|
332 |
*
|
333 |
* @return rgb del s?mbolo.
|
334 |
*/
|
335 |
public int getRgb() { |
336 |
return rgb;
|
337 |
} |
338 |
|
339 |
/**
|
340 |
* @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getXMLEntity()
|
341 |
*/
|
342 |
public XMLEntity getXMLEntity() {
|
343 |
XMLEntity xml = new XMLEntity();
|
344 |
xml.putProperty("className",this.getClass().getName()); |
345 |
xml.putProperty("m_symbolType", getSymbolType());
|
346 |
xml.putProperty("m_Style", getStyle());
|
347 |
xml.putProperty("m_useOutline", isOutlined());
|
348 |
|
349 |
if (getColor() != null) { |
350 |
xml.putProperty("m_Color", StringUtilities.color2String(getColor()));
|
351 |
} |
352 |
|
353 |
if (getOutlineColor() != null) { |
354 |
xml.putProperty("m_outlineColor",
|
355 |
StringUtilities.color2String(getOutlineColor())); |
356 |
} |
357 |
|
358 |
if (getFont() != null) { |
359 |
xml.putProperty("fontname", getFont().getName());
|
360 |
xml.putProperty("fontstyle", getFont().getStyle());
|
361 |
|
362 |
xml.putProperty("m_FontSize", getFontSize());
|
363 |
xml.putProperty("m_FontColor",
|
364 |
StringUtilities.color2String(getFontColor())); |
365 |
|
366 |
} |
367 |
xml.putProperty("m_bUseFontSize", isFontSizeInPixels());
|
368 |
xml.putProperty("m_bDrawShape", isShapeVisible());
|
369 |
xml.putProperty("m_Size", getSize());
|
370 |
|
371 |
//xml.putProperty("m_Icon",m_Icon.);
|
372 |
xml.putProperty("m_Rotation", getRotation());
|
373 |
|
374 |
if (getFill() instanceof Color) { |
375 |
xml.putProperty("m_Fill",
|
376 |
StringUtilities.color2String((Color) getFill()));
|
377 |
} |
378 |
else
|
379 |
if (getFill() != null) |
380 |
{ |
381 |
xml.putProperty("m_Fill", "WithFill"); |
382 |
} |
383 |
|
384 |
|
385 |
xml.putProperty("m_LinePattern", m_LinePattern);
|
386 |
|
387 |
//Ancho del stroke en float
|
388 |
if (getStroke() != null) { |
389 |
xml.putProperty("m_stroke",
|
390 |
((BasicStroke) getStroke()).getLineWidth());
|
391 |
} else {
|
392 |
xml.putProperty("m_stroke", 0f); |
393 |
} |
394 |
|
395 |
xml.putProperty("m_bUseSize", isSizeInPixels());
|
396 |
xml.putProperty("m_AlingVert", getAlingVert());
|
397 |
xml.putProperty("m_AlingHoriz", getAlingHoriz());
|
398 |
xml.putProperty("m_Descrip", getDescription());
|
399 |
|
400 |
if (m_BackColor != null) { |
401 |
xml.putProperty("m_BackColor",
|
402 |
StringUtilities.color2String(m_BackColor)); |
403 |
} |
404 |
|
405 |
if (m_BackFill instanceof Color) { |
406 |
xml.putProperty("m_BackFill",
|
407 |
StringUtilities.color2String((Color) m_BackFill));
|
408 |
} |
409 |
|
410 |
xml.putProperty("rgb", rgb);
|
411 |
|
412 |
if (m_Icon != null) |
413 |
{ |
414 |
xml.putProperty("m_IconURI", m_IconURI);
|
415 |
} |
416 |
|
417 |
return xml;
|
418 |
} |
419 |
/**
|
420 |
* Crea el s?mbolo a partir del xml.
|
421 |
*
|
422 |
* @param xml xml que contiene la informaci?n para crear el s?mbolo.
|
423 |
*
|
424 |
* @return S?mbolo creado a partir del XML.
|
425 |
*/
|
426 |
public static FSymbol createFromXML03(XMLEntity xml) { |
427 |
FSymbol symbol = new FSymbol();
|
428 |
symbol.setSymbolType(xml.getIntProperty("m_symbolType"));
|
429 |
symbol.setStyle(xml.getIntProperty("m_Style"));
|
430 |
// System.out.println("createFromXML: m_Style=" + xml.getIntProperty("m_Style"));
|
431 |
|
432 |
symbol.setOutlined(xml.getBooleanProperty("m_useOutline"));
|
433 |
|
434 |
if (xml.contains("m_Color")) { |
435 |
symbol.setColor(StringUtilities.string2Color(xml.getStringProperty( |
436 |
"m_Color")));
|
437 |
} |
438 |
|
439 |
if (xml.contains("m_outlineColor")) { |
440 |
symbol.setOutlineColor(StringUtilities.string2Color( |
441 |
xml.getStringProperty("m_outlineColor")));
|
442 |
} |
443 |
|
444 |
if (xml.contains("m_FontColor")) { |
445 |
symbol.setFont(new Font(xml.getStringProperty("fontname"), |
446 |
xml.getIntProperty("fontstyle"),
|
447 |
(int) xml.getFloatProperty("m_FontSize"))); |
448 |
symbol.setFontColor(StringUtilities.string2Color( |
449 |
xml.getStringProperty("m_FontColor")));
|
450 |
symbol.setFontSize(xml.getFloatProperty("m_FontSize"));
|
451 |
} |
452 |
|
453 |
symbol.setFontSizeInPixels(xml.getBooleanProperty("m_bUseFontSize"));
|
454 |
symbol.setShapeVisible(xml.getBooleanProperty("m_bDrawShape"));
|
455 |
symbol.setSize(xml.getIntProperty("m_Size"));
|
456 |
|
457 |
//xml.putProperty("m_Icon",m_Icon.);
|
458 |
symbol.setRotation(xml.getIntProperty("m_Rotation"));
|
459 |
|
460 |
if (xml.contains("m_Fill")) { |
461 |
// TODO: Si es un Fill de tipo imagen, deber?amos recuperar la imagen.
|
462 |
String strFill = xml.getStringProperty("m_Fill"); |
463 |
if (strFill.compareTo("WithFill") == 0) |
464 |
symbol.setFill(FSymbolFactory.createPatternFill(symbol.getStyle(), symbol.getColor())); |
465 |
else
|
466 |
symbol.setFill(StringUtilities.string2Color(strFill)); |
467 |
} |
468 |
|
469 |
|
470 |
symbol.m_LinePattern = xml.getStringProperty("m_LinePattern");
|
471 |
|
472 |
//Ancho del stroke en float
|
473 |
symbol.setStroke(new BasicStroke(xml.getFloatProperty("m_stroke"))); |
474 |
symbol.setSizeInPixels(xml.getBooleanProperty("m_bUseSize"));
|
475 |
symbol.setAlingVert(xml.getIntProperty("m_AlingVert"));
|
476 |
symbol.setAlingHoriz(xml.getIntProperty("m_AlingHoriz"));
|
477 |
symbol.setDescription(xml.getStringProperty("m_Descrip"));
|
478 |
|
479 |
if (xml.contains("m_BackColor")) { |
480 |
symbol.m_BackColor = StringUtilities.string2Color(xml.getStringProperty( |
481 |
"m_BackColor"));
|
482 |
} |
483 |
|
484 |
if (xml.contains("m_BackFill")) { |
485 |
symbol.m_BackFill = StringUtilities.string2Color(xml.getStringProperty( |
486 |
"m_BackFill"));
|
487 |
} |
488 |
|
489 |
symbol.rgb = xml.getIntProperty("rgb");
|
490 |
|
491 |
if (xml.contains("m_IconURI")) { |
492 |
try {
|
493 |
symbol.setIconURI(new URI(xml.getStringProperty("m_IconURI"))); |
494 |
} catch (URISyntaxException e) { |
495 |
// TODO Auto-generated catch block
|
496 |
e.printStackTrace(); |
497 |
} |
498 |
} |
499 |
|
500 |
return symbol;
|
501 |
} |
502 |
|
503 |
/**
|
504 |
* Crea el s?mbolo a partir del xml.
|
505 |
*
|
506 |
* @param xml xml que contiene la informaci?n para crear el s?mbolo.
|
507 |
*
|
508 |
* @return S?mbolo creado a partir del XML.
|
509 |
*/
|
510 |
public static FSymbol createFromXML(XMLEntity xml) { |
511 |
FSymbol symbol = new FSymbol();
|
512 |
symbol.setSymbolType(xml.getIntProperty("m_symbolType"));
|
513 |
symbol.setStyle(xml.getIntProperty("m_Style"));
|
514 |
// System.out.println("createFromXML: m_Style=" + xml.getIntProperty("m_Style"));
|
515 |
|
516 |
symbol.setOutlined(xml.getBooleanProperty("m_useOutline"));
|
517 |
|
518 |
if (xml.contains("m_Color")) { |
519 |
symbol.setColor(StringUtilities.string2Color(xml.getStringProperty( |
520 |
"m_Color")));
|
521 |
} |
522 |
|
523 |
if (xml.contains("m_outlineColor")) { |
524 |
symbol.setOutlineColor(StringUtilities.string2Color( |
525 |
xml.getStringProperty("m_outlineColor")));
|
526 |
} |
527 |
|
528 |
if (xml.contains("fontname")) { |
529 |
symbol.setFont(new Font(xml.getStringProperty("fontname"), |
530 |
xml.getIntProperty("fontstyle"),
|
531 |
(int) xml.getFloatProperty("m_FontSize"))); |
532 |
|
533 |
symbol.setFontColor(StringUtilities.string2Color( |
534 |
xml.getStringProperty("m_FontColor")));
|
535 |
symbol.setFontSize(xml.getFloatProperty("m_FontSize"));
|
536 |
|
537 |
} |
538 |
symbol.setFontSizeInPixels(xml.getBooleanProperty("m_bUseFontSize"));
|
539 |
symbol.setShapeVisible(xml.getBooleanProperty("m_bDrawShape"));
|
540 |
symbol.setSize(xml.getIntProperty("m_Size"));
|
541 |
|
542 |
//xml.putProperty("m_Icon",m_Icon.);
|
543 |
symbol.setRotation(xml.getIntProperty("m_Rotation"));
|
544 |
|
545 |
if (xml.contains("m_Fill")) { |
546 |
// TODO: Si es un Fill de tipo imagen, deber?amos recuperar la imagen.
|
547 |
String strFill = xml.getStringProperty("m_Fill"); |
548 |
if (strFill.compareTo("WithFill") == 0) |
549 |
symbol.setFill(FSymbolFactory.createPatternFill(symbol.getStyle(), symbol.getColor())); |
550 |
else
|
551 |
symbol.setFill(StringUtilities.string2Color(strFill)); |
552 |
} |
553 |
|
554 |
|
555 |
symbol.m_LinePattern = xml.getStringProperty("m_LinePattern");
|
556 |
|
557 |
//Ancho del stroke en float
|
558 |
float lineWidth = xml.getFloatProperty("m_stroke"); |
559 |
if (symbol.m_LinePattern.compareTo("0") == 0) |
560 |
{ |
561 |
symbol.setStroke(new BasicStroke(lineWidth)); |
562 |
} |
563 |
else
|
564 |
{ |
565 |
symbol.setStroke(new BasicStroke(lineWidth, BasicStroke.CAP_ROUND, |
566 |
BasicStroke.JOIN_BEVEL, 1.0f, |
567 |
toArray(symbol.m_LinePattern, lineWidth), 0));
|
568 |
} |
569 |
|
570 |
symbol.setSizeInPixels(xml.getBooleanProperty("m_bUseSize"));
|
571 |
symbol.setAlingVert(xml.getIntProperty("m_AlingVert"));
|
572 |
symbol.setAlingHoriz(xml.getIntProperty("m_AlingHoriz"));
|
573 |
symbol.setDescription(xml.getStringProperty("m_Descrip"));
|
574 |
|
575 |
if (xml.contains("m_BackColor")) { |
576 |
symbol.m_BackColor = StringUtilities.string2Color(xml.getStringProperty( |
577 |
"m_BackColor"));
|
578 |
} |
579 |
|
580 |
if (xml.contains("m_BackFill")) { |
581 |
symbol.m_BackFill = StringUtilities.string2Color(xml.getStringProperty( |
582 |
"m_BackFill"));
|
583 |
} |
584 |
|
585 |
symbol.rgb = xml.getIntProperty("rgb");
|
586 |
|
587 |
if (xml.contains("m_IconURI")) { |
588 |
try {
|
589 |
symbol.setIconURI(new URI(xml.getStringProperty("m_IconURI"))); |
590 |
} catch (URISyntaxException e) { |
591 |
// TODO Auto-generated catch block
|
592 |
e.printStackTrace(); |
593 |
} |
594 |
} |
595 |
|
596 |
return symbol;
|
597 |
} |
598 |
|
599 |
/**
|
600 |
* Introduce el estilo del s?mbolo.
|
601 |
*
|
602 |
* @param m_Style The m_Style to set.
|
603 |
*/
|
604 |
public void setStyle(int m_Style) { |
605 |
this.m_Style = m_Style;
|
606 |
|
607 |
// calculateRgb();
|
608 |
} |
609 |
|
610 |
/**
|
611 |
* Devuelve el estilo del s?mbolo.
|
612 |
*
|
613 |
* @return Returns the m_Style.
|
614 |
*/
|
615 |
public int getStyle() { |
616 |
return m_Style;
|
617 |
} |
618 |
|
619 |
/**
|
620 |
* Introduce el tipo de s?mbolo.
|
621 |
*
|
622 |
* @param m_symbolType The m_symbolType to set.
|
623 |
*/
|
624 |
public void setSymbolType(int m_symbolType) { |
625 |
this.m_symbolType = m_symbolType;
|
626 |
} |
627 |
|
628 |
/**
|
629 |
* Devuelve el tipo de s?mbolo.
|
630 |
*
|
631 |
* @return Returns the m_symbolType.
|
632 |
*/
|
633 |
public int getSymbolType() { |
634 |
return m_symbolType;
|
635 |
} |
636 |
|
637 |
/**
|
638 |
* Introduce si el s?mbolo contiene linea de brode o no.
|
639 |
*
|
640 |
* @param m_useOutline The m_useOutline to set.
|
641 |
*/
|
642 |
public void setOutlined(boolean m_useOutline) { |
643 |
this.m_useOutline = m_useOutline;
|
644 |
|
645 |
// calculateRgb();
|
646 |
} |
647 |
|
648 |
/**
|
649 |
* Devuelve si el s?mbolo contiene o no linea de borde.
|
650 |
*
|
651 |
* @return Returns the m_useOutline.
|
652 |
*/
|
653 |
public boolean isOutlined() { |
654 |
return m_useOutline;
|
655 |
} |
656 |
|
657 |
/**
|
658 |
* Introduce el color del s?mbolo.
|
659 |
*
|
660 |
* @param m_Color The m_Color to set.
|
661 |
*/
|
662 |
public void setColor(Color m_Color) { |
663 |
this.m_Color = m_Color;
|
664 |
calculateRgb(); |
665 |
} |
666 |
|
667 |
/**
|
668 |
* Devuelve el color del s?mbolo.
|
669 |
*
|
670 |
* @return Returns the m_Color.
|
671 |
*/
|
672 |
public Color getColor() { |
673 |
return m_Color;
|
674 |
} |
675 |
|
676 |
/**
|
677 |
* Introduce el color de la l?nea de borde.
|
678 |
*
|
679 |
* @param m_outlineColor The m_outlineColor to set.
|
680 |
*/
|
681 |
public void setOutlineColor(Color m_outlineColor) { |
682 |
this.m_outlineColor = m_outlineColor;
|
683 |
|
684 |
// calculateRgb();
|
685 |
} |
686 |
|
687 |
/**
|
688 |
* Devuelve el color de la l?nea de borde.
|
689 |
*
|
690 |
* @return Returns the m_outlineColor.
|
691 |
*/
|
692 |
public Color getOutlineColor() { |
693 |
return m_outlineColor;
|
694 |
} |
695 |
|
696 |
/**
|
697 |
* Introduce el Font del s?mbolo.
|
698 |
*
|
699 |
* @param m_Font The m_Font to set.
|
700 |
*/
|
701 |
public void setFont(Font m_Font) { |
702 |
this.m_Font = m_Font;
|
703 |
|
704 |
// calculateRgb();
|
705 |
} |
706 |
|
707 |
/**
|
708 |
* Devuelve el Font del s?mbolo.
|
709 |
*
|
710 |
* @return Returns the m_Font.
|
711 |
*/
|
712 |
public Font getFont() { |
713 |
return m_Font;
|
714 |
} |
715 |
|
716 |
/**
|
717 |
* Introduce el color de la fuente.
|
718 |
*
|
719 |
* @param m_FontColor The m_FontColor to set.
|
720 |
*/
|
721 |
public void setFontColor(Color m_FontColor) { |
722 |
this.m_FontColor = m_FontColor;
|
723 |
|
724 |
// calculateRgb();
|
725 |
} |
726 |
|
727 |
/**
|
728 |
* Devuelve el color de la fuente.
|
729 |
*
|
730 |
* @return Returns the m_FontColor.
|
731 |
*/
|
732 |
public Color getFontColor() { |
733 |
return m_FontColor;
|
734 |
} |
735 |
|
736 |
/**
|
737 |
* Introduce si se usa el tama?o de la fuente en pixels.
|
738 |
*
|
739 |
* @param m_bUseFontSize The m_bUseFontSize to set.
|
740 |
*/
|
741 |
public void setFontSizeInPixels(boolean m_bUseFontSize) { |
742 |
this.m_bUseFontSizeInPixels = m_bUseFontSize;
|
743 |
|
744 |
// calculateRgb();
|
745 |
} |
746 |
|
747 |
/**
|
748 |
* Devuelve true si el tama?o de la fuente esta seleccionado en pixels.
|
749 |
*
|
750 |
* @return Returns the m_bUseFontSize.
|
751 |
*/
|
752 |
public boolean isFontSizeInPixels() { |
753 |
return m_bUseFontSizeInPixels;
|
754 |
} |
755 |
|
756 |
/**
|
757 |
* Introduce si el shape e visible o no lo es.
|
758 |
*
|
759 |
* @param m_bDrawShape The m_bDrawShape to set.
|
760 |
*/
|
761 |
public void setShapeVisible(boolean m_bDrawShape) { |
762 |
this.m_bDrawShape = m_bDrawShape;
|
763 |
|
764 |
// calculateRgb();
|
765 |
} |
766 |
|
767 |
/**
|
768 |
* Devuelve true si el shape es visible.
|
769 |
*
|
770 |
* @return Returns the m_bDrawShape.
|
771 |
*/
|
772 |
public boolean isShapeVisible() { |
773 |
return m_bDrawShape;
|
774 |
} |
775 |
|
776 |
/**
|
777 |
* Introduce el tama?o del s?mbolo.
|
778 |
*
|
779 |
* @param m_Size The m_Size to set.
|
780 |
*/
|
781 |
public void setSize(int m_Size) { |
782 |
this.m_Size = m_Size;
|
783 |
|
784 |
// calculateRgb();
|
785 |
} |
786 |
|
787 |
/**
|
788 |
* Devuelve el tama?o del s?mbolo.
|
789 |
*
|
790 |
* @return Returns the m_Size.
|
791 |
*/
|
792 |
public int getSize() { |
793 |
return m_Size;
|
794 |
} |
795 |
|
796 |
/**
|
797 |
* Introduce la imagen que hace de icono.
|
798 |
*
|
799 |
* @param m_Icon The m_Icon to set.
|
800 |
*/
|
801 |
public void setIcon(Image m_Icon) { |
802 |
this.m_Icon = m_Icon;
|
803 |
|
804 |
// calculateRgb();
|
805 |
} |
806 |
|
807 |
/**
|
808 |
* Devuelve el icono.
|
809 |
*
|
810 |
* @return Returns the m_Icon.
|
811 |
*/
|
812 |
public Image getIcon() { |
813 |
return m_Icon;
|
814 |
} |
815 |
|
816 |
/**
|
817 |
* Introduce la rotaci?n.
|
818 |
*
|
819 |
* @param m_Rotation The m_Rotation to set.
|
820 |
*/
|
821 |
public void setRotation(int m_Rotation) { |
822 |
this.m_Rotation = m_Rotation;
|
823 |
|
824 |
// calculateRgb();
|
825 |
} |
826 |
|
827 |
/**
|
828 |
* Devuelve la rotaci?n.
|
829 |
*
|
830 |
* @return Returns the m_Rotation.
|
831 |
*/
|
832 |
public int getRotation() { |
833 |
return m_Rotation;
|
834 |
} |
835 |
|
836 |
/**
|
837 |
* Introduce el relleno.
|
838 |
*
|
839 |
* @param m_Fill The m_Fill to set.
|
840 |
*/
|
841 |
public void setFill(Paint m_Fill) { |
842 |
this.m_Fill = m_Fill;
|
843 |
|
844 |
// calculateRgb();
|
845 |
} |
846 |
|
847 |
/**
|
848 |
* Devuelve el relleno.
|
849 |
*
|
850 |
* @return Returns the m_Fill.
|
851 |
*/
|
852 |
public Paint getFill() { |
853 |
return m_Fill;
|
854 |
} |
855 |
|
856 |
/**
|
857 |
* Introduce el Stroke.
|
858 |
*
|
859 |
* @param m_Stroke The m_Stroke to set.
|
860 |
*/
|
861 |
public void setStroke(Stroke m_Stroke) { |
862 |
this.m_Stroke = m_Stroke;
|
863 |
|
864 |
// calculateRgb();
|
865 |
} |
866 |
|
867 |
/**
|
868 |
* Devuelve el Stroke.
|
869 |
*
|
870 |
* @return Returns the m_Stroke.
|
871 |
*/
|
872 |
public Stroke getStroke() { |
873 |
return m_Stroke;
|
874 |
} |
875 |
|
876 |
/**
|
877 |
* Introduce si el tama?o del simbolo est? en pixels.
|
878 |
*
|
879 |
* @param m_bUseSize The m_bUseSize to set.
|
880 |
*/
|
881 |
public void setSizeInPixels(boolean m_bUseSize) { |
882 |
this.m_bUseSize = m_bUseSize;
|
883 |
|
884 |
// calculateRgb();
|
885 |
} |
886 |
|
887 |
/**
|
888 |
* Devuelve si el tama?o del s?mbolo est? en pixels.
|
889 |
*
|
890 |
* @return Returns the m_bUseSize.
|
891 |
*/
|
892 |
public boolean isSizeInPixels() { |
893 |
return m_bUseSize;
|
894 |
} |
895 |
|
896 |
/**
|
897 |
* Introduce la descripci?n del s?mbolo.
|
898 |
*
|
899 |
* @param m_Descrip The m_Descrip to set.
|
900 |
*/
|
901 |
public void setDescription(String m_Descrip) { |
902 |
this.m_Descrip = m_Descrip;
|
903 |
} |
904 |
|
905 |
/**
|
906 |
* Devuelve la descripci?n del s?mbolo.
|
907 |
*
|
908 |
* @return Returns the m_Descrip.
|
909 |
*/
|
910 |
public String getDescription() { |
911 |
return m_Descrip;
|
912 |
} |
913 |
|
914 |
/**
|
915 |
* Introduce la alineaci?n en vertical.
|
916 |
*
|
917 |
* @param m_AlingVert The m_AlingVert to set.
|
918 |
*/
|
919 |
public void setAlingVert(int m_AlingVert) { |
920 |
this.m_AlingVert = m_AlingVert;
|
921 |
|
922 |
// calculateRgb();
|
923 |
} |
924 |
|
925 |
/**
|
926 |
* Devuelve la alineaci?n en vertical.
|
927 |
*
|
928 |
* @return Returns the m_AlingVert.
|
929 |
*/
|
930 |
public int getAlingVert() { |
931 |
return m_AlingVert;
|
932 |
} |
933 |
|
934 |
/**
|
935 |
* Introduce la alineaci?n en horizontal.
|
936 |
*
|
937 |
* @param m_AlingHoriz The m_AlingHoriz to set.
|
938 |
*/
|
939 |
public void setAlingHoriz(int m_AlingHoriz) { |
940 |
this.m_AlingHoriz = m_AlingHoriz;
|
941 |
|
942 |
// calculateRgb();
|
943 |
} |
944 |
|
945 |
/**
|
946 |
* Devuelve la alineaci?n en horizontal.
|
947 |
*
|
948 |
* @return Returns the m_AlingHoriz.
|
949 |
*/
|
950 |
public int getAlingHoriz() { |
951 |
return m_AlingHoriz;
|
952 |
} |
953 |
|
954 |
/**
|
955 |
* Devuelve el color que se aplica a los shapes seleccionados.
|
956 |
*
|
957 |
* @return DOCUMENT ME!
|
958 |
*/
|
959 |
public static Color getSelectionColor() { |
960 |
return selectionColor;
|
961 |
} |
962 |
|
963 |
/**
|
964 |
* Introduce el color que se aplica a los shapes seleccionados.
|
965 |
*
|
966 |
* @param selectionColor DOCUMENT ME!
|
967 |
*/
|
968 |
public static void setSelectionColor(Color selectionColor) { |
969 |
FSymbol.selectionColor = selectionColor; |
970 |
} |
971 |
|
972 |
/**
|
973 |
* Introduce el tama?o de la fuente.
|
974 |
*
|
975 |
* @param m_FontSize The m_FontSize to set.
|
976 |
*/
|
977 |
public void setFontSize(float m_FontSize) { |
978 |
this.m_FontSize = m_FontSize;
|
979 |
} |
980 |
|
981 |
/**
|
982 |
* Devuelve el tama?o de la fuente.
|
983 |
*
|
984 |
* @return Returns the m_FontSize.
|
985 |
*/
|
986 |
public float getFontSize() { |
987 |
return m_FontSize;
|
988 |
} |
989 |
public URI getIconURI() { |
990 |
return m_IconURI;
|
991 |
} |
992 |
public void setIconURI(URI iconURI) { |
993 |
m_IconURI = iconURI; |
994 |
ImageIcon prov;
|
995 |
try {
|
996 |
prov = new ImageIcon(iconURI.toURL()); |
997 |
m_Icon = prov.getImage(); |
998 |
} catch (MalformedURLException e) { |
999 |
// TODO Auto-generated catch block
|
1000 |
e.printStackTrace(); |
1001 |
} |
1002 |
|
1003 |
} |
1004 |
|
1005 |
//methods to be ISLDCompatible
|
1006 |
|
1007 |
/**
|
1008 |
* converts FSymbol to an SLD
|
1009 |
*/
|
1010 |
public String toSLD () |
1011 |
{ |
1012 |
StringBuffer sld = new StringBuffer(); |
1013 |
try
|
1014 |
{ |
1015 |
switch (this.getSymbolType()) |
1016 |
{ |
1017 |
|
1018 |
case FConstant.SYMBOL_TYPE_POINT:
|
1019 |
// Para no tener que clonarlo si viene en unidades de mapa
|
1020 |
boolean bAux2 = this.isSizeInPixels(); |
1021 |
int alturaMetros = this.getSize(); // Nota: Cambiar m_Size a float |
1022 |
|
1023 |
if (!bAux2) {
|
1024 |
this.setSizeInPixels(true); |
1025 |
this.setSize(8); // tama?o fijo |
1026 |
} |
1027 |
if (this.getFont() != null) { |
1028 |
// Para no tener que clonarlo si viene en unidades de mapa
|
1029 |
boolean bAux = this.isFontSizeInPixels(); |
1030 |
this.setFontSizeInPixels(true); |
1031 |
} |
1032 |
|
1033 |
break;
|
1034 |
|
1035 |
case FConstant.SYMBOL_TYPE_LINE:
|
1036 |
sld.append(SLDTags.OT_LINESYMBOLIZER); |
1037 |
// <Geometry>
|
1038 |
// <ogc:PropertyName>centerline</ogc:PropertyName>
|
1039 |
// </Geometry>
|
1040 |
// <Stroke>
|
1041 |
// <CssParameter name="stroke">#0000ff</CssParameter>
|
1042 |
// <CssParameter name="stroke-width">2</CssParameter>
|
1043 |
// </Stroke>
|
1044 |
sld.append(SLDTags.CT_LINESYMBOLIZER); |
1045 |
break;
|
1046 |
|
1047 |
case FConstant.SYMBOL_TYPE_FILL:
|
1048 |
//FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
|
1049 |
break;
|
1050 |
|
1051 |
case FShape.MULTI:
|
1052 |
//FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
|
1053 |
//FGraphicUtilities.DrawShape(g2, mT, shp, symbol);
|
1054 |
// Punto:
|
1055 |
// Para no tener que clonarlo si viene en unidades de mapa
|
1056 |
//bAux2 = symbol.isSizeInPixels();
|
1057 |
//alturaMetros = symbol.getSize(); // Nota: Cambiar m_Size a float
|
1058 |
// if (!bAux2) {
|
1059 |
// this.setSizeInPixels(true);
|
1060 |
// this.setSize(4); // tama?o fijo
|
1061 |
// }
|
1062 |
// FGraphicUtilities.DrawShape(g2, mT, shp, this);
|
1063 |
|
1064 |
// if (!bAux2) {
|
1065 |
// this.setSize(alturaMetros);
|
1066 |
// this.setSizeInPixels(bAux2);
|
1067 |
// }
|
1068 |
|
1069 |
if (this.getFont() != null) { |
1070 |
// Para no tener que clonarlo si viene en unidades de mapa
|
1071 |
boolean bAux = this.isFontSizeInPixels(); |
1072 |
this.setFontSizeInPixels(true); |
1073 |
//FGraphicUtilities.DrawLabel(g2, mT, shp, symbol,new FLabel("Abcd"));
|
1074 |
this.setFontSizeInPixels(bAux);
|
1075 |
} |
1076 |
|
1077 |
break;
|
1078 |
} |
1079 |
|
1080 |
|
1081 |
|
1082 |
|
1083 |
return sld.toString();
|
1084 |
} |
1085 |
catch(Exception e) |
1086 |
{ |
1087 |
e.printStackTrace(); |
1088 |
return null; |
1089 |
} |
1090 |
} |
1091 |
|
1092 |
/**
|
1093 |
* creates an FSymbol from an SLD
|
1094 |
*
|
1095 |
*/
|
1096 |
public String fromSLD (String sld) |
1097 |
{ |
1098 |
//TODO: This function can be implemented later...
|
1099 |
StringBuffer sb = new StringBuffer(); |
1100 |
try
|
1101 |
{ |
1102 |
|
1103 |
return sb.toString();
|
1104 |
} |
1105 |
catch(Exception e) |
1106 |
{ |
1107 |
e.printStackTrace(); |
1108 |
return null; |
1109 |
} |
1110 |
} |
1111 |
|
1112 |
} |