Class MarvinTransferable
- All Implemented Interfaces:
MTransferable
,Transferable
Abstract Adapter implementation of the MTransferable interface used by Marvin.
The infrastructure in Marvin is developed to transfer Molecule data to the clipboard, and Marvin has many predefined clipboard formats. If you would like to extend Marvin's clipboard features programmatically in your application with another formats, you can use this adapter to make your work a bit simpler.
The adapter introduces some new functionality, which is not part of the MTransferable interface, those methods should not be called from outside of the class hierarchy, and have been made to make the implementation of clipboard formats of marvin simpler.
The Java Transferable
interface provides support to implementors handling more
DataFlavor
s per Transferable, but in Marvin we recommend to use only one DataFlavor with
one Transferable. This is important to make the Copy As dialog easier to understand, and ensures
the possibility to add clipboard types one by one to the dialog.
Since this adapter supports only one DataFlavor, handling more DataFlavors per Transferable
requires an own MTransferable implementation.
- Since:
- Marvin 5.3 11/25/2009
-
Field Summary
Modifier and TypeFieldDescriptionprotected int
Clipboard operation type.protected DataFlavor
protected DataFlavor
The DataFlavor represented by the implementation.protected String
The format string.protected Molecule
TheMolecule
which will be transferred to the clipboard.protected Properties
Display properties of the Molecule.protected Transferable
TheTransferable
which represents the clipboard data.Fields inherited from interface chemaxon.marvin.modules.datatransfer.MTransferable
CLIPBOARD_OPERATION_GET, CLIPBOARD_OPERATION_PUT, CLIPBOARD_OPERATION_UNDEFINED, CLIPBOARD_ORIGIN_IS_FILE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected Object
Helper function to get Molecule or MacroMolecule from the given InputStream with MolImporter.protected abstract Object
Returns the Molecule from theTransferable
object.protected abstract Object
Returns the clipboard representation of the givenMolecule
.protected InputStream
Gets an InputStream from the clipboard data if the format is supported by this MTransferableReturns the result of the transfer operation.Returns the DataFlavors supported by the actual implementation.boolean
Checks whether theflavor
equals with the given parameter.boolean
Checks that the implementation supports input from clipboard.void
Registers the Native names supported by the implementation.void
setMolecule
(Molecule mol) Sets the Molecule which will be represented by the MTransferable.void
setProperties
(Properties props) Sets display properties of the Molecule.void
setTransfer
(Transferable transfer) Sets the Transferable which contains the Molecule that should be retrieved.toString()
-
Field Details
-
flavor
The DataFlavor represented by the implementation. -
format
The format string. This will be applied to MolExporter while generating output to clipboard. -
clipboardOperation
protected int clipboardOperationClipboard operation type. Determines if the Transferable is putting data to Clipboard or is gathering data from there. This variable is used bygetTransferData(DataFlavor)
to determine what to do and handled internally fromsetMolecule(Molecule)
and fromsetTransfer(Transferable)
functions. -
molecule
TheMolecule
which will be transferred to the clipboard. The system will call thegetTransferData(DataFlavor)
- as defined in the java documentation - to gather the data for the Clipboard. -
properties
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()
- See Also:
-
transfer
TheTransferable
which represents the clipboard data. From this object a Molecule should be retrieved and returned as object in thegetTransferData(DataFlavor)
method. -
extraFlavor
-
-
Constructor Details
-
MarvinTransferable
public MarvinTransferable()
-
-
Method Details
-
getTransferData
Returns the result of the transfer operation. The function returns data in a format which could be placed into the clipboard or theMolecule
, which was wrapped fromtransfer
depending onclipboardOperation
The default function which is called when importing isgetDataFromClipboard(DataFlavor)
The default function which is called when exporting isgetDataToClipboard(DataFlavor)
- Specified by:
getTransferData
in interfaceTransferable
- Parameters:
flv
- theDataFlavor
of the format.- Returns:
- the object in the format determined by
clipboardOperation
if the flavor of this MTransferable is equals with the given parameter - Throws:
UnsupportedFlavorException
- if the flavor of this MTransferable does not equal with the given parameterIOException
- See Also:
-
isDataFlavorSupported
Checks whether theflavor
equals with the given parameter.- Specified by:
isDataFlavorSupported
in interfaceTransferable
- Parameters:
flv
- the DataFlavor which should be checked- Returns:
- true, if the DataFlavor of the MTransferable equals with the given parameter, false otherwise.
-
getDataToClipboard
Returns the clipboard representation of the givenMolecule
. The Object has to be an instance of the representationClass defined by the flavor of this MTransferable- Parameters:
flv
- theDataFlavor
of the format.- Returns:
- the clipboard representation of the Molecule.
-
getDataFromClipboard
Returns the Molecule from theTransferable
object. The transferable object should be gathered from the clipboard, and set to MTransferable through thesetTransfer(Transferable)
method.- Parameters:
flv
- theDataFlavor
of the format.- Returns:
- the Molecule as an Object from the specified Transferable
- Throws:
IOException
-
getTransferDataFlavors
Returns the DataFlavors supported by the actual implementation. The returned array contains the DataFlavor corresponding to the MTransferable, and its index will be 0.- Specified by:
getTransferDataFlavors
in interfaceTransferable
- Returns:
- an array containing only the DataFlavor supported by the MTransferable.
-
registerNativeNames
public void registerNativeNames()Registers the Native names supported by the implementation. This has to be done for all native formats which are not supported by default in Java.
This function will be called from ClipboardHandler before performing the first clipboard operation. The default implementation is empty.- Specified by:
registerNativeNames
in interfaceMTransferable
-
setMolecule
Sets the Molecule which will be represented by the MTransferable. The method will setclipboardOperation
toMTransferable.CLIPBOARD_OPERATION_PUT
- Specified by:
setMolecule
in interfaceMTransferable
- Parameters:
mol
- the Molecule object which will be put to the clipboard
-
setProperties
Sets display properties of the Molecule. This properties 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()
- Specified by:
setProperties
in interfaceMTransferable
- Parameters:
props
- the Properties- See Also:
-
isInputAvailable
public boolean isInputAvailable()Checks that the implementation supports input from clipboard. The default implementation returns true.- Specified by:
isInputAvailable
in interfaceMTransferable
- Returns:
- true if the representation could read a Molecule from Clipboard false otherwise
-
setTransfer
Sets the Transferable which contains the Molecule that should be retrieved. The Transferable should be gathered from the clipboard, and the MTransferable implementation should deal with the conversion from clipboard format to Molecule if input is available. Before trying to set Transferable the program should check that the MTransferable implementation supports the DataFlavor of the clipboard data.
If the DataFlavor and input from clipboard is supported, after setting the clipboard data the getTransferData method should return a Molecule as an Object instance.
The default implementation set theclipboardOperation
toMTransferable.CLIPBOARD_OPERATION_GET
.- Specified by:
setTransfer
in interfaceMTransferable
- Parameters:
transfer
- The Transferable containing the Molecule- See Also:
-
createMoleculeFromInputStream
Helper function to get Molecule or MacroMolecule from the given InputStream with MolImporter. If the format variable is set to "source" or "file" then the function will call the recognizer subsystem to recognize the format, otherwise it tries to import in the format.
If PDB format recognized as the input, the MacroMolecule instance will be returned, otherwise a Molecule instance or null if the format is unrecognizable.
If copying a simple text, which contains multiple lines, but recognized as a one line format, then the function is trying to interpret the whole string without line ending characters, if copying a file (this happens while dragging a file into the canvas) the lines will be interpreted one by one, and the first will be imported.
- Parameters:
is
- the InputStream representing the Molecule- Returns:
- the imported object
-
getInputStreamFromClipboard
Gets an InputStream from the clipboard data if the format is supported by this MTransferable- Returns:
- the InputStream created from the Clipboard data
-
toString
-