当前位置: 首页>>代码示例>>Java>>正文


Java AWTDrawVisitor类代码示例

本文整理汇总了Java中org.openscience.cdk.renderer.visitor.AWTDrawVisitor的典型用法代码示例。如果您正苦于以下问题:Java AWTDrawVisitor类的具体用法?Java AWTDrawVisitor怎么用?Java AWTDrawVisitor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


AWTDrawVisitor类属于org.openscience.cdk.renderer.visitor包,在下文中一共展示了AWTDrawVisitor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: generateImage

import org.openscience.cdk.renderer.visitor.AWTDrawVisitor; //导入依赖的package包/类
/**
 * draw image and return it as RenderedImage
 * 
 * @param structure
 * @return
 * @throws CDKException
 */
public RenderedImage generateImage(final IAtomContainer structure) {
	Image image = new BufferedImage(this.imageWidth, this.imageHeight, BufferedImage.TYPE_INT_ARGB);
	Graphics2D g2 = (Graphics2D) image.getGraphics();
	g2.setColor(new Color(1.0f, 1.0f, 1.0f, 0.0f));
	g2.fillRect(0, 0, this.imageWidth, this.imageHeight);
	try {
		IAtomContainer moleculeToDraw = AtomContainerManipulator.removeHydrogens(structure);

		Rectangle drawArea = new Rectangle(this.imageWidth, this.imageHeight);

		AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(moleculeToDraw);
		for(int i = 0; i < moleculeToDraw.getAtomCount(); i++) 
			moleculeToDraw.getAtom(i).setProperty(StandardGenerator.ANNOTATION_LABEL, i + "");
		for(int i = 0; i < moleculeToDraw.getBondCount(); i++) 
			moleculeToDraw.getBond(i).setProperty(StandardGenerator.ANNOTATION_LABEL, i + "");
		
		StructureDiagramGenerator sdg = new StructureDiagramGenerator();
           sdg.setMolecule(moleculeToDraw);
           sdg.generateCoordinates();
		this.renderer.setup(sdg.getMolecule(), drawArea);
		RendererModel rendererModel = this.renderer.getRenderer2DModel();
		rendererModel.set(StandardGenerator.Visibility.class, SymbolVisibility.iupacRecommendations());
   		rendererModel.set(StandardGenerator.AtomColor.class, new CDK2DAtomColors()); 
   		rendererModel.set(StandardGenerator.AnnotationColor.class, new Color(0x455FFF));
   		rendererModel.set(StandardGenerator.StrokeRatio.class, this.strokeRatio);
		Rectangle2D bounds = new Rectangle2D.Double(0, 0, this.imageWidth, this.imageHeight);
		
		this.renderer.paint(sdg.getMolecule(), new AWTDrawVisitor(g2), bounds, true);

	} catch (Exception e) {
		return (RenderedImage) image;
	}
	return (RenderedImage) image;
}
 
开发者ID:c-ruttkies,项目名称:MetFragRelaunched,代码行数:42,代码来源:AnnotatedStandardSingleStructureImageGenerator.java

示例2: generateImage

import org.openscience.cdk.renderer.visitor.AWTDrawVisitor; //导入依赖的package包/类
/**
 * draw image and return it as RenderedImage
 * 
 * @param structure
 * @return
 * @throws CDKException
 */
public RenderedImage generateImage(final IAtomContainer structure) {
	Image image = new BufferedImage(this.imageWidth, this.imageHeight, BufferedImage.TYPE_INT_ARGB);
	Graphics2D g2 = (Graphics2D) image.getGraphics();
	g2.setColor(this.backgroundColor);
	g2.fillRect(0, 0, this.imageWidth, this.imageHeight);
	try {
		IAtomContainer moleculeToDraw = AtomContainerManipulator.removeHydrogens(structure);

		Rectangle drawArea = new Rectangle(this.imageWidth, this.imageHeight);

		AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(moleculeToDraw);
		StructureDiagramGenerator sdg = new StructureDiagramGenerator();
           sdg.setMolecule(moleculeToDraw);
           sdg.generateCoordinates();
		this.renderer.setup(sdg.getMolecule(), drawArea);
		RendererModel rendererModel = this.renderer.getRenderer2DModel();
		rendererModel.set(StandardGenerator.Visibility.class, SymbolVisibility.iupacRecommendations());
   		rendererModel.set(StandardGenerator.AtomColor.class, new CDK2DAtomColors());
   		rendererModel.set(StandardGenerator.StrokeRatio.class, this.strokeRatio);
		Rectangle2D bounds = new Rectangle2D.Double(0, 0, this.imageWidth, this.imageHeight);
		
		this.renderer.paint(sdg.getMolecule(), new AWTDrawVisitor(g2), bounds, true);

	} catch (Exception e) {
		return (RenderedImage) image;
	}
	return (RenderedImage) image;
}
 
