BasicAtomGenerator implements IGenerator<IAtomContainer> { protected Color getAtomColor(IAtom atom, RendererModel model) { Color atomColor = model.get(AtomColor.class); if ((Boolean) model.get(ColorByType.class)) { atomColor = ((IAtomColorer) model.get(AtomColorer.class)).getAtomColor(atom); } return atomColor; } BasicAtomGenerator(); @Override IRenderingElement generate(IAtomContainer container, RendererModel model); IRenderingElement generate(IAtomContainer atomContainer, IAtom atom, RendererModel model); IRenderingElement generateCompactElement(IAtom atom, RendererModel model); AtomSymbolElement generateElement(IAtom atom, int alignment, RendererModel model); @Override List<IGeneratorParameter<?>> getParameters();  }
@Test public void getAtomColorTest() { Color testColor = Color.RED; IAtomContainer singleAtom = makeSingleAtom("O"); model.set(AtomColor.class, testColor); model.set(ColorByType.class, false); generator.getAtomColor(singleAtom.getAtom(0), model); List<IRenderingElement> elements = getAllSimpleElements(generator, singleAtom); Assert.assertEquals(1, elements.size()); AtomSymbolElement element = ((AtomSymbolElement) unbox(elements.get(0))); Assert.assertEquals(testColor, element.color); }
@Test public void atomColorerTest() { IAtomContainer cnop = makeSNOPSquare(); final Map<String, Color> colorMap = new HashMap<String, Color>(); colorMap.put("S", Color.YELLOW); colorMap.put("N", Color.BLUE); colorMap.put("O", Color.RED); colorMap.put("P", Color.MAGENTA); IAtomColorer atomColorer = new IAtomColorer() { @Override public Color getAtomColor(IAtom atom) { String symbol = atom.getSymbol(); if (colorMap.containsKey(symbol)) { return colorMap.get(symbol); } else { return null; } } @Override public Color getAtomColor(IAtom atom, Color defaultColor) { Color color = getAtomColor(atom); if (color == null) { return defaultColor; } else { return color; } } }; model.set(AtomColorer.class, atomColorer); List<IRenderingElement> elements = getAllSimpleElements(generator, cnop); Assert.assertEquals(4, elements.size()); for (IRenderingElement element : elements) { AtomSymbolElement symbolElement = (AtomSymbolElement) unbox(element); String symbol = symbolElement.text; Assert.assertTrue(colorMap.containsKey(symbol)); Assert.assertEquals(colorMap.get(symbol), symbolElement.color); } }