1 package snow.utils.gui; 2 3 import java.io.File ; 4 import java.awt.*; 5 import javax.swing.*; 6 import javax.swing.filechooser.*; 7 8 10 public class FileViewWithAttributes extends FileView 11 { 12 final static int fontSize = UIManager.getFont("Tree.font").getSize(); 13 private final FileIcon fileIcon = new FileIcon(false, fontSize+2); 14 private final FileIcon dirIcon = new FileIcon(true, fontSize+2); 15 16 19 public String getName(File file) 20 { 21 String filename = file.getName(); 22 if (filename.endsWith(".java")) 23 { 24 return filename; 26 } 27 return null; 28 } 29 30 private boolean isRoot(File f) 31 { 32 File [] roots = File.listRoots(); 33 for(int i=0; i<roots.length; i++) 34 { 35 if(roots[i].equals(f)) return true; 36 } 37 return false; 38 } 39 40 43 public Icon getIcon(File file) 44 { 45 if(isRoot(file)) return null; 48 49 if (file.isDirectory()) 50 { 51 if(file.canWrite() && file.canRead()) 52 { 53 dirIcon.setType(FileIcon.IconColor.Green); 54 return dirIcon; 55 } 56 if(file.canRead()) 57 { 58 dirIcon.setType(FileIcon.IconColor.Red); 59 return dirIcon; 60 } 61 dirIcon.setType(FileIcon.IconColor.RedGreen); 62 return dirIcon; 63 } 64 65 67 if(file.canWrite() && file.canRead()) 68 { 69 fileIcon.setType(FileIcon.IconColor.Green); 70 return fileIcon; 71 } 72 if(file.canRead()) 73 { 74 fileIcon.setType(FileIcon.IconColor.Red); 75 return fileIcon; 76 } 77 78 fileIcon.setType(FileIcon.IconColor.RedGreen); 79 return fileIcon; 80 } 81 82 95 } | Popular Tags |