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
101
102
103
104
105
|
package gjt;
import java.awt.*;
/**
* A panel containing a single component, around which a border
* is drawn. Of course, the single component may be a
* container which may contain other components, so a Border
* can surround multiple components.<p>
*
* Thickness of the border, and the gap between the Component
* and the border are specified at time of construction.
* Default border thickness is 2 - default gap is 0.<p>
*
* Border color may be set via setLineColor(Color).<p>
*
* Border employs a DrawnRectangle to paint the border. Derived
* classes are free to override DrawnRectangle border() if they
* wish to use an extension of DrawnRectangle for drawing their
* border.<p>
*
* The following code snippet, from gjt.test.BorderTest creates
* and AWT Button, and embeds the button in a border. That
* border is then embedded in another border. The AWT Button
* winds up inside of a cyan border with a pixel width of 7,
* inside of a black border (pixel width 2):<p>
*
* <pre>
* private Border makeBorderedAWTButton() {
* Button button;
* Border cyanBorder, blackBorder;
*
* button = new Button("Button Inside Two Borders");
* cyanBorder = new Border(button, 7);
* cyanBorder.setLineColor(Color.cyan);
*
* blackBorder = new Border(cyanBorder);
*
* return blackBorder;
* }
*</pre>
*
* @version 1.0, Apr 1 1996
* @author David Geary
* @see DrawnRectangle
* @see ThreeDBorder
* @see EtchedBorder
* @see gjt.test.BorderTest
*/
public class Border extends Panel {
protected int thickness;
protected int gap;
protected DrawnRectangle border;
protected static int _defaultThickness = 2;
protected static int _defaultGap = 0;
public Border(Component borderMe) {
this(borderMe, _defaultThickness, _defaultGap);
}
public Border(Component borderMe, int thickness) {
this(borderMe, thickness, _defaultGap);
}
public Border(Component borderMe, int thickness, int gap) {
this.thickness = thickness;
this.gap = gap;
setLayout(new BorderLayout());
add("Center", borderMe);
}
public Insets insets() {
return new Insets(thickness+gap, thickness+gap,
thickness+gap, thickness+gap);
}
public Rectangle getInnerBounds() {
return border().getInnerBounds();
}
public void setLineColor(Color c) {
border().setLineColor(c);
}
public Color getLineColor() {
return border().getLineColor();
}
public void paint(Graphics g) {
border().paint();
}
public void resize(int w, int h) {
Point location = location();
reshape(location.x, location.y, w, h);
}
public void reshape(int x, int y, int w, int h) {
super.reshape(x, y, w, h);
border().resize(w, h);
}
protected String paramString() {
return super.paramString() + ",border=" +
border().toString() + ",thickness=" + thickness
+ ",gap=" + gap;
}
protected DrawnRectangle border() {
if(border == null)
border = new DrawnRectangle(this, thickness);
return border;
}
}
|