< prev index next >

src/java.desktop/share/classes/java/awt/Container.java

Print this page




 788              addDelicately(comp, curParent, index);
 789 
 790              // If the oldZindex == -1, the component gets inserted,
 791              // rather than it changes its z-order.
 792              if (!peerRecreated && oldZindex != -1) {
 793                  // The new 'index' cannot be == -1.
 794                  // It gets checked at the checkAdding() method.
 795                  // Therefore both oldZIndex and index denote
 796                  // some existing positions at this point and
 797                  // this is actually a Z-order changing.
 798                  comp.mixOnZOrderChanging(oldZindex, index);
 799              }
 800          }
 801     }
 802 
 803     /**
 804      * Traverses the tree of components and reparents children heavyweight component
 805      * to new heavyweight parent.
 806      * @since 1.5
 807      */

 808     private void reparentTraverse(ContainerPeer parentPeer, Container child) {
 809         checkTreeLock();
 810 
 811         for (int i = 0; i < child.getComponentCount(); i++) {
 812             Component comp = child.getComponent(i);
 813             if (comp.isLightweight()) {
 814                 // If components is lightweight check if it is container
 815                 // If it is container it might contain heavyweight children we need to reparent
 816                 if (comp instanceof Container) {
 817                     reparentTraverse(parentPeer, (Container)comp);
 818                 }
 819             } else {
 820                 // Q: Need to update NativeInLightFixer?
 821                 comp.getPeer().reparent(parentPeer);
 822             }
 823         }
 824     }
 825 
 826     /**
 827      * Reparents child component peer to this container peer.
 828      * Container must be heavyweight.
 829      * @since 1.5
 830      */

 831     private void reparentChild(Component comp) {
 832         checkTreeLock();
 833         if (comp == null) {
 834             return;
 835         }
 836         if (comp.isLightweight()) {
 837             // If component is lightweight container we need to reparent all its explicit  heavyweight children
 838             if (comp instanceof Container) {
 839                 // Traverse component's tree till depth-first until encountering heavyweight component
 840                 reparentTraverse((ContainerPeer)getPeer(), (Container)comp);
 841             }
 842         } else {
 843             comp.getPeer().reparent((ContainerPeer)getPeer());
 844         }
 845     }
 846 
 847     /**
 848      * Adds component to this container. Tries to minimize side effects of this adding -
 849      * doesn't call remove notify if it is not required.
 850      * @since 1.5


4172             return;
4173         }
4174         // An invalid container with not-null layout should be ignored
4175         // by the mixing code, the container will be validated later
4176         // and the mixing code will be executed later.
4177         if (getLayout() != null && !isValid()) {
4178             return;
4179         }
4180         for (int index = fromZorder; index <= toZorder; index++) {
4181             Component comp = getComponent(index);
4182             if (!comp.isLightweight()) {
4183                 comp.applyCurrentShape();
4184             }
4185             if (comp instanceof Container &&
4186                     ((Container)comp).hasHeavyweightDescendants()) {
4187                 ((Container)comp).recursiveApplyCurrentShape();
4188             }
4189         }
4190     }
4191 

4192     private void recursiveShowHeavyweightChildren() {
4193         if (!hasHeavyweightDescendants() || !isVisible()) {
4194             return;
4195         }
4196         for (int index = 0; index < getComponentCount(); index++) {
4197             Component comp = getComponent(index);
4198             if (comp.isLightweight()) {
4199                 if  (comp instanceof Container) {
4200                     ((Container)comp).recursiveShowHeavyweightChildren();
4201                 }
4202             } else {
4203                 if (comp.isVisible()) {
4204                     ComponentPeer peer = comp.getPeer();
4205                     if (peer != null) {
4206                         peer.setVisible(true);
4207                     }
4208                 }
4209             }
4210         }
4211     }
4212 

4213     private void recursiveHideHeavyweightChildren() {
4214         if (!hasHeavyweightDescendants()) {
4215             return;
4216         }
4217         for (int index = 0; index < getComponentCount(); index++) {
4218             Component comp = getComponent(index);
4219             if (comp.isLightweight()) {
4220                 if  (comp instanceof Container) {
4221                     ((Container)comp).recursiveHideHeavyweightChildren();
4222                 }
4223             } else {
4224                 if (comp.isVisible()) {
4225                     ComponentPeer peer = comp.getPeer();
4226                     if (peer != null) {
4227                         peer.setVisible(false);
4228                     }
4229                 }
4230             }
4231         }
4232     }
4233 

4234     private void recursiveRelocateHeavyweightChildren(Point origin) {
4235         for (int index = 0; index < getComponentCount(); index++) {
4236             Component comp = getComponent(index);
4237             if (comp.isLightweight()) {
4238                 if  (comp instanceof Container &&
4239                         ((Container)comp).hasHeavyweightDescendants())
4240                 {
4241                     final Point newOrigin = new Point(origin);
4242                     newOrigin.translate(comp.getX(), comp.getY());
4243                     ((Container)comp).recursiveRelocateHeavyweightChildren(newOrigin);
4244                 }
4245             } else {
4246                 ComponentPeer peer = comp.getPeer();
4247                 if (peer != null) {
4248                     peer.setBounds(origin.x + comp.getX(), origin.y + comp.getY(),
4249                             comp.getWidth(), comp.getHeight(),
4250                             ComponentPeer.SET_LOCATION);
4251                 }
4252             }
4253         }




 788              addDelicately(comp, curParent, index);
 789 
 790              // If the oldZindex == -1, the component gets inserted,
 791              // rather than it changes its z-order.
 792              if (!peerRecreated && oldZindex != -1) {
 793                  // The new 'index' cannot be == -1.
 794                  // It gets checked at the checkAdding() method.
 795                  // Therefore both oldZIndex and index denote
 796                  // some existing positions at this point and
 797                  // this is actually a Z-order changing.
 798                  comp.mixOnZOrderChanging(oldZindex, index);
 799              }
 800          }
 801     }
 802 
 803     /**
 804      * Traverses the tree of components and reparents children heavyweight component
 805      * to new heavyweight parent.
 806      * @since 1.5
 807      */
 808     @SuppressWarnings("deprecation")
 809     private void reparentTraverse(ContainerPeer parentPeer, Container child) {
 810         checkTreeLock();
 811 
 812         for (int i = 0; i < child.getComponentCount(); i++) {
 813             Component comp = child.getComponent(i);
 814             if (comp.isLightweight()) {
 815                 // If components is lightweight check if it is container
 816                 // If it is container it might contain heavyweight children we need to reparent
 817                 if (comp instanceof Container) {
 818                     reparentTraverse(parentPeer, (Container)comp);
 819                 }
 820             } else {
 821                 // Q: Need to update NativeInLightFixer?
 822                 comp.getPeer().reparent(parentPeer);
 823             }
 824         }
 825     }
 826 
 827     /**
 828      * Reparents child component peer to this container peer.
 829      * Container must be heavyweight.
 830      * @since 1.5
 831      */
 832     @SuppressWarnings("deprecation")
 833     private void reparentChild(Component comp) {
 834         checkTreeLock();
 835         if (comp == null) {
 836             return;
 837         }
 838         if (comp.isLightweight()) {
 839             // If component is lightweight container we need to reparent all its explicit  heavyweight children
 840             if (comp instanceof Container) {
 841                 // Traverse component's tree till depth-first until encountering heavyweight component
 842                 reparentTraverse((ContainerPeer)getPeer(), (Container)comp);
 843             }
 844         } else {
 845             comp.getPeer().reparent((ContainerPeer)getPeer());
 846         }
 847     }
 848 
 849     /**
 850      * Adds component to this container. Tries to minimize side effects of this adding -
 851      * doesn't call remove notify if it is not required.
 852      * @since 1.5


4174             return;
4175         }
4176         // An invalid container with not-null layout should be ignored
4177         // by the mixing code, the container will be validated later
4178         // and the mixing code will be executed later.
4179         if (getLayout() != null && !isValid()) {
4180             return;
4181         }
4182         for (int index = fromZorder; index <= toZorder; index++) {
4183             Component comp = getComponent(index);
4184             if (!comp.isLightweight()) {
4185                 comp.applyCurrentShape();
4186             }
4187             if (comp instanceof Container &&
4188                     ((Container)comp).hasHeavyweightDescendants()) {
4189                 ((Container)comp).recursiveApplyCurrentShape();
4190             }
4191         }
4192     }
4193 
4194     @SuppressWarnings("deprecation")
4195     private void recursiveShowHeavyweightChildren() {
4196         if (!hasHeavyweightDescendants() || !isVisible()) {
4197             return;
4198         }
4199         for (int index = 0; index < getComponentCount(); index++) {
4200             Component comp = getComponent(index);
4201             if (comp.isLightweight()) {
4202                 if  (comp instanceof Container) {
4203                     ((Container)comp).recursiveShowHeavyweightChildren();
4204                 }
4205             } else {
4206                 if (comp.isVisible()) {
4207                     ComponentPeer peer = comp.getPeer();
4208                     if (peer != null) {
4209                         peer.setVisible(true);
4210                     }
4211                 }
4212             }
4213         }
4214     }
4215 
4216     @SuppressWarnings("deprecation")
4217     private void recursiveHideHeavyweightChildren() {
4218         if (!hasHeavyweightDescendants()) {
4219             return;
4220         }
4221         for (int index = 0; index < getComponentCount(); index++) {
4222             Component comp = getComponent(index);
4223             if (comp.isLightweight()) {
4224                 if  (comp instanceof Container) {
4225                     ((Container)comp).recursiveHideHeavyweightChildren();
4226                 }
4227             } else {
4228                 if (comp.isVisible()) {
4229                     ComponentPeer peer = comp.getPeer();
4230                     if (peer != null) {
4231                         peer.setVisible(false);
4232                     }
4233                 }
4234             }
4235         }
4236     }
4237 
4238     @SuppressWarnings("deprecation")
4239     private void recursiveRelocateHeavyweightChildren(Point origin) {
4240         for (int index = 0; index < getComponentCount(); index++) {
4241             Component comp = getComponent(index);
4242             if (comp.isLightweight()) {
4243                 if  (comp instanceof Container &&
4244                         ((Container)comp).hasHeavyweightDescendants())
4245                 {
4246                     final Point newOrigin = new Point(origin);
4247                     newOrigin.translate(comp.getX(), comp.getY());
4248                     ((Container)comp).recursiveRelocateHeavyweightChildren(newOrigin);
4249                 }
4250             } else {
4251                 ComponentPeer peer = comp.getPeer();
4252                 if (peer != null) {
4253                     peer.setBounds(origin.x + comp.getX(), origin.y + comp.getY(),
4254                             comp.getWidth(), comp.getHeight(),
4255                             ComponentPeer.SET_LOCATION);
4256                 }
4257             }
4258         }


< prev index next >