jdk/src/share/classes/sun/awt/shell/ShellFolder.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 678 7d331a53a753
child 2489 5052722686e2
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 678
diff changeset
     2
 * Copyright 2000-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
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
678
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
    28
import javax.swing.*;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Toolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.FileNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * @author Michael Martak
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
public abstract class ShellFolder extends File {
678
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
    41
    private static final String COLUMN_NAME = "FileChooser.fileNameHeaderText";
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
    42
    private static final String COLUMN_SIZE = "FileChooser.fileSizeHeaderText";
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
    43
    private static final String COLUMN_DATE = "FileChooser.fileDateHeaderText";
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
    44
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    protected ShellFolder parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * Create a file system shell folder from a file
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    ShellFolder(ShellFolder parent, String pathname) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        super((pathname != null) ? pathname : "ShellFolder");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        this.parent = parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * @return Whether this is a file system shell folder
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    public boolean isFileSystem() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        return (!getPath().startsWith("ShellFolder"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * This method must be implemented to make sure that no instances
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * of <code>ShellFolder</code> are ever serialized. If <code>isFileSystem()</code> returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * <code>true</code>, then the object should be representable with an instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * <code>java.io.File</code> instead. If not, then the object is most likely
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * depending on some internal (native) state and cannot be serialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * @returns a <code>java.io.File</code> replacement object, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * if no suitable replacement can be found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    protected abstract Object writeReplace() throws java.io.ObjectStreamException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * Returns the path for this object's parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * or <code>null</code> if this object does not name a parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * folder.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @return  the path as a String for this object's parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * or <code>null</code> if this object does not name a parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * folder
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @see java.io.File#getParent()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public String getParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        if (parent == null && isFileSystem()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            return super.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            return (parent.getPath());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * Returns a File object representing this object's parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * or <code>null</code> if this object does not name a parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * folder.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @return  a File object representing this object's parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * or <code>null</code> if this object does not name a parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * folder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @see java.io.File#getParentFile()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    public File getParentFile() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            return parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        } else if (isFileSystem()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            return super.getParentFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public File[] listFiles() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        return listFiles(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public File[] listFiles(boolean includeHiddenFiles) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        File[] files = super.listFiles();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        if (!includeHiddenFiles) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            Vector v = new Vector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            int nameCount = (files == null) ? 0 : files.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            for (int i = 0; i < nameCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                if (!files[i].isHidden()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                    v.addElement(files[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            files = (File[])v.toArray(new File[v.size()]);
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 files;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
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 Whether this shell folder is a link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    public abstract boolean isLink();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @return The shell folder linked to by this shell folder, or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * if this shell folder is not a link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    public abstract ShellFolder getLinkLocation() throws FileNotFoundException;
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 name used to display this shell folder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    public abstract String getDisplayName();
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 type of shell folder as a string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public abstract String getFolderType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @return The executable type as a string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    public abstract String getExecutableType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * Compares this ShellFolder with the specified ShellFolder for order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @see #compareTo(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    public int compareTo(File file2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        if (file2 == null || !(file2 instanceof ShellFolder)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            || ((file2 instanceof ShellFolder) && ((ShellFolder)file2).isFileSystem())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            if (isFileSystem()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                return super.compareTo(file2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            if (isFileSystem()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                return getName().compareTo(file2.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * @param getLargeIcon whether to return large icon (ignored in base implementation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @return The icon used to display this shell folder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    public Image getIcon(boolean getLargeIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    // Static
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    private static ShellFolderManager shellFolderManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        Class managerClass = (Class)Toolkit.getDefaultToolkit().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            getDesktopProperty("Shell.shellFolderManager");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        if (managerClass == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            managerClass = ShellFolderManager.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            shellFolderManager =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                (ShellFolderManager)managerClass.newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        } catch (InstantiationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            throw new Error("Could not instantiate Shell Folder Manager: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            + managerClass.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        } catch (IllegalAccessException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            throw new Error ("Could not access Shell Folder Manager: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            + managerClass.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * Return a shell folder from a file object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @exception FileNotFoundException if file does not exist
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    public static ShellFolder getShellFolder(File file) throws FileNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        if (file instanceof ShellFolder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            return (ShellFolder)file;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        if (!file.exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            throw new FileNotFoundException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        return shellFolderManager.createShellFolder(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @param key a <code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * @return An Object matching the string <code>key</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * @see ShellFolderManager#get(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    public static Object get(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        return shellFolderManager.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * Does <code>dir</code> represent a "computer" such as a node on the network, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * "My Computer" on the desktop.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    public static boolean isComputerNode(File dir) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        return shellFolderManager.isComputerNode(dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * @return Whether this is a file system root directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    public static boolean isFileSystemRoot(File dir) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        return shellFolderManager.isFileSystemRoot(dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * Canonicalizes files that don't have symbolic links in their path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * Normalizes files that do, preserving symbolic links from being resolved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    public static File getNormalizedFile(File f) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        File canonical = f.getCanonicalFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        if (f.equals(canonical)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            // path of f doesn't contain symbolic links
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            return canonical;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        // preserve symbolic links from being resolved
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        return new File(f.toURI().normalize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    // Override File methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
678
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   276
    public static void sort(List<? extends File> files) {
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   277
        if (files == null || files.size() <= 1) {
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   278
            return;
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   279
        }
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   280
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   281
        // Check that we can use the ShellFolder.sortChildren() method:
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   282
        //   1. All files have the same non-null parent
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   283
        //   2. All files is ShellFolders
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   284
        File commonParent = null;
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   285
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   286
        for (File file : files) {
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   287
            File parent = file.getParentFile();
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   288
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   289
            if (parent == null || !(file instanceof ShellFolder)) {
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   290
                commonParent = null;
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   291
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   292
                break;
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   293
            }
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   294
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   295
            if (commonParent == null) {
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   296
                commonParent = parent;
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   297
            } else {
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   298
                if (commonParent != parent && !commonParent.equals(parent)) {
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   299
                    commonParent = null;
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   300
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   301
                    break;
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   302
                }
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   303
            }
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   304
        }
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   305
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   306
        if (commonParent instanceof ShellFolder) {
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   307
            ((ShellFolder) commonParent).sortChildren(files);
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   308
        } else {
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   309
            Collections.sort(files, FILE_COMPARATOR);
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   310
        }
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   311
    }
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   312
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   313
    public void sortChildren(List<? extends File> files) {
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   314
        Collections.sort(files, FILE_COMPARATOR);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    public boolean isAbsolute() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        return (!isFileSystem() || super.isAbsolute());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    public File getAbsoluteFile() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        return (isFileSystem() ? super.getAbsoluteFile() : this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    public boolean canRead() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        return (isFileSystem() ? super.canRead() : true);       // ((Fix?))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * Returns true if folder allows creation of children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * True for the "Desktop" folder, but false for the "My Computer"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * folder.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    public boolean canWrite() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        return (isFileSystem() ? super.canWrite() : false);     // ((Fix?))
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 exists() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        // Assume top-level drives exist, because state is uncertain for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        // removable drives.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        return (!isFileSystem() || isFileSystemRoot(this) || super.exists()) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    public boolean isDirectory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        return (isFileSystem() ? super.isDirectory() : true);   // ((Fix?))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    public boolean isFile() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        return (isFileSystem() ? super.isFile() : !isDirectory());      // ((Fix?))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    public long lastModified() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        return (isFileSystem() ? super.lastModified() : 0L);    // ((Fix?))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    public long length() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        return (isFileSystem() ? super.length() : 0L);  // ((Fix?))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    public boolean createNewFile() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        return (isFileSystem() ? super.createNewFile() : false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    public boolean delete() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        return (isFileSystem() ? super.delete() : false);       // ((Fix?))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    public void deleteOnExit() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        if (isFileSystem()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            super.deleteOnExit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            // Do nothing       // ((Fix?))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    public boolean mkdir() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        return (isFileSystem() ? super.mkdir() : false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    public boolean mkdirs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        return (isFileSystem() ? super.mkdirs() : false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    public boolean renameTo(File dest) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        return (isFileSystem() ? super.renameTo(dest) : false); // ((Fix?))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    public boolean setLastModified(long time) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        return (isFileSystem() ? super.setLastModified(time) : false); // ((Fix?))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    public boolean setReadOnly() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        return (isFileSystem() ? super.setReadOnly() : false); // ((Fix?))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        return (isFileSystem() ? super.toString() : getDisplayName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    public static ShellFolderColumnInfo[] getFolderColumns(File dir) {
678
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   401
        ShellFolderColumnInfo[] columns = null;
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   402
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   403
        if (dir instanceof ShellFolder) {
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   404
            columns = ((ShellFolder) dir).getFolderColumns();
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   405
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
678
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   407
        if (columns == null) {
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   408
            columns = new ShellFolderColumnInfo[]{
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   409
                    new ShellFolderColumnInfo(COLUMN_NAME, 150,
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   410
                            SwingConstants.LEADING, true, null,
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   411
                            FILE_COMPARATOR),
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   412
                    new ShellFolderColumnInfo(COLUMN_SIZE, 75,
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   413
                            SwingConstants.RIGHT, true, null,
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   414
                            DEFAULT_COMPARATOR, true),
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   415
                    new ShellFolderColumnInfo(COLUMN_DATE, 130,
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   416
                            SwingConstants.LEADING, true, null,
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   417
                            DEFAULT_COMPARATOR, true)
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   418
            };
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   419
        }
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   420
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   421
        return columns;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    public ShellFolderColumnInfo[] getFolderColumns() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
678
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   428
    public static Object getFolderColumnValue(File file, int column) {
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   429
        if (file instanceof ShellFolder) {
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   430
            Object value = ((ShellFolder)file).getFolderColumnValue(column);
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   431
            if (value != null) {
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   432
                return value;
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   433
            }
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   434
        }
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   435
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   436
        if (file == null || !file.exists()) {
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   437
            return null;
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   438
        }
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   439
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   440
        switch (column) {
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   441
            case 0:
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   442
                // By default, file name will be rendered using getSystemDisplayName()
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   443
                return file;
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   444
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   445
            case 1: // size
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   446
                return file.isDirectory() ? null : Long.valueOf(file.length());
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   447
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   448
            case 2: // date
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   449
                if (isFileSystemRoot(file)) {
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   450
                    return null;
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   451
                }
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   452
                long time = file.lastModified();
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   453
                return (time == 0L) ? null : new Date(time);
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   454
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   455
            default:
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   456
                return null;
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   457
        }
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   458
    }
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   459
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    public Object getFolderColumnValue(int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    }
678
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   463
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   464
    /**
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   465
     * Provides a default comparator for the default column set
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   466
     */
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   467
    private static final Comparator DEFAULT_COMPARATOR = new Comparator() {
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   468
        public int compare(Object o1, Object o2) {
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   469
            int gt;
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   470
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   471
            if (o1 == null && o2 == null) {
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   472
                gt = 0;
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   473
            } else if (o1 != null && o2 == null) {
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   474
                gt = 1;
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   475
            } else if (o1 == null && o2 != null) {
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   476
                gt = -1;
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   477
            } else if (o1 instanceof Comparable) {
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   478
                gt = ((Comparable) o1).compareTo(o2);
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   479
            } else {
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   480
                gt = 0;
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   481
            }
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   482
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   483
            return gt;
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   484
        }
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   485
    };
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   486
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   487
    private static final Comparator<File> FILE_COMPARATOR = new Comparator<File>() {
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   488
        public int compare(File f1, File f2) {
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   489
            ShellFolder sf1 = null;
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   490
            ShellFolder sf2 = null;
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   491
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   492
            if (f1 instanceof ShellFolder) {
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   493
                sf1 = (ShellFolder) f1;
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   494
                if (sf1.isFileSystem()) {
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   495
                    sf1 = null;
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   496
                }
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   497
            }
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   498
            if (f2 instanceof ShellFolder) {
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   499
                sf2 = (ShellFolder) f2;
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   500
                if (sf2.isFileSystem()) {
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   501
                    sf2 = null;
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   502
                }
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   503
            }
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   504
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   505
            if (sf1 != null && sf2 != null) {
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   506
                return sf1.compareTo(sf2);
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   507
            } else if (sf1 != null) {
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   508
                // Non-file shellfolders sort before files
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   509
                return -1;
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   510
            } else if (sf2 != null) {
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   511
                return 1;
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   512
            } else {
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   513
                String name1 = f1.getName();
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   514
                String name2 = f2.getName();
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   515
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   516
                // First ignore case when comparing
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   517
                int diff = name1.compareToIgnoreCase(name2);
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   518
                if (diff != 0) {
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   519
                    return diff;
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   520
                } else {
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   521
                    // May differ in case (e.g. "mail" vs. "Mail")
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   522
                    // We need this test for consistent sorting
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   523
                    return name1.compareTo(name2);
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   524
                }
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   525
            }
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   526
        }
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   527
    };
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
}