summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Kennke <roman@kennke.org>2006-01-27 12:37:58 +0000
committerRoman Kennke <roman@kennke.org>2006-01-27 12:37:58 +0000
commitb4805a6a9d8dbb75b0eb38d8fddf5d1f7680560d (patch)
treee10f109244ccc7e7c4094689d21efd7602987cac
parent0d7342ae69b7e480c7ffc4562feee8dc565ef990 (diff)
downloadclasspath-b4805a6a9d8dbb75b0eb38d8fddf5d1f7680560d.tar.gz
2006-01-27 Roman Kennke <kennke@aicas.com>
PR classpath/25968 * javax/swing/JComponent.java (findOverlapFreeParent): Improved the algorithm to make better use of the optimizedDrawingEnabled flag. * javax/swing/JLayeredPane.java (isOptimizedDrawingEnabled): Reimplemented to match the specs. * javax/swing/JViewport.java (computeBlit): Fixed check to decide if blitting is possible or not, so that it doesn't blit if nothing was scrolled (in order to update the buffer when the view updates itself).
-rw-r--r--ChangeLog13
-rw-r--r--javax/swing/JComponent.java53
-rw-r--r--javax/swing/JLayeredPane.java34
-rw-r--r--javax/swing/JViewport.java6
4 files changed, 55 insertions, 51 deletions
diff --git a/ChangeLog b/ChangeLog
index 6527709a0..ef10abaa4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
2006-01-27 Roman Kennke <kennke@aicas.com>
+ PR classpath/25968
+ * javax/swing/JComponent.java
+ (findOverlapFreeParent): Improved the algorithm to make better use
+ of the optimizedDrawingEnabled flag.
+ * javax/swing/JLayeredPane.java
+ (isOptimizedDrawingEnabled): Reimplemented to match the specs.
+ * javax/swing/JViewport.java
+ (computeBlit): Fixed check to decide if blitting is possible or not,
+ so that it doesn't blit if nothing was scrolled (in order to
+ update the buffer when the view updates itself).
+
+2006-01-27 Roman Kennke <kennke@aicas.com>
+
* javax/swing/plaf/metal/MetalFileChooserUI.java
(createList): Don't set scrollbar policy.
diff --git a/javax/swing/JComponent.java b/javax/swing/JComponent.java
index 83e1a2b35..dd186ef18 100644
--- a/javax/swing/JComponent.java
+++ b/javax/swing/JComponent.java
@@ -3245,62 +3245,25 @@ public abstract class JComponent extends Container implements Serializable
while (parent != null && !(parent instanceof Window))
{
Container newParent = parent.getParent();
- if (newParent == null)
+ if (newParent == null || newParent instanceof Window)
break;
// If the parent is optimizedDrawingEnabled, then its children are
// tiled and cannot have an overlapping child. Go directly to next
// parent.
- if (newParent instanceof JComponent
- && ((JComponent) newParent).isOptimizedDrawingEnabled())
+ if ((newParent instanceof JComponent
+ && ((JComponent) newParent).isOptimizedDrawingEnabled()))
+
{
parent = newParent;
continue;
}
-
- // First we must check if the new parent itself somehow clips the
- // target rectangle. This can happen in JViewports.
- Rectangle parRect = new Rectangle(0, 0, newParent.getWidth(),
- newParent.getHeight());
+ // If the parent is not optimizedDrawingEnabled, we must paint the
+ // parent.
Rectangle target = SwingUtilities.convertRectangle(found,
currentClip,
newParent);
- if (! target.intersection(parRect).equals(target))
- {
- found = newParent;
- currentClip = target;
- parent = newParent;
- continue;
- }
-
- // Otherwise we must check if one of the children of this parent
- // overlaps with the current component.
- Component[] children = newParent.getComponents();
- // This flag is used to skip components that are 'below' the component
- // in question.
- boolean skip = true;
- for (int i = children.length - 1; i >= 0; i--)
- {
- boolean nextSkip = skip;
- if (children[i] == parent)
- nextSkip = false;
- if (skip)
- continue;
- skip = nextSkip;
- Component c = children[i];
- Rectangle compBounds = c.getBounds();
- // If the component completely overlaps the clip in question, we
- // don't need to repaint. Return null.
- if (compBounds.contains(target))
- return null;
- if (compBounds.intersects(target))
- {
- // We found a parent whose children overlap with our current
- // component. Make this the current component.
- found = newParent;
- currentClip = target;
- break;
- }
- }
+ found = newParent;
+ currentClip = target;
parent = newParent;
}
return found;
diff --git a/javax/swing/JLayeredPane.java b/javax/swing/JLayeredPane.java
index 23b3d741a..e86c026d6 100644
--- a/javax/swing/JLayeredPane.java
+++ b/javax/swing/JLayeredPane.java
@@ -711,13 +711,39 @@ public class JLayeredPane extends JComponent implements Accessible
}
/**
- * Overridden to return <code>false</code>, since <code>JLayeredPane</code>
- * cannot guarantee that its children don't overlap.
+ * Returns <code>false</code> if components in this layered pane can overlap,
+ * otherwise <code>true</code>.
*
- * @return <code>false</code>
+ * @return <code>false</code> if components in this layered pane can overlap,
+ * otherwise <code>true</code>
*/
public boolean isOptimizedDrawingEnabled()
{
- return false;
+ int numChildren = getComponentCount();
+ boolean result = false;
+ // We implement a heuristic here in order to return a quick result:
+ // - For 0 or 1 children it is clear that they do not overlap, return true.
+ // - For 2 children we check their bounding rectangles and if they don't
+ // interect, return true.
+ // - For more than 2 children we return false. Comparing all the bounding
+ // rectangles costs too much time and in most cases this will return
+ // false anyway, since JLayeredPane are mostly used in JRootPane and then
+ // have at least one child (the contentPane) that takes up the whole
+ // area of the JLayeredPane.
+ switch (numChildren)
+ {
+ case 0:
+ case 1:
+ result = true;
+ break;
+ case 2:
+ Rectangle r1 = getComponent(0).getBounds();
+ Rectangle r2 = getComponent(1).getBounds();
+ result = !r1.intersects(r2);
+ break;
+ default:
+ result = false;
+ }
+ return result;
}
}
diff --git a/javax/swing/JViewport.java b/javax/swing/JViewport.java
index 5ad9593b4..1e8bec82e 100644
--- a/javax/swing/JViewport.java
+++ b/javax/swing/JViewport.java
@@ -710,9 +710,11 @@ public class JViewport extends JComponent implements Accessible
protected boolean computeBlit(int dx, int dy, Point blitFrom, Point blitTo,
Dimension blitSize, Rectangle blitPaint)
{
- if ((dx != 0 && dy != 0) || damaged)
+ if ((dx != 0 && dy != 0) || (dy == 0 && dy == 0) || damaged)
// We cannot blit if the viewport is scrolled in both directions at
- // once.
+ // once. Also, we do not want to blit if the viewport is not scrolled at
+ // all, because that probably means the view component repaints itself
+ // and the buffer needs updating.
return false;
Rectangle portBounds = SwingUtilities.calculateInnerArea(this, getBounds());