Search in sources :

Example 1 with Depictor2D

use of com.actelion.research.chem.Depictor2D in project openchemlib by Actelion.

the class MoleculeDragAdapter method drawDragImage.

public Image drawDragImage(Transferable transferable, int width, int height) {
    if (transferable instanceof MoleculeTransferable) {
        try {
            MoleculeTransferable t = (MoleculeTransferable) transferable;
            Object o = t.getTransferData(MoleculeFlavors.DF_SERIALIZEDOBJECT);
            if (o instanceof StereoMolecule) {
                StereoMolecule mol = (StereoMolecule) o;
                Depictor2D depict = new Depictor2D(mol);
                BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
                Graphics g = img.getGraphics();
                ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
                depict.validateView(g, new Rectangle2D.Double(0, 0, width, height), AbstractDepictor.cModeInflateToMaxAVBL);
                depict.paint(g);
                return img;
            }
        } catch (IOException e1) {
            System.err.println(e1);
        } catch (UnsupportedFlavorException e1) {
            System.err.println(e1);
        }
    }
    return null;
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) Depictor2D(com.actelion.research.chem.Depictor2D) IOException(java.io.IOException) StereoMolecule(com.actelion.research.chem.StereoMolecule) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) BufferedImage(java.awt.image.BufferedImage)

Aggregations

Depictor2D (com.actelion.research.chem.Depictor2D)1 StereoMolecule (com.actelion.research.chem.StereoMolecule)1 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1 Rectangle2D (java.awt.geom.Rectangle2D)1 BufferedImage (java.awt.image.BufferedImage)1 IOException (java.io.IOException)1