This fixes a problem in the lightweight dispatcher, when it dispatches
events for no-more showing components. This lead to occasional glitches
in Swing GUIs.
2007-09-21 Roman Kennke <[EMAIL PROTECTED]>
* java/awt/LightweightDispatcher.java
(dispatchEvent): Lock the component's tree to avoid threading
problems.
(redispatch): Only redispatch when component is showing.
/Roman
--
Dipl.-Inform. (FH) Roman Kennke, Software Engineer, http://kennke.org
aicas Allerton Interworks Computer Automated Systems GmbH
Haid-und-Neu-Straße 18 * D-76131 Karlsruhe * Germany
http://www.aicas.com * Tel: +49-721-663 968-0
USt-Id: DE216375633, Handelsregister HRB 109481, AG Karlsruhe
Geschäftsführer: Dr. James J. Hunt
Index: java/awt/LightweightDispatcher.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/LightweightDispatcher.java,v
retrieving revision 1.17
diff -u -1 -0 -r1.17 LightweightDispatcher.java
--- java/awt/LightweightDispatcher.java 10 Oct 2006 15:29:04 -0000 1.17
+++ java/awt/LightweightDispatcher.java 21 Sep 2007 08:37:49 -0000
@@ -105,21 +105,29 @@
/**
* Receives notification if a mouse event passes along the eventqueue.
*
* @param event the event
*/
public boolean dispatchEvent(final AWTEvent event)
{
if (event instanceof MouseEvent)
{
MouseEvent mouseEvent = (MouseEvent) event;
- return handleMouseEvent(mouseEvent);
+ /**
+ * The lightweight dispatching relies on the integrity of the
+ * component tree (e.g. isShowing(), getLocationOnScreen(), etc),
+ * therefore we must synchronize on the tree lock here.
+ */
+ synchronized (mouseEvent.getComponent().getTreeLock())
+ {
+ return handleMouseEvent(mouseEvent);
+ }
}
return false;
}
/**
* Handles all mouse events that are targetted at toplevel containers
* (Window instances) and dispatches them to the correct lightweight child.
*
* @param ev the mouse event
* @return whether or not we found a lightweight that handled the event.
@@ -279,21 +287,22 @@
* Redispatches the specified mouse event to the specified target with the
* specified id.
*
* @param ev the mouse event
* @param target the new target
* @param id the new id
*/
private void redispatch(MouseEvent ev, Component target, int id)
{
Component source = ev.getComponent();
- if (target != null)
+ assert target != null;
+ if (target.isShowing())
{
// Translate coordinates.
int x = ev.getX();
int y = ev.getY();
for (Component c = target; c != null && c != source; c = c.getParent())
{
x -= c.x;
y -= c.y;
}