org.xnap.commons.gui.dnd
Class DefaultTextFieldFileTransferHandler

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

public class DefaultTextFieldFileTransferHandler
extends AbstractFileTransferHandler

Provides a default file transfer handler for JTextFields.

When creating a transferable the text of the textfield is interpreted as the absolute path of the file.

When a file is dropped on the text field, the file's absolute path replaces the current text of the text field.

Use the static install(JTextField) method to install it for a text field.

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
protected DefaultTextFieldFileTransferHandler()
           
 
Method Summary
protected  Transferable createTransferable(JComponent c)
          Returns null, if the text field is empty or disabled.
 boolean importFiles(JComponent comp, List<File> files)
          Overriden to set the text of the textfield to the absolute path of the first file of the list.
static void install(JTextField textField)
          Installs the default file transfer handler for this textField Does not activate dragging, call JTextComponent.setDragEnabled(boolean) to enable it.
 
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

DefaultTextFieldFileTransferHandler

protected DefaultTextFieldFileTransferHandler()
Method Detail

install

public static void install(JTextField textField)
Installs the default file transfer handler for this textField

Does not activate dragging, call JTextComponent.setDragEnabled(boolean) to enable it.

The transfer handler can be be removed by calling textField.setTransferHandler(null).

Parameters:
textField -

createTransferable

protected Transferable createTransferable(JComponent c)
Returns null, if the text field is empty or disabled.

Overrides:
createTransferable in class AbstractFileTransferHandler

importFiles

public boolean importFiles(JComponent comp,
                           List<File> files)
Overriden to set the text of the textfield to the absolute path of the first file of the list.

Overrides:
importFiles in class AbstractFileTransferHandler


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