Changeset 1146 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2008-12-19T14:43:36+01:00 (16 years ago)
Author:
framm
Message:
  • Added new "open location" option in the file menu which can be used to download OSM data from a given URL. Experimental feature, use with care.
Location:
trunk/src/org/openstreetmap/josm
Files:
3 added
1 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/Main.java

    r1138 r1146  
    484484        if (s.startsWith("file:")) {
    485485            try {
    486                 main.menu.open.openFile(new File(new URI(s)));
     486                main.menu.openFile.openFile(new File(new URI(s)));
    487487            } catch (URISyntaxException e) {
    488488                JOptionPane.showMessageDialog(Main.parent, tr("Ignoring malformed file url: \"{0}\"", s));
     
    501501        }
    502502
    503         main.menu.open.openFile(new File(s));
     503        main.menu.openFile.openFile(new File(s));
    504504    }
    505505
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java

    r1082 r1146  
    1616import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1717import org.openstreetmap.josm.io.BoundingBoxDownloader;
     18import org.openstreetmap.josm.io.OsmServerLocationReader;
     19import org.openstreetmap.josm.io.OsmServerReader;
    1820import org.openstreetmap.josm.data.Bounds;
    1921import org.openstreetmap.josm.data.coor.LatLon;
     
    3032
    3133        private static class Task extends PleaseWaitRunnable {
    32                 private BoundingBoxDownloader reader;
     34                private OsmServerReader reader;
    3335                private DataSet dataSet;
    3436                private boolean newLayer;
    3537
    36                 public Task(boolean newLayer, BoundingBoxDownloader reader) {
     38                public Task(boolean newLayer, OsmServerReader reader) {
    3739                        super(tr("Downloading data"));
    3840                        this.reader = reader;
     
    8385                Main.worker.execute(task);
    8486    }
     87   
     88    public void loadUrl(boolean new_layer, String url) {
     89        Task task = new Task(new_layer, new OsmServerLocationReader(url));
     90        Main.worker.execute(task);
     91    }
     92   
     93   
     94   
    8595
    8696        public JCheckBox getCheckBox() {
  • trunk/src/org/openstreetmap/josm/gui/MainApplet.java

    r1084 r1146  
    108108                m.remove(m.fileMenu);
    109109                m.editMenu.add(new UploadPreferencesAction());
    110                 m.open.setEnabled(false);
     110                m.openFile.setEnabled(false);
    111111                m.exit.setEnabled(false);
    112112                m.save.setEnabled(false);
  • trunk/src/org/openstreetmap/josm/gui/MainMenu.java

    r1130 r1146  
    2020import org.openstreetmap.josm.actions.AlignInCircleAction;
    2121import org.openstreetmap.josm.actions.AlignInLineAction;
     22import org.openstreetmap.josm.actions.OpenLocationAction;
    2223import org.openstreetmap.josm.actions.OrthogonalizeAction;
    2324import org.openstreetmap.josm.actions.AutoScaleAction;
     
    3637import org.openstreetmap.josm.actions.MergeNodesAction;
    3738import org.openstreetmap.josm.actions.NewAction;
    38 import org.openstreetmap.josm.actions.OpenAction;
     39import org.openstreetmap.josm.actions.OpenFileAction;
    3940import org.openstreetmap.josm.actions.PasteAction;
    4041import org.openstreetmap.josm.actions.PasteTagsAction;
     
    7677    /* File menu */
    7778    public final NewAction newAction = new NewAction();
    78     public final OpenAction open = new OpenAction();
     79    public final OpenFileAction openFile = new OpenFileAction();
     80    public final OpenLocationAction openLocation = new OpenLocationAction();
    7981    public final JosmAction save = new SaveAction(null);
    8082    public final JosmAction saveAs = new SaveAsAction(null);
     
    167169
    168170        add(fileMenu, newAction);
    169         add(fileMenu, open);
     171        add(fileMenu, openFile);
     172        add(fileMenu, openLocation);
    170173        fileMenu.addSeparator();
    171174        add(fileMenu, save);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/RelationEditor.java

    r1113 r1146  
    539539                }
    540540                if (download) {
    541                         OsmServerObjectReader reader = new OsmServerObjectReader();
     541                        OsmServerObjectReader reader = new OsmServerObjectReader(clone.id, OsmServerObjectReader.TYPE_REL, true);
    542542                        try {
    543                                 DataSet dataSet = reader.parseOsm(clone.id,
    544                                                 OsmServerObjectReader.TYPE_REL, true);
     543                                DataSet dataSet = reader.parseOsm();
    545544                                if (dataSet != null) {
    546545                                        final MergeVisitor visitor = new MergeVisitor(Main.main
  • trunk/src/org/openstreetmap/josm/io/OsmServerObjectReader.java

    r1071 r1146  
    1717    public final static  String TYPE_NODE = "node";
    1818
     19    long id;
     20    String type;
     21    boolean full;
     22   
     23    public OsmServerObjectReader(long id, String type, boolean full) {
     24        this.id = id;
     25        this.type = type;
     26        this.full = full;
     27    }
    1928    /**
    2029     * Method to download single objects from OSM server. ways, relations, nodes
     
    2635     * @throws IOException
    2736     */
    28     public DataSet parseOsm(long id, String type, boolean full) throws SAXException, IOException {
     37    public DataSet parseOsm() throws SAXException, IOException {
    2938        try {
    30 
    3139            Main.pleaseWaitDlg.progress.setValue(0);
    3240            Main.pleaseWaitDlg.currentAction.setText(tr("Contacting OSM Server..."));
  • trunk/src/org/openstreetmap/josm/io/OsmServerReader.java

    r1071 r1146  
    1313
    1414import org.openstreetmap.josm.Main;
     15import org.openstreetmap.josm.data.osm.DataSet;
    1516import org.openstreetmap.josm.gui.PleaseWaitDialog;
     17import org.xml.sax.SAXException;
    1618
    1719/**
     
    2426 * @author imi
    2527 */
    26 abstract class OsmServerReader extends OsmConnection {
     28public abstract class OsmServerReader extends OsmConnection {
    2729        /**
    2830         * Open a connection to the given url and return a reader on the input stream
     
    3537                String version = Main.pref.get("osm-server.version", "0.5");
    3638                urlStr = Main.pref.get("osm-server.url")+"/"+version+"/" + urlStr;
     39        return getInputStreamRaw(urlStr, pleaseWaitDlg);
     40    }
     41   
     42    protected InputStream getInputStreamRaw(String urlStr, PleaseWaitDialog pleaseWaitDlg) throws IOException {
     43       
    3744                System.out.println("download: "+urlStr);
    3845                initAuthentication();
     
    5057                if (isAuthCancelled() && activeConnection.getResponseCode() == 401)
    5158                        return null;
    52                 if( activeConnection.getResponseCode() == 500 )
     59                if (activeConnection.getResponseCode() == 500)
    5360                {
    5461                        throw new IOException(tr("Server returned internal error. Try a reduced area or retry after waiting some time."));
     
    6673                return inputStream;
    6774        }
     75   
     76    public abstract DataSet parseOsm() throws SAXException, IOException;
     77   
    6878}
Note: See TracChangeset for help on using the changeset viewer.