开发者ID:c-ruttkies,项目名称:MetFragRelaunched,代码行数:36,代码来源:StandardSingleStructureImageGenerator.java

示例3: paintComponent

import org.openscience.cdk.renderer.visitor.AWTDrawVisitor; //导入依赖的package包/类
@Override
   protected void paintComponent(Graphics g) {

Graphics2D g2 = (Graphics2D) g;
g2.setColor(Color.WHITE);
g2.fillRect(0, 0, getWidth(), getHeight());

final Rectangle drawArea = new Rectangle(getWidth(), getHeight());
renderer.setup(molecule, drawArea);
renderer.paint(molecule, new AWTDrawVisitor(g2), drawArea, true);
   }
 
开发者ID:mzmine,项目名称:mzmine2,代码行数:12,代码来源:Structure2DComponent.java

示例4: toBufferedImage

import org.openscience.cdk.renderer.visitor.AWTDrawVisitor; //导入依赖的package包/类
BufferedImage toBufferedImage(double width, double height) {
    BufferedImage img = new BufferedImage((int) (margin + width + margin),
                                          (int) (margin + height + margin),
                                          BufferedImage.TYPE_3BYTE_BGR);
    Graphics2D g2 = img.createGraphics();
    g2.setBackground(parameters.get(BasicSceneGenerator.BackgroundColor.class));
    g2.clearRect(0, 0, img.getWidth(), img.getHeight());
    draw(new AWTDrawVisitor(g2),
         new Rectangle2D.Double(margin, margin, width, height));
    g2.dispose();
    return img;
}
 
开发者ID:johnmay,项目名称:efficient-bits,代码行数:13,代码来源:AbstractDepiction.java

示例5: toPdf

import org.openscience.cdk.renderer.visitor.AWTDrawVisitor; //导入依赖的package包/类
String toPdf(double width, double height, double margin) {
    Graphics2D g2 = new PDFGraphics2D(0, 0,
                                      margin + width + margin,
                                      margin + height + margin);
    draw(AWTDrawVisitor.forVectorGraphics(g2),
         new Rectangle2D.Double(margin, margin, width, height));
    g2.dispose();
    return g2.toString();
}
 
开发者ID:johnmay,项目名称:efficient-bits,代码行数:10,代码来源:AbstractDepiction.java

示例6: toSvg

import org.openscience.cdk.renderer.visitor.AWTDrawVisitor; //导入依赖的package包/类
String toSvg(double width, double height, double margin) {
    Graphics2D g2 = new SVGGraphics2D(0, 0,
                                      margin + width + margin,
                                      margin + height + margin);
    draw(AWTDrawVisitor.forVectorGraphics(g2),
         new Rectangle2D.Double(margin, margin, width, height));
    g2.dispose();
    return g2.toString();
}
 
开发者ID:johnmay,项目名称:efficient-bits,代码行数:10,代码来源:AbstractDepiction.java

示例7: testSVGRenderer

