[kaffe] CVS kaffe (robilad): Resynced with GNU Classpath: swing fixes

Kaffe CVS cvs-commits at kaffe.org
Wed Mar 2 15:00:38 PST 2005


PatchSet 5491 
Date: 2005/03/02 22:56:19
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
Resynced with GNU Classpath: swing fixes

2005-03-02  Dalibor Topic  <robilad at kaffe.org>

        Resynced with GNU Classpath.

        2005-02-27  Roman Kennke  <roman at ontographics.com>

        * javax/swing/JList.java
        (getPreferredScrollableViewportSize):
        The previous implementation was merely guessing the size,
        now it respects layoutOrientation, visibleRowCount
        and preferredSize.
        (getScrollableTracksViewportHeight):
        Reimplemented so that layoutOrientation, visibleRowCount
        and preferred size are respected.
        (getScrollableTracksViewportWidth):
        Reimplemented so that layoutOrientation, visibleRowCount
        and preferred size are respected.
        * javax/swing/plaf/basic/BasicListUI.java
        (getPreferredSize):
        Improved calculation of preferredSize when JList is
        set to HORIZONTAL_WRAP or VERTICAL_WRAP.
        (getCellBounds):
        The previous implementation assumed a layoutOrientation of
        JList.VERTICAL, now also ok with JList.HORIZONTAL_WRAP and
        JList.VERTICAL_WRAP.

Members: 
	libraries/javalib/javax/swing/JList.java:1.8->1.9 
	libraries/javalib/javax/swing/plaf/basic/BasicListUI.java:1.8->1.9 

Index: kaffe/libraries/javalib/javax/swing/JList.java
diff -u kaffe/libraries/javalib/javax/swing/JList.java:1.8 kaffe/libraries/javalib/javax/swing/JList.java:1.9
--- kaffe/libraries/javalib/javax/swing/JList.java:1.8	Sat Feb 19 15:23:41 2005
+++ kaffe/libraries/javalib/javax/swing/JList.java	Wed Mar  2 22:56:19 2005
@@ -1029,32 +1029,20 @@
    */
   public Dimension getPreferredScrollableViewportSize()
   {
-    int vis = getVisibleRowCount();
-    int nrows = getModel() == null ? 0 : getModel().getSize();
-    // FIXME: this is a somewhat arbitrary default, but.. ?
-    Dimension single = new Dimension(10, 10);;
-    Rectangle bounds = null;
 
-    if (vis > nrows)
+    Dimension retVal = getPreferredSize();
+    if (getLayoutOrientation() == VERTICAL)
       {
-        if (fixedCellWidth != -1 && 
-            fixedCellHeight != -1)
+        if (fixedCellHeight != -1)
           {
-            single = new Dimension(fixedCellWidth, fixedCellHeight);
-          }
-        else if (nrows != 0 && getUI() != null)
-          {
-            Rectangle tmp = getUI().getCellBounds(this, 0, 0);
-            if (tmp != null)
-              single = tmp.getSize();
-          }
-      }
-    else if (getUI() != null)
-      {
-        return getUI().getCellBounds(this, 0, vis - 1).getSize();
+            if (fixedCellWidth != -1)
+              {
+                int size = getModel().getSize();
+                retVal = new Dimension(fixedCellWidth, size * fixedCellHeight);
+              } // TODO: add else clause (preferredSize is ok for now)
+          } // TODO: add else clause (preferredSize is ok for now)
       }
-
-    return new Dimension(single.width, single.height * vis);
+    return retVal;
   }
 
   /**
@@ -1193,7 +1181,19 @@
    */
   public boolean getScrollableTracksViewportWidth()
   {
-    return false;
+    Component parent = getParent();
+    boolean retVal = false;
+    if (parent instanceof JViewport)
+      {
+        JViewport viewport = (JViewport) parent;
+        Dimension pref = getPreferredSize();
+        if (viewport.getSize().width > pref.width)
+          retVal = true;
+        if ((getLayoutOrientation() == HORIZONTAL_WRAP)
+            && (getVisibleRowCount() <= 0))
+          retVal = true;
+      }
+    return retVal;
   }
 
   /**
@@ -1206,7 +1206,19 @@
    */
   public boolean getScrollableTracksViewportHeight()
   {
-    return false;
+    Component parent = getParent();
+    boolean retVal = false;
+    if (parent instanceof JViewport)
+      {
+        JViewport viewport = (JViewport) parent;
+        Dimension pref = getPreferredSize();
+        if (viewport.getSize().height > pref.height)
+          retVal = true;
+        if ((getLayoutOrientation() == VERTICAL_WRAP)
+            && (getVisibleRowCount() <= 0))
+          retVal = true;
+      }
+    return retVal;
   }
 
   public int getAnchorSelectionIndex()
