Class ContentProvider

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public class ContentProvider extends GObject

Provides content for the clipboard or for drag-and-drop operations in a number of formats.

To create a GdkContentProvider, use forValue(Value) or forBytes(String, byte[]).

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.

  • Constructor Details

    • ContentProvider

      public ContentProvider(MemorySegment address)
      Create a ContentProvider instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • ContentProvider

      public ContentProvider()
      Create a new ContentProvider.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the ContentProvider class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected ContentProvider asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class GObject
      Returns:
      the instance as if it were its parent type
    • forBytes

      public static ContentProvider forBytes(String mimeType, byte[] bytes)
      Create a content provider that provides the given bytes as data for the given mimeType.
      Parameters:
      mimeType - the mime type
      bytes - a GBytes with the data for mimeType
      Returns:
      a new GdkContentProvider
    • forValue

      public static ContentProvider forValue(Value value)
      Create a content provider that provides the given value.
      Parameters:
      value - a GValue
      Returns:
      a new GdkContentProvider
    • typed

      public static ContentProvider typed(Type type, Object... varargs)

      Create a content provider that provides the value of the given type.

      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 follow
      varargs - value
      Returns:
      a new GdkContentProvider
    • union

      public static ContentProvider union(@Nullable ContentProvider @Nullable [] providers)

      Creates a content provider that represents all the given providers.

      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 (GDK_TYPE_TEXTURE, texture)
                                      }, 2);
      
      Parameters:
      providers - The GdkContentProviders to present the union of
      Returns:
      a new GdkContentProvider
    • contentChanged

      public void contentChanged()
      Emits the ::content-changed signal.
    • getValue

      public boolean getValue(Value value) throws GErrorException

      Gets the contents of this ContentProvider stored in value.

      The value will have been initialized to the GType the value should be provided in. This given GType does not need to be listed in the formats returned by refFormats(). However, if the given GType is not supported, this operation can fail and G_IO_ERROR_NOT_SUPPORTED will be reported.

      Parameters:
      value - the GValue to fill
      Returns:
      true if the value was set successfully. Otherwise error will be set to describe the failure.
      Throws:
      GErrorException - see GError
    • refFormats

      public ContentFormats refFormats()
      Gets the formats that the provider can provide its current contents in.
      Returns:
      The formats of the provider
    • refStorableFormats

      public ContentFormats 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 Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Asynchronously writes the contents of this ContentProvider to stream in the given mimeType.

      The given mime type does not need to be listed in the formats returned by refFormats(). However, if the given GType 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 in
      stream - the GOutputStream to write to
      ioPriority - I/O priority of the request.
      cancellable - optional GCancellable object, null to ignore.
      callback - callback to call when the request is satisfied
    • writeMimeTypeFinish

      public boolean writeMimeTypeFinish(AsyncResult result) throws GErrorException
      Parameters:
      result - a GAsyncResult
      Returns:
      true if the operation was completed successfully. Otherwise error will be set to describe the failure.
      Throws:
      GErrorException - see GError
    • attachClipboard

      protected void attachClipboard(Clipboard clipboard)
    • detachClipboard

      protected void detachClipboard(Clipboard clipboard)
    • onContentChanged

      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. See onContentChanged(ContentProvider.ContentChangedCallback).
    • builder

      public static ContentProvider.Builder<? extends ContentProvider.Builder> builder()
      A ContentProvider.Builder object constructs a ContentProvider with the specified properties. Use the various set...() methods to set properties, and finish construction with ContentProvider.Builder.build().
      Returns:
      the builder object