001    // GraphLab Project: http://graphlab.sharif.edu
002    // Copyright (C) 2008 Mathematical Science Department of Sharif University of Technology
003    // Distributed under the terms of the GNU General Public License (GPL): http://www.gnu.org/licenses/
004    
005    package graphlab.ui.components.gpropertyeditor.editors;
006    
007    import javax.swing.*;
008    import java.io.File;
009    
010    /**
011     * @author azin azadi
012    
013     */
014    public class GFileEditor extends GDialogEditor<File> {
015        JFileChooser jf = new JFileChooser();
016        boolean selectDirectory;
017        File lastFile = null;
018    
019        public GFileEditor() {
020            jf.setControlButtonsAreShown(false);
021        }
022    
023        public JComponent getComponent(File initialValue) {
024            lastFile = initialValue;
025            selectDirectory = initialValue.isDirectory();
026            jf.setCurrentDirectory(initialValue);
027            return jf;
028        }
029    
030        public File getEditorValue() {
031            File selectedFile = jf.getSelectedFile();
032            File ret = selectDirectory ? jf.getCurrentDirectory() : selectedFile;
033            if (ret == null)
034                ret = lastFile;
035            return ret;
036        }
037    
038        public void setEditorValue(File value) {
039            jf.setSelectedFile(value);
040        }
041    
042    }