/[classpath]/classpath/javax/swing/JComponent.java
ViewVC logotype

Diff of /classpath/javax/swing/JComponent.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.59 by rabbit78, Thu Sep 22 20:58:34 2005 UTC revision 1.60 by rabbit78, Sat Sep 24 20:40:21 2005 UTC
# Line 341  public abstract class JComponent extends Line 341  public abstract class JComponent extends
341    boolean autoscrolls = false;    boolean autoscrolls = false;
342    
343    /**    /**
344       * Indicates whether the current paint call is already double buffered or
345       * not.
346       */
347      static boolean isPaintingDoubleBuffered = false;
348    
349      /**
350     * Listeners for events other than {@link PropertyChangeEvent} are     * Listeners for events other than {@link PropertyChangeEvent} are
351     * handled by this listener list. PropertyChangeEvents are handled in     * handled by this listener list. PropertyChangeEvents are handled in
352     * {@link #changeSupport}.     * {@link #changeSupport}.
# Line 1449  public abstract class JComponent extends Line 1455  public abstract class JComponent extends
1455     */     */
1456    public void paint(Graphics g)    public void paint(Graphics g)
1457    {    {
1458      paintComponent(g);      RepaintManager rm = RepaintManager.currentManager(this);
1459      paintBorder(g);      // We do a little stunt act here to switch on double buffering if it's
1460      paintChildren(g);      // not already on. If we are not already doublebuffered, then we jump
1461        // into the method paintDoubleBuffered, which turns on the double buffer
1462        // and then calls paint(g) again. In the second call we go into the else
1463        // branch of this if statement and actually paint things to the double
1464        // buffer. When this method completes, the call stack unwinds back to
1465        // paintDoubleBuffered, where the buffer contents is finally drawn to the
1466        // screen.
1467        if (!isPaintingDoubleBuffered && isDoubleBuffered()
1468            && rm.isDoubleBufferingEnabled())
1469          paintDoubleBuffered(g);
1470        else
1471          {
1472            paintComponent(g);
1473            paintBorder(g);
1474            paintChildren(g);
1475          }
1476    }    }
1477    
1478    /**    /**
# Line 1604  public abstract class JComponent extends Line 1625  public abstract class JComponent extends
1625    void paintImmediately2(Rectangle r)    void paintImmediately2(Rectangle r)
1626    {    {
1627      RepaintManager rm = RepaintManager.currentManager(this);      RepaintManager rm = RepaintManager.currentManager(this);
1628        Graphics g = getGraphics();
1629        g.setClip(r.x, r.y, r.width, r.height);
1630      if (rm.isDoubleBufferingEnabled() && isDoubleBuffered())      if (rm.isDoubleBufferingEnabled() && isDoubleBuffered())
1631        paintDoubleBuffered(r);        paintDoubleBuffered(g);
1632      else      else
1633        paintSimple(r);        paintSimple(g);
1634        g.dispose();
1635    }    }
1636    
1637    /**    /**
# Line 1615  public abstract class JComponent extends Line 1639  public abstract class JComponent extends
1639     *     *
1640     * @param r the area to be repainted     * @param r the area to be repainted
1641     */     */
1642    void paintDoubleBuffered(Rectangle r)    void paintDoubleBuffered(Graphics g)
1643    {    {
1644        
1645        Rectangle r = g.getClipBounds();
1646        if (r == null)
1647          r = new Rectangle(0, 0, getWidth(), getHeight());
1648      RepaintManager rm = RepaintManager.currentManager(this);      RepaintManager rm = RepaintManager.currentManager(this);
1649    
1650      // Paint on the offscreen buffer.      // Paint on the offscreen buffer.
1651      Image buffer = rm.getOffscreenBuffer(this, getWidth(), getHeight());      synchronized (paintLock)
1652      Graphics g = buffer.getGraphics();        {
1653      Graphics g2 = getComponentGraphics(g);          Image buffer = rm.getOffscreenBuffer(this, getWidth(), getHeight());
1654      g2.setClip(r.x, r.y, r.width, r.height);          Graphics g2 = buffer.getGraphics();
1655      paint(g2);          g2 = getComponentGraphics(g2);
1656      g2.dispose();          g2.setClip(r.x, r.y, r.width, r.height);
1657      g.dispose();          isPaintingDoubleBuffered = true;
1658            paint(g2);
1659            isPaintingDoubleBuffered = false;
1660            g2.dispose();
1661    
1662      // Paint the buffer contents on screen.          // Paint the buffer contents on screen.
1663      Graphics g3 = getGraphics();          g.drawImage(buffer, 0, 0, this);
1664      g3.setClip(r.x, r.y, r.width, r.height);        }
     g3.drawImage(buffer, 0, 0, this);  
     g3.dispose();  
1665    }    }
1666    
1667    /**    /**
1668     * Performs normal painting without double buffering.     * Performs normal painting without double buffering.
1669     *     *
1670     * @param r the area to be repainted     * @param g the graphics context to use
1671     */     */
1672    void paintSimple(Rectangle r)    void paintSimple(Graphics g)
1673    {    {
     Graphics g = getGraphics();  
1674      Graphics g2 = getComponentGraphics(g);      Graphics g2 = getComponentGraphics(g);
1675      paint(g2);      paint(g2);
     g2.dispose();  
     g2.dispose();  
1676    }    }
1677    
1678    /**    /**

Legend:
Removed from v.1.59  
changed lines
  Added in v.1.60

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26