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

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

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

revision 1.27 by abalkiss, Mon Sep 12 20:59:15 2005 UTC revision 1.28 by rabbit78, Fri Sep 23 20:28:19 2005 UTC
# Line 40  package javax.swing; Line 40  package javax.swing;
40    
41  import java.awt.Component;  import java.awt.Component;
42  import java.awt.ComponentOrientation;  import java.awt.ComponentOrientation;
 import java.awt.Dimension;  
43  import java.awt.Insets;  import java.awt.Insets;
44  import java.awt.LayoutManager;  import java.awt.LayoutManager;
 import java.awt.Point;  
45  import java.awt.Rectangle;  import java.awt.Rectangle;
46    
47  import javax.accessibility.Accessible;  import javax.accessibility.Accessible;
48  import javax.swing.border.Border;  import javax.swing.border.Border;
 import javax.swing.event.ChangeEvent;  
 import javax.swing.event.ChangeListener;  
49  import javax.swing.plaf.ScrollPaneUI;  import javax.swing.plaf.ScrollPaneUI;
50  import javax.swing.plaf.UIResource;  import javax.swing.plaf.UIResource;
51    
# Line 100  public class JScrollPane Line 96  public class JScrollPane
96        
97    Border viewportBorder;    Border viewportBorder;
98    boolean wheelScrollingEnabled;    boolean wheelScrollingEnabled;
   ChangeListener scrollListener;    
99    
100    public JViewport getColumnHeader()    public JViewport getColumnHeader()
101    {    {
# Line 331  public class JScrollPane Line 326  public class JScrollPane
326      firePropertyChange("horizontalScrollBar", old, h);      firePropertyChange("horizontalScrollBar", old, h);
327      sync();      sync();
328    
     if (old != null)  
       {  
         BoundedRangeModel model = old.getModel();  
         if (model != null)  
           model.removeChangeListener(scrollListener);  
       }  
     if (h != null)  
       {  
         BoundedRangeModel model = h.getModel();  
         if (model != null)  
           model.addChangeListener(scrollListener);  
       }  
329    }    }
330    
331    public void setHorizontalScrollBarPolicy(int h)    public void setHorizontalScrollBarPolicy(int h)
# Line 359  public class JScrollPane Line 342  public class JScrollPane
342      horizontalScrollBarPolicy = h;      horizontalScrollBarPolicy = h;
343      firePropertyChange("horizontalScrollBarPolicy", old, h);      firePropertyChange("horizontalScrollBarPolicy", old, h);
344      sync();      sync();
345        revalidate();
346    }    }
347    
348    public void setLayout(LayoutManager l)    public void setLayout(LayoutManager l)
# Line 403  public class JScrollPane Line 387  public class JScrollPane
387      addNonNull(v, JScrollPane.VERTICAL_SCROLLBAR);      addNonNull(v, JScrollPane.VERTICAL_SCROLLBAR);
388      firePropertyChange("verticalScrollBar", old, v);      firePropertyChange("verticalScrollBar", old, v);
389      sync();      sync();
   
     if (old != null)  
       {  
         BoundedRangeModel model = old.getModel();  
         if (model != null)  
           model.removeChangeListener(scrollListener);  
       }  
     if (v != null)  
       {  
         BoundedRangeModel model = v.getModel();  
         if (model != null)  
           model.addChangeListener(scrollListener);  
       }  
390    }    }
391    
392    public void setVerticalScrollBarPolicy(int v)    public void setVerticalScrollBarPolicy(int v)
# Line 432  public class JScrollPane Line 403  public class JScrollPane
403      verticalScrollBarPolicy = v;      verticalScrollBarPolicy = v;
404      firePropertyChange("verticalScrollBarPolicy", old, v);      firePropertyChange("verticalScrollBarPolicy", old, v);
405      sync();      sync();
406        revalidate();
407    }    }
408    
409    public void setWheelScrollingEnabled(boolean b)    public void setWheelScrollingEnabled(boolean b)
# Line 452  public class JScrollPane Line 424  public class JScrollPane
424            
425      JViewport old = viewport;      JViewport old = viewport;
426      removeNonNull(old);      removeNonNull(old);
     if (old != null)  
       old.removeChangeListener(scrollListener);  
