< prev index next >

src/java.desktop/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java

Print this page




 208                     }
 209                     if (personal != null) {
 210                         personal.setIsPersonal();
 211                     }
 212                 }
 213             } catch (SecurityException e) {
 214                 // Ignore error
 215             } catch (InterruptedException e) {
 216                 // Ignore error
 217             } catch (IOException e) {
 218                 // Ignore error
 219             }
 220         }
 221         return personal;
 222     }
 223 
 224 
 225     private static File[] roots;
 226 
 227     /**
 228      * @param key a <code>String</code>
 229      *  "fileChooserDefaultFolder":
 230      *    Returns a <code>File</code> - the default shellfolder for a new filechooser
 231      *  "roots":
 232      *    Returns a <code>File[]</code> - containing the root(s) of the displayable hierarchy
 233      *  "fileChooserComboBoxFolders":
 234      *    Returns a <code>File[]</code> - an array of shellfolders representing the list to
 235      *    show by default in the file chooser's combobox
 236      *   "fileChooserShortcutPanelFolders":
 237      *    Returns a <code>File[]</code> - an array of shellfolders representing well-known
 238      *    folders, such as Desktop, Documents, History, Network, Home, etc.
 239      *    This is used in the shortcut panel of the filechooser on Windows 2000
 240      *    and Windows Me.
 241      *  "fileChooserIcon <icon>":
 242      *    Returns an <code>Image</code> - icon can be ListView, DetailsView, UpFolder, NewFolder or
 243      *    ViewMenu (Windows only).
 244      *  "optionPaneIcon iconName":
 245      *    Returns an <code>Image</code> - icon from the system icon list
 246      *
 247      * @return An Object matching the key string.
 248      */
 249     public Object get(String key) {
 250         if (key.equals("fileChooserDefaultFolder")) {
 251             File file = getPersonal();
 252             if (file == null) {
 253                 file = getDesktop();
 254             }
 255             return checkFile(file);
 256         } else if (key.equals("roots")) {
 257             // Should be "History" and "Desktop" ?
 258             if (roots == null) {
 259                 File desktop = getDesktop();
 260                 if (desktop != null) {
 261                     roots = new File[] { desktop };
 262                 } else {
 263                     roots = (File[])super.get(key);
 264                 }
 265             }


 398         if (sm == null || files == null || files.length == 0) {
 399             return files;
 400         }
 401         return checkFiles(Arrays.stream(files), sm);
 402     }
 403 
 404     private File[] checkFiles(List<File> files) {
 405         SecurityManager sm = System.getSecurityManager();
 406         if (sm == null || files.isEmpty()) {
 407             return files.toArray(new File[files.size()]);
 408         }
 409         return checkFiles(files.stream(), sm);
 410     }
 411 
 412     private File[] checkFiles(Stream<File> filesStream, SecurityManager sm) {
 413         return filesStream.filter((file) -> checkFile(file, sm) != null)
 414                 .toArray(File[]::new);
 415     }
 416 
 417     /**
 418      * Does <code>dir</code> represent a "computer" such as a node on the network, or
 419      * "My Computer" on the desktop.
 420      */
 421     public boolean isComputerNode(final File dir) {
 422         if (dir != null && dir == getDrives()) {
 423             return true;
 424         } else {
 425             String path = AccessController.doPrivileged(new PrivilegedAction<String>() {
 426                 public String run() {
 427                     return dir.getAbsolutePath();
 428                 }
 429             });
 430 
 431             return (path.startsWith("\\\\") && path.indexOf("\\", 2) < 0);      //Network path
 432         }
 433     }
 434 
 435     public boolean isFileSystemRoot(File dir) {
 436         //Note: Removable drives don't "exist" but are listed in "My Computer"
 437         if (dir != null) {
 438             Win32ShellFolder2 drives = getDrives();




 208                     }
 209                     if (personal != null) {
 210                         personal.setIsPersonal();
 211                     }
 212                 }
 213             } catch (SecurityException e) {
 214                 // Ignore error
 215             } catch (InterruptedException e) {
 216                 // Ignore error
 217             } catch (IOException e) {
 218                 // Ignore error
 219             }
 220         }
 221         return personal;
 222     }
 223 
 224 
 225     private static File[] roots;
 226 
 227     /**
 228      * @param key a {@code String}
 229      *  "fileChooserDefaultFolder":
 230      *    Returns a {@code File} - the default shellfolder for a new filechooser
 231      *  "roots":
 232      *    Returns a {@code File[]} - containing the root(s) of the displayable hierarchy
 233      *  "fileChooserComboBoxFolders":
 234      *    Returns a {@code File[]} - an array of shellfolders representing the list to
 235      *    show by default in the file chooser's combobox
 236      *   "fileChooserShortcutPanelFolders":
 237      *    Returns a {@code File[]} - an array of shellfolders representing well-known
 238      *    folders, such as Desktop, Documents, History, Network, Home, etc.
 239      *    This is used in the shortcut panel of the filechooser on Windows 2000
 240      *    and Windows Me.
 241      *  "fileChooserIcon <icon>":
 242      *    Returns an {@code Image} - icon can be ListView, DetailsView, UpFolder, NewFolder or
 243      *    ViewMenu (Windows only).
 244      *  "optionPaneIcon iconName":
 245      *    Returns an {@code Image} - icon from the system icon list
 246      *
 247      * @return An Object matching the key string.
 248      */
 249     public Object get(String key) {
 250         if (key.equals("fileChooserDefaultFolder")) {
 251             File file = getPersonal();
 252             if (file == null) {
 253                 file = getDesktop();
 254             }
 255             return checkFile(file);
 256         } else if (key.equals("roots")) {
 257             // Should be "History" and "Desktop" ?
 258             if (roots == null) {
 259                 File desktop = getDesktop();
 260                 if (desktop != null) {
 261                     roots = new File[] { desktop };
 262                 } else {
 263                     roots = (File[])super.get(key);
 264                 }
 265             }


 398         if (sm == null || files == null || files.length == 0) {
 399             return files;
 400         }
 401         return checkFiles(Arrays.stream(files), sm);
 402     }
 403 
 404     private File[] checkFiles(List<File> files) {
 405         SecurityManager sm = System.getSecurityManager();
 406         if (sm == null || files.isEmpty()) {
 407             return files.toArray(new File[files.size()]);
 408         }
 409         return checkFiles(files.stream(), sm);
 410     }
 411 
 412     private File[] checkFiles(Stream<File> filesStream, SecurityManager sm) {
 413         return filesStream.filter((file) -> checkFile(file, sm) != null)
 414                 .toArray(File[]::new);
 415     }
 416 
 417     /**
 418      * Does {@code dir} represent a "computer" such as a node on the network, or
 419      * "My Computer" on the desktop.
 420      */
 421     public boolean isComputerNode(final File dir) {
 422         if (dir != null && dir == getDrives()) {
 423             return true;
 424         } else {
 425             String path = AccessController.doPrivileged(new PrivilegedAction<String>() {
 426                 public String run() {
 427                     return dir.getAbsolutePath();
 428                 }
 429             });
 430 
 431             return (path.startsWith("\\\\") && path.indexOf("\\", 2) < 0);      //Network path
 432         }
 433     }
 434 
 435     public boolean isFileSystemRoot(File dir) {
 436         //Note: Removable drives don't "exist" but are listed in "My Computer"
 437         if (dir != null) {
 438             Win32ShellFolder2 drives = getDrives();


< prev index next >