public class Clipboard extends Object
FlavorListeners may be registered on an instance of the Clipboard
class to be notified about changes to the set of DataFlavors
available on this clipboard (see addFlavorListener(java.awt.datatransfer.FlavorListener)).
- Since:
- 1.1
- See Also:
Toolkit.getSystemClipboard(),Toolkit.getSystemSelection()
-
Field Summary
Fields Modifier and Type Field Description protected TransferablecontentsContents of the clipboard.protected ClipboardOwnerownerThe owner of the clipboard. -
Constructor Summary
-
Method Summary
Modifier and Type Method Description voidaddFlavorListener(FlavorListener listener)Registers the specifiedFlavorListenerto receiveFlavorEvents from this clipboard.DataFlavor[]getAvailableDataFlavors()Returns an array ofDataFlavors in which the current contents of this clipboard can be provided.TransferablegetContents(Object requestor)Returns a transferable object representing the current contents of the clipboard.ObjectgetData(DataFlavor flavor)Returns an object representing the current contents of this clipboard in the specifiedDataFlavor.FlavorListener[]getFlavorListeners()Returns an array of all theFlavorListeners currently registered on thisClipboard.StringgetName()Returns the name of this clipboard object.booleanisDataFlavorAvailable(DataFlavor flavor)Returns whether or not the current contents of this clipboard can be provided in the specifiedDataFlavor.voidremoveFlavorListener(FlavorListener listener)Removes the specifiedFlavorListenerso that it no longer receivesFlavorEvents from thisClipboard.voidsetContents(Transferable contents, ClipboardOwner owner)Sets the current contents of the clipboard to the specified transferable object and registers the specified clipboard owner as the owner of the new contents.
-
Field Details
-
Constructor Details
-
Clipboard
Creates a clipboard object.- Parameters:
name- for the clipboard- See Also:
Toolkit.getSystemClipboard()
-
-
Method Details
-
getName
Returns the name of this clipboard object.- Returns:
- the name of this clipboard object
- See Also:
Toolkit.getSystemClipboard()
-
setContents
Sets the current contents of the clipboard to the specified transferable object and registers the specified clipboard owner as the owner of the new contents.If there is an existing owner different from the argument
owner, that owner is notified that it no longer holds ownership of the clipboard contents via an invocation ofClipboardOwner.lostOwnership()on that owner. An implementation ofsetContents()is free not to invokelostOwnership()directly from this method. For example,lostOwnership()may be invoked later on a different thread. The same applies toFlavorListeners registered on this clipboard.The method throws
IllegalStateExceptionif the clipboard is currently unavailable. For example, on some platforms, the system clipboard is unavailable while it is accessed by another application.- Parameters:
contents- the transferable object representing the clipboard contentowner- the object which owns the clipboard content- Throws:
IllegalStateException- if the clipboard is currently unavailable- See Also:
Toolkit.getSystemClipboard()
-
getContents
Returns a transferable object representing the current contents of the clipboard. If the clipboard currently has no contents, it returnsnull. The parameter Object requestor is not currently used. The method throwsIllegalStateExceptionif the clipboard is currently unavailable. For example, on some platforms, the system clipboard is unavailable while it is accessed by another application.- Parameters:
requestor- the object requesting the clip data (not used)- Returns:
- the current transferable object on the clipboard
- Throws:
IllegalStateException- if the clipboard is currently unavailable- See Also:
Toolkit.getSystemClipboard()
-
getAvailableDataFlavors
Returns an array ofDataFlavors in which the current contents of this clipboard can be provided. If there are noDataFlavors available, this method returns a zero-length array.- Returns:
- an array of
DataFlavors in which the current contents of this clipboard can be provided - Throws:
IllegalStateException- if this clipboard is currently unavailable- Since:
- 1.5
-
isDataFlavorAvailable
Returns whether or not the current contents of this clipboard can be provided in the specifiedDataFlavor.- Parameters:
flavor- the requestedDataFlavorfor the contents- Returns:
trueif the current contents of this clipboard can be provided in the specifiedDataFlavor;falseotherwise- Throws:
NullPointerException- ifflavorisnullIllegalStateException- if this clipboard is currently unavailable- Since:
- 1.5
-
getData
Returns an object representing the current contents of this clipboard in the specifiedDataFlavor. The class of the object returned is defined by the representation class offlavor.- Parameters:
flavor- the requestedDataFlavorfor the contents- Returns:
- an object representing the current contents of this clipboard in
the specified
DataFlavor - Throws:
NullPointerException- ifflavorisnullIllegalStateException- if this clipboard is currently unavailableUnsupportedFlavorException- if the requestedDataFlavoris not availableIOException- if the data in the requestedDataFlavorcan not be retrieved- Since:
- 1.5
- See Also:
DataFlavor.getRepresentationClass()
-
addFlavorListener
Registers the specifiedFlavorListenerto receiveFlavorEvents from this clipboard. Iflistenerisnull, no exception is thrown and no action is performed.- Parameters:
listener- the listener to be added- Since:
- 1.5
- See Also:
removeFlavorListener(java.awt.datatransfer.FlavorListener),getFlavorListeners(),FlavorListener,FlavorEvent
-
removeFlavorListener
Removes the specifiedFlavorListenerso that it no longer receivesFlavorEvents from thisClipboard. This method performs no function, nor does it throw an exception, if the listener specified by the argument was not previously added to thisClipboard. Iflistenerisnull, no exception is thrown and no action is performed.- Parameters:
listener- the listener to be removed- Since:
- 1.5
- See Also:
addFlavorListener(java.awt.datatransfer.FlavorListener),getFlavorListeners(),FlavorListener,FlavorEvent
-
getFlavorListeners
Returns an array of all theFlavorListeners currently registered on thisClipboard.- Returns:
- all of this clipboard's
FlavorListeners or an empty array if no listeners are currently registered - Since:
- 1.5
- See Also:
addFlavorListener(java.awt.datatransfer.FlavorListener),removeFlavorListener(java.awt.datatransfer.FlavorListener),FlavorListener,FlavorEvent
-