root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / FileOpenDialog.java @ 1346
History | View | Annotate | Download (12.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 com.iver.cit.gvsig.gui; |
48 |
|
49 |
import java.awt.BorderLayout; |
50 |
import java.io.File; |
51 |
import java.util.ArrayList; |
52 |
import java.util.Iterator; |
53 |
import java.util.Vector; |
54 |
|
55 |
import javax.swing.DefaultComboBoxModel; |
56 |
import javax.swing.DefaultListModel; |
57 |
import javax.swing.JFileChooser; |
58 |
import javax.swing.JPanel; |
59 |
import javax.swing.filechooser.FileFilter; |
60 |
|
61 |
import com.hardcode.driverManager.Driver; |
62 |
import com.hardcode.driverManager.DriverLoadException; |
63 |
import com.hardcode.gdbms.engine.data.FileDriver; |
64 |
import com.iver.andami.PluginServices; |
65 |
import com.iver.andami.messages.NotificationManager; |
66 |
import com.iver.cit.gvsig.fmap.drivers.RasterDriver; |
67 |
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
68 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
69 |
import com.iver.cit.gvsig.gui.Panels.ProjChooserPanel; |
70 |
|
71 |
import javax.swing.JComboBox; |
72 |
|
73 |
import org.cresques.cts.IProjection; |
74 |
import org.cresques.cts.ProjectionPool; |
75 |
import com.iver.utiles.listManager.ListManagerListener; |
76 |
/**
|
77 |
* Di?logo para cargar las dieferentes capas a la vista.
|
78 |
*
|
79 |
* @author Vicente Caballero Navarro
|
80 |
*/
|
81 |
public class FileOpenDialog extends JPanel{ |
82 |
// TODO LWS ?los m_Files ... ?tendr?an que ser GeoFiles (Projected y dem?s)?
|
83 |
private static String lastPath = null; |
84 |
private ArrayList m_Files; |
85 |
private javax.swing.JPanel jPanel2 = null; |
86 |
private DefaultListModel m_lstModel; |
87 |
private JFileChooser fileChooser; |
88 |
private Class[] driverClasses; |
89 |
|
90 |
private ProjChooserPanel jPanelProj = null; |
91 |
//private JLabel jLabel = null;
|
92 |
//private JComboBox jCboProjections = null;
|
93 |
private ListManagerSkin listManagerDemoSkin = null; |
94 |
/**
|
95 |
* Creates a new FOpenDialog object.
|
96 |
*
|
97 |
* @param view Vista que vamos a refrescar
|
98 |
* @param mapControl MapControl que recibe la capa (te puede interesar
|
99 |
* a?adirla al principal o al Overview.
|
100 |
*/
|
101 |
public FileOpenDialog(Class[] driverClasses) { |
102 |
initialize(); |
103 |
|
104 |
m_Files = new ArrayList(); |
105 |
|
106 |
this.driverClasses = driverClasses;
|
107 |
|
108 |
// Cada vez que se abre, se borran las capas que pudiera haber.
|
109 |
m_lstModel = new DefaultListModel(); |
110 |
} |
111 |
|
112 |
/**
|
113 |
* This method initializes this
|
114 |
*/
|
115 |
private void initialize() { |
116 |
this.setLayout(new BorderLayout()); |
117 |
this.setSize(514, 280); |
118 |
this.setLayout(null); |
119 |
// this.setBorder(javax.swing.BorderFactory.createBevelBorder(
|
120 |
// javax.swing.border.BevelBorder.RAISED));
|
121 |
this.add(getJPanel2(), null); |
122 |
} |
123 |
|
124 |
/**
|
125 |
* DOCUMENT ME!
|
126 |
*
|
127 |
* @return DOCUMENT ME!
|
128 |
*/
|
129 |
public File[] getFiles() { |
130 |
MyFile[] files = (MyFile[]) getListManagerDemoSkin().getListManager().getListModel().getObjects().toArray(new MyFile[0]); |
131 |
File[] ret = new File[files.length]; |
132 |
|
133 |
for (int i=0; i < files.length; i++) |
134 |
{ |
135 |
ret[i] = files[i].f; |
136 |
} |
137 |
return ret;
|
138 |
} |
139 |
|
140 |
/**
|
141 |
* This method initializes jPanel2
|
142 |
*
|
143 |
* @return javax.swing.JPanel
|
144 |
*/
|
145 |
private javax.swing.JPanel getJPanel2() {
|
146 |
if (jPanel2 == null) { |
147 |
javax.swing.border.TitledBorder titledBorder1 = javax.swing.BorderFactory.createTitledBorder(null,
|
148 |
PluginServices.getText(this,"Seleccionar_fichero"), |
149 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
150 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null); |
151 |
jPanel2 = new javax.swing.JPanel();
|
152 |
jPanel2.setLayout(null);
|
153 |
jPanel2.setBorder(titledBorder1); |
154 |
jPanel2.setPreferredSize(new java.awt.Dimension(380,200)); |
155 |
jPanel2.setBounds(2, 2, 510, 272); |
156 |
titledBorder1.setTitle(PluginServices.getText(this,"Capas")); |
157 |
jPanel2.add(getJPanelProj(), null);
|
158 |
jPanel2.add(getListManagerDemoSkin(), null);
|
159 |
} |
160 |
|
161 |
return jPanel2;
|
162 |
} |
163 |
|
164 |
public String[] getDriverNames(){ |
165 |
MyFile[] files = (MyFile[]) getListManagerDemoSkin().getListManager().getListModel().getObjects().toArray(new MyFile[0]); |
166 |
String[] ret = new String[files.length]; |
167 |
|
168 |
for (int i=0; i < files.length; i++) |
169 |
{ |
170 |
ret[i] = files[i].getDriverName(); |
171 |
} |
172 |
return ret;
|
173 |
|
174 |
// return ((DriverFileFilter) fileChooser.getFileFilter()).getDescription();
|
175 |
} |
176 |
|
177 |
public class DriverFileFilter extends FileFilter{ |
178 |
|
179 |
private Driver driver; |
180 |
|
181 |
public DriverFileFilter(String driverName) throws DriverLoadException{ |
182 |
driver = LayerFactory.getDM().getDriver(driverName); |
183 |
} |
184 |
|
185 |
/**
|
186 |
* @see javax.swing.filechooser.FileFilter#accept(java.io.File)
|
187 |
*/
|
188 |
public boolean accept(File f) { |
189 |
if (f.isDirectory()) return true; |
190 |
if (driver instanceof VectorialFileDriver){ |
191 |
return ((VectorialFileDriver) driver).accept(f);
|
192 |
}else if (driver instanceof FileDriver){ |
193 |
return ((FileDriver) driver).fileAccepted(f);
|
194 |
}else if (driver instanceof RasterDriver){ |
195 |
return ((RasterDriver) driver).fileAccepted(f);
|
196 |
}else{
|
197 |
throw new RuntimeException("Tipo no reconocido"); |
198 |
} |
199 |
} |
200 |
|
201 |
/**
|
202 |
* @see javax.swing.filechooser.FileFilter#getDescription()
|
203 |
*/
|
204 |
public String getDescription() { |
205 |
return ((Driver) driver).getName(); |
206 |
} |
207 |
} |
208 |
|
209 |
public void setDriverClasses(Class[] driverClasses) { |
210 |
this.driverClasses = driverClasses;
|
211 |
} |
212 |
/**
|
213 |
* This method initializes jPanel
|
214 |
*
|
215 |
* @return javax.swing.JPanel
|
216 |
*/
|
217 |
private ProjChooserPanel getJPanelProj() {
|
218 |
if (jPanelProj == null) { |
219 |
jPanelProj = new ProjChooserPanel(FOpenDialog.getLastProjection());
|
220 |
jPanelProj.setBounds(11, 214, 448, 35); |
221 |
jPanelProj.setPreferredSize(new java.awt.Dimension(448,35)); |
222 |
jPanelProj.addActionListener(new java.awt.event.ActionListener() {
|
223 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
224 |
if (jPanelProj.isOkPressed()) {
|
225 |
FOpenDialog.setLastProjection(jPanelProj.getCurProj()); |
226 |
} |
227 |
} |
228 |
}); |
229 |
/* jPanel = new JLabel();
|
230 |
jPanel.setBounds(11, 214, 448, 37);
|
231 |
jLabel.setText("Seleccione la proyecci?n:");
|
232 |
jPanel.add(jLabel, null);
|
233 |
jPanel.add(getJCboProjections(), null);*/
|
234 |
} |
235 |
return jPanelProj;
|
236 |
} |
237 |
/**
|
238 |
* This method initializes jComboBox
|
239 |
*
|
240 |
* @return javax.swing.JComboBox
|
241 |
* /
|
242 |
private JComboBox getJCboProjections() {
|
243 |
if (jCboProjections == null) {
|
244 |
Iterator it = ProjectionPool.iterator();
|
245 |
Vector vector = new Vector();
|
246 |
int selected = -1;
|
247 |
int i=0;
|
248 |
while (it.hasNext())
|
249 |
{
|
250 |
IProjection auxP =(IProjection) it.next();
|
251 |
if (auxP == FOpenDialog.getLastProjection())
|
252 |
selected = i;
|
253 |
vector.add(auxP.getAbrev());
|
254 |
i++;
|
255 |
}
|
256 |
DefaultComboBoxModel cModel = new DefaultComboBoxModel(vector);
|
257 |
cModel.setSelectedItem(vector.get(selected));
|
258 |
jCboProjections = new JComboBox(cModel);
|
259 |
jCboProjections.setPreferredSize(new java.awt.Dimension(124,19));
|
260 |
jCboProjections.addActionListener(new java.awt.event.ActionListener() {
|
261 |
public void actionPerformed(java.awt.event.ActionEvent e) {
|
262 |
System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
|
263 |
String strProj = (String) jCboProjections.getSelectedItem();
|
264 |
FOpenDialog.setLastProjection(ProjectionPool.get(strProj));
|
265 |
}
|
266 |
});
|
267 |
}
|
268 |
return jCboProjections;
|
269 |
}*/
|
270 |
|
271 |
public class MyFile { |
272 |
private File f; |
273 |
private String driverName; |
274 |
|
275 |
public MyFile(File f, String driverName){ |
276 |
this.f = f;
|
277 |
this.driverName = driverName;
|
278 |
} |
279 |
|
280 |
public String toString(){ |
281 |
return f.getName();
|
282 |
} |
283 |
public String getDriverName(){ |
284 |
return driverName;
|
285 |
} |
286 |
|
287 |
} |
288 |
|
289 |
/**
|
290 |
* This method initializes listManagerDemoSkin
|
291 |
*
|
292 |
* @return com.iver.utiles.listManager.ListManagerDemoSkin
|
293 |
*/
|
294 |
private ListManagerSkin getListManagerDemoSkin() {
|
295 |
if (listManagerDemoSkin == null) { |
296 |
listManagerDemoSkin = new ListManagerSkin();
|
297 |
listManagerDemoSkin.setBounds(11, 21, 491, 164); |
298 |
listManagerDemoSkin.getListManager().setListener(new ListManagerListener() {
|
299 |
public Object[] addObjects() { |
300 |
fileChooser = new JFileChooser(lastPath); |
301 |
fileChooser.setMultiSelectionEnabled(true);
|
302 |
fileChooser.setAcceptAllFileFilterUsed(false);
|
303 |
|
304 |
try {
|
305 |
String[] driverNames = LayerFactory.getDM().getDriverNames(); |
306 |
FileFilter defaultFileFilter = null, auxF; |
307 |
for (int i = 0; i < driverNames.length; i++) { |
308 |
System.err.println("DRIVER "+i+" : "+driverNames[i]); |
309 |
boolean is = false; |
310 |
for (int j = 0; j < driverClasses.length; j++) { |
311 |
if (i == 0) System.err.println("DRIVER CLASS "+j+" : "+driverClasses[j].toString()); |
312 |
if (LayerFactory.getDM().isA(driverNames[i], driverClasses[j]))
|
313 |
is = true;
|
314 |
} |
315 |
if (is){
|
316 |
auxF = new DriverFileFilter(driverNames[i]);
|
317 |
fileChooser.addChoosableFileFilter(auxF); |
318 |
if (driverNames[i].indexOf("shp") != -1) |
319 |
{ |
320 |
defaultFileFilter = auxF; |
321 |
} |
322 |
} |
323 |
} |
324 |
if (defaultFileFilter != null) |
325 |
fileChooser.setFileFilter(defaultFileFilter); |
326 |
} catch (DriverLoadException e1) {
|
327 |
NotificationManager.addError("No se pudo acceder a los drivers", e1);
|
328 |
} |
329 |
|
330 |
int result = fileChooser.showOpenDialog(FileOpenDialog.this);
|
331 |
|
332 |
File[] newFiles = null; |
333 |
MyFile[] toAdd;
|
334 |
if (result == JFileChooser.APPROVE_OPTION) { |
335 |
lastPath = fileChooser.getCurrentDirectory().getAbsolutePath(); |
336 |
newFiles = fileChooser.getSelectedFiles(); |
337 |
toAdd = new MyFile[newFiles.length];
|
338 |
for (int ind=0; ind < newFiles.length; ind++) |
339 |
{ |
340 |
String driverName = ((DriverFileFilter) fileChooser.getFileFilter()).getDescription();
|
341 |
toAdd[ind] = new MyFile(newFiles[ind], driverName);
|
342 |
} |
343 |
|
344 |
|
345 |
return toAdd;
|
346 |
} |
347 |
else
|
348 |
return new Object[0]; |
349 |
|
350 |
// DefaultListModel lstModel = new DefaultListModel();
|
351 |
/*
|
352 |
for (int iFile = 0; iFile < newFiles.length;
|
353 |
iFile++) {
|
354 |
File theFile = newFiles[iFile];
|
355 |
String absolutePath = theFile.getAbsolutePath();
|
356 |
lastPath = theFile.getParent();
|
357 |
// Miramos por si es un ecwp:
|
358 |
int test = absolutePath.indexOf("ecwp:");
|
359 |
if (test == -1)
|
360 |
m_lstModel.addElement(absolutePath);
|
361 |
else
|
362 |
m_lstModel.addElement(absolutePath.substring(test));
|
363 |
}
|
364 |
|
365 |
getJListLayers().setModel(m_lstModel);*/
|
366 |
|
367 |
} |
368 |
|
369 |
public Object getProperties(Object selected) { |
370 |
return null; |
371 |
} |
372 |
}); |
373 |
} |
374 |
return listManagerDemoSkin;
|
375 |
} |
376 |
} // @jve:decl-index=0:visual-constraint="10,10"
|
377 |
// @jve:visual-info decl-index=0 visual-constraint="10,10"
|
378 |
// @jve:visual-info decl-index=0 visual-constraint="10,10"
|