Package net.iharder.dnd
Class TransferableObject
java.lang.Object
net.iharder.dnd.TransferableObject
- All Implemented Interfaces:
Transferable
public class 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 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
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:
- You may include this software with other software that uses a different (even non-open source) license.
- You may use this software to make for-profit software.
- Your patent rights, should you generate patents, are protected.
Copyright � 2001 Robert Harder
- Version:
- 1.1
- Author:
- Robert.Harder
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
TransferableObject.Fetcher
Instead of passing your data directly to theTransferableObject
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
forTransferableObject
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(Class<?> dataClass, TransferableObject.Fetcher fetcher)
Creates a newTransferableObject
that will return the object that is returned by fetcher.TransferableObject(Object data)
Creates a newTransferableObject
that wraps data.TransferableObject(TransferableObject.Fetcher fetcher)
Creates a newTransferableObject
that will return the object that is returned by fetcher. -
Method Summary
Modifier and Type Method Description DataFlavor
getCustomDataFlavor()
Returns the customDataFlavor
associated with the encapsulated object or null if theTransferableObject.Fetcher
constructor was used without passing aClass
.Object
getTransferData(DataFlavor flavor)
Returns the data encapsulated in thisTransferableObject
.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 withTransferableObject
, and third thejava.awt.datatransfer.DataFlavor.stringFlavor
.boolean
isDataFlavorSupported(DataFlavor flavor)
Returns true if flavor is one of the supported flavors.
-
Field Details
-
MIME_TYPE
The MIME type forDATA_FLAVOR
is application/x-net.iharder.dnd.TransferableObject.- Since:
- 1.1
- See Also:
- Constant Field Values
-
DATA_FLAVOR
The defaultDataFlavor
forTransferableObject
has 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 newTransferableObject
that wraps data. 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:
data
- The data to transfer- Since:
- 1.1
-
TransferableObject
Creates a newTransferableObject
that will return the object that is returned by fetcher. No custom data flavor is set other than the defaultDATA_FLAVOR
.- Parameters:
fetcher
- TheTransferableObject.Fetcher
that will return the data object- Since:
- 1.1
- See Also:
TransferableObject.Fetcher
-
TransferableObject
Creates a newTransferableObject
that will return the object that is returned by fetcher. Along with theDATA_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.- Parameters:
dataClass
- TheClass
to use in the custom data flavorfetcher
- TheTransferableObject.Fetcher
that will return the data object- Since:
- 1.1
- See Also:
TransferableObject.Fetcher
-
-
Method Details
-
getCustomDataFlavor
Returns the customDataFlavor
associated with the encapsulated object or null if theTransferableObject.Fetcher
constructor 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_FLAVOR
associated withTransferableObject
, and third thejava.awt.datatransfer.DataFlavor.stringFlavor
.- Specified by:
getTransferDataFlavors
in interfaceTransferable
- Returns:
- An array of supported data flavors
- Since:
- 1.1
-
getTransferData
Returns the data encapsulated in thisTransferableObject
. If theTransferableObject.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:
flavor
- The data flavor for the data to return- Returns:
- The dropped data
- Throws:
UnsupportedFlavorException
IOException
- Since:
- 1.1
-
isDataFlavorSupported
Returns true if flavor is one of the supported flavors. Flavors are supported using theequals(...)
method.- Specified by:
isDataFlavorSupported
in interfaceTransferable
- Parameters:
flavor
- The data flavor to check- Returns:
- Whether or not the flavor is supported
- Since:
- 1.1
-