StandardAtomGenerator { AtomSymbol generatePeriodicSymbol(final int number, final int hydrogens, int mass, final int charge, final int unpaired, HydrogenPosition position, RendererModel opts) { Font myfont = font; final String label; switch (number) { case 0: label = "*"; myfont = font.deriveFont(Font.BOLD); break; case 1: if (mass == 2 && opts.get(DeuteriumSymbol.class)) { label = "D"; mass = 0; } else { label = Elements.ofNumber(number).symbol(); } break; default: label = Elements.ofNumber(number).symbol(); break; } TextOutline element = new TextOutline(label, myfont); TextOutline hydrogenAdjunct = defaultHydrogenLabel; TextOutline hydrogenCount = new TextOutline(Integer.toString(hydrogens), font).resize(scriptSize, scriptSize); TextOutline chargeAdjunct = new TextOutline(chargeAdjunctText(charge, unpaired), font).resize(scriptSize, scriptSize); TextOutline massAdjunct = new TextOutline(Integer.toString(mass), font).resize(scriptSize, scriptSize); hydrogenAdjunct = positionHydrogenLabel(position, element, hydrogenAdjunct); hydrogenCount = positionSubscript(hydrogenAdjunct, hydrogenCount); chargeAdjunct = positionChargeLabel(hydrogens, position, chargeAdjunct, element, hydrogenAdjunct); massAdjunct = positionMassLabel(massAdjunct, element); if (position == Left) { final double nudgeX = hydrogenXDodge(hydrogens, mass, element, hydrogenAdjunct, hydrogenCount, massAdjunct); hydrogenAdjunct = hydrogenAdjunct.translate(nudgeX, 0); hydrogenCount = hydrogenCount.translate(nudgeX, 0); chargeAdjunct = chargeAdjunct.translate(nudgeX, 0); } final List<TextOutline> adjuncts = new ArrayList<TextOutline>(4); if (hydrogens > 0) adjuncts.add(hydrogenAdjunct); if (hydrogens > 1) adjuncts.add(hydrogenCount); if (charge != 0 || unpaired > 0) adjuncts.add(chargeAdjunct); if (mass > 0) adjuncts.add(massAdjunct); return new AtomSymbol(element, adjuncts); } StandardAtomGenerator(Font font); private  StandardAtomGenerator(Font font, double adjunctSpacing, double scriptSize);   }
@Test public void generateWithNoAdjuncts() { AtomSymbol symbol = atomGenerator.generatePeriodicSymbol(7, 0, -1, 0, 0, HydrogenPosition.Right, null); assertThat(symbol.getOutlines().size(), is(1)); }
@Test public void generateWithHydrogenAdjunct() { AtomSymbol symbol = atomGenerator.generatePeriodicSymbol(7, 1, -1, 0, 0, HydrogenPosition.Right, null); assertThat(symbol.getOutlines().size(), is(2)); }
@Test public void generateWithHydrogenAndCountAdjunct() { AtomSymbol symbol = atomGenerator.generatePeriodicSymbol(7, 2, -1, 0, 0, HydrogenPosition.Right, null); assertThat(symbol.getOutlines().size(), is(3)); }
@Test public void generateWithMassAdjunct() { AtomSymbol symbol = atomGenerator.generatePeriodicSymbol(7, 0, 15, 0, 0, HydrogenPosition.Right, null); assertThat(symbol.getOutlines().size(), is(2)); }
@Test public void generateWithChargeAdjunct() { AtomSymbol symbol = atomGenerator.generatePeriodicSymbol(7, 0, -1, 1, 0, HydrogenPosition.Right, null); assertThat(symbol.getOutlines().size(), is(2)); }
@Test public void generateWithRadicalAdjunct() { AtomSymbol symbol = atomGenerator.generatePeriodicSymbol(7, 0, -1, 0, 1, HydrogenPosition.Right, null); assertThat(symbol.getOutlines().size(), is(2)); }
@Test public void hydrogenDodgesMassLabel() { AtomSymbol symbol = atomGenerator.generatePeriodicSymbol(7, 1, 15, 0, 0, HydrogenPosition.Left, null); List<Shape> outlines = symbol.getOutlines(); assertThat(outlines.size(), is(3)); Shape hydrogenShape = outlines.get(1); Shape massShape = outlines.get(2); assertThat(hydrogenShape.getBounds2D().getMaxX(), lessThan(massShape.getBounds2D().getMinX())); }
@Test public void hydrogenAndHydrogenCountDodgesMassLabel() { AtomSymbol symbol = atomGenerator.generatePeriodicSymbol(7, 2, 15, 0, 0, HydrogenPosition.Left, null); List<Shape> outlines = symbol.getOutlines(); assertThat(outlines.size(), is(4)); Shape hydrogenShape = outlines.get(1); Shape hydrogenCountShape = outlines.get(2); Shape massShape = outlines.get(3); assertThat(hydrogenShape.getBounds2D().getMaxX(), lessThan(massShape.getBounds2D().getMinX())); assertThat(hydrogenCountShape.getBounds2D().getMaxX(), greaterThan(massShape.getBounds2D().getMinX())); assertThat(hydrogenCountShape.getBounds2D().getMaxX(), lessThan(massShape.getBounds2D().getMaxX())); assertThat(hydrogenShape.getBounds2D().getMaxX(), lessThan(hydrogenCountShape.getBounds2D().getMinX())); }
@Test public void hydrogenCountDodgesElement() { AtomSymbol symbol = atomGenerator.generatePeriodicSymbol(7, 2, -1, 0, 0, HydrogenPosition.Left, null); List<Shape> outlines = symbol.getOutlines(); assertThat(outlines.size(), is(3)); Shape elementShape = outlines.get(0); Shape hydrogenShape = outlines.get(1); Shape hydrogenCountShape = outlines.get(2); assertThat(hydrogenCountShape.getBounds2D().getMaxX(), lessThan(elementShape.getBounds2D().getMinX())); assertThat(hydrogenShape.getBounds2D().getMaxX(), lessThan(hydrogenCountShape.getBounds2D().getMinX())); }
@Test public void hydrogenDoesNotNeedToDodge() { AtomSymbol symbol = atomGenerator.generatePeriodicSymbol(7, 1, -1, 0, 0, HydrogenPosition.Left, null); List<Shape> outlines = symbol.getOutlines(); assertThat(outlines.size(), is(2)); Shape elementShape = outlines.get(0); Shape hydrogenShape = outlines.get(1); assertThat(hydrogenShape.getBounds2D().getMaxX(), lessThan(elementShape.getBounds2D().getMinX())); }