jdk/src/share/classes/java/awt/Container.java
changeset 3938 ef327bd847c0
parent 2805 9f18d7e66042
child 3972 8942e64cf57d
equal deleted inserted replaced
3934:487e1aa949c4 3938:ef327bd847c0
    44 import java.util.Arrays;
    44 import java.util.Arrays;
    45 import java.util.EventListener;
    45 import java.util.EventListener;
    46 import java.util.HashSet;
    46 import java.util.HashSet;
    47 import java.util.Set;
    47 import java.util.Set;
    48 
    48 
    49 import java.util.logging.*;
       
    50 
       
    51 import javax.accessibility.*;
    49 import javax.accessibility.*;
       
    50 
       
    51 import sun.util.logging.PlatformLogger;
    52 
    52 
    53 import sun.awt.AppContext;
    53 import sun.awt.AppContext;
    54 import sun.awt.CausedFocusEvent;
    54 import sun.awt.CausedFocusEvent;
    55 import sun.awt.PeerEvent;
    55 import sun.awt.PeerEvent;
    56 import sun.awt.SunToolkit;
    56 import sun.awt.SunToolkit;
    83  * @see       LayoutManager
    83  * @see       LayoutManager
    84  * @since     JDK1.0
    84  * @since     JDK1.0
    85  */
    85  */
    86 public class Container extends Component {
    86 public class Container extends Component {
    87 
    87 
    88     private static final Logger log = Logger.getLogger("java.awt.Container");
    88     private static final PlatformLogger log = PlatformLogger.getLogger("java.awt.Container");
    89     private static final Logger eventLog = Logger.getLogger("java.awt.event.Container");
    89     private static final PlatformLogger eventLog = PlatformLogger.getLogger("java.awt.event.Container");
    90 
    90 
    91     private static final Component[] EMPTY_ARRAY = new Component[0];
    91     private static final Component[] EMPTY_ARRAY = new Component[0];
    92 
    92 
    93     /**
    93     /**
    94      * The components in this container.
    94      * The components in this container.
   199      * all descendant containers).
   199      * all descendant containers).
   200      */
   200      */
   201     private transient int numOfHWComponents = 0;
   201     private transient int numOfHWComponents = 0;
   202     private transient int numOfLWComponents = 0;
   202     private transient int numOfLWComponents = 0;
   203 
   203 
   204     private static final Logger mixingLog = Logger.getLogger("java.awt.mixing.Container");
   204     private static final PlatformLogger mixingLog = PlatformLogger.getLogger("java.awt.mixing.Container");
   205 
   205 
   206     /**
   206     /**
   207      * @serialField ncomponents                     int
   207      * @serialField ncomponents                     int
   208      *       The number of components in this container.
   208      *       The number of components in this container.
   209      *       This value can be null.
   209      *       This value can be null.
  1285     // Should only be called while holding tree lock
  1285     // Should only be called while holding tree lock
  1286     int numListening(long mask) {
  1286     int numListening(long mask) {
  1287         int superListening = super.numListening(mask);
  1287         int superListening = super.numListening(mask);
  1288 
  1288 
  1289         if (mask == AWTEvent.HIERARCHY_EVENT_MASK) {
  1289         if (mask == AWTEvent.HIERARCHY_EVENT_MASK) {
  1290             if (eventLog.isLoggable(Level.FINE)) {
  1290             if (eventLog.isLoggable(PlatformLogger.FINE)) {
  1291                 // Verify listeningChildren is correct
  1291                 // Verify listeningChildren is correct
  1292                 int sum = 0;
  1292                 int sum = 0;
  1293                 for (Component comp : component) {
  1293                 for (Component comp : component) {
  1294                     sum += comp.numListening(mask);
  1294                     sum += comp.numListening(mask);
  1295                 }
  1295                 }
  1296                 if (listeningChildren != sum) {
  1296                 if (listeningChildren != sum) {
  1297                     eventLog.log(Level.FINE, "Assertion (listeningChildren == sum) failed");
  1297                     eventLog.fine("Assertion (listeningChildren == sum) failed");
  1298                 }
  1298                 }
  1299             }
  1299             }
  1300             return listeningChildren + superListening;
  1300             return listeningChildren + superListening;
  1301         } else if (mask == AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) {
  1301         } else if (mask == AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) {
  1302             if (eventLog.isLoggable(Level.FINE)) {
  1302             if (eventLog.isLoggable(PlatformLogger.FINE)) {
  1303                 // Verify listeningBoundsChildren is correct
  1303                 // Verify listeningBoundsChildren is correct
  1304                 int sum = 0;
  1304                 int sum = 0;
  1305                 for (Component comp : component) {
  1305                 for (Component comp : component) {
  1306                     sum += comp.numListening(mask);
  1306                     sum += comp.numListening(mask);
  1307                 }
  1307                 }
  1308                 if (listeningBoundsChildren != sum) {
  1308                 if (listeningBoundsChildren != sum) {
  1309                     eventLog.log(Level.FINE, "Assertion (listeningBoundsChildren == sum) failed");
  1309                     eventLog.fine("Assertion (listeningBoundsChildren == sum) failed");
  1310                 }
  1310                 }
  1311             }
  1311             }
  1312             return listeningBoundsChildren + superListening;
  1312             return listeningBoundsChildren + superListening;
  1313         } else {
  1313         } else {
  1314             // assert false;
  1314             // assert false;
  1315             if (eventLog.isLoggable(Level.FINE)) {
  1315             if (eventLog.isLoggable(PlatformLogger.FINE)) {
  1316                 eventLog.log(Level.FINE, "This code must never be reached");
  1316                 eventLog.fine("This code must never be reached");
  1317             }
  1317             }
  1318             return superListening;
  1318             return superListening;
  1319         }
  1319         }
  1320     }
  1320     }
  1321 
  1321 
  1322     // Should only be called while holding tree lock
  1322     // Should only be called while holding tree lock
  1323     void adjustListeningChildren(long mask, int num) {
  1323     void adjustListeningChildren(long mask, int num) {
  1324         if (eventLog.isLoggable(Level.FINE)) {
  1324         if (eventLog.isLoggable(PlatformLogger.FINE)) {
  1325             boolean toAssert = (mask == AWTEvent.HIERARCHY_EVENT_MASK ||
  1325             boolean toAssert = (mask == AWTEvent.HIERARCHY_EVENT_MASK ||
  1326                                 mask == AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK ||
  1326                                 mask == AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK ||
  1327                                 mask == (AWTEvent.HIERARCHY_EVENT_MASK |
  1327                                 mask == (AWTEvent.HIERARCHY_EVENT_MASK |
  1328                                          AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK));
  1328                                          AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK));
  1329             if (!toAssert) {
  1329             if (!toAssert) {
  1330                 eventLog.log(Level.FINE, "Assertion failed");
  1330                 eventLog.fine("Assertion failed");
  1331             }
  1331             }
  1332         }
  1332         }
  1333 
  1333 
  1334         if (num == 0)
  1334         if (num == 0)
  1335             return;
  1335             return;
  1360         }
  1360         }
  1361     }
  1361     }
  1362 
  1362 
  1363     // Should only be called while holding tree lock
  1363     // Should only be called while holding tree lock
  1364     int countHierarchyMembers() {
  1364     int countHierarchyMembers() {
  1365         if (log.isLoggable(Level.FINE)) {
  1365         if (log.isLoggable(PlatformLogger.FINE)) {
  1366             // Verify descendantsCount is correct
  1366             // Verify descendantsCount is correct
  1367             int sum = 0;
  1367             int sum = 0;
  1368             for (Component comp : component) {
  1368             for (Component comp : component) {
  1369                 sum += comp.countHierarchyMembers();
  1369                 sum += comp.countHierarchyMembers();
  1370             }
  1370             }
  1371             if (descendantsCount != sum) {
  1371             if (descendantsCount != sum) {
  1372                 log.log(Level.FINE, "Assertion (descendantsCount == sum) failed");
  1372                 log.fine("Assertion (descendantsCount == sum) failed");
  1373             }
  1373             }
  1374         }
  1374         }
  1375         return descendantsCount + 1;
  1375         return descendantsCount + 1;
  1376     }
  1376     }
  1377 
  1377 
  3922         recursiveSubtractAndApplyShape(shape, fromZorder, getBottommostComponentIndex());
  3922         recursiveSubtractAndApplyShape(shape, fromZorder, getBottommostComponentIndex());
  3923     }
  3923     }
  3924 
  3924 
  3925     final void recursiveSubtractAndApplyShape(Region shape, int fromZorder, int toZorder) {
  3925     final void recursiveSubtractAndApplyShape(Region shape, int fromZorder, int toZorder) {
  3926         checkTreeLock();
  3926         checkTreeLock();
  3927         if (mixingLog.isLoggable(Level.FINE)) {
  3927         if (mixingLog.isLoggable(PlatformLogger.FINE)) {
  3928             mixingLog.fine("this = " + this +
  3928             mixingLog.fine("this = " + this +
  3929                 "; shape=" + shape + "; fromZ=" + fromZorder + "; toZ=" + toZorder);
  3929                 "; shape=" + shape + "; fromZ=" + fromZorder + "; toZ=" + toZorder);
  3930         }
  3930         }
  3931         if (fromZorder == -1) {
  3931         if (fromZorder == -1) {
  3932             return;
  3932             return;
  3959         recursiveApplyCurrentShape(fromZorder, getBottommostComponentIndex());
  3959         recursiveApplyCurrentShape(fromZorder, getBottommostComponentIndex());
  3960     }
  3960     }
  3961 
  3961 
  3962     final void recursiveApplyCurrentShape(int fromZorder, int toZorder) {
  3962     final void recursiveApplyCurrentShape(int fromZorder, int toZorder) {
  3963         checkTreeLock();
  3963         checkTreeLock();
  3964         if (mixingLog.isLoggable(Level.FINE)) {
  3964         if (mixingLog.isLoggable(PlatformLogger.FINE)) {
  3965             mixingLog.fine("this = " + this +
  3965             mixingLog.fine("this = " + this +
  3966                 "; fromZ=" + fromZorder + "; toZ=" + toZorder);
  3966                 "; fromZ=" + fromZorder + "; toZ=" + toZorder);
  3967         }
  3967         }
  3968         if (fromZorder == -1) {
  3968         if (fromZorder == -1) {
  3969             return;
  3969             return;
  4063     }
  4063     }
  4064 
  4064 
  4065     @Override
  4065     @Override
  4066     void mixOnShowing() {
  4066     void mixOnShowing() {
  4067         synchronized (getTreeLock()) {
  4067         synchronized (getTreeLock()) {
  4068             if (mixingLog.isLoggable(Level.FINE)) {
  4068             if (mixingLog.isLoggable(PlatformLogger.FINE)) {
  4069                 mixingLog.fine("this = " + this);
  4069                 mixingLog.fine("this = " + this);
  4070             }
  4070             }
  4071 
  4071 
  4072             if (!isMixingNeeded()) {
  4072             if (!isMixingNeeded()) {
  4073                 return;
  4073                 return;
  4088     }
  4088     }
  4089 
  4089 
  4090     @Override
  4090     @Override
  4091     void mixOnHiding(boolean isLightweight) {
  4091     void mixOnHiding(boolean isLightweight) {
  4092         synchronized (getTreeLock()) {
  4092         synchronized (getTreeLock()) {
  4093             if (mixingLog.isLoggable(Level.FINE)) {
  4093             if (mixingLog.isLoggable(PlatformLogger.FINE)) {
  4094                 mixingLog.fine("this = " + this +
  4094                 mixingLog.fine("this = " + this +
  4095                         "; isLightweight=" + isLightweight);
  4095                         "; isLightweight=" + isLightweight);
  4096             }
  4096             }
  4097             if (isLightweight) {
  4097             if (isLightweight) {
  4098                 recursiveHideHeavyweightChildren();
  4098                 recursiveHideHeavyweightChildren();
  4102     }
  4102     }
  4103 
  4103 
  4104     @Override
  4104     @Override
  4105     void mixOnReshaping() {
  4105     void mixOnReshaping() {
  4106         synchronized (getTreeLock()) {
  4106         synchronized (getTreeLock()) {
  4107             if (mixingLog.isLoggable(Level.FINE)) {
  4107             if (mixingLog.isLoggable(PlatformLogger.FINE)) {
  4108                 mixingLog.fine("this = " + this);
  4108                 mixingLog.fine("this = " + this);
  4109             }
  4109             }
  4110 
  4110 
  4111             boolean isMixingNeeded = isMixingNeeded();
  4111             boolean isMixingNeeded = isMixingNeeded();
  4112 
  4112 
  4137     }
  4137     }
  4138 
  4138 
  4139     @Override
  4139     @Override
  4140     void mixOnZOrderChanging(int oldZorder, int newZorder) {
  4140     void mixOnZOrderChanging(int oldZorder, int newZorder) {
  4141         synchronized (getTreeLock()) {
  4141         synchronized (getTreeLock()) {
  4142             if (mixingLog.isLoggable(Level.FINE)) {
  4142             if (mixingLog.isLoggable(PlatformLogger.FINE)) {
  4143                 mixingLog.fine("this = " + this +
  4143                 mixingLog.fine("this = " + this +
  4144                     "; oldZ=" + oldZorder + "; newZ=" + newZorder);
  4144                     "; oldZ=" + oldZorder + "; newZ=" + newZorder);
  4145             }
  4145             }
  4146 
  4146 
  4147             if (!isMixingNeeded()) {
  4147             if (!isMixingNeeded()) {
  4158     }
  4158     }
  4159 
  4159 
  4160     @Override
  4160     @Override
  4161     void mixOnValidating() {
  4161     void mixOnValidating() {
  4162         synchronized (getTreeLock()) {
  4162         synchronized (getTreeLock()) {
  4163             if (mixingLog.isLoggable(Level.FINE)) {
  4163             if (mixingLog.isLoggable(PlatformLogger.FINE)) {
  4164                 mixingLog.fine("this = " + this);
  4164                 mixingLog.fine("this = " + this);
  4165             }
  4165             }
  4166 
  4166 
  4167             if (!isMixingNeeded()) {
  4167             if (!isMixingNeeded()) {
  4168                 return;
  4168                 return;
  4204      * Our own mouse event for when we're dragged over from another hw
  4204      * Our own mouse event for when we're dragged over from another hw
  4205      * container
  4205      * container
  4206      */
  4206      */
  4207     private static final int  LWD_MOUSE_DRAGGED_OVER = 1500;
  4207     private static final int  LWD_MOUSE_DRAGGED_OVER = 1500;
  4208 
  4208 
  4209     private static final Logger eventLog = Logger.getLogger("java.awt.event.LightweightDispatcher");
  4209     private static final PlatformLogger eventLog = PlatformLogger.getLogger("java.awt.event.LightweightDispatcher");
  4210 
  4210 
  4211     LightweightDispatcher(Container nativeContainer) {
  4211     LightweightDispatcher(Container nativeContainer) {
  4212         this.nativeContainer = nativeContainer;
  4212         this.nativeContainer = nativeContainer;
  4213         mouseEventTarget = null;
  4213         mouseEventTarget = null;
  4214         eventMask = 0;
  4214         eventMask = 0;
  4346                 break;
  4346                 break;
  4347         case MouseEvent.MOUSE_WHEEL:
  4347         case MouseEvent.MOUSE_WHEEL:
  4348             // This may send it somewhere that doesn't have MouseWheelEvents
  4348             // This may send it somewhere that doesn't have MouseWheelEvents
  4349             // enabled.  In this case, Component.dispatchEventImpl() will
  4349             // enabled.  In this case, Component.dispatchEventImpl() will
  4350             // retarget the event to a parent that DOES have the events enabled.
  4350             // retarget the event to a parent that DOES have the events enabled.
  4351             if (eventLog.isLoggable(Level.FINEST) && (mouseOver != null)) {
  4351             if (eventLog.isLoggable(PlatformLogger.FINEST) && (mouseOver != null)) {
  4352                 eventLog.log(Level.FINEST, "retargeting mouse wheel to " +
  4352                 eventLog.finest("retargeting mouse wheel to " +
  4353                              mouseOver.getName() + ", " +
  4353                                 mouseOver.getName() + ", " +
  4354                              mouseOver.getClass());
  4354                                 mouseOver.getClass());
  4355             }
  4355             }
  4356             retargetMouseEvent(mouseOver, id, e);
  4356             retargetMouseEvent(mouseOver, id, e);
  4357         break;
  4357         break;
  4358             }
  4358             }
  4359             e.consume();
  4359             e.consume();