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