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 java.awt.datatransfer.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
Public Member Functions | |
TransferableObject (Class dataClass, Fetcher fetcher) | |
Creates a new TransferableObject that will return the object that is returned by fetcher. | |
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. | |
java.awt.datatransfer.DataFlavor | getCustomDataFlavor () |
Returns the custom java.awt.datatransfer.DataFlavor associated with the encapsulated object or null if the Fetcher constructor was used without passing a java.lang.Class. | |
Object | getTransferData (java.awt.datatransfer.DataFlavor flavor) throws java.awt.datatransfer.UnsupportedFlavorException, java.io.IOException |
Returns the data encapsulated in this TransferableObject. | |
java.awt.datatransfer.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 java.awt.datatransfer.DataFlavor.stringFlavor. | |
boolean | isDataFlavorSupported (java.awt.datatransfer.DataFlavor flavor) |
Returns true if flavor is one of the supported flavors. | |
Static Public Attributes | |
static final String | MIME_TYPE = "application/x-net.iharder.dnd.TransferableObject" |
The MIME type for DATA_FLAVOR is application/x-net.iharder.dnd.TransferableObject . | |
static final java.awt.datatransfer.DataFlavor | DATA_FLAVOR |
The default java.awt.datatransfer.DataFlavor for TransferableObject has the representation class net.iharder.dnd.TransferableObject.class and the MIME type application/x-net.iharder.dnd.TransferableObject . | |
Private Attributes | |
Fetcher | fetcher |
Object | data |
java.awt.datatransfer.DataFlavor | customFlavor |
Classes | |
interface | 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). More... |
net.iharder.dnd.TransferableObject.TransferableObject | ( | Class | dataClass, | |
Fetcher | fetcher | |||
) |
Creates a new 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 java.lang.Class to use in the custom data flavor | |
fetcher | The Fetcher that will return the data object |
net.iharder.dnd.TransferableObject.TransferableObject | ( | Fetcher | fetcher | ) |
Creates a new 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 Fetcher that will return the data object |
net.iharder.dnd.TransferableObject.TransferableObject | ( | Object | data | ) |
Creates a new 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 transfer |
java.awt.datatransfer.DataFlavor net.iharder.dnd.TransferableObject.getCustomDataFlavor | ( | ) |
Returns the custom java.awt.datatransfer.DataFlavor associated with the encapsulated object or null
if the Fetcher constructor was used without passing a java.lang.Class.
Object net.iharder.dnd.TransferableObject.getTransferData | ( | java.awt.datatransfer.DataFlavor | flavor | ) | throws java.awt.datatransfer.UnsupportedFlavorException, java.io.IOException |
Returns the data encapsulated in this TransferableObject.
If the Fetcher constructor was used, then this is when the Fetcher.getObject getObject() method will be called. If the requested data flavor is not supported, then the Fetcher.getObject getObject() method will not be called.
flavor | The data flavor for the data to return |
java.awt.datatransfer.DataFlavor [] net.iharder.dnd.TransferableObject.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 java.awt.datatransfer.DataFlavor.stringFlavor.
boolean net.iharder.dnd.TransferableObject.isDataFlavorSupported | ( | java.awt.datatransfer.DataFlavor | flavor | ) |
Returns true
if flavor is one of the supported flavors.
Flavors are supported using the equals(...)
method.
flavor | The data flavor to check |
final String net.iharder.dnd.TransferableObject.MIME_TYPE = "application/x-net.iharder.dnd.TransferableObject" [static] |
final java.awt.datatransfer.DataFlavor net.iharder.dnd.TransferableObject.DATA_FLAVOR [static] |
Initial value:
new java.awt.datatransfer.DataFlavor( net.iharder.dnd.TransferableObject.class, TransferableObject.MIME_TYPE)
net.iharder.dnd.TransferableObject.class
and the MIME type application/x-net.iharder.dnd.TransferableObject
.