root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / wizards / FileOpenRasterDialog.java @ 12118
History | View | Annotate | Download (10.1 KB)
1 | 10740 | nacho | /*
|
---|---|---|---|
2 | * Created on 23-abr-2004
|
||
3 | *
|
||
4 | * To change the template for this generated file go to
|
||
5 | * Window>Preferences>Java>Code Generation>Code and Comments
|
||
6 | */
|
||
7 | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
8 | *
|
||
9 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
10 | *
|
||
11 | * This program is free software; you can redistribute it and/or
|
||
12 | * modify it under the terms of the GNU General Public License
|
||
13 | * as published by the Free Software Foundation; either version 2
|
||
14 | * of the License, or (at your option) any later version.
|
||
15 | *
|
||
16 | * This program is distributed in the hope that it will be useful,
|
||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
19 | * GNU General Public License for more details.
|
||
20 | *
|
||
21 | * You should have received a copy of the GNU General Public License
|
||
22 | * along with this program; if not, write to the Free Software
|
||
23 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
24 | *
|
||
25 | * For more information, contact:
|
||
26 | *
|
||
27 | * Generalitat Valenciana
|
||
28 | * Conselleria d'Infraestructures i Transport
|
||
29 | * Av. Blasco Ib??ez, 50
|
||
30 | * 46010 VALENCIA
|
||
31 | * SPAIN
|
||
32 | *
|
||
33 | * +34 963862235
|
||
34 | * gvsig@gva.es
|
||
35 | * www.gvsig.gva.es
|
||
36 | *
|
||
37 | * or
|
||
38 | *
|
||
39 | * IVER T.I. S.A
|
||
40 | * Salamanca 50
|
||
41 | * 46005 Valencia
|
||
42 | * Spain
|
||
43 | *
|
||
44 | * +34 963163400
|
||
45 | * dac@iver.es
|
||
46 | */
|
||
47 | package org.gvsig.rastertools.wizards; |
||
48 | |||
49 | import java.awt.BorderLayout; |
||
50 | 11647 | nacho | import java.awt.Component; |
51 | 10740 | nacho | import java.awt.geom.Rectangle2D; |
52 | import java.io.File; |
||
53 | |||
54 | import javax.swing.JFileChooser; |
||
55 | 11647 | nacho | import javax.swing.JOptionPane; |
56 | 10740 | nacho | import javax.swing.filechooser.FileFilter; |
57 | |||
58 | import org.cresques.cts.IProjection; |
||
59 | import org.gvsig.fmap.layers.FLyrRasterSE; |
||
60 | 11893 | nacho | import org.gvsig.rastertools.RasterModule; |
61 | 10740 | nacho | |
62 | import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
||
63 | import com.iver.andami.PluginServices; |
||
64 | import com.iver.andami.ui.mdiManager.IWindow; |
||
65 | import com.iver.cit.gvsig.exceptions.expansionfile.ExpansionFileReadException; |
||
66 | 11647 | nacho | import com.iver.cit.gvsig.exceptions.layers.LoadLayerException; |
67 | 10740 | nacho | import com.iver.cit.gvsig.fmap.MapControl; |
68 | import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
||
69 | import com.iver.cit.gvsig.fmap.layers.FLayer; |
||
70 | import com.iver.cit.gvsig.gui.WizardPanel; |
||
71 | import com.iver.cit.gvsig.gui.panels.CRSSelectPanel; |
||
72 | import com.iver.cit.gvsig.project.documents.gui.FOpenDialog; |
||
73 | import com.iver.cit.gvsig.project.documents.gui.ListManagerSkin; |
||
74 | import com.iver.cit.gvsig.project.documents.view.gui.View; |
||
75 | import com.iver.utiles.listManager.ListManagerListener; |
||
76 | |||
77 | 11647 | nacho | public class FileOpenRasterDialog extends WizardPanel implements ListManagerListener { |
78 | 11191 | bsanchez | private static final long serialVersionUID = 335310147513197564L; |
79 | 12050 | bsanchez | // private static DriverFileFilter lastFileFilter = null;
|
80 | 11647 | nacho | private javax.swing.JPanel jPanel2 = null; |
81 | private JFileChooser fileChooser; |
||
82 | //private Class[] driverClasses;
|
||
83 | private String title = PluginServices.getText(this,"Raster"); |
||
84 | 10740 | nacho | private CRSSelectPanel jPanelProj = null; |
85 | private ListManagerSkin listManagerDemoSkin = null; |
||
86 | 11647 | nacho | private boolean proj; |
87 | 12050 | bsanchez | |
88 | 11647 | nacho | public FileOpenRasterDialog() {
|
89 | init(/*new Class[] {GenericRasterDriver.class }*/null, true); |
||
90 | } |
||
91 | 12050 | bsanchez | |
92 | 11647 | nacho | public void initWizard() { |
93 | setTabName("Raster");
|
||
94 | init(/*new Class[] {GenericRasterDriver.class }*/null, true); |
||
95 | 10740 | nacho | } |
96 | |||
97 | 11191 | bsanchez | public void execute() { |
98 | 12050 | bsanchez | if (getFiles() == null) |
99 | 10740 | nacho | return;
|
100 | 12050 | bsanchez | |
101 | 10740 | nacho | MapControl mapControl = null;
|
102 | IWindow[] w = PluginServices.getMDIManager().getAllWindows();
|
||
103 | for(int i = 0 ; i < w.length; i ++){ |
||
104 | if(w[i] instanceof View){ |
||
105 | mapControl = ((View)w[i]).getMapControl();
|
||
106 | } |
||
107 | } |
||
108 | 11191 | bsanchez | |
109 | 10740 | nacho | if(mapControl == null) |
110 | return;
|
||
111 | 12050 | bsanchez | |
112 | 10740 | nacho | FLayer lyr = null;
|
113 | IProjection proj = FOpenDialog.getLastProjection(); |
||
114 | 12050 | bsanchez | |
115 | 10740 | nacho | Rectangle2D[] rects = new Rectangle2D[getFiles().length]; |
116 | boolean first = false; |
||
117 | 12050 | bsanchez | |
118 | 10740 | nacho | mapControl.getMapContext().beginAtomicEvent(); |
119 | 12050 | bsanchez | |
120 | 10740 | nacho | for (int iFile = 0; iFile < getFiles().length; iFile++) { |
121 | File fich = getFiles()[iFile];
|
||
122 | String layerName = fich.getName();
|
||
123 | try{
|
||
124 | 12050 | bsanchez | |
125 | 11647 | nacho | try {
|
126 | lyr = FLyrRasterSE.createLayer(layerName, fich, proj); |
||
127 | } catch (LoadLayerException e) {
|
||
128 | JOptionPane.showMessageDialog(
|
||
129 | (Component) PluginServices.getMainFrame(), PluginServices.getText(
|
||
130 | this, "coordenadas_erroneas")); |
||
131 | 10740 | nacho | } |
132 | 12050 | bsanchez | |
133 | 10740 | nacho | if (lyr != null) { |
134 | lyr.setVisible(true);
|
||
135 | if (mapControl.getMapContext().getViewPort().getExtent() == null) |
||
136 | first = true;
|
||
137 | //checkProjection(lyr, mapControl.getViewPort());
|
||
138 | mapControl.getMapContext().getLayers().addLayer(lyr); |
||
139 | rects[iFile] = lyr.getFullExtent(); |
||
140 | } |
||
141 | }catch(ReadDriverException e){
|
||
142 | 12050 | bsanchez | |
143 | 10740 | nacho | }catch(ExpansionFileReadException e1){
|
144 | 12050 | bsanchez | |
145 | 10740 | nacho | } |
146 | } |
||
147 | 12050 | bsanchez | |
148 | 10740 | nacho | if (rects.length > 1) { |
149 | Rectangle2D rect = new Rectangle2D.Double(); |
||
150 | rect.setRect(rects[0]);
|
||
151 | |||
152 | if (first) {
|
||
153 | for (int i = 0; i < rects.length; i++) { |
||
154 | if (rects[i] != null) { |
||
155 | rect.add(rects[i]); |
||
156 | } |
||
157 | } |
||
158 | mapControl.getMapContext().getViewPort().setExtent(rect); |
||
159 | } |
||
160 | } |
||
161 | mapControl.getMapContext().endAtomicEvent(); |
||
162 | } |
||
163 | |||
164 | public FLayer getLayer() {
|
||
165 | return null; |
||
166 | } |
||
167 | 12050 | bsanchez | |
168 | /**
|
||
169 | * @param driverClasses2
|
||
170 | * @param b
|
||
171 | */
|
||
172 | 11191 | bsanchez | private void init(Class[] driverClasses, boolean proj) { |
173 | this.proj = proj;
|
||
174 | 10740 | nacho | |
175 | 11647 | nacho | initialize(); |
176 | } |
||
177 | 10740 | nacho | |
178 | 12050 | bsanchez | /**
|
179 | * Creates a new FOpenDialog object.
|
||
180 | *
|
||
181 | * @param view Vista que vamos a refrescar
|
||
182 | * @param mapControl MapControl que recibe la capa (te puede interesar
|
||
183 | * a?adirla al principal o al Overview.
|
||
184 | */
|
||
185 | public FileOpenRasterDialog(Class[] driverClasses, boolean proj) { |
||
186 | init(driverClasses, proj); |
||
187 | } |
||
188 | 10740 | nacho | |
189 | 12050 | bsanchez | public FileOpenRasterDialog(Class[] driverClasses, boolean proj, String title) { |
190 | this.title= title;
|
||
191 | init(driverClasses, proj); |
||
192 | } |
||
193 | 10740 | nacho | |
194 | 12050 | bsanchez | /**
|
195 | * This method initializes this
|
||
196 | */
|
||
197 | private void initialize() { |
||
198 | this.setLayout(new BorderLayout()); |
||
199 | this.setSize(514, 280); |
||
200 | this.setLayout(null); |
||
201 | this.add(getJPanel2(), null); |
||
202 | } |
||
203 | 10740 | nacho | |
204 | 12050 | bsanchez | /**
|
205 | * DOCUMENT ME!
|
||
206 | *
|
||
207 | * @return DOCUMENT ME!
|
||
208 | */
|
||
209 | public File[] getFiles() { |
||
210 | MyFile[] files = (MyFile[]) getListManagerDemoSkin().getListManager().getListModel().getObjects().toArray(new MyFile[0]); |
||
211 | File[] ret = new File[files.length]; |
||
212 | int pos=files.length-1; |
||
213 | for (int i=0; i < files.length; i++){ |
||
214 | ret[pos] = files[i].f; |
||
215 | pos--; |
||
216 | } |
||
217 | return ret;
|
||
218 | } |
||
219 | 10740 | nacho | |
220 | 12050 | bsanchez | public boolean accept(File f){ |
221 | return fileChooser.getFileFilter().accept(f);
|
||
222 | } |
||
223 | 11191 | bsanchez | |
224 | 12050 | bsanchez | /**
|
225 | * This method initializes jPanel2
|
||
226 | *
|
||
227 | * @return javax.swing.JPanel
|
||
228 | */
|
||
229 | private javax.swing.JPanel getJPanel2() {
|
||
230 | if (jPanel2 == null) { |
||
231 | javax.swing.border.TitledBorder titledBorder1 = javax.swing.BorderFactory.createTitledBorder(null,
|
||
232 | PluginServices.getText(this,"Seleccionar_fichero"), |
||
233 | javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
||
234 | javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null); |
||
235 | jPanel2 = new javax.swing.JPanel();
|
||
236 | jPanel2.setLayout(null);
|
||
237 | jPanel2.setBorder(titledBorder1); |
||
238 | jPanel2.setPreferredSize(new java.awt.Dimension(380,200)); |
||
239 | jPanel2.setBounds(2, 2, 506, 472); |
||
240 | titledBorder1.setTitle(this.title);
|
||
241 | if (proj) {
|
||
242 | jPanel2.add(getJPanelProj(), null);
|
||
243 | } |
||
244 | jPanel2.add(getListManagerDemoSkin(), null);
|
||
245 | } |
||
246 | 10740 | nacho | |
247 | 12050 | bsanchez | return jPanel2;
|
248 | } |
||
249 | 10740 | nacho | |
250 | 12050 | bsanchez | public String[] getDriverNames(){ |
251 | MyFile[] files = (MyFile[]) getListManagerDemoSkin().getListManager().getListModel().getObjects().toArray(new MyFile[0]); |
||
252 | String[] ret = new String[files.length]; |
||
253 | int pos=files.length-1; |
||
254 | 11191 | bsanchez | |
255 | 12050 | bsanchez | for (int i=0; i < files.length; i++) |
256 | { |
||
257 | ret[pos] = files[i].getDriverName(); |
||
258 | pos--; |
||
259 | } |
||
260 | return ret;
|
||
261 | } |
||
262 | 10740 | nacho | |
263 | 12050 | bsanchez | public class DriverFileFilter extends FileFilter { |
264 | |||
265 | 11647 | nacho | public DriverFileFilter() {
|
266 | 10740 | nacho | } |
267 | 12050 | bsanchez | |
268 | 10740 | nacho | /**
|
269 | * @see javax.swing.filechooser.FileFilter#accept(java.io.File)
|
||
270 | */
|
||
271 | 11670 | nacho | public synchronized boolean accept(File f) { |
272 | 12050 | bsanchez | if (f.isDirectory())
|
273 | 11647 | nacho | return true; |
274 | return FLyrRasterSE.isFileAccepted(f);
|
||
275 | 10740 | nacho | } |
276 | |||
277 | /**
|
||
278 | * @see javax.swing.filechooser.FileFilter#getDescription()
|
||
279 | */
|
||
280 | public String getDescription() { |
||
281 | 11647 | nacho | return "gvSIG Raster Driver"; |
282 | 10740 | nacho | } |
283 | } |
||
284 | |||
285 | /**
|
||
286 | * This method initializes jPanel
|
||
287 | *
|
||
288 | * @return javax.swing.JPanel
|
||
289 | */
|
||
290 | private CRSSelectPanel getJPanelProj() {
|
||
291 | if (jPanelProj == null) { |
||
292 | IProjection proj = CRSFactory.getCRS("EPSG:23030");
|
||
293 | if (PluginServices.getMainFrame() != null) { |
||
294 | proj = FOpenDialog.getLastProjection(); |
||
295 | } |
||
296 | |||
297 | jPanelProj = CRSSelectPanel.getPanel(proj); |
||
298 | jPanelProj.setTransPanelActive(true);
|
||
299 | jPanelProj.setBounds(11, 400, 448, 35); |
||
300 | jPanelProj.setPreferredSize(new java.awt.Dimension(448,35)); |
||
301 | jPanelProj.addActionListener(new java.awt.event.ActionListener() {
|
||
302 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
303 | 12050 | bsanchez | if (jPanelProj.isOkPressed()) {
|
304 | FOpenDialog.setLastProjection(jPanelProj.getCurProj()); |
||
305 | } |
||
306 | 10740 | nacho | } |
307 | }); |
||
308 | |||
309 | } |
||
310 | return jPanelProj;
|
||
311 | } |
||
312 | |||
313 | public class MyFile { |
||
314 | private File f; |
||
315 | private String driverName; |
||
316 | |||
317 | public MyFile(File f, String driverName){ |
||
318 | this.f = f;
|
||
319 | this.driverName = driverName;
|
||
320 | } |
||
321 | |||
322 | public String toString(){ |
||
323 | return f.getName();
|
||
324 | } |
||
325 | 11191 | bsanchez | |
326 | 10740 | nacho | public String getDriverName(){ |
327 | return driverName;
|
||
328 | } |
||
329 | } |
||
330 | |||
331 | /**
|
||
332 | * This method initializes listManagerDemoSkin
|
||
333 | *
|
||
334 | * @return com.iver.utiles.listManager.ListManagerDemoSkin
|
||
335 | */
|
||
336 | private ListManagerSkin getListManagerDemoSkin() {
|
||
337 | if (listManagerDemoSkin == null) { |
||
338 | listManagerDemoSkin = new ListManagerSkin(false); |
||
339 | listManagerDemoSkin.setBounds(11, 21, 491, 363); |
||
340 | listManagerDemoSkin.getListManager().setListener(this);
|
||
341 | } |
||
342 | return listManagerDemoSkin;
|
||
343 | } |
||
344 | |||
345 | public Object getProperties(Object selected) { |
||
346 | return null; |
||
347 | } |
||
348 | 12050 | bsanchez | |
349 | 10740 | nacho | public Object[] addObjects() { |
350 | this.callStateChanged(true); |
||
351 | 12118 | bsanchez | |
352 | 12050 | bsanchez | fileChooser = new JFileChooser(RasterModule.getPath()); |
353 | fileChooser.setMultiSelectionEnabled(true);
|
||
354 | fileChooser.setAcceptAllFileFilterUsed(false);
|
||
355 | 10740 | nacho | |
356 | 12050 | bsanchez | DriverFileFilter element = new DriverFileFilter();
|
357 | fileChooser.addChoosableFileFilter(element); |
||
358 | |||
359 | 10740 | nacho | int result = fileChooser.showOpenDialog(FileOpenRasterDialog.this);
|
360 | |||
361 | 12050 | bsanchez | File[] newFiles = null; |
362 | MyFile[] toAdd;
|
||
363 | if (result == JFileChooser.APPROVE_OPTION) { |
||
364 | // lastFileFilter = (DriverFileFilter) fileChooser.getFileFilter();
|
||
365 | RasterModule.setPath(fileChooser.getCurrentDirectory().getAbsolutePath()); |
||
366 | newFiles = fileChooser.getSelectedFiles(); |
||
367 | toAdd = new MyFile[newFiles.length];
|
||
368 | for (int ind = 0; ind < newFiles.length; ind++) { |
||
369 | String driverName = ((DriverFileFilter) fileChooser.getFileFilter()).getDescription();
|
||
370 | toAdd[ind] = new MyFile(newFiles[ind], driverName);
|
||
371 | } |
||
372 | 10740 | nacho | |
373 | 12050 | bsanchez | return toAdd;
|
374 | } else
|
||
375 | return new Object[0]; |
||
376 | 10740 | nacho | } |
377 | 11191 | bsanchez | } |