/** A class to render numbers in scientific format. */
  class ScientificRenderer extends JLabel implements TableCellRenderer {
    NumberFormat format = NumberFormat.getInstance();

    public ScientificRenderer(int sigfigs) {
      sigfigs = Math.min(sigfigs, 6);
      if (format instanceof DecimalFormat) {
        String pattern = "0.0"; // $NON-NLS-1$
        for (int i = 0; i < sigfigs - 1; i++) {
          pattern += "0"; // $NON-NLS-1$
        }
        pattern += "E0"; // $NON-NLS-1$
        ((DecimalFormat) format).applyPattern(pattern);
      }
    }

    public Component getTableCellRendererComponent(
        JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
      setFont(
          getDefaultRenderer(String.class)
              .getTableCellRendererComponent(DatasetStatisticsTable.this, "a", false, false, 0, 0)
              .getFont()); //$NON-NLS-1$
      setText(format.format(value));
      setHorizontalAlignment(SwingConstants.TRAILING);
      return this;
    }
  }
  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);
  }