Package ca.cgjennings.ui.dnd
Class ScrapBook
- java.lang.Object
-
- ca.cgjennings.ui.dnd.ScrapBook
-
public class ScrapBook extends java.lang.Object
This 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 class
ScrapBook.FileListSelection
A transferable implementation for lists ofFile
s.static class
ScrapBook.ImageSelection
A transferable implementation for images.static class
ScrapBook.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 ofFile
objects, ornull
.static java.awt.image.BufferedImage
getImage()
Returns the image stored on the clipboard, ornull
if the clipboard content does not consist of an image.static java.lang.String
getSystemSelectionText()
Returns the text stored in the system selection on platforms that support this feature.static java.lang.String
getText()
Returns the current text on the clipboard, ornull
if the clipboard content does not include text.static boolean
isFileAvailable()
Returns whether one or more files are available on the clipboard.static boolean
isImageAvailable()
Returns whether an image is available on the clipboard.static boolean
isTextAvailable()
Returns whether there is text available on the clipboard.static void
setFiles(java.io.File[] content)
Sets the clipboard content to a list of files.static void
setFiles(java.util.List<java.io.File> content)
Sets the clipboard content to a list of files.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.static void
setImage(java.awt.Image content)
Sets the clipboard content to an image.static void
setImage(java.awt.Image content, java.awt.datatransfer.ClipboardOwner owner)
Sets the clipboard content to the specified image, using the specified owner.static void
setSystemSelectionText(java.lang.String content)
Sets the text stored in the system selection on platforms that support this feature.static void
setText(java.lang.String content)
Sets the clipboard text to the specified string.static void
setText(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, ornull
if 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:
true
if 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. Returnsnull
if 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, ornull
if 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:
true
if 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 ofFile
objects, 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:
true
if files are available
-
-