TrueZIP 6.8.2

de.schlichtherle.io.swing
Class JFileTree

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JTree
                  extended by de.schlichtherle.io.swing.JFileTree
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable

public class JFileTree
extends JTree

A custom JTree to browse files and directories. There are a couple of file creation/modification/removal methods added which notify the tree of any changes in the file system and update the current path expansions and selection.

Since:
TrueZIP 5.1
Version:
$Id: JFileTree.java 06f3ba684701 2010/11/04 01:15:55 christian $
Author:
Christian Schlichtherle
See Also:
Serialized Form

Nested Class Summary
private  class JFileTree.Controller
           
 
Nested classes/interfaces inherited from class javax.swing.JTree
JTree.AccessibleJTree, JTree.DropLocation, JTree.DynamicUtilTreeNode, JTree.EmptySelectionModel, JTree.TreeModelHandler, JTree.TreeSelectionRedirector
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
private  JFileTree.Controller controller
           
private  String defaultSuffix
          Holds value of property defaultSuffix.
private  boolean displayingSuffixes
          Holds value of property displayingSuffixes.
private  File editedNode
          Holds value of property editedNode.
private  boolean editingSuffixes
          Holds value of property editingSuffixes.
private static String PROPERTY_DEFAULT_SUFFIX
          The name of the property defaultSuffix.
private static String PROPERTY_DISPLAYING_SUFFIXES
          The name of the property displayingSuffixes.
private static String PROPERTY_EDITING_SUFFIXES
          The name of the property editingSuffixes.
 
Fields inherited from class javax.swing.JTree
ANCHOR_SELECTION_PATH_PROPERTY, CELL_EDITOR_PROPERTY, CELL_RENDERER_PROPERTY, cellEditor, cellRenderer, 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, treeModel, 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
JFileTree()
          Creates an empty JFileTree with no root.
JFileTree(File root)
          Creates a new JFileTree which traverses the given root File.
JFileTree(FileTreeModel model)
          Creates a new JFileTree which traverses the given FileTreeModel.
 
Method Summary
 boolean archiveCopyAllTo(File oldNode, File node)
          Forwards the call to the FileTreeModel and scrolls the tree so that the recursively copied node is selected and visible.
 boolean archiveCopyTo(File oldNode, File node)
          Forwards the call to the FileTreeModel and scrolls the tree so that the copied node is selected and visible.
 void cancelEditing()
           
 String convertValueToText(Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)
           
 boolean copyAllTo(File oldNode, File node)
          Forwards the call to the FileTreeModel and scrolls the tree so that the recursively copied node is selected and visible.
 boolean copyFrom(File node, InputStream in)
          Forwards the call to the FileTreeModel and scrolls the tree so that the copied node is selected and visible.
 boolean copyTo(File oldNode, File node)
          Forwards the call to the FileTreeModel and scrolls the tree so that the copied node is selected and visible.
 boolean createNewFile(File node)
          Forwards the call to the FileTreeModel and scrolls the tree so that the newly created file is selected and visible.
protected  TreeCellRenderer createTreeCellRenderer()
          Returns a new tree cell renderer.
 boolean delete(File node)
          Forwards the call to the FileTreeModel and scrolls the tree so that the successor to the deleted node is selected and visible.
 boolean deleteAll(File node)
          Forwards the call to the FileTreeModel and scrolls the tree so that the successor to the deleted node is selected and visible.
 String getDefaultSuffix()
          Getter for bound property defaultSuffix.
 File getEditedNode()
          Returns the node that is currently edited, if any.
private  String getSuffix(String base)
           
 boolean isDisplayingSuffixes()
          Getter for bound property displayingSuffixes.
 boolean isEditing()
           
 boolean isEditingSuffixes()
          Getter for bound property editingSuffixes.
 boolean mkdir(File node)
          Forwards the call to the FileTreeModel and scrolls the tree so that the newly created directory is selected and visible.
 boolean mkdirs(File node)
          Forwards the call to the FileTreeModel and scrolls the tree so that the newly created directory is selected and visible.
protected  void onEditingStopped(ChangeEvent evt)
          Called when the editing of a cell has been stopped.
 void refresh()
          Refreshes the entire tree, restores the expanded and selected paths and scrolls to the lead selection path if necessary.
 void refresh(File node)
          Refreshes the subtree for the given node, restores the expanded and selected paths and scrolls to the lead selection path if necessary.
 void refresh(TreePath[] paths)
          Refreshes the subtree for the given paths, restores the expanded and selected paths and scrolls to the lead selection path if necessary.
 boolean renameTo(File oldNode, File node)
          Forwards the call to the FileTreeModel, restores the expanded paths, selects node and scrolls to it if necessary.
 void scrollNodeToVisible(File node)
           
 void setDefaultSuffix(String defaultSuffix)
          Setter for bound property defaultSuffixes.
 void setDisplayingSuffixes(boolean displayingSuffixes)
          Setter for bound property displayingSuffixes.
 void setEditable(boolean editable)
           
 void setEditingSuffixes(boolean editingSuffixes)
          Setter for bound property editingSuffixes.
