|
Try the following code. JChemPaintViewerOnlyPanel just doesn't respond to mouse click. Any ideas?
import javax.swing.*; import org.openscience.cdk.applications.jchempaint.*; import java.awt.Dimension; import java.awt.event.*; import java.awt.BorderLayout; import org.openscience.cdk.smiles.SmilesParser; import org.openscience.cdk.Molecule; import org.openscience.cdk.ChemModel; import org.openscience.cdk.SetOfAtomContainers; import org.openscience.cdk.SetOfMolecules; import org.openscience.cdk.exception.*; import org.openscience.cdk.layout.StructureDiagramGenerator; import org.openscience.cdk.geometry.GeometryTools; import org.openscience.cdk.renderer.Renderer2DModel; import org.openscience.cdk.AtomContainer; import org.openscience.cdk.tools.manipulator.ChemModelManipulator; public class MolViewer extends JPanel { public static void main(String[] ags) { JFrame frame =new JFrame(); MolViewer ms = new MolViewer(); frame.getContentPane().add(ms); frame.pack(); frame.setVisible(true); }
public MolViewer() { setLayout(new BorderLayout()); Dimension mysize = new Dimension(250,250); JChemPaintViewerOnlyPanel ViewerOnlyPanel = new JChemPaintViewerOnlyPanel();
ViewerOnlyPanel.setPreferredSize(mysize); ViewerOnlyPanel.addMouseListener(new doubleClick()); add(ViewerOnlyPanel,BorderLayout.CENTER ); } class doubleClick extends MouseAdapter { public void mouseClicked(MouseEvent e) { if(e.getClickCount()==2) System.out.println("click ="); } } } Thanks.
Hongmei
-----Original Message-----
Hello,
You'll need to assign 2D coordinates to the molecule (through StructureDiagramGenerator). JChemPaint can't display molecule without 2D coordinates.
(well, perhaps such advice should go into JChemPaint help/tutorial, I went the same way some months ago ...)
Regards, Nina
"Sun, Hongmei*" <[EMAIL PROTECTED]> wrote:
> > > Hello, > > > > I used JChemPaintEidtorPanel like following and got error messages. Could > you help me figure out what might be wrong? > > > > > > > > import javax.swing.*; > > import org.openscience.cdk.applications.jchempaint.*; > > import java.awt.Dimension; > > import java.awt.event.*; > > import java.awt.BorderLayout; > > import org.openscience.cdk.smiles.SmilesParser; > > import org.openscience.cdk.Molecule; > > import org.openscience.cdk.ChemModel; > > import org.openscience.cdk.SetOfAtomContainers; > > import org.openscience.cdk.SetOfMolecules; > > import org.openscience.cdk.exception.*; > > public class MolSketch > > { > > public static void main(String[] ags) > > { > > MolSketch ms = new MolSketch(); > > } > > public MolSketch() > > { > > SmilesParser parser = new SmilesParser() ; > > try{ > > Molecule mol= parser.parseSmiles("c1ccccc1"); > > > > SetOfMolecules set = new SetOfMolecules(); > > set.addMolecule(mol); > > > > ChemModel chem = new ChemModel(); > > chem.setSetOfMolecules(set); > > > > model = new JChemPaintModel(chem) ; > > > > } > > catch(InvalidSmilesException ise) > > { > > System.out.println("smiles"); > > } > > JFrame frame = JChemPaintEditorPanel.getNewFrame(model); > > frame.pack(); > > frame.setVisible(true); > > > > } > > } > > > > > > The running result is it brings up greyout frame and bunch of errors > messages in the console window. (You will see it after you run this > program); > > > > Your help is highly appreciated. > > > > Thanks. > > > > Hongmei > > > > > > > > > >
|

