Module org.monte.media.swing
Class DropFileTransferHandler
java.lang.Object
javax.swing.TransferHandler
org.monte.media.swing.datatransfer.DropFileTransferHandler
- All Implemented Interfaces:
Serializable
The DropFileTransferHandler can be used to add drag and drop
support. When a file is dropped, the supplied ActionListner is invoked.
The filename is passed in the action command.
- Author:
- Werner Randelshofer
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.TransferHandler
TransferHandler.DropLocation, TransferHandler.TransferSupport -
Field Summary
Fields inherited from class javax.swing.TransferHandler
COPY, COPY_OR_MOVE, LINK, MOVE, NONE -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance.DropFileTransferHandler(int fileSelectionMode) Creates a new instance.DropFileTransferHandler(int fileSelectionMode, FileFilter filter) Creates a new instance.DropFileTransferHandler(int fileSelectionMode, FileFilter filter, ActionListener l) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionbooleancanImport(JComponent comp, DataFlavor[] transferFlavors) protected TransferablecreateTransferable(JComponent comp) protected voidexportDone(JComponent comp, Transferable data, int action) This method is called after data has been exported.protected DataFlavorgetImportFlavor(DataFlavor[] flavors, JComponent c) Try to find a flavor that can be used to import a Transferable.intgetSourceActions(JComponent comp) This is the type of transfer actions supported by the source.booleanimportData(JComponent c, Transferable t) voidvoidsetFileFilter(FileFilter fileFilter) Methods inherited from class javax.swing.TransferHandler
canImport, exportAsDrag, exportToClipboard, getCopyAction, getCutAction, getDragImage, getDragImageOffset, getPasteAction, getVisualRepresentation, importData, setDragImage, setDragImageOffset
-
Constructor Details
-
DropFileTransferHandler
public DropFileTransferHandler()Creates a new instance. -
DropFileTransferHandler
public DropFileTransferHandler(int fileSelectionMode) Creates a new instance.- Parameters:
fileSelectionMode- JFileChooser file selection mode.
-
DropFileTransferHandler
Creates a new instance.- Parameters:
fileSelectionMode- JFileChooser file selection mode.
-
DropFileTransferHandler
Creates a new instance.- Parameters:
fileSelectionMode- JFileChooser file selection mode.
-
-
Method Details
-
setActionListener
-
importData
- Overrides:
importDatain classTransferHandler
-
createTransferable
- Overrides:
createTransferablein classTransferHandler
-
canImport
- Overrides:
canImportin classTransferHandler
-
getImportFlavor
Try to find a flavor that can be used to import a Transferable. The set of usable flavors are tried in the following order:- First, an attempt to find a text/plain flavor is made.
- Second, an attempt to find a flavor representing a String reference in the same VM is made.
- Lastly, DataFlavor.stringFlavor is searched for.
-
getSourceActions
This is the type of transfer actions supported by the source. Some models are not mutable, so a transfer operation of COPY only should be advertised in that case.- Overrides:
getSourceActionsin classTransferHandler- Parameters:
comp- The component holding the data to be transfered. This argument is provided to enable sharing of TransferHandlers by multiple components.- Returns:
- This is implemented to return NONE if the component is a JPasswordField since exporting data via user gestures is not allowed. If the text component is editable, COPY_OR_MOVE is returned, otherwise just COPY is allowed.
-
exportDone
This method is called after data has been exported. This method should remove the data that was transfered if the action was MOVE.- Overrides:
exportDonein classTransferHandler- Parameters:
comp- The component that was the source of the data.data- The data that was transferred or possibly null if the action isNONE.action- The actual action that was performed.
-
getFileFilter
- Returns:
- the fileFilter
-
setFileFilter
- Parameters:
fileFilter- the fileFilter to set
-