Changeset 219 in josm for src/org/openstreetmap


Ignore:
Timestamp:
2007-04-25T00:37:21+02:00 (17 years ago)
Author:
framm
Message:

Give users the chance to delete segments from a way if they fail to download.
Patch submitted by Martijn van Oosterhout <kleptog@…>.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/io/IncompleteDownloader.java

    r212 r219  
    1010import java.io.StringReader;
    1111import java.util.Collection;
     12import java.util.ArrayList;
    1213
    1314import org.openstreetmap.josm.Main;
     
    1920import org.xml.sax.Attributes;
    2021import org.xml.sax.SAXException;
     22
     23import javax.swing.JOptionPane;
     24import org.openstreetmap.josm.command.ChangeCommand;
     25import org.openstreetmap.josm.command.Command;
     26import org.openstreetmap.josm.command.SequenceCommand;
    2127
    2228import uk.co.wilson.xml.MinML2;
     
    4854                Main.pleaseWaitDlg.progress.setMaximum(toDownload.size());
    4955                Main.pleaseWaitDlg.progress.setValue(0);
     56                ArrayList<Command> cmds = new ArrayList<Command>();
    5057                int i = 0;
    5158                try {
    5259                        for (Way w : toDownload) {
    53                                 download(w);
     60                                // if some of the way's segments fail to download and the user
     61                                // decides to delete them, the download method will return an
     62                                // "edit way" command.
     63                                Command cmd = download(w);
     64                                if (cmd != null)
     65                                        cmds.add(cmd);
    5466                                Main.pleaseWaitDlg.progress.setValue(++i);
    5567                        }
     
    6375                                throw (e instanceof RuntimeException) ? (RuntimeException)e : new RuntimeException(e);
    6476                }
     77                if (cmds.size() > 0)
     78                        Main.main.editLayer().add(new SequenceCommand(tr("Fix data errors"), cmds));
    6579        }
    6680
     
    7589        }
    7690
    77         private void download(Way w) throws IOException, SAXException {
     91        /**
     92         * Downloads all missing segments from the given way. If segments fail do download,
     93         * offers the user a chance to delete those segments from the way.
     94         *
     95         * @param w way to complete
     96         * @return an "edit way" command if the user decided to delete segments
     97         * @throws IOException
     98         * @throws SAXException
     99         */
     100        private Command download(Way w) throws IOException, SAXException {
    78101                // get all the segments
     102                Way newway = null;
    79103                for (Segment s : w.segments) {
    80104                        if (!s.incomplete)
    81105                                continue;
    82106                        BufferedReader segReader;
    83                     try {
    84                         segReader = new BufferedReader(new InputStreamReader(getInputStream("segment/"+s.id, null), "UTF-8"));
    85                 } catch (FileNotFoundException e) {
    86                         e.printStackTrace();
    87                         throw new IOException(tr("Data error: Segment {0} is deleted but part of Way {1}", s.id, w.id));
    88                 }
     107                        try {
     108                                segReader = new BufferedReader(new InputStreamReader(getInputStream("segment/"+s.id, null), "UTF-8"));
     109                        } catch (FileNotFoundException e) {
     110                                Object[] options = {"Delete", "Ignore", "Abort"};
     111                                int n = JOptionPane.showOptionDialog(Main.parent,
     112                                                tr("Segment {0} is deleted but part of Way {1}",s.id, w.id),
     113                                                tr("Data error"),
     114                                                JOptionPane.YES_NO_CANCEL_OPTION,
     115                                                JOptionPane.ERROR_MESSAGE,
     116                                                null, options, options[2]);
     117                                if (n == 0)
     118                                {
     119                                        if( newway == null )
     120                                                newway = new Way(w);
     121                                        newway.segments.remove(s);
     122                                }
     123                                else if (n == 2)
     124                                {
     125                                        e.printStackTrace();
     126                                        throw new IOException(tr("Data error: Segment {0} is deleted but part of Way {1}", s.id, w.id));
     127                                }
     128                                continue;
     129                        }
    89130                        StringBuilder segBuilder = new StringBuilder();
    90131                        for (String line = segReader.readLine(); line != null; line = segReader.readLine())
     
    100141                        readSegment(segBuilder.toString()).visit(merger);
    101142                }
     143                if( newway != null )
     144                        return new ChangeCommand(w, newway);
     145                return null;
    102146        }
    103147
Note: See TracChangeset for help on using the changeset viewer.