Changeset 13797 in josm
- Timestamp:
- 2018-05-20T23:43:01+02:00 (5 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/ImageryAdjustAction.java
r13795 r13797 83 83 tempOffset = new OffsetBookmark( 84 84 Main.getProjection().toCode(), 85 layer.getInfo().getId(), 85 86 layer.getInfo().getName(), 86 87 null, -
trunk/src/org/openstreetmap/josm/data/imagery/ImageryLayerInfo.java
r13537 r13797 430 430 return null; 431 431 } 432 433 /** 434 * Returns imagery layer info for the given id. 435 * @param id imagery layer id. 436 * @return imagery layer info for the given id, or {@code null} 437 * @since 13797 438 */ 439 public ImageryInfo getLayer(String id) { 440 return layerIds.get(id); 441 } 432 442 } -
trunk/src/org/openstreetmap/josm/data/imagery/OffsetBookmark.java
r13493 r13797 2 2 package org.openstreetmap.josm.data.imagery; 3 3 4 import static org.openstreetmap.josm.tools.I18n.tr;5 6 4 import java.util.ArrayList; 7 import java.util.Collection;8 5 import java.util.Collections; 9 6 import java.util.List; 10 7 import java.util.ListIterator; 11 8 import java.util.Map; 9 import java.util.Objects; 10 import java.util.stream.Collectors; 12 11 13 12 import org.openstreetmap.josm.Main; … … 36 35 37 36 @StructEntry private String projection_code; 37 @StructEntry private String imagery_id; 38 /** Imagery localized name. Locale insensitive {@link #imagery_id} is preferred. */ 38 39 @StructEntry private String imagery_name; 39 40 @StructEntry private String name; … … 49 50 if (projection_code == null) return false; 50 51 if (!Main.getProjection().toCode().equals(projection_code) && !hasCenter()) return false; 51 return layer.getInfo().getName().equals(imagery_name); 52 ImageryInfo info = layer.getInfo(); 53 return imagery_id != null ? Objects.equals(info.getId(), imagery_id) : Objects.equals(info.getName(), imagery_name); 52 54 } 53 55 … … 64 66 * Create a new {@link OffsetBookmark} object using (0, 0) as center 65 67 * <p> 66 * The use of the {@link #OffsetBookmark(String, String, String, EastNorth, ILatLon)} constructor is preferred.68 * The use of the {@link #OffsetBookmark(String, String, String, String, EastNorth, ILatLon)} constructor is preferred. 67 69 * @param projectionCode The projection for which this object was created 68 * @param imageryName The name of the imagery on the layer 70 * @param imageryId The id of the imagery on the layer (locale insensitive) 71 * @param imageryName The name of the imagery on the layer (locale sensitive) 69 72 * @param name The name of the new bookmark 70 73 * @param dx The x displacement 71 74 * @param dy The y displacement 72 */ 73 public OffsetBookmark(String projectionCode, String imageryName, String name, double dx, double dy) { 74 this(projectionCode, imageryName, name, dx, dy, 0, 0); 75 * @since 13797 76 */ 77 public OffsetBookmark(String projectionCode, String imageryId, String imageryName, String name, double dx, double dy) { 78 this(projectionCode, imageryId, imageryName, name, dx, dy, 0, 0); 75 79 } 76 80 … … 78 82 * Create a new {@link OffsetBookmark} object 79 83 * @param projectionCode The projection for which this object was created 80 * @param imageryName The name of the imagery on the layer 84 * @param imageryId The id of the imagery on the layer (locale insensitive) 85 * @param imageryName The name of the imagery on the layer (locale sensitive) 81 86 * @param name The name of the new bookmark 82 87 * @param displacement The displacement in east/north space. 83 88 * @param center The point on earth that was used as reference to align the image. 84 * @since 13 24385 */ 86 public OffsetBookmark(String projectionCode, String imagery Name, String name, EastNorth displacement, ILatLon center) {87 this(projectionCode, imagery Name, name, displacement.east(), displacement.north(), center.lon(), center.lat());89 * @since 13797 90 */ 91 public OffsetBookmark(String projectionCode, String imageryId, String imageryName, String name, EastNorth displacement, ILatLon center) { 92 this(projectionCode, imageryId, imageryName, name, displacement.east(), displacement.north(), center.lon(), center.lat()); 88 93 } 89 94 … … 91 96 * Create a new {@link OffsetBookmark} by specifying all values. 92 97 * <p> 93 * The use of the {@link #OffsetBookmark(String, String, String, EastNorth, ILatLon)} constructor is preferred.98 * The use of the {@link #OffsetBookmark(String, String, String, String, EastNorth, ILatLon)} constructor is preferred. 94 99 * @param projectionCode The projection for which this object was created 95 * @param imageryName The name of the imagery on the layer 100 * @param imageryId The id of the imagery on the layer (locale insensitive) 101 * @param imageryName The name of the imagery on the layer (locale sensitive) 96 102 * @param name The name of the new bookmark 97 103 * @param dx The x displacement … … 99 105 * @param centerLon The point on earth that was used as reference to align the image. 100 106 * @param centerLat The point on earth that was used as reference to align the image. 101 */ 102 public OffsetBookmark(String projectionCode, String imageryName, String name, double dx, double dy, double centerLon, double centerLat) { 107 * @since 13797 108 */ 109 public OffsetBookmark(String projectionCode, String imageryId, String imageryName, String name, 110 double dx, double dy, double centerLon, double centerLat) { 103 111 this.projection_code = projectionCode; 112 this.imagery_id = imageryId; 104 113 this.imagery_name = imageryName; 105 114 this.name = name; … … 111 120 112 121 /** 113 * Loads an old bookmark. For backward compatibility with settings. Do not use.114 * @param list The settings that were read115 */116 public OffsetBookmark(Collection<String> list) {117 List<String> array = new ArrayList<>(list);118 this.projection_code = array.get(0);119 this.imagery_name = array.get(1);120 this.name = array.get(2);121 this.dx = Double.parseDouble(array.get(3));122 this.dy = Double.parseDouble(array.get(4));123 if (array.size() >= 7) {124 this.center_lon = Double.parseDouble(array.get(5));125 this.center_lat = Double.parseDouble(array.get(6));126 }127 if (projection_code == null) {128 Logging.error(tr("Projection ''{0}'' is not found, bookmark ''{1}'' is not usable", projection_code, name));129 }130 }131 132 /**133 122 * Get the projection code for which this bookmark was created. 134 123 * @return The projection. … … 147 136 148 137 /** 149 * Get the name of the imagery for which this bookmark was created. It is used to match the bookmark to the right layers. 138 * Get the id of the imagery for which this bookmark was created. It is used to match the bookmark to the right layers. 139 * @return The imagery identifier 140 * @since 13797 141 */ 142 public String getImageryId() { 143 return imagery_id; 144 } 145 146 /** 147 * Get the name of the imagery for which this bookmark was created. 148 * It is used to match the bookmark to the right layers if id is missing. 150 149 * @return The name 151 150 */ … … 233 232 234 233 /** 234 * Sets the id of the imagery 235 * @param imageryId The identifier 236 * @see #getImageryId() 237 * @since xxx 238 */ 239 public void setImageryId(String imageryId) { 240 this.imagery_id = imageryId; 241 } 242 243 /** 235 244 * Update the displacement of this imagery. 236 245 * @param displacement The displacement … … 248 257 Config.getPref(), "imagery.offsetbookmarks", null, OffsetBookmark.class); 249 258 if (bookmarks == null) { 250 loadBookmarksOld();251 259 saveBookmarks(); 252 260 } else { 261 sanitizeBookmarks(bookmarks); 253 262 allBookmarks.addAll(bookmarks); 254 263 } 255 264 } 256 265 257 // migration code - remove Nov. 2017 258 private static void loadBookmarksOld() { 259 for (Collection<String> c : Config.getPref().getListOfLists("imagery.offsets")) { 260 allBookmarks.add(new OffsetBookmark(c)); 261 } 266 static void sanitizeBookmarks(List<OffsetBookmark> bookmarks) { 267 // Retrieve layer id from layer name (it was not available before #13937) 268 bookmarks.stream().filter(b -> b.getImageryId() == null).forEach(b -> { 269 List<ImageryInfo> candidates = ImageryLayerInfo.instance.getLayers().stream() 270 .filter(l -> Objects.equals(l.getName(), b.getImageryName())) 271 .collect(Collectors.toList()); 272 // Make sure there is no ambiguity 273 if (candidates.size() == 1) { 274 b.setImageryId(candidates.get(0).getId()); 275 } else { 276 Logging.warn("Not a single layer for the name '" + b.getImageryName() + "': " + candidates); 277 } 278 }); 279 // Update layer name (locale sensitive) if the locale has changed 280 bookmarks.stream().filter(b -> b.getImageryId() != null).forEach(b -> { 281 ImageryInfo info = ImageryLayerInfo.instance.getLayer(b.getImageryId()); 282 if (info != null && !Objects.equals(info.getName(), b.getImageryName())) { 283 b.setImageryName(info.getName()); 284 } 285 }); 262 286 } 263 287 … … 346 370 } 347 371 OffsetBookmark nb = new OffsetBookmark( 348 Main.getProjection().toCode(), layer.getInfo().get Name(),372 Main.getProjection().toCode(), layer.getInfo().getId(), layer.getInfo().getName(), 349 373 name, layer.getDisplaySettings().getDisplacement(), center); 350 374 for (ListIterator<OffsetBookmark> it = allBookmarks.listIterator(); it.hasNext();) { -
trunk/src/org/openstreetmap/josm/gui/preferences/imagery/ImageryPreference.java
r13761 r13797 24 24 import java.util.List; 25 25 import java.util.Map; 26 import java.util.Objects; 26 27 import java.util.Set; 28 import java.util.stream.Collectors; 27 29 28 30 import javax.swing.AbstractAction; … … 853 855 JButton add = new JButton(tr("Add")); 854 856 buttonPanel.add(add, GBC.std().insets(0, 5, 0, 0)); 855 add.addActionListener(e -> model.addRow(new OffsetBookmark(Main.getProjection().toCode(), "", "", 0, 0)));857 add.addActionListener(e -> model.addRow(new OffsetBookmark(Main.getProjection().toCode(), "", "", "", 0, 0))); 856 858 857 859 JButton delete = new JButton(tr("Delete")); … … 920 922 return info.getDisplacement().north(); 921 923 default: 922 throw new ArrayIndexOutOfBoundsException( );924 throw new ArrayIndexOutOfBoundsException(column); 923 925 } 924 926 } … … 929 931 switch (column) { 930 932 case 1: 931 info.setImageryName(o.toString()); 933 String name = o.toString(); 934 info.setImageryName(name); 935 List<ImageryInfo> layers = ImageryLayerInfo.instance.getLayers().stream() 936 .filter(l -> Objects.equals(name, l.getName())).collect(Collectors.toList()); 937 if (layers.size() == 1) { 938 info.setImageryId(layers.get(0).getId()); 939 } else { 940 Logging.warn("Not a single layer for the name '" + info.getImageryName() + "': " + layers); 941 } 932 942 break; 933 943 case 2: … … 943 953 break; 944 954 default: 945 throw new ArrayIndexOutOfBoundsException( );955 throw new ArrayIndexOutOfBoundsException(column); 946 956 } 947 957 } -
trunk/test/unit/org/openstreetmap/josm/io/session/SessionWriterTest.java
r12636 r13797 144 144 TMSLayer layer = new TMSLayer(new ImageryInfo("the name", "http://www.url.com/")); 145 145 layer.getDisplaySettings().setOffsetBookmark( 146 new OffsetBookmark(Main.getProjection().toCode(), layer.getInfo().get Name(), "", 12, 34));146 new OffsetBookmark(Main.getProjection().toCode(), layer.getInfo().getId(), layer.getInfo().getName(), "", 12, 34)); 147 147 return layer; 148 148 }
Note: See TracChangeset
for help on using the changeset viewer.