StringSelection (Java 2 Platform SE 5.0) (original) (raw)


java.awt.datatransfer

Class StringSelection

java.lang.Object extended by java.awt.datatransfer.StringSelection

All Implemented Interfaces:

ClipboardOwner, Transferable


public class StringSelection

extends Object

implements Transferable, ClipboardOwner

A Transferable which implements the capability required to transfer a String. This Transferable properly supportsDataFlavor.stringFlavor and all equivalent flavors. Support forDataFlavor.plainTextFlavor and all equivalent flavors is deprecated. No otherDataFlavors are supported.

See Also:

DataFlavor.stringFlavor, DataFlavor.plainTextFlavor


Constructor Summary
StringSelection(String data) Creates a Transferable capable of transferring the specified String.
Method Summary
Object getTransferData(DataFlavor flavor) Returns the Transferable's data in the requestedDataFlavor if possible.
DataFlavor[] getTransferDataFlavors() Returns an array of flavors in which this Transferable can provide the data.
boolean isDataFlavorSupported(DataFlavor flavor) Returns whether the requested flavor is supported by thisTransferable.
void [lostOwnership](../../../java/awt/datatransfer/StringSelection.html#lostOwnership%28java.awt.datatransfer.Clipboard, java.awt.datatransfer.Transferable%29)(Clipboard clipboard,Transferable contents) Notifies this object that it is no longer the clipboard owner.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, [wait](../../../java/lang/Object.html#wait%28long, int%29)
Constructor Detail

StringSelection

public StringSelection(String data)

Creates a Transferable capable of transferring the specified String.

Method Detail

getTransferDataFlavors

public DataFlavor[] getTransferDataFlavors()

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

Specified by:

[getTransferDataFlavors](../../../java/awt/datatransfer/Transferable.html#getTransferDataFlavors%28%29) in interface [Transferable](../../../java/awt/datatransfer/Transferable.html "interface in java.awt.datatransfer")

Returns:

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


isDataFlavorSupported

public boolean isDataFlavorSupported(DataFlavor flavor)

Returns whether the requested flavor is supported by thisTransferable.

Specified by:

[isDataFlavorSupported](../../../java/awt/datatransfer/Transferable.html#isDataFlavorSupported%28java.awt.datatransfer.DataFlavor%29) in interface [Transferable](../../../java/awt/datatransfer/Transferable.html "interface in java.awt.datatransfer")

Parameters:

flavor - the requested flavor for the data

Returns:

true if flavor is equal toDataFlavor.stringFlavor orDataFlavor.plainTextFlavor; false if flavor is not one of the above flavors

Throws:

[NullPointerException](../../../java/lang/NullPointerException.html "class in java.lang") - if flavor is null


getTransferData

public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException

Returns the Transferable's data in the requestedDataFlavor if possible. If the desired flavor isDataFlavor.stringFlavor, or an equivalent flavor, the String representing the selection is returned. If the desired flavor isDataFlavor.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.

Specified by:

[getTransferData](../../../java/awt/datatransfer/Transferable.html#getTransferData%28java.awt.datatransfer.DataFlavor%29) in interface [Transferable](../../../java/awt/datatransfer/Transferable.html "interface in java.awt.datatransfer")

Parameters:

flavor - the requested flavor for the data

Returns:

the data in the requested flavor, as outlined above

Throws:

[UnsupportedFlavorException](../../../java/awt/datatransfer/UnsupportedFlavorException.html "class in java.awt.datatransfer") - if the requested data flavor is not equivalent to either DataFlavor.stringFlavor or DataFlavor.plainTextFlavor

[IOException](../../../java/io/IOException.html "class in java.io") - if an IOException occurs while retrieving the data. By default, StringSelection never throws this exception, but a subclass may.

[NullPointerException](../../../java/lang/NullPointerException.html "class in java.lang") - if flavor is null

See Also:

Reader


lostOwnership

public void lostOwnership(Clipboard clipboard, Transferable contents)

Description copied from interface: [ClipboardOwner](../../../java/awt/datatransfer/ClipboardOwner.html#lostOwnership%28java.awt.datatransfer.Clipboard, java.awt.datatransfer.Transferable%29)

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.

Specified by:

[lostOwnership](../../../java/awt/datatransfer/ClipboardOwner.html#lostOwnership%28java.awt.datatransfer.Clipboard, java.awt.datatransfer.Transferable%29) in interface [ClipboardOwner](../../../java/awt/datatransfer/ClipboardOwner.html "interface in java.awt.datatransfer")

Parameters:

clipboard - the clipboard that is no longer owned

contents - the contents which this owner had placed on the clipboard



Submit a bug or feature
For further API reference and developer documentation, see Java 2 SDK SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.

Copyright © 2004, 2010 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.