import org.openscience.cdk.renderer.visitor.AWTDrawVisitor; //导入依赖的package包/类
@Test
public void testSVGRenderer() throws IOException {
	int width = 200;
	int height = 200;

	Rectangle drawArea = new Rectangle(width, height);
	Image image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

	IAtomContainer triazole = MoleculeFactory.make123Triazole();
	StructureDiagramGenerator sdg = new StructureDiagramGenerator();
	sdg.setMolecule(triazole);
	try {
		sdg.generateCoordinates();
	} catch (Exception e) {
	}
	triazole = sdg.getMolecule();

	List<IGenerator<IAtomContainer>> generators = new ArrayList<IGenerator<IAtomContainer>>();
	generators.add(new BasicSceneGenerator());
	generators.add(new BasicBondGenerator());
	generators.add(new BasicAtomGenerator());

	AtomContainerRenderer renderer = new AtomContainerRenderer(generators, new AWTFontManager());

	renderer.setup(triazole, drawArea);

	Graphics2D g2 = (Graphics2D) image.getGraphics();
	
	SVGRenderer svgR = new SVGRenderer(g2);
	
	renderer.paint(triazole, new AWTDrawVisitor(svgR));
	
	SVGUtil.debug(svgR.getSVG(), new FileOutputStream(getClass().getResource("/uk/ac/cam/ch/ucc/svggraphics2d/").getFile() + "testOutputTriazole.svg"), 0);
	
	Assert.assertEquals("Test for number of SVG elements", 13, svgR.getSVG().getChildCount());
}
 
开发者ID:AndyHowlettGitHub,项目名称:SVGGraphics2D,代码行数:37,代码来源:SVGRendererTest.java

示例8: draw

