Revision 33562
tags/v2_0_0_Build_2011/libraries/libFMap_mapcontext/src-test/org/gvsig/fmap/mapcontext/rendering/symbol/DummyVectorLegend.java | ||
---|---|---|
1 |
package org.gvsig.fmap.mapcontext.rendering.symbol; |
|
2 |
|
|
3 |
import java.awt.Color; |
|
4 |
import java.awt.Graphics2D; |
|
5 |
import java.awt.image.BufferedImage; |
|
6 |
import java.util.Iterator; |
|
7 |
import java.util.Map; |
|
8 |
|
|
9 |
import org.cresques.cts.ICoordTrans; |
|
10 |
import org.gvsig.compat.print.PrintAttributes; |
|
11 |
import org.gvsig.fmap.dal.exception.DataException; |
|
12 |
import org.gvsig.fmap.dal.feature.Feature; |
|
13 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
|
14 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
15 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
|
16 |
import org.gvsig.fmap.mapcontext.ViewPort; |
|
17 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
|
18 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend; |
|
19 |
import org.gvsig.fmap.mapcontext.rendering.legend.LegendException; |
|
20 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendContentsChangedListener; |
|
21 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent; |
|
22 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
23 |
import org.gvsig.tools.ToolsLocator; |
|
24 |
import org.gvsig.tools.dynobject.DynStruct; |
|
25 |
import org.gvsig.tools.observer.Observer; |
|
26 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
27 |
import org.gvsig.tools.persistence.PersistentState; |
|
28 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
29 |
import org.gvsig.tools.task.Cancellable; |
|
30 |
|
|
31 |
public class DummyVectorLegend implements IVectorLegend { |
|
32 |
|
|
33 |
private long shpType = -1; |
|
34 |
|
|
35 |
private ISymbol sym = new DummySymbol(Color.RED, TYPES.SOLID); |
|
36 |
|
|
37 |
public DummyVectorLegend() { |
|
38 |
shpType = System.currentTimeMillis() % 1000000; |
|
39 |
} |
|
40 |
|
|
41 |
public DummyVectorLegend(int type) { |
|
42 |
shpType = type; // System.currentTimeMillis() % 1000000; |
|
43 |
} |
|
44 |
|
|
45 |
public void draw(BufferedImage image, Graphics2D graphics2D, |
|
46 |
ViewPort viewPort, Cancellable cancel, double scale, |
|
47 |
Map queryParameters, ICoordTrans coordTrans, |
|
48 |
FeatureStore featureStore) throws LegendException { |
|
49 |
|
|
50 |
try { |
|
51 |
FeatureSet fs = featureStore.getFeatureSet(); |
|
52 |
Iterator iter = fs.iterator(); |
|
53 |
Feature feat = null; |
|
54 |
ISymbol symb = null; |
|
55 |
while (iter.hasNext()) { |
|
56 |
feat = (Feature) iter.next(); |
|
57 |
symb = this.getSymbolByFeature(feat); |
|
58 |
symb.draw(graphics2D, viewPort.getAffineTransform(), feat.getDefaultGeometry(), feat, null); |
|
59 |
} |
|
60 |
} catch (DataException e) { |
|
61 |
// TODO Auto-generated catch block |
|
62 |
e.printStackTrace(); |
|
63 |
} |
|
64 |
// TODO Auto-generated method stub |
|
65 |
|
|
66 |
} |
|
67 |
|
|
68 |
public int getShapeType() { |
|
69 |
// TODO Auto-generated method stub |
|
70 |
return (int) shpType; |
|
71 |
} |
|
72 |
|
|
73 |
public ISymbol getSymbolByFeature(Feature feat) { |
|
74 |
return sym; |
|
75 |
} |
|
76 |
|
|
77 |
public boolean isSuitableForShapeType(int shapeType) { |
|
78 |
return sym.getSymbolType() == shapeType; |
|
79 |
} |
|
80 |
|
|
81 |
public boolean isUseDefaultSymbol() { |
|
82 |
return true; |
|
83 |
} |
|
84 |
|
|
85 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
|
86 |
double scale, Object object, ICoordTrans coordTrans, |
|
87 |
FeatureStore featureStore, PrintAttributes properties) |
|
88 |
throws LegendException { |
|
89 |
// TODO Auto-generated method stub |
|
90 |
|
|
91 |
} |
|
92 |
|
|
93 |
public void setDefaultSymbol(ISymbol s) throws IllegalArgumentException { |
|
94 |
sym = s; |
|
95 |
} |
|
96 |
|
|
97 |
public void setShapeType(int shapeType) { |
|
98 |
shpType = shapeType; |
|
99 |
} |
|
100 |
|
|
101 |
public void useDefaultSymbol(boolean b) { |
|
102 |
} |
|
103 |
|
|
104 |
public void addLegendListener(LegendContentsChangedListener listener) { |
|
105 |
// TODO Auto-generated method stub |
|
106 |
|
|
107 |
} |
|
108 |
|
|
109 |
public ILegend cloneLegend() { |
|
110 |
// TODO Auto-generated method stub |
|
111 |
return null; |
|
112 |
} |
|
113 |
|
|
114 |
public void fireDefaultSymbolChangedEvent(SymbolLegendEvent event) { |
|
115 |
// TODO Auto-generated method stub |
|
116 |
|
|
117 |
} |
|
118 |
|
|
119 |
public ISymbol getDefaultSymbol() { |
|
120 |
return sym; |
|
121 |
} |
|
122 |
|
|
123 |
public LegendContentsChangedListener[] getListeners() { |
|
124 |
// TODO Auto-generated method stub |
|
125 |
return null; |
|
126 |
} |
|
127 |
|
|
128 |
public void removeLegendListener(LegendContentsChangedListener listener) { |
|
129 |
// TODO Auto-generated method stub |
|
130 |
|
|
131 |
} |
|
132 |
|
|
133 |
public String getClassName() { |
|
134 |
return this.getClass().getName(); |
|
135 |
} |
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
public void addDrawingObserver(Observer observer) { |
|
141 |
// TODO Auto-generated method stub |
|
142 |
|
|
143 |
} |
|
144 |
|
|
145 |
public void deleteDrawingObserver(Observer observer) { |
|
146 |
// TODO Auto-generated method stub |
|
147 |
|
|
148 |
} |
|
149 |
|
|
150 |
public void deleteDrawingObservers() { |
|
151 |
// TODO Auto-generated method stub |
|
152 |
|
|
153 |
} |
|
154 |
|
|
155 |
public void loadFromState(PersistentState state) throws PersistenceException { |
|
156 |
shpType = state.getLong("shpType"); |
|
157 |
} |
|
158 |
|
|
159 |
|
|
160 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
161 |
state.set("shpType", shpType); |
|
162 |
} |
|
163 |
|
|
164 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
|
165 |
double scale, Map queryParameters, ICoordTrans coordTrans, |
|
166 |
FeatureStore featureStore, PrintAttributes properties) |
|
167 |
throws LegendException { |
|
168 |
// TODO Auto-generated method stub |
|
169 |
|
|
170 |
} |
|
171 |
|
|
172 |
public static void registerPersistent() { |
|
173 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
174 |
DynStruct definition = manager.addDefinition( |
|
175 |
DummyVectorLegend.class, |
|
176 |
"DummyVectorLegend", |
|
177 |
"DummyVectorLegend Persistence definition", |
|
178 |
null, |
|
179 |
null |
|
180 |
); |
|
181 |
definition.addDynFieldLong("shpType") |
|
182 |
.setMandatory(true); |
|
183 |
} |
|
184 |
|
|
185 |
|
|
186 |
public Object clone() throws CloneNotSupportedException { |
|
187 |
return super.clone(); |
|
188 |
} |
|
189 |
|
|
190 |
|
|
191 |
} |
|
0 | 192 |
tags/v2_0_0_Build_2011/libraries/libFMap_mapcontext/src-test/org/gvsig/fmap/mapcontext/rendering/symbol/DummySymbol.java | ||
---|---|---|
1 |
package org.gvsig.fmap.mapcontext.rendering.symbol; |
|
2 |
|
|
3 |
import java.awt.Color; |
|
4 |
import java.awt.Graphics2D; |
|
5 |
import java.awt.Rectangle; |
|
6 |
import java.awt.geom.AffineTransform; |
|
7 |
import java.awt.geom.PathIterator; |
|
8 |
import java.util.ArrayList; |
|
9 |
|
|
10 |
import org.gvsig.compat.print.PrintAttributes; |
|
11 |
import org.gvsig.fmap.dal.feature.Feature; |
|
12 |
import org.gvsig.fmap.geom.Geometry; |
|
13 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
|
14 |
import org.gvsig.fmap.geom.primitive.Point; |
|
15 |
import org.gvsig.fmap.mapcontext.ViewPort; |
|
16 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
17 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException; |
|
18 |
import org.gvsig.tools.persistence.PersistentState; |
|
19 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
20 |
import org.gvsig.tools.task.Cancellable; |
|
21 |
|
|
22 |
public class DummySymbol implements ISymbol { |
|
23 |
|
|
24 |
private Color color = Color.GREEN; |
|
25 |
private int type = TYPES.SOLID; |
|
26 |
|
|
27 |
public DummySymbol(Color c, int geomtype) { |
|
28 |
color = c; |
|
29 |
type = geomtype; |
|
30 |
} |
|
31 |
|
|
32 |
public Object clone() { |
|
33 |
return null; |
|
34 |
} |
|
35 |
|
|
36 |
public void draw(Graphics2D g, AffineTransform affineTransform, |
|
37 |
Geometry geom, Feature f, Cancellable cancel) { |
|
38 |
|
|
39 |
g.setColor(color); |
|
40 |
|
|
41 |
if (geom instanceof Point) { |
|
42 |
Point p = (Point) geom; |
|
43 |
p.transform(affineTransform); |
|
44 |
g.drawRect((int) p.getX(), (int) p.getY(), 3, 3); |
|
45 |
} else { |
|
46 |
PathIterator piter = geom.getPathIterator(affineTransform); |
|
47 |
drawPathIterator(g, piter); |
|
48 |
} |
|
49 |
} |
|
50 |
|
|
51 |
public void drawInsideRectangle(Graphics2D g, |
|
52 |
AffineTransform scaleInstance, Rectangle r, |
|
53 |
PrintAttributes properties) throws SymbolDrawingException { |
|
54 |
// TODO Auto-generated method stub |
|
55 |
|
|
56 |
} |
|
57 |
|
|
58 |
public Color getColor() { |
|
59 |
return color; |
|
60 |
} |
|
61 |
|
|
62 |
public String getDescription() { |
|
63 |
return "a dummy symbol"; |
|
64 |
} |
|
65 |
|
|
66 |
public int getOnePointRgb() { |
|
67 |
return color.getRGB(); |
|
68 |
} |
|
69 |
|
|
70 |
public void getPixExtentPlus(Geometry geom, float[] distances, |
|
71 |
ViewPort viewPort, int dpi) { |
|
72 |
// TODO Auto-generated method stub |
|
73 |
|
|
74 |
} |
|
75 |
|
|
76 |
public ISymbol getSymbolForSelection() { |
|
77 |
return new DummySymbol(Color.YELLOW, type); |
|
78 |
} |
|
79 |
|
|
80 |
public int getSymbolType() { |
|
81 |
return type; |
|
82 |
} |
|
83 |
|
|
84 |
public boolean isOneDotOrPixel(Geometry geom, |
|
85 |
double[] positionOfDotOrPixel, ViewPort viewPort, int dpi) { |
|
86 |
// TODO Auto-generated method stub |
|
87 |
return false; |
|
88 |
} |
|
89 |
|
|
90 |
public boolean isShapeVisible() { |
|
91 |
return true; |
|
92 |
} |
|
93 |
|
|
94 |
public boolean isSuitableFor(Geometry geom) { |
|
95 |
return type == geom.getType(); |
|
96 |
} |
|
97 |
|
|
98 |
public void setColor(Color c) { |
|
99 |
color = c; |
|
100 |
} |
|
101 |
|
|
102 |
public void setDescription(String desc) { |
|
103 |
} |
|
104 |
|
|
105 |
public void loadFromState(PersistentState state) |
|
106 |
throws PersistenceException { |
|
107 |
} |
|
108 |
|
|
109 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
110 |
} |
|
111 |
|
|
112 |
public void print(Graphics2D g, AffineTransform at, Geometry shape, |
|
113 |
PrintAttributes properties) { |
|
114 |
} |
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
/** |
|
119 |
* Draws the general path on the graphics object with the given affine transformation |
|
120 |
* @param g the graphics object |
|
121 |
* @param gp the general path |
|
122 |
*/ |
|
123 |
public static void drawPathIterator(Graphics2D g, PathIterator pit) { |
|
124 |
|
|
125 |
ArrayList x = new ArrayList(); |
|
126 |
ArrayList y = new ArrayList(); |
|
127 |
double[] current = new double[6]; |
|
128 |
|
|
129 |
while (!pit.isDone()) { |
|
130 |
pit.currentSegment(current); |
|
131 |
x.add(new Integer((int) current[0])); |
|
132 |
y.add(new Integer((int) current[1])); |
|
133 |
pit.next(); |
|
134 |
} |
|
135 |
|
|
136 |
int[] gx = integerArrayListToIntArray(x); |
|
137 |
int[] gy = integerArrayListToIntArray(y); |
|
138 |
|
|
139 |
g.drawPolyline(gx, gy, gx.length); |
|
140 |
} |
|
141 |
|
|
142 |
|
|
143 |
/** |
|
144 |
* Converts array list of Integer objects into array of int |
|
145 |
* @param l |
|
146 |
* @return array of int |
|
147 |
*/ |
|
148 |
public static int[] integerArrayListToIntArray(ArrayList l) { |
|
149 |
|
|
150 |
int size = l.size(); |
|
151 |
int[] resp = new int[size]; |
|
152 |
for (int i=0; i<size; i++) { |
|
153 |
resp[i] = ((Integer) l.get(i)).intValue(); |
|
154 |
} |
|
155 |
return resp; |
|
156 |
} |
|
157 |
|
|
158 |
} |
|
0 | 159 |
tags/v2_0_0_Build_2011/libraries/libFMap_mapcontext/src-test/org/gvsig/fmap/mapcontext/tools/persistence/DimensionPersistenceFactoryTest.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Gobernment (CIT) |
|
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 2 |
|
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 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2009 {} {{Task}} |
|
26 |
*/ |
|
27 |
package org.gvsig.fmap.mapcontext.tools.persistence; |
|
28 |
|
|
29 |
import java.awt.Dimension; |
|
30 |
|
|
31 |
import org.easymock.MockControl; |
|
32 |
import org.gvsig.tools.ToolsLocator; |
|
33 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
|
34 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
35 |
import org.gvsig.tools.persistence.PersistentState; |
|
36 |
|
|
37 |
/** |
|
38 |
* Unit tests for the class {@link DimensionPersistenceFactory}. |
|
39 |
* |
|
40 |
* @author gvSIG team |
|
41 |
*/ |
|
42 |
public class DimensionPersistenceFactoryTest extends |
|
43 |
AbstractLibraryAutoInitTestCase { |
|
44 |
|
|
45 |
private DimensionPersistenceFactory factory; |
|
46 |
private MockControl stateControl; |
|
47 |
private PersistentState state; |
|
48 |
private Dimension dimension; |
|
49 |
|
|
50 |
protected void doSetUp() throws Exception { |
|
51 |
PersistenceManager persistenceManager = ToolsLocator |
|
52 |
.getPersistenceManager(); |
|
53 |
factory = (DimensionPersistenceFactory) persistenceManager |
|
54 |
.getFactories().get(Dimension.class); |
|
55 |
stateControl = MockControl.createNiceControl(PersistentState.class); |
|
56 |
state = (PersistentState) stateControl.getMock(); |
|
57 |
dimension = new Dimension(320, 200); |
|
58 |
} |
|
59 |
|
|
60 |
/** |
|
61 |
* Test method for |
|
62 |
* {@link org.gvsig.fmap.mapcontext.tools.persistence.DimensionPersistenceFactory#createFromState(org.gvsig.tools.persistence.PersistentState, java.lang.Class)} |
|
63 |
* . |
|
64 |
*/ |
|
65 |
public void testCreateFromState() throws Exception { |
|
66 |
stateControl.expectAndReturn(state |
|
67 |
.getDouble(DimensionPersistenceFactory.FIELD_WIDTH), dimension |
|
68 |
.getWidth()); |
|
69 |
stateControl.expectAndReturn(state |
|
70 |
.getDouble(DimensionPersistenceFactory.FIELD_HEIGHT), dimension |
|
71 |
.getHeight()); |
|
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 |
|
87 |
.set(DimensionPersistenceFactory.FIELD_WIDTH, dimension |
|
88 |
.getWidth()); |
|
89 |
state.set(DimensionPersistenceFactory.FIELD_HEIGHT, dimension |
|
90 |
.getHeight()); |
|
91 |
stateControl.replay(); |
|
92 |
|
|
93 |
factory.saveToState(state, dimension); |
|
94 |
|
|
95 |
stateControl.verify(); |
|
96 |
} |
|
97 |
|
|
98 |
} |
tags/v2_0_0_Build_2011/libraries/libFMap_mapcontext/src-test/org/gvsig/fmap/mapcontext/tools/persistence/FontPersistenceFactoryTest.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Gobernment (CIT) |
|
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 2 |
|
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 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2009 {} {{Task}} |
|
26 |
*/ |
|
27 |
package org.gvsig.fmap.mapcontext.tools.persistence; |
|
28 |
|
|
29 |
import java.awt.Font; |
|
30 |
|
|
31 |
import org.easymock.MockControl; |
|
32 |
import org.gvsig.tools.ToolsLocator; |
|
33 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
|
34 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
35 |
import org.gvsig.tools.persistence.PersistentState; |
|
36 |
|
|
37 |
/** |
|
38 |
* Unit tests for the class {@link FontPersistenceFactory}. |
|
39 |
* |
|
40 |
* @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team |
|
41 |
*/ |
|
42 |
public class FontPersistenceFactoryTest extends AbstractLibraryAutoInitTestCase { |
|
43 |
|
|
44 |
private FontPersistenceFactory factory; |
|
45 |
private MockControl stateControl; |
|
46 |
private PersistentState state; |
|
47 |
private Font font; |
|
48 |
|
|
49 |
protected void doSetUp() throws Exception { |
|
50 |
PersistenceManager persistenceManager = ToolsLocator |
|
51 |
.getPersistenceManager(); |
|
52 |
factory = (FontPersistenceFactory) persistenceManager.getFactories() |
|
53 |
.get(Font.class); |
|
54 |
stateControl = MockControl.createNiceControl(PersistentState.class); |
|
55 |
state = (PersistentState) stateControl.getMock(); |
|
56 |
font = new Font("Arial", Font.BOLD, 18); |
|
57 |
} |
|
58 |
|
|
59 |
/** |
|
60 |
* Test method for |
|
61 |
* {@link org.gvsig.fmap.mapcontext.tools.persistence.FontPersistenceFactory#createFromState(org.gvsig.tools.persistence.PersistentState, java.lang.Class)} |
|
62 |
* . |
|
63 |
*/ |
|
64 |
public void testCreateFromState() throws Exception { |
|
65 |
stateControl.expectAndReturn(state |
|
66 |
.getString(FontPersistenceFactory.FIELD_NAME), font.getName()); |
|
67 |
stateControl.expectAndReturn(state |
|
68 |
.getInt(FontPersistenceFactory.FIELD_STYLE), font.getStyle()); |
|
69 |
stateControl.expectAndReturn(state |
|
70 |
.getInt(FontPersistenceFactory.FIELD_SIZE), font.getSize()); |
|
71 |
stateControl.replay(); |
|
72 |
|
|
73 |
Font newFont = (Font) factory.createFromState(state); |
|
74 |
assertTrue(newFont.equals(font)); |
|
75 |
|
|
76 |
stateControl.verify(); |
|
77 |
} |
|
78 |
|
|
79 |
/** |
|
80 |
* Test method for |
|
81 |
* {@link org.gvsig.fmap.mapcontext.tools.persistence.FontPersistenceFactory#saveToState(org.gvsig.tools.persistence.PersistentState, java.lang.Object)} |
|
82 |
* . |
|
83 |
*/ |
|
84 |
public void testSaveToState() throws Exception { |
|
85 |
state.set(FontPersistenceFactory.FIELD_NAME, font.getName()); |
|
86 |
state.set(FontPersistenceFactory.FIELD_STYLE, font.getStyle()); |
|
87 |
state.set(FontPersistenceFactory.FIELD_SIZE, font.getSize()); |
|
88 |
stateControl.replay(); |
|
89 |
|
|
90 |
factory.saveToState(state, font); |
|
91 |
|
|
92 |
stateControl.verify(); |
|
93 |
} |
|
94 |
|
|
95 |
} |
tags/v2_0_0_Build_2011/libraries/libFMap_mapcontext/src-test/org/gvsig/fmap/mapcontext/tools/persistence/Rectangle2DPersistenceFactoryTest.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Gobernment (CIT) |
|
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 2 |
|
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 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2009 {} {{Task}} |
|
26 |
*/ |
|
27 |
package org.gvsig.fmap.mapcontext.tools.persistence; |
|
28 |
|
|
29 |
import java.awt.geom.Rectangle2D; |
|
30 |
|
|
31 |
import org.easymock.MockControl; |
|
32 |
import org.gvsig.tools.ToolsLocator; |
|
33 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
|
34 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
35 |
import org.gvsig.tools.persistence.PersistentState; |
|
36 |
|
|
37 |
/** |
|
38 |
* Unit tests for the class {@link Rectangle2DPersistenceFactory}. |
|
39 |
* |
|
40 |
* @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team |
|
41 |
*/ |
|
42 |
public class Rectangle2DPersistenceFactoryTest extends |
|
43 |
AbstractLibraryAutoInitTestCase { |
|
44 |
|
|
45 |
private Rectangle2DPersistenceFactory factory; |
|
46 |
private MockControl stateControl; |
|
47 |
private PersistentState state; |
|
48 |
private Rectangle2D rectangle; |
|
49 |
|
|
50 |
protected void doSetUp() throws Exception { |
|
51 |
PersistenceManager persistenceManager = ToolsLocator |
|
52 |
.getPersistenceManager(); |
|
53 |
factory = (Rectangle2DPersistenceFactory) persistenceManager |
|
54 |
.getFactories().get(Rectangle2D.class); |
|
55 |
stateControl = MockControl.createNiceControl(PersistentState.class); |
|
56 |
state = (PersistentState) stateControl.getMock(); |
|
57 |
double x = Math.random() * 1000d; |
|
58 |
double y = Math.random() * 1000d; |
|
59 |
rectangle = new Rectangle2D.Double(x, y, 320, 200); |
|
60 |
} |
|
61 |
|
|
62 |
/** |
|
63 |
* Test method for |
|
64 |
* {@link org.gvsig.fmap.mapcontext.tools.persistence.Rectangle2DPersistenceFactory#createFromState(PersistentState, Class)} |
|
65 |
* . |
|
66 |
*/ |
|
67 |
public void testCreateFromState() throws Exception { |
|
68 |
stateControl.expectAndReturn(state |
|
69 |
.getDouble(Rectangle2DPersistenceFactory.FIELD_X), rectangle |
|
70 |
.getX()); |
|
71 |
stateControl.expectAndReturn(state |
|
72 |
.getDouble(Rectangle2DPersistenceFactory.FIELD_Y), rectangle |
|
73 |
.getY()); |
|
74 |
stateControl.expectAndReturn(state |
|
75 |
.getDouble(Rectangle2DPersistenceFactory.FIELD_WIDTH), |
|
76 |
rectangle.getWidth()); |
|
77 |
stateControl.expectAndReturn(state |
|
78 |
.getDouble(Rectangle2DPersistenceFactory.FIELD_HEIGHT), |
|
79 |
rectangle.getHeight()); |
|
80 |
stateControl.replay(); |
|
81 |
|
|
82 |
Rectangle2D newRectangle = (Rectangle2D) factory.createFromState(state); |
|
83 |
|
|
84 |
System.out.println("Orig x = " + rectangle.getX() + " - New x = " |
|
85 |
+ newRectangle.getX()); |
|
86 |
assertEquals(rectangle.getX(), newRectangle.getX(), 0.0d); |
|
87 |
System.out.println("Orig y = " + rectangle.getY() + " - New y = " |
|
88 |
+ newRectangle.getY()); |
|
89 |
assertEquals(rectangle.getY(), newRectangle.getY(), 0.0d); |
|
90 |
System.out.println("Orig width = " + rectangle.getWidth() |
|
91 |
+ " - New width = " + newRectangle.getWidth()); |
|
92 |
assertEquals(rectangle.getWidth(), newRectangle.getWidth(), 0.0d); |
|
93 |
System.out.println("Orig height = " + rectangle.getHeight() |
|
94 |
+ " - New height = " + newRectangle.getHeight()); |
|
95 |
assertEquals(rectangle.getHeight(), newRectangle.getHeight(), 0.0d); |
|
96 |
|
|
97 |
assertTrue(newRectangle.equals(rectangle)); |
|
98 |
|
|
99 |
stateControl.verify(); |
|
100 |
} |
|
101 |
|
|
102 |
/** |
|
103 |
* Test method for |
|
104 |
* {@link org.gvsig.fmap.mapcontext.tools.persistence.Rectangle2DPersistenceFactory#saveToState(org.gvsig.tools.persistence.PersistentState, java.lang.Object)} |
|
105 |
* . |
|
106 |
*/ |
|
107 |
public void testSaveToState() throws Exception { |
|
108 |
state.set(Rectangle2DPersistenceFactory.FIELD_X, rectangle.getX()); |
|
109 |
state.set(Rectangle2DPersistenceFactory.FIELD_Y, rectangle.getY()); |
|
110 |
state.set(Rectangle2DPersistenceFactory.FIELD_WIDTH, rectangle |
|
111 |
.getWidth()); |
|
112 |
state.set(Rectangle2DPersistenceFactory.FIELD_HEIGHT, rectangle |
|
113 |
.getHeight()); |
|
114 |
stateControl.replay(); |
|
115 |
|
|
116 |
factory.saveToState(state, rectangle); |
|
117 |
|
|
118 |
stateControl.verify(); |
|
119 |
} |
|
120 |
} |
tags/v2_0_0_Build_2011/libraries/libFMap_mapcontext/src-test/org/gvsig/fmap/mapcontext/tools/persistence/ColorPersistenceFactoryTest.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Gobernment (CIT) |
|
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 2 |
|
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 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2009 {} {{Task}} |
|
26 |
*/ |
|
27 |
package org.gvsig.fmap.mapcontext.tools.persistence; |
|
28 |
|
|
29 |
import java.awt.Color; |
|
30 |
|
|
31 |
import org.easymock.MockControl; |
|
32 |
import org.gvsig.tools.ToolsLocator; |
|
33 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
|
34 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
35 |
import org.gvsig.tools.persistence.PersistentState; |
|
36 |
|
|
37 |
/** |
|
38 |
* Unit tests for the class {@link ColorPersistenceFactory}. |
|
39 |
* |
|
40 |
* @author gvSIG team |
|
41 |
*/ |
|
42 |
public class ColorPersistenceFactoryTest extends |
|
43 |
AbstractLibraryAutoInitTestCase { |
|
44 |
|
|
45 |
private ColorPersistenceFactory factory; |
|
46 |
private MockControl stateControl; |
|
47 |
private PersistentState state; |
|
48 |
private Color color; |
|
49 |
|
|
50 |
protected void doSetUp() throws Exception { |
|
51 |
PersistenceManager persistenceManager = ToolsLocator |
|
52 |
.getPersistenceManager(); |
|
53 |
factory = (ColorPersistenceFactory) persistenceManager.getFactories() |
|
54 |
.get(Color.class); |
|
55 |
stateControl = MockControl.createNiceControl(PersistentState.class); |
|
56 |
state = (PersistentState) stateControl.getMock(); |
|
57 |
color = Color.magenta; |
|
58 |
} |
|
59 |
|
|
60 |
/** |
|
61 |
* Test method for |
|
62 |
* {@link org.gvsig.fmap.mapcontext.tools.persistence.ColorPersistenceFactory#createFromState(org.gvsig.tools.persistence.PersistentState, java.lang.Class)} |
|
63 |
* . |
|
64 |
*/ |
|
65 |
public void testCreateFromState() throws Exception { |
|
66 |
stateControl.expectAndReturn(state |
|
67 |
.getInt(ColorPersistenceFactory.FIELD_RED), color.getRed()); |
|
68 |
stateControl.expectAndReturn(state |
|
69 |
.getInt(ColorPersistenceFactory.FIELD_GREEN), color.getGreen()); |
|
70 |
stateControl.expectAndReturn(state |
|
71 |
.getInt(ColorPersistenceFactory.FIELD_BLUE), color.getBlue()); |
|
72 |
stateControl.expectAndReturn(state |
|
73 |
.getInt(ColorPersistenceFactory.FIELD_ALPHA), color.getAlpha()); |
|
74 |
stateControl.replay(); |
|
75 |
|
|
76 |
Color newColor = (Color) factory.createFromState(state); |
|
77 |
assertTrue(newColor.equals(color)); |
|
78 |
|
|
79 |
stateControl.verify(); |
|
80 |
} |
|
81 |
|
|
82 |
/** |
|
83 |
* Test method for |
|
84 |
* {@link org.gvsig.fmap.mapcontext.tools.persistence.ColorPersistenceFactory#saveToState(org.gvsig.tools.persistence.PersistentState, java.lang.Object)} |
|
85 |
* . |
|
86 |
*/ |
|
87 |
public void testSaveToState() throws Exception { |
|
88 |
state.set(ColorPersistenceFactory.FIELD_RED, color.getRed()); |
|
89 |
state.set(ColorPersistenceFactory.FIELD_GREEN, color.getGreen()); |
|
90 |
state.set(ColorPersistenceFactory.FIELD_BLUE, color.getBlue()); |
|
91 |
state.set(ColorPersistenceFactory.FIELD_ALPHA, color.getAlpha()); |
|
92 |
stateControl.replay(); |
|
93 |
|
|
94 |
factory.saveToState(state, color); |
|
95 |
|
|
96 |
stateControl.verify(); |
|
97 |
} |
|
98 |
|
|
99 |
} |
tags/v2_0_0_Build_2011/libraries/libFMap_mapcontext/src-test/org/gvsig/fmap/mapcontext/tools/persistence/Point2DPersistenceFactoryTest.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Gobernment (CIT) |
|
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 2 |
|
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 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2009 {} {{Task}} |
|
26 |
*/ |
|
27 |
package org.gvsig.fmap.mapcontext.tools.persistence; |
|
28 |
|
|
29 |
import java.awt.geom.Point2D; |
|
30 |
|
|
31 |
import org.easymock.MockControl; |
|
32 |
import org.gvsig.tools.ToolsLocator; |
|
33 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
|
34 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
35 |
import org.gvsig.tools.persistence.PersistentState; |
|
36 |
|
|
37 |
/** |
|
38 |
* Unit tests for the class {@link Point2DPersistenceFactory}. |
|
39 |
* |
|
40 |
* @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team |
|
41 |
*/ |
|
42 |
public class Point2DPersistenceFactoryTest extends |
|
43 |
AbstractLibraryAutoInitTestCase { |
|
44 |
|
|
45 |
private Point2DPersistenceFactory factory; |
|
46 |
private MockControl stateControl; |
|
47 |
private PersistentState state; |
|
48 |
private Point2D point; |
|
49 |
|
|
50 |
protected void doSetUp() throws Exception { |
|
51 |
PersistenceManager persistenceManager = ToolsLocator |
|
52 |
.getPersistenceManager(); |
|
53 |
factory = (Point2DPersistenceFactory) persistenceManager.getFactories() |
|
54 |
.get(Point2D.class); |
|
55 |
stateControl = MockControl.createNiceControl(PersistentState.class); |
|
56 |
state = (PersistentState) stateControl.getMock(); |
|
57 |
double x = Math.random() * 1000d; |
|
58 |
double y = Math.random() * 1000d; |
|
59 |
point = new Point2D.Double(x, y); |
|
60 |
} |
|
61 |
|
|
62 |
/** |
|
63 |
* Test method for |
|
64 |
* {@link org.gvsig.fmap.mapcontext.tools.persistence.Point2DPersistenceFactory#createFromState(PersistentState, Class)} |
|
65 |
* . |
|
66 |
*/ |
|
67 |
public void testCreateFromState() throws Exception { |
|
68 |
stateControl.expectAndReturn(state |
|
69 |
.getDouble(Point2DPersistenceFactory.FIELD_X), point.getX()); |
|
70 |
stateControl.expectAndReturn(state |
|
71 |
.getDouble(Point2DPersistenceFactory.FIELD_Y), point.getY()); |
|
72 |
stateControl.replay(); |
|
73 |
|
|
74 |
Point2D newPoint = (Point2D) factory.createFromState(state); |
|
75 |
assertTrue(newPoint.equals(point)); |
|
76 |
|
|
77 |
stateControl.verify(); |
|
78 |
} |
|
79 |
|
|
80 |
/** |
|
81 |
* Test method for |
|
82 |
* {@link org.gvsig.fmap.mapcontext.tools.persistence.Point2DPersistenceFactory#saveToState(org.gvsig.tools.persistence.PersistentState, java.lang.Object)} |
|
83 |
* . |
|
84 |
*/ |
|
85 |
public void testSaveToState() throws Exception { |
|
86 |
state.set(Point2DPersistenceFactory.FIELD_X, point.getX()); |
|
87 |
state.set(Point2DPersistenceFactory.FIELD_Y, point.getY()); |
|
88 |
stateControl.replay(); |
|
89 |
|
|
90 |
factory.saveToState(state, point); |
|
91 |
|
|
92 |
stateControl.verify(); |
|
93 |
} |
|
94 |
} |
tags/v2_0_0_Build_2011/libraries/libFMap_mapcontext/src-test/org/gvsig/fmap/mapcontext/impl/DefaultMapContextManagerTest.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
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 2 |
|
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 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2009 {DiSiD Technologies} {{Task}} |
|
26 |
*/ |
|
27 |
package org.gvsig.fmap.mapcontext.impl; |
|
28 |
|
|
29 |
import java.awt.Graphics2D; |
|
30 |
import java.awt.image.BufferedImage; |
|
31 |
import java.util.Map; |
|
32 |
|
|
33 |
import org.cresques.cts.ICoordTrans; |
|
34 |
import org.gvsig.compat.print.PrintAttributes; |
|
35 |
import org.gvsig.fmap.crs.CRSFactory; |
|
36 |
import org.gvsig.fmap.dal.exception.ReadException; |
|
37 |
import org.gvsig.fmap.dal.feature.Feature; |
|
38 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
39 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
40 |
import org.gvsig.fmap.mapcontext.MapContextDrawer; |
|
41 |
import org.gvsig.fmap.mapcontext.MapContextException; |
|
42 |
import org.gvsig.fmap.mapcontext.MapContextRuntimeException; |
|
43 |
import org.gvsig.fmap.mapcontext.ViewPort; |
|
44 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
|
45 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
|
46 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend; |
|
47 |
import org.gvsig.fmap.mapcontext.rendering.legend.LegendException; |
|
48 |
import org.gvsig.fmap.mapcontext.rendering.legend.driver.ILegendReader; |
|
49 |
import org.gvsig.fmap.mapcontext.rendering.legend.driver.ILegendWriter; |
|
50 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendContentsChangedListener; |
|
51 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent; |
|
52 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
53 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
|
54 |
import org.gvsig.tools.observer.Observer; |
|
55 |
import org.gvsig.tools.persistence.PersistentState; |
|
56 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
57 |
import org.gvsig.tools.task.Cancellable; |
|
58 |
|
|
59 |
/** |
|
60 |
* @author <a href="mailto:cordinyana@gvsig.org">C?sar Ordi?ana</a> |
|
61 |
*/ |
|
62 |
public class DefaultMapContextManagerTest extends |
|
63 |
AbstractLibraryAutoInitTestCase { |
|
64 |
|
|
65 |
private DefaultMapContextManager manager; |
|
66 |
|
|
67 |
protected void doSetUp() throws Exception { |
|
68 |
manager = new DefaultMapContextManager(); |
|
69 |
|
|
70 |
manager.registerLegend("DummyLegend", DummyVectorLegend.class); |
|
71 |
manager.setDefaultVectorLegend("DummyLegend"); |
|
72 |
manager.registerLegendReader("Dummy", DummyLegendReader.class); |
|
73 |
manager.registerLegendWriter("DummyLegend", "Dummy", DummyLegendWriter.class); |
|
74 |
} |
|
75 |
|
|
76 |
protected void tearDown() throws Exception { |
|
77 |
super.tearDown(); |
|
78 |
} |
|
79 |
|
|
80 |
/** |
|
81 |
* Test method for |
|
82 |
* {@link org.gvsig.fmap.mapcontext.impl.DefaultMapContextManager#createDefaultMapContextDrawerInstance()} |
|
83 |
* . |
|
84 |
*/ |
|
85 |
public void testGetDefaultMapContextDrawerInstance() throws Exception { |
|
86 |
|
|
87 |
manager.setDefaultMapContextDrawer(DummyMapContextDrawer.class); |
|
88 |
|
|
89 |
MapContextDrawer drawer = manager |
|
90 |
.createDefaultMapContextDrawerInstance(); |
|
91 |
|
|
92 |
assertNotNull("The created MapContextDrawer instance can't be null", |
|
93 |
drawer); |
|
94 |
assertTrue( |
|
95 |
"The created MapContextDrawer is not instance of the registered class" |
|
96 |
+ DummyMapContextDrawer.class, |
|
97 |
drawer instanceof DummyMapContextDrawer); |
|
98 |
} |
|
99 |
|
|
100 |
/** |
|
101 |
* Test method for |
|
102 |
* {@link org.gvsig.fmap.mapcontext.impl.DefaultMapContextManager#setDefaultMapContextDrawer(java.lang.Class)} |
|
103 |
* . |
|
104 |
*/ |
|
105 |
public void testSetDefaultMapContextDrawer() throws Exception { |
|
106 |
|
|
107 |
// First, try to register an invalid class |
|
108 |
try { |
|
109 |
manager.setDefaultMapContextDrawer(Object.class); |
|
110 |
fail("Error, a class that does not implement the MapContextDrawer " |
|
111 |
+ "interface has been accepted"); |
|
112 |
} catch (MapContextRuntimeException e) { |
|
113 |
// OK |
|
114 |
} |
|
115 |
|
|
116 |
// Next, try to register a valid class |
|
117 |
manager.setDefaultMapContextDrawer(DummyMapContextDrawer.class); |
|
118 |
} |
|
119 |
|
|
120 |
public void testCreateGraphicsLayer() throws Exception { |
|
121 |
assertNotNull(manager.createGraphicsLayer(CRSFactory.getCRS("EPSG:23030"))); |
|
122 |
} |
|
123 |
|
|
124 |
public void testCreateDefaultVectorLegend() throws Exception { |
|
125 |
|
|
126 |
IVectorLegend legend = manager.createDefaultVectorLegend(1); |
|
127 |
assertNotNull(legend); |
|
128 |
assertTrue(legend instanceof DummyVectorLegend); |
|
129 |
} |
|
130 |
|
|
131 |
public void testRegisterCreateLegend() throws Exception { |
|
132 |
|
|
133 |
manager.registerLegend("DummyLegend", DummyVectorLegend.class); |
|
134 |
|
|
135 |
ILegend legend = manager.createLegend("DummyLegend"); |
|
136 |
assertNotNull(legend); |
|
137 |
assertTrue(legend instanceof DummyVectorLegend); |
|
138 |
|
|
139 |
assertNull(manager.createLegend("NONE")); |
|
140 |
} |
|
141 |
|
|
142 |
public void testRegisterCreateLegendReader() throws Exception { |
|
143 |
|
|
144 |
manager.registerLegendReader("Dummy", DummyLegendReader.class); |
|
145 |
|
|
146 |
ILegendReader legendReader = manager.createLegendReader("Dummy"); |
|
147 |
assertNotNull(legendReader); |
|
148 |
assertTrue(legendReader instanceof DummyLegendReader); |
|
149 |
|
|
150 |
assertNull(manager.createLegendReader("NONE")); |
|
151 |
} |
|
152 |
|
|
153 |
public void testRegisterCreateLegendWriter() throws Exception { |
|
154 |
|
|
155 |
manager.registerLegend("DummyLegend", DummyVectorLegend.class); |
|
156 |
|
|
157 |
manager.registerLegendWriter("DummyLegend", "Dummy", |
|
158 |
DummyLegendWriter.class); |
|
159 |
|
|
160 |
// Test the registered writer is created |
|
161 |
ILegendWriter legendWriter = manager.createLegendWriter("DummyLegend", |
|
162 |
"Dummy"); |
|
163 |
assertNotNull(legendWriter); |
|
164 |
assertTrue(legendWriter instanceof DummyLegendWriter); |
|
165 |
|
|
166 |
// Test non registered cases |
|
167 |
assertNull(manager.createLegendWriter("NONE", "Dummy")); |
|
168 |
assertNull(manager.createLegendWriter("DummyLegend", "NONE")); |
|
169 |
assertNull(manager.createLegendWriter("NONE", "NONE")); |
|
170 |
} |
|
171 |
|
|
172 |
public static class DummyMapContextDrawer implements MapContextDrawer { |
|
173 |
|
|
174 |
public void dispose() { |
|
175 |
} |
|
176 |
|
|
177 |
public void draw(FLayers root, BufferedImage image, Graphics2D g, |
|
178 |
Cancellable cancel, double scale) throws ReadException { |
|
179 |
} |
|
180 |
|
|
181 |
public void print(FLayers root, Graphics2D g, Cancellable cancel, |
|
182 |
double scale, PrintAttributes properties) throws ReadException { |
|
183 |
} |
|
184 |
|
|
185 |
public void setMapContext(MapContext mapContext) { |
|
186 |
} |
|
187 |
|
|
188 |
public void setViewPort(ViewPort viewPort) { |
|
189 |
} |
|
190 |
|
|
191 |
} |
|
192 |
|
|
193 |
public static class DummyLegendReader implements ILegendReader { |
|
194 |
|
|
195 |
} |
|
196 |
|
|
197 |
public static class DummyLegendWriter implements ILegendWriter { |
|
198 |
|
|
199 |
} |
|
200 |
|
|
201 |
public static class DummyVectorLegend implements IVectorLegend { |
|
202 |
|
|
203 |
public void draw(BufferedImage image, Graphics2D graphics2d, |
|
204 |
ViewPort viewPort, Cancellable cancel, double scale, |
|
205 |
Map queryParameters, ICoordTrans coordTrans, |
|
206 |
FeatureStore featureStore) throws LegendException { |
|
207 |
// Empty method |
|
208 |
} |
|
209 |
|
|
210 |
public int getShapeType() { |
|
211 |
// Empty method |
|
212 |
return 0; |
|
213 |
} |
|
214 |
|
|
215 |
public ISymbol getSymbolByFeature(Feature feat) |
|
216 |
throws MapContextException { |
|
217 |
// Empty method |
|
218 |
return null; |
|
219 |
} |
|
220 |
|
|
221 |
public boolean isSuitableForShapeType(int shapeType) { |
|
222 |
// Empty method |
|
223 |
return false; |
|
224 |
} |
|
225 |
|
|
226 |
public boolean isUseDefaultSymbol() { |
|
227 |
// Empty method |
|
228 |
return false; |
|
229 |
} |
|
230 |
|
|
231 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
|
232 |
double scale, Map queryParameters, ICoordTrans coordTrans, |
|
233 |
FeatureStore featureStore, PrintAttributes properties) |
|
234 |
throws LegendException { |
|
235 |
// Empty method |
|
236 |
} |
|
237 |
|
|
238 |
public void setDefaultSymbol(ISymbol s) { |
|
239 |
// Empty method |
|
240 |
} |
|
241 |
|
|
242 |
public void setShapeType(int shapeType) { |
|
243 |
// Empty method |
|
244 |
} |
|
245 |
|
|
246 |
public void useDefaultSymbol(boolean b) { |
|
247 |
// Empty method |
|
248 |
} |
|
249 |
|
|
250 |
public void addLegendListener(LegendContentsChangedListener listener) { |
|
251 |
// Empty method |
|
252 |
} |
|
253 |
|
|
254 |
public ILegend cloneLegend() { |
|
255 |
// Empty method |
|
256 |
return null; |
|
257 |
} |
|
258 |
|
|
259 |
public Object clone() throws CloneNotSupportedException { |
|
260 |
// TODO Auto-generated method stub |
|
261 |
return super.clone(); |
|
262 |
} |
|
263 |
|
|
264 |
public void fireDefaultSymbolChangedEvent(SymbolLegendEvent event) { |
|
265 |
// Empty method |
|
266 |
} |
|
267 |
|
|
268 |
public ISymbol getDefaultSymbol() { |
|
269 |
// Empty method |
|
270 |
return null; |
|
271 |
} |
|
272 |
|
|
273 |
public LegendContentsChangedListener[] getListeners() { |
|
274 |
// Empty method |
|
275 |
return null; |
|
276 |
} |
|
277 |
|
|
278 |
public void removeLegendListener(LegendContentsChangedListener listener) { |
|
279 |
// Empty method |
|
280 |
} |
|
281 |
|
|
282 |
public void loadFromState(PersistentState state) |
|
283 |
throws PersistenceException { |
|
284 |
// Empty method |
|
285 |
} |
|
286 |
|
|
287 |
public void saveToState(PersistentState state) |
|
288 |
throws PersistenceException { |
|
289 |
// Empty method |
|
290 |
} |
|
291 |
|
|
292 |
public void addDrawingObserver(Observer observer) { |
|
293 |
// Empty method |
|
294 |
} |
|
295 |
|
|
296 |
public void deleteDrawingObserver(Observer observer) { |
|
297 |
// Empty method |
|
298 |
} |
|
299 |
|
|
300 |
public void deleteDrawingObservers() { |
|
301 |
// Empty method |
|
302 |
} |
|
303 |
} |
|
304 |
} |
tags/v2_0_0_Build_2011/libraries/libFMap_mapcontext/src-test/org/gvsig/fmap/mapcontext/persistence/MapContextPersistenceTest.java | ||
---|---|---|
1 |
package org.gvsig.fmap.mapcontext.persistence; |
|
2 |
|
|
3 |
import java.awt.Color; |
|
4 |
import java.awt.Dimension; |
|
5 |
import java.awt.geom.Rectangle2D; |
|
6 |
import java.io.File; |
|
7 |
import java.io.FileInputStream; |
|
8 |
import java.io.FileOutputStream; |
|
9 |
|
|
10 |
import org.gvsig.fmap.crs.CRSFactory; |
|
11 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
12 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
|
13 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
14 |
import org.gvsig.fmap.geom.primitive.impl.Envelope2D; |
|
15 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
16 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
|
17 |
import org.gvsig.fmap.mapcontext.ViewPort; |
|
18 |
import org.gvsig.fmap.mapcontext.exceptions.LegendLayerException; |
|
19 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
20 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
|
21 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
22 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
|
23 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend; |
|
24 |
import org.gvsig.fmap.mapcontext.rendering.symbol.DummyVectorLegend; |
|
25 |
import org.gvsig.tools.ToolsLocator; |
|
26 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
|
27 |
import org.gvsig.tools.persistence.Persistent; |
|
28 |
import org.gvsig.tools.persistence.PersistentState; |
|
29 |
import org.slf4j.Logger; |
|
30 |
import org.slf4j.LoggerFactory; |
|
31 |
|
|
32 |
public class MapContextPersistenceTest extends AbstractLibraryAutoInitTestCase { |
|
33 |
|
|
34 |
final static private Logger logger = |
|
35 |
LoggerFactory.getLogger(MapContextPersistenceTest.class); |
|
36 |
|
|
37 |
protected void doSetUp() throws Exception { |
|
38 |
DummyVectorLegend.registerPersistent(); |
|
39 |
DummyDBFeatureStore.registerPersistent(); |
|
40 |
DummyFileFeatureStore.registerPersistent(); |
|
41 |
|
|
42 |
MapContextLocator.getMapContextManager().registerLegend("DummyLegend", |
|
43 |
DummyVectorLegend.class); |
|
44 |
MapContextLocator.getMapContextManager().setDefaultVectorLegend( |
|
45 |
"DummyLegend"); |
|
46 |
} |
|
47 |
|
|
48 |
private File getTempFile() throws Exception { |
|
49 |
|
|
50 |
File tempFile = File.createTempFile("persisted_mapcontext", ".xml"); |
|
51 |
if (tempFile.exists()) |
|
52 |
tempFile.delete(); |
|
53 |
tempFile.createNewFile(); |
|
54 |
|
|
55 |
System.out.println("TEMP FILE: " + tempFile.getAbsolutePath()); |
|
56 |
return tempFile; |
|
57 |
} |
|
58 |
|
|
59 |
public void testMapContext() throws Exception { |
|
60 |
ViewPort vp = getViewPort(); |
|
61 |
logger.debug("Creating mapcontext..."); |
|
62 |
MapContext mc = new MapContext(vp); |
|
63 |
addDummyLayers(mc); |
|
64 |
doTestPersist(mc); |
|
65 |
} |
|
66 |
|
|
67 |
public void noTestFLyrs() throws Exception { |
|
68 |
|
|
69 |
int lyr_count = 3; |
|
70 |
// testPersist(mc); |
|
71 |
FLyrVect[] lyr = new FLyrVect[lyr_count]; |
|
72 |
FeatureStore[] fs = new FeatureStore[lyr_count]; |
|
73 |
FLayers lyrs = new FLayers(); |
|
74 |
|
|
75 |
for (int i=0; i<lyr_count; i++) { |
|
76 |
fs[i] = new DummyFileFeatureStore("" + System.currentTimeMillis()); |
|
77 |
lyr[i] = createLayer(fs[i]); |
|
78 |
lyr[i].setName("Layer " + (i+System.currentTimeMillis())); |
|
79 |
lyr[i].setIsLabeled(false); |
|
80 |
try { lyr[i].setLegend(new DummyVectorLegend(TYPES.SOLID)); } catch (LegendLayerException e) { |
|
81 |
assertTrue("Error while creating legend: " + e.getMessage(), false); |
|
82 |
} |
|
83 |
lyrs.addLayer(lyr[i]); |
|
84 |
} |
|
85 |
|
|
86 |
for (int i=0; i<lyr_count; i++) { |
|
87 |
fs[i] = new DummyDBFeatureStore("" + System.currentTimeMillis()); |
|
88 |
lyr[i] = createLayer(fs[i]); |
|
89 |
lyr[i].setName("Layer " + (10000 + i + System.currentTimeMillis())); |
|
90 |
lyr[i].setIsLabeled(false); |
|
91 |
try { lyr[i].setLegend(new DummyVectorLegend(TYPES.SOLID)); } catch (LegendLayerException e) { |
|
92 |
assertTrue("Error while creating legend: " + e.getMessage(), false); |
|
93 |
} |
|
94 |
lyrs.addLayer(lyr[i]); |
|
95 |
} |
|
96 |
|
|
97 |
doTestPersist(lyrs); |
|
98 |
} |
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
private ViewPort getViewPort() { |
|
103 |
|
|
104 |
ViewPort vp = new ViewPort(CRSFactory.getCRS("EPSG:4326")); |
|
105 |
vp.setImageSize(new Dimension(640, 480)); |
|
106 |
Envelope env = new Envelope2D(0, 0, 1000000, 1000000); |
|
107 |
vp.setEnvelope(env); |
|
108 |
env = new Envelope2D(200000, 200000, 500000, 500000); |
|
109 |
vp.setEnvelope(env); |
|
110 |
env = new Envelope2D(300000, 300000, 300000, 300000); |
|
111 |
vp.setEnvelope(env); |
|
112 |
env = new Envelope2D(400000, 400000, 200000, 200000); |
|
113 |
vp.setEnvelope(env); |
|
114 |
env = new Envelope2D(440000, 440000, 100000, 100000); |
|
115 |
vp.setEnvelope(env); |
|
116 |
env = new Envelope2D(480000, 480000, 30000, 30000); |
|
117 |
vp.setEnvelope(env); |
|
118 |
vp.setBackColor(Color.YELLOW); |
|
119 |
vp.setClipRect(new Rectangle2D.Double(0, 0, 10, 10)); |
|
120 |
return vp; |
|
121 |
} |
|
122 |
|
|
123 |
private void addDummyLayers(MapContext mcon) throws Exception { |
|
124 |
|
|
125 |
FLayers resp = new FLayers(); |
|
126 |
resp.setMapContext(mcon); |
|
127 |
resp.setName("root layer"); |
|
128 |
|
|
129 |
FLayers aux = new FLayers(); |
|
130 |
aux.setMapContext(mcon); |
|
131 |
aux.setName("Group"); |
|
132 |
|
|
133 |
FLyrVect lyr = null; |
|
134 |
IVectorLegend lgn = null; |
|
135 |
FeatureStore fs = null; |
|
136 |
|
|
137 |
logger.debug("Adding dummy layers..."); |
|
138 |
|
|
139 |
fs = new DummyFileFeatureStore("1"); |
|
140 |
lyr = createLayer(fs); |
|
141 |
lyr.setName("Layer 1"); |
|
142 |
try { lyr.setLegend(new DummyVectorLegend(TYPES.SOLID)); } catch (LegendLayerException e) { } |
|
143 |
|
|
144 |
aux.addLayer(lyr); |
|
145 |
|
|
146 |
fs = new DummyDBFeatureStore("A"); |
|
147 |
lyr = createLayer(fs); |
|
148 |
lyr.setName("Layer A"); |
|
149 |
try { lyr.setLegend(new DummyVectorLegend(TYPES.SOLID)); } catch (LegendLayerException e) { } |
|
150 |
|
|
151 |
aux.addLayer(lyr); |
|
152 |
|
|
153 |
fs = new DummyFileFeatureStore("2"); |
|
154 |
lyr = createLayer(fs); |
|
155 |
lyr.setName("Layer 2"); |
|
156 |
try { lyr.setLegend(new DummyVectorLegend(TYPES.SOLID)); } catch (LegendLayerException e) { } |
|
157 |
|
|
158 |
aux.addLayer(lyr); |
|
159 |
|
|
160 |
fs = new DummyDBFeatureStore("B"); |
|
161 |
lyr = createLayer(fs); |
|
162 |
lyr.setName("Layer 1"); |
|
163 |
try { lyr.setLegend(new DummyVectorLegend(TYPES.SOLID)); } catch (LegendLayerException e) { } |
|
164 |
|
|
165 |
resp.addLayer(lyr); |
|
166 |
resp.addLayer(aux); |
|
167 |
|
|
168 |
mcon.getLayers().addLayer(resp); |
|
169 |
} |
|
170 |
|
|
171 |
private FLyrVect createLayer(FeatureStore fs) throws Exception { |
|
172 |
|
|
173 |
FLyrVect resp = new FLyrVect(); |
|
174 |
resp.setDataStore(fs); |
|
175 |
resp.wakeUp(); |
|
176 |
resp.load(); |
|
177 |
return resp; |
|
178 |
} |
|
179 |
|
|
180 |
private void doTestPersist(Persistent p) throws Exception { |
|
181 |
|
|
182 |
System.out.println("Starting persistence test for class: " + p.getClass().getName()); |
|
183 |
|
|
184 |
File perfile = getTempFile(); |
|
185 |
FileOutputStream fos = new FileOutputStream(perfile); |
|
186 |
System.out.println("Getting state for class: " + p.getClass().getName()); |
|
187 |
PersistentState pst = ToolsLocator.getPersistenceManager().getState(p); |
|
188 |
System.out.println("Saving state..."); |
|
189 |
|
|
190 |
System.out.println("Saving state..."); |
|
191 |
ToolsLocator.getPersistenceManager().saveState(pst, fos); |
|
192 |
System.out.println("Saving state... done."); |
|
193 |
|
|
194 |
fos.close(); |
|
195 |
|
|
196 |
// ============================================== |
|
197 |
// ============================================== |
|
198 |
System.out.println("Is now persisted: " + p.getClass().getName()); |
|
199 |
// ============================================== |
|
200 |
|
|
201 |
// if (true) return; |
|
202 |
|
|
203 |
System.out.println("Opening persistence file..."); |
|
204 |
FileInputStream fis = new FileInputStream(perfile); |
|
205 |
|
|
206 |
System.out.println("Loading state from file..."); |
|
207 |
pst = ToolsLocator.getPersistenceManager().loadState(fis); |
|
208 |
|
|
209 |
System.out.println("Instantiating " + p.getClass().getName() |
|
210 |
+ " from state, pst = " + pst); |
|
211 |
Object p2 = ToolsLocator.getPersistenceManager().create(pst); |
|
212 |
|
|
213 |
System.out.println("Comparing original and current..."); |
|
214 |
comparePersistent(p, p2); |
|
215 |
|
|
216 |
System.out.println("Successful mapcontext persistence test!"); |
|
217 |
|
|
218 |
} |
|
219 |
|
|
220 |
|
|
221 |
// FeatureStore, ILegend, ViewPort |
|
222 |
private void comparePersistent(Persistent p, Object p2) { |
|
223 |
|
|
224 |
if (p2.getClass().getName().compareTo(p.getClass().getName()) == 0) { |
|
225 |
|
|
226 |
if (p instanceof MapContext) { |
|
227 |
compareMapContexts((MapContext) p, (MapContext) p2); |
|
228 |
} else { |
|
229 |
if (p instanceof FLayer) { |
|
230 |
compareLayers((FLayer) p, (FLayer) p2); |
|
231 |
} else { |
|
232 |
if (p instanceof FeatureStore) { |
|
233 |
compareStore((FeatureStore) p, (FeatureStore) p2); |
|
234 |
} else { |
|
235 |
if (p instanceof ILegend) { |
|
236 |
compareLegend((ILegend) p, (ILegend) p2); |
|
237 |
} else { |
|
238 |
if (p instanceof ViewPort) { |
|
239 |
compareViewPorts((ViewPort) p, (ViewPort) p2); |
|
240 |
} else { |
|
241 |
fail("Did not compare: " + p.getClass().getName()); |
|
242 |
} |
|
243 |
} |
|
244 |
} |
|
245 |
} |
|
246 |
} |
|
247 |
} else { |
|
248 |
fail("Comparing different classes (?)"); |
|
249 |
} |
|
250 |
|
|
251 |
} |
|
252 |
|
|
253 |
private void compareMapContexts(MapContext m1, MapContext m2) { |
|
254 |
|
|
255 |
logger.debug("Getting viewports to compare..."); |
|
256 |
ViewPort vp1 = m1.getViewPort(); |
|
257 |
ViewPort vp2 = m2.getViewPort(); |
|
258 |
|
|
259 |
compareViewPorts(vp1, vp2); |
|
260 |
|
|
261 |
logger.debug("Getting root flayers to compare..."); |
|
262 |
FLayers lyr1 = m1.getLayers(); |
|
263 |
FLayers lyr2 = m2.getLayers(); |
|
264 |
compareLayers(lyr1, lyr2); |
|
265 |
} |
|
266 |
|
|
267 |
private void compareLayers(FLayer l1, FLayer l2) { |
|
268 |
|
|
269 |
logger.debug("Comparing layers..."); |
|
270 |
|
|
271 |
assertTrue("Layers of diff type!", l1.getClass().getName().compareTo(l2.getClass().getName()) == 0); |
Also available in: Unified diff