javax.swing.plaf.basic

Class BasicDirectoryModel

Implemented Interfaces:
EventListener, ListModel, PropertyChangeListener, Serializable

public class BasicDirectoryModel
extends AbstractListModel
implements PropertyChangeListener

Implements an AbstractListModel for directories where the source of the files is a JFileChooser object. This class is used for sorting and ordering the file list in a JFileChooser L&F object.
See Also:
Serialized Form

Field Summary

Fields inherited from class javax.swing.AbstractListModel

listenerList

Constructor Summary

BasicDirectoryModel(JFileChooser filechooser)
Creates a new BasicDirectoryModel object.

Method Summary

boolean
contains(Object o)
Returns whether a given (File) object is included in the list.
void
fireContentsChanged()
Fires a content change event.
Vector
getDirectories()
Returns a Vector of (java.io.File) objects containing the directories in this list.
Object
getElementAt(int index)
Returns the (java.io.File) object at an index in the list.
Vector
getFiles()
Returns a Vector of (java.io.File) objects containing the files in this list.
int
getSize()
Returns the size of the list, which only includes directories if the JFileChooser is set to DIRECTORIES_ONLY.
int
indexOf(Object o)
Returns the index of an (java.io.File) object in the list.
void
intervalAdded(ListDataEvent e)
Obsoleted method which does nothing.
void
intervalRemoved(ListDataEvent e)
Obsoleted method which does nothing.
void
invalidateFileCache()
Obsoleted method which does nothing.
protected boolean
lt(File a, File b)
Less than, determine the relative order in the list of two files for sorting purposes.
void
propertyChange(PropertyChangeEvent e)
Listens for a property change; the change in file selection mode of the associated JFileChooser.
boolean
renameFile(File oldFile, File newFile)
Renames a file - However, does not re-sort the list or replace the old file with the new one in the list.
protected void
sort(File> v)
Sorts a Vector of File objects.
void
validateFileCache()
Re-loads the list of files

Methods inherited from class javax.swing.AbstractListModel

addListDataListener, extends EventListener> T[] getListeners, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, getListDataListeners, removeListDataListener

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

BasicDirectoryModel

public BasicDirectoryModel(JFileChooser filechooser)
Creates a new BasicDirectoryModel object.
Parameters:
filechooser - DOCUMENT ME!

Method Details

contains

public boolean contains(Object o)
Returns whether a given (File) object is included in the list.
Parameters:
o - - The file object to test.
Returns:
true if the list contains the given object.

fireContentsChanged

public void fireContentsChanged()
Fires a content change event.

getDirectories

public Vector getDirectories()
Returns a Vector of (java.io.File) objects containing the directories in this list.
Returns:
a Vector

getElementAt

public Object getElementAt(int index)
Returns the (java.io.File) object at an index in the list.
Specified by:
getElementAt in interface ListModel
Parameters:
index - The list index
Returns:
a File object

getFiles

public Vector getFiles()
Returns a Vector of (java.io.File) objects containing the files in this list.
Returns:
a Vector

getSize

public int getSize()
Returns the size of the list, which only includes directories if the JFileChooser is set to DIRECTORIES_ONLY. Otherwise, both directories and files are included in the count.
Specified by:
getSize in interface ListModel
Returns:
The size of the list.

indexOf

public int indexOf(Object o)
Returns the index of an (java.io.File) object in the list.
Parameters:
o - The object - normally a File.
Returns:
the index of that object, or -1 if it is not in the list.

intervalAdded

public void intervalAdded(ListDataEvent e)
Obsoleted method which does nothing.

intervalRemoved

public void intervalRemoved(ListDataEvent e)
Obsoleted method which does nothing.

invalidateFileCache

public void invalidateFileCache()
Obsoleted method which does nothing.

lt

protected boolean lt(File a,
                     File b)
Less than, determine the relative order in the list of two files for sorting purposes. The order is: directories <32files, and thereafter alphabetically, using the default locale collation.
Parameters:
a - the first file
b - the second file
Returns:
true if a > b, false if a <32b.

propertyChange

public void propertyChange(PropertyChangeEvent e)
Listens for a property change; the change in file selection mode of the associated JFileChooser. Reloads the file cache on that event.
Specified by:
propertyChange in interface PropertyChangeListener
Parameters:
e - - A PropertyChangeEvent.

renameFile

public boolean renameFile(File oldFile,
                          File newFile)
Renames a file - However, does not re-sort the list or replace the old file with the new one in the list.
Parameters:
oldFile - The old file
newFile - The new file name
Returns:
true if the rename succeeded

sort

protected void sort(File> v)
Sorts a Vector of File objects.
Parameters:
v - The Vector to sort.

validateFileCache

public void validateFileCache()
Re-loads the list of files

BasicDirectoryModel.java -- Copyright (C) 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.