Revision 42210

View differences:

tags/org.gvsig.desktop-2.0.99/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.99/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.99/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.99/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.99/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.99/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.99/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.99</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.99/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.99</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.99/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.fmap.mapcontext.MapContextLibrary
2
org.gvsig.fmap.mapcontext.impl.MapContextImplLibrary
tags/org.gvsig.desktop-2.0.99/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/main/java/org/gvsig/fmap/mapcontext/MapContextDrawer.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;
25

  
26
import java.awt.Graphics2D;
27
import java.awt.image.BufferedImage;
28

  
29
import org.gvsig.compat.print.PrintAttributes;
30
import org.gvsig.fmap.dal.exception.ReadException;
31
import org.gvsig.fmap.mapcontext.layers.FLayers;
32
import org.gvsig.tools.task.Cancellable;
33

  
34
public interface MapContextDrawer {
35

  
36
	public void setMapContext(MapContext mapContext);
37
	public void setViewPort(ViewPort viewPort);
38
	public void draw(FLayers root, BufferedImage image, Graphics2D g, Cancellable cancel,
39
			double scale) throws ReadException;
40
	public void print(FLayers root, Graphics2D g, Cancellable cancel,
41
			double scale, PrintAttributes properties) throws ReadException;
42
	public void dispose();
43
}
0 44

  
tags/org.gvsig.desktop-2.0.99/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/main/java/org/gvsig/fmap/mapcontext/ExtentHistory.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;
25

  
26
import java.awt.geom.Rectangle2D;
27

  
28
import org.gvsig.tools.ToolsLocator;
29
import org.gvsig.tools.dynobject.DynStruct;
30
import org.gvsig.tools.persistence.PersistenceManager;
31
import org.gvsig.tools.persistence.Persistent;
32
import org.gvsig.tools.persistence.PersistentState;
33
import org.gvsig.tools.persistence.exception.PersistenceException;
34
import org.gvsig.tools.util.Callable;
35

  
36

  
37
/**
38
 * <p>
39
 * <code>ExtentHistory</code> is designed for managing a history of extents.
40
 * </p>
41
 * <p>
42
 * Note: An <i>extent</i> is a rectangular area, with information of its
43
 * top-left 2D corner.
44
 * </p>
45
 *
46
 * @author Vicente Caballero Navarro
47
 */
