classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cp-patches] java.awt.Choice selection behaviour when when no peer i


From: Mark Wielaard
Subject: Re: [cp-patches] java.awt.Choice selection behaviour when when no peer is set
Date: Sun, 24 Oct 2004 10:31:07 +0200

Hi,

On Sun, 2004-10-24 at 00:24, Noa Resare wrote:
> If you just instantiate a java.awt.Choice object and add/remove items
> the rules for what item gets selected isn't obeyed since there is no
> peer widget set instantiated. The attached patch implements this
> behavior, so that the mauve testcases work.

Thanks. Don't forget to update the copyright year in the files you edit.
And in general we try to list all methods that changed explicitly like:

2004-10-22  Noa Resare  <address@hidden>

       * java/awt/Choice.java (add):
       Implement correct selection behavior when peer == null.
       (insert): Likewise.
       (remove): Likewise.

And the entries should be full sentences, ending with a dot. See also:
  "Documenting what changed when with ChangeLog entries"
  http://www.gnu.org/software/classpath/docs/hacking.html#SEC9

> The code I have added only affects the no-peer case, so any errors in it
> shouldn't effect anyone doing anything real :)

Which I actually think is a flaw in your patch.
The tests in mauve were added since some programs first set up a Choice,
fill it with items and/or manipulate it somehow before it gets shown.
So I think something like the following (untested) needs to be added:

        * gnu/java/awt/peer/gtk/GtkChoicePeer.java (GtkChoicePeer):
        Call select() when Choice has a selected item.

> +      if (index == selectedIndex)
> +       select(0);
> +      if (getItemCount() == 0)
> +       selectedIndex = -1;

I think this should be:

      if (getItemCount() == 0)
       selectedIndex = -1;
      else if (index == selectedIndex)
       select(0);

Otherwise you will get a IllegalArgumentException from select(0) if you
remove the last item.

What do you think?

Cheers,

Mark
Index: java/awt/Choice.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/Choice.java,v
retrieving revision 1.15
diff -u -r1.15 Choice.java
--- java/awt/Choice.java        3 Feb 2004 17:17:29 -0000       1.15
+++ java/awt/Choice.java        24 Oct 2004 08:32:44 -0000
@@ -1,5 +1,5 @@
 /* Choice.java -- Java choice button widget.
-   Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+   Copyright (C) 1999, 2000, 2001, 2002, 2004 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -169,6 +169,8 @@
       ChoicePeer cp = (ChoicePeer) peer;
       cp.add (item, i);
     }
+  else if (selectedIndex == -1) 
+    select(0);
 }
 
 /*************************************************************************/
@@ -218,6 +220,8 @@
       ChoicePeer cp = (ChoicePeer) peer;
       cp.add (item, index);
     }
+  else if (selectedIndex == -1 || selectedIndex >= index)
+    select(0);
 }
 
 /*************************************************************************/
@@ -261,6 +265,13 @@
       ChoicePeer cp = (ChoicePeer) peer;
       cp.remove (index);
     }
+  else
+    {
+      if (getItemCount() == 0)
+       selectedIndex = -1;
+      else if (index == selectedIndex)
+       select(0);
+    }
 
   if (selectedIndex > index)
     --selectedIndex;
Index: gnu/java/awt/peer/gtk/GtkChoicePeer.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/gnu/java/awt/peer/gtk/GtkChoicePeer.java,v
retrieving revision 1.17
diff -u -r1.17 GtkChoicePeer.java
--- gnu/java/awt/peer/gtk/GtkChoicePeer.java    31 Jul 2004 21:15:06 -0000      
1.17
+++ gnu/java/awt/peer/gtk/GtkChoicePeer.java    24 Oct 2004 08:32:44 -0000
@@ -59,6 +59,10 @@
          
        append (items);
       }
+
+    int selected = c.getSelectedIndex();
+    if (selected >= 0)
+      select(selected);
   }
 
   native void create ();

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]