1 34 package org.objectstyle.cayenne.modeler.pref; 35 36 import java.io.File ; 37 38 import javax.swing.JFileChooser ; 39 40 45 public class FSPath extends _FSPath { 46 47 public void updateFromChooser(JFileChooser chooser) { 48 File file = chooser.getSelectedFile(); 49 if (file != null) { 50 setDirectory(file); 51 } 52 } 53 54 public void updateChooser(JFileChooser chooser) { 55 File startDir = getExistingDirectory(false); 56 if (startDir != null) { 57 chooser.setCurrentDirectory(startDir); 58 } 59 } 60 61 public void setDirectory(File file) { 62 63 if (file.isFile()) { 64 setPath(file.getParentFile().getAbsolutePath()); 65 } 66 else { 67 setPath(file.getAbsolutePath()); 68 } 69 } 70 71 public File getExistingDirectory(boolean create) { 72 if (getPath() == null) { 73 return null; 74 } 75 76 File path = new File (getPath()); 77 if (path.isDirectory()) { 78 return path; 79 } 80 81 if (path.isFile()) { 82 return path.getParentFile(); 83 } 84 85 if (create) { 86 path.mkdirs(); 87 return path; 88 } 89 90 return null; 91 } 92 } 93 94 | Popular Tags |