jdk/src/share/classes/sun/awt/shell/ShellFolder.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 678 7d331a53a753
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2000-2006 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.awt.shell;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Toolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.FileNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * @author Michael Martak
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
public abstract class ShellFolder extends File {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    protected ShellFolder parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     * Create a file system shell folder from a file
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    ShellFolder(ShellFolder parent, String pathname) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        super((pathname != null) ? pathname : "ShellFolder");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        this.parent = parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * @return Whether this is a file system shell folder
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public boolean isFileSystem() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        return (!getPath().startsWith("ShellFolder"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * This method must be implemented to make sure that no instances
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * of <code>ShellFolder</code> are ever serialized. If <code>isFileSystem()</code> returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * <code>true</code>, then the object should be representable with an instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * <code>java.io.File</code> instead. If not, then the object is most likely
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * depending on some internal (native) state and cannot be serialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * @returns a <code>java.io.File</code> replacement object, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * if no suitable replacement can be found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    protected abstract Object writeReplace() throws java.io.ObjectStreamException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * Returns the path for this object's parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * or <code>null</code> if this object does not name a parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * folder.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * @return  the path as a String for this object's parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * or <code>null</code> if this object does not name a parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * folder
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @see java.io.File#getParent()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public String getParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        if (parent == null && isFileSystem()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            return super.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            return (parent.getPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * Returns a File object representing this object's parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * or <code>null</code> if this object does not name a parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * folder.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @return  a File object representing this object's parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * or <code>null</code> if this object does not name a parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * folder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @see java.io.File#getParentFile()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public File getParentFile() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            return parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        } else if (isFileSystem()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            return super.getParentFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public File[] listFiles() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        return listFiles(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    public File[] listFiles(boolean includeHiddenFiles) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        File[] files = super.listFiles();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        if (!includeHiddenFiles) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            Vector v = new Vector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            int nameCount = (files == null) ? 0 : files.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            for (int i = 0; i < nameCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                if (!files[i].isHidden()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                    v.addElement(files[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            files = (File[])v.toArray(new File[v.size()]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        return files;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @return Whether this shell folder is a link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public abstract boolean isLink();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @return The shell folder linked to by this shell folder, or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * if this shell folder is not a link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    public abstract ShellFolder getLinkLocation() throws FileNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @return The name used to display this shell folder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    public abstract String getDisplayName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * @return The type of shell folder as a string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    public abstract String getFolderType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @return The executable type as a string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public abstract String getExecutableType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * Compares this ShellFolder with the specified ShellFolder for order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @see #compareTo(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public int compareTo(File file2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        if (file2 == null || !(file2 instanceof ShellFolder)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            || ((file2 instanceof ShellFolder) && ((ShellFolder)file2).isFileSystem())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            if (isFileSystem()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                return super.compareTo(file2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            if (isFileSystem()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                return getName().compareTo(file2.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @param getLargeIcon whether to return large icon (ignored in base implementation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @return The icon used to display this shell folder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    public Image getIcon(boolean getLargeIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    // Static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    private static ShellFolderManager shellFolderManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        Class managerClass = (Class)Toolkit.getDefaultToolkit().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            getDesktopProperty("Shell.shellFolderManager");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        if (managerClass == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            managerClass = ShellFolderManager.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            shellFolderManager =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                (ShellFolderManager)managerClass.newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        } catch (InstantiationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            throw new Error("Could not instantiate Shell Folder Manager: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            + managerClass.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        } catch (IllegalAccessException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            throw new Error ("Could not access Shell Folder Manager: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            + managerClass.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * Return a shell folder from a file object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @exception FileNotFoundException if file does not exist
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    public static ShellFolder getShellFolder(File file) throws FileNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        if (file instanceof ShellFolder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            return (ShellFolder)file;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        if (!file.exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            throw new FileNotFoundException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        return shellFolderManager.createShellFolder(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @param key a <code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @return An Object matching the string <code>key</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @see ShellFolderManager#get(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public static Object get(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        return shellFolderManager.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * Does <code>dir</code> represent a "computer" such as a node on the network, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * "My Computer" on the desktop.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    public static boolean isComputerNode(File dir) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        return shellFolderManager.isComputerNode(dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * @return Whether this is a file system root directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    public static boolean isFileSystemRoot(File dir) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        return shellFolderManager.isFileSystemRoot(dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * Canonicalizes files that don't have symbolic links in their path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * Normalizes files that do, preserving symbolic links from being resolved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    public static File getNormalizedFile(File f) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        File canonical = f.getCanonicalFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        if (f.equals(canonical)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            // path of f doesn't contain symbolic links
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            return canonical;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        // preserve symbolic links from being resolved
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        return new File(f.toURI().normalize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    // Override File methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    public static void sortFiles(List files) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        shellFolderManager.sortFiles(files);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    public boolean isAbsolute() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        return (!isFileSystem() || super.isAbsolute());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    public File getAbsoluteFile() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        return (isFileSystem() ? super.getAbsoluteFile() : this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    public boolean canRead() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        return (isFileSystem() ? super.canRead() : true);       // ((Fix?))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * Returns true if folder allows creation of children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * True for the "Desktop" folder, but false for the "My Computer"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * folder.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    public boolean canWrite() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        return (isFileSystem() ? super.canWrite() : false);     // ((Fix?))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    public boolean exists() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        // Assume top-level drives exist, because state is uncertain for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        // removable drives.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        return (!isFileSystem() || isFileSystemRoot(this) || super.exists()) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    public boolean isDirectory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        return (isFileSystem() ? super.isDirectory() : true);   // ((Fix?))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    public boolean isFile() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        return (isFileSystem() ? super.isFile() : !isDirectory());      // ((Fix?))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    public long lastModified() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        return (isFileSystem() ? super.lastModified() : 0L);    // ((Fix?))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    public long length() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        return (isFileSystem() ? super.length() : 0L);  // ((Fix?))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    public boolean createNewFile() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        return (isFileSystem() ? super.createNewFile() : false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    public boolean delete() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        return (isFileSystem() ? super.delete() : false);       // ((Fix?))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    public void deleteOnExit() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        if (isFileSystem()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            super.deleteOnExit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            // Do nothing       // ((Fix?))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    public boolean mkdir() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        return (isFileSystem() ? super.mkdir() : false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    public boolean mkdirs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        return (isFileSystem() ? super.mkdirs() : false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    public boolean renameTo(File dest) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        return (isFileSystem() ? super.renameTo(dest) : false); // ((Fix?))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    public boolean setLastModified(long time) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        return (isFileSystem() ? super.setLastModified(time) : false); // ((Fix?))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    public boolean setReadOnly() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        return (isFileSystem() ? super.setReadOnly() : false); // ((Fix?))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        return (isFileSystem() ? super.toString() : getDisplayName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    public static ShellFolderColumnInfo[] getFolderColumns(File dir) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        return shellFolderManager.getFolderColumns(dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    public static Object getFolderColumnValue(File file, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        return shellFolderManager.getFolderColumnValue(file, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    public ShellFolderColumnInfo[] getFolderColumns() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    public Object getFolderColumnValue(int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
}