root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / rendering / LegendFactory.java @ 38563
History | View | Annotate | Download (4.68 KB)
1 | 1100 | fjp | /* 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 | 214 | fernando | package com.iver.cit.gvsig.fmap.rendering; |
42 | |||
43 | 15676 | jdominguez | import java.awt.Color; |
44 | import java.util.Random; |
||
45 | |||
46 | 1828 | fernando | import com.hardcode.gdbms.engine.data.driver.DriverException; |
47 | 10815 | jaume | import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
48 | 490 | fernando | import com.iver.cit.gvsig.fmap.layers.XMLException; |
49 | 413 | vcaballero | import com.iver.utiles.XMLEntity; |
50 | 214 | fernando | |
51 | |||
52 | 326 | fernando | /**
|
53 | 1034 | vcaballero | * Clase factoria de las diferentes leyendas.
|
54 | 326 | fernando | *
|
55 | * @author Fernando Gonz?lez Cort?s
|
||
56 | */
|
||
57 | 214 | fernando | public class LegendFactory { |
58 | 1034 | vcaballero | /**
|
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 | 13884 | jaume | public static IVectorLegend createSingleSymbolLegend(int shapeType) { |
67 | 15676 | jdominguez | Random rand = new Random(); |
68 | 23116 | vcaballero | |
69 | 15676 | jdominguez | 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 | 23116 | vcaballero | |
76 | if(!SymbologyFactory.DefaultAleatoryFillColor)
|
||
77 | randomColor = SymbologyFactory.DefaultFillSymbolColor; |
||
78 | |||
79 | 10815 | jaume | return new SingleSymbolLegend( |
80 | 15676 | jdominguez | SymbologyFactory.createDefaultSymbolByShapeType(shapeType, randomColor)); |
81 | 10815 | jaume | |
82 | 1034 | vcaballero | } |
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 | 13884 | jaume | public static IVectorLegend createFromXML03(XMLEntity xml) |
120 | 2183 | fernando | throws XMLException {
|
121 | //TODO Implementar bien
|
||
122 | try {
|
||
123 | 13884 | jaume | IVectorLegend vl = null;
|
124 | 2183 | fernando | Class clase = Class.forName(xml.getStringProperty("className")); |
125 | 13884 | jaume | vl = (IVectorLegend) clase.newInstance(); |
126 | 2183 | fernando | 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 | 13884 | jaume | public static IVectorLegend createFromXML(XMLEntity xml) |
148 | 1034 | vcaballero | throws XMLException {
|
149 | //TODO Implementar bien
|
||
150 | try {
|
||
151 | 13884 | jaume | IVectorLegend vl = null;
|
152 | 1094 | vcaballero | Class clase = Class.forName(xml.getStringProperty("className")); |
153 | 13884 | jaume | vl = (IVectorLegend) clase.newInstance(); |
154 | 1034 | vcaballero | vl.setXMLEntity(xml); |
155 | |||
156 | return vl;
|
||
157 | } catch (ClassNotFoundException e) { |
||
158 | 490 | fernando | throw new XMLException(e); |
159 | } catch (InstantiationException e) { |
||
160 | throw new XMLException(e); |
||
161 | } catch (IllegalAccessException e) { |
||
162 | throw new XMLException(e); |
||
163 | } |
||
164 | 1034 | vcaballero | } |
165 | 214 | fernando | |
166 | 1034 | vcaballero | /**
|
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 | 13884 | jaume | public static IVectorLegend cloneLegend(IVectorLegend l) |
177 | 1034 | vcaballero | throws XMLException, DriverException {
|
178 | 21535 | vcaballero | return createFromXML(l.getXMLEntity());
|
179 | 1034 | vcaballero | } |
180 | 214 | fernando | } |