Class HighlightGenerator
java.lang.Object
org.openscience.cdk.renderer.generators.HighlightGenerator
- All Implemented Interfaces:
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 the
HighlightGenerator.Palette to determine the color. The size of the highlight is
specified with the HighlightGenerator.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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classDefines the color palette used to provide the highlight colors.static classMagic number with unknown units that defines the radius around an atom, e.g. used for highlighting atoms.static interfaceDefines a color palette, the palette should provide a color the specified identifier (id). -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic HighlightGenerator.PalettecreateAutoGenPalette(boolean transparent) Create an auto generating palette which will generate colors using the provided parameters.static HighlightGenerator.PalettecreateAutoGenPalette(float saturation, float brightness, boolean transparent) Create an auto generating palette which will generate colors using the provided parameters.static HighlightGenerator.PalettecreateAutoPalette(float saturation, float brightness, int alpha) Create an auto generating palette which will generate colors using the provided parameters.static HighlightGenerator.PalettecreatePalette(Color[] colors) Create a palette which uses the provided colors.static HighlightGenerator.PalettecreatePalette(Color color, Color... colors) Create a palette which uses the provided colors.generate(IAtomContainer container, RendererModel model) Converts aIChemObjectfrom the chemical data model into something that can be drawn in the chemical drawing.Returns the list ofIGeneratorParameterfor this particular generator.
-
Field Details
-
ID_MAP
-
-
Constructor Details
-
HighlightGenerator
public HighlightGenerator()
-
-
Method Details
-
generate
Converts aIChemObjectfrom the chemical data model into something that can be drawn in the chemical drawing.- Specified by:
generatein interfaceIGenerator<IAtomContainer>- Parameters:
container- the chemical entity to be depictedmodel- the rendering parameters- Returns:
- a drawable chemical depiction component
-
getParameters
Returns the list ofIGeneratorParameterfor this particular generator.- Specified by:
getParametersin interfaceIGenerator<IAtomContainer>- Returns:
- a
ListofIGeneratorParameters
-
createPalette
Create a palette which uses the provided colors.- Parameters:
colors- colors to use in the palette- Returns:
- a palette to use in highlighting
-
createPalette
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
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
-