private String getNewRefSysDescription() {
    int nr = 1;
    String name = Language.I18N.getString("pref.db.srs.label.newReferenceSystem");
    for (DatabaseSrs refSys : config.getProject().getDatabase().getReferenceSystems())
      if (refSys.getDescription().toLowerCase().startsWith(name.toLowerCase())) nr++;

    if (nr > 1) return name + " " + nr;
    else return name;
  }
  private boolean requestChange() {
    if (isModified()) {
      String text = Language.I18N.getString("pref.db.srs.apply.msg");
      Object[] args = new Object[] {srsComboBox.getSelectedItem().getDescription()};
      String formattedMsg = MessageFormat.format(text, args);

      int res =
          JOptionPane.showConfirmDialog(
              getTopLevelAncestor(),
              formattedMsg,
              Language.I18N.getString("pref.db.srs.apply.title"),
              JOptionPane.YES_NO_CANCEL_OPTION);
      if (res == JOptionPane.CANCEL_OPTION) return false;
      else if (res == JOptionPane.YES_OPTION) {
        setSettings();
      } else loadSettings();
    }

    return true;
  }
  private void exportReferenceSystems() {
    try {
      setSettings();

      if (config.getProject().getDatabase().getReferenceSystems().isEmpty()) {
        LOG.error("There are no user-defined reference systems to be exported.");
        return;
      }

      topFrame.clearConsole();
      topFrame.setStatusText(Language.I18N.getString("main.status.database.srs.export.label"));

      String fileName = fileText.getText().trim();
      if (fileName.length() == 0) {
        LOG.error("Please specify the export file for the reference systems.");
        topFrame.errorMessage(
            Language.I18N.getString("common.dialog.error.io.title"),
            Language.I18N.getString("pref.db.srs.error.write.msg"));
        return;
      }

      if ((!fileName.contains("."))) {
        fileName += ".xml";
        fileText.setText(fileName);
      }

      File file = new File(fileName);
      LOG.info("Writing reference systems to file '" + file.getAbsolutePath() + "'.");

      DatabaseSrsList refSys = new DatabaseSrsList();
      for (DatabaseSrs tmp : config.getProject().getDatabase().getReferenceSystems()) {
        DatabaseSrs copy = new DatabaseSrs(tmp);
        copy.setId(null);
        refSys.addItem(copy);

        LOG.info(
            "Writing reference system '"
                + tmp.getDescription()
                + "' (SRID: "
                + tmp.getSrid()
                + ").");
      }

      ConfigUtil.marshal(refSys, file, getJAXBContext());
      LOG.info("Reference systems successfully written to file '" + file.getAbsolutePath() + "'.");
    } catch (JAXBException jaxb) {
      String msg = jaxb.getMessage();
      if (msg == null && jaxb.getLinkedException() != null)
        msg = jaxb.getLinkedException().getMessage();

      LOG.error("Failed to write file: " + msg);
      topFrame.errorMessage(
          Language.I18N.getString("common.dialog.error.io.title"),
          MessageFormat.format(Language.I18N.getString("common.dialog.file.write.error"), msg));
    } finally {
      topFrame.setStatusText(Language.I18N.getString("main.status.ready.label"));
    }
  }
  private String getCopyOfDescription(DatabaseSrs refSys) {
    // pattern: "referenceSystemName - copy 1"
    // so to retrieve referenceSystem, " - copy*" has to be deleted...

    int nr = 0;
    String name =
        refSys
            .getDescription()
            .replaceAll(
                "\\s*-\\s*"
                    + Language.I18N.getString("pref.db.srs.label.copyReferenceSystem")
                    + ".*$",
                "");
    String copy = name + " - " + Language.I18N.getString("pref.db.srs.label.copyReferenceSystem");

    if (Language.I18N
        .getString("common.label.boundingBox.crs.sameAsInDB")
        .replaceAll(
            "\\s*-\\s*" + Language.I18N.getString("pref.db.srs.label.copyReferenceSystem") + ".*$",
            "")
        .toLowerCase()
        .equals(name.toLowerCase())) nr++;

    for (DatabaseSrs tmp : config.getProject().getDatabase().getReferenceSystems())
      if (tmp.getDescription()
          .replaceAll(
              "\\s*-\\s*"
                  + Language.I18N.getString("pref.db.srs.label.copyReferenceSystem")
                  + ".*$",
              "")
          .toLowerCase()
          .equals(name.toLowerCase())) nr++;

    if (nr > 1) return copy + " " + nr;
    else return copy;
  }
  private void importReferenceSystems(boolean replace) {
    try {
      topFrame.clearConsole();
      topFrame.setStatusText(Language.I18N.getString("main.status.database.srs.import.label"));

      File file = new File(fileText.getText().trim());
      String msg = "";

      if (replace) msg += "Replacing reference systems with those from file '";
      else msg += "Adding reference systems from file '";

      LOG.info(msg + file.getAbsolutePath() + "'.");

      if (!file.exists() || !file.isFile() || !file.canRead()) {
        LOG.error("Failed to open reference system file.");
        topFrame.errorMessage(
            Language.I18N.getString("common.dialog.error.io.title"),
            MessageFormat.format(
                Language.I18N.getString("common.dialog.file.read.error"),
                Language.I18N.getString("pref.db.srs.error.read.msg")));
        return;
      }

      Object object = ConfigUtil.unmarshal(file, getJAXBContext());
      if (object instanceof DatabaseSrsList) {
        DatabaseSrsList refSyss = (DatabaseSrsList) object;
        if (replace) config.getProject().getDatabase().getReferenceSystems().clear();

        if (dbPool.isConnected())
          LOG.info("Checking whether reference systems are supported by database profile.");

        for (DatabaseSrs refSys : refSyss.getItems()) {
          msg =
              "Adding reference system '"
                  + refSys.getDescription()
                  + "' (SRID: "
                  + refSys.getSrid()
                  + ").";

          if (dbPool.isConnected()) {
            try {
              dbPool.getActiveDatabaseAdapter().getUtil().getSrsInfo(refSys);
              if (!refSys.isSupported()) msg += " (NOT supported)";
              else msg += " (supported)";

            } catch (SQLException sqlEx) {
              LOG.error("Error while checking user-defined SRSs: " + sqlEx.getMessage().trim());
            }
          }

          config.getProject().getDatabase().getReferenceSystems().add(refSys);
          LOG.info(msg);
        }

        updateSrsComboBoxes(true);
        displaySelectedValues();

        LOG.info(
            "Reference systems successfully imported from file '" + file.getAbsolutePath() + "'.");
      } else
        LOG.error(
            "Could not find reference system definitions in file '"
                + file.getAbsolutePath()
                + "'.");

    } catch (JAXBException jaxb) {
      String msg = jaxb.getMessage();
      if (msg == null && jaxb.getLinkedException() != null)
        msg = jaxb.getLinkedException().getMessage();

      LOG.error("Failed to parse file: " + msg);
      topFrame.errorMessage(
          Language.I18N.getString("common.dialog.error.io.title"),
          MessageFormat.format(Language.I18N.getString("common.dialog.file.read.error"), msg));
    } catch (IOException e) {
      String msg = e.getMessage();
      LOG.error("Failed to access file: " + msg);
      topFrame.errorMessage(
          Language.I18N.getString("common.dialog.error.io.title"),
          MessageFormat.format(Language.I18N.getString("common.dialog.file.read.error"), msg));
    } finally {
      topFrame.setStatusText(Language.I18N.getString("main.status.ready.label"));
    }
  }
 @Override
 public String getTitle() {
   return Language.I18N.getString("pref.tree.db.srs");
 }
  @Override
  public void doTranslation() {
    ((TitledBorder) contentsPanel.getBorder())
        .setTitle(Language.I18N.getString("pref.db.srs.border.currentlySupported"));
    ((TitledBorder) impExpPanel.getBorder())
        .setTitle(Language.I18N.getString("pref.db.srs.border.impexp"));

    srsComboBoxLabel.setText(Language.I18N.getString("common.label.boundingBox.crs"));
    sridLabel.setText(Language.I18N.getString("pref.db.srs.label.srid"));
    srsNameLabel.setText(Language.I18N.getString("pref.db.srs.label.srsName"));
    descriptionLabel.setText(Language.I18N.getString("pref.db.srs.label.description"));
    dbSrsTypeLabel.setText(Language.I18N.getString("pref.db.srs.label.dbSrsType"));
    dbSrsNameLabel.setText(Language.I18N.getString("pref.db.srs.label.dbSrsName"));
    newButton.setText(Language.I18N.getString("pref.db.srs.button.new"));
    applyButton.setText(Language.I18N.getString("common.button.apply"));
    deleteButton.setText(Language.I18N.getString("pref.db.srs.button.delete"));
    copyButton.setText(Language.I18N.getString("pref.db.srs.button.copy"));
    checkButton.setText(Language.I18N.getString("pref.db.srs.button.check"));

    fileLabel.setText(Language.I18N.getString("pref.db.srs.label.file"));
    browseFileButton.setText(Language.I18N.getString("common.button.browse"));
    addFileButton.setText(Language.I18N.getString("pref.db.srs.button.addFile"));
    replaceWithFileButton.setText(Language.I18N.getString("pref.db.srs.button.replaceWithFile"));
    saveFileButton.setText(Language.I18N.getString("pref.db.srs.button.saveFile"));
  }