427      viewport = v;      viewport = v;
     if (v != null)  
       v.addChangeListener(scrollListener);  
428      addNonNull(v, JScrollPane.VIEWPORT);      addNonNull(v, JScrollPane.VIEWPORT);
429      revalidate();      revalidate();
430      repaint();      repaint();
# Line 494  public class JScrollPane Line 462  public class JScrollPane
462      return true;      return true;
463    }    }
464    
   ChangeListener createScrollListener()  
   {  
     return new ChangeListener()  
       {  
           
         public void stateChanged(ChangeEvent event)  
         {  
           JScrollBar vsb = JScrollPane.this.getVerticalScrollBar();  
           JScrollBar hsb = JScrollPane.this.getHorizontalScrollBar();  
           JViewport vp = JScrollPane.this.getViewport();  
   
           if (vp != null && event.getSource() == vp)  
             {  
               // if the viewport changed, we should update the VSB / HSB  
               // models according to the new vertical and horizontal sizes  
   
               Rectangle vr = vp.getViewRect();  
               Dimension vs = vp.getViewSize();  
               if (vsb != null  
                   && (vsb.getMinimum() != 0  
                       || vsb.getMaximum() != vs.height  
                       || vsb.getValue() != vr.y  
                       || vsb.getVisibleAmount() != vr.height))  
                 vsb.setValues(vr.y, vr.height, 0, vs.height);  
   
               if (hsb != null  
                   && (hsb.getMinimum() != 0  
                       || hsb.getMaximum() != vs.width  
                       || hsb.getValue() != vr.width  
                       || hsb.getVisibleAmount() != vr.height))  
                 hsb.setValues(vr.x, vr.width, 0, vs.width);  
             }  
           else  
             {  
               // otherwise we got a change update from either the VSB or  
               // HSB model, and we need to update the viewport positions of  
               // both the main viewport and any row or column headers to  
               // match.  
   
               int xpos = 0;  
               int ypos = 0;  
                 
               if (vsb != null)  
                 ypos = vsb.getValue();  
                 
               if (hsb != null)  
                 xpos = hsb.getValue();  
   
               Point pt = new Point(xpos, ypos);  
   
               if (vp != null  
                   && vp.getViewPosition() != pt)  
                 vp.setViewPosition(pt);  
   
               pt.x = 0;  
   
               if (rowHeader != null  
                   && rowHeader.getViewPosition() != pt)  
                 rowHeader.setViewPosition(pt);  
                 
               pt.x = xpos;  
               pt.y = 0;  
   
               if (columnHeader != null  
                   && columnHeader.getViewPosition() != pt)  
                 columnHeader.setViewPosition(pt);  
   
             }  
         }  
       };  
   }  
   
   
465    /**    /**
466     * Creates a new <code>JScrollPane</code> without a view. The scrollbar     * Creates a new <code>JScrollPane</code> without a view. The scrollbar
467     * policy is set to {@link #VERTICAL_SCROLLBAR_AS_NEEDED} and     * policy is set to {@link #VERTICAL_SCROLLBAR_AS_NEEDED} and
# Line 627  public class JScrollPane Line 522  public class JScrollPane
522     */     */
523    public JScrollPane(Component view, int vsbPolicy, int hsbPolicy)    public JScrollPane(Component view, int vsbPolicy, int hsbPolicy)
524    {    {
     scrollListener = createScrollListener();  
525      setVerticalScrollBarPolicy(vsbPolicy);      setVerticalScrollBarPolicy(vsbPolicy);
526      setVerticalScrollBar(createVerticalScrollBar());      setVerticalScrollBar(createVerticalScrollBar());
527      setHorizontalScrollBarPolicy(hsbPolicy);      setHorizontalScrollBarPolicy(hsbPolicy);
# Line 635  public class JScrollPane Line 529  public class JScrollPane
529      viewport = createViewport();      viewport = createViewport();
530      if (view != null)      if (view != null)
531        getViewport().setView(view);        getViewport().setView(view);
     viewport.addChangeListener(scrollListener);  
532      add(viewport,0);      add(viewport,0);
533      setLayout(new ScrollPaneLayout());      setLayout(new ScrollPaneLayout());
534      setOpaque(false);      setOpaque(false);

Legend:
Removed from v.1.27  
changed lines
  Added in v.1.28

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