This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gui] [PATCH] FYI: Dispatching ComponentEvents


Hello,

I'm committing the following patch to the java-gui-branch.  The patch
implements the dispatching of ComponentEvents, which occur when a
component is resized, moved, shown or hidden.  This can happen either as
a result of user interaction, or as a result of calling the
corresponding action methods in the Component class (eg show(),
setSize()).

-David Jee

2004-02-16  David Jee  <djee@redhat.com>

        * java/awt/Component.java
        (show): Dispatch COMPONENT_SHOWN ComponentEvent.
        (hide): Dispatch COMPONENT_HIDDEN ComponentEvent.
        (move): Erase old bounds and repaint new bounds. Dispatch
        COMPONENT_MOVED ComponentEvent.
        (resize): Erase old bounds and repaint new bounds. Dispatch
        COMPONENT_RESIZED ComponentEvent.
        (reshape): Dispatch COMPONENT_RESIZED and COMPONENT_MOVED
        ComponentEvents.
        * java/awt/Window.java
        (setBoundsCallback): Dispatch COMPONENT_RESIZED and COMPONENT_MOVED
        ComponentEvents.


Index: java/awt/Component.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/Component.java,v
retrieving revision 1.37.2.1
diff -u -r1.37.2.1 Component.java
--- java/awt/Component.java	13 Feb 2004 18:02:11 -0000	1.37.2.1
+++ java/awt/Component.java	16 Feb 2004 22:16:06 -0000
@@ -882,6 +882,7 @@
         if (peer != null)
           peer.setVisible(true);
         invalidate();
+        dispatchEvent(new ComponentEvent(this, ComponentEvent.COMPONENT_SHOWN));
       }
   }
 
@@ -912,6 +913,7 @@
           peer.setVisible(false);
         this.visible = false;
         invalidate();
+        dispatchEvent(new ComponentEvent(this, ComponentEvent.COMPONENT_HIDDEN));
       }
   }
 
@@ -1156,6 +1158,9 @@
    */
   public void move(int x, int y)
   {
+    int oldx = this.x;
+    int oldy = this.y;
+
     if (this.x == x && this.y == y)
       return;
     invalidate ();
@@ -1163,6 +1168,16 @@
     this.y = y;
     if (peer != null)
       peer.setBounds (x, y, width, height);
+
+    // Erase old bounds and repaint new bounds for lightweights.
+    if (isLightweight() && width != 0 && height !=0)
+      {
+        parent.repaint(oldx, oldy, width, height);
+        repaint();
+      }
+
+    if (oldx != x || oldy != y)
+      dispatchEvent(new ComponentEvent(this, ComponentEvent.COMPONENT_MOVED));
   }
 
   /**
@@ -1226,6 +1241,9 @@
    */
   public void resize(int width, int height)
   {
+    int oldwidth = this.width;
+    int oldheight = this.height;
+
     if (this.width == width && this.height == height)
       return;
     invalidate ();
@@ -1233,6 +1251,18 @@
     this.height = height;
     if (peer != null)
       peer.setBounds (x, y, width, height);
+
+    // Erase old bounds and repaint new bounds for lightweights.
+    if (isLightweight())
+      {
+        if (oldwidth != 0 && oldheight != 0 && parent != null)
+          parent.repaint(x, y, oldwidth, oldheight);
+        if (width != 0 && height != 0)
+          repaint();
+      }
+
+    if (oldwidth != width || oldheight != height)
+      dispatchEvent(new ComponentEvent(this, ComponentEvent.COMPONENT_RESIZED));
   }
 
   /**
@@ -1345,6 +1375,11 @@
         if (width != 0 && height != 0)
           repaint();
       }
+
+    if (oldx != x || oldy != y)
+      dispatchEvent(new ComponentEvent(this, ComponentEvent.COMPONENT_MOVED));
+    if (oldwidth != width || oldheight != height)
+      dispatchEvent(new ComponentEvent(this, ComponentEvent.COMPONENT_RESIZED));
   }
 
   /**
Index: java/awt/Window.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/Window.java,v
retrieving revision 1.32
diff -u -r1.32 Window.java
--- java/awt/Window.java	24 Oct 2003 19:40:29 -0000	1.32
+++ java/awt/Window.java	16 Feb 2004 22:16:07 -0000
@@ -38,6 +38,7 @@
 
 package java.awt;
 
+import java.awt.event.ComponentEvent;
 import java.awt.event.WindowEvent;
 import java.awt.event.WindowFocusListener;
 import java.awt.event.WindowListener;
@@ -784,9 +785,15 @@
     if (this.x == x && this.y == y && width == w && height == h)
       return;
     invalidate();
+    boolean resized = width != w || height != h;
+    boolean moved = this.x != x || this.y != y;
     this.x = x;
     this.y = y;
     width = w;
     height = h;
+    if (resized)
+      dispatchEvent(new ComponentEvent(this, ComponentEvent.COMPONENT_RESIZED));
+    if (moved)
+      dispatchEvent(new ComponentEvent(this, ComponentEvent.COMPONENT_MOVED));
   }
 }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]