Revision 43434

View differences:

tags/org.gvsig.desktop-2.0.197/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.impl/src/main/java/org/gvsig/fmap/mapcontext/layers/order/impl/TrivialLayerOrderManager.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.layers.order.impl;
25

  
26
import org.gvsig.fmap.mapcontext.layers.FLayer;
27
import org.gvsig.fmap.mapcontext.layers.FLayers;
28
import org.gvsig.fmap.mapcontext.layers.order.LayerOrderManager;
29
import org.gvsig.i18n.Messages;
30
import org.gvsig.tools.ToolsLocator;
31
import org.gvsig.tools.dynobject.DynStruct;
32
import org.gvsig.tools.persistence.PersistenceManager;
33
import org.gvsig.tools.persistence.PersistentState;
34
import org.gvsig.tools.persistence.exception.PersistenceException;
35

  
36
public class TrivialLayerOrderManager implements LayerOrderManager {
37

  
38
	public static final String TRIVIAL_LAYER_ORDER_MANAGER_PERSISTENCE_NAME =
39
			"TRIVIAL_LAYER_ORDER_MANAGER_PERSISTENCE_NAME";
40

  
41
	public TrivialLayerOrderManager() {
42
		
43
	}
44
	
45
	public int getPosition(FLayers target, FLayer newLayer) {
46
		/*
47
		 * Always on top
48
		 */
49
		return target.getLayersCount();
50
	}
51

  
52
	public String getName() {
53
		return Messages.getText("_Default_order");
54
	}
55

  
56
	public String getDescription() {
57
		return Messages.getText("_Layers_are_placed_always_on_top");
58
	}
59

  
60
	public String getCode() {
61
		return this.getClass().getName();
62
	}
63
	
64
	public void loadFromState(PersistentState state) throws PersistenceException {
65
	}
66

  
67
	public void saveToState(PersistentState state) throws PersistenceException {
68
		state.set("name", this.getName());
69
	}
70
	
71
	public static void registerPersistent() {
72
		PersistenceManager manager = ToolsLocator.getPersistenceManager();
73
		if (manager.getDefinition(TRIVIAL_LAYER_ORDER_MANAGER_PERSISTENCE_NAME) == null) {
74
			DynStruct def = manager.addDefinition(
75
					TrivialLayerOrderManager.class,
76
					TRIVIAL_LAYER_ORDER_MANAGER_PERSISTENCE_NAME,
77
					TRIVIAL_LAYER_ORDER_MANAGER_PERSISTENCE_NAME +" Persistence definition",
78
					null, 
79
					null);
80
			def.addDynFieldString("name").setMandatory(true);
81
		}			
82
	}
83
	
84
	public Object clone() throws CloneNotSupportedException {
85
		return new TrivialLayerOrderManager();
86
	}
87

  
88
}
tags/org.gvsig.desktop-2.0.197/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.impl/src/main/java/org/gvsig/fmap/mapcontext/layers/order/impl/BasicLayerOrderLibrary.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
package org.gvsig.fmap.mapcontext.layers.order.impl;
26

  
27
import org.gvsig.fmap.mapcontext.MapContextLibrary;
28
import org.gvsig.fmap.mapcontext.MapContextLocator;
29
import org.gvsig.fmap.mapcontext.layers.order.LayerOrderManager;
30
import org.gvsig.i18n.Messages;
31
import org.gvsig.tools.library.AbstractLibrary;
32
import org.gvsig.tools.library.LibraryException;
33

  
34

  
35
/**
36
 * Registers the default implementation for {@link LayerOrderManager}
37
 * 
38
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
39
 */
