Class ClipboardContent

java.lang.Object
com.codename1.ui.ClipboardContent
Direct Known Subclasses:
RichTextClipboardData

public class ClipboardContent extends Object

A set of alternative clipboard representations keyed by MIME type. A clipboard write should normally include text/plain plus any richer formats it can provide. Clipboard readers negotiate by inspecting #getMimeTypes() and requesting the representation they understand best.

Values are usually String or byte[]. Ports may support additional native value types, but must retain the plain-text representation when one is supplied.

  • Field Details

  • Constructor Details

    • ClipboardContent

      public ClipboardContent()
  • Method Details

    • setData

      public ClipboardContent setData(String mimeType, Object value)
      Adds or replaces a representation. Passing null removes the MIME type.
    • setDataProvider

      public ClipboardContent setDataProvider(String mimeType, ClipboardDataProvider provider)

      Declares a representation that is only built if something reads it, which is how a drag offers a file it has not written yet or an image it has not encoded yet.

      The provider is asked at most once and its answer is then cached, so #getData(java.lang.String) behaves exactly as it would for a value passed to #setData(java.lang.String, java.lang.Object). It may run on a native clipboard or drag thread; see ClipboardDataProvider. Passing a null provider removes the MIME type.

      Parameters
      • mimeType: the MIME type this provider can produce

      • provider: the provider, or null to remove the representation

      Returns

      this instance, for chaining

    • getData

      public Object getData(String mimeType)

      Returns the representation for a MIME type, or null when it isn't available.

      A representation registered through #setDataProvider(java.lang.String, com.codename1.ui.ClipboardDataProvider) is produced here, on the first call for that MIME type.

    • getBytes

      public byte[] getBytes(String mimeType)
      Returns the binary (byte[]) representation for a MIME type -- e.g. the raw bytes of an image or file -- or null when it isn't available or isn't binary.
    • getText

      public String getText(String mimeType)
      Returns a string representation, or null when the value isn't a string.
    • hasMimeType

      public boolean hasMimeType(String mimeType)
      Returns true when this content includes the requested MIME type.
    • getMimeTypes

      public String[] getMimeTypes()
      Returns the available MIME types in preference order.
    • setFiles

      public ClipboardContent setFiles(String[] paths)

      Sets the #MIME_FILE representation from a list of file paths or file: URIs.

      Ports differ on whether a single file is carried as a String or a one element String[]; this writes the form the rest of the framework expects, and #getFiles() reads either.

      Parameters
      • paths: the file paths, or null to remove the representation
      Returns

      this instance, for chaining

    • getFiles

      public String[] getFiles()
      Returns the #MIME_FILE representation as a path array regardless of whether the producer stored one String or a String[], or null when no files are available.
    • findPreferredMimeType

      public String findPreferredMimeType(String[] preferredMimeTypes)
      Returns the first available MIME type from the caller's preference list, or null.