Changeset 27696 in osm for applications


Ignore:
Timestamp:
2012-02-02T22:33:52+01:00 (13 years ago)
Author:
bastik
Message:

move list of urls to the josm wiki

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/mirrored_download/src/mirrored_download/UrlSelectionDialog.java

    r27692 r27696  
    1010import java.awt.event.ActionEvent;
    1111import java.awt.event.ActionListener;
     12import java.io.BufferedReader;
    1213import java.io.File;
    1314import java.io.FileInputStream;
    1415import java.io.FileNotFoundException;
    1516import java.io.InputStream;
     17import java.io.InputStreamReader;
    1618import java.io.IOException;
    1719import java.text.DecimalFormat;
    1820import java.text.Format;
     21import java.util.ArrayList;
     22import java.util.Collection;
    1923import java.util.Collections;
    2024import java.util.Iterator;
     
    6064import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
    6165import org.openstreetmap.josm.io.GpxReader;
     66import org.openstreetmap.josm.io.MirroredInputStream;
     67import org.openstreetmap.josm.tools.Utils;
    6268
    6369import org.xml.sax.SAXException;
     
    7076
    7177  public UrlSelectionDialog() {
    72 
    7378    Frame frame = JOptionPane.getFrameForComponent(Main.parent);
    7479    jDialog = new JDialog(frame, tr("Select OSM mirror URL"), false);
     
    99104    cbSelectUrl.setEditable(true);
    100105
    101     cbSelectUrl.addItem("http://overpass.osm.rambler.ru/cgi/xapi?");
    102     cbSelectUrl.addItem("http://overpass-api.de/api/xapi?");
     106    for (String url: getURLs()) {
     107      cbSelectUrl.addItem(url);
     108    }
    103109
    104110    cbSelectUrl.setActionCommand("selectURL");
     
    116122    jDialog.pack();
    117123    jDialog.setLocationRelativeTo(frame);
     124  }
     125
     126  private Collection<String> getURLs() {
     127    // List can be edited at http://josm.openstreetmap.de/wiki/MirroredDownloadInfo
     128    String src = Main.pref.get("plugin.mirrored_download.url-src", "http://josm.openstreetmap.de/mirrored_download_info");
     129    Collection<String> urls = new ArrayList<String>();
     130    InputStream in = null;
     131    try {
     132      in = new MirroredInputStream(src, 24*60*60);
     133      BufferedReader reader = new BufferedReader(new InputStreamReader(in));
     134      String line = null;
     135      while ((line = reader.readLine()) != null) {
     136        line = line.trim();
     137        if (!line.equals("")) {
     138          urls.add(line);
     139        }
     140      }
     141    } catch (IOException e) {
     142      e.printStackTrace();
     143    }
     144    Utils.close(in);
     145    for (String url : Main.pref.getCollection("plugin.mirrored_download.custom-urls")) {
     146      urls.add(url);
     147    }
     148    return urls;
    118149  }
    119150
Note: See TracChangeset for help on using the changeset viewer.