G'day, Following on from my previous post - my before (CDK 1.0.1) and after (CDK 1.2.1) code for structure diagram rendering is given below.
One problem I have with the CDK 1.2.1 version is that for large structures the text can be unreadably small, while for small structures the text is comically large. I can't seem to find a happy medium. Comments? Thanks, Chris. ---- ***** Before (CDK 1.0.1): ***** public class MoleculeRenderer extends JPanel { //////////// // CONSTANTS //////////// /** * Dimensions of a small structure diagram. */ public static final Dimension2D STRUCTURES_DIMENSIONS_SMALL = new Dimension(150, 150); /** * Dimensions of a medium structure diagram. */ public static final Dimension STRUCTURES_DIMENSIONS_MEDIUM = new Dimension(200, 200); /** * Dimensions of a large structure diagram. */ public static final Dimension STRUCTURES_DIMENSIONS_LARGE = new Dimension(250, 250); private static final Font STRUCTURES_FONT = new Font("sanserif", Font.PLAIN, 9); private static final String STRUCTURES_MISSING_LABEL = "[no structure]"; private static final double STRUCTURES_SCALE = 0.85; private static final double BOND_WIDTH = 1.0; private static final double BOND_DISTANCE = 3.0; ///////// // FIELDS ///////// private IAtomContainer molecule; private final Renderer2D renderer; private final Renderer2DModel model; /////////////// // CONSTRUCTORS /////////////// /** * Creates a new molecule renderer. */ public MoleculeRenderer() { DVLogger.fine("Create MoleculeRenderer."); molecule = null; // initialise. // Renderer. model = new Renderer2DModel(); model.setBondDistance(BOND_DISTANCE); model.setBondWidth(BOND_WIDTH); model.setShowAromaticity(true); model.setAtomColorer(new DaylightCOWAtomColors()); renderer = new Renderer2D(model); setFont(STRUCTURES_FONT); setLayout(new BorderLayout()); } ////////// // METHODS ////////// /** * Draws the component's molecule. '[no molecule]' is displayed if * the molecule is null. * * @param g the component's graphics context. */ public void paint(final Graphics g) { super.paint(g); if (molecule != null) { // Draw structure. model.setBackgroundDimension(getSize()); final HashMap coords = model.getRenderingCoordinates(); GeometryTools.translateAllPositive(molecule, coords); GeometryTools.scaleMolecule(molecule, model.getBackgroundDimension(), STRUCTURES_SCALE, coords); GeometryTools.center(molecule, model.getBackgroundDimension(), coords); renderer.paintMolecule(molecule, (Graphics2D) g); } } ... } ***** After (CDK 1.2.1) ***** public class MoleculeRenderer extends JPanel { //////////// // CONSTANTS //////////// private static final Font STRUCTURES_FONT = new Font("sanserif", Font.PLAIN, 12); private static final String STRUCTURES_MISSING_LABEL = "[no structure]"; private static final double STRUCTURES_SCALE = 1.1; private static final double BOND_WIDTH = 1.0; private static final double BOND_DISTANCE = 3.0; ///////// // FIELDS ///////// private IAtomContainer molecule; private final Java2DRenderer renderer; private final Renderer2DModel model; /////////////// // CONSTRUCTORS /////////////// /** * Creates a new molecule renderer. */ public MoleculeRenderer() { molecule = null; // initialise. // Renderer. model = new Renderer2DModel(); model.setBondDistance(BOND_DISTANCE); model.setBondWidth(BOND_WIDTH); model.setShowAromaticity(true); model.setUseAntiAliasing(true); model.setShowExplicitHydrogens(false); model.setShowImplicitHydrogens(false); model.setAtomColorer(new DaylightCOWAtomColors()); model.setZoomFactor(STRUCTURES_SCALE); model.setFont(STRUCTURES_FONT); renderer = new Java2DRenderer(model); setLayout(new BorderLayout()); } ////////// // METHODS ////////// /** * Draws the component's molecule. '[no molecule]' is displayed if * the molecule is null. * * @param g the component's graphics context. */ public void paint(final Graphics g) { super.paint(g); if (molecule != null) { renderer.paintMolecule(molecule, (Graphics2D) g, getBounds()); } } ... } ------------------------------------------------------------------------------ Register Now & Save for Velocity, the Web Performance & Operations Conference from O'Reilly Media. Velocity features a full day of expert-led, hands-on workshops and two days of sessions from industry leaders in dedicated Performance & Operations tracks. Use code vel09scf and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf _______________________________________________ Cdk-user mailing list Cdk-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/cdk-user