public void actionPerformed(ActionEvent e) {
logger.info(" type ", type);
logger.debug(" source ", e.getSource());
JChemPaintRendererModel renderModel = jcpPanel.get2DHub().getRenderer().getRenderer2DModel();
IChemModel chemModel = jcpPanel.getChemModel();
Clipboard sysClip = jcpPanel.getToolkit().getSystemClipboard();
if ("copy".equals(type)) {
handleSystemClipboard(sysClip);
IAtom atomInRange = null;
IChemObject object = getSource(e);
logger.debug("Source of call: ", object);
if (object instanceof IAtom) {
atomInRange = (IAtom) object;
} else {
atomInRange = renderModel.getHighlightedAtom();
}
if (atomInRange != null) {
IAtomContainer tocopyclone =
atomInRange.getBuilder().newInstance(IAtomContainer.class);
try {
tocopyclone.addAtom((IAtom) atomInRange.clone());
} catch (CloneNotSupportedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
addToClipboard(sysClip, tocopyclone);
}
else if(renderModel.getHighlightedBond()!=null){
IBond bond = renderModel.getHighlightedBond();
if (bond != null) {
IAtomContainer tocopyclone =
bond.getBuilder().newInstance(IAtomContainer.class);
try {
tocopyclone.addAtom((IAtom) bond.getAtom(0).clone());
tocopyclone.addAtom((IAtom) bond.getAtom(1).clone());
} catch (CloneNotSupportedException e1) {
e1.printStackTrace();
}
tocopyclone.addBond(bond.getBuilder().newInstance(IBond.class,tocopyclone.getAtom(0), tocopyclone.getAtom(1), bond.getOrder()));
addToClipboard(sysClip, tocopyclone);
}
}else if(renderModel.getSelection().getConnectedAtomContainer()!=null){
addToClipboard(sysClip,
renderModel.getSelection().getConnectedAtomContainer());
}else{
addToClipboard(sysClip, JChemPaintPanel.getAllAtomContainersInOne(chemModel));
}
} else if ("copyAsSmiles".equals(type)) {
handleSystemClipboard(sysClip);
try {
final IAtomContainer selection = renderModel.getSelection().getConnectedAtomContainer();
if(selection!=null){
final IChemObjectBuilder bldr = selection.getBuilder();
IChemModel selectionModel = bldr.newInstance(IChemModel.class);
selectionModel.setMoleculeSet(bldr.newInstance(IAtomContainerSet.class));
selectionModel.getMoleculeSet().addAtomContainer(selection);
sysClip.setContents(new SmilesSelection(CreateSmilesAction.getSmiles(selectionModel)), null);
}else{
sysClip.setContents(new SmilesSelection(CreateSmilesAction.getSmiles(chemModel)),null);
}
} catch (Exception e1) {