1 33 34 package edu.rice.cs.util.swing; 35 36 import edu.rice.cs.plt.io.IOUtil; 37 import edu.rice.cs.util.swing.Utilities; 38 39 import java.io.File ; 40 41 import javax.swing.JFileChooser ; 42 import javax.swing.filechooser.FileView ; 44 45 import java.awt.Component ; 46 47 public class FileChooser extends JFileChooser { 48 49 50 protected File _root; 51 52 55 public FileChooser(File root) { 56 super(root); 57 _init(root); 58 } 59 60 61 62 63 private void _init(final File root) { 64 65 _root = root; if (root != null) { 67 if (! root.exists()) _root = null; 68 else if (! root.isDirectory()) _root = root.getParentFile(); 69 } 70 71 setFileSelectionMode(FILES_ONLY); 72 setDialogType(CUSTOM_DIALOG); 73 setApproveButtonText("Select"); 74 } 75 76 public boolean isTraversable(File f) { 77 if (_root == null) return super.isTraversable(f); 78 return f != null && f.isDirectory() && IOUtil.isMember(f, _root); 80 } 81 } 82 | Popular Tags |