< prev index next >

src/java.desktop/share/classes/sun/swing/CachedPainter.java

Print this page

        

@@ -23,10 +23,11 @@
  * questions.
  */
 package sun.swing;
 
 import java.awt.*;
+import java.awt.geom.AffineTransform;
 import java.awt.image.*;
 import java.util.*;
 
 /**
  * A base class used for icons or images that are expensive to paint.

@@ -102,11 +103,16 @@
     private void paint0(Component c, Graphics g, int x,
                          int y, int w, int h, Object... args) {
         Object key = getClass();
         GraphicsConfiguration config = getGraphicsConfiguration(c);
         ImageCache cache = getCache(key);
-        Image image = cache.getImage(key, config, w, h, args);
+        
+        AffineTransform tx = ((Graphics2D) g).getTransform();
+        int sw = tx.isIdentity() ? w : (int) Math.round(w * tx.getScaleX());
+        int sh = tx.isIdentity() ? h : (int) Math.round(h * tx.getScaleY());
+        
+        Image image = cache.getImage(key, config, sw, sh, args);
         int attempts = 0;
         do {
             boolean draw = false;
             if (image instanceof VolatileImage) {
                 // See if we need to recreate the image

@@ -120,18 +126,18 @@
                     break;
                 }
             }
             if (image == null) {
                 // Recreate the image
-                image = createImage(c, w, h, config, args);
-                cache.setImage(key, config, w, h, args, image);
+                image = createImage(c, sw, sh, config, args);
+                cache.setImage(key, config, sw, sh, args, image);
                 draw = true;
             }
             if (draw) {
                 // Render to the Image
                 Graphics g2 = image.getGraphics();
-                paintToImage(c, image, g2, w, h, args);
+                paintToImage(c, image, g2, sw, sh, args);
                 g2.dispose();
             }
 
             // Render to the passed in Graphics
             paintImage(c, g, x, y, w, h, image, args);

@@ -170,11 +176,11 @@
      * @param args Arguments supplied to <code>paint</code>
      */
     protected void paintImage(Component c, Graphics g,
                               int x, int y, int w, int h, Image image,
                               Object[] args) {
-        g.drawImage(image, x, y, null);
+        g.drawImage(image, x, y, w, h, null);
     }
 
     /**
      * Creates the image to cache.  This returns an opaque image, subclasses
      * that require translucency or transparency will need to override this
< prev index next >