root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / addlayer / fileopen / vectorial / VectorialFileOpen.java @ 25166
History | View | Annotate | Download (4.18 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.io.File; |
22 |
import java.util.ArrayList; |
23 |
import java.util.Iterator; |
24 |
import java.util.List; |
25 |
|
26 |
import javax.swing.filechooser.FileFilter; |
27 |
|
28 |
import org.cresques.cts.IProjection; |
29 |
import org.gvsig.fmap.dal.DALLocator; |
30 |
import org.gvsig.fmap.dal.DataManager; |
31 |
import org.gvsig.fmap.dal.DataStoreParameters; |
32 |
import org.gvsig.fmap.dal.exception.DataException; |
33 |
import org.gvsig.fmap.dal.exception.InitializeException; |
34 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
35 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemFileFilter; |
36 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer; |
37 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters; |
38 |
import org.gvsig.fmap.geom.primitive.Envelope; |
39 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
40 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
41 |
import org.gvsig.fmap.mapcontext.layers.LayerFactory; |
42 |
import org.gvsig.fmap.mapcontrol.MapControl; |
43 |
|
44 |
import com.iver.andami.messages.NotificationManager; |
45 |
import com.iver.cit.gvsig.AddLayer; |
46 |
import com.iver.cit.gvsig.addlayer.fileopen.IFileOpen; |
47 |
/**
|
48 |
* Clase que indicar? que ficheros puede tratar al panel de apertura de ficheros
|
49 |
*
|
50 |
* @version 04/09/2007
|
51 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
52 |
*/
|
53 |
public class VectorialFileOpen implements IFileOpen { |
54 |
|
55 |
private FilesystemServerExplorer explorer;
|
56 |
private List filters; |
57 |
|
58 |
/**
|
59 |
* Constructor de FileOpenRaster
|
60 |
*
|
61 |
* @throws ProviderNotRegisteredException
|
62 |
* @throws InitializeException
|
63 |
*/
|
64 |
public VectorialFileOpen() throws InitializeException, |
65 |
ProviderNotRegisteredException { |
66 |
DataManager dm = DALLocator.getDataManager(); |
67 |
FilesystemServerExplorerParameters param = (FilesystemServerExplorerParameters) dm |
68 |
.createServerExplorerParameters(FilesystemServerExplorer.NAME); |
69 |
explorer = (FilesystemServerExplorer) dm |
70 |
.createServerExplorer(param); |
71 |
this.filters = new ArrayList(); |
72 |
Iterator<FilesystemFileFilter> iter = explorer.getFilters();
|
73 |
while (iter.hasNext()) {
|
74 |
this.filters.add(new VectorialFileFilter(iter.next())); |
75 |
} |
76 |
this.filters.add(new VectorialFileFilter(explorer.getGenericFilter())); |
77 |
} |
78 |
|
79 |
/*
|
80 |
* (non-Javadoc)
|
81 |
* @see org.gvsig.raster.gui.wizards.IFileOpen#execute(java.io.File[])
|
82 |
*/
|
83 |
public Envelope createLayer(File file, MapControl mapControl, |
84 |
FileFilter filter, IProjection proj) {
|
85 |
FLayer lyr = null;
|
86 |
// FeatureStore store = null;
|
87 |
|
88 |
try {
|
89 |
// try to load the drivers referenced by the file dialog
|
90 |
DataStoreParameters params = this.explorer.getParametersFor(file);
|
91 |
|
92 |
String layerName = file.getName();
|
93 |
|
94 |
// ((FilesystemStoreParameters) params).setFile(file);
|
95 |
lyr = LayerFactory.getInstance().createLayer( |
96 |
layerName, params, proj); |
97 |
|
98 |
if (lyr != null) { |
99 |
AddLayer.checkProjection(lyr, mapControl.getViewPort()); |
100 |
mapControl.getMapContext().getLayers().addLayer(lyr); |
101 |
|
102 |
return lyr.getFullEnvelope();
|
103 |
} |
104 |
} catch (LoadLayerException e) {
|
105 |
NotificationManager.showMessageError("Error_creating_layer", e);
|
106 |
} catch (DataException e) {
|
107 |
NotificationManager.showMessageError("Error_creating_layer", e);
|
108 |
} |
109 |
return null; |
110 |
} |
111 |
|
112 |
public List getFileFilter() { |
113 |
return this.filters; |
114 |
} |
115 |
|
116 |
public File post(File file) { |
117 |
// TODO Auto-generated method stub
|
118 |
return file;
|
119 |
} |
120 |
|
121 |
public void pre() { |
122 |
// TODO Par?meteros??
|
123 |
|
124 |
} |
125 |
} |