import org.openscience.cdk.renderer.visitor.AWTDrawVisitor; //导入依赖的package包/类
public static void draw(IAtomContainer mol, String imageName){
	int WIDTH = 500;
    int HEIGHT = 500;
    
    // the draw area and the image should be the same size
    Rectangle drawArea = new Rectangle(WIDTH, HEIGHT);
    Image image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
    
    
    // generators make the image elements
    List<IGenerator<IAtomContainer>> generators = new ArrayList<IGenerator<IAtomContainer>>();
    generators.add(new BasicSceneGenerator());
    generators.add(new BasicBondGenerator());
    generators.add(new BasicAtomGenerator());
    
    // the renderer needs to have a toolkit-specific font manager 
    AtomContainerRenderer renderer = new AtomContainerRenderer(generators, new AWTFontManager());
    
    // the call to 'setup' only needs to be done on the first paint
    renderer.setup(mol, drawArea);
    
    // paint the background
    Graphics2D g2 = (Graphics2D)image.getGraphics();
    g2.setColor(Color.WHITE);
    g2.fillRect(0, 0, WIDTH, HEIGHT);
    
    
  IDrawVisitor drawVisitor = new AWTDrawVisitor(g2);
    
    // the paint method also needs a toolkit-specific renderer
    renderer.paint(mol, drawVisitor);
    try {
		ImageIO.write((RenderedImage)image, "PNG", new File(imageName+".png"));
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

}
 
开发者ID:ndaniels,项目名称:Ammolite,代码行数:40,代码来源:MolDrawer.java

示例9: renderMolecule

import org.openscience.cdk.renderer.visitor.AWTDrawVisitor; //导入依赖的package包/类
public Image renderMolecule(IMolecule molecule)
{
    // the draw area and the image should be the same size
    Rectangle drawArea = new Rectangle(width, height);
    Image image = new BufferedImage(
            width, height, BufferedImage.TYPE_INT_RGB);

    StructureDiagramGenerator sdg = new StructureDiagramGenerator();       
    sdg.setMolecule(molecule);
    try
    {
        sdg.generateCoordinates();
    }
    catch (Exception e)
    {}
    molecule = sdg.getMolecule();
    
    // generators make the image elements
    List<IAtomContainerGenerator> generators = new ArrayList<IAtomContainerGenerator>();
    generators.add(new BasicBondGenerator());
    MyAtomGenerator atomGenerator = new MyAtomGenerator(shouldShowHydrogens, shouldShowCarbons);
    generators.add(atomGenerator);

    // the renderer needs to have a toolkit-specific font manager
    Renderer renderer = new Renderer(generators, new AWTFontManager());

    // the call to 'setup' only needs to be done on the first paint
    renderer.setup(molecule, drawArea);

    // paint the background
    Graphics2D g2 = (Graphics2D)image.getGraphics();
    g2.setColor(Color.WHITE);
    g2.fillRect(0, 0, width, height);

    // the paint method also needs a toolkit-specific renderer

    renderer.paintMolecule(molecule, new AWTDrawVisitor(g2), new Rectangle(0, 0, width, height), false);
    return image;
}
 
开发者ID:dhmay,项目名称:msInspect,代码行数:40,代码来源:MoleculeRenderer2D.java

示例10: generateImage

import org.openscience.cdk.renderer.visitor.AWTDrawVisitor; //导入依赖的package包/类
public RenderedImage generateImage(final DefaultBitArrayFragment structure) {
	Image image = new BufferedImage(this.imageWidth, this.imageHeight, BufferedImage.TYPE_INT_ARGB);
	try {
		IAtomContainer molecule = new AtomContainer(structure.getPrecursor().getStructureAsIAtomContainer());
		StructureDiagramGenerator sdg = new StructureDiagramGenerator();
		sdg.setMolecule(molecule);
		sdg.generateCoordinates();

		Rectangle drawArea = new Rectangle(this.imageWidth, this.imageHeight);

		IAtomContainer moleculeToDraw = sdg.getMolecule();
		this.renderer.setup(sdg.getMolecule(), drawArea);

		RendererModel rendererModel = this.renderer.getRenderer2DModel();
		//rendererModel.set(StandardGenerator.Visibility.class, SelectionVisibility.iupacRecommendations());
		//rendererModel.set(StandardGenerator.AtomColor.class, new CDK2DAtomColors());
		rendererModel.set(StandardGenerator.Highlighting.class, StandardGenerator.HighlightStyle.OuterGlow);
   		rendererModel.set(StandardGenerator.StrokeRatio.class, this.strokeRatio);

		BitArray atoms = structure.getAtomsBitArray();
		for (int i = 0; i < atoms.getSize(); i++) {
			if(atoms.get(i)) moleculeToDraw.getAtom(i).setProperty(StandardGenerator.HIGHLIGHT_COLOR, new Color(0x98F08E));
			else moleculeToDraw.getAtom(i).removeProperty(StandardGenerator.HIGHLIGHT_COLOR);
		}

		BitArray bonds = structure.getBondsBitArray();
		for (int i = 0; i < bonds.getSize(); i++) {
			if(bonds.get(i)) moleculeToDraw.getBond(i).setProperty(StandardGenerator.HIGHLIGHT_COLOR, new Color(0x98F08E));
			else moleculeToDraw.getBond(i).removeProperty(StandardGenerator.HIGHLIGHT_COLOR);
		}

		Rectangle2D bounds = new Rectangle2D.Double(0, 0, this.imageWidth, this.imageHeight);
		
		Graphics2D g2 = (Graphics2D) image.getGraphics();
		g2.setColor(new Color(1.0f, 1.0f, 1.0f, 0.0f));
		g2.fillRect(0, 0, this.imageWidth, this.imageHeight);
		this.renderer.paint(moleculeToDraw, new AWTDrawVisitor(g2), bounds, true);
	} catch (Exception e) {
		return (RenderedImage) image;
	}
	return (RenderedImage) image;
}
 
开发者ID:c-ruttkies,项目名称:MetFragRelaunched,代码行数:43,代码来源:HighlightSubStructureImageGenerator.java

示例11: createPNG

import org.openscience.cdk.renderer.visitor.AWTDrawVisitor; //导入依赖的package包/类
/**
 * Create a PNG picture of molecule with width and height sizes
 * @param smiles SMILES of the molecule to be print
 * @param outfile Out file
 * @throws InvalidSmilesException 
 */
public void createPNG (String smiles, File outfile) throws InvalidSmilesException {
	IMolecule molecule = this.transform(smiles);
	
	// the draw area and the image should be the same size
	Rectangle drawArea = new Rectangle(0, 0, SIZE, SIZE);
	this.renderer.setup(molecule, drawArea);
	Rectangle diagramBounds = this.renderer.calculateDiagramBounds(molecule);

	int width = diagramBounds.width;
	int height = diagramBounds.height;
	int diff = Math.abs(width - height);
	int max = width > height ? width : height;
	int xshift = width > height ? 0 : diff / 2;
	int yshift = width > height ? diff / 2 : 0;
	
	// Recenter image
	this.renderer.shiftDrawCenter(
			xshift - diagramBounds.x,
			yshift - diagramBounds.y
	);
	
	Image image = new BufferedImage(
			max,
			max,
			BufferedImage.TYPE_INT_RGB
	);
	
	// Drawing options
	this.model.set(BasicAtomGenerator.KekuleStructure.class, true);
	this.model.set(BasicAtomGenerator.ColorByType.class, true);
	
	// paint the background
	Graphics2D g2 = (Graphics2D)image.getGraphics();
	g2.setColor(Color.WHITE);
	g2.fillRect(0, 0, max, max);
   
	// the paint method also needs a toolkit-specific renderer
	this.renderer.paint(molecule, new AWTDrawVisitor(g2));
   
	try {
		ImageIO.write((RenderedImage)image, "PNG", outfile);
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
开发者ID:yoann-dufresne,项目名称:Smiles2Monomers,代码行数:52,代码来源:PictureGenerator.java

示例12: createPNG

import org.openscience.cdk.renderer.visitor.AWTDrawVisitor; //导入依赖的package包/类
/**
 * Create a PNG picture of molecule with width and height sizes
 * @param molecule Molecule to be print
 * @param outfile Out file
 */
public void createPNG (IMolecule molecule, File outfile) {
	/* Warning : This part of code change IAtoms coordinates
	StructureDiagramGenerator sdg = new StructureDiagramGenerator();
	sdg.setMolecule(molecule);
	try {
		sdg.generateCoordinates();
		molecule = sdg.getMolecule();
	} catch (CDKException e1) {
		e1.printStackTrace();
	}*/
	
	// the draw area and the image should be the same size
	Rectangle drawArea = new Rectangle(0, 0, SIZE, SIZE);
	this.renderer.setup(molecule, drawArea);
	Rectangle diagramBounds = this.renderer.calculateDiagramBounds(molecule);

	int width = diagramBounds.width;
	int height = diagramBounds.height;
	int diff = Math.abs(width - height);
	int max = width > height ? width : height;
	int xshift = width > height ? 0 : diff / 2;
	int yshift = width > height ? diff / 2 : 0;
	
	// Recenter image
	this.renderer.shiftDrawCenter(
			xshift - diagramBounds.x,
			yshift - diagramBounds.y
	);
	
	Image image = new BufferedImage(
			max,
			max,
			BufferedImage.TYPE_INT_RGB
	);
	
	// Drawing options
	this.model.set(ColoredAtomGenerator.KekuleStructure.class, true);
	this.model.set(ColoredAtomGenerator.ColorByType.class, true);
	
	// paint the background
	Graphics2D g2 = (Graphics2D)image.getGraphics();
	g2.setColor(Color.WHITE);
	g2.fillRect(0, 0, max, max);
   
	// the paint method also needs a toolkit-specific renderer
	this.renderer.paint(molecule, new AWTDrawVisitor(g2));
   
	try {
		ImageIO.write((RenderedImage)image, "PNG", outfile);
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
开发者ID:yoann-dufresne,项目名称:Smiles2Monomers,代码行数:59,代码来源:AbstractPictureGenerator.java

示例13: draw

import org.openscience.cdk.renderer.visitor.AWTDrawVisitor; //导入依赖的package包/类
@Override protected void draw(AWTDrawVisitor visitor, Rectangle2D viewBounds) {
    this.draw(visitor, viewBounds, diagramBounds, primitives);
}
 
开发者ID:johnmay,项目名称:efficient-bits,代码行数:4,代码来源:Depiction.java

示例14: draw

import org.openscience.cdk.renderer.visitor.AWTDrawVisitor; //导入依赖的package包/类
@Override protected void draw(AWTDrawVisitor visitor, Rectangle2D viewBounds) {
    throw new UnsupportedOperationException();
}
 
开发者ID:johnmay,项目名称:efficient-bits,代码行数:4,代码来源:SetDepiction.java

示例15: draw

import org.openscience.cdk.renderer.visitor.AWTDrawVisitor; //导入依赖的package包/类
protected abstract void draw(AWTDrawVisitor visitor, Rectangle2D viewBounds); 
开发者ID:johnmay,项目名称:efficient-bits,代码行数:2,代码来源:AbstractDepiction.java


注:本文中的org.openscience.cdk.renderer.visitor.AWTDrawVisitor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。