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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
package gjt.test;
import java.applet.Applet;
import java.net.URL;
import java.awt.*;
import gjt.*;
/**
* Lays out 3 image buttons, and provides controls for setting
* orientations and gaps on the fly.<p>
*
* @version 1.0, April 25, 1996
* @author David Geary
* @see gjt.test.UnitTest
* @see gjt.ImageButton
* @see gjt.Box
*/
public class ColumnLayoutTest extends UnitTest {
public String title() {
return "ColumnLayout Test";
}
public Panel centerPanel() {
ColumnButtonPanel buttonPanel;
Panel panel = new Panel();
buttonPanel = new ColumnButtonPanel(this);
panel.setLayout(new BorderLayout());
panel.add("Center", buttonPanel);
panel.add("North", new Box(new ColumnPicker(buttonPanel),
"Column Layout Settings"));
return panel;
}
}
class ColumnButtonPanel extends Panel implements DialogClient {
private ImageButton one, two, three;
private Panel panel = new Panel();
private TenPixelBorder border = new TenPixelBorder(panel);
public ColumnButtonPanel(Applet applet) {
URL cb = applet.getCodeBase();
one = new ImageButton(applet.getImage(cb,
"gifs/one.gif"));
two = new ImageButton(applet.getImage(cb,
"gifs/two.gif"));
three = new ImageButton(applet.getImage(cb,
"gifs/three.gif"));
panel.setLayout(new ColumnLayout(0));
panel.add(one);
panel.add(two);
panel.add(three);
setLayout(new BorderLayout());
add ("Center", border);
}
public void updateOrientations(Orientation horient,
Orientation vorient,
int gap) {
panel.setLayout(new ColumnLayout(horient, vorient, gap));
border.validate();
}
public void dialogDismissed(Dialog d) { }
}
class ColumnPicker extends Panel {
private Label horientLabel = new Label("Horizontal:");
private Label vorientLabel = new Label("Vertical:");
private Label gapLabel = new Label("Gap:");
private Choice hchoice = new Choice();
private Choice vchoice = new Choice();
private Choice gapChoice = new Choice();
private ColumnButtonPanel buttonPanel;
public ColumnPicker(ColumnButtonPanel buttonPanel) {
Panel orientations = new Panel();
Panel gap = new Panel();
this.buttonPanel = buttonPanel;
hchoice.addItem("left");
hchoice.addItem("center");
hchoice.addItem("right");
hchoice.select(1);
vchoice.addItem("top");
vchoice.addItem("center");
vchoice.addItem("bottom");
vchoice.select(1);
gapChoice.addItem("0");
gapChoice.addItem("5");
gapChoice.addItem("10");
gapChoice.addItem("15");
gapChoice.addItem("20");
orientations.add(horientLabel);
orientations.add(hchoice);
orientations.add(vorientLabel);
orientations.add(vchoice);
gap.add(gapLabel);
gap.add(gapChoice);
add(new Box(orientations, "Orientations"));
add(new Box(gap, "Gap"));
}
public boolean action(Event event, Object what) {
String horient, vorient;
int gap;
horient = hchoice.getSelectedItem();
vorient = vchoice.getSelectedItem();
gap =
(new Integer(gapChoice.getSelectedItem())).intValue();
buttonPanel.updateOrientations(
Orientation.fromString(horient),
Orientation.fromString(vorient), gap);
return true;
}
}
|