/[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.15 by abalkiss, Mon Sep 12 20:59:15 2005 UTC revision 1.16 by rabbit78, Wed Oct 12 14:36:11 2005 UTC
# Line 60  public class ScrollPaneLayout Line 60  public class ScrollPaneLayout
60    private static final long serialVersionUID = -4480022884523193743L;    private static final long serialVersionUID = -4480022884523193743L;
61    
62    public static class UIResource extends ScrollPaneLayout    public static class UIResource extends ScrollPaneLayout
63      implements javax.swing.plaf.UIResource {      implements javax.swing.plaf.UIResource
64      public UIResource() {    {
65        public UIResource()
66        {
67      }      }
68    }    }
69    
# Line 251  public class ScrollPaneLayout Line 253  public class ScrollPaneLayout
253      return null;      return null;
254    }    }
255    
   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);  
   }  
   
256    public Dimension preferredLayoutSize(Container parent)    public Dimension preferredLayoutSize(Container parent)
257    {    {
258      if (parent != null && parent instanceof JScrollPane)      if (parent != null && parent instanceof JScrollPane)
259        {        {
260          JScrollPane sc = (JScrollPane) parent;          JScrollPane sc = (JScrollPane) parent;
261          synchronized (sc.getTreeLock ())          Dimension viewportSize = viewport.getPreferredSize();
262            {          int width = viewportSize.width;
263              Dimension insetsSize = new Dimension(0,0);          int height = viewportSize.height;
264              Dimension viewportSize = new Dimension(0,0);          if (hsb.isVisible())
265              Dimension viewportInsetsSize = new Dimension(0,0);            height += hsb.getPreferredSize().height;
266              Dimension columnHeaderSize = new Dimension(0,0);          if (vsb.isVisible())
267              Dimension rowHeaderSize = new Dimension(0,0);            width += vsb.getPreferredSize().width;
268              Dimension verticalScrollBarSize = new Dimension(0,0);          if (rowHead != null && rowHead.isVisible())
269              Dimension horizontalScrollBarSize = new Dimension(0,0);            width += rowHead.getPreferredSize().width;
270            if (colHead != null && colHead.isVisible())
271              Insets insets = sc.getInsets();            height += colHead.getPreferredSize().height;
272              Border viewportBorder = sc.getViewportBorder();          return new Dimension(width, height);
             Insets viewportInsets = null;  
   
             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);  
   
             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);  
273        }        }
274        // TODO: Probably throw an exception here. Check this.
275        return new Dimension(0, 0);
276    }    }
277    
278    public Dimension minimumLayoutSize(Container parent)    public Dimension minimumLayoutSize(Container parent)
279    {    {
280      if (parent instanceof JScrollPane)      if (parent != null && parent instanceof JScrollPane)
281        {        {
282          JScrollPane sc = (JScrollPane) parent;          JScrollPane sc = (JScrollPane) parent;
283          synchronized (sc.getTreeLock ())          Dimension viewportSize = viewport.getMinimumSize();
284            {          int width = viewportSize.width;
285              Dimension insetsSize = new Dimension(0,0);          int height = viewportSize.height;
286              Dimension viewportSize = new Dimension(0,0);          if (hsb.isVisible())
287              Dimension viewportInsetsSize = new Dimension(0,0);            height += hsb.getMinimumSize().height;
288              Dimension columnHeaderSize = new Dimension(0,0);          if (vsb.isVisible())
289              Dimension rowHeaderSize = new Dimension(0,0);            width += vsb.getMinimumSize().width;
290              Dimension verticalScrollBarSize = new Dimension(0,0);          if (rowHead.isVisible())
291              Dimension horizontalScrollBarSize = new Dimension(0,0);            width += rowHead.getMinimumSize().width;
292            if (colHead.isVisible())
293              Insets insets = sc.getInsets();            height += colHead.getMinimumSize().height;
294              Border viewportBorder = sc.getViewportBorder();          return new Dimension(width, height);
             Insets viewportInsets = null;  
   
             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);  
295        }        }
296        // TODO: Probably throw an exception here. Check this.
297        return new Dimension(0, 0);
298    }    }
299    
300    /**    /**
# Line 424  public class ScrollPaneLayout Line 323  public class ScrollPaneLayout
323      if (parent instanceof JScrollPane)      if (parent instanceof JScrollPane)
324        {        {
325          JScrollPane sc = (JScrollPane) parent;          JScrollPane sc = (JScrollPane) parent;
326          synchronized (sc.getTreeLock ())          JViewport viewport = sc.getViewport();
327            {          Dimension viewSize = viewport.getViewSize();
             JViewport viewport = sc.getViewport();  
             Dimension viewSize = viewport.getViewSize();  
             Point viewPos = viewport.getViewPosition();  
   
             int x1 = 0, x2 = 0, x3 = 0, x4 = 0;  
             int y1 = 0, y2 = 0, y3 = 0, y4 = 0;  
   
             Rectangle scrollPaneBounds = SwingUtilities.calculateInnerArea(sc, null);  
   
             x1 = scrollPaneBounds.x;  
             y1 = scrollPaneBounds.y;  
             x4 = scrollPaneBounds.x + scrollPaneBounds.width;  
             y4 = scrollPaneBounds.y + scrollPaneBounds.height;  
               
             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));  
328    
329              if (upperRight != null)          int x1 = 0, x2 = 0, x3 = 0, x4 = 0;
330                upperRight.setBounds(new Rectangle(x3, y1, x4-x3, y2-y1));          int y1 = 0, y2 = 0, y3 = 0, y4 = 0;
331    
332              if (lowerLeft != null)          Rectangle scrollPaneBounds = SwingUtilities.calculateInnerArea(sc, null);
               lowerLeft.setBounds(new Rectangle(x1, y3, x2-x1, y4-y3));  
333    
334              if (lowerRight != null)          x1 = scrollPaneBounds.x;
335                lowerRight.setBounds(new Rectangle(x3, y3, x4-x3, y4-y3));          y1 = scrollPaneBounds.y;
336            x4 = scrollPaneBounds.x + scrollPaneBounds.width;
337            y4 = scrollPaneBounds.y + scrollPaneBounds.height;
338    
339            if (colHead != null)
340              y2 = y1 + colHead.getPreferredSize().height;
341            else
342              y2 = y1;
343    
344            if (rowHead != null)
345              x2 = x1 + rowHead.getPreferredSize().width;
346            else
347              x2 = x1;
348    
349            int vsbPolicy = sc.getVerticalScrollBarPolicy();
350            int hsbPolicy = sc.getHorizontalScrollBarPolicy();
351    
352            boolean showVsb =
353              (vsb != null)
354              && ((vsbPolicy == VERTICAL_SCROLLBAR_ALWAYS)
355                  || (vsbPolicy == VERTICAL_SCROLLBAR_AS_NEEDED
356                      && viewSize.height > (y4 - y2)));
357            boolean showHsb =
358              (hsb != null)
359              && ((hsbPolicy == HORIZONTAL_SCROLLBAR_ALWAYS)
360                  || (hsbPolicy == HORIZONTAL_SCROLLBAR_AS_NEEDED
361                      && viewSize.width > (x4 - x2)));
362    
363            if (!showVsb)
364              x3 = x4;
365            else
366              x3 = x4 - vsb.getPreferredSize().width;
367    
368            if (!showHsb)
369              y3 = y4;
370            else
371              y3 = y4 - hsb.getPreferredSize().height;
372    
373            // now set the layout
374            if (viewport != null)
375              viewport.setBounds(new Rectangle(x2, y2, x3 - x2, y3 - y2));
376    
377            if (colHead != null)
378              colHead.setBounds(new Rectangle(x2, y1, x3 - x2, y2 - y1));
379    
380            if (rowHead != null)
381              rowHead.setBounds(new Rectangle(x1, y2, x2 - x1, y3 - y2));
382    
383            if (showVsb)
384              {
385                vsb.setVisible(true);
386                vsb.setBounds(new Rectangle(x3, y2, x4 - x3, y3 - y2));
387            }            }
388            else if (vsb != null)
389              vsb.setVisible(false);
390    
391            if (showHsb)
392              {
393                hsb.setVisible(true);
394                hsb.setBounds(new Rectangle(x2, y3, x3 - x2, y4 - y3));
395              }
396            else if (hsb != null)
397              hsb.setVisible(false);
398    
399            if (upperLeft != null)
400              upperLeft.setBounds(new Rectangle(x1, y1, x2 - x1, y2 - y1));
401            
402            if (upperRight != null)
403              upperRight.setBounds(new Rectangle(x3, y1, x4 - x3, y2 - y1));
404    
405            if (lowerLeft != null)
406              lowerLeft.setBounds(new Rectangle(x1, y3, x2 - x1, y4 - y3));
407    
408            if (lowerRight != null)
409              lowerRight.setBounds(new Rectangle(x3, y3, x4 - x3, y4 - y3));
410        }        }
411    }    }
412    

Legend:
Removed from v.1.15  
changed lines
  Added in v.1.16

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