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