[cp-patches] FYI: ListDataEvent fixlet

David Gilbert david.gilbert at object-refinery.com
Fri Jun 16 13:18:35 UTC 2006


This patch (committed) fixes a minor bug in the ListDataEvent class, and updates the 
API docs:

2006-06-16  David Gilbert  <david.gilbert at object-refinery.com>

	* javax/swing/event/ListDataEvent.java: updated API docs, plus
	(ListDataEvent): Handle case where index0 > index1,
	(toString): Implemented.

Regards,

Dave
-------------- next part --------------
Index: javax/swing/event/ListDataEvent.java
===================================================================
RCS file: /sources/classpath/classpath/javax/swing/event/ListDataEvent.java,v
retrieving revision 1.8
diff -u -r1.8 ListDataEvent.java
--- javax/swing/event/ListDataEvent.java	2 Jul 2005 20:32:50 -0000	1.8
+++ javax/swing/event/ListDataEvent.java	16 Jun 2006 13:09:01 -0000
@@ -1,5 +1,5 @@
 /* ListDataEvent.java --
-   Copyright (C) 2002 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2006, Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -41,6 +41,9 @@
 import java.util.EventObject;
 
 /**
+ * An event that contains information about a modification to the content of
+ * a list.
+ * 
  * @author Andrew Selkirk
  * @author Ronald Veldema
  */
@@ -48,32 +51,46 @@
 {
   private static final long serialVersionUID = 2510353260071004774L;
   
+  /** An event type indicating that the list content has been modified. */
   public static final int CONTENTS_CHANGED = 0;
+  
+  /** An event type indicating that an interval has been added to the list. */
   public static final int INTERVAL_ADDED = 1;
+  
+  /** 
+   * An event type indicating that an interval has been removed from the 
+   * list. 
+   */
   public static final int INTERVAL_REMOVED = 2;
 
-  private int type = 0;
-  private int index0 = 0;
-  private int index1 = 0;
+  private int type;
+  private int index0;
+  private int index1;
 	
   /**
    * Creates a <code>ListDataEvent</code> object.
    * 
-   * @param source The source of the event.
-   * @param type The type of the event
-   * @param index0 Bottom of range
-   * @param index1 Top of range
+   * @param source  the source of the event (<code>null</code> not permitted).
+   * @param type  the type of the event (should be one of 
+   *     {@link #CONTENTS_CHANGED}, {@link #INTERVAL_ADDED} or 
+   *     {@link #INTERVAL_REMOVED}, although this is not enforced).
+   * @param index0  the index for one end of the modified range of list 
+   *     elements.
+   * @param index1  the index for the other end of the modified range of list 
+   *     elements.
    */
   public ListDataEvent(Object source, int type, int index0, int index1)
   {
     super(source);
     this.type = type;
-    this.index0 = index0;
-    this.index1 = index1;
+    this.index0 = Math.min(index0, index1);
+    this.index1 = Math.max(index0, index1);
   }
 	
   /**
-   * Returns the bottom index.
+   * Returns the index of the first item in the range of modified list items.
+   * 
+   * @return The index of the first item in the range of modified list items.
    */
   public int getIndex0()
   {
@@ -81,7 +98,9 @@
   }
 
   /**
-   * Returns the top index.
+   * Returns the index of the last item in the range of modified list items.
+   * 
+   * @return The index of the last item in the range of modified list items.
    */
   public int getIndex1()
   {
@@ -89,10 +108,25 @@
   }
 
   /**
-   * Returns the type of this event.
+   * Returns a code representing the type of this event, which is usually one
+   * of {@link #CONTENTS_CHANGED}, {@link #INTERVAL_ADDED} or 
+   * {@link #INTERVAL_REMOVED}.
+   * 
+   * @return The event type.
    */
   public int getType()
   {
     return type;
   }
+  
+  /**
+   * Returns a string representing the state of this event.
+   * 
+   * @return A string.
+   */
+  public String toString()
+  {
+    return getClass().getName() + "[type=" + type + ",index0=" + index0 
+        + ",index1=" + index1 + "]";
+  }
 }


More information about the Classpath-patches mailing list