1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 }