AliasBeanpublic class AliasBean extends JPanel
Fields Summary |
---|
protected Vector | aliVector | protected JList | aliJList | private JTextField | nameTF | private JTextField | addrTF |
Constructors Summary |
---|
public AliasBean()
aliVector = new Vector();
aliJList = new JList();
// XXX MUST FIX THIS
// aliJList.setSelectionMode(JList.SINGLE_SELECTION);
aliJList.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent evt) {
int i = aliJList.getSelectedIndex();
if (i<0) return;
Alias al = (Alias)aliVector.get(i);
nameTF.setText(al.getName());
addrTF.setText(al.getAddress());
}
});
setLayout(new BorderLayout());
add(BorderLayout.WEST, new JScrollPane(aliJList));
JPanel rightPanel = new JPanel();
add(BorderLayout.EAST, rightPanel);
rightPanel.setLayout(new GridLayout(0, 1));
JPanel buttons = new JPanel();
rightPanel.add(buttons);
buttons.setLayout(new GridLayout(0, 1, 15, 15));
JButton b;
buttons.add(b = new JButton("Set"));
b.setToolTipText("Add or Change an alias");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
int i = aliJList.getSelectedIndex();
if (i<0) {
// XXX error dialog??
return;
}
setAlias(i, nameTF.getText(), addrTF.getText());
}
});
buttons.add(b = new JButton("Delete"));
b.setToolTipText("Delete the selected alias");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
int i = aliJList.getSelectedIndex();
if (i<0) {
return;
}
deleteAlias(i);
}
});
buttons.add(b = new JButton("Apply"));
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
System.err.println("NOT WRITTEN YET");
}
});
JPanel fields = new JPanel();
rightPanel.add(fields);
fields.setLayout(new GridLayout(2,2));
fields.add(new JLabel("Name"));
fields.add(nameTF = new JTextField(10));
fields.add(new JLabel("Address"));
fields.add(addrTF = new JTextField(20));
|
Methods Summary |
---|
public void | addAlias(Alias a)Add an Alias
Alias al = findAlias(a.getName());
if (al == null) {
aliVector.addElement(a);
} else {
// aliVector.setElement(a); // XXX fuzzy
}
aliJList.setListData(aliVector);
| public void | addAlias(java.lang.String nn, java.lang.String addr)Add an alias, by its constituent parts
addAlias(new Alias(nn, addr));
| public void | deleteAlias(int i)
aliVector.removeElementAt(i);
aliJList.setListData(aliVector);
| public java.lang.String | expandAlias(java.lang.String ali)
Alias a = findAlias(ali);
if (a == null)
return null;
return a.getAddress();
| public Alias | findAlias(java.lang.String ali)
for (int i=0; i<aliVector.size(); i++) {
Alias a = (Alias)aliVector.get(i);
if (a.getName().equals(ali))
return a;
}
return null; // not found
| public void | setAlias(int n, java.lang.String nam, java.lang.String addr)Replace an Alias
// TODO find it, replace it, or add it.
aliVector.setElementAt(new Alias(nam, addr), n);
aliJList.setListData(aliVector);
|
|