Top Description Fields Constructors Methods
java.awt.datatransfer

public Class Clipboard

extends Object
Class Inheritance
Annotations
@SuppressWarnings:doclint:reference
Imports
java.io.IOException, java.util.Arrays, .HashSet, .Objects, .Set, sun.datatransfer.DataFlavorUtil

A class that implements a mechanism to transfer data using cut/copy/paste operations.

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).

Authors
Amy Fowler, Alexander Gerasimov
Since
1.1
See Also
java.desktop/java.awt.Toolkit#getSystemClipboard, java.desktop/java.awt.Toolkit#getSystemSelection

Field Summary

Modifier and TypeField and Description
protected Transferable
contents

Contents of the clipboard.

private Set<DataFlavor>
currentDataFlavors

A set of DataFlavors that is available on this local clipboard.

private Set<FlavorListener>
flavorListeners

An aggregate of flavor listeners registered on this local clipboard.

pack-priv String
protected ClipboardOwner
owner

The owner of the clipboard.

Constructor Summary

AccessConstructor and Description
public
Clipboard(String
for the clipboard
name
)

Creates a clipboard object.

Method Summary

Modifier and TypeMethod and Description
public synchronized void
addFlavorListener(FlavorListener
the listener to be added
listener
)

Registers the specified FlavorListener to receive FlavorEvents from this clipboard.

private void
fireFlavorsChanged()

Checks change of the DataFlavors and, if necessary, notifies all listeners that have registered interest for notification on FlavorEvents.

public DataFlavor[]

Returns:

an array of DataFlavors in which the current contents of this clipboard can be provided
getAvailableDataFlavors
()

Returns an array of DataFlavors in which the current contents of this clipboard can be provided.

private Set<DataFlavor>

Returns:

a set of DataFlavors currently available on this clipboard
getAvailableDataFlavorSet
()

Returns a set of DataFlavors currently available on this clipboard.

public synchronized Transferable

Returns:

the current transferable object on the clipboard
getContents
(Object
the object requesting the clip data (not used)
requestor
)

Returns a transferable object representing the current contents of the clipboard.

public Object

Returns:

an object representing the current contents of this clipboard in the specified DataFlavor
getData
(DataFlavor
the requested DataFlavor for the contents
flavor
)

Returns an object representing the current contents of this clipboard in the specified DataFlavor.

public synchronized FlavorListener[]

Returns:

all of this clipboard's FlavorListeners or an empty array if no listeners are currently registered
getFlavorListeners
()

Returns an array of all the FlavorListeners currently registered on this Clipboard.

public String

Returns:

the name of this clipboard object
getName
()

Returns the name of this clipboard object.

public boolean

Returns:

true if the current contents of this clipboard can be provided in the specified DataFlavor; false otherwise
isDataFlavorAvailable
(DataFlavor
the requested DataFlavor for the contents
flavor
)

Returns whether or not the current contents of this clipboard can be provided in the specified DataFlavor.

public synchronized void
removeFlavorListener(FlavorListener
the listener to be removed
listener
)

Removes the specified FlavorListener so that it no longer receives FlavorEvents from this Clipboard.

