1
/* $Revision: 7636 $ $Author: egonw $ $Date: 2007-01-04 18:46:10 +0100 (Thu, 04 Jan 2007) $
3
* Copyright (C) 2004-2007 Alexander Krassavine <akrassavine@users.sf.net>
5
* Contact: cdk-devel@lists.sourceforge.net
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Lesser General Public License
9
* as published by the Free Software Foundation; either version 2.1
10
* of the License, or (at your option) any later version.
11
* All we ask is that proper credit is given for our work, which includes
12
* - but is not limited to - adding the above copyright notice to the beginning
13
* of your source code files, and to any copyright notice that you may distribute
14
* with programs based on this work.
16
* This program is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU Lesser General Public License for more details.
21
* You should have received a copy of the GNU Lesser General Public License
22
* along with this program; if not, write to the Free Software
23
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
25
package org.openscience.cdk.renderer;
27
import org.openscience.cdk.graph.ConnectivityChecker;
28
import org.openscience.cdk.interfaces.IAtomContainer;
29
import org.openscience.cdk.interfaces.IMolecule;
30
import org.openscience.cdk.interfaces.IRingSet;
31
import org.openscience.cdk.ringsearch.SSSRFinder;
32
import org.openscience.cdk.tools.LoggingTool;
35
import java.awt.geom.Area;
36
import java.awt.geom.Rectangle2D;
39
* A subclass of Renderer2D that uses masks (Area Class) to make an area
40
* erased to background.
46
* @cdk.created 2004-02-04
48
public class AlphaRenderer2D extends Renderer2D implements IRenderer2D {
50
private LoggingTool logger;
52
private Renderer2DModel r2dm = null;
53
private Area mask = null;
55
public AlphaRenderer2D()
57
this(new Renderer2DModel());
60
public AlphaRenderer2D(Renderer2DModel r2dm)
64
logger = new LoggingTool(this);
67
public void paintEmptySpace(int x, int y, int width, int height, int border, Color backColor, Graphics2D g)
69
int[] coords = { x - border, y + border };
70
double[] bounds = { getScreenSize(width + 2 * border), getScreenSize(height + 2 * border)};
71
int[] screenCoords = getScreenCoordinates(coords);
73
mask.subtract(new Area(new Rectangle2D.Double(screenCoords[0], screenCoords[1], bounds[0], bounds[1])));
76
protected IRingSet getRingSet(IAtomContainer atomContainer)
78
IRingSet ringSet = atomContainer.getBuilder().newRingSet();
79
java.util.Iterator molecules = null;
83
molecules = ConnectivityChecker.partitionIntoMolecules(atomContainer).molecules();
86
catch (Exception exception)
88
logger.warn("Could not partition molecule: ", exception.getMessage());
89
logger.debug(exception);
93
while (molecules.hasNext())
95
SSSRFinder sssrf = new SSSRFinder((IMolecule)molecules.next());
97
ringSet.add(sssrf.findSSSR());
103
public void paintMolecule(IAtomContainer atomContainer, Graphics2D graphics)
105
// make the initial mask cover the entire dimension we are going to paint
107
new Area(new Rectangle2D.Double(0, 0, r2dm.getBackgroundDimension().width, r2dm.getBackgroundDimension().height));
109
if (r2dm.getPointerVectorStart() != null && r2dm.getPointerVectorEnd() != null)
111
paintPointerVector(graphics);
114
paintAtoms(atomContainer, graphics);
116
Shape oldClip = graphics.getClip();
117
graphics.setClip(mask);
118
paintBonds(atomContainer, getRingSet(atomContainer), graphics);
119
graphics.setClip(oldClip);
121
paintLassoLines(graphics);