Hi there,

> I don't have too much time to look at your combo box changes right now 
> (there's a new baby in the Gilbert household!), but I noticed there are 
> some Mauve regressions.

I looked into it and managed to make all the Mauve tests PASS (with some
Mauve tests adjusted to check for the correct logic rather than pixel
values). The mistake I was making was obviously that I developed and
tested my stuff against an application that was coded for Swing1.1 and
makes heavy use of the plaf stuff. However, this fix still works with
this 'old' app and passes all the 1.5 mauve tests, so it must be
good ;-)


2006-03-18  Roman Kennke  <[EMAIL PROTECTED]>

        * javax/swing/plaf/basic/BasicComboBoxEditor.java
        (listener): Removed field.
        (BasicComboBoxEditor): Removed initialization of listener field.
        (addActionListener): Add listener directly to editor.
        (removeActionListener): Remove listener directly from editor.
        (ComboBoxEditorListener): Removed class.
        * javax/swing/plaf/basic/BasicComboBoxUI.java
        (getPreferredSize): Fixed to return the minimumSize.
        (getMinimumSize): Improved code for more clearness.
        (getMaximumSize): Return (32767,32767) as requested by the mauve
test.
        (rectangleForCurrentValue): Correctly respect insets.
        (getDefaultSize): Return preferredSize here. Dont override
height
        with 100.
        (getDisplaySize): Moved around code for more clearness. Added
        handling of prototype renderer.
        (ComboBoxLayoutManager.layoutContainer): Set editor bounds after
        arrowButton bounds since the former depends on the latter.
        * javax/swing/plaf/metal/MetalComboBoxButton.java:
        (MetalComboBoxButton): Make button rollover disabled.
        (isFocusTraversable): Return false unconditionally.
        * javax/swing/plaf/metal/MetalComboBoxEditor.java:
        (EditorTextField): New class. Fixes the size properties.
        (MetalComboBoxEditor): Create instance of EditorTextField.
        * javax/swing/plaf/metal/MetalComboBoxUI.java:
        (getMinimumSize): Fixed editable size.


Cheers, Roman

-- 
“Improvement makes straight roads, but the crooked roads, without
Improvement, are roads of Genius.” - William Blake
Index: javax/swing/plaf/basic/BasicComboBoxEditor.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicComboBoxEditor.java,v
retrieving revision 1.9
diff -u -r1.9 BasicComboBoxEditor.java
--- javax/swing/plaf/basic/BasicComboBoxEditor.java	14 Mar 2006 13:29:10 -0000	1.9
+++ javax/swing/plaf/basic/BasicComboBoxEditor.java	19 Mar 2006 11:03:04 -0000
@@ -39,14 +39,10 @@
 package javax.swing.plaf.basic;
 
 import java.awt.Component;
-import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.FocusEvent;
 import java.awt.event.FocusListener;
 
-import java.util.Iterator;
-import java.util.LinkedList;
-
 import javax.swing.ComboBoxEditor;
 import javax.swing.JTextField;
 
@@ -62,8 +58,6 @@
   /** The editor component. */
   protected JTextField editor;
 
-  private ComboBoxEditorListener listener;
-
   /**
    * Creates a new <code>BasicComboBoxEditor</code> instance.
    */
@@ -72,7 +66,6 @@
     editor = new JTextField();
     editor.setBorder(null);
     editor.setColumns(9);
