|
Bali Share 1.1.18 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--oracle.bali.share.datatransfer.ObjectTransferable
An ObjectTransferable is a basic Transferable implementation that makes it easy to send an object as a Transferable for use in drag-and-drop. It supports requests for data flavors that are superclasses of the provided data, and allows for both lazily-instantiated data and data provided up-front. It also correctly special cases Strings and single-element arrays.
The DataFlavor used by ObjectTransferables can be independently derived from TransferUtils.getDataFlavor()
.
The most common style of usage is:
Transferable t = ObjectTransferable.createTransferable(anObject);
In this style of usage, the object must be provided up front. In cases where this is impossible or undesirable (e.g., because the object requires a lot of memory to instantiate), this class can be subclassed to lazily request the object's data:
class DelayedTransferable extends ObjectTransferable { public DelayedTransferable() { // Provide the class of the data immediately super(SomeClass.class); } protected Object getTransferData() { // But we only create the object when necessary return new SomeClass(); } }
This class is especially useful in conjunction with the CompoundTransferable class (also in this package), which lets you glue multiple transferables together.
TransferUtils
, CompoundTransferable
Constructor Summary | |
protected |
ObjectTransferable(java.lang.Class classObj) Creates a lazily-instantiated transferable for the given class. |
Method Summary | |
static java.awt.datatransfer.Transferable |
createTransferable(java.lang.Object object) Returns a Transferable implementation that will wrap the given object. |
protected abstract java.lang.Object |
getTransferData() Subclasses must override this method to return the data Object contained by this Transferable. |
java.lang.Object |
getTransferData(java.awt.datatransfer.DataFlavor flavor) Returns an object which represents the data to be transferred. |
java.awt.datatransfer.DataFlavor[] |
getTransferDataFlavors() Returns an array of DataFlavor objects indicating the flavors the data can be provided in. |
boolean |
isDataFlavorSupported(java.awt.datatransfer.DataFlavor flavor) Returns whether or not the specified data flavor is supported for this object. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
protected ObjectTransferable(java.lang.Class classObj)
createTransferable()
methods; other clients must subclass this class and override getTransferData().createTransferable(java.lang.Object)
Method Detail |
public static java.awt.datatransfer.Transferable createTransferable(java.lang.Object object)
Arrays with single elements are special cased to also include a DataFlavor of just the first element.
Strings are special-cased to return instances of StringSelection.
object
- the objectpublic java.awt.datatransfer.DataFlavor[] getTransferDataFlavors()
getTransferDataFlavors
in interface java.awt.datatransfer.Transferable
public boolean isDataFlavorSupported(java.awt.datatransfer.DataFlavor flavor)
isDataFlavorSupported
in interface java.awt.datatransfer.Transferable
flavor
- the requested flavor for the datapublic final java.lang.Object getTransferData(java.awt.datatransfer.DataFlavor flavor) throws java.awt.datatransfer.UnsupportedFlavorException, java.io.IOException
getTransferData()
method to return the actual data.getTransferData
in interface java.awt.datatransfer.Transferable
flavor
- the requested flavor for the datajava.io.IOException
- if the data is no longer available in the requested flavor.java.awt.datatransfer.UnsupportedFlavorException
- if the requested data flavor is not supported.protected abstract java.lang.Object getTransferData()
|
Bali Share 1.1.18 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |