class ProductsBoxGenerator implements IGenerator<IReaction> {

    @Override
    public IRenderingElement generate(IReaction reaction, RendererModel model) {
        if (!model.getParameter(ShowReactionBoxes.class).getValue()) return null;
        if (reaction.getProductCount() == 0) return new ElementGroup();
        double distance = model.getParameter(BondLength.class).getValue() / model.getParameter(Scale.class).getValue()
                / 2;
        Rectangle2D totalBounds = null;
        for (IAtomContainer molecule : reaction.getProducts().atomContainers()) {
            Rectangle2D bounds = BoundsCalculator.calculateBounds(molecule);
            if (totalBounds == null) {
                totalBounds = bounds;
            } else {
                totalBounds = totalBounds.createUnion(bounds);
            }
        }
        if (totalBounds == null) return null;

        ElementGroup diagram = new ElementGroup();
        Color foregroundColor = model.getParameter(BasicSceneGenerator.ForegroundColor.class).getValue();
        diagram.add(new RectangleElement(totalBounds.getMinX() - distance, totalBounds.getMinY() - distance,
                totalBounds.getMaxX() + distance, totalBounds.getMaxY() + distance, foregroundColor));
        diagram.add(new TextElement((totalBounds.getMinX() + totalBounds.getMaxX()) / 2, totalBounds.getMinY()
                - distance, "Products", foregroundColor));
        return diagram;
    }

}