This cleans up some cruft in JComponent and adds a small optimization. 2006-06-21 Roman Kennke <[EMAIL PROTECTED]>
* javax/swing/JComponent.java
(paintChildrenWithOverlap): Determine opaque property by
calling the corresponding Component method, without requiring
a JComponent.
(paintChildrenOptimized): Removed old unneeded code.
(paintImmediately): Use JComponent's
convertRectangleToAncestor()
method instead of SwingUtilities.convertRectangle(). This is
more efficient.
/Roman
--
“Improvement makes straight roads, but the crooked roads, without
Improvement, are roads of Genius.” - William Blake
Index: javax/swing/JComponent.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JComponent.java,v
retrieving revision 1.128
diff -u -1 -0 -r1.128 JComponent.java
--- javax/swing/JComponent.java 15 Jun 2006 13:32:45 -0000 1.128
+++ javax/swing/JComponent.java 21 Jun 2006 12:31:51 -0000
@@ -1858,40 +1858,39 @@
// Go through children from top to bottom and find out their paint
// rectangles.
for (int index = 0; paintRectangles.size() > 0 &&
index < children.length; index++)
{
Component comp = children[index];
if (! comp.isVisible() || ! comp.isLightweight())
continue;
Rectangle compBounds = comp.getBounds();
- boolean isOpaque = comp instanceof JComponent
- && ((JComponent) comp).isOpaque();
+ boolean isOpaque = comp.isOpaque();
// Add all the current paint rectangles that intersect with the
// component to the component's paint rectangle array.
for (int i = paintRectangles.size() - 1; i >= 0; i--)
{
Rectangle r = (Rectangle) paintRectangles.get(i);
if (r.intersects(compBounds))
{
Rectangle compRect = r.intersection(compBounds);
componentRectangles.add(compRect);
// If the component is opaque, split up each paint rect and
// add paintRect - compBounds to the newPaintRects array.
if (isOpaque)
{
int x, y, w, h;
Rectangle rect = new Rectangle();
- // The north retangle.
+ // The north rectangle.
x = Math.max(compBounds.x, r.x);
y = r.y;
w = Math.min(compBounds.width, r.width + r.x - x);
h = compBounds.y - r.y;
rect.setBounds(x, y, w, h);
if (! rect.isEmpty())
{
newPaintRects.add(rect);
rect = new Rectangle();
}
@@ -2011,53 +2010,46 @@
* Paints the children of this container when it is marked as
* optimizedDrawingEnabled. In this case the container can guarantee that
* it's children are tiled, which allows for a much more efficient
* algorithm to determine the minimum rectangles to be painted for
* each child.
*
* @param g the graphics context to use
*/
private void paintChildrenOptimized(Graphics g)
{
- Shape originalClip = g.getClip();
Rectangle inner = SwingUtilities.calculateInnerArea(this, rectCache);
g.clipRect(inner.x, inner.y, inner.width, inner.height);
Component[] children = getComponents();
// paintingTile becomes true just before we start painting the component's
// children.
paintingTile = true;
for (int i = children.length - 1; i >= 0; i--) //children.length; i++)
{
// paintingTile must be set to false before we begin to start painting
// the last tile.
if (i == children.length - 1)
paintingTile = false;
if (!children[i].isVisible() || ! children[i].isLightweight())
continue;
Rectangle bounds = children[i].getBounds(rectCache);
- Rectangle oldClip = g.getClipBounds();
- if (oldClip == null)
- oldClip = bounds;
-
if (!g.hitClip(bounds.x, bounds.y, bounds.width, bounds.height))
continue;
- boolean translated = false;
Graphics g2 = g.create(bounds.x, bounds.y, bounds.width,
bounds.height);
children[i].paint(g2);
g2.dispose();
}
- g.setClip(originalClip);
}
/**
* Paint the component's body. This usually means calling [EMAIL PROTECTED]
* ComponentUI#update} on the [EMAIL PROTECTED] #ui} property of the component, if
* it is non-<code>null</code>. You may override this if you wish to
* customize the component's body-painting behavior. The component's body
* is painted first, before the border and children.
*
* @param g The graphics context with which to paint the body
@@ -2111,30 +2103,27 @@
*
* @param r The dirty rectangle to paint
*/
public void paintImmediately(Rectangle r)
{
// Try to find a root pane for this component.
//Component root = findPaintRoot(r);
Component root = findPaintRoot(r);
// If no paint root is found, then this component is completely overlapped
// by another component and we don't need repainting.
- if (root == null)
+ if (root == null|| !root.isShowing())
return;
- if (root == null || !root.isShowing())
- return;
-
- Rectangle rootClip = SwingUtilities.convertRectangle(this, r, root);
+ SwingUtilities.convertRectangleToAncestor(this, r, root);
if (root instanceof JComponent)
- ((JComponent) root).paintImmediately2(rootClip);
+ ((JComponent) root).paintImmediately2(r);
else
- root.repaint(rootClip.x, rootClip.y, rootClip.width, rootClip.height);
+ root.repaint(r.x, r.y, r.width, r.height);
}
/**
* Performs the actual work of paintImmediatly on the repaint root.
*
* @param r the area to be repainted
*/
void paintImmediately2(Rectangle r)
{
isRepainting = true;
signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil
