org.xnap.commons.gui.dnd
Class DefaultTreeFileTransferHandler

java.lang.Object
  extended by javax.swing.TransferHandler
      extended by org.xnap.commons.gui.dnd.AbstractFileTransferHandler
          extended by org.xnap.commons.gui.dnd.DefaultTreeFileTransferHandler
All Implemented Interfaces:
Serializable

public class DefaultTreeFileTransferHandler
extends AbstractFileTransferHandler

Provides a default file transfer handler for JTrees.

When a drag from a tree is initiated all selected paths are collected and their last path components, if they are files, are added to the FileTransferable that is created.

To support dragging of files you have to enable it for the tree, see JTree.setDragEnabled(boolean).

When a transferable with files is dropped on the tree, the handler tries to copy the dropped files to the first directory that is selected in the tree. A confirmation dialog is shown before copying if the boolean setting getShowCopyDialogSetting() is true.

Author:
Felix Berger
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.xnap.commons.gui.dnd.AbstractFileTransferHandler
linuxURIFlavor
 
Fields inherited from class javax.swing.TransferHandler
COPY, COPY_OR_MOVE, MOVE, NONE
 
Constructor Summary
DefaultTreeFileTransferHandler()
          Convenience constructor which creates a dummy boolean setting that says the copy confirmation dialog should not be shown.
DefaultTreeFileTransferHandler(BooleanSetting showCopyDialog)
          Constructs a file transfer handler for JTrees.
 
Method Summary
protected  Transferable createTransferable(JComponent c)
          Returns null.
 BooleanSetting getShowCopyDialogSetting()
          Returns the boolean setting which decides if a confirmation dialog is shown before any files are copied.
 boolean importFiles(JComponent comp, List<File> files)
          Returns false if no directory is selected in the tree where the files could be dropped into or the selected file is not an existent directory.
 void setShowCopyDialogSetting(BooleanSetting setting)
          Sets the boolean setting which decides if a confirmation dialog is shown before any files are copied.
 
Methods inherited from class org.xnap.commons.gui.dnd.AbstractFileTransferHandler
canImport, getSourceActions, importData
 
Methods inherited from class javax.swing.TransferHandler
exportAsDrag, exportDone, exportToClipboard, getCopyAction, getCutAction, getPasteAction, getVisualRepresentation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultTreeFileTransferHandler

public DefaultTreeFileTransferHandler(BooleanSetting showCopyDialog)
Constructs a file transfer handler for JTrees.

Parameters:
showCopyDialog - the boolean setting which decides if a confirmation dialog is shown before dropped files are copied to the selected directory in the tree.
Throws:
NullPointerException - if showCopyDialog is null.

DefaultTreeFileTransferHandler

public DefaultTreeFileTransferHandler()
Convenience constructor which creates a dummy boolean setting that says the copy confirmation dialog should not be shown.

See DefaultTreeFileTransferHandler(BooleanSetting) and Dialogs.showCopyDialog(Component, File[], File, BooleanSetting).

Method Detail

setShowCopyDialogSetting

public void setShowCopyDialogSetting(BooleanSetting setting)
Sets the boolean setting which decides if a confirmation dialog is shown before any files are copied.

See Dialogs.showCopyDialog(Component, File[], File, BooleanSetting).

Throws:
NullPointerException - if setting is null.

getShowCopyDialogSetting

public BooleanSetting getShowCopyDialogSetting()
Returns the boolean setting which decides if a confirmation dialog is shown before any files are copied.


createTransferable

protected Transferable createTransferable(JComponent c)
Description copied from class: AbstractFileTransferHandler
Returns null.

Subclasses can return a FileTransferable.

Overrides:
createTransferable in class AbstractFileTransferHandler

importFiles

public boolean importFiles(JComponent comp,
                           List<File> files)
Returns false if no directory is selected in the tree where the files could be dropped into or the selected file is not an existent directory.

Otherwise files are copied to the specified directory while a progress dialog is displayed.

Overrides:
importFiles in class AbstractFileTransferHandler


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