I fixed a couple of buggies mentioned in:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27222

2006-04-20  Roman Kennke  <[EMAIL PROTECTED]>

        PR 27222
        * javax/swing/JList.java
        (JList()): Call init() with DefaultListModel instance.
        (JList(Object[])): Call init() with null.
        (JList(Vector)): Call init() with null.
        (JList(ListModel)): Call init() with model.
        (init): Changed to take the model as argument. Don't call
        setter methods and initialize stuff directly instead.
        (getCellBounds): Check if UI is null.

/Roman

Index: javax/swing/JList.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JList.java,v
retrieving revision 1.48
diff -u -1 -0 -r1.48 JList.java
--- javax/swing/JList.java	9 Mar 2006 16:21:35 -0000	1.48
+++ javax/swing/JList.java	20 Apr 2006 09:13:12 -0000
@@ -1019,72 +1019,84 @@
    * #model} and [EMAIL PROTECTED] #selectionModel} properties of the list.
    */
   ListListener listListener;
 
 
   /**
    * Creates a new JList object.
    */
   public JList()
   {
-    init();
+    init(new DefaultListModel());
   }
 
   /**
    * Creates a new JList object.
    *
    * @param listData Initial data to populate the list with
    */
   public JList(Object[] listData)
   {
-    init();
+    init(null);
     setListData(listData);
   }
 
   /**
    * Creates a new JList object.
    *
    * @param listData Initial data to populate the list with
    */
   public JList(Vector listData)
   {
-    init();
+    init(null);
     setListData(listData);
   }
 
   /**
    * Creates a new JList object.
    *
    * @param listData Initial data to populate the list with
    */
   public JList(ListModel listData)
   {
-    init();
-    setModel(listData);
+    init(listData);
   }
 
-  void init()
+  /**
+   * Initializes the list.
+   *
+   * @param m the list model to set
+   */
+  private void init(ListModel m)
   {
     dragEnabled = false;
     fixedCellHeight = -1;
     fixedCellWidth = -1;
     layoutOrientation = VERTICAL;
     opaque = true;
     valueIsAdjusting = false;
     visibleRowCount = 7;
 
     cellRenderer = new DefaultListCellRenderer();
     listListener = new ListListener();
 
-    setModel(new DefaultListModel());
-    setSelectionModel(createSelectionModel());
-    setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
+    model = m;
+    if (model != null)
+      model.addListDataListener(listListener);
+
+    selectionModel = createSelectionModel();
+    if (selectionModel != null)
+      {
+        selectionModel.addListSelectionListener(listListener);
+        selectionModel.setSelectionMode
+                              (ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
+      }
     setLayout(null);
     
     updateUI();
   }
 
   /**
    * Creates the default <code>ListSelectionModel</code>.
    *
    * @return the <code>ListSelectionModel</code>
    */
@@ -2133,21 +2145,28 @@
    *
    * @param index0 the index of the first cell
    * @param index1 the index of the second cell
    *
    * @return  the bounds of the rectangle that encloses both list cells
    *     with index0 and index1, <code>null</code> if one of the indices is
    *     not valid
    */
   public Rectangle getCellBounds(int index0, int index1)
   {
-    return getUI().getCellBounds(this, index0, index1);
+    ListUI ui = getUI();
+    Rectangle bounds = null;
+    if (ui != null)
+      {
+        bounds = ui.getCellBounds(this, index0, index1);
+      }
+    // When the UI is null, this method also returns null in the RI.
+    return bounds;
   }
 
   /**
    * Returns the next list element (beginning from <code>startIndex</code>
    * that starts with <code>prefix</code>. Searching is done in the direction
    * specified by <code>bias</code>.
    *
    * @param prefix the prefix to search for in the cell values
    * @param startIndex the index where to start searching from
    * @param bias the search direction, either [EMAIL PROTECTED] Position.Bias#Forward}

Reply via email to