Hey,
This patch now makes a few of harmony's test suites now pass on
classpath. The main problem was that 'selected' was not being updated
in a couple of necessary methods. I have also committed some mauve
tests (gnu.testlet.java.awt.List.testSelected.java). The other minor
modifications were also based on harmony's test suites.
If someone could kindly review this patch and approve and/or comment on
it, that would be great.
Thanks.
Tania
2006-07-26 Tania Bento <[EMAIL PROTECTED]>
* java/awt/List.java
Initialized private variable visibleIndex to -1.
(addItem(String, int)): If string is null, it should be
set to the empty string.
(addItem(String, int)): If int < -1, it should be
set to -1.
(delItem): If the item to be deleted was selected, the
next item on the list automatically is selected.
(delItems): Checks are not necessarily and all indices
in selected should be deleted.
(getSelectedIndex): If selected == null, 0 should be
returned.
(select): Updated selected.
(deselect): Updated selected.
Index: java/awt/List.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/List.java,v
retrieving revision 1.28
diff -u -r1.28 List.java
--- java/awt/List.java 13 Jul 2006 17:30:24 -0000 1.28
+++ java/awt/List.java 26 Jul 2006 14:11:35 -0000
@@ -108,7 +108,7 @@
* @serial An index value used by <code>makeVisible()</code> and
* <code>getVisibleIndex</code>.
*/
-private int visibleIndex;
+private int visibleIndex = -1;
// The list of ItemListeners for this object.
private ItemListener item_listeners;
@@ -116,7 +116,6 @@
// The list of ActionListeners for this object.
private ActionListener action_listeners;
-
/*************************************************************************/
/*
@@ -176,6 +175,7 @@
if (GraphicsEnvironment.isHeadless())
throw new HeadlessException ();
+
}
/*************************************************************************/
@@ -314,12 +314,13 @@
*/
public void
setMultipleSelections(boolean multipleMode)
-{
+{
this.multipleMode = multipleMode;
ListPeer peer = (ListPeer) getPeer ();
if (peer != null)
peer.setMultipleMode (multipleMode);
+
}
/*************************************************************************/
@@ -519,6 +520,12 @@
public void
addItem(String item, int index)
{
+ if (item == null)
+ item = "";
+
+ if (index < -1)
+ index = -1;
+
if ((index == -1) || (index >= items.size ()))
items.addElement (item);
else
@@ -543,7 +550,17 @@
public void
delItem(int index) throws IllegalArgumentException
{
+ boolean selected = false;
+ if (isSelected(index))
+ {
+ selected = true;
+ deselect(index);
+ }
+
items.removeElementAt (index);
+
+ if (selected)
+ select(index);
ListPeer peer = (ListPeer) getPeer ();
if (peer != null)
@@ -580,15 +597,6 @@
public synchronized void
delItems(int start, int end) throws IllegalArgumentException
{
- if ((start < 0) || (start >= items.size()))
- throw new IllegalArgumentException("Bad list start index value: " + start);
-
- if ((start < 0) || (start >= items.size()))
- throw new IllegalArgumentException("Bad list start index value: " + start);
-
- if (start > end)
- throw new IllegalArgumentException("Start is greater than end!");
-
// We must run the loop in reverse direction.
for (int i = end; i >= start; --i)
items.removeElementAt (i);
@@ -644,6 +652,8 @@
ListPeer peer = (ListPeer) getPeer ();
if (peer != null)
peer.removeAll ();
+
+ selected = new int[0];
}
/*************************************************************************/
@@ -693,8 +703,12 @@
selected = l.getSelectedIndexes ();
}
- if (selected == null || selected.length != 1)
+ if (selected != null && selected.length != 1)
return -1;
+
+ if (selected == null)
+ return 0;
+
return selected[0];
}
@@ -713,7 +727,8 @@
{
ListPeer l = (ListPeer) peer;
selected = l.getSelectedIndexes ();
- }
+ }
+
return selected;
}
@@ -862,13 +877,31 @@
*
* @param index The index of the item to select.
*/
-public synchronized void
-select(int index)
-{
- ListPeer lp = (ListPeer)getPeer();
- if (lp != null)
- lp.select(index);
-}
+ public synchronized void select(int index)
+ {
+ ListPeer lp = (ListPeer) getPeer();
+ if (lp != null)
+ lp.select(index);
+
+ boolean found = false;
+ for (int i = 0; i < selected.length; i++)
+ {
+ if (selected[i] == index)
+ {
+ found = true;
+ }
+ }
+ if (! found)
+ {
+ if (! isMultipleMode())
+ selected = new int[0];
+
+ int[] temp = new int[selected.length + 1];
+ System.arraycopy(selected, 0, temp, 0, selected.length);
+ temp[selected.length] = index;
+ selected = temp;
+ }
+ }
/*************************************************************************/
@@ -880,9 +913,26 @@
public synchronized void
deselect(int index)
{
- ListPeer lp = (ListPeer)getPeer();
- if (lp != null)
- lp.deselect(index);
+ if (isSelected(index))
+ {
+ ListPeer lp = (ListPeer)getPeer();
+ if (lp != null)
+ lp.deselect(index);
+
+ int[] temp = new int[selected.length - 1];
+ for (int i = 0; i < temp.length; i++)
+ {
+ if (selected[i] != index)
+ temp[i] = selected[i];
+ else
+ {
+ System.arraycopy(selected, i + 1, temp, i,
+ selected.length - i - 1);
+ break;
+ }
+ }
+ selected = temp;
+ }
}
/*************************************************************************/