-    listener = new ComboBoxEditorListener();
   }
 
   /**
@@ -156,7 +149,7 @@
    */
   public void addActionListener(ActionListener l)
   {
-    listener.addListener(l);
+    editor.addActionListener(l);
   }
 
   /**
@@ -166,7 +159,7 @@
    */
   public void removeActionListener(ActionListener l)
   {
-    listener.removeListener(l);
+    editor.removeActionListener(l);
   }
 
   /**
@@ -185,37 +178,4 @@
     }
   }
 
-  /**
-   * Helper class that forwards action events between the jtextfield
-   * editor and the basic combo box editor for use by the combo box.
-   */
-  class ComboBoxEditorListener implements ActionListener
-  {
-    private final LinkedList listeners = new LinkedList();
-  
-    public void actionPerformed(ActionEvent ae)
-    {
-      ActionEvent nae;
-      nae = new ActionEvent(BasicComboBoxEditor.this,
-			    ae.getID(), ae.getActionCommand(),
-			    ae.getWhen(), ae.getModifiers());
-      Iterator it = listeners.iterator();
-      while (it.hasNext())
-	((ActionListener) it.next()).actionPerformed(nae);
-    }
-
-    void addListener(ActionListener al)
-    {
-      if (listeners.size() == 0)
-	editor.addActionListener(this);
-      listeners.add(al);
-    }
-
-    void removeListener(ActionListener al)
-    {
-      listeners.remove(al);
-      if (listeners.size() == 0)
-	editor.removeActionListener(this);
-    }
-  }
 }
Index: javax/swing/plaf/basic/BasicComboBoxUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicComboBoxUI.java,v
retrieving revision 1.32
diff -u -r1.32 BasicComboBoxUI.java
--- javax/swing/plaf/basic/BasicComboBoxUI.java	17 Mar 2006 16:20:58 -0000	1.32
+++ javax/swing/plaf/basic/BasicComboBoxUI.java	19 Mar 2006 11:03:05 -0000
@@ -70,7 +70,6 @@
 import javax.swing.JList;
 import javax.swing.ListCellRenderer;
 import javax.swing.LookAndFeel;
-import javax.swing.SwingUtilities;
 import javax.swing.UIManager;
 import javax.swing.event.ListDataEvent;
 import javax.swing.event.ListDataListener;
@@ -672,9 +671,7 @@
    */
   public Dimension getPreferredSize(JComponent c)
   {
-    Dimension size = getMinimumSize(c);
-    size.width += 4;
-    return size;
+    return getMinimumSize(c);
   }
 
   /**
@@ -691,10 +688,8 @@
       {
         Insets i = getInsets();
         Dimension d = getDisplaySize();
-        d.height += i.top + i.bottom;
-        int arrowButtonWidth = d.height - (i.top + i.bottom);
-        cachedMinimumSize = new Dimension(d.width + arrowButtonWidth + i.left
-                                          + i.right, d.height);
+        d.width += i.left + i.right + d.height;
+        cachedMinimumSize = new Dimension(d.width, d.height + i.top + i.bottom);
         isMinimumSizeDirty = false;
       }
     return new Dimension(cachedMinimumSize);
@@ -710,9 +705,7 @@
    */
   public Dimension getMaximumSize(JComponent c)
   {
-    Dimension size = getPreferredSize(c);
-    size.width = 32767;
-    return size;
+    return new Dimension(32767, 32767);
   }
 
   public int getAccessibleChildrenCount(JComponent c)
