Re: [cp-patches] scrollable JList

2005-02-28 Thread Michael Koch
On Mon, Feb 28, 2005 at 11:27:30AM +0100, Roman Kennke wrote:
> Hi,
> 
> please review the attached patch that improves the behaviour of JList
> within a scrolling container, especially with layoutOrientation set to
> JList.HORIZONTAL_WRAP or VERTICAL_WRAP. Is the ChangeLog entry ok?
> 
> 2005-02-27  Roman Kennke  <[EMAIL PROTECTED]>
> 
>   * javax/swing/JList.java
>   (getPreferredScrollableViewportSize):
>   previous implementation was merely guessing the size,
>   now it respects layoutOrientation, visibleRowCount
>   and preferredSize
>   (getScrollableTracksViewportHeight):
>   reimplemented to respect layoutOrientation, visibleRowCount
>   and preferred size
>   (getScrollableTracksViewportWidth):
>   reimplemented to respect layoutOrientation, visibleRowCount
>   and preferred size
>   * javax/swing/plaf/basic/BasicListUI.java
>   (getPreferredSize):
>   improved calculation of preferredSize when JList is
>   set to HORIZONTAL_WRAP or VERTICAL_WRAP.
>   (getCellBounds):
>   previous implementation assumed a layoutOrientation of
>   JList.VERTICAL, now also ok with JList.HORIZONTAL_WRAP and
>   JList.VERTICAL_WRAP

Sentences start with upercase letters, even in english language. :-)

The patch itself is very very fine. Please commit.


Michael
--
Java Trap: http://www.gnu.org/philosophy/java-trap.html


___
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches


Re: [cp-patches] scrollable JList

2005-02-28 Thread Roman Kennke
Am Montag, den 28.02.2005, 12:04 + schrieb Chris Burdess:
> Roman Kennke wrote:
> > please review the attached patch that improves the behaviour of JList
> > within a scrolling container, especially with layoutOrientation set to
> > JList.HORIZONTAL_WRAP or VERTICAL_WRAP.
> 
> The fields of the Dimension class are not final, so you don't need to
> create new Dimension objects each time you want to set retVal's values.

They are not final, but I don't want to fiddle with the Dimension object
that is from getPreferredSize() since I don't know if it's a copy or
not. I it's sure that it's only a copy I would change this.

/Roman



signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil
___
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches


Re: [cp-patches] scrollable JList

2005-02-28 Thread Chris Burdess
Roman Kennke wrote:
> please review the attached patch that improves the behaviour of JList
> within a scrolling container, especially with layoutOrientation set to
> JList.HORIZONTAL_WRAP or VERTICAL_WRAP.

The fields of the Dimension class are not final, so you don't need to
create new Dimension objects each time you want to set retVal's values.
-- 
Chris Burdess


pgpIFzh5BypQe.pgp
Description: PGP signature
___
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches


[cp-patches] scrollable JList

2005-02-28 Thread Roman Kennke
Hi,

please review the attached patch that improves the behaviour of JList
within a scrolling container, especially with layoutOrientation set to
JList.HORIZONTAL_WRAP or VERTICAL_WRAP. Is the ChangeLog entry ok?

2005-02-27  Roman Kennke  <[EMAIL PROTECTED]>

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

/Roman

Index: javax/swing/JList.java
===
RCS file: /cvsroot/classpath/classpath/javax/swing/JList.java,v
retrieving revision 1.24
diff -u -r1.24 JList.java
--- javax/swing/JList.java	16 Feb 2005 12:36:22 -	1.24
+++ javax/swing/JList.java	27 Feb 2005 22:12:27 -
@@ -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: javax/swing/plaf/basic/BasicListUI.java
===
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicListUI.java,v
retrieving revision 1.14
diff -u -r1.14 BasicListUI.java
--- javax/swing/plaf/basic/BasicListUI.java	27 Feb 2005 20:35:55 -	1.14
+++ javax/swing/plaf/basic/BasicListUI.java	27 Feb 2005 22:12:30 -
@@ -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 Recta