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

Print this page


   1 /*
   2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 384         if (delegate != null) {
 385             delegate.removeInvalidComponent(component);
 386             return;
 387         }
 388         if(invalidComponents != null) {
 389             int index = invalidComponents.indexOf(component);
 390             if(index != -1) {
 391                 invalidComponents.remove(index);
 392             }
 393         }
 394     }
 395 
 396 
 397     /**
 398      * Add a component in the list of components that should be refreshed.
 399      * If <i>c</i> already has a dirty region, the rectangle <i>(x,y,w,h)</i>
 400      * will be unioned with the region that should be redrawn.
 401      *
 402      * @see JComponent#repaint
 403      */
 404     @SuppressWarnings("deprecation")
 405     private void addDirtyRegion0(Container c, int x, int y, int w, int h) {
 406         /* Special cases we don't have to bother with.
 407          */
 408         if ((w <= 0) || (h <= 0) || (c == null)) {
 409             return;
 410         }
 411 
 412         if ((c.getWidth() <= 0) || (c.getHeight() <= 0)) {
 413             return;
 414         }
 415 
 416         if (extendDirtyRegion(c, x, y, w, h)) {
 417             // Component was already marked as dirty, region has been
 418             // extended, no need to continue.
 419             return;
 420         }
 421 
 422         /* Make sure that c and all it ancestors (up to an Applet or
 423          * Window) are visible.  This loop has the same effect as
 424          * checking c.isShowing() (and note that it's still possible
 425          * that c is completely obscured by an opaque ancestor in
 426          * the specified rectangle).
 427          */
 428         Component root = null;
 429 
 430         // Note: We can't synchronize around this, Frame.getExtendedState
 431         // is synchronized so that if we were to synchronize around this
 432         // it could lead to the possibility of getting locks out
 433         // of order and deadlocking.
 434         for (Container p = c; p != null; p = p.getParent()) {
 435             if (!p.isVisible() || (p.getPeer() == null)) {
 436                 return;
 437             }
 438             if ((p instanceof Window) || (p instanceof Applet)) {
 439                 // Iconified frames are still visible!
 440                 if (p instanceof Frame &&
 441                         (((Frame)p).getExtendedState() & Frame.ICONIFIED) ==
 442                                     Frame.ICONIFIED) {
 443                     return;
 444                 }
 445                 root = p;
 446                 break;
 447             }
 448         }
 449 
 450         if (root == null) return;
 451 
 452         synchronized(this) {
 453             if (extendDirtyRegion(c, x, y, w, h)) {
 454                 // In between last check and this check another thread
 455                 // queued up runnable, can bail here.


   1 /*
   2  * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 384         if (delegate != null) {
 385             delegate.removeInvalidComponent(component);
 386             return;
 387         }
 388         if(invalidComponents != null) {
 389             int index = invalidComponents.indexOf(component);
 390             if(index != -1) {
 391                 invalidComponents.remove(index);
 392             }
 393         }
 394     }
 395 
 396 
 397     /**
 398      * Add a component in the list of components that should be refreshed.
 399      * If <i>c</i> already has a dirty region, the rectangle <i>(x,y,w,h)</i>
 400      * will be unioned with the region that should be redrawn.
 401      *
 402      * @see JComponent#repaint
 403      */

 404     private void addDirtyRegion0(Container c, int x, int y, int w, int h) {
 405         /* Special cases we don't have to bother with.
 406          */
 407         if ((w <= 0) || (h <= 0) || (c == null)) {
 408             return;
 409         }
 410 
 411         if ((c.getWidth() <= 0) || (c.getHeight() <= 0)) {
 412             return;
 413         }
 414 
 415         if (extendDirtyRegion(c, x, y, w, h)) {
 416             // Component was already marked as dirty, region has been
 417             // extended, no need to continue.
 418             return;
 419         }
 420 
 421         /* Make sure that c and all it ancestors (up to an Applet or
 422          * Window) are visible.  This loop has the same effect as
 423          * checking c.isShowing() (and note that it's still possible
 424          * that c is completely obscured by an opaque ancestor in
 425          * the specified rectangle).
 426          */
 427         Component root = null;
 428 
 429         // Note: We can't synchronize around this, Frame.getExtendedState
 430         // is synchronized so that if we were to synchronize around this
 431         // it could lead to the possibility of getting locks out
 432         // of order and deadlocking.
 433         for (Container p = c; p != null; p = p.getParent()) {
 434             if (!p.isVisible() || !p.isDisplayable()) {
 435                 return;
 436             }
 437             if ((p instanceof Window) || (p instanceof Applet)) {
 438                 // Iconified frames are still visible!
 439                 if (p instanceof Frame &&
 440                         (((Frame)p).getExtendedState() & Frame.ICONIFIED) ==
 441                                     Frame.ICONIFIED) {
 442                     return;
 443                 }
 444                 root = p;
 445                 break;
 446             }
 447         }
 448 
 449         if (root == null) return;
 450 
 451         synchronized(this) {
 452             if (extendDirtyRegion(c, x, y, w, h)) {
 453                 // In between last check and this check another thread
 454                 // queued up runnable, can bail here.