48
public class ExtentHistory implements Persistent {
49

  
50
  private static final String FIELD_CURRENT_EXTENT = "current";
51
  private static final String FIELD_NUM_PREVIOUS = "num";
52
  private static final String FIELD_NUM_NEXT = "numnext";
53
  private static final String FIELD_NUM_RECORDS = "numrec";
54
  private static final String FIELD_PREVIOUS_EXTENTS = "extents";
55
  private static final String FIELD_NEXT_EXTENTS = "extentsNext";
56
  
57
  /**
58
   * <p>
59
   * Maximum number of extents that can store.
60
   * </p>
61
   */
62
  private int NUMREC;
63

  
64
  /**
65
   * <p>
66
   * Array with the previous extents.
67
   * </p>
68
   *
69
   * @see #hasPrevious()
70
   * @see #put(Rectangle2D)
71
   * @see #getPrev()
72
   * @see #popPrev()
73
   */
74
  private Rectangle2D[] extentsPrev;
75

  
76
  /**
77
   * <p>
78
   * Array with the next extents.
79
   * </p>
80
   *
81
   * @see #hasNext()
82
   * @see #putNext(Rectangle2D)
83
   * @see #getNext()
84
   * @see #popNext()
85
   */
86
  private Rectangle2D[] extentsNext;
87

  
88
  /**
89
   * <p>
90
   * The current extent of the viewport.
91
   * </p>
92
   */
93
  private Rectangle2D currentExtent;
94

  
95
  /**
96
   * <p>
97
   * Number of previous extents stored.
98
   * </p>
99
   *
100
   * @see #hasPrevious()
101
   * @see #put(Rectangle2D)
102
   * @see #getPrev()
103
   * @see #popPrev()
104
   */
105
  private int numPrev = 0;
106

  
107
  /**
108
   * <p>
109
   * Number of next extents stored.
110
   * </p>
111
   *
112
   * @see #hasNext()
113
   * @see #putNext(Rectangle2D)
114
   * @see #getNext()
115
   * @see #popNext()
116
   */
117
  private int numNext = 0;
118

  
119
  /**
120
   * <p>
121
   * Creates a new instance of <code>ExtentsHistory</code> with an history of 10
122
   * extents.
123
   * </p>
124
   */
125
  public ExtentHistory() {
126
    this(10);
127
  }
128

  
129
  /**
130
   * <p>
131
   * Creates a new instance of <code>ExtentsHistory</code> with an history of
132
   * <code>numEntries</code> extents.
133
   * </p>
134
   *
135
   * @param numEntries the maximum number of extents that will store the
136
   *          instance
137
   */
138
  public ExtentHistory(int numEntries) {
139
    NUMREC = numEntries;
140
    extentsPrev = new Rectangle2D[NUMREC];
141
    extentsNext = new Rectangle2D[NUMREC];
142
  }
143

  
144
  /**
145
   * <p>
146
   * Appends the specified extent at the end of the array of previous zooms.
147
   * </p>
148
   *
149
   * @param ext the new extent
150
   */
151
  public void put(Rectangle2D ext) {
152
    
153
    // Si al cargar de la persistencia currentExtent es null ViewPort nos dar? su extent
154
    if(currentExtent == null) {
155
      this.currentExtent = ext;
156
      return;
157
    }
158
    
159
    if ( !ext.equals(getPrev()) && !ext.equals(getNext()) ) {
160
      clearNumNext();
161
    }
162

  
163
    pushPrevious(currentExtent);
164

  
165
    this.currentExtent = ext;
166
  }
167

  
168
  /**
169
   * <p>
170
   * Returns <code>true</code> if there are previous extents registered.
171
   * </p>
172
   *
173
   * @return <code>true</code> if there are previous extents registered;
174
   *         <code>false</code> otherwise
175
   */
176
  public boolean hasPrevious() {
177
    return numPrev > 0;
178
  }
179

  
180
  /**
181
   * <p>
182
   * Returns <code>true</code> if there are next extents registered.
183
   * </p>
184
   *
185
   * @return <code>true</code> if there are next extents registered;
186
   *         <code>false</code> otherwise
187
   */
188
  public boolean hasNext() {
189
    return numNext > 0;
190
  }
191

  
192
  /**
193
   * <p>
194
   * Returns the last previous extent from the history.
195
   * </p>
196
   *
197
   * @return the last previous extent from the history
198
   */
199
  public Rectangle2D getPrev() {
200
    if (numPrev <= 0) {
201
      return null;
202
    }
203
    Rectangle2D ext = extentsPrev[numPrev - 1];
204

  
205
    return ext;
206
  }
207

  
208
  /**
209
   * <p>
210
   * Returns the last next extent from the history.
211
   * </p>
212
   *
213
   * @return the last next extent from the history
214
   */
215
  public Rectangle2D getNext() {
216
    if (numNext <= 0) {
217
      return null;
218
    }
219

  
220
    Rectangle2D ext = extentsNext[numNext - 1];
221
    return ext;
222
  }
223

  
224
  /**
225
   * <p>
226
   * Extracts (removing) the last previous extent from the history.
227
   * </p>
228
   *
229
   * @return last previous extent from the history
230
   */
231
  private Rectangle2D popPrev() {
232
    if (numPrev <= 0) {
233
      return null;
234
    }
235

  
236
    Rectangle2D ext = extentsPrev[--numPrev];
237
    return ext;
238
  }
239

  
240
  /**
241
   * <p>
242
   * Extracts (removing) the last next extent from the history.
243
   * </p>
244
   *
245
   * @return last next extent from the history
246
   */
247
  private Rectangle2D popNext() {
248
    if (numNext <= 0) {
249
      return null;
250
    }
251

  
252
    Rectangle2D ext = extentsNext[--numNext];
253
    return ext;
254
  }
255

  
256
  /**
257
   * <p>
258
   * Sets to zero the number of previous extents from the history.
259
   * </p>
260
   */
261
  private void clearNumPrev() {
262
    numPrev = 0;
263
  }
264

  
265
  /**
266
   * <p>
267
   * Sets to zero the number of next extents from the history.
268
   * </p>
269
   */
270
  private void clearNumNext() {
271
    numNext = 0;
272
  }
273

  
274
  /**
275
   * <p>
276
   * Adds the current extent to the next extent history and sets the last
277
   * previous extent as the new current extent.
278
   * </p>
279
   *
280
   * @return the last previous extent as the new current extent
281
   */
282
  public Rectangle2D setPreviousExtent() {
283
    
284
    if (currentExtent != null) {
285
      pushNext(currentExtent);
286
    }
287
    currentExtent = popPrev();
288
    return currentExtent;
289
  }
290
  
291
  /**
292
   * <p>
293
   * Adds the specified extent to the next extent history.
294
   * If the array of next extents is complete, loses the
295
   * first extent of the array and adds the new one at the end.
296
   * </p>
297
   *  
298
   */
299
  private void pushNext(Rectangle2D ext) {
300
    if (numNext < (NUMREC)) {
301
      extentsNext[numNext] = ext;
302
      numNext = numNext + 1;
303
    }
304
    else {
305
      for (int i = 0; i < (NUMREC - 1); i++) {
306
        extentsNext[i] = extentsNext[i + 1];
307
      }
308
      extentsNext[numNext - 1] = ext;
309
    }
310
  }
311

  
312
  /**
313
   * <p>
314
   * Adds the current extent to the previous extent history and sets the last
315
   * next extent as the new current extent.
316
   * </p>
317
   * 
318
   * @return the last next extent as the new current extent
319
   */
320
  public Rectangle2D setNextExtent() {
321

  
322
    if (currentExtent != null) {
323
      pushPrevious(currentExtent);
324
      
325
    }
326
    currentExtent = popNext();
327
    return currentExtent;
328
  }
329

  
330
  /**
331
   * <p>
332
   * Adds the specified extent to the previous extent history.
333
   * If the array of previous extents is complete, loses the
334
   * first extent of the array and adds the new one at the end.
335
   * </p>
336
   *  
337
   */
338
  private void pushPrevious(Rectangle2D ext) {
339
    if (numPrev < (NUMREC)) {
340
      extentsPrev[numPrev] = ext;
341
      numPrev++;
342
    } else {
343
      for (int i = 0; i < (NUMREC - 1); i++) {
344
        extentsPrev[i] = extentsPrev[i + 1];
345
      }
346
      extentsPrev[numPrev - 1] = ext;
347
    }
348
  }
349
  
350
  /**
351
   * <p>
352
   * Returns the current extent.
353
   * </p>
354
   *  
355
   * @return the current extent
356
   */
357
  public Rectangle2D getCurrent() {
358
    return currentExtent;
359
  }
360

  
361
  public void loadFromState(PersistentState state) throws PersistenceException {
362

  
363
    if (state.hasValue("num")) {
364
      numPrev = state.getInt("num");
365
    }
366
    else {
367
      clearNumPrev();
368
    }
369

  
370
    if (state.hasValue("numnext")) {
371
      numNext = state.getInt("numnext");
372
    }
373
    else {
374
      clearNumNext();
375
    }
376

  
377
    if (state.hasValue("numrec")) {
378
      NUMREC = state.getInt("numrec");
379
    }
380
    else {
381
      NUMREC = 10;
382
    }
383

  
384
    if (state.hasValue("extents")) {
385
      extentsPrev = (Rectangle2D[]) state
386
          .getArray("extents", Rectangle2D.class);
387
    }
388
    else {
389
      extentsPrev = new Rectangle2D[NUMREC];
390
      clearNumPrev();
391
    }
392

  
393
    if (state.hasValue("extentsNext")) {
394
      extentsNext = (Rectangle2D[]) state.getArray("extentsNext",
395
          Rectangle2D.class);
396
    }
397
    else {
398
      extentsNext = new Rectangle2D[NUMREC];
399
      clearNumNext();
400
    }
401
    
402
    if (state.hasValue("current")) {
403
      currentExtent = (Rectangle2D) state.get("current");
404
    }
405
    else {
406
      currentExtent = null;
407
    }
408
  }
409

  
410
  /**
411
   * <p>
412
   * Returns information of this object. All information is stored as
413
   * properties:<br>
414
   * </p>
415
   * <p>
416
   * <b>Properties:</b>
417
   * <ul>
418
   * <li><i>className</i>: name of this class.
419
   * <li><i>num</i>: number of extents registered.
420
   * <li><i>numrec</i>: maximum number of extents that can register.
421
   * <li><i>extents</i>: .
422
   * </ul>
423
   * </p>
424
   */
425
  public void saveToState(PersistentState state) throws PersistenceException {
426

  
427
    state.set(FIELD_NUM_PREVIOUS, numPrev);
428
    state.set(FIELD_NUM_NEXT, numNext);
429
    state.set(FIELD_NUM_RECORDS, NUMREC);
430
    state.set(FIELD_PREVIOUS_EXTENTS, extentsPrev);
431
    state.set(FIELD_NEXT_EXTENTS, extentsNext);
432
    state.set(FIELD_CURRENT_EXTENT, currentExtent);
433
  }
434

  
435
  public static class RegisterPersistence implements Callable {
436

  
437
    public Object call() {
438
      PersistenceManager manager = ToolsLocator.getPersistenceManager();
439
      DynStruct definition = manager.addDefinition(ExtentHistory.class,
440
          "ExtentHistory", "ExtentHistory Persistence definition", null, null);
441
      definition.addDynFieldInt(FIELD_NUM_PREVIOUS).setMandatory(true);
442
      definition.addDynFieldInt(FIELD_NUM_NEXT).setMandatory(true);
443
      definition.addDynFieldInt(FIELD_NUM_RECORDS).setMandatory(true);
444
      definition.addDynFieldArray(FIELD_PREVIOUS_EXTENTS).setClassOfItems(Rectangle2D.class)
445
          .setMandatory(true);
446
      definition.addDynFieldArray(FIELD_NEXT_EXTENTS)
447
          .setClassOfItems(Rectangle2D.class).setMandatory(true);
448
      definition.addDynFieldObject(FIELD_CURRENT_EXTENT)
449
      .setClassOfValue(Rectangle2D.class).setMandatory(false);
450

  
451
      return Boolean.TRUE;
452
    }
453
  }
454
}
0 455

  
tags/org.gvsig.desktop-2.0.99/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/main/java/org/gvsig/fmap/mapcontext/rendering/strategies/MemoryShapeInfo.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.strategies;
25

  
26
import java.awt.geom.Rectangle2D;
27
import java.util.ArrayList;
28

  
29

  
30

  
31
/**
32
 * Estructura de datos con la informaci?n relativa a las geometr?as de una
33
 * fuente de datos necesaria para acelerar el procesado de la capa en memoria.
34
 *
35
 * @author Vicente Caballero Navarro
36
 */
