public static class FileDrop.TransferableObject extends Object implements Transferable
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.
Modifier and Type | Class and Description |
---|---|
static interface |
FileDrop.TransferableObject.Fetcher
Instead of passing your data directly to the
FileDrop.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). |
Modifier and Type | Field and Description |
---|---|
static DataFlavor |
DATA_FLAVOR
The default
DataFlavor for
FileDrop.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 for
DATA_FLAVOR is
application/x-net.iharder.dnd.TransferableObject. |
Constructor and Description |
---|
TransferableObject(Class pDataClass,
FileDrop.TransferableObject.Fetcher pFetcher)
Creates a new
FileDrop.TransferableObject that will return the
object that is returned by pFetcher . |
TransferableObject(FileDrop.TransferableObject.Fetcher pFetcher)
Creates a new
FileDrop.TransferableObject that will return the
object that is returned by pFetcher . |
TransferableObject(Object pData)
Creates a new
FileDrop.TransferableObject that wraps pData . |
Modifier and Type | Method and Description |
---|---|
DataFlavor |
getCustomDataFlavor()
Returns the custom
DataFlavor associated
with the encapsulated object or null if the FileDrop.TransferableObject.Fetcher
constructor was used without passing a Class . |
Object |
getTransferData(DataFlavor pFlavor)
Returns the data encapsulated in this
FileDrop.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 default
DATA_FLAVOR associated with
FileDrop.TransferableObject , and third the
DataFlavor.stringFlavor . |
boolean |
isDataFlavorSupported(DataFlavor pFlavor)
Returns true if
pFlavor is one of the supported
flavors. |
public static final String MIME_TYPE
DATA_FLAVOR
is
application/x-net.iharder.dnd.TransferableObject.public static final DataFlavor DATA_FLAVOR
DataFlavor
for
FileDrop.TransferableObject
has the representation class
net.iharder.dnd.TransferableObject.class
and the MIME type
application/x-net.iharder.dnd.TransferableObject.public TransferableObject(Object pData)
FileDrop.TransferableObject
that wraps pData
.
Along with the DATA_FLAVOR
associated with this class,
this creates a custom data flavor with a representation class
determined from data.getClass()
and the MIME type
application/x-net.iharder.dnd.TransferableObject.pData
- The data to transferpublic TransferableObject(FileDrop.TransferableObject.Fetcher pFetcher)
FileDrop.TransferableObject
that will return the
object that is returned by pFetcher
.
No custom data flavor is set other than the default
DATA_FLAVOR
.pFetcher
- The FileDrop.TransferableObject.Fetcher
that will return the data objectFileDrop.TransferableObject.Fetcher
public TransferableObject(Class pDataClass, FileDrop.TransferableObject.Fetcher pFetcher)
FileDrop.TransferableObject
that will return the
object that is returned by pFetcher
.
Along with the DATA_FLAVOR
associated with this class,
this creates a custom data flavor with a representation class pDataClass
and the MIME type
application/x-net.iharder.dnd.TransferableObject.pDataClass
- The Class
to use in the custom data flavorpFetcher
- The FileDrop.TransferableObject.Fetcher
that will return the data objectFileDrop.TransferableObject.Fetcher
public DataFlavor getCustomDataFlavor()
DataFlavor
associated
with the encapsulated object or null if the FileDrop.TransferableObject.Fetcher
constructor was used without passing a Class
.public DataFlavor[] getTransferDataFlavors()
DATA_FLAVOR
associated with
FileDrop.TransferableObject
, and third the
DataFlavor.stringFlavor
.getTransferDataFlavors
in interface Transferable
public Object getTransferData(DataFlavor pFlavor) throws UnsupportedFlavorException, IOException
FileDrop.TransferableObject
.
If the FileDrop.TransferableObject.Fetcher
constructor was used, then this is when
the getObject()
method will be called.
If the requested data flavor is not supported, then the
getObject()
method will not be called.getTransferData
in interface Transferable
pFlavor
- The data flavor for the data to returnUnsupportedFlavorException
IOException
public boolean isDataFlavorSupported(DataFlavor pFlavor)
pFlavor
is one of the supported
flavors. Flavors are supported using the equals(...)
method.isDataFlavorSupported
in interface Transferable
pFlavor
- The data flavor to checkCopyright © 2023. All rights reserved.