Revision 3513 branches/FMap_CAD/libraries/libFMap/src/com/iver/cit/gvsig/fmap/edition/prueba.java

View differences:

prueba.java
1 1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
2
*
3
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
*
19
* For more information, contact:
20
*
21
*  Generalitat Valenciana
22
*   Conselleria d'Infraestructures i Transport
23
*   Av. Blasco Ib??ez, 50
24
*   46010 VALENCIA
25
*   SPAIN
26
*
27
*      +34 963862235
28
*   gvsig@gva.es
29
*      www.gvsig.gva.es
30
*
31
*    or
32
*
33
*   IVER T.I. S.A
34
*   Salamanca 50
35
*   46005 Valencia
36
*   Spain
37
*
38
*   +34 963163400
39
*   dac@iver.es
40
*/
41 41
package com.iver.cit.gvsig.fmap.edition;
42 42

  
43
import java.io.File;
44
import java.io.IOException;
45
import java.util.BitSet;
46

  
47
import org.cresques.cts.IProjection;
48
import org.cresques.cts.ProjectionPool;
49

  
43 50
import com.hardcode.driverManager.Driver;
44 51
import com.hardcode.driverManager.DriverLoadException;
45 52
import com.hardcode.driverManager.DriverManager;
46

  
47 53
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException;
48

  
49 54
import com.iver.cit.gvsig.fmap.DriverException;
50 55
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
51 56
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
52 57
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver;
53 58
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver;
54 59
import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend;
60
import com.iver.cit.gvsig.fmap.layers.FBitSet;
55 61
import com.iver.cit.gvsig.fmap.layers.FLayer;
56 62
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
57 63
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
......
59 65
import com.iver.cit.gvsig.fmap.rendering.LegendFactory;
60 66
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
61 67

  
62
import org.cresques.cts.IProjection;
63
import org.cresques.cts.ProjectionPool;
64 68

  
65
import java.io.File;
66
import java.io.IOException;
67

  
68

  
69
/**
70
 * DOCUMENT ME!
71
 *
72
 * @author Fernando Gonz?lez Cort?s
73
 */
