org.xnap.commons.gui.completion
Class FileCompletionModel

java.lang.Object
  extended by javax.swing.AbstractListModel
      extended by javax.swing.DefaultComboBoxModel
          extended by org.xnap.commons.gui.completion.FileCompletionModel
All Implemented Interfaces:
Serializable, ComboBoxModel, ListModel, MutableComboBoxModel, CompletionModel

public class FileCompletionModel
extends DefaultComboBoxModel
implements CompletionModel

This class provides completion for path prefixes on the local file system.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.AbstractListModel
listenerList
 
Constructor Summary
FileCompletionModel()
          Constructs a new file completion model.
FileCompletionModel(boolean completeOnlyDirectories)
          Constructs a new file completion model.
 
Method Summary
 boolean complete(String prefix)
          Returns true if there are files in the local file system having the given prefix.
 String completeUniquePrefix(String prefix)
          This method's behaviour is a matter of taste.
 void setCompleteDirectoriesOnly(boolean complete)
          Set whether only directories should be suggested as possible completions.
 void setCompleteHiddenFiles(boolean complete)
          Set whether hidden files should be suggested as possible completions.
 
Methods inherited from class javax.swing.DefaultComboBoxModel
addElement, getElementAt, getIndexOf, getSelectedItem, getSize, insertElementAt, removeAllElements, removeElement, removeElementAt, setSelectedItem
 
Methods inherited from class javax.swing.AbstractListModel
addListDataListener, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, getListDataListeners, getListeners, removeListDataListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.swing.MutableComboBoxModel
addElement, insertElementAt, removeElement, removeElementAt
 
Methods inherited from interface javax.swing.ComboBoxModel
getSelectedItem, setSelectedItem
 
Methods inherited from interface javax.swing.ListModel
addListDataListener, getElementAt, getSize, removeListDataListener
 

Constructor Detail

FileCompletionModel

public FileCompletionModel(boolean completeOnlyDirectories)
Constructs a new file completion model.

Parameters:
completeOnlyDirectories - if true only subdirectories are suggested as possible completions, otherwise files are taken into account too

FileCompletionModel

public FileCompletionModel()
Constructs a new file completion model. The default setting is to complete subdirectories and files.

Method Detail

setCompleteHiddenFiles

public void setCompleteHiddenFiles(boolean complete)
Set whether hidden files should be suggested as possible completions.

The default behavior is they are not suggested.


setCompleteDirectoriesOnly

public void setCompleteDirectoriesOnly(boolean complete)
Set whether only directories should be suggested as possible completions.

The default behavior is files and directories are suggested.


complete

public boolean complete(String prefix)
Returns true if there are files in the local file system having the given prefix. First we test if the given prefix denotes a file which exists and is a directory. If that is the case all the files contained in that directory are added to the model. Regardless of the above results the parent directory, if there is, one is searched for files matching the prefix. Thus we get all possible completions that make sense.

Specified by:
complete in interface CompletionModel
Parameters:
prefix - the prefix being matched
Returns:
true, if completion was successful, i.e. the prefix matches at least one item in the model

completeUniquePrefix

public String completeUniquePrefix(String prefix)
This method's behaviour is a matter of taste. It first checks if the given prefix is an existing directory. If that is the case the commmon unique prefix of all files found in the directory is returned. Only if the above fails the parent directory is searched for the common unique prefix.

Specified by:
completeUniquePrefix in interface CompletionModel
Parameters:
prefix - the prefix being matched
Returns:
the largest common prefix of all possible matches, the prefix given if no longer prefix can be found


Copyright © 2004-2007 XNap Commons Team. All Rights Reserved.