/[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.57 by trebligd, Mon Sep 12 22:20:59 2005 UTC revision 1.58 by rabbit78, Thu Sep 22 14:08:01 2005 UTC
# Line 143  public abstract class JComponent extends Line 143  public abstract class JComponent extends
143      protected FocusListener accessibleFocusHandler;      protected FocusListener accessibleFocusHandler;
144    
145      protected AccessibleJComponent() {}      protected AccessibleJComponent() {}
146      public void addPropertyChangeListener(PropertyChangeListener listener) {}  
147        /**
148         * Adds a property change listener to the list of registered listeners.
149         *
150         * @param listener the listener to add
151         */
152        public void addPropertyChangeListener(PropertyChangeListener listener)
153        {
154          // TODO: Why is this overridden?
155          super.addPropertyChangeListener(listener);
156        }
157    
158      public void removePropertyChangeListener(PropertyChangeListener listener) {}      public void removePropertyChangeListener(PropertyChangeListener listener) {}
159      public int getAccessibleChildrenCount() { return 0; }      public int getAccessibleChildrenCount() { return 0; }
160      public Accessible getAccessibleChild(int value0) { return null; }      public Accessible getAccessibleChild(int value0) { return null; }
161      public AccessibleStateSet getAccessibleStateSet() { return null; }  
162        /**
163         * Returns the accessible state set of this component.
164         *
165         * @return the accessible state set of this component
166         */
167        public AccessibleStateSet getAccessibleStateSet()
168        {
169          // FIXME: Figure out which states should be set here, and which are
170          // inherited from the super class.
171          return super.getAccessibleStateSet();
172        }
173    
174      public String getAccessibleName() { return null; }      public String getAccessibleName() { return null; }
175      public String getAccessibleDescription() { return null; }      public String getAccessibleDescription() { return null; }
176      public AccessibleRole getAccessibleRole() { return null; }      public AccessibleRole getAccessibleRole() { return null; }
# Line 225  public abstract class JComponent extends Line 248  public abstract class JComponent extends
248    
249    /**    /**
250     * <p>Whether to double buffer this component when painting. This flag     * <p>Whether to double buffer this component when painting. This flag
251     * should generally be <code>false</code>, except for top level     * should generally be <code>true</code>, to ensure good painting
252     * components such as {@link JFrame} or {@link JApplet}.</p>     * performance.</p>
253     *     *
254     * <p>All children of a double buffered component are painted into the     * <p>All children of a double buffered component are painted into the
255     * double buffer automatically, so only the top widget in a window needs     * double buffer automatically, so only the top widget in a window needs
# Line 237  public abstract class JComponent extends Line 260  public abstract class JComponent extends
260     * @see #paintLock     * @see #paintLock
261     * @see #paint     * @see #paint
262     */     */
263    boolean doubleBuffered = false;    boolean doubleBuffered = true;
264    
265    /**    /**
266     * A set of flags indicating which debugging graphics facilities should     * A set of flags indicating which debugging graphics facilities should
# Line 1411  public abstract class JComponent extends Line 1434  public abstract class JComponent extends
1434     * RepaintManager}. Client code should usually call {@link #repaint()} to     * RepaintManager}. Client code should usually call {@link #repaint()} to
1435     * trigger painting.</p>     * trigger painting.</p>
1436     *     *
    * <p>This method will acquire a double buffer from the {@link  
    * RepaintManager} if the component's {@link #doubleBuffered} property is  
    * <code>true</code> and the <code>paint</code> call is the  
    * <em>first</em> recursive <code>paint</code> call inside swing.</p>  
    *  
    * <p>The method will also modify the provided {@link Graphics} context  
    * via the {@link #getComponentGraphics} method. If you want to customize  
    * the graphics object used for painting, you should override that method  
    * rather than <code>paint</code>.</p>  
    *  
1437     * <p>The body of the <code>paint</code> call involves calling {@link     * <p>The body of the <code>paint</code> call involves calling {@link
1438     * #paintComponent}, {@link #paintBorder}, and {@link #paintChildren} in     * #paintComponent}, {@link #paintBorder}, and {@link #paintChildren} in
1439     * order. If you want to customize painting behavior, you should override     * order. If you want to customize painting behavior, you should override
# Line 1436  public abstract class JComponent extends Line 1449  public abstract class JComponent extends
1449     */     */
1450    public void paint(Graphics g)    public void paint(Graphics g)
1451    {    {
1452      Graphics g2 = g;      paintComponent(g);
1453      Image doubleBuffer = null;      paintBorder(g);
1454      RepaintManager rm = RepaintManager.currentManager(this);      paintChildren(g);
   
     if (isDoubleBuffered()  
         && (rm.isDoubleBufferingEnabled())  
         && (! Thread.holdsLock(paintLock)))  
       {  
         doubleBuffer = rm.getOffscreenBuffer(this, getWidth(), getHeight());  
       }  
   
     synchronized (paintLock)  
       {  
         if (doubleBuffer != null)  
           {  
             g2 = doubleBuffer.getGraphics();  
             g2.setClip(g.getClipBounds());  
           }  
             
         g2 = getComponentGraphics(g2);  
         paintComponent(g2);  
         paintBorder(g2);  
         paintChildren(g2);  
           
         if (doubleBuffer != null)  
           g.drawImage(doubleBuffer, 0, 0, (ImageObserver) null);  
       }  
1455    }    }
1456    
1457    /**    /**
# Line 1500  public abstract class JComponent extends Line 1489  public abstract class JComponent extends
1489     */     */
1490    protected void paintChildren(Graphics g)    protected void paintChildren(Graphics g)
1491    {    {
1492      super.paint(g);      Component[] children = getComponents();
1493        for (int i = children.length - 1; i >= 0; --i)
1494          {
1495            Rectangle bounds = children[i].getBounds();
1496            Rectangle oldClip = g.getClipBounds();
1497            Rectangle clip = oldClip.intersection(bounds);
1498            if (clip.isEmpty())
1499              continue;
1500            boolean translated = false;
1501            try
1502              {
1503                g.setClip(clip.x, clip.y, clip.width, clip.height);
1504                g.translate(bounds.x, bounds.y);
1505                translated = true;
1506                children[i].paint(g);
1507              }
1508            finally
1509              {
1510                if (translated)
1511                  g.translate(-bounds.x, -bounds.y);
1512                g.setClip(oldClip);
1513              }
1514          }
1515    }    }
1516    
1517    /**    /**
# Line 1549  public abstract class JComponent extends Line 1560  public abstract class JComponent extends
1560     * that root pane. This method is called from the {@link RepaintManager}     * that root pane. This method is called from the {@link RepaintManager}
1561     * and should always be called within the painting thread.     * and should always be called within the painting thread.
1562     *     *
1563       * <p>This method will acquire a double buffer from the {@link
1564       * RepaintManager} if the component's {@link #doubleBuffered} property is
1565       * <code>true</code> and the <code>paint</code> call is the
1566       * <em>first</em> recursive <code>paint</code> call inside swing.</p>
1567       *
1568       * <p>The method will also modify the provided {@link Graphics} context
1569       * via the {@link #getComponentGraphics} method. If you want to customize
1570       * the graphics object used for painting, you should override that method
1571       * rather than <code>paint</code>.</p>
1572       *
1573     * @param r The dirty rectangle to paint     * @param r The dirty rectangle to paint
1574     */     */
1575    public void paintImmediately(Rectangle r)    public void paintImmediately(Rectangle r)
1576    {    {
1577      Component root = SwingUtilities.getRoot(this);      // Try to find a root pane for this component.
1578      if (root == null || ! root.isShowing())      Component root = SwingUtilities.getRootPane(this);
1579        return;      // If no root pane can be found, then try to find the Window that contains
1580      Graphics g = root.getGraphics();      // this component.
1581      if (g == null)      if (root == null)
1582          root = SwingUtilities.getRoot(this);
1583        if (root == null || !root.isShowing())
1584        return;        return;
1585    
1586      Rectangle clip = SwingUtilities.convertRectangle(this, r, root);      Rectangle rootClip = SwingUtilities.convertRectangle(this, r, root);
1587      g.setClip(clip);      if (root instanceof JComponent)
1588      root.paint(g);        ((JComponent) root).paintImmediately2(rootClip);
1589        else
1590          root.repaint(rootClip.x, rootClip.y, rootClip.width, rootClip.height);
1591      }
1592    
1593      /**
1594       * Performs the actual work of paintImmediatly on the repaint root.
1595       *
1596       * @param r the area to be repainted
1597       */
1598      void paintImmediately2(Rectangle r)
1599      {
1600        RepaintManager rm = RepaintManager.currentManager(this);
1601        if (rm.isDoubleBufferingEnabled() && isDoubleBuffered())
1602          paintDoubleBuffered(r);
1603        else
1604          paintSimple(r);
1605      }
1606    
1607      /**
1608       * Performs double buffered repainting.
1609       *
1610       * @param r the area to be repainted
1611       */
1612      void paintDoubleBuffered(Rectangle r)
1613      {
1614        RepaintManager rm = RepaintManager.currentManager(this);
1615    
1616        // Paint on the offscreen buffer.
1617        Image buffer = rm.getOffscreenBuffer(this, getWidth(), getHeight());
1618        Graphics g = buffer.getGraphics();
1619        Graphics g2 = getComponentGraphics(g);
1620        g2.setClip(r.x, r.y, r.width, r.height);
1621        paint(g2);
1622        g2.dispose();
1623      g.dispose();      g.dispose();
1624    
1625        // Paint the buffer contents on screen.
1626        Graphics g3 = getGraphics();
1627        g3.setClip(r.x, r.y, r.width, r.height);
1628        g3.drawImage(buffer, 0, 0, this);
1629        g3.dispose();
1630      }
1631    
1632      /**
1633       * Performs normal painting without double buffering.
1634       *
1635       * @param r the area to be repainted
1636       */
1637      void paintSimple(Rectangle r)
1638      {
1639        Graphics g = getGraphics();
1640        Graphics g2 = getComponentGraphics(g);
1641        paint(g2);
1642        g2.dispose();
1643        g2.dispose();
1644    }    }
1645    
1646    /**    /**

Legend:
Removed from v.1.57  
changed lines
  Added in v.1.58

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