svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.mapcontext / org.gvsig.fmap.mapcontext.api / src / test / java / org / gvsig / fmap / mapcontext / impl / DefaultMapContextManagerTest.java @ 40559
History | View | Annotate | Download (10.5 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
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 |
* as published by the Free Software Foundation; either version 3
|
9 |
* 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 |
*
|
16 |
* 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 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
/*
|
25 |
* AUTHORS (In addition to CIT):
|
26 |
* 2009 {DiSiD Technologies} {{Task}}
|
27 |
*/
|
28 |
package org.gvsig.fmap.mapcontext.impl; |
29 |
|
30 |
import java.awt.Graphics2D; |
31 |
import java.awt.image.BufferedImage; |
32 |
import java.util.Map; |
33 |
|
34 |
import org.cresques.cts.ICoordTrans; |
35 |
|
36 |
import org.gvsig.compat.print.PrintAttributes; |
37 |
import org.gvsig.fmap.crs.CRSFactory; |
38 |
import org.gvsig.fmap.dal.exception.ReadException; |
39 |
import org.gvsig.fmap.dal.feature.Feature; |
40 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
41 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
42 |
import org.gvsig.fmap.mapcontext.MapContext; |
43 |
import org.gvsig.fmap.mapcontext.MapContextDrawer; |
44 |
import org.gvsig.fmap.mapcontext.MapContextException; |
45 |
import org.gvsig.fmap.mapcontext.MapContextRuntimeException; |
46 |
import org.gvsig.fmap.mapcontext.ViewPort; |
47 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
48 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
49 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend; |
50 |
import org.gvsig.fmap.mapcontext.rendering.legend.LegendException; |
51 |
import org.gvsig.fmap.mapcontext.rendering.legend.driver.ILegendReader; |
52 |
import org.gvsig.fmap.mapcontext.rendering.legend.driver.ILegendWriter; |
53 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendContentsChangedListener; |
54 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent; |
55 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
56 |
import org.gvsig.tools.evaluator.Evaluator; |
57 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
58 |
import org.gvsig.tools.observer.Observer; |
59 |
import org.gvsig.tools.persistence.PersistentState; |
60 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
61 |
import org.gvsig.tools.task.Cancellable; |
62 |
|
63 |
/**
|
64 |
* @author <a href="mailto:cordinyana@gvsig.org">C?sar Ordi?ana</a>
|
65 |
*/
|
66 |
public class DefaultMapContextManagerTest extends |
67 |
AbstractLibraryAutoInitTestCase { |
68 |
|
69 |
private DefaultMapContextManager manager;
|
70 |
|
71 |
protected void doSetUp() throws Exception { |
72 |
manager = new DefaultMapContextManager();
|
73 |
|
74 |
manager.registerLegend("DummyLegend", DummyVectorLegend.class);
|
75 |
manager.setDefaultVectorLegend("DummyLegend");
|
76 |
manager.registerLegendReader("Dummy", DummyLegendReader.class);
|
77 |
manager.registerLegendWriter("DummyLegend", "Dummy", DummyLegendWriter.class); |
78 |
} |
79 |
|
80 |
protected void tearDown() throws Exception { |
81 |
super.tearDown();
|
82 |
} |
83 |
|
84 |
/**
|
85 |
* Test method for
|
86 |
* {@link org.gvsig.fmap.mapcontext.impl.DefaultMapContextManager#createDefaultMapContextDrawerInstance()}
|
87 |
* .
|
88 |
*/
|
89 |
public void testGetDefaultMapContextDrawerInstance() throws Exception { |
90 |
|
91 |
manager.setDefaultMapContextDrawer(DummyMapContextDrawer.class); |
92 |
|
93 |
MapContextDrawer drawer = manager |
94 |
.createDefaultMapContextDrawerInstance(); |
95 |
|
96 |
assertNotNull("The created MapContextDrawer instance can't be null",
|
97 |
drawer); |
98 |
assertTrue( |
99 |
"The created MapContextDrawer is not instance of the registered class"
|
100 |
+ DummyMapContextDrawer.class, |
101 |
drawer instanceof DummyMapContextDrawer);
|
102 |
} |
103 |
|
104 |
/**
|
105 |
* Test method for
|
106 |
* {@link org.gvsig.fmap.mapcontext.impl.DefaultMapContextManager#setDefaultMapContextDrawer(java.lang.Class)}
|
107 |
* .
|
108 |
*/
|
109 |
public void testSetDefaultMapContextDrawer() throws Exception { |
110 |
|
111 |
// First, try to register an invalid class
|
112 |
try {
|
113 |
manager.setDefaultMapContextDrawer(Object.class);
|
114 |
fail("Error, a class that does not implement the MapContextDrawer "
|
115 |
+ "interface has been accepted");
|
116 |
} catch (MapContextRuntimeException e) {
|
117 |
// OK
|
118 |
} |
119 |
|
120 |
// Next, try to register a valid class
|
121 |
manager.setDefaultMapContextDrawer(DummyMapContextDrawer.class); |
122 |
} |
123 |
|
124 |
public void testCreateGraphicsLayer() throws Exception { |
125 |
assertNotNull(manager.createGraphicsLayer(CRSFactory.getCRS("EPSG:23030")));
|
126 |
} |
127 |
|
128 |
public void testCreateDefaultVectorLegend() throws Exception { |
129 |
|
130 |
IVectorLegend legend = manager.createDefaultVectorLegend(1);
|
131 |
assertNotNull(legend); |
132 |
assertTrue(legend instanceof DummyVectorLegend);
|
133 |
} |
134 |
|
135 |
public void testRegisterCreateLegend() throws Exception { |
136 |
|
137 |
manager.registerLegend("DummyLegend", DummyVectorLegend.class);
|
138 |
|
139 |
ILegend legend = manager.createLegend("DummyLegend");
|
140 |
assertNotNull(legend); |
141 |
assertTrue(legend instanceof DummyVectorLegend);
|
142 |
|
143 |
assertNull(manager.createLegend("NONE"));
|
144 |
} |
145 |
|
146 |
public void testRegisterCreateLegendReader() throws Exception { |
147 |
|
148 |
manager.registerLegendReader("Dummy", DummyLegendReader.class);
|
149 |
|
150 |
ILegendReader legendReader = manager.createLegendReader("Dummy");
|
151 |
assertNotNull(legendReader); |
152 |
assertTrue(legendReader instanceof DummyLegendReader);
|
153 |
|
154 |
assertNull(manager.createLegendReader("NONE"));
|
155 |
} |
156 |
|
157 |
public void testRegisterCreateLegendWriter() throws Exception { |
158 |
|
159 |
manager.registerLegend("DummyLegend", DummyVectorLegend.class);
|
160 |
|
161 |
manager.registerLegendWriter("DummyLegend", "Dummy", |
162 |
DummyLegendWriter.class); |
163 |
|
164 |
// Test the registered writer is created
|
165 |
ILegendWriter legendWriter = manager.createLegendWriter("DummyLegend",
|
166 |
"Dummy");
|
167 |
assertNotNull(legendWriter); |
168 |
assertTrue(legendWriter instanceof DummyLegendWriter);
|
169 |
|
170 |
// Test non registered cases
|
171 |
assertNull(manager.createLegendWriter("NONE", "Dummy")); |
172 |
assertNull(manager.createLegendWriter("DummyLegend", "NONE")); |
173 |
assertNull(manager.createLegendWriter("NONE", "NONE")); |
174 |
} |
175 |
|
176 |
public static class DummyMapContextDrawer implements MapContextDrawer { |
177 |
|
178 |
public void dispose() { |
179 |
} |
180 |
|
181 |
public void draw(FLayers root, BufferedImage image, Graphics2D g, |
182 |
Cancellable cancel, double scale) throws ReadException { |
183 |
} |
184 |
|
185 |
public void print(FLayers root, Graphics2D g, Cancellable cancel, |
186 |
double scale, PrintAttributes properties) throws ReadException { |
187 |
} |
188 |
|
189 |
public void setMapContext(MapContext mapContext) { |
190 |
} |
191 |
|
192 |
public void setViewPort(ViewPort viewPort) { |
193 |
} |
194 |
|
195 |
} |
196 |
|
197 |
public static class DummyLegendReader implements ILegendReader { |
198 |
|
199 |
} |
200 |
|
201 |
public static class DummyLegendWriter implements ILegendWriter { |
202 |
|
203 |
} |
204 |
|
205 |
public static class DummyVectorLegend implements IVectorLegend { |
206 |
|
207 |
public void draw(BufferedImage image, Graphics2D graphics2d, |
208 |
ViewPort viewPort, Cancellable cancel, double scale,
|
209 |
Map queryParameters, ICoordTrans coordTrans,
|
210 |
FeatureStore featureStore, FeatureQuery featureQuery) throws LegendException {
|
211 |
// Empty method
|
212 |
} |
213 |
|
214 |
public void draw(BufferedImage image, Graphics2D graphics2d, |
215 |
ViewPort viewPort, Cancellable cancel, double scale,
|
216 |
Map queryParameters, ICoordTrans coordTrans,
|
217 |
FeatureStore featureStore) throws LegendException {
|
218 |
// Empty method
|
219 |
} |
220 |
|
221 |
public int getShapeType() { |
222 |
// Empty method
|
223 |
return 0; |
224 |
} |
225 |
|
226 |
public ISymbol getSymbolByFeature(Feature feat)
|
227 |
throws MapContextException {
|
228 |
// Empty method
|
229 |
return null; |
230 |
} |
231 |
|
232 |
public boolean isSuitableForShapeType(int shapeType) { |
233 |
// Empty method
|
234 |
return false; |
235 |
} |
236 |
|
237 |
public boolean isUseDefaultSymbol() { |
238 |
// Empty method
|
239 |
return false; |
240 |
} |
241 |
|
242 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
243 |
double scale, Map queryParameters, ICoordTrans coordTrans, |
244 |
FeatureStore featureStore, PrintAttributes properties) |
245 |
throws LegendException {
|
246 |
// Empty method
|
247 |
} |
248 |
|
249 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
250 |
double scale, Map queryParameters, ICoordTrans coordTrans, |
251 |
FeatureStore featureStore, FeatureQuery featureQuery, PrintAttributes properties) |
252 |
throws LegendException {
|
253 |
// Empty method
|
254 |
} |
255 |
|
256 |
public void setDefaultSymbol(ISymbol s) { |
257 |
// Empty method
|
258 |
} |
259 |
|
260 |
public void setShapeType(int shapeType) { |
261 |
// Empty method
|
262 |
} |
263 |
|
264 |
public void useDefaultSymbol(boolean b) { |
265 |
// Empty method
|
266 |
} |
267 |
|
268 |
public void addLegendListener(LegendContentsChangedListener listener) { |
269 |
// Empty method
|
270 |
} |
271 |
|
272 |
public ILegend cloneLegend() {
|
273 |
// Empty method
|
274 |
return null; |
275 |
} |
276 |
|
277 |
public Object clone() throws CloneNotSupportedException { |
278 |
// TODO Auto-generated method stub
|
279 |
return super.clone(); |
280 |
} |
281 |
|
282 |
public void fireDefaultSymbolChangedEvent(SymbolLegendEvent event) { |
283 |
// Empty method
|
284 |
} |
285 |
|
286 |
public ISymbol getDefaultSymbol() {
|
287 |
// Empty method
|
288 |
return null; |
289 |
} |
290 |
|
291 |
public LegendContentsChangedListener[] getListeners() { |
292 |
// Empty method
|
293 |
return null; |
294 |
} |
295 |
|
296 |
public void removeLegendListener(LegendContentsChangedListener listener) { |
297 |
// Empty method
|
298 |
} |
299 |
|
300 |
public void loadFromState(PersistentState state) |
301 |
throws PersistenceException {
|
302 |
// Empty method
|
303 |
} |
304 |
|
305 |
public void saveToState(PersistentState state) |
306 |
throws PersistenceException {
|
307 |
// Empty method
|
308 |
} |
309 |
|
310 |
public void addDrawingObserver(Observer observer) { |
311 |
// Empty method
|
312 |
} |
313 |
|
314 |
public void deleteDrawingObserver(Observer observer) { |
315 |
// Empty method
|
316 |
} |
317 |
|
318 |
public void deleteDrawingObservers() { |
319 |
// Empty method
|
320 |
} |
321 |
} |
322 |
} |