- java.lang.Object
-
- com.iamsoft.util.ui.swing.FileDrop.TransferableObject
-
- All Implemented Interfaces:
Transferable
- Enclosing class:
- FileDrop
public static class FileDrop.TransferableObject extends Object implements Transferable
At last an easy way to encapsulate your custom objects for dragging and dropping in your Java programs! When you need to create aTransferable
object, use this class to wrap your object. For example:
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... MyCoolClass myObj = new MyCoolClass(); Transferable xfer = new TransferableObject( myObj ); ...
FileDrop.TransferableObject.Fetcher
inner class to return your object Just in Time. For example:
The... final MyCoolClass myObj = new MyCoolClass(); TransferableObject.Fetcher fetcher = new TransferableObject.Fetcher() { public Object getObject(){ return myObj; } }; // end fetcher Transferable xfer = new TransferableObject( fetcher ); ...
DataFlavor
associated withFileDrop.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 staticDATA_FLAVOR
property.I'm releasing this code into the Public Domain. Enjoy.
- Version:
- 1.2
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
FileDrop.TransferableObject.Fetcher
Instead of passing your data directly to theFileDrop.TransferableObject
constructor, 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
Fields Modifier and Type Field Description static DataFlavor
DATA_FLAVOR
The defaultDataFlavor
forFileDrop.TransferableObject
has the representation class net.iharder.dnd.TransferableObject.class and the MIME type application/x-net.iharder.dnd.TransferableObject.static String
MIME_TYPE
The MIME type forDATA_FLAVOR
is application/x-net.iharder.dnd.TransferableObject.
-
Constructor Summary
Constructors Constructor Description TransferableObject(FileDrop.TransferableObject.Fetcher pFetcher)
Creates a newFileDrop.TransferableObject
that will return the object that is returned bypFetcher
.TransferableObject(Class pDataClass, FileDrop.TransferableObject.Fetcher pFetcher)
Creates a newFileDrop.TransferableObject
that will return the object that is returned bypFetcher
.TransferableObject(Object pData)
Creates a newFileDrop.TransferableObject
that wrapspData
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DataFlavor
getCustomDataFlavor()
Returns the customDataFlavor
associated with the encapsulated object or null if theFileDrop.TransferableObject.Fetcher
constructor was used without passing aClass
.Object
getTransferData(DataFlavor pFlavor)
Returns the data encapsulated in thisFileDrop.TransferableObject
.DataFlavor[]
getTransferDataFlavors()
Returns a two- or three-element array containing first the custom data flavor, if one was created in the constructors, second the defaultDATA_FLAVOR
associated withFileDrop.TransferableObject
, and third theDataFlavor.stringFlavor
.boolean
isDataFlavorSupported(DataFlavor pFlavor)
Returns true ifpFlavor
is one of the supported flavors.
-
-
-
Field Detail
-
MIME_TYPE
public static final String MIME_TYPE
The MIME type forDATA_FLAVOR
is application/x-net.iharder.dnd.TransferableObject.- Since:
- 1.1
- See Also:
- Constant Field Values
-
DATA_FLAVOR
public static final DataFlavor DATA_FLAVOR
The defaultDataFlavor
forFileDrop.TransferableObject
has the representation class net.iharder.dnd.TransferableObject.class and the MIME type application/x-net.iharder.dnd.TransferableObject.- Since:
- 1.1
-
-
Constructor Detail
-
TransferableObject
public TransferableObject(Object pData)
Creates a newFileDrop.TransferableObject
that wrapspData
. Along with theDATA_FLAVOR
associated 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
public TransferableObject(FileDrop.TransferableObject.Fetcher pFetcher)
Creates a newFileDrop.TransferableObject
that will return the object that is returned bypFetcher
. No custom data flavor is set other than the defaultDATA_FLAVOR
.- Parameters:
pFetcher
- TheFileDrop.TransferableObject.Fetcher
that will return the data object- Since:
- 1.1
- See Also:
FileDrop.TransferableObject.Fetcher
-
TransferableObject
public TransferableObject(Class pDataClass, FileDrop.TransferableObject.Fetcher pFetcher)
Creates a newFileDrop.TransferableObject
that will return the object that is returned bypFetcher
. Along with theDATA_FLAVOR
associated with this class, this creates a custom data flavor with a representation classpDataClass
and the MIME type application/x-net.iharder.dnd.TransferableObject.- Parameters:
pDataClass
- TheClass
to use in the custom data flavorpFetcher
- TheFileDrop.TransferableObject.Fetcher
that will return the data object- Since:
- 1.1
- See Also:
FileDrop.TransferableObject.Fetcher
-
-
Method Detail
-
getCustomDataFlavor
public DataFlavor getCustomDataFlavor()
Returns the customDataFlavor
associated with the encapsulated object or null if theFileDrop.TransferableObject.Fetcher
constructor was used without passing aClass
.- Returns:
- The custom data flavor for the encapsulated object
- Since:
- 1.1
-
getTransferDataFlavors
public DataFlavor[] getTransferDataFlavors()
Returns a two- or three-element array containing first the custom data flavor, if one was created in the constructors, second the defaultDATA_FLAVOR
associated withFileDrop.TransferableObject
, and third theDataFlavor.stringFlavor
.- Specified by:
getTransferDataFlavors
in interfaceTransferable
- Returns:
- An array of supported data flavors
- Since:
- 1.1
-
getTransferData
public Object getTransferData(DataFlavor pFlavor) throws UnsupportedFlavorException, IOException
Returns the data encapsulated in thisFileDrop.TransferableObject
. If theFileDrop.TransferableObject.Fetcher
constructor 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:
getTransferData
in interfaceTransferable
- Parameters:
pFlavor
- The data flavor for the data to return- Returns:
- The dropped data
- Throws:
UnsupportedFlavorException
IOException
- Since:
- 1.1
-
isDataFlavorSupported
public boolean isDataFlavorSupported(DataFlavor pFlavor)
Returns true ifpFlavor
is one of the supported flavors. Flavors are supported using theequals(...)
method.- Specified by:
isDataFlavorSupported
in interfaceTransferable
- Parameters:
pFlavor
- The data flavor to check- Returns:
- Whether or not the flavor is supported
- Since:
- 1.1
-
-