4
* $Date: 2007-05-01 21:15:34 +0200 (Tue, 01 May 2007) $
7
* Copyright (C) 2002-2007 The Jmol Development Team
9
* Contact: jmol-developers@lists.sf.net
11
* This program is free software; you can redistribute it and/or
12
* modify it under the terms of the GNU Lesser General Public License
13
* as published by the Free Software Foundation; either version 2.1
14
* of the License, or (at your option) any later version.
15
* All we ask is that proper credit is given for our work, which includes
16
* - but is not limited to - adding the above copyright notice to the beginning
17
* of your source code files, and to any copyright notice that you may distribute
18
* with programs based on this work.
20
* This program is distributed in the hope that it will be useful,
21
* but WITHOUT ANY WARRANTY; without even the implied warranty of
22
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
* GNU Lesser General Public License for more details.
25
* You should have received a copy of the GNU Lesser General Public License
26
* along with this program; if not, write to the Free Software
27
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
29
package org.openscience.cdk.applications.jchempaint.applet;
31
import java.awt.Canvas;
32
import java.awt.Color;
33
import java.awt.Graphics;
34
import java.awt.Graphics2D;
35
import java.util.Iterator;
37
import javax.vecmath.Point2d;
39
import org.openscience.cdk.Atom;
40
import org.openscience.cdk.interfaces.IAtomContainer;
41
import org.openscience.cdk.applications.jchempaint.JChemPaintModel;
42
import org.openscience.cdk.geometry.GeometryTools;
43
import org.openscience.cdk.renderer.Renderer2D;
44
import org.openscience.cdk.tools.manipulator.ChemModelManipulator;
47
* The canvas for a JChempaint applet
49
* @cdk.module jchempaint.applet
52
public class AppletCanvas extends Canvas
55
private static final long serialVersionUID = 5776370310193515006L;
57
private Renderer2D renderer;
58
private JChemPaintModel model;
62
* Sets the renderer attribute of the AppletCanvas object
64
*@param renderer The new renderer value
66
public void setRenderer(Renderer2D renderer)
68
this.renderer = renderer;
71
public void update(Graphics g)
78
* Sets the jChemPaintModel attribute of the AppletCanvas object
80
*@param model The new jChemPaintModel value
82
public void setJChemPaintModel(JChemPaintModel model)
87
public void paint(Graphics g)
89
renderer.getRenderer2DModel().setBackgroundDimension(getSize());
90
IAtomContainer container = null;
92
container = model.getChemModel().getBuilder().newAtomContainer();
93
Iterator containers = ChemModelManipulator.getAllAtomContainers(model.getChemModel()).iterator();
94
while (containers.hasNext()) {
95
container.add((IAtomContainer)containers.next());
99
Atom carbon = new Atom("C");
100
carbon.setHydrogenCount(4);
101
carbon.setPoint2d(new Point2d(1.0, 1.0));
102
container.addAtom(carbon);
105
* this code ensures that the molecule ends up somewhere in the model
108
GeometryTools.translateAllPositive(container,renderer.getRenderer2DModel().getRenderingCoordinates());
109
double scaleFactor = GeometryTools.getScaleFactor(container, 40.0,renderer.getRenderer2DModel().getRenderingCoordinates());
110
GeometryTools.scaleMolecule(container, scaleFactor,renderer.getRenderer2DModel().getRenderingCoordinates());
111
GeometryTools.center(container, getSize(),renderer.getRenderer2DModel().getRenderingCoordinates());
113
setBackground(Color.white);
116
renderer.paintChemModel(model.getChemModel(), (Graphics2D) g);
119
renderer.paintMolecule(container, (Graphics2D) g,false,true);