org.fife.ui.rtextfilechooser
Class FileSystemTree

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JTree
                  extended byorg.fife.ui.ToolTipTree
                      extended byorg.fife.ui.rtextfilechooser.FileSystemTree
All Implemented Interfaces:
javax.accessibility.Accessible, FileSelector, java.awt.image.ImageObserver, java.awt.MenuContainer, javax.swing.Scrollable, java.io.Serializable
Direct Known Subclasses:
DirectoryTree

public class FileSystemTree
extends ToolTipTree
implements FileSelector

A tree containing all files in the local host's file system. So that you can create components that contain a FileSystemTree, the following property change events are fired when the tree is manipulated:

Version:
0.8
Author:
Robert Futrell
See Also:
Serialized Form

Nested Class Summary
static class FileSystemTree.FileSystemTreeModel
           
static class FileSystemTree.FileSystemTreeNode
          The tree node used by the file tree.
 
Nested classes inherited from class javax.swing.JTree
javax.swing.JTree.AccessibleJTree, javax.swing.JTree.DynamicUtilTreeNode, javax.swing.JTree.EmptySelectionModel, javax.swing.JTree.TreeModelHandler, javax.swing.JTree.TreeSelectionRedirector
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static java.lang.String EXPANDED_PROPERTY
           
protected  org.fife.ui.rtextfilechooser.FileChooserIconManager iconManager
           
protected  org.fife.ui.rtextfilechooser.FileSystemTreeActions.NewFileAction newFileAction
           
protected  javax.swing.JPopupMenu popup
           
static java.lang.String WILL_EXPAND_PROPERTY
           
 
Fields inherited from class javax.swing.JTree
ANCHOR_SELECTION_PATH_PROPERTY, CELL_EDITOR_PROPERTY, CELL_RENDERER_PROPERTY, cellEditor, editable, EDITABLE_PROPERTY, EXPANDS_SELECTED_PATHS_PROPERTY, INVOKES_STOP_CELL_EDITING_PROPERTY, invokesStopCellEditing, LARGE_MODEL_PROPERTY, largeModel, LEAD_SELECTION_PATH_PROPERTY, ROOT_VISIBLE_PROPERTY, rootVisible, ROW_HEIGHT_PROPERTY, rowHeight, SCROLLS_ON_EXPAND_PROPERTY, scrollsOnExpand, SELECTION_MODEL_PROPERTY, selectionModel, selectionRedirector, SHOWS_ROOT_HANDLES_PROPERTY, showsRootHandles, TOGGLE_CLICK_COUNT_PROPERTY, toggleClickCount, TREE_MODEL_PROPERTY, treeModelListener, VISIBLE_ROW_COUNT_PROPERTY, visibleRowCount
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
FileSystemTree()
          Constructor.
FileSystemTree(java.io.File rootDir)
          Constructor.
 
Method Summary
protected  void collapseAllNodes()
          Collapses all tree nodes.
protected  void configurePopupMenuActions()
          Called right before the popup menu is displayed.
 java.lang.String convertValueToText(java.lang.Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)
           
protected  javax.swing.JPopupMenu createPopupMenu()
          Creates the popup menu for this file system tree.
 FileSystemTree.FileSystemTreeNode createTreeNodeFor(java.io.File file)
          Creates a tree node for the specified file.
protected  FileSystemTree.FileSystemTreeNode createTreeNodeForImpl(java.io.File file, boolean directory)
          Creates a tree node for the specified file.
protected  java.io.File[] filterAndSort(java.io.File[] files)
          Does any filtering and sorting of an array of files so that they will be displayed properly.
 void fireTreeExpanded(javax.swing.tree.TreePath e)
          Called when a node has expanded.
 void fireTreeWillExpand(javax.swing.tree.TreePath e)
          Called when a node is about to be expanded.
protected  java.lang.String getName(java.io.File file)
          Returns the display name for a given file.
 java.awt.Dimension getPreferredSize()
          This method is overridden to ensure that this tree is given a little bit of room if it is placed into a JScrollPane (which is likely).
 java.io.File getRoot()
          Returns the directory being used as the invisible "root" of this tree.
 java.io.File getSelectedFile()
          Returns the file currently selected by the user.
 java.lang.String getSelectedFileName()
          Returns the name of the file currently selected by the user.
 java.io.File[] getSelectedFiles()
          Returns any selected files.
 java.lang.String getToolTipText(java.awt.event.MouseEvent e)
          Returns the string to use for the tooltip.
