src/share/classes/javax/swing/RepaintManager.java

Print this page




 972                 return null;
 973             }
 974         }
 975 
 976         GraphicsConfiguration config = c.getGraphicsConfiguration();
 977         if (config == null) {
 978             config = GraphicsEnvironment.getLocalGraphicsEnvironment().
 979                             getDefaultScreenDevice().getDefaultConfiguration();
 980         }
 981         Dimension maxSize = getDoubleBufferMaximumSize();
 982         int width = proposedWidth < 1 ? 1 :
 983             (proposedWidth > maxSize.width? maxSize.width : proposedWidth);
 984         int height = proposedHeight < 1 ? 1 :
 985             (proposedHeight > maxSize.height? maxSize.height : proposedHeight);
 986         VolatileImage image = volatileMap.get(config);
 987         if (image == null || image.getWidth() < width ||
 988                              image.getHeight() < height) {
 989             if (image != null) {
 990                 image.flush();
 991             }




 992             image = config.createCompatibleVolatileImage(width, height);

 993             volatileMap.put(config, image);
 994         }
 995         return image;
 996     }
 997 
 998     private Image _getOffscreenBuffer(Component c, int proposedWidth, int proposedHeight) {
 999         Dimension maxSize = getDoubleBufferMaximumSize();
1000         DoubleBufferInfo doubleBuffer;
1001         int width, height;
1002 
1003         // If the window is non-opaque, it's double-buffered at peer's level
1004         Window w = (c instanceof Window) ? (Window)c : SwingUtilities.getWindowAncestor(c);
1005         if (!w.isOpaque()) {
1006             Toolkit tk = Toolkit.getDefaultToolkit();
1007             if ((tk instanceof SunToolkit) && (((SunToolkit)tk).needUpdateWindow())) {
1008                 return null;
1009             }
1010         }
1011 
1012         if (standardDoubleBuffer == null) {


1460             return false;
1461         }
1462 
1463         /**
1464          * Invoked when the doubleBuffered or useTrueDoubleBuffering
1465          * properties of a JRootPane change.  This may come in on any thread.
1466          */
1467         public void doubleBufferingChanged(JRootPane rootPane) {
1468         }
1469 
1470         /**
1471          * Paints a portion of a component to an offscreen buffer.
1472          */
1473         protected void paintDoubleBuffered(JComponent c, Image image,
1474                             Graphics g, int clipX, int clipY,
1475                             int clipW, int clipH) {
1476             Graphics osg = image.getGraphics();
1477             int bw = Math.min(clipW, image.getWidth(null));
1478             int bh = Math.min(clipH, image.getHeight(null));
1479             int x,y,maxx,maxy;



1480 
1481             try {
1482                 for(x = clipX, maxx = clipX+clipW; x < maxx ;  x += bw ) {
1483                     for(y=clipY, maxy = clipY + clipH; y < maxy ; y += bh) {
1484                         osg.translate(-x, -y);
1485                         osg.setClip(x,y,bw,bh);





1486                         c.paintToOffscreen(osg, x, y, bw, bh, maxx, maxy);
1487                         g.setClip(x, y, bw, bh);





1488                         g.drawImage(image, x, y, c);

1489                         osg.translate(x, y);
1490                     }
1491                 }
1492             } finally {
1493                 osg.dispose();
1494             }
1495         }
1496 
1497         /**
1498          * If <code>image</code> is non-null with a positive size it
1499          * is returned, otherwise null is returned.
1500          */
1501         private Image getValidImage(Image image) {
1502             if (image != null && image.getWidth(null) > 0 &&
1503                                  image.getHeight(null) > 0) {
1504                 return image;
1505             }
1506             return null;
1507         }
1508 




 972                 return null;
 973             }
 974         }
 975 
 976         GraphicsConfiguration config = c.getGraphicsConfiguration();
 977         if (config == null) {
 978             config = GraphicsEnvironment.getLocalGraphicsEnvironment().
 979                             getDefaultScreenDevice().getDefaultConfiguration();
 980         }
 981         Dimension maxSize = getDoubleBufferMaximumSize();
 982         int width = proposedWidth < 1 ? 1 :
 983             (proposedWidth > maxSize.width? maxSize.width : proposedWidth);
 984         int height = proposedHeight < 1 ? 1 :
 985             (proposedHeight > maxSize.height? maxSize.height : proposedHeight);
 986         VolatileImage image = volatileMap.get(config);
 987         if (image == null || image.getWidth() < width ||
 988                              image.getHeight() < height) {
 989             if (image != null) {
 990                 image.flush();
 991             }
 992             final Toolkit tk = Toolkit.getDefaultToolkit();
 993             if ((tk instanceof SunToolkit) && ((SunToolkit)tk).isSwingBackbufferTranslucencySupported()) {
 994                 image = config.createCompatibleVolatileImage(width, height, Transparency.TRANSLUCENT);
 995             }else {
 996                 image = config.createCompatibleVolatileImage(width, height);
 997             }
 998             volatileMap.put(config, image);
 999         }
