Class ClipboardHandler
- java.lang.Object
-
- chemaxon.marvin.modules.datatransfer.ClipboardHandler
-
@PublicAPI public final class ClipboardHandler extends Object
Facade of the Clipboard handling in Marvin.
Utility class that can be used to transfer Molecule or other data from Marvin to the system clipboard using cut/copy/paste operations.
- Since:
- Marvin 5.3 11/25/2009
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static void
addTransferable(TransferableDescriptor d)
Add aTransferableDescriptor
to theMTransferable
Registry.static void
addTransferable(String name, String className, Integer priority, Integer inputPriority, boolean isdefault, boolean copyAsTransferable)
Deprecated.static void
addTransferable(String name, String className, Integer priority, Integer inputPriority, boolean isdefault, boolean copyAsTransferable, boolean dndTransferable)
Add aTransferableDescriptor
to the registry, and constructing it by the given parameters.static void
clearClipboard()
Clears the clipboard by creating an empty Transferable and placing it on the clipboard.static void
clearClipboardConditionally()
Clears the clipboard, ifisClearClipboardBeforeExport()
is true.static boolean
convert(chemaxon.marvin.modules.datatransfer.TransferDataImporter converter)
Convert transfer data available on clipboard in one of the requested flavors.static Clipboard
getClipboard()
Returns the default Toolkit's system clipboard if available, otherwise returns a new singleton clipboard instance.static Transferable
getClipboardContents()
Inits and return the transferable of the Clipboard for later import.static List<String>
getCopyAsTransferableNames()
Returns the format's names that are available in the current environment as transfer types for the Copy As dialog.static Object
getObjectFromClipboard()
Returns the current content of the clipboard if the data can be imported in any of data formats supported by MolImporter.static Object
getObjectFromClipboard(String imageImportServiceURL)
Returns the current content of the clipboard if the data can be imported in any of data formats supported by MolImporter.static Object
getObjectFromTransferable(Transferable transfer)
Returns the content of Transferable if the data can be imported in any of data formats supported by MolImporter.static Object
getObjectFromTransferable(Transferable transfer, String imageImportServiceURL)
Returns the content of Transferable if the data can be imported in any of data formats supported by MolImporter.static String
getStringFromClipboard()
Returns the String data from the clipboard contents, if the clipboard contains a Transferable that provides support toDataFlavor.stringFlavor
static Transferable
getTransferableFor(Molecule mol, Properties props)
Creates aMTransferable
object to the givenMolecule
with the given properties.static Transferable
getTransferableFor(Molecule mol, Properties props, String fmt)
Creates aMTransferable
to the givenMolecule
with the given properties in the given format.static boolean
getWorkOnBackGround()
Returns whether the subsystem works on the current thread or on a background thread.static boolean
isClearClipboardBeforeExport()
Returns whether the subsystem clears the clipboard before a copy operation.static boolean
isSupportedTransferFormat(String fmtId)
Checks whether the given format is available in the current environment or not.static void
putFormattedTextToClipboard(Document doc, int start, int end)
Deprecated.static void
putImageToClipboard(Image img)
Places the given Image to the clipboard.static void
putMoleculeToClipboard(Molecule mol, Properties props)
Places a Molecule object to the clipboard which is represented as a Transferable being configured to support all the default Transfer types of Marvin.static void
putMoleculeToClipboard(Molecule mol, Properties props, String fmt)
Places a Molecule object to the clipboard which is represented as a Transferable configured to support the transfer types of the specified format identifier.static void
putOLEToClipboard(Molecule mol, Properties props)
static void
putStringToClipboard(String str)
Places the given String to the clipboard as aStringSelection
.static void
putTransferableToClipboard(Transferable t)
A generic way to put content to clipboard.static void
releasePermanentResources()
Releases all clipboard related native libraries and resources.static void
removeOLESupport()
Removing the support of OLE transfer format.static TransferableDescriptor
removeTransferable(TransferableDescriptor d)
Removes aTransferableDescriptor
to theMTransferable
Registry.static TransferableDescriptor
removeTransferable(String name)
Removes aTransferableDescriptor
to theMTransferable
Registry by name.static void
setClearClipboardBeforeExport(boolean b)
Sets whether the subsystem should clear the clipboard before a copy operation.static void
setWorkOnBackground(boolean b)
Starts or stops the background worker thread and ensures the required state for the type of work.static void
startPermanentResources()
Starts all the permanent native resources that have to be started to do fast and reliable copy in Marvin.
-
-
-
Method Detail
-
setWorkOnBackground
public static void setWorkOnBackground(boolean b)
Starts or stops the background worker thread and ensures the required state for the type of work. If it previously worked in the background then waits for the previously submitted tasks to finish.
It defaults to false.- Parameters:
b
- true means working in the background, false means working on the current thread.
-
getWorkOnBackGround
public static boolean getWorkOnBackGround()
Returns whether the subsystem works on the current thread or on a background thread.- Returns:
- true if it works on the current thread false otherwise.
-
setClearClipboardBeforeExport
public static void setClearClipboardBeforeExport(boolean b)
Sets whether the subsystem should clear the clipboard before a copy operation. The default value is true.- Parameters:
b
- true or false
-
isClearClipboardBeforeExport
public static boolean isClearClipboardBeforeExport()
Returns whether the subsystem clears the clipboard before a copy operation.- Returns:
- true if the clipboard is cleared before a copy operation false otherwise.
-
putStringToClipboard
public static void putStringToClipboard(String str)
Places the given String to the clipboard as aStringSelection
. When processing on a background thread, this method will continuously try to put the String to the clipboard until the operation has succeeded.- Parameters:
str
- the String to be placed to the clipboard- Throws:
IllegalStateException
- if the clipboard is currently unavailable, and running on the current thread.
-
putFormattedTextToClipboard
@Deprecated public static void putFormattedTextToClipboard(Document doc, int start, int end)
Deprecated.Method to place HTMLDocument on clipboard. Use putTransferableToClipboard() instead.- Parameters:
doc
-start
-end
-
-
putImageToClipboard
public static void putImageToClipboard(Image img)
Places the given Image to the clipboard. When processing on a background thread, this method will continuously try to put the String to the clipboard until the operation has succeeded.- Parameters:
img
- the Image to be placed to the clipboard- Throws:
IllegalStateException
- if the clipboard is currently unavailable, and running on the current thread.
-
putMoleculeToClipboard
public static void putMoleculeToClipboard(Molecule mol, Properties props)
Places a Molecule object to the clipboard which is represented as a Transferable being configured to support all the default Transfer types of Marvin. When processing on a background thread, this method will continuously try to put the String to the clipboard until the operation has succeeded.- Parameters:
mol
- the Molecule to be placed to the clipboardprops
- display properties of the Molecule, this parameter will be used when transferring Molecule images to clipboard, and can be one of, or the union of properties stored inUserSettings
, and in the result ofMDocument.getGUIPropertyContainer()
- Throws:
IllegalStateException
- if the clipboard is currently unavailable, and running on the current thread.- See Also:
ImageExportUtil
-
putMoleculeToClipboard
public static void putMoleculeToClipboard(Molecule mol, Properties props, String fmt)
Places a Molecule object to the clipboard which is represented as a Transferable configured to support the transfer types of the specified format identifier. When processing on a background thread, this method will continuously try to put the String to the clipboard until the operation has succeeded.- Parameters:
mol
- the Molecule to be placed to the clipboardprops
- display properties of the Molecule, this parameter is useful when transferring Molecule images to clipboard, and can be one of, or the union of properties stored inUserSettings
, and in the result ofMDocument.getGUIPropertyContainer()
fmt
- format identifier in which the data will be represented on the clipboard. It can be null in which case the Molecule will be transferred in the default formats.- Throws:
IllegalStateException
- if the clipboard is currently unavailable, and running on the current thread.- See Also:
ImageExportUtil
-
putOLEToClipboard
public static void putOLEToClipboard(Molecule mol, Properties props)
-
putTransferableToClipboard
public static void putTransferableToClipboard(Transferable t)
A generic way to put content to clipboard.- Parameters:
t
-
-
convert
public static boolean convert(chemaxon.marvin.modules.datatransfer.TransferDataImporter converter)
Convert transfer data available on clipboard in one of the requested flavors. Converter defines what flavors it supports, steps through that list and tries to find one that is available on the clipboard.- Parameters:
converter
-- Returns:
-
removeOLESupport
public static void removeOLESupport()
Removing the support of OLE transfer format.
-
getStringFromClipboard
public static String getStringFromClipboard()
Returns the String data from the clipboard contents, if the clipboard contains a Transferable that provides support toDataFlavor.stringFlavor
- Returns:
- the String from the clipboard.
-
getObjectFromClipboard
public static Object getObjectFromClipboard() throws IOException
Returns the current content of the clipboard if the data can be imported in any of data formats supported by MolImporter. If the clipboard represents a Molecule, the returned object will be an instance of Molecule, if the clipboard represents a MacroMolecule used by MarvinSpace, then the returned object will be an instance of MacroMolecule, otherwise the function returns null.- Returns:
- the molecule represented on the clipboard, null if molecule representation cannot be found
- Throws:
IOException
-
getObjectFromClipboard
public static Object getObjectFromClipboard(String imageImportServiceURL) throws IOException
Returns the current content of the clipboard if the data can be imported in any of data formats supported by MolImporter. If the clipboard represents a Molecule, the returned object will be an instance of Molecule, if the clipboard represents a MacroMolecule used by MarvinSpace, then the returned object will be an instance of MacroMolecule, otherwise the function returns null.- Parameters:
imageImportServiceURL
- if it points to a working http based image import service url the importer will use that service when importing images from clipboard.- Returns:
- the molecule represented on the clipboard, null if molecule representation cannot be found
- Throws:
IOException
-
getClipboardContents
public static Transferable getClipboardContents()
Inits and return the transferable of the Clipboard for later import.- Returns:
- the contents of the clipboard as a
Transferable
object.
-
getObjectFromTransferable
public static Object getObjectFromTransferable(Transferable transfer) throws IOException
Returns the content of Transferable if the data can be imported in any of data formats supported by MolImporter. If the clipboard represents a Molecule, the returned object will be an instanceof Molecule, if the clipboard represents a MacroMolecule used by MarvinSpace, then the returned object will be an instanceof MacroMolecule, otherwise the function returns null.- Parameters:
transfer
- the Transferable which represents the data- Returns:
- the molecule represented in the Transferable, null if molecule representation cannot be found
- Throws:
IOException
-
getObjectFromTransferable
public static Object getObjectFromTransferable(Transferable transfer, String imageImportServiceURL) throws IOException
Returns the content of Transferable if the data can be imported in any of data formats supported by MolImporter. If the clipboard represents a Molecule, the returned object will be an instanceof Molecule, if the clipboard represents a MacroMolecule used by MarvinSpace, then the returned object will be an instanceof MacroMolecule, otherwise the function returns null.- Parameters:
transfer
- the Transferable which represents the dataimageImportServiceURL
- if it points to a working http based image import service url the importer will use that service when importing images from clipboard.- Returns:
- the molecule represented in the Transferable, null if molecule representation cannot be found
- Throws:
IOException
-
getTransferableFor
public static Transferable getTransferableFor(Molecule mol, Properties props)
Creates aMTransferable
object to the givenMolecule
with the given properties.- Parameters:
mol
- the Molecule which has to be represented by the Transferableprops
- display properties of the Molecule, this parameter will be used when transferring Molecule images to clipboard, and can be one of, or the union of properties stored inUserSettings
, and in the result ofMDocument.getGUIPropertyContainer()
- Returns:
- the Transferable created from the given data.
- See Also:
ImageExportUtil
-
getTransferableFor
public static Transferable getTransferableFor(Molecule mol, Properties props, String fmt)
Creates aMTransferable
to the givenMolecule
with the given properties in the given format.- Parameters:
mol
- the Molecule which has to be represented by the Transferableprops
- display properties of the Molecule, this parameter will be used when transferring Molecule images to clipboard, and can be one of, or the union of properties stored inUserSettings
, and in the result ofMDocument.getGUIPropertyContainer()
fmt
- format identifier in which the data will be represented on the clipboard. It can be null in which case the Molecule will be transferred in the default formats. If null is given, the default will be used.- Returns:
- the Transferable created from the given data.
- See Also:
ImageExportUtil
-
isSupportedTransferFormat
public static boolean isSupportedTransferFormat(String fmtId)
Checks whether the given format is available in the current environment or not.- Parameters:
fmtId
- the format identifier- Returns:
- true if the format is available
-
getCopyAsTransferableNames
public static List<String> getCopyAsTransferableNames()
Returns the format's names that are available in the current environment as transfer types for the Copy As dialog.- Returns:
- List
list of the the copy as dialog format's names
-
clearClipboard
public static void clearClipboard()
Clears the clipboard by creating an empty Transferable and placing it on the clipboard.
-
clearClipboardConditionally
public static void clearClipboardConditionally()
Clears the clipboard, ifisClearClipboardBeforeExport()
is true.
-
getClipboard
public static Clipboard getClipboard()
Returns the default Toolkit's system clipboard if available, otherwise returns a new singleton clipboard instance.- Returns:
- the system clipboard or a local clipboard instance.
- See Also:
Toolkit.getSystemClipboard()
-
removeTransferable
public static TransferableDescriptor removeTransferable(TransferableDescriptor d)
Removes aTransferableDescriptor
to theMTransferable
Registry.- Parameters:
d
- the descriptor.- Returns:
- the descriptor which has been removed.
-
removeTransferable
public static TransferableDescriptor removeTransferable(String name)
Removes aTransferableDescriptor
to theMTransferable
Registry by name.- Parameters:
name
- the name of the MTransferable- Returns:
- the descriptor which has been removed.
-
addTransferable
public static void addTransferable(TransferableDescriptor d)
Add aTransferableDescriptor
to theMTransferable
Registry.- Parameters:
d
- the descriptor.
-
addTransferable
@Deprecated public static void addTransferable(String name, String className, Integer priority, Integer inputPriority, boolean isdefault, boolean copyAsTransferable)
Deprecated.Add aTransferableDescriptor
to the registry, and constructing it by the given parameters.
-
addTransferable
public static void addTransferable(String name, String className, Integer priority, Integer inputPriority, boolean isdefault, boolean copyAsTransferable, boolean dndTransferable)
Add aTransferableDescriptor
to the registry, and constructing it by the given parameters.- Parameters:
name
- of the MTransferable represented by the descriptor.className
- The representing class name of the MTransferable represented by the descriptor.priority
- priority on the Copy as dialog of the MTransferable represented by the descriptor.inputPriority
- priority used when importing with the help of the MTransferable represented by the descriptor.isdefault
- decides whether the MTransferable should be used in default copy.copyAsTransferable
- decides whether the MTrasnferable should be displayed in the copy as dialog.dndTransferable
- flag to indicate whether the transferable is used when importing data from a dropped object
-
releasePermanentResources
public static void releasePermanentResources()
Releases all clipboard related native libraries and resources. Waits background workers to finish before releasing.
-
startPermanentResources
public static void startPermanentResources()
Starts all the permanent native resources that have to be started to do fast and reliable copy in Marvin.
-
-