@Override
public void actionPerformed(ActionEvent e) {
Node node = yoshikoder.getSelectedNode();
YKDictionary dict = yoshikoder.getDictionary();
CategoryNode cnode = null;
if (node instanceof CategoryNode)
cnode = (CategoryNode)node;
else
cnode = (CategoryNode)node.getParent();
if (area == null){
area = new JTextArea(20,30);
area.setEditable(true);
area.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
area.setDropMode(DropMode.INSERT);
area.setLineWrap(true);
area.setWrapStyleWord(true);
} else {
area.setText("");
}
JScrollPane pane = new JScrollPane(area);
int resp = JOptionPane.showConfirmDialog(yoshikoder, pane, "Add patterns to " + cnode.getName(),
JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
if (resp != JOptionPane.OK_OPTION)
return;
String str = area.getText();
String[] spl = str.split("[^\\w]+");
List<String> errors = new ArrayList<String>();
for (int ii = 0; ii < spl.length; ii++) {
String newpat = spl[ii];
try {
dict.addPattern(spl[ii], null, cnode);
} catch (DuplicateException dex){
// quietly supress duplicates
} catch (Exception ex){
errors.add(spl[ii]);
}
}
yoshikoder.setSelectedNode(cnode);
if (errors.size() > 0){
StringBuffer sb = new StringBuffer();
sb.append("There were some problems adding the patterns:\n\n");
for (Iterator iterator = errors.iterator(); iterator.hasNext();) {
String string = (String) iterator.next();
sb.append(string);
sb.append(" ");
}
sb.append("\nThis is usually because " +
"a dictionary entry of the same name already exists.");
area.setText(sb.toString());
JOptionPane.showMessageDialog(yoshikoder, new JScrollPane(area), "Error adding patterns to " + cnode.getName(),
JOptionPane.PLAIN_MESSAGE);
}
}