Changeset 12134 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2017-05-13T12:58:12+02:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/imagery/OffsetBookmark.java
r12118 r12134 9 9 import java.util.List; 10 10 import java.util.ListIterator; 11 import java.util.Map; 11 12 12 13 import org.openstreetmap.josm.Main; 14 import org.openstreetmap.josm.data.Preferences; 13 15 import org.openstreetmap.josm.data.Preferences.pref; 14 16 import org.openstreetmap.josm.data.Preferences.writeExplicitly; … … 262 264 saveBookmarks(); 263 265 } 266 267 /** 268 * Converts the offset bookmark to a properties map. 269 * 270 * The map contains all the information to restore the offset bookmark. 271 * @return properties map of all data 272 * @since 12134 273 * @see #fromPropertiesMap(java.util.Map) 274 */ 275 public Map<String, String> toPropertiesMap() { 276 return Preferences.serializeStruct(this, OffsetBookmark.class); 277 } 278 279 /** 280 * Creates an offset bookmark from a properties map. 281 * @param properties the properties map 282 * @return corresponding offset bookmark 283 * @since 12134 284 * @see #toPropertiesMap() 285 */ 286 public static OffsetBookmark fromPropertiesMap(Map<String, String> properties) { 287 return Preferences.deserializeStruct(properties, OffsetBookmark.class); 288 } 264 289 } -
trunk/src/org/openstreetmap/josm/gui/layer/imagery/TileSourceDisplaySettings.java
r12117 r12134 248 248 /** 249 249 * Stores the current settings object to the given hashmap. 250 * The offset data is not stored and needs to be handled separately. 250 251 * @param data The map to store the settings to. 251 252 * @see #loadFrom(Map) 253 * @see OffsetBookmark#toPropertiesMap() 252 254 */ 253 255 public void storeTo(Map<String, String> data) { … … 255 257 data.put(AUTO_ZOOM, Boolean.toString(autoZoom)); 256 258 data.put(SHOW_ERRORS, Boolean.toString(showErrors)); 257 data.put("dx", String.valueOf(getDx()));258 data.put("dy", String.valueOf(getDy()));259 259 } 260 260 261 261 /** 262 262 * Load the settings from the given data instance. 263 * The offset data is not loaded and needs to be handled separately. 263 264 * @param data The data 264 265 * @see #storeTo(Map) 266 * @see OffsetBookmark#fromPropertiesMap(java.util.Map) 265 267 */ 266 268 public void loadFrom(Map<String, String> data) { … … 279 281 if (doShowErrors != null) { 280 282 setShowErrors(Boolean.parseBoolean(doShowErrors)); 281 }282 283 String dx = data.get("dx");284 String dy = data.get("dy");285 if (dx != null && dy != null) {286 setDisplacement(new EastNorth(Double.parseDouble(dx), Double.parseDouble(dy)));287 283 } 288 284 } catch (JosmRuntimeException | IllegalArgumentException | IllegalStateException e) { -
trunk/src/org/openstreetmap/josm/io/session/ImagerySessionExporter.java
r10578 r12134 14 14 import org.openstreetmap.josm.data.Preferences; 15 15 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryPreferenceEntry; 16 import org.openstreetmap.josm.data.imagery.OffsetBookmark; 16 17 import org.openstreetmap.josm.gui.layer.AbstractTileSourceLayer; 17 18 import org.openstreetmap.josm.gui.layer.ImageryLayer; … … 82 83 Map<String, String> data = new LinkedHashMap<>(Preferences.serializeStruct(e, ImageryPreferenceEntry.class)); 83 84 if (layer instanceof AbstractTileSourceLayer) { 84 AbstractTileSourceLayer<?> tsLayer = (AbstractTileSourceLayer<?>) layer; 85 tsLayer.getDisplaySettings().storeTo(data); 85 ((AbstractTileSourceLayer<?>) layer).getDisplaySettings().storeTo(data); 86 86 } 87 for (Map.Entry<String, String> entry : data.entrySet()) { 88 Element attrElem = support.createElement(entry.getKey()); 89 layerElem.appendChild(attrElem); 90 attrElem.appendChild(support.createTextNode(entry.getValue())); 87 addAttributes(layerElem, data, support); 88 if (layer instanceof AbstractTileSourceLayer) { 89 OffsetBookmark offset = ((AbstractTileSourceLayer<?>) layer).getDisplaySettings().getOffsetBookmark(); 90 if (offset != null) { 91 Map<String, String> offsetProps = offset.toPropertiesMap(); 92 Element offsetEl = support.createElement("offset"); 93 layerElem.appendChild(offsetEl); 94 addAttributes(offsetEl, offsetProps, support); 95 } 91 96 } 92 97 return layerElem; 93 98 } 99 100 private void addAttributes(Element element, Map<String, String> props, ExportSupport support) { 101 for (Map.Entry<String, String> entry : props.entrySet()) { 102 Element attrElem = support.createElement(entry.getKey()); 103 element.appendChild(attrElem); 104 attrElem.appendChild(support.createTextNode(entry.getValue())); 105 } 106 } 94 107 } -
trunk/src/org/openstreetmap/josm/io/session/ImagerySessionImporter.java
r10571 r12134 11 11 import org.openstreetmap.josm.data.imagery.ImageryInfo; 12 12 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryPreferenceEntry; 13 import org.openstreetmap.josm.data.imagery.OffsetBookmark; 13 14 import org.openstreetmap.josm.gui.layer.AbstractTileSourceLayer; 14 15 import org.openstreetmap.josm.gui.layer.ImageryLayer; … … 36 37 throw new IllegalDataException(tr("Version ''{0}'' of meta data for imagery layer is not supported. Expected: 0.1", version)); 37 38 } 39 Map<String, String> attributes = readProperties(elem); 40 41 ImageryPreferenceEntry prefEntry = Preferences.deserializeStruct(attributes, ImageryPreferenceEntry.class); 42 ImageryInfo info = new ImageryInfo(prefEntry); 43 ImageryLayer layer = ImageryLayer.create(info); 44 if (layer instanceof AbstractTileSourceLayer) { 45 AbstractTileSourceLayer<?> tsLayer = (AbstractTileSourceLayer<?>) layer; 46 tsLayer.getDisplaySettings().loadFrom(attributes); 47 NodeList nodes = elem.getChildNodes(); 48 for (int i = 0; i < nodes.getLength(); ++i) { 49 Node node = nodes.item(i); 50 if (node.getNodeType() == Node.ELEMENT_NODE && "offset".equals(node.getLocalName())) { 51 Map<String, String> offsetAttributes = readProperties((Element) node); 52 OffsetBookmark offset = OffsetBookmark.fromPropertiesMap(offsetAttributes); 53 tsLayer.getDisplaySettings().setOffsetBookmark(offset); 54 break; 55 } 56 } 57 } 58 return layer; 59 } 60 61 private Map<String, String> readProperties(Element elem) { 38 62 Map<String, String> attributes = new HashMap<>(); 39 40 63 NodeList nodes = elem.getChildNodes(); 41 42 64 for (int i = 0; i < nodes.getLength(); ++i) { 43 65 Node node = nodes.item(i); 44 if (node.getNodeType() == Node.ELEMENT_NODE ) {66 if (node.getNodeType() == Node.ELEMENT_NODE && node.getChildNodes().getLength() <= 1) { 45 67 Element e = (Element) node; 46 68 attributes.put(e.getTagName(), e.getTextContent()); 47 69 } 48 70 } 49 ImageryPreferenceEntry prefEntry = Preferences.deserializeStruct(attributes, ImageryPreferenceEntry.class); 50 ImageryInfo i = new ImageryInfo(prefEntry); 51 ImageryLayer layer = ImageryLayer.create(i); 52 if (layer instanceof AbstractTileSourceLayer) { 53 AbstractTileSourceLayer<?> tsLayer = (AbstractTileSourceLayer<?>) layer; 54 tsLayer.getDisplaySettings().loadFrom(attributes); 55 } 56 return layer; 71 return attributes; 57 72 } 58 73 }
Note:
See TracChangeset
for help on using the changeset viewer.