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 / legend / impl / SingleSymbolLegend.java @ 44361
History | View | Annotate | Download (6.1 KB)
1 | 40560 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40560 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | 40560 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * of the License, or (at your option) any later version.
|
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | 43326 | jjdelcerro | |
16 | 40435 | jjdelcerro | * You should have received a copy of the GNU General Public License
|
17 | * along with this program; if not, write to the Free Software
|
||
18 | 40560 | jjdelcerro | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | * MA 02110-1301, USA.
|
||
20 | 40435 | jjdelcerro | *
|
21 | 40560 | jjdelcerro | * For any additional information, do not hesitate to contact us
|
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40435 | jjdelcerro | */
|
24 | package org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl; |
||
25 | |||
26 | import org.gvsig.fmap.dal.exception.DataException; |
||
27 | import org.gvsig.fmap.dal.feature.Feature; |
||
28 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
29 | import org.gvsig.fmap.geom.Geometry; |
||
30 | import org.gvsig.fmap.mapcontext.MapContextLocator; |
||
31 | import org.gvsig.fmap.mapcontext.MapContextManager; |
||
32 | import org.gvsig.fmap.mapcontext.rendering.legend.ISingleSymbolLegend; |
||
33 | import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent; |
||
34 | import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
||
35 | import org.gvsig.tools.ToolsLocator; |
||
36 | import org.gvsig.tools.dynobject.DynStruct; |
||
37 | import org.gvsig.tools.persistence.PersistenceManager; |
||
38 | import org.gvsig.tools.persistence.PersistentState; |
||
39 | import org.gvsig.tools.persistence.exception.PersistenceException; |
||
40 | import org.gvsig.tools.util.Callable; |
||
41 | import org.slf4j.Logger; |
||
42 | import org.slf4j.LoggerFactory; |
||
43 | |||
44 | /**
|
||
45 | * Implements a legend composed by single symbols.
|
||
46 | *
|
||
47 | */
|
||
48 | public class SingleSymbolLegend extends AbstractVectorialLegend implements |
||
49 | ISingleSymbolLegend { |
||
50 | |||
51 | final static private Logger LOG = LoggerFactory.getLogger(VectorialUniqueValueLegend.class); |
||
52 | |||
53 | public static final String SINGLE_SYMBOL_PERSISTENCE_DEFINITION_NAME = |
||
54 | "SimgleSymbolLegend";
|
||
55 | |||
56 | private ISymbol defaultSymbol;
|
||
57 | private int shapeType = Geometry.TYPES.SURFACE; // Por defecto, tipo pol?gono |
||
58 | |||
59 | /**
|
||
60 | * Constructor method, needed by persistence.
|
||
61 | */
|
||
62 | public SingleSymbolLegend() {
|
||
63 | super();
|
||
64 | } |
||
65 | |||
66 | /**
|
||
67 | * Convenience fast constructor.
|
||
68 | *
|
||
69 | * @param style S?mbolo.
|
||
70 | */
|
||
71 | public SingleSymbolLegend(ISymbol style) {
|
||
72 | super();
|
||
73 | setDefaultSymbol(style); |
||
74 | } |
||
75 | |||
76 | |||
77 | 43326 | jjdelcerro | @Override
|
78 | 40435 | jjdelcerro | public void setDefaultSymbol(ISymbol s) { |
79 | 43326 | jjdelcerro | if (s == null) { |
80 | throw new NullPointerException("Default symbol cannot be null"); |
||
81 | } |
||
82 | 40435 | jjdelcerro | ISymbol old = defaultSymbol; |
83 | defaultSymbol = s; |
||
84 | fireDefaultSymbolChangedEvent(new SymbolLegendEvent(old, s));
|
||
85 | } |
||
86 | |||
87 | |||
88 | public ISymbol getSymbol(int recordIndex) { |
||
89 | return defaultSymbol;
|
||
90 | } |
||
91 | |||
92 | 43326 | jjdelcerro | @Override
|
93 | 40435 | jjdelcerro | public ISymbol getDefaultSymbol() {
|
94 | if(defaultSymbol==null) { |
||
95 | defaultSymbol = getSymbolManager().createSymbol(shapeType); |
||
96 | } |
||
97 | return defaultSymbol;
|
||
98 | } |
||
99 | |||
100 | |||
101 | |||
102 | 43326 | jjdelcerro | @Override
|
103 | 40435 | jjdelcerro | public int getShapeType() { |
104 | return shapeType;
|
||
105 | } |
||
106 | |||
107 | 43326 | jjdelcerro | @Override
|
108 | 40435 | jjdelcerro | public void setShapeType(int shapeType) { |
109 | if (this.shapeType != shapeType) { |
||
110 | if(defaultSymbol==null || defaultSymbol.getSymbolType()!=shapeType){ |
||
111 | defaultSymbol = getSymbolManager().createSymbol(shapeType); |
||
112 | } |
||
113 | this.shapeType = shapeType;
|
||
114 | } |
||
115 | } |
||
116 | |||
117 | 43326 | jjdelcerro | @Override
|
118 | 40435 | jjdelcerro | public ISymbol getSymbolByFeature(Feature feat) {
|
119 | return getDefaultSymbol();
|
||
120 | } |
||
121 | |||
122 | 43326 | jjdelcerro | @Override
|
123 | 40435 | jjdelcerro | public void useDefaultSymbol(boolean b) { |
124 | LOG.warn("TODO: SingleSymbolLegend.useDefaultSymbol");
|
||
125 | } |
||
126 | |||
127 | public String[] getUsedFields() { |
||
128 | return new String[0]; |
||
129 | } |
||
130 | |||
131 | 43326 | jjdelcerro | @Override
|
132 | 40435 | jjdelcerro | public boolean isUseDefaultSymbol() { |
133 | return true; |
||
134 | |||
135 | } |
||
136 | |||
137 | |||
138 | public String getClassName() { |
||
139 | return getClass().getName();
|
||
140 | } |
||
141 | |||
142 | 43326 | jjdelcerro | @Override
|
143 | 40435 | jjdelcerro | public boolean isSuitableForShapeType(int shapeType) { |
144 | return getShapeType() == shapeType;
|
||
145 | } |
||
146 | |||
147 | |||
148 | public void setFeatureStore(FeatureStore fs) throws DataException { |
||
149 | LOG.warn("TODO: SingleSymbolLegend.useDefaultSymbol");
|
||
150 | } |
||
151 | |||
152 | 43326 | jjdelcerro | @Override
|
153 | 40435 | jjdelcerro | protected String[] getRequiredFeatureAttributeNames( |
154 | FeatureStore featureStore) throws DataException {
|
||
155 | // We only need the default Geometry to draw
|
||
156 | 43326 | jjdelcerro | return new String[] { featureStore.getDefaultFeatureType().getDefaultGeometryAttributeName() }; |
157 | 40435 | jjdelcerro | } |
158 | |||
159 | 43326 | jjdelcerro | @Override
|
160 | 40435 | jjdelcerro | public Object clone() throws CloneNotSupportedException { |
161 | SingleSymbolLegend clone = (SingleSymbolLegend) super.clone();
|
||
162 | |||
163 | // Clone default symbol
|
||
164 | if (defaultSymbol != null) { |
||
165 | clone.defaultSymbol = (ISymbol) defaultSymbol.clone(); |
||
166 | } |
||
167 | |||
168 | return clone;
|
||
169 | } |
||
170 | |||
171 | 43326 | jjdelcerro | @Override
|
172 | 40435 | jjdelcerro | public void loadFromState(PersistentState state) |
173 | throws PersistenceException {
|
||
174 | super.loadFromState(state);
|
||
175 | } |
||
176 | |||
177 | 43326 | jjdelcerro | @Override
|
178 | 40435 | jjdelcerro | public void saveToState(PersistentState state) throws PersistenceException { |
179 | super.saveToState(state);
|
||
180 | } |
||
181 | |||
182 | public static class RegisterPersistence implements Callable { |
||
183 | |||
184 | 43326 | jjdelcerro | @Override
|
185 | 40435 | jjdelcerro | public Object call() throws Exception { |
186 | PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
||
187 | if( manager.getDefinition(SINGLE_SYMBOL_PERSISTENCE_DEFINITION_NAME)==null ) { |
||
188 | DynStruct definition = manager.addDefinition( |
||
189 | SingleSymbolLegend.class, |
||
190 | SINGLE_SYMBOL_PERSISTENCE_DEFINITION_NAME, |
||
191 | SINGLE_SYMBOL_PERSISTENCE_DEFINITION_NAME+" Persistence definition",
|
||
192 | null,
|
||
193 | null
|
||
194 | ); |
||
195 | // Extend the Vectorial Legend base definition
|
||
196 | definition.extend(manager.getDefinition(VECTORIAL_LEGEND_PERSISTENCE_DEFINITION_NAME)); |
||
197 | } |
||
198 | return Boolean.TRUE; |
||
199 | } |
||
200 | |||
201 | } |
||
202 | |||
203 | public static class RegisterLegend implements Callable { |
||
204 | |||
205 | 43326 | jjdelcerro | @Override
|
206 | 40435 | jjdelcerro | public Object call() throws Exception { |
207 | MapContextManager manager = MapContextLocator.getMapContextManager(); |
||
208 | |||
209 | manager.registerLegend(ISingleSymbolLegend.LEGEND_NAME, |
||
210 | SingleSymbolLegend.class); |
||
211 | |||
212 | return Boolean.TRUE; |
||
213 | } |
||
214 | |||
215 | } |
||
216 | |||
217 | } |