FileDocCategorySizeDatePackage
TransferableColor.javaAPI DocExample2636Mon Oct 11 15:07:22 BST 1999None

TransferableColor

public class TransferableColor extends Object implements Transferable
This class is used to transfer a Color object via cut-and-paste or drag-and-drop. It allows a color to be transfered as a Color object, or as a string. Due to a long-standing bug in Java 1.1 and Java 2, transferring a color as a string to native Windows applications will not work.

Fields Summary
protected static DataFlavor
colorFlavor
protected static DataFlavor[]
supportedFlavors
Color
color
Constructors Summary
public TransferableColor(Color color)
Create a new TransferableColor that encapsulates the specified color

                    // The color we encapsulate and transfer

            
      this.color = color; 
Methods Summary
public java.lang.ObjectgetTransferData(java.awt.datatransfer.DataFlavor flavor)
Transfer the data. Given a specified DataFlavor, return an Object appropriate for that flavor. Throw UnsupportedFlavorException if we don't support the requested flavor.

    if (flavor.equals(colorFlavor)) return color;
    else if (flavor.equals(DataFlavor.stringFlavor)) return color.toString();
    else if (flavor.equals(DataFlavor.plainTextFlavor))
      return new ByteArrayInputStream(color.toString().getBytes("Unicode"));
    else throw new UnsupportedFlavorException(flavor);
  
public java.awt.datatransfer.DataFlavor[]getTransferDataFlavors()
Return a list of DataFlavors we can support

 return supportedFlavors; 
public booleanisDataFlavorSupported(java.awt.datatransfer.DataFlavor flavor)
Check whether a specified DataFlavor is available

    if (flavor.equals(colorFlavor) || 
        flavor.equals(DataFlavor.stringFlavor) ||
        flavor.equals(DataFlavor.plainTextFlavor)) return true;
    return false;