39 |
|
|
40 |
package java.awt; |
package java.awt; |
41 |
|
|
42 |
|
import java.awt.event.ComponentListener; |
43 |
import java.awt.event.ContainerEvent; |
import java.awt.event.ContainerEvent; |
44 |
import java.awt.event.ContainerListener; |
import java.awt.event.ContainerListener; |
45 |
import java.awt.event.KeyEvent; |
import java.awt.event.KeyEvent; |
422 |
{ |
{ |
423 |
Component r = component[index]; |
Component r = component[index]; |
424 |
|
|
425 |
|
ComponentListener[] list = r.getComponentListeners(); |
426 |
|
for (int j = 0; j < list.length; j++) |
427 |
|
r.removeComponentListener(list[j]); |
428 |
|
|
429 |
r.removeNotify(); |
r.removeNotify(); |
430 |
|
|
431 |
System.arraycopy(component, index + 1, component, index, |
System.arraycopy(component, index + 1, component, index, |
1054 |
return this; |
return this; |
1055 |
} |
} |
1056 |
} |
} |
1057 |
|
|
1058 |
|
/** |
1059 |
|
* Finds the visible child component that contains the specified position. |
1060 |
|
* The top-most child is returned in the case where there is overlap. |
1061 |
|
* If the top-most child is transparent and has no MouseListeners attached, |
1062 |
|
* we discard it and return the next top-most component containing the |
1063 |
|
* specified position. |
1064 |
|
* @param x the x coordinate |
1065 |
|
* @param y the y coordinate |
1066 |
|
* @return null if the <code>this</code> does not contain the position, |
1067 |
|
* otherwise the top-most component (out of this container itself and |
1068 |
|
* its descendants) meeting the criteria above. |
1069 |
|
*/ |
1070 |
|
Component findComponentForMouseEventAt(int x, int y) |
1071 |
|
{ |
1072 |
|
synchronized (getTreeLock()) |
1073 |
|
{ |
1074 |
|
if (!contains(x, y)) |
1075 |
|
return null; |
1076 |
|
|
1077 |
|
for (int i = 0; i < ncomponents; ++i) |
1078 |
|
{ |
1079 |
|
// Ignore invisible children... |
1080 |
|
if (!component[i].isVisible()) |
1081 |
|
continue; |
1082 |
|
|
1083 |
|
int x2 = x - component[i].x; |
1084 |
|
int y2 = y - component[i].y; |
1085 |
|
// We don't do the contains() check right away because |
1086 |
|
// findComponentAt would redundantly do it first thing. |
1087 |
|
if (component[i] instanceof Container) |
1088 |
|
{ |
1089 |
|
Container k = (Container) component[i]; |
1090 |
|
Component r = k.findComponentForMouseEventAt(x2, y2); |
1091 |
|
if (r != null) |
1092 |
|
return r; |
1093 |
|
} |
1094 |
|
else if (component[i].contains(x2, y2)) |
1095 |
|
return component[i]; |
1096 |
|
} |
1097 |
|
|
1098 |
|
//don't return transparent components with no MouseListeners |
1099 |
|
if (this.getMouseListeners().length == 0) |
1100 |
|
return null; |
1101 |
|
return this; |
1102 |
|
} |
1103 |
|
} |
1104 |
|
|
1105 |
public Component findComponentAt(Point p) |
public Component findComponentAt(Point p) |
1106 |
{ |
{ |
2011 |
eventMask |= l; |
eventMask |= l; |
2012 |
} |
} |
2013 |
|
|
2014 |
|
/** |
2015 |
|
* Returns the deepest visible descendent of parent that contains the |
2016 |
|
* specified location and that is not transparent and MouseListener-less. |
2017 |
|
* @param parent the root component to begin the search |
2018 |
|
* @param x the x coordinate |
2019 |
|
* @param y the y coordinate |
2020 |
|
* @return null if <code>parent</code> doesn't contain the location, |
2021 |
|
* parent if parent is not a container or has no child that contains the |
2022 |
|
* location, otherwise the appropriate component from the conditions |
2023 |
|
* above. |
2024 |
|
*/ |
2025 |
|
Component getDeepestComponentForMouseEventAt ( |
2026 |
|
Component parent, int x, int y) |
2027 |
|
{ |
2028 |
|
if (parent == null || (! parent.contains(x, y))) |
2029 |
|
return null; |
2030 |
|
|
2031 |
|
if (! (parent instanceof Container)) |
2032 |
|
return parent; |
2033 |
|
|
2034 |
|
Container c = (Container) parent; |
2035 |
|
return c.findComponentForMouseEventAt(x, y); |
2036 |
|
} |
2037 |
|
|
2038 |
Component acquireComponentForMouseEvent(MouseEvent me) |
Component acquireComponentForMouseEvent(MouseEvent me) |
2039 |
{ |
{ |
2040 |
int x = me.getX (); |
int x = me.getX (); |
2048 |
while (candidate == null && parent != null) |
while (candidate == null && parent != null) |
2049 |
{ |
{ |
2050 |
candidate = |
candidate = |
2051 |
AWTUtilities.getDeepestComponentAt(parent, p.x, p.y); |
getDeepestComponentForMouseEventAt(parent, p.x, p.y); |
2052 |
if (candidate == null || (candidate.eventMask & me.getID()) == 0) |
if (candidate == null || (candidate.eventMask & me.getID()) == 0) |
2053 |
{ |
{ |
2054 |
candidate = null; |
candidate = null; |