TrueZIP File* 7.0

de.schlichtherle.truezip.file.swing
Class TFileTree

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.truezip.file.swing.TFileTree
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable

@DefaultAnnotation(value=edu.umd.cs.findbugs.annotations.NonNull.class)
public final class TFileTree
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.

Author:
Christian Schlichtherle
See Also:
Serialized Form

Nested Class Summary
private  class TFileTree.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  TFileTree.Controller controller
           
private  String defaultSuffix
           
private  boolean displayingSuffixes
           
private  TFile editedNode
           
private  boolean 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.
private static long serialVersionUID
           
 
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
TFileTree()
          Creates an empty TFileTree with no root.
TFileTree(TFile root)
          Creates a new TFileTree which traverses the given root root file.
TFileTree(TFileTreeModel model)
          Creates a new TFileTree which traverses the given TFileTreeModel.
 
Method Summary
 void cancelEditing()
           
 String convertValueToText(Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)
           
 void cp_p(TFile oldNode, TFile node)
          Forwards the call to the TFileTreeModel and scrolls the tree so that the copied node is selected and visible.
 void cp_r(TFile oldNode, TFile node)
          Forwards the call to the TFileTreeModel and scrolls the tree so that the recursively copied node is selected and visible.
 void cp_rp(TFile oldNode, TFile node)
          Forwards the call to the TFileTreeModel and scrolls the tree so that the recursively copied node is selected and visible.
 void cp(InputStream in, TFile node)
          Forwards the call to the TFileTreeModel and scrolls the tree so that the copied node is selected and visible.
 void cp(TFile oldNode, TFile node)
          Forwards the call to the TFileTreeModel and scrolls the tree so that the copied node is selected and visible.
 boolean createNewFile(TFile node)
          Forwards the call to the TFileTreeModel and scrolls the tree so that the newly created file is selected and visible.
 String getDefaultSuffix()
          Getter for bound property defaultSuffix.
(package private)  TFile getEditedNode()
          Returns the node that is currently edited, if any.
 TFileTreeModel getModel()
           
private  String getSuffix(String base)
           
 boolean isDisplayingSuffixes()
          Getter for bound property displayingSuffixes.
 boolean isEditing()
           
 boolean isEditingSuffixes()
          Getter for bound property editingSuffixes.
 void mkdir(TFile node, boolean recursive)
          Forwards the call to the TFileTreeModel and scrolls the tree so that the newly created directory is selected and visible.
 void mv(TFile oldNode, TFile node)
          Forwards the call to the TFileTreeModel, restores the expanded paths, selects node and scrolls to it if necessary.
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(TFile 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.
 void rm_r(TFile node)
          Forwards the call to the TFileTreeModel and scrolls the tree so that the successor to the deleted node is selected and visible.
 void rm(TFile node)
          Forwards the call to the TFileTreeModel and scrolls the tree so that the successor to the deleted node is selected and visible.
 void scrollNodeToVisible(TFile 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<TreePath> expansions)
           
 void setModel(TreeModel model)
          
 void setSelectionNode(TFile node)
           
 void setSelectionNodes(TFile[] 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, 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

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

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 TFileTree.Controller controller

displayingSuffixes

private boolean displayingSuffixes

editingSuffixes

private boolean editingSuffixes

defaultSuffix

@CheckForNull
private String defaultSuffix

editedNode

@CheckForNull
private transient TFile editedNode
Constructor Detail

TFileTree

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


TFileTree

public TFileTree(TFile root)
Creates a new TFileTree which traverses the given root root file.


TFileTree

public TFileTree(TFileTreeModel model)
Creates a new TFileTree which traverses the given TFileTreeModel.

Method Detail

getModel

public TFileTreeModel getModel()
Overrides:
getModel in class JTree

setModel

public void setModel(TreeModel model)

Overrides:
setModel in class JTree
Throws:
ClassCastException - if model is not an instance of TFileTreeModel.

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

@Nullable
public String getDefaultSuffix()
Getter for bound property defaultSuffix.

Returns:
Value of property defaultSuffix.

setDefaultSuffix

public void setDefaultSuffix(@CheckForNull
                             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

@Nullable
TFile getEditedNode()
Returns the node that is currently edited, if any.


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

@Nullable
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(TFile 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<TreePath> expansions)

createNewFile

public boolean createNewFile(TFile node)
                      throws IOException
Forwards the call to the TFileTreeModel 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 cp(InputStream, TFile).

Throws:
IOException - if any I/O error occurs.

mkdir

public void mkdir(TFile node,
                  boolean recursive)
           throws IOException
Forwards the call to the TFileTreeModel and scrolls the tree so that the newly created directory is selected and visible.

Throws:
IOException - if any I/O error occurs.

cp

public void cp(InputStream in,
               TFile node)
        throws IOException
Forwards the call to the TFileTreeModel and scrolls the tree so that the copied node is selected and visible.

Throws:
IOException - if any I/O error occurs.

cp

public void cp(TFile oldNode,
               TFile node)
        throws IOException
Forwards the call to the TFileTreeModel and scrolls the tree so that the copied node is selected and visible.

Throws:
IOException - if any I/O error occurs.

cp_r

public void cp_r(TFile oldNode,
                 TFile node)
          throws IOException
Forwards the call to the TFileTreeModel and scrolls the tree so that the recursively copied node is selected and visible.

Throws:
IOException - if any I/O error occurs.

cp_p

public void cp_p(TFile oldNode,
                 TFile node)
          throws IOException
Forwards the call to the TFileTreeModel and scrolls the tree so that the copied node is selected and visible.

Throws:
IOException - if any I/O error occurs.

cp_rp

public void cp_rp(TFile oldNode,
                  TFile node)
           throws IOException
Forwards the call to the TFileTreeModel and scrolls the tree so that the recursively copied node is selected and visible.

Throws:
IOException - if any I/O error occurs.

mv

public void mv(TFile oldNode,
               TFile node)
        throws IOException
Forwards the call to the TFileTreeModel, restores the expanded paths, selects node and scrolls to it if necessary.

Throws:
IOException - if any I/O error occurs.

substPath

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

rm

public void rm(TFile node)
        throws IOException
Forwards the call to the TFileTreeModel and scrolls the tree so that the successor to the deleted node is selected and visible.

Throws:
IOException - if any I/O error occurs.

rm_r

public void rm_r(TFile node)
          throws IOException
Forwards the call to the TFileTreeModel and scrolls the tree so that the successor to the deleted node is selected and visible.

Throws:
IOException - if any I/O error occurs.

setSelectionNode

public void setSelectionNode(TFile node)

setSelectionNodes

public void setSelectionNodes(TFile[] nodes)

scrollNodeToVisible

public void scrollNodeToVisible(TFile node)

TrueZIP File* 7.0

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