Hi Mark,

> On Sat, 2007-01-06 at 16:44 +0100, Roman Kennke wrote:
> > This fixes one weird NPE (see associated bug report) and I also cleaned
> > up some inconsistencies that I came over and some warnings that Eclipse
> > came over :-)
> > 
> > 2007-01-06  Roman Kennke  <[EMAIL PROTECTED]>
> > 
> >     PR 30337
> >     * javax/swing/plaf/basic/BasicComboBoxUI.java
> >     (installUI): Install popup and list here.
> >     Don't configure the arrow button and editor here.
> >     (installComponents): Don't install popup and list here. (Moved
> >     to installUI). Configure arrow button here and check for null.
> >     (addEditor): Configure editor here.
> >     (configureArrowButton): Directly fetch listeners from popup.
> >     (paintCurrentValue): Removed unused local variables.
> >     (layoutContainer): Removed unused local variables.
> >     (PropertyChangeHandler.propertyChange): Don't invalidate minimumSize
> >     on each property change. Avoid calling getPropertyName() repeatedly.
> >     Clean up. Call addEditor() when editor changes. Configure and
> >     unconfigure editor when editable changes. Use 'model' instead
> >     of non-existing 'dataModel' property.
> >     * javax/swing/plaf/basic/BasicComboPopup.java
> >     (uninstallingUI): Remove property change listener and item listener
> >     here. Uninstall list listeners. Set model to null to prevent leakage.
> >     (configureList): Don't sync list selection there.
> >     (uninstallComboBoxListeners): Moved to uninstallingUI.
> >     (uninstallListeners): Moved to uninstallingUI.
> >     * javax/swing/plaf/metal/MetalComboBoxUI.java
> >     (createPopup): Call super.
> >     (getMinimumSize): Removed unused statement.
> 
> Could you take a look at the following Mauve regressions caused by this
> patch?
> 
> FAIL: javax.swing.JComboBox.setEditor
> FAIL: javax.swing.plaf.basic.BasicComboBoxUI.general
> FAIL: javax.swing.plaf.basic.BasicComboBoxUI.getDefaultSize
> FAIL: javax.swing.plaf.basic.BasicComboBoxUI.getMaximumSize
> FAIL: javax.swing.plaf.basic.BasicComboBoxUI.getMinimumSize
> FAIL: javax.swing.plaf.metal.MetalComboBoxUI.createArrowButton

Thanks for checking. I believe that some of these failures are caused by
an earlier patch (Component.getFont() should _not_ return a default font
as checked by another Mauve test). Anyway, I fixed all these
regressions. I also added a Mauve test for the original bug report. We
are passing them all now and the combo boxes still seem to work.

2007-01-07  Roman Kennke  <[EMAIL PROTECTED]>

        PR 30337
        * java/awt/Component.java
        (getFontImpl): Return null when the component has no font set
        and also has no parent yet.
        * javax/swing/plaf/basic/BasicComboBoxUI.java
        (PropertyChangeHandler.propertyChange): Only add editor when combo
        box is editable. Avoid fetching the property name repeatedly.
        Invalidate when renderer or prototypeDisplayValue change.
        (uninstallComponents): Unconfigure everything and then remove all
        components.
        * javax/swing/plaf/basic/BasicComboPopup.java
        (uninstallingUI): Don't nullify list model.
        * javax/swing/plaf/metal/MetalComboBoxUI.java
        (createArrowButton): Pass currentValuePane to the MetalComboBoxButton
        constructor rather than a new (unconnected) CellRendererPane.


/Roman

