Package org.rexxla.bsf.engines.rexx
Class BsfSystemClipboard
java.lang.Object
org.rexxla.bsf.engines.rexx.BsfSystemClipboard
This class employs the java.awt.datatransfer.Clipboard class and allows for
setting (and getting from) the system clipboard Java images (java.awt.Image)
and strings.
- Since:
- 2023-06-10
- Author:
- Rony G. Flatscher
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidclear()Clears (empties) the system clipboard.static DataFlavor[]Returns an array of java.awt.datatransfer.DataFlavors (formats) currently available on the system clipboard.static ImagegetImage()Gets an image from the system clipboard and returns it.static StringReturns the string currently in the system clipboard.static byte[]Returns the string currently in the system clipboard as a byte array encoded according to the supplied codepage.static booleanisEmpty()Tests whether the system clipboard is empty (if no data flavors are present).static voidThis copies the received image to the clipboard.static ImageThis allows a java.awt.Image image to be copied as a JPG/JPEG (!) image to the system clipboard.static voidSets the supplied string to the system clipboard.
-
Field Details
-
version
- See Also:
-
-
Constructor Details
-
BsfSystemClipboard
public BsfSystemClipboard()
-
-
Method Details
-
isEmpty
public static boolean isEmpty()Tests whether the system clipboard is empty (if no data flavors are present).- Returns:
- true if empty, false else
-
getDataFlavors
Returns an array of java.awt.datatransfer.DataFlavors (formats) currently available on the system clipboard. If no data is availalbe the array will have a length of 0 and the method {@link public static boolean isEmpty()} will return .true.- Returns:
- an array of type java.awt.datatransfer.DataFlavor
-
clear
public static void clear()Clears (empties) the system clipboard. -
setImageWithoutAlpha
This allows a java.awt.Image image to be copied as a JPG/JPEG (!) image to the system clipboard. The supplied image will therefore be transformed into a JPG/JPEG (with a white background).- Parameters:
img- the image to be copied (without alpha/translucency on white background) to the clipboard)- Returns:
- image that was used to set the clipboard
-
setImage
This copies the received image to the clipboard.
Note 1: if the image has an alpha channel there will be a non catchable stack trace created by the default ImageIIO writer when creating a JPG/JPEG rendering. In order to intercept that stack trace, this method will temporarily reassign System.err to a PrintStream that is to receive that output in order to hide it.
Note 2: even if the JPG/JPEG is not created usually a "BITMAP" and a "GDI metafile" get created in the Windows clipboard.
Note 3: Use {@link public static void setImageNoAlpha(Image img)} to make sure that the image does not have alpha (translucency) such that creating a JPG/JPEG is possible in any case.- Parameters:
img- the image to copy to the clipboard
-
getImage
Gets an image from the system clipboard and returns it.- Returns:
- image from the system clipboard or null if no image available
-
setString
Sets the supplied string to the system clipboard. -
getString
Returns the string currently in the system clipboard.- Returns:
- the string currently in the system clipboard, null if no string available
-
getString
Returns the string currently in the system clipboard as a byte array encoded according to the supplied codepage. *@param codepage the codepage to be used for creating the byte array, if null then defaults to "UTF-8"- Returns:
- the string currently in the system clipboard, null if no string available
-