37
public class MemoryShapeInfo implements ShapeInfo {
38
	ArrayList infos = new ArrayList();
39

  
40
	/**
41
	 * @see org.gvsig.fmap.mapcontext.rendering.strategies.ShapeInfo#addShapeInfo(java.awt.geom.Rectangle2D,
42
	 * 		int)
43
	 */
44
	public void addShapeInfo(Rectangle2D boundingBox, int type) {
45
		infos.add(new Info(boundingBox, type));
46
	}
47

  
48
	/**
49
	 * @see org.gvsig.fmap.mapcontext.rendering.strategies.ShapeInfo#addShapeInfo(int,
50
	 * 		java.awt.geom.Rectangle2D, int)
51
	 */
52
	public void setShapeInfo(int index, Rectangle2D boundingBox, int type)
53
		throws ArrayIndexOutOfBoundsException {
54
		infos.set(index, new Info(boundingBox, type));
55
	}
56

  
57
	/**
58
	 * @see org.gvsig.fmap.mapcontext.rendering.strategies.ShapeInfo#getBoundingBox(int)
59
	 */
60
	public Rectangle2D getBoundingBox(int index) {
61
		return ((Info) infos.get(index)).getRect();
62
	}
63

  
64
	/**
65
	 * @see org.gvsig.fmap.mapcontext.rendering.strategies.ShapeInfo#getType(int)
66
	 */
67
	public int getType(int index) {
68
		return ((Info) infos.get(index)).getType();
69
	}
70

  
71
	/**
72
	 * Clase con el rect?ngulo y el tipo de shape.
73
	 *
74
	 * @author Vicente Caballero Navarro
75
	 */
76
	class Info {
77
		private Rectangle2D rect;
78
		private int type;
79

  
80
		/**
81
		 * Crea un nuevo Info.
82
		 *
83
		 * @param rect Extent del shape.
84
		 * @param type Tipo de shape.
85
		 */
86
		public Info(Rectangle2D rect, int type) {
87
			this.rect = rect;
88
			this.type = type;
89
		}
90

  
91
		/**
92
		 * Devuelve el extent del shape.
93
		 *
94
		 * @return Extent del shape.
95
		 */
96
		public Rectangle2D getRect() {
97
			return rect;
98
		}
99

  
100
		/**
101
		 * Devuelve el tipo de shape.
102
		 *
103
		 * @return Tipo de shape.
104
		 */
105
		public int getType() {
106
			return type;
107
		}
108
	}
109
}
0 110

  
tags/org.gvsig.desktop-2.0.99/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/main/java/org/gvsig/fmap/mapcontext/rendering/strategies/SelectedEnvelopeVisitor.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.strategies;
25

  
26
import org.cresques.cts.ICoordTrans;
27
import org.slf4j.Logger;
28
import org.slf4j.LoggerFactory;
29

  
30
import org.gvsig.fmap.dal.DataSet;
31
import org.gvsig.fmap.dal.feature.Feature;
32
import org.gvsig.fmap.dal.feature.FeatureSelection;
33
import org.gvsig.fmap.geom.primitive.Envelope;
34
import org.gvsig.fmap.mapcontext.layers.FLayer;
35
import org.gvsig.fmap.mapcontext.layers.operations.LayersVisitor;
36
import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer;
37
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
38
import org.gvsig.tools.dispose.DisposableIterator;
39
import org.gvsig.tools.exception.BaseException;
40
import org.gvsig.tools.visitor.NotSupportedOperationException;
41

  
42
/**
43
 * This visitor accumulates the envelope of the
44
 * selected geometries
45
 */