40
public class BasicLayerOrderLibrary extends AbstractLibrary {
41

  
42
    public void doRegistration() {
43
        require(MapContextLibrary.class);
44
    }
45

  
46
    protected void doInitialize() throws LibraryException {
47
        Messages.addResourceFamily(
48
        		"org.gvsig.fmap.mapcontext.impl.i18n.text",
49
        		BasicLayerOrderLibrary.class.getClassLoader(),
50
        		BasicLayerOrderLibrary.class.getClass().getName());
51
        
52
    	TrivialLayerOrderManager.registerPersistent();
53
    	RasterPolLinePointOrderManager.registerPersistent();
54

  
55
        MapContextLocator.registerDefaultOrderManager(
56
    			TrivialLayerOrderManager.class);
57
    	MapContextLocator.registerOrderManager(
58
    			RasterPolLinePointOrderManager.class);
59
    }
60

  
61
    protected void doPostInitialize() throws LibraryException {  	
62

  
63
    }
64
}
tags/org.gvsig.desktop-2.0.197/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.impl/src/main/java/org/gvsig/fmap/mapcontext/layers/order/impl/RasterPolLinePointOrderManager.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.layers.order.impl;
25

  
26
import java.util.Map;
27

  
28
import org.gvsig.fmap.dal.exception.ReadException;
29
import org.gvsig.fmap.geom.Geometry;
30
import org.gvsig.fmap.geom.Geometry.TYPES;
31
import org.gvsig.fmap.geom.type.GeometryType;
32
import org.gvsig.fmap.mapcontext.layers.FLayer;
33
import org.gvsig.fmap.mapcontext.layers.FLayers;
34
import org.gvsig.fmap.mapcontext.layers.order.LayerOrderManager;
35
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
36
import org.gvsig.i18n.Messages;
37
import org.gvsig.tools.ToolsLocator;
38
import org.gvsig.tools.dynobject.DynStruct;
39
import org.gvsig.tools.persistence.PersistenceManager;
40
import org.gvsig.tools.persistence.PersistentState;
41
import org.gvsig.tools.persistence.exception.PersistenceException;
42
import org.slf4j.Logger;
43
import org.slf4j.LoggerFactory;
44

  
45

  
46
public class RasterPolLinePointOrderManager implements LayerOrderManager {
47

  
48
	public static final String RASTER_POLYGON_LINE_POINT_LAYER_ORDER_MANAGER_PERSISTENCE_NAME =
49
			"RASTER_POLYGON_LINE_POINT_LAYER_ORDER_MANAGER_PERSISTENCE_NAME";
50
	
51
	private static Logger logger =
52
		LoggerFactory.getLogger(RasterPolLinePointOrderManager.class);
53
	
54
	public RasterPolLinePointOrderManager() {
55
		
56
	}
57
	
58
	public int getPosition(FLayers target, FLayer newLayer) {
59
		
60
		int new_weight = 3;
61
		new_weight = getLayerWeight(newLayer);
62
		
63
		int len = target.getLayersCount();
64
		int item_w = 0;
65
		// from top to bottom,
66
		// look for a layer at
67
		// least as "heavy" as this one
68
		for (int i=(len-1); i>=0; i--) {
69
			item_w = getLayerWeight(target.getLayer(i));
70
			if (item_w >= new_weight) {
71
				return (i+1);
72
			}
73
		}
74
		// layer "falls" to bottom
75
		return 0;
76
	}
77

  
78
	public String getDescription() {
79
		return Messages.getText("_Raster_at_bottom_then_polygons_lines_points");
80
	}
81

  
82
	public String getName() {
83
		return Messages.getText("_Raster_Polygon_Line_Point_order_manager");
84
	}
85

  
86
	
87
	public String getCode() {
88
		return this.getClass().getName();
89
	}
90

  
91
	/**
92
	 * 
93
	 * @param lyr
94
	 * @return weight: point=0, line=1, polygon=2, other=3, raster=4
95
	 */
96
	private int getLayerWeight(FLayer lyr) {
97
		
98
		if (lyr.getClass().getName().toLowerCase().indexOf("raster") != -1) {
99
			return 4;
100
		} else {
101
			if (lyr instanceof FLyrVect) {
102
				FLyrVect lyrv = (FLyrVect) lyr;
103
				int type2d = Geometry.TYPES.SURFACE;
104
				try {
105
					type2d = simplifyType(lyrv.getGeometryType());
106
				} catch (ReadException e) {
107
					logger.error("While getting geo type.", e);
108
				}
109
				switch (type2d) {
110
				case TYPES.SURFACE:
111
					return 2;
112
				case TYPES.CURVE:
113
					return 1;
114
				case TYPES.POINT:
115
					return 0;
116
				default:
117
					// should not reach this
118
					return 3;
119
				}
120
			} else {
121
				// other:
122
				return 3;
123
			}
124
		}
125
		
126
	}
127

  
128
	/**
129
	 * 
130
	 */
131
	private int simplifyType(GeometryType gt) {
132

  
133
		if (gt.getType() == TYPES.POINT || gt.getType() == TYPES.MULTIPOINT) {
134
			return TYPES.POINT;
135
		} else {
136
			if (gt.isTypeOf(TYPES.CURVE) || gt.getType() == TYPES.MULTICURVE) {
137
				return TYPES.CURVE;
138
			} else {
139
				if (gt.isTypeOf(TYPES.SURFACE) || gt.getType() == TYPES.MULTISURFACE) {
140
					return TYPES.SURFACE;
141
				} else {
142
					// default
143
					return TYPES.SURFACE;
144
				}
145
			}
146
		}
147
	}
148

  
149
	public void loadFromState(PersistentState state) throws PersistenceException {
150
	}
151

  
152
	public void saveToState(PersistentState state) throws PersistenceException {
153
		state.set("name", this.getName());
154
	}
155
	
156
	public static void registerPersistent() {
157
		PersistenceManager manager = ToolsLocator.getPersistenceManager();
158
		if (manager.getDefinition(RASTER_POLYGON_LINE_POINT_LAYER_ORDER_MANAGER_PERSISTENCE_NAME) == null) {
159
			DynStruct def = manager.addDefinition(
160
					RasterPolLinePointOrderManager.class,
161
					RASTER_POLYGON_LINE_POINT_LAYER_ORDER_MANAGER_PERSISTENCE_NAME,
162
					RASTER_POLYGON_LINE_POINT_LAYER_ORDER_MANAGER_PERSISTENCE_NAME +" Persistence definition",
163
					null, 
164
					null);
165
			def.addDynFieldString("name").setMandatory(true);
166
		}			
167
	}
168
	
169
	public Object clone() throws CloneNotSupportedException {
170
		return new RasterPolLinePointOrderManager();
171
	}
172
	
173

  
174

  
175
}
tags/org.gvsig.desktop-2.0.197/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.impl/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.fmap.mapcontext.layers.order.impl.BasicLayerOrderLibrary
tags/org.gvsig.desktop-2.0.197/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.impl/src/main/resources/org/gvsig/fmap/mapcontext/impl/i18n/text.properties
1
_Raster_at_bottom_then_polygons_lines_points=Capas de im?genes en el fondo, despu?s pol?gonos, l?neas y puntos
2
_Raster_Polygon_Line_Point_order_manager=Orden Im?genes-Pol?gonos-L?neas-Puntos
3
_Default_order=Orden por defecto
4
_Layers_are_placed_always_on_top=Las capas se colocan siempre sobre las existentes
tags/org.gvsig.desktop-2.0.197/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.impl/src/main/resources/org/gvsig/fmap/mapcontext/impl/i18n/text_en.properties
1
_Raster_at_bottom_then_polygons_lines_points=Raster layers at bottom, then polygon, linear and point layers
2
_Raster_Polygon_Line_Point_order_manager=Raster-Polygon-Line-Point order
3
_Default_order=Default order
4
_Layers_are_placed_always_on_top=Layers are placed always on top
5

  
tags/org.gvsig.desktop-2.0.197/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.impl/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2

  
3
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4
  <modelVersion>4.0.0</modelVersion>
