PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/org/gjt/sp/jedit/io/FileRootsVFS.java

#
Java | 174 lines | 107 code | 23 blank | 44 comment | 16 complexity | ef63e0ce143f8f91befe22478b7eb6c4 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /*
  2. * FileRootsVFS.java - Local root filesystems VFS
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2000, 2005 Slava Pestov
  7. * Portions copyright (C) 2002 Kris Kopicki
  8. * Portions copyright (C) 2002 Carmine Lucarelli
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version 2
  13. * of the License, or any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  23. */
  24. package org.gjt.sp.jedit.io;
  25. //{{{ Imports
  26. import javax.swing.filechooser.FileSystemView;
  27. import java.awt.Component;
  28. import java.io.File;
  29. import java.util.LinkedList;
  30. import org.gjt.sp.jedit.MiscUtilities;
  31. import org.gjt.sp.jedit.OperatingSystem;
  32. import org.gjt.sp.util.Log;
  33. //}}}
  34. /**
  35. * A VFS that lists local root filesystems.
  36. * @author Slava Pestov
  37. * @version $Id: FileRootsVFS.java 5181 2005-02-10 22:35:18Z spestov $
  38. */
  39. public class FileRootsVFS extends VFS
  40. {
  41. public static final String PROTOCOL = "roots";
  42. //{{{ FileRootsVFS constructor
  43. public FileRootsVFS()
  44. {
  45. super("roots",LOW_LATENCY_CAP,new String[] {
  46. EA_TYPE });
  47. } //}}}
  48. //{{{ getParentOfPath() method
  49. public String getParentOfPath(String path)
  50. {
  51. return PROTOCOL + ":";
  52. } //}}}
  53. //{{{ _listFiles() method
  54. public VFSFile[] _listFiles(Object session, String url,
  55. Component comp)
  56. {
  57. File[] roots = listRoots();
  58. if(roots == null)
  59. return null;
  60. VFSFile[] rootDE = new VFSFile[roots.length];
  61. for(int i = 0; i < roots.length; i++)
  62. rootDE[i] = new Root(roots[i]);
  63. return rootDE;
  64. } //}}}
  65. //{{{ _getFile() method
  66. public VFSFile _getFile(Object session, String path,
  67. Component comp)
  68. {
  69. return new Root(new File(path));
  70. } //}}}
  71. //{{{ Private members
  72. private static FileSystemView fsView = FileSystemView.getFileSystemView();
  73. //{{{ listRoots() method
  74. private static File[] listRoots()
  75. {
  76. if (OperatingSystem.isMacOS())
  77. {
  78. // Nasty hardcoded values
  79. File[] volumes = new File("/Volumes").listFiles();
  80. LinkedList roots = new LinkedList();
  81. roots.add(new File("/"));
  82. for (int i=0; i<volumes.length; i++)
  83. {
  84. // Make sure people don't do stupid things like putting files in /Volumes
  85. if (volumes[i].isDirectory())
  86. roots.add(volumes[i]);
  87. }
  88. return (File[])roots.toArray(new File[0]);
  89. }
  90. else
  91. {
  92. File[] roots = File.listRoots();
  93. File[] desktop = fsView.getRoots();
  94. if(desktop == null)
  95. return roots;
  96. File[] rootsPlus = new File[roots.length + desktop.length];
  97. System.arraycopy(desktop, 0, rootsPlus, 0, desktop.length);
  98. System.arraycopy(roots, 0, rootsPlus, 1, roots.length);
  99. return rootsPlus;
  100. }
  101. } //}}}
  102. //}}}
  103. //{{{ Root class
  104. static class Root extends VFSFile
  105. {
  106. Root(File file)
  107. {
  108. // REMIND: calling isDirectory() on a floppy drive
  109. // displays stupid I/O error dialog box on Windows
  110. String path = file.getPath();
  111. setPath(path);
  112. setDeletePath(path);
  113. setSymlinkPath(path);
  114. if(fsView.isFloppyDrive(file))
  115. {
  116. setType(VFSFile.FILESYSTEM);
  117. setName(path);
  118. }
  119. else if(fsView.isDrive(file))
  120. {
  121. setType(VFSFile.FILESYSTEM);
  122. setName(path + " "
  123. + fsView.getSystemDisplayName(file));
  124. }
  125. else if(file.isDirectory())
  126. {
  127. if(fsView.isFileSystemRoot(file))
  128. setType(VFSFile.DIRECTORY);
  129. else
  130. setType(VFSFile.FILESYSTEM);
  131. if(OperatingSystem.isMacOS())
  132. setName(MiscUtilities.getFileName(path));
  133. else
  134. setName(path);
  135. }
  136. else
  137. setType(VFSFile.FILE);
  138. }
  139. public String getExtendedAttribute(String name)
  140. {
  141. if(name.equals(EA_TYPE))
  142. return super.getExtendedAttribute(name);
  143. else
  144. {
  145. // don't want it to show "0 bytes" for size,
  146. // etc.
  147. return null;
  148. }
  149. }
  150. } //}}}
  151. }