1 18 package org.apache.batik.apps.svgbrowser; 19 20 import java.io.File ; 21 import java.io.IOException ; 22 import java.lang.reflect.Method ; 23 import java.util.Vector ; 24 25 import javax.swing.filechooser.FileSystemView ; 26 27 37 38 51 class WindowsAltFileSystemView extends FileSystemView { 52 public static final String EXCEPTION_CONTAINING_DIR_NULL 53 = "AltFileSystemView.exception.containing.dir.null"; 54 55 public static final String EXCEPTION_DIRECTORY_ALREADY_EXISTS 56 = "AltFileSystemView.exception.directory.already.exists"; 57 58 public static final String NEW_FOLDER_NAME = 59 " AltFileSystemView.new.folder.name"; 60 61 public static final String FLOPPY_DRIVE = 62 "AltFileSystemView.floppy.drive"; 63 64 private static final Object [] noArgs = {}; 65 private static final Class [] noArgTypes = {}; 66 67 private static Method listRootsMethod = null; 68 private static boolean listRootsMethodChecked = false; 69 70 73 public boolean isRoot(File f) { 74 if(!f.isAbsolute()) { 75 return false; 76 } 77 78 String parentPath = f.getParent(); 79 if(parentPath == null) { 80 return true; 81 } else { 82 File parent = new File (parentPath); 83 return parent.equals(f); 84 } 85 } 86 87 90 public File createNewFolder(File containingDir) throws 91 IOException { 92 if(containingDir == null) { 93 throw new IOException (Resources.getString(EXCEPTION_CONTAINING_DIR_NULL)); 94 } 95 File newFolder = null; 96 newFolder = createFileObject(containingDir, 98 Resources.getString(NEW_FOLDER_NAME)); 99 int i = 2; 100 while (newFolder.exists() && (i < 100)) { 101 newFolder = createFileObject 102 (containingDir, Resources.getString(NEW_FOLDER_NAME) + " (" + i + ")"); 103 i++; 104 } 105 106 if(newFolder.exists()) { 107 throw new IOException 108 (Resources.formatMessage(EXCEPTION_DIRECTORY_ALREADY_EXISTS, 109 new Object []{newFolder.getAbsolutePath()})); 110 } else { 111 newFolder.mkdirs(); 112 } 113 114 return newFolder; 115 } 116 117 122 public boolean isHiddenFile(File f) { 123 return false; 124 } 125 126 130 public File [] getRoots() { 131 132 Vector rootsVector = new Vector (); 133 134 FileSystemRoot floppy = new FileSystemRoot(Resources.getString(FLOPPY_DRIVE) 136 + "\\"); 137 rootsVector.addElement(floppy); 138 139 for (char c = 'C'; c <= 'Z'; c++) { 142 char device[] = {c, ':', '\\'}; 143 String deviceName = new String (device); 144 File deviceFile = new FileSystemRoot(deviceName); 145 if (deviceFile != null && deviceFile.exists()) { 146 rootsVector.addElement(deviceFile); 147 } 148 } 149 File [] roots = new File [rootsVector.size()]; 150 rootsVector.copyInto(roots); 151 return roots; 152 } 153 154 class FileSystemRoot extends File { 155 public FileSystemRoot(File f) { 156 super(f, ""); 157 } 158 159 public FileSystemRoot(String s) { 160 super(s); 161 } 162 163 public boolean isDirectory() { 164 return true; 165 } 166 } 167 168 } 169 170 | Popular Tags |