5
  <artifactId>org.gvsig.fmap.mapcontext.impl</artifactId>
6
  <packaging>jar</packaging>
7
  <name>${project.artifactId}</name>
8
  <parent>
9
      <groupId>org.gvsig</groupId>
10
      <artifactId>org.gvsig.fmap.mapcontext</artifactId>
11
      <version>2.0.197</version>
12
  </parent>
13
  
14
  <dependencies>
15
    <dependency>
16
      <groupId>org.gvsig</groupId>
17
      <artifactId>org.gvsig.fmap.mapcontext.api</artifactId>
18
      <scope>compile</scope>
19
    </dependency>
20
  </dependencies>
21
  
22
</project>
23

  
0 24

  
tags/org.gvsig.desktop-2.0.197/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2

  
3
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4
  <modelVersion>4.0.0</modelVersion>
5
  <artifactId>org.gvsig.fmap.mapcontext</artifactId>
6
  <packaging>pom</packaging>
7
  <name>${project.artifactId}</name>
8
  <parent>
9
      <groupId>org.gvsig</groupId>
10
      <artifactId>org.gvsig.desktop.compat.cdc</artifactId>
11
      <version>2.0.197</version>
12
  </parent>
13

  
14
  <modules>
15
      <module>org.gvsig.fmap.mapcontext.api</module>
