svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.symbology / org.gvsig.symbology.lib / org.gvsig.symbology.lib.impl / src / main / java / org / gvsig / symbology / fmap / mapcontext / rendering / dynamiclegend / DefaultDynamicVectorLegend.java @ 44247
History | View | Annotate | Download (6.53 KB)
1 |
/*
|
---|---|
2 |
* To change this license header, choose License Headers in Project Properties.
|
3 |
* To change this template file, choose Tools | Templates
|
4 |
* and open the template in the editor.
|
5 |
*/
|
6 |
package org.gvsig.symbology.fmap.mapcontext.rendering.dynamiclegend; |
7 |
|
8 |
import org.gvsig.fmap.dal.exception.DataException; |
9 |
import org.gvsig.fmap.dal.feature.Feature; |
10 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
11 |
import org.gvsig.fmap.geom.Geometry; |
12 |
import org.gvsig.fmap.geom.type.GeometryType; |
13 |
import org.gvsig.fmap.mapcontext.MapContextException; |
14 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
15 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
16 |
import org.gvsig.fmap.mapcontext.rendering.legend.ISingleSymbolLegend; |
17 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent; |
18 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
19 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager; |
20 |
import org.gvsig.symbology.SymbologyLocator; |
21 |
import org.gvsig.symbology.SymbologyManager; |
22 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractVectorialLegend; |
23 |
import static org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractVectorialLegend.VECTORIAL_LEGEND_PERSISTENCE_DEFINITION_NAME; |
24 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.VectorialUniqueValueLegend; |
25 |
import org.gvsig.tools.ToolsLocator; |
26 |
import org.gvsig.tools.dynobject.DynStruct; |
27 |
import org.gvsig.tools.persistence.PersistenceManager; |
28 |
import org.gvsig.tools.persistence.PersistentState; |
29 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
30 |
import org.gvsig.tools.util.Callable; |
31 |
import org.slf4j.Logger; |
32 |
import org.slf4j.LoggerFactory; |
33 |
|
34 |
/**
|
35 |
*
|
36 |
* @author osc
|
37 |
*/
|
38 |
public class DefaultDynamicVectorLegend extends AbstractVectorialLegend implements DynamicVectorLegend { |
39 |
|
40 |
final static private Logger LOG = LoggerFactory.getLogger(VectorialUniqueValueLegend.class); |
41 |
|
42 |
public static final String DYNAMIC_VECTOR_PERSISTENCE_DEFINITION_NAME |
43 |
= "SimgleSymbolLegend";
|
44 |
public static final String LEGEND_NAME = "DynamicSymbol"; |
45 |
private ISymbol defaultSymbol;
|
46 |
private int shapeType = Geometry.TYPES.SURFACE; // Por defecto, tipo pol?gono |
47 |
|
48 |
/**
|
49 |
* Constructor method, needed by persistence.
|
50 |
*/
|
51 |
public DefaultDynamicVectorLegend() {
|
52 |
|
53 |
} |
54 |
|
55 |
/**
|
56 |
* Convenience fast constructor.
|
57 |
*
|
58 |
* @param style S?mbolo.
|
59 |
*/
|
60 |
public DefaultDynamicVectorLegend(ISymbol style) {
|
61 |
|
62 |
setDefaultSymbol(style); |
63 |
} |
64 |
|
65 |
@Override
|
66 |
public void setDefaultSymbol(ISymbol s) { |
67 |
if (s == null) { |
68 |
throw new NullPointerException("Default symbol cannot be null"); |
69 |
} |
70 |
ISymbol old = defaultSymbol; |
71 |
defaultSymbol = s; |
72 |
// fireDefaultSymbolChangedEvent(new SymbolLegendEvent(old, s));
|
73 |
} |
74 |
|
75 |
public ISymbol getSymbol(int recordIndex) { |
76 |
return defaultSymbol;
|
77 |
} |
78 |
|
79 |
@Override
|
80 |
public ISymbol getDefaultSymbol() {
|
81 |
if (defaultSymbol == null) { |
82 |
SymbologyManager symbolManager = SymbologyLocator.getSymbologyManager(); |
83 |
defaultSymbol = symbolManager.createDynamicSymbol(); |
84 |
} |
85 |
return defaultSymbol;
|
86 |
} |
87 |
|
88 |
@Override
|
89 |
public int getShapeType() { |
90 |
return shapeType;
|
91 |
} |
92 |
|
93 |
@Override
|
94 |
public void setShapeType(int shapeType) { |
95 |
if (this.shapeType != shapeType) { |
96 |
if (defaultSymbol == null || defaultSymbol.getSymbolType() != shapeType) { |
97 |
defaultSymbol = getSymbolManager().createSymbol(shapeType); |
98 |
} |
99 |
this.shapeType = shapeType;
|
100 |
} |
101 |
} |
102 |
|
103 |
@Override
|
104 |
public ISymbol getSymbolByFeature(Feature feat) {
|
105 |
DynamicSymbol symbol = (DynamicSymbol) getDefaultSymbol(); |
106 |
symbol.setFeature(feat); |
107 |
return symbol;
|
108 |
|
109 |
} |
110 |
|
111 |
@Override
|
112 |
public void useDefaultSymbol(boolean b) { |
113 |
LOG.warn("TODO: SingleSymbolLegend.useDefaultSymbol");
|
114 |
} |
115 |
|
116 |
public String[] getUsedFields() { |
117 |
return new String[0]; |
118 |
} |
119 |
|
120 |
@Override
|
121 |
public boolean isUseDefaultSymbol() { |
122 |
return true; |
123 |
|
124 |
} |
125 |
|
126 |
public String getClassName() { |
127 |
return getClass().getName();
|
128 |
} |
129 |
|
130 |
@Override
|
131 |
public boolean isSuitableForShapeType(int shapeType) { |
132 |
return getShapeType() == shapeType;
|
133 |
} |
134 |
|
135 |
public void setFeatureStore(FeatureStore fs) throws DataException { |
136 |
LOG.warn("TODO: SingleSymbolLegend.useDefaultSymbol");
|
137 |
} |
138 |
|
139 |
@Override
|
140 |
protected String[] getRequiredFeatureAttributeNames( |
141 |
FeatureStore featureStore) throws DataException {
|
142 |
// We only need the default Geometry to draw
|
143 |
return new String[]{featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName()}; |
144 |
} |
145 |
|
146 |
@Override
|
147 |
public Object clone() throws CloneNotSupportedException { |
148 |
DynamicVectorLegend clone = (DynamicVectorLegend) super.clone();
|
149 |
|
150 |
// // Clone default symbol
|
151 |
// if (defaultSymbol != null) {
|
152 |
// clone.defaultSymbol = (ISymbol) defaultSymbol.clone();
|
153 |
// }
|
154 |
|
155 |
return clone;
|
156 |
} |
157 |
|
158 |
@Override
|
159 |
public void loadFromState(PersistentState state) |
160 |
throws PersistenceException {
|
161 |
super.loadFromState(state);
|
162 |
} |
163 |
|
164 |
@Override
|
165 |
public void saveToState(PersistentState state) throws PersistenceException { |
166 |
super.saveToState(state);
|
167 |
} |
168 |
|
169 |
public static class RegisterPersistence implements Callable { |
170 |
|
171 |
@Override
|
172 |
public Object call() throws Exception { |
173 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
174 |
if (manager.getDefinition(DYNAMIC_VECTOR_PERSISTENCE_DEFINITION_NAME) == null) { |
175 |
DynStruct definition = manager.addDefinition( |
176 |
DynamicVectorLegend.class, |
177 |
DYNAMIC_VECTOR_PERSISTENCE_DEFINITION_NAME, |
178 |
DYNAMIC_VECTOR_PERSISTENCE_DEFINITION_NAME + " Persistence definition",
|
179 |
null,
|
180 |
null
|
181 |
); |
182 |
// Extend the Vectorial Legend base definition
|
183 |
definition.extend(manager.getDefinition(VECTORIAL_LEGEND_PERSISTENCE_DEFINITION_NAME)); |
184 |
} |
185 |
return Boolean.TRUE; |
186 |
} |
187 |
|
188 |
} |
189 |
|
190 |
public static class RegisterLegend implements Callable { |
191 |
|
192 |
@Override
|
193 |
public Object call() throws Exception { |
194 |
MapContextManager manager = MapContextLocator.getMapContextManager(); |
195 |
|
196 |
// manager.registerLegend(ISingleSymbolLegend.LEGEND_NAME,
|
197 |
manager.registerLegend(LEGEND_NAME, |
198 |
DynamicVectorLegend.class); |
199 |
|
200 |
return Boolean.TRUE; |
201 |
} |
202 |
|
203 |
} |
204 |
|
205 |
} |