Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / MemoryDriver.java @ 695

History | View | Annotate | Download (4.55 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
package com.iver.cit.gvsig.fmap.drivers;
8

    
9
import java.awt.geom.Rectangle2D;
10
import java.io.File;
11
import java.io.IOException;
12
import java.util.ArrayList;
13

    
14
import javax.swing.table.DefaultTableModel;
15

    
16
import com.hardcode.gdbms.engine.data.DriverException;
17
import com.hardcode.gdbms.engine.data.FileDriver;
18
import com.hardcode.gdbms.engine.values.Value;
19
import com.iver.cit.gvsig.fmap.core.FGeometry;
20
import com.iver.cit.gvsig.fmap.core.FShape;
21
import com.iver.cit.gvsig.fmap.core.IGeometry;
22
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
23
import com.iver.cit.gvsig.fmap.operations.strategies.MemoryShapeInfo;
24

    
25
/**
26
 * @author FJP
27
 *
28
 * TODO To change the template for this generated type comment go to
29
 * Window - Preferences - Java - Code Generation - Code and Comments
30
 */
31
public abstract class MemoryDriver implements VectorialFileDriver, FileDriver, BoundedShapes {
32
    private MemoryShapeInfo memShapeInfo = new MemoryShapeInfo();
33
    private ArrayList arrayGeometries = new ArrayList();
34
    private Rectangle2D fullExtent;
35
    private int m_Position;
36
    private DefaultTableModel m_TableModel = new DefaultTableModel();
37
    
38
    public DefaultTableModel getTableModel()
39
    {
40
            return m_TableModel;
41
    }
42
    
43
    public void addShape(FShape shp, Object [] row) {
44
            if (shp == null) return; // No a?adimos nada
45
            Rectangle2D boundsShp = shp.getBounds(); 
46
        memShapeInfo.addShapeInfo(boundsShp, shp.getShapeType());
47
        arrayGeometries.add(ShapeFactory.createGeometry(shp));
48
        m_TableModel.addRow(row);
49
        try {
50
                        fullExtent = getFullExtent();
51
                } catch (IOException e) {
52
                        e.printStackTrace();
53
                }
54
        if (fullExtent == null)
55
        {
56
                fullExtent = boundsShp;
57
        }
58
        else
59
                fullExtent.add(boundsShp);
60
        
61
        m_Position++;
62
    }
63

    
64
    public Rectangle2D getShapeBounds(int index) throws IOException
65
        {
66
                return memShapeInfo.getBoundingBox(index);
67
        }
68
        
69
        
70
        public int getShapeType(int index) 
71
        {
72
                return memShapeInfo.getType(index);
73
        }
74
    
75
        /* (non-Javadoc)
76
         * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#open(java.io.File)
77
         */
78
        public abstract void open(File f) throws IOException;
79
        /* (non-Javadoc)
80
         * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#close()
81
         */
82
        public void close() throws IOException {
83
                // No hago nada, lo he abierto y cerrado en el inicialize de la clase hija
84
        }
85
        /* (non-Javadoc)
86
         * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#getShape(int)
87
         */
88
        public IGeometry getShape(int index) throws IOException {
89
                return (IGeometry) arrayGeometries.get(index);
90
        }
91
        /* (non-Javadoc)
92
         * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#getShapeCount()
93
         */
94
        public int getShapeCount() throws IOException {
95
                return arrayGeometries.size();
96
        }
97
        /* (non-Javadoc)
98
         * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#getFullExtent()
99
         */
100
        public Rectangle2D getFullExtent() throws IOException {
101
                return fullExtent;
102
        }
103
        /* (non-Javadoc)
104
         * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#initialize()
105
         */
106
        public void initialize() throws IOException {
107
                
108
        }
109
        /* (non-Javadoc)
110
         * @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#accept(java.io.File)
111
         */
112
        public abstract boolean accept(File f);
113
        /* (non-Javadoc)
114
         * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getShapeType()
115
         */
116
        public int getShapeType() {
117
                return 15;
118
        }
119
        /* (non-Javadoc)
120
         * @see com.hardcode.driverManager.Driver#getName()
121
         */
122
        public abstract String getName();
123
        /* (non-Javadoc)
124
         * @see com.hardcode.gdbms.engine.data.FileDriver#fileAccepted(java.io.File)
125
         */
126
        public boolean fileAccepted(File f) {
127
                return false;
128
        }
129
        /* (non-Javadoc)
130
         * @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldValue(long, int)
131
         */
132
        public Value getFieldValue(long rowIndex, int fieldId) throws DriverException {
133
                return (Value) m_TableModel.getValueAt((int) rowIndex, fieldId);
134
        }
135
        /* (non-Javadoc)
136
         * @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldCount()
137
         */
138
        public int getFieldCount() throws DriverException {
139
                return m_TableModel.getColumnCount();
140
        }
141
        /* (non-Javadoc)
142
         * @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldName(int)
143
         */
144
        public String getFieldName(int fieldId) throws DriverException {
145
                return m_TableModel.getColumnName(fieldId);
146
        }
147
        /* (non-Javadoc)
148
         * @see com.hardcode.gdbms.engine.data.ReadDriver#getRowCount()
149
         */
150
        public long getRowCount() throws DriverException {
151
                return arrayGeometries.size();
152
        }
153

    
154
}