/[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.18 by rabbit78, Thu Oct 13 18:33:05 2005 UTC revision 1.19 by rabbit78, Tue Oct 18 09:50:39 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 64  public class ScrollPaneLayout Line 61  public class ScrollPaneLayout
61    {    {
62      public UIResource()      public UIResource()
63      {      {
64          super();
65      }      }
66    }    }
67    
# Line 79  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 255  public class ScrollPaneLayout Line 254  public class ScrollPaneLayout
254    
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          Dimension viewportSize = viewport.getPreferredSize();      Dimension viewportSize = viewport.getPreferredSize();
261          int width = viewportSize.width;      int width = viewportSize.width;
262          int height = viewportSize.height;      int height = viewportSize.height;
263          if (hsb != null && hsb.isVisible())      if (hsb != null && hsb.isVisible())
264            height += hsb.getPreferredSize().height;        height += hsb.getPreferredSize().height;
265          if (vsb != null && vsb.isVisible())      if (vsb != null && vsb.isVisible())
266            width += vsb.getPreferredSize().width;        width += vsb.getPreferredSize().width;
267          if (rowHead != null && rowHead.isVisible())      if (rowHead != null && rowHead.isVisible())
268            width += rowHead.getPreferredSize().width;        width += rowHead.getPreferredSize().width;
269          if (colHead != null && colHead.isVisible())      if (colHead != null && colHead.isVisible())
270            height += colHead.getPreferredSize().height;        height += colHead.getPreferredSize().height;
271          return new Dimension(width, height);      Insets i = sc.getInsets();
272        }      return new Dimension(width + i.left + i.right,
273      // TODO: Probably throw an exception here. Check this.                           height + i.left + i.right);
     return new Dimension(0, 0);  
274    }    }
275    
276    public Dimension minimumLayoutSize(Container parent)    public Dimension minimumLayoutSize(Container parent)
277    {    {
278      if (parent != null && parent instanceof JScrollPane)      // Sun's implementation simply throws a ClassCastException if
279        {      // parent is no JScrollPane, so do we.
280          JScrollPane sc = (JScrollPane) parent;      JScrollPane sc = (JScrollPane) parent;
281          Dimension viewportSize = viewport.getMinimumSize();      Dimension viewportSize = viewport.getMinimumSize();
282          int width = viewportSize.width;      int width = viewportSize.width;
283          int height = viewportSize.height;      int height = viewportSize.height;
284          if (hsb != null && hsb.isVisible())      if (hsb != null && hsb.isVisible())
285            height += hsb.getMinimumSize().height;        height += hsb.getMinimumSize().height;
286          if (vsb != null && vsb.isVisible())      if (vsb != null && vsb.isVisible())
287            width += vsb.getMinimumSize().width;        width += vsb.getMinimumSize().width;
288          if (rowHead != null && rowHead.isVisible())      if (rowHead != null && rowHead.isVisible())
289            width += rowHead.getMinimumSize().width;        width += rowHead.getMinimumSize().width;
290          if (colHead != null && colHead.isVisible())      if (colHead != null && colHead.isVisible())
291            height += colHead.getMinimumSize().height;        height += colHead.getMinimumSize().height;
292          return new Dimension(width, height);      Insets i = sc.getInsets();
293        }      return new Dimension(width + i.left + i.right,
294      // TODO: Probably throw an exception here. Check this.                           height + i.top + i.bottom);
     return new Dimension(0, 0);  
295    }    }
296    
297    /**    /**
# Line 320  public class ScrollPaneLayout Line 317  public class ScrollPaneLayout
317     */     */
318    public void layoutContainer(Container parent)    public void layoutContainer(Container parent)
319    {    {
320      if (parent instanceof JScrollPane)      // Sun's implementation simply throws a ClassCastException if
321        {      // parent is no JScrollPane, so do we.
322          JScrollPane sc = (JScrollPane) parent;      JScrollPane sc = (JScrollPane) parent;
323          JViewport viewport = sc.getViewport();      JViewport viewport = sc.getViewport();
324          Dimension viewSize = viewport.getViewSize();      Dimension viewSize = viewport.getViewSize();
325    
326          int x1 = 0, x2 = 0, x3 = 0, x4 = 0;      int x1 = 0, x2 = 0, x3 = 0, x4 = 0;
327          int y1 = 0, y2 = 0, y3 = 0, y4 = 0;      int y1 = 0, y2 = 0, y3 = 0, y4 = 0;
328        Rectangle scrollPaneBounds = SwingUtilities.calculateInnerArea(sc, null);
329          Rectangle scrollPaneBounds = SwingUtilities.calculateInnerArea(sc, null);  
330        x1 = scrollPaneBounds.x;
331          x1 = scrollPaneBounds.x;      y1 = scrollPaneBounds.y;
332          y1 = scrollPaneBounds.y;      x4 = scrollPaneBounds.x + scrollPaneBounds.width;
333          x4 = scrollPaneBounds.x + scrollPaneBounds.width;      y4 = scrollPaneBounds.y + scrollPaneBounds.height;
334          y4 = scrollPaneBounds.y + scrollPaneBounds.height;      if (colHead != null)
335          y2 = y1 + colHead.getPreferredSize().height;
336          if (colHead != null)      else
337            y2 = y1 + colHead.getPreferredSize().height;        y2 = y1;
338          else  
339            y2 = y1;      if (rowHead != null)
340          x2 = x1 + rowHead.getPreferredSize().width;
341          if (rowHead != null)      else
342            x2 = x1 + rowHead.getPreferredSize().width;        x2 = x1;
343          else  
344            x2 = x1;      int vsbPolicy = sc.getVerticalScrollBarPolicy();
345        int hsbPolicy = sc.getHorizontalScrollBarPolicy();
346          int vsbPolicy = sc.getVerticalScrollBarPolicy();  
347          int hsbPolicy = sc.getHorizontalScrollBarPolicy();      boolean showVsb =
348          (vsb != null)
349          boolean showVsb =        && ((vsbPolicy == VERTICAL_SCROLLBAR_ALWAYS)
350            (vsb != null)            || (vsbPolicy == VERTICAL_SCROLLBAR_AS_NEEDED
351            && ((vsbPolicy == VERTICAL_SCROLLBAR_ALWAYS)                && viewSize.height > (y4 - y2)));
352                || (vsbPolicy == VERTICAL_SCROLLBAR_AS_NEEDED      boolean showHsb =
353                    && viewSize.height > (y4 - y2)));        (hsb != null)
354          boolean showHsb =        && ((hsbPolicy == HORIZONTAL_SCROLLBAR_ALWAYS)
355            (hsb != null)            || (hsbPolicy == HORIZONTAL_SCROLLBAR_AS_NEEDED
356            && ((hsbPolicy == HORIZONTAL_SCROLLBAR_ALWAYS)                && viewSize.width > (x4 - x2)));
357                || (hsbPolicy == HORIZONTAL_SCROLLBAR_AS_NEEDED  
358                    && viewSize.width > (x4 - x2)));      if (!showVsb)
359          x3 = x4;
360          if (!showVsb)      else
361            x3 = x4;        x3 = x4 - vsb.getPreferredSize().width;
362          else  
363            x3 = x4 - vsb.getPreferredSize().width;      if (!showHsb)
364          y3 = y4;
365          if (!showHsb)      else
366            y3 = y4;        y3 = y4 - hsb.getPreferredSize().height;
367          else  
368            y3 = y4 - hsb.getPreferredSize().height;      // now set the layout
369        if (viewport != null)
370          // now set the layout        viewport.setBounds(new Rectangle(x2, y2, x3 - x2, y3 - y2));
         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));  
371    
372          if (lowerLeft != null)      if (colHead != null)
373            lowerLeft.setBounds(new Rectangle(x1, y3, x2 - x1, y4 - y3));        colHead.setBounds(new Rectangle(x2, y1, x3 - x2, y2 - y1));
374    
375          if (lowerRight != null)      if (rowHead != null)
376            lowerRight.setBounds(new Rectangle(x3, y3, x4 - x3, y4 - y3));        rowHead.setBounds(new Rectangle(x1, y2, x2 - x1, y3 - y2));
377    
378        if (showVsb)
379          {
380            vsb.setVisible(true);
381            vsb.setBounds(new Rectangle(x3, y2, x4 - x3, y3 - y2));
382        }        }
383        else if (vsb != null)
384          vsb.setVisible(false);
385    
386        if (showHsb)
387          {
388            hsb.setVisible(true);
389            hsb.setBounds(new Rectangle(x2, y3, x3 - x2, y4 - y3));
390          }
391        else if (hsb != null)
392          hsb.setVisible(false);
393    
394        if (upperLeft != null)
395          upperLeft.setBounds(new Rectangle(x1, y1, x2 - x1, y2 - y1));
396    
397        if (upperRight != null)
398          upperRight.setBounds(new Rectangle(x3, y1, x4 - x3, y2 - y1));
399    
400        if (lowerLeft != null)
401          lowerLeft.setBounds(new Rectangle(x1, y3, x2 - x1, y4 - y3));
402    
403        if (lowerRight != null)
404          lowerRight.setBounds(new Rectangle(x3, y3, x4 - x3, y4 - y3));
405    }    }
406    
407    /**    /**

Legend:
Removed from v.1.18  
changed lines
  Added in v.1.19

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