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)).
| Modifier and Type | Field and Description |
|---|---|
protected Transferable |
contents
|
protected ClipboardOwner |
owner
|
| Constructor and Description |
|---|
Clipboard(String
Creates a clipboard object.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addFlavorListener(FlavorListener
Registers the specified
FlavorListener to receive
FlavorEvents from this clipboard.
|
DataFlavor |
getAvailableDataFlavors()
Returns an array of
DataFlavors in which the current contents of this clipboard can be provided.
|
Transferable |
getContents(Object
Returns a transferable object representing the current contents of the clipboard.
|
Object |
getData(DataFlavor
Returns an object representing the current contents of this clipboard in the specified
DataFlavor.
|
FlavorListener |
getFlavorListeners()
Returns an array of all the
FlavorListeners currently registered on this
Clipboard.
|
String |
getName()
Returns the name of this clipboard object.
|
boolean |
isDataFlavorAvailable(DataFlavor
Returns whether or not the current contents of this clipboard can be provided in the specified
DataFlavor.
|
void |
removeFlavorListener(FlavorListener
Removes the specified
FlavorListener so that it no longer receives
FlavorEvents from this
Clipboard.
|
void |
setContents(Transferable
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.
|
protected ClipboardOwnerowner
protected Transferablecontents
public Clipboard(Stringname)
Toolkit.getSystemClipboard()
public StringgetName()
Toolkit.getSystemClipboard()
public void setContents(Transferablecontents, ClipboardOwner owner)
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 of ClipboardOwner.lostOwnership() on that owner. An implementation of setContents() is free not to invoke lostOwnership() directly from this method. For example, lostOwnership() may be invoked later on a different thread. The same applies to FlavorListeners registered on this clipboard.
The method throws IllegalStateException if the clipboard is currently unavailable. For example, on some platforms, the system clipboard is unavailable while it is accessed by another application.
contents - the transferable object representing the clipboard content
owner - the object which owns the clipboard content
IllegalStateException - if the clipboard is currently unavailable
Toolkit.getSystemClipboard()
public TransferablegetContents(Object requestor)
null. The parameter Object requestor is not currently used. The method throws
IllegalStateException if the clipboard is currently unavailable. For example, on some platforms, the system clipboard is unavailable while it is accessed by another application.
requestor - the object requesting the clip data (not used)
IllegalStateException - if the clipboard is currently unavailable
Toolkit.getSystemClipboard()
public DataFlavor[] getAvailableDataFlavors()
DataFlavors in which the current contents of this clipboard can be provided. If there are no
DataFlavors available, this method returns a zero-length array.
DataFlavors in which the current contents of this clipboard can be provided
IllegalStateException - if this clipboard is currently unavailable
public boolean isDataFlavorAvailable(DataFlavorflavor)
DataFlavor.
flavor - the requested
DataFlavor for the contents
true if the current contents of this clipboard can be provided in the specified
DataFlavor;
false otherwise
NullPointerException - if
flavor is
null
IllegalStateException - if this clipboard is currently unavailable
public ObjectgetData(DataFlavor flavor) throws UnsupportedFlavorException , IOException
DataFlavor. The class of the object returned is defined by the representation class of
flavor.
flavor - the requested
DataFlavor for the contents
DataFlavor
NullPointerException - if
flavor is
null
IllegalStateException - if this clipboard is currently unavailable
UnsupportedFlavorException - if the requested
DataFlavor is not available
IOException - if the data in the requested
DataFlavor can not be retrieved
DataFlavor.getRepresentationClass()
public void addFlavorListener(FlavorListenerlistener)
FlavorListener to receive
FlavorEvents from this clipboard. If
listener is
null, no exception is thrown and no action is performed.
listener - the listener to be added
removeFlavorListener(java.awt.datatransfer.FlavorListener),
getFlavorListeners(),
FlavorListener,
FlavorEvent
public void removeFlavorListener(FlavorListenerlistener)
FlavorListener so that it no longer receives
FlavorEvents from this
Clipboard. This method performs no function, nor does it throw an exception, if the listener specified by the argument was not previously added to this
Clipboard. If
listener is
null, no exception is thrown and no action is performed.
listener - the listener to be removed
addFlavorListener(java.awt.datatransfer.FlavorListener),
getFlavorListeners(),
FlavorListener,
FlavorEvent
public FlavorListener[] getFlavorListeners()
FlavorListeners currently registered on this
Clipboard.
FlavorListeners or an empty array if no listeners are currently registered
addFlavorListener(java.awt.datatransfer.FlavorListener),
removeFlavorListener(java.awt.datatransfer.FlavorListener),
FlavorListener,
FlavorEvent