示例#1
0
 public void saveCountry(final File f, final OsmBaseStorage storage) {
   final OsmStorageWriter writer = new OsmStorageWriter();
   try {
     final ProgressDialog dlg =
         new ProgressDialog(
             frame, Messages.getString("OsmExtractionUI.SAVING_OSM_FILE")); // $NON-NLS-1$
     dlg.setRunnable(
         new Runnable() {
           @Override
           public void run() {
             try {
               OutputStream output = new FileOutputStream(f);
               try {
                 if (f.getName().endsWith(".bz2")) { // $NON-NLS-1$
                   output.write('B');
                   output.write('Z');
                   output = new CBZip2OutputStream(output);
                 }
                 writer.saveStorage(output, storage, null, false);
               } finally {
                 output.close();
               }
             } catch (IOException e) {
               throw new IllegalArgumentException(e);
             } catch (XMLStreamException e) {
               throw new IllegalArgumentException(e);
             }
           }
         });
     dlg.run();
   } catch (InterruptedException e1) {
     log.error("Interrupted", e1); // $NON-NLS-1$
   } catch (InvocationTargetException e1) {
     ExceptionHandler.handle("Log file is not found", e1.getCause()); // $NON-NLS-1$
   }
 }
示例#2
0
  public void loadCountry(final File f, final IOsmStorageFilter filter) {
    try {
      final ProgressDialog dlg =
          new ProgressDialog(
              frame, Messages.getString("OsmExtractionUI.LOADING_OSM_FILE")); // $NON-NLS-1$
      dlg.setRunnable(
          new Runnable() {

            @Override
            public void run() {
              File dir = DataExtractionSettings.getSettings().getDefaultWorkingDir();
              IndexCreator creator = new IndexCreator(dir);
              try {
                creator.setIndexAddress(buildAddressIndex.isSelected());
                creator.setIndexPOI(buildPoiIndex.isSelected());
                creator.setNormalizeStreets(normalizingStreets.isSelected());
                creator.setIndexTransport(buildTransportIndex.isSelected());
                creator.setIndexMap(buildMapIndex.isSelected());
                creator.setCityAdminLevel(DataExtractionSettings.getSettings().getCityAdminLevel());
                String fn = DataExtractionSettings.getSettings().getMapRenderingTypesFile();
                MapRenderingTypes types;
                if (fn == null || fn.length() == 0) {
                  types = MapRenderingTypes.getDefault();
                } else {
                  types = new MapRenderingTypes(fn);
                }
                RTree.clearCache();
                int smoothness = 0;
                try {
                  smoothness =
                      Integer.parseInt(DataExtractionSettings.getSettings().getLineSmoothness());
                } catch (NumberFormatException e) {
                }
                creator.setZoomWaySmothness(smoothness);
                creator.generateIndexes(
                    f,
                    dlg,
                    filter,
                    DataExtractionSettings.getSettings().getMapZooms(),
                    types,
                    null);
              } catch (IOException e) {
                throw new IllegalArgumentException(e);
              } catch (SAXException e) {
                throw new IllegalStateException(e);
              } catch (SQLException e) {
                throw new IllegalStateException(e);
              } catch (InterruptedException e) {
                throw new IllegalStateException(e);
              }
              regionName = creator.getRegionName();
              StringBuilder msg = new StringBuilder();
              msg.append(Messages.getString("OsmExtractionUI.INDEXES_FOR"))
                  .append(regionName)
                  .append(" : "); // $NON-NLS-1$ //$NON-NLS-2$
              boolean comma = false;
              if (buildMapIndex.isSelected()) {
                if (comma) msg.append(", "); // $NON-NLS-1$
                comma = true;
                msg.append(Messages.getString("OsmExtractionUI.MAP")); // $NON-NLS-1$
              }
              if (buildPoiIndex.isSelected()) {
                if (comma) msg.append(", "); // $NON-NLS-1$
                comma = true;
                msg.append(Messages.getString("OsmExtractionUI.POI")); // $NON-NLS-1$
              }
              if (buildAddressIndex.isSelected()) {
                if (comma) msg.append(", "); // $NON-NLS-1$
                comma = true;
                msg.append(Messages.getString("OsmExtractionUI.ADDRESS")); // $NON-NLS-1$
              }
              if (buildTransportIndex.isSelected()) {
                if (comma) msg.append(", "); // $NON-NLS-1$
                comma = true;
                msg.append(Messages.getString("OsmExtractionUI.TRANSPORT")); // $NON-NLS-1$
              }
              msg.append(
                  MessageFormat.format(
                      Messages.getString("OsmExtractionUI.WERE_SUCCESFULLY_CREATED"),
                      dir.getAbsolutePath())); // $NON-NLS-1$
              JOptionPane pane = new JOptionPane(msg);
              JDialog dialog =
                  pane.createDialog(
                      frame, Messages.getString("OsmExtractionUI.GENERATION_DATA")); // $NON-NLS-1$
              dialog.setVisible(true);
            }
          });

      dlg.run();
      frame.setTitle(
          Messages.getString("OsmExtractionUI.OSMAND_MAP_CREATOR_FILE")
              + f.getName()); // $NON-NLS-1$
    } catch (InterruptedException e1) {
      log.error("Interrupted", e1); // $NON-NLS-1$
    } catch (InvocationTargetException e1) {
      ExceptionHandler.handle("Exception during operation", e1.getCause()); // $NON-NLS-1$
    }
  }