Changeset 1670 in josm for trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
- Timestamp:
- 2009-06-15T20:22:46+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r1646 r1670 51 51 import org.openstreetmap.josm.data.osm.Node; 52 52 import org.openstreetmap.josm.data.osm.OsmPrimitive; 53 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 53 54 import org.openstreetmap.josm.data.osm.Relation; 54 55 import org.openstreetmap.josm.data.osm.Way; … … 77 78 public final int[] normal = new int[3]; 78 79 public final int[] deleted = new int[3]; 79 public final String[] names = {"node", "way", "relation"}; 80 public final String[] names = { 81 OsmPrimitiveType.NODE.getAPIName(), 82 OsmPrimitiveType.WAY.getAPIName(), 83 OsmPrimitiveType.RELATION.getAPIName() 84 }; 80 85 81 86 private void inc(final OsmPrimitive osm, final int i) { 82 87 normal[i]++; 83 if (osm.deleted) 88 if (osm.deleted) { 84 89 deleted[i]++; 90 } 85 91 } 86 92 … … 201 207 202 208 SimplePaintVisitor painter; 203 if (Main.pref.getBoolean("draw.wireframe")) 209 if (Main.pref.getBoolean("draw.wireframe")) { 204 210 painter = new SimplePaintVisitor(); 205 else211 } else { 206 212 painter = new MapPaintVisitor(); 213 } 207 214 painter.setGraphics(g); 208 215 painter.setNavigatableComponent(mv); … … 216 223 tool += undeletedSize(data.nodes)+" "+trn("node", "nodes", undeletedSize(data.nodes))+", "; 217 224 tool += undeletedSize(data.ways)+" "+trn("way", "ways", undeletedSize(data.ways)); 218 if (data.version != null) tool += ", " + tr("version {0}", data.version); 225 if (data.version != null) { 226 tool += ", " + tr("version {0}", data.version); 227 } 219 228 File f = getAssociatedFile(); 220 if (f != null) 229 if (f != null) { 221 230 tool = "<html>"+tool+"<br>"+f.getPath()+"</html>"; 231 } 222 232 return tool; 223 233 } 224 234 225 235 @Override public void mergeFrom(final Layer from) { 226 final MergeVisitor visitor = new MergeVisitor(data,((OsmDataLayer)from).data); 227 for (final OsmPrimitive osm : ((OsmDataLayer)from).data.allPrimitives()) { 228 // i++; 229 // if(i%100 == 0) { 230 // double perc = (((double)i) / ((double)max) * 100.0); 231 // System.out.format(" " + (int)perc + "%%"); 232 // } 236 mergeFrom(((OsmDataLayer)from).data); 237 } 238 239 /** 240 * merges the primitives in dataset <code>from</code> into the dataset of 241 * this layer 242 * 243 * @param from the source data set 244 */ 245 public void mergeFrom(final DataSet from) { 246 final MergeVisitor visitor = new MergeVisitor(data,from); 247 for (final OsmPrimitive osm : from.allPrimitives()) { 233 248 osm.visit(visitor); 234 249 } 235 250 visitor.fixReferences(); 236 // System.out.println("");237 251 238 252 Area a = data.getDataSourceArea(); 239 240 // copy the merged layer's data source info; 253 254 // copy the merged layer's data source info; 241 255 // only add source rectangles if they are not contained in the 242 256 // layer already. 243 for (DataSource src : ((OsmDataLayer)from).data.dataSources) {244 if (a == null || !a.contains(src.bounds.asRect())) 257 for (DataSource src : from.dataSources) { 258 if (a == null || !a.contains(src.bounds.asRect())) { 245 259 data.dataSources.add(src); 246 } 247 260 } 261 } 262 248 263 // copy the merged layer's API version, downgrade if required 249 264 if (data.version == null) { 250 data.version = ((OsmDataLayer)from).data.version;265 data.version = from.version; 251 266 } else { 252 if ("0.5".equals(data.version) ^ "0.5".equals( ((OsmDataLayer)from).data.version)) {253 System.err.println( "Warning: mixing 0.6 and 0.5 data results in version 0.5");267 if ("0.5".equals(data.version) ^ "0.5".equals(from.version)) { 268 System.err.println(tr("Warning: mixing 0.6 and 0.5 data results in version 0.5")); 254 269 data.version = "0.5"; 255 270 } … … 263 278 final ConflictDialog dlg = Main.map.conflictDialog; 264 279 dlg.add(visitor.conflicts); 265 JOptionPane.showMessageDialog(Main.parent,tr("There were conflicts during import."));266 if (!dlg.isVisible()) 280 JOptionPane.showMessageDialog(Main.parent,tr("There were {0} conflicts during import.", visitor.conflicts.size())); 281 if (!dlg.isVisible()) { 267 282 dlg.action.actionPerformed(new ActionEvent(this, 0, "")); 283 } 268 284 } 269 285 … … 274 290 @Override public void visitBoundingBox(final BoundingXYVisitor v) { 275 291 for (final Node n : data.nodes) 276 if (!n.deleted && !n.incomplete) 292 if (!n.deleted && !n.incomplete) { 277 293 v.visit(n); 294 } 278 295 } 279 296 … … 299 316 if (processed != null) { 300 317 final Set<OsmPrimitive> processedSet = new HashSet<OsmPrimitive>(processed); 301 for (final Iterator<Node> it = data.nodes.iterator(); it.hasNext();) 318 for (final Iterator<Node> it = data.nodes.iterator(); it.hasNext();) { 302 319 cleanIterator(it, processedSet); 303 for (final Iterator<Way> it = data.ways.iterator(); it.hasNext();) 320 } 321 for (final Iterator<Way> it = data.ways.iterator(); it.hasNext();) { 304 322 cleanIterator(it, processedSet); 305 for (final Iterator<Relation> it = data.relations.iterator(); it.hasNext();) 323 } 324 for (final Iterator<Relation> it = data.relations.iterator(); it.hasNext();) { 306 325 cleanIterator(it, processedSet); 326 } 307 327 } 308 328 … … 330 350 return; 331 351 osm.modified = false; 332 if (osm.deleted) 352 if (osm.deleted) { 333 353 it.remove(); 354 } 334 355 } 335 356 … … 342 363 return; 343 364 this.modified = modified; 344 for (final ModifiedChangedListener l : listenerModified) 365 for (final ModifiedChangedListener l : listenerModified) { 345 366 l.modifiedChanged(modified, this); 367 } 346 368 } 347 369 … … 352 374 int size = 0; 353 375 for (final OsmPrimitive osm : list) 354 if (!osm.deleted) 376 if (!osm.deleted) { 355 377 size++; 378 } 356 379 return size; 357 380 } … … 359 382 @Override public Object getInfoComponent() { 360 383 final DataCountVisitor counter = new DataCountVisitor(); 361 for (final OsmPrimitive osm : data.allPrimitives()) 384 for (final OsmPrimitive osm : data.allPrimitives()) { 362 385 osm.visit(counter); 386 } 363 387 final JPanel p = new JPanel(new GridBagLayout()); 364 388 p.add(new JLabel(tr("{0} consists of:", name)), GBC.eol()); 365 389 for (int i = 0; i < counter.normal.length; ++i) { 366 390 String s = counter.normal[i]+" "+trn(counter.names[i],counter.names[i]+"s",counter.normal[i]); 367 if (counter.deleted[i] > 0) 391 if (counter.deleted[i] > 0) { 368 392 s += tr(" ({0} deleted.)",counter.deleted[i]); 393 } 369 394 p.add(new JLabel(s, ImageProvider.get("data", counter.names[i]), JLabel.HORIZONTAL), GBC.eop().insets(15,0,0,0)); 370 395 } … … 375 400 376 401 @Override public Component[] getMenuEntries() { 377 if (Main.applet) {402 if (Main.applet) 378 403 return new Component[]{ 379 new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)), 380 new JMenuItem(new LayerListDialog.DeleteLayerAction(this)), 381 new JSeparator(), 382 new JMenuItem(new RenameLayerAction(getAssociatedFile(), this)), 383 new JSeparator(), 384 new JMenuItem(new LayerListPopup.InfoAction(this))}; 385 } 404 new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)), 405 new JMenuItem(new LayerListDialog.DeleteLayerAction(this)), 406 new JSeparator(), 407 new JMenuItem(new RenameLayerAction(getAssociatedFile(), this)), 408 new JSeparator(), 409 new JMenuItem(new LayerListPopup.InfoAction(this))}; 386 410 return new Component[]{ 387 411 new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)), … … 409 433 HashSet<Node> doneNodes = new HashSet<Node>(); 410 434 for (Way w : data.ways) { 411 if (w.incomplete || w.deleted) continue; 435 if (w.incomplete || w.deleted) { 436 continue; 437 } 412 438 GpxTrack trk = new GpxTrack(); 413 439 gpxData.tracks.add(trk); 414 440 415 if (w.get("name") != null) 441 if (w.get("name") != null) { 416 442 trk.attr.put("name", w.get("name")); 443 } 417 444 418 445 ArrayList<WayPoint> trkseg = null; … … 429 456 doneNodes.add(n); 430 457 } 431 WayPoint wpt = new WayPoint(n.getCoor()); 458 WayPoint wpt = new WayPoint(n.getCoor()); 432 459 if (!n.isTimestampEmpty()) 433 460 { … … 442 469 // records them? 443 470 for (Node n : data.nodes) { 444 if (n.incomplete || n.deleted || doneNodes.contains(n)) continue; 471 if (n.incomplete || n.deleted || doneNodes.contains(n)) { 472 continue; 473 } 445 474 WayPoint wpt = new WayPoint(n.getCoor()); 446 475 if (!n.isTimestampEmpty()) {
Note:
See TracChangeset
for help on using the changeset viewer.