@@ -780,11 +773,16 @@
    */
   protected Rectangle rectangleForCurrentValue()
   {
-    Rectangle cbBounds = SwingUtilities.getLocalBounds(comboBox);
-    Rectangle abBounds = arrowButton.getBounds();   
-    Rectangle rectForCurrentValue = new Rectangle(cbBounds.x, cbBounds.y,
-      cbBounds.width - abBounds.width, cbBounds.height);
-    return rectForCurrentValue;
+    int w = comboBox.getWidth();
+    int h = comboBox.getHeight();
+    Insets i = comboBox.getInsets();
+    int arrowSize = h - (i.top + i.bottom);
+    if (arrowButton != null)
+      {
+        arrowSize = arrowButton.getWidth();
+      }
+    return new Rectangle(i.left, i.top, w - (i.left + i.right + arrowSize),
+                         h - (i.top + i.left));
   }
 
   /**
@@ -902,9 +900,9 @@
                                                                    false);
     currentValuePane.add(comp);
     comp.setFont(comboBox.getFont());
-    int h = comp.getPreferredSize().height;
+    Dimension d = comp.getPreferredSize();
     currentValuePane.remove(comp);
-    return new Dimension(100, h);
+    return d;
   }
 
   /**
@@ -915,37 +913,58 @@
    */
   protected Dimension getDisplaySize()
   {
-    if (comboBox.isEditable() && comboBox.getModel().getSize() == 0)
-      return new Dimension(100, editor.getPreferredSize().height);
-
     Dimension dim = new Dimension();
     ListCellRenderer renderer = comboBox.getRenderer();
-    ComboBoxModel model = comboBox.getModel();
-    if (renderer != null && model.getSize() > 0)
+    if (renderer == null)
+      {
+        renderer = DEFAULT_RENDERER;
+      }
+    
+    Object prototype = comboBox.getPrototypeDisplayValue();
+    if (prototype != null)
+      {
+        Component comp = renderer.getListCellRendererComponent
+          (listBox, prototype, -1, false, false);
+        currentValuePane.add(comp);
+        comp.setFont(comboBox.getFont());
+        Dimension renderSize = comp.getPreferredSize();
+        currentValuePane.remove(comp);
+        dim.height = renderSize.height;
+        dim.width = renderSize.width;
+      }
+    else
       {
-        // TODO: Optimize using prototype here.
+        ComboBoxModel model = comboBox.getModel();
         int size = model.getSize();
-        for (int i = 0; i < size; ++i)
+        if (size > 0)
           {
-            Component comp = renderer.getListCellRendererComponent
-              (listBox, model.getElementAt(i), -1, false, false);
-            currentValuePane.add(comp);
-            comp.setFont(comboBox.getFont());
-            Dimension renderSize = comp.getPreferredSize();
-            currentValuePane.remove(comp);
-            dim.width = Math.max(dim.width, renderSize.width);
-            dim.height = Math.max(dim.height, renderSize.height);
+            for (int i = 0; i < size; ++i)
+              {
+                Component comp = renderer.getListCellRendererComponent
+                (listBox, model.getElementAt(i), -1, false, false);
+                currentValuePane.add(comp);
+                comp.setFont(comboBox.getFont());
+                Dimension renderSize = comp.getPreferredSize();
+                currentValuePane.remove(comp);
+                dim.width = Math.max(dim.width, renderSize.width);
+                dim.height = Math.max(dim.height, renderSize.height);
+              }
           }
-        if (comboBox.isEditable())
+        else
           {
-            Dimension editSize = editor.getPreferredSize();
-            dim.width = Math.max(dim.width, editSize.width);
-            dim.height = Math.max(dim.height, editSize.height);
+            dim = getDefaultSize();
+            if (comboBox.isEditable())
+              dim.width = 100;
           }
-        displaySize.setSize(dim.width, dim.height);
-        return displaySize;
       }
-    return getDefaultSize();
+    if (comboBox.isEditable())
+      {
+        Dimension editSize = editor.getPreferredSize();
+        dim.width = Math.max(dim.width, editSize.width);
+        dim.height = Math.max(dim.height, editSize.height);
+      }
+    displaySize.setSize(dim.width, dim.height);
+    return dim;
   }
 
   /**
@@ -1046,12 +1065,11 @@
       int arrowSize = comboBox.getHeight() - (i.top + i.bottom);
       int editorWidth = comboBox.getBounds().width - arrowSize;
 
-      if (editor != null)
-        editor.setBounds(rectangleForCurrentValue());
-
       if (arrowButton != null)
         arrowButton.setBounds(comboBox.getWidth() - (i.right + arrowSize),
                               i.top, arrowSize, arrowSize);
+      if (editor != null)
+        editor.setBounds(rectangleForCurrentValue());
     }
   }
 
Index: javax/swing/plaf/metal/MetalComboBoxButton.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalComboBoxButton.java,v
retrieving revision 1.8
diff -u -r1.8 MetalComboBoxButton.java
--- javax/swing/plaf/metal/MetalComboBoxButton.java	17 Mar 2006 21:13:17 -0000	1.8
+++ javax/swing/plaf/metal/MetalComboBoxButton.java	19 Mar 2006 11:03:05 -0000
@@ -112,6 +112,7 @@
     iconOnly = onlyIcon;
     listBox = list;
     rendererPane = pane;
+    setRolloverEnabled(false);
     setEnabled(comboBox.isEnabled());
     setFocusable(comboBox.isEnabled());
   }
@@ -187,7 +188,7 @@
    */
   public boolean isFocusTraversable()
   {
-    return !comboBox.isEditable() && comboBox.isEnabled();
+    return false;
   }
   
   /**
Index: javax/swing/plaf/metal/MetalComboBoxEditor.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalComboBoxEditor.java,v
retrieving revision 1.7
diff -u -r1.7 MetalComboBoxEditor.java
--- javax/swing/plaf/metal/MetalComboBoxEditor.java	17 Mar 2006 23:02:16 -0000	1.7
+++ javax/swing/plaf/metal/MetalComboBoxEditor.java	19 Mar 2006 11:03:05 -0000
@@ -39,6 +39,7 @@
 package javax.swing.plaf.metal;
 
 import java.awt.Component;
+import java.awt.Dimension;
 import java.awt.Graphics;
 import java.awt.Insets;
 
@@ -140,7 +141,40 @@
       // Nothing to do here.
     }
   }
-  
+
+  /**
+   * A special textfield implementation for the MetalComboBoxEditor.
+   */
+  private class EditorTextField extends JTextField
+  {
+    EditorTextField(String s, int columns)
+    {
+      super(s, columns);
+    }
+
+    /**
+     * Tests seem to show that the textfield in MetalComboBoxEditors have
+     * a height + 4.
+     */
+    public Dimension getPreferredSize()
+    {
+      Dimension size = super.getPreferredSize();
+      size.height += 4;
+      return size;
+    }
+
+    /**
+     * Tests seem to show that the textfield in MetalComboBoxEditors have
+     * a height + 4.
+     */
+    public Dimension getMinimumSize()
+    {
+      Dimension size = super.getMinimumSize();
+      size.height += 4;
+      return size;
+    }
+  }
+
   /** The editor's border insets. */
   protected static Insets editorBorderInsets = new Insets(2, 2, 2, 0);
   
