Changeset 16548 in josm
- Timestamp:
- 2020-06-07T12:21:07+02:00 (5 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/ImageData.java
r16436 r16548 5 5 6 6 import java.util.ArrayList; 7 import java.util.Collection; 7 8 import java.util.Collections; 8 9 import java.util.List; … … 18 19 * @since 14590 19 20 */ 20 public class ImageData {21 public class ImageData implements Data { 21 22 /** 22 23 * A listener that is informed when the current selection change … … 340 341 listeners.removeListener(listener); 341 342 } 343 344 @Override 345 public Collection<DataSource> getDataSources() { 346 return Collections.emptyList(); 347 } 342 348 } -
trunk/src/org/openstreetmap/josm/data/osm/NoteData.java
r14102 r16548 10 10 import java.util.Map; 11 11 12 import org.openstreetmap.josm.data.Data; 13 import org.openstreetmap.josm.data.DataSource; 12 14 import org.openstreetmap.josm.data.UserIdentityManager; 13 15 import org.openstreetmap.josm.data.coor.LatLon; … … 21 23 * Class to hold and perform operations on a set of notes 22 24 */ 23 public class NoteData {25 public class NoteData implements Data { 24 26 25 27 /** … … 310 312 listeners.removeListener(listener); 311 313 } 314 315 @Override 316 public Collection<DataSource> getDataSources() { 317 return Collections.emptyList(); // Notes don't currently store data sources 318 } 312 319 } -
trunk/src/org/openstreetmap/josm/gui/layer/AbstractModifiableLayer.java
r13453 r16548 2 2 package org.openstreetmap.josm.gui.layer; 3 3 4 import java.io.File; 5 import java.io.IOException; 6 7 import org.openstreetmap.josm.data.Data; 4 8 import org.openstreetmap.josm.data.osm.Lockable; 5 9 import org.openstreetmap.josm.gui.io.AbstractIOTask; … … 103 107 return false; 104 108 } 109 110 /** 111 * Perform the autosave action for the layer 112 * 113 * @param file The file to save to 114 * @return {@code true} if the layer was successfully saved 115 * @throws IOException If there was an IO exception from saving 116 * @since 16548 117 */ 118 public boolean autosave(File file) throws IOException { 119 // Override if needed; 120 return false; 121 } 122 123 /** 124 * Get the data for the modifiable layer 125 * 126 * @return The data object 127 * @since 16548 128 */ 129 public Data getData() { 130 // Override if needed; 131 return null; 132 } 105 133 } -
trunk/src/org/openstreetmap/josm/gui/layer/AutosaveTask.java
r16436 r16548 32 32 33 33 import org.openstreetmap.josm.actions.OpenFileAction.OpenFileTask; 34 import org.openstreetmap.josm.data. osm.DataSet;34 import org.openstreetmap.josm.data.Data; 35 35 import org.openstreetmap.josm.data.osm.NoteData; 36 36 import org.openstreetmap.josm.data.osm.NoteData.NoteDataUpdateListener; … … 42 42 import org.openstreetmap.josm.gui.MainApplication; 43 43 import org.openstreetmap.josm.gui.Notification; 44 import org.openstreetmap.josm.gui.io.importexport.NoteExporter;45 44 import org.openstreetmap.josm.gui.io.importexport.NoteImporter; 46 import org.openstreetmap.josm.gui.io.importexport.OsmExporter;47 45 import org.openstreetmap.josm.gui.io.importexport.OsmImporter; 48 46 import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent; … … 117 115 118 116 private final DataSetListenerAdapter datasetAdapter = new DataSetListenerAdapter(this); 119 private final Set<DataSet> changedDatasets = new HashSet<>(); 120 private final Set<NoteData> changedNoteData = new HashSet<>(); 117 private final Set<Data> changedData = new HashSet<>(); 121 118 private final List<AutosaveLayerInfo<?>> layersInfo = new ArrayList<>(); 122 119 private final Object layersLock = new Object(); … … 230 227 } 231 228 try { 232 if (info.layer instanceof OsmDataLayer) { 233 OsmDataLayer dataLayer = (OsmDataLayer) info.layer; 234 if (changedDatasets.remove(dataLayer.data)) { 235 File file = getNewLayerFile(info, new Date(), 0); 236 if (file != null) { 237 info.backupFiles.add(file); 238 new OsmExporter().exportData(file, info.layer, true /* no backup with appended ~ */); 239 } 240 } 241 } else if (info.layer instanceof NoteLayer) { 242 NoteLayer noteLayer = (NoteLayer) info.layer; 243 if (changedNoteData.remove(noteLayer.getNoteData())) { 244 File file = getNewLayerFile(info, new Date(), 0); 245 if (file != null) { 246 info.backupFiles.add(file); 247 new NoteExporter().exportData(file, info.layer); 248 } 229 Data data = info.layer.getData(); 230 if (data != null && changedData.remove(data)) { 231 File file = getNewLayerFile(info, new Date(), 0); 232 if (file != null) { 233 info.backupFiles.add(file); 234 info.layer.autosave(file); 249 235 } 250 236 } … … 267 253 savelayer(info); 268 254 } 269 changedDatasets.clear(); 270 changedNoteData.clear(); 255 changedData.clear(); 271 256 if (PROP_NOTIFICATION.get() && !layersInfo.isEmpty()) { 272 257 GuiHelper.runInEDT(this::displayNotification); … … 311 296 } else if (e.getAddedLayer() instanceof NoteLayer) { 312 297 registerNewlayer((NoteLayer) e.getAddedLayer()); 298 } else if (e.getAddedLayer() instanceof AbstractModifiableLayer) { 299 synchronized (layersLock) { 300 layersInfo.add(new AutosaveLayerInfo<>((AbstractModifiableLayer) e.getAddedLayer())); 301 } 313 302 } 314 303 } … … 355 344 @Override 356 345 public void processDatasetEvent(AbstractDatasetChangedEvent event) { 357 changedDatasets.add(event.getDataset());346 dataUpdated(event.getDataset()); 358 347 } 359 348 360 349 @Override 361 350 public void noteDataUpdated(NoteData data) { 362 changedNoteData.add(data); 351 dataUpdated(data); 352 } 353 354 /** 355 * Indicate that data has changed, and it might be a good idea to autosave. 356 * 357 * @param data The data that has changed 358 * @return See {@link Set#add} 359 * @since 16548 360 */ 361 public boolean dataUpdated(Data data) { 362 return changedData.add(data); 363 363 } 364 364 -
trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
r15924 r16548 28 28 import org.openstreetmap.josm.actions.SaveActionBase; 29 29 import org.openstreetmap.josm.data.Bounds; 30 import org.openstreetmap.josm.data.Data; 30 31 import org.openstreetmap.josm.data.SystemOfMeasurement; 31 32 import org.openstreetmap.josm.data.gpx.GpxConstants; … … 547 548 return isLocalFile ? "survey" : null; 548 549 } 550 551 @Override 552 public Data getData() { 553 return data; 554 } 549 555 } -
trunk/src/org/openstreetmap/josm/gui/layer/NoteLayer.java
r15654 r16548 14 14 import java.awt.event.MouseWheelListener; 15 15 import java.io.File; 16 import java.io.IOException; 16 17 import java.text.DateFormat; 17 18 import java.util.ArrayList; … … 36 37 import org.openstreetmap.josm.actions.SaveActionBase; 37 38 import org.openstreetmap.josm.data.Bounds; 39 import org.openstreetmap.josm.data.Data; 38 40 import org.openstreetmap.josm.data.notes.Note; 39 41 import org.openstreetmap.josm.data.notes.Note.State; … … 479 481 return "Notes"; 480 482 } 483 484 @Override 485 public boolean autosave(File file) throws IOException { 486 new NoteExporter().exportData(file, this); 487 return true; 488 } 489 490 @Override 491 public Data getData() { 492 return getNoteData(); 493 } 481 494 } -
trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r16438 r16548 55 55 import org.openstreetmap.josm.data.APIDataSet; 56 56 import org.openstreetmap.josm.data.Bounds; 57 import org.openstreetmap.josm.data.Data; 57 58 import org.openstreetmap.josm.data.ProjectionBounds; 58 59 import org.openstreetmap.josm.data.UndoRedoHandler; … … 112 113 import org.openstreetmap.josm.gui.io.UploadLayerTask; 113 114 import org.openstreetmap.josm.gui.io.importexport.NoteExporter; 115 import org.openstreetmap.josm.gui.io.importexport.OsmExporter; 114 116 import org.openstreetmap.josm.gui.io.importexport.OsmImporter; 115 117 import org.openstreetmap.josm.gui.io.importexport.ValidatorErrorExporter; … … 1302 1304 return isUploadInProgress.get(); 1303 1305 } 1306 1307 @Override 1308 public Data getData() { 1309 return getDataSet(); 1310 } 1311 1312 @Override 1313 public boolean autosave(File file) throws IOException { 1314 new OsmExporter().exportData(file, this, true /* no backup with appended ~ */); 1315 return true; 1316 } 1304 1317 } -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java
r16438 r16548 41 41 import org.openstreetmap.josm.actions.mapmode.SelectAction; 42 42 import org.openstreetmap.josm.data.Bounds; 43 import org.openstreetmap.josm.data.Data; 43 44 import org.openstreetmap.josm.data.ImageData; 44 45 import org.openstreetmap.josm.data.ImageData.ImageDataUpdateListener; … … 1009 1010 return "Geotagged Images"; 1010 1011 } 1012 1013 @Override 1014 public Data getData() { 1015 return data; 1016 } 1011 1017 }
Note:
See TracChangeset
for help on using the changeset viewer.