panel.setLayout(l);
c.fill = GridBagConstraints.BOTH;
int token;
int ChoiceCount = 0;
JList list;
// parse the setup file
try {
while ((token = setup.nextToken()) != StreamTokenizer.TT_EOF) {
switch (token) {
case StreamTokenizer.TT_WORD:
// reset the constraints
c.gridwidth = 1;
c.weightx = 0.0;
c.weighty = 0.0;
// keyword found, parse arguments
if (setup.sval.equals("button")) {
if ((token = setup.nextToken()) != StreamTokenizer.TT_EOF) {
String descr = setup.sval;
if ((token = setup.nextToken()) != StreamTokenizer.TT_EOF) {
JButton b = new JButton(descr);
buttons.put(b, setup.sval);
b.addActionListener(ButtonBar.this);
l.setConstraints(b, constraints(c, setup));
panel.add(b);
} else
ButtonBar.this.error(descr + ": missing button command");
} else
ButtonBar.this.error("unexpected end of file");
} else if (setup.sval.equals("label")) {
if ((token = setup.nextToken()) != StreamTokenizer.TT_EOF) {
String descr = setup.sval;
JLabel b = new JLabel(descr);
l.setConstraints(b, constraints(c, setup));
panel.add(b);
} else
ButtonBar.this.error("unexpected end of file");
/* choice - new stuff added APS 07-dec-2001 for Choice
* buttons
* Choice info is held in the choices hash. There are two
* sorts of hash entry:
* 1) for each choices button on the terminal, key=choice
* object, value=ID ("C1.", "C2.", etc)
* 2) for each item, key=ID+user's text (eg "C1.opt1"),
* value=user's command
*/
} else if (setup.sval.equals("choice")) {
ChoiceCount++;
String ident = "C" + ChoiceCount + ".";
list = new JList();
choices.put(list, ident);
list.addListSelectionListener(ButtonBar.this);// Choices use ItemListener, not Action
l.setConstraints(list, constraints(c, setup));
panel.add(list);
while ((token = setup.nextToken()) != StreamTokenizer.TT_EOF) {
if (isKeyword(setup.sval)) {// Got command ... Back off.
setup.pushBack();
break;
}
String descr = setup.sval; // This is the hash key.
token = setup.nextToken();
if (token == StreamTokenizer.TT_EOF) {
ButtonBar.this.error("unexpected end of file");
} else {
String value = setup.sval;
if (isKeyword(value)) { // Missing command - complain but continue
System.err.println(descr + ": missing choice command");
setup.pushBack();
break;
}
System.out.println("choice: name='" + descr + "', value='" + value);
list.add(descr, new JLabel(descr));
choices.put(ident + descr, value);
}
}
ButtonBar.this.error("choices hash: " + choices);
} else if (setup.sval.equals("input")) {