< prev index next >

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

Print this page

        

*** 23,32 **** --- 23,33 ---- * 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,112 **** 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); int attempts = 0; do { boolean draw = false; if (image instanceof VolatileImage) { // See if we need to recreate the image --- 103,118 ---- 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); ! ! 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,137 **** break; } } if (image == null) { // Recreate the image ! image = createImage(c, w, h, config, args); ! cache.setImage(key, config, w, h, args, image); draw = true; } if (draw) { // Render to the Image Graphics g2 = image.getGraphics(); ! paintToImage(c, image, g2, w, h, args); g2.dispose(); } // Render to the passed in Graphics paintImage(c, g, x, y, w, h, image, args); --- 126,143 ---- break; } } if (image == null) { // Recreate the 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, sw, sh, args); g2.dispose(); } // Render to the passed in Graphics paintImage(c, g, x, y, w, h, image, args);
*** 170,180 **** * @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); } /** * Creates the image to cache. This returns an opaque image, subclasses * that require translucency or transparency will need to override this --- 176,186 ---- * @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, 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 >