46
public class SelectedEnvelopeVisitor implements LayersVisitor {
47
    
48
    private static final Logger logger =
49
        LoggerFactory.getLogger(SelectedEnvelopeVisitor.class);
50
    
51
	private Envelope rectangle = null;
52
	public Envelope getSelectioEnvelope() {
53
	    return rectangle;
54
	}
55

  
56
	public String getProcessDescription() {
57
		return "Defining rectangle to zoom from selected geometries";
58
	}
59

  
60
	public void visit(Object obj) throws BaseException {
61
		if (obj instanceof FLayer) {
62
			this.visit((FLayer) obj);
63
		} else {
64
		    throw new NotSupportedOperationException(this, obj);
65
		}
66
	}
67

  
68
	public void visit(FLayer layer) throws BaseException {
69
	    
70
		if (!(layer instanceof SingleLayer)) {
71
			return;
72
		} else if (!layer.isActive()) {
73
			return;
74
        } else if (!(layer instanceof FLyrVect)) {
75
            return;
76
        }
77
		
78
		FLyrVect lyr_vect = (FLyrVect) layer;
79
		BaseException be = null;
80
		
81
		DataSet selection = ((SingleLayer) layer).getDataStore()
82
				.getSelection();
83
		
84
		if (selection != null && (selection instanceof FeatureSelection)) {
85
		    
86
		    long tot_count = lyr_vect.getFeatureStore().getFeatureCount();
87
		    FeatureSelection fsel = (FeatureSelection) selection;
88
		    long sel_count = fsel.getSize();
89
		    if (tot_count == sel_count) {
90
		        try {
91
		            /*
92
		             * If all selected, use layer envelope
93
		             */
94
		            rectangle = accum(rectangle, lyr_vect.getFullEnvelope(), null);
95
		        } catch (CloneNotSupportedException ex) {
96
                    /*
97
                     * This should not happen because
98
                     * envelopes support clone 
99
                     */
100
		            logger.debug("Error while adding envelope: " + ex.getMessage(), ex);
101
		        }
102
		    } else {
103
		        
104
		        /*
105
		         * We'll use this reprojection if not null
106
		         * to convert feature envelopes
107
		         */
108
		        ICoordTrans ct = lyr_vect.getCoordTrans();
109
		        
110
		        DisposableIterator iter = fsel.fastIterator();
111
		        Feature feat = null;
112
		        while (iter.hasNext()) {
113
		            feat = (Feature) iter.next();
114
		            try {
115
	                    rectangle = accum(
116
	                        rectangle, feat.getDefaultEnvelope(), ct);
117
		            } catch (CloneNotSupportedException ex) {
118
	                    /*
119
	                     * This should not happen because
120
	                     * envelopes support clone 
121
	                     */
122
	                    logger.debug("Error while adding envelope: " + ex.getMessage(), ex);
123
	                    break;
124
		            }
125
		        }
126
		        iter.dispose();
127
		    }
128
		}
129
	}
130

  
131
	/**
132
	 * Adds add_env envelope to ini_env after reprojecting add_env
133
	 * if cotr not null
134
	 * 
135
	 * @param ini_env
136
	 * @param add_env
137
	 * @param cotr
138
	 * @return
139
	 */
140
    private Envelope accum(
141
        Envelope ini_env,
142
        Envelope add_env,
143
        ICoordTrans cotr) throws CloneNotSupportedException {
144
        
145
        if (add_env == null) {
146
            /*
147
             * Nothing to add
148
             */
149
            return ini_env;
150
        } else {
151
            
152
            if (cotr == null) {
153
                
154
                /*
155
                 * No reprojection needed
156
                 */
157
                if (ini_env == null) {
158
                    return add_env;
159
                } else {
160
                    Envelope resp = (Envelope) ini_env.clone(); 
161
                    resp.add(add_env);
162
                    return resp;
163
                }
164
                
165
            } else {
166
                
167
                /*
168
                 * Reproject before adding
169
                 */
170
                Envelope add_rep = (Envelope) add_env.convert(cotr).clone();
171
                if (ini_env == null) {
172
                    /*
173
                     * Initial was null
174
                     */
175
                    return add_rep;
176
                } else {
177
                    Envelope resp = (Envelope) ini_env.clone(); 
178
                    resp.add(add_rep);
179
                    return resp;
180
                }
181
            }
182
        }
183
    }
184

  
185

  
186
}
0 187

  
tags/org.gvsig.desktop-2.0.99/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/main/java/org/gvsig/fmap/mapcontext/rendering/strategies/ShapeInfo.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.strategies;
25

  
26
import java.awt.geom.Rectangle2D;
27

  
28

  
29
/**
30
 * Estructura de datos con la informaci?n relativa a las geometr?as de una
31
 * fuente de datos necesaria para acelerar el procesado de la capa
32
 */
