FileDocCategorySizeDatePackage
BasicDirectoryModel.javaAPI DocJava SE 5 API8987Fri Aug 26 14:58:04 BST 2005javax.swing.plaf.basic

BasicDirectoryModel

public class BasicDirectoryModel extends AbstractListModel implements PropertyChangeListener
Basic implementation of a file list.
version
%i% %g%
author
Jeff Dinkins

Fields Summary
private JFileChooser
filechooser
private Vector
fileCache
private LoadFilesThread
loadThread
private Vector
files
private Vector
directories
private int
fetchID
Constructors Summary
public BasicDirectoryModel(JFileChooser filechooser)


       
	this.filechooser = filechooser;
	validateFileCache();
    
Methods Summary
public booleancontains(java.lang.Object o)

	return fileCache.contains(o);
    
public voidfireContentsChanged()

	// System.out.println("BasicDirectoryModel: firecontentschanged");
	fireContentsChanged(this, 0, getSize()-1);
    
public java.util.VectorgetDirectories()

	synchronized(fileCache) {
	    if (directories != null) {
		return directories;
	    }
	    Vector fls = getFiles();
	    return directories;
	}
    
public java.lang.ObjectgetElementAt(int index)

	return fileCache.get(index);
    
public java.util.VectorgetFiles()

	synchronized(fileCache) {
	    if (files != null) {
		return files;
	    }
	    files = new Vector();
	    directories = new Vector();
	    directories.addElement(filechooser.getFileSystemView().createFileObject(
		filechooser.getCurrentDirectory(), "..")
	    );

	    for (int i = 0; i < getSize(); i++) {
		File f = (File)fileCache.get(i);
		if (filechooser.isTraversable(f)) {
		    directories.add(f);
		} else {
		    files.add(f);
		}
	    }
	    return files;
	}
    
public intgetSize()

	return fileCache.size();
    
public intindexOf(java.lang.Object o)

	return fileCache.indexOf(o);
    
public voidintervalAdded(javax.swing.event.ListDataEvent e)
Obsolete - not used.

    
public voidintervalRemoved(javax.swing.event.ListDataEvent e)
Obsolete - not used.

    
public voidinvalidateFileCache()
Obsolete - not used.

    
protected booleanlt(java.io.File a, java.io.File b)

	// First ignore case when comparing
	int diff = a.getName().toLowerCase().compareTo(b.getName().toLowerCase());
	if (diff != 0) {
	    return diff < 0;
	} else {
	    // May differ in case (e.g. "mail" vs. "Mail")
	    return a.getName().compareTo(b.getName()) < 0;
	}
    
public voidpropertyChange(java.beans.PropertyChangeEvent e)

	String prop = e.getPropertyName();
	if(prop == JFileChooser.DIRECTORY_CHANGED_PROPERTY ||
	   prop == JFileChooser.FILE_VIEW_CHANGED_PROPERTY ||
	   prop == JFileChooser.FILE_FILTER_CHANGED_PROPERTY ||
	   prop == JFileChooser.FILE_HIDING_CHANGED_PROPERTY ||
	   prop == JFileChooser.FILE_SELECTION_MODE_CHANGED_PROPERTY) {
	    validateFileCache();
	}
    
public booleanrenameFile(java.io.File oldFile, java.io.File newFile)
Renames a file in the underlying file system.

param
oldFile a File object representing the existing file
param
newFile a File object representing the desired new file name
return
true if rename succeeded, otherwise false
since
1.4

	synchronized(fileCache) {
	    if (oldFile.renameTo(newFile)) {
		validateFileCache();
		return true;
	    }
	    return false;
	}
    
protected voidsort(java.util.Vector v)

	ShellFolder.sortFiles(v);
    
public voidvalidateFileCache()

	File currentDirectory = filechooser.getCurrentDirectory();
	if (currentDirectory == null) {
	    return;
	}
	if (loadThread != null) {
	    loadThread.interrupt();
            loadThread.cancelRunnables();
	}
	fetchID++;
	loadThread = new LoadFilesThread(currentDirectory, fetchID);
	loadThread.start();