Container.java (validate): Use tree lock.

* java/awt/Container.java (validate): Use tree lock.
	(getComponent): Likewise.
	(getComponents): Likewise.
	(addImpl): Likewise.
	(remove): Likewise.
	(removeAll): Likewise.
	(processEvent): Fixed indentation.
	(getComponentAt): Use tree lock.
	(findComponentAt): Likewise.
	(removeNotify): Likewise.
	(isAncestorOf): Likewise.
	(list): Likewise.
	(visitChildren): Likewise.
	(findNextFocusComponent): Likewise.
	(addNotifyContainerChildren): Likewise.
	(getAccessibleChildrenCount): Likewise.
	(getAccessibleChild): Likewise.

From-SVN: r59009
This commit is contained in:
Tom Tromey 2002-11-11 06:33:08 +00:00 committed by Tom Tromey
parent f981a754fc
commit 459c4c517e
2 changed files with 275 additions and 208 deletions

View file

@ -1,5 +1,23 @@
2002-11-10 Tom Tromey <tromey@redhat.com> 2002-11-10 Tom Tromey <tromey@redhat.com>
* java/awt/Container.java (validate): Use tree lock.
(getComponent): Likewise.
(getComponents): Likewise.
(addImpl): Likewise.
(remove): Likewise.
(removeAll): Likewise.
(processEvent): Fixed indentation.
(getComponentAt): Use tree lock.
(findComponentAt): Likewise.
(removeNotify): Likewise.
(isAncestorOf): Likewise.
(list): Likewise.
(visitChildren): Likewise.
(findNextFocusComponent): Likewise.
(addNotifyContainerChildren): Likewise.
(getAccessibleChildrenCount): Likewise.
(getAccessibleChild): Likewise.
* java/awt/GridLayout.java (layoutContainer): Use tree lock. * java/awt/GridLayout.java (layoutContainer): Use tree lock.
(getSize): Likewise. (getSize): Likewise.
* java/awt/FlowLayout.java (layoutContainer): Use tree lock. * java/awt/FlowLayout.java (layoutContainer): Use tree lock.

View file

