~ubuntu-branches/ubuntu/trusty/cdk/trusty-proposed

« back to all changes in this revision

Viewing changes to src/org/openscience/cdk/renderer/AlphaRenderer2D.java

  • Committer: Bazaar Package Importer
  • Author(s): Paul Cager
  • Date: 2008-04-09 21:17:53 UTC
  • Revision ID: james.westby@ubuntu.com-20080409211753-46lmjw5z8mx5pd8d
Tags: upstream-1.0.2
ImportĀ upstreamĀ versionĀ 1.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Revision: 7636 $ $Author: egonw $ $Date: 2007-01-04 18:46:10 +0100 (Thu, 04 Jan 2007) $
 
2
 * 
 
3
 * Copyright (C) 2004-2007  Alexander Krassavine <akrassavine@users.sf.net>
 
4
 *
 
5
 * Contact: cdk-devel@lists.sourceforge.net
 
6
 *
 
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.
 
15
 *
 
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.
 
20
 *
 
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.
 
24
 */
 
25
package org.openscience.cdk.renderer;
 
26
 
 
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;
 
33
 
 
34
import java.awt.*;
 
35
import java.awt.geom.Area;
 
36
import java.awt.geom.Rectangle2D;
 
37
 
 
38
/**
 
39
 * A subclass of Renderer2D that uses masks (Area Class) to make an area
 
40
 * erased to background.
 
41
 *
 
42
 * @cdk.module render
 
43
 *
 
44
 * @author     akrassavine
 
45
 *
 
46
 * @cdk.created    2004-02-04
 
47
 */
 
48
public class AlphaRenderer2D extends Renderer2D implements IRenderer2D {
 
49
    
 
50
  private LoggingTool logger;
 
51
 
 
52
  private Renderer2DModel r2dm = null;
 
53
  private Area mask = null;
 
54
 
 
55
  public AlphaRenderer2D()
 
56
  {
 
57
    this(new Renderer2DModel());
 
58
  }
 
59
 
 
60
  public AlphaRenderer2D(Renderer2DModel r2dm)
 
61
  {
 
62
    super(r2dm);
 
63
    this.r2dm = r2dm;
 
64
    logger = new LoggingTool(this);
 
65
  }
 
66
 
 
67
  public void paintEmptySpace(int x, int y, int width, int height, int border, Color backColor, Graphics2D g)
 
68
  {
 
69
    int[] coords = { x - border, y + border };
 
70
    double[] bounds = { getScreenSize(width + 2 * border), getScreenSize(height + 2 * border)};
 
71
    int[] screenCoords = getScreenCoordinates(coords);
 
72
 
 
73
    mask.subtract(new Area(new Rectangle2D.Double(screenCoords[0], screenCoords[1], bounds[0], bounds[1])));
 
74
}
 
75
 
 
76
protected IRingSet getRingSet(IAtomContainer atomContainer)
 
77
{
 
78
  IRingSet ringSet = atomContainer.getBuilder().newRingSet();
 
79
  java.util.Iterator molecules = null;
 
80
 
 
81
  try
 
82
  {
 
83
    molecules = ConnectivityChecker.partitionIntoMolecules(atomContainer).molecules();
 
84
  }
 
85
 
 
86
  catch (Exception exception)
 
87
  {
 
88
    logger.warn("Could not partition molecule: ", exception.getMessage());
 
89
    logger.debug(exception);
 
90
    return ringSet;
 
91
  }
 
92
 
 
93
  while (molecules.hasNext())
 
94
  {
 
95
    SSSRFinder sssrf = new SSSRFinder((IMolecule)molecules.next());
 
96
 
 
97
    ringSet.add(sssrf.findSSSR());
 
98
  }
 
99
 
 
100
  return ringSet;
 
101
}
 
102
 
 
103
public void paintMolecule(IAtomContainer atomContainer, Graphics2D graphics)
 
104
{
 
105
  // make the initial mask cover the entire dimension we are going to paint
 
106
  mask =
 
107
    new Area(new Rectangle2D.Double(0, 0, r2dm.getBackgroundDimension().width, r2dm.getBackgroundDimension().height));
 
108
 
 
109
  if (r2dm.getPointerVectorStart() != null && r2dm.getPointerVectorEnd() != null)
 
110
  {
 
111
    paintPointerVector(graphics);
 
112
  }
 
113
 
 
114
  paintAtoms(atomContainer, graphics);
 
115
 
 
116
  Shape oldClip = graphics.getClip();
 
117
  graphics.setClip(mask);
 
118
  paintBonds(atomContainer, getRingSet(atomContainer), graphics);
 
119
  graphics.setClip(oldClip);
 
120
 
 
121
  paintLassoLines(graphics);
 
122
 
 
123
  mask = null;
 
124
}
 
125
 
 
126
}