public GroupDialog(JFrame parent_,
Vector groups_,
int index_,
String defaultField) {
super(parent_, "Edit group", true);
parent = parent_;
groups = groups_;
index = index_;
if (index >= 0) {
// Group entry already exists.
try {
oldField = (String)groups.elementAt(index);
field.setText(oldField);
oldName = (String)groups.elementAt(index+1);
name.setText(oldName);
oldRegexp = (String)groups.elementAt(index+2);
regexp.setText(oldRegexp);
// We disable these text fields, since changing field
// or regexp would leave the entries added to the
// group hanging.
field.setEnabled(false);
regexp.setEnabled(false);
} catch (ArrayIndexOutOfBoundsException ex) {
}
} else
field.setText(defaultField);
ActionListener okListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Check that there are no empty strings.
if ((field.getText().equals("")) ||
(name.getText().equals("")) ||
(regexp.getText().equals(""))) {
JOptionPane.showMessageDialog
(parent, "You must provide a name, a search "
+"string and a field name for this group.",
"Create group", JOptionPane.ERROR_MESSAGE);
return;
}
// Handling of : and ; must also be done.
ok_pressed = true;
if (index < 0) {
// New group.
index = GroupSelector.findPos(groups, name.getText());
groups.add(index, regexp.getText());
groups.add(index, name.getText());
groups.add(index, field.getText());
} else if (index < groups.size()) {
// Change group.
for (int i=0; i< GroupSelector.DIM; i++)
groups.removeElementAt(index);
index = GroupSelector.findPos(groups, name.getText());
groups.add(index, regexp.getText());
groups.add(index, name.getText());
groups.add(index, field.getText());
}
dispose();
}
};
ok.addActionListener(okListener);
name.addActionListener(okListener);
regexp.addActionListener(okListener);
field.addActionListener(okListener);
/*cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});*/
AbstractAction cancelAction = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
dispose();
}
};
cancel.addActionListener(cancelAction);
// Key bindings:
ActionMap am = main.getActionMap();
InputMap im = main.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
im.put(GUIGlobals.exitDialog, "close");
am.put("close", cancelAction);
// Layout starts here.
main.setLayout(gbl);
opt.setLayout(gbl);
main.setBorder(BorderFactory.createTitledBorder
(BorderFactory.createEtchedBorder(),
"Group properties"));
// Main panel:
con.weightx = 0;
con.gridwidth = 1;
con.insets = new Insets(3, 5, 3, 5);
con.anchor = GridBagConstraints.EAST;
con.fill = GridBagConstraints.NONE;
con.gridx = 0;
con.gridy = 0;
gbl.setConstraints(nl, con);
main.add(nl);
con.gridy = 1;
gbl.setConstraints(nr, con);
main.add(nr);
con.gridy = 2;
gbl.setConstraints(nf, con);
main.add(nf);
con.weightx = 1;
con.anchor = GridBagConstraints.WEST;
con.fill = GridBagConstraints.HORIZONTAL;
con.gridy = 0;
con.gridx = 1;
gbl.setConstraints(name, con);
main.add(name);
con.gridy = 1;
gbl.setConstraints(regexp, con);
main.add(regexp);
con.gridy = 2;
gbl.setConstraints(field, con);
main.add(field);
// Option buttons:
con.gridx = GridBagConstraints.RELATIVE;
con.gridy = GridBagConstraints.RELATIVE;
con.weightx = 1;
con.gridwidth = 1;
con.anchor = GridBagConstraints.EAST;
con.fill = GridBagConstraints.NONE;
gbl.setConstraints(ok, con);
opt.add(ok);
con.anchor = GridBagConstraints.WEST;
con.gridwidth = GridBagConstraints.REMAINDER;
gbl.setConstraints(cancel, con);
opt.add(cancel);
getContentPane().add(main, BorderLayout.CENTER);
getContentPane().add(opt, BorderLayout.SOUTH);
//pack();
setSize(400, 170);
Util.placeDialog(this, parent);
}
|