/**
   * Adds a JLabel and three JRadioButton instances in a ButtonGroup to the given panel with a
   * GridBagLayout, and returns the buttons in an array.
   */
  private JRadioButton[] addRadioButtonTriplet(String labelText, JPanel panel) {
    GridBagConstraints labelConstraints = new GridBagConstraints();
    labelConstraints.anchor = GridBagConstraints.WEST;
    labelConstraints.insets = new Insets(2, 10, 2, 10);

    GridBagConstraints buttonConstraints = new GridBagConstraints();
    buttonConstraints.insets = labelConstraints.insets;

    GridBagConstraints lastGlueConstraints = new GridBagConstraints();
    lastGlueConstraints.gridwidth = GridBagConstraints.REMAINDER;
    lastGlueConstraints.weightx = 1.0;

    // Create the radio buttons.
    JRadioButton radioButton0 = new JRadioButton();
    JRadioButton radioButton1 = new JRadioButton();
    JRadioButton radioButton2 = new JRadioButton();

    // Put them in a button group.
    ButtonGroup buttonGroup = new ButtonGroup();
    buttonGroup.add(radioButton0);
    buttonGroup.add(radioButton1);
    buttonGroup.add(radioButton2);

    // Add the label and the buttons to the panel.
    panel.add(new JLabel(labelText), labelConstraints);
    panel.add(radioButton0, buttonConstraints);
    panel.add(radioButton1, buttonConstraints);
    panel.add(radioButton2, buttonConstraints);
    panel.add(Box.createGlue(), lastGlueConstraints);

    return new JRadioButton[] {radioButton0, radioButton1, radioButton2};
  }
  public ClassMemberSpecificationDialog(JDialog owner, boolean isField) {
    super(owner, true);
    setResizable(true);

    // Create some constraints that can be reused.
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.anchor = GridBagConstraints.WEST;
    constraints.insets = new Insets(1, 2, 1, 2);

    GridBagConstraints constraintsStretch = new GridBagConstraints();
    constraintsStretch.fill = GridBagConstraints.HORIZONTAL;
    constraintsStretch.weightx = 1.0;
    constraintsStretch.anchor = GridBagConstraints.WEST;
    constraintsStretch.insets = constraints.insets;

    GridBagConstraints constraintsLast = new GridBagConstraints();
    constraintsLast.gridwidth = GridBagConstraints.REMAINDER;
    constraintsLast.anchor = GridBagConstraints.WEST;
    constraintsLast.insets = constraints.insets;

    GridBagConstraints constraintsLastStretch = new GridBagConstraints();
    constraintsLastStretch.gridwidth = GridBagConstraints.REMAINDER;
    constraintsLastStretch.fill = GridBagConstraints.HORIZONTAL;
    constraintsLastStretch.weightx = 1.0;
    constraintsLastStretch.anchor = GridBagConstraints.WEST;
    constraintsLastStretch.insets = constraints.insets;

    GridBagConstraints panelConstraints = new GridBagConstraints();
    panelConstraints.gridwidth = GridBagConstraints.REMAINDER;
    panelConstraints.fill = GridBagConstraints.HORIZONTAL;
    panelConstraints.weightx = 1.0;
    panelConstraints.weighty = 0.0;
    panelConstraints.anchor = GridBagConstraints.NORTHWEST;
    panelConstraints.insets = constraints.insets;

    GridBagConstraints stretchPanelConstraints = new GridBagConstraints();
    stretchPanelConstraints.gridwidth = GridBagConstraints.REMAINDER;
    stretchPanelConstraints.fill = GridBagConstraints.BOTH;
    stretchPanelConstraints.weightx = 1.0;
    stretchPanelConstraints.weighty = 1.0;
    stretchPanelConstraints.anchor = GridBagConstraints.NORTHWEST;
    stretchPanelConstraints.insets = constraints.insets;

    GridBagConstraints labelConstraints = new GridBagConstraints();
    labelConstraints.anchor = GridBagConstraints.CENTER;
    labelConstraints.insets = new Insets(2, 10, 2, 10);

    GridBagConstraints lastLabelConstraints = new GridBagConstraints();
    lastLabelConstraints.gridwidth = GridBagConstraints.REMAINDER;
    lastLabelConstraints.anchor = GridBagConstraints.CENTER;
    lastLabelConstraints.insets = labelConstraints.insets;

    GridBagConstraints okButtonConstraints = new GridBagConstraints();
    okButtonConstraints.weightx = 1.0;
    okButtonConstraints.weighty = 1.0;
    okButtonConstraints.anchor = GridBagConstraints.SOUTHEAST;
    okButtonConstraints.insets = new Insets(4, 4, 8, 4);

    GridBagConstraints cancelButtonConstraints = new GridBagConstraints();
    cancelButtonConstraints.gridwidth = GridBagConstraints.REMAINDER;
    cancelButtonConstraints.weighty = 1.0;
    cancelButtonConstraints.anchor = GridBagConstraints.SOUTHEAST;
    cancelButtonConstraints.insets = okButtonConstraints.insets;

    GridBagLayout layout = new GridBagLayout();

    Border etchedBorder = BorderFactory.createEtchedBorder(EtchedBorder.RAISED);

    this.isField = isField;

    // Create the access panel.
    JPanel accessPanel = new JPanel(layout);
    accessPanel.setBorder(
        BorderFactory.createTitledBorder(etchedBorder, GUIResources.getMessage("access")));

    accessPanel.add(Box.createGlue(), labelConstraints);
    accessPanel.add(new JLabel(GUIResources.getMessage("required")), labelConstraints);
    accessPanel.add(new JLabel(GUIResources.getMessage("not")), labelConstraints);
    accessPanel.add(new JLabel(GUIResources.getMessage("dontCare")), labelConstraints);
    accessPanel.add(Box.createGlue(), constraintsLastStretch);

    publicRadioButtons = addRadioButtonTriplet("Public", accessPanel);
    privateRadioButtons = addRadioButtonTriplet("Private", accessPanel);
    protectedRadioButtons = addRadioButtonTriplet("Protected", accessPanel);
    staticRadioButtons = addRadioButtonTriplet("Static", accessPanel);
    finalRadioButtons = addRadioButtonTriplet("Final", accessPanel);

    if (isField) {
      volatileRadioButtons = addRadioButtonTriplet("Volatile", accessPanel);
      transientRadioButtons = addRadioButtonTriplet("Transient", accessPanel);
    } else {
      synchronizedRadioButtons = addRadioButtonTriplet("Synchronized", accessPanel);
      nativeRadioButtons = addRadioButtonTriplet("Native", accessPanel);
      abstractRadioButtons = addRadioButtonTriplet("Abstract", accessPanel);
      strictRadioButtons = addRadioButtonTriplet("Strict", accessPanel);
    }

    // Create the type panel.
    JPanel typePanel = new JPanel(layout);
    typePanel.setBorder(
        BorderFactory.createTitledBorder(
            etchedBorder, GUIResources.getMessage(isField ? "type" : "returnType")));

    typePanel.add(typeTextField, constraintsLastStretch);

    // Create the name panel.
    JPanel namePanel = new JPanel(layout);
    namePanel.setBorder(
        BorderFactory.createTitledBorder(etchedBorder, GUIResources.getMessage("name")));

    namePanel.add(nameTextField, constraintsLastStretch);

    // Create the arguments panel.
    JPanel argumentsPanel = new JPanel(layout);
    argumentsPanel.setBorder(
        BorderFactory.createTitledBorder(etchedBorder, GUIResources.getMessage("arguments")));

    argumentsPanel.add(argumentsTextField, constraintsLastStretch);

    // Create the Ok button.
    JButton okButton = new JButton(GUIResources.getMessage("ok"));
    okButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            returnValue = APPROVE_OPTION;
            hide();
          }
        });

    // Create the Cancel button.
    JButton cancelButton = new JButton(GUIResources.getMessage("cancel"));
    cancelButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            hide();
          }
        });

    // Add all panels to the main panel.
    JPanel mainPanel = new JPanel(layout);
    mainPanel.add(accessPanel, panelConstraints);
    mainPanel.add(typePanel, panelConstraints);
    mainPanel.add(namePanel, panelConstraints);

    if (!isField) {
      mainPanel.add(argumentsPanel, panelConstraints);
    }

    mainPanel.add(okButton, okButtonConstraints);
    mainPanel.add(cancelButton, cancelButtonConstraints);

    getContentPane().add(mainPanel);
  }