svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / rendering / SingleSymbolLegend.java @ 10926
History | View | Annotate | Download (8.02 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.util.ArrayList; |
44 |
|
45 |
import com.hardcode.gdbms.engine.data.DataSource; |
46 |
import com.iver.cit.gvsig.fmap.core.FShape; |
47 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
48 |
import com.iver.cit.gvsig.fmap.core.ISLDCompatible; |
49 |
import com.iver.cit.gvsig.fmap.core.SLDTags; |
50 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
51 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
52 |
import com.iver.cit.gvsig.fmap.core.symbols.SimpleFillSymbol; |
53 |
import com.iver.cit.gvsig.fmap.core.symbols.SimpleLineSymbol; |
54 |
import com.iver.cit.gvsig.fmap.core.symbols.SimpleMarkerSymbol; |
55 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
56 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
57 |
import com.iver.utiles.XMLEntity; |
58 |
|
59 |
|
60 |
/**
|
61 |
* Leyenda se s?mbolo ?nico.
|
62 |
* @author Vicente Caballero Navarro
|
63 |
*/
|
64 |
public class SingleSymbolLegend implements VectorialLegend { |
65 |
private ISymbol defaultSymbol;
|
66 |
/**
|
67 |
* @deprecated
|
68 |
*/
|
69 |
private String labelFieldName = null; |
70 |
/**
|
71 |
* @deprecated
|
72 |
*/
|
73 |
private String labelFieldHeight = null; |
74 |
/**
|
75 |
* @deprecated
|
76 |
*/
|
77 |
private String labelFieldRotation = null; |
78 |
private int shapeType = FShape.POLYGON; // Por defecto, tipo pol?gono |
79 |
// private boolean bWithHeightText;
|
80 |
|
81 |
|
82 |
public SingleSymbolLegend() { }
|
83 |
|
84 |
|
85 |
/**
|
86 |
* Crea un nuevo SingleSymbolLegend.
|
87 |
*
|
88 |
* @param style S?mbolo.
|
89 |
*/
|
90 |
public SingleSymbolLegend(ISymbol style) {
|
91 |
defaultSymbol = style; |
92 |
} |
93 |
|
94 |
/*
|
95 |
/**
|
96 |
* Crea un nuevo SingleSymbolLegend.
|
97 |
* /
|
98 |
public SingleSymbolLegend() {
|
99 |
defaultSymbol = LegendFactory.DEFAULT_POLYGON_SYMBOL;
|
100 |
}*/
|
101 |
|
102 |
public void setDefaultSymbol(ISymbol s) { |
103 |
setShapeType(s.getSymbolType()); |
104 |
defaultSymbol = s; |
105 |
} |
106 |
|
107 |
/**
|
108 |
* @deprecated
|
109 |
*/
|
110 |
public String getLabelField() { |
111 |
return labelFieldName;
|
112 |
} |
113 |
|
114 |
/**
|
115 |
* @deprecated
|
116 |
*/
|
117 |
public void setLabelField(String fieldName) { |
118 |
labelFieldName = fieldName; |
119 |
} |
120 |
|
121 |
public ISymbol getSymbol(int recordIndex) { |
122 |
return defaultSymbol;
|
123 |
} |
124 |
|
125 |
public ISymbol getDefaultSymbol() {
|
126 |
return defaultSymbol;
|
127 |
} |
128 |
|
129 |
public String getSLDString(String layerName) |
130 |
{ |
131 |
// StyledLayerDescriptor sld = new StyledLayerDescriptor();
|
132 |
// StyleFactory styleFactory = StyleFactory.createStyleFactory();
|
133 |
// Style style = styleFactory.createStyle();
|
134 |
// style.setName("default");
|
135 |
// try{
|
136 |
// FeatureTypeStyle featStyle = styleFactory.createFeatureTypeStyle();
|
137 |
// Symbolizer[] theSymbolizers = new Symbolizer[1];
|
138 |
// theSymbolizers[0] = SDLUtils.toGeotoolsSymbol(this.defaultSymbol);
|
139 |
// Rule myRule = styleFactory.createRule();
|
140 |
// myRule.setSymbolizers(theSymbolizers);
|
141 |
// featStyle.addRule(myRule);
|
142 |
// style.addFeatureTypeStyle(featStyle);
|
143 |
// NamedLayer namedLayer = new NamedLayer();
|
144 |
// namedLayer.setName("comunidades");
|
145 |
// namedLayer.addStyle(style);
|
146 |
// sld.addStyledLayer(namedLayer);
|
147 |
// SLDTransformer st = new SLDTransformer();
|
148 |
// String result = st.transform(style);
|
149 |
// return result;
|
150 |
// }catch(Exception e) {
|
151 |
// e.printStackTrace();
|
152 |
// return null;
|
153 |
// }
|
154 |
try{
|
155 |
XmlBuilder xmlBuilder = new XmlBuilder();
|
156 |
xmlBuilder.writeHeader(); |
157 |
xmlBuilder.openTag(SLDTags.SLD_ROOT, SLDTags.VERSION_ATTR, SLDTags.VERSION_1_0_0); |
158 |
xmlBuilder.openTag(SLDTags.NAMEDLAYER); |
159 |
xmlBuilder.writeTag(SLDTags.NAME,layerName); |
160 |
xmlBuilder.openTag(SLDTags.USERSTYLE); |
161 |
xmlBuilder.openTag(SLDTags.FEATURETYPESTYLE); |
162 |
xmlBuilder.writeTag(SLDTags.FEATURETYPENAME,"FeatureTypeName");
|
163 |
xmlBuilder.openTag(SLDTags.RULE); |
164 |
if (this.defaultSymbol instanceof ISLDCompatible) |
165 |
{ |
166 |
ISLDCompatible symSLD = (ISLDCompatible) this.defaultSymbol;
|
167 |
xmlBuilder.writeRaw(symSLD.toSLD()); |
168 |
} |
169 |
else
|
170 |
throw new RuntimeException("Cannot convert default Symbol " + this.defaultSymbol.getDescription() + " to SLD"); |
171 |
|
172 |
xmlBuilder.closeTag(); |
173 |
xmlBuilder.closeTag(); |
174 |
xmlBuilder.closeTag(); |
175 |
xmlBuilder.closeTag(); |
176 |
xmlBuilder.closeTag(); |
177 |
return xmlBuilder.getXML();
|
178 |
} |
179 |
catch(Exception e) |
180 |
{ |
181 |
e.printStackTrace(); |
182 |
return null; |
183 |
} |
184 |
} |
185 |
|
186 |
public XMLEntity getXMLEntity() {
|
187 |
XMLEntity xml = new XMLEntity();
|
188 |
xml.putProperty("className",this.getClass().getName()); |
189 |
/*xml.putProperty("labelFieldName", labelFieldName);
|
190 |
xml.putProperty("labelHeightFieldName", labelFieldHeight);
|
191 |
xml.putProperty("labelRotationFieldName", labelFieldRotation);*/
|
192 |
xml.addChild(defaultSymbol.getXMLEntity()); |
193 |
|
194 |
return xml;
|
195 |
} |
196 |
|
197 |
public void setXMLEntity03(XMLEntity xml) { |
198 |
setLabelField(xml.getStringProperty("labelFieldName"));
|
199 |
|
200 |
FSymbol auxSym = FSymbol.createFromXML03(xml.getChild(0));
|
201 |
setDefaultSymbol(auxSym); |
202 |
} |
203 |
|
204 |
public void setXMLEntity(XMLEntity xml) { |
205 |
/*
|
206 |
setLabelField(xml.getStringProperty("labelFieldName"));
|
207 |
if (xml.contains("labelHeightFieldName"))
|
208 |
setLabelHeightField(xml.getStringProperty("labelHeightFieldName"));
|
209 |
if (xml.contains("labelRotationFieldName"))
|
210 |
setLabelRotationField(xml.getStringProperty("labelRotationFieldName"));
|
211 |
*/
|
212 |
// FSymbol auxSym = FSymbol.createFromXML(xml.getChild(0));
|
213 |
ISymbol auxSym = SymbologyFactory.createSymbolFromXML(xml.getChild(0), null); |
214 |
setDefaultSymbol(auxSym); |
215 |
} |
216 |
|
217 |
|
218 |
public Legend cloneLegend() throws XMLException { |
219 |
return (Legend) LegendFactory.createFromXML(getXMLEntity());
|
220 |
} |
221 |
|
222 |
|
223 |
public void setDataSource(DataSource ds) { |
224 |
// No hacemos nada, no lo vamos a usar
|
225 |
} |
226 |
|
227 |
public int getShapeType() { |
228 |
return shapeType;
|
229 |
} |
230 |
|
231 |
public void setShapeType(int shapeType) { |
232 |
if (this.shapeType != shapeType) { |
233 |
switch (shapeType) {
|
234 |
case FShape.POINT:
|
235 |
defaultSymbol = new SimpleMarkerSymbol();
|
236 |
break;
|
237 |
|
238 |
case FShape.LINE:
|
239 |
defaultSymbol = new SimpleLineSymbol();
|
240 |
|
241 |
break;
|
242 |
|
243 |
case FShape.POLYGON:
|
244 |
defaultSymbol = new SimpleFillSymbol();
|
245 |
|
246 |
break;
|
247 |
} |
248 |
|
249 |
this.shapeType = shapeType;
|
250 |
} |
251 |
} |
252 |
|
253 |
/**
|
254 |
* @deprecated
|
255 |
*/
|
256 |
public String getLabelHeightField() { |
257 |
return labelFieldHeight;
|
258 |
} |
259 |
|
260 |
/**
|
261 |
* Inserta el texto que refleja el alto del campo.
|
262 |
* @deprecated
|
263 |
* @param str String.
|
264 |
*/
|
265 |
public void setLabelHeightField(String str) { |
266 |
labelFieldHeight = str; |
267 |
} |
268 |
|
269 |
/**
|
270 |
* @deprecated
|
271 |
*/
|
272 |
public String getLabelRotationField() { |
273 |
return labelFieldRotation;
|
274 |
} |
275 |
|
276 |
/**
|
277 |
* Inserta el texto que refleja la rotaci?n del campo.
|
278 |
* @deprecated
|
279 |
*
|
280 |
* @param str String.
|
281 |
*/
|
282 |
public void setLabelRotationField(String str) { |
283 |
labelFieldRotation = str; |
284 |
} |
285 |
|
286 |
public ISymbol getSymbolByFeature(IFeature feat) {
|
287 |
return defaultSymbol;
|
288 |
} |
289 |
|
290 |
public void useDefaultSymbol(boolean b) { |
291 |
// TODO Auto-generated method stub
|
292 |
} |
293 |
|
294 |
public String[] getUsedFields() { |
295 |
ArrayList usedFields = new ArrayList(); |
296 |
if (getLabelField() != null) |
297 |
usedFields.add(getLabelField()); |
298 |
if (getLabelHeightField() != null) |
299 |
usedFields.add(getLabelHeightField()); |
300 |
if (getLabelRotationField() != null) |
301 |
usedFields.add(getLabelRotationField()); |
302 |
|
303 |
return (String[]) usedFields.toArray(new String[0]); |
304 |
} |
305 |
|
306 |
public boolean isUseDefaultSymbol() { |
307 |
return true; |
308 |
|
309 |
} |
310 |
} |