/[classpath]/classpath/javax/swing/plaf/basic/BasicComboBoxUI.java
ViewVC logotype

Diff of /classpath/javax/swing/plaf/basic/BasicComboBoxUI.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.11 by trebligd, Tue Sep 13 21:10:50 2005 UTC revision 1.12 by langel, Thu Sep 15 19:58:43 2005 UTC
# Line 844  public class BasicComboBoxUI extends Com Line 844  public class BasicComboBoxUI extends Com
844     */     */
845    protected Dimension getDefaultSize()    protected Dimension getDefaultSize()
846    {    {
847      return new Dimension(6, 17);      // FIXME: Not implemented properly.
848        return new Dimension(100, 20);
849    }    }
850    
851    /**    /**
# Line 853  public class BasicComboBoxUI extends Com Line 854  public class BasicComboBoxUI extends Com
854     *     *
855     * @return dimensions of the largest item in the combo box.     * @return dimensions of the largest item in the combo box.
856     */     */
857    protected Dimension getLargestItemSize()    private Dimension getLargestItemSize()
858    {    {
859      ComboBoxModel model = comboBox.getModel();      ComboBoxModel model = comboBox.getModel();
860      int numItems = model.getSize();      int numItems = model.getSize();
# Line 939  public class BasicComboBoxUI extends Com Line 940  public class BasicComboBoxUI extends Com
940        Dimension d = new Dimension(0, 0);        Dimension d = new Dimension(0, 0);
941    
942        if (largestItemSize == null)        if (largestItemSize == null)
943          largestItemSize = getLargestItemSize();          largestItemSize = getLargestItemSize();
944    
945        // add size for the area that will display selected item        // add size for the area that will display selected item
946        d.width += largestItemSize.getWidth();        d.width += largestItemSize.getWidth();
# Line 962  public class BasicComboBoxUI extends Com Line 963  public class BasicComboBoxUI extends Com
963    
964      public Dimension minimumLayoutSize(Container parent)      public Dimension minimumLayoutSize(Container parent)
965      {      {
966        return preferredLayoutSize(parent);        Dimension minSize = getDefaultSize();
967          ComboBoxModel model = comboBox.getModel();
968          int numItems = model.getSize();
969    
970          if (numItems == 0)
971              return minSize;
972    
973          ListCellRenderer renderer = comboBox.getRenderer();
974    
975          for (int i = 0; i < numItems; i++)
976            {
977          Object item = model.getElementAt(i);
978          String s = item.toString();
979          Component comp = renderer.getListCellRendererComponent(listBox, item,
980                                                                 -1, false, false);
981    
982          if (comp.getPreferredSize().width < minSize.width)
983            minSize =  comp.getMinimumSize();
984            }
985          return minSize;
986      }      }
987    
988      /**      /**
# Line 1105  public class BasicComboBoxUI extends Com Line 1125  public class BasicComboBoxUI extends Com
1125       */       */
1126      public void intervalAdded(ListDataEvent e)      public void intervalAdded(ListDataEvent e)
1127      {      {
       // must determine if the size of the combo box should change  
       int start = e.getIndex0();  
       int end = e.getIndex1();  
   
1128        ComboBoxModel model = comboBox.getModel();        ComboBoxModel model = comboBox.getModel();
1129        ListCellRenderer renderer = comboBox.getRenderer();        ListCellRenderer renderer = comboBox.getRenderer();
1130    
1131        if (largestItemSize == null)        if (largestItemSize == null)
1132          largestItemSize = new Dimension(0, 0);          largestItemSize = getLargestItemSize();
1133          if (largestItemSize.width < getDefaultSize().width)
1134            largestItemSize.width = getDefaultSize().width;
1135          if (largestItemSize.height < getDefaultSize().height)
1136            largestItemSize.height = getDefaultSize().height;
1137    
1138        for (int i = start; i < end; i++)        comboBox.repaint();
         {  
           Object item = model.getElementAt(i);  
           Component comp = renderer.getListCellRendererComponent(new JList(),  
                                                                  item, -1,  
                                                                  false, false);  
           if (comp.getPreferredSize().getWidth() > largestItemSize.getWidth())  
             largestItemSize = comp.getPreferredSize();  
         }  
1139      }      }
1140    
1141      /**      /**

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.12

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26