protected  void processMouseEvent(java.awt.event.MouseEvent e)
          Called when a mouse event occurs in this file system tree.
 void setRoot(java.io.File rootFile)
          Changes the "root" of this tree.
 boolean setSelectedFile(java.io.File file)
          Selects the given file in the tree.
 void updateUI()
          Overridden so that the renderer is also updated on a LnF change.
 
Methods inherited from class org.fife.ui.ToolTipTree
getToolTipLocation, getToolTipsEnabled, initialize, setToolTipsEnabled
 
Methods inherited from class javax.swing.JTree
addSelectionInterval, addSelectionPath, addSelectionPaths, addSelectionRow, addSelectionRows, addTreeExpansionListener, addTreeSelectionListener, addTreeWillExpandListener, cancelEditing, clearSelection, clearToggledPaths, collapsePath, collapseRow, createTreeModel, createTreeModelListener, expandPath, expandRow, fireTreeCollapsed, fireTreeWillCollapse, fireValueChanged, getAccessibleContext, getAnchorSelectionPath, getCellEditor, getCellRenderer, getClosestPathForLocation, getClosestRowForLocation, getDefaultTreeModel, getDescendantToggledPaths, getDragEnabled, getEditingPath, getExpandedDescendants, getExpandsSelectedPaths, getInvokesStopCellEditing, getLastSelectedPathComponent, getLeadSelectionPath, getLeadSelectionRow, getMaxSelectionRow, getMinSelectionRow, getModel, getNextMatch, getPathBetweenRows, getPathBounds, getPathForLocation, getPathForRow, getPreferredScrollableViewportSize, getRowBounds, getRowCount, getRowForLocation, getRowForPath, getRowHeight, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getScrollsOnExpand, getSelectionCount, getSelectionModel, getSelectionPath, getSelectionPaths, getSelectionRows, getShowsRootHandles, getToggleClickCount, getTreeExpansionListeners, getTreeSelectionListeners, getTreeWillExpandListeners, getUI, getUIClassID, getVisibleRowCount, hasBeenExpanded, isCollapsed, isCollapsed, isEditable, isEditing, isExpanded, isExpanded, isFixedRowHeight, isLargeModel, isPathEditable, isPathSelected, isRootVisible, isRowSelected, isSelectionEmpty, isVisible, makeVisible, paramString, removeDescendantSelectedPaths, removeDescendantToggledPaths, removeSelectionInterval, removeSelectionPath, removeSelectionPaths, removeSelectionRow, removeSelectionRows, removeTreeExpansionListener, removeTreeSelectionListener, removeTreeWillExpandListener, scrollPathToVisible, scrollRowToVisible, setAnchorSelectionPath, setCellEditor, setCellRenderer, setDragEnabled, setEditable, setExpandedState, setExpandsSelectedPaths, setInvokesStopCellEditing, setLargeModel, setLeadSelectionPath, setModel, setRootVisible, setRowHeight, setScrollsOnExpand, setSelectionInterval, setSelectionModel, setSelectionPath, setSelectionPaths, setSelectionRow, setSelectionRows, setShowsRootHandles, setToggleClickCount, setUI, setVisibleRowCount, startEditingAtPath, stopEditing, treeDidChange
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

EXPANDED_PROPERTY

public static final java.lang.String EXPANDED_PROPERTY
See Also:
Constant Field Values

WILL_EXPAND_PROPERTY

public static final java.lang.String WILL_EXPAND_PROPERTY
See Also:
Constant Field Values

iconManager

protected org.fife.ui.rtextfilechooser.FileChooserIconManager iconManager

popup

protected javax.swing.JPopupMenu popup

newFileAction

protected org.fife.ui.rtextfilechooser.FileSystemTreeActions.NewFileAction newFileAction
Constructor Detail

FileSystemTree

public FileSystemTree()
Constructor. This will create a tree with a root node for each root drive on the local file system.


FileSystemTree

public FileSystemTree(java.io.File rootDir)
Constructor.

Parameters:
rootDir - The root directory for the tree.
Throws:
java.lang.IllegalArgumentException - If this directory does not exist.
Method Detail

collapseAllNodes

protected void collapseAllNodes()
Collapses all tree nodes.


configurePopupMenuActions

protected void configurePopupMenuActions()
Called right before the popup menu is displayed. This method gives subclasses a chance to configure any extra actions or menu items they have added to the popup menu, so they are tailored to the selected item. popup has been created before this method is called. Subclasses should call the super implementation when overriding this method.


convertValueToText

public java.lang.String convertValueToText(java.lang.Object value,
                                           boolean selected,
                                           boolean expanded,
                                           boolean leaf,
                                           int row,
                                           boolean hasFocus)

