1047 |
return this; |
return this; |
1048 |
} |
} |
1049 |
} |
} |
1050 |
|
|
1051 |
|
/** |
1052 |
|
* Finds the visible child component that contains the specified position. |
1053 |
|
* The top-most child is returned in the case where there is overlap. |
1054 |
|
* If the top-most child is transparent and has no MouseListeners attached, |
1055 |
|
* we discard it and return the next top-most component containing the |
1056 |
|
* specified position. |
1057 |
|
* @param x the x coordinate |
1058 |
|
* @param y the y coordinate |
1059 |
|
* @return null if the <code>this</code> does not contain the position, |
1060 |
|
* otherwise the top-most component (out of this container itself and |
1061 |
|
* its descendants) meeting the criteria above. |
1062 |
|
*/ |
1063 |
|
public Component findComponentForMouseEventAt(int x, int y) |
1064 |
|
{ |
1065 |
|
synchronized (getTreeLock()) |
1066 |
|
{ |
1067 |
|
if (!contains(x, y)) |
1068 |
|
return null; |
1069 |
|
|
1070 |
|
for (int i = 0; i < ncomponents; ++i) |
1071 |
|
{ |
1072 |
|
// Ignore invisible children... |
1073 |
|
if (!component[i].isVisible()) |
1074 |
|
continue; |
1075 |
|
|
1076 |
|
int x2 = x - component[i].x; |
1077 |
|
int y2 = y - component[i].y; |
1078 |
|
// We don't do the contains() check right away because |
1079 |
|
// findComponentAt would redundantly do it first thing. |
1080 |
|
if (component[i] instanceof Container) |
1081 |
|
{ |
1082 |
|
Container k = (Container) component[i]; |
1083 |
|
Component r = k.findComponentForMouseEventAt(x2, y2); |
1084 |
|
if (r != null) |
1085 |
|
return r; |
1086 |
|
} |
1087 |
|
else if (component[i].contains(x2, y2)) |
1088 |
|
return component[i]; |
1089 |
|
} |
1090 |
|
|
1091 |
|
//don't return transparent components with no MouseListeners |
1092 |
|
if (!this.isOpaque() && this.getMouseListeners().length == 0) |
1093 |
|
return null; |
1094 |
|
return this; |
1095 |
|
} |
1096 |
|
} |
1097 |
|
|
1098 |
public Component findComponentAt(Point p) |
public Component findComponentAt(Point p) |
1099 |
{ |
{ |
2002 |
eventMask |= l; |
eventMask |= l; |
2003 |
} |
} |
2004 |
|
|
2005 |
|
/** |
2006 |
|
* Returns the deepest visible descendent of parent that contains the |
2007 |
|
* specified location and that is not transparent and MouseListener-less. |
2008 |
|
* @param parent the root component to begin the search |
2009 |
|
* @param x the x coordinate |
2010 |
|
* @param y the y coordinate |
2011 |
|
* @return null if <code>parent</code> doesn't contain the location, |
2012 |
|
* parent if parent is not a container or has no child that contains the |
2013 |
|
* location, otherwise the appropriate component from the conditions |
2014 |
|
* above. |
2015 |
|
*/ |
2016 |
|
public static Component getDeepestComponentForMouseEventAt ( |
2017 |
|
Component parent, int x, int y) |
2018 |
|
{ |
2019 |
|
if (parent == null || (! parent.contains(x, y))) |
2020 |
|
return null; |
2021 |
|
|
2022 |
|
if (! (parent instanceof Container)) |
2023 |
|
return parent; |
2024 |
|
|
2025 |
|
Container c = (Container) parent; |
2026 |
|
return c.findComponentForMouseEventAt(x, y); |
2027 |
|
} |
2028 |
|
|
2029 |
Component acquireComponentForMouseEvent(MouseEvent me) |
Component acquireComponentForMouseEvent(MouseEvent me) |
2030 |
{ |
{ |
2031 |
int x = me.getX (); |
int x = me.getX (); |
2039 |
while (candidate == null && parent != null) |
while (candidate == null && parent != null) |
2040 |
{ |
{ |
2041 |
candidate = |
candidate = |
2042 |
AWTUtilities.getDeepestComponentAt(parent, p.x, p.y); |
getDeepestComponentForMouseEventAt(parent, p.x, p.y); |
2043 |
if (candidate == null || (candidate.eventMask & me.getID()) == 0) |
if (candidate == null || (candidate.eventMask & me.getID()) == 0) |
2044 |
{ |
{ |
2045 |
candidate = null; |
candidate = null; |