1 36 37 40 41 import javax.swing.*; 42 import javax.swing.filechooser.*; 43 44 import java.io.File ; 45 import java.util.Hashtable ; 46 47 70 public class ExampleFileView extends FileView { 71 private Hashtable icons = new Hashtable (5); 72 private Hashtable fileDescriptions = new Hashtable (5); 73 private Hashtable typeDescriptions = new Hashtable (5); 74 75 80 public String getName(File f) { 81 return null; 82 } 83 84 87 public void putDescription(File f, String fileDescription) { 88 fileDescriptions.put(f, fileDescription); 89 } 90 91 96 public String getDescription(File f) { 97 return (String ) fileDescriptions.get(f); 98 }; 99 100 104 public void putTypeDescription(String extension, String typeDescription) { 105 typeDescriptions.put(extension, typeDescription); 106 } 107 108 113 public void putTypeDescription(File f, String typeDescription) { 114 putTypeDescription(getExtension(f), typeDescription); 115 } 116 117 122 public String getTypeDescription(File f) { 123 return (String ) typeDescriptions.get(getExtension(f)); 124 } 125 126 130 public String getExtension(File f) { 131 String name = f.getName(); 132 if(name != null) { 133 int extensionIndex = name.lastIndexOf('.'); 134 if(extensionIndex < 0) { 135 return null; 136 } 137 return name.substring(extensionIndex+1).toLowerCase(); 138 } 139 return null; 140 } 141 142 146 public void putIcon(String extension, Icon icon) { 147 icons.put(extension, icon); 148 } 149 150 157 public Icon getIcon(File f) { 158 Icon icon = null; 159 String extension = getExtension(f); 160 if(extension != null) { 161 icon = (Icon) icons.get(extension); 162 } 163 return icon; 164 } 165 166 178 public Boolean isTraversable(File f) { 179 return null; }; 184 185 } 186 | Popular Tags |