net.iharder.dnd.TransferableObject Class Reference

Collaboration diagram for net.iharder.dnd.TransferableObject:

Collaboration graph
[legend]
List of all members.

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.

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

Author:
Robert.Harder
Version:
1.1


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...


Constructor & Destructor Documentation

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.

See also:
Fetcher
Parameters:
dataClass The java.lang.Class to use in the custom data flavor
fetcher The Fetcher that will return the data object
Since:
1.1

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.

See also:
Fetcher
Parameters:
fetcher The Fetcher that will return the data object
Since:
1.1

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.

Parameters:
data The data to transfer
Since:
1.1


Member Function Documentation

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.

Returns:
The custom data flavor for the encapsulated object
Since:
1.1

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.

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

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.

Returns:
An array of supported data flavors
Since:
1.1

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.

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


Member Data Documentation

final String net.iharder.dnd.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

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)
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


The documentation for this class was generated from the following file:
Generated on Wed Aug 8 17:02:59 2007 for CALO by  doxygen 1.5.2