Skip to content

Commit

Permalink
Only draw + signs when there is more than one entity
Browse files Browse the repository at this point in the history
  • Loading branch information
egonw committed May 19, 2012
1 parent 8cae7b2 commit fe6807d
Showing 1 changed file with 31 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,32 +49,40 @@ public class ReactionPlusGenerator implements IGenerator<IReaction> {
@TestMethod("testEmptyReaction")
public IRenderingElement generate(IReaction reaction, RendererModel model) {
ElementGroup diagram = new ElementGroup();


Color color = model.getParameter(
BasicSceneGenerator.ForegroundColor.class
).getValue();
IMoleculeSet reactants = reaction.getReactants();
Rectangle2D totalBoundsReactants = BoundsCalculator.calculateBounds(reactants);
Rectangle2D bounds1 =
BoundsCalculator.calculateBounds(reactants.getAtomContainer(0));
double axis = totalBoundsReactants.getCenterY();
Color color = model.getParameter(
BasicSceneGenerator.ForegroundColor.class).getValue();
for (int i = 1; i < reaction.getReactantCount(); i++) {
Rectangle2D bounds2 =
BoundsCalculator.calculateBounds(reactants.getAtomContainer(i));
diagram.add(makePlus(bounds1, bounds2, axis, color));
bounds1 = bounds2;
}

// only draw + signs when there are more than one reactant
if (reactants.getAtomContainerCount() > 1) {
Rectangle2D totalBoundsReactants = BoundsCalculator.calculateBounds(reactants);
Rectangle2D bounds1 =
BoundsCalculator.calculateBounds(reactants.getAtomContainer(0));
double axis = totalBoundsReactants.getCenterY();
for (int i = 1; i < reaction.getReactantCount(); i++) {
Rectangle2D bounds2 =
BoundsCalculator.calculateBounds(reactants.getAtomContainer(i));
diagram.add(makePlus(bounds1, bounds2, axis, color));
bounds1 = bounds2;
}
}

// only draw + signs when there are more than one products
IMoleculeSet products = reaction.getProducts();
Rectangle2D totalBoundsProducts = BoundsCalculator.calculateBounds(products);
axis = totalBoundsProducts.getCenterY();
bounds1 = BoundsCalculator.calculateBounds(reactants.getAtomContainer(0));
for (int i = 1; i < reaction.getProductCount(); i++) {
Rectangle2D bounds2 =
BoundsCalculator.calculateBounds(products.getAtomContainer(i));

diagram.add(makePlus(bounds1, bounds2, axis, color));
bounds1 = bounds2;
}
if (products.getAtomContainerCount() > 1) {
Rectangle2D totalBoundsProducts = BoundsCalculator.calculateBounds(products);
double axis = totalBoundsProducts.getCenterY();
Rectangle2D bounds1 = BoundsCalculator.calculateBounds(reactants.getAtomContainer(0));
for (int i = 1; i < reaction.getProductCount(); i++) {
Rectangle2D bounds2 =
BoundsCalculator.calculateBounds(products.getAtomContainer(i));

diagram.add(makePlus(bounds1, bounds2, axis, color));
bounds1 = bounds2;
}
}
return diagram;
}

Expand Down

0 comments on commit fe6807d

Please sign in to comment.