41 |
import java.awt.event.ContainerEvent; |
import java.awt.event.ContainerEvent; |
42 |
import java.awt.event.ContainerListener; |
import java.awt.event.ContainerListener; |
43 |
import java.awt.event.MouseEvent; |
import java.awt.event.MouseEvent; |
44 |
|
import java.awt.event.KeyEvent; |
45 |
import java.awt.peer.ContainerPeer; |
import java.awt.peer.ContainerPeer; |
46 |
import java.awt.peer.LightweightPeer; |
import java.awt.peer.LightweightPeer; |
47 |
import java.beans.PropertyChangeListener; |
import java.beans.PropertyChangeListener; |
1226 |
Component comp) |
Component comp) |
1227 |
{ |
{ |
1228 |
Rectangle bounds = comp.getBounds(); |
Rectangle bounds = comp.getBounds(); |
1229 |
Rectangle clip = gfx.getClipBounds(); |
Rectangle oldClip = gfx.getClipBounds(); |
1230 |
if (clip == null) |
if (oldClip == null) |
1231 |
clip = bounds; |
oldClip = bounds; |
1232 |
else |
Rectangle clip = oldClip.intersection(bounds); |
|
clip = clip.intersection(bounds); |
|
1233 |
|
|
1234 |
if (clip.isEmpty()) return; |
if (clip.isEmpty()) return; |
1235 |
|
|
1236 |
Graphics gfx2 = gfx.create(); |
boolean clipped = false; |
1237 |
|
boolean translated = false; |
1238 |
try |
try |
1239 |
{ |
{ |
1240 |
gfx2.setClip(clip.x, clip.y, clip.width, clip.height); |
gfx.setClip(clip.x, clip.y, clip.width, clip.height); |
1241 |
gfx2.translate(bounds.x, bounds.y); |
clipped = true; |
1242 |
|
gfx.translate(bounds.x, bounds.y); |
1243 |
visitor.visit(comp, gfx2); |
translated = true; |
1244 |
|
visitor.visit(comp, gfx); |
1245 |
} |
} |
1246 |
finally |
finally |
1247 |
{ |
{ |
1248 |
gfx2.dispose (); |
if (translated) |
1249 |
|
gfx.translate (-bounds.x, -bounds.y); |
1250 |
|
if (clipped) |
1251 |
|
gfx.setClip (oldClip.x, oldClip.y, oldClip.width, oldClip.height); |
1252 |
} |
} |
1253 |
} |
} |
1254 |
|
|
1255 |
void dispatchEventImpl(AWTEvent e) |
void dispatchEventImpl(AWTEvent e) |
1256 |
{ |
{ |
1257 |
|
// Give lightweight dispatcher a chance to handle it. |
1258 |
|
if (dispatcher != null |
1259 |
|
&& dispatcher.handleEvent (e)) |
1260 |
|
return; |
1261 |
|
|
1262 |
if ((e.id <= ContainerEvent.CONTAINER_LAST |
if ((e.id <= ContainerEvent.CONTAINER_LAST |
1263 |
&& e.id >= ContainerEvent.CONTAINER_FIRST) |
&& e.id >= ContainerEvent.CONTAINER_FIRST) |
1264 |
&& (containerListener != null |
&& (containerListener != null |
1265 |
|| (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0)) |
|| (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0)) |
1266 |
processEvent(e); |
processEvent(e); |
1328 |
{ |
{ |
1329 |
component[i].addNotify(); |
component[i].addNotify(); |
1330 |
if (component[i].isLightweight ()) |
if (component[i].isLightweight ()) |
1331 |
{ |
{ |
1332 |
enableEvents(component[i].eventMask); |
|
1333 |
if (peer != null && !isLightweight ()) |
// If we're not lightweight, and we just got a lightweight |
1334 |
enableEvents (AWTEvent.PAINT_EVENT_MASK); |
// child, we need a lightweight dispatcher to feed it events. |
1335 |
} |
if (! this.isLightweight() |
1336 |
|
&& dispatcher == null) |
1337 |
|
{ |
1338 |
|
dispatcher = new LightweightDispatcher (this); |
1339 |
|
dispatcher.enableEvents (component[i].eventMask); |
1340 |
|
} |
1341 |
|
|
1342 |
|
|
1343 |
|
enableEvents(component[i].eventMask); |
1344 |
|
if (peer != null && !isLightweight ()) |
1345 |
|
enableEvents (AWTEvent.PAINT_EVENT_MASK); |
1346 |
|
} |
1347 |
} |
} |
1348 |
} |
} |
1349 |
} |
} |
1516 |
} // class Container |
} // class Container |
1517 |
|
|
1518 |
/** |
/** |
1519 |
* Undocumented helper class. |
* There is a helper class implied from stack traces called |
1520 |
* STUBBED |
* LightweightDispatcher, but since it is not part of the public API, |
1521 |
|
* rather than mimic it exactly we write something which does "roughly |
1522 |
|
* the same thing". |
1523 |
*/ |
*/ |
1524 |
class LightweightDispatcher implements Serializable, AWTEventListener |
|
1525 |
|
class LightweightDispatcher implements Serializable |
1526 |
{ |
{ |
1527 |
private static final long serialVersionUID = 5184291520170872969L; |
private static final long serialVersionUID = 5184291520170872969L; |
1528 |
private Container nativeContainer; |
private Container nativeContainer; |
1529 |
private Component focus; |
private Component focus; |
|
private transient Component mouseEventTarget; |
|
|
private transient Component targetLastEntered; |
|
|
private transient boolean isMouseInNativeContainer; |
|
1530 |
private Cursor nativeCursor; |
private Cursor nativeCursor; |
1531 |
private long eventMask; |
private long eventMask; |
1532 |
|
|
1533 |
|
private transient Component mouseEventTarget; |
1534 |
|
|
1535 |
LightweightDispatcher(Container c) |
LightweightDispatcher(Container c) |
1536 |
{ |
{ |
1537 |
|
nativeContainer = c; |
1538 |
} |
} |
1539 |
|
|
1540 |
void dispose() |
void dispose() |
1543 |
|
|
1544 |
void enableEvents(long l) |
void enableEvents(long l) |
1545 |
{ |
{ |
1546 |
|
eventMask |= l; |
1547 |
} |
} |
1548 |
|
|
1549 |
boolean dispatchEvent(AWTEvent e) |
void mouseExit (MouseEvent me, int x, int y) |
|
{ |
|
|
return true; |
|
|
} |
|
|
|
|
|
boolean isMouseGrab(MouseEvent e) |
|
1550 |
{ |
{ |
|
return true; |
|
1551 |
} |
} |
1552 |
|
|
1553 |
boolean processMouseEvent(MouseEvent e) |
void acquireComponentForMouseEvent (MouseEvent me) |
1554 |
{ |
{ |
1555 |
return true; |
int x = me.getX (); |
1556 |
} |
int y = me.getY (); |
1557 |
|
|
1558 |
void trackMouseEnterExit(Component c, MouseEvent e) |
Component candidate = mouseEventTarget; |
|
{ |
|
|
} |
|
1559 |
|
|
1560 |
void startListeningForOtherDrags() |
boolean candidate_is_container_with_children = |
1561 |
{ |
((candidate != null) |
1562 |
|
&& (candidate instanceof Container) |
1563 |
|
&& (((Container)candidate).getComponentCount () > 0)); |
1564 |
|
|
1565 |
|
boolean candidate_does_not_contain_point = |
1566 |
|
((candidate != null) |
1567 |
|
&& (! candidate.contains (x - candidate.getX (), |
1568 |
|
y - candidate.getY ()))); |
1569 |
|
|
1570 |
|
if (candidate == null |
1571 |
|
|| candidate_is_container_with_children |
1572 |
|
|| candidate_does_not_contain_point) |
1573 |
|
{ |
1574 |
|
// Try to reacquire. |
1575 |
|
candidate = nativeContainer.findComponentAt (x, y); |
1576 |
|
} |
1577 |
|
|
1578 |
|
if (mouseEventTarget != null |
1579 |
|
&& mouseEventTarget != candidate) |
1580 |
|
{ |
1581 |
|
int nx = x - mouseEventTarget.getX (); |
1582 |
|
int ny = y - mouseEventTarget.getY (); |
1583 |
|
MouseEvent exited = new MouseEvent (mouseEventTarget, |
1584 |
|
MouseEvent.MOUSE_EXITED, |
1585 |
|
me.getWhen (), |
1586 |
|
me.getModifiers (), |
1587 |
|
nx, ny, |
1588 |
|
me.getClickCount (), |
1589 |
|
me.isPopupTrigger (), |
1590 |
|
me.getButton ()); |
1591 |
|
mouseEventTarget.dispatchEvent (exited); |
1592 |
|
mouseEventTarget = null; |
1593 |
|
} |
1594 |
|
|
1595 |
|
if (candidate != null) |
1596 |
|
{ |
1597 |
|
// Possibly set new state. |
1598 |
|
if (candidate.isLightweight() |
1599 |
|
&& candidate != nativeContainer |
1600 |
|
&& candidate != mouseEventTarget) |
1601 |
|
{ |
1602 |
|
|
1603 |
|
mouseEventTarget = candidate; |
1604 |
|
|
1605 |
|
int nx = x - mouseEventTarget.getX (); |
1606 |
|
int ny = y - mouseEventTarget.getY (); |
1607 |
|
|
1608 |
|
// If acquired, enter it. |
1609 |
|
MouseEvent entered = new MouseEvent (mouseEventTarget, |
1610 |
|
MouseEvent.MOUSE_ENTERED, |
1611 |
|
me.getWhen (), |
1612 |
|
me.getModifiers (), |
1613 |
|
nx, ny, |
1614 |
|
me.getClickCount (), |
1615 |
|
me.isPopupTrigger (), |
1616 |
|
me.getButton ()); |
1617 |
|
mouseEventTarget.dispatchEvent (entered); |
1618 |
|
} |
1619 |
|
} |
1620 |
} |
} |
1621 |
|
|
1622 |
void stopListeningForOtherDrags() |
boolean handleEvent (AWTEvent e) |
1623 |
{ |
{ |
1624 |
} |
if ((eventMask & e.getID ()) == 0) |
1625 |
|
return false; |
1626 |
|
|
1627 |
|
if (e instanceof MouseEvent) |
1628 |
|
{ |
1629 |
|
MouseEvent me = (MouseEvent) e; |
1630 |
|
acquireComponentForMouseEvent (me); |
1631 |
|
|
1632 |
public void eventDispatched(AWTEvent e) |
if (mouseEventTarget != null) |
1633 |
{ |
{ |
1634 |
|
Component oldSource = (Component) me.getSource (); |
1635 |
|
me.setSource (mouseEventTarget); |
1636 |
|
mouseEventTarget.dispatchEvent (me); |
1637 |
|
me.setSource (oldSource); |
1638 |
|
} |
1639 |
|
} |
1640 |
|
else if (e instanceof KeyEvent && focus != null) |
1641 |
|
{ |
1642 |
|
focus.processKeyEvent ((KeyEvent) e); |
1643 |
|
} |
1644 |
|
|
1645 |
|
return e.isConsumed(); |
1646 |
} |
} |
1647 |
|
|
|
void retargetMouseEvent(Component c, int i, MouseEvent e) |
|
|
{ |
|
|
} |
|
1648 |
} // class LightweightDispatcher |
} // class LightweightDispatcher |