root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / MemoryDriver.java @ 1100
History | View | Annotate | Download (5.92 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 |
/**
|
82 |
* Devuelve el modelo de la tabla.
|
83 |
*
|
84 |
* @return modelo de la tabla.
|
85 |
*/
|
86 |
public DefaultTableModel getTableModel() { |
87 |
return m_TableModel;
|
88 |
} |
89 |
|
90 |
/**
|
91 |
* A?ade un shape.
|
92 |
*
|
93 |
* @param shp shape.
|
94 |
* @param row fila.
|
95 |
*/
|
96 |
public void addShape(FShape shp, Object[] row) { |
97 |
if (shp == null) { |
98 |
return; // No a?adimos nada |
99 |
} |
100 |
|
101 |
Rectangle2D boundsShp = shp.getBounds();
|
102 |
memShapeInfo.addShapeInfo(boundsShp, shp.getShapeType()); |
103 |
arrayGeometries.add(ShapeFactory.createGeometry(shp)); |
104 |
m_TableModel.addRow(row); |
105 |
|
106 |
try {
|
107 |
fullExtent = getFullExtent(); |
108 |
} catch (IOException e) { |
109 |
e.printStackTrace(); |
110 |
} |
111 |
|
112 |
if (fullExtent == null) { |
113 |
fullExtent = boundsShp; |
114 |
} else {
|
115 |
fullExtent.add(boundsShp); |
116 |
} |
117 |
|
118 |
m_Position++; |
119 |
} |
120 |
|
121 |
/**
|
122 |
* Devuelve el extent a partir de un ?ndice.
|
123 |
*
|
124 |
* @param index ?ndice.
|
125 |
*
|
126 |
* @return Extent.
|
127 |
*
|
128 |
* @throws IOException
|
129 |
*/
|
130 |
public Rectangle2D getShapeBounds(int index) throws IOException { |
131 |
return memShapeInfo.getBoundingBox(index);
|
132 |
} |
133 |
|
134 |
/**
|
135 |
* Devuelve el tipo del shape.
|
136 |
*
|
137 |
* @param index ?ndice.
|
138 |
*
|
139 |
* @return tipo del shape.
|
140 |
*/
|
141 |
public int getShapeType(int index) { |
142 |
return memShapeInfo.getType(index);
|
143 |
} |
144 |
|
145 |
/* (non-Javadoc)
|
146 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#open(java.io.File)
|
147 |
*/
|
148 |
public abstract void open(File f) throws IOException; |
149 |
|
150 |
/* (non-Javadoc)
|
151 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#close()
|
152 |
*/
|
153 |
public void close() throws IOException { |
154 |
// No hago nada, lo he abierto y cerrado en el inicialize de la clase hija
|
155 |
} |
156 |
|
157 |
/* (non-Javadoc)
|
158 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#getShape(int)
|
159 |
*/
|
160 |
public IGeometry getShape(int index) throws IOException { |
161 |
IGeometry geom = (IGeometry) arrayGeometries.get(index); |
162 |
|
163 |
return geom.cloneGeometry();
|
164 |
} |
165 |
|
166 |
/* (non-Javadoc)
|
167 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#getShapeCount()
|
168 |
*/
|
169 |
public int getShapeCount() throws IOException { |
170 |
return arrayGeometries.size();
|
171 |
} |
172 |
|
173 |
/* (non-Javadoc)
|
174 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#getFullExtent()
|
175 |
*/
|
176 |
public Rectangle2D getFullExtent() throws IOException { |
177 |
return fullExtent;
|
178 |
} |
179 |
|
180 |
/* (non-Javadoc)
|
181 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#initialize()
|
182 |
*/
|
183 |
public void initialize() throws IOException { |
184 |
} |
185 |
|
186 |
/* (non-Javadoc)
|
187 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#accept(java.io.File)
|
188 |
*/
|
189 |
public abstract boolean accept(File f); |
190 |
|
191 |
/* (non-Javadoc)
|
192 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getShapeType()
|
193 |
*/
|
194 |
public abstract int getShapeType(); |
195 |
|
196 |
/* (non-Javadoc)
|
197 |
* @see com.hardcode.driverManager.Driver#getName()
|
198 |
*/
|
199 |
public abstract String getName(); |
200 |
|
201 |
/* (non-Javadoc)
|
202 |
* @see com.hardcode.gdbms.engine.data.FileDriver#fileAccepted(java.io.File)
|
203 |
*/
|
204 |
public boolean fileAccepted(File f) { |
205 |
return false; |
206 |
} |
207 |
|
208 |
/* (non-Javadoc)
|
209 |
* @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldValue(long, int)
|
210 |
*/
|
211 |
public Value getFieldValue(long rowIndex, int fieldId) |
212 |
throws DriverException {
|
213 |
return (Value) m_TableModel.getValueAt((int) rowIndex, fieldId); |
214 |
} |
215 |
|
216 |
/* (non-Javadoc)
|
217 |
* @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldCount()
|
218 |
*/
|
219 |
public int getFieldCount() throws DriverException { |
220 |
return m_TableModel.getColumnCount();
|
221 |
} |
222 |
|
223 |
/* (non-Javadoc)
|
224 |
* @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldName(int)
|
225 |
*/
|
226 |
public String getFieldName(int fieldId) throws DriverException { |
227 |
return m_TableModel.getColumnName(fieldId);
|
228 |
} |
229 |
|
230 |
/* (non-Javadoc)
|
231 |
* @see com.hardcode.gdbms.engine.data.ReadDriver#getRowCount()
|
232 |
*/
|
233 |
public long getRowCount() throws DriverException { |
234 |
return arrayGeometries.size();
|
235 |
} |
236 |
} |