16
      <module>org.gvsig.fmap.mapcontext.impl</module>
17
      <module>org.gvsig.fmap.mapcontext.operation</module>
18
  </modules>
19

  
20
  <description>This project contains the core of the map drawer of gvSIG.</description>
21
</project>
22

  
0 23

  
tags/org.gvsig.desktop-2.0.197/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/test/resources/log4j.xml
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!--
3

  
4
    gvSIG. Desktop Geographic Information System.
5

  
6
    Copyright (C) 2007-2013 gvSIG Association.
7

  
8
    This program is free software; you can redistribute it and/or
9
    modify it under the terms of the GNU General Public License
10
    as published by the Free Software Foundation; either version 3
11
    of the License, or (at your option) any later version.
12

  
13
    This program is distributed in the hope that it will be useful,
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
    GNU General Public License for more details.
17

  
18
    You should have received a copy of the GNU General Public License
19
    along with this program; if not, write to the Free Software
20
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
    MA  02110-1301, USA.
22

  
23
    For any additional information, do not hesitate to contact us
24
    at info AT gvsig.com, or visit our website www.gvsig.com.
25

  
26
-->
27
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
28

  
29
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
30

  
31
	<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
32
		<layout class="org.apache.log4j.PatternLayout">
33
			<param name="ConversionPattern" value="%d{HH:mm:ss,SSS} %-5p [%c{2}.%M()]\n  %m%n" />
34
		</layout>
35
	</appender>
36

  
37
	<category name="org.gvsig.tools">
38
		<priority value="DEBUG" />
39
	</category>
40
	<category name="org.gvsig.fmap.mapcontext">
41
		<priority value="DEBUG" /> 
42
	</category>
43

  
44
	<root>
45
		<priority value="INFO" />
46
		<appender-ref ref="CONSOLE" />
47
	</root>
48
</log4j:configuration>
0 49

  
tags/org.gvsig.desktop-2.0.197/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.197/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.197/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.197/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.197/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
 *
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.Font;
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 FontPersistenceFactory}.
40
 * 
41
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
42
 */
43
public class FontPersistenceFactoryTest extends AbstractLibraryAutoInitTestCase {
44

  
45
	private FontPersistenceFactory factory;
46
	private MockControl stateControl;
47
	private PersistentState state;
48
	private Font font;
49

  
50
	protected void doSetUp() throws Exception {
51
		PersistenceManager persistenceManager = ToolsLocator
52
				.getPersistenceManager();
53
		factory = (FontPersistenceFactory) persistenceManager.getFactories()
54
				.get(Font.class);
55
		stateControl = MockControl.createNiceControl(PersistentState.class);
56
		state = (PersistentState) stateControl.getMock();
57
		font = new Font("Arial", Font.BOLD, 18);
58
	}
59

  
60
	/**
61
	 * Test method for
62
	 * {@link org.gvsig.fmap.mapcontext.tools.persistence.FontPersistenceFactory#createFromState(org.gvsig.tools.persistence.PersistentState, java.lang.Class)}
63
	 * .
64
	 */
65
	public void testCreateFromState() throws Exception {
66
		stateControl.expectAndReturn(state
67
				.getString(FontPersistenceFactory.FIELD_NAME), font.getName());
68
		stateControl.expectAndReturn(state
69
				.getInt(FontPersistenceFactory.FIELD_STYLE), font.getStyle());
70
		stateControl.expectAndReturn(state
71
				.getInt(FontPersistenceFactory.FIELD_SIZE), font.getSize());
72
		stateControl.replay();
73

  
74
		Font newFont = (Font) factory.createFromState(state);
75
		assertTrue(newFont.equals(font));
76

  
77
		stateControl.verify();
78
	}
79

  
80
	/**
81
	 * Test method for
82
	 * {@link org.gvsig.fmap.mapcontext.tools.persistence.FontPersistenceFactory#saveToState(org.gvsig.tools.persistence.PersistentState, java.lang.Object)}
83
	 * .
84
	 */
85
	public void testSaveToState() throws Exception {
86
		state.set(FontPersistenceFactory.FIELD_NAME, font.getName());
87
		state.set(FontPersistenceFactory.FIELD_STYLE, font.getStyle());
88
		state.set(FontPersistenceFactory.FIELD_SIZE, font.getSize());
89
		stateControl.replay();
90

  
91
		factory.saveToState(state, font);
92

  
93
		stateControl.verify();
94
	}
95

  
96
}
0 97

  
tags/org.gvsig.desktop-2.0.197/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/test/java/org/gvsig/fmap/mapcontext/tools/persistence/Rectangle2DPersistenceFactoryTest.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.Rectangle2D;
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 Rectangle2DPersistenceFactory}.
40
 * 
