- java.lang.Object
-
- java.awt.datatransfer.Clipboard
-
public class Clipboard extends Object
A class that implements a mechanism to transfer data using cut/copy/paste operations.FlavorListener
s may be registered on an instance of the Clipboard class to be notified about changes to the set ofDataFlavor
s available on this clipboard (seeaddFlavorListener(java.awt.datatransfer.FlavorListener)
).
-
-
Field Summary
Fields Modifier and Type Field and Description protected Transferable
contents
protected ClipboardOwner
owner
-
Constructor Summary
Constructors Constructor and Description Clipboard(String name)
Creates a clipboard object.
-
Method Summary
Methods Modifier and Type Method and Description void
addFlavorListener(FlavorListener listener)
Registers the specifiedFlavorListener
to receiveFlavorEvent
s from this clipboard.DataFlavor[]
getAvailableDataFlavors()
Returns an array ofDataFlavor
s in which the current contents of this clipboard can be provided.Transferable
getContents(Object requestor)
Returns a transferable object representing the current contents of the clipboard.Object
getData(DataFlavor flavor)
Returns an object representing the current contents of this clipboard in the specifiedDataFlavor
.FlavorListener[]
getFlavorListeners()
Returns an array of all theFlavorListener
s currently registered on thisClipboard
.String
getName()
Returns the name of this clipboard object.boolean
isDataFlavorAvailable(DataFlavor flavor)
Returns whether or not the current contents of this clipboard can be provided in the specifiedDataFlavor
.void
removeFlavorListener(FlavorListener listener)
Removes the specifiedFlavorListener
so that it no longer receivesFlavorEvent
s from thisClipboard
.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.
-
-
-
Field Detail
-
owner
protected ClipboardOwner owner
-
contents
protected Transferable contents
-
-
Constructor Detail
-
Clipboard
public Clipboard(String name)
Creates a clipboard object.- See Also:
Toolkit.getSystemClipboard()
-
-
Method Detail
-
getName
public String getName()
Returns the name of this clipboard object.- See Also:
Toolkit.getSystemClipboard()
-
setContents
public 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 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 toFlavorListener
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.- 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
public Transferable getContents(Object requestor)
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 throwsIllegalStateException
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
- 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
public DataFlavor[] getAvailableDataFlavors()
Returns an array ofDataFlavor
s in which the current contents of this clipboard can be provided. If there are noDataFlavor
s available, this method returns a zero-length array.- Returns:
- an array of
DataFlavor
s in which the current contents of this clipboard can be provided - Throws:
IllegalStateException
- if this clipboard is currently unavailable- Since:
- 1.5
-
isDataFlavorAvailable
public boolean isDataFlavorAvailable(DataFlavor flavor)
Returns whether or not the current contents of this clipboard can be provided in the specifiedDataFlavor
.- Parameters:
flavor
- the requestedDataFlavor
for the contents- Returns:
true
if the current contents of this clipboard can be provided in the specifiedDataFlavor
;false
otherwise- Throws:
NullPointerException
- ifflavor
isnull
IllegalStateException
- if this clipboard is currently unavailable- Since:
- 1.5
-
getData
public Object getData(DataFlavor flavor) throws UnsupportedFlavorException, IOException
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 requestedDataFlavor
for the contents- Returns:
- an object representing the current contents of this clipboard
in the specified
DataFlavor
- Throws:
NullPointerException
- ifflavor
isnull
IllegalStateException
- if this clipboard is currently unavailableUnsupportedFlavorException
- if the requestedDataFlavor
is not availableIOException
- if the data in the requestedDataFlavor
can not be retrieved- Since:
- 1.5
- See Also:
DataFlavor.getRepresentationClass()
-
addFlavorListener
public void addFlavorListener(FlavorListener listener)
Registers the specifiedFlavorListener
to receiveFlavorEvent
s from this clipboard. Iflistener
isnull
, 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
public void removeFlavorListener(FlavorListener listener)
Removes the specifiedFlavorListener
so that it no longer receivesFlavorEvent
s 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
. Iflistener
isnull
, 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
public FlavorListener[] getFlavorListeners()
Returns an array of all theFlavorListener
s currently registered on thisClipboard
.- Returns:
- all of this clipboard's
FlavorListener
s 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
-
-
Deutsche Übersetzung
Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.
Vielen Dank im Voraus.
Dokument erstellt 11/06/2005, zuletzt geändert 04/03/2020
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/java-api-rf-java/awt/datatransfer/Clipboard.html
Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.
Referenzen
Diese Verweise und Links verweisen auf Dokumente, die während des Schreibens dieser Seite konsultiert wurden, oder die zusätzliche Informationen liefern können, aber die Autoren dieser Quellen können nicht für den Inhalt dieser Seite verantwortlich gemacht werden.
Der Autor Diese Website ist allein dafür verantwortlich, wie die verschiedenen Konzepte und Freiheiten, die mit den Nachschlagewerken gemacht werden, hier dargestellt werden. Denken Sie daran, dass Sie mehrere Quellinformationen austauschen müssen, um das Risiko von Fehlern zu reduzieren.