Changeset 219 in josm
- Timestamp:
- 2007-04-25T00:37:21+02:00 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/io/IncompleteDownloader.java
r212 r219 10 10 import java.io.StringReader; 11 11 import java.util.Collection; 12 import java.util.ArrayList; 12 13 13 14 import org.openstreetmap.josm.Main; … … 19 20 import org.xml.sax.Attributes; 20 21 import org.xml.sax.SAXException; 22 23 import javax.swing.JOptionPane; 24 import org.openstreetmap.josm.command.ChangeCommand; 25 import org.openstreetmap.josm.command.Command; 26 import org.openstreetmap.josm.command.SequenceCommand; 21 27 22 28 import uk.co.wilson.xml.MinML2; … … 48 54 Main.pleaseWaitDlg.progress.setMaximum(toDownload.size()); 49 55 Main.pleaseWaitDlg.progress.setValue(0); 56 ArrayList<Command> cmds = new ArrayList<Command>(); 50 57 int i = 0; 51 58 try { 52 59 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); 54 66 Main.pleaseWaitDlg.progress.setValue(++i); 55 67 } … … 63 75 throw (e instanceof RuntimeException) ? (RuntimeException)e : new RuntimeException(e); 64 76 } 77 if (cmds.size() > 0) 78 Main.main.editLayer().add(new SequenceCommand(tr("Fix data errors"), cmds)); 65 79 } 66 80 … … 75 89 } 76 90 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 { 78 101 // get all the segments 102 Way newway = null; 79 103 for (Segment s : w.segments) { 80 104 if (!s.incomplete) 81 105 continue; 82 106 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 } 89 130 StringBuilder segBuilder = new StringBuilder(); 90 131 for (String line = segReader.readLine(); line != null; line = segReader.readLine()) … … 100 141 readSegment(segBuilder.toString()).visit(merger); 101 142 } 143 if( newway != null ) 144 return new ChangeCommand(w, newway); 145 return null; 102 146 } 103 147
Note:
See TracChangeset
for help on using the changeset viewer.