}
private void setupActions() {
wordList.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
wordEditField.setText((String)wordList.getSelectedValue());
wordEditField.selectAll();
new FocusRequester(wordEditField);
}
});
newWord.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
newWordAction();
}
});
wordEditFieldListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
int index = wordList.getSelectedIndex();
String old = (String)wordList.getSelectedValue(),
newVal = wordEditField.getText();
if (newVal.equals("") || newVal.equals(old))
return; // Empty string or no change.
int newIndex = findPos(wordListModel, newVal);
if (index >= 0) {
wordListModel.remove(index);
wordListModel.add((newIndex <= index ? newIndex : newIndex-1),
newVal);
} else
wordListModel.add(newIndex, newVal);
wordEditField.selectAll();
}
};
wordEditField.addActionListener(wordEditFieldListener);
removeWord.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int index = wordList.getSelectedIndex();
if (index == -1)
return;
wordListModel.remove(index);
wordEditField.setText("");
if (wordListModel.size() > 0)
wordList.setSelectedIndex(Math.min(index, wordListModel.size()-1));
}
});
fieldList.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
currentField = (String)fieldList.getSelectedValue();
fieldNameField.setText("");
setupWordSelector();
}