|
From: <ls...@us...> - 2007-02-03 18:44:50
|
Revision: 3102
http://jnode.svn.sourceforge.net/jnode/?rev=3102&view=rev
Author: lsantha
Date: 2007-02-03 10:44:48 -0800 (Sat, 03 Feb 2007)
Log Message:
-----------
Classpath patches.
Modified Paths:
--------------
trunk/core/src/classpath/java/java/awt/Component.java
trunk/core/src/classpath/java/java/awt/Container.java
trunk/core/src/classpath/java/java/awt/Window.java
Modified: trunk/core/src/classpath/java/java/awt/Component.java
===================================================================
--- trunk/core/src/classpath/java/java/awt/Component.java 2007-02-03 15:05:27 UTC (rev 3101)
+++ trunk/core/src/classpath/java/java/awt/Component.java 2007-02-03 18:44:48 UTC (rev 3102)
@@ -971,18 +971,40 @@
// case lightweight components are not initially painted --
// Container.paint first calls isShowing () before painting itself
// and its children.
- if(!isVisible())
+ if(! visible)
{
- this.visible = true;
+ // Need to lock the tree here to avoid races and inconsistencies.
+ synchronized (getTreeLock())
+ {
+ visible = true;
// Avoid NullPointerExceptions by creating a local reference.
ComponentPeer currentPeer=peer;
if (currentPeer != null)
+ {
currentPeer.show();
+ // Fire HierarchyEvent.
+ fireHierarchyEvent(HierarchyEvent.HIERARCHY_CHANGED,
+ this, parent,
+ HierarchyEvent.SHOWING_CHANGED);
+
// The JDK repaints the component before invalidating the parent.
// So do we.
- if (isShowing() && isLightweight())
+ if (peer instanceof LightweightPeer)
repaint();
+ }
+
+ // Only post an event if this component actually has a listener
+ // or has this event explicitly enabled.
+ if (componentListener != null
+ || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0)
+ {
+ ComponentEvent ce =
+ new ComponentEvent(this,ComponentEvent.COMPONENT_SHOWN);
+ getToolkit().getSystemEventQueue().postEvent(ce);
+ }
+ }
+
// Invalidate the parent if we have one. The component itself must
// not be invalidated. We also avoid NullPointerException with
// a local reference here.
@@ -990,9 +1012,6 @@
if (currentParent != null)
currentParent.invalidate();
- ComponentEvent ce =
- new ComponentEvent(this,ComponentEvent.COMPONENT_SHOWN);
- getToolkit().getSystemEventQueue().postEvent(ce);
}
}
@@ -1018,29 +1037,47 @@
*/
public void hide()
{
- if (isVisible())
+ if (visible)
{
+ // Need to lock the tree here to avoid races and inconsistencies.
+ synchronized (getTreeLock())
+ {
+ visible = false;
+
// Avoid NullPointerExceptions by creating a local reference.
ComponentPeer currentPeer=peer;
if (currentPeer != null)
- currentPeer.setVisible(false);
- boolean wasShowing = isShowing();
- this.visible = false;
+ {
+ currentPeer.hide();
- // The JDK repaints the component before invalidating the parent.
- // So do we.
- if (wasShowing)
+ // Fire hierarchy event.
+ fireHierarchyEvent(HierarchyEvent.HIERARCHY_CHANGED,
+ this, parent,
+ HierarchyEvent.SHOWING_CHANGED);
+ // The JDK repaints the component before invalidating the
+ // parent. So do we. This only applies for lightweights.
+ if (peer instanceof LightweightPeer)
repaint();
- // Invalidate the parent if we have one. The component itself must
+ }
+
+ // Only post an event if this component actually has a listener
+ // or has this event explicitly enabled.
+ if (componentListener != null
+ || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0)
+ {
+ ComponentEvent ce =
+ new ComponentEvent(this,ComponentEvent.COMPONENT_HIDDEN);
+ getToolkit().getSystemEventQueue().postEvent(ce);
+ }
+ }
+
+ // Invalidate the parent if we have one. The component itself need
// not be invalidated. We also avoid NullPointerException with
// a local reference here.
Container currentParent = parent;
if (currentParent != null)
currentParent.invalidate();
- ComponentEvent ce =
- new ComponentEvent(this,ComponentEvent.COMPONENT_HIDDEN);
- getToolkit().getSystemEventQueue().postEvent(ce);
}
}
@@ -3935,19 +3972,38 @@
*/
public void addNotify()
{
+ // We need to lock the tree here to avoid races and inconsistencies.
+ synchronized (getTreeLock())
+ {
if (peer == null)
peer = getToolkit().createComponent(this);
else if (parent != null && parent.isLightweight())
new HeavyweightInLightweightListener(parent);
- /* Now that all the children has gotten their peers, we should
- have the event mask needed for this component and its
- lightweight subcomponents. */
+ // Now that all the children has gotten their peers, we should
+ // have the event mask needed for this component and its
+ //lightweight subcomponents.
peer.setEventMask(eventMask);
- /* We do not invalidate here, but rather leave that job up to
- the peer. For efficiency, the peer can choose not to
- invalidate if it is happy with the current dimensions,
- etc. */
+
+ // We used to leave the invalidate() to the peer. However, I put it
+ // back here for 2 reasons: 1) The RI does call invalidate() from
+ // addNotify(); 2) The peer shouldn't be bother with validation too
+ // much.
+ invalidate();
+
+ if (dropTarget != null)
+ dropTarget.addNotify(peer);
+
+ // Fetch the peerFont for later installation in validate().
+ peerFont = getFont();
+
+ // Notify hierarchy listeners.
+ long flags = HierarchyEvent.DISPLAYABILITY_CHANGED;
+ if (isHierarchyVisible())
+ flags |= HierarchyEvent.SHOWING_CHANGED;
+ fireHierarchyEvent(HierarchyEvent.HIERARCHY_CHANGED, this, parent,
+ flags);
}
+ }
/**
* Called to inform this component is has been removed from its
@@ -3960,6 +4016,9 @@
*/
public void removeNotify()
{
+ // We need to lock the tree here to avoid races and inconsistencies.
+ synchronized (getTreeLock())
+ {
// We null our peer field before disposing of it, such that if we're
// not the event dispatch thread and the dispatch thread is awoken by
// the dispose call, there will be no race checking the peer's null
@@ -3967,12 +4026,21 @@
ComponentPeer tmp = peer;
peer = null;
+ peerFont = null;
if (tmp != null)
{
tmp.hide();
tmp.dispose();
}
+
+ // Notify hierarchy listeners.
+ long flags = HierarchyEvent.DISPLAYABILITY_CHANGED;
+ if (isHierarchyVisible())
+ flags |= HierarchyEvent.SHOWING_CHANGED;
+ fireHierarchyEvent(HierarchyEvent.HIERARCHY_CHANGED, this, parent,
+ flags);
}
+ }
/**
* AWT 1.0 GOT_FOCUS event handler. This method is meant to be
Modified: trunk/core/src/classpath/java/java/awt/Container.java
===================================================================
--- trunk/core/src/classpath/java/java/awt/Container.java 2007-02-03 15:05:27 UTC (rev 3101)
+++ trunk/core/src/classpath/java/java/awt/Container.java 2007-02-03 18:44:48 UTC (rev 3102)
@@ -39,7 +39,6 @@
package java.awt;
-import java.awt.event.ComponentListener;
import java.awt.event.ContainerEvent;
import java.awt.event.ContainerListener;
import java.awt.event.HierarchyEvent;
@@ -90,12 +89,7 @@
Dimension maxSize;
- /**
- * Keeps track if the Container was cleared during a paint/update.
- */
- private boolean backCleared;
-
- /**
+ /*
* @since 1.4
*/
boolean focusCycleRoot;
@@ -333,24 +327,7 @@
// 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();
-
- if (comp.isLightweight ())
- {
- enableEvents (comp.eventMask);
- if (!isLightweight ())
- enableEvents (AWTEvent.PAINT_EVENT_MASK);
- }
- }
-
- // Invalidate the layout of the added component and its ancestors.
- comp.invalidate();
-
if (component == null)
component = new Component[4]; // FIXME, better initial size?
@@ -374,6 +351,31 @@
++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)
{
@@ -394,14 +396,20 @@
// 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.
+ if (containerListener != null
+ || (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0)
+ {
ContainerEvent ce = new ContainerEvent(this,
ContainerEvent.COMPONENT_ADDED,
comp);
- ContainerListener[] listeners = getContainerListeners();
- for (int i = 0; i < listeners.length; i++)
- listeners[i].componentAdded(ce);
+ 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.
@@ -412,33 +420,48 @@
{
synchronized (getTreeLock ())
{
+ if (index < 0 || index >= ncomponents)
+ throw new ArrayIndexOutOfBoundsException();
+
Component r = component[index];
+ if (peer != null)
+ r.removeNotify();
- ComponentListener[] list = r.getComponentListeners();
- for (int j = 0; j < list.length; j++)
- r.removeComponentListener(list[j]);
+ if (layoutMgr != null)
+ layoutMgr.removeLayoutComponent(r);
- r.removeNotify();
+ // Update the counter for Hierarchy(Bounds)Listeners.
+ int childHierarchyListeners = r.numHierarchyListeners;
+ if (childHierarchyListeners > 0)
+ updateHierarchyListenerCount(AWTEvent.HIERARCHY_EVENT_MASK,
+ -childHierarchyListeners);
+ int childHierarchyBoundsListeners = r.numHierarchyBoundsListeners;
+ if (childHierarchyBoundsListeners > 0)
+ updateHierarchyListenerCount(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK,
+ -childHierarchyListeners);
+ r.parent = null;
+
System.arraycopy(component, index + 1, component, index,
ncomponents - index - 1);
component[--ncomponents] = null;
+ if (valid)
invalidate();
- if (layoutMgr != null)
- layoutMgr.removeLayoutComponent(r);
-
- r.parent = null;
-
- if (isShowing ())
+ if (containerListener != null
+ || (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0)
{
// Post event to notify of removing the component.
ContainerEvent ce = new ContainerEvent(this,
ContainerEvent.COMPONENT_REMOVED,
r);
- getToolkit().getSystemEventQueue().postEvent(ce);
+ dispatchEvent(ce);
}
+
+ // Notify hierarchy listeners.
+ r.fireHierarchyEvent(HierarchyEvent.HIERARCHY_CHANGED, r,
+ this, HierarchyEvent.PARENT_CHANGED);
}
}
@@ -477,14 +500,13 @@
// super.removeAll() ).
// By doing it this way, user code cannot prevent the correct
// removal of components.
- for ( int index = 0; index < ncomponents; index++)
+ while (ncomponents > 0)
{
- Component r = component[index];
+ ncomponents--;
+ Component r = component[ncomponents];
+ component[ncomponents] = null;
- ComponentListener[] list = r.getComponentListeners();
- for (int j = 0; j < list.length; j++)
- r.removeComponentListener(list[j]);
-
+ if (peer != null)
r.removeNotify();
if (layoutMgr != null)
@@ -492,21 +514,37 @@
r.parent = null;
- if (isShowing ())
+ // Send ContainerEvent if necessary.
+ if (containerListener != null
+ || (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0)
{
// Post event to notify of removing the component.
ContainerEvent ce
= new ContainerEvent(this,
ContainerEvent.COMPONENT_REMOVED,
r);
-
- getToolkit().getSystemEventQueue().postEvent(ce);
+ dispatchEvent(ce);
}
- }
-
+
+ // Update the counter for Hierarchy(Bounds)Listeners.
+ int childHierarchyListeners = r.numHierarchyListeners;
+ if (childHierarchyListeners > 0)
+ updateHierarchyListenerCount(AWTEvent.HIERARCHY_EVENT_MASK,
+ -childHierarchyListeners);
+ int childHierarchyBoundsListeners = r.numHierarchyBoundsListeners;
+ if (childHierarchyBoundsListeners > 0)
+ updateHierarchyListenerCount(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK,
+ -childHierarchyListeners);
+
+
+ // Send HierarchyEvent if necessary.
+ fireHierarchyEvent(HierarchyEvent.HIERARCHY_CHANGED, r, this,
+ HierarchyEvent.PARENT_CHANGED);
+
+ }
+
+ if (valid)
invalidate();
-
- ncomponents = 0;
}
}
@@ -571,11 +609,20 @@
*/
public void validate()
{
+ ComponentPeer p = peer;
+ if (! valid && p != null)
+ {
+ ContainerPeer cPeer = null;
+ if (p instanceof ContainerPeer)
+ cPeer = (ContainerPeer) peer;
synchronized (getTreeLock ())
{
- if (! isValid() && peer != null)
- {
+ if (cPeer != null)
+ cPeer.beginValidate();
validateTree();
+ valid = true;
+ if (cPeer != null)
+ cPeer.endValidate();
}
}
}
@@ -585,19 +632,18 @@
*/
void invalidateTree()
{
- super.invalidate(); // Clean cached layout state.
+ synchronized (getTreeLock())
+ {
for (int i = 0; i < ncomponents; i++)
{
Component comp = component[i];
- comp.invalidate();
if (comp instanceof Container)
((Container) comp).invalidateTree();
+ else if (comp.valid)
+ comp.invalidate();
}
-
- if (layoutMgr != null && layoutMgr instanceof LayoutManager2)
- {
- LayoutManager2 lm2 = (LayoutManager2) layoutMgr;
- lm2.invalidateLayout(this);
+ if (valid)
+ invalidate();
}
}
@@ -607,60 +653,52 @@
*/
protected void validateTree()
{
- if (valid)
- return;
-
+ if (!valid)
+ {
ContainerPeer cPeer = null;
- if (peer != null && ! (peer instanceof LightweightPeer))
+ if (peer instanceof ContainerPeer)
{
cPeer = (ContainerPeer) peer;
- cPeer.beginValidate();
+ cPeer.beginLayout();
}
- for (int i = 0; i < ncomponents; ++i)
- {
- Component comp = component[i];
-
- if (comp.getPeer () == null)
- comp.addNotify();
- }
-
doLayout ();
for (int i = 0; i < ncomponents; ++i)
{
Component comp = component[i];
- if (! comp.isValid())
+ if (comp instanceof Container && ! (comp instanceof Window)
+ && ! comp.valid)
{
- if (comp instanceof Container)
- {
((Container) comp).validateTree();
}
else
{
- component[i].validate();
+ comp.validate();
}
}
+
+ 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;
- if (cPeer != null)
- cPeer.endValidate();
}
public void setFont(Font f)
{
- if( (f != null && (font == null || !font.equals(f)))
- || f == null)
+ Font oldFont = getFont();
+ super.setFont(f);
+ Font newFont = getFont();
+ if (newFont != oldFont && (oldFont == null || ! oldFont.equals(newFont)))
{
- super.setFont(f);
- // FIXME: Although it might make more sense to invalidate only
- // those children whose font == null, Sun invalidates all children.
- // So we'll do the same.
invalidateTree();
}
}
@@ -922,8 +960,13 @@
*/
public synchronized void addContainerListener(ContainerListener listener)
{
- containerListener = AWTEventMulticaster.add(containerListener, listener);
+ if (listener != null)
+ {
+ containerListener = AWTEventMulticaster.add(containerListener,
+ listener);
+ newEventsOnly = true;
}
+ }
/**
* Removes the specified container listener from this object's list of
@@ -1853,6 +1896,7 @@
bounds.height);
try
{
+ g2.setFont(comp.getFont());
visitor.visit(comp, g2);
}
finally
@@ -2053,15 +2097,9 @@
for (int i = ncomponents; --i >= 0; )
{
component[i].addNotify();
- if (component[i].isLightweight ())
- {
- enableEvents(component[i].eventMask);
- if (peer != null && !isLightweight ())
- enableEvents (AWTEvent.PAINT_EVENT_MASK);
}
}
}
- }
/**
* Deserialize this Container:
Modified: trunk/core/src/classpath/java/java/awt/Window.java
===================================================================
--- trunk/core/src/classpath/java/java/awt/Window.java 2007-02-03 15:05:27 UTC (rev 3101)
+++ trunk/core/src/classpath/java/java/awt/Window.java 2007-02-03 18:44:48 UTC (rev 3102)
@@ -393,11 +393,17 @@
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_CLOSED);
+ Toolkit tk = Toolkit.getDefaultToolkit();
+ tk.getSystemEventQueue().postEvent(ev);
}
}
+ }
/**
* Sends this window to the back so that all other windows display in
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|