The classes and methods of the Molecule example represent a
molecule so that the diagram component can display it. To display a
specific molecule, you need to load the
Molecule
instance from a data source.
The following code example shows a data source that contains a
Phenol molecule. This class is a subclass of IlvDiagrammerDataSource.
public class PhenolMoleculeDataSource extends IlvDiagrammerDataSource { ...
The Read method
To load a data source into a diagram component, call its
read
method, which is shown in the following code example.
public void read(IlvDiagrammer diagrammer) throws IlvDiagrammerException { Molecule phenol = Molecule.createPhenolMolecule(); MoleculeModel model = new MoleculeModel(phenol); diagrammer.getEngine().setModel(model); }
The code lines in the
read
method are as follows:
- Create the phenol
Molecule
instance with a static method for this purpose. - Wrap the
Molecule
instance into the molecule model. - Load the new model into the diagram component.
Empty methods
The data source class has other methods
which must be implemented because they are abstract, but they do
nothing. The following code example shows these methods.
Implementation of unused abstract
methods
public void write(IlvDiagrammer diagrammer) throws IlvDiagrammerException { } protected void serializeImpl(Element element) throws IlvDiagrammerException { } protected void deserializeImpl(Element element) throws IlvDiagrammerException { }
The
write
method is not needed because the molecule data cannot be written.
The
serialize
method is not needed because there is no need to write any
additional information to define the data source in a project
file.
The
deserialize
method is not needed because there is no need to read any
additional information to load the data source from a project
file.