add text boxes through the api?

User c23c5e9da4

18-01-2007 17:03:27

Is there a way to add a text box to a molecule through the API? In addition is there a way to position it below a structure in the molecule. I'm trying to add name labels to the structures in a molecule.





Thanks,





Trevor

ChemAxon 7c2d26e5cf

21-01-2007 13:19:16

Use the MTextBox API to create a textbox that you can add to the proper MDocument object. MDocument is the container of the graphical components.


Code:
Molecule mol = ...


MDocument doc = mol.getDocument();


MTextBox textbox = new MTextBox();


textbox.setFontScale(10.0); // font scale


// textbox corners (top left and bottom right)


MPoint top = new MPoint(-6.241666793823242,7.116666793823242);


MPoint bottom = new MPoint(-1.1904667938232425,6.315866793823242);


textbox.setCorners(top,bottom);


// the text


textbox.setText("This is a text box.");


// append the textbox to the document


doc.addObject(textbox);

ChemAxon 7c2d26e5cf

22-01-2007 12:22:56

If the molecule hasn't got MDocument, you can define it by the following way:


Code:
Molecule mol = ...


MDocument doc = mol.getDocument();


if(doc == null) doc = new MDocument(mol);