View Javadoc

1   /*
2   * The contents of this file are subject to the BT "ZEUS" Open Source 
3   * Licence (L77741), Version 1.0 (the "Licence"); you may not use this file 
4   * except in compliance with the Licence. You may obtain a copy of the Licence
5   * from $ZEUS_INSTALL/licence.html or alternatively from
6   * http://www.labs.bt.com/projects/agents/zeus/licence.htm
7   * 
8   * Except as stated in Clause 7 of the Licence, software distributed under the
9   * Licence is distributed WITHOUT WARRANTY OF ANY KIND, either express or 
10  * implied. See the Licence for the specific language governing rights and 
11  * limitations under the Licence.
12  * 
13  * The Original Code is within the package zeus.*.
14  * The Initial Developer of the Original Code is British Telecommunications
15  * public limited company, whose registered office is at 81 Newgate Street, 
16  * London, EC1A 7AJ, England. Portions created by British Telecommunications 
17  * public limited company are Copyright 1996-9. All Rights Reserved.
18  * 
19  * THIS NOTICE MUST BE INCLUDED ON ANY COPY OF THIS FILE
20  */
21  
22  
23  
24  package zeus.gui.graph;
25  
26  import java.awt.*;
27  import zeus.util.Assert;
28  
29  /***
30   * Lays out components as though they were pinned to
31   * a bulletin board.<p>
32   *
33   * Components are simply reshaped to their location and their
34   * preferred size.  BulletinLayout is preferrable to setting
35   * a container's layout manager to null and explicitly positioning
36   * and sizing components.<p>
37   *
38   * @version 1.0, Apr 1 1996
39   * @author  David Geary
40   */
41  public class BulletinLayout implements LayoutManager {
42      public BulletinLayout() {
43      }
44      public void addLayoutComponent(String name, Component comp) {
45      }
46      public void removeLayoutComponent(Component comp) {
47      }
48      public Dimension preferredLayoutSize(Container target) {
49          Insets    insets      = target.insets();
50          Dimension dim         = new Dimension(0,0);
51          int       ncomponents = target.countComponents();
52          Component comp;
53          Dimension d;
54          Rectangle preferredBounds = new Rectangle(0,0);
55          Rectangle compPreferredBounds;
56  
57          for (int i = 0 ; i < ncomponents ; i++) {
58              comp = target.getComponent(i);
59  
60              if(comp.isVisible()) {
61                  d = comp.preferredSize();
62                  compPreferredBounds =
63                      new Rectangle(comp.location());
64                  compPreferredBounds.width  = d.width;
65                  compPreferredBounds.height = d.height;
66  
67                  preferredBounds =
68                      preferredBounds.union(compPreferredBounds);
69              }
70          }
71          dim.width  += insets.left + insets.right;
72          dim.height += insets.top + insets.bottom;
73  
74          return dim;
75      }
76      public Dimension minimumLayoutSize(Container target) {
77          Insets    insets      = target.insets();
78          Dimension dim         = new Dimension(0,0);
79          int       ncomponents = target.countComponents();
80          Component comp;
81          Dimension d;
82          Rectangle minimumBounds = new Rectangle(0,0);
83          Rectangle compMinimumBounds;
84  
85          for (int i = 0 ; i < ncomponents ; i++) {
86              comp = target.getComponent(i);
87  
88              if(comp.isVisible()) {
89                  d = comp.minimumSize();
90                  compMinimumBounds =
91                      new Rectangle(comp.location());
92                  compMinimumBounds.width  = d.width;
93                  compMinimumBounds.height = d.height;
94  
95                  minimumBounds =
96                      minimumBounds.union(compMinimumBounds);
97              }
98          }
99          dim.width  += insets.left + insets.right;
100         dim.height += insets.top + insets.bottom;
101 
102         return dim;
103     }
104     public void layoutContainer(Container target) {
105         Insets    insets      = target.insets();
106         int       ncomponents = target.countComponents();
107         Component comp;
108         Dimension ps;
109         Point loc;
110 
111         for (int i = 0 ; i < ncomponents ; i++) {
112             comp = target.getComponent(i);
113 
114             if(comp.isVisible()) {
115                 ps  = comp.preferredSize();
116                 loc = comp.location();
117 
118                 comp.reshape(insets.left + loc.x,
119                              insets.top + loc.y,
120                              ps.width, ps.height);
121             }
122         }
123     }
124 }