In java.awt.Container we were not calling the ContainerPeer begin|
endLayout|validate() methods correctly. I fixed this with the attached
patch.
2006-10-18 Roman Kennke <[EMAIL PROTECTED]>
* java/awt/Container.java
(validateTree): Call ContainerPeer.begin|endLayout() rather than
begin|endValidate().
(validate): Call ContainerPeer.begin|endValidate() here.
Added some local vars to avoid NPEs.
/Roman
Index: java/awt/Container.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/Container.java,v
retrieving revision 1.109
diff -u -1 -5 -r1.109 Container.java
--- java/awt/Container.java 27 Sep 2006 21:00:07 -0000 1.109
+++ java/awt/Container.java 18 Oct 2006 09:38:29 -0000
@@ -31,30 +31,31 @@
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package java.awt;
import java.awt.event.ContainerEvent;
import java.awt.event.ContainerListener;
import java.awt.event.HierarchyEvent;
import java.awt.event.KeyEvent;
+import java.awt.event.MouseEvent;
import java.awt.peer.ComponentPeer;
import java.awt.peer.ContainerPeer;
import java.awt.peer.LightweightPeer;
import java.beans.PropertyChangeListener;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.Serializable;
import java.util.Collections;
import java.util.EventListener;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
@@ -593,95 +594,104 @@
public void invalidate()
{
super.invalidate();
if (layoutMgr != null && layoutMgr instanceof LayoutManager2)
{
LayoutManager2 lm2 = (LayoutManager2) layoutMgr;
lm2.invalidateLayout(this);
}
}
/**
* Re-lays out the components in this container.
*/
public void validate()
{
- synchronized (getTreeLock ())
+ ComponentPeer p = peer;
+ if (! valid && p != null)
{
- if (! isValid() && peer != null)
+ ContainerPeer cPeer = null;
+ if (p instanceof ContainerPeer)
+ cPeer = (ContainerPeer) peer;
+ synchronized (getTreeLock ())
{
+ if (cPeer != null)
+ cPeer.beginValidate();
validateTree();
+ valid = true;
+ if (cPeer != null)
+ cPeer.endValidate();
}
}
}
/**
* Recursively invalidates the container tree.
*/
private final void invalidateTree()
{
synchronized (getTreeLock())
{
for (int i = 0; i < ncomponents; i++)
{
Component comp = component[i];
if (comp instanceof Container)
((Container) comp).invalidateTree();
else if (comp.valid)
comp.invalidate();
}
if (valid)
invalidate();
}
}
/**
* Recursively validates the container tree, recomputing any invalid
* layouts.
*/
protected void validateTree()
{
- if (valid)
- return;
-
- ContainerPeer cPeer = null;
- if (peer instanceof ContainerPeer)
- {
- cPeer = (ContainerPeer) peer;
- cPeer.beginValidate();
- }
-
- doLayout ();
- for (int i = 0; i < ncomponents; ++i)
+ if (!valid)
{
- Component comp = component[i];
-
- if (comp instanceof Container && ! (comp instanceof Window)
- && ! comp.valid)
+ ContainerPeer cPeer = null;
+ if (peer instanceof ContainerPeer)
{
- ((Container) comp).validateTree();
+ cPeer = (ContainerPeer) peer;
+ cPeer.beginLayout();
}
- else
+
+ doLayout ();
+ for (int i = 0; i < ncomponents; ++i)
{
- comp.validate();
+ Component comp = component[i];
+
+ if (comp instanceof Container && ! (comp instanceof Window)
+ && ! comp.valid)
+ {
+ ((Container) comp).validateTree();
+ }
+ else
+ {
+ comp.validate();
+ }
}
- }
- if (peer instanceof ContainerPeer)
- {
- cPeer = (ContainerPeer) peer;
- cPeer.endValidate();
+ if (cPeer != null)
+ {
+ cPeer = (ContainerPeer) peer;
+ cPeer.endLayout();
+ }
}
/* children will call invalidate() when they are layed out. It
is therefore important that valid is not set to true
until after the children have been layed out. */
valid = true;
}
public void setFont(Font f)
{
Font oldFont = getFont();
super.setFont(f);
Font newFont = getFont();
if (newFont != oldFont && (oldFont == null || ! oldFont.equals(newFont)))