root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / Abrir.java @ 1178
History | View | Annotate | Download (6.71 KB)
1 | 1103 | fjp | /* 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 | 312 | fernando | package com.iver.cit.gvsig; |
42 | |||
43 | 904 | fjp | import java.awt.geom.Rectangle2D; |
44 | import java.io.File; |
||
45 | 359 | fjp | |
46 | 904 | fjp | import javax.swing.JOptionPane; |
47 | 357 | fjp | |
48 | 904 | fjp | 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 | 596 | fernando | import com.iver.andami.PluginServices; |
54 | 755 | fernando | import com.iver.andami.messages.NotificationManager; |
55 | 596 | fernando | import com.iver.andami.plugins.Extension; |
56 | 652 | fernando | import com.iver.cit.gvsig.fmap.DriverException; |
57 | 1038 | vcaballero | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
58 | 671 | luisw | import com.iver.cit.gvsig.fmap.drivers.RasterDriver; |
59 | 378 | fjp | import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
60 | 357 | fjp | import com.iver.cit.gvsig.fmap.layers.FLayer; |
61 | import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
||
62 | 1056 | vcaballero | import com.iver.cit.gvsig.fmap.layers.XMLException; |
63 | 312 | fernando | import com.iver.cit.gvsig.gui.FOpenDialog; |
64 | 429 | fernando | import com.iver.cit.gvsig.gui.FileOpenDialog; |
65 | 312 | fernando | import com.iver.cit.gvsig.gui.View; |
66 | 854 | fernando | import com.iver.cit.gvsig.gui.WMSDataSourceAdapter; |
67 | import com.iver.cit.gvsig.gui.wms.WMSWizard; |
||
68 | 312 | fernando | |
69 | |||
70 | /**
|
||
71 | * DOCUMENT ME!
|
||
72 | *
|
||
73 | * @author Fernando Gonz?lez Cort?s
|
||
74 | */
|
||
75 | 596 | fernando | public class Abrir implements Extension { |
76 | 854 | fernando | public FOpenDialog fopen = null; |
77 | 312 | fernando | |
78 | 854 | fernando | /**
|
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 | 596 | fernando | |
85 | 854 | fernando | if (f == null) { |
86 | return false; |
||
87 | } |
||
88 | 596 | fernando | |
89 | 854 | fernando | return (f.getClass() == View.class); |
90 | } |
||
91 | 596 | fernando | |
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 | 854 | fernando | public void execute(String actionCommand) { |
102 | View theView = (View) PluginServices.getMDIManager().getActiveView(); |
||
103 | fopen = new FOpenDialog();
|
||
104 | 438 | fernando | |
105 | 854 | fernando | FileOpenDialog fileDlg = new FileOpenDialog(new Class[] { |
106 | VectorialFileDriver.class, RasterDriver.class |
||
107 | }); |
||
108 | WMSWizard wms = new WMSWizard();
|
||
109 | wms.setDataSource(new WMSDataSourceAdapter());
|
||
110 | 438 | fernando | |
111 | 854 | fernando | // DataBaseOpenDialog dbop = new DataBaseOpenDialog();
|
112 | // dbop.setClasses(new Class[] { DBDriver.class });
|
||
113 | fopen.addTab("Fichero", fileDlg);
|
||
114 | fopen.addWizardTab("WMS", wms);
|
||
115 | 438 | fernando | |
116 | 854 | fernando | // fopen.addTab("Base de datos", dbop);
|
117 | PluginServices.getMDIManager().addView(fopen); |
||
118 | 438 | fernando | |
119 | 854 | fernando | if (fopen.isAccepted()) {
|
120 | FLayer lyr = null;
|
||
121 | 438 | fernando | |
122 | 854 | fernando | if (fopen.getSelectedTab() == fileDlg) {
|
123 | if (fileDlg.getFiles() == null) { |
||
124 | return;
|
||
125 | } |
||
126 | 438 | fernando | |
127 | 904 | fjp | IProjection proj = FOpenDialog.getLastProjection(); |
128 | 854 | fernando | File[] files = fileDlg.getFiles(); |
129 | 1171 | fjp | String[] driverNames = fileDlg.getDriverNames(); |
130 | 870 | vcaballero | Rectangle2D[] rects=new Rectangle2D[files.length]; |
131 | boolean first=false; |
||
132 | 854 | fernando | for (int iFile = 0; iFile < files.length; iFile++) { |
133 | File fich = files[iFile];
|
||
134 | String layerName = fich.getName();
|
||
135 | String layerPath = fich.getAbsolutePath();
|
||
136 | 438 | fernando | |
137 | 854 | fernando | try {
|
138 | lyr = LayerFactory.createLayer(layerName, |
||
139 | 1171 | fjp | driverNames[iFile], fich, proj); |
140 | 854 | fernando | |
141 | if (lyr != null) { |
||
142 | lyr.setVisible(true);
|
||
143 | theView.getMapControl().getMapContext() |
||
144 | .beginAtomicEvent(); |
||
145 | 870 | vcaballero | if (theView.getMapControl().getMapContext().getViewPort().getExtent()==null){ |
146 | first=true;
|
||
147 | } |
||
148 | 904 | fjp | // 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 | 854 | fernando | theView.getMapControl().getMapContext().getLayers() |
169 | .addLayer(lyr); |
||
170 | 870 | vcaballero | rects[iFile]=lyr.getFullExtent(); |
171 | 854 | fernando | theView.getMapControl().getMapContext() |
172 | .endAtomicEvent(); |
||
173 | 870 | vcaballero | |
174 | 854 | fernando | // 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 | 1056 | vcaballero | } |
184 | 854 | fernando | } |
185 | 870 | vcaballero | //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 | 854 | fernando | } 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 | 596 | fernando | } |
215 | 438 | fernando | |
216 | 596 | fernando | /**
|
217 | * @see com.iver.andami.plugins.Extension#isEnabled()
|
||
218 | */
|
||
219 | public boolean isEnabled() { |
||
220 | return true; |
||
221 | } |
||
222 | 312 | fernando | } |