public void exit() {
   // save preferences
   DataExtractionSettings settings = DataExtractionSettings.getSettings();
   settings.saveDefaultLocation(mapPanel.getLatitude(), mapPanel.getLongitude());
   settings.saveDefaultZoom(mapPanel.getZoom());
   settings.saveWindowBounds(frame.getBounds());
   System.exit(0);
 }
  public JFileChooser getOsmFileChooser() {
    JFileChooser fc = new JFileChooser();
    fc.setDialogTitle(Messages.getString("OsmExtractionUI.CHOOSE_OSM_FILE")); // $NON-NLS-1$
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fc.setAcceptAllFileFilterUsed(true);
    fc.setCurrentDirectory(
        DataExtractionSettings.getSettings().getDefaultWorkingDir().getParentFile());
    fc.setFileFilter(
        new FileFilter() {

          @Override
          public boolean accept(File f) {
            return f.isDirectory()
                || f.getName().endsWith(".bz2")
                || f.getName().endsWith(".osm")
                || f.getName().endsWith(".pbf"); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
          }

          @Override
          public String getDescription() {
            return Messages.getString("OsmExtractionUI.OSM_FILES"); // $NON-NLS-1$
          }
        });
    return fc;
  }
  public void createUI() {
    frame = new JFrame(Messages.getString("OsmExtractionUI.OSMAND_MAP_CREATOR")); // $NON-NLS-1$
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
      log.error("Can't set look and feel", e); // $NON-NLS-1$
    }

    frame.addWindowListener(new ExitListener());
    Container content = frame.getContentPane();
    frame.setFocusable(true);

    mapPanel = new MapPanel(DataExtractionSettings.getSettings().getTilesDirectory());
    mapPanel.setFocusable(true);
    mapPanel.addMapLocationListener(this);

    statusBarLabel = new JLabel();
    content.add(statusBarLabel, BorderLayout.SOUTH);
    File workingDir = DataExtractionSettings.getSettings().getDefaultWorkingDir();
    statusBarLabel.setText(
        workingDir == null
            ? Messages.getString("OsmExtractionUI.WORKING_DIR_UNSPECIFIED")
            : Messages.getString("OsmExtractionUI.WORKING_DIRECTORY")
                + workingDir.getAbsolutePath()); // $NON-NLS-1$ //$NON-NLS-2$

    treePlaces = new JTree();
    treePlaces.setModel(
        new DefaultTreeModel(
            new DefaultMutableTreeNode(Messages.getString("OsmExtractionUI.REGION")),
            false)); //$NON-NLS-1$
    JSplitPane panelForTreeAndMap =
        new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(treePlaces), mapPanel);
    panelForTreeAndMap.setResizeWeight(0.2);
    content.add(panelForTreeAndMap, BorderLayout.CENTER);

    createButtonsBar(content);

    JMenuBar bar = new JMenuBar();
    fillMenuWithActions(bar);

    frame.setJMenuBar(bar);
  }
 private static void generateObf(String[] subArgsArray, IndexCreator ic)
     throws IOException, SQLException, InterruptedException, XmlPullParserException {
   String fn = DataExtractionSettings.getSettings().getMapRenderingTypesFile();
   String regionName = subArgsArray[0];
   MapRenderingTypesEncoder types = new MapRenderingTypesEncoder(fn, regionName);
   ic.generateIndexes(
       new File(subArgsArray[0]),
       new ConsoleProgressImplementation(),
       null,
       MapZooms.getDefault(),
       types,
       log);
 }
 public static String getUserLogDirectoryPath() {
   return DataExtractionSettings.getSettings().getDefaultWorkingDir().getAbsolutePath();
   //		String path = null;
   //		if (System.getProperty("os.name").startsWith("Windows")) {
   //			path = System.getenv("APPDATA").replaceAll("\\\\", "/");
   //		} else if (System.getProperty("os.name").startsWith("Mac")) {
   //			path = System.getProperty("user.home") + "/Library/Logs";
   //		} else if (System.getenv("XDG_CACHE_HOME") != null) {
   //			path = System.getenv("XDG_CACHE_HOME");
   //		} else {
   //			path = System.getProperty("user.home") + "/.cache";
   //		}
   //		return path;
 }
  public static void main(String[] args) {
    // first of all config log
    configLogFile();

    final UncaughtExceptionHandler defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
    Thread.setDefaultUncaughtExceptionHandler(
        new UncaughtExceptionHandler() {
          @Override
          public void uncaughtException(Thread t, Throwable e) {
            if (!(e instanceof ThreadDeath)) {
              ExceptionHandler.handle("Error in thread " + t.getName(), e); // $NON-NLS-1$
            }
            defaultHandler.uncaughtException(t, e);
          }
        });

    MAIN_APP = new OsmExtractionUI();
    MAIN_APP.frame.setBounds(DataExtractionSettings.getSettings().getWindowBounds());
    MAIN_APP.frame.setVisible(true);
  }
  private void createGeneralSection(JPanel root) {
    JPanel panel = new JPanel();
    //		panel.setLayout(new GridLayout(3, 1, 5, 5));
    GridBagLayout l = new GridBagLayout();
    panel.setLayout(l);
    panel.setBorder(
        BorderFactory.createTitledBorder(
            Messages.getString("OsmExtractionPreferencesDialog.GENERAL"))); // $NON-NLS-1$
    root.add(panel);

    useInternet = new JCheckBox();
    useInternet.setText(
        Messages.getString(
            "OsmExtractionPreferencesDialog.INTERNET.TO.DOWNLOAD.FILES")); //$NON-NLS-1$
    useInternet.setSelected(DataExtractionSettings.getSettings().useInternetToLoadImages());
    panel.add(useInternet);
    GridBagConstraints constr = new GridBagConstraints();
    constr.ipadx = 5;
    constr.gridx = 0;
    constr.gridy = 0;
    constr.gridwidth = 2;
    constr.anchor = GridBagConstraints.WEST;
    l.setConstraints(useInternet, constr);

    JLabel label = new JLabel("Path to obf files (test routing, comma separated) : ");
    panel.add(label);
    constr = new GridBagConstraints();
    constr.ipadx = 5;
    constr.gridx = 0;
    constr.gridy = 1;
    constr.anchor = GridBagConstraints.WEST;
    l.setConstraints(label, constr);

    pathToObfRoutingFile = new JTextField();

    pathToObfRoutingFile.setText(DataExtractionSettings.getSettings().getDefaultRoutingFilePath());
    panel.add(pathToObfRoutingFile);
    constr = new GridBagConstraints();
    constr.weightx = 1;
    constr.fill = GridBagConstraints.HORIZONTAL;
    constr.ipadx = 5;
    constr.gridx = 1;
    constr.gridy = 1;
    l.setConstraints(pathToObfRoutingFile, constr);

    label = new JLabel("City admin level : ");
    panel.add(label);
    constr = new GridBagConstraints();
    constr.ipadx = 5;
    constr.gridx = 0;
    constr.gridy = 2;
    constr.anchor = GridBagConstraints.WEST;
    l.setConstraints(label, constr);

    cityAdminLevel = new JTextField();

    cityAdminLevel.setText(DataExtractionSettings.getSettings().getCityAdminLevel());
    panel.add(cityAdminLevel);
    constr = new GridBagConstraints();
    constr.weightx = 1;
    constr.fill = GridBagConstraints.HORIZONTAL;
    constr.ipadx = 5;
    constr.gridx = 1;
    constr.gridy = 2;
    l.setConstraints(cityAdminLevel, constr);

    //		supressWarning = new JCheckBox();
    //		supressWarning.setText(Messages.getString("OsmExtractionPreferencesDialog.DUPLICATED.ID"));
    // //$NON-NLS-1$
    //
    //	supressWarning.setSelected(DataExtractionSettings.getSettings().isSupressWarningsForDuplicatedId());
    //		panel.add(supressWarning);
    //
    //		loadWholeOsmInfo = new JCheckBox();
    //
    //	loadWholeOsmInfo.setText(Messages.getString("OsmExtractionPreferencesDialog.LOAD.WHOLE.OSM")); //$NON-NLS-1$
    //		loadWholeOsmInfo.setSelected(DataExtractionSettings.getSettings().getLoadEntityInfo());
    //		panel.add(loadWholeOsmInfo);

    panel.setMaximumSize(new Dimension(Short.MAX_VALUE, panel.getPreferredSize().height));
  }
  public void saveProperties() {
    DataExtractionSettings settings = DataExtractionSettings.getSettings();
    if (!settings.getSuffixesToNormalizeStreetsString().equals(streetSuffixes.getText())) {
      settings.setSuffixesToNormalizeStreets(streetSuffixes.getText());
    }
    if (!settings
        .getDefaultSuffixesToNormalizeStreetsString()
        .equals(streetDefaultSuffixes.getText())) {
      settings.setDefaultSuffixesToNormalizeStreets(streetDefaultSuffixes.getText());
    }
    if (settings.useInternetToLoadImages() != useInternet.isSelected()) {
      settings.setUseInterentToLoadImages(useInternet.isSelected());
    }

    if (!settings.getLineSmoothness().equals(lineSmoothness.getText())) {
      settings.setLineSmoothness(lineSmoothness.getText());
    }
    if (!settings.getMapZoomsValue().equals(mapZooms.getText())) {
      settings.setMapZooms(mapZooms.getText());
    }
    if (!settings.getMapRenderingTypesFile().equals(renderingTypesFile.getText())) {
      settings.setMapRenderingTypesFile(renderingTypesFile.getText());
    }
    if (!settings.getDefaultRoutingFilePath().equals(pathToObfRoutingFile.getText())) {
      settings.setDefaultRoutingPath(pathToObfRoutingFile.getText());
    }
    if (!settings.getCityAdminLevel().equals(cityAdminLevel.getText())) {
      settings.setCityAdminLevel(cityAdminLevel.getText());
    }
    //		if(settings.isSupressWarningsForDuplicatedId() != supressWarning.isSelected()){
    //			settings.setSupressWarningsForDuplicatedId	(supressWarning.isSelected());
    //		}
    //		if(settings.getLoadEntityInfo() != loadWholeOsmInfo.isSelected()){
    //			settings.setLoadEntityInfo(loadWholeOsmInfo.isSelected());
    //		}

  }
  private void createNormalizingStreetSection(JPanel root) {
    JPanel panel = new JPanel();
    GridBagLayout l = new GridBagLayout();
    panel.setLayout(l);
    panel.setBorder(BorderFactory.createTitledBorder("Map creation parameters"));
    root.add(panel);

    JLabel label =
        new JLabel(
            Messages.getString("OsmExtractionPreferencesDialog.NAME.SUFFIXES")); // $NON-NLS-1$
    panel.add(label);
    GridBagConstraints constr = new GridBagConstraints();
    constr.anchor = GridBagConstraints.WEST;
    constr.ipadx = 5;
    constr.gridx = 0;
    constr.gridy = 0;
    l.setConstraints(label, constr);

    streetSuffixes = new JTextField();
    streetSuffixes.setText(
        DataExtractionSettings.getSettings().getSuffixesToNormalizeStreetsString());
    panel.add(streetSuffixes);
    constr = new GridBagConstraints();
    constr.fill = GridBagConstraints.HORIZONTAL;
    constr.ipadx = 5;
    constr.gridx = 1;
    constr.gridy = 0;
    l.setConstraints(streetSuffixes, constr);

    label =
        new JLabel(
            Messages.getString("OsmExtractionPreferencesDialog.DEFAULT.SUFFIXES")); // $NON-NLS-1$
    panel.add(label);
    constr = new GridBagConstraints();
    constr.ipadx = 5;
    constr.gridx = 0;
    constr.gridy = 1;
    constr.anchor = GridBagConstraints.WEST;
    l.setConstraints(label, constr);

    streetDefaultSuffixes = new JTextField();
    streetDefaultSuffixes.setText(
        DataExtractionSettings.getSettings().getDefaultSuffixesToNormalizeStreetsString());
    panel.add(streetDefaultSuffixes);
    constr = new GridBagConstraints();
    constr.weightx = 1;
    constr.fill = GridBagConstraints.HORIZONTAL;
    constr.ipadx = 5;
    constr.gridx = 1;
    constr.gridy = 1;
    l.setConstraints(streetDefaultSuffixes, constr);

    label =
        new JLabel(
            "Map zooms (specify zoom levels in binary map) example - "
                + MapZooms.MAP_ZOOMS_DEFAULT);
    panel.add(label);
    constr = new GridBagConstraints();
    constr.ipadx = 5;
    constr.gridx = 0;
    constr.gridy = 2;
    constr.anchor = GridBagConstraints.WEST;
    l.setConstraints(label, constr);

    mapZooms = new JTextField();
    mapZooms.setText(DataExtractionSettings.getSettings().getMapZoomsValue());
    panel.add(mapZooms);
    constr = new GridBagConstraints();
    constr.weightx = 1;
    constr.fill = GridBagConstraints.HORIZONTAL;
    constr.ipadx = 5;
    constr.gridx = 1;
    constr.gridy = 2;
    l.setConstraints(mapZooms, constr);

    label = new JLabel("Line smoothness for low zooms (value 0-3) : ");
    panel.add(label);
    constr = new GridBagConstraints();
    constr.ipadx = 5;
    constr.gridx = 0;
    constr.gridy = 3;
    constr.anchor = GridBagConstraints.WEST;
    l.setConstraints(label, constr);

    lineSmoothness = new JTextField();
    lineSmoothness.setText(DataExtractionSettings.getSettings().getLineSmoothness());
    panel.add(lineSmoothness);
    constr = new GridBagConstraints();
    constr.weightx = 1;
    constr.fill = GridBagConstraints.HORIZONTAL;
    constr.ipadx = 5;
    constr.gridx = 1;
    constr.gridy = 3;
    l.setConstraints(lineSmoothness, constr);

    label = new JLabel("Rendering types (xml config to extract osm data) file path");
    panel.add(label);
    constr = new GridBagConstraints();
    constr.ipadx = 5;
    constr.gridx = 0;
    constr.gridy = 4;
    constr.anchor = GridBagConstraints.WEST;
    l.setConstraints(label, constr);

    renderingTypesFile = new JTextField();
    renderingTypesFile.setText(DataExtractionSettings.getSettings().getMapRenderingTypesFile());
    panel.add(renderingTypesFile);
    constr = new GridBagConstraints();
    constr.weightx = 1;
    constr.fill = GridBagConstraints.HORIZONTAL;
    constr.ipadx = 5;
    constr.gridx = 1;
    constr.gridy = 4;
    l.setConstraints(renderingTypesFile, constr);

    panel.setMaximumSize(new Dimension(Short.MAX_VALUE, panel.getPreferredSize().height));
  }