blob: 848a280de03c2f886c32c32934d1a8b4739d19c6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
package gjt;
import java.awt.*;
/**
* Lays out components as though they were pinned to
* a bulletin board.<p>
*
* Components are simply reshaped to their location and their
* preferred size. BulletinLayout is preferrable to setting
* a container's layout manager to null and explicitly positioning
* and sizing components.<p>
*
* @version 1.0, Apr 1 1996
* @author David Geary
*/
public class BulletinLayout implements LayoutManager {
public BulletinLayout() {
}
public void addLayoutComponent(String name, Component comp) {
}
public void removeLayoutComponent(Component comp) {
}
public Dimension preferredLayoutSize(Container target) {
Insets insets = target.insets();
Dimension dim = new Dimension(0,0);
int ncomponents = target.countComponents();
Component comp;
Dimension d;
Rectangle preferredBounds = new Rectangle(0,0);
Rectangle compPreferredBounds;
for (int i = 0 ; i < ncomponents ; i++) {
comp = target.getComponent(i);
if(comp.isVisible()) {
d = comp.preferredSize();
compPreferredBounds =
new Rectangle(comp.location());
compPreferredBounds.width = d.width;
compPreferredBounds.height = d.height;
preferredBounds =
preferredBounds.union(compPreferredBounds);
}
}
dim.width += insets.left + insets.right;
dim.height += insets.top + insets.bottom;
return dim;
}
public Dimension minimumLayoutSize(Container target) {
Insets insets = target.insets();
Dimension dim = new Dimension(0,0);
int ncomponents = target.countComponents();
Component comp;
Dimension d;
Rectangle minimumBounds = new Rectangle(0,0);
Rectangle compMinimumBounds;
for (int i = 0 ; i < ncomponents ; i++) {
comp = target.getComponent(i);
if(comp.isVisible()) {
d = comp.minimumSize();
compMinimumBounds =
new Rectangle(comp.location());
compMinimumBounds.width = d.width;
compMinimumBounds.height = d.height;
minimumBounds =
minimumBounds.union(compMinimumBounds);
}
}
dim.width += insets.left + insets.right;
dim.height += insets.top + insets.bottom;
return dim;
}
public void layoutContainer(Container target) {
Insets insets = target.insets();
int ncomponents = target.countComponents();
Component comp;
Dimension ps;
Point loc;
for (int i = 0 ; i < ncomponents ; i++) {
comp = target.getComponent(i);
if(comp.isVisible()) {
ps = comp.preferredSize();
loc = comp.location();
comp.reshape(insets.left + loc.x,
insets.top + loc.y,
ps.width, ps.height);
}
}
}
}
|