/** Show the filter dialog */
 public void showDialog() {
   empty_border = new EmptyBorder(5, 5, 0, 5);
   indent_border = new EmptyBorder(5, 25, 5, 5);
   include_panel =
       new ServiceFilterPanel("Include messages based on target service:", filter_include_list);
   exclude_panel =
       new ServiceFilterPanel("Exclude messages based on target service:", filter_exclude_list);
   status_box = new JCheckBox("Filter messages based on status:");
   status_box.addActionListener(this);
   status_active = new JRadioButton("Active messages only");
   status_active.setSelected(true);
   status_active.setEnabled(false);
   status_complete = new JRadioButton("Complete messages only");
   status_complete.setEnabled(false);
   status_group = new ButtonGroup();
   status_group.add(status_active);
   status_group.add(status_complete);
   if (filter_active || filter_complete) {
     status_box.setSelected(true);
     status_active.setEnabled(true);
     status_complete.setEnabled(true);
     if (filter_complete) {
       status_complete.setSelected(true);
     }
   }
   status_options = new JPanel();
   status_options.setLayout(new BoxLayout(status_options, BoxLayout.Y_AXIS));
   status_options.add(status_active);
   status_options.add(status_complete);
   status_options.setBorder(indent_border);
   status_panel = new JPanel();
   status_panel.setLayout(new BorderLayout());
   status_panel.add(status_box, BorderLayout.NORTH);
   status_panel.add(status_options, BorderLayout.CENTER);
   status_panel.setBorder(empty_border);
   ok_button = new JButton("Ok");
   ok_button.addActionListener(this);
   cancel_button = new JButton("Cancel");
   cancel_button.addActionListener(this);
   buttons = new JPanel();
   buttons.setLayout(new FlowLayout());
   buttons.add(ok_button);
   buttons.add(cancel_button);
   panel = new JPanel();
   panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
   panel.add(include_panel);
   panel.add(exclude_panel);
   panel.add(status_panel);
   panel.add(buttons);
   dialog = new JDialog();
   dialog.setTitle("SOAP Monitor Filter");
   dialog.setContentPane(panel);
   dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
   dialog.setModal(true);
   dialog.pack();
   Dimension d = dialog.getToolkit().getScreenSize();
   dialog.setLocation((d.width - dialog.getWidth()) / 2, (d.height - dialog.getHeight()) / 2);
   ok_pressed = false;
   dialog.show();
 }
  /**
   * Creates a new <code>AddPersonDialog</code> with a given owner <code>JFrame</code> and <code>
   * FamilyTree</code>.
   */
  public AddPersonDialog(JFrame owner, FamilyTree tree) {
    super(owner, "Add New Person", true /* modal */);

    Container pane = this.getContentPane();
    pane.setLayout(new BorderLayout());

    JPanel infoPanel = new JPanel();
    infoPanel.setLayout(new GridLayout(0, 2));
    Border infoBorder = BorderFactory.createEmptyBorder(5, 5, 5, 5);
    infoPanel.setBorder(infoBorder);

    infoPanel.add(new JLabel("id:"));
    final JTextField idField = new JTextField();
    infoPanel.add(idField);

    final ButtonGroup group = new ButtonGroup();

    final JRadioButton male = new JRadioButton("male", true);
    group.add(male);
    infoPanel.add(male);

    final JRadioButton female = new JRadioButton("female");
    group.add(female);
    infoPanel.add(female);

    infoPanel.add(new JLabel("First name:"));
    final JTextField firstNameField = new JTextField();
    infoPanel.add(firstNameField);

    infoPanel.add(new JLabel("Middle name:"));
    final JTextField middleNameField = new JTextField();
    infoPanel.add(middleNameField);

    infoPanel.add(new JLabel("Last name:"));
    final JTextField lastNameField = new JTextField();
    infoPanel.add(lastNameField);

    infoPanel.add(new JLabel("Date of Birth:"));
    final JTextField dobField = new JTextField();
    infoPanel.add(dobField);

    infoPanel.add(new JLabel("Date of Death:"));
    final JTextField dodField = new JTextField();
    infoPanel.add(dodField);

    infoPanel.add(new JLabel("Father:"));
    JPanel fatherPanel = new JPanel();
    fatherPanel.setLayout(new FlowLayout());
    final JTextField fatherText = new JTextField("Click to choose");
    fatherText.setEditable(false);
    fatherText.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            // Pop up a PersonChooseDialog, place name in TextField
            System.out.println("Clicked father");
          }
        });
    fatherPanel.add(fatherText);
    infoPanel.add(fatherPanel);

    infoPanel.add(new JLabel("Mother:"));
    JPanel motherPanel = new JPanel();
    motherPanel.setLayout(new FlowLayout());
    final JTextField motherText = new JTextField("Click to choose");
    motherText.setEditable(false);
    motherText.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            // Pop up a PersonChooseDialog, place name in TextField
            System.out.println("Clicked mother");
          }
        });
    motherPanel.add(motherText);
    infoPanel.add(motherPanel);

    pane.add(infoPanel, BorderLayout.NORTH);

    // "Add" and "Cancel" buttons
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
    buttonPanel.add(Box.createHorizontalGlue());

    JButton addButton = new JButton("Add");
    addButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // Create a new person based on the information entered in
            // this dialog
            int id = 0;
            try {
              id = Integer.parseInt(idField.getText());

            } catch (NumberFormatException ex) {
              error("Invalid id: " + idField.getText());
              return;
            }

            String text = null;

            text = dobField.getText();
            Date dob = null;
            if (text != null && !text.equals("")) {
              dob = parseDate(dobField.getText());
              if (dob == null) {
                // Parse error
                return;
              }
            }

            text = dodField.getText();
            Date dod = null;
            if (text != null && !text.equals("")) {
              dod = parseDate(dodField.getText());
              if (dod == null) {
                // Parse error
                return;
              }
            }

            Person.Gender gender;
            if (group.getSelection().equals(male)) {
              gender = Person.MALE;

            } else {
              gender = Person.FEMALE;
            }

            // Okay, everything parsed alright
            newPerson = new Person(id, gender);
            newPerson.setFirstName(firstNameField.getText());
            newPerson.setMiddleName(middleNameField.getText());
            newPerson.setLastName(lastNameField.getText());
            newPerson.setDateOfBirth(dob);
            newPerson.setDateOfDeath(dod);

            if (mother != null) {
              newPerson.setMother(mother);
            }

            if (father != null) {
              newPerson.setFather(father);
            }

            // We're all happy
            AddPersonDialog.this.dispose();
          }
        });
    buttonPanel.add(addButton);

    buttonPanel.add(Box.createHorizontalGlue());

    JButton cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // Read my lips, no new Person!

            AddPersonDialog.this.newPerson = null;

            AddPersonDialog.this.dispose();
          }
        });
    buttonPanel.add(cancelButton);

    buttonPanel.add(Box.createHorizontalGlue());

    pane.add(buttonPanel, BorderLayout.SOUTH);
  }
  /**
   * Set up the calendar panel with the basic layout and components. These are not date specific.
   */
  private void createCalendarComponents() {
    // The date panel will hold the calendar and/or the time spinner

    JPanel datePanel = new JPanel(new BorderLayout(2, 2));

    // Create the calendar if we are displaying a calendar

    if ((selectedComponents & DISPLAY_DATE) > 0) {
      formatMonth = new SimpleDateFormat("MMM", locale);
      formatWeekDay = new SimpleDateFormat("EEE", locale);

      // Set up the shared keyboard bindings

      setInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap);
      setActionMap(actionMap);

      // Set up the decrement buttons

      yearDecrButton =
          new JButton(
              new ButtonAction(
                  "YearDecrButton",
                  "YearDecrButtonMnemonic",
                  "YearDecrButtonAccelerator",
                  "YearDecrButtonImage",
                  "YearDecrButtonShort",
                  "YearDecrButtonLong",
                  YEAR_DECR_BUTTON));
      monthDecrButton =
          new JButton(
              new ButtonAction(
                  "MonthDecrButton",
                  "MonthDecrButtonMnemonic",
                  "MonthDecrButtonAccelerator",
                  "MonthDecrButtonImage",
                  "MonthDecrButtonShort",
                  "MonthDecrButtonLong",
                  MONTH_DECR_BUTTON));
      JPanel decrPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 2, 0));
      decrPanel.add(yearDecrButton);
      decrPanel.add(monthDecrButton);

      // Set up the month/year label

      monthYearLabel = new JLabel();
      monthYearLabel.setHorizontalAlignment(JLabel.CENTER);

      // Set up the increment buttons

      monthIncrButton =
          new JButton(
              new ButtonAction(
                  "MonthIncrButton",
                  "MonthIncrButtonMnemonic",
                  "MonthIncrButtonAccelerator",
                  "MonthIncrButtonImage",
                  "MonthIncrButtonShort",
                  "MonthIncrButtonLong",
                  MONTH_INCR_BUTTON));
      yearIncrButton =
          new JButton(
              new ButtonAction(
                  "YearIncrButton",
                  "YearIncrButtonMnemonic",
                  "YearIncrButtonAccelerator",
                  "YearIncrButtonImage",
                  "YearIncrButtonShort",
                  "YearIncrButtonLong",
                  YEAR_INCR_BUTTON));
      JPanel incrPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 2, 0));
      incrPanel.add(monthIncrButton);
      incrPanel.add(yearIncrButton);

      // Put them all together

      JPanel monthYearNavigator = new JPanel(new BorderLayout(2, 2));
      monthYearNavigator.add(decrPanel, BorderLayout.WEST);
      monthYearNavigator.add(monthYearLabel);
      monthYearNavigator.add(incrPanel, BorderLayout.EAST);

      // Set up the day panel

      JPanel dayPanel = new JPanel(new GridLayout(7, 7));
      int firstDay = displayCalendar.getFirstDayOfWeek();

      // Get the week day labels. The following technique is used so
      // that we can start the calendar on the right day of the week and
      // we can get the week day labels properly localized

      Calendar temp = Calendar.getInstance(locale);
      temp.set(2000, Calendar.MARCH, 15);
      while (temp.get(Calendar.DAY_OF_WEEK) != firstDay) {
        temp.add(Calendar.DATE, 1);
      }
      dayOfWeekLabels = new JLabel[7];
      for (int i = 0; i < 7; i++) {
        Date date = temp.getTime();
        String dayOfWeek = formatWeekDay.format(date);
        dayOfWeekLabels[i] = new JLabel(dayOfWeek);
        dayOfWeekLabels[i].setHorizontalAlignment(JLabel.CENTER);
        dayPanel.add(dayOfWeekLabels[i]);
        temp.add(Calendar.DATE, 1);
      }

      // Add all the day buttons

      dayButtons = new JToggleButton[6][7];
      dayGroup = new ButtonGroup();
      DayListener dayListener = new DayListener();
      for (int row = 0; row < 6; row++) {
        for (int day = 0; day < 7; day++) {
          dayButtons[row][day] = new JToggleButton();
          dayButtons[row][day].addItemListener(dayListener);
          dayPanel.add(dayButtons[row][day]);
          dayGroup.add(dayButtons[row][day]);
        }
      }

      // We add this special button to the button group, so we have a
      // way of unselecting all the visible buttons

      offScreenButton = new JToggleButton("X");
      dayGroup.add(offScreenButton);

      // Combine the navigators and days

      datePanel.add(monthYearNavigator, BorderLayout.NORTH);
      datePanel.add(dayPanel);
    }

    // Create the time spinner field if we are displaying the time

    if ((selectedComponents & DISPLAY_TIME) > 0) {

      // Create the time component

      spinnerDateModel = new SpinnerDateModel();
      spinnerDateModel.addChangeListener(new TimeListener());
      spinner = new JSpinner(spinnerDateModel);

      JSpinner.DateEditor dateEditor = new JSpinner.DateEditor(spinner, timePattern);
      dateEditor.getTextField().setEditable(false);
      dateEditor.getTextField().setHorizontalAlignment(JTextField.CENTER);
      spinner.setEditor(dateEditor);

      // Set the input/action maps for the spinner. (Only BACK_SPACE
      // seems to work!)

      InputMap sim = new InputMap();
      sim.put(KeyStroke.getKeyStroke("BACK_SPACE"), "setNullDate");
      sim.put(KeyStroke.getKeyStroke("DELETE"), "setNullDate");
      sim.setParent(spinner.getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT));

      ActionMap sam = new ActionMap();
      sam.put(
          "setNullDate",
          new AbstractAction("setNullDate") {
            public void actionPerformed(ActionEvent e) {
              JCalendar.this.setDate(null);
            }
          });
      sam.setParent(spinner.getActionMap());

      spinner.setInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, sim);
      spinner.setActionMap(sam);

      // Create a special panel for the time display

      JPanel timePanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 2, 2));
      timePanel.add(spinner);

      // Now add it to the bottom

      datePanel.add(timePanel, BorderLayout.SOUTH);
    }

    setLayout(new BorderLayout(2, 2));
    add(datePanel);

    // Add today's date at the bottom of the calendar/time, if needed

    if (isTodayDisplayed) {
      Object[] args = {new Date()};
      String todaysDate = MessageFormat.format(bundle.getString("Today"), args);
      todaysLabel = new JLabel(todaysDate);
      todaysLabel.setHorizontalAlignment(JLabel.CENTER);

      // Add today's date at the very bottom

      add(todaysLabel, BorderLayout.SOUTH);
    }
  }
  public MainCitiesCriteriaPanel() {
    super(new BorderLayout());

    CountryController countryc = Application.getCountryController();
    CitiesController citiesc = Application.getCitiesController();
    countryName = Application.getCountryName();

    label = new JLabel();
    labelPanel = new JPanel();
    labelPanel.add(label);

    label.setText("Criteria to select main cities for " + countryName.replaceAll("_", " "));

    listModel = new DefaultListModel();

    Iterator<HashMap<String, String>> iter = citiesc.getToponymTypesIterator();
    while (iter.hasNext()) {
      String topTypeName = iter.next().get("code");
      listModel.addElement(topTypeName);
    }
    list = new JList(listModel);
    list.addListSelectionListener(this);
    listPanel = new JScrollPane(list);

    NumberFormat nCitiesFormat = NumberFormat.getInstance();
    nCitiesFormat.setMaximumFractionDigits(0);
    nCitiesFormat.setMaximumIntegerDigits(4);

    NumberFormat distFormat = NumberFormat.getInstance();
    distFormat.setMaximumFractionDigits(0);
    distFormat.setMaximumIntegerDigits(3);

    nCitiesField = new JFormattedTextField(nCitiesFormat);
    distField = new JFormattedTextField(distFormat);

    nCitiesField.setMaximumSize(new Dimension(50, 1));
    distField.setMaximumSize(new Dimension(50, 1));

    rb1 = new JRadioButton("Filter by type", true);
    rb2 = new JRadioButton("Filter by number", false);
    rb3 = new JRadioButton("Filter by distance to the borders (km)", false);

    ButtonGroup bgroup = new ButtonGroup();

    bgroup.add(rb1);
    bgroup.add(rb2);
    bgroup.add(rb3);

    JPanel radioPanel = new JPanel();

    radioPanel.setLayout(new BoxLayout(radioPanel, BoxLayout.Y_AXIS));
    radioPanel.add(rb1);
    radioPanel.add(listPanel);
    radioPanel.add(rb2);
    radioPanel.add(nCitiesField);
    radioPanel.add(rb3);
    radioPanel.add(distField);

    submit = new JButton();
    back = new JButton();

    submit.setText("OK");
    back.setText("GO BACK");
    submit.addActionListener(this);
    back.addActionListener(this);

    buttonPanel = new JPanel();
    buttonPanel.add(back);
    buttonPanel.add(submit);

    add(labelPanel, BorderLayout.NORTH);
    add(radioPanel, BorderLayout.CENTER);
    add(buttonPanel, BorderLayout.SOUTH);
  }