| Method from java.awt.datatransfer.Clipboard Detail: |
public synchronized void addFlavorListener(FlavorListener listener) {
if (listener == null) {
return;
}
if (flavorListeners == null) {
currentDataFlavors = getAvailableDataFlavorSet();
flavorListeners = new EventListenerAggregate(FlavorListener.class);
}
flavorListeners.add(listener);
}
Registers the specified FlavorListener to receive
FlavorEvents from this clipboard.
If listener is null, no exception
is thrown and no action is performed. |
public DataFlavor[] getAvailableDataFlavors() {
Transferable cntnts = getContents(null);
if (cntnts == null) {
return new DataFlavor[0];
}
return cntnts.getTransferDataFlavors();
}
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. |
public synchronized Transferable getContents(Object requestor) {
return contents;
}
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. |
public Object getData(DataFlavor flavor) throws IOException, UnsupportedFlavorException {
if (flavor == null) {
throw new NullPointerException("flavor");
}
Transferable cntnts = getContents(null);
if (cntnts == null) {
throw new UnsupportedFlavorException(flavor);
}
return cntnts.getTransferData(flavor);
}
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. |
public synchronized FlavorListener[] getFlavorListeners() {
return flavorListeners == null ? new FlavorListener[0] :
(FlavorListener[])flavorListeners.getListenersCopy();
}
Returns an array of all the FlavorListeners currently
registered on this Clipboard. |
public String getName() {
return name;
}
Returns the name of this clipboard object. |
public boolean isDataFlavorAvailable(DataFlavor flavor) {
if (flavor == null) {
throw new NullPointerException("flavor");
}
Transferable cntnts = getContents(null);
if (cntnts == null) {
return false;
}
return cntnts.isDataFlavorSupported(flavor);
}
Returns whether or not the current contents of this clipboard can be
provided in the specified DataFlavor. |
public synchronized void removeFlavorListener(FlavorListener listener) {
if (listener == null || flavorListeners == null) {
return;
}
flavorListeners.remove(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. |
public synchronized void setContents(Transferable contents,
ClipboardOwner owner) {
final ClipboardOwner oldOwner = this.owner;
final Transferable oldContents = this.contents;
this.owner = owner;
this.contents = contents;
if (oldOwner != null && oldOwner != owner) {
EventQueue.invokeLater(new Runnable() {
public void run() {
oldOwner.lostOwnership(Clipboard.this, oldContents);
}
});
}
fireFlavorsChanged();
}
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. |