Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
import java.awt.Color;
import javax.vecmath.Point2d;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.renderer.RendererModel;
import org.openscience.cdk.renderer.elements.ElementGroup;
import org.openscience.cdk.renderer.elements.IRenderingElement;
import org.openscience.cdk.renderer.elements.OvalElement;
import org.openscience.cdk.renderer.generators.BasicBondGenerator;
public class FancyHighlightGenerator extends BasicBondGenerator {
private Color fancyColor = Color.BLUE;
public IRenderingElement generate(IAtomContainer ac, RendererModel model) {
ElementGroup group = new ElementGroup();
IAtomContainer selection = model.getExternalSelectedPart();
if (selection == null) return group;
super.ringSet = super.getRingSet(selection);
// crude, but works
double originalWidth = model.getBondWidth();
model.setBondWidth(originalWidth * 6);
for (IBond bond : selection.bonds()) {
group.add(super.generate(bond, model));
// now do the atoms
double originalRadius = model.getAtomRadius() / model.getScale();
for (IAtom atom : selection.atoms()) {
Point2d p = atom.getPoint2d();
new OvalElement(
p.x, p.y, originalRadius * 1.5, fancyColor));
return group;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment