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

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

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

revision 1.14 by rabbit78, Sun Feb 27 20:35:55 2005 UTC revision 1.15 by rabbit78, Mon Feb 28 13:14:19 2005 UTC
# Line 56  import java.beans.PropertyChangeListener Line 56  import java.beans.PropertyChangeListener
56  import javax.swing.CellRendererPane;  import javax.swing.CellRendererPane;
57  import javax.swing.JComponent;  import javax.swing.JComponent;
58  import javax.swing.JList;  import javax.swing.JList;
59    import javax.swing.JViewport;
60  import javax.swing.ListCellRenderer;  import javax.swing.ListCellRenderer;
61  import javax.swing.ListModel;  import javax.swing.ListModel;
62  import javax.swing.ListSelectionModel;  import javax.swing.ListSelectionModel;
# Line 386  public class BasicListUI extends ListUI Line 387  public class BasicListUI extends ListUI
387      if (l != list || cellWidth == -1)      if (l != list || cellWidth == -1)
388        return null;        return null;
389    
390      int lo = Math.min(index1, index2);      int minIndex = Math.min(index1, index2);
391      int hi = Math.max(index1, index2);      int maxIndex = Math.max(index1, index2);
392      Point loLoc = indexToLocation(list, lo);      Point loc = indexToLocation(list, minIndex);
393      Point hiLoc = indexToLocation(list, hi);      Rectangle bounds = new Rectangle(loc.x, loc.y, cellWidth,
394      Rectangle lobounds = new Rectangle(loLoc.x, loLoc.y, cellWidth,                                       getRowHeight(minIndex));
                                        getRowHeight(lo));  
     Rectangle hibounds = new Rectangle(hiLoc.x, hiLoc.y, cellWidth,  
                                        getRowHeight(hi));  
395    
396      return lobounds.union(hibounds);      for (int i = minIndex + 1; i <= maxIndex; i++)
397          {
398            Point hiLoc = indexToLocation(list, i);
399            Rectangle hibounds = new Rectangle(hiLoc.x, hiLoc.y, cellWidth,
400                                           getRowHeight(i));
401            bounds = bounds.union(hibounds);
402          }
403    
404        return bounds;
405    }    }
406    
407    /**    /**
# Line 639  public class BasicListUI extends ListUI Line 645  public class BasicListUI extends ListUI
645     */     */
646    public Dimension getPreferredSize(JComponent c)    public Dimension getPreferredSize(JComponent c)
647    {    {
648      if (list.getModel().getSize() == 0)      int size = list.getModel().getSize();
649        if (size == 0)
650        return new Dimension(0, 0);        return new Dimension(0, 0);
651        int visibleRows = list.getVisibleRowCount();
652        int layoutOrientation = list.getLayoutOrientation();
653      Rectangle bounds = getCellBounds(list, 0, list.getModel().getSize() - 1);      Rectangle bounds = getCellBounds(list, 0, list.getModel().getSize() - 1);
654      return bounds.getSize();      Dimension retVal = bounds.getSize();
655        Component parent = list.getParent();
656        if ((visibleRows == -1) && (parent instanceof JViewport))
657          {
658            JViewport viewport = (JViewport) parent;
659    
660            if (layoutOrientation == JList.HORIZONTAL_WRAP)
661              {
662                int h = viewport.getSize().height;
663                int cellsPerCol = h / cellHeight;
664                int w = size / cellsPerCol * cellWidth;
665                retVal = new Dimension(w, h);
666              }
667            else if (layoutOrientation == JList.VERTICAL_WRAP)
668              {
669                int w = viewport.getSize().width;
670                int cellsPerRow = Math.max(w / cellWidth, 1);
671                int h = size / cellsPerRow * cellHeight;
672                retVal = new Dimension(w, h);
673              }
674          }
675        return retVal;
676    }    }
677    
678    /**    /**

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.15

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