root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / rendering / SingleSymbolLegend.java @ 11853
History | View | Annotate | Download (5.15 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 com.hardcode.gdbms.engine.data.DataSource; |
44 |
import com.iver.cit.gvsig.fmap.core.FShape; |
45 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
46 |
import com.iver.cit.gvsig.fmap.core.ISLDCompatible; |
47 |
import com.iver.cit.gvsig.fmap.core.SLDTags; |
48 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
49 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
50 |
import com.iver.cit.gvsig.fmap.core.symbols.SimpleFillSymbol; |
51 |
import com.iver.cit.gvsig.fmap.core.symbols.SimpleLineSymbol; |
52 |
import com.iver.cit.gvsig.fmap.core.symbols.SimpleMarkerSymbol; |
53 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
54 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
55 |
import com.iver.utiles.XMLEntity; |
56 |
|
57 |
|
58 |
/**
|
59 |
* Leyenda se s?mbolo ?nico.
|
60 |
* @author Vicente Caballero Navarro
|
61 |
*/
|
62 |
public class SingleSymbolLegend implements IVectorialLegend { |
63 |
private ISymbol defaultSymbol;
|
64 |
private int shapeType = FShape.POLYGON; // Por defecto, tipo pol?gono |
65 |
private ZSort zSort;
|
66 |
|
67 |
|
68 |
public SingleSymbolLegend() { }
|
69 |
|
70 |
|
71 |
/**
|
72 |
* Crea un nuevo SingleSymbolLegend.
|
73 |
*
|
74 |
* @param style S?mbolo.
|
75 |
*/
|
76 |
public SingleSymbolLegend(ISymbol style) {
|
77 |
defaultSymbol = style; |
78 |
} |
79 |
|
80 |
|
81 |
|
82 |
public void setDefaultSymbol(ISymbol s) { |
83 |
setShapeType(s.getSymbolType()); |
84 |
defaultSymbol = s; |
85 |
} |
86 |
|
87 |
|
88 |
public ISymbol getSymbol(int recordIndex) { |
89 |
return defaultSymbol;
|
90 |
} |
91 |
|
92 |
public ISymbol getDefaultSymbol() {
|
93 |
return defaultSymbol;
|
94 |
} |
95 |
|
96 |
public String getSLDString(String layerName) |
97 |
{ |
98 |
|
99 |
try{
|
100 |
XmlBuilder xmlBuilder = new XmlBuilder();
|
101 |
xmlBuilder.writeHeader(); |
102 |
xmlBuilder.openTag(SLDTags.SLD_ROOT, SLDTags.VERSION_ATTR, SLDTags.VERSION_1_0_0); |
103 |
xmlBuilder.openTag(SLDTags.NAMEDLAYER); |
104 |
xmlBuilder.writeTag(SLDTags.NAME,layerName); |
105 |
xmlBuilder.openTag(SLDTags.USERSTYLE); |
106 |
xmlBuilder.openTag(SLDTags.FEATURETYPESTYLE); |
107 |
xmlBuilder.writeTag(SLDTags.FEATURETYPENAME,"FeatureTypeName");
|
108 |
xmlBuilder.openTag(SLDTags.RULE); |
109 |
if (this.defaultSymbol instanceof ISLDCompatible) |
110 |
{ |
111 |
ISLDCompatible symSLD = (ISLDCompatible) this.defaultSymbol;
|
112 |
xmlBuilder.writeRaw(symSLD.toSLD()); |
113 |
} |
114 |
else
|
115 |
throw new RuntimeException("Cannot convert default Symbol " + this.defaultSymbol.getDescription() + " to SLD"); |
116 |
|
117 |
xmlBuilder.closeTag(); |
118 |
xmlBuilder.closeTag(); |
119 |
xmlBuilder.closeTag(); |
120 |
xmlBuilder.closeTag(); |
121 |
xmlBuilder.closeTag(); |
122 |
return xmlBuilder.getXML();
|
123 |
} |
124 |
catch(Exception e) |
125 |
{ |
126 |
e.printStackTrace(); |
127 |
return null; |
128 |
} |
129 |
} |
130 |
|
131 |
public XMLEntity getXMLEntity() {
|
132 |
XMLEntity xml = new XMLEntity();
|
133 |
xml.putProperty("className",this.getClass().getName()); |
134 |
xml.addChild(defaultSymbol.getXMLEntity()); |
135 |
|
136 |
return xml;
|
137 |
} |
138 |
|
139 |
public void setXMLEntity03(XMLEntity xml) { |
140 |
FSymbol auxSym = FSymbol.createFromXML03(xml.getChild(0));
|
141 |
setDefaultSymbol(auxSym); |
142 |
} |
143 |
|
144 |
public void setXMLEntity(XMLEntity xml) { |
145 |
ISymbol auxSym = SymbologyFactory.createSymbolFromXML(xml.getChild(0), null); |
146 |
setDefaultSymbol(auxSym); |
147 |
} |
148 |
|
149 |
|
150 |
public ILegend cloneLegend() throws XMLException { |
151 |
return (ILegend) LegendFactory.createFromXML(getXMLEntity());
|
152 |
} |
153 |
|
154 |
|
155 |
public void setDataSource(DataSource ds) { |
156 |
// No hacemos nada, no lo vamos a usar
|
157 |
} |
158 |
|
159 |
public int getShapeType() { |
160 |
return shapeType;
|
161 |
} |
162 |
|
163 |
public void setShapeType(int shapeType) { |
164 |
if (this.shapeType != shapeType) { |
165 |
switch (shapeType) {
|
166 |
case FShape.POINT:
|
167 |
defaultSymbol = new SimpleMarkerSymbol();
|
168 |
break;
|
169 |
|
170 |
case FShape.LINE:
|
171 |
defaultSymbol = new SimpleLineSymbol();
|
172 |
|
173 |
break;
|
174 |
|
175 |
case FShape.POLYGON:
|
176 |
defaultSymbol = new SimpleFillSymbol();
|
177 |
|
178 |
break;
|
179 |
} |
180 |
|
181 |
this.shapeType = shapeType;
|
182 |
} |
183 |
} |
184 |
|
185 |
|
186 |
|
187 |
public ISymbol getSymbolByFeature(IFeature feat) {
|
188 |
return defaultSymbol;
|
189 |
} |
190 |
|
191 |
public void useDefaultSymbol(boolean b) { |
192 |
// TODO Auto-generated method stub
|
193 |
} |
194 |
|
195 |
public String[] getUsedFields() { |
196 |
return new String[0]; |
197 |
} |
198 |
|
199 |
public boolean isUseDefaultSymbol() { |
200 |
return true; |
201 |
|
202 |
} |
203 |
|
204 |
|
205 |
public ZSort getZSort() {
|
206 |
return zSort;
|
207 |
|
208 |
} |
209 |
public void setZSort(ZSort zSort) { |
210 |
this.zSort = zSort;
|
211 |
} |
212 |
|
213 |
|
214 |
} |