Class ClipboardUtils


  • public final class ClipboardUtils
    extends java.lang.Object
    This is a utility class that provides methods useful for general data transfer support.
    Since:
    10604
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.awt.datatransfer.Clipboard clipboard  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private ClipboardUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean clear()
      Clears the system clipboard.
      static boolean copy​(java.awt.datatransfer.Transferable transferable)
      Copies the given transferable to the clipboard.
      static boolean copyString​(java.lang.String s)
      Copy the given string to the clipboard.
      static java.awt.datatransfer.Clipboard getClipboard()
      This method should be used from all of JOSM to access the clipboard.
      static java.awt.datatransfer.Transferable getClipboardContent()
      Extracts clipboard content as Transferable object.
      static java.awt.datatransfer.Transferable getClipboardContent​(java.awt.datatransfer.Clipboard clipboard)
      Extracts clipboard content as Transferable object.
      static java.lang.String getClipboardStringContent()
      Gets the clipboard content as string.
      static java.awt.datatransfer.Clipboard getSystemSelection()
      Gets the singleton instance of the system selection as a Clipboard object.
      static java.awt.datatransfer.DataFlavor newDataFlavor​(java.lang.Class<?> c, java.lang.String humanPresentableName)
      Returns a new DataFlavor for the given class and human-readable name.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • clipboard

        private static java.awt.datatransfer.Clipboard clipboard
    • Method Detail

      • getClipboard

        public static java.awt.datatransfer.Clipboard getClipboard()
        This method should be used from all of JOSM to access the clipboard.

        It will default to the system clipboard except for cases where that clipboard is not accessible.

        Returns:
        A clipboard.
        See Also:
        getClipboardContent()
      • getSystemSelection

        public static java.awt.datatransfer.Clipboard getSystemSelection()
        Gets the singleton instance of the system selection as a Clipboard object. This allows an application to read and modify the current, system-wide selection.
        Returns:
        the system selection as a Clipboard, or null if the native platform does not support a system selection Clipboard or if GraphicsEnvironment.isHeadless() returns true
        See Also:
        Toolkit.getSystemSelection()
      • getClipboardStringContent

        public static java.lang.String getClipboardStringContent()
        Gets the clipboard content as string.
        Returns:
        the content if available, null otherwise.
      • getClipboardContent

        public static java.awt.datatransfer.Transferable getClipboardContent()
        Extracts clipboard content as Transferable object. Using this method avoids some problems on some platforms.
        Returns:
        The content or null if it is not available
      • getClipboardContent

        public static java.awt.datatransfer.Transferable getClipboardContent​(java.awt.datatransfer.Clipboard clipboard)
        Extracts clipboard content as Transferable object. Using this method avoids some problems on some platforms.
        Parameters:
        clipboard - clipboard from which contents are retrieved
        Returns:
        clipboard contents if available, null otherwise.
      • copyString

        public static boolean copyString​(java.lang.String s)
        Copy the given string to the clipboard.
        Parameters:
        s - The string to copy.
        Returns:
        True if the copy was successful
      • copy

        public static boolean copy​(java.awt.datatransfer.Transferable transferable)
        Copies the given transferable to the clipboard. Handles state problems that occur on some platforms.
        Parameters:
        transferable - The transferable to copy.
        Returns:
        True if the copy was successful
      • newDataFlavor

        public static java.awt.datatransfer.DataFlavor newDataFlavor​(java.lang.Class<?> c,
                                                                     java.lang.String humanPresentableName)
        Returns a new DataFlavor for the given class and human-readable name.
        Parameters:
        c - class
        humanPresentableName - the human-readable string used to identify this flavor
        Returns:
        a new DataFlavor for the given class and human-readable name
        Since:
        10801
      • clear

        public static boolean clear()
        Clears the system clipboard.
        Returns:
        True if the clear was successful
        Since:
        14500