Class HighlightGenerator
- java.lang.Object
-
- org.openscience.cdk.renderer.generators.HighlightGenerator
-
- All Implemented Interfaces:
IGenerator<IAtomContainer>
public final class HighlightGenerator extends Object implements IGenerator<IAtomContainer>
Generate an under/overlaid highlight in structure depictions. The highlight emphasises atoms and bonds. Each atom and bond is optionally assigned an integer identifier. Entities with identifiers are then highlighted using theHighlightGenerator.Palette
to determine the color. The size of the highlight is specified with theHighlightGenerator.HighlightRadius
parameter. Basic usage:
By default colours are automatically generated, to assign specific colors a custom// create with the highlight generator AtomContainerRenderer renderer = ...; IAtomContainer m = ...; // input molecule Map<IChemObject, Integer> ids = new HashMap<>(); // set atom/bond ids, atoms with no id will not be highlighted, numbering // starts at 0 ids.put(m.getAtom(0), 0); ids.put(m.getAtom(1), 0); ids.put(m.getAtom(2), 0); ids.put(m.getAtom(5), 2); ids.put(m.getAtom(6), 1); ids.put(m.getBond(0), 0); ids.put(m.getBond(1), 0); ids.put(m.getBond(3), 1); ids.put(m.getBond(4), 2); // attach ids to the structure m.setProperty(HighlightGenerator.ID_MAP, ids); // draw renderer.paint(m, new AWTDrawVisitor(g2), bounds, true);
HighlightGenerator.Palette
must be used. Here are some examples of setting the palette parameter in the renderer.AtomContainerRenderer renderer = ...; // opaque colors renderer.getRenderer2DModel() .set(HighlightGenerator.HighlightPalette.class, HighlightGenerator.createPalette(Color.RED, Color.BLUE, Color.GREEN)); // opaque colors (hex) renderer.getRenderer2DModel() .set(HighlightGenerator.HighlightPalette.class, HighlightGenerator.createPalette(new Color(0xff0000), Color.BLUE, Color.GREEN)); // first color is transparent renderer.getRenderer2DModel() .set(HighlightGenerator.HighlightPalette.class, HighlightGenerator.createPalette(new Color(0x88ff0000, true), Color.BLUE, Color.GREEN));
- Author:
- John May
- Source code:
- main
- Belongs to CDK module:
- renderextra
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
HighlightGenerator.HighlightPalette
Defines the color palette used to provide the highlight colors.static class
HighlightGenerator.HighlightRadius
Magic number with unknown units that defines the radius around an atom, e.g.static interface
HighlightGenerator.Palette
Defines a color palette, the palette should provide a color the specified identifier (id).
-
Constructor Summary
Constructors Constructor Description HighlightGenerator()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static HighlightGenerator.Palette
createAutoGenPalette(boolean transparent)
Create an auto generating palette which will generate colors using the provided parameters.static HighlightGenerator.Palette
createAutoGenPalette(float saturation, float brightness, boolean transparent)
Create an auto generating palette which will generate colors using the provided parameters.static HighlightGenerator.Palette
createAutoPalette(float saturation, float brightness, int alpha)
Create an auto generating palette which will generate colors using the provided parameters.static HighlightGenerator.Palette
createPalette(Color[] colors)
Create a palette which uses the provided colors.static HighlightGenerator.Palette
createPalette(Color color, Color... colors)
Create a palette which uses the provided colors.IRenderingElement
generate(IAtomContainer container, RendererModel model)
Converts aIChemObject
from the chemical data model into something that can be drawn in the chemical drawing.List<IGeneratorParameter<?>>
getParameters()
Returns the list ofIGeneratorParameter
for this particular generator.
-
-
-
Field Detail
-
ID_MAP
public static final String ID_MAP
Property key.- See Also:
- Constant Field Values
-
-
Method Detail
-
generate
public IRenderingElement generate(IAtomContainer container, RendererModel model)
Converts aIChemObject
from the chemical data model into something that can be drawn in the chemical drawing.- Specified by:
generate
in interfaceIGenerator<IAtomContainer>
- Parameters:
container
- the chemical entity to be depictedmodel
- the rendering parameters- Returns:
- a drawable chemical depiction component
-
getParameters
public List<IGeneratorParameter<?>> getParameters()
Returns the list ofIGeneratorParameter
for this particular generator.- Specified by:
getParameters
in interfaceIGenerator<IAtomContainer>
- Returns:
- a
List
ofIGeneratorParameter
s
-
createPalette
public static HighlightGenerator.Palette createPalette(Color[] colors)
Create a palette which uses the provided colors.- Parameters:
colors
- colors to use in the palette- Returns:
- a palette to use in highlighting
-
createPalette
public static HighlightGenerator.Palette createPalette(Color color, Color... colors)
Create a palette which uses the provided colors.- Parameters:
colors
- colors to use in the palette- Returns:
- a palette to use in highlighting
-
createAutoPalette
public static HighlightGenerator.Palette createAutoPalette(float saturation, float brightness, int alpha)
Create an auto generating palette which will generate colors using the provided parameters.- Parameters:
saturation
- color saturation, 0.0 < x < 1.0brightness
- color brightness, 0.0 < x < 1.0alpha
- color alpha (transparency), 0 < x < 255- Returns:
- a palette to use in highlighting
-
createAutoGenPalette
public static HighlightGenerator.Palette createAutoGenPalette(float saturation, float brightness, boolean transparent)
Create an auto generating palette which will generate colors using the provided parameters.- Parameters:
saturation
- color saturation, 0.0 < x < 1.0brightness
- color brightness, 0.0 < x < 1.0transparent
- generate transparent colors, 0 < x < 255- Returns:
- a palette to use in highlighting
-
createAutoGenPalette
public static HighlightGenerator.Palette createAutoGenPalette(boolean transparent)
Create an auto generating palette which will generate colors using the provided parameters.- Parameters:
transparent
- generate transparent colors- Returns:
- a palette to use in highlighting
-
-