Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / main / java / org / gvsig / gui / beans / openfile / listeners / OpenFileListener.java @ 40561

History | View | Annotate | Download (2.36 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.gui.beans.openfile.listeners;
25

    
26
import java.awt.event.ActionEvent;
27
import java.awt.event.ActionListener;
28
import java.io.File;
29

    
30
import javax.swing.JButton;
31
import javax.swing.JFileChooser;
32

    
33
import org.gvsig.gui.beans.openfile.OpenFileContainer;
34

    
35
public class OpenFileListener implements ActionListener{
36

    
37
        private JButton button = null;
38
        private String fName = null;
39
        private OpenFileContainer controlPanel= null;
40
        
41
        public OpenFileListener(OpenFileContainer panel){
42
                this.controlPanel = panel;
43
        }
44
        
45
        public void setButton(JButton but){
46
                this.button = but;
47
        }
48
        
49
        
50
        public void actionPerformed(ActionEvent e) {
51
                if(e.getSource() == this.button){
52
                        JFileChooser file = new JFileChooser();
53
                        file.setDialogTitle("Select File");
54
                        file.addChoosableFileFilter(new ReadFilter(file, "raw"));
55
                        int returnVal = file.showOpenDialog(controlPanel);
56
                        if(returnVal == JFileChooser.APPROVE_OPTION){
57
                                fName = file.getSelectedFile().toString();
58
                                controlPanel.getTOpen().setText(fName);
59
                        }
60
                }
61
                
62
        }
63

    
64
        public String getFileName(){
65
                return fName;
66
        }
67
        
68
}
69

    
70
class ReadFilter extends javax.swing.filechooser.FileFilter{
71

    
72
        JFileChooser chooser = null;
73
        String filter = null;
74
        
75
        public ReadFilter(JFileChooser cho,String fil){
76
                this.chooser = cho;
77
                this.filter = fil;
78
        }
79
        
80
        public boolean accept(File f) {
81
                 return f.isDirectory() || f.getName().toLowerCase().endsWith("."+filter);
82
        }
83

    
84
        public String getDescription() {
85
                return "."+filter;
86
        }
87
        
88
}