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 the HighlightGenerator.Palette to determine the color. The size of the highlight is specified with the HighlightGenerator.HighlightRadius parameter. Basic usage:

 // 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);
 
By default colours are automatically generated, to assign specific colors a custom 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
  • Field Details

  • Constructor Details

    • HighlightGenerator

      public HighlightGenerator()
  • Method Details

    • generate

      public IRenderingElement generate(IAtomContainer container, RendererModel model)
      Converts a IChemObject from the chemical data model into something that can be drawn in the chemical drawing.
      Specified by:
      generate in interface IGenerator<IAtomContainer>
      Parameters:
      container - the chemical entity to be depicted
      model - the rendering parameters
      Returns:
      a drawable chemical depiction component
    • getParameters

      public List<IGeneratorParameter<?>> getParameters()
      Returns the list of IGeneratorParameter for this particular generator.
      Specified by:
      getParameters in interface IGenerator<IAtomContainer>
      Returns:
      a List of IGeneratorParameters
    • 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.0
      brightness - color brightness, 0.0 < x < 1.0
      alpha - 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.0
      brightness - color brightness, 0.0 < x < 1.0
      transparent - 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