Interface NativeClipboard

All Known Implementing Classes:
MacClipboard, WaylandClipboard, WindowsClipboard, X11Clipboard

public interface NativeClipboard
One windowing system's clipboard, in the terms every one of them shares: a list of type names and the bytes behind each. The names are the canonical ones of ClipboardTypes for the four standard formats, whatever the system calls them, and an application's own format under its own name.

Every method may be called from the UI thread; what an implementation does on threads of its own is its business, and the two callbacks it is handed say which thread they tolerate.

  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Lets go of the system's resources.
    boolean
     
    default List<String>
    madeAhead(List<String> offered)
    The types worth making ahead of anybody asking, because this system asks on the UI thread and waits there: the picture's, where making it is slow.
    void
    offer(List<String> types, Function<String,byte[]> bytes)
    Makes this process the clipboard's owner.
    read(String type)
    Asks for the bytes of one type.
    void
     
    The types on the clipboard as the system last reported them, without asking it again.
  • Method Details

    • isOwner

      boolean isOwner()
      Returns:
      whether what the clipboard holds was put there by the last offer(java.util.List<java.lang.String>, java.util.function.Function<java.lang.String, byte[]>) of this process and has not been replaced since
    • types

      List<String> types()
      The types on the clipboard as the system last reported them, without asking it again.
      Returns:
      canonical type names, best first; empty when the clipboard is empty or unknown
    • read

      CompletableFuture<byte[]> read(String type)
      Asks for the bytes of one type.
      Parameters:
      type - one of types()
      Returns:
      the bytes, completed on whatever thread the implementation reads on; completed exceptionally when the type is not, or no longer, there
    • offer

      void offer(List<String> types, Function<String,byte[]> bytes)
      Makes this process the clipboard's owner.
      Parameters:
      types - what is offered, best first; empty empties the clipboard
      bytes - the bytes of one of those types, asked for when a program wants them; it may be called on any thread and may block, and answers null for what it cannot make
    • madeAhead

      default List<String> madeAhead(List<String> offered)
      The types worth making ahead of anybody asking, because this system asks on the UI thread and waits there: the picture's, where making it is slow.
      Parameters:
      offered - the types about to be offered
      Returns:
      those of offered, and of the private types this clipboard asks for itself, that should be made in the background as soon as they are offered
    • setChangeListener

      void setChangeListener(Runnable listener)
      Parameters:
      listener - called, on any thread, after the clipboard's types or its owner change, an offer(java.util.List<java.lang.String>, java.util.function.Function<java.lang.String, byte[]>) of this process included; replaces the one before
    • close

      void close()
      Lets go of the system's resources. The clipboard is not used afterwards.