Quaqua 7.4.2 2011-07-05

ch.randelshofer.quaqua.datatransfer
Class DefaultTransferable

java.lang.Object
  extended by ch.randelshofer.quaqua.datatransfer.DefaultTransferable
All Implemented Interfaces:
java.awt.datatransfer.Transferable

public class DefaultTransferable
extends java.lang.Object
implements java.awt.datatransfer.Transferable

A Transferable which uses a char array or a byte array as its data source.

Version:
$Id: DefaultTransferable.java 363 2010-11-21 17:41:04Z wrandelshofer $
Author:
Werner Randelshofer

Constructor Summary
DefaultTransferable(byte[] data, java.lang.String mimetype, java.lang.String description)
          Creates a new instance using a byte array as the data source.
DefaultTransferable(char[] chars, java.lang.String mimetype, java.lang.String description)
          Creates a new instance using a char array as the data source.
DefaultTransferable(java.lang.String data, java.lang.String mimetype, java.lang.String description)
          Creates a new instance using a String as the data source.
 
Method Summary
 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

DefaultTransferable

public DefaultTransferable(java.lang.String data,
                           java.lang.String mimetype,
                           java.lang.String description)
Creates a new instance using a String as the data source. The charset parameter of the mimetype is used to convert the chars into bytes. If no charset parameter is specified ;charset="UTF-8" is added and the data is encoded using UTF-8.


DefaultTransferable

public DefaultTransferable(char[] chars,
                           java.lang.String mimetype,
                           java.lang.String description)
Creates a new instance using a char array as the data source. The charset parameter of the mimetype is used to convert the chars into bytes. If no charset parameter is specified ;charset="UTF-8" is added and the data is encoded using UTF-8.


DefaultTransferable

public DefaultTransferable(byte[] data,
                           java.lang.String mimetype,
                           java.lang.String description)
Creates a new instance using a byte array as the data source.

Note: For efficiency reasons this method stores the passed in array internally without copying it. Do not modify the array after invoking this method.

Method Detail

getTransferData

public java.lang.Object getTransferData(java.awt.datatransfer.DataFlavor flavor)
                                 throws java.awt.datatransfer.UnsupportedFlavorException,
                                        java.io.IOException
Returns an object which represents the data to be transferred. The class of the object returned is defined by the representation class of the flavor.

Specified by:
getTransferData in interface java.awt.datatransfer.Transferable
Parameters:
flavor - the requested flavor for the data
Throws:
java.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.
See Also:
DataFlavor.getRepresentationClass()

getTransferDataFlavors

public java.awt.datatransfer.DataFlavor[] getTransferDataFlavors()
Returns an array of DataFlavor objects indicating the flavors the data can be provided in. The array should be ordered according to preference for providing the data (from most richly descriptive to least descriptive).

Specified by:
getTransferDataFlavors in interface java.awt.datatransfer.Transferable
Returns:
an array of data flavors in which this data can be transferred

isDataFlavorSupported

public boolean isDataFlavorSupported(java.awt.datatransfer.DataFlavor flavor)
Returns whether or not the specified data flavor is supported for this object.

Specified by:
isDataFlavorSupported in interface java.awt.datatransfer.Transferable
Parameters:
flavor - the requested flavor for the data
Returns:
boolean indicating wjether or not the data flavor is supported

Copyright 2003-2007 (c) Werner Randelshofer.
All rights reserved.