Class PlatformClipboard

java.lang.Object
limn.backend.lwjgl.transfer.PlatformClipboard
All Implemented Interfaces:
Clipboard

public final class PlatformClipboard extends Object implements Clipboard
The clipboard an application sees, over one system's NativeClipboard: a transfer going out becomes type names and, when a program asks, bytes; what another program offers comes back as formats and, when the application asks, values.

While this process owns the clipboard, what it reads is the transfer it set, as it is: no encoding, no round trip, and the in-process formats with it.

  • Constructor Details

    • PlatformClipboard

      public PlatformClipboard(NativeClipboard system, UiRuntime ui)
      Parameters:
      system - the windowing system's clipboard
      ui - the runtime whose thread lazy values are made on and results arrive on
  • Method Details

    • text

      public String text()
      Description copied from interface: Clipboard
      The clipboard's text, now. A paste in a key handler and a menu that greys its Paste item both want the answer in the same breath, so this one read does not wait: where the text has to come from another program through a pipe, it gives up after a second.
      Specified by:
      text in interface Clipboard
      Returns:
      the text; the empty string when the clipboard holds none, never null
    • set

      public void set(Transfer content)
      Description copied from interface: Clipboard
      Replaces what the clipboard holds. A lazy value of the transfer is asked for when a program, this one included, first reads that format.
      Specified by:
      set in interface Clipboard
      Parameters:
      content - what to offer; Transfer.EMPTY empties the clipboard
    • types

      public static List<String> types(Transfer content)
      The types a transfer offers another program, best first: what a copy announces and what a drag carries. A format that never leaves the process is not among them.
      Parameters:
      content - the transfer
      Returns:
      the canonical type names
    • provider

      public static Function<String,byte[]> provider(Transfer content, UiRuntime ui)
      What makes the bytes of one of a transfer's types, once, for a system that asks for them: as a copy's are made, on the UI thread for the value and where it is asked for the rest.
      Parameters:
      content - the transfer
      ui - the runtime whose thread a lazy value is made on
      Returns:
      from a canonical type to its bytes, or null for what cannot be made
    • content

      public Offer content()
      Description copied from interface: Clipboard
      What the clipboard holds now. The formats are answered from what the platform last reported, without a round trip, so a menu can ask on every opening; a read of something that has been replaced meanwhile fails with TransferGoneException.
      Specified by:
      content in interface Clipboard
      Returns:
      the offer; Offer.EMPTY's equal when the clipboard is empty
    • offer

      public static Offer offer(List<String> offered, Function<String,CompletableFuture<byte[]>> read, UiRuntime ui)
      What another program offers, as an offer: the clipboard's content, or what a drag carries.
      Parameters:
      offered - the canonical types on offer
      read - asks for the bytes of one of them
      ui - the runtime whose thread the values arrive on
      Returns:
      the offer
    • onChange

      public Subscription onChange(Runnable listener)
      Description copied from interface: Clipboard
      Hears the clipboard's content change, whoever changed it, where the platform tells.
      Specified by:
      onChange in interface Clipboard
      Parameters:
      listener - called on the UI thread after each change
      Returns:
      the way to stop listening
    • close

      public void close()
      Lets go of the system's clipboard; called once, as the backend closes.