root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / wizards / FileOpenRasterDialog.java @ 12117
History | View | Annotate | Download (10.2 KB)
1 |
/*
|
---|---|
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 |
import java.awt.Component; |
51 |
import java.awt.geom.Rectangle2D; |
52 |
import java.io.File; |
53 |
|
54 |
import javax.swing.JFileChooser; |
55 |
import javax.swing.JOptionPane; |
56 |
import javax.swing.filechooser.FileFilter; |
57 |
|
58 |
import org.cresques.cts.IProjection; |
59 |
import org.gvsig.fmap.layers.FLyrRasterSE; |
60 |
import org.gvsig.rastertools.RasterModule; |
61 |
|
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 |
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException; |
67 |
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 |
public class FileOpenRasterDialog extends WizardPanel implements ListManagerListener { |
78 |
private static final long serialVersionUID = 335310147513197564L; |
79 |
// private static DriverFileFilter lastFileFilter = null;
|
80 |
private javax.swing.JPanel jPanel2 = null; |
81 |
private JFileChooser fileChooser; |
82 |
//private Class[] driverClasses;
|
83 |
private String title = PluginServices.getText(this,"Raster"); |
84 |
private CRSSelectPanel jPanelProj = null; |
85 |
private ListManagerSkin listManagerDemoSkin = null; |
86 |
private boolean proj; |
87 |
|
88 |
public FileOpenRasterDialog() {
|
89 |
init(/*new Class[] {GenericRasterDriver.class }*/null, true); |
90 |
} |
91 |
|
92 |
public void initWizard() { |
93 |
setTabName("Raster");
|
94 |
init(/*new Class[] {GenericRasterDriver.class }*/null, true); |
95 |
} |
96 |
|
97 |
public void execute() { |
98 |
if (getFiles() == null) |
99 |
return;
|
100 |
|
101 |
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 |
|
109 |
if(mapControl == null) |
110 |
return;
|
111 |
|
112 |
FLayer lyr = null;
|
113 |
IProjection proj = FOpenDialog.getLastProjection(); |
114 |
|
115 |
Rectangle2D[] rects = new Rectangle2D[getFiles().length]; |
116 |
boolean first = false; |
117 |
|
118 |
mapControl.getMapContext().beginAtomicEvent(); |
119 |
|
120 |
for (int iFile = 0; iFile < getFiles().length; iFile++) { |
121 |
File fich = getFiles()[iFile];
|
122 |
String layerName = fich.getName();
|
123 |
try{
|
124 |
|
125 |
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 |
} |
132 |
|
133 |
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 |
|
143 |
}catch(ExpansionFileReadException e1){
|
144 |
|
145 |
} |
146 |
} |
147 |
|
148 |
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 |
|
168 |
/**
|
169 |
* @param driverClasses2
|
170 |
* @param b
|
171 |
*/
|
172 |
private void init(Class[] driverClasses, boolean proj) { |
173 |
this.proj = proj;
|
174 |
|
175 |
initialize(); |
176 |
} |
177 |
|
178 |
/**
|
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 |
|
189 |
public FileOpenRasterDialog(Class[] driverClasses, boolean proj, String title) { |
190 |
this.title= title;
|
191 |
init(driverClasses, proj); |
192 |
} |
193 |
|
194 |
/**
|
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 |
|
204 |
/**
|
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 |
|
220 |
public boolean accept(File f){ |
221 |
return fileChooser.getFileFilter().accept(f);
|
222 |
} |
223 |
|
224 |
/**
|
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 |
|
247 |
return jPanel2;
|
248 |
} |
249 |
|
250 |
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 |
|
255 |
for (int i=0; i < files.length; i++) |
256 |
{ |
257 |
ret[pos] = files[i].getDriverName(); |
258 |
pos--; |
259 |
} |
260 |
return ret;
|
261 |
} |
262 |
|
263 |
public class DriverFileFilter extends FileFilter { |
264 |
|
265 |
public DriverFileFilter() {
|
266 |
} |
267 |
|
268 |
/**
|
269 |
* @see javax.swing.filechooser.FileFilter#accept(java.io.File)
|
270 |
*/
|
271 |
public synchronized boolean accept(File f) { |
272 |
if (f.isDirectory())
|
273 |
return true; |
274 |
return FLyrRasterSE.isFileAccepted(f);
|
275 |
} |
276 |
|
277 |
/**
|
278 |
* @see javax.swing.filechooser.FileFilter#getDescription()
|
279 |
*/
|
280 |
public String getDescription() { |
281 |
return "gvSIG Raster Driver"; |
282 |
} |
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 |
if (jPanelProj.isOkPressed()) {
|
304 |
FOpenDialog.setLastProjection(jPanelProj.getCurProj()); |
305 |
} |
306 |
} |
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 |
|
326 |
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 |
|
349 |
public Object[] addObjects() { |
350 |
this.callStateChanged(true); |
351 |
Class c = FLyrRasterSE.class;
|
352 |
fileChooser = new JFileChooser(RasterModule.getPath()); |
353 |
fileChooser.setMultiSelectionEnabled(true);
|
354 |
fileChooser.setAcceptAllFileFilterUsed(false);
|
355 |
|
356 |
DriverFileFilter element = new DriverFileFilter();
|
357 |
fileChooser.addChoosableFileFilter(element); |
358 |
|
359 |
int result = fileChooser.showOpenDialog(FileOpenRasterDialog.this);
|
360 |
|
361 |
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 |
|
373 |
return toAdd;
|
374 |
} else
|
375 |
return new Object[0]; |
376 |
} |
377 |
} |