The current ViewportLayout.java.layoutContainer method seems behaving
differently from Sun's implementation in the following ways:
1. If the view is smaller than the port where it should be displayed,
the view is bottom aligned. For instance, if the table is displayed in
the frame that is larger than the table size, the table body is bottom
aligned (large whitespace between table header and table body). This is
not correct, in Sun's implementation the table is always top aligned is
such case.
2. If the view width is exactly the same as the view port width, it
should be set as such and the view offset must be set to zero, instead
of performing unnecessary calculations. Somehow the view offset is
calculated different from zero, this results the unexpected whitespace
at the left border of the tables and text areas in the Swing demo.
The patch seems bringing no regressions, as far as I was able to test.
2006-03-19 Audrius Meskauskas <[EMAIL PROTECTED]>
* javax/swing/ViewportLayout.java (layoutContainer):
If Scrollable tracks dimension, set view size to the port size.
If port is larger than the view, move the view to the top/left.
Index: javax/swing/ViewportLayout.java
===================================================================
RCS file: /sources/classpath/classpath/javax/swing/ViewportLayout.java,v
retrieving revision 1.26
diff -u -r1.26 ViewportLayout.java
--- javax/swing/ViewportLayout.java 28 Feb 2006 20:10:31 -0000 1.26
+++ javax/swing/ViewportLayout.java 19 Mar 2006 10:19:38 -0000
@@ -128,10 +128,10 @@
* <ol>
*
* <li>If the port is smaller than the view, leave the view at its
- * current size. Also, do not move the port, <em>unless</em> the port
- * extends into space <em>past</em> the edge of the view. If so, move the
- * port up or to the left, in view space, by the amount of empty space
- * (keep the lower and right edges lined up)</li>
+ * current size.</li>
+ * <li>If the view is smaller than the port, the view is top aligned.</li>
+ * <li>If the view tracks the port size, the view position is always zero
+ * and the size equal to the viewport size</li>
* <li>In [EMAIL PROTECTED] JViewport#setViewSize(Dimension)}, the view size is never
* set smaller that its minimum size.</li>
*
@@ -142,7 +142,7 @@
* @see JViewport#getViewPosition
* @see JViewport#setViewPosition
*/
- public void layoutContainer(Container parent)
+ public void layoutContainer(Container parent)
{
// The way to interpret this function is basically to ignore the names
// of methods it calls, and focus on the variable names here. getViewRect
@@ -150,9 +150,9 @@
// view space. Likwise setViewPosition doesn't reposition the view; it
// positions the port, in view coordinates.
- JViewport port = (JViewport) parent;
+ JViewport port = (JViewport) parent;
Component view = port.getView();
-
+
if (view == null)
return;
@@ -163,37 +163,45 @@
Rectangle portBounds = port.getViewRect();
Dimension viewPref = view.getPreferredSize();
- Dimension viewMinimum = view.getMinimumSize();
-
+
Point portLowerRight = new Point(portBounds.x + portBounds.width,
portBounds.y + portBounds.height);
- int overextension;
// vertical implementation of the above rules
- if ((! (view instanceof Scrollable) && viewPref.height < portBounds.height
- || (view instanceof Scrollable
- && ((Scrollable) view).getScrollableTracksViewportHeight())))
- viewPref.height = portBounds.height;
-
- // If the view is larger than the port, and port is partly outside
- // the view, it is moved fully into the view area.
- overextension = portLowerRight.y - viewPref.height;
- if (overextension > 0)
- portBounds.y -= overextension;
-
- // horizontal implementation of the above rules
- if ((! (view instanceof Scrollable) && viewPref.width < portBounds.width
- || (view instanceof Scrollable
- && ((Scrollable) view).getScrollableTracksViewportWidth())))
- viewPref.width = portBounds.width;
-
- // If the view is larger than the port, and port is partly outside
- // the view, it is moved fully into the view area.
- overextension = portLowerRight.x - viewPref.width;
- if (overextension > 0)
- portBounds.x -= overextension;
+ if (view instanceof Scrollable)
+ {
+ Scrollable sView = (Scrollable) view;
+
+ // If the view size matches viewport size, the port offset can
+ // only be zero.
+ if (sView.getScrollableTracksViewportWidth())
+ {
+ viewPref.width = portBounds.width;
+ portBounds.x = 0;
+ }
+ if (sView.getScrollableTracksViewportHeight())
+ {
+ viewPref.height = portBounds.height;
+ portBounds.y = 0;
+ }
+ }
+ else
+ {
+ if (viewPref.width < portBounds.width)
+ viewPref.width = portBounds.width;
+ if (viewPref.height < portBounds.height)
+ viewPref.height = portBounds.height;
+
+ // If the view is larger than the port, the port is top and right aligned.
+ if (portLowerRight.x > viewPref.width)
+ portBounds.x = 0;
+
+ if (portLowerRight.y > viewPref.height)
+ portBounds.y = 0;
+ }
port.setViewSize(viewPref);
port.setViewPosition(portBounds.getLocation());
}
+
}