Class StringSelection
java.lang.Object
java.awt.datatransfer.StringSelection
- All Implemented Interfaces:
ClipboardOwner, Transferable
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:
-
Constructor Summary
ConstructorsConstructorDescriptionStringSelection(String data) Creates aTransferablecapable of transferring the specifiedString. -
Method Summary
Modifier and TypeMethodDescriptiongetTransferData(DataFlavor flavor) Returns theTransferable's data in the requestedDataFlavorif possible.Returns an array of flavors in which thisTransferablecan provide the data.booleanisDataFlavorSupported(DataFlavor flavor) Returns whether the requested flavor is supported by thisTransferable.voidlostOwnership(Clipboard clipboard, Transferable contents) Notifies this object that it is no longer the clipboard owner.Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()Answers a new instance of the same class as the receiver, whose slots have been filled in with the values in the slots of the receiver.booleanCompares the argument to the receiver, and answers true if they represent the same object using a class specific comparison.protected voidfinalize()Deprecated, for removal: This API element is subject to removal in a future version.May cause performance issues, deadlocks and hangs.getClass()Answers the unique instance of java.lang.Class which represents the class of the receiver.inthashCode()Answers an integer hash code for the receiver.final voidnotify()Causes one thread which iswaiting on the receiver to be made ready to run.final voidCauses all threads which arewaiting on the receiver to be made ready to run.toString()Answers a string containing a concise, human-readable description of the receiver.final voidwait()Causes the thread which sent this message to be made not ready to run pending some change in the receiver (as indicated bynotifyornotifyAll).final voidwait(long time) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.final voidwait(long time, int frac) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.
-
Constructor Details
-
StringSelection
Creates aTransferablecapable of transferring the specifiedString.- Parameters:
data- the string to be transferred
-
-
Method Details
-
getTransferDataFlavors
Returns an array of flavors in which thisTransferablecan provide the data.DataFlavor.stringFlavoris properly supported. Support forDataFlavor.plainTextFlavoris deprecated.- Specified by:
getTransferDataFlavorsin interfaceTransferable- Returns:
- an array of length two, whose elements are
DataFlavor.stringFlavorandDataFlavor.plainTextFlavor
-
isDataFlavorSupported
Returns whether the requested flavor is supported by thisTransferable.- Specified by:
isDataFlavorSupportedin interfaceTransferable- Parameters:
flavor- the requested flavor for the data- Returns:
trueifflavoris equal toDataFlavor.stringFlavororDataFlavor.plainTextFlavor;falseifflavoris not one of the above flavors- Throws:
NullPointerException- ifflavorisnull
-
getTransferData
Returns theTransferable's data in the requestedDataFlavorif possible. If the desired flavor isDataFlavor.stringFlavor, or an equivalent flavor, theStringrepresenting the selection is returned. If the desired flavor isDataFlavor.plainTextFlavor, or an equivalent flavor, aReaderis returned.
Note: The behavior of this method forDataFlavor.plainTextFlavorand equivalentDataFlavors is inconsistent with the definition ofDataFlavor.plainTextFlavor.- Specified by:
getTransferDatain interfaceTransferable- Parameters:
flavor- the requested flavor for the data- Returns:
- the data in the requested flavor, as outlined above
- Throws:
UnsupportedFlavorException- if the requested data flavor is not equivalent to eitherDataFlavor.stringFlavororDataFlavor.plainTextFlavorIOException- if an IOException occurs while retrieving the data. By default, StringSelection never throws this exception, but a subclass may.NullPointerException- ifflavorisnull- See Also:
-
lostOwnership
Description copied from interface:ClipboardOwnerNotifies 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:
lostOwnershipin interfaceClipboardOwner- Parameters:
clipboard- the clipboard that is no longer ownedcontents- the contents which this owner had placed on theclipboard
-