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]

Re: [gui][patch] various fixes and initialWindow.setLocationRelativeTo implementation


Here's the patch.

Tom

On Thu, 2004-12-09 at 16:43 -0500, Thomas Fitzsimmons wrote:
> Hi,
> 
> I committed this to java-gui-branch.  It prevents posting certain events
> to components that are not showing -- without the patch, components were
> being painted multiple times when they were first shown.
> 
> The patch also contains an initial implementation of
> Window.setLocationRelativeTo and some other small fixes.
> 
> Tom
> 
> 2004-12-08  Thomas Fitzsimmons  <fitzsim@redhat.com>
> 
> 	* gnu/java/awt/peer/gtk/GdkGraphics.java (setClip): Protect
> 	against null clip region.
> 	* gnu/java/awt/peer/gtk/GtkFramePeer.java (create): Call
> 	gtkWindowSetResizable.
> 	(postConfigureEvent): Only revalidate if frame size has changed.
> 	* gnu/java/awt/peer/gtk/GtkWindowPeer.java (postConfigureEvent):
> 	Only revalidate if frame size has changed.
> 	* java/awt/Component.java (reshape): Only repaint and post
> 	component events if component is showing.
> 	* java/awt/Container.java (addImpl): Only post container event if
> 	container is showing.
> 	(remove): Likewise.
> 	* java/awt/Window.java (setLocationRelativeTo): Implement.
> 	(setBoundsCallback): Only post component events if component is
> 	showing.
> 	* jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics.c (clearRect):
> 	Protect against null graphics structure.  Flush gdk event queue.
> 
> 
Index: gnu/java/awt/peer/gtk/GdkGraphics.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/awt/peer/gtk/GdkGraphics.java,v
retrieving revision 1.4.16.11
diff -u -r1.4.16.11 GdkGraphics.java
--- gnu/java/awt/peer/gtk/GdkGraphics.java	25 Nov 2004 02:34:53 -0000	1.4.16.11
+++ gnu/java/awt/peer/gtk/GdkGraphics.java	9 Dec 2004 21:36:08 -0000
@@ -426,7 +426,8 @@
 
   public void setClip (int x, int y, int width, int height)
   {
-    if (component != null && ! component.isRealized ())
+    if ((component != null && ! component.isRealized ())
+        || clip == null)
       return;
 
     clip.x = x;
Index: gnu/java/awt/peer/gtk/GtkFramePeer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/awt/peer/gtk/GtkFramePeer.java,v
retrieving revision 1.17.2.11
diff -u -r1.17.2.11 GtkFramePeer.java
--- gnu/java/awt/peer/gtk/GtkFramePeer.java	25 Nov 2004 02:34:53 -0000	1.17.2.11
+++ gnu/java/awt/peer/gtk/GtkFramePeer.java	9 Dec 2004 21:36:08 -0000
@@ -165,7 +165,7 @@
     setMenuBar (frame.getMenuBar ());
 
     setTitle (frame.getTitle ());
-    setResizable (frame.isResizable ());
+    gtkWindowSetResizable (frame.isResizable ());
     setIconImage(frame.getIconImage());
   }
 
@@ -237,9 +237,9 @@
                            frame_y,
                            frame_width,
                            frame_height);
-      }
 
-    awtComponent.validate();
+        awtComponent.validate();
+      }
   }
 
   protected void postMouseEvent(int id, long when, int mods, int x, int y, 
Index: gnu/java/awt/peer/gtk/GtkWindowPeer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/awt/peer/gtk/GtkWindowPeer.java,v
retrieving revision 1.10.8.3
diff -u -r1.10.8.3 GtkWindowPeer.java
--- gnu/java/awt/peer/gtk/GtkWindowPeer.java	7 Oct 2004 22:11:57 -0000	1.10.8.3
+++ gnu/java/awt/peer/gtk/GtkWindowPeer.java	9 Dec 2004 21:36:08 -0000
@@ -166,10 +166,12 @@
 	|| frame_y != awtComponent.getY()
 	|| frame_width != awtComponent.getWidth()
 	|| frame_height != awtComponent.getHeight())
-      setBoundsCallback ((Window) awtComponent,
-			 frame_x, frame_y, frame_width, frame_height);
+      {
+        setBoundsCallback ((Window) awtComponent,
+                           frame_x, frame_y, frame_width, frame_height);
 
-    awtComponent.validate();
+        awtComponent.validate();
+      }
   }
 
   native void nativeSetVisible (boolean b);
Index: java/awt/Component.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/Component.java,v
retrieving revision 1.37.2.29
diff -u -r1.37.2.29 Component.java
--- java/awt/Component.java	6 Dec 2004 13:50:29 -0000	1.37.2.29
+++ java/awt/Component.java	9 Dec 2004 21:36:08 -0000
@@ -1362,7 +1362,7 @@
       peer.setBounds (x, y, width, height);
 
     // Erase old bounds and repaint new bounds for lightweights.
