root / trunk / libraries / libUIComponent_praster / src / org / gvsig / gui / beans / openFile / listeners / OpenFileListener.java @ 8026
History | View | Annotate | Download (2.26 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 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 |
package org.gvsig.gui.beans.openFile.listeners; |
20 |
|
21 |
import java.awt.event.ActionEvent; |
22 |
import java.awt.event.ActionListener; |
23 |
import java.io.File; |
24 |
|
25 |
import javax.swing.JButton; |
26 |
import javax.swing.JFileChooser; |
27 |
|
28 |
import org.gvsig.gui.beans.openFile.OpenFileContainer; |
29 |
|
30 |
public class OpenFileListener implements ActionListener{ |
31 |
|
32 |
private JButton button = null; |
33 |
private String fName = null; |
34 |
private OpenFileContainer controlPanel= null; |
35 |
|
36 |
public OpenFileListener(OpenFileContainer panel){
|
37 |
this.controlPanel = panel;
|
38 |
} |
39 |
|
40 |
public void setButton(JButton but){ |
41 |
this.button = but;
|
42 |
} |
43 |
|
44 |
|
45 |
public void actionPerformed(ActionEvent e) { |
46 |
if(e.getSource() == this.button){ |
47 |
JFileChooser file = new JFileChooser(); |
48 |
file.setDialogTitle("Select File");
|
49 |
file.addChoosableFileFilter(new ReadFilter(file, "raw")); |
50 |
int returnVal = file.showOpenDialog(controlPanel);
|
51 |
if(returnVal == JFileChooser.APPROVE_OPTION){ |
52 |
fName = file.getSelectedFile().toString(); |
53 |
controlPanel.getTOpen().setText(fName); |
54 |
} |
55 |
} |
56 |
|
57 |
} |
58 |
|
59 |
public String getFileName(){ |
60 |
return fName;
|
61 |
} |
62 |
|
63 |
} |
64 |
|
65 |
class ReadFilter extends javax.swing.filechooser.FileFilter{ |
66 |
|
67 |
JFileChooser chooser = null; |
68 |
String filter = null; |
69 |
|
70 |
public ReadFilter(JFileChooser cho,String fil){ |
71 |
this.chooser = cho;
|
72 |
this.filter = fil;
|
73 |
} |
74 |
|
75 |
public boolean accept(File f) { |
76 |
return f.isDirectory() || f.getName().toLowerCase().endsWith("."+filter); |
77 |
} |
78 |
|
79 |
public String getDescription() { |
80 |
return "."+filter; |
81 |
} |
82 |
|
83 |
} |