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

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

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

revision 1.8.2.7 by gnu_andrew, Tue Sep 20 18:46:32 2005 UTC revision 1.8.2.8 by gnu_andrew, Wed Nov 2 00:43:48 2005 UTC
# Line 43  import java.awt.Container; Line 43  import java.awt.Container;
43  import java.awt.Dimension;  import java.awt.Dimension;
44  import java.awt.Insets;  import java.awt.Insets;
45  import java.awt.LayoutManager;  import java.awt.LayoutManager;
 import java.awt.Point;  
46  import java.awt.Rectangle;  import java.awt.Rectangle;
47  import java.io.Serializable;  import java.io.Serializable;
48    
 import javax.swing.border.Border;  
   
49  /**  /**
50   * ScrollPaneLayout   * ScrollPaneLayout
51   * @author      Andrew Selkirk   * @author      Andrew Selkirk
# Line 60  public class ScrollPaneLayout Line 57  public class ScrollPaneLayout
57    private static final long serialVersionUID = -4480022884523193743L;    private static final long serialVersionUID = -4480022884523193743L;
58    
59    public static class UIResource extends ScrollPaneLayout    public static class UIResource extends ScrollPaneLayout
60      implements javax.swing.plaf.UIResource {      implements javax.swing.plaf.UIResource
61      public UIResource() {    {
62        public UIResource()
63        {
64          super();
65      }      }
66    }    }
67    
# Line 77  public class ScrollPaneLayout Line 77  public class ScrollPaneLayout
77    protected int vsbPolicy;    protected int vsbPolicy;
78    protected int hsbPolicy;    protected int hsbPolicy;
79    
80    public ScrollPaneLayout() {    public ScrollPaneLayout()
81                      {
82            // Nothing to do here.
83    }    }
84    
85    public void syncWithScrollPane(JScrollPane scrollPane) {    public void syncWithScrollPane(JScrollPane scrollPane) {
# Line 251  public class ScrollPaneLayout Line 252  public class ScrollPaneLayout
252      return null;      return null;
253    }    }
254    
   private static void maybeSetPreferredSize(JComponent src, Dimension dim)  
   {  
     Dimension tmp = null;  
     if (src != null)  
       tmp = src.getPreferredSize();  
     if (tmp != null)  
       dim.setSize(tmp);          
   }  
   
   private static void maybeSetMinimumSize(JComponent src, Dimension dim)  
   {  
     Dimension tmp = null;  
     if (src != null)  
       tmp = src.getMinimumSize();  
     if (tmp != null)  
       dim.setSize(tmp);  
   }  
   
255    public Dimension preferredLayoutSize(Container parent)    public Dimension preferredLayoutSize(Container parent)
256    {    {
257      if (parent != null && parent instanceof JScrollPane)      // Sun's implementation simply throws a ClassCastException if
258        {      // parent is no JScrollPane, so do we.
259          JScrollPane sc = (JScrollPane) parent;      JScrollPane sc = (JScrollPane) parent;
260          synchronized (sc.getTreeLock ())      Dimension viewportSize = viewport.getPreferredSize();
261            {      Dimension viewSize = viewport.getViewSize();
262              Dimension insetsSize = new Dimension(0,0);      int width = viewportSize.width;
263              Dimension viewportSize = new Dimension(0,0);      int height = viewportSize.height;
264              Dimension viewportInsetsSize = new Dimension(0,0);  
265              Dimension columnHeaderSize = new Dimension(0,0);      // horizontal scrollbar needed if the view's preferred width
266              Dimension rowHeaderSize = new Dimension(0,0);      // is larger than the viewport's preferred width
267              Dimension verticalScrollBarSize = new Dimension(0,0);      if (hsb != null && viewSize.width > viewportSize.width)
268              Dimension horizontalScrollBarSize = new Dimension(0,0);        height += hsb.getPreferredSize().height;
269    
270              Insets insets = sc.getInsets();      // vertical scrollbar needed if the view's preferred height
271              Border viewportBorder = sc.getViewportBorder();      // is larger than the viewport's preferred height
272              Insets viewportInsets = null;      if (vsb != null && viewSize.height > viewportSize.height)
273          width += vsb.getPreferredSize().width;
274              if (viewportBorder != null)      if (rowHead != null && rowHead.isVisible())
275                {        width += rowHead.getPreferredSize().width;
276                  viewportInsets = viewportBorder.getBorderInsets(parent);      if (colHead != null && colHead.isVisible())
277                  if (viewportInsets != null)        height += colHead.getPreferredSize().height;
278                    viewportInsetsSize.setSize(viewportInsets.left + viewportInsets.right,      Insets i = sc.getInsets();
279                                               viewportInsets.top + viewportInsets.bottom);      return new Dimension(width + i.left + i.right,
280                }                           height + i.left + i.right);
   
             if (insets != null)  
               insetsSize.setSize(insets.left + insets.right,  
                                  insets.top + insets.bottom);  
   
             if (viewport != null)  
               {  
                 Component view = null;  
                 Scrollable scr = null;  
                 Dimension pref = null;  
                   
                 view = viewport.getView();  
                 if (view != null && view instanceof Scrollable)  
                   scr = (Scrollable) view;  
                 if (scr != null)  
                   pref = scr.getPreferredScrollableViewportSize();  
                 if (pref == null)  
                   pref = viewport.getPreferredSize();  
                 if (pref != null)  
                   viewportSize.setSize(pref);  
               }  
                         
             maybeSetPreferredSize(colHead, columnHeaderSize);  
             maybeSetPreferredSize(rowHead, rowHeaderSize);  
             maybeSetPreferredSize(vsb, verticalScrollBarSize);  
             maybeSetPreferredSize(hsb, horizontalScrollBarSize);  
   
             return new Dimension(insetsSize.width  
                                  + viewportSize.width  
                                  + viewportInsetsSize.width  
                                  + rowHeaderSize.width  
                                  + verticalScrollBarSize.width,  
                                  insetsSize.height  
                                  + viewportSize.height  
                                  + viewportInsetsSize.height  
                                  + columnHeaderSize.height  
                                  + horizontalScrollBarSize.height);  
           }  
       }  
     else  
       {  
         return new Dimension(0,0);  
       }  
281    }    }
282    
283    public Dimension minimumLayoutSize(Container parent)    public Dimension minimumLayoutSize(Container parent)
284    {    {
285      if (parent instanceof JScrollPane)      // Sun's implementation simply throws a ClassCastException if
286        {      // parent is no JScrollPane, so do we.
287          JScrollPane sc = (JScrollPane) parent;      JScrollPane sc = (JScrollPane) parent;
288          synchronized (sc.getTreeLock ())      Dimension viewportSize = viewport.getMinimumSize();
289            {      int width = viewportSize.width;
290              Dimension insetsSize = new Dimension(0,0);      int height = viewportSize.height;
291              Dimension viewportSize = new Dimension(0,0);      if (hsb != null && hsb.isVisible())
292              Dimension viewportInsetsSize = new Dimension(0,0);        height += hsb.getMinimumSize().height;
293              Dimension columnHeaderSize = new Dimension(0,0);      if (vsb != null && vsb.isVisible())
294              Dimension rowHeaderSize = new Dimension(0,0);        width += vsb.getMinimumSize().width;
295              Dimension verticalScrollBarSize = new Dimension(0,0);      if (rowHead != null && rowHead.isVisible())
296              Dimension horizontalScrollBarSize = new Dimension(0,0);        width += rowHead.getMinimumSize().width;
297        if (colHead != null && colHead.isVisible())
298              Insets insets = sc.getInsets();        height += colHead.getMinimumSize().height;
299              Border viewportBorder = sc.getViewportBorder();      Insets i = sc.getInsets();
300              Insets viewportInsets = null;      return new Dimension(width + i.left + i.right,
301                             height + i.top + i.bottom);
             if (viewportBorder != null)  
               {  
                 viewportInsets = viewportBorder.getBorderInsets(parent);  
                 if (viewportInsets != null)  
                   viewportInsetsSize.setSize(viewportInsets.left + viewportInsets.right,  
                                              viewportInsets.top + viewportInsets.bottom);  
               }  
               
             if (insets != null)  
               insetsSize.setSize(insets.left + insets.right,  
                                  insets.top + insets.bottom);  
   
             maybeSetMinimumSize(colHead, columnHeaderSize);  
             maybeSetMinimumSize(rowHead, rowHeaderSize);  
               
             if (vsbPolicy != VERTICAL_SCROLLBAR_NEVER)  
               maybeSetMinimumSize(vsb, verticalScrollBarSize);  
   
             if (hsbPolicy != HORIZONTAL_SCROLLBAR_NEVER)  
               maybeSetMinimumSize(hsb, horizontalScrollBarSize);  
               
             return new Dimension(insetsSize.width  
                                  + viewportSize.width  
                                  + viewportInsetsSize.width  
                                  + rowHeaderSize.width  
                                  + verticalScrollBarSize.width,  
                                  insetsSize.height  
                                  + viewportSize.height  
                                  + viewportInsetsSize.height  
                                  + columnHeaderSize.height  
                                  + horizontalScrollBarSize.height);  
           }  
       }  
     else  
       {  
         return new Dimension(0,0);  
       }  
302    }    }
303    
304    /**    /**
# Line 421  public class ScrollPaneLayout Line 324  public class ScrollPaneLayout
324     */     */
325    public void layoutContainer(Container parent)    public void layoutContainer(Container parent)
326    {    {
327      if (parent instanceof JScrollPane)      // Sun's implementation simply throws a ClassCastException if
328        {      // parent is no JScrollPane, so do we.
329          JScrollPane sc = (JScrollPane) parent;      JScrollPane sc = (JScrollPane) parent;
330          synchronized (sc.getTreeLock ())      JViewport viewport = sc.getViewport();
331            {      Dimension viewSize = viewport.getViewSize();
332              JViewport viewport = sc.getViewport();  
333              Dimension viewSize = viewport.getViewSize();      int x1 = 0, x2 = 0, x3 = 0, x4 = 0;
334              Point viewPos = viewport.getViewPosition();      int y1 = 0, y2 = 0, y3 = 0, y4 = 0;
335        Rectangle scrollPaneBounds = SwingUtilities.calculateInnerArea(sc, null);
336              int x1 = 0, x2 = 0, x3 = 0, x4 = 0;  
337              int y1 = 0, y2 = 0, y3 = 0, y4 = 0;      x1 = scrollPaneBounds.x;
338        y1 = scrollPaneBounds.y;
339              Rectangle scrollPaneBounds = SwingUtilities.calculateInnerArea(sc, null);      x4 = scrollPaneBounds.x + scrollPaneBounds.width;
340        y4 = scrollPaneBounds.y + scrollPaneBounds.height;
341              x1 = scrollPaneBounds.x;      if (colHead != null)
342              y1 = scrollPaneBounds.y;        y2 = y1 + colHead.getPreferredSize().height;
343              x4 = scrollPaneBounds.x + scrollPaneBounds.width;      else
344              y4 = scrollPaneBounds.y + scrollPaneBounds.height;        y2 = y1;
               
             if (colHead != null)  
               y2 = y1 + colHead.getPreferredSize().height;  
             else  
               y2 = y1;  
   
             if (rowHead != null)  
               x2 = x1 + rowHead.getPreferredSize().width;  
             else  
               x2 = x1;  
   
             int vsbPolicy = sc.getVerticalScrollBarPolicy();  
             int hsbPolicy = sc.getHorizontalScrollBarPolicy();  
   
             x3 = x4 - vsb.getPreferredSize().width;  
             y3 = y4 - hsb.getPreferredSize().height;  
   
             boolean showVsb =  
               (vsb != null)  
               && ((vsbPolicy == VERTICAL_SCROLLBAR_ALWAYS)  
                   || (vsbPolicy == VERTICAL_SCROLLBAR_AS_NEEDED  
                       && viewSize.height > (y3 - y2)));  
   
             boolean showHsb =  
               (hsb != null)  
               && ((hsbPolicy == HORIZONTAL_SCROLLBAR_ALWAYS)  
                   || (hsbPolicy == HORIZONTAL_SCROLLBAR_AS_NEEDED  
                       && viewSize.width > (x3 - x2)));  
               
             if (!showVsb)  
               x3 = x4;  
               
             if (!showHsb)  
               y3 = y4;  
   
             // now set the layout  
   
             if (viewport != null)  
               viewport.setBounds(new Rectangle(x2, y2, x3-x2, y3-y2));  
   
             if (colHead != null)  
               colHead.setBounds(new Rectangle(x2, y1, x3-x2, y2-y1));  
   
             if (rowHead != null)  
               rowHead.setBounds(new Rectangle(x1, y2, x2-x1, y3-y2));  
   
             if (showVsb)  
               {  
                 vsb.setVisible(true);  
                 vsb.setBounds(new Rectangle(x3, y2, x4-x3, y3-y2));  
               }  
             else if (vsb != null)  
               vsb.setVisible(false);  
   
             if (showHsb)  
               {  
                 hsb.setVisible(true);  
                 hsb.setBounds(new Rectangle(x2, y3, x3-x2, y4-y3));  
               }  
             else if (hsb != null)  
               hsb.setVisible(false);  
   
             if (upperLeft != null)  
               upperLeft.setBounds(new Rectangle(x1, y1, x2-x1, y2-y1));  
   
             if (upperRight != null)  
               upperRight.setBounds(new Rectangle(x3, y1, x4-x3, y2-y1));  
345    
346              if (lowerLeft != null)      if (rowHead != null)
347                lowerLeft.setBounds(new Rectangle(x1, y3, x2-x1, y4-y3));        x2 = x1 + rowHead.getPreferredSize().width;
348        else
349          x2 = x1;
350    
351        int vsbPolicy = sc.getVerticalScrollBarPolicy();
352        int hsbPolicy = sc.getHorizontalScrollBarPolicy();
353    
354        boolean showVsb =
355          (vsb != null)
356          && ((vsbPolicy == VERTICAL_SCROLLBAR_ALWAYS)
357              || (vsbPolicy == VERTICAL_SCROLLBAR_AS_NEEDED
358                  && viewSize.height > (y4 - y2)));
359        boolean showHsb =
360          (hsb != null)
361          && ((hsbPolicy == HORIZONTAL_SCROLLBAR_ALWAYS)
362              || (hsbPolicy == HORIZONTAL_SCROLLBAR_AS_NEEDED
363                  && viewSize.width > (x4 - x2)));
364    
365        if (!showVsb)
366          x3 = x4;
367        else
368          x3 = x4 - vsb.getPreferredSize().width;
369    
370        if (!showHsb)
371          y3 = y4;
372        else
373          y3 = y4 - hsb.getPreferredSize().height;
374    
375        // now set the layout
376        if (viewport != null)
377          viewport.setBounds(new Rectangle(x2, y2, x3 - x2, y3 - y2));
378    
379        if (colHead != null)
380          colHead.setBounds(new Rectangle(x2, y1, x3 - x2, y2 - y1));
381    
382              if (lowerRight != null)      if (rowHead != null)
383                lowerRight.setBounds(new Rectangle(x3, y3, x4-x3, y4-y3));        rowHead.setBounds(new Rectangle(x1, y2, x2 - x1, y3 - y2));
384    
385            }      if (showVsb)
386          {
387            vsb.setVisible(true);
388            vsb.setBounds(new Rectangle(x3, y2, x4 - x3, y3 - y2));
389          }
390        else if (vsb != null)
391          vsb.setVisible(false);
392    
393        if (showHsb)
394          {
395            hsb.setVisible(true);
396            hsb.setBounds(new Rectangle(x2, y3, x3 - x2, y4 - y3));
397        }        }
398        else if (hsb != null)
399          hsb.setVisible(false);
400    
401        if (upperLeft != null)
402          upperLeft.setBounds(new Rectangle(x1, y1, x2 - x1, y2 - y1));
403    
404        if (upperRight != null)
405          upperRight.setBounds(new Rectangle(x3, y1, x4 - x3, y2 - y1));
406    
407        if (lowerLeft != null)
408          lowerLeft.setBounds(new Rectangle(x1, y3, x2 - x1, y4 - y3));
409    
410        if (lowerRight != null)
411          lowerRight.setBounds(new Rectangle(x3, y3, x4 - x3, y4 - y3));
412    }    }
413    
414    /**    /**

Legend:
Removed from v.1.8.2.7  
changed lines
  Added in v.1.8.2.8

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