Class DataFormat


  • public class DataFormat
    extends Object
    Data format identifier used as means of identifying the data stored on a clipboard/dragboard.
    Since:
    JavaFX 2.0
    • Field Detail

      • PLAIN_TEXT

        public static final DataFormat PLAIN_TEXT
        Represents a plain text string.
      • HTML

        public static final DataFormat HTML
        Represents an HTML formatted string.
      • RTF

        public static final DataFormat RTF
        Represents an RTF formatted string
      • URL

        public static final DataFormat URL
        Represents a URL, encoded as a String
      • IMAGE

        public static final DataFormat IMAGE
        A special platform specific image type, such as is commonly used on the clipboard and interoperates widely with other applications. For example, on Mac this might ultimately be a TIFF while on Windows it might be a DIB (device independent bitmap).
      • FILES

        public static final DataFormat FILES
        Represents a List of Files.
    • Constructor Detail

      • DataFormat

        public DataFormat​(String... ids)
        Create a new DataFormat, specifying the set of ids that are associated with this data format. Typically the ids are one or more mime types. For each id, any data associated with this DataFormat will be registered on the clipboard. For example, suppose I had the following:
        
             DataFormat fmt = new DataFormat("text/foo", "text/bar");
             Clipboard clipboard = Clipboard.getSystemClipboard();
             ClipboardContent content = new ClipboardContent();
             content.put(fmt, "Hello");
             clipboard.setContent(content);
         
        With the above code, if I were to look on the clipboard, I'd find the String "Hello" listed both for "text/foo" and "text/bar" on the clipboard.

        Note that the ids may be subject to platform restrictions in some cases. For instance, Swing requires a mime type so if an id is not of the "type/subtype" format it won't be possible to drag data of this type from/to JFXPanel.

        Parameters:
        ids - The set of ids used to represent this DataFormat on the clipboard.
        Throws:
        IllegalArgumentException - if one of the given mime types is already assigned to another DataFormat.
    • Method Detail

      • getIdentifiers

        public final Set<String> getIdentifiers()
        Gets the unmodifiable set of identifiers for this DataFormat.
        Returns:
        an unmodifiable set that is never null.
      • toString

        public String toString()
        Returns a string representation of this DataFormat object.
        Overrides:
        toString in class Object
        Returns:
        a string representation of this DataFormat object.
      • hashCode

        public int hashCode()
        Returns a hash code for this DataFormat object.
        Overrides:
        hashCode in class Object
        Returns:
        a hash code for this DataFormat object.
      • equals

        public boolean equals​(Object obj)
        Indicates whether some other object is "equal to" this one.
        Overrides:
        equals in class Object
        Parameters:
        obj - the reference object with which to compare.
        Returns:
        true if this object is equal to the obj argument; false otherwise.
      • lookupMimeType

        public static DataFormat lookupMimeType​(String mimeType)
        Looks for the DataFormat which has been previously created with the given mime type as one of its ids.
        Parameters:
        mimeType - If null or the empty string, then null is returned.
        Returns:
        The matching DataFormat