Search in sources :

Example 1 with MoleculeDropAdapter

use of com.actelion.research.gui.dnd.MoleculeDropAdapter in project openchemlib by Actelion.

the class JDrawArea method initializeDragAndDrop.

private void initializeDragAndDrop(int dropAction) {
    if (dropAction != DnDConstants.ACTION_NONE) {
        MoleculeDropAdapter d = new MoleculeDropAdapter() {

            public void onDropMolecule(StereoMolecule m, Point pt) {
                if (m != null && m.getAllAtoms() != 0) {
                    for (int atom = 0; atom < mMol.getAllAtoms(); atom++) {
                        // deselect all current atoms
                        mMol.setAtomSelection(atom, false);
                    }
                    double avbl = mMol.getAverageBondLength();
                    double dropAVBL = m.getAverageBondLength();
                    m.scaleCoords(avbl / dropAVBL);
                    Point cog = new Point();
                    for (int atom = 0; atom < m.getAllAtoms(); atom++) {
                        // select all new atoms
                        m.setAtomSelection(atom, true);
                        cog.x += m.getAtomX(atom);
                        cog.y += m.getAtomY(atom);
                    }
                    cog.x /= m.getAllAtoms();
                    cog.y /= m.getAllAtoms();
                    m.translateCoords(pt.x - cog.x, pt.y - cog.y);
                    m.removeAtomColors();
                    m.removeBondHiliting();
                    mMol.addMolecule(m);
                    fireMoleculeChanged();
                    update(UPDATE_CHECK_COORDS);
                }
            }
        };
        new DropTarget(this, dropAction, d, true, new OurFlavorMap());
    }
}
Also used : MoleculeDropAdapter(com.actelion.research.gui.dnd.MoleculeDropAdapter) DropTarget(java.awt.dnd.DropTarget)

Aggregations

MoleculeDropAdapter (com.actelion.research.gui.dnd.MoleculeDropAdapter)1 DropTarget (java.awt.dnd.DropTarget)1