private  void setExpandedDescendants(Enumeration expansions)
           
 void setModel(TreeModel model)
           
 void setSelectionNode(File node)
           
 void setSelectionNodes(File[] nodes)
           
 void startEditingAtPath(TreePath path)
           
 boolean stopEditing()
           
private  TreePath substPath(TreePath tp, TreePath oldPath, TreePath path)
           
 
Methods inherited from class javax.swing.JTree
addSelectionInterval, addSelectionPath, addSelectionPaths, addSelectionRow, addSelectionRows, addTreeExpansionListener, addTreeSelectionListener, addTreeWillExpandListener, clearSelection, clearToggledPaths, collapsePath, collapseRow, createTreeModel, createTreeModelListener, expandPath, expandRow, fireTreeCollapsed, fireTreeExpanded, fireTreeWillCollapse, fireTreeWillExpand, fireValueChanged, getAccessibleContext, getAnchorSelectionPath, getCellEditor, getCellRenderer, getClosestPathForLocation, getClosestRowForLocation, getDefaultTreeModel, getDescendantToggledPaths, getDragEnabled, getDropLocation, getDropMode, 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, getToolTipText, getTreeExpansionListeners, getTreeSelectionListeners, getTreeWillExpandListeners, getUI, getUIClassID, getVisibleRowCount, hasBeenExpanded, isCollapsed, isCollapsed, isEditable, 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, setDropMode, setExpandedState, setExpandsSelectedPaths, setInvokesStopCellEditing, setLargeModel, setLeadSelectionPath, setRootVisible, setRowHeight, setScrollsOnExpand, setSelectionInterval, setSelectionModel, setSelectionPath, setSelectionPaths, setSelectionRow, setSelectionRows, setShowsRootHandles, setToggleClickCount, setUI, setVisibleRowCount, treeDidChange, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, 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, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, 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, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, 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, removePropertyChangeListener, removePropertyChangeListener, 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

PROPERTY_DISPLAYING_SUFFIXES

private static final String PROPERTY_DISPLAYING_SUFFIXES
The name of the property displayingSuffixes.

See Also:
Constant Field Values

PROPERTY_EDITING_SUFFIXES

private static final String PROPERTY_EDITING_SUFFIXES
The name of the property editingSuffixes.

See Also:
Constant Field Values

PROPERTY_DEFAULT_SUFFIX

private static final String PROPERTY_DEFAULT_SUFFIX
The name of the property defaultSuffix.

See Also:
Constant Field Values

controller

private final JFileTree.Controller controller

displayingSuffixes

private boolean displayingSuffixes
Holds value of property displayingSuffixes.


editingSuffixes

private boolean editingSuffixes
Holds value of property editingSuffixes.


defaultSuffix

private String defaultSuffix
Holds value of property defaultSuffix.


editedNode

private File editedNode
Holds value of property editedNode.

Constructor Detail

JFileTree

public JFileTree()
Creates an empty JFileTree with no root. You shouldn't use this constructor. It's only provided to implement the JavaBean pattern.


JFileTree

public JFileTree(File root)
Creates a new JFileTree which traverses the given root File. The ZipDetector of the given file is used to detect and configure any ZIP compatible files in this directory tree.

See Also:
File.getDefaultArchiveDetector(), File.setDefaultArchiveDetector(ArchiveDetector)

JFileTree

public JFileTree(FileTreeModel model)
Creates a new JFileTree which traverses the given FileTreeModel.

Method Detail

createTreeCellRenderer

protected TreeCellRenderer createTreeCellRenderer()
Returns a new tree cell renderer. This method may be overridden by subclasses.

This implementation simply returns a new FileTreeCellRenderer.


setModel

public void setModel(TreeModel model)
Overrides:
setModel in class JTree
Throws:
ClassCastException - If model is not an instance of FileTreeModel.

setEditable

public void setEditable(boolean editable)
Overrides:
setEditable in class JTree

isDisplayingSuffixes

public boolean isDisplayingSuffixes()
Getter for bound property displayingSuffixes.

Returns:
Value of property displayingSuffixes.

setDisplayingSuffixes

public void setDisplayingSuffixes(boolean displayingSuffixes)
Setter for bound property displayingSuffixes. If this is false, the suffix of files will not be displayed in this tree. Defaults to true.

Parameters:
displayingSuffixes - New value of property displayingSuffixes.

isEditingSuffixes

public boolean isEditingSuffixes()
Getter for bound property editingSuffixes.

Returns:
Value of property editingSuffixes.

setEditingSuffixes