1000         return image;
1001     }
1002 
1003     private Image _getOffscreenBuffer(Component c, int proposedWidth, int proposedHeight) {
1004         Dimension maxSize = getDoubleBufferMaximumSize();
1005         DoubleBufferInfo doubleBuffer;
1006         int width, height;
1007 
1008         // If the window is non-opaque, it's double-buffered at peer's level
1009         Window w = (c instanceof Window) ? (Window)c : SwingUtilities.getWindowAncestor(c);
1010         if (!w.isOpaque()) {
1011             Toolkit tk = Toolkit.getDefaultToolkit();
1012             if ((tk instanceof SunToolkit) && (((SunToolkit)tk).needUpdateWindow())) {
1013                 return null;
1014             }
1015         }
1016 
1017         if (standardDoubleBuffer == null) {


1465             return false;
1466         }
1467 
1468         /**
1469          * Invoked when the doubleBuffered or useTrueDoubleBuffering
1470          * properties of a JRootPane change.  This may come in on any thread.
1471          */
1472         public void doubleBufferingChanged(JRootPane rootPane) {
1473         }
1474 
1475         /**
1476          * Paints a portion of a component to an offscreen buffer.
1477          */
1478         protected void paintDoubleBuffered(JComponent c, Image image,
1479                             Graphics g, int clipX, int clipY,
1480                             int clipW, int clipH) {
1481             Graphics osg = image.getGraphics();
1482             int bw = Math.min(clipW, image.getWidth(null));
1483             int bh = Math.min(clipH, image.getHeight(null));
1484             int x,y,maxx,maxy;
1485             final Toolkit tk = Toolkit.getDefaultToolkit();
1486             final boolean isTranslucent = (tk instanceof SunToolkit)
1487                     && ((SunToolkit) tk).isSwingBackbufferTranslucencySupported();
1488 
1489             try {
1490                 for(x = clipX, maxx = clipX+clipW; x < maxx ;  x += bw ) {
1491                     for(y=clipY, maxy = clipY + clipH; y < maxy ; y += bh) {
1492                         osg.translate(-x, -y);
1493                         osg.setClip(x,y,bw,bh);
1494                         if (isTranslucent && osg instanceof Graphics2D) {
1495                             Graphics2D g2d = (Graphics2D) osg.create();
1496                             g2d.setBackground(c.getBackground());
1497                             g2d.clearRect(x, y, bw, bh);
1498                         }
1499                         c.paintToOffscreen(osg, x, y, bw, bh, maxx, maxy);
1500                         g.setClip(x, y, bw, bh);
1501                         if (isTranslucent && g instanceof Graphics2D) {
1502                             Graphics2D g2d = (Graphics2D) g.create();
1503                             g2d.setComposite(AlphaComposite.Src);
1504                             g2d.drawImage(image, x, y, c);
1505                         } else {
1506                             g.drawImage(image, x, y, c);
1507                         }
1508                         osg.translate(x, y);
1509                     }
1510                 }
1511             } finally {
1512                 osg.dispose();
1513             }
1514         }
1515 
1516         /**
1517          * If <code>image</code> is non-null with a positive size it
1518          * is returned, otherwise null is returned.
1519          */
1520         private Image getValidImage(Image image) {
1521             if (image != null && image.getWidth(null) > 0 &&
1522                                  image.getHeight(null) > 0) {
1523                 return image;
1524             }
1525             return null;
1526         }
1527