svn-gvsig-desktop / tags / Root_FMap_piloto_CAD_Layout_version / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / MemoryDriver.java @ 1664
History | View | Annotate | Download (6.46 KB)
1 |
/*
|
---|---|
2 |
* Created on 27-dic-2004
|
3 |
*
|
4 |
* TODO To change the template for this generated file go to
|
5 |
* Window - Preferences - Java - Code Generation - Code and Comments
|
6 |
*/
|
7 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
8 |
*
|
9 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
10 |
*
|
11 |
* This program is free software; you can redistribute it and/or
|
12 |
* modify it under the terms of the GNU General Public License
|
13 |
* as published by the Free Software Foundation; either version 2
|
14 |
* of the License, or (at your option) any later version.
|
15 |
*
|
16 |
* This program is distributed in the hope that it will be useful,
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19 |
* GNU General Public License for more details.
|
20 |
*
|
21 |
* You should have received a copy of the GNU General Public License
|
22 |
* along with this program; if not, write to the Free Software
|
23 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
24 |
*
|
25 |
* For more information, contact:
|
26 |
*
|
27 |
* Generalitat Valenciana
|
28 |
* Conselleria d'Infraestructures i Transport
|
29 |
* Av. Blasco Ib??ez, 50
|
30 |
* 46010 VALENCIA
|
31 |
* SPAIN
|
32 |
*
|
33 |
* +34 963862235
|
34 |
* gvsig@gva.es
|
35 |
* www.gvsig.gva.es
|
36 |
*
|
37 |
* or
|
38 |
*
|
39 |
* IVER T.I. S.A
|
40 |
* Salamanca 50
|
41 |
* 46005 Valencia
|
42 |
* Spain
|
43 |
*
|
44 |
* +34 963163400
|
45 |
* dac@iver.es
|
46 |
*/
|
47 |
package com.iver.cit.gvsig.fmap.drivers; |
48 |
|
49 |
import com.hardcode.gdbms.engine.data.DriverException; |
50 |
import com.hardcode.gdbms.engine.data.FileDriver; |
51 |
import com.hardcode.gdbms.engine.values.Value; |
52 |
|
53 |
import com.iver.cit.gvsig.fmap.core.FShape; |
54 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
55 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
56 |
import com.iver.cit.gvsig.fmap.operations.strategies.MemoryShapeInfo; |
57 |
|
58 |
import java.awt.geom.Rectangle2D; |
59 |
|
60 |
import java.io.File; |
61 |
import java.io.IOException; |
62 |
|
63 |
import java.util.ArrayList; |
64 |
|
65 |
import javax.swing.table.DefaultTableModel; |
66 |
|
67 |
|
68 |
/**
|
69 |
* Clase abstracta para Driver en memoria.
|
70 |
*
|
71 |
* @author FJP
|
72 |
*/
|
73 |
public abstract class MemoryDriver implements VectorialFileDriver, FileDriver, |
74 |
BoundedShapes { |
75 |
private MemoryShapeInfo memShapeInfo = new MemoryShapeInfo(); |
76 |
private ArrayList arrayGeometries = new ArrayList(); |
77 |
private Rectangle2D fullExtent; |
78 |
private int m_Position; |
79 |
private DefaultTableModel m_TableModel = new DefaultTableModel(); |
80 |
|
81 |
public void clearGeometryArray(){ |
82 |
arrayGeometries.clear(); |
83 |
} |
84 |
|
85 |
/**
|
86 |
* Devuelve el modelo de la tabla.
|
87 |
*
|
88 |
* @return modelo de la tabla.
|
89 |
*/
|
90 |
public DefaultTableModel getTableModel() { |
91 |
return m_TableModel;
|
92 |
} |
93 |
|
94 |
/**
|
95 |
* A?ade un shape.
|
96 |
*
|
97 |
* @param shp shape.
|
98 |
* @param row fila.
|
99 |
*/
|
100 |
public void addShape(FShape shp, Object[] row) { |
101 |
if (shp == null) { |
102 |
return; // No a?adimos nada |
103 |
} |
104 |
|
105 |
Rectangle2D boundsShp = shp.getBounds();
|
106 |
memShapeInfo.addShapeInfo(boundsShp, shp.getShapeType()); |
107 |
arrayGeometries.add(ShapeFactory.createGeometry(shp)); |
108 |
m_TableModel.addRow(row); |
109 |
|
110 |
try {
|
111 |
fullExtent = getFullExtent(); |
112 |
} catch (IOException e) { |
113 |
e.printStackTrace(); |
114 |
} |
115 |
|
116 |
if (fullExtent == null) { |
117 |
fullExtent = boundsShp; |
118 |
} else {
|
119 |
fullExtent.add(boundsShp); |
120 |
} |
121 |
|
122 |
m_Position++; |
123 |
} |
124 |
|
125 |
public void addGeometry(IGeometry g, Object[] row){ |
126 |
if (g == null) { |
127 |
return; // No a?adimos nada |
128 |
} |
129 |
|
130 |
Rectangle2D boundsShp = g.getBounds2D();
|
131 |
memShapeInfo.addShapeInfo(boundsShp, g.getGeometryType()); |
132 |
arrayGeometries.add(g); |
133 |
m_TableModel.addRow(row); |
134 |
|
135 |
try {
|
136 |
fullExtent = getFullExtent(); |
137 |
} catch (IOException e) { |
138 |
e.printStackTrace(); |
139 |
} |
140 |
|
141 |
if (fullExtent == null) { |
142 |
fullExtent = boundsShp; |
143 |
} else {
|
144 |
fullExtent.add(boundsShp); |
145 |
} |
146 |
|
147 |
m_Position++; |
148 |
} |
149 |
|
150 |
/**
|
151 |
* Devuelve el extent a partir de un ?ndice.
|
152 |
*
|
153 |
* @param index ?ndice.
|
154 |
*
|
155 |
* @return Extent.
|
156 |
*
|
157 |
* @throws IOException
|
158 |
*/
|
159 |
public Rectangle2D getShapeBounds(int index) throws IOException { |
160 |
return memShapeInfo.getBoundingBox(index);
|
161 |
} |
162 |
|
163 |
/**
|
164 |
* Devuelve el tipo del shape.
|
165 |
*
|
166 |
* @param index ?ndice.
|
167 |
*
|
168 |
* @return tipo del shape.
|
169 |
*/
|
170 |
public int getShapeType(int index) { |
171 |
return memShapeInfo.getType(index);
|
172 |
} |
173 |
|
174 |
/* (non-Javadoc)
|
175 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#open(java.io.File)
|
176 |
*/
|
177 |
public abstract void open(File f) throws IOException; |
178 |
|
179 |
/* (non-Javadoc)
|
180 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#close()
|
181 |
*/
|
182 |
public void close() throws IOException { |
183 |
// No hago nada, lo he abierto y cerrado en el inicialize de la clase hija
|
184 |
} |
185 |
|
186 |
/* (non-Javadoc)
|
187 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#getShape(int)
|
188 |
*/
|
189 |
public IGeometry getShape(int index) throws IOException { |
190 |
IGeometry geom = (IGeometry) arrayGeometries.get(index); |
191 |
|
192 |
return geom.cloneGeometry();
|
193 |
} |
194 |
|
195 |
/* (non-Javadoc)
|
196 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#getShapeCount()
|
197 |
*/
|
198 |
public int getShapeCount() throws IOException { |
199 |
return arrayGeometries.size();
|
200 |
} |
201 |
|
202 |
/* (non-Javadoc)
|
203 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#getFullExtent()
|
204 |
*/
|
205 |
public Rectangle2D getFullExtent() throws IOException { |
206 |
return fullExtent;
|
207 |
} |
208 |
|
209 |
/* (non-Javadoc)
|
210 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#initialize()
|
211 |
*/
|
212 |
public void initialize() throws IOException { |
213 |
} |
214 |
|
215 |
/* (non-Javadoc)
|
216 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#accept(java.io.File)
|
217 |
*/
|
218 |
public abstract boolean accept(File f); |
219 |
|
220 |
/* (non-Javadoc)
|
221 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getShapeType()
|
222 |
*/
|
223 |
public abstract int getShapeType(); |
224 |
|
225 |
/* (non-Javadoc)
|
226 |
* @see com.hardcode.driverManager.Driver#getName()
|
227 |
*/
|
228 |
public abstract String getName(); |
229 |
|
230 |
/* (non-Javadoc)
|
231 |
* @see com.hardcode.gdbms.engine.data.FileDriver#fileAccepted(java.io.File)
|
232 |
*/
|
233 |
public boolean fileAccepted(File f) { |
234 |
return false; |
235 |
} |
236 |
|
237 |
/* (non-Javadoc)
|
238 |
* @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldValue(long, int)
|
239 |
*/
|
240 |
public Value getFieldValue(long rowIndex, int fieldId) |
241 |
throws DriverException {
|
242 |
return (Value) m_TableModel.getValueAt((int) rowIndex, fieldId); |
243 |
} |
244 |
|
245 |
/* (non-Javadoc)
|
246 |
* @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldCount()
|
247 |
*/
|
248 |
public int getFieldCount() throws DriverException { |
249 |
return m_TableModel.getColumnCount();
|
250 |
} |
251 |
|
252 |
/* (non-Javadoc)
|
253 |
* @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldName(int)
|
254 |
*/
|
255 |
public String getFieldName(int fieldId) throws DriverException { |
256 |
return m_TableModel.getColumnName(fieldId);
|
257 |
} |
258 |
|
259 |
/* (non-Javadoc)
|
260 |
* @see com.hardcode.gdbms.engine.data.ReadDriver#getRowCount()
|
261 |
*/
|
262 |
public long getRowCount() throws DriverException { |
263 |
return arrayGeometries.size();
|
264 |
} |
265 |
} |