41
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
42
 */
43
public class Rectangle2DPersistenceFactoryTest extends
44
		AbstractLibraryAutoInitTestCase {
45

  
46
	private Rectangle2DPersistenceFactory factory;
47
	private MockControl stateControl;
48
	private PersistentState state;
49
	private Rectangle2D rectangle;
50

  
51
	protected void doSetUp() throws Exception {
52
		PersistenceManager persistenceManager = ToolsLocator
53
				.getPersistenceManager();
54
		factory = (Rectangle2DPersistenceFactory) persistenceManager
55
				.getFactories().get(Rectangle2D.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
		rectangle = new Rectangle2D.Double(x, y, 320, 200);
61
	}
62

  
63
	/**
64
	 * Test method for
65
	 * {@link org.gvsig.fmap.mapcontext.tools.persistence.Rectangle2DPersistenceFactory#createFromState(PersistentState, Class)}
66
	 * .
67
	 */
68
	public void testCreateFromState() throws Exception {
69
		stateControl.expectAndReturn(state
70
				.getDouble(Rectangle2DPersistenceFactory.FIELD_X), rectangle
71
				.getX());
72
		stateControl.expectAndReturn(state
73
				.getDouble(Rectangle2DPersistenceFactory.FIELD_Y), rectangle
74
				.getY());
75
		stateControl.expectAndReturn(state
76
				.getDouble(Rectangle2DPersistenceFactory.FIELD_WIDTH),
77
				rectangle.getWidth());
78
		stateControl.expectAndReturn(state
79
				.getDouble(Rectangle2DPersistenceFactory.FIELD_HEIGHT),
80
				rectangle.getHeight());
81
		stateControl.replay();
82

  
83
		Rectangle2D newRectangle = (Rectangle2D) factory.createFromState(state);
84

  
85
		System.out.println("Orig x = " + rectangle.getX() + " - New x = "
86
				+ newRectangle.getX());
87
		assertEquals(rectangle.getX(), newRectangle.getX(), 0.0d);
88
		System.out.println("Orig y = " + rectangle.getY() + " - New y = "
89
				+ newRectangle.getY());
90
		assertEquals(rectangle.getY(), newRectangle.getY(), 0.0d);
91
		System.out.println("Orig width = " + rectangle.getWidth()
92
				+ " - New width = " + newRectangle.getWidth());
93
		assertEquals(rectangle.getWidth(), newRectangle.getWidth(), 0.0d);
94
		System.out.println("Orig height = " + rectangle.getHeight()
95
				+ " - New height = " + newRectangle.getHeight());
96
		assertEquals(rectangle.getHeight(), newRectangle.getHeight(), 0.0d);
97

  
98
		assertTrue(newRectangle.equals(rectangle));
99

  
100
		stateControl.verify();
101
	}
102

  
103
	/**
104
	 * Test method for
105
	 * {@link org.gvsig.fmap.mapcontext.tools.persistence.Rectangle2DPersistenceFactory#saveToState(org.gvsig.tools.persistence.PersistentState, java.lang.Object)}
106
	 * .
107
	 */
108
	public void testSaveToState() throws Exception {
109
		state.set(Rectangle2DPersistenceFactory.FIELD_X, rectangle.getX());
110
		state.set(Rectangle2DPersistenceFactory.FIELD_Y, rectangle.getY());
111
		state.set(Rectangle2DPersistenceFactory.FIELD_WIDTH, rectangle
112
				.getWidth());
113
		state.set(Rectangle2DPersistenceFactory.FIELD_HEIGHT, rectangle
114
				.getHeight());
115
		stateControl.replay();
116

  
117
		factory.saveToState(state, rectangle);
118

  
119
		stateControl.verify();
120
	}
121
}
0 122

  
tags/org.gvsig.desktop-2.0.197/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

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff