Hi,

This fixes some smaller issues with JComboBox, most importantly closing
the popup when the combobox loses focus (like, when it is made
invisible).

2005-10-17  Roman Kennke  <[EMAIL PROTECTED]>

        * javax/swing/plaf/basic/BasicComboBoxUI.java
        Filled empty blocks with comments.
        (FocusHandler.focusLost): Close popup when the combobox loses
focus.
        * javax/swing/plaf/basic/BasicComboPopup.java
        Filled empty blocks with comments.
        (updateListBoxSelectionForEvent): Implemented partly.
        (ListMouseHandler.mouseReleased): Call
updateListBoxSelectionForEvent.
        (ListMouseMotionHandler.mouseReleased): Likewise.


/Roman
Index: javax/swing/plaf/basic/BasicComboBoxUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicComboBoxUI.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- javax/swing/plaf/basic/BasicComboBoxUI.java	17 Oct 2005 10:02:51 -0000	1.21
+++ javax/swing/plaf/basic/BasicComboBoxUI.java	17 Oct 2005 13:35:58 -0000	1.22
@@ -179,6 +179,7 @@
    */
   public BasicComboBoxUI()
   {
+    // Nothing to do here.
   }
 
   /**
@@ -207,13 +208,13 @@
 
     if (c instanceof JComboBox)
       {
-	comboBox = (JComboBox) c;
-	comboBox.setOpaque(true);
-	comboBox.setLayout(createLayoutManager());
-	installDefaults();
-	installComponents();
-	installListeners();
-	installKeyboardActions();
+        comboBox = (JComboBox) c;
+        comboBox.setOpaque(true);
+        comboBox.setLayout(createLayoutManager());
+        installDefaults();
+        installComponents();
+        installListeners();
+        installKeyboardActions();
       }
   }
 
@@ -532,9 +533,13 @@
    * Unconfigures the arrow button.
    * 
    * @see #configureArrowButton()
+   *
+   * @specnote The specification says this method is implementation specific
+   *           and should not be used or overridden.
    */
   public void unconfigureArrowButton()
   {
+    // Nothing to do here yet.
   }
 
   /**
@@ -878,6 +883,7 @@
      */
     public ComboBoxLayoutManager()
     {
+      // Nothing to do here.
     }
 
     /**
@@ -964,6 +970,7 @@
      */
     public FocusHandler()
     {
+      // Nothing to do here.
     }
 
     /**
@@ -987,6 +994,7 @@
     public void focusLost(FocusEvent e)
     {
       hasFocus = false;
+      setPopupVisible(comboBox, false);
       comboBox.repaint();
     }
   }
@@ -1002,6 +1010,7 @@
      */
     public ItemHandler()
     {
+      // Nothing to do here.
     }
 
     /**
@@ -1023,6 +1032,7 @@
   {
     public KeyHandler()
     {
+      // Nothing to do here.
     }
 
     /**
@@ -1045,6 +1055,7 @@
      */
     public ListDataHandler()
     {
+      // Nothing to do here.
     }
 
     /**
@@ -1102,6 +1113,7 @@
      */
     public PropertyChangeHandler()
     {
+      // Nothing to do here.
     }
 
     /**
Index: javax/swing/plaf/basic/BasicComboPopup.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicComboPopup.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- javax/swing/plaf/basic/BasicComboPopup.java	29 Sep 2005 20:19:20 -0000	1.8
+++ javax/swing/plaf/basic/BasicComboPopup.java	17 Oct 2005 13:35:59 -0000	1.9
@@ -718,7 +718,11 @@
   protected void updateListBoxSelectionForEvent(MouseEvent anEvent,
                                                 boolean shouldScroll)
   {
-    // FIXME: Need to implement
+    // TODO: We need to handle the shouldScroll parameter somehow.
+    int index = list.locationToIndex(anEvent.getPoint());
+    // Check for valid index.
+    if (index >= 0)
+      list.setSelectedIndex(index);
   }
 
   /**
@@ -736,6 +740,7 @@
      */
     protected InvocationMouseHandler()
     {
+      // Nothing to do here.
     }
 
     /**
@@ -748,7 +753,7 @@
     public void mousePressed(MouseEvent e)
     {
       if (comboBox.isEnabled())
-	togglePopup();
+        togglePopup();
     }
 
     /**
@@ -772,15 +777,15 @@
       // then change selection and close popup
       if (! (releasedComponent instanceof JComboBox))
         {
-	  // List model contains the item over which mouse is released,
-	  // since it is updated every time the mouse is moved over a different
-	  // item in the list. Now that the mouse is released we need to
-	  // update model of the combo box as well. 	  
-	  comboBox.setSelectedIndex(list.getSelectedIndex());
-
-	  if (isAutoScrolling)
-	    stopAutoScrolling();
-	  hide();
+          // List model contains the item over which mouse is released,
+          // since it is updated every time the mouse is moved over a different
+          // item in the list. Now that the mouse is released we need to
+          // update model of the combo box as well. 	  
+          comboBox.setSelectedIndex(list.getSelectedIndex());
+
+          if (isAutoScrolling)
+            stopAutoScrolling();
+          hide();
         }
     }
   }
@@ -796,6 +801,7 @@
      */
     protected InvocationMouseMotionHandler()
     {
+      // Nothing to do here.
     }
 
     /**
@@ -872,6 +878,7 @@
      */
     protected ItemHandler()
     {
+      // Nothing to do here.
     }
 
     /**
@@ -881,6 +888,7 @@
      */
     public void itemStateChanged(ItemEvent e)
     {
+      // TODO: What should be done here?
     }
   }
 
@@ -894,16 +902,17 @@
   {
     protected ListMouseHandler()
     {
+      // Nothing to do here.
     }
 
     public void mousePressed(MouseEvent e)
     {
+      // TODO: What should be do here?
     }
 
     public void mouseReleased(MouseEvent anEvent)
     {
-      int index = list.locationToIndex(anEvent.getPoint());
-      comboBox.setSelectedIndex(index);
+      updateListBoxSelectionForEvent(anEvent, false);
       hide();
     }
   }
@@ -917,15 +926,12 @@
   {
     protected ListMouseMotionHandler()
     {
+      // Nothing to do here.
     }
 
     public void mouseMoved(MouseEvent anEvent)
     {
-      // Highlight list cells over which the mouse is located. 
-      // This changes list model, but has no effect on combo box's data model
-      int index = list.locationToIndex(anEvent.getPoint());
-      list.setSelectedIndex(index);
-      list.repaint();
+      updateListBoxSelectionForEvent(anEvent, false);
     }
   }
 
@@ -938,6 +944,7 @@
   {
     protected PropertyChangeHandler()
     {
+      // Nothing to do here.
     }
 
     public void propertyChange(PropertyChangeEvent e)
@@ -1013,18 +1020,22 @@
   {
     public ListDataHandler()
     {
+      // Nothing to do here.
     }
 
     public void contentsChanged(ListDataEvent e)
     {
+      // Nothing to do here.
     }
 
     public void intervalAdded(ListDataEvent e)
     {
+      // Nothing to do here.
     }
 
     public void intervalRemoved(ListDataEvent e)
     {
+      // Nothing to do here.
     }
   }
 
@@ -1036,10 +1047,12 @@
   {
     protected ListSelectionHandler()
     {
+      // Nothing to do here.
     }
 
     public void valueChanged(ListSelectionEvent e)
     {
+      // Nothing to do here.
     }
   }
 
@@ -1050,10 +1063,12 @@
   {
     public InvocationKeyHandler()
     {
+      // Nothing to do here.
     }
 
     public void keyReleased(KeyEvent e)
     {
+      // Nothing to do here.
     }
   }
 }
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to