33
public interface ShapeInfo {
34
	/**
35
	 * A?ade al final de la estructura de datos la informaci?n de una geometr?a
36
	 *
37
	 * @param boundingBox Extent del shape.
38
	 * @param type Tipo de shape.
39
	 */
40
	void addShapeInfo(Rectangle2D boundingBox, int type);
41

  
42
	/**
43
	 * Establece en la posici?n index-?sima de la estructura de datos la
44
	 * informaci?n de una geometr?a
45
	 *
46
	 * @param index ?ndice.
47
	 * @param boundingBox Extent del shape.
48
	 * @param type Tipo de shape.
49
	 *
50
	 * @throws ArrayIndexOutOfBoundsException Si se intenta establecer la
51
	 * 		   informaci?n para una geometr?a que no existe
52
	 */
53
	void setShapeInfo(int index, Rectangle2D boundingBox, int type)
54
		throws ArrayIndexOutOfBoundsException;
55

  
56
	/**
57
	 * Obtiene el bounding box de la geometr?a index-?sima
58
	 *
59
	 * @param index ?ndice de la geometr?a.
60
	 *
61
	 * @return Extent de la geometr?a.
62
	 */
63
	Rectangle2D getBoundingBox(int index);
64

  
65
	/**
66
	 * Obtiene el tipo de la geometr?a index-?sima
67
	 *
68
	 * @param index ?ndice.
69
	 *
70
	 * @return Tipo de geometr?a.
71
	 */
72
	int getType(int index);
73
}
0 74

  
tags/org.gvsig.desktop-2.0.99/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/main/java/org/gvsig/fmap/mapcontext/rendering/strategies/SelectedZoomVisitor.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.strategies;
25

  
26
import org.gvsig.fmap.dal.DataSet;
27
import org.gvsig.fmap.dal.feature.Feature;
28
import org.gvsig.fmap.dal.feature.FeatureReference;
29
import org.gvsig.fmap.geom.primitive.Envelope;
30
import org.gvsig.fmap.mapcontext.layers.FLayer;
31
import org.gvsig.fmap.mapcontext.layers.operations.LayersVisitor;
32
import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer;
33
import org.gvsig.tools.exception.BaseException;
34
import org.gvsig.tools.visitor.NotSupportedOperationException;
35
import org.gvsig.tools.visitor.Visitable;
36
import org.gvsig.tools.visitor.Visitor;
37

  
38

  
39
/**
40
 * Visitor de zoom a lo seleccionado.
41
 *
42
 * @author Vicente Caballero Navarro
43
 */
