1 /*
2 * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
562 } catch (InternalError e) {
563 System.err.println("FileSystemView.getShellFolder: f="+f);
564 e.printStackTrace();
565 return null;
566 }
567 }
568
569 /**
570 * Creates a new <code>File</code> object for <code>f</code> with correct
571 * behavior for a file system root directory.
572 *
573 * @param f a <code>File</code> object representing a file system root
574 * directory, for example "/" on Unix or "C:\" on Windows.
575 * @return a new <code>File</code> object
576 * @since 1.4
577 */
578 protected File createFileSystemRoot(File f) {
579 return new FileSystemRoot(f);
580 }
581
582
583
584
585 static class FileSystemRoot extends File {
586 public FileSystemRoot(File f) {
587 super(f,"");
588 }
589
590 public FileSystemRoot(String s) {
591 super(s);
592 }
593
594 public boolean isDirectory() {
595 return true;
596 }
597
598 public String getName() {
599 return getPath();
600 }
601 }
602 }
603
604 /**
758 });
759
760 return path != null && (path.equals("A:\\") || path.equals("B:\\"));
761 }
762
763 /**
764 * Returns a File object constructed from the given path string.
765 */
766 public File createFileObject(String path) {
767 // Check for missing backslash after drive letter such as "C:" or "C:filename"
768 if (path.length() >= 2 && path.charAt(1) == ':' && Character.isLetter(path.charAt(0))) {
769 if (path.length() == 2) {
770 path += "\\";
771 } else if (path.charAt(2) != '\\') {
772 path = path.substring(0, 2) + "\\" + path.substring(2);
773 }
774 }
775 return super.createFileObject(path);
776 }
777
778 protected File createFileSystemRoot(File f) {
779 // Problem: Removable drives on Windows return false on f.exists()
780 // Workaround: Override exists() to always return true.
781 return new FileSystemRoot(f) {
782 public boolean exists() {
783 return true;
784 }
785 };
786 }
787
788 }
789
790 /**
791 * Fallthrough FileSystemView in case we can't determine the OS.
792 */
793 class GenericFileSystemView extends FileSystemView {
794
795 private static final String newFolderString =
796 UIManager.getString("FileChooser.other.newFolder");
797
|
1 /*
2 * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
562 } catch (InternalError e) {
563 System.err.println("FileSystemView.getShellFolder: f="+f);
564 e.printStackTrace();
565 return null;
566 }
567 }
568
569 /**
570 * Creates a new <code>File</code> object for <code>f</code> with correct
571 * behavior for a file system root directory.
572 *
573 * @param f a <code>File</code> object representing a file system root
574 * directory, for example "/" on Unix or "C:\" on Windows.
575 * @return a new <code>File</code> object
576 * @since 1.4
577 */
578 protected File createFileSystemRoot(File f) {
579 return new FileSystemRoot(f);
580 }
581
582 @SuppressWarnings("serial") // Same-version serialization only
583 static class FileSystemRoot extends File {
584 public FileSystemRoot(File f) {
585 super(f,"");
586 }
587
588 public FileSystemRoot(String s) {
589 super(s);
590 }
591
592 public boolean isDirectory() {
593 return true;
594 }
595
596 public String getName() {
597 return getPath();
598 }
599 }
600 }
601
602 /**
756 });
757
758 return path != null && (path.equals("A:\\") || path.equals("B:\\"));
759 }
760
761 /**
762 * Returns a File object constructed from the given path string.
763 */
764 public File createFileObject(String path) {
765 // Check for missing backslash after drive letter such as "C:" or "C:filename"
766 if (path.length() >= 2 && path.charAt(1) == ':' && Character.isLetter(path.charAt(0))) {
767 if (path.length() == 2) {
768 path += "\\";
769 } else if (path.charAt(2) != '\\') {
770 path = path.substring(0, 2) + "\\" + path.substring(2);
771 }
772 }
773 return super.createFileObject(path);
774 }
775
776 @SuppressWarnings("serial") // anonymous class
777 protected File createFileSystemRoot(File f) {
778 // Problem: Removable drives on Windows return false on f.exists()
779 // Workaround: Override exists() to always return true.
780 return new FileSystemRoot(f) {
781 public boolean exists() {
782 return true;
783 }
784 };
785 }
786
787 }
788
789 /**
790 * Fallthrough FileSystemView in case we can't determine the OS.
791 */
792 class GenericFileSystemView extends FileSystemView {
793
794 private static final String newFolderString =
795 UIManager.getString("FileChooser.other.newFolder");
796
|