root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / MemoryDriver.java @ 2720
History | View | Annotate | Download (6.78 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 java.awt.geom.Rectangle2D; |
50 |
import java.io.File; |
51 |
import java.io.IOException; |
52 |
import java.sql.Types; |
53 |
import java.util.ArrayList; |
54 |
import java.util.Date; |
55 |
|
56 |
import javax.swing.table.DefaultTableModel; |
57 |
|
58 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
59 |
import com.hardcode.gdbms.engine.data.driver.ObjectDriver; |
60 |
import com.hardcode.gdbms.engine.values.Value; |
61 |
import com.iver.cit.gvsig.fmap.core.FShape; |
62 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
63 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
64 |
import com.iver.cit.gvsig.fmap.operations.strategies.MemoryShapeInfo; |
65 |
|
66 |
|
67 |
/**
|
68 |
* Clase abstracta para Driver en memoria.
|
69 |
*
|
70 |
* @author FJP
|
71 |
*/
|
72 |
public abstract class MemoryDriver implements VectorialFileDriver, ObjectDriver, |
73 |
BoundedShapes { |
74 |
private MemoryShapeInfo memShapeInfo = new MemoryShapeInfo(); |
75 |
private ArrayList arrayGeometries = new ArrayList(); |
76 |
private Rectangle2D fullExtent; |
77 |
private int m_Position; |
78 |
private DefaultTableModel m_TableModel = new DefaultTableModel(); |
79 |
|
80 |
/**
|
81 |
* Devuelve el modelo de la tabla.
|
82 |
*
|
83 |
* @return modelo de la tabla.
|
84 |
*/
|
85 |
public DefaultTableModel getTableModel() { |
86 |
return m_TableModel;
|
87 |
} |
88 |
|
89 |
/**
|
90 |
* A?ade un shape.
|
91 |
*
|
92 |
* @param shp shape.
|
93 |
* @param row fila.
|
94 |
*/
|
95 |
public void addShape(FShape shp, Object[] row) { |
96 |
if (shp == null) { |
97 |
return; // No a?adimos nada |
98 |
} |
99 |
|
100 |
Rectangle2D boundsShp = shp.getBounds();
|
101 |
memShapeInfo.addShapeInfo(boundsShp, shp.getShapeType()); |
102 |
arrayGeometries.add(ShapeFactory.createGeometry(shp)); |
103 |
m_TableModel.addRow(row); |
104 |
|
105 |
try {
|
106 |
fullExtent = getFullExtent(); |
107 |
} catch (IOException e) { |
108 |
e.printStackTrace(); |
109 |
} |
110 |
|
111 |
if (fullExtent == null) { |
112 |
fullExtent = boundsShp; |
113 |
} else {
|
114 |
fullExtent.add(boundsShp); |
115 |
} |
116 |
|
117 |
m_Position++; |
118 |
} |
119 |
|
120 |
/**
|
121 |
* Devuelve el extent a partir de un ?ndice.
|
122 |
*
|
123 |
* @param index ?ndice.
|
124 |
*
|
125 |
* @return Extent.
|
126 |
*
|
127 |
* @throws IOException
|
128 |
*/
|
129 |
public Rectangle2D getShapeBounds(int index) throws IOException { |
130 |
return memShapeInfo.getBoundingBox(index);
|
131 |
} |
132 |
|
133 |
/**
|
134 |
* Devuelve el tipo del shape.
|
135 |
*
|
136 |
* @param index ?ndice.
|
137 |
*
|
138 |
* @return tipo del shape.
|
139 |
*/
|
140 |
public int getShapeType(int index) { |
141 |
return memShapeInfo.getType(index);
|
142 |
} |
143 |
|
144 |
/* (non-Javadoc)
|
145 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#open(java.io.File)
|
146 |
*/
|
147 |
public abstract void open(File f) throws IOException; |
148 |
|
149 |
/* (non-Javadoc)
|
150 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#close()
|
151 |
*/
|
152 |
public void close() throws IOException { |
153 |
// No hago nada, lo he abierto y cerrado en el inicialize de la clase hija
|
154 |
} |
155 |
|
156 |
/* (non-Javadoc)
|
157 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#getShape(int)
|
158 |
*/
|
159 |
public IGeometry getShape(int index) throws IOException { |
160 |
IGeometry geom = (IGeometry) arrayGeometries.get(index); |
161 |
|
162 |
return geom.cloneGeometry();
|
163 |
} |
164 |
|
165 |
/* (non-Javadoc)
|
166 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#getShapeCount()
|
167 |
*/
|
168 |
public int getShapeCount() throws IOException { |
169 |
return arrayGeometries.size();
|
170 |
} |
171 |
|
172 |
/* (non-Javadoc)
|
173 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#getFullExtent()
|
174 |
*/
|
175 |
public Rectangle2D getFullExtent() throws IOException { |
176 |
return fullExtent;
|
177 |
} |
178 |
|
179 |
/* (non-Javadoc)
|
180 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#initialize()
|
181 |
*/
|
182 |
public void initialize() throws IOException { |
183 |
} |
184 |
|
185 |
/* (non-Javadoc)
|
186 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#accept(java.io.File)
|
187 |
*/
|
188 |
public abstract boolean accept(File f); |
189 |
|
190 |
/* (non-Javadoc)
|
191 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getShapeType()
|
192 |
*/
|
193 |
public abstract int getShapeType(); |
194 |
|
195 |
/* (non-Javadoc)
|
196 |
* @see com.hardcode.driverManager.Driver#getName()
|
197 |
*/
|
198 |
public abstract String getName(); |
199 |
|
200 |
/**
|
201 |
* @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldType(int)
|
202 |
*/
|
203 |
public int getFieldType(int i) throws DriverException { |
204 |
// TODO: Revisar esto. Por ejemplo, el long
|
205 |
|
206 |
if (m_TableModel.getColumnClass(i) == String.class) |
207 |
return Types.VARCHAR; |
208 |
if (m_TableModel.getColumnClass(i) == Float.class) |
209 |
return Types.FLOAT; |
210 |
if (m_TableModel.getColumnClass(i) == Double.class) |
211 |
return Types.DOUBLE; |
212 |
if (m_TableModel.getColumnClass(i) == Integer.class) |
213 |
return Types.INTEGER; |
214 |
if (m_TableModel.getColumnClass(i) == Long.class) |
215 |
return Types.INTEGER; |
216 |
if (m_TableModel.getColumnClass(i) == Boolean.class) |
217 |
return Types.BIT; |
218 |
if (m_TableModel.getColumnClass(i) == Date.class) |
219 |
return Types.DATE; |
220 |
|
221 |
return Types.VARCHAR; |
222 |
// return m_TableModel.getColumnClass(i);
|
223 |
// throw new DriverException("Tipo no soportado: " + m_TableModel.getColumnClass(i).getName());
|
224 |
} |
225 |
/* (non-Javadoc)
|
226 |
* @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldValue(long, int)
|
227 |
*/
|
228 |
public Value getFieldValue(long rowIndex, int fieldId) |
229 |
throws DriverException {
|
230 |
return (Value) m_TableModel.getValueAt((int) rowIndex, fieldId); |
231 |
} |
232 |
|
233 |
/* (non-Javadoc)
|
234 |
* @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldCount()
|
235 |
*/
|
236 |
public int getFieldCount() throws DriverException { |
237 |
return m_TableModel.getColumnCount();
|
238 |
} |
239 |
|
240 |
/* (non-Javadoc)
|
241 |
* @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldName(int)
|
242 |
*/
|
243 |
public String getFieldName(int fieldId) throws DriverException { |
244 |
return m_TableModel.getColumnName(fieldId);
|
245 |
} |
246 |
|
247 |
/* (non-Javadoc)
|
248 |
* @see com.hardcode.gdbms.engine.data.ReadDriver#getRowCount()
|
249 |
*/
|
250 |
public long getRowCount() throws DriverException { |
251 |
return arrayGeometries.size();
|
252 |
} |
253 |
} |