Index: kaffe/libraries/javalib/javax/swing/plaf/basic/BasicListUI.java
diff -u kaffe/libraries/javalib/javax/swing/plaf/basic/BasicListUI.java:1.8 kaffe/libraries/javalib/javax/swing/plaf/basic/BasicListUI.java:1.9
--- kaffe/libraries/javalib/javax/swing/plaf/basic/BasicListUI.java:1.8	Wed Mar  2 22:52:42 2005
+++ kaffe/libraries/javalib/javax/swing/plaf/basic/BasicListUI.java	Wed Mar  2 22:56:19 2005
@@ -56,6 +56,7 @@
 import javax.swing.CellRendererPane;
 import javax.swing.JComponent;
 import javax.swing.JList;
+import javax.swing.JViewport;
 import javax.swing.ListCellRenderer;
 import javax.swing.ListModel;
 import javax.swing.ListSelectionModel;
@@ -386,16 +387,21 @@
     if (l != list || cellWidth == -1)
       return null;
 
-    int lo = Math.min(index1, index2);
-    int hi = Math.max(index1, index2);
-    Point loLoc = indexToLocation(list, lo);
-    Point hiLoc = indexToLocation(list, hi);
-    Rectangle lobounds = new Rectangle(loLoc.x, loLoc.y, cellWidth,
-                                       getRowHeight(lo));
-    Rectangle hibounds = new Rectangle(hiLoc.x, hiLoc.y, cellWidth,
-                                       getRowHeight(hi));
+    int minIndex = Math.min(index1, index2);
+    int maxIndex = Math.max(index1, index2);
+    Point loc = indexToLocation(list, minIndex);
+    Rectangle bounds = new Rectangle(loc.x, loc.y, cellWidth,
+                                     getRowHeight(minIndex));
 
-    return lobounds.union(hibounds);
+    for (int i = minIndex + 1; i <= maxIndex; i++)
+      {
+        Point hiLoc = indexToLocation(list, i);
+        Rectangle hibounds = new Rectangle(hiLoc.x, hiLoc.y, cellWidth,
+                                       getRowHeight(i));
+        bounds = bounds.union(hibounds);
+      }
+
+    return bounds;
   }
 
   /**
@@ -639,10 +645,34 @@
    */
   public Dimension getPreferredSize(JComponent c)
   {
-    if (list.getModel().getSize() == 0)
+    int size = list.getModel().getSize();
+    if (size == 0)
       return new Dimension(0, 0);
+    int visibleRows = list.getVisibleRowCount();
+    int layoutOrientation = list.getLayoutOrientation();
     Rectangle bounds = getCellBounds(list, 0, list.getModel().getSize() - 1);
-    return bounds.getSize();
+    Dimension retVal = bounds.getSize();
+    Component parent = list.getParent();
+    if ((visibleRows == -1) && (parent instanceof JViewport))
+      {
+        JViewport viewport = (JViewport) parent;
+
+        if (layoutOrientation == JList.HORIZONTAL_WRAP)
+          {
+            int h = viewport.getSize().height;
+            int cellsPerCol = h / cellHeight;
+            int w = size / cellsPerCol * cellWidth;
+            retVal = new Dimension(w, h);
+          }
+        else if (layoutOrientation == JList.VERTICAL_WRAP)
+          {
+            int w = viewport.getSize().width;
+            int cellsPerRow = Math.max(w / cellWidth, 1);
+            int h = size / cellsPerRow * cellHeight;
+            retVal = new Dimension(w, h);
+          }
+      }
+    return retVal;
   }
 
   /**




More information about the kaffe mailing list