/* * Creates a structure PDF based on a MOL string */ public final void writeMOL2PDFFile(IMolecule molSource, File epsFile) throws Exception { // creates CDK Molecule object and get the renderer // Molecule mol = prepareMolecule(MOLString); StructureDiagramGenerator sdg = new StructureDiagramGenerator(); sdg.setMolecule(molSource); sdg.generateCoordinates(); IMolecule mol = sdg.getMolecule(); Java2DRenderer renderer = prepareRenderer(mol); try { // paint molecule to java.awt.BufferedImage VectorGraphics vg = new PDFGraphics2D(epsFile, new Dimension(vRenderSizeX, vRenderSizeY)); Properties p = new Properties(); p.setProperty("PageSize", "A5"); vg.setProperties(p); vg.startExport(); renderer.paintMolecule(mol, vg, new Rectangle(vRenderSizeX, vRenderSizeY)); vg.endExport(); } catch (Exception e) { e.printStackTrace(); throw new Exception("PDF rendering of structure(s) failed"); } }
public void paint(Graphics g) { vg[0] = VectorGraphics.create(g); vg[0].setCreator("FreeHEP JAVAGraphics2D"); Paint0s0.paint(vg); } // paint
public void paintComponent(Graphics g) { if (g != null) { VectorGraphics vg = VectorGraphics.create(g); Dimension dim = getSize(); Insets insets = getInsets(); vg.setColor(Color.white); vg.fillRect( insets.left, insets.top, dim.width - insets.left - insets.right, dim.height - insets.top - insets.bottom); int dw = dim.width / 17; int dh = dim.height / 17; vg.setColor(Color.black); fontsize = dh * 2 / 3; Font font = new Font(fontname, Font.ITALIC, fontsize); vg.setFont(font); StringBuffer character = new StringBuffer(" "); int iy = dh / 2 + dh; int ix = dw / 2 + dw; for (int i = 0; i < 16; i++) { vg.drawString( label[i], dw / 2, iy, VectorGraphics.TEXT_CENTER, VectorGraphics.TEXT_CENTER, false, Color.cyan, 2, false, Color.yellow); vg.drawString( label[i], ix, dh / 2, VectorGraphics.TEXT_CENTER, VectorGraphics.TEXT_CENTER, false, Color.cyan, 2, false, Color.yellow); iy += dh; ix += dw; } iy = dh / 2 + dh; ix = dw / 2; for (int i = (int) startString.charAt(0); i <= (int) endString.charAt(0); i++) { if (i % 16 == 0) { iy = dh / 2 + dh; ix += dw; } character.setCharAt(0, (char) i); vg.drawString( character.toString(), ix, iy, VectorGraphics.TEXT_CENTER, VectorGraphics.TEXT_CENTER, false, Color.cyan, 2, true, Color.yellow); iy += dh; } } }