This fixes two issues in JViewport:
- in scrollRectToVisible() we were calculating with the viewport
coordinates, but we should be calculating with the view coordinates to
get the correct results. This caused wrong scrolling offset.
- in paintBackbuffer() we must update the buffer when we are not the
paint root. This caused artifacts while scrolling.
2007-02-08 Roman Kennke <[EMAIL PROTECTED]>
PR 30347
* javax/swing/JViewport.java
(scrollRectToVisible): Use correct X/Y offset for calculations.
(paintBackingStore): Update backbuffer when we are not the paint
root.
/Roman
Index: javax/swing/JViewport.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JViewport.java,v
retrieving revision 1.51
diff -u -1 -5 -r1.51 JViewport.java
--- javax/swing/JViewport.java 18 Oct 2006 22:28:11 -0000 1.51
+++ javax/swing/JViewport.java 8 Feb 2007 22:14:33 -0000
@@ -562,54 +562,58 @@
{
if (border != null)
throw new IllegalArgumentException();
}
/**
* Scrolls the view so that contentRect becomes visible.
*
* @param contentRect the rectangle to make visible within the view
*/
public void scrollRectToVisible(Rectangle contentRect)
{
Component view = getView();
if (view == null)
return;
-
+
Point pos = getViewPosition();
+ // We get the contentRect in the viewport coordinates. But we want to
+ // calculate with view coordinates.
+ int contentX = contentRect.x + pos.x;
+ int contentY = contentRect.y + pos.y;
Rectangle viewBounds = getView().getBounds();
Rectangle portBounds = getBounds();
if (isShowing())
getView().validate();
// If the bottom boundary of contentRect is below the port
// boundaries, scroll up as necessary.
- if (contentRect.y + contentRect.height + viewBounds.y > portBounds.height)
- pos.y = contentRect.y + contentRect.height - portBounds.height;
- // If contentRect.y is above the port boundaries, scroll down to
- // contentRect.y.
- if (contentRect.y + viewBounds.y < 0)
- pos.y = contentRect.y;
+ if (contentY + contentRect.height + viewBounds.y > portBounds.height)
+ pos.y = contentY + contentRect.height - portBounds.height;
+ // If contentY is above the port boundaries, scroll down to
+ // contentY.
+ if (contentY + viewBounds.y < 0)
+ pos.y = contentY;
// If the right boundary of contentRect is right from the port
// boundaries, scroll left as necessary.
- if (contentRect.x + contentRect.width + viewBounds.x > portBounds.width)
- pos.x = contentRect.x + contentRect.width - portBounds.width;
- // If contentRect.x is left from the port boundaries, scroll right to
+ if (contentX + contentRect.width + viewBounds.x > portBounds.width)
+ pos.x = contentX + contentRect.width - portBounds.width;
+ // If contentX is left from the port boundaries, scroll right to
// contentRect.x.
- if (contentRect.x + viewBounds.x < 0)
- pos.x = contentRect.x;
+ if (contentX + viewBounds.x < 0)
+ pos.x = contentX;
setViewPosition(pos);
}
/**
* Returns the accessible context for this <code>JViewport</code>. This
* will be an instance of [EMAIL PROTECTED] AccessibleJViewport}.
*
* @return the accessible context for this <code>JViewport</code>
*/
public AccessibleContext getAccessibleContext()
{
if (accessibleContext == null)
accessibleContext = new AccessibleJViewport();
return accessibleContext;
}
@@ -822,31 +826,31 @@
Graphics g2 = backingStoreImage.getGraphics();
paintSimple(g2);
g2.dispose();
}
// Otherwise we can perform the blitting on the backing store image:
// First we move the part that remains visible after scrolling, then
// we only need to paint the bit that becomes newly visible.
else
{
Graphics g2 = backingStoreImage.getGraphics();
Point viewPosition = getViewPosition();
int dx = viewPosition.x - lastPaintPosition.x;
int dy = viewPosition.y - lastPaintPosition.y;
boolean canBlit = computeBlit(dx, dy, cachedBlitFrom, cachedBlitTo,
cachedBlitSize, cachedBlitPaint);
- if (canBlit)
+ if (canBlit && isPaintRoot)
{
// Copy the part that remains visible during scrolling.
if (cachedBlitSize.width > 0 && cachedBlitSize.height > 0)
{
g2.copyArea(cachedBlitFrom.x, cachedBlitFrom.y,
cachedBlitSize.width, cachedBlitSize.height,
cachedBlitTo.x - cachedBlitFrom.x,
cachedBlitTo.y - cachedBlitFrom.y);
}
// Now paint the part that becomes newly visible.
g2.setClip(cachedBlitPaint.x, cachedBlitPaint.y,
cachedBlitPaint.width, cachedBlitPaint.height);
paintSimple(g2);
}
// If blitting is not possible for some reason, fall back to repainting