Index: java/awt/Component.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/Component.java,v
retrieving revision 1.154
diff -u -1 -5 -r1.154 Component.java
--- java/awt/Component.java	5 Jan 2007 22:55:59 -0000	1.154
+++ java/awt/Component.java	7 Jan 2007 21:12:01 -0000
@@ -1186,31 +1186,36 @@
   /**
    * Implementation of getFont(). This is pulled out of getFont() to prevent
    * client programs from overriding this.
    *
    * @return the font of this component
    */
   private final Font getFontImpl()
   {
     Font f = font;
     if (f == null)
       {
         Component p = parent;
         if (p != null)
           f = p.getFontImpl();
         else
-          f = new Font("Dialog", Font.PLAIN, 12);
+          {
+            // It is important to return null here and not some kind of default
+            // font, otherwise the Swing UI would not install its fonts because
+            // it keeps non-UIResource fonts.
+            f = null;
+          }
       }
     return f;
   }
 
   /**
    * Sets the font for this component to the specified font. This is a bound
    * property.
    *
    * @param f the new font for this component
    * 
    * @see #getFont()
    */
   public void setFont(Font f)
   {
     Font oldFont;
Index: javax/swing/plaf/basic/BasicComboBoxUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicComboBoxUI.java,v
retrieving revision 1.41
diff -u -1 -5 -r1.41 BasicComboBoxUI.java
--- javax/swing/plaf/basic/BasicComboBoxUI.java	6 Jan 2007 15:43:21 -0000	1.41
+++ javax/swing/plaf/basic/BasicComboBoxUI.java	7 Jan 2007 21:12:01 -0000
@@ -477,48 +477,44 @@
       configureArrowButton();
 
     if (comboBox.isEditable())
       addEditor();
 
     comboBox.add(currentValuePane);
   }
 
   /**
    * Uninstalls components from this [EMAIL PROTECTED] JComboBox}.
    * 
    * @see #installComponents()
    */
   protected void uninstallComponents()
   {
-    // uninstall arrow button
-    unconfigureArrowButton();
-    comboBox.remove(arrowButton);
-    arrowButton = null;
-
-    popup = null;
-
-    if (comboBox.getRenderer() instanceof UIResource)
-      comboBox.setRenderer(null);
+    // Unconfigure arrow button.
+    if (arrowButton != null)
+      {
+        unconfigureArrowButton();
+      }
 
-    // if the editor is not an instanceof UIResource, it was not set by the
-    // UI delegate, so don't clear it...
-    ComboBoxEditor currentEditor = comboBox.getEditor();
-    if (currentEditor instanceof UIResource)
+    // Unconfigure editor.
+    if (editor != null)
       {
-        comboBox.setEditor(null);
-        editor = null;
+        unconfigureEditor();
       }
+
+    comboBox.removeAll();
+    arrowButton = null;
   }
 
   /**
    * Adds the current editor to the combo box.
    */
   public void addEditor()
   {
     removeEditor();
     editor = comboBox.getEditor().getEditorComponent();
     if (editor != null)
       {
         configureEditor();
         comboBox.add(editor);
       }
   }
@@ -1337,69 +1333,78 @@
      */
     public void propertyChange(PropertyChangeEvent e)
     {
       // Lets assume every change invalidates the minimumsize.
       String propName = e.getPropertyName();
       if (propName.equals("enabled"))
         {
           boolean enabled = comboBox.isEnabled();
           if (editor != null)
             editor.setEnabled(enabled);
           if (arrowButton != null)
             arrowButton.setEnabled(enabled);
 
           comboBox.repaint();
         }
-      else if (propName.equals("editor"))
+      else if (propName.equals("editor") && comboBox.isEditable())
         {
           addEditor();
           comboBox.revalidate();
         }
       else if (e.getPropertyName().equals("editable"))
         {
           if (comboBox.isEditable())
             {
               addEditor();
             }
           else
             {
               removeEditor();
             }
 
           comboBox.revalidate();
         }
-      else if (e.getPropertyName().equals("model"))
+      else if (propName.equals("model"))
         {
           // remove ListDataListener from old model and add it to new model
           ComboBoxModel oldModel = (ComboBoxModel) e.getOldValue();
           if (oldModel != null && listDataListener != null)
             oldModel.removeListDataListener(listDataListener);
 
           ComboBoxModel newModel = (ComboBoxModel) e.getNewValue();
           if (newModel != null && listDataListener != null)
             comboBox.getModel().addListDataListener(listDataListener);
 
           if (editor != null)
             {
               comboBox.configureEditor(comboBox.getEditor(),
                                        comboBox.getSelectedItem());
             }
           isMinimumSizeDirty = true;
           comboBox.revalidate();
           comboBox.repaint();
         }
-      else if (e.getPropertyName().equals("font"))
+      else if (propName.equals("font"))
         {
           Font font = (Font) e.getNewValue();
           if (editor != null)
             {
               editor.setFont(font);
             }
           listBox.setFont(font);
           isMinimumSizeDirty = true;
           comboBox.revalidate();
         }
-
+      else if (propName.equals("prototypeDisplayValue"))
+        {
+          isMinimumSizeDirty = true;
+          comboBox.revalidate();
+        }
+      else if (propName.equals("renderer"))
+        {
+          isMinimumSizeDirty = true;
+          comboBox.revalidate();
+        }
       // FIXME: Need to handle changes in other bound properties.       
     }
   }
 }
