addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { cancel_actionPerformed(); } });
  public CMTDialog(JFrame parent, Organizer organizer,                   String experimentName,                   String experimentId) {    super(parent, "Threads and Groups", true); // modal dialog    createLogger();    this.organizer = organizer; // to get unique names    this.experimentName = experimentName;    this.experimentId = experimentId;    this.trialId = ExperimentDB.getTrialId(experimentId);    JPanel panel = new JPanel(new BorderLayout());    // Panel for threads    JPanel bottomPanel = new JPanel(new GridBagLayout());    bottomPanel.setBorder(LineBorder.createGrayLineBorder());    int x = 0;    int y = 0;    int leftIndent = 0;    bottomPanel.add(new JLabel("Select Threads:"),              new GridBagConstraints(x, y++, 1, 1, 0.0, 0.0,                                     GridBagConstraints.WEST,                                     GridBagConstraints.NONE,                                     new Insets(0, leftIndent, 5, 0),                                     0, 0));    leftIndent = leftIndent + 5;    for (int i = 0; i < ULThreads.length; i++) {      JCheckBox cb = new JCheckBox(ULThreads[i]);      // Class 4 is disabled this year      if (ULThreads[i].indexOf('4') != -1)	cb.setEnabled(false);      //        if (DBUtils.isMySQL())//  	cb.setEnabled(false); // MySQL DB            ULThreadCheckBoxes.add(cb);      boolean sel = ExperimentDB.isULThreadSelected(trialId, ULDBThreads[i]);      cb.setSelected(sel);      originalThreadSelected.add(new Boolean(sel));            //if (i == (ULThreads.length-1))      //  cb.setEnabled(false); // spare parts      bottomPanel.add(cb,                      new GridBagConstraints(x, y++, 1, 1, 0.0, 0.0,                                             GridBagConstraints.WEST,                                             GridBagConstraints.NONE,                                             new Insets(0, leftIndent, 5, 0),                                             0, 0));    }    leftIndent = leftIndent - 5;    bottomPanel.add(new JLabel("Select Organization Groups:"),              new GridBagConstraints(x, y++, 1, 1, 0.0, 0.0,                                     GridBagConstraints.WEST,                                     GridBagConstraints.NONE,                                     new Insets(0, leftIndent, 0, 0),                                     0, 0));    leftIndent = leftIndent + 5;    Map groupNameToId = ExperimentDB.getOrganizationGroups(experimentId);    Set groups = groupNameToId.keySet();    groupNames = (String[])groups.toArray(new String[groups.size()]);    int nGroupNames = groupNames.length;    for (int i = 0; i < nGroupNames; i++) {      String groupName = (String)groupNames[i];      JCheckBox groupCB = new JCheckBox(groupName);      //        if (DBUtils.isMySQL())//  	groupCB.setEnabled(false); // MySQL DB            boolean sel = ExperimentDB.isGroupSelected(trialId, groupName);      groupCheckBoxes.add(groupCB);      originalGroupSelected.add(new Boolean(sel));      groupCB.setSelected(sel);      bottomPanel.add(groupCB,                new GridBagConstraints(x++, y, 1, 1, 0.0, 0.0,                                       GridBagConstraints.WEST,                                       GridBagConstraints.NONE,                                       new Insets(0, leftIndent, 5, 0),                                       0, 0));      bottomPanel.add(new JLabel("Number of Copies:"),                new GridBagConstraints(x++, y, 1, 1, 0.0, 0.0,                                       GridBagConstraints.WEST,                                       GridBagConstraints.NONE,                                       new Insets(0, 0, 5, 5),                                       0, 0));      JTextField multiplierField = new JTextField(4);      multiplierFields.add(multiplierField);      int multiplier = ExperimentDB.getMultiplier(trialId, groupName);      multiplierField.setText(String.valueOf(multiplier));      originalGroupMultiplier.add(new Integer(multiplier));      bottomPanel.add(multiplierField,                new GridBagConstraints(x++, y, 1, 1, 0.0, 0.0,                                       GridBagConstraints.WEST,                                       GridBagConstraints.NONE,                                       new Insets(0, 0, 5, 5),                                       0, 0));      bottomPanel.add(new JLabel("Members:"),                new GridBagConstraints(x++, y, 1, 1, 0.0, 0.0,                                       GridBagConstraints.WEST,                                       GridBagConstraints.NONE,                                       new Insets(0, 0, 5, 5),                                       0, 0));      Set members =         ExperimentDB.getOrganizationsInGroup(experimentId,                                          (String)groupNameToId.get(groupName));      JList membersList = new JList(members.toArray());      membersList.setVisibleRowCount(4);      bottomPanel.add(new JScrollPane(membersList),                new GridBagConstraints(x++, y++, 1, 1, 0.0, 0.0,                                       GridBagConstraints.WEST,                                       GridBagConstraints.NONE,                                       new Insets(0, 0, 5, 5),                                       0, 0));      x = 0;    }    leftIndent = leftIndent - 5;    bottomPanel.add(new JLabel("Society:"),              new GridBagConstraints(x, y++, 1, 1, 0.0, 0.0,                                     GridBagConstraints.WEST,                                     GridBagConstraints.NONE,                                     new Insets(0, leftIndent, 0, 0),                                     0, 0));    leftIndent = leftIndent + 5;    forceRecomputeBox = new JCheckBox("Force Recompute");    bottomPanel.add(forceRecomputeBox,                new GridBagConstraints(x, y+1, 1, 1, 0.0, 0.0,                                       GridBagConstraints.WEST,                                       GridBagConstraints.NONE,                                       new Insets(0, leftIndent, 5, 5),                                       0, 0));       panel.add(bottomPanel, BorderLayout.CENTER);    // Buttons panel    JPanel buttonPanel = new JPanel();    JButton okButton = new JButton("OK");    okButton.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        ok_actionPerformed();      }    });    JButton cancelButton = new JButton("Cancel");    cancelButton.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        cancel_actionPerformed();      }    });    buttonPanel.add(okButton);    buttonPanel.add(cancelButton);    panel.add(buttonPanel, BorderLayout.SOUTH);    getContentPane().add(panel);    pack();    // make dialog display over the middle of the caller's frame    Point p = parent.getLocation();    Dimension d = parent.getSize();    int centerX = p.x + d.width/2;    int centerY = p.y + d.height/2;    Dimension myD = getSize();    setLocation(new Point(centerX - myD.width/2, centerY - myD.height/2));    show();  }