public void setEditingSuffixes(boolean editingSuffixes)
Setter for bound property editingSuffixes. If this is false, the suffix of a file will be truncated before editing its name starts. Defaults to true.

Parameters:
editingSuffixes - New value of property editingSuffixes.

getDefaultSuffix

public String getDefaultSuffix()
Getter for bound property defaultSuffix.

Returns:
Value of property defaultSuffix.

setDefaultSuffix

public void setDefaultSuffix(String defaultSuffix)
Setter for bound property defaultSuffixes. Sets the default suffix to use when suffixes are shown and allowed to be edited, but the user did not provide a suffix when editing a file name. This property defaults to null and is ignored for directories.

Parameters:
defaultSuffix - The new default suffix. If not null, this parameter is fixed to always start with a '.'.

getEditedNode

public File getEditedNode()
Returns the node that is currently edited, if any. This method is not intended for public use - do not use it!


isEditing

public boolean isEditing()
Overrides:
isEditing in class JTree

startEditingAtPath

public void startEditingAtPath(TreePath path)
Overrides:
startEditingAtPath in class JTree

cancelEditing

public void cancelEditing()
Overrides:
cancelEditing in class JTree

stopEditing

public boolean stopEditing()
Overrides:
stopEditing in class JTree

onEditingStopped

protected void onEditingStopped(ChangeEvent evt)
Called when the editing of a cell has been stopped. The implementation in this class will rename the edited file, obeying the rules for suffix handling and updating the expanded and selected paths accordingly.

Parameters:
evt - The change event passed to CellEditorListener.editingStopped(ChangeEvent).

getSuffix

private String getSuffix(String base)

convertValueToText

public String convertValueToText(Object value,
                                 boolean selected,
                                 boolean expanded,
                                 boolean leaf,
                                 int row,
                                 boolean hasFocus)
Overrides:
convertValueToText in class JTree

refresh

public void refresh()
Refreshes the entire tree, restores the expanded and selected paths and scrolls to the lead selection path if necessary.


refresh

public void refresh(File node)
Refreshes the subtree for the given node, restores the expanded and selected paths and scrolls to the lead selection path if necessary.

Parameters:
node - The file or directory to refresh. This may not be null.

refresh

public void refresh(TreePath[] paths)
Refreshes the subtree for the given paths, restores the expanded and selected paths and scrolls to the lead selection path if necessary.

Parameters:
paths - The array of TreePaths to refresh. This may be null.

setExpandedDescendants

private void setExpandedDescendants(Enumeration expansions)

createNewFile

public boolean createNewFile(File node)
                      throws IOException
Forwards the call to the FileTreeModel and scrolls the tree so that the newly created file is selected and visible. If you would like to create a new file with initial content, please check copyFrom(de.schlichtherle.io.File, InputStream).

Throws:
IOException

mkdir

public boolean mkdir(File node)
Forwards the call to the FileTreeModel and scrolls the tree so that the newly created directory is selected and visible.


mkdirs

public boolean mkdirs(File node)
Forwards the call to the FileTreeModel and scrolls the tree so that the newly created directory is selected and visible.


copyFrom

public boolean copyFrom(File node,
                        InputStream in)
Forwards the call to the FileTreeModel and scrolls the tree so that the copied node is selected and visible.


copyTo

public boolean copyTo(File oldNode,
                      File node)
Forwards the call to the FileTreeModel and scrolls the tree so that the copied node is selected and visible.


copyAllTo

public boolean copyAllTo(File oldNode,
                         File node)
Forwards the call to the FileTreeModel and scrolls the tree so that the recursively copied node is selected and visible.


archiveCopyTo

public boolean archiveCopyTo(File oldNode,
                             File node)
Forwards the call to the FileTreeModel and scrolls the tree so that the copied node is selected and visible.


archiveCopyAllTo

public boolean archiveCopyAllTo(File oldNode,
                                File node)
Forwards the call to the FileTreeModel and scrolls the tree so that the recursively copied node is selected and visible.


renameTo

public boolean renameTo(File oldNode,
                        File node)
Forwards the call to the FileTreeModel, restores the expanded paths, selects node and scrolls to it if necessary.


substPath

private TreePath substPath(TreePath tp,
                           TreePath oldPath,
                           TreePath path)

delete

public boolean delete(File node)
Forwards the call to the FileTreeModel and scrolls the tree so that the successor to the deleted node is selected and visible.


deleteAll

public boolean deleteAll(File node)
Forwards the call to the FileTreeModel and scrolls the tree so that the successor to the deleted node is selected and visible.


setSelectionNode

public void setSelectionNode(File node)

setSelectionNodes

public void setSelectionNodes(File[] nodes)

scrollNodeToVisible

public void scrollNodeToVisible(File node)

TrueZIP 6.8.2

Copyright © 2005-2011 Schlichtherle IT Services. All Rights Reserved.