Top Description Fields Constructors Methods
java.awt.datatransfer

public Class StringSelection

extends Object
implements Transferable, ClipboardOwner
Class Inheritance
All Implemented Interfaces
java.awt.datatransfer.ClipboardOwner, java.awt.datatransfer.Transferable
Imports
java.io.IOException, .StringReader

A Transferable which implements the capability required to transfer a String.

This Transferable properly supports DataFlavor.stringFlavor and all equivalent flavors. Support for DataFlavor.plainTextFlavor and all equivalent flavors is deprecated. No other DataFlavors are supported.

Since
1.1
See Also
DataFlavor#stringFlavor, DataFlavor#plainTextFlavor

Field Summary

Modifier and TypeField and Description
private String
private static final DataFlavor[]
private static final int
private static final int

Constructor Summary

AccessConstructor and Description
public
StringSelection(String
the string to be transferred
data
)

Creates a Transferable capable of transferring the specified String.

Method Summary

Modifier and TypeMethod and Description
public Object

Returns:

the data in the requested flavor, as outlined above
getTransferData
(DataFlavor
the requested flavor for the data
flavor
)

Implements java.awt.datatransfer.Transferable.getTransferData.

Returns the Transferable's data in the requested DataFlavor if possible.

public DataFlavor[]

Returns:

an array of length two, whose elements are DataFlavor.stringFlavor and DataFlavor.plainTextFlavor
getTransferDataFlavors
()

Implements java.awt.datatransfer.Transferable.getTransferDataFlavors.

Returns an array of flavors in which this Transferable can provide the data.

public boolean

Returns:

true if flavor is equal to DataFlavor.stringFlavor or DataFlavor.plainTextFlavor; false if flavor is not one of the above flavors
isDataFlavorSupported
(DataFlavor
the requested flavor for the data
flavor
)

Implements java.awt.datatransfer.Transferable.isDataFlavorSupported.

Returns whether the requested flavor is supported by this Transferable.

public void
lostOwnership(Clipboard
the clipboard that is no longer owned
clipboard
,
Transferable
the contents which this owner had placed on the clipboard
contents
)

Implements java.awt.datatransfer.ClipboardOwner.lostOwnership.

Notifies this object that it is no longer the clipboard owner.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

databack to summary
private String data
flavorsback to summary
private static final DataFlavor[] flavors
Annotations
@SuppressWarnings:deprecation
PLAIN_TEXTback to summary
private static final int PLAIN_TEXT
STRINGback to summary
private static final int STRING

Constructor Detail

StringSelectionback to summary
public StringSelection(String data)

Creates a Transferable capable of transferring the specified String.

Parameters
data:String

the string to be transferred

Method Detail

getTransferDataback to summary
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException

Implements java.awt.datatransfer.Transferable.getTransferData.

Returns the Transferable's data in the requested DataFlavor if possible. If the desired flavor is DataFlavor.stringFlavor, or an equivalent flavor, the String representing the selection is returned. If the desired flavor is DataFlavor.plainTextFlavor, or an equivalent flavor, a Reader is returned

Note

The behavior of this method for DataFlavor.plainTextFlavor and equivalent DataFlavors is inconsistent with the definition of DataFlavor.plainTextFlavor.

Parameters
flavor:DataFlavor

the requested flavor for the data

Returns:Object

the data in the requested flavor, as outlined above

Exceptions
UnsupportedFlavorException:
if the requested data flavor is not equivalent to either DataFlavor.stringFlavor or DataFlavor.plainTextFlavor
IOException:
if an IOException occurs while retrieving the data. By default, StringSelection never throws this exception, but a subclass may.
NullPointerException:
if flavor is null
See Also
java.io.Reader
getTransferDataFlavorsback to summary
public DataFlavor[] getTransferDataFlavors()

Implements java.awt.datatransfer.Transferable.getTransferDataFlavors.

Returns an array of flavors in which this Transferable can provide the data. DataFlavor.stringFlavor is properly supported. Support for DataFlavor.plainTextFlavor is deprecated.

Returns:DataFlavor[]

an array of length two, whose elements are DataFlavor.stringFlavor and DataFlavor.plainTextFlavor

isDataFlavorSupportedback to summary
public boolean isDataFlavorSupported(DataFlavor flavor)

Implements java.awt.datatransfer.Transferable.isDataFlavorSupported.

Returns whether the requested flavor is supported by this Transferable.

Parameters
flavor:DataFlavor

the requested flavor for the data

Returns:boolean

true if flavor is equal to DataFlavor.stringFlavor or DataFlavor.plainTextFlavor; false if flavor is not one of the above flavors

Exceptions
NullPointerException:
if flavor is null
lostOwnershipback to summary
public void lostOwnership(Clipboard clipboard, Transferable contents)

Implements java.awt.datatransfer.ClipboardOwner.lostOwnership.

Doc from java.awt.datatransfer.ClipboardOwner.lostOwnership.

Notifies this object that it is no longer the clipboard owner. This method will be called when another application or another object within this application asserts ownership of the clipboard.

Parameters
clipboard:Clipboard

the clipboard that is no longer owned

contents:Transferable

the contents which this owner had placed on the clipboard