public class 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 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
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.
This code is licensed for public use under the Common Public License version 0.5.
The Common Public License, developed by IBM and modeled after their industry-friendly IBM Public License,
differs from other common open source licenses in several important ways:
Copyright ? 2001 Robert Harder
Modifier and Type | Class and Description |
---|---|
static interface |
TransferableObject.Fetcher
Instead of passing your data directly to the
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 |
---|---|
private DataFlavor |
customFlavor |
private Object |
data |
static DataFlavor |
DATA_FLAVOR
The default
DataFlavor for
TransferableObject has the representation class
net.iharder.dnd.TransferableObject.class
and the MIME type
application/x-net.iharder.dnd.TransferableObject. |
private TransferableObject.Fetcher |
fetcher |
static String |
MIME_TYPE
The MIME type for
DATA_FLAVOR is
application/x-net.iharder.dnd.TransferableObject. |
Constructor and Description |
---|
TransferableObject(Class dataClass,
TransferableObject.Fetcher fetcher)
Creates a new
TransferableObject that will return the
object that is returned by fetcher. |
TransferableObject(Object data)
Creates a new
TransferableObject that wraps data. |
TransferableObject(TransferableObject.Fetcher fetcher)
Creates a new
TransferableObject that will return the
object that is returned by fetcher. |
Modifier and Type | Method and Description |
---|---|
DataFlavor |
getCustomDataFlavor()
Returns the custom
DataFlavor associated
with the encapsulated object or null if the TransferableObject.Fetcher
constructor was used without passing a Class . |
Object |
getTransferData(DataFlavor flavor)
Returns the data encapsulated in this
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
TransferableObject , and third the
DataFlavor.stringFlavor . |
boolean |
isDataFlavorSupported(DataFlavor flavor)
Returns true if flavor 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
TransferableObject
has the representation class
net.iharder.dnd.TransferableObject.class
and the MIME type
application/x-net.iharder.dnd.TransferableObject.private TransferableObject.Fetcher fetcher
private DataFlavor customFlavor
public TransferableObject(Object data)
TransferableObject
that wraps data.
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.data
- The data to transferpublic TransferableObject(TransferableObject.Fetcher fetcher)
TransferableObject
that will return the
object that is returned by fetcher.
No custom data flavor is set other than the default
DATA_FLAVOR
.fetcher
- The TransferableObject.Fetcher
that will return the data objectTransferableObject.Fetcher
public TransferableObject(Class dataClass, TransferableObject.Fetcher fetcher)
TransferableObject
that will return the
object that is returned by fetcher.
Along with the DATA_FLAVOR
associated with this class,
this creates a custom data flavor with a representation class dataClass
and the MIME type
application/x-net.iharder.dnd.TransferableObject.dataClass
- The Class
to use in the custom data flavorfetcher
- The TransferableObject.Fetcher
that will return the data objectTransferableObject.Fetcher
public DataFlavor getCustomDataFlavor()
DataFlavor
associated
with the encapsulated object or null if the TransferableObject.Fetcher
constructor was used without passing a Class
.public DataFlavor[] getTransferDataFlavors()
DATA_FLAVOR
associated with
TransferableObject
, and third the
DataFlavor.stringFlavor
.getTransferDataFlavors
in interface Transferable
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException
TransferableObject
.
If the 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
flavor
- The data flavor for the data to returnUnsupportedFlavorException
IOException
public boolean isDataFlavorSupported(DataFlavor flavor)
equals(...)
method.isDataFlavorSupported
in interface Transferable
flavor
- The data flavor to checkWebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses