Ejemplo n.º 1
0
  private void changeDirectory(File dir) {
    JFileChooser fc = getFileChooser();
    // Traverse shortcuts on Windows
    if (dir != null && FilePane.usesShellFolder(fc)) {
      try {
        ShellFolder shellFolder = ShellFolder.getShellFolder(dir);

        if (shellFolder.isLink()) {
          File linkedTo = shellFolder.getLinkLocation();

          // If linkedTo is null we try to use dir
          if (linkedTo != null) {
            if (fc.isTraversable(linkedTo)) {
              dir = linkedTo;
            } else {
              return;
            }
          } else {
            dir = shellFolder;
          }
        }
      } catch (FileNotFoundException ex) {
        return;
      }
    }
    fc.setCurrentDirectory(dir);
    if (fc.getFileSelectionMode() == JFileChooser.FILES_AND_DIRECTORIES
        && fc.getFileSystemView().isFileSystem(dir)) {

      setFileName(dir.getAbsolutePath());
    }
  }
Ejemplo n.º 2
0
 /**
  * Checks if <code>f</code> represents a real directory or file as opposed to a special folder
  * such as <code>"Desktop"</code>. Used by UI classes to decide if a folder is selectable when
  * doing directory choosing.
  *
  * @param f a <code>File</code> object
  * @return <code>true</code> if <code>f</code> is a real file or directory.
  * @since 1.4
  */
 public boolean isFileSystem(File f) {
   if (f instanceof ShellFolder) {
     ShellFolder sf = (ShellFolder) f;
     // Shortcuts to directories are treated as not being file system objects,
     // so that they are never returned by JFileChooser.
     return sf.isFileSystem() && !(sf.isLink() && sf.isDirectory());
   } else {
     return true;
   }
 }