Methods Summary |
---|
public synchronized void | addFlavorListener(java.awt.datatransfer.FlavorListener listener)Registers the specified FlavorListener to receive
FlavorEvent s from this clipboard.
If listener is null , no exception
is thrown and no action is performed.
if (listener == null) {
return;
}
if (flavorListeners == null) {
currentDataFlavors = getAvailableDataFlavorSet();
flavorListeners = new EventListenerAggregate(FlavorListener.class);
}
flavorListeners.add(listener);
|
private void | fireFlavorsChanged()Checks change of the DataFlavor s and, if necessary,
notifies all listeners that have registered interest for notification
on FlavorEvent s.
if (flavorListeners == null) {
return;
}
Set prevDataFlavors = currentDataFlavors;
currentDataFlavors = getAvailableDataFlavorSet();
if (prevDataFlavors.equals(currentDataFlavors)) {
return;
}
FlavorListener[] flavorListenerArray =
(FlavorListener[])flavorListeners.getListenersInternal();
for (int i = 0; i < flavorListenerArray.length; i++) {
final FlavorListener listener = flavorListenerArray[i];
EventQueue.invokeLater(new Runnable() {
public void run() {
listener.flavorsChanged(new FlavorEvent(Clipboard.this));
}
});
}
|
private java.util.Set | getAvailableDataFlavorSet()Returns a set of DataFlavor s currently available
on this clipboard.
Set set = new HashSet();
Transferable contents = getContents(null);
if (contents != null) {
DataFlavor[] flavors = contents.getTransferDataFlavors();
if (flavors != null) {
set.addAll(Arrays.asList(flavors));
}
}
return set;
|
public java.awt.datatransfer.DataFlavor[] | getAvailableDataFlavors()Returns an array of DataFlavor s in which the current
contents of this clipboard can be provided. If there are no
DataFlavor s available, this method returns a zero-length
array.
Transferable cntnts = getContents(null);
if (cntnts == null) {
return new DataFlavor[0];
}
return cntnts.getTransferDataFlavors();
|
public synchronized java.awt.datatransfer.Transferable | getContents(java.lang.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.
return contents;
|
public java.lang.Object | getData(java.awt.datatransfer.DataFlavor 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 .
if (flavor == null) {
throw new NullPointerException("flavor");
}
Transferable cntnts = getContents(null);
if (cntnts == null) {
throw new UnsupportedFlavorException(flavor);
}
return cntnts.getTransferData(flavor);
|
public synchronized java.awt.datatransfer.FlavorListener[] | getFlavorListeners()Returns an array of all the FlavorListener s currently
registered on this Clipboard .
return flavorListeners == null ? new FlavorListener[0] :
(FlavorListener[])flavorListeners.getListenersCopy();
|
public java.lang.String | getName()Returns the name of this clipboard object.
return name;
|
public boolean | isDataFlavorAvailable(java.awt.datatransfer.DataFlavor flavor)Returns whether or not the current contents of this clipboard can be
provided in the specified DataFlavor .
if (flavor == null) {
throw new NullPointerException("flavor");
}
Transferable cntnts = getContents(null);
if (cntnts == null) {
return false;
}
return cntnts.isDataFlavorSupported(flavor);
|
public synchronized void | removeFlavorListener(java.awt.datatransfer.FlavorListener listener)Removes the specified FlavorListener so that it no longer
receives FlavorEvent s 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.
if (listener == null || flavorListeners == null) {
return;
}
flavorListeners.remove(listener);
|
public synchronized void | setContents(java.awt.datatransfer.Transferable contents, java.awt.datatransfer.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 FlavorListener s
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.
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();
|