Author: scooter
Date: 2010-10-31 21:10:09 -0700 (Sun, 31 Oct 2010)
New Revision: 22673

Modified:
   csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/model/Compound.java
Log:
Fixed rendering problems, but still not getting good graphics export...


Modified: csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/model/Compound.java
===================================================================
--- csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/model/Compound.java        
2010-11-01 03:43:06 UTC (rev 22672)
+++ csplugins/trunk/ucsf/scooter/chemViz/src/chemViz/model/Compound.java        
2010-11-01 04:10:09 UTC (rev 22673)
@@ -39,7 +39,9 @@
 import java.awt.Font;
 import java.awt.Graphics2D;
 import java.awt.Image;
+import java.awt.geom.AffineTransform;
 import java.awt.geom.Rectangle2D;
+import java.awt.image.AffineTransformOp;
 import java.awt.image.BufferedImage;
 import java.io.IOException;
 import java.io.InputStream;
@@ -715,7 +717,7 @@
        public Image depictWithCDK(int width, int height, Color background) {
                BufferedImage bufferedImage = null;
 
-               if (iMolecule == null) {
+               if (iMolecule == null || width == 0 || height == 0) {
                        return null;
                }
 
@@ -750,9 +752,9 @@
                        model.setBondWidth(model.getBondWidth()*2);
 
                        int renderWidth = width;
-                       if (renderWidth < 150) renderWidth = 200;
+                       if (renderWidth < 200) renderWidth = 200;
                        int renderHeight = height;
-                       if (renderHeight < 150) renderHeight = 200;
+                       if (renderHeight < 200) renderHeight = 200;
                        Rectangle2D bbox = new 
Rectangle2D.Double(0,0,renderWidth,renderHeight);
 
                        bufferedImage = new BufferedImage(renderWidth, 
renderHeight, BufferedImage.TYPE_INT_ARGB);
@@ -766,10 +768,17 @@
                        renderer.paintMolecule(iMolecule, new 
AWTDrawVisitor(graphics), bbox, true);
 
                        if (renderWidth != width || renderHeight != height) {
-                               if (width < height)
-                                       return 
bufferedImage.getScaledInstance(width, width, java.awt.Image.SCALE_SMOOTH);
-                               else
-                                       return 
bufferedImage.getScaledInstance(height, height, java.awt.Image.SCALE_SMOOTH);
+                               AffineTransform tx = new AffineTransform();
+                               if (width < height) {
+                                       
tx.scale((double)width/(double)renderWidth, (double)width/(double)renderWidth);
+                                       // return 
bufferedImage.getScaledInstance(width, width, java.awt.Image.SCALE_SMOOTH);
+                               } else {
+                                       
tx.scale((double)height/(double)renderHeight, 
(double)height/(double)renderHeight);
+                                       // return 
bufferedImage.getScaledInstance(height, height, java.awt.Image.SCALE_SMOOTH);
+                               }
+
+                               AffineTransformOp op = new 
AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR);
+                               bufferedImage = op.filter(bufferedImage, null);
                        }
                } catch (Exception e) {
                        logger.warning("Unable to depict molecule with CDK 
depiction: "+e.getMessage(), e);

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to