Skip to content

Commit

Permalink
Added rendering parameters for coloring the atom numbers by some sche…
Browse files Browse the repository at this point in the history
…me, e.g. by element type
  • Loading branch information
egonw committed May 19, 2012
1 parent d0f718a commit 4c8b255
Showing 1 changed file with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
import java.util.Arrays;
import java.util.List;

import javax.vecmath.Vector2d;
import javax.vecmath.Point2d;
import javax.vecmath.Vector2d;

import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.renderer.RendererModel;
import org.openscience.cdk.renderer.color.CDK2DAtomColors;
import org.openscience.cdk.renderer.color.IAtomColorer;
import org.openscience.cdk.renderer.elements.ElementGroup;
import org.openscience.cdk.renderer.elements.IRenderingElement;
import org.openscience.cdk.renderer.elements.TextElement;
Expand Down Expand Up @@ -62,6 +64,22 @@ public Boolean getDefault() {
private WillDrawAtomNumbers willDrawAtomNumbers =
new WillDrawAtomNumbers();

public static class AtomColorer extends
AbstractGeneratorParameter<IAtomColorer> {
public IAtomColorer getDefault() {
return new CDK2DAtomColors();
}
}
private IGeneratorParameter<IAtomColorer> atomColorer = new AtomColorer();

public static class ColorByType extends
AbstractGeneratorParameter<Boolean> {
public Boolean getDefault() {
return Boolean.FALSE;
}
}
private IGeneratorParameter<Boolean> colorByType = new ColorByType();

/**
* Offset vector in screen space coordinates where the atom number label
* will be placed.
Expand Down Expand Up @@ -90,10 +108,12 @@ public IRenderingElement generate(IAtomContainer ac, RendererModel model) {
Point2d p = new Point2d(atom.getPoint2d());
p.add( offset );
numbers.add(
new TextElement(
p.x, p.y, String.valueOf(number),
textColor.getValue()
)
new TextElement(
p.x, p.y, String.valueOf(number),
colorByType.getValue() ?
atomColorer.getValue().getAtomColor(atom)
: textColor.getValue()
)
);
number++;
}
Expand All @@ -104,7 +124,9 @@ public List<IGeneratorParameter<?>> getParameters() {
return Arrays.asList( new IGeneratorParameter<?>[] {
textColor,
willDrawAtomNumbers,
offset
offset,
atomColorer,
colorByType
}
);
}
Expand Down

0 comments on commit 4c8b255

Please sign in to comment.