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;
}
Aggregations