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

Print this page




 165      * set to true in <code>paintDirtyRegions</code>.
 166      */
 167     private boolean painting;
 168     /**
 169      * If the PaintManager calls into repaintRoot during painting this field
 170      * will be set to the root.
 171      */
 172     private JComponent repaintRoot;
 173 
 174     /**
 175      * The Thread that has initiated painting.  If null it
 176      * indicates painting is not currently in progress.
 177      */
 178     private Thread paintThread;
 179 
 180     /**
 181      * Runnable used to process all repaint/revalidate requests.
 182      */
 183     private final ProcessingRunnable processingRunnable;
 184 
 185     private final static JavaSecurityAccess javaSecurityAccess =
 186         SharedSecrets.getJavaSecurityAccess();
 187 







 188 
 189     static {
 190         SwingAccessor.setRepaintManagerAccessor(new SwingAccessor.RepaintManagerAccessor() {
 191             @Override
 192             public void addRepaintListener(RepaintManager rm, RepaintListener l) {
 193                 rm.addRepaintListener(l);
 194             }
 195             @Override
 196             public void removeRepaintListener(RepaintManager rm, RepaintListener l) {
 197                 rm.removeRepaintListener(l);
 198             }
 199         });
 200 
 201         volatileImageBufferEnabled = "true".equals(AccessController.
 202                 doPrivileged(new GetPropertyAction(
 203                 "swing.volatileImageBufferEnabled", "true")));
 204         boolean headless = GraphicsEnvironment.isHeadless();
 205         if (volatileImageBufferEnabled && headless) {
 206             volatileImageBufferEnabled = false;
 207         }


 209                     new GetPropertyAction("awt.nativeDoubleBuffering")));
 210         String bs = AccessController.doPrivileged(
 211                           new GetPropertyAction("swing.bufferPerWindow"));
 212         if (headless) {
 213             BUFFER_STRATEGY_TYPE = BUFFER_STRATEGY_SPECIFIED_OFF;
 214         }
 215         else if (bs == null) {
 216             BUFFER_STRATEGY_TYPE = BUFFER_STRATEGY_NOT_SPECIFIED;
 217         }
 218         else if ("true".equals(bs)) {
 219             BUFFER_STRATEGY_TYPE = BUFFER_STRATEGY_SPECIFIED_ON;
 220         }
 221         else {
 222             BUFFER_STRATEGY_TYPE = BUFFER_STRATEGY_SPECIFIED_OFF;
 223         }
 224         HANDLE_TOP_LEVEL_PAINT = "true".equals(AccessController.doPrivileged(
 225                new GetPropertyAction("swing.handleTopLevelPaint", "true")));
 226         GraphicsEnvironment ge = GraphicsEnvironment.
 227                 getLocalGraphicsEnvironment();
 228         if (ge instanceof SunGraphicsEnvironment) {
 229             ((SunGraphicsEnvironment)ge).addDisplayChangedListener(
 230                     new DisplayChangedHandler());
 231         }
 232         Toolkit tk = Toolkit.getDefaultToolkit();
 233         if ((tk instanceof SunToolkit)
 234                 && ((SunToolkit) tk).isSwingBackbufferTranslucencySupported()) {
 235             volatileBufferType = Transparency.TRANSLUCENT;
 236         } else {
 237             volatileBufferType = Transparency.OPAQUE;
 238         }
 239     }
 240 
 241     /**
 242      * Return the RepaintManager for the calling thread given a Component.
 243      *
 244      * @param c a Component -- unused in the default implementation, but could
 245      *          be used by an overridden version to return a different RepaintManager
 246      *          depending on the Component
 247      * @return the RepaintManager object
 248      */
 249     public static RepaintManager currentManager(Component c) {
 250         // Note: DisplayChangedRunnable passes in null as the component, so if


1662         protected void dispose() {
1663         }
1664     }
1665 
1666 
1667     private class DoubleBufferInfo {
1668         public Image image;
1669         public Dimension size;
1670         public boolean needsReset = false;
1671     }
1672 
1673 
1674     /**
1675      * Listener installed to detect display changes. When display changes,
1676      * schedules a callback to notify all RepaintManagers of the display
1677      * changes. Only one DisplayChangedHandler is ever installed. The
1678      * singleton instance will schedule notification for all AppContexts.
1679      */
1680     private static final class DisplayChangedHandler implements
1681                                              DisplayChangedListener {






1682         public void displayChanged() {
1683             scheduleDisplayChanges();
1684         }
1685 
1686         public void paletteChanged() {
1687         }
1688 
1689         private void scheduleDisplayChanges() {
1690             // To avoid threading problems, we notify each RepaintManager
1691             // on the thread it was created on.
1692             for (Object c : AppContext.getAppContexts()) {
1693                 AppContext context = (AppContext) c;
1694                 synchronized(context) {
1695                     if (!context.isDisposed()) {
1696                         EventQueue eventQueue = (EventQueue)context.get(
1697                             AppContext.EVENT_QUEUE_KEY);
1698                         if (eventQueue != null) {
1699                             eventQueue.postEvent(new InvocationEvent(
1700                                 Toolkit.getDefaultToolkit(),
1701                                 new DisplayChangedRunnable()));
1702                         }
1703                     }
1704                 }
1705             }
1706         }
1707     }
1708 
1709 
1710     private static final class DisplayChangedRunnable implements Runnable {
1711         public void run() {
1712             RepaintManager.currentManager((JComponent)null).displayChanged();
1713         }




 165      * set to true in <code>paintDirtyRegions</code>.
 166      */
 167     private boolean painting;
 168     /**
 169      * If the PaintManager calls into repaintRoot during painting this field
 170      * will be set to the root.
 171      */
 172     private JComponent repaintRoot;
 173 
 174     /**
 175      * The Thread that has initiated painting.  If null it
 176      * indicates painting is not currently in progress.
 177      */
 178     private Thread paintThread;
 179 
 180     /**
 181      * Runnable used to process all repaint/revalidate requests.
 182      */
 183     private final ProcessingRunnable processingRunnable;
 184 
 185     private static final JavaSecurityAccess javaSecurityAccess =
 186             SharedSecrets.getJavaSecurityAccess();
 187 
 188     /**
 189      * Listener installed to detect display changes. When display changes,
 190      * schedules a callback to notify all RepaintManagers of the display
 191      * changes.
 192      */
 193     private static final DisplayChangedListener displayChangedHandler =
 194             new DisplayChangedHandler();
 195 
 196     static {
 197         SwingAccessor.setRepaintManagerAccessor(new SwingAccessor.RepaintManagerAccessor() {
 198             @Override
 199             public void addRepaintListener(RepaintManager rm, RepaintListener l) {
 200                 rm.addRepaintListener(l);
 201             }
 202             @Override
 203             public void removeRepaintListener(RepaintManager rm, RepaintListener l) {
 204                 rm.removeRepaintListener(l);
 205             }
 206         });
 207 
 208         volatileImageBufferEnabled = "true".equals(AccessController.
 209                 doPrivileged(new GetPropertyAction(
 210                 "swing.volatileImageBufferEnabled", "true")));
 211         boolean headless = GraphicsEnvironment.isHeadless();
 212         if (volatileImageBufferEnabled && headless) {
 213             volatileImageBufferEnabled = false;
 214         }


 216                     new GetPropertyAction("awt.nativeDoubleBuffering")));
 217         String bs = AccessController.doPrivileged(
 218                           new GetPropertyAction("swing.bufferPerWindow"));
 219         if (headless) {
 220             BUFFER_STRATEGY_TYPE = BUFFER_STRATEGY_SPECIFIED_OFF;
 221         }
 222         else if (bs == null) {
 223             BUFFER_STRATEGY_TYPE = BUFFER_STRATEGY_NOT_SPECIFIED;
 224         }
 225         else if ("true".equals(bs)) {
 226             BUFFER_STRATEGY_TYPE = BUFFER_STRATEGY_SPECIFIED_ON;
 227         }
 228         else {
 229             BUFFER_STRATEGY_TYPE = BUFFER_STRATEGY_SPECIFIED_OFF;
 230         }
 231         HANDLE_TOP_LEVEL_PAINT = "true".equals(AccessController.doPrivileged(
 232                new GetPropertyAction("swing.handleTopLevelPaint", "true")));
 233         GraphicsEnvironment ge = GraphicsEnvironment.
 234                 getLocalGraphicsEnvironment();
 235         if (ge instanceof SunGraphicsEnvironment) {
 236             ((SunGraphicsEnvironment) ge).addDisplayChangedListener(
 237                     displayChangedHandler);
 238         }
 239         Toolkit tk = Toolkit.getDefaultToolkit();
 240         if ((tk instanceof SunToolkit)
 241                 && ((SunToolkit) tk).isSwingBackbufferTranslucencySupported()) {
 242             volatileBufferType = Transparency.TRANSLUCENT;
 243         } else {
 244             volatileBufferType = Transparency.OPAQUE;
 245         }
 246     }
 247 
 248     /**
 249      * Return the RepaintManager for the calling thread given a Component.
 250      *
 251      * @param c a Component -- unused in the default implementation, but could
 252      *          be used by an overridden version to return a different RepaintManager
 253      *          depending on the Component
 254      * @return the RepaintManager object
 255      */
 256     public static RepaintManager currentManager(Component c) {
 257         // Note: DisplayChangedRunnable passes in null as the component, so if


1669         protected void dispose() {
1670         }
1671     }
1672 
1673 
1674     private class DoubleBufferInfo {
1675         public Image image;
1676         public Dimension size;
1677         public boolean needsReset = false;
1678     }
1679 
1680 
1681     /**
1682      * Listener installed to detect display changes. When display changes,
1683      * schedules a callback to notify all RepaintManagers of the display
1684      * changes. Only one DisplayChangedHandler is ever installed. The
1685      * singleton instance will schedule notification for all AppContexts.
1686      */
1687     private static final class DisplayChangedHandler implements
1688                                              DisplayChangedListener {
1689         // Empty non private constructor was added because access to this
1690         // class shouldn't be emulated by a synthetic accessor method.
1691         DisplayChangedHandler() {
1692             super();
1693         }
1694 
1695         public void displayChanged() {
1696             scheduleDisplayChanges();
1697         }
1698 
1699         public void paletteChanged() {
1700         }
1701 
1702         private static void scheduleDisplayChanges() {
1703             // To avoid threading problems, we notify each RepaintManager
1704             // on the thread it was created on.
1705             for (AppContext context : AppContext.getAppContexts()) {

1706                 synchronized(context) {
1707                     if (!context.isDisposed()) {
1708                         EventQueue eventQueue = (EventQueue)context.get(
1709                             AppContext.EVENT_QUEUE_KEY);
1710                         if (eventQueue != null) {
1711                             eventQueue.postEvent(new InvocationEvent(
1712                                 Toolkit.getDefaultToolkit(),
1713                                 new DisplayChangedRunnable()));
1714                         }
1715                     }
1716                 }
1717             }
1718         }
1719     }
1720 
1721 
1722     private static final class DisplayChangedRunnable implements Runnable {
1723         public void run() {
1724             RepaintManager.currentManager((JComponent)null).displayChanged();
1725         }