@@ -149,7 +183,7 @@
    */
   public MetalComboBoxEditor()
   {
-    editor = new JTextField("", 9);
+    editor = new EditorTextField("", 9);
     editor.setBorder(new MetalComboBoxEditorBorder());
   }
   
Index: javax/swing/plaf/metal/MetalComboBoxUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalComboBoxUI.java,v
retrieving revision 1.10
diff -u -r1.10 MetalComboBoxUI.java
--- javax/swing/plaf/metal/MetalComboBoxUI.java	17 Mar 2006 21:30:01 -0000	1.10
+++ javax/swing/plaf/metal/MetalComboBoxUI.java	19 Mar 2006 11:03:05 -0000
@@ -306,14 +306,8 @@
       {
         d = super.getMinimumSize(c);
         Insets arrowMargin = arrowButton.getMargin();
-        Insets comboInsets = comboBox.getInsets();
-        if (editor instanceof JComponent)
-          {
-            Insets editorInsets = ((JComponent) editor).getInsets();
-            d.height += editorInsets.top + editorInsets.bottom;
-          }
         d.height += arrowMargin.top + arrowMargin.bottom;
-        d.height += comboInsets.top + comboInsets.bottom;
+        d.width += arrowMargin.left + arrowMargin.right;
       }
     else
       {

Attachment: signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil

Reply via email to