Index: javax/swing/plaf/basic/BasicComboPopup.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicComboPopup.java,v
retrieving revision 1.20
diff -u -1 -5 -r1.20 BasicComboPopup.java
--- javax/swing/plaf/basic/BasicComboPopup.java	6 Jan 2007 15:43:21 -0000	1.20
+++ javax/swing/plaf/basic/BasicComboPopup.java	7 Jan 2007 21:12:01 -0000
@@ -270,31 +270,30 @@
    * This method uninstalls the UI for the  given JComponent.
    */
   public void uninstallingUI()
   {
     if (propertyChangeListener != null)
       {
         comboBox.removePropertyChangeListener(propertyChangeListener);
       }
     if (itemListener != null)
       {
         comboBox.removeItemListener(itemListener);
       }
     uninstallComboBoxModelListeners(comboBox.getModel());
     uninstallKeyboardActions();
     uninstallListListeners();
-    list.setModel(null);
   }
 
   /**
    * This method uninstalls listeners that were listening to changes occuring
    * in the comb box's data model
    *
    * @param model data model for the combo box from which to uninstall
    *        listeners
    */
   protected void uninstallComboBoxModelListeners(ComboBoxModel model)
   {
     model.removeListDataListener(listDataListener);
   }
 
   /**
Index: javax/swing/plaf/metal/MetalComboBoxUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalComboBoxUI.java,v
retrieving revision 1.13
diff -u -1 -5 -r1.13 MetalComboBoxUI.java
--- javax/swing/plaf/metal/MetalComboBoxUI.java	6 Jan 2007 15:43:21 -0000	1.13
+++ javax/swing/plaf/metal/MetalComboBoxUI.java	7 Jan 2007 21:12:01 -0000
@@ -36,31 +36,30 @@
 exception statement from your version. */
 
 
 package javax.swing.plaf.metal;
 
 import java.awt.Color;
 import java.awt.Container;
 import java.awt.Dimension;
 import java.awt.Graphics;
 import java.awt.Insets;
 import java.awt.LayoutManager;
 import java.awt.event.MouseEvent;
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
 
-import javax.swing.CellRendererPane;
 import javax.swing.ComboBoxEditor;
 import javax.swing.Icon;
 import javax.swing.JButton;
 import javax.swing.JComboBox;
 import javax.swing.JComponent;
 import javax.swing.plaf.ComponentUI;
 import javax.swing.plaf.basic.BasicComboBoxUI;
 import javax.swing.plaf.basic.BasicComboPopup;
 import javax.swing.plaf.basic.ComboPopup;
 
 
 /**
  * A UI delegate for the [EMAIL PROTECTED] JComboBox} component.
  */
 public class MetalComboBoxUI extends BasicComboBoxUI
@@ -216,31 +215,31 @@
    * @return A popup.
    */
   protected ComboPopup createPopup()
   {
     return super.createPopup();
   }
   
   /**
    * Creates a new button for use in rendering the JComboBox.
    * 
    * @return A button.
    */
   protected JButton createArrowButton()
   {
     JButton button = new MetalComboBoxButton(comboBox, new MetalComboBoxIcon(), 
-            new CellRendererPane(), listBox);  
+            currentValuePane, listBox);  
     button.setMargin(new Insets(0, 1, 1, 3));
     return button;
   }
   
   /**
    * Creates a new property change listener.
    * 
    * @return A new property change listener.
    */
   public PropertyChangeListener createPropertyChangeListener()
   {
     return new MetalPropertyChangeListener();
   }
   
   public void paint(Graphics g, JComponent c)

Reply via email to