74 69
public class prueba {
75
	/**
76
	 * DOCUMENT ME!
77
	 *
78
	 * @param layerName DOCUMENT ME!
79
	 * @param d DOCUMENT ME!
80
	 * @param f DOCUMENT ME!
81
	 * @param proj DOCUMENT ME!
82
	 *
83
	 * @return DOCUMENT ME!
84
	 *
85
	 * @throws DriverException DOCUMENT ME!
86
	 */
87
	public FLayer createLayer(String layerName, VectorialFileDriver d, File f,
88
		IProjection proj) throws DriverException {
89
		//TODO Comprobar si hay un adaptador ya
90
		VectorialFileAdapter adapter = new VectorialFileAdapter(f);
91
		adapter.setDriver((VectorialDriver) d);
70
	
71
	public FLayer createLayer(String layerName, VectorialFileDriver d,
72
			File f, IProjection proj) throws DriverException {
73
			//TODO Comprobar si hay un adaptador ya
74
			VectorialFileAdapter adapter = new VectorialFileAdapter(f);
75
			adapter.setDriver((VectorialDriver) d);
76
			FileEditableFeatureSource fefs=new FileEditableFeatureSource((VectorialFileAdapter)adapter);
77
			MemoryExpansionFile mef=new MemoryExpansionFile();
78
			DefaultEditableFeatureSource defs=new DefaultEditableFeatureSource(mef,fefs, new FBitSet());
79
			try {
80
				defs.addGeometry(ShapeFactory.createPoint2D(1,3));
81
				defs.addGeometry(ShapeFactory.createPoint2D(2,2));
82
				defs.addGeometry(ShapeFactory.createPoint2D(3,1));
83
				defs.addGeometry(ShapeFactory.createPoint2D(4,0));
84
			} catch (DriverIOException e1) {
85
				e1.printStackTrace();
86
			} catch (IOException e1) {
87
				e1.printStackTrace();
88
			}
89
			FLyrVect capa = new FLyrVect();
90
			capa.setName(layerName);
92 91

  
93
		FileEditableFeatureSource fefs = new FileEditableFeatureSource((VectorialFileAdapter) adapter);
94
		MemoryExpansionFile mef = new MemoryExpansionFile();
95
		DefaultEditableFeatureSource defs = new DefaultEditableFeatureSource(mef,
96
				fefs);
97

  
98
		try {
99
			defs.addGeometry(ShapeFactory.createPoint2D(1, 3));
100
			defs.addGeometry(ShapeFactory.createPoint2D(2, 2));
101
			defs.addGeometry(ShapeFactory.createPoint2D(3, 1));
102
			defs.addGeometry(ShapeFactory.createPoint2D(4, 0));
103
		} catch (DriverIOException e1) {
104
			e1.printStackTrace();
105
		} catch (IOException e1) {
106
			e1.printStackTrace();
107
		}
108

  
109
		FLyrVect capa = new FLyrVect();
110
		capa.setName(layerName);
111

  
112
		//TODO Meter esto dentro de la comprobaci?n de si hay memoria
113
		if (false) {
114
		} else {
115
			capa.setSource(adapter);
116
			capa.setProjection(proj);
117
		}
118

  
119
		try {
120
			// Le asignamos tambi?n una legenda por defecto acorde con
121
			// el tipo de shape que tenga. Tampoco s? si es aqu? el
122
			// sitio adecuado, pero en fin....
123
			if (d instanceof WithDefaultLegend) {
124
				WithDefaultLegend aux = (WithDefaultLegend) d;
125
				adapter.start();
126
				capa.setLegend((VectorialLegend) aux.getDefaultLegend());
127
				adapter.stop();
92
			//TODO Meter esto dentro de la comprobaci?n de si hay memoria
93
			if (false) {
128 94
			} else {
129
				capa.setLegend(LegendFactory.createSingleSymbolLegend(
130
						capa.getShapeType()));
95
				capa.setSource(adapter);
96
				capa.setProjection(proj);
131 97
			}
132
		} catch (FieldNotFoundException e) {
133
			//Esta no puede saltar
134
		} catch (DriverIOException e) {
135
			throw new DriverException(e);
136
		}
137 98

  
138
		return capa;
139
	}
99
			try {
100
				// Le asignamos tambi?n una legenda por defecto acorde con
101
				// el tipo de shape que tenga. Tampoco s? si es aqu? el
102
				// sitio adecuado, pero en fin....
103
				if (d instanceof WithDefaultLegend) {
104
					WithDefaultLegend aux = (WithDefaultLegend) d;
105
					adapter.start();
106
					capa.setLegend((VectorialLegend) aux.getDefaultLegend());
107
					adapter.stop();
108
				} else {
109
					capa.setLegend(LegendFactory.createSingleSymbolLegend(
110
							capa.getShapeType()));
111
				}
112
			} catch (FieldNotFoundException e) {
113
				//Esta no puede saltar
114
			} catch (DriverIOException e) {
115
				throw new DriverException(e);
116
			}
140 117

  
141
	/**
142
	 * DOCUMENT ME!
143
	 *
144
	 * @param args DOCUMENT ME!
145
	 */
118
			return capa;
119
		}
146 120
	public static void main(String[] args) {
147 121
		DriverManager driverManager = new DriverManager();
148 122
		driverManager.loadDrivers(new File("../FMap 03/drivers"));
149

  
150
		prueba prueba = new prueba();
151
		FLayer layer = null;
152

  
123
		prueba prueba=new prueba();
124
		FLayer layer=null;
153 125
		try {
154
			layer = prueba.createLayer("prueba",
155
					(VectorialFileDriver) driverManager.getDriver(
156
						"gvSIG shp driver"),
157
					new File("c:/Layers/puntosPrueba.shp"),
158
					ProjectionPool.get("EPSG:23030"));
126
			layer=prueba.createLayer("prueba", (VectorialFileDriver)driverManager.getDriver("gvSIG shp driver"),new File("c:/Layers/puntosPrueba.shp"),ProjectionPool.get("EPSG:23030"));
159 127
		} catch (DriverException e) {
160 128
			e.printStackTrace();
161 129
		} catch (DriverLoadException e) {
162 130
			e.printStackTrace();
163 131
		}
132
		
164 133
	}
165 134
}

Also available in: Unified diff