Commit 459c4c51 by Tom Tromey Committed by Tom Tromey

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
parent f981a754
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.
......
...@@ -123,10 +123,13 @@ public class Container extends Component ...@@ -123,10 +123,13 @@ public class Container extends Component
*/ */
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.
...@@ -135,11 +138,14 @@ public class Container extends Component ...@@ -135,11 +138,14 @@ public class Container extends Component
*/ */
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
...@@ -260,6 +266,8 @@ public class Container extends Component ...@@ -260,6 +266,8 @@ public class Container extends Component
*/ */
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)
|| comp instanceof Window || comp instanceof Window
...@@ -324,6 +332,7 @@ public class Container extends Component ...@@ -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.
...@@ -332,6 +341,8 @@ public class Container extends Component ...@@ -332,6 +341,8 @@ public class Container extends Component
*/ */
public void remove(int index) public void remove(int index)
{ {
synchronized (getTreeLock ())
{
Component r = component[index]; Component r = component[index];
r.removeNotify(); r.removeNotify();
...@@ -351,6 +362,7 @@ public class Container extends Component ...@@ -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.
...@@ -359,6 +371,8 @@ public class Container extends Component ...@@ -359,6 +371,8 @@ public class Container extends Component
*/ */
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)
{ {
if (component[i] == comp) if (component[i] == comp)
...@@ -368,15 +382,19 @@ public class Container extends Component ...@@ -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 ...@@ -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 ...@@ -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);
} }
/** /**
...@@ -764,6 +782,8 @@ public class Container extends Component ...@@ -764,6 +782,8 @@ public class Container extends Component
*/ */
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;
for (int i = 0; i < ncomponents; ++i) for (int i = 0; i < ncomponents; ++i)
...@@ -779,6 +799,7 @@ public class Container extends Component ...@@ -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
...@@ -818,6 +839,8 @@ public class Container extends Component ...@@ -818,6 +839,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 ...@@ -844,6 +867,7 @@ public class Container extends Component
return this; return this;
} }
}
public Component findComponentAt(Point p) public Component findComponentAt(Point p)
{ {
...@@ -868,10 +892,13 @@ public class Container extends Component ...@@ -868,10 +892,13 @@ public class Container extends Component
*/ */
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,10 +907,12 @@ public class Container extends Component ...@@ -880,10 +907,12 @@ 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)
{ {
if (comp == null) if (comp == null)
...@@ -893,6 +922,7 @@ public class Container extends Component ...@@ -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
...@@ -918,10 +948,13 @@ public class Container extends Component ...@@ -918,10 +948,13 @@ public class Container extends Component
*/ */
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
...@@ -932,10 +965,13 @@ public class Container extends Component ...@@ -932,10 +965,13 @@ public class Container extends Component
*/ */
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 ...@@ -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 ...@@ -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
...@@ -1061,6 +1098,8 @@ public class Container extends Component ...@@ -1061,6 +1098,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,9 +1145,12 @@ public class Container extends Component ...@@ -1106,9 +1145,12 @@ 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; )
{ {
component[i].addNotify(); component[i].addNotify();
...@@ -1116,6 +1158,7 @@ public class Container extends Component ...@@ -1116,6 +1158,7 @@ public class Container extends Component
enableEvents(component[i].eventMask); enableEvents(component[i].eventMask);
} }
} }
}
// Nested classes. // Nested classes.
...@@ -1190,6 +1233,8 @@ public class Container extends Component ...@@ -1190,6 +1233,8 @@ public class Container extends Component
*/ */
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;
while (--i >= 0) while (--i >= 0)
...@@ -1197,6 +1242,7 @@ public class Container extends Component ...@@ -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.
...@@ -1206,6 +1252,8 @@ public class Container extends Component ...@@ -1206,6 +1252,8 @@ public class Container extends Component
*/ */
public Accessible getAccessibleChild(int i) public Accessible getAccessibleChild(int i)
{ {
synchronized (getTreeLock ())
{
if (component == null) if (component == null)
return null; return null;
int index = -1; int index = -1;
...@@ -1216,6 +1264,7 @@ public class Container extends Component ...@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment