Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / addlayer / fileopen / vectorial / VectorialFileOpen.java @ 16403

History | View | Annotate | Download (4.17 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package com.iver.cit.gvsig.addlayer.fileopen.vectorial;
20

    
21
import java.awt.geom.Rectangle2D;
22
import java.io.File;
23
import java.util.ArrayList;
24
import java.util.Comparator;
25
import java.util.Iterator;
26
import java.util.TreeSet;
27

    
28
import org.cresques.cts.IProjection;
29

    
30
import com.hardcode.driverManager.Driver;
31
import com.hardcode.driverManager.DriverLoadException;
32
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
33
import com.iver.andami.messages.NotificationManager;
34
import com.iver.cit.gvsig.AddLayer;
35
import com.iver.cit.gvsig.addlayer.fileopen.AbstractFileOpen;
36
import com.iver.cit.gvsig.fmap.MapControl;
37
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver;
38
import com.iver.cit.gvsig.fmap.layers.FLayer;
39
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
40
/**
41
 * Clase que indicar? que ficheros puede tratar al panel de apertura de ficheros
42
 *
43
 * @version 04/09/2007
44
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
45
 */
46
public class VectorialFileOpen extends AbstractFileOpen{
47
        private ArrayList arrayFileFilter;
48

    
49
        /**
50
         * Constructor de FileOpenRaster
51
         */
52
        public VectorialFileOpen() {
53
                TreeSet filters = new TreeSet(new Comparator() {
54
                        public int compare(Object o1, Object o2) {
55
                                VectorialFileFilter dff1 = (VectorialFileFilter) o1;
56
                                VectorialFileFilter dff2 = (VectorialFileFilter) o2;
57

    
58
                                return dff1.driver.getName().compareTo(dff2.driver.getName());
59
                        }
60
                });
61

    
62
                Class[] driverClasses = new Class[] { VectorialFileDriver.class };
63
                String[] driverNames = LayerFactory.getDM().getDriverNames();
64
                VectorialFileFilter auxF;
65
                try {
66
                        for (int i = 0; i < driverNames.length; i++) {
67
                                System.err.println("DRIVER " + i + " : " + driverNames[i]);
68
                                boolean is = false;
69
                                for (int j = 0; j < driverClasses.length; j++) {
70
                                        if (i == 0)
71
                                                System.err.println("DRIVER CLASS " + j + " : " + driverClasses[j].toString());
72
                                        if (LayerFactory.getDM().isA(driverNames[i], driverClasses[j]))
73
                                                is = true;
74
                                }
75
                                if (is) {
76
                                        auxF = new VectorialFileFilter(driverNames[i]);
77
                                        filters.add(auxF);
78
                                }
79
                        }
80
                        Iterator i = filters.iterator();
81
                        while (i.hasNext()) {
82
                                VectorialFileFilter element = (VectorialFileFilter) i.next();
83
                                getFileFilter().add(element);
84
                        }
85
                } catch (DriverLoadException e1) {
86
                        NotificationManager.addError("No se pudo acceder a los drivers", e1);
87
                }
88

    
89
        }
90

    
91
        /*
92
         * (non-Javadoc)
93
         * @see org.gvsig.raster.gui.wizards.IFileOpen#execute(java.io.File[])
94
         */
95
        public Rectangle2D createLayer(File file, MapControl mapControl, String driverName, IProjection proj) {
96
                FLayer lyr = null;
97
                Driver driver = null;
98

    
99
                // all catched errors will be saved here, to show user at the end of the method
100
                ArrayList errors = new ArrayList();
101

    
102
                // try to load the drivers referenced by the file dialog
103
                try {
104
                        driver = LayerFactory.getDM().getDriver(driverName);
105
                } catch (DriverLoadException e) {
106
                        errors.add(e);
107
                }
108

    
109
                // Envelope de cada fichero seleccionado por el usuario
110
                String layerName = file.getName();
111
                try {
112

    
113
                        if (driver instanceof VectorialFileDriver) {
114
                                lyr = LayerFactory.createLayer(layerName, (VectorialFileDriver) driver, file, proj);
115
                        }
116

    
117
                        if (lyr != null) {
118
                                AddLayer.checkProjection(lyr, mapControl.getViewPort());
119
                                mapControl.getMapContext().getLayers().addLayer(lyr);
120

    
121
                                return lyr.getFullExtent();
122
                        }
123
                } catch (ReadDriverException e) {
124
                        errors.add(e);
125
                }
126
                return null;
127
        }
128
}