JFileChooser chooser = new JFileChooser(SocietyFinder.getInstance().getPath()); chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);  int result = chooser.showDialog(this, "OK"); if (result != JFileChooser.APPROVE_OPTION) return null; SocietyComponent sc = null; File file = chooser.getSelectedFile();  String name = ""; if (file.isDirectory()) { String[] filenames = SocietyFinder.getInstance().getAgentFilenames(file); name = (String)JOptionPane.showInputDialog(this, "Enter Society Name", "Society Name", JOptionPane.QUESTION_MESSAGE, null, null, name); if (name == null) return null; sc = helper.createSociety(name, filenames, SocietyFileComponent.class); } else { sc = helper.createSociety(file.getName(), SocietyFileComponent.class); name = file.getName(); if (name.endsWith(".ini")) name = name.substring(0, name.length()-4); } if (sc == null) return null;  while (societyNames.contains(name)) { name = societyNames.generateName(name); name = (String)JOptionPane.showInputDialog(this, "Enter Society Name", "Society Name Not Unique", JOptionPane.QUESTION_MESSAGE, null, null, name); if (name == null) return null; } societyNames.add(name); sc.setName(name);
SocietyComponent sc = newSocietyComponent();
  public DefaultMutableTreeNode newSociety() {    // display file chooser to allow user to select file that defines society    JFileChooser chooser =       new JFileChooser(SocietyFinder.getInstance().getPath());    chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);    //    int result = chooser.showOpenDialog(this);    int result = chooser.showDialog(this, "OK");    if (result != JFileChooser.APPROVE_OPTION)      return null;    SocietyComponent sc = null;    File file = chooser.getSelectedFile();    // create society from agent files or single node file    String name = "";    if (file.isDirectory()) {      String[] filenames =        SocietyFinder.getInstance().getAgentFilenames(file);      name =        (String)JOptionPane.showInputDialog(this, "Enter Society Name",                                            "Society Name",                                            JOptionPane.QUESTION_MESSAGE,                                            null, null, name);      if (name == null) return null;       sc = helper.createSociety(name, filenames, SocietyFileComponent.class);    } else {      sc = helper.createSociety(file.getName(), SocietyFileComponent.class);      name = file.getName();      if (name.endsWith(".ini"))        name = name.substring(0, name.length()-4);    }    if (sc == null)      return null;    // if name is not unique, then get an unique name for the society    while (societyNames.contains(name)) {      name = societyNames.generateName(name);      name =         (String)JOptionPane.showInputDialog(this, "Enter Society Name",                                            "Society Name Not Unique",                                            JOptionPane.QUESTION_MESSAGE,                                            null, null, name);      if (name == null) return null; // TODO: delete society to clean up    }    societyNames.add(name);    sc.setName(name);     DefaultMutableTreeNode newNode =       addSocietyToWorkspace(sc, getSelectedNode());    workspace.setSelection(newNode);    return newNode;  }