java.lang.Object
com.iamsoft.util.ui.swing.FileDrop.TransferableObject
- All Implemented Interfaces:
Transferable
- Enclosing class:
- FileDrop
At last an easy way to encapsulate your custom objects for dragging and dropping
in your Java programs!
When you need to create a
Transferable object,
use this class to wrap your object.
For example:
...
MyCoolClass myObj = new MyCoolClass();
Transferable xfer = new TransferableObject( myObj );
...
Or if you need to know when the data was actually dropped, like when you're
moving data out of a list, say, you can use the FileDrop.TransferableObject.Fetcher
inner class to return your object Just in Time.
For example:
...
final MyCoolClass myObj = new MyCoolClass();
TransferableObject.Fetcher fetcher = new TransferableObject.Fetcher()
{ public Object getObject(){ return myObj; }
}; // end fetcher
Transferable xfer = new TransferableObject( fetcher );
...
The DataFlavor associated with
FileDrop.TransferableObject has the representation class
net.iharder.dnd.TransferableObject.class and MIME type
application/x-net.iharder.dnd.TransferableObject.
This data flavor is accessible via the static
DATA_FLAVOR property.
I'm releasing this code into the Public Domain. Enjoy.
- Version:
- 1.2
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceInstead of passing your data directly to theFileDrop.TransferableObjectconstructor, you may want to know exactly when your data was received in case you need to remove it from its source (or do anyting else to it). -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DataFlavorThe defaultDataFlavorforFileDrop.TransferableObjecthas the representation class net.iharder.dnd.TransferableObject.class and the MIME type application/x-net.iharder.dnd.TransferableObject.static final StringThe MIME type forDATA_FLAVORis application/x-net.iharder.dnd.TransferableObject. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a newFileDrop.TransferableObjectthat will return the object that is returned bypFetcher.TransferableObject(Class pDataClass, FileDrop.TransferableObject.Fetcher pFetcher) Creates a newFileDrop.TransferableObjectthat will return the object that is returned bypFetcher.TransferableObject(Object pData) Creates a newFileDrop.TransferableObjectthat wrapspData. -
Method Summary
Modifier and TypeMethodDescriptionReturns the customDataFlavorassociated with the encapsulated object or null if theFileDrop.TransferableObject.Fetcherconstructor was used without passing aClass.getTransferData(DataFlavor pFlavor) Returns the data encapsulated in thisFileDrop.TransferableObject.Returns a two- or three-element array containing first the custom data flavor, if one was created in the constructors, second the defaultDATA_FLAVORassociated withFileDrop.TransferableObject, and third theDataFlavor.stringFlavor.booleanisDataFlavorSupported(DataFlavor pFlavor) Returns true ifpFlavoris one of the supported flavors.
-
Field Details
-
MIME_TYPE
The MIME type forDATA_FLAVORis application/x-net.iharder.dnd.TransferableObject.- Since:
- 1.1
- See Also:
-
DATA_FLAVOR
The defaultDataFlavorforFileDrop.TransferableObjecthas the representation class net.iharder.dnd.TransferableObject.class and the MIME type application/x-net.iharder.dnd.TransferableObject.- Since:
- 1.1
-
-
Constructor Details
-
TransferableObject
Creates a newFileDrop.TransferableObjectthat wrapspData. Along with theDATA_FLAVORassociated with this class, this creates a custom data flavor with a representation class determined fromdata.getClass()and the MIME type application/x-net.iharder.dnd.TransferableObject.- Parameters:
pData- The data to transfer- Since:
- 1.1
-
TransferableObject
Creates a newFileDrop.TransferableObjectthat will return the object that is returned bypFetcher. No custom data flavor is set other than the defaultDATA_FLAVOR.- Parameters:
pFetcher- TheFileDrop.TransferableObject.Fetcherthat will return the data object- Since:
- 1.1
- See Also:
-
TransferableObject
Creates a newFileDrop.TransferableObjectthat will return the object that is returned bypFetcher. Along with theDATA_FLAVORassociated with this class, this creates a custom data flavor with a representation classpDataClassand the MIME type application/x-net.iharder.dnd.TransferableObject.- Parameters:
pDataClass- TheClassto use in the custom data flavorpFetcher- TheFileDrop.TransferableObject.Fetcherthat will return the data object- Since:
- 1.1
- See Also:
-
-
Method Details
-
getCustomDataFlavor
Returns the customDataFlavorassociated with the encapsulated object or null if theFileDrop.TransferableObject.Fetcherconstructor was used without passing aClass.- Returns:
- The custom data flavor for the encapsulated object
- Since:
- 1.1
-
getTransferDataFlavors
Returns a two- or three-element array containing first the custom data flavor, if one was created in the constructors, second the defaultDATA_FLAVORassociated withFileDrop.TransferableObject, and third theDataFlavor.stringFlavor.- Specified by:
getTransferDataFlavorsin interfaceTransferable- Returns:
- An array of supported data flavors
- Since:
- 1.1
-
getTransferData
Returns the data encapsulated in thisFileDrop.TransferableObject. If theFileDrop.TransferableObject.Fetcherconstructor was used, then this is when thegetObject()method will be called. If the requested data flavor is not supported, then thegetObject()method will not be called.- Specified by:
getTransferDatain interfaceTransferable- Parameters:
pFlavor- The data flavor for the data to return- Returns:
- The dropped data
- Throws:
UnsupportedFlavorExceptionIOException- Since:
- 1.1
-
isDataFlavorSupported
Returns true ifpFlavoris one of the supported flavors. Flavors are supported using theequals(...)method.- Specified by:
isDataFlavorSupportedin interfaceTransferable- Parameters:
pFlavor- The data flavor to check- Returns:
- Whether or not the flavor is supported
- Since:
- 1.1
-