803 804 /** 805 * Traverses the tree of components and reparents children heavyweight component 806 * to new heavyweight parent. 807 * @since 1.5 808 */ 809 @SuppressWarnings("deprecation") 810 private void reparentTraverse(ContainerPeer parentPeer, Container child) { 811 checkTreeLock(); 812 813 for (int i = 0; i < child.getComponentCount(); i++) { 814 Component comp = child.getComponent(i); 815 if (comp.isLightweight()) { 816 // If components is lightweight check if it is container 817 // If it is container it might contain heavyweight children we need to reparent 818 if (comp instanceof Container) { 819 reparentTraverse(parentPeer, (Container)comp); 820 } 821 } else { 822 // Q: Need to update NativeInLightFixer? 823 comp.getPeer().reparent(parentPeer); 824 } 825 } 826 } 827 828 /** 829 * Reparents child component peer to this container peer. 830 * Container must be heavyweight. 831 * @since 1.5 832 */ 833 @SuppressWarnings("deprecation") 834 private void reparentChild(Component comp) { 835 checkTreeLock(); 836 if (comp == null) { 837 return; 838 } 839 if (comp.isLightweight()) { 840 // If component is lightweight container we need to reparent all its explicit heavyweight children 841 if (comp instanceof Container) { 842 // Traverse component's tree till depth-first until encountering heavyweight component 843 reparentTraverse((ContainerPeer)getPeer(), (Container)comp); 844 } 845 } else { 846 comp.getPeer().reparent((ContainerPeer)getPeer()); 847 } 848 } 849 850 /** 851 * Adds component to this container. Tries to minimize side effects of this adding - 852 * doesn't call remove notify if it is not required. 853 * @since 1.5 854 */ 855 private void addDelicately(Component comp, Container curParent, int index) { 856 checkTreeLock(); 857 858 // Check if moving between containers 859 if (curParent != this) { 860 //index == -1 means add to the end. 861 if (index == -1) { 862 component.add(comp); 863 } else { 864 component.add(index, comp); 865 } 866 comp.parent = this; 4178 if (comp instanceof Container && 4179 ((Container)comp).hasHeavyweightDescendants()) { 4180 ((Container)comp).recursiveApplyCurrentShape(); 4181 } 4182 } 4183 } 4184 4185 @SuppressWarnings("deprecation") 4186 private void recursiveShowHeavyweightChildren() { 4187 if (!hasHeavyweightDescendants() || !isVisible()) { 4188 return; 4189 } 4190 for (int index = 0; index < getComponentCount(); index++) { 4191 Component comp = getComponent(index); 4192 if (comp.isLightweight()) { 4193 if (comp instanceof Container) { 4194 ((Container)comp).recursiveShowHeavyweightChildren(); 4195 } 4196 } else { 4197 if (comp.isVisible()) { 4198 ComponentPeer peer = comp.getPeer(); 4199 if (peer != null) { 4200 peer.setVisible(true); 4201 } 4202 } 4203 } 4204 } 4205 } 4206 4207 @SuppressWarnings("deprecation") 4208 private void recursiveHideHeavyweightChildren() { 4209 if (!hasHeavyweightDescendants()) { 4210 return; 4211 } 4212 for (int index = 0; index < getComponentCount(); index++) { 4213 Component comp = getComponent(index); 4214 if (comp.isLightweight()) { 4215 if (comp instanceof Container) { 4216 ((Container)comp).recursiveHideHeavyweightChildren(); 4217 } 4218 } else { 4219 if (comp.isVisible()) { 4220 ComponentPeer peer = comp.getPeer(); 4221 if (peer != null) { 4222 peer.setVisible(false); 4223 } 4224 } 4225 } 4226 } 4227 } 4228 4229 @SuppressWarnings("deprecation") 4230 private void recursiveRelocateHeavyweightChildren(Point origin) { 4231 for (int index = 0; index < getComponentCount(); index++) { 4232 Component comp = getComponent(index); 4233 if (comp.isLightweight()) { 4234 if (comp instanceof Container && 4235 ((Container)comp).hasHeavyweightDescendants()) 4236 { 4237 final Point newOrigin = new Point(origin); 4238 newOrigin.translate(comp.getX(), comp.getY()); 4239 ((Container)comp).recursiveRelocateHeavyweightChildren(newOrigin); 4240 } 4241 } else { 4242 ComponentPeer peer = comp.getPeer(); 4243 if (peer != null) { 4244 peer.setBounds(origin.x + comp.getX(), origin.y + comp.getY(), 4245 comp.getWidth(), comp.getHeight(), 4246 ComponentPeer.SET_LOCATION); 4247 } 4248 } 4249 } 4250 } 4251 4252 /** 4253 * Checks if the container and its direct lightweight containers are 4254 * visible. 4255 * 4256 * Consider the heavyweight container hides or shows the HW descendants 4257 * automatically. Therefore we care of LW containers' visibility only. 4258 * 4259 * This method MUST be invoked under the TreeLock. 4260 */ 4261 final boolean isRecursivelyVisibleUpToHeavyweightContainer() { 4262 if (!isLightweight()) { | 803 804 /** 805 * Traverses the tree of components and reparents children heavyweight component 806 * to new heavyweight parent. 807 * @since 1.5 808 */ 809 @SuppressWarnings("deprecation") 810 private void reparentTraverse(ContainerPeer parentPeer, Container child) { 811 checkTreeLock(); 812 813 for (int i = 0; i < child.getComponentCount(); i++) { 814 Component comp = child.getComponent(i); 815 if (comp.isLightweight()) { 816 // If components is lightweight check if it is container 817 // If it is container it might contain heavyweight children we need to reparent 818 if (comp instanceof Container) { 819 reparentTraverse(parentPeer, (Container)comp); 820 } 821 } else { 822 // Q: Need to update NativeInLightFixer? 823 comp.peer.reparent(parentPeer); 824 } 825 } 826 } 827 828 /** 829 * Reparents child component peer to this container peer. 830 * Container must be heavyweight. 831 * @since 1.5 832 */ 833 @SuppressWarnings("deprecation") 834 private void reparentChild(Component comp) { 835 checkTreeLock(); 836 if (comp == null) { 837 return; 838 } 839 if (comp.isLightweight()) { 840 // If component is lightweight container we need to reparent all its explicit heavyweight children 841 if (comp instanceof Container) { 842 // Traverse component's tree till depth-first until encountering heavyweight component 843 reparentTraverse((ContainerPeer)peer, (Container)comp); 844 } 845 } else { 846 comp.peer.reparent((ContainerPeer) peer); 847 } 848 } 849 850 /** 851 * Adds component to this container. Tries to minimize side effects of this adding - 852 * doesn't call remove notify if it is not required. 853 * @since 1.5 854 */ 855 private void addDelicately(Component comp, Container curParent, int index) { 856 checkTreeLock(); 857 858 // Check if moving between containers 859 if (curParent != this) { 860 //index == -1 means add to the end. 861 if (index == -1) { 862 component.add(comp); 863 } else { 864 component.add(index, comp); 865 } 866 comp.parent = this; 4178 if (comp instanceof Container && 4179 ((Container)comp).hasHeavyweightDescendants()) { 4180 ((Container)comp).recursiveApplyCurrentShape(); 4181 } 4182 } 4183 } 4184 4185 @SuppressWarnings("deprecation") 4186 private void recursiveShowHeavyweightChildren() { 4187 if (!hasHeavyweightDescendants() || !isVisible()) { 4188 return; 4189 } 4190 for (int index = 0; index < getComponentCount(); index++) { 4191 Component comp = getComponent(index); 4192 if (comp.isLightweight()) { 4193 if (comp instanceof Container) { 4194 ((Container)comp).recursiveShowHeavyweightChildren(); 4195 } 4196 } else { 4197 if (comp.isVisible()) { 4198 ComponentPeer peer = comp.peer; 4199 if (peer != null) { 4200 peer.setVisible(true); 4201 } 4202 } 4203 } 4204 } 4205 } 4206 4207 @SuppressWarnings("deprecation") 4208 private void recursiveHideHeavyweightChildren() { 4209 if (!hasHeavyweightDescendants()) { 4210 return; 4211 } 4212 for (int index = 0; index < getComponentCount(); index++) { 4213 Component comp = getComponent(index); 4214 if (comp.isLightweight()) { 4215 if (comp instanceof Container) { 4216 ((Container)comp).recursiveHideHeavyweightChildren(); 4217 } 4218 } else { 4219 if (comp.isVisible()) { 4220 ComponentPeer peer = comp.peer; 4221 if (peer != null) { 4222 peer.setVisible(false); 4223 } 4224 } 4225 } 4226 } 4227 } 4228 4229 @SuppressWarnings("deprecation") 4230 private void recursiveRelocateHeavyweightChildren(Point origin) { 4231 for (int index = 0; index < getComponentCount(); index++) { 4232 Component comp = getComponent(index); 4233 if (comp.isLightweight()) { 4234 if (comp instanceof Container && 4235 ((Container)comp).hasHeavyweightDescendants()) 4236 { 4237 final Point newOrigin = new Point(origin); 4238 newOrigin.translate(comp.getX(), comp.getY()); 4239 ((Container)comp).recursiveRelocateHeavyweightChildren(newOrigin); 4240 } 4241 } else { 4242 ComponentPeer peer = comp.peer; 4243 if (peer != null) { 4244 peer.setBounds(origin.x + comp.getX(), origin.y + comp.getY(), 4245 comp.getWidth(), comp.getHeight(), 4246 ComponentPeer.SET_LOCATION); 4247 } 4248 } 4249 } 4250 } 4251 4252 /** 4253 * Checks if the container and its direct lightweight containers are 4254 * visible. 4255 * 4256 * Consider the heavyweight container hides or shows the HW descendants 4257 * automatically. Therefore we care of LW containers' visibility only. 4258 * 4259 * This method MUST be invoked under the TreeLock. 4260 */ 4261 final boolean isRecursivelyVisibleUpToHeavyweightContainer() { 4262 if (!isLightweight()) { |