corpus-services  1.0
de.uni_hamburg.corpora.swing.FileDrop.TransferableObject Class Reference
+ Inheritance diagram for de.uni_hamburg.corpora.swing.FileDrop.TransferableObject:
+ Collaboration diagram for de.uni_hamburg.corpora.swing.FileDrop.TransferableObject:

Classes

interface  Fetcher
 

Public Member Functions

 TransferableObject (Object data)
 
 TransferableObject (Fetcher fetcher)
 
 TransferableObject (Class dataClass, Fetcher fetcher)
 
java.awt.datatransfer.DataFlavor getCustomDataFlavor ()
 
java.awt.datatransfer.DataFlavor[] getTransferDataFlavors ()
 
Object getTransferData (java.awt.datatransfer.DataFlavor flavor) throws java.awt.datatransfer.UnsupportedFlavorException, java.io.IOException
 
boolean isDataFlavorSupported (java.awt.datatransfer.DataFlavor flavor)
 

Static Public Attributes

static final String MIME_TYPE = "application/x-net.iharder.dnd.TransferableObject"
 
static final java.awt.datatransfer.DataFlavor DATA_FLAVOR
 

Detailed Description

At last an easy way to encapsulate your custom objects for dragging and dropping in your Java programs! When you need to create a java.awt.datatransfer.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 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.

I'm releasing this code into the Public Domain. Enjoy.

Author
Robert Harder
rob@i.nosp@m.hard.nosp@m.er.ne.nosp@m.t
Version
1.2

Definition at line 728 of file FileDrop.java.

Constructor & Destructor Documentation

de.uni_hamburg.corpora.swing.FileDrop.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.

Parameters
dataThe data to transfer
Since
1.1

Definition at line 769 of file FileDrop.java.

de.uni_hamburg.corpora.swing.FileDrop.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.

See also
Fetcher
Parameters
fetcherThe Fetcher that will return the data object
Since
1.1

Definition at line 786 of file FileDrop.java.

de.uni_hamburg.corpora.swing.FileDrop.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.

See also
Fetcher
Parameters
dataClassThe java.lang.Class to use in the custom data flavor
fetcherThe Fetcher that will return the data object
Since
1.1

Definition at line 805 of file FileDrop.java.

Member Function Documentation

java.awt.datatransfer.DataFlavor de.uni_hamburg.corpora.swing.FileDrop.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.

Returns
The custom data flavor for the encapsulated object
Since
1.1

Definition at line 818 of file FileDrop.java.

Object de.uni_hamburg.corpora.swing.FileDrop.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 getObject() method will be called. If the requested data flavor is not supported, then the getObject() method will not be called.

Parameters
flavorThe data flavor for the data to return
Returns
The dropped data
Since
1.1

Definition at line 864 of file FileDrop.java.

java.awt.datatransfer.DataFlavor [] de.uni_hamburg.corpora.swing.FileDrop.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.

Returns
An array of supported data flavors
Since
1.1

Definition at line 836 of file FileDrop.java.

boolean de.uni_hamburg.corpora.swing.FileDrop.TransferableObject.isDataFlavorSupported ( java.awt.datatransfer.DataFlavor  flavor)

Returns true if flavor is one of the supported flavors. Flavors are supported using the equals(...) method.

Parameters
flavorThe data flavor to check
Returns
Whether or not the flavor is supported
Since
1.1

Definition at line 890 of file FileDrop.java.

Member Data Documentation

final java.awt.datatransfer.DataFlavor de.uni_hamburg.corpora.swing.FileDrop.TransferableObject.DATA_FLAVOR
static
Initial value:
=
new java.awt.datatransfer.DataFlavor( FileDrop.TransferableObject.class, MIME_TYPE )

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.

Since
1.1

Definition at line 748 of file FileDrop.java.

final String de.uni_hamburg.corpora.swing.FileDrop.TransferableObject.MIME_TYPE = "application/x-net.iharder.dnd.TransferableObject"
static

The MIME type for DATA_FLAVOR is application/x-net.iharder.dnd.TransferableObject.

Since
1.1

Definition at line 736 of file FileDrop.java.


The documentation for this class was generated from the following file: