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