root / branches / v2_0_0_prep / extensions / org.gvsig.symbology / src / main / java / org / gvsig / symbology / fmap / mapcontext / rendering / legend / impl / SingleSymbolLegend.java @ 32880
History | View | Annotate | Download (6.95 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 org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl; |
42 |
|
43 |
import org.gvsig.fmap.dal.exception.DataException; |
44 |
import org.gvsig.fmap.dal.feature.Feature; |
45 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
46 |
import org.gvsig.fmap.geom.Geometry; |
47 |
import org.gvsig.fmap.mapcontext.rendering.legend.ISingleSymbolLegend; |
48 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent; |
49 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
50 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol; |
51 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl.MultiShapeSymbol; |
52 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol; |
53 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol; |
54 |
import org.gvsig.tools.ToolsLocator; |
55 |
import org.gvsig.tools.dynobject.DynStruct; |
56 |
import org.gvsig.tools.persistence.PersistenceManager; |
57 |
import org.gvsig.tools.persistence.PersistentState; |
58 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
59 |
import org.gvsig.utils.XMLEntity; |
60 |
import org.gvsig.utils.XMLException; |
61 |
|
62 |
/**
|
63 |
* Implements a legend composed by single symbols.
|
64 |
*
|
65 |
* @author Vicente Caballero Navarro
|
66 |
* @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
|
67 |
*/
|
68 |
public class SingleSymbolLegend extends AbstractVectorialLegend implements |
69 |
ISingleSymbolLegend { |
70 |
|
71 |
public static final String SINGLE_SYMBOL_DYNCLASS_NAME = |
72 |
"SimgleSymbolLegend";
|
73 |
|
74 |
private ISymbol defaultSymbol;
|
75 |
private int shapeType = Geometry.TYPES.SURFACE; // Por defecto, tipo pol?gono |
76 |
|
77 |
/**
|
78 |
* Constructor method, needed by persistence.
|
79 |
*/
|
80 |
public SingleSymbolLegend() {
|
81 |
// Nothing to do
|
82 |
} |
83 |
|
84 |
/**
|
85 |
* Convenience fast constructor.
|
86 |
*
|
87 |
* @param style S?mbolo.
|
88 |
*/
|
89 |
public SingleSymbolLegend(ISymbol style) {
|
90 |
defaultSymbol = style; |
91 |
|
92 |
if (style instanceof MultiShapeSymbol) { |
93 |
shapeType = Geometry.TYPES.GEOMETRY; |
94 |
} else if (style instanceof IMarkerSymbol) { |
95 |
shapeType = Geometry.TYPES.POINT; |
96 |
} else if (style instanceof ILineSymbol) { |
97 |
shapeType = Geometry.TYPES.CURVE; |
98 |
} else if (style instanceof IFillSymbol) { |
99 |
shapeType = Geometry.TYPES.SURFACE; |
100 |
} |
101 |
} |
102 |
|
103 |
|
104 |
public void setDefaultSymbol(ISymbol s) { |
105 |
if (s == null) throw new NullPointerException("Default symbol cannot be null"); |
106 |
setShapeType(s.getSymbolType()); |
107 |
ISymbol old = defaultSymbol; |
108 |
defaultSymbol = s; |
109 |
fireDefaultSymbolChangedEvent(new SymbolLegendEvent(old, s));
|
110 |
} |
111 |
|
112 |
|
113 |
public ISymbol getSymbol(int recordIndex) { |
114 |
return defaultSymbol;
|
115 |
} |
116 |
|
117 |
public ISymbol getDefaultSymbol() {
|
118 |
if(defaultSymbol==null) { |
119 |
defaultSymbol = |
120 |
getSymbolManager().createSymbol(IFillSymbol.SYMBOL_NAME); |
121 |
} |
122 |
return defaultSymbol;
|
123 |
} |
124 |
|
125 |
|
126 |
public XMLEntity getXMLEntity() throws XMLException { |
127 |
XMLEntity xml = new XMLEntity();
|
128 |
// xml.putProperty("className",this.getClass().getName());
|
129 |
// xml.addChild(defaultSymbol.getXMLEntity());
|
130 |
//
|
131 |
// if (zSort != null) {
|
132 |
// XMLEntity zSortXML = zSort.getXMLEntity();
|
133 |
// zSortXML.putProperty("id", "zSort");
|
134 |
// xml.addChild(zSortXML);
|
135 |
// }
|
136 |
return xml;
|
137 |
} |
138 |
|
139 |
/**
|
140 |
* TODO: replace with the new persistence API
|
141 |
*/
|
142 |
public void setXMLEntity(XMLEntity xml) { |
143 |
// ISymbol auxSym = SymbologyFactory.createSymbolFromXML(xml.getChild(0), null);
|
144 |
// setDefaultSymbol(auxSym);
|
145 |
//
|
146 |
// XMLEntity zSortXML = xml.firstChild("id", "zSort");
|
147 |
// if (zSortXML != null) {
|
148 |
// zSort = new ZSort(this);
|
149 |
// zSort.setXMLEntity(zSortXML);
|
150 |
// }
|
151 |
} |
152 |
|
153 |
|
154 |
// public ILegend cloneLegend() throws XMLException {
|
155 |
// return (ILegend) LegendFactory.createFromXML(getXMLEntity());
|
156 |
// }
|
157 |
|
158 |
|
159 |
public int getShapeType() { |
160 |
return shapeType;
|
161 |
} |
162 |
|
163 |
public void setShapeType(int shapeType) { |
164 |
if (this.shapeType != shapeType) { |
165 |
defaultSymbol = getSymbolManager().createSymbol(shapeType); |
166 |
this.shapeType = shapeType;
|
167 |
} |
168 |
} |
169 |
|
170 |
public ISymbol getSymbolByFeature(Feature feat) {
|
171 |
return defaultSymbol;
|
172 |
} |
173 |
|
174 |
public void useDefaultSymbol(boolean b) { |
175 |
// TODO Auto-generated method stub
|
176 |
} |
177 |
|
178 |
public String[] getUsedFields() { |
179 |
return new String[0]; |
180 |
} |
181 |
|
182 |
public boolean isUseDefaultSymbol() { |
183 |
return true; |
184 |
|
185 |
} |
186 |
|
187 |
|
188 |
public String getClassName() { |
189 |
return getClass().getName();
|
190 |
} |
191 |
|
192 |
public boolean isSuitableForShapeType(int shapeType) { |
193 |
return getShapeType() == shapeType;
|
194 |
} |
195 |
|
196 |
|
197 |
public void setFeatureStore(FeatureStore fs) throws DataException { |
198 |
// TODO Auto-generated method stub
|
199 |
|
200 |
} |
201 |
|
202 |
protected String[] getRequiredFeatureAttributeNames( |
203 |
FeatureStore featureStore) throws DataException {
|
204 |
// We only need the default Geometry to draw
|
205 |
return new String[] { featureStore |
206 |
.getDefaultFeatureType().getDefaultGeometryAttributeName() }; |
207 |
} |
208 |
|
209 |
public Object clone() throws CloneNotSupportedException { |
210 |
SingleSymbolLegend clone = (SingleSymbolLegend) super.clone();
|
211 |
|
212 |
// Clone default symbol
|
213 |
if (defaultSymbol != null) { |
214 |
clone.defaultSymbol = (ISymbol) defaultSymbol.clone(); |
215 |
} |
216 |
|
217 |
return clone;
|
218 |
} |
219 |
|
220 |
public void loadFromState(PersistentState state) |
221 |
throws PersistenceException {
|
222 |
// Set parent properties
|
223 |
super.loadFromState(state);
|
224 |
} |
225 |
|
226 |
public void saveToState(PersistentState state) throws PersistenceException { |
227 |
// Save parent properties
|
228 |
super.saveToState(state);
|
229 |
} |
230 |
|
231 |
public static void registerPersistence() { |
232 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
233 |
DynStruct definition = manager.addDefinition( |
234 |
SingleSymbolLegend.class, |
235 |
SINGLE_SYMBOL_DYNCLASS_NAME, |
236 |
SINGLE_SYMBOL_DYNCLASS_NAME+" Persistence definition",
|
237 |
null,
|
238 |
null
|
239 |
); |
240 |
// Extend the Vectorial Legend base definition
|
241 |
definition.extend(VECTORIAL_LEGEND_DYNCLASS_NAME); |
242 |
} |
243 |
|
244 |
} |