-    if (isLightweight())
+    if (isLightweight() && isShowing ())
       {
         boolean shouldRepaintParent = false;
         boolean shouldRepaintSelf = false;
@@ -1386,13 +1386,16 @@
           repaint();
       }
 
-    if (oldx != x || oldy != y)
+    // Only post event if this component is visible and has changed size.
+    if (isShowing ()
+        && (oldx != x || oldy != y))
       {
         ComponentEvent ce = new ComponentEvent(this,
                                                ComponentEvent.COMPONENT_MOVED);
         getToolkit().getSystemEventQueue().postEvent(ce);
       }
-    if (oldwidth != width || oldheight != height)
+    if (isShowing ()
+        && (oldwidth != width || oldheight != height))
       {
         ComponentEvent ce = new ComponentEvent(this,
                                                ComponentEvent.COMPONENT_RESIZED);
Index: java/awt/Container.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/Container.java,v
retrieving revision 1.34.2.24
diff -u -r1.34.2.24 Container.java
--- java/awt/Container.java	16 Nov 2004 09:55:30 -0000	1.34.2.24
+++ java/awt/Container.java	9 Dec 2004 21:36:08 -0000
@@ -387,11 +387,14 @@
               layoutMgr.addLayoutComponent(null, comp);
           }
 
-        // Post event to notify of adding the container.
-        ContainerEvent ce = new ContainerEvent(this,
-                                               ContainerEvent.COMPONENT_ADDED,
-                                               comp);
-        getToolkit().getSystemEventQueue().postEvent(ce);
+        if (isShowing ())
+          {
+            // Post event to notify of adding the component.
+            ContainerEvent ce = new ContainerEvent(this,
+                                                   ContainerEvent.COMPONENT_ADDED,
+                                                   comp);
+            getToolkit().getSystemEventQueue().postEvent(ce);
+          }
       }
   }
 
@@ -419,11 +422,14 @@
 
         r.parent = null;
 
-        // Post event to notify of adding the container.
-        ContainerEvent ce = new ContainerEvent(this,
-                                               ContainerEvent.COMPONENT_REMOVED,
-                                               r);
-        getToolkit().getSystemEventQueue().postEvent(ce);
+        if (isShowing ())
+          {
+            // Post event to notify of removing the component.
+            ContainerEvent ce = new ContainerEvent(this,
+                                                   ContainerEvent.COMPONENT_REMOVED,
+                                                   r);
+            getToolkit().getSystemEventQueue().postEvent(ce);
+          }
       }
   }
 
Index: java/awt/Window.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/Window.java,v
retrieving revision 1.32.12.14
diff -u -r1.32.12.14 Window.java
--- java/awt/Window.java	16 Nov 2004 09:55:38 -0000	1.32.12.14
+++ java/awt/Window.java	9 Dec 2004 21:36:08 -0000
@@ -731,6 +731,22 @@
     return super.isShowing();
   }
 
+  public void setLocationRelativeTo (Component c)
+  {
+    if (c == null || !c.isShowing ())
+      {
+        int x = 0;
+        int y = 0;
+
+        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment ();
+        Point center = ge.getCenterPoint ();
+        x = center.x - (width / 2);
+        y = center.y - (height / 2);
+        setLocation (x, y);
+      }
+    // FIXME: handle case where component is non-null.
+  }
+
   /**
    * @since 1.2
    *
@@ -866,13 +882,13 @@
     this.y = y;
     width = w;
     height = h;
-    if (resized)
+    if (resized && isShowing ())
       {
         ComponentEvent ce =
           new ComponentEvent(this, ComponentEvent.COMPONENT_RESIZED);
         getToolkit().getSystemEventQueue().postEvent(ce);
       }
-    if (moved)
+    if (moved && isShowing ())
       {
         ComponentEvent ce =
           new ComponentEvent(this, ComponentEvent.COMPONENT_MOVED);
Index: jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics.c
===================================================================
RCS file: /cvs/gcc/gcc/libjava/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics.c,v
retrieving revision 1.5.2.14
diff -u -r1.5.2.14 gnu_java_awt_peer_gtk_GdkGraphics.c
--- jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics.c	25 Nov 2004 02:34:54 -0000	1.5.2.14
+++ jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics.c	9 Dec 2004 21:36:08 -0000
@@ -438,6 +438,12 @@
   g = (struct graphics *) NSA_GET_PTR (env, obj);
 
   gdk_threads_enter ();
+
+  if (!g)
+    {
+      gdk_threads_leave ();
+      return;
+    }
   if (GDK_IS_WINDOW (g->drawable))
     {
       w.widget = &widget;
@@ -455,6 +461,8 @@
 			  x + g->x_offset, y + g->y_offset, width, height);
       gdk_gc_set_foreground (g->gc, &(saved.foreground));
     }
+
+  gdk_flush ();
   gdk_threads_leave ();
 }
 

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