Skip to content

@gilleain /gist:68111
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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.