svn-gvsig-desktop / tags / v2_0_0_Build_2023 / libraries / org.gvsig.symbology / org.gvsig.symbology.lib / org.gvsig.symbology.lib.impl / src / main / java / org / gvsig / symbology / fmap / mapcontext / rendering / legend / impl / SingleSymbolLegend.java @ 34389
History | View | Annotate | Download (6.66 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.MapContextLocator; |
48 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
49 |
import org.gvsig.fmap.mapcontext.rendering.legend.ISingleSymbolLegend; |
50 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent; |
51 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
52 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol; |
53 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl.MultiShapeSymbol; |
54 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol; |
55 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol; |
56 |
import org.gvsig.tools.ToolsLocator; |
57 |
import org.gvsig.tools.dynobject.DynStruct; |
58 |
import org.gvsig.tools.persistence.PersistenceManager; |
59 |
import org.gvsig.tools.persistence.PersistentState; |
60 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
61 |
import org.gvsig.tools.util.Callable; |
62 |
import org.slf4j.Logger; |
63 |
import org.slf4j.LoggerFactory; |
64 |
|
65 |
/**
|
66 |
* Implements a legend composed by single symbols.
|
67 |
*
|
68 |
* @author Vicente Caballero Navarro
|
69 |
* @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
|
70 |
*/
|
71 |
public class SingleSymbolLegend extends AbstractVectorialLegend implements |
72 |
ISingleSymbolLegend { |
73 |
|
74 |
final static private Logger LOG = LoggerFactory.getLogger(VectorialUniqueValueLegend.class); |
75 |
|
76 |
public static final String SINGLE_SYMBOL_PERSISTENCE_DEFINITION_NAME = |
77 |
"SimgleSymbolLegend";
|
78 |
|
79 |
private ISymbol defaultSymbol;
|
80 |
private int shapeType = Geometry.TYPES.SURFACE; // Por defecto, tipo pol?gono |
81 |
|
82 |
/**
|
83 |
* Constructor method, needed by persistence.
|
84 |
*/
|
85 |
public SingleSymbolLegend() {
|
86 |
super();
|
87 |
} |
88 |
|
89 |
/**
|
90 |
* Convenience fast constructor.
|
91 |
*
|
92 |
* @param style S?mbolo.
|
93 |
*/
|
94 |
public SingleSymbolLegend(ISymbol style) {
|
95 |
super();
|
96 |
setDefaultSymbol(style); |
97 |
} |
98 |
|
99 |
|
100 |
public void setDefaultSymbol(ISymbol s) { |
101 |
if (s == null) throw new NullPointerException("Default symbol cannot be null"); |
102 |
ISymbol old = defaultSymbol; |
103 |
defaultSymbol = s; |
104 |
fireDefaultSymbolChangedEvent(new SymbolLegendEvent(old, s));
|
105 |
} |
106 |
|
107 |
|
108 |
public ISymbol getSymbol(int recordIndex) { |
109 |
return defaultSymbol;
|
110 |
} |
111 |
|
112 |
public ISymbol getDefaultSymbol() {
|
113 |
if(defaultSymbol==null) { |
114 |
defaultSymbol = getSymbolManager().createSymbol(shapeType); |
115 |
} |
116 |
return defaultSymbol;
|
117 |
} |
118 |
|
119 |
|
120 |
|
121 |
public int getShapeType() { |
122 |
return shapeType;
|
123 |
} |
124 |
|
125 |
public void setShapeType(int shapeType) { |
126 |
if (this.shapeType != shapeType) { |
127 |
defaultSymbol = getSymbolManager().createSymbol(shapeType); |
128 |
this.shapeType = shapeType;
|
129 |
} |
130 |
} |
131 |
|
132 |
public ISymbol getSymbolByFeature(Feature feat) {
|
133 |
return getDefaultSymbol();
|
134 |
} |
135 |
|
136 |
public void useDefaultSymbol(boolean b) { |
137 |
LOG.warn("TODO: SingleSymbolLegend.useDefaultSymbol");
|
138 |
} |
139 |
|
140 |
public String[] getUsedFields() { |
141 |
return new String[0]; |
142 |
} |
143 |
|
144 |
public boolean isUseDefaultSymbol() { |
145 |
return true; |
146 |
|
147 |
} |
148 |
|
149 |
|
150 |
public String getClassName() { |
151 |
return getClass().getName();
|
152 |
} |
153 |
|
154 |
public boolean isSuitableForShapeType(int shapeType) { |
155 |
return getShapeType() == shapeType;
|
156 |
} |
157 |
|
158 |
|
159 |
public void setFeatureStore(FeatureStore fs) throws DataException { |
160 |
LOG.warn("TODO: SingleSymbolLegend.useDefaultSymbol");
|
161 |
} |
162 |
|
163 |
protected String[] getRequiredFeatureAttributeNames( |
164 |
FeatureStore featureStore) throws DataException {
|
165 |
// We only need the default Geometry to draw
|
166 |
return new String[] { featureStore |
167 |
.getDefaultFeatureType().getDefaultGeometryAttributeName() }; |
168 |
} |
169 |
|
170 |
public Object clone() throws CloneNotSupportedException { |
171 |
SingleSymbolLegend clone = (SingleSymbolLegend) super.clone();
|
172 |
|
173 |
// Clone default symbol
|
174 |
if (defaultSymbol != null) { |
175 |
clone.defaultSymbol = (ISymbol) defaultSymbol.clone(); |
176 |
} |
177 |
|
178 |
return clone;
|
179 |
} |
180 |
|
181 |
public void loadFromState(PersistentState state) |
182 |
throws PersistenceException {
|
183 |
// Set parent properties
|
184 |
super.loadFromState(state);
|
185 |
LOG.warn("FIXME: SingleSymbolLegend.loadFromState");
|
186 |
} |
187 |
|
188 |
public void saveToState(PersistentState state) throws PersistenceException { |
189 |
// Save parent properties
|
190 |
super.saveToState(state);
|
191 |
LOG.warn("FIXME: SingleSymbolLegend.saveToState");
|
192 |
} |
193 |
|
194 |
public static class RegisterPersistence implements Callable { |
195 |
|
196 |
public Object call() throws Exception { |
197 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
198 |
if( manager.getDefinition(SINGLE_SYMBOL_PERSISTENCE_DEFINITION_NAME)==null ) { |
199 |
DynStruct definition = manager.addDefinition( |
200 |
SingleSymbolLegend.class, |
201 |
SINGLE_SYMBOL_PERSISTENCE_DEFINITION_NAME, |
202 |
SINGLE_SYMBOL_PERSISTENCE_DEFINITION_NAME+" Persistence definition",
|
203 |
null,
|
204 |
null
|
205 |
); |
206 |
// Extend the Vectorial Legend base definition
|
207 |
definition.extend(manager.getDefinition(VECTORIAL_LEGEND_PERSISTENCE_DEFINITION_NAME)); |
208 |
} |
209 |
return Boolean.TRUE; |
210 |
} |
211 |
|
212 |
} |
213 |
|
214 |
public static class RegisterLegend implements Callable { |
215 |
|
216 |
public Object call() throws Exception { |
217 |
MapContextManager manager = MapContextLocator.getMapContextManager(); |
218 |
|
219 |
manager.registerLegend(ISingleSymbolLegend.LEGEND_NAME, |
220 |
SingleSymbolLegend.class); |
221 |
|
222 |
return Boolean.TRUE; |
223 |
} |
224 |
|
225 |
} |
226 |
|
227 |
} |