public synchronized void
setContents(Transferable
the transferable object representing the clipboard content
contents
,
ClipboardOwner
the object which owns the clipboard content
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.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

contentsback to summary
protected Transferable contents

Contents of the clipboard.

currentDataFlavorsback to summary
private Set<DataFlavor> currentDataFlavors

A set of DataFlavors that is available on this local clipboard. It is used for tracking changes of DataFlavors available on this clipboard.

Since
1.5
flavorListenersback to summary
private Set<FlavorListener> flavorListeners

An aggregate of flavor listeners registered on this local clipboard.

Since
1.5
nameback to summary
pack-priv String name
ownerback to summary
protected ClipboardOwner owner

The owner of the clipboard.

Constructor Detail

Clipboardback to summary
public Clipboard(String name)

Creates a clipboard object.

Parameters
name:String

for the clipboard

See Also
java.desktop/java.awt.Toolkit#getSystemClipboard

Method Detail

addFlavorListenerback to summary
public synchronized void addFlavorListener(FlavorListener listener)

Registers the specified FlavorListener to receive FlavorEvents from this clipboard. If listener is null, no exception is thrown and no action is performed.

Parameters
listener:FlavorListener

the listener to be added

Since
1.5
See Also
removeFlavorListener, getFlavorListeners, FlavorListener, FlavorEvent
fireFlavorsChangedback to summary
private void fireFlavorsChanged()

Checks change of the DataFlavors and, if necessary, notifies all listeners that have registered interest for notification on FlavorEvents.

Since
1.5
getAvailableDataFlavorsback to summary
public DataFlavor[] getAvailableDataFlavors()

Returns an array of 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.

Returns:DataFlavor[]

an array of DataFlavors in which the current contents of this clipboard can be provided

Exceptions
IllegalStateException:
if this clipboard is currently unavailable
Since
1.5
getAvailableDataFlavorSetback to summary
private Set<DataFlavor> getAvailableDataFlavorSet()

Returns a set of DataFlavors currently available on this clipboard.

Returns:Set<DataFlavor>

a set of DataFlavors currently available on this clipboard

Since
1.5
getContentsback to summary
public synchronized Transferable getContents(Object requestor)

Returns a transferable object representing the current contents of the clipboard. If the clipboard currently has no contents, it returns 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.

Parameters
requestor:Object

the object requesting the clip data (not used)

Returns:Transferable

the current transferable object on the clipboard

Exceptions
IllegalStateException:
if the clipboard is currently unavailable
See Also
java.desktop/java.awt.Toolkit#getSystemClipboard
getDataback to summary
public Object getData(DataFlavor flavor) throws UnsupportedFlavorException, IOException

Returns an object representing the current contents of this clipboard in the specified DataFlavor. The class of the object returned is defined by the representation class of flavor.

Parameters
flavor:DataFlavor

the requested DataFlavor for the contents

Returns:Object

an object representing the current contents of this clipboard in the specified DataFlavor

Exceptions
UnsupportedFlavorException:
if the requested DataFlavor is not available
IOException:
if the data in the requested DataFlavor can not be retrieved
NullPointerException:
if flavor is null
IllegalStateException:
if this clipboard is currently unavailable
Since
1.5
See Also
DataFlavor#getRepresentationClass
getFlavorListenersback to summary
public synchronized FlavorListener[] getFlavorListeners()

Returns an array of all the FlavorListeners currently registered on this Clipboard.

Returns:FlavorListener[]

all of this clipboard's FlavorListeners or an empty array if no listeners are currently registered

Since
1.5
See Also
addFlavorListener, removeFlavorListener, FlavorListener, FlavorEvent
getNameback to summary
public String getName()

Returns the name of this clipboard object.

Returns:String

the name of this clipboard object

See Also
java.desktop/java.awt.Toolkit#getSystemClipboard
isDataFlavorAvailableback to summary
public boolean isDataFlavorAvailable(DataFlavor flavor)

Returns whether or not the current contents of this clipboard can be provided in the specified DataFlavor.

Parameters
flavor:DataFlavor

the requested DataFlavor for the contents

Returns:boolean

true if the current contents of this clipboard can be provided in the specified DataFlavor; false otherwise

Exceptions
NullPointerException:
if flavor is null
IllegalStateException:
if this clipboard is currently unavailable
Since
1.5
removeFlavorListenerback to summary
public synchronized void removeFlavorListener(FlavorListener listener)

Removes the specified 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.

Parameters
listener:FlavorListener

the listener to be removed

Since
1.5
See Also
addFlavorListener, getFlavorListeners, FlavorListener, FlavorEvent
setContentsback to summary
public synchronized void setContents(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.

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.

Parameters
contents:Transferable

the transferable object representing the clipboard content

owner:ClipboardOwner

the object which owns the clipboard content

Exceptions
IllegalStateException:
if the clipboard is currently unavailable
See Also
java.desktop/java.awt.Toolkit#getSystemClipboard