jdk/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicDirectoryModel.java
author darcy
Tue, 14 Apr 2015 14:47:12 -0700
changeset 30461 57e36ed1a9ab
parent 25859 3317bb8137f4
child 30465 a77083748efc
permissions -rw-r--r--
8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package Reviewed-by: serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 25859
diff changeset
     2
 * Copyright (c) 1998, 2015, Oracle and/or its affiliates. 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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4282
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4282
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4282
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4282
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4282
diff changeset
    23
 * questions.
2
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 javax.swing.plaf.basic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.*;
2489
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
    30
import java.util.concurrent.Callable;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.filechooser.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.beans.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.awt.shell.ShellFolder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * Basic implementation of a file list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @author Jeff Dinkins
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
    43
@SuppressWarnings("serial") // Superclass is not serializable across versions
9665
f43db0b310cc 7031551: Generics: JComboBox
rupashka
parents: 5506
diff changeset
    44
public class BasicDirectoryModel extends AbstractListModel<Object> implements PropertyChangeListener {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private JFileChooser filechooser = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    // PENDING(jeff) pick the size more sensibly
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 678
diff changeset
    48
    private Vector<File> fileCache = new Vector<File>(50);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private LoadFilesThread loadThread = null;
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 678
diff changeset
    50
    private Vector<File> files = null;
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 678
diff changeset
    51
    private Vector<File> directories = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private int fetchID = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private PropertyChangeSupport changeSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private boolean busy = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
25761
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
    58
    /**
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
    59
     * Constructs a new instance of {@code BasicDirectoryModel}.
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
    60
     *
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
    61
     * @param filechooser an instance of {JFileChooser}
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
    62
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public BasicDirectoryModel(JFileChooser filechooser) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        this.filechooser = filechooser;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        validateFileCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        String prop = e.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        if(prop == JFileChooser.DIRECTORY_CHANGED_PROPERTY ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
           prop == JFileChooser.FILE_VIEW_CHANGED_PROPERTY ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
           prop == JFileChooser.FILE_FILTER_CHANGED_PROPERTY ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
           prop == JFileChooser.FILE_HIDING_CHANGED_PROPERTY ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
           prop == JFileChooser.FILE_SELECTION_MODE_CHANGED_PROPERTY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            validateFileCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        } else if ("UI".equals(prop)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            Object old = e.getOldValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            if (old instanceof BasicFileChooserUI) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                BasicFileChooserUI ui = (BasicFileChooserUI) old;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                BasicDirectoryModel model = ui.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                if (model != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                    model.invalidateFileCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        } else if ("JFileChooserDialogIsClosingProperty".equals(prop)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            invalidateFileCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * This method is used to interrupt file loading thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public void invalidateFileCache() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        if (loadThread != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            loadThread.interrupt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            loadThread.cancelRunnables();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            loadThread = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
25761
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   101
    /**
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   102
     * Returns a list of directories.
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   103
     *
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   104
     * @return a list of directories
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   105
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    public Vector<File> getDirectories() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        synchronized(fileCache) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            if (directories != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                return directories;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            }
25565
ce603b34c98d 8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents: 23697
diff changeset
   111
            Vector<File> fls = getFiles();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            return directories;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
25761
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   116
    /**
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   117
     * Returns a list of files.
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   118
     *
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   119
     * @return a list of files
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   120
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    public Vector<File> getFiles() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        synchronized(fileCache) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            if (files != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                return files;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            }
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 678
diff changeset
   126
            files = new Vector<File>();
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 678
diff changeset
   127
            directories = new Vector<File>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            directories.addElement(filechooser.getFileSystemView().createFileObject(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                filechooser.getCurrentDirectory(), "..")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            for (int i = 0; i < getSize(); i++) {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 678
diff changeset
   133
                File f = fileCache.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                if (filechooser.isTraversable(f)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                    directories.add(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                    files.add(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            return files;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
25761
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   144
    /**
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   145
     * Validates content of file cache.
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   146
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public void validateFileCache() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        File currentDirectory = filechooser.getCurrentDirectory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        if (currentDirectory == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        if (loadThread != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            loadThread.interrupt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            loadThread.cancelRunnables();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        setBusy(true, ++fetchID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        loadThread = new LoadFilesThread(currentDirectory, fetchID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        loadThread.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * Renames a file in the underlying file system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @param oldFile a <code>File</code> object representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *        the existing file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * @param newFile a <code>File</code> object representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     *        the desired new file name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @return <code>true</code> if rename succeeded,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *        otherwise <code>false</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    public boolean renameFile(File oldFile, File newFile) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        synchronized(fileCache) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            if (oldFile.renameTo(newFile)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                validateFileCache();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
25761
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   184
    /**
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   185
     * Invoked when a content is changed.
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   186
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    public void fireContentsChanged() {
25761
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   188
        fireContentsChanged(this, 0, getSize() - 1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    public int getSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        return fileCache.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
25761
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   195
    /**
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   196
     * Returns {@code true} if an element {@code o} is in file cache,
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   197
     * otherwise, returns {@code false}.
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   198
     *
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   199
     * @param o an element
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   200
     * @return {@code true} if an element {@code o} is in file cache
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   201
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    public boolean contains(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        return fileCache.contains(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
25761
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   206
    /**
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   207
     * Returns an index of element {@code o} in file cache.
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   208
     *
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   209
     * @param o an element
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   210
     * @return an index of element {@code o} in file cache
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   211
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    public int indexOf(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        return fileCache.indexOf(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    public Object getElementAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        return fileCache.get(index);
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
     * Obsolete - not used.
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 25859
diff changeset
   222
     * @param e list data event
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    public void intervalAdded(ListDataEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * Obsolete - not used.
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 25859
diff changeset
   229
     * @param e list data event
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    public void intervalRemoved(ListDataEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
25761
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   234
    /**
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   235
     * Sorts a list of files.
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   236
     *
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   237
     * @param v a list of files
c408b10ef757 8043968: Fix doclint warnings from javax.swing.plaf.basic package, 1 of 7
aeremeev
parents: 25565
diff changeset
   238
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    protected void sort(Vector<? extends File> v){
678
7d331a53a753 6571802: 'Shared Documents' listed in-between C,D drives in the JFileChooser, does not match with native
rupashka
parents: 2
diff changeset
   240
        ShellFolder.sort(v);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
30461
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 25859
diff changeset
   243
    /**
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 25859
diff changeset
   244
     * Obsolete - not used
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 25859
diff changeset
   245
     * @return a comparison of the file names
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 25859
diff changeset
   246
     * @param a a file
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 25859
diff changeset
   247
     * @param b another file
57e36ed1a9ab 8077095: Fix missing doclint warnings in the javax.swing.plaf.basic package
darcy
parents: 25859
diff changeset
   248
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    protected boolean lt(File a, File b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        // First ignore case when comparing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        int diff = a.getName().toLowerCase().compareTo(b.getName().toLowerCase());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        if (diff != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            return diff < 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            // May differ in case (e.g. "mail" vs. "Mail")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            return a.getName().compareTo(b.getName()) < 0;
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    class LoadFilesThread extends Thread {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        File currentDirectory = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        int fid;
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 678
diff changeset
   264
        Vector<DoChangeContents> runnables = new Vector<DoChangeContents>(10);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        public LoadFilesThread(File currentDirectory, int fid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            super("Basic L&F File Loading Thread");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            this.currentDirectory = currentDirectory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            this.fid = fid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            run0();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            setBusy(false, fid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        public void run0() {
2817
f171f2417978 6713352: Deadlock in JFileChooser with synchronized custom FileSystemView
rupashka
parents: 2489
diff changeset
   278
            FileSystemView fileSystem = filechooser.getFileSystemView();
f171f2417978 6713352: Deadlock in JFileChooser with synchronized custom FileSystemView
rupashka
parents: 2489
diff changeset
   279
3346
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   280
            if (isInterrupted()) {
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   281
                return;
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   282
            }
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   283
2817
f171f2417978 6713352: Deadlock in JFileChooser with synchronized custom FileSystemView
rupashka
parents: 2489
diff changeset
   284
            File[] list = fileSystem.getFiles(currentDirectory, filechooser.isFileHidingEnabled());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
2817
f171f2417978 6713352: Deadlock in JFileChooser with synchronized custom FileSystemView
rupashka
parents: 2489
diff changeset
   286
            if (isInterrupted()) {
f171f2417978 6713352: Deadlock in JFileChooser with synchronized custom FileSystemView
rupashka
parents: 2489
diff changeset
   287
                return;
f171f2417978 6713352: Deadlock in JFileChooser with synchronized custom FileSystemView
rupashka
parents: 2489
diff changeset
   288
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
2817
f171f2417978 6713352: Deadlock in JFileChooser with synchronized custom FileSystemView
rupashka
parents: 2489
diff changeset
   290
            final Vector<File> newFileCache = new Vector<File>();
f171f2417978 6713352: Deadlock in JFileChooser with synchronized custom FileSystemView
rupashka
parents: 2489
diff changeset
   291
            Vector<File> newFiles = new Vector<File>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
2817
f171f2417978 6713352: Deadlock in JFileChooser with synchronized custom FileSystemView
rupashka
parents: 2489
diff changeset
   293
            // run through the file list, add directories and selectable files to fileCache
f171f2417978 6713352: Deadlock in JFileChooser with synchronized custom FileSystemView
rupashka
parents: 2489
diff changeset
   294
            // Note that this block must be OUTSIDE of Invoker thread because of
f171f2417978 6713352: Deadlock in JFileChooser with synchronized custom FileSystemView
rupashka
parents: 2489
diff changeset
   295
            // deadlock possibility with custom synchronized FileSystemView
f171f2417978 6713352: Deadlock in JFileChooser with synchronized custom FileSystemView
rupashka
parents: 2489
diff changeset
   296
            for (File file : list) {
f171f2417978 6713352: Deadlock in JFileChooser with synchronized custom FileSystemView
rupashka
parents: 2489
diff changeset
   297
                if (filechooser.accept(file)) {
f171f2417978 6713352: Deadlock in JFileChooser with synchronized custom FileSystemView
rupashka
parents: 2489
diff changeset
   298
                    boolean isTraversable = filechooser.isTraversable(file);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
2817
f171f2417978 6713352: Deadlock in JFileChooser with synchronized custom FileSystemView
rupashka
parents: 2489
diff changeset
   300
                    if (isTraversable) {
f171f2417978 6713352: Deadlock in JFileChooser with synchronized custom FileSystemView
rupashka
parents: 2489
diff changeset
   301
                        newFileCache.addElement(file);
f171f2417978 6713352: Deadlock in JFileChooser with synchronized custom FileSystemView
rupashka
parents: 2489
diff changeset
   302
                    } else if (filechooser.isFileSelectionEnabled()) {
f171f2417978 6713352: Deadlock in JFileChooser with synchronized custom FileSystemView
rupashka
parents: 2489
diff changeset
   303
                        newFiles.addElement(file);
2489
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   304
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
2489
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   306
                    if (isInterrupted()) {
2817
f171f2417978 6713352: Deadlock in JFileChooser with synchronized custom FileSystemView
rupashka
parents: 2489
diff changeset
   307
                        return;
2489
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   308
                    }
2817
f171f2417978 6713352: Deadlock in JFileChooser with synchronized custom FileSystemView
rupashka
parents: 2489
diff changeset
   309
                }
f171f2417978 6713352: Deadlock in JFileChooser with synchronized custom FileSystemView
rupashka
parents: 2489
diff changeset
   310
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
2817
f171f2417978 6713352: Deadlock in JFileChooser with synchronized custom FileSystemView
rupashka
parents: 2489
diff changeset
   312
            // First sort alphabetically by filename
f171f2417978 6713352: Deadlock in JFileChooser with synchronized custom FileSystemView
rupashka
parents: 2489
diff changeset
   313
            sort(newFileCache);
f171f2417978 6713352: Deadlock in JFileChooser with synchronized custom FileSystemView
rupashka
parents: 2489
diff changeset
   314
            sort(newFiles);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
2817
f171f2417978 6713352: Deadlock in JFileChooser with synchronized custom FileSystemView
rupashka
parents: 2489
diff changeset
   316
            newFileCache.addAll(newFiles);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
2817
f171f2417978 6713352: Deadlock in JFileChooser with synchronized custom FileSystemView
rupashka
parents: 2489
diff changeset
   318
            // To avoid loads of synchronizations with Invoker and improve performance we
f171f2417978 6713352: Deadlock in JFileChooser with synchronized custom FileSystemView
rupashka
parents: 2489
diff changeset
   319
            // execute the whole block on the COM thread
3346
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   320
            DoChangeContents doChangeContents = ShellFolder.invoke(new Callable<DoChangeContents>() {
1c65be97eaa2 6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents: 2817
diff changeset
   321
                public DoChangeContents call() {
2489
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   322
                    int newSize = newFileCache.size();
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   323
                    int oldSize = fileCache.size();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
2489
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   325
                    if (newSize > oldSize) {
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   326
                        //see if interval is added
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   327
                        int start = oldSize;
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   328
                        int end = newSize;
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   329
                        for (int i = 0; i < oldSize; i++) {
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   330
                            if (!newFileCache.get(i).equals(fileCache.get(i))) {
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   331
                                start = i;
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   332
                                for (int j = i; j < newSize; j++) {
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   333
                                    if (newFileCache.get(j).equals(fileCache.get(i))) {
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   334
                                        end = j;
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   335
                                        break;
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   336
                                    }
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   337
                                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                        }
2489
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   341
                        if (start >= 0 && end > start
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   342
                            && newFileCache.subList(end, newSize).equals(fileCache.subList(start, oldSize))) {
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   343
                            if (isInterrupted()) {
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   344
                                return null;
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   345
                            }
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   346
                            return new DoChangeContents(newFileCache.subList(start, end), start, null, 0, fid);
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   347
                        }
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   348
                    } else if (newSize < oldSize) {
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   349
                        //see if interval is removed
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   350
                        int start = -1;
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   351
                        int end = -1;
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   352
                        for (int i = 0; i < newSize; i++) {
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   353
                            if (!newFileCache.get(i).equals(fileCache.get(i))) {
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   354
                                start = i;
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   355
                                end = i + oldSize - newSize;
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   356
                                break;
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   357
                            }
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   358
                        }
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   359
                        if (start >= 0 && end > start
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   360
                            && fileCache.subList(end, oldSize).equals(newFileCache.subList(start, newSize))) {
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   361
                            if (isInterrupted()) {
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   362
                                return null;
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   363
                            }
25565
ce603b34c98d 8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents: 23697
diff changeset
   364
                            return new DoChangeContents(null, 0, new Vector<>(fileCache.subList(start, end)), start, fid);
2489
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   365
                        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                    }
2489
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   367
                    if (!fileCache.equals(newFileCache)) {
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   368
                        if (isInterrupted()) {
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   369
                            cancelRunnables(runnables);
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   370
                        }
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   371
                        return new DoChangeContents(newFileCache, 0, fileCache, 0, fid);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                    }
2489
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   373
                    return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                }
2489
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   375
            });
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   376
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   377
            if (doChangeContents != null) {
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   378
                runnables.addElement(doChangeContents);
5052722686e2 6491795: COM should be initialized for Shell API calls in ShellFolder2.cpp
rupashka
parents: 1299
diff changeset
   379
                SwingUtilities.invokeLater(doChangeContents);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 678
diff changeset
   384
        public void cancelRunnables(Vector<DoChangeContents> runnables) {
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 678
diff changeset
   385
            for (DoChangeContents runnable : runnables) {
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 678
diff changeset
   386
                runnable.cancel();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        public void cancelRunnables() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            cancelRunnables(runnables);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * Adds a PropertyChangeListener to the listener list. The listener is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * registered for all bound properties of this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * If <code>listener</code> is <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * @param    listener  the property change listener to be added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * @see #removePropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * @see #getPropertyChangeListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    public void addPropertyChangeListener(PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        if (changeSupport == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            changeSupport = new PropertyChangeSupport(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        changeSupport.addPropertyChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * Removes a PropertyChangeListener from the listener list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * If listener is null, no exception is thrown and no action is performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * @param listener the PropertyChangeListener to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * @see #addPropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * @see #getPropertyChangeListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    public void removePropertyChangeListener(PropertyChangeListener listener) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        if (changeSupport != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            changeSupport.removePropertyChangeListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * Returns an array of all the property change listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * registered on this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * @return all of this component's <code>PropertyChangeListener</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     *         or an empty array if no property change
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     *         listeners are currently registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * @see      #addPropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * @see      #removePropertyChangeListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * @see      java.beans.PropertyChangeSupport#getPropertyChangeListeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    public PropertyChangeListener[] getPropertyChangeListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        if (changeSupport == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            return new PropertyChangeListener[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        return changeSupport.getPropertyChangeListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * Support for reporting bound property changes for boolean properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * This method can be called when a bound property has changed and it will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * send the appropriate PropertyChangeEvent to any registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * PropertyChangeListeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * @param propertyName the property whose value has changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * @param oldValue the property's previous value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * @param newValue the property's new value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    protected void firePropertyChange(String propertyName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                                      Object oldValue, Object newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        if (changeSupport != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            changeSupport.firePropertyChange(propertyName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                                             oldValue, newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * Set the busy state for the model. The model is considered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * busy when it is running a separate (interruptable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * thread in order to load the contents of a directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    private synchronized void setBusy(final boolean busy, int fid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        if (fid == fetchID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            boolean oldValue = this.busy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            this.busy = busy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            if (changeSupport != null && busy != oldValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                SwingUtilities.invokeLater(new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                    public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                        firePropertyChange("busy", !busy, busy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    class DoChangeContents implements Runnable {
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 678
diff changeset
   499
        private List<File> addFiles;
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 678
diff changeset
   500
        private List<File> remFiles;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        private boolean doFire = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        private int fid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        private int addStart = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        private int remStart = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
1290
da8902cd496c 6727661: Code improvement and warnings removing from the swing/plaf packages
rupashka
parents: 678
diff changeset
   506
        public DoChangeContents(List<File> addFiles, int addStart, List<File> remFiles, int remStart, int fid) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            this.addFiles = addFiles;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            this.addStart = addStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            this.remFiles = remFiles;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            this.remStart = remStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            this.fid = fid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        synchronized void cancel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                doFire = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        public synchronized void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            if (fetchID == fid && doFire) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                int remSize = (remFiles == null) ? 0 : remFiles.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                int addSize = (addFiles == null) ? 0 : addFiles.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                synchronized(fileCache) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                    if (remSize > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                        fileCache.removeAll(remFiles);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                    if (addSize > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                        fileCache.addAll(addStart, addFiles);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                    files = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                    directories = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                if (remSize > 0 && addSize == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                    fireIntervalRemoved(BasicDirectoryModel.this, remStart, remStart + remSize - 1);
4282
ac32f2a927e0 6520574: JFileChooser - create new folder - not editable
rupashka
parents: 3346
diff changeset
   534
                } else if (addSize > 0 && remSize == 0 && addStart + addSize <= fileCache.size()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                    fireIntervalAdded(BasicDirectoryModel.this, addStart, addStart + addSize - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                    fireContentsChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
}