jdk/src/share/classes/java/awt/Container.java
changeset 1183 80d6aafba03a
parent 1172 a1d23c450f84
child 1188 44c63c47def9
equal deleted inserted replaced
1182:9590bc50fe0f 1183:80d6aafba03a
   503             adjustDescendants(-(comp.countHierarchyMembers()));
   503             adjustDescendants(-(comp.countHierarchyMembers()));
   504 
   504 
   505             comp.parent = null;
   505             comp.parent = null;
   506             component.remove(index);
   506             component.remove(index);
   507 
   507 
   508             if (valid) {
   508             invalidateIfValid();
   509                 invalidate();
       
   510             }
       
   511         } else {
   509         } else {
   512             // We should remove component and then
   510             // We should remove component and then
   513             // add it by the newIndex without newIndex decrement if even we shift components to the left
   511             // add it by the newIndex without newIndex decrement if even we shift components to the left
   514             // after remove. Consult the rules below:
   512             // after remove. Consult the rules below:
   515             // 2->4: 012345 -> 013425, 2->5: 012345 -> 013452
   513             // 2->4: 012345 -> 013425, 2->5: 012345 -> 013452
   798             if (index < component.size()) {
   796             if (index < component.size()) {
   799                 component.set(index, comp);
   797                 component.set(index, comp);
   800             }
   798             }
   801         }
   799         }
   802 
   800 
   803         if (valid) {
   801         invalidateIfValid();
   804             invalidate();
       
   805         }
       
   806         if (peer != null) {
   802         if (peer != null) {
   807             if (comp.peer == null) { // Remove notify was called or it didn't have peer - create new one
   803             if (comp.peer == null) { // Remove notify was called or it didn't have peer - create new one
   808                 comp.addNotify();
   804                 comp.addNotify();
   809                 // New created peer creates component on top of the stacking order
   805                 // New created peer creates component on top of the stacking order
   810                 Container newNativeContainer = getHeavyweightContainer();
   806                 Container newNativeContainer = getHeavyweightContainer();
  1062                 comp.numListening(AWTEvent.HIERARCHY_EVENT_MASK));
  1058                 comp.numListening(AWTEvent.HIERARCHY_EVENT_MASK));
  1063             adjustListeningChildren(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK,
  1059             adjustListeningChildren(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK,
  1064                 comp.numListening(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK));
  1060                 comp.numListening(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK));
  1065             adjustDescendants(comp.countHierarchyMembers());
  1061             adjustDescendants(comp.countHierarchyMembers());
  1066 
  1062 
  1067             if (valid) {
  1063             invalidateIfValid();
  1068                 invalidate();
       
  1069             }
       
  1070             if (peer != null) {
  1064             if (peer != null) {
  1071                 comp.addNotify();
  1065                 comp.addNotify();
  1072             }
  1066             }
  1073 
  1067 
  1074             /* Notify the layout manager of the added component. */
  1068             /* Notify the layout manager of the added component. */
  1153             adjustDescendants(-(comp.countHierarchyMembers()));
  1147             adjustDescendants(-(comp.countHierarchyMembers()));
  1154 
  1148 
  1155             comp.parent = null;
  1149             comp.parent = null;
  1156             component.remove(index);
  1150             component.remove(index);
  1157 
  1151 
  1158             if (valid) {
  1152             invalidateIfValid();
  1159                 invalidate();
       
  1160             }
       
  1161             if (containerListener != null ||
  1153             if (containerListener != null ||
  1162                 (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0 ||
  1154                 (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0 ||
  1163                 Toolkit.enabledOnToolkit(AWTEvent.CONTAINER_EVENT_MASK)) {
  1155                 Toolkit.enabledOnToolkit(AWTEvent.CONTAINER_EVENT_MASK)) {
  1164                 ContainerEvent e = new ContainerEvent(this,
  1156                 ContainerEvent e = new ContainerEvent(this,
  1165                                      ContainerEvent.COMPONENT_REMOVED,
  1157                                      ContainerEvent.COMPONENT_REMOVED,
  1247                                            Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));
  1239                                            Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));
  1248             }
  1240             }
  1249             if (peer != null && layoutMgr == null && isVisible()) {
  1241             if (peer != null && layoutMgr == null && isVisible()) {
  1250                 updateCursorImmediately();
  1242                 updateCursorImmediately();
  1251             }
  1243             }
  1252             if (valid) {
  1244             invalidateIfValid();
  1253                 invalidate();
       
  1254             }
       
  1255         }
  1245         }
  1256     }
  1246     }
  1257 
  1247 
  1258     // Should only be called while holding tree lock
  1248     // Should only be called while holding tree lock
  1259     int numListening(long mask) {
  1249     int numListening(long mask) {
  1409      * @see #doLayout
  1399      * @see #doLayout
  1410      * @see #getLayout
  1400      * @see #getLayout
  1411      */
  1401      */
  1412     public void setLayout(LayoutManager mgr) {
  1402     public void setLayout(LayoutManager mgr) {
  1413         layoutMgr = mgr;
  1403         layoutMgr = mgr;
  1414         if (valid) {
  1404         invalidateIfValid();
  1415             invalidate();
       
  1416         }
       
  1417     }
  1405     }
  1418 
  1406 
  1419     /**
  1407     /**
  1420      * Causes this container to lay out its components.  Most programs
  1408      * Causes this container to lay out its components.  Most programs
  1421      * should not call this method directly, but should invoke
  1409      * should not call this method directly, but should invoke
  1483      * @see javax.swing.JComponent#revalidate()
  1471      * @see javax.swing.JComponent#revalidate()
  1484      * @see #validateTree
  1472      * @see #validateTree
  1485      */
  1473      */
  1486     public void validate() {
  1474     public void validate() {
  1487         /* Avoid grabbing lock unless really necessary. */
  1475         /* Avoid grabbing lock unless really necessary. */
  1488         if (!valid) {
  1476         if (!isValid()) {
  1489             boolean updateCur = false;
  1477             boolean updateCur = false;
  1490             synchronized (getTreeLock()) {
  1478             synchronized (getTreeLock()) {
  1491                 if (!valid && peer != null) {
  1479                 if (!isValid() && peer != null) {
  1492                     ContainerPeer p = null;
  1480                     ContainerPeer p = null;
  1493                     if (peer instanceof ContainerPeer) {
  1481                     if (peer instanceof ContainerPeer) {
  1494                         p = (ContainerPeer) peer;
  1482                         p = (ContainerPeer) peer;
  1495                     }
  1483                     }
  1496                     if (p != null) {
  1484                     if (p != null) {
  1497                         p.beginValidate();
  1485                         p.beginValidate();
  1498                     }
  1486                     }
  1499                     validateTree();
  1487                     validateTree();
  1500                     valid = true;
       
  1501                     if (p != null) {
  1488                     if (p != null) {
  1502                         p.endValidate();
  1489                         p.endValidate();
  1503                         updateCur = isVisible();
  1490                         updateCur = isVisible();
  1504                     }
  1491                     }
  1505                 }
  1492                 }
  1518      *
  1505      *
  1519      * @see #doLayout
  1506      * @see #doLayout
  1520      * @see #validate
  1507      * @see #validate
  1521      */
  1508      */
  1522     protected void validateTree() {
  1509     protected void validateTree() {
  1523         if (!valid) {
  1510         if (!isValid()) {
  1524             if (peer instanceof ContainerPeer) {
  1511             if (peer instanceof ContainerPeer) {
  1525                 ((ContainerPeer)peer).beginLayout();
  1512                 ((ContainerPeer)peer).beginLayout();
  1526             }
  1513             }
  1527             doLayout();
  1514             doLayout();
  1528             for (int i = 0; i < component.size(); i++) {
  1515             for (int i = 0; i < component.size(); i++) {
  1529                 Component comp = component.get(i);
  1516                 Component comp = component.get(i);
  1530                 if (   (comp instanceof Container)
  1517                 if (   (comp instanceof Container)
  1531                        && !(comp instanceof Window)
  1518                        && !(comp instanceof Window)
  1532                        && !comp.valid) {
  1519                        && !comp.isValid()) {
  1533                     ((Container)comp).validateTree();
  1520                     ((Container)comp).validateTree();
  1534                 } else {
  1521                 } else {
  1535                     comp.validate();
  1522                     comp.validate();
  1536                 }
  1523                 }
  1537             }
  1524             }
  1538             if (peer instanceof ContainerPeer) {
  1525             if (peer instanceof ContainerPeer) {
  1539                 ((ContainerPeer)peer).endLayout();
  1526                 ((ContainerPeer)peer).endLayout();
  1540             }
  1527             }
  1541         }
  1528         }
  1542         valid = true;
  1529         super.validate();
  1543     }
  1530     }
  1544 
  1531 
  1545     /**
  1532     /**
  1546      * Recursively descends the container tree and invalidates all
  1533      * Recursively descends the container tree and invalidates all
  1547      * contained components.
  1534      * contained components.
  1552                 Component comp = component.get(i);
  1539                 Component comp = component.get(i);
  1553                 if (comp instanceof Container) {
  1540                 if (comp instanceof Container) {
  1554                     ((Container)comp).invalidateTree();
  1541                     ((Container)comp).invalidateTree();
  1555                 }
  1542                 }
  1556                 else {
  1543                 else {
  1557                     if (comp.valid) {
  1544                     comp.invalidateIfValid();
  1558                         comp.invalidate();
  1545                 }
  1559                     }
  1546             }
  1560                 }
  1547             invalidateIfValid();
  1561             }
       
  1562             if (valid) {
       
  1563                 invalidate();
       
  1564             }
       
  1565         }
  1548         }
  1566     }
  1549     }
  1567 
  1550 
  1568     /**
  1551     /**
  1569      * Sets the font of this container.
  1552      * Sets the font of this container.
  4081             }
  4064             }
  4082             super.mixOnZOrderChanging(oldZorder, newZorder);
  4065             super.mixOnZOrderChanging(oldZorder, newZorder);
  4083         }
  4066         }
  4084     }
  4067     }
  4085 
  4068 
       
  4069     @Override
       
  4070     void mixOnValidating() {
       
  4071         synchronized (getTreeLock()) {
       
  4072             if (mixingLog.isLoggable(Level.FINE)) {
       
  4073                 mixingLog.fine("this = " + this);
       
  4074             }
       
  4075 
       
  4076             if (hasHeavyweightDescendants()) {
       
  4077                 recursiveApplyCurrentShape();
       
  4078             }
       
  4079 
       
  4080             super.mixOnValidating();
       
  4081         }
       
  4082     }
       
  4083 
  4086     // ****************** END OF MIXING CODE ********************************
  4084     // ****************** END OF MIXING CODE ********************************
  4087 }
  4085 }
  4088 
  4086 
  4089 
  4087 
  4090 /**
  4088 /**