@ -122,11 +122,14 @@ public class Container extends Component
* @throws ArrayIndexOutOfBoundsException If the specified index is invalid * @throws ArrayIndexOutOfBoundsException If the specified index is invalid
*/ */
public Component getComponent(int n) public Component getComponent(int n)
{
synchronized (getTreeLock ())
{ {
if (n < 0 || n >= ncomponents) if (n < 0 || n >= ncomponents)
throw new ArrayIndexOutOfBoundsException("no such component"); throw new ArrayIndexOutOfBoundsException("no such component");
return component[n]; return component[n];
} }
}
/** /**
* Returns an array of the components in this container. * Returns an array of the components in this container.
@ -134,12 +137,15 @@ public class Container extends Component
* @return The components in this container. * @return The components in this container.
*/ */
public Component[] getComponents() public Component[] getComponents()
{
synchronized (getTreeLock ())
{ {
Component[] result = new Component[ncomponents]; Component[] result = new Component[ncomponents];
if (ncomponents > 0) if (ncomponents > 0)
System.arraycopy(component, 0, result, 0, ncomponents); System.arraycopy(component, 0, result, 0, ncomponents);
return result; return result;
} }
}
/** /**
* Returns the insets for this container, which is the space used for * Returns the insets for this container, which is the space used for
@ -259,6 +265,8 @@ public class Container extends Component
* @throws ArrayIndexOutOfBounds If the specified index is invalid. * @throws ArrayIndexOutOfBounds If the specified index is invalid.
*/ */
protected void addImpl(Component comp, Object constraints, int index) protected void addImpl(Component comp, Object constraints, int index)
{
synchronized (getTreeLock ())
{ {
if (index > ncomponents if (index > ncomponents
|| (index < 0 && index != -1) || (index < 0 && index != -1)
@ -324,6 +332,7 @@ public class Container extends Component
comp); comp);
getToolkit().getSystemEventQueue().postEvent(ce); getToolkit().getSystemEventQueue().postEvent(ce);
} }
}
/** /**
* Removes the component at the specified index from this container. * Removes the component at the specified index from this container.
@ -331,6 +340,8 @@ public class Container extends Component
* @param index The index of the component to remove. * @param index The index of the component to remove.
*/ */
public void remove(int index) public void remove(int index)
{
synchronized (getTreeLock ())
{ {
Component r = component[index]; Component r = component[index];
@ -351,6 +362,7 @@ public class Container extends Component
r); r);
getToolkit().getSystemEventQueue().postEvent(ce); getToolkit().getSystemEventQueue().postEvent(ce);
} }
}
/** /**
* Removes the specified component from this container. * Removes the specified component from this container.
@ -358,6 +370,8 @@ public class Container extends Component
* @return component The component to remove from this container. * @return component The component to remove from this container.
*/ */
public void remove(Component comp) public void remove(Component comp)
{
synchronized (getTreeLock ())
{ {
for (int i = 0; i < ncomponents; ++i) for (int i = 0; i < ncomponents; ++i)
{ {
@ -368,15 +382,19 @@ public class Container extends Component
} }
} }
} }
}
/** /**
* Removes all components from this container. * Removes all components from this container.
*/ */
public void removeAll() public void removeAll()
{
synchronized (getTreeLock ())
{ {
while (ncomponents > 0) while (ncomponents > 0)
remove(0); remove(0);
} }
}
/** /**
* Returns the current layout manager for this container. * Returns the current layout manager for this container.
@ -433,8 +451,7 @@ public class Container extends Component
*/ */
public void validate() public void validate()
{ {
// FIXME: use the tree lock? synchronized (getTreeLock ())
synchronized (this)
{ {
if (! isValid()) if (! isValid())
{ {
@ -713,7 +730,8 @@ public class Container extends Component
{ {
if (e instanceof ContainerEvent) if (e instanceof ContainerEvent)
processContainerEvent((ContainerEvent) e); processContainerEvent((ContainerEvent) e);
else super.processEvent(e); else
super.processEvent(e);
} }
/** /**
@ -763,6 +781,8 @@ public class Container extends Component
* <code>null</code> if there is no such point. * <code>null</code> if there is no such point.
*/ */
public Component getComponentAt(int x, int y) public Component getComponentAt(int x, int y)
{
synchronized (getTreeLock ())
{ {
if (! contains(x, y)) if (! contains(x, y))
return null; return null;
@ -779,6 +799,7 @@ public class Container extends Component
} }
return this; return this;
} }
}
/** /**
* Returns the component located at the specified point. This is done * Returns the component located at the specified point. This is done
@ -817,6 +838,8 @@ public class Container extends Component
} }
public Component findComponentAt(int x, int y) public Component findComponentAt(int x, int y)
{
synchronized (getTreeLock ())
{ {
if (! contains(x, y)) if (! contains(x, y))
return null; return null;
@ -844,6 +867,7 @@ public class Container extends Component
return this; return this;
} }
}
public Component findComponentAt(Point p) public Component findComponentAt(Point p)
{ {
@ -867,11 +891,14 @@ public class Container extends Component
* component to be destroyed as well. * component to be destroyed as well.
*/ */
public void removeNotify() public void removeNotify()
{
synchronized (getTreeLock ())
{ {
for (int i = 0; i < ncomponents; ++i) for (int i = 0; i < ncomponents; ++i)
component[i].removeNotify(); component[i].removeNotify();
super.removeNotify(); super.removeNotify();
} }
}
/** /**
* Tests whether or not the specified component is contained within * Tests whether or not the specified component is contained within
@ -880,9 +907,11 @@ public class Container extends Component
* @param component The component to test. * @param component The component to test.
* *
* @return <code>true</code> if this container is an ancestor of the * @return <code>true</code> if this container is an ancestor of the
* specified component, <code>false</code>. * specified component, <code>false</code> otherwise.
*/ */
public boolean isAncestorOf(Component comp) public boolean isAncestorOf(Component comp)
{
synchronized (getTreeLock ())
{ {
while (true) while (true)
{ {
@ -893,6 +922,7 @@ public class Container extends Component
comp = comp.getParent(); comp = comp.getParent();
} }
} }
}
/** /**
* Returns a string representing the state of this container for * Returns a string representing the state of this container for
@ -917,11 +947,14 @@ public class Container extends Component
* @param indent The indentation point. * @param indent The indentation point.
*/ */
public void list(PrintStream out, int indent) public void list(PrintStream out, int indent)
{
synchronized (getTreeLock ())
{ {
super.list(out, indent); super.list(out, indent);
for (int i = 0; i < ncomponents; ++i) for (int i = 0; i < ncomponents; ++i)
component[i].list(out, indent + 2); component[i].list(out, indent + 2);
} }
}
/** /**
* Writes a listing of this container to the specified stream starting * Writes a listing of this container to the specified stream starting
@ -931,11 +964,14 @@ public class Container extends Component
* @param indent The indentation point. * @param indent The indentation point.
*/ */
public void list(PrintWriter out, int indent) public void list(PrintWriter out, int indent)
{
synchronized (getTreeLock ())
{ {
super.list(out, indent); super.list(out, indent);
for (int i = 0; i < ncomponents; ++i) for (int i = 0; i < ncomponents; ++i)
component[i].list(out, indent + 2); component[i].list(out, indent + 2);
} }
}
public void setFocusTraversalKeys(int id, Set keys) public void setFocusTraversalKeys(int id, Set keys)
{ {
@ -1006,8 +1042,8 @@ public class Container extends Component
private void visitChildren(Graphics gfx, GfxVisitor visitor, private void visitChildren(Graphics gfx, GfxVisitor visitor,
boolean lightweightOnly) boolean lightweightOnly)
{ {
// FIXME: do locking synchronized (getTreeLock ())
{
for (int i = 0; i < ncomponents; ++i) for (int i = 0; i < ncomponents; ++i)
{ {
Component comp = component[i]; Component comp = component[i];
@ -1018,6 +1054,7 @@ public class Container extends Component
visitChild(gfx, visitor, comp); visitChild(gfx, visitor, comp);
} }
} }
}
/** /**
* Perform a graphics operation on a child. A translated and clipped * Perform a graphics operation on a child. A translated and clipped
@ -1060,6 +1097,8 @@ public class Container extends Component
// This is used to implement Component.transferFocus. // This is used to implement Component.transferFocus.
Component findNextFocusComponent(Component child) Component findNextFocusComponent(Component child)
{
synchronized (getTreeLock ())
{ {
int start, end; int start, end;
if (child != null) if (child != null)
@ -1106,8 +1145,11 @@ public class Container extends Component
return null; return null;
} }
}
private void addNotifyContainerChildren() private void addNotifyContainerChildren()
{
synchronized (getTreeLock ())
{ {
for (int i = ncomponents; --i >= 0; ) for (int i = ncomponents; --i >= 0; )
{ {
@ -1116,6 +1158,7 @@ public class Container extends Component
enableEvents(component[i].eventMask); enableEvents(component[i].eventMask);
} }
} }
}
// Nested classes. // Nested classes.
@ -1189,6 +1232,8 @@ public class Container extends Component
* @return the number of accessible children * @return the number of accessible children
*/ */
public int getAccessibleChildrenCount() public int getAccessibleChildrenCount()
{
synchronized (getTreeLock ())
{ {
int count = 0; int count = 0;
int i = component == null ? 0 : component.length; int i = component == null ? 0 : component.length;
@ -1197,6 +1242,7 @@ public class Container extends Component
count++; count++;
return count; return count;
} }
}
/** /**
* Return the nth accessible child of the containing accessible object. * Return the nth accessible child of the containing accessible object.
@ -1205,6 +1251,8 @@ public class Container extends Component
* @return the accessible child, or null * @return the accessible child, or null
*/ */
public Accessible getAccessibleChild(int i) public Accessible getAccessibleChild(int i)
{
synchronized (getTreeLock ())
{ {
if (component == null) if (component == null)
return null; return null;
@ -1216,6 +1264,7 @@ public class Container extends Component
return (Accessible) component[index]; return (Accessible) component[index];
return null; return null;
} }
}
/** /**
* Return the accessible child located at point (in the parent's * Return the accessible child located at point (in the parent's