Module org.monte.media.swing
Class FileTextFieldTransferHandler
java.lang.Object
javax.swing.TransferHandler
org.monte.media.swing.datatransfer.FileTextFieldTransferHandler
- All Implemented Interfaces:
Serializable
The FileTextFieldTransferHandler can be used to add drag and drop
support for JTextFields, which contain the path to a file.
- 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.FileTextFieldTransferHandler(int fileSelectionMode) Creates a new instance.FileTextFieldTransferHandler(int fileSelectionMode, FileFilter filter) 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, JTextComponent 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.protected voidhandleReaderImport(Reader in, JTextComponent c, boolean useRead) Import the given stream data into the text component.booleanimportData(JComponent comp, Transferable t) voidsetFileFilter(FileFilter fileFilter) Methods inherited from class javax.swing.TransferHandler
canImport, exportAsDrag, exportToClipboard, getCopyAction, getCutAction, getDragImage, getDragImageOffset, getPasteAction, getVisualRepresentation, importData, setDragImage, setDragImageOffset
-
Constructor Details
-
FileTextFieldTransferHandler
public FileTextFieldTransferHandler()Creates a new instance. -
FileTextFieldTransferHandler
public FileTextFieldTransferHandler(int fileSelectionMode) Creates a new instance.- Parameters:
fileSelectionMode- JFileChooser file selection mode.
-
FileTextFieldTransferHandler
Creates a new instance.- Parameters:
fileSelectionMode- JFileChooser file selection mode.
-
-
Method Details
-
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.
-
handleReaderImport
protected void handleReaderImport(Reader in, JTextComponent c, boolean useRead) throws BadLocationException, IOException Import the given stream data into the text component.- Throws:
BadLocationExceptionIOException
-
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
-