Revision 46755
tags/org.gvsig.desktop-2.0.395/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/test/java/org/gvsig/fmap/mapcontext/persistence/DummyFileFeatureStore.java | ||
---|---|---|
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 modify it under |
|
7 |
* the terms of the GNU General Public License as published by the Free Software |
|
8 |
* Foundation; either version 3 of the License, or (at your option) any later |
|
9 |
* version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
14 |
* details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License along with |
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51 |
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
19 |
* |
|
20 |
* For any additional information, do not hesitate to contact us at info AT |
|
21 |
* gvsig.com, or visit our website www.gvsig.com. |
|
22 |
*/ |
|
23 |
package org.gvsig.fmap.mapcontext.persistence; |
|
24 |
|
|
25 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
26 |
import org.gvsig.tools.ToolsLocator; |
|
27 |
import org.gvsig.tools.dynobject.DynStruct; |
|
28 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
29 |
import org.gvsig.tools.persistence.PersistentState; |
|
30 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
31 |
import org.gvsig.fmap.dal.feature.DummyFetureStore; |
|
32 |
|
|
33 |
public class DummyFileFeatureStore extends DummyFetureStore implements FeatureStore { |
|
34 |
|
|
35 |
private String name = "[empty]"; |
|
36 |
|
|
37 |
public DummyFileFeatureStore() { |
|
38 |
|
|
39 |
} |
|
40 |
|
|
41 |
public DummyFileFeatureStore(String id) { |
|
42 |
name = "[FILE FEATURE STORE - " + id + "]"; |
|
43 |
} |
|
44 |
|
|
45 |
public String getName() { |
|
46 |
return name; |
|
47 |
} |
|
48 |
|
|
49 |
public void loadFromState(PersistentState state) |
|
50 |
throws PersistenceException { |
|
51 |
name = state.getString("name"); |
|
52 |
} |
|
53 |
|
|
54 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
55 |
state.set("name", name); |
|
56 |
} |
|
57 |
|
|
58 |
public static void registerPersistent() { |
|
59 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
60 |
DynStruct definition = manager.addDefinition( |
|
61 |
DummyFileFeatureStore.class, |
|
62 |
"DummyFileFeatureStore", |
|
63 |
"DummyFileFeatureStore Persistence definition", |
|
64 |
null, |
|
65 |
null |
|
66 |
); |
|
67 |
definition.addDynFieldString("name") |
|
68 |
.setMandatory(true); |
|
69 |
} |
|
70 |
|
|
71 |
} |
|
0 | 72 |
tags/org.gvsig.desktop-2.0.395/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/test/java/org/gvsig/fmap/mapcontext/persistence/MapContextPersistenceTest.java | ||
---|---|---|
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 |
package org.gvsig.fmap.mapcontext.persistence; |
|
25 |
|
|
26 |
import java.awt.Color; |
|
27 |
import java.awt.Dimension; |
|
28 |
import java.awt.geom.Rectangle2D; |
|
29 |
import java.io.File; |
|
30 |
import java.io.FileInputStream; |
|
31 |
import java.io.FileOutputStream; |
|
32 |
|
|
33 |
import org.gvsig.fmap.crs.CRSFactory; |
|
34 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
35 |
import org.gvsig.fmap.geom.Geometry; |
|
36 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
|
37 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
38 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
|
39 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
40 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
41 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
|
42 |
import org.gvsig.fmap.mapcontext.ViewPort; |
|
43 |
import org.gvsig.fmap.mapcontext.exceptions.LegendLayerException; |
|
44 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
45 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
|
46 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
47 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
|
48 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend; |
|
49 |
import org.gvsig.fmap.mapcontext.rendering.symbol.DummyVectorLegend; |
|
50 |
import org.gvsig.tools.ToolsLocator; |
|
51 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
|
52 |
import org.gvsig.tools.locator.LocatorException; |
|
53 |
import org.gvsig.tools.persistence.Persistent; |
|
54 |
import org.gvsig.tools.persistence.PersistentState; |
|
55 |
import org.slf4j.Logger; |
|
56 |
import org.slf4j.LoggerFactory; |
|
57 |
|
|
58 |
public class MapContextPersistenceTest extends AbstractLibraryAutoInitTestCase { |
|
59 |
|
|
60 |
final static private Logger logger = |
|
61 |
LoggerFactory.getLogger(MapContextPersistenceTest.class); |
|
62 |
|
|
63 |
protected void doSetUp() throws Exception { |
|
64 |
DummyVectorLegend.registerPersistent(); |
|
65 |
DummyDBFeatureStore.registerPersistent(); |
|
66 |
DummyFileFeatureStore.registerPersistent(); |
|
67 |
|
|
68 |
MapContextLocator.getMapContextManager().registerLegend("DummyLegend", |
|
69 |
DummyVectorLegend.class); |
|
70 |
MapContextLocator.getMapContextManager().setDefaultVectorLegend( |
|
71 |
"DummyLegend"); |
|
72 |
} |
|
73 |
|
|
74 |
private File getTempFile() throws Exception { |
|
75 |
|
|
76 |
File tempFile = File.createTempFile("persisted_mapcontext", ".xml"); |
|
77 |
if (tempFile.exists()) |
|
78 |
tempFile.delete(); |
|
79 |
tempFile.createNewFile(); |
|
80 |
|
|
81 |
System.out.println("TEMP FILE: " + tempFile.getAbsolutePath()); |
|
82 |
return tempFile; |
|
83 |
} |
|
84 |
|
|
85 |
public void testMapContext() throws Exception { |
|
86 |
ViewPort vp = getViewPort(); |
|
87 |
logger.debug("Creating mapcontext..."); |
|
88 |
MapContext mc = new MapContext(vp); |
|
89 |
addDummyLayers(mc); |
|
90 |
doTestPersist(mc); |
|
91 |
} |
|
92 |
|
|
93 |
public void noTestFLyrs() throws Exception { |
|
94 |
|
|
95 |
int lyr_count = 3; |
|
96 |
// testPersist(mc); |
|
97 |
FLyrVect[] lyr = new FLyrVect[lyr_count]; |
|
98 |
FeatureStore[] fs = new FeatureStore[lyr_count]; |
|
99 |
FLayers lyrs = new FLayers(); |
|
100 |
|
|
101 |
for (int i=0; i<lyr_count; i++) { |
|
102 |
fs[i] = new DummyFileFeatureStore("" + System.currentTimeMillis()); |
|
103 |
lyr[i] = createLayer(fs[i]); |
|
104 |
lyr[i].setName("Layer " + (i+System.currentTimeMillis())); |
|
105 |
lyr[i].setIsLabeled(false); |
|
106 |
try { lyr[i].setLegend(new DummyVectorLegend(TYPES.SOLID)); } catch (LegendLayerException e) { |
|
107 |
assertTrue("Error while creating legend: " + e.getMessage(), false); |
|
108 |
} |
|
109 |
lyrs.addLayer(lyr[i]); |
|
110 |
lyr[i].dispose(); |
|
111 |
} |
|
112 |
|
|
113 |
for (int i=0; i<lyr_count; i++) { |
|
114 |
fs[i] = new DummyDBFeatureStore("" + System.currentTimeMillis()); |
|
115 |
lyr[i] = createLayer(fs[i]); |
|
116 |
lyr[i].setName("Layer " + (10000 + i + System.currentTimeMillis())); |
|
117 |
lyr[i].setIsLabeled(false); |
|
118 |
try { lyr[i].setLegend(new DummyVectorLegend(TYPES.SOLID)); } catch (LegendLayerException e) { |
|
119 |
assertTrue("Error while creating legend: " + e.getMessage(), false); |
|
120 |
} |
|
121 |
lyrs.addLayer(lyr[i]); |
|
122 |
lyr[i].dispose(); |
|
123 |
} |
|
124 |
|
|
125 |
doTestPersist(lyrs); |
|
126 |
} |
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
private ViewPort getViewPort() throws LocatorException, CreateEnvelopeException { |
|
131 |
|
|
132 |
ViewPort vp = new ViewPort(CRSFactory.getCRS("EPSG:4326")); |
|
133 |
vp.setImageSize(new Dimension(640, 480)); |
|
134 |
Envelope env = createEnvelope2D(0, 0, 1000000, 1000000); |
|
135 |
vp.setEnvelope(env); |
|
136 |
env = createEnvelope2D(200000, 200000, 500000, 500000); |
|
137 |
vp.setEnvelope(env); |
|
138 |
env = createEnvelope2D(300000, 300000, 300000, 300000); |
|
139 |
vp.setEnvelope(env); |
|
140 |
env = createEnvelope2D(400000, 400000, 200000, 200000); |
|
141 |
vp.setEnvelope(env); |
|
142 |
env = createEnvelope2D(440000, 440000, 100000, 100000); |
|
143 |
vp.setEnvelope(env); |
|
144 |
env = createEnvelope2D(480000, 480000, 30000, 30000); |
|
145 |
vp.setEnvelope(env); |
|
146 |
vp.setBackColor(Color.YELLOW); |
|
147 |
vp.setClipRect(new Rectangle2D.Double(0, 0, 10, 10)); |
|
148 |
return vp; |
|
149 |
} |
|
150 |
|
|
151 |
private Envelope createEnvelope2D(double minX,double minY,double maxX, double maxY) throws LocatorException, CreateEnvelopeException { |
|
152 |
return GeometryLocator.getGeometryManager().createEnvelope(minX, minY, maxX, maxY, Geometry.SUBTYPES.GEOM2D); |
|
153 |
} |
|
154 |
|
|
155 |
private void addDummyLayers(MapContext mcon) throws Exception { |
|
156 |
|
|
157 |
FLayers resp = new FLayers(); |
|
158 |
resp.setMapContext(mcon); |
|
159 |
resp.setName("root layer"); |
|
160 |
|
|
161 |
FLayers aux = new FLayers(); |
|
162 |
aux.setMapContext(mcon); |
|
163 |
aux.setName("Group"); |
|
164 |
|
|
165 |
FLyrVect lyr = null; |
|
166 |
IVectorLegend lgn = null; |
|
167 |
FeatureStore fs = null; |
|
168 |
|
|
169 |
logger.debug("Adding dummy layers..."); |
|
170 |
|
|
171 |
fs = new DummyFileFeatureStore("1"); |
|
172 |
lyr = createLayer(fs); |
|
173 |
lyr.setName("Layer 1"); |
|
174 |
try { lyr.setLegend(new DummyVectorLegend(TYPES.SOLID)); } catch (LegendLayerException e) { } |
|
175 |
|
|
176 |
aux.addLayer(lyr); |
|
177 |
lyr.dispose(); |
|
178 |
|
|
179 |
fs = new DummyDBFeatureStore("A"); |
|
180 |
lyr = createLayer(fs); |
|
181 |
lyr.setName("Layer A"); |
|
182 |
try { lyr.setLegend(new DummyVectorLegend(TYPES.SOLID)); } catch (LegendLayerException e) { } |
|
183 |
|
|
184 |
aux.addLayer(lyr); |
|
185 |
lyr.dispose(); |
|
186 |
|
|
187 |
fs = new DummyFileFeatureStore("2"); |
|
188 |
lyr = createLayer(fs); |
|
189 |
lyr.setName("Layer 2"); |
|
190 |
try { lyr.setLegend(new DummyVectorLegend(TYPES.SOLID)); } catch (LegendLayerException e) { } |
|
191 |
|
|
192 |
aux.addLayer(lyr); |
|
193 |
lyr.dispose(); |
|
194 |
|
|
195 |
fs = new DummyDBFeatureStore("B"); |
|
196 |
lyr = createLayer(fs); |
|
197 |
lyr.setName("Layer 1"); |
|
198 |
try { lyr.setLegend(new DummyVectorLegend(TYPES.SOLID)); } catch (LegendLayerException e) { } |
|
199 |
|
|
200 |
resp.addLayer(lyr); |
|
201 |
resp.addLayer(aux); |
|
202 |
lyr.dispose(); |
|
203 |
aux.dispose(); |
|
204 |
|
|
205 |
mcon.getLayers().addLayer(resp); |
|
206 |
resp.dispose(); |
|
207 |
} |
|
208 |
|
|
209 |
private FLyrVect createLayer(FeatureStore fs) throws Exception { |
|
210 |
|
|
211 |
FLyrVect resp = new FLyrVect(); |
|
212 |
resp.setDataStore(fs); |
|
213 |
resp.wakeUp(); |
|
214 |
resp.load(); |
|
215 |
return resp; |
|
216 |
} |
|
217 |
|
|
218 |
private void doTestPersist(Persistent p) throws Exception { |
|
219 |
|
|
220 |
System.out.println("Starting persistence test for class: " + p.getClass().getName()); |
|
221 |
|
|
222 |
File perfile = getTempFile(); |
|
223 |
FileOutputStream fos = new FileOutputStream(perfile); |
|
224 |
System.out.println("Getting state for class: " + p.getClass().getName()); |
|
225 |
PersistentState pst = ToolsLocator.getPersistenceManager().getState(p); |
|
226 |
System.out.println("Saving state..."); |
|
227 |
|
|
228 |
System.out.println("Saving state..."); |
|
229 |
ToolsLocator.getPersistenceManager().saveState(pst, fos); |
|
230 |
System.out.println("Saving state... done."); |
|
231 |
|
|
232 |
fos.close(); |
|
233 |
|
|
234 |
// ============================================== |
|
235 |
// ============================================== |
|
236 |
System.out.println("Is now persisted: " + p.getClass().getName()); |
|
237 |
// ============================================== |
|
238 |
|
|
239 |
// if (true) return; |
|
240 |
|
|
241 |
System.out.println("Opening persistence file..."); |
|
242 |
FileInputStream fis = new FileInputStream(perfile); |
|
243 |
|
|
244 |
System.out.println("Loading state from file..."); |
|
245 |
pst = ToolsLocator.getPersistenceManager().loadState(fis); |
|
246 |
|
|
247 |
System.out.println("Instantiating " + p.getClass().getName() |
|
248 |
+ " from state, pst = " + pst); |
|
249 |
Object p2 = ToolsLocator.getPersistenceManager().create(pst); |
|
250 |
|
|
251 |
System.out.println("Comparing original and current..."); |
|
252 |
comparePersistent(p, p2); |
|
253 |
|
|
254 |
System.out.println("Successful mapcontext persistence test!"); |
|
255 |
|
|
256 |
} |
|
257 |
|
|
258 |
|
|
259 |
// FeatureStore, ILegend, ViewPort |
|
260 |
private void comparePersistent(Persistent p, Object p2) { |
|
261 |
|
|
262 |
if (p2.getClass().getName().compareTo(p.getClass().getName()) == 0) { |
|
263 |
|
|
264 |
if (p instanceof MapContext) { |
|
265 |
compareMapContexts((MapContext) p, (MapContext) p2); |
|
266 |
} else { |
|
267 |
if (p instanceof FLayer) { |
|
268 |
compareLayers((FLayer) p, (FLayer) p2); |
|
269 |
} else { |
|
270 |
if (p instanceof FeatureStore) { |
|
271 |
compareStore((FeatureStore) p, (FeatureStore) p2); |
|
272 |
} else { |
|
273 |
if (p instanceof ILegend) { |
|
274 |
compareLegend((ILegend) p, (ILegend) p2); |
|
275 |
} else { |
|
276 |
if (p instanceof ViewPort) { |
|
277 |
compareViewPorts((ViewPort) p, (ViewPort) p2); |
|
278 |
} else { |
|
279 |
fail("Did not compare: " + p.getClass().getName()); |
|
280 |
} |
|
281 |
} |
|
282 |
} |
|
283 |
} |
|
284 |
} |
|
285 |
} else { |
|
286 |
fail("Comparing different classes (?)"); |
|
287 |
} |
|
288 |
|
|
289 |
} |
|
290 |
|
|
291 |
private void compareMapContexts(MapContext m1, MapContext m2) { |
|
292 |
|
|
293 |
logger.debug("Getting viewports to compare..."); |
|
294 |
ViewPort vp1 = m1.getViewPort(); |
|
295 |
ViewPort vp2 = m2.getViewPort(); |
|
296 |
|
|
297 |
compareViewPorts(vp1, vp2); |
|
298 |
|
|
299 |
logger.debug("Getting root flayers to compare..."); |
|
300 |
FLayers lyr1 = m1.getLayers(); |
|
301 |
FLayers lyr2 = m2.getLayers(); |
|
302 |
compareLayers(lyr1, lyr2); |
|
303 |
} |
|
304 |
|
|
305 |
private void compareLayers(FLayer l1, FLayer l2) { |
|
306 |
|
|
307 |
logger.debug("Comparing layers..."); |
|
308 |
|
|
309 |
assertTrue("Layers of diff type!", l1.getClass().getName().compareTo(l2.getClass().getName()) == 0); |
|
310 |
if (l1 instanceof FLayers) { |
|
311 |
|
|
312 |
logger.debug("(type FLayers)..."); |
|
313 |
FLayers ls1 = (FLayers) l1; |
|
314 |
FLayers ls2 = (FLayers) l2; |
|
315 |
assertEquals(ls1.getLayersCount(), ls2.getLayersCount()); |
|
316 |
int sz = ls2.getLayersCount(); |
|
317 |
for (int i=0; i<sz; i++) { |
|
318 |
compareLayers(ls1.getLayer(i), ls2.getLayer(i)); |
|
319 |
} |
|
320 |
|
|
321 |
} else { |
|
322 |
if (l1 instanceof FLyrVect) { |
|
323 |
|
|
324 |
logger.debug("(type FLyrVect)..."); |
|
325 |
FLyrVect ls1 = (FLyrVect) l1; |
|
326 |
FLyrVect ls2 = (FLyrVect) l2; |
|
327 |
compareVectLayers(ls1, ls2); |
|
328 |
|
|
329 |
} else { |
|
330 |
|
|
331 |
} |
|
332 |
} |
|
333 |
|
|
334 |
} |
|
335 |
|
|
336 |
private void compareVectLayers(FLyrVect l1, FLyrVect l2) { |
|
337 |
compareLegend(l1.getLegend(), l2.getLegend()); |
|
338 |
compareStore(l1.getFeatureStore(), l2.getFeatureStore()); |
|
339 |
} |
|
340 |
|
|
341 |
private void compareStore(FeatureStore fs1, |
|
342 |
FeatureStore fs2) { |
|
343 |
|
|
344 |
logger.debug("Comparing stores..."); |
|
345 |
assertTrue("Diff stores!", fs1.getName().compareTo(fs2.getName()) == 0); |
|
346 |
} |
|
347 |
|
|
348 |
private void compareLegend(ILegend l1, ILegend l2) { |
|
349 |
|
|
350 |
logger.debug("Comparing legends..."); |
|
351 |
IVectorLegend vl1 = (IVectorLegend) l1; |
|
352 |
IVectorLegend vl2 = (IVectorLegend) l2; |
|
353 |
assertTrue("Diff legends!", vl1.getShapeType() == vl2.getShapeType()); |
|
354 |
|
|
355 |
} |
|
356 |
|
|
357 |
private void compareViewPorts(ViewPort vp1, ViewPort vp2) { |
|
358 |
|
|
359 |
|
|
360 |
logger.debug("Comparing viewports..."); |
|
361 |
|
|
362 |
assertEquals( |
|
363 |
vp1.getAdjustedEnvelope().getMinimum(0), |
|
364 |
vp2.getAdjustedEnvelope().getMinimum(0), |
|
365 |
0.00000000000001); |
|
366 |
assertEquals( |
|
367 |
vp1.getAdjustedEnvelope().getMinimum(1), |
|
368 |
vp2.getAdjustedEnvelope().getMinimum(1), |
|
369 |
0.00000000000001); |
|
370 |
assertEquals( |
|
371 |
vp1.getAdjustedEnvelope().getMaximum(0), |
|
372 |
vp2.getAdjustedEnvelope().getMaximum(0), |
|
373 |
0.00000000000001); |
|
374 |
assertEquals( |
|
375 |
vp1.getAdjustedEnvelope().getMaximum(1), |
|
376 |
vp2.getAdjustedEnvelope().getMaximum(1), |
|
377 |
0.00000000000001); |
|
378 |
} |
|
379 |
|
|
380 |
} |
|
0 | 381 |
tags/org.gvsig.desktop-2.0.395/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/test/java/org/gvsig/fmap/mapcontext/persistence/DummyDBFeatureStore.java | ||
---|---|---|
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 modify it under |
|
7 |
* the terms of the GNU General Public License as published by the Free Software |
|
8 |
* Foundation; either version 3 of the License, or (at your option) any later |
|
9 |
* version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
14 |
* details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License along with |
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51 |
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
19 |
* |
|
20 |
* For any additional information, do not hesitate to contact us at info AT |
|
21 |
* gvsig.com, or visit our website www.gvsig.com. |
|
22 |
*/ |
|
23 |
package org.gvsig.fmap.mapcontext.persistence; |
|
24 |
|
|
25 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
26 |
import org.gvsig.fmap.dal.feature.DummyFetureStore; |
|
27 |
import org.gvsig.tools.ToolsLocator; |
|
28 |
import org.gvsig.tools.dynobject.DynStruct; |
|
29 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
30 |
import org.gvsig.tools.persistence.PersistentState; |
|
31 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
32 |
|
|
33 |
public class DummyDBFeatureStore extends DummyFetureStore implements FeatureStore { |
|
34 |
|
|
35 |
private String name = "[empty]"; |
|
36 |
|
|
37 |
public DummyDBFeatureStore() { |
|
38 |
|
|
39 |
} |
|
40 |
|
|
41 |
public DummyDBFeatureStore(String id) { |
|
42 |
name = "[DATABASE FEATURE STORE - " + id + "]"; |
|
43 |
} |
|
44 |
|
|
45 |
public String getName() { |
|
46 |
return name; |
|
47 |
} |
|
48 |
|
|
49 |
public void loadFromState(PersistentState state) throws PersistenceException { |
|
50 |
name = state.getString("name"); |
|
51 |
} |
|
52 |
|
|
53 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
54 |
state.set("name", name); |
|
55 |
} |
|
56 |
|
|
57 |
public static void registerPersistent() { |
|
58 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
59 |
DynStruct definition = manager.addDefinition( |
|
60 |
DummyDBFeatureStore.class, |
|
61 |
"DummyDBFeatureStore", |
|
62 |
"DummyDBFeatureStore Persistence definition", |
|
63 |
null, |
|
64 |
null |
|
65 |
); |
|
66 |
definition.addDynFieldString("name"); |
|
67 |
} |
|
68 |
} |
|
0 | 69 |
tags/org.gvsig.desktop-2.0.395/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/test/java/org/gvsig/fmap/mapcontext/ExtentHistoryTest.java | ||
---|---|---|
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 {} {{Task}} |
|
27 |
*/ |
|
28 |
package org.gvsig.fmap.mapcontext; |
|
29 |
|
|
30 |
import java.awt.Rectangle; |
|
31 |
import java.awt.geom.Rectangle2D; |
|
32 |
|
|
33 |
import junit.framework.TestCase; |
|
34 |
|
|
35 |
/** |
|
36 |
* Unit tests for the class {@link ExtentHistory}. |
|
37 |
* |
|
38 |
* @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team |
|
39 |
*/ |
|
40 |
public class ExtentHistoryTest extends TestCase { |
|
41 |
|
|
42 |
protected void setUp() throws Exception { |
|
43 |
super.setUp(); |
|
44 |
} |
|
45 |
|
|
46 |
/** |
|
47 |
* Test method for |
|
48 |
* {@link org.gvsig.fmap.mapcontext.ExtentHistory#put(java.awt.geom.Rectangle2D)} |
|
49 |
* . |
|
50 |
*/ |
|
51 |
public void testPut() { |
|
52 |
ExtentHistory history = new ExtentHistory(); |
|
53 |
|
|
54 |
Rectangle2D rectangle = new Rectangle2D.Double(1, 1, 2, 2); |
|
55 |
Rectangle2D rectangle2 = new Rectangle2D.Double(2, 2, 3, 3); |
|
56 |
Rectangle2D rectangle3 = new Rectangle2D.Double(3, 3, 4, 4); |
|
57 |
history.put(rectangle3); |
|
58 |
history.put(rectangle2); |
|
59 |
history.put(rectangle); |
|
60 |
|
|
61 |
assertEquals(rectangle2, history.getPrev()); |
|
62 |
|
|
63 |
history = new ExtentHistory(2); |
|
64 |
|
|
65 |
history.put(rectangle); |
|
66 |
history.put(rectangle2); |
|
67 |
history.put(rectangle3); |
|
68 |
|
|
69 |
assertEquals(rectangle2, history.getPrev()); |
|
70 |
} |
|
71 |
|
|
72 |
/** |
|
73 |
* Test method for |
|
74 |
* {@link org.gvsig.fmap.mapcontext.ExtentHistory#hasPrevious()}. |
|
75 |
*/ |
|
76 |
public void testHasPrevious() { |
|
77 |
ExtentHistory history = new ExtentHistory(); |
|
78 |
|
|
79 |
assertFalse(history.hasPrevious()); |
|
80 |
|
|
81 |
Rectangle2D rectangle = new Rectangle2D.Double(1, 1, 2, 2); |
|
82 |
history.put(rectangle); |
|
83 |
assertFalse(history.hasPrevious()); |
|
84 |
|
|
85 |
Rectangle2D rectangle2 = new Rectangle2D.Double(2, 2, 3, 3); |
|
86 |
history.put(rectangle2); |
|
87 |
assertTrue(history.hasPrevious()); |
|
88 |
|
|
89 |
history.setPreviousExtent(); |
|
90 |
assertFalse(history.hasPrevious()); |
|
91 |
} |
|
92 |
|
|
93 |
/** |
|
94 |
* Test method for |
|
95 |
* {@link org.gvsig.fmap.mapcontext.ExtentHistory#hasNext()}. |
|
96 |
*/ |
|
97 |
public void testHasNext() { |
|
98 |
ExtentHistory history = new ExtentHistory(); |
|
99 |
|
|
100 |
assertFalse(history.hasNext()); |
|
101 |
|
|
102 |
Rectangle2D rectangle = new Rectangle2D.Double(1, 1, 2, 2); |
|
103 |
history.put(rectangle); |
|
104 |
|
|
105 |
history.setPreviousExtent(); |
|
106 |
assertTrue(history.hasNext()); |
|
107 |
} |
|
108 |
|
|
109 |
/** |
|
110 |
* Test method for {@link org.gvsig.fmap.mapcontext.ExtentHistory#getPrev()}. |
|
111 |
*/ |
|
112 |
public void testGet() { |
|
113 |
ExtentHistory history = new ExtentHistory(); |
|
114 |
|
|
115 |
assertNull("The ExtentHistory has got an element without adding one", |
|
116 |
history.getPrev()); |
|
117 |
|
|
118 |
Rectangle2D rectangle = new Rectangle2D.Double(1, 1, 2, 2); |
|
119 |
Rectangle2D rectangle2 = new Rectangle2D.Double(2, 2, 3, 3); |
|
120 |
|
|
121 |
history.put(rectangle); |
|
122 |
assertEquals(rectangle, history.getCurrent()); |
|
123 |
|
|
124 |
history.put(rectangle2); |
|
125 |
assertEquals(rectangle2, history.getCurrent()); |
|
126 |
assertEquals(rectangle, history.getPrev()); |
|
127 |
|
|
128 |
assertEquals(rectangle, history.setPreviousExtent()); |
|
129 |
|
|
130 |
assertNull("The ExtentHistory hasn't got a previous element", history.setPreviousExtent()); |
|
131 |
} |
|
132 |
|
|
133 |
/** |
|
134 |
* Test method for |
|
135 |
* {@link org.gvsig.fmap.mapcontext.ExtentHistory#removePrev()}. |
|
136 |
*/ |
|
137 |
public void testRemovePrev() { |
|
138 |
ExtentHistory history = new ExtentHistory(); |
|
139 |
|
|
140 |
assertNull( |
|
141 |
"The ExtentHistory allows setting an element without adding " |
|
142 |
+ "at least one", history.setPreviousExtent()); |
|
143 |
|
|
144 |
Rectangle2D rectangle = new Rectangle2D.Double(1, 1, 2, 2); |
|
145 |
Rectangle2D rectangle2 = new Rectangle2D.Double(2, 2, 3, 3); |
|
146 |
|
|
147 |
history.put(rectangle); |
|
148 |
history.put(rectangle2); |
|
149 |
|
|
150 |
assertEquals(rectangle, history.setPreviousExtent()); |
|
151 |
|
|
152 |
assertNull("The ExtentHistory allows to set the last element, " |
|
153 |
+ "but all have been previously removed", history.setPreviousExtent()); |
|
154 |
} |
|
155 |
} |
|
0 | 156 |
tags/org.gvsig.desktop-2.0.395/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/test/java/org/gvsig/fmap/mapcontext/rendering/symbol/DummyVectorLegend.java | ||
---|---|---|
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 |
package org.gvsig.fmap.mapcontext.rendering.symbol; |
|
25 |
|
|
26 |
import java.awt.Color; |
|
27 |
import java.awt.Graphics2D; |
|
28 |
import java.awt.image.BufferedImage; |
|
29 |
import java.util.Iterator; |
|
30 |
import java.util.Map; |
|
31 |
|
|
32 |
import org.cresques.cts.ICoordTrans; |
|
33 |
|
|
34 |
import org.gvsig.compat.print.PrintAttributes; |
|
35 |
import org.gvsig.fmap.dal.exception.DataException; |
|
36 |
import org.gvsig.fmap.dal.feature.Feature; |
|
37 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
|
38 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
39 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
40 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
|
41 |
import org.gvsig.fmap.mapcontext.ViewPort; |
|
42 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
|
43 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend; |
|
44 |
import org.gvsig.fmap.mapcontext.rendering.legend.LegendException; |
|
45 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendContentsChangedListener; |
|
46 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent; |
|
47 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
48 |
import org.gvsig.tools.ToolsLocator; |
|
49 |
import org.gvsig.tools.dynobject.DynStruct; |
|
50 |
import org.gvsig.tools.evaluator.Evaluator; |
|
51 |
import org.gvsig.tools.observer.Observer; |
|
52 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
53 |
import org.gvsig.tools.persistence.PersistentState; |
|
54 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
55 |
import org.gvsig.tools.task.Cancellable; |
|
56 |
|
|
57 |
public class DummyVectorLegend implements IVectorLegend { |
|
58 |
|
|
59 |
private long shpType = -1; |
|
60 |
|
|
61 |
private ISymbol sym = new DummySymbol(Color.RED, TYPES.SOLID); |
|
62 |
|
|
63 |
public DummyVectorLegend() { |
|
64 |
shpType = System.currentTimeMillis() % 1000000; |
|
65 |
} |
|
66 |
|
|
67 |
public DummyVectorLegend(int type) { |
|
68 |
shpType = type; // System.currentTimeMillis() % 1000000; |
|
69 |
} |
|
70 |
|
|
71 |
public void draw(BufferedImage image, Graphics2D graphics2D, |
|
72 |
ViewPort viewPort, Cancellable cancel, double scale, |
|
73 |
Map queryParameters, ICoordTrans coordTrans, |
|
74 |
FeatureStore featureStore, FeatureQuery featureQuery) throws LegendException { |
|
75 |
|
|
76 |
} |
|
77 |
public void draw(BufferedImage image, Graphics2D graphics2D, |
|
78 |
ViewPort viewPort, Cancellable cancel, double scale, |
|
79 |
Map queryParameters, ICoordTrans coordTrans, |
|
80 |
FeatureStore featureStore) throws LegendException { |
|
81 |
|
|
82 |
try { |
|
83 |
FeatureSet fs = featureStore.getFeatureSet(); |
|
84 |
Iterator iter = fs.iterator(); |
|
85 |
Feature feat = null; |
|
86 |
ISymbol symb = null; |
|
87 |
while (iter.hasNext()) { |
|
88 |
feat = (Feature) iter.next(); |
|
89 |
symb = this.getSymbolByFeature(feat); |
|
90 |
symb.draw(graphics2D, viewPort.getAffineTransform(), feat.getDefaultGeometry(), feat, null); |
|
91 |
} |
|
92 |
} catch (DataException e) { |
|
93 |
// TODO Auto-generated catch block |
|
94 |
e.printStackTrace(); |
|
95 |
} |
|
96 |
// TODO Auto-generated method stub |
|
97 |
|
|
98 |
} |
|
99 |
|
|
100 |
public int getShapeType() { |
|
101 |
// TODO Auto-generated method stub |
|
102 |
return (int) shpType; |
|
103 |
} |
|
104 |
|
|
105 |
public ISymbol getSymbolByFeature(Feature feat) { |
|
106 |
return sym; |
|
107 |
} |
|
108 |
|
|
109 |
public boolean isSuitableForShapeType(int shapeType) { |
|
110 |
return sym.getSymbolType() == shapeType; |
|
111 |
} |
|
112 |
|
|
113 |
public boolean isUseDefaultSymbol() { |
|
114 |
return true; |
|
115 |
} |
|
116 |
|
|
117 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
|
118 |
double scale, Object object, ICoordTrans coordTrans, |
|
119 |
FeatureStore featureStore, Evaluator evaluator, PrintAttributes properties) |
|
120 |
throws LegendException { |
|
121 |
// TODO Auto-generated method stub |
|
122 |
|
|
123 |
} |
|
124 |
|
|
125 |
public void setDefaultSymbol(ISymbol s) throws IllegalArgumentException { |
|
126 |
sym = s; |
|
127 |
} |
|
128 |
|
|
129 |
public void setShapeType(int shapeType) { |
|
130 |
shpType = shapeType; |
|
131 |
} |
|
132 |
|
|
133 |
public void useDefaultSymbol(boolean b) { |
|
134 |
} |
|
135 |
|
|
136 |
public void addLegendListener(LegendContentsChangedListener listener) { |
|
137 |
// TODO Auto-generated method stub |
|
138 |
|
|
139 |
} |
|
140 |
|
|
141 |
public ILegend cloneLegend() { |
|
142 |
// TODO Auto-generated method stub |
|
143 |
return null; |
|
144 |
} |
|
145 |
|
|
146 |
public void fireDefaultSymbolChangedEvent(SymbolLegendEvent event) { |
|
147 |
// TODO Auto-generated method stub |
|
148 |
|
|
149 |
} |
|
150 |
|
|
151 |
public ISymbol getDefaultSymbol() { |
|
152 |
return sym; |
|
153 |
} |
|
154 |
|
|
155 |
public LegendContentsChangedListener[] getListeners() { |
|
156 |
// TODO Auto-generated method stub |
|
157 |
return null; |
|
158 |
} |
|
159 |
|
|
160 |
public void removeLegendListener(LegendContentsChangedListener listener) { |
|
161 |
// TODO Auto-generated method stub |
|
162 |
|
|
163 |
} |
|
164 |
|
|
165 |
public String getClassName() { |
|
166 |
return this.getClass().getName(); |
|
167 |
} |
|
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
public void addDrawingObserver(Observer observer) { |
|
173 |
// TODO Auto-generated method stub |
|
174 |
|
|
175 |
} |
|
176 |
|
|
177 |
public void deleteDrawingObserver(Observer observer) { |
|
178 |
// TODO Auto-generated method stub |
|
179 |
|
|
180 |
} |
|
181 |
|
|
182 |
public void deleteDrawingObservers() { |
|
183 |
// TODO Auto-generated method stub |
|
184 |
|
|
185 |
} |
|
186 |
|
|
187 |
public void loadFromState(PersistentState state) throws PersistenceException { |
|
188 |
shpType = state.getLong("shpType"); |
|
189 |
} |
|
190 |
|
|
191 |
|
|
192 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
193 |
state.set("shpType", shpType); |
|
194 |
} |
|
195 |
|
|
196 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
|
197 |
double scale, Map queryParameters, ICoordTrans coordTrans, |
|
198 |
FeatureStore featureStore, FeatureQuery featureQuery, PrintAttributes properties) |
|
199 |
throws LegendException { |
|
200 |
// TODO Auto-generated method stub |
|
201 |
|
|
202 |
} |
|
203 |
|
|
204 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
|
205 |
double scale, Map queryParameters, ICoordTrans coordTrans, |
|
206 |
FeatureStore featureStore, PrintAttributes properties) |
|
207 |
throws LegendException { |
|
208 |
// TODO Auto-generated method stub |
|
209 |
|
|
210 |
} |
|
211 |
|
|
212 |
public static void registerPersistent() { |
|
213 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
214 |
DynStruct definition = manager.addDefinition( |
|
215 |
DummyVectorLegend.class, |
|
216 |
"DummyVectorLegend", |
|
217 |
"DummyVectorLegend Persistence definition", |
|
218 |
null, |
|
219 |
null |
|
220 |
); |
|
221 |
definition.addDynFieldLong("shpType") |
|
222 |
.setMandatory(true); |
|
223 |
} |
|
224 |
|
|
225 |
|
|
226 |
public Object clone() throws CloneNotSupportedException { |
|
227 |
return super.clone(); |
|
228 |
} |
|
229 |
|
|
230 |
|
|
231 |
} |
|
0 | 232 |
tags/org.gvsig.desktop-2.0.395/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/test/java/org/gvsig/fmap/mapcontext/rendering/symbol/DummySymbol.java | ||
---|---|---|
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 |
package org.gvsig.fmap.mapcontext.rendering.symbol; |
|
25 |
|
|
26 |
import java.awt.Color; |
|
27 |
import java.awt.Graphics2D; |
|
28 |
import java.awt.Rectangle; |
|
29 |
import java.awt.geom.AffineTransform; |
|
30 |
import java.awt.geom.PathIterator; |
|
31 |
import java.util.ArrayList; |
|
32 |
|
|
33 |
import org.gvsig.compat.print.PrintAttributes; |
|
34 |
import org.gvsig.fmap.dal.feature.Feature; |
|
35 |
import org.gvsig.fmap.geom.Geometry; |
|
36 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
|
37 |
import org.gvsig.fmap.geom.primitive.Point; |
|
38 |
import org.gvsig.fmap.mapcontext.ViewPort; |
|
39 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
40 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException; |
|
41 |
import org.gvsig.tools.persistence.PersistentState; |
|
42 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
43 |
import org.gvsig.tools.task.Cancellable; |
|
44 |
|
|
45 |
public class DummySymbol implements ISymbol { |
|
46 |
|
|
47 |
private Color color = Color.GREEN; |
|
48 |
private int type = TYPES.SOLID; |
|
49 |
|
|
50 |
public DummySymbol(Color c, int geomtype) { |
|
51 |
color = c; |
|
52 |
type = geomtype; |
|
53 |
} |
|
54 |
|
|
55 |
public Object clone() { |
|
56 |
return null; |
|
57 |
} |
|
58 |
|
|
59 |
public void draw(Graphics2D g, AffineTransform affineTransform, |
|
60 |
Geometry geom, Feature f, Cancellable cancel) { |
|
61 |
|
|
62 |
g.setColor(color); |
|
63 |
|
|
64 |
if (geom instanceof Point) { |
|
65 |
Point p = (Point) geom; |
|
66 |
p.transform(affineTransform); |
|
67 |
g.drawRect((int) p.getX(), (int) p.getY(), 3, 3); |
|
68 |
} else { |
|
69 |
PathIterator piter = geom.getPathIterator(affineTransform); |
|
70 |
drawPathIterator(g, piter); |
|
71 |
} |
|
72 |
} |
|
73 |
|
|
74 |
public void drawInsideRectangle(Graphics2D g, |
|
75 |
AffineTransform scaleInstance, Rectangle r, |
|
76 |
PrintAttributes properties) throws SymbolDrawingException { |
|
77 |
// TODO Auto-generated method stub |
|
78 |
|
|
79 |
} |
|
80 |
|
|
81 |
public Color getColor() { |
|
82 |
return color; |
|
83 |
} |
|
84 |
|
|
85 |
public String getDescription() { |
|
86 |
return "a dummy symbol"; |
|
87 |
} |
|
88 |
|
|
89 |
public int getOnePointRgb() { |
|
90 |
return color.getRGB(); |
|
91 |
} |
|
92 |
|
|
93 |
public void getPixExtentPlus(Geometry geom, float[] distances, |
|
94 |
ViewPort viewPort, int dpi) { |
|
95 |
// TODO Auto-generated method stub |
|
96 |
|
|
97 |
} |
|
98 |
|
|
99 |
public ISymbol getSymbolForSelection() { |
|
100 |
return new DummySymbol(Color.YELLOW, type); |
|
101 |
} |
|
102 |
|
|
103 |
public int getSymbolType() { |
|
104 |
return type; |
|
105 |
} |
|
106 |
|
|
107 |
public boolean isOneDotOrPixel(Geometry geom, |
|
108 |
double[] positionOfDotOrPixel, ViewPort viewPort, int dpi) { |
|
109 |
// TODO Auto-generated method stub |
|
110 |
return false; |
|
111 |
} |
|
112 |
|
|
113 |
public boolean isShapeVisible() { |
|
114 |
return true; |
|
115 |
} |
|
116 |
|
|
117 |
public boolean isSuitableFor(Geometry geom) { |
|
118 |
return type == geom.getType(); |
|
119 |
} |
|
120 |
|
|
121 |
public void setColor(Color c) { |
|
122 |
color = c; |
|
123 |
} |
|
124 |
|
|
125 |
public void setDescription(String desc) { |
|
126 |
} |
|
127 |
|
|
128 |
public void loadFromState(PersistentState state) |
|
129 |
throws PersistenceException { |
|
130 |
} |
|
131 |
|
|
132 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
133 |
} |
|
134 |
|
|
135 |
public void print(Graphics2D g, AffineTransform at, Geometry shape, |
|
136 |
PrintAttributes properties) { |
|
137 |
} |
|
138 |
|
|
139 |
|
|
140 |
|
|
141 |
/** |
|
142 |
* Draws the general path on the graphics object with the given affine transformation |
|
143 |
* @param g the graphics object |
|
144 |
* @param gp the general path |
|
145 |
*/ |
|
146 |
public static void drawPathIterator(Graphics2D g, PathIterator pit) { |
|
147 |
|
|
148 |
ArrayList x = new ArrayList(); |
|
149 |
ArrayList y = new ArrayList(); |
|
150 |
double[] current = new double[6]; |
|
151 |
|
|
152 |
while (!pit.isDone()) { |
|
153 |
pit.currentSegment(current); |
|
154 |
x.add(new Integer((int) current[0])); |
|
155 |
y.add(new Integer((int) current[1])); |
|
156 |
pit.next(); |
|
157 |
} |
|
158 |
|
|
159 |
int[] gx = integerArrayListToIntArray(x); |
|
160 |
int[] gy = integerArrayListToIntArray(y); |
|
161 |
|
|
162 |
g.drawPolyline(gx, gy, gx.length); |
|
163 |
} |
|
164 |
|
|
165 |
|
|
166 |
/** |
|
167 |
* Converts array list of Integer objects into array of int |
|
168 |
* @param l |
|
169 |
* @return array of int |
|
170 |
*/ |
|
171 |
public static int[] integerArrayListToIntArray(ArrayList l) { |
|
172 |
|
|
173 |
int size = l.size(); |
|
174 |
int[] resp = new int[size]; |
|
175 |
for (int i=0; i<size; i++) { |
|
176 |
resp[i] = ((Integer) l.get(i)).intValue(); |
|
177 |
} |
|
178 |
return resp; |
|
179 |
} |
|
180 |
|
|
181 |
} |
|
0 | 182 |
tags/org.gvsig.desktop-2.0.395/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/test/java/org/gvsig/fmap/mapcontext/tools/persistence/ColorPersistenceFactoryTest.java | ||
---|---|---|
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 {} {{Task}} |
|
27 |
*/ |
|
28 |
package org.gvsig.fmap.mapcontext.tools.persistence; |
|
29 |
|
|
30 |
import java.awt.Color; |
|
31 |
|
|
32 |
import org.easymock.MockControl; |
|
33 |
import org.gvsig.tools.ToolsLocator; |
|
34 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
|
35 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
36 |
import org.gvsig.tools.persistence.PersistentState; |
|
37 |
|
|
38 |
/** |
|
39 |
* Unit tests for the class {@link ColorPersistenceFactory}. |
|
40 |
* |
|
41 |
* @author gvSIG team |
|
42 |
*/ |
|
43 |
public class ColorPersistenceFactoryTest extends |
|
44 |
AbstractLibraryAutoInitTestCase { |
|
45 |
|
|
46 |
private ColorPersistenceFactory factory; |
|
47 |
private MockControl stateControl; |
|
48 |
private PersistentState state; |
|
49 |
private Color color; |
|
50 |
|
|
51 |
protected void doSetUp() throws Exception { |
|
52 |
PersistenceManager persistenceManager = ToolsLocator |
|
53 |
.getPersistenceManager(); |
|
54 |
factory = (ColorPersistenceFactory) persistenceManager.getFactories() |
|
55 |
.get(Color.class); |
|
56 |
stateControl = MockControl.createNiceControl(PersistentState.class); |
|
57 |
state = (PersistentState) stateControl.getMock(); |
|
58 |
color = Color.magenta; |
|
59 |
} |
|
60 |
|
|
61 |
/** |
|
62 |
* Test method for |
|
63 |
* {@link org.gvsig.fmap.mapcontext.tools.persistence.ColorPersistenceFactory#createFromState(org.gvsig.tools.persistence.PersistentState, java.lang.Class)} |
|
64 |
* . |
|
65 |
*/ |
|
66 |
public void testCreateFromState() throws Exception { |
|
67 |
stateControl.expectAndReturn(state |
|
68 |
.getInt(ColorPersistenceFactory.FIELD_RED), color.getRed()); |
|
69 |
stateControl.expectAndReturn(state |
|
70 |
.getInt(ColorPersistenceFactory.FIELD_GREEN), color.getGreen()); |
|
71 |
stateControl.expectAndReturn(state |
|
72 |
.getInt(ColorPersistenceFactory.FIELD_BLUE), color.getBlue()); |
|
73 |
stateControl.expectAndReturn(state |
|
74 |
.getInt(ColorPersistenceFactory.FIELD_ALPHA), color.getAlpha()); |
|
75 |
stateControl.replay(); |
|
76 |
|
|
77 |
Color newColor = (Color) factory.createFromState(state); |
|
78 |
assertTrue(newColor.equals(color)); |
|
79 |
|
|
80 |
stateControl.verify(); |
|
81 |
} |
|
82 |
|
|
83 |
/** |
|
84 |
* Test method for |
|
85 |
* {@link org.gvsig.fmap.mapcontext.tools.persistence.ColorPersistenceFactory#saveToState(org.gvsig.tools.persistence.PersistentState, java.lang.Object)} |
|
86 |
* . |
|
87 |
*/ |
|
88 |
public void testSaveToState() throws Exception { |
|
89 |
state.set(ColorPersistenceFactory.FIELD_RED, color.getRed()); |
|
90 |
state.set(ColorPersistenceFactory.FIELD_GREEN, color.getGreen()); |
|
91 |
state.set(ColorPersistenceFactory.FIELD_BLUE, color.getBlue()); |
|
92 |
state.set(ColorPersistenceFactory.FIELD_ALPHA, color.getAlpha()); |
|
93 |
stateControl.replay(); |
|
94 |
|
|
95 |
factory.saveToState(state, color); |
|
96 |
|
|
97 |
stateControl.verify(); |
|
98 |
} |
|
99 |
|
|
100 |
} |
|
0 | 101 |
tags/org.gvsig.desktop-2.0.395/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/test/java/org/gvsig/fmap/mapcontext/tools/persistence/Point2DPersistenceFactoryTest.java | ||
---|---|---|
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 {} {{Task}} |
|
27 |
*/ |
|
28 |
package org.gvsig.fmap.mapcontext.tools.persistence; |
|
29 |
|
|
30 |
import java.awt.geom.Point2D; |
|
31 |
|
|
32 |
import org.easymock.MockControl; |
|
33 |
import org.gvsig.tools.ToolsLocator; |
|
34 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
|
35 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
36 |
import org.gvsig.tools.persistence.PersistentState; |
|
37 |
|
|
38 |
/** |
|
39 |
* Unit tests for the class {@link Point2DPersistenceFactory}. |
|
40 |
* |
|
41 |
* @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team |
|
42 |
*/ |
|
43 |
public class Point2DPersistenceFactoryTest extends |
|
44 |
AbstractLibraryAutoInitTestCase { |
|
45 |
|
|
46 |
private Point2DPersistenceFactory factory; |
|
47 |
private MockControl stateControl; |
|
48 |
private PersistentState state; |
|
49 |
private Point2D point; |
|
50 |
|
|
51 |
protected void doSetUp() throws Exception { |
|
52 |
PersistenceManager persistenceManager = ToolsLocator |
|
53 |
.getPersistenceManager(); |
|
54 |
factory = (Point2DPersistenceFactory) persistenceManager.getFactories() |
|
55 |
.get(Point2D.class); |
|
56 |
stateControl = MockControl.createNiceControl(PersistentState.class); |
|
57 |
state = (PersistentState) stateControl.getMock(); |
|
58 |
double x = Math.random() * 1000d; |
|
59 |
double y = Math.random() * 1000d; |
|
60 |
point = new Point2D.Double(x, y); |
|
61 |
} |
|
62 |
|
|
63 |
/** |
|
64 |
* Test method for |
|
65 |
* {@link org.gvsig.fmap.mapcontext.tools.persistence.Point2DPersistenceFactory#createFromState(PersistentState, Class)} |
|
66 |
* . |
|
67 |
*/ |
|
68 |
public void testCreateFromState() throws Exception { |
|
69 |
stateControl.expectAndReturn(state |
|
70 |
.getDouble(Point2DPersistenceFactory.FIELD_X), point.getX()); |
|
71 |
stateControl.expectAndReturn(state |
|
72 |
.getDouble(Point2DPersistenceFactory.FIELD_Y), point.getY()); |
|
73 |
stateControl.replay(); |
|
74 |
|
|
75 |
Point2D newPoint = (Point2D) factory.createFromState(state); |
|
76 |
assertTrue(newPoint.equals(point)); |
|
77 |
|
|
78 |
stateControl.verify(); |
|
79 |
} |
|
80 |
|
|
81 |
/** |
|
82 |
* Test method for |
|
83 |
* {@link org.gvsig.fmap.mapcontext.tools.persistence.Point2DPersistenceFactory#saveToState(org.gvsig.tools.persistence.PersistentState, java.lang.Object)} |
|
84 |
* . |
|
85 |
*/ |
|
86 |
public void testSaveToState() throws Exception { |
|
87 |
state.set(Point2DPersistenceFactory.FIELD_X, point.getX()); |
|
88 |
state.set(Point2DPersistenceFactory.FIELD_Y, point.getY()); |
|
89 |
stateControl.replay(); |
|
90 |
|
|
91 |
factory.saveToState(state, point); |
|
92 |
|
|
93 |
stateControl.verify(); |
|
94 |
} |
|
95 |
} |
|
0 | 96 |
tags/org.gvsig.desktop-2.0.395/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/test/java/org/gvsig/fmap/mapcontext/tools/persistence/DimensionPersistenceFactoryTest.java | ||
---|---|---|
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 {} {{Task}} |
|
27 |
*/ |
|
28 |
package org.gvsig.fmap.mapcontext.tools.persistence; |
|
29 |
|
|
30 |
import java.awt.Dimension; |
|
31 |
|
|
32 |
import org.easymock.MockControl; |
|
33 |
|
|
34 |
import org.gvsig.tools.ToolsLocator; |
|
35 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
|
36 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
37 |
import org.gvsig.tools.persistence.PersistentState; |
|
38 |
|
|
39 |
/** |
|
40 |
* Unit tests for the class {@link DimensionPersistenceFactory}. |
|
41 |
* |
|
42 |
* @author gvSIG team |
|
43 |
*/ |
|
44 |
public class DimensionPersistenceFactoryTest extends |
|
45 |
AbstractLibraryAutoInitTestCase { |
|
46 |
|
|
47 |
private DimensionPersistenceFactory factory; |
|
48 |
private MockControl stateControl; |
|
49 |
private PersistentState state; |
|
50 |
private Dimension dimension; |
|
51 |
|
|
52 |
protected void doSetUp() throws Exception { |
|
53 |
PersistenceManager persistenceManager = ToolsLocator |
|
54 |
.getPersistenceManager(); |
|
55 |
factory = (DimensionPersistenceFactory) persistenceManager |
|
56 |
.getFactories().get(Dimension.class); |
|
57 |
stateControl = MockControl.createNiceControl(PersistentState.class); |
|
58 |
state = (PersistentState) stateControl.getMock(); |
|
59 |
dimension = new Dimension(320, 200); |
|
60 |
} |
|
61 |
|
|
62 |
/** |
|
63 |
* Test method for |
|
64 |
* {@link org.gvsig.fmap.mapcontext.tools.persistence.DimensionPersistenceFactory#createFromState(org.gvsig.tools.persistence.PersistentState, java.lang.Class)} |
|
65 |
* . |
|
66 |
*/ |
|
67 |
public void testCreateFromState() throws Exception { |
|
68 |
stateControl.expectAndReturn(state |
|
69 |
.getInt(DimensionPersistenceFactory.FIELD_WIDTH), dimension.width); |
|
70 |
stateControl.expectAndReturn(state |
|
71 |
.getInt(DimensionPersistenceFactory.FIELD_HEIGHT), dimension.height); |
|
72 |
stateControl.replay(); |
|
73 |
|
|
74 |
Dimension newDimension = (Dimension) factory.createFromState(state); |
|
75 |
assertTrue(newDimension.equals(dimension)); |
|
76 |
|
|
77 |
stateControl.verify(); |
|
78 |
} |
|
79 |
|
|
80 |
/** |
|
81 |
* Test method for |
|
82 |
* {@link org.gvsig.fmap.mapcontext.tools.persistence.DimensionPersistenceFactory#saveToState(org.gvsig.tools.persistence.PersistentState, java.lang.Object)} |
|
83 |
* . |
|
84 |
*/ |
|
85 |
public void testSaveToState() throws Exception { |
|
86 |
state.set(DimensionPersistenceFactory.FIELD_WIDTH, dimension.width); |
|
87 |
state.set(DimensionPersistenceFactory.FIELD_HEIGHT, dimension.height); |
|
88 |
|
|
89 |
stateControl.replay(); |
|
90 |
|
|
91 |
factory.saveToState(state, dimension); |
|
92 |
|
|
93 |
stateControl.verify(); |
|
94 |
} |
|
95 |
|
|
96 |
} |
|
0 | 97 |
tags/org.gvsig.desktop-2.0.395/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/test/java/org/gvsig/fmap/mapcontext/tools/persistence/FontPersistenceFactoryTest.java | ||
---|---|---|
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 |
* |
Also available in: Unified diff