Revision 10450 branches/simbologia/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/MemoryDriver.java

View differences:

MemoryDriver.java
47 47
package com.iver.cit.gvsig.fmap.drivers;
48 48

  
49 49
import java.awt.geom.Rectangle2D;
50
import java.io.File;
51 50
import java.io.IOException;
52 51
import java.sql.Types;
53 52
import java.util.ArrayList;
......
58 57
import com.hardcode.gdbms.engine.data.DataSourceFactory;
59 58
import com.hardcode.gdbms.engine.data.driver.DriverException;
60 59
import com.hardcode.gdbms.engine.data.driver.ObjectDriver;
60
import com.hardcode.gdbms.engine.values.StringValue;
61 61
import com.hardcode.gdbms.engine.values.Value;
62 62
import com.iver.cit.gvsig.fmap.core.FShape;
63 63
import com.iver.cit.gvsig.fmap.core.IGeometry;
......
79 79
	private Rectangle2D fullExtent;
80 80
	private int m_Position;
81 81
	private DefaultTableModel m_TableModel = new DefaultTableModel();
82

  
82
	private int[] fieldWidth=null;
83
	
83 84
	/**
84 85
	 * Devuelve el modelo de la tabla.
85 86
	 *
......
103 104
		Rectangle2D boundsShp = geom.getBounds();
104 105
		memShapeInfo.addShapeInfo(boundsShp, geom.getGeometryType());
105 106
		arrayGeometries.add(geom);
107
		if (fieldWidth==null) {
108
			initializeFieldWidth(row);
109
		}
110
		actualizeFieldWidth(row);
106 111
		m_TableModel.addRow(row);
107 112

  
108 113
		try {
......
120 125
		m_Position++;
121 126
	}
122 127

  
123
	
128

  
124 129
	/**
125 130
	 * M?todo de conveniencia, para poder a?adir directamente un shape
126 131
	 * o una IGeometry. (Arriba est? el de a?adir una IGeometry.
......
132 137
			return; // No a?adimos nada
133 138
		}
134 139
		IGeometry geom = ShapeFactory.createGeometry(shp);
135
		
140

  
136 141
		addGeometry(geom, row);
137 142
	}
138 143

  
......
203 208
	/**
204 209
	 * @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldType(int)
205 210
	 */
206
	
211

  
207 212
/*
208 213
 * azabala, bug 666
209 214
 * Habra que estudiar como hacer, porque si una fila tiene el primer valor
210 215
 * (o todos) a NullValue, devolvera como tipo de dato Types.NULL.
211 216
 * Quizas, habra que hacer que los MemoryDriver tb tengan un ITableDefinition.
212
 * 
217
 *
213 218
 * DxfMemoryDriver no obstante si que tiene informacion sobre el esquema, asi
214 219
 * que debera sobreescribir este metodo para salvar el bug
215 220
 * (metodo getTableDefinition)
216
 * 
217
 * 
218
 * 
219
 * 
221
 *
222
 *
223
 *
224
 *
220 225
 */
221 226
	public int getFieldType(int i) throws DriverException {
222 227
	    // TODO: Revisar esto. Por ejemplo, el long
......
232 237
        }
233 238
        else
234 239
        {
235
            // TODO: ESTO CREO QUE NO TIENE SENTIDO. SIEMPRE DEVUELVE Object.class, lo dice en 
240
            // TODO: ESTO CREO QUE NO TIENE SENTIDO. SIEMPRE DEVUELVE Object.class, lo dice en
236 241
            // la documentaci?n. Creo que habr?a que quitarlo.
237 242
    	    if (m_TableModel.getColumnClass(i) == String.class)
238 243
    	        return Types.VARCHAR;
......
248 253
    	        return Types.BIT;
249 254
    	    if (m_TableModel.getColumnClass(i) == Date.class)
250 255
    	        return Types.DATE;
251
        }	    
256
        }
252 257
	    return Types.VARCHAR;
253 258
	    // return m_TableModel.getColumnClass(i);
254 259
//	    throw new DriverException("Tipo no soportado: " + m_TableModel.getColumnClass(i).getName());
......
281 286
	public long getRowCount() throws DriverException {
282 287
		return arrayGeometries.size();
283 288
	}
284
    
289

  
285 290
    /* (non-Javadoc)
286 291
     * @see com.hardcode.gdbms.engine.data.driver.GDBMSDriver#setDataSourceFactory(com.hardcode.gdbms.engine.data.DataSourceFactory)
287 292
     */
......
299 304
		m_Position = 0;
300 305

  
301 306
    }
302
    
303
    public int getFieldWidth(int fieldId)
304
    {
305
    	// TODO
306
    	return 30;
307
    private void initializeFieldWidth(Object[] row) {
308
    	fieldWidth=new int[row.length];
309
		for (int i=0;i<row.length;i++) {
310
			fieldWidth[i]=((Value)row[i]).getWidth();
311
		}
307 312
    }
308
    
313
    /**
314
     * Actualize the width fields with StringValue.
315
     * @param row
316
     */
317
    private void actualizeFieldWidth(Object[] row) {
318
    	for (int i=0;i<row.length;i++) {
319
			if (row[i] instanceof StringValue) {
320
				int width=((StringValue)row[i]).getWidth();
321
				if (fieldWidth[i]<width) {
322
					fieldWidth[i]=width;
323
				}
324
			}
325
		}
326
    }
327
    public int getFieldWidth(int fieldId){
328
    	if (fieldWidth==null)
329
    		return 1;
330
    	return fieldWidth[fieldId];
331
    }
309 332

  
333

  
310 334
}

Also available in: Unified diff