< prev index next >

src/java.desktop/share/classes/sun/awt/shell/ShellFolderManager.java

Print this page




  27 
  28 import java.io.File;
  29 import java.io.FileNotFoundException;
  30 import java.util.concurrent.Callable;
  31 
  32 /**
  33  * @author Michael Martak
  34  * @since 1.4
  35  */
  36 
  37 class ShellFolderManager {
  38     /**
  39      * Create a shell folder from a file.
  40      * Override to return machine-dependent behavior.
  41      */
  42     public ShellFolder createShellFolder(File file) throws FileNotFoundException {
  43         return new DefaultShellFolder(null, file);
  44     }
  45 
  46     /**
  47      * @param key a <code>String</code>
  48      *  "fileChooserDefaultFolder":
  49      *    Returns a <code>File</code> - the default shellfolder for a new filechooser
  50      *  "roots":
  51      *    Returns a <code>File[]</code> - containing the root(s) of the displayable hierarchy
  52      *  "fileChooserComboBoxFolders":
  53      *    Returns a <code>File[]</code> - an array of shellfolders representing the list to
  54      *    show by default in the file chooser's combobox
  55      *   "fileChooserShortcutPanelFolders":
  56      *    Returns a <code>File[]</code> - an array of shellfolders representing well-known
  57      *    folders, such as Desktop, Documents, History, Network, Home, etc.
  58      *    This is used in the shortcut panel of the filechooser on Windows 2000
  59      *    and Windows Me.
  60      *  "fileChooserIcon <icon>":
  61      *    Returns an <code>Image</code> - icon can be ListView, DetailsView, UpFolder, NewFolder or
  62      *    ViewMenu (Windows only).
  63      *
  64      * @return An Object matching the key string.
  65      */
  66     public Object get(String key) {
  67         if (key.equals("fileChooserDefaultFolder")) {
  68             // Return the default shellfolder for a new filechooser
  69             File homeDir = new File(System.getProperty("user.home"));
  70             try {
  71                 return createShellFolder(homeDir);
  72             } catch (FileNotFoundException e) {
  73                 return homeDir;
  74             }
  75         } else if (key.equals("roots")) {
  76             // The root(s) of the displayable hierarchy
  77             return File.listRoots();
  78         } else if (key.equals("fileChooserComboBoxFolders")) {
  79             // Return an array of ShellFolders representing the list to
  80             // show by default in the file chooser's combobox
  81             return get("roots");
  82         } else if (key.equals("fileChooserShortcutPanelFolders")) {
  83             // Return an array of ShellFolders representing well-known
  84             // folders, such as Desktop, Documents, History, Network, Home, etc.
  85             // This is used in the shortcut panel of the filechooser on Windows 2000
  86             // and Windows Me
  87             return new File[] { (File)get("fileChooserDefaultFolder") };
  88         }
  89         return null;
  90     }
  91 
  92     /**
  93      * Does <code>dir</code> represent a "computer" such as a node on the network, or
  94      * "My Computer" on the desktop.
  95      */
  96     public boolean isComputerNode(File dir) {
  97         return false;
  98     }
  99 
 100     public boolean isFileSystemRoot(File dir) {
 101         if (dir instanceof ShellFolder && !((ShellFolder) dir).isFileSystem()) {
 102             return false;
 103         }
 104         return (dir.getParentFile() == null);
 105     }
 106 
 107     protected ShellFolder.Invoker createInvoker() {
 108         return new DirectInvoker();
 109     }
 110 
 111     private static class DirectInvoker implements ShellFolder.Invoker {
 112         public <T> T invoke(Callable<T> task) throws Exception {
 113             return task.call();


  27 
  28 import java.io.File;
  29 import java.io.FileNotFoundException;
  30 import java.util.concurrent.Callable;
  31 
  32 /**
  33  * @author Michael Martak
  34  * @since 1.4
  35  */
  36 
  37 class ShellFolderManager {
  38     /**
  39      * Create a shell folder from a file.
  40      * Override to return machine-dependent behavior.
  41      */
  42     public ShellFolder createShellFolder(File file) throws FileNotFoundException {
  43         return new DefaultShellFolder(null, file);
  44     }
  45 
  46     /**
  47      * @param key a {@code String}
  48      *  "fileChooserDefaultFolder":
  49      *    Returns a {@code File} - the default shellfolder for a new filechooser
  50      *  "roots":
  51      *    Returns a {@code File[]} - containing the root(s) of the displayable hierarchy
  52      *  "fileChooserComboBoxFolders":
  53      *    Returns a {@code File[]} - an array of shellfolders representing the list to
  54      *    show by default in the file chooser's combobox
  55      *   "fileChooserShortcutPanelFolders":
  56      *    Returns a {@code File[]} - an array of shellfolders representing well-known
  57      *    folders, such as Desktop, Documents, History, Network, Home, etc.
  58      *    This is used in the shortcut panel of the filechooser on Windows 2000
  59      *    and Windows Me.
  60      *  "fileChooserIcon <icon>":
  61      *    Returns an {@code Image} - icon can be ListView, DetailsView, UpFolder, NewFolder or
  62      *    ViewMenu (Windows only).
  63      *
  64      * @return An Object matching the key string.
  65      */
  66     public Object get(String key) {
  67         if (key.equals("fileChooserDefaultFolder")) {
  68             // Return the default shellfolder for a new filechooser
  69             File homeDir = new File(System.getProperty("user.home"));
  70             try {
  71                 return createShellFolder(homeDir);
  72             } catch (FileNotFoundException e) {
  73                 return homeDir;
  74             }
  75         } else if (key.equals("roots")) {
  76             // The root(s) of the displayable hierarchy
  77             return File.listRoots();
  78         } else if (key.equals("fileChooserComboBoxFolders")) {
  79             // Return an array of ShellFolders representing the list to
  80             // show by default in the file chooser's combobox
  81             return get("roots");
  82         } else if (key.equals("fileChooserShortcutPanelFolders")) {
  83             // Return an array of ShellFolders representing well-known
  84             // folders, such as Desktop, Documents, History, Network, Home, etc.
  85             // This is used in the shortcut panel of the filechooser on Windows 2000
  86             // and Windows Me
  87             return new File[] { (File)get("fileChooserDefaultFolder") };
  88         }
  89         return null;
  90     }
  91 
  92     /**
  93      * Does {@code dir} represent a "computer" such as a node on the network, or
  94      * "My Computer" on the desktop.
  95      */
  96     public boolean isComputerNode(File dir) {
  97         return false;
  98     }
  99 
 100     public boolean isFileSystemRoot(File dir) {
 101         if (dir instanceof ShellFolder && !((ShellFolder) dir).isFileSystem()) {
 102             return false;
 103         }
 104         return (dir.getParentFile() == null);
 105     }
 106 
 107     protected ShellFolder.Invoker createInvoker() {
 108         return new DirectInvoker();
 109     }
 110 
 111     private static class DirectInvoker implements ShellFolder.Invoker {
 112         public <T> T invoke(Callable<T> task) throws Exception {
 113             return task.call();
< prev index next >