282 * @deprecated As of JDK version 1.1, |
286 * @deprecated As of JDK version 1.1, |
283 * replaced by getComponentCount(). |
287 * replaced by getComponentCount(). |
284 */ |
288 */ |
285 @Deprecated |
289 @Deprecated |
286 public int countComponents() { |
290 public int countComponents() { |
287 synchronized (getTreeLock()) { |
291 // This method is not synchronized under AWT tree lock. |
288 return component.size(); |
292 // Instead, the calling code is responsible for the |
289 } |
293 // synchronization. See 6784816 for details. |
|
294 return component.size(); |
290 } |
295 } |
291 |
296 |
292 /** |
297 /** |
293 * Gets the nth component in this container. |
298 * Gets the nth component in this container. |
|
299 * <p> |
|
300 * Note: This method should be called under AWT tree lock. |
|
301 * |
294 * @param n the index of the component to get. |
302 * @param n the index of the component to get. |
295 * @return the n<sup>th</sup> component in this container. |
303 * @return the n<sup>th</sup> component in this container. |
296 * @exception ArrayIndexOutOfBoundsException |
304 * @exception ArrayIndexOutOfBoundsException |
297 * if the n<sup>th</sup> value does not exist. |
305 * if the n<sup>th</sup> value does not exist. |
|
306 * @see Component#getTreeLock() |
298 */ |
307 */ |
299 public Component getComponent(int n) { |
308 public Component getComponent(int n) { |
300 synchronized (getTreeLock()) { |
309 // This method is not synchronized under AWT tree lock. |
301 if ((n < 0) || (n >= component.size())) { |
310 // Instead, the calling code is responsible for the |
302 throw new ArrayIndexOutOfBoundsException("No such child: " + n); |
311 // synchronization. See 6784816 for details. |
303 } |
312 try { |
304 return component.get(n); |
313 return component.get(n); |
|
314 } catch (IndexOutOfBoundsException z) { |
|
315 throw new ArrayIndexOutOfBoundsException("No such child: " + n); |
305 } |
316 } |
306 } |
317 } |
307 |
318 |
308 /** |
319 /** |
309 * Gets all the components in this container. |
320 * Gets all the components in this container. |
|
321 * <p> |
|
322 * Note: This method should be called under AWT tree lock. |
|
323 * |
310 * @return an array of all the components in this container. |
324 * @return an array of all the components in this container. |
|
325 * @see Component#getTreeLock() |
311 */ |
326 */ |
312 public Component[] getComponents() { |
327 public Component[] getComponents() { |
|
328 // This method is not synchronized under AWT tree lock. |
|
329 // Instead, the calling code is responsible for the |
|
330 // synchronization. See 6784816 for details. |
313 return getComponents_NoClientCode(); |
331 return getComponents_NoClientCode(); |
314 } |
332 } |
|
333 |
315 // NOTE: This method may be called by privileged threads. |
334 // NOTE: This method may be called by privileged threads. |
316 // This functionality is implemented in a package-private method |
335 // This functionality is implemented in a package-private method |
317 // to insure that it cannot be overridden by client subclasses. |
336 // to insure that it cannot be overridden by client subclasses. |
318 // DO NOT INVOKE CLIENT CODE ON THIS THREAD! |
337 // DO NOT INVOKE CLIENT CODE ON THIS THREAD! |
319 final Component[] getComponents_NoClientCode() { |
338 final Component[] getComponents_NoClientCode() { |
|
339 return component.toArray(EMPTY_ARRAY); |
|
340 } |
|
341 |
|
342 /* |
|
343 * Wrapper for getComponents() method with a proper synchronization. |
|
344 */ |
|
345 Component[] getComponentsSync() { |
320 synchronized (getTreeLock()) { |
346 synchronized (getTreeLock()) { |
321 return component.toArray(EMPTY_ARRAY); |
347 return getComponents(); |
322 } |
348 } |
323 } // getComponents_NoClientCode() |
349 } |
324 |
350 |
325 /** |
351 /** |
326 * Determines the insets of this container, which indicate the size |
352 * Determines the insets of this container, which indicate the size |
327 * of the container's border. |
353 * of the container's border. |
328 * <p> |
354 * <p> |
1026 throw new IllegalArgumentException( |
1052 throw new IllegalArgumentException( |
1027 "illegal component position"); |
1053 "illegal component position"); |
1028 } |
1054 } |
1029 checkAddToSelf(comp); |
1055 checkAddToSelf(comp); |
1030 checkNotAWindow(comp); |
1056 checkNotAWindow(comp); |
1031 if (thisGC != null) { |
1057 if (thisGC != null) { |
1032 comp.checkGD(thisGC.getDevice().getIDstring()); |
1058 comp.checkGD(thisGC.getDevice().getIDstring()); |
1033 } |
1059 } |
1034 |
1060 |
1035 /* Reparent the component and tidy up the tree's state. */ |
1061 /* Reparent the component and tidy up the tree's state. */ |
1036 if (comp.parent != null) { |
1062 if (comp.parent != null) { |
1037 comp.parent.remove(comp); |
1063 comp.parent.remove(comp); |
1038 if (index > component.size()) { |
1064 if (index > component.size()) { |
1365 } |
1391 } |
1366 |
1392 |
1367 final int createHierarchyEvents(int id, Component changed, |
1393 final int createHierarchyEvents(int id, Component changed, |
1368 Container changedParent, long changeFlags, boolean enabledOnToolkit) |
1394 Container changedParent, long changeFlags, boolean enabledOnToolkit) |
1369 { |
1395 { |
1370 assert Thread.holdsLock(getTreeLock()); |
1396 checkTreeLock(); |
1371 int listeners = getListenersCount(id, enabledOnToolkit); |
1397 int listeners = getListenersCount(id, enabledOnToolkit); |
1372 |
1398 |
1373 for (int count = listeners, i = 0; count > 0; i++) { |
1399 for (int count = listeners, i = 0; count > 0; i++) { |
1374 count -= component.get(i).createHierarchyEvents(id, changed, |
1400 count -= component.get(i).createHierarchyEvents(id, changed, |
1375 changedParent, changeFlags, enabledOnToolkit); |
1401 changedParent, changeFlags, enabledOnToolkit); |
2483 * The cursor code calls this function directly via native code. |
2508 * The cursor code calls this function directly via native code. |
2484 * |
2509 * |
2485 * The addition of this feature is temporary, pending the |
2510 * The addition of this feature is temporary, pending the |
2486 * adoption of new, public API which exports this feature. |
2511 * adoption of new, public API which exports this feature. |
2487 */ |
2512 */ |
2488 final Component findComponentAt(int x, int y, boolean ignoreEnabled) |
2513 final Component findComponentAt(int x, int y, boolean ignoreEnabled) { |
2489 { |
2514 synchronized (getTreeLock()) { |
2490 if (isRecursivelyVisible()){ |
2515 if (isRecursivelyVisible()){ |
2491 return findComponentAtImpl(x, y, ignoreEnabled); |
2516 return findComponentAtImpl(x, y, ignoreEnabled); |
|
2517 } |
2492 } |
2518 } |
2493 return null; |
2519 return null; |
2494 } |
2520 } |
2495 |
2521 |
2496 final Component findComponentAtImpl(int x, int y, boolean ignoreEnabled){ |
2522 final Component findComponentAtImpl(int x, int y, boolean ignoreEnabled){ |
|
2523 checkTreeLock(); |
|
2524 |
2497 if (!(contains(x, y) && visible && (ignoreEnabled || enabled))) { |
2525 if (!(contains(x, y) && visible && (ignoreEnabled || enabled))) { |
2498 return null; |
2526 return null; |
2499 } |
2527 } |
2500 |
2528 |
2501 // Two passes: see comment in sun.awt.SunGraphicsCallback |
2529 // Two passes: see comment in sun.awt.SunGraphicsCallback |
2502 synchronized (getTreeLock()) { |
2530 for (int i = 0; i < component.size(); i++) { |
2503 for (int i = 0; i < component.size(); i++) { |
2531 Component comp = component.get(i); |
2504 Component comp = component.get(i); |
2532 if (comp != null && |
2505 if (comp != null && |
2533 !(comp.peer instanceof LightweightPeer)) { |
2506 !(comp.peer instanceof LightweightPeer)) { |
2534 if (comp instanceof Container) { |
2507 if (comp instanceof Container) { |
2535 comp = ((Container)comp).findComponentAtImpl(x - comp.x, |
2508 comp = ((Container)comp).findComponentAtImpl(x - comp.x, |
2536 y - comp.y, |
2509 y - comp.y, |
2537 ignoreEnabled); |
2510 ignoreEnabled); |
2538 } else { |
2511 } else { |
2539 comp = comp.locate(x - comp.x, y - comp.y); |
2512 comp = comp.locate(x - comp.x, y - comp.y); |
2540 } |
2513 } |
2541 if (comp != null && comp.visible && |
2514 if (comp != null && comp.visible && |
2542 (ignoreEnabled || comp.enabled)) |
2515 (ignoreEnabled || comp.enabled)) |
2543 { |
2516 { |
2544 return comp; |
2517 return comp; |
2545 } |
2518 } |
2546 } |
2519 } |
2547 } |
2520 } |
2548 for (int i = 0; i < component.size(); i++) { |
2521 for (int i = 0; i < component.size(); i++) { |
2549 Component comp = component.get(i); |
2522 Component comp = component.get(i); |
2550 if (comp != null && |
2523 if (comp != null && |
2551 comp.peer instanceof LightweightPeer) { |
2524 comp.peer instanceof LightweightPeer) { |
2552 if (comp instanceof Container) { |
2525 if (comp instanceof Container) { |
2553 comp = ((Container)comp).findComponentAtImpl(x - comp.x, |
2526 comp = ((Container)comp).findComponentAtImpl(x - comp.x, |
2554 y - comp.y, |
2527 y - comp.y, |
2555 ignoreEnabled); |
2528 ignoreEnabled); |
2556 } else { |
2529 } else { |
2557 comp = comp.locate(x - comp.x, y - comp.y); |
2530 comp = comp.locate(x - comp.x, y - comp.y); |
2558 } |
2531 } |
2559 if (comp != null && comp.visible && |
2532 if (comp != null && comp.visible && |
2560 (ignoreEnabled || comp.enabled)) |
2533 (ignoreEnabled || comp.enabled)) |
2561 { |
2534 { |
2562 return comp; |
2535 return comp; |
2563 } |
2536 } |
2564 } |
2537 } |
2565 } |
2538 } |
2566 |
2539 } |
|
2540 return this; |
2567 return this; |
2541 } |
2568 } |
2542 |
2569 |
2543 /** |
2570 /** |
2544 * Locates the visible child component that contains the specified |
2571 * Locates the visible child component that contains the specified |
3489 * @see #readObject(ObjectInputStream) |
3516 * @see #readObject(ObjectInputStream) |
3490 */ |
3517 */ |
3491 private void writeObject(ObjectOutputStream s) throws IOException { |
3518 private void writeObject(ObjectOutputStream s) throws IOException { |
3492 ObjectOutputStream.PutField f = s.putFields(); |
3519 ObjectOutputStream.PutField f = s.putFields(); |
3493 f.put("ncomponents", component.size()); |
3520 f.put("ncomponents", component.size()); |
3494 f.put("component", component.toArray(EMPTY_ARRAY)); |
3521 f.put("component", getComponentsSync()); |
3495 f.put("layoutMgr", layoutMgr); |
3522 f.put("layoutMgr", layoutMgr); |
3496 f.put("dispatcher", dispatcher); |
3523 f.put("dispatcher", dispatcher); |
3497 f.put("maxSize", maxSize); |
3524 f.put("maxSize", maxSize); |
3498 f.put("focusCycleRoot", focusCycleRoot); |
3525 f.put("focusCycleRoot", focusCycleRoot); |
3499 f.put("containerSerializedDataVersion", containerSerializedDataVersion); |
3526 f.put("containerSerializedDataVersion", containerSerializedDataVersion); |