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: [PATCH] overriding setBackground for GtkContainerPeer


On Mon, 2004-01-12 at 18:17, Tom Tromey wrote:
> >>>>> "David" == David Jee <djee@redhat.com> writes:
> 
> David> +        Component comp = (Component) components[i];
> [ ... ]
> David> +          comp.peer.setBackground(c);
> 
> I think this will only compile due to a gcj bug, as `peer' is
> package-private in Component.  The patch is fine if you change this
> to use getPeer().

Here, then, is the final patch that I'll be committing, with the change
above.

-David Jee

2004-01-13  David Jee  <djee@redhat.com>

        * gnu/java/awt/peer/gtk/GtkContainerPeer.java
        (setBackground): New method. Children with no explicitly-set
        background will be repainted with the parent container's new
        background color.


Index: gnu/java/awt/peer/gtk/GtkContainerPeer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/awt/peer/gtk/GtkContainerPeer.java,v
retrieving revision 1.6
diff -u -r1.6 GtkContainerPeer.java
--- gnu/java/awt/peer/gtk/GtkContainerPeer.java	31 Dec 2003 08:58:30 -0000	1.6
+++ gnu/java/awt/peer/gtk/GtkContainerPeer.java	13 Jan 2004 16:46:16 -0000
@@ -39,6 +39,8 @@
 package gnu.java.awt.peer.gtk;
 
 import java.awt.AWTEvent;
+import java.awt.Color;
+import java.awt.Component;
 import java.awt.Container;
 import java.awt.Graphics;
 import java.awt.Insets;
@@ -136,4 +138,23 @@
   public void beginLayout () { }
   public void endLayout () { }
   public boolean isPaintPending () { return false; }
+
+  public void setBackground (Color c)
+  {
+    super.setBackground(c);
+  
+    Object components[] = ((Container) awtComponent).getComponents();
+    for (int i = 0; i < components.length; i++)
+      {
+        Component comp = (Component) components[i];
+
+        // If the child's background has not been explicitly set yet,
+        // it should inherit this container's background. This makes the
+        // child component appear as if it has a transparent background.
+        // Note that we do not alter the background property of the child,
+        // but only repaint the child with the parent's background color.
+        if (!comp.isBackgroundSet() && comp.getPeer() != null)
+          comp.getPeer().setBackground(c);
+      }
+  }
 }

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