Package ca.cgjennings.ui.dnd
Class ScrapBook
- java.lang.Object
-
- ca.cgjennings.ui.dnd.ScrapBook
-
public class ScrapBook extends java.lang.ObjectThis class provides a simple interface for accessing common data types from the clipboard.- Author:
- Chris Jennings
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classScrapBook.FileListSelectionA transferable implementation for lists ofFiles.static classScrapBook.ImageSelectionA transferable implementation for images.static classScrapBook.Selection<K>A base class for creating transferables with exactly one acceptableDataFlavor.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.io.File[]getFiles()Returns the list of files on the clipboard as an array ofFileobjects, ornull.static java.awt.image.BufferedImagegetImage()Returns the image stored on the clipboard, ornullif the clipboard content does not consist of an image.static java.lang.StringgetSystemSelectionText()Returns the text stored in the system selection on platforms that support this feature.static java.lang.StringgetText()Returns the current text on the clipboard, ornullif the clipboard content does not include text.static booleanisFileAvailable()Returns whether one or more files are available on the clipboard.static booleanisImageAvailable()Returns whether an image is available on the clipboard.static booleanisTextAvailable()Returns whether there is text available on the clipboard.static voidsetFiles(java.io.File[] content)Sets the clipboard content to a list of files.static voidsetFiles(java.util.List<java.io.File> content)Sets the clipboard content to a list of files.static voidsetFiles(java.util.List<java.io.File> content, java.awt.datatransfer.ClipboardOwner owner)Sets the clipboard content to a list of files, using the specified owner.static voidsetImage(java.awt.Image content)Sets the clipboard content to an image.static voidsetImage(java.awt.Image content, java.awt.datatransfer.ClipboardOwner owner)Sets the clipboard content to the specified image, using the specified owner.static voidsetSystemSelectionText(java.lang.String content)Sets the text stored in the system selection on platforms that support this feature.static voidsetText(java.lang.String content)Sets the clipboard text to the specified string.static voidsetText(java.lang.String content, java.awt.datatransfer.ClipboardOwner owner)Sets the clipboard text to the specified string, using the specified owner.
-
-
-
Method Detail
-
setText
public static void setText(java.lang.String content)
Sets the clipboard text to the specified string.- Parameters:
content- the string to set as the clipboard content
-
setText
public static void setText(java.lang.String content, java.awt.datatransfer.ClipboardOwner owner)Sets the clipboard text to the specified string, using the specified owner.- Parameters:
content- the string to set as the clipboard contentowner- the content owner to specify
-
getText
public static java.lang.String getText()
Returns the current text on the clipboard, ornullif the clipboard content does not include text.- Returns:
- the current clipboard text
-
isTextAvailable
public static boolean isTextAvailable()
Returns whether there is text available on the clipboard.- Returns:
trueif the clipboard contains text (or can be converted to text)
-
getSystemSelectionText
public static java.lang.String getSystemSelectionText()
Returns the text stored in the system selection on platforms that support this feature. Returnsnullif the platform does not have a system selection or it does not have any text available.- Returns:
- the system selection text
-
setSystemSelectionText
public static void setSystemSelectionText(java.lang.String content)
Sets the text stored in the system selection on platforms that support this feature. Has no effect if the platform does not include the concept of a system selection.- Parameters:
content- the system selection text to set
-
setImage
public static void setImage(java.awt.Image content)
Sets the clipboard content to an image. Note that some platforms may not support some image features. For example, Windows platforms may not support image transparency (alpha channels).- Parameters:
content- the image to place on the clipboard
-
setImage
public static void setImage(java.awt.Image content, java.awt.datatransfer.ClipboardOwner owner)Sets the clipboard content to the specified image, using the specified owner. Note that some platforms may not support some image features. For example, Windows platforms may not support image transparency (alpha channels).- Parameters:
content- the image to place on the clipboardowner- the content owner to specify
-
getImage
public static java.awt.image.BufferedImage getImage()
Returns the image stored on the clipboard, ornullif the clipboard content does not consist of an image.- Returns:
- the image on the clipboard, or
null
-
isImageAvailable
public static boolean isImageAvailable()
Returns whether an image is available on the clipboard.- Returns:
trueif an image is available
-
setFiles
public static void setFiles(java.io.File[] content)
Sets the clipboard content to a list of files.- Parameters:
content- an array of the files to list on the clipboard
-
setFiles
public static void setFiles(java.util.List<java.io.File> content)
Sets the clipboard content to a list of files.- Parameters:
content- a list of the files to place on the clipboard
-
setFiles
public static void setFiles(java.util.List<java.io.File> content, java.awt.datatransfer.ClipboardOwner owner)Sets the clipboard content to a list of files, using the specified owner.- Parameters:
content- a list of the files to place on the clipboardowner- the content owner to specify
-
getFiles
public static java.io.File[] getFiles()
Returns the list of files on the clipboard as an array ofFileobjects, ornull.- Returns:
- the files on the clipboard, or
null
-
isFileAvailable
public static boolean isFileAvailable()
Returns whether one or more files are available on the clipboard.- Returns:
trueif files are available
-
-