Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View gist:68111
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
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);
super.setOverrideColor(fancyColor);
for (IBond bond : selection.bonds()) {
group.add(super.generate(bond, model));
}
super.setOverrideColor(null);
model.setBondWidth(originalWidth);
// now do the atoms
double originalRadius = model.getAtomRadius() / model.getScale();
for (IAtom atom : selection.atoms()) {
Point2d p = atom.getPoint2d();
group.add(
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
Something went wrong with that request. Please try again.