Changeset 160 in josm
- Timestamp:
- 2006-10-13T21:49:10+02:00 (18 years ago)
- 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 10 10 import java.util.Collection; 11 11 import java.util.HashSet; 12 import java.util.Iterator;13 12 14 13 import javax.swing.JOptionPane; 15 14 16 15 import 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;20 16 import org.openstreetmap.josm.data.osm.Way; 21 17 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 22 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 23 import org.openstreetmap.josm.io.ObjectListDownloader; 18 import org.openstreetmap.josm.io.IncompleteDownloader; 24 19 import org.xml.sax.SAXException; 25 20 … … 39 34 */ 40 35 private final class DownloadTask extends PleaseWaitRunnable { 41 private ObjectListDownloader reader; 42 private DataSet dataSet; 43 private boolean nodesLoaded = false; 36 private IncompleteDownloader reader; 44 37 45 private DownloadTask(Collection< OsmPrimitive> toDownload) {38 private DownloadTask(Collection<Way> toDownload) { 46 39 super(trn("Downloading {0} segment", "Downloading {0} segments", toDownload.size(), toDownload.size())); 47 reader = new ObjectListDownloader(toDownload);40 reader = new IncompleteDownloader(toDownload); 48 41 } 49 42 50 43 @Override public void realRun() throws IOException, SAXException { 51 dataSet =reader.parse();44 reader.parse(); 52 45 } 53 46 54 47 @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(); 74 49 } 75 50 … … 85 60 public void actionPerformed(ActionEvent e) { 86 61 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) 90 64 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; 92 68 } 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)) 101 70 return; 102 PleaseWaitRunnable task = new DownloadTask( toDownload);71 PleaseWaitRunnable task = new DownloadTask(ways); 103 72 Main.worker.execute(task); 104 73 } -
src/org/openstreetmap/josm/actions/ExternalToolsAction.java
r153 r160 201 201 } 202 202 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); 204 204 } 205 205 -
src/org/openstreetmap/josm/actions/OpenAction.java
r138 r160 69 69 DataSet dataSet; 70 70 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); 72 72 } else if (ExtensionFileFilter.filters[ExtensionFileFilter.CSV].acceptName(fn)) { 73 73 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 11 11 import org.openstreetmap.josm.actions.AlignInCircleAction; 12 12 import org.openstreetmap.josm.actions.DownloadAction; 13 import org.openstreetmap.josm.actions.DownloadIncompleteAction; 13 14 import org.openstreetmap.josm.actions.ExitAction; 14 15 import org.openstreetmap.josm.actions.ExternalToolsAction; … … 55 56 public final JMenu fileMenu = new JMenu(tr("Files")); 56 57 public final JMenu connectionMenu = new JMenu(tr("Connection")); 58 private DownloadIncompleteAction downloadIncomplete = new DownloadIncompleteAction(); 57 59 58 60 … … 80 82 connectionMenu.setMnemonic('C'); 81 83 connectionMenu.add(download); 82 //connectionMenu.add(new DownloadIncompleteAction());84 connectionMenu.add(downloadIncomplete); 83 85 connectionMenu.add(upload); 84 86 add(connectionMenu); -
src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
r155 r160 72 72 try { 73 73 URLConnection con = url.openConnection(); 74 InputStream in = new ProgressInputStream(con); 74 InputStream in = new ProgressInputStream(con, Main.pleaseWaitDlg); 75 75 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading...")); 76 76 Map<Long, String> ids = idReader.parseIds(in); -
src/org/openstreetmap/josm/io/BoundingBoxDownloader.java
r153 r160 44 44 for (int i = 0;;++i) { 45 45 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); 47 47 if (in == null) 48 48 break; … … 84 84 public DataSet parseOsm() throws SAXException, IOException { 85 85 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); 87 87 if (in == null) 88 88 return null; 89 89 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); 91 91 in.close(); 92 92 activeConnection = null; -
src/org/openstreetmap/josm/io/OsmReader.java
r153 r160 13 13 import java.util.Map.Entry; 14 14 15 import javax.swing.BoundedRangeModel;16 import javax.swing.JLabel;17 15 18 16 import org.openstreetmap.josm.data.coor.LatLon; … … 24 22 import org.openstreetmap.josm.data.osm.visitor.AddVisitor; 25 23 import org.openstreetmap.josm.data.osm.visitor.Visitor; 24 import org.openstreetmap.josm.gui.PleaseWaitDialog; 26 25 import org.openstreetmap.josm.tools.DateParser; 27 26 import org.xml.sax.Attributes; … … 43 42 */ 44 43 public 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; 45 50 46 51 /** … … 168 173 private void createSegments() { 169 174 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]); 172 177 if (from == null || to == null) 173 178 continue; //TODO: implement support for incomplete nodes. … … 179 184 } 180 185 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 181 206 private void createWays() { 182 207 for (Entry<OsmPrimitiveData, Collection<Long>> e : ways.entrySet()) { 183 208 Way w = new Way(); 184 209 for (long id : e.getValue()) { 185 Segment s = segments.get(id);210 Segment s = findSegment(id); 186 211 if (s == null) { 187 212 s = new Segment(id); // incomplete line segment … … 202 227 /** 203 228 * 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 { 206 232 OsmReader osm = new OsmReader(); 233 osm.references = ref; 207 234 208 235 // phase 1: Parse nodes and read in raw segments and ways 209 236 osm.new Parser().parse(new InputStreamReader(source, "UTF-8")); 210 if (p rogress!= 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 } 214 241 for (Node n : osm.nodes.values()) 215 242 osm.adder.visit(n); -
src/org/openstreetmap/josm/io/OsmServerReader.java
r153 r160 7 7 8 8 import org.openstreetmap.josm.Main; 9 import org.openstreetmap.josm.gui.PleaseWaitDialog; 9 10 10 11 /** … … 20 21 * @return An reader reading the input stream (servers answer) or <code>null</code>. 21 22 */ 22 protected InputStream getInputStream(String urlStr) throws IOException { 23 protected InputStream getInputStream(String urlStr, PleaseWaitDialog pleaseWaitDlg) throws IOException { 23 24 urlStr = Main.pref.get("osm-server.url")+"/0.3/" + urlStr; 24 25 System.out.println("download: "+urlStr); … … 30 31 if (isAuthCancelled() && activeConnection.getResponseCode() == 401) 31 32 return null; 32 return new ProgressInputStream(activeConnection); 33 return new ProgressInputStream(activeConnection, pleaseWaitDlg); 33 34 } 34 35 } -
src/org/openstreetmap/josm/io/ProgressInputStream.java
r153 r160 5 5 import java.net.URLConnection; 6 6 7 import org.openstreetmap.josm. Main;7 import org.openstreetmap.josm.gui.PleaseWaitDialog; 8 8 9 9 /** … … 17 17 private int lastDialogUpdate = 0; 18 18 private final URLConnection connection; 19 private PleaseWaitDialog pleaseWaitDlg; 19 20 20 public ProgressInputStream(URLConnection con) throws IOException { 21 public ProgressInputStream(URLConnection con, PleaseWaitDialog pleaseWaitDlg) throws IOException { 21 22 this.connection = con; 22 23 this.in = con.getInputStream(); 23 24 int contentLength = con.getContentLength(); 25 this.pleaseWaitDlg = pleaseWaitDlg; 26 if (pleaseWaitDlg == null) 27 return; 24 28 if (contentLength > 0) 25 Main.pleaseWaitDlg.progress.setMaximum(contentLength);29 pleaseWaitDlg.progress.setMaximum(contentLength); 26 30 else 27 Main.pleaseWaitDlg.progress.setMaximum(0);28 Main.pleaseWaitDlg.progress.setValue(0);31 pleaseWaitDlg.progress.setMaximum(0); 32 pleaseWaitDlg.progress.setValue(0); 29 33 } 30 34 … … 52 56 */ 53 57 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()); 56 63 57 64 readSoFar += amount; … … 60 67 lastDialogUpdate++; 61 68 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); 64 71 65 String cur = Main.pleaseWaitDlg.currentAction.getText();72 String cur = pleaseWaitDlg.currentAction.getText(); 66 73 int i = cur.indexOf(' '); 67 74 if (i != -1) … … 69 76 else 70 77 cur += progStr; 71 Main.pleaseWaitDlg.currentAction.setText(cur);78 pleaseWaitDlg.currentAction.setText(cur); 72 79 } 73 80 } -
src/org/openstreetmap/josm/tools/SearchCompiler.java
r142 r160 120 120 } 121 121 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 122 129 public static Match compile(String searchStr) { 123 130 return new SearchCompiler().parse(new PushbackReader(new StringReader(searchStr))); … … 195 202 if (value.equals("modified")) 196 203 c = new Modified(); 204 else if (value.equals("incomplete")) 205 c = new Incomplete(); 197 206 else 198 207 c = new Any(value); 199 if (notValue) 200 return new Not(c); 201 return c; 208 return notValue ? new Not(c) : c; 202 209 } 203 210 Match c;
Note:
See TracChangeset
for help on using the changeset viewer.