root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / rendering / LegendFactory.java @ 38563
History | View | Annotate | Download (4.68 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.fmap.rendering; |
42 |
|
43 |
import java.awt.Color; |
44 |
import java.util.Random; |
45 |
|
46 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
47 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
48 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
49 |
import com.iver.utiles.XMLEntity; |
50 |
|
51 |
|
52 |
/**
|
53 |
* Clase factoria de las diferentes leyendas.
|
54 |
*
|
55 |
* @author Fernando Gonz?lez Cort?s
|
56 |
*/
|
57 |
public class LegendFactory { |
58 |
/**
|
59 |
* Crea un objeto renderer de s?mbolo ?nico con las caracter?sticas que se
|
60 |
* pasan como par?metro
|
61 |
*
|
62 |
* @param shapeType Tipo de shape.
|
63 |
*
|
64 |
* @return VectorialLegend.
|
65 |
*/
|
66 |
public static IVectorLegend createSingleSymbolLegend(int shapeType) { |
67 |
Random rand = new Random(); |
68 |
|
69 |
int numreg = rand.nextInt(255/2); |
70 |
double div = (1-rand.nextDouble()*0.66)*0.9; |
71 |
Color randomColor = new Color( |
72 |
((int) (255*div + (numreg * rand.nextDouble()))) % 255, |
73 |
((int) (255*div + (numreg * rand.nextDouble()))) % 255, |
74 |
((int) (255*div + (numreg * rand.nextDouble()))) % 255); |
75 |
|
76 |
if(!SymbologyFactory.DefaultAleatoryFillColor)
|
77 |
randomColor = SymbologyFactory.DefaultFillSymbolColor; |
78 |
|
79 |
return new SingleSymbolLegend( |
80 |
SymbologyFactory.createDefaultSymbolByShapeType(shapeType, randomColor)); |
81 |
|
82 |
} |
83 |
|
84 |
/**
|
85 |
* Crea un objeto VectorialUniqueValueLegend vac?o, dispuesto para cargar
|
86 |
* s?mbolos
|
87 |
*
|
88 |
* @param shapeType Tipo de shape.
|
89 |
*
|
90 |
* @return VectorialUniqueValueLegend.
|
91 |
*/
|
92 |
public static VectorialUniqueValueLegend createVectorialUniqueValueLegend( |
93 |
int shapeType) {
|
94 |
return new VectorialUniqueValueLegend(shapeType); |
95 |
} |
96 |
|
97 |
/**
|
98 |
* Crea un objeto VectorialIntervalLegend vac?o, dispuesto para cargar
|
99 |
* s?mbolos
|
100 |
*
|
101 |
* @param shapeType tipo de shape.
|
102 |
*
|
103 |
* @return VectorialIntervalLegend
|
104 |
*/
|
105 |
public static VectorialIntervalLegend createVectorialIntervalLegend( |
106 |
int shapeType) {
|
107 |
return new VectorialIntervalLegend(shapeType); |
108 |
} |
109 |
|
110 |
/**
|
111 |
* Crea un renderer con la informaci?n contenida en el objeto XMLEntity
|
112 |
*
|
113 |
* @param xml XMLEntity.
|
114 |
*
|
115 |
* @return VectorialLegend
|
116 |
*
|
117 |
* @throws XMLException
|
118 |
*/
|
119 |
public static IVectorLegend createFromXML03(XMLEntity xml) |
120 |
throws XMLException {
|
121 |
//TODO Implementar bien
|
122 |
try {
|
123 |
IVectorLegend vl = null;
|
124 |
Class clase = Class.forName(xml.getStringProperty("className")); |
125 |
vl = (IVectorLegend) clase.newInstance(); |
126 |
vl.setXMLEntity03(xml); |
127 |
|
128 |
return vl;
|
129 |
} catch (ClassNotFoundException e) { |
130 |
throw new XMLException(e); |
131 |
} catch (InstantiationException e) { |
132 |
throw new XMLException(e); |
133 |
} catch (IllegalAccessException e) { |
134 |
throw new XMLException(e); |
135 |
} |
136 |
} |
137 |
|
138 |
/**
|
139 |
* Crea un renderer con la informaci?n contenida en el objeto XMLEntity
|
140 |
*
|
141 |
* @param xml XMLEntity.
|
142 |
*
|
143 |
* @return VectorialLegend
|
144 |
*
|
145 |
* @throws XMLException
|
146 |
*/
|
147 |
public static IVectorLegend createFromXML(XMLEntity xml) |
148 |
throws XMLException {
|
149 |
//TODO Implementar bien
|
150 |
try {
|
151 |
IVectorLegend vl = null;
|
152 |
Class clase = Class.forName(xml.getStringProperty("className")); |
153 |
vl = (IVectorLegend) clase.newInstance(); |
154 |
vl.setXMLEntity(xml); |
155 |
|
156 |
return vl;
|
157 |
} catch (ClassNotFoundException e) { |
158 |
throw new XMLException(e); |
159 |
} catch (InstantiationException e) { |
160 |
throw new XMLException(e); |
161 |
} catch (IllegalAccessException e) { |
162 |
throw new XMLException(e); |
163 |
} |
164 |
} |
165 |
|
166 |
/**
|
167 |
* Clona la leyenda.
|
168 |
*
|
169 |
* @param l VectorialLegend a clonar.
|
170 |
*
|
171 |
* @return VectorialLegend cloando.
|
172 |
*
|
173 |
* @throws XMLException
|
174 |
* @throws DriverException
|
175 |
*/
|
176 |
public static IVectorLegend cloneLegend(IVectorLegend l) |
177 |
throws XMLException, DriverException {
|
178 |
return createFromXML(l.getXMLEntity());
|
179 |
} |
180 |
} |