Changeset 160 in josm


Ignore:
Timestamp:
2006-10-13T21:49:10+02:00 (18 years ago)
Author:
imi
Message:
  • added Incomplete Way Download
  • added search for incomplete ways to selection search (use "incomplete")
Location:
src/org/openstreetmap/josm
Files:
2 added
1 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/actions/DownloadIncompleteAction.java

    r153 r160  
    1010import java.util.Collection;
    1111import java.util.HashSet;
    12 import java.util.Iterator;
    1312
    1413import javax.swing.JOptionPane;
    1514
    1615import org.openstreetmap.josm.Main;
    17 import org.openstreetmap.josm.data.osm.DataSet;
    18 import org.openstreetmap.josm.data.osm.OsmPrimitive;
    19 import org.openstreetmap.josm.data.osm.Segment;
    2016import org.openstreetmap.josm.data.osm.Way;
    2117import org.openstreetmap.josm.gui.PleaseWaitRunnable;
    22 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    23 import org.openstreetmap.josm.io.ObjectListDownloader;
     18import org.openstreetmap.josm.io.IncompleteDownloader;
    2419import org.xml.sax.SAXException;
    2520
     
    3934         */
    4035        private final class DownloadTask extends PleaseWaitRunnable {
    41                 private ObjectListDownloader reader;
    42                 private DataSet dataSet;
    43                 private boolean nodesLoaded = false;
     36                private IncompleteDownloader reader;
    4437
    45                 private DownloadTask(Collection<OsmPrimitive> toDownload) {
     38                private DownloadTask(Collection<Way> toDownload) {
    4639                        super(trn("Downloading {0} segment", "Downloading {0} segments", toDownload.size(), toDownload.size()));
    47                         reader = new ObjectListDownloader(toDownload);
     40                        reader = new IncompleteDownloader(toDownload);
    4841                }
    4942
    5043                @Override public void realRun() throws IOException, SAXException {
    51                         dataSet = reader.parse();
     44                        reader.parse();
    5245                }
    5346
    5447                @Override protected void finish() {
    55                         if (dataSet == null)
    56                                 return; // user cancelled download or error occoured
    57                         if (dataSet.allPrimitives().isEmpty())
    58                                 errorMessage = tr("No data imported.");
    59                         if (errorMessage == null && nodesLoaded == false)
    60                                 startDownloadNodes();
    61                         else if (errorMessage == null)
    62                                 Main.main.addLayer(new OsmDataLayer(dataSet, tr("Data Layer"), null));
    63                 }
    64 
    65                 private void startDownloadNodes() {
    66                         Collection<OsmPrimitive> nodes = new HashSet<OsmPrimitive>();
    67                         for (Segment s : dataSet.segments) {
    68                                 nodes.add(s.from);
    69                                 nodes.add(s.to);
    70                         }
    71                         reader = new ObjectListDownloader(nodes);
    72                         nodesLoaded = true;
    73                         Main.worker.execute(this);
     48                        Main.parent.repaint();
    7449                }
    7550
     
    8560        public void actionPerformed(ActionEvent e) {
    8661                Collection<Way> ways = new HashSet<Way>();
    87                 boolean sel = false;
    88                 for (Way w : Main.ds.ways) {
    89                         if (w.isIncomplete())
     62                for (Way w : Main.ds.ways)
     63                        if (w.isIncomplete() && w.selected)
    9064                                ways.add(w);
    91                         sel = sel || w.selected;
     65                if (ways.isEmpty()) {
     66                        JOptionPane.showMessageDialog(Main.parent, tr("Please select an incomplete way."));
     67                        return;
    9268                }
    93                 if (sel)
    94                         for (Iterator<Way> it = ways.iterator(); it.hasNext();)
    95                                 if (!it.next().selected)
    96                                         it.remove();
    97                 Collection<OsmPrimitive> toDownload = new HashSet<OsmPrimitive>();
    98                 for (Way w : ways)
    99                         toDownload.addAll(w.segments);
    100                 if (JOptionPane.YES_OPTION != JOptionPane.showConfirmDialog(Main.parent, tr("Download {0} ways containing a total of {1} segments?", ways.size(), toDownload.size()), tr("Download?"), JOptionPane.YES_NO_OPTION))
     69                if (JOptionPane.YES_OPTION != JOptionPane.showConfirmDialog(Main.parent, tr("Download {0} incomplete ways?", ways.size()), tr("Download?"), JOptionPane.YES_NO_OPTION))
    10170                        return;
    102                 PleaseWaitRunnable task = new DownloadTask(toDownload);
     71                PleaseWaitRunnable task = new DownloadTask(ways);
    10372                Main.worker.execute(task);
    10473        }
  • src/org/openstreetmap/josm/actions/ExternalToolsAction.java

    r153 r160  
    201201                        }
    202202                        if (output != null)
    203                                 dataSet = OsmReader.parseDataSet(p.getInputStream(), Main.pleaseWaitDlg.currentAction, Main.pleaseWaitDlg.progress);
     203                                dataSet = OsmReader.parseDataSet(p.getInputStream(), Main.ds, Main.pleaseWaitDlg);
    204204                }
    205205
  • src/org/openstreetmap/josm/actions/OpenAction.java

    r138 r160  
    6969                                DataSet dataSet;
    7070                                if (ExtensionFileFilter.filters[ExtensionFileFilter.OSM].acceptName(fn)) {
    71                                         dataSet = OsmReader.parseDataSet(new FileInputStream(file), null, null);
     71                                        dataSet = OsmReader.parseDataSet(new FileInputStream(file), Main.ds, Main.pleaseWaitDlg);
    7272                                } else if (ExtensionFileFilter.filters[ExtensionFileFilter.CSV].acceptName(fn)) {
    7373                                        JOptionPane.showMessageDialog(Main.parent, fn+": "+tr("CSV Data import for non-GPS data is not implemented yet."));
  • src/org/openstreetmap/josm/gui/MainMenu.java

    r159 r160  
    1111import org.openstreetmap.josm.actions.AlignInCircleAction;
    1212import org.openstreetmap.josm.actions.DownloadAction;
     13import org.openstreetmap.josm.actions.DownloadIncompleteAction;
    1314import org.openstreetmap.josm.actions.ExitAction;
    1415import org.openstreetmap.josm.actions.ExternalToolsAction;
     
    5556        public final JMenu fileMenu = new JMenu(tr("Files"));
    5657        public final JMenu connectionMenu = new JMenu(tr("Connection"));
     58        private DownloadIncompleteAction downloadIncomplete = new DownloadIncompleteAction();
    5759
    5860
     
    8082                connectionMenu.setMnemonic('C');
    8183                connectionMenu.add(download);
    82                 //connectionMenu.add(new DownloadIncompleteAction());
     84                connectionMenu.add(downloadIncomplete);
    8385                connectionMenu.add(upload);
    8486                add(connectionMenu);
  • src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java

    r155 r160  
    7272                        try {
    7373                                URLConnection con = url.openConnection();
    74                                 InputStream in = new ProgressInputStream(con);
     74                                InputStream in = new ProgressInputStream(con, Main.pleaseWaitDlg);
    7575                                Main.pleaseWaitDlg.currentAction.setText(tr("Downloading..."));
    7676                                Map<Long, String> ids = idReader.parseIds(in);
  • src/org/openstreetmap/josm/io/BoundingBoxDownloader.java

    r153 r160  
    4444                for (int i = 0;;++i) {
    4545                        Main.pleaseWaitDlg.currentAction.setText(tr("Downloading points {0} to {1}...", i * 5000, ((i + 1) * 5000)));
    46                         InputStream in = getInputStream(url+i);
     46                        InputStream in = getInputStream(url+i, Main.pleaseWaitDlg);
    4747                        if (in == null)
    4848                                break;
     
    8484    public DataSet parseOsm() throws SAXException, IOException {
    8585        try {
    86                 final InputStream in = getInputStream("map?bbox="+lon1+","+lat1+","+lon2+","+lat2);
     86                final InputStream in = getInputStream("map?bbox="+lon1+","+lat1+","+lon2+","+lat2, Main.pleaseWaitDlg);
    8787                if (in == null)
    8888                        return null;
    8989                Main.pleaseWaitDlg.currentAction.setText(tr("Downloading OSM data..."));
    90                 final DataSet data = OsmReader.parseDataSet(in, Main.pleaseWaitDlg.currentAction, Main.pleaseWaitDlg.progress);
     90                final DataSet data = OsmReader.parseDataSet(in, Main.ds, Main.pleaseWaitDlg);
    9191                in.close();
    9292                activeConnection = null;
  • src/org/openstreetmap/josm/io/OsmReader.java

    r153 r160  
    1313import java.util.Map.Entry;
    1414
    15 import javax.swing.BoundedRangeModel;
    16 import javax.swing.JLabel;
    1715
    1816import org.openstreetmap.josm.data.coor.LatLon;
     
    2422import org.openstreetmap.josm.data.osm.visitor.AddVisitor;
    2523import org.openstreetmap.josm.data.osm.visitor.Visitor;
     24import org.openstreetmap.josm.gui.PleaseWaitDialog;
    2625import org.openstreetmap.josm.tools.DateParser;
    2726import org.xml.sax.Attributes;
     
    4342 */
    4443public class OsmReader {
     44
     45        /**
     46         * This is used as (readonly) source for finding missing references when not transferred in the
     47         * file.
     48         */
     49        private DataSet references;
    4550
    4651        /**
     
    168173        private void createSegments() {
    169174                for (Entry<OsmPrimitiveData, long[]> e : segs.entrySet()) {
    170                         Node from = nodes.get(e.getValue()[0]);
    171                         Node to = nodes.get(e.getValue()[1]);
     175                        Node from = findNode(e.getValue()[0]);
     176                        Node to = findNode(e.getValue()[1]);
    172177                        if (from == null || to == null)
    173178                                continue; //TODO: implement support for incomplete nodes.
     
    179184        }
    180185
     186        private Node findNode(long id) {
     187            Node n = nodes.get(id);
     188            if (n != null)
     189                return n;
     190            for (Node node : references.nodes)
     191                if (node.id == id)
     192                        return node;
     193            return null;
     194    }
     195
     196        private Segment findSegment(long id) {
     197                Segment s = segments.get(id);
     198                if (s != null)
     199                        return s;
     200                for (Segment seg : references.segments)
     201                        if (seg.id == id)
     202                                return seg;
     203                return null;
     204        }
     205
    181206        private void createWays() {
    182207                for (Entry<OsmPrimitiveData, Collection<Long>> e : ways.entrySet()) {
    183208                        Way w = new Way();
    184209                        for (long id : e.getValue()) {
    185                                 Segment s = segments.get(id);
     210                                Segment s = findSegment(id);
    186211                                if (s == null) {
    187212                                        s = new Segment(id); // incomplete line segment
     
    202227        /**
    203228         * Parse the given input source and return the dataset.
    204          */
    205         public static DataSet parseDataSet(InputStream source, JLabel currentAction, BoundedRangeModel progress) throws SAXException, IOException {
     229         * @param pleaseWaitDlg TODO
     230         */
     231        public static DataSet parseDataSet(InputStream source, DataSet ref, PleaseWaitDialog pleaseWaitDlg) throws SAXException, IOException {
    206232                OsmReader osm = new OsmReader();
     233                osm.references = ref;
    207234
    208235                // phase 1: Parse nodes and read in raw segments and ways
    209236                osm.new Parser().parse(new InputStreamReader(source, "UTF-8"));
    210                 if (progress != null)
    211                         progress.setValue(0);
    212                 if (currentAction != null)
    213                         currentAction.setText(tr("Preparing data..."));
     237                if (pleaseWaitDlg != null) {
     238                        pleaseWaitDlg.progress.setValue(0);
     239                        pleaseWaitDlg.currentAction.setText(tr("Preparing data..."));
     240                }
    214241                for (Node n : osm.nodes.values())
    215242                        osm.adder.visit(n);
  • src/org/openstreetmap/josm/io/OsmServerReader.java

    r153 r160  
    77
    88import org.openstreetmap.josm.Main;
     9import org.openstreetmap.josm.gui.PleaseWaitDialog;
    910
    1011/**
     
    2021         * @return An reader reading the input stream (servers answer) or <code>null</code>.
    2122         */
    22         protected InputStream getInputStream(String urlStr) throws IOException {
     23        protected InputStream getInputStream(String urlStr, PleaseWaitDialog pleaseWaitDlg) throws IOException {
    2324                urlStr = Main.pref.get("osm-server.url")+"/0.3/" + urlStr;
    2425                System.out.println("download: "+urlStr);
     
    3031                if (isAuthCancelled() && activeConnection.getResponseCode() == 401)
    3132                        return null;
    32                 return new ProgressInputStream(activeConnection);
     33                return new ProgressInputStream(activeConnection, pleaseWaitDlg);
    3334        }
    3435}
  • src/org/openstreetmap/josm/io/ProgressInputStream.java

    r153 r160  
    55import java.net.URLConnection;
    66
    7 import org.openstreetmap.josm.Main;
     7import org.openstreetmap.josm.gui.PleaseWaitDialog;
    88
    99/**
     
    1717        private int lastDialogUpdate = 0;
    1818        private final URLConnection connection;
     19        private PleaseWaitDialog pleaseWaitDlg;
    1920
    20         public ProgressInputStream(URLConnection con) throws IOException {
     21        public ProgressInputStream(URLConnection con, PleaseWaitDialog pleaseWaitDlg) throws IOException {
    2122                this.connection = con;
    2223                this.in = con.getInputStream();
    2324                int contentLength = con.getContentLength();
     25                this.pleaseWaitDlg = pleaseWaitDlg;
     26                if (pleaseWaitDlg == null)
     27                        return;
    2428                if (contentLength > 0)
    25                         Main.pleaseWaitDlg.progress.setMaximum(contentLength);
     29                        pleaseWaitDlg.progress.setMaximum(contentLength);
    2630                else
    27                         Main.pleaseWaitDlg.progress.setMaximum(0);
    28                 Main.pleaseWaitDlg.progress.setValue(0);
     31                        pleaseWaitDlg.progress.setMaximum(0);
     32                pleaseWaitDlg.progress.setValue(0);
    2933        }
    3034
     
    5256         */
    5357        private void advanceTicker(int amount) {
    54                 if (Main.pleaseWaitDlg.progress.getMaximum() == 0 && connection.getContentLength() != -1)
    55                         Main.pleaseWaitDlg.progress.setMaximum(connection.getContentLength());
     58                if (pleaseWaitDlg == null)
     59                        return;
     60
     61                if (pleaseWaitDlg.progress.getMaximum() == 0 && connection.getContentLength() != -1)
     62                        pleaseWaitDlg.progress.setMaximum(connection.getContentLength());
    5663
    5764                readSoFar += amount;
     
    6067                        lastDialogUpdate++;
    6168                        String progStr = " "+readSoFar/1024+"/";
    62                         progStr += (Main.pleaseWaitDlg.progress.getMaximum()==0) ? "??? KB" : (Main.pleaseWaitDlg.progress.getMaximum()/1024)+" KB";
    63                         Main.pleaseWaitDlg.progress.setValue(readSoFar);
     69                        progStr += (pleaseWaitDlg.progress.getMaximum()==0) ? "??? KB" : (pleaseWaitDlg.progress.getMaximum()/1024)+" KB";
     70                        pleaseWaitDlg.progress.setValue(readSoFar);
    6471
    65                         String cur = Main.pleaseWaitDlg.currentAction.getText();
     72                        String cur = pleaseWaitDlg.currentAction.getText();
    6673                        int i = cur.indexOf(' ');
    6774                        if (i != -1)
     
    6976                        else
    7077                                cur += progStr;
    71                         Main.pleaseWaitDlg.currentAction.setText(cur);
     78                        pleaseWaitDlg.currentAction.setText(cur);
    7279                }
    7380        }
  • src/org/openstreetmap/josm/tools/SearchCompiler.java

    r142 r160  
    120120        }
    121121
     122        private static class Incomplete extends Match {
     123                @Override public boolean match(OsmPrimitive osm) {
     124                        return osm instanceof Way && ((Way)osm).isIncomplete();
     125                }
     126                @Override public String toString() {return "modified";}
     127        }
     128       
    122129        public static Match compile(String searchStr) {
    123130                return new SearchCompiler().parse(new PushbackReader(new StringReader(searchStr)));
     
    195202                        if (value.equals("modified"))
    196203                                c = new Modified();
     204                        else if (value.equals("incomplete"))
     205                                c = new Incomplete();
    197206                        else
    198207                                c = new Any(value);
    199                         if (notValue)
    200                                 return new Not(c);
    201                         return c;
     208                        return notValue ? new Not(c) : c;
    202209                }
    203210                Match c;
Note: See TracChangeset for help on using the changeset viewer.