Package org.openscience.cdk.renderer

Examples of org.openscience.cdk.renderer.Renderer2D


   * co-ordinates must already have been generated.
   * @throws Exception
   */
  public void renderMolecule(IMolecule mol, OutputStream out, boolean genCoords) throws Exception {
    Renderer2DModel r2dm = new Renderer2DModel();
    Renderer2D r2d = new Renderer2D(r2dm);
    try {
      if(mol != null) {
        if(genCoords) {
          //System.out.println("Making co-ordinates");
          mol = MultiFragmentStructureDiagramGenerator.getMoleculeWith2DCoords(mol);
        }
        GeometryToolsInternalCoordinates.translateAllPositive(mol);
        if(fixedWidthAndHeight) {
          r2dm.setBackgroundDimension(new Dimension(width, height));
          GeometryToolsInternalCoordinates.scaleMolecule(mol, r2dm.getBackgroundDimension(), occupationFactor);         
        } else {
          double [] cvals = GeometryToolsInternalCoordinates.getMinMax(mol);
          width = (int) Math.round(((cvals[2] - cvals[0]) * scaleFactor) + (fontSize*3)/2 + 3 + borderWidth * 2);
          height = (int) Math.round(((cvals[3] - cvals[1]) * scaleFactor) + fontSize/2 + 1 + borderWidth * 2);
          GeometryToolsInternalCoordinates.scaleMolecule(mol, scaleFactor);
          r2dm.setBackgroundDimension(new Dimension(width, height));
        }
        GeometryToolsInternalCoordinates.center(mol, r2dm.getBackgroundDimension());
       
        if(mol == null) throw new Exception();
      }
    } catch (Exception e) {
      mol = null;
    }
    BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
    Graphics g = img.getGraphics();
    g.setColor(backgroundColour);   
    g.fillRect(0, 0, width, height);
    r2dm.setBackColor(backgroundColour);
    r2dm.setFont(new Font(fontName, fontStyle, fontSize));
    r2dm.setColorAtomsByType(colourAtoms);
    if(mol != null) r2d.paintMolecule(mol, img.createGraphics(), true, true);
    ImageIO.write(img, format, out);   
  }
View Full Code Here

TOP

Related Classes of org.openscience.cdk.renderer.Renderer2D

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.