44
public class SelectedZoomVisitor implements LayersVisitor, Visitor {
45
	private Envelope rectangle = null;
46

  
47
	/**
48
	 * Devuelve el Extent de los shapes seleccionados, y si no hay ning?n shape
49
	 * seleccionado devuelve null.
50
	 *
51
	 * @return Extent de los shapes seleccionados.
52
	 */
53
	public Envelope getSelectBound() {
54
		return rectangle;
55
	}
56

  
57
	public String getProcessDescription() {
58
		return "Defining rectangle to zoom from selected geometries";
59
	}
60

  
61
	public void visit(Feature feature) throws BaseException {
62
		if (rectangle == null) {
63
			rectangle = (feature.getDefaultGeometry()).getEnvelope();
64
		} else {
65
			rectangle.add((feature.getDefaultGeometry())
66
					.getEnvelope());
67
		}
68
	}
69

  
70
	public void visit(FeatureReference featureRefence) throws BaseException {
71
		this.visit(featureRefence.getFeature());
72
	}
73

  
74
	public void visit(Object obj) throws BaseException {
75
		if (obj instanceof FeatureReference) {
76
			this.visit((FeatureReference) obj);
77
			return;
78
		}
79
		if (obj instanceof Feature) {
80
			this.visit((Feature) obj);
81
			return;
82
		}
83
		if (obj instanceof FLayer) {
84
			this.visit((FLayer) obj);
85
			return;
86
		}
87

  
88
		throw new NotSupportedOperationException(this, obj);
89
	}
90

  
91
	public void visit(FLayer layer) throws BaseException {
92
		if (!(layer instanceof SingleLayer)) {
93
			return;
94
		} else if (!layer.isActive()) {
95
			return;
96
		}
97
		DataSet selection = ((SingleLayer) layer).getDataStore()
98
				.getSelection();
99

  
100
		if (selection instanceof Visitable) {
101
			((Visitable) selection).accept(this);
102
		}
103
	}
104

  
105

  
106
}
0 107

  
tags/org.gvsig.desktop-2.0.99/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/main/java/org/gvsig/fmap/mapcontext/rendering/legend/events/LegendClearEvent.java
1
/**
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff