1 /*
2 * Copyright (c) 1998, 2008, 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
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 /**
605 * FileSystemView that handles some specific unix-isms.
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
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 private static final long serialVersionUID = 718975903156136977L;
587
588 public FileSystemRoot(File f) {
589 super(f,"");
590 }
591
592 public FileSystemRoot(String s) {
593 super(s);
594 }
595
596 public boolean isDirectory() {
597 return true;
598 }
599
600 public String getName() {
601 return getPath();
602 }
603 }
604 }
605
606 /**
607 * FileSystemView that handles some specific unix-isms.
760 });
761
762 return path != null && (path.equals("A:\\") || path.equals("B:\\"));
763 }
764
765 /**
766 * Returns a File object constructed from the given path string.
767 */
768 public File createFileObject(String path) {
769 // Check for missing backslash after drive letter such as "C:" or "C:filename"
770 if (path.length() >= 2 && path.charAt(1) == ':' && Character.isLetter(path.charAt(0))) {
771 if (path.length() == 2) {
772 path += "\\";
773 } else if (path.charAt(2) != '\\') {
774 path = path.substring(0, 2) + "\\" + path.substring(2);
775 }
776 }
777 return super.createFileObject(path);
778 }
779
780 @SuppressWarnings("serial") // anonymous class
781 protected File createFileSystemRoot(File f) {
782 // Problem: Removable drives on Windows return false on f.exists()
783 // Workaround: Override exists() to always return true.
784 return new FileSystemRoot(f) {
785 public boolean exists() {
786 return true;
787 }
788 };
789 }
790
791 }
792
793 /**
794 * Fallthrough FileSystemView in case we can't determine the OS.
795 */
796 class GenericFileSystemView extends FileSystemView {
797
798 private static final String newFolderString =
799 UIManager.getString("FileChooser.other.newFolder");
800
|