summaryrefslogtreecommitdiff
path: root/java/gjt/test/ComponentScrollerTest.java
blob: 4f0e4a2ec707b92c6d92f3cbf0fc6fb5110f4b3b (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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
package gjt.test;

import java.awt.*;
import java.util.Vector;
import java.applet.Applet;
import java.net.URL;

import gjt.Border;
import gjt.ButtonPanel;
import gjt.ColumnLayout;
import gjt.ComponentScroller;
import gjt.EtchedBorder;
import gjt.ImageButton;
import gjt.RowLayout;
import gjt.Separator;
import gjt.StickyImageButtonController;

/**
 * A phony image store, where you can purchase images.<p>
 *
 * @version 1.0, April 25, 1996
 * @author  David Geary
 * @see     gjt.test.UnitTest
 * @see     Border
 * @see     ButtonPanel
 * @see     ImageButton
 * @see     Separator
 * @see     StickyImageButtonController
 * @see     ComponentScroller
 */
public class ComponentScrollerTest extends UnitTest {
    public String title() { 
        return "ComponentScroller Test"; 
    }
    public Panel  centerPanel() { 
        return new ComponentScrollerTestPanel(this);
    }
}

class ComponentScrollerTestPanel extends Panel {
    private ComponentScroller scroller;
    private Panel             purchasePanel;
    private ImageButtonRow    nextRow;
    private String[][]        imageNames = {
        { "gifs/ballot_box.gif",  "gifs/filmstrip.gif",
          "gifs/fly.gif",         "gifs/eagle.gif",
          "gifs/bullet_hole.gif" },
        { "gifs/mad_hacker.gif",  "gifs/tricycle.gif",
          "gifs/light_bulb1.gif", "gifs/scissors.gif",
          "gifs/palette.gif" },
        { "gifs/frog.gif",        "gifs/gear.gif",
          "gifs/wrench.gif",      "gifs/www.gif",
          "gifs/Dining.gif" },
        { "gifs/ant.gif",         "gifs/abomb.gif",
          "gifs/basketball.gif",  "gifs/soccer.gif",
          "gifs/skelly.gif" },
    };
    public ComponentScrollerTestPanel(Applet applet) {
        URL    base = applet.getCodeBase();
        Image  nextImage;
        Border border, blackBorder;

        purchasePanel = new Panel();
        purchasePanel.setLayout(new ColumnLayout());

        for(int r=0; r < imageNames.length; ++r) {
            nextRow = new ImageButtonRow();
            nextRow.setLayout(new RowLayout());

            for(int c=0; c < imageNames[r].length; ++c) {
                nextImage = applet.getImage(base, 
                                            imageNames[r][c]);
                nextRow.add(nextImage);
            }
            purchasePanel.add(nextRow);
        }
        purchasePanel.add(new ButtonPurchaseForm());

        scroller    = new ComponentScroller();
        border      = new Border(purchasePanel, 3, 2);
        blackBorder = new Border(border, 1, 0);

        border.setLineColor(Color.gray);
        blackBorder.setLineColor(Color.black);
        scroller.setComponent(blackBorder);

        setLayout(new BorderLayout());
        add("Center", scroller);
    }
}

class ButtonPurchaseForm extends Panel {
    TextField nameField    = new TextField(25);
    TextField addressField = new TextField(25);
    TextField cityField    = new TextField(15);
    TextField stateField   = new TextField(2);

    Choice    paymentChoice = new Choice();

    Button    paymentButton = new Button("Purchase");
    Button    cancelButton   = new Button("Cancel");

    public ButtonPurchaseForm() {
        GridBagLayout      gbl = new GridBagLayout();
        GridBagConstraints gbc = new GridBagConstraints();

        Separator sep = new Separator();
        Label title   = 
            new Label("Purchase A Fine Image Today");
        Label name    = new Label("Name:");
        Label address = new Label("Address:");
        Label payment = new Label("Purchase Method:");
        Label phone   = new Label("Phone:");
        Label city    = new Label("City:");
        Label state   = new Label("State:");

        setLayout(gbl);

        paymentChoice.addItem("Visa");
        paymentChoice.addItem("MasterCard");
        paymentChoice.addItem("COD");

        title.setFont(new Font("Times-Roman", 
                               Font.BOLD + Font.ITALIC,
                               16));
        gbc.anchor    = GridBagConstraints.NORTH;
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbl.setConstraints(title, gbc);
        add(title);

        gbc.anchor    = GridBagConstraints.NORTH;
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.fill      = GridBagConstraints.HORIZONTAL;
        gbc.insets    = new Insets(0,0,10,0);
        gbl.setConstraints(sep, gbc);
        add(sep);

        gbc.anchor    = GridBagConstraints.WEST;
        gbc.gridwidth = 1;
        gbc.insets    = new Insets(0,0,0,10);
        gbl.setConstraints(name, gbc);
        add(name);

        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbl.setConstraints(nameField, gbc);
        add(nameField);

        gbc.gridwidth = 1;
        gbl.setConstraints(address, gbc);
        add(address);

        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbl.setConstraints(addressField, gbc);
        add(addressField);

        gbc.gridwidth = 1;
        gbl.setConstraints(city, gbc);
        add(city);

        gbl.setConstraints(cityField, gbc);
        add(cityField);

        gbl.setConstraints(state, gbc);
        add(state);

        gbl.setConstraints(stateField, gbc);
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbl.setConstraints(stateField, gbc);
        add(stateField);

        gbc.gridwidth = 1;
        gbl.setConstraints(payment, gbc);
        gbc.insets = new Insets(5,0,5,0);
        add(payment);

        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.fill      = GridBagConstraints.NONE;
        gbl.setConstraints(paymentChoice, gbc);
        add(paymentChoice);

        ButtonPanel buttonPanel = new ButtonPanel();

        buttonPanel.add(paymentButton);
        buttonPanel.add(cancelButton);

        gbc.anchor    = GridBagConstraints.SOUTH;
        gbc.insets    = new Insets(5,0,0,0);
        gbc.fill      = GridBagConstraints.HORIZONTAL;
        gbc.gridwidth = 4;
        gbl.setConstraints(buttonPanel, gbc);
        add(buttonPanel);
    }
}
class ImageButtonRow extends Panel {
    public ImageButtonRow() {
        setLayout(new RowLayout());
    }
    public void add(Image image) {
        ImageButton button = new ImageButton(image);
        add(button);
        button.setController(
                new StickyImageButtonController(button));
    }
}