Some more issues fixed that hurt with Espial/Espresso:
2006-09-20 Roman Kennke <[EMAIL PROTECTED]>
* java/awt/Container.java
(addImpl): Set the new component's parent after it has been
added to the array. Call addNotify() and invalidate()
after the component has been added, so that the peer
gets to know about the component structure when it is created.
* java/awt/Window.java
(dispatchEventImpl): Only revalidate when window is resized,
let the other stuff be processed by the superclass.
(dispose): Post WINDOW_CLOSED event only when some listener
is registered or event is explicitly enabled.
(show): Post WINDOW_OPENED event when appropriate.
/Roman
Index: java/awt/Container.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/Container.java,v
retrieving revision 1.106
diff -u -1 -5 -r1.106 Container.java
--- java/awt/Container.java 20 Sep 2006 09:12:25 -0000 1.106
+++ java/awt/Container.java 20 Sep 2006 12:35:08 -0000
@@ -311,100 +311,107 @@
protected void addImpl(Component comp, Object constraints, int index)
{
synchronized (getTreeLock ())
{
if (index > ncomponents
|| (index < 0 && index != -1)
|| comp instanceof Window
|| (comp instanceof Container
&& ((Container) comp).isAncestorOf(this)))
throw new IllegalArgumentException();
// Reparent component, and make sure component is instantiated if
// we are.
if (comp.parent != null)
comp.parent.remove(comp);
- comp.parent = this;
-
- if (peer != null)
- {
- // Notify the component that it has a new parent.
- comp.addNotify();
- }
-
- // Invalidate the layout of the added component and its ancestors.
- comp.invalidate();
if (component == null)
component = new Component[4]; // FIXME, better initial size?
// This isn't the most efficient implementation. We could do less
// copying when growing the array. It probably doesn't matter.
if (ncomponents >= component.length)
{
int nl = component.length * 2;
Component[] c = new Component[nl];
System.arraycopy(component, 0, c, 0, ncomponents);
component = c;
}
if (index == -1)
component[ncomponents++] = comp;
else
{
System.arraycopy(component, index, component, index + 1,
ncomponents - index);
component[index] = comp;
++ncomponents;
}
+ // Give the new component a parent.
+ comp.parent = this;
+
// Update the counter for Hierarchy(Bounds)Listeners.
int childHierarchyListeners = comp.numHierarchyListeners;
if (childHierarchyListeners > 0)
updateHierarchyListenerCount(AWTEvent.HIERARCHY_EVENT_MASK,
childHierarchyListeners);
int childHierarchyBoundsListeners = comp.numHierarchyBoundsListeners;
if (childHierarchyBoundsListeners > 0)
updateHierarchyListenerCount(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK,
childHierarchyListeners);
+ // Invalidate the layout of this container.
+ if (valid)
+ invalidate();
+
+ // Create the peer _after_ the component has been added, so that
+ // the peer gets to know about the component hierarchy.
+ if (peer != null)
+ {
+ // Notify the component that it has a new parent.
+ comp.addNotify();
+ }
+
// Notify the layout manager.
if (layoutMgr != null)
{
// If we have a LayoutManager2 the constraints are "real",
// otherwise they are the "name" of the Component to add.
if (layoutMgr instanceof LayoutManager2)
{
LayoutManager2 lm2 = (LayoutManager2) layoutMgr;
lm2.addLayoutComponent(comp, constraints);
}
else if (constraints instanceof String)
layoutMgr.addLayoutComponent((String) constraints, comp);
else
layoutMgr.addLayoutComponent("", comp);
}
// We previously only sent an event when this container is showing.
// Also, the event was posted to the event queue. A Mauve test shows
// that this event is not delivered using the event queue and it is
- // also sent when the container is not showing.
- ContainerEvent ce = new ContainerEvent(this,
- ContainerEvent.COMPONENT_ADDED,
- comp);
- ContainerListener[] listeners = getContainerListeners();
- for (int i = 0; i < listeners.length; i++)
- listeners[i].componentAdded(ce);
+ // also sent when the container is not showing.
+ if (containerListener != null
+ || (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0)
+ {
+ ContainerEvent ce = new ContainerEvent(this,
+ ContainerEvent.COMPONENT_ADDED,
+ comp);
+ dispatchEvent(ce);
+ }
// Notify hierarchy listeners.
comp.fireHierarchyEvent(HierarchyEvent.HIERARCHY_CHANGED, comp,
this, HierarchyEvent.PARENT_CHANGED);
}
}
/**
* Removes the component at the specified index from this container.
*
* @param index The index of the component to remove.
*/
public void remove(int index)
{
synchronized (getTreeLock ())
Index: java/awt/Window.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/Window.java,v
retrieving revision 1.74
diff -u -1 -5 -r1.74 Window.java
--- java/awt/Window.java 26 Jul 2006 19:09:50 -0000 1.74
+++ java/awt/Window.java 20 Sep 2006 12:35:09 -0000
@@ -128,31 +128,31 @@
visible = false;
// Windows are the only Containers that default to being focus
// cycle roots.
focusCycleRoot = true;
setLayout(new BorderLayout());
GraphicsEnvironment g = GraphicsEnvironment.getLocalGraphicsEnvironment();
graphicsConfiguration = g.getDefaultScreenDevice().getDefaultConfiguration();
}
Window(GraphicsConfiguration gc)
{
this();
graphicsConfiguration = gc;
}
-
+
/**
* Initializes a new instance of <code>Window</code> with the specified
* parent. The window will initially be invisible.
*
* @param owner The owning <code>Frame</code> of this window.
*
* @exception IllegalArgumentException If the owner's GraphicsConfiguration
* is not from a screen device, or if owner is null; this exception is always
* thrown when GraphicsEnvironment.isHeadless returns true.
*/
public Window(Frame owner)
{
this (owner, owner.getGraphicsConfiguration ());
}
@@ -243,32 +243,30 @@
addNotify();
setSize(getPreferredSize());
validate();
}
/**
* Shows on-screen this window and any of its owned windows for whom
* isVisible returns true.
*/
public void show()
{
synchronized (getTreeLock())
{
- if (parent != null && ! parent.isDisplayable())
- parent.addNotify();
if (peer == null)
addNotify();
validate();
if (visible)
toFront();
else
{
super.show();
// Show visible owned windows.
Iterator e = ownedWindows.iterator();
while (e.hasNext())
{
Window w = (Window) (((Reference) e.next()).get());
if (w != null)
@@ -286,30 +284,39 @@
}
KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
manager.setGlobalFocusedWindow(this);
if (! shown)
{
FocusTraversalPolicy policy = getFocusTraversalPolicy();
Component initialFocusOwner = null;
if (policy != null)
initialFocusOwner = policy.getInitialComponent(this);
if (initialFocusOwner != null)
initialFocusOwner.requestFocusInWindow();
+ // Post WINDOW_OPENED from here.
+ if (windowListener != null
+ || (eventMask & AWTEvent.WINDOW_EVENT_MASK) != 0)
+ {
+ WindowEvent ev = new WindowEvent(this,
+ WindowEvent.WINDOW_OPENED);
+ Toolkit tk = Toolkit.getDefaultToolkit();
+ tk.getSystemEventQueue().postEvent(ev);
+ }
shown = true;
}
}
}
public void hide()
{
// Hide visible owned windows.
synchronized (getTreeLock ())
{
Iterator e = ownedWindows.iterator();
while(e.hasNext())
{
Window w = (Window)(((Reference) e.next()).get());
if (w != null)
@@ -337,33 +344,39 @@
Iterator e = ownedWindows.iterator();
while(e.hasNext())
{
Window w = (Window)(((Reference) e.next()).get());
if (w != null)
w.dispose();
else
// Remove null weak reference from ownedWindows.
e.remove();
}
for (int i = 0; i < ncomponents; ++i)
component[i].removeNotify();
this.removeNotify();
- // Post a WINDOW_CLOSED event.
- WindowEvent we = new WindowEvent(this, WindowEvent.WINDOW_CLOSED);
- getToolkit().getSystemEventQueue().postEvent(we);
+ // Post WINDOW_CLOSED from here.
+ if (windowListener != null
+ || (eventMask & AWTEvent.WINDOW_EVENT_MASK) != 0)
+ {
+ WindowEvent ev = new WindowEvent(this,
+ WindowEvent.WINDOW_OPENED);
+ Toolkit tk = Toolkit.getDefaultToolkit();
+ tk.getSystemEventQueue().postEvent(ev);
+ }
}
}
/**
* Sends this window to the back so that all other windows display in
* front of it.
*
* If the window is set to be always-on-top, this will remove its
* always-on-top status.
*/
public void toBack()
{
if (peer != null)
{
if( alwaysOnTop )
@@ -574,57 +587,36 @@
*
* @exception ClassCastException If listenerType doesn't specify a class or
* interface that implements java.util.EventListener.
*
* @since 1.3
*/
public EventListener[] getListeners(Class listenerType)
{
if (listenerType == WindowListener.class)
return getWindowListeners();
return super.getListeners(listenerType);
}
void dispatchEventImpl(AWTEvent e)
{
- // Make use of event id's in order to avoid multiple instanceof tests.
- if (e.id <= WindowEvent.WINDOW_LAST
- && e.id >= WindowEvent.WINDOW_FIRST
- && (windowListener != null
- || windowFocusListener != null
- || windowStateListener != null
- || (eventMask & AWTEvent.WINDOW_EVENT_MASK) != 0))
- processEvent(e);
- else
+ if (e.getID() == ComponentEvent.COMPONENT_RESIZED)
{
- if (peer != null && (e.id == ComponentEvent.COMPONENT_RESIZED
- || e.id == ComponentEvent.COMPONENT_MOVED))
- {
- Rectangle bounds = peer.getBounds();
- x = bounds.x;
- y = bounds.y;
- height = bounds.height;
- width = bounds.width;
-
- if (e.id == ComponentEvent.COMPONENT_RESIZED)
- {
- invalidate();
- validate();
- }
- }
- super.dispatchEventImpl(e);
+ invalidate();
+ validate();
}
+ super.dispatchEventImpl(e);
}
/**
* Processes the specified event for this window. If the event is an
* instance of <code>WindowEvent</code>, then
* <code>processWindowEvent()</code> is called to process the event,
* otherwise the superclass version of this method is invoked.
*
* @param evt The event to process.
*/
protected void processEvent(AWTEvent evt)
{
if (evt instanceof WindowEvent)
processWindowEvent((WindowEvent) evt);
else