createPopupMenu

protected javax.swing.JPopupMenu createPopupMenu()
Creates the popup menu for this file system tree. Subclasses can override this method if they wish to add more menu items to the popup menu.

Returns:
The popup menu for this file system tree.

createTreeNodeFor

public FileSystemTree.FileSystemTreeNode createTreeNodeFor(java.io.File file)
Creates a tree node for the specified file.

Parameters:
file - The file for which to create a tree node.
Returns:
The tree node for the file.

createTreeNodeForImpl

protected FileSystemTree.FileSystemTreeNode createTreeNodeForImpl(java.io.File file,
                                                                  boolean directory)
Creates a tree node for the specified file. This version of the method is for when you know ahead of time whether the file is a directory such as when the file is a "root"). This greatly speeds things up, as isDirectory() is notoriously slow.

Parameters:
file - The file for which to create a tree node.
directory - Whether the specified file is a directory.
Returns:
The tree node for the file.

filterAndSort

protected java.io.File[] filterAndSort(java.io.File[] files)
Does any filtering and sorting of an array of files so that they will be displayed properly. For example this method sorts the array so that directories are all listed before regular files. Subclasses can override this method to do other things, such as only display directories.

Parameters:
files - The array of files to filter and sort.
Returns:
The filtered and sorted array of files.

fireTreeExpanded

public void fireTreeExpanded(javax.swing.tree.TreePath e)
Called when a node has expanded.


fireTreeWillExpand

public void fireTreeWillExpand(javax.swing.tree.TreePath e)
                        throws javax.swing.tree.ExpandVetoException
Called when a node is about to be expanded. This method is overridden so that the node that is being expanded will be populated with its subdirectories, if necessary.

Throws:
javax.swing.tree.ExpandVetoException

getName

protected java.lang.String getName(java.io.File file)
Returns the display name for a given file.

Parameters:
file - The file for which to get the display name.
Returns:
The display name.

getPreferredSize

public java.awt.Dimension getPreferredSize()
This method is overridden to ensure that this tree is given a little bit of room if it is placed into a JScrollPane (which is likely). If you don't do this, the tree's preferred width will only be the maximum width of one of its visible nodes, so it will appear "squished" into whatever frame/dialog it's in.

Returns:
The preferred size of this tree.

getRoot

public java.io.File getRoot()
Returns the directory being used as the invisible "root" of this tree.

Returns:
The root directory, or null if none (i.e., if all file system roots are being shown instead).
See Also:
setRoot(File)

getSelectedFile

public java.io.File getSelectedFile()
Returns the file currently selected by the user.

Specified by:
getSelectedFile in interface FileSelector
Returns:
The file currently selected, or null if no file is selected.
See Also:
getSelectedFileName(), setSelectedFile(java.io.File)

getSelectedFiles

public java.io.File[] getSelectedFiles()
Returns any selected files. This will always be either a zero-length array, or an array containing only the value returned from getSelectedFile(), since this component only allows selection of one file at a time.

Specified by:
getSelectedFiles in interface FileSelector
Returns:
The selected files.

getSelectedFileName

public java.lang.String getSelectedFileName()
Returns the name of the file currently selected by the user.

Returns:
The name of the file currently selected, or null if no file is selected.
See Also:
getSelectedFile(), setSelectedFile(java.io.File)

getToolTipText

public java.lang.String getToolTipText(java.awt.event.MouseEvent e)
Returns the string to use for the tooltip.

Overrides:
getToolTipText in class ToolTipTree
Returns:
The tooltip text.

processMouseEvent

protected void processMouseEvent(java.awt.event.MouseEvent e)
Called when a mouse event occurs in this file system tree. This method is overridden so that we can display our popup menu if necessary.

Parameters:
e - The mouse event.

setRoot

public void setRoot(java.io.File rootFile)
Changes the "root" of this tree.

Parameters:
rootFile - The new root. If this is null, then all of the file system's roots are used. If it is a directory, then that directory is used. If it is a plain file, or does not exist, an IllegalArgumentException is thrown.
See Also:
getRoot()

setSelectedFile

public boolean setSelectedFile(java.io.File file)
Selects the given file in the tree. If the file does not exist, then the selection is cleared.

Parameters:
file - The file to select.
Returns:
Whether the file exists and was selected.
See Also:
getSelectedFile()

updateUI

public void updateUI()
Overridden so that the renderer is also updated on a LnF change. If we don't do this, the renderer will still work, but will use the "background color" and other colors from the original LnF.