1 24 25 package org.gjt.sp.jedit.io; 26 27 import javax.swing.filechooser.FileSystemView ; 29 import java.awt.Component ; 30 import java.io.File ; 31 import java.util.LinkedList ; 32 import org.gjt.sp.jedit.MiscUtilities; 33 import org.gjt.sp.jedit.OperatingSystem; 34 36 41 public class FileRootsVFS extends VFS 42 { 43 public static final String PROTOCOL = "roots"; 44 45 public FileRootsVFS() 47 { 48 super("roots",LOW_LATENCY_CAP,new String [] { 49 EA_TYPE }); 50 } 52 public String getParentOfPath(String path) 54 { 55 return PROTOCOL + ':'; 56 } 58 public VFSFile[] _listFiles(Object session, String url, 60 Component comp) 61 { 62 File [] roots = listRoots(); 63 64 if(roots == null) 65 return null; 66 67 VFSFile[] rootDE = new VFSFile[roots.length]; 68 for(int i = 0; i < roots.length; i++) 69 rootDE[i] = new Root(roots[i]); 70 71 return rootDE; 72 } 74 public VFSFile _getFile(Object session, String path, 76 Component comp) 77 { 78 return new Root(new File (path)); 79 } 81 private static FileSystemView fsView = FileSystemView.getFileSystemView(); 83 84 private static File [] listRoots() 86 { 87 if (OperatingSystem.isMacOS()) 88 { 89 File [] volumes = new File ("/Volumes").listFiles(); 91 LinkedList <File > roots = new LinkedList <File >(); 92 93 roots.add(new File ("/")); 94 95 for (int i=0; i<volumes.length; i++) 96 { 97 if (volumes[i].isDirectory()) 99 roots.add(volumes[i]); 100 } 101 102 return roots.toArray(new File [roots.size()]); 103 } 104 else 105 { 106 File [] roots = File.listRoots(); 107 File [] desktop = fsView.getRoots(); 108 109 if(desktop == null) 110 return roots; 111 112 File [] rootsPlus = new File [roots.length + desktop.length]; 113 System.arraycopy(desktop, 0, rootsPlus, 0, desktop.length); 114 System.arraycopy(roots, 0, rootsPlus, 1, roots.length); 115 return rootsPlus; 116 } 117 } 119 121 static class Root extends VFSFile 123 { 124 Root(File file) 125 { 126 129 String path = file.getPath(); 130 setPath(path); 131 setDeletePath(path); 132 setSymlinkPath(path); 133 134 if(fsView.isFloppyDrive(file)) 135 { 136 setType(VFSFile.FILESYSTEM); 137 setName(path); 138 } 139 else if(fsView.isDrive(file)) 140 { 141 setType(VFSFile.FILESYSTEM); 142 setName(path + ' ' 143 + fsView.getSystemDisplayName(file)); 144 } 145 else if(file.isDirectory()) 146 { 147 if(fsView.isFileSystemRoot(file)) 148 setType(VFSFile.DIRECTORY); 149 else 150 setType(VFSFile.FILESYSTEM); 151 152 if(OperatingSystem.isMacOS()) 153 setName(MiscUtilities.getFileName(path)); 154 else 155 setName(path); 156 } 157 else 158 setType(VFSFile.FILE); 159 } 160 161 public String getExtendedAttribute(String name) 162 { 163 if(name.equals(EA_TYPE)) 164 return super.getExtendedAttribute(name); 165 else 166 { 167 return null; 170 } 171 } 172 } } 174 | Popular Tags |