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