Class ContentProvider
- All Implemented Interfaces:
Proxy
GdkContentProvider
is used to provide content for the clipboard or
for drag-and-drop operations in a number of formats.
To create a GdkContentProvider
, use forValue(org.gnome.gobject.Value)
or forBytes(java.lang.String, org.gnome.glib.Bytes)
.
GDK knows how to handle common text and image formats out-of-the-box. See
ContentSerializer
and ContentDeserializer
if you want
to add support for application-specific data formats.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
ContentProvider.Builder<B extends ContentProvider.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static interface
Functional interface declaration of theContentChangedCallback
callback.static class
Class structure forGdkContentProvider
.Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
-
Constructor Summary
ConstructorDescriptionContentProvider
(MemorySegment address) Create a ContentProvider proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected ContentProvider
asParent()
Returns this instance as if it were its parent type.protected void
attachClipboard
(Clipboard clipboard) static ContentProvider.Builder
<? extends ContentProvider.Builder> builder()
AContentProvider.Builder
object constructs aContentProvider
with the specified properties.void
Emits the ::content-changed signal.protected void
detachClipboard
(Clipboard clipboard) void
Emits the "content-changed" signal.static ContentProvider
Create a content provider that provides the givenbytes
as data for the givenmimeType
.static ContentProvider
Create a content provider that provides the givenvalue
.static MemoryLayout
The memory layout of the native struct.static Type
getType()
Get the GType of the ContentProvider classboolean
Gets the contents of this ContentProvider stored invalue
.Emitted whenever the content provided by this provider has changed.Gets the formats that the provider can provide its current contents in.Gets the formats that the provider suggests other applications to store the data in.static ContentProvider
Create a content provider that provides the value of the giventype
.static ContentProvider
union
(@Nullable ContentProvider[] providers) Creates a content provider that represents all the givenproviders
.void
writeMimeTypeAsync
(String mimeType, OutputStream stream, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Asynchronously writes the contents of this ContentProvider tostream
in the givenmimeType
.boolean
writeMimeTypeFinish
(AsyncResult result) Finishes an asynchronous write operation.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, 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
-
ContentProvider
Create a ContentProvider proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
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. -
forBytes
Create a content provider that provides the givenbytes
as data for the givenmimeType
.- Parameters:
mimeType
- the mime typebytes
- aGBytes
with the data formimeType
- Returns:
- a new
GdkContentProvider
-
forValue
Create a content provider that provides the givenvalue
.- Parameters:
value
- aGValue
- Returns:
- a new
GdkContentProvider
-
typed
Create a content provider that provides the value of the giventype
.The value is provided using G_VALUE_COLLECT(), so the same rules apply as when calling g_object_new() or g_object_set().
- Parameters:
type
- Type of value to followvarargs
- value- Returns:
- a new
GdkContentProvider
-
union
Creates a content provider that represents all the givenproviders
.Whenever data needs to be written, the union provider will try the given
providers
in the given order and the first one supporting a format will be chosen to provide it.This allows an easy way to support providing data in different formats. For example, an image may be provided by its file and by the image contents with a call such as
gdk_content_provider_new_union ((GdkContentProvider *[2]) { gdk_content_provider_new_typed (G_TYPE_FILE, file), gdk_content_provider_new_typed (G_TYPE_TEXTURE, texture) }, 2);
- Parameters:
providers
- TheGdkContentProvider
s to present the union of- Returns:
- a new
GdkContentProvider
-
contentChanged
public void contentChanged()Emits the ::content-changed signal. -
getValue
Gets the contents of this ContentProvider stored invalue
.The
value
will have been initialized to theGType
the value should be provided in. This givenGType
does not need to be listed in the formats returned byrefFormats()
. However, if the givenGType
is not supported, this operation can fail andG_IO_ERROR_NOT_SUPPORTED
will be reported.- Parameters:
value
- theGValue
to fill- Returns:
true
if the value was set successfully. Otherwiseerror
will be set to describe the failure.- Throws:
GErrorException
- seeGError
-
refFormats
Gets the formats that the provider can provide its current contents in.- Returns:
- The formats of the provider
-
refStorableFormats
Gets the formats that the provider suggests other applications to store the data in.An example of such an application would be a clipboard manager.
This can be assumed to be a subset of
refFormats()
.- Returns:
- The storable formats of the provider
-
writeMimeTypeAsync
public void writeMimeTypeAsync(String mimeType, OutputStream stream, int ioPriority, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) Asynchronously writes the contents of this ContentProvider tostream
in the givenmimeType
.The given mime type does not need to be listed in the formats returned by
refFormats()
. However, if the givenGType
is not supported,G_IO_ERROR_NOT_SUPPORTED
will be reported.The given
stream
will not be closed.- Parameters:
mimeType
- the mime type to provide the data instream
- theGOutputStream
to write toioPriority
- I/O priority of the request.cancellable
- optionalGCancellable
object,null
to ignore.callback
- callback to call when the request is satisfied
-
writeMimeTypeFinish
Finishes an asynchronous write operation.- Parameters:
result
- aGAsyncResult
- Returns:
true
if the operation was completed successfully. Otherwiseerror
will be set to describe the failure.- Throws:
GErrorException
- seeGError
-
attachClipboard
-
detachClipboard
-
onContentChanged
public SignalConnection<ContentProvider.ContentChangedCallback> onContentChanged(ContentProvider.ContentChangedCallback handler) Emitted whenever the content provided by this provider has changed.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitContentChanged
public void emitContentChanged()Emits the "content-changed" signal. SeeonContentChanged(org.gnome.gdk.ContentProvider.ContentChangedCallback)
. -
builder
AContentProvider.Builder
object constructs aContentProvider
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withContentProvider.Builder.build()
.
-