source: josm/trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java@ 2433

Last change on this file since 2433 was 2433, checked in by Gubaer, 14 years ago

Improved test cases for MergeVisitor.
Moved MergeVisitor and removed Visitor-pattern. Double-dispatching isn't necessary and only slows down the merge process.

  • Property svn:eol-style set to native
File size: 26.4 KB
Line 
1// License: GPL. See LICENSE file for details.
2
3package org.openstreetmap.josm.gui.layer;
4
5import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
6import static org.openstreetmap.josm.tools.I18n.marktr;
7import static org.openstreetmap.josm.tools.I18n.tr;
8import static org.openstreetmap.josm.tools.I18n.trn;
9
10import java.awt.AlphaComposite;
11import java.awt.Color;
12import java.awt.Component;
13import java.awt.Composite;
14import java.awt.Graphics;
15import java.awt.Graphics2D;
16import java.awt.GridBagLayout;
17import java.awt.Point;
18import java.awt.Rectangle;
19import java.awt.TexturePaint;
20import java.awt.event.ActionEvent;
21import java.awt.geom.Area;
22import java.awt.image.BufferedImage;
23import java.io.File;
24import java.util.ArrayList;
25import java.util.Collection;
26import java.util.HashSet;
27import java.util.Iterator;
28import java.util.LinkedList;
29import java.util.Set;
30
31import javax.swing.AbstractAction;
32import javax.swing.Icon;
33import javax.swing.JLabel;
34import javax.swing.JMenuItem;
35import javax.swing.JOptionPane;
36import javax.swing.JPanel;
37import javax.swing.JSeparator;
38
39import org.openstreetmap.josm.Main;
40import org.openstreetmap.josm.actions.RenameLayerAction;
41import org.openstreetmap.josm.command.PurgePrimitivesCommand;
42import org.openstreetmap.josm.data.conflict.Conflict;
43import org.openstreetmap.josm.data.conflict.ConflictCollection;
44import org.openstreetmap.josm.data.coor.EastNorth;
45import org.openstreetmap.josm.data.coor.LatLon;
46import org.openstreetmap.josm.data.gpx.GpxData;
47import org.openstreetmap.josm.data.gpx.GpxTrack;
48import org.openstreetmap.josm.data.gpx.WayPoint;
49import org.openstreetmap.josm.data.osm.BackreferencedDataSet;
50import org.openstreetmap.josm.data.osm.DataSet;
51import org.openstreetmap.josm.data.osm.DataSource;
52import org.openstreetmap.josm.data.osm.DataSetMerger;
53import org.openstreetmap.josm.data.osm.Node;
54import org.openstreetmap.josm.data.osm.OsmPrimitive;
55import org.openstreetmap.josm.data.osm.Relation;
56import org.openstreetmap.josm.data.osm.Way;
57import org.openstreetmap.josm.data.osm.visitor.AbstractVisitor;
58import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
59import org.openstreetmap.josm.data.osm.visitor.MapPaintVisitor;
60import org.openstreetmap.josm.data.osm.visitor.SimplePaintVisitor;
61import org.openstreetmap.josm.gui.HelpAwareOptionPane;
62import org.openstreetmap.josm.gui.MapView;
63import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec;
64import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
65import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
66import org.openstreetmap.josm.tools.DateUtils;
67import org.openstreetmap.josm.tools.GBC;
68import org.openstreetmap.josm.tools.ImageProvider;
69
70/**
71 * A layer holding data from a specific dataset.
72 * The data can be fully edited.
73 *
74 * @author imi
75 */
76public class OsmDataLayer extends Layer {
77 static public final String REQUIRES_SAVE_TO_DISK_PROP = OsmDataLayer.class.getName() + ".requiresSaveToDisk";
78 static public final String REQUIRES_UPLOAD_TO_SERVER_PROP = OsmDataLayer.class.getName() + ".requiresUploadToServer";
79
80 private boolean requiresSaveToFile = false;
81 private boolean requiresUploadToServer = false;
82
83 protected void setRequiresSaveToFile(boolean newValue) {
84 boolean oldValue = requiresSaveToFile;
85 requiresSaveToFile = newValue;
86 if (oldValue != newValue) {
87 propertyChangeSupport.firePropertyChange(REQUIRES_SAVE_TO_DISK_PROP, oldValue, newValue);
88 }
89 }
90
91 protected void setRequiresUploadToServer(boolean newValue) {
92 boolean oldValue = requiresUploadToServer;
93 requiresUploadToServer = newValue;
94 if (oldValue != newValue) {
95 propertyChangeSupport.firePropertyChange(REQUIRES_UPLOAD_TO_SERVER_PROP, oldValue, newValue);
96 }
97 }
98
99 /** the global counter for created data layers */
100 static private int dataLayerCounter = 0;
101
102 /**
103 * Replies a new unique name for a data layer
104 *
105 * @return a new unique name for a data layer
106 */
107 static public String createNewName() {
108 dataLayerCounter++;
109 return tr("Data Layer {0}", dataLayerCounter);
110 }
111
112 public final static class DataCountVisitor extends AbstractVisitor {
113 public int nodes;
114 public int ways;
115 public int relations;
116 public int deletedNodes;
117 public int deletedWays;
118 public int deletedRelations;
119
120 public void visit(final Node n) {
121 nodes++;
122 if (n.isDeleted()) {
123 deletedNodes++;
124 }
125 }
126
127 public void visit(final Way w) {
128 ways++;
129 if (w.isDeleted()) {
130 deletedWays++;
131 }
132 }
133
134 public void visit(final Relation r) {
135 relations++;
136 if (r.isDeleted()) {
137 deletedRelations++;
138 }
139 }
140 }
141
142 public interface CommandQueueListener {
143 void commandChanged(int queueSize, int redoSize);
144 }
145
146 /**
147 * The data behind this layer.
148 */
149 public final DataSet data;
150
151 /**
152 * the collection of conflicts detected in this layer
153 */
154 private ConflictCollection conflicts;
155
156 public final LinkedList<DataChangeListener> listenerDataChanged = new LinkedList<DataChangeListener>();
157
158 /**
159 * a paint texture for non-downloaded area
160 */
161 private static TexturePaint hatched;
162
163 static {
164 createHatchTexture();
165 }
166
167 /**
168 * Initialize the hatch pattern used to paint the non-downloaded area
169 */
170 public static void createHatchTexture() {
171 BufferedImage bi = new BufferedImage(15, 15, BufferedImage.TYPE_INT_ARGB);
172 Graphics2D big = bi.createGraphics();
173 big.setColor(Main.pref.getColor(marktr("background"), Color.BLACK));
174 Composite comp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f);
175 big.setComposite(comp);
176 big.fillRect(0,0,15,15);
177 big.setColor(Main.pref.getColor(marktr("outside downloaded area"), Color.YELLOW));
178 big.drawLine(0,15,15,0);
179 Rectangle r = new Rectangle(0, 0, 15,15);
180 hatched = new TexturePaint(bi, r);
181 }
182
183 /**
184 * Construct a OsmDataLayer.
185 */
186 public OsmDataLayer(final DataSet data, final String name, final File associatedFile) {
187 super(name);
188 this.data = data;
189 this.setAssociatedFile(associatedFile);
190 conflicts = new ConflictCollection();
191 }
192
193 /**
194 * TODO: @return Return a dynamic drawn icon of the map data. The icon is
195 * updated by a background thread to not disturb the running programm.
196 */
197 @Override public Icon getIcon() {
198 return ImageProvider.get("layer", "osmdata_small");
199 }
200
201 /**
202 * Draw all primitives in this layer but do not draw modified ones (they
203 * are drawn by the edit layer).
204 * Draw nodes last to overlap the ways they belong to.
205 */
206 @Override public void paint(final Graphics g, final MapView mv) {
207 boolean active = mv.getActiveLayer() == this;
208 boolean inactive = !active && Main.pref.getBoolean("draw.data.inactive_color", true);
209 boolean virtual = !inactive && mv.isVirtualNodesEnabled();
210
211 // draw the hatched area for non-downloaded region. only draw if we're the active
212 // and bounds are defined; don't draw for inactive layers or loaded GPX files etc
213 if (active && Main.pref.getBoolean("draw.data.downloaded_area", true) && !data.dataSources.isEmpty()) {
214 // initialize area with current viewport
215 Rectangle b = mv.getBounds();
216 // on some platforms viewport bounds seem to be offset from the left,
217 // over-grow it just to be sure
218 b.grow(100, 100);
219 Area a = new Area(b);
220
221 // now succesively subtract downloaded areas
222 for (DataSource src : data.dataSources) {
223 if (src.bounds != null && !src.bounds.getMin().equals(src.bounds.getMax())) {
224 EastNorth en1 = mv.getProjection().latlon2eastNorth(src.bounds.getMin());
225 EastNorth en2 = mv.getProjection().latlon2eastNorth(src.bounds.getMax());
226 Point p1 = mv.getPoint(en1);
227 Point p2 = mv.getPoint(en2);
228 Rectangle r = new Rectangle(Math.min(p1.x, p2.x),Math.min(p1.y, p2.y),Math.abs(p2.x-p1.x),Math.abs(p2.y-p1.y));
229 a.subtract(new Area(r));
230 }
231 }
232
233 // paint remainder
234 ((Graphics2D)g).setPaint(hatched);
235 ((Graphics2D)g).fill(a);
236 }
237
238 SimplePaintVisitor painter;
239 if (Main.pref.getBoolean("draw.wireframe")) {
240 painter = new SimplePaintVisitor();
241 } else {
242 painter = new MapPaintVisitor();
243 }
244 painter.setGraphics(g);
245 painter.setNavigatableComponent(mv);
246 painter.inactive = inactive;
247 painter.visitAll(data, virtual);
248 Main.map.conflictDialog.paintConflicts(g, mv);
249 }
250
251 @Override public String getToolTipText() {
252 int nodes = undeletedSize(data.getNodes());
253 int ways = undeletedSize(data.getWays());
254
255 String tool = trn("{0} node", "{0} nodes", nodes, nodes)+", ";
256 tool += trn("{0} way", "{0} ways", ways, ways);
257
258 if (data.getVersion() != null) {
259 tool += ", " + tr("version {0}", data.getVersion());
260 }
261 File f = getAssociatedFile();
262 if (f != null) {
263 tool = "<html>"+tool+"<br>"+f.getPath()+"</html>";
264 }
265 return tool;
266 }
267
268 @Override public void mergeFrom(final Layer from) {
269 mergeFrom(((OsmDataLayer)from).data);
270 }
271
272 /**
273 * merges the primitives in dataset <code>from</code> into the dataset of
274 * this layer
275 *
276 * @param from the source data set
277 */
278 public void mergeFrom(final DataSet from) {
279 final DataSetMerger visitor = new DataSetMerger(data,from);
280 visitor.merge();
281
282 Area a = data.getDataSourceArea();
283
284 // copy the merged layer's data source info;
285 // only add source rectangles if they are not contained in the
286 // layer already.
287 for (DataSource src : from.dataSources) {
288 if (a == null || !a.contains(src.bounds.asRect())) {
289 data.dataSources.add(src);
290 }
291 }
292
293 // copy the merged layer's API version, downgrade if required
294 if (data.getVersion() == null) {
295 data.setVersion(from.getVersion());
296 } else if ("0.5".equals(data.getVersion()) ^ "0.5".equals(from.getVersion())) {
297 System.err.println(tr("Warning: mixing 0.6 and 0.5 data results in version 0.5"));
298 data.setVersion("0.5");
299 }
300
301 int numNewConflicts = 0;
302 for (Conflict<?> c : visitor.getConflicts()) {
303 if (!conflicts.hasConflict(c)) {
304 numNewConflicts++;
305 conflicts.add(c);
306 }
307 }
308 PurgePrimitivesCommand cmd = buildPurgeCommand();
309 if (cmd != null) {
310 Main.main.undoRedo.add(cmd);
311 }
312 fireDataChange();
313 // repaint to make sure new data is displayed properly.
314 Main.map.mapView.repaint();
315 warnNumNewConflicts(
316 numNewConflicts,
317 cmd == null ? 0 : cmd.getPurgedPrimitives().size()
318 );
319 }
320
321 /**
322 * Warns the user about the number of detected conflicts
323 *
324 * @param numNewConflicts the number of detected conflicts
325 * @param numPurgedPrimitives the number of automatically purged objects
326 */
327 protected void warnNumNewConflicts(int numNewConflicts, int numPurgedPrimitives) {
328 if (numNewConflicts == 0 && numPurgedPrimitives == 0) return;
329
330 String msg1 = trn(
331 "There was {0} conflict detected.",
332 "There were {0} conflicts detected.",
333 numNewConflicts,
334 numNewConflicts
335 );
336 String msg2 = trn(
337 "{0} conflict has been <strong>resolved automatically</strong> by purging {0} object<br>from the local dataset because it is deleted on the server.",
338 "{0} conflicts have been <strong>resolved automatically</strong> by purging {0} objects<br> from the local dataset because they are deleted on the server.",
339 numPurgedPrimitives,
340 numPurgedPrimitives
341 );
342 int numRemainingConflicts = numNewConflicts - numPurgedPrimitives;
343 String msg3 = "";
344 if (numRemainingConflicts >0) {
345 msg3 = trn(
346 "{0} conflict remains to be resolved.<br><br>Please open the Conflict List Dialog and manually resolve it.",
347 "{0} conflicts remain to be resolved.<br><br>Please open the Conflict List Dialog and manually resolve them.",
348 numRemainingConflicts,
349 numRemainingConflicts
350 );
351 }
352
353 StringBuffer sb = new StringBuffer();
354 sb.append("<html>").append(msg1);
355 if (numPurgedPrimitives > 0) {
356 sb.append("<br>").append(msg2);
357 }
358 if (numRemainingConflicts > 0) {
359 sb.append("<br>").append(msg3);
360 }
361 sb.append("</html>");
362 if (numNewConflicts > 0) {
363 ButtonSpec[] options = new ButtonSpec[] {
364 new ButtonSpec(
365 tr("OK"),
366 ImageProvider.get("ok"),
367 tr("Click to close this dialog and continue editing"),
368 null /* no specific help */
369 )
370 };
371 HelpAwareOptionPane.showOptionDialog(
372 Main.parent,
373 sb.toString(),
374 tr("Conflicts detected"),
375 JOptionPane.WARNING_MESSAGE,
376 null, /* no icon */
377 options,
378 options[0],
379 ht("/Concepts/Conflict#WarningAboutDetectedConflicts")
380 );
381 }
382 }
383
384 /**
385 * Builds the purge command for primitives which can be purged automatically
386 * from the local dataset because they've been deleted on the
387 * server.
388 *
389 * @return the purge command. <code>null</code> if no primitives have to
390 * be purged
391 */
392 protected PurgePrimitivesCommand buildPurgeCommand() {
393 BackreferencedDataSet ds = new BackreferencedDataSet();
394 ArrayList<OsmPrimitive> toPurge = new ArrayList<OsmPrimitive>();
395 conflictLoop: for (Conflict<?> c: conflicts) {
396 if (c.getMy().isDeleted() && !c.getTheir().isVisible()) {
397 // Local and server version of the primitive are deleted. We
398 // can purge it from the local dataset.
399 //
400 toPurge.add(c.getMy());
401 } else if (!c.getMy().isModified() && ! c.getTheir().isVisible()) {
402 // We purge deleted *ways* and *relations* automatically if they are
403 // deleted on the server and if they aren't modified in the local
404 // dataset.
405 //
406 if (c.getMy() instanceof Way || c.getMy() instanceof Relation) {
407 toPurge.add(c.getMy());
408 continue conflictLoop;
409 }
410 // We only purge nodes if they aren't part of a modified way.
411 // Otherwise the number of nodes of a modified way could drop
412 // below 2 and we would lose the modified data when the way
413 // gets purged.
414 //
415 for (OsmPrimitive parent: ds.getParents(c.getMy())) {
416 if (parent.isModified() && parent instanceof Way) {
417 continue conflictLoop;
418 }
419 }
420 toPurge.add(c.getMy());
421 }
422 }
423 if (toPurge.isEmpty()) return null;
424 PurgePrimitivesCommand cmd = new PurgePrimitivesCommand(this, toPurge);
425 cmd.setBackreferenceDataSet(ds);
426 return cmd;
427 }
428
429 @Override public boolean isMergable(final Layer other) {
430 return other instanceof OsmDataLayer;
431 }
432
433 @Override public void visitBoundingBox(final BoundingXYVisitor v) {
434 for (final Node n: data.getNodes()) {
435 if (n.isUsable()) {
436 v.visit(n);
437 }
438 }
439 }
440
441 /**
442 * Clean out the data behind the layer. This means clearing the redo/undo lists,
443 * really deleting all deleted objects and reset the modified flags. This should
444 * be done after an upload, even after a partial upload.
445 *
446 * @param processed A list of all objects that were actually uploaded.
447 * May be <code>null</code>, which means nothing has been uploaded
448 */
449 public void cleanupAfterUpload(final Collection<OsmPrimitive> processed) {
450 // return immediately if an upload attempt failed
451 if (processed == null || processed.isEmpty())
452 return;
453
454 Main.main.undoRedo.clean(this);
455
456 // if uploaded, clean the modified flags as well
457 final Set<OsmPrimitive> processedSet = new HashSet<OsmPrimitive>(processed);
458 data.clenupDeletedPrimitives();
459 for (final Iterator<Node> it = data.getNodes().iterator(); it.hasNext();) {
460 cleanIterator(it, processedSet);
461 }
462 for (final Iterator<Way> it = data.getWays().iterator(); it.hasNext();) {
463 cleanIterator(it, processedSet);
464 }
465 for (final Iterator<Relation> it = data.getRelations().iterator(); it.hasNext();) {
466 cleanIterator(it, processedSet);
467 }
468 }
469
470 /**
471 * Clean the modified flag for the given iterator over a collection if it is in the
472 * list of processed entries.
473 *
474 * @param it The iterator to change the modified and remove the items if deleted.
475 * @param processed A list of all objects that have been successfully progressed.
476 * If the object in the iterator is not in the list, nothing will be changed on it.
477 */
478 private void cleanIterator(final Iterator<? extends OsmPrimitive> it, final Collection<OsmPrimitive> processed) {
479 final OsmPrimitive osm = it.next();
480 if (!processed.remove(osm))
481 return;
482 osm.setModified(false);
483 }
484
485 /**
486 * @return The number of not-deleted primitives in the list.
487 */
488 private int undeletedSize(final Collection<? extends OsmPrimitive> list) {
489 int size = 0;
490 for (final OsmPrimitive osm : list)
491 if (!osm.isDeleted()) {
492 size++;
493 }
494 return size;
495 }
496
497 @Override public Object getInfoComponent() {
498 final DataCountVisitor counter = new DataCountVisitor();
499 for (final OsmPrimitive osm : data.allPrimitives()) {
500 osm.visit(counter);
501 }
502 final JPanel p = new JPanel(new GridBagLayout());
503
504 String nodeText = trn("{0} node", "{0} nodes", counter.nodes, counter.nodes);
505 if (counter.deletedNodes > 0) {
506 nodeText += " ("+trn("{0} deleted", "{0} deleted", counter.deletedNodes, counter.deletedNodes)+")";
507 }
508
509 String wayText = trn("{0} way", "{0} ways", counter.ways, counter.ways);
510 if (counter.deletedWays > 0) {
511 wayText += " ("+trn("{0} deleted", "{0} deleted", counter.deletedWays, counter.deletedWays)+")";
512 }
513
514 String relationText = trn("{0} relation", "{0} relations", counter.relations, counter.relations);
515 if (counter.deletedRelations > 0) {
516 relationText += " ("+trn("{0} deleted", "{0} deleted", counter.deletedRelations, counter.deletedRelations)+")";
517 }
518
519 p.add(new JLabel(tr("{0} consists of:", getName())), GBC.eol());
520 p.add(new JLabel(nodeText, ImageProvider.get("data", "node"), JLabel.HORIZONTAL), GBC.eop().insets(15,0,0,0));
521 p.add(new JLabel(wayText, ImageProvider.get("data", "way"), JLabel.HORIZONTAL), GBC.eop().insets(15,0,0,0));
522 p.add(new JLabel(relationText, ImageProvider.get("data", "relation"), JLabel.HORIZONTAL), GBC.eop().insets(15,0,0,0));
523 p.add(new JLabel(tr("API version: {0}", (data.getVersion() != null) ? data.getVersion() : tr("unset"))));
524
525 return p;
526 }
527
528 @Override public Component[] getMenuEntries() {
529 if (Main.applet)
530 return new Component[]{
531 new JMenuItem(LayerListDialog.getInstance().createActivateLayerAction(this)),
532 new JMenuItem(LayerListDialog.getInstance().createShowHideLayerAction(this)),
533 new JMenuItem(LayerListDialog.getInstance().createDeleteLayerAction(this)),
534 new JSeparator(),
535 new JMenuItem(LayerListDialog.getInstance().createMergeLayerAction(this)),
536 new JSeparator(),
537 new JMenuItem(new RenameLayerAction(getAssociatedFile(), this)),
538 new JSeparator(),
539 new JMenuItem(new LayerListPopup.InfoAction(this))};
540 return new Component[]{
541 new JMenuItem(LayerListDialog.getInstance().createActivateLayerAction(this)),
542 new JMenuItem(LayerListDialog.getInstance().createShowHideLayerAction(this)),
543 new JMenuItem(LayerListDialog.getInstance().createDeleteLayerAction(this)),
544 new JSeparator(),
545 new JMenuItem(LayerListDialog.getInstance().createMergeLayerAction(this)),
546 new JMenuItem(new LayerSaveAction(this)),
547 new JMenuItem(new LayerSaveAsAction(this)),
548 new JMenuItem(new LayerGpxExportAction(this)),
549 new JMenuItem(new ConvertToGpxLayerAction()),
550 new JSeparator(),
551 new JMenuItem(new RenameLayerAction(getAssociatedFile(), this)),
552 new JSeparator(),
553 new JMenuItem(new LayerListPopup.InfoAction(this))};
554 }
555
556 public void fireDataChange() {
557 setRequiresSaveToFile(true);
558 setRequiresUploadToServer(true);
559 for (DataChangeListener dcl : listenerDataChanged) {
560 dcl.dataChanged(this);
561 }
562 }
563
564 public static GpxData toGpxData(DataSet data, File file) {
565 GpxData gpxData = new GpxData();
566 gpxData.storageFile = file;
567 HashSet<Node> doneNodes = new HashSet<Node>();
568 for (Way w : data.getWays()) {
569 if (!w.isUsable()) {
570 continue;
571 }
572 GpxTrack trk = new GpxTrack();
573 gpxData.tracks.add(trk);
574
575 if (w.get("name") != null) {
576 trk.attr.put("name", w.get("name"));
577 }
578
579 ArrayList<WayPoint> trkseg = null;
580 for (Node n : w.getNodes()) {
581 if (!n.isUsable()) {
582 trkseg = null;
583 continue;
584 }
585 if (trkseg == null) {
586 trkseg = new ArrayList<WayPoint>();
587 trk.trackSegs.add(trkseg);
588 }
589 if (!n.isTagged()) {
590 doneNodes.add(n);
591 }
592 WayPoint wpt = new WayPoint(n.getCoor());
593 if (!n.isTimestampEmpty()) {
594 wpt.attr.put("time", DateUtils.fromDate(n.getTimestamp()));
595 wpt.setTime();
596 }
597 trkseg.add(wpt);
598 }
599 }
600
601 // what is this loop meant to do? it creates waypoints but never
602 // records them?
603 for (Node n : data.getNodes()) {
604 if (n.incomplete || n.isDeleted() || doneNodes.contains(n)) {
605 continue;
606 }
607 WayPoint wpt = new WayPoint(n.getCoor());
608 if (!n.isTimestampEmpty()) {
609 wpt.attr.put("time", DateUtils.fromDate(n.getTimestamp()));
610 wpt.setTime();
611 }
612 String name = n.get("name");
613 if (name != null) {
614 wpt.attr.put("name", name);
615 }
616 ;
617 }
618 return gpxData;
619 }
620
621 public GpxData toGpxData() {
622 return toGpxData(data, getAssociatedFile());
623 }
624
625 public class ConvertToGpxLayerAction extends AbstractAction {
626 public ConvertToGpxLayerAction() {
627 super(tr("Convert to GPX layer"), ImageProvider.get("converttogpx"));
628 }
629 public void actionPerformed(ActionEvent e) {
630 Main.main.addLayer(new GpxLayer(toGpxData(), tr("Converted from: {0}", getName())));
631 Main.main.removeLayer(OsmDataLayer.this);
632 }
633 }
634
635 public boolean containsPoint(LatLon coor) {
636 // we'll assume that if this has no data sources
637 // that it also has no borders
638 if (this.data.dataSources.isEmpty())
639 return true;
640
641 boolean layer_bounds_point = false;
642 for (DataSource src : this.data.dataSources) {
643 if (src.bounds.contains(coor)) {
644 layer_bounds_point = true;
645 break;
646 }
647 }
648 return layer_bounds_point;
649 }
650
651 /**
652 * replies the set of conflicts currently managed in this layer
653 *
654 * @return the set of conflicts currently managed in this layer
655 */
656 public ConflictCollection getConflicts() {
657 return conflicts;
658 }
659
660 /**
661 * Replies true if the data managed by this layer needs to be uploaded to
662 * the server because it contains at least one modified primitive.
663 *
664 * @return true if the data managed by this layer needs to be uploaded to
665 * the server because it contains at least one modified primitive; false,
666 * otherwise
667 */
668 public boolean requiresUploadToServer() {
669 return requiresUploadToServer;
670 }
671
672 /**
673 * Replies true if the data managed by this layer needs to be saved to
674 * a file. Only replies true if a file is assigned to this layer and
675 * if the data managed by this layer has been modified since the last
676 * save operation to the file.
677 *
678 * @return true if the data managed by this layer needs to be saved to
679 * a file
680 */
681 public boolean requiresSaveToFile() {
682 return getAssociatedFile() != null && requiresSaveToFile;
683 }
684
685 /**
686 * Initializes the layer after a successful load of OSM data from a file
687 *
688 */
689 public void onPostLoadFromFile() {
690 setRequiresSaveToFile(false);
691 setRequiresUploadToServer(data.isModified());
692 }
693
694 /**
695 * Initializes the layer after a successful save of OSM data to a file
696 *
697 */
698 public void onPostSaveToFile() {
699 setRequiresSaveToFile(false);
700 setRequiresUploadToServer(data.isModified());
701 }
702
703 /**
704 * Initializes the layer after a successful upload to the server
705 *
706 */
707 public void onPostUploadToServer() {
708 setRequiresUploadToServer(data.isModified());
709 // keep requiresSaveToDisk unchanged
710 }
711}
Note: See TracBrowser for help on using the repository browser.