classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] FYI: BasicComboBoxUI.getLargestItemSize()


From: David Gilbert
Subject: [cp-patches] FYI: BasicComboBoxUI.getLargestItemSize()
Date: Sun, 18 Sep 2005 14:44:01 +0000
User-agent: Mozilla Thunderbird 1.0.6 (X11/20050728)

The (private) method getLargestItemSize() is a good match for the missing getDisplaySize() method, so I renamed it and made it protected:

2005-09-18  David Gilbert  <address@hidden>

        * javax/swing/plaf/basic/BasicComboBoxUI.java
        (largestItemSize): renamed displaySize,
        (getLargestItemSize): renamed getDisplaySize and changed to protected,
        (ComboBoxLayoutManager.preferredLayoutSize): updated for renamed field
        and method,
        (ListDataHandler.intervalAdded): likewise,
        (ListDataHandler.intervalRemoved): likewise.

Regards,

Dave
Index: javax/swing/plaf/basic/BasicComboBoxUI.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicComboBoxUI.java,v
retrieving revision 1.13
diff -u -r1.13 BasicComboBoxUI.java
--- javax/swing/plaf/basic/BasicComboBoxUI.java 18 Sep 2005 10:41:11 -0000      
1.13
+++ javax/swing/plaf/basic/BasicComboBoxUI.java 18 Sep 2005 13:26:54 -0000
@@ -165,7 +165,7 @@
   /* Size of the largest item in the comboBox
    * This is package-private to avoid an accessor method.
    */
-  Dimension largestItemSize;
+  Dimension displaySize;
 
   // It seems that JComboBox doesn't have a border set explicitely. So we just
   // paint the border everytime combo box is displayed. 
@@ -874,7 +874,7 @@
    *
    * @return dimensions of the largest item in the combo box.
    */
-  private Dimension getLargestItemSize()
+  protected Dimension getDisplaySize()
   {
     ComboBoxModel model = comboBox.getModel();
     int numItems = model.getSize();
@@ -883,8 +883,8 @@
     // return its default size
     if (numItems == 0)
       {
-       largestItemSize = getDefaultSize();
-       return largestItemSize;
+       displaySize = getDefaultSize();
+       return displaySize;
       }
 
     Dimension size = new Dimension(0, 0);
@@ -893,6 +893,8 @@
     // size of the largest item in the combo box. 
     ListCellRenderer renderer = comboBox.getRenderer();
 
+    // FIXME: use the JComboBox.getPrototypeDisplayValue() if there is
+    // one
     for (int i = 0; i < numItems; i++)
       {
        Object item = model.getElementAt(i);
@@ -904,8 +906,8 @@
          size = comp.getPreferredSize();
       }
 
-    largestItemSize = size;
-    return largestItemSize;
+    displaySize = size;
+    return displaySize;
   }
 
   /**
@@ -976,12 +978,12 @@
     {
       Dimension d = new Dimension(0, 0);
 
-      if (largestItemSize == null)
-        largestItemSize = getLargestItemSize();
+      if (displaySize == null)
+        displaySize = getDisplaySize();
 
       // add size for the area that will display selected item
-      d.width += largestItemSize.getWidth();
-      d.height += largestItemSize.getHeight();
+      d.width += displaySize.getWidth();
+      d.height += displaySize.getHeight();
 
       // add size of the arrow button
       d.width += arrowButtonWidth;
@@ -1170,12 +1172,12 @@
       ComboBoxModel model = comboBox.getModel();
       ListCellRenderer renderer = comboBox.getRenderer();
 
-      if (largestItemSize == null)
-        largestItemSize = getLargestItemSize();
-      if (largestItemSize.width < getDefaultSize().width)
-        largestItemSize.width = getDefaultSize().width;
-      if (largestItemSize.height < getDefaultSize().height)
-        largestItemSize.height = getDefaultSize().height;
+      if (displaySize == null)
+        displaySize = getDisplaySize();
+      if (displaySize.width < getDefaultSize().width)
+        displaySize.width = getDefaultSize().width;
+      if (displaySize.height < getDefaultSize().height)
+        displaySize.height = getDefaultSize().height;
 
       comboBox.repaint();
     }
@@ -1189,7 +1191,7 @@
     public void intervalRemoved(ListDataEvent e)
     {
       // recalculate display size of the JComboBox.
-      largestItemSize = getLargestItemSize();
+      displaySize = getDisplaySize();
       comboBox.repaint();
     }
   }

reply via email to

[Prev in Thread] Current Thread [Next in Thread]