root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / Abrir.java @ 1178
History | View | Annotate | Download (6.71 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 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 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig; |
42 |
|
43 |
import java.awt.geom.Rectangle2D; |
44 |
import java.io.File; |
45 |
|
46 |
import javax.swing.JOptionPane; |
47 |
|
48 |
import org.cresques.cts.ICoordTrans; |
49 |
import org.cresques.cts.IProjection; |
50 |
import org.cresques.cts.gt2.CoordSys; |
51 |
import org.cresques.cts.gt2.CoordTrans; |
52 |
|
53 |
import com.iver.andami.PluginServices; |
54 |
import com.iver.andami.messages.NotificationManager; |
55 |
import com.iver.andami.plugins.Extension; |
56 |
import com.iver.cit.gvsig.fmap.DriverException; |
57 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
58 |
import com.iver.cit.gvsig.fmap.drivers.RasterDriver; |
59 |
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
60 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
61 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
62 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
63 |
import com.iver.cit.gvsig.gui.FOpenDialog; |
64 |
import com.iver.cit.gvsig.gui.FileOpenDialog; |
65 |
import com.iver.cit.gvsig.gui.View; |
66 |
import com.iver.cit.gvsig.gui.WMSDataSourceAdapter; |
67 |
import com.iver.cit.gvsig.gui.wms.WMSWizard; |
68 |
|
69 |
|
70 |
/**
|
71 |
* DOCUMENT ME!
|
72 |
*
|
73 |
* @author Fernando Gonz?lez Cort?s
|
74 |
*/
|
75 |
public class Abrir implements Extension { |
76 |
public FOpenDialog fopen = null; |
77 |
|
78 |
/**
|
79 |
* @see com.iver.mdiApp.plugins.Extension#isVisible()
|
80 |
*/
|
81 |
public boolean isVisible() { |
82 |
com.iver.andami.ui.mdiManager.View f = PluginServices.getMDIManager() |
83 |
.getActiveView(); |
84 |
|
85 |
if (f == null) { |
86 |
return false; |
87 |
} |
88 |
|
89 |
return (f.getClass() == View.class); |
90 |
} |
91 |
|
92 |
/**
|
93 |
* @see com.iver.andami.plugins.Extension#inicializar()
|
94 |
*/
|
95 |
public void inicializar() { |
96 |
} |
97 |
|
98 |
/**
|
99 |
* @see com.iver.andami.plugins.Extension#execute(java.lang.String)
|
100 |
*/
|
101 |
public void execute(String actionCommand) { |
102 |
View theView = (View) PluginServices.getMDIManager().getActiveView(); |
103 |
fopen = new FOpenDialog();
|
104 |
|
105 |
FileOpenDialog fileDlg = new FileOpenDialog(new Class[] { |
106 |
VectorialFileDriver.class, RasterDriver.class |
107 |
}); |
108 |
WMSWizard wms = new WMSWizard();
|
109 |
wms.setDataSource(new WMSDataSourceAdapter());
|
110 |
|
111 |
// DataBaseOpenDialog dbop = new DataBaseOpenDialog();
|
112 |
// dbop.setClasses(new Class[] { DBDriver.class });
|
113 |
fopen.addTab("Fichero", fileDlg);
|
114 |
fopen.addWizardTab("WMS", wms);
|
115 |
|
116 |
// fopen.addTab("Base de datos", dbop);
|
117 |
PluginServices.getMDIManager().addView(fopen); |
118 |
|
119 |
if (fopen.isAccepted()) {
|
120 |
FLayer lyr = null;
|
121 |
|
122 |
if (fopen.getSelectedTab() == fileDlg) {
|
123 |
if (fileDlg.getFiles() == null) { |
124 |
return;
|
125 |
} |
126 |
|
127 |
IProjection proj = FOpenDialog.getLastProjection(); |
128 |
File[] files = fileDlg.getFiles(); |
129 |
String[] driverNames = fileDlg.getDriverNames(); |
130 |
Rectangle2D[] rects=new Rectangle2D[files.length]; |
131 |
boolean first=false; |
132 |
for (int iFile = 0; iFile < files.length; iFile++) { |
133 |
File fich = files[iFile];
|
134 |
String layerName = fich.getName();
|
135 |
String layerPath = fich.getAbsolutePath();
|
136 |
|
137 |
try {
|
138 |
lyr = LayerFactory.createLayer(layerName, |
139 |
driverNames[iFile], fich, proj); |
140 |
|
141 |
if (lyr != null) { |
142 |
lyr.setVisible(true);
|
143 |
theView.getMapControl().getMapContext() |
144 |
.beginAtomicEvent(); |
145 |
if (theView.getMapControl().getMapContext().getViewPort().getExtent()==null){ |
146 |
first=true;
|
147 |
} |
148 |
// Comprobar que la projecci?n es la misma que la vista
|
149 |
if (proj != theView.getProjection())
|
150 |
{ |
151 |
int option = JOptionPane.showConfirmDialog(null, |
152 |
"La proyecci?n de la capa no es igual que la de la vista", "?Desea reproyectar?", JOptionPane.YES_NO_OPTION); |
153 |
|
154 |
if (option == JOptionPane.NO_OPTION) |
155 |
{ |
156 |
continue;
|
157 |
} |
158 |
else
|
159 |
{ |
160 |
ICoordTrans ct = new CoordTrans((CoordSys) proj, (CoordSys) theView.getProjection());
|
161 |
lyr.setCoordTrans(ct); |
162 |
System.err.println("coordTrans = " + |
163 |
proj.getAbrev() + " " + theView.getProjection().getAbrev());
|
164 |
} |
165 |
|
166 |
|
167 |
} |
168 |
theView.getMapControl().getMapContext().getLayers() |
169 |
.addLayer(lyr); |
170 |
rects[iFile]=lyr.getFullExtent(); |
171 |
theView.getMapControl().getMapContext() |
172 |
.endAtomicEvent(); |
173 |
|
174 |
// TODO: Poner una variable y dibujar solo cuando
|
175 |
// todas las capas hayan sido cargadas.
|
176 |
// TODO Se deber? de redibujar mediante la captura de los eventos, por
|
177 |
//eso se comenta la parte anterior
|
178 |
// theView.getMapControl().drawMap();
|
179 |
// theView.getTOC().refresh();
|
180 |
} |
181 |
} catch (DriverException e) {
|
182 |
NotificationManager.addError("Error al crear la capa", e);
|
183 |
} |
184 |
} |
185 |
//Esto permite que cuando se cargan varias capas de golpe y la vista est? vacia,se ponga como extent la suma de todos sus extents.
|
186 |
if (rects.length>1){ |
187 |
Rectangle2D rect=new Rectangle2D.Double(); |
188 |
rect.setRect(rects[0]);
|
189 |
if (first){
|
190 |
for (int i=0;i<rects.length;i++){ |
191 |
rect.add(rects[i]); |
192 |
} |
193 |
theView.getMapControl().getMapContext().getViewPort().setExtent(rect); |
194 |
} |
195 |
} |
196 |
} else if (fopen.getSelectedTab() == wms) { |
197 |
String layerName = wms.getLayerName();
|
198 |
|
199 |
lyr = LayerFactory.createLayer(layerName, |
200 |
wms.getLayersRectangle(), wms.getHost(), |
201 |
wms.getFormat(), wms.getLayersQuery(), |
202 |
wms.getQueryableLayerQuery(), wms.getSRS()); |
203 |
|
204 |
if (lyr != null) { |
205 |
lyr.setVisible(true);
|
206 |
theView.getMapControl().getMapContext().beginAtomicEvent(); |
207 |
theView.getMapControl().getMapContext().getLayers() |
208 |
.addLayer(lyr); |
209 |
theView.getMapControl().getMapContext().endAtomicEvent(); |
210 |
|
211 |
} |
212 |
} // for
|
213 |
} |
214 |
} |
215 |
|
216 |
/**
|
217 |
* @see com.iver.andami.plugins.Extension#isEnabled()
|
218 |
*/
|
219 |
public boolean isEnabled() { |
220 |
return true; |
221 |
} |
222 |
} |