Class Clipboard
- All Implemented Interfaces:
Proxy
GdkClipboard
object represents data shared between applications or
inside an application.
To get a GdkClipboard
object, use Display.getClipboard()
or
Display.getPrimaryClipboard()
. You can find out about the data
that is currently available in a clipboard using
getFormats()
.
To make text or image data available in a clipboard, use
setText(java.lang.String)
or setTexture(org.gnome.gdk.Texture)
.
For other data, you can use setContent(org.gnome.gdk.ContentProvider)
, which
takes a ContentProvider
object.
To read textual or image data from a clipboard, use
readTextAsync(org.gnome.gio.Cancellable, org.gnome.gio.AsyncReadyCallback)
or
readTextureAsync(org.gnome.gio.Cancellable, org.gnome.gio.AsyncReadyCallback)
. For other data, use
readAsync(java.lang.String[], int, org.gnome.gio.Cancellable, org.gnome.gio.AsyncReadyCallback)
, which provides a GInputStream
object.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Clipboard.Builder<B extends Clipboard.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static interface
Functional interface declaration of theChangedCallback
callback.Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
-
Constructor Summary
ConstructorDescriptionClipboard
(MemorySegment address) Create a Clipboard proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected Clipboard
asParent()
Returns this instance as if it were its parent type.static Clipboard.Builder
<? extends Clipboard.Builder> builder()
AClipboard.Builder
object constructs aClipboard
with the specified properties.void
Emits the "changed" signal.Returns theGdkContentProvider
currently set on this Clipboard.Gets theGdkDisplay
that the clipboard was created for.Gets the formats that the clipboard can provide its current contents in.static Type
getType()
Get the GType of the Clipboard classboolean
isLocal()
Returns if the clipboard is local.onChanged
(Clipboard.ChangedCallback handler) Emitted when the clipboard changes ownership.void
readAsync
(String[] mimeTypes, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously requests an input stream to read the this Clipboard's contents from.readFinish
(AsyncResult result, @Nullable Out<String> outMimeType) Finishes an asynchronous clipboard read.void
readTextAsync
(@Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously request the this Clipboard contents converted to a string.readTextFinish
(AsyncResult result) Finishes an asynchronous clipboard read.void
readTextureAsync
(@Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously request the this Clipboard contents converted to aGdkPixbuf
.readTextureFinish
(AsyncResult result) Finishes an asynchronous clipboard read.void
readValueAsync
(Type type, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously request the this Clipboard contents converted to the giventype
.readValueFinish
(AsyncResult result) Finishes an asynchronous clipboard read.void
Sets the this Clipboard to contain the givenvalue
.boolean
setContent
(@Nullable ContentProvider provider) Sets a new content provider on this Clipboard.void
Puts the giventext
into the clipboard.void
setTexture
(Texture texture) Puts the giventexture
into the clipboard.void
storeAsync
(int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously instructs the this Clipboard to store its contents remotely.boolean
storeFinish
(AsyncResult result) Finishes an asynchronous clipboard store.Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getMemoryLayout, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newInstance, newInstance, newv, notify_, notify_, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Clipboard
Create a Clipboard proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()
doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName()
. This will call the native function pointer of this virtual method in the typeclass of the parent type. -
getContent
Returns theGdkContentProvider
currently set on this Clipboard.If the this Clipboard is empty or its contents are not owned by the current process,
null
will be returned.- Returns:
- The content of a clipboard if the clipboard does not maintain any content
-
getDisplay
Gets theGdkDisplay
that the clipboard was created for.- Returns:
- a
GdkDisplay
-
getFormats
Gets the formats that the clipboard can provide its current contents in.- Returns:
- The formats of the clipboard
-
isLocal
public boolean isLocal()Returns if the clipboard is local.A clipboard is considered local if it was last claimed by the running application.
Note that
getContent()
may returnnull
even on a local clipboard. In this case the clipboard is empty.- Returns:
true
if the clipboard is local
-
readAsync
public void readAsync(String[] mimeTypes, int ioPriority, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) Asynchronously requests an input stream to read the this Clipboard's contents from.The clipboard will choose the most suitable mime type from the given list to fulfill the request, preferring the ones listed first.
- Parameters:
mimeTypes
- anull
-terminated array of mime types to choose fromioPriority
- the I/O priority of the requestcancellable
- optionalGCancellable
objectcallback
- callback to call when the request is satisfied
-
readFinish
public InputStream readFinish(AsyncResult result, @Nullable @Nullable Out<String> outMimeType) throws GErrorException Finishes an asynchronous clipboard read.See
readAsync(java.lang.String[], int, org.gnome.gio.Cancellable, org.gnome.gio.AsyncReadyCallback)
.- Parameters:
result
- aGAsyncResult
outMimeType
- location to store the chosen mime type- Returns:
- a
GInputStream
- Throws:
GErrorException
- seeGError
-
readTextAsync
public void readTextAsync(@Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) Asynchronously request the this Clipboard contents converted to a string.This is a simple wrapper around
readValueAsync(org.gnome.glib.Type, int, org.gnome.gio.Cancellable, org.gnome.gio.AsyncReadyCallback)
. Use that function orreadAsync(java.lang.String[], int, org.gnome.gio.Cancellable, org.gnome.gio.AsyncReadyCallback)
directly if you need more control over the operation.- Parameters:
cancellable
- optionalGCancellable
objectcallback
- callback to call when the request is satisfied
-
readTextFinish
Finishes an asynchronous clipboard read.See
readTextAsync(org.gnome.gio.Cancellable, org.gnome.gio.AsyncReadyCallback)
.- Parameters:
result
- aGAsyncResult
- Returns:
- a new string
- Throws:
GErrorException
- seeGError
-
readTextureAsync
public void readTextureAsync(@Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) Asynchronously request the this Clipboard contents converted to aGdkPixbuf
.This is a simple wrapper around
readValueAsync(org.gnome.glib.Type, int, org.gnome.gio.Cancellable, org.gnome.gio.AsyncReadyCallback)
. Use that function orreadAsync(java.lang.String[], int, org.gnome.gio.Cancellable, org.gnome.gio.AsyncReadyCallback)
directly if you need more control over the operation.- Parameters:
cancellable
- optionalGCancellable
object,null
to ignore.callback
- callback to call when the request is satisfied
-
readTextureFinish
Finishes an asynchronous clipboard read.See
readTextureAsync(org.gnome.gio.Cancellable, org.gnome.gio.AsyncReadyCallback)
.- Parameters:
result
- aGAsyncResult
- Returns:
- a new
GdkTexture
- Throws:
GErrorException
- seeGError
-
readValueAsync
public void readValueAsync(Type type, int ioPriority, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) Asynchronously request the this Clipboard contents converted to the giventype
.For local clipboard contents that are available in the given
GType
, the value will be copied directly. Otherwise, GDK will try to useGdk.contentDeserializeAsync(org.gnome.gio.InputStream, java.lang.String, org.gnome.glib.Type, int, org.gnome.gio.Cancellable, org.gnome.gio.AsyncReadyCallback)
to convert the clipboard's data.- Parameters:
type
- aGType
to readioPriority
- the I/O priority of the requestcancellable
- optionalGCancellable
objectcallback
- callback to call when the request is satisfied
-
readValueFinish
Finishes an asynchronous clipboard read.- Parameters:
result
- aGAsyncResult
- Returns:
- a
GValue
containing the result. - Throws:
GErrorException
- seeGError
-
setContent
Sets a new content provider on this Clipboard.The clipboard will claim the
GdkDisplay
's resources and advertise these new contents to other applications.In the rare case of a failure, this function will return
false
. The clipboard will then continue reporting its old contents and ignoreprovider
.If the contents are read by either an external application or the this Clipboard's read functions, this Clipboard will select the best format to transfer the contents and then request that format from
provider
.- Parameters:
provider
- the new contents of this Clipboard ornull
to clear the clipboard- Returns:
true
if setting the clipboard succeeded
-
setText
Puts the giventext
into the clipboard.- Parameters:
text
- Text to put into the clipboard
-
setTexture
Puts the giventexture
into the clipboard.- Parameters:
texture
- aGdkTexture
to put into the clipboard
-
set
Sets the this Clipboard to contain the givenvalue
.- Parameters:
value
- aGValue
to set
-
storeAsync
public void storeAsync(int ioPriority, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) Asynchronously instructs the this Clipboard to store its contents remotely.If the clipboard is not local, this function does nothing but report success.
The purpose of this call is to preserve clipboard contents beyond the lifetime of an application, so this function is typically called on exit. Depending on the platform, the functionality may not be available unless a "clipboard manager" is running.
This function is called automatically when a GtkApplication is shut down, so you likely don't need to call it.
- Parameters:
ioPriority
- the I/O priority of the requestcancellable
- optionalGCancellable
objectcallback
- callback to call when the request is satisfied
-
storeFinish
Finishes an asynchronous clipboard store.See
storeAsync(int, org.gnome.gio.Cancellable, org.gnome.gio.AsyncReadyCallback)
.- Parameters:
result
- aGAsyncResult
- Returns:
true
if storing was successful.- Throws:
GErrorException
- seeGError
-
onChanged
Emitted when the clipboard changes ownership.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitChanged
public void emitChanged()Emits the "changed" signal. SeeonChanged(org.gnome.gdk.Clipboard.ChangedCallback)
. -
builder
AClipboard.Builder
object constructs aClipboard
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withClipboard.Builder.build()
.
-