- Timestamp:
- 2011-09-19T11:59:27+02:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/Preferences.java
r4426 r4450 901 901 structPrototype = klass.newInstance(); 902 902 } catch (InstantiationException ex) { 903 throw new RuntimeException( );903 throw new RuntimeException(ex); 904 904 } catch (IllegalAccessException ex) { 905 throw new RuntimeException( );905 throw new RuntimeException(ex); 906 906 } 907 907 -
trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java
r4437 r4450 14 14 import org.openstreetmap.josm.Main; 15 15 import org.openstreetmap.josm.data.Bounds; 16 import org.openstreetmap.josm.data.Preferences.pref; 16 17 import org.openstreetmap.josm.io.OsmApi; 17 18 import org.openstreetmap.josm.tools.CheckParameterUtil; … … 42 43 } 43 44 } 44 45 45 46 public static class ImageryBounds extends Bounds { 46 47 public ImageryBounds(String asString, String separator) { … … 49 50 50 51 private List<Shape> shapes = new ArrayList<Shape>(); 51 52 52 53 public void addShape(Shape shape) { 53 54 this.shapes.add(shape); … … 80 81 private String countryCode = ""; 81 82 83 /** auxiliary class to save an ImageryInfo object in the preferences */ 84 public static class ImageryPreferenceEntry { 85 @pref String name; 86 @pref String type; 87 @pref String url; 88 @pref String eula; 89 @pref String attribution_text; 90 @pref String attribution_url; 91 @pref String terms_of_use_url; 92 @pref String country_code = ""; 93 @pref int max_zoom; 94 @pref int min_zoom; 95 @pref String cookies; 96 @pref String bounds; 97 @pref String shapes; 98 @pref String projections; 99 100 public ImageryPreferenceEntry() { 101 } 102 103 public ImageryPreferenceEntry(ImageryInfo i) { 104 name = i.name; 105 type = i.imageryType.getUrlString(); 106 url = i.url; 107 eula = i.eulaAcceptanceRequired; 108 attribution_text = i.attributionText; 109 attribution_url = i.attributionLinkURL; 110 terms_of_use_url = i.termsOfUseURL; 111 country_code = i.countryCode; 112 max_zoom = i.defaultMaxZoom; 113 min_zoom = i.defaultMinZoom; 114 cookies = i.cookies; 115 if (i.bounds != null) { 116 bounds = i.bounds.encodeAsString(","); 117 String shapesString = ""; 118 for (Shape s : i.bounds.getShapes()) { 119 if (!shapesString.isEmpty()) { 120 shapesString += ";"; 121 } 122 shapesString += s.encodeAsString(","); 123 } 124 if (!shapesString.isEmpty()) { 125 shapes = shapesString; 126 } 127 } 128 if (i.serverProjections != null && !i.serverProjections.isEmpty()) { 129 String val = ""; 130 for (String p : i.serverProjections) { 131 if (!val.isEmpty()) 132 val += ","; 133 val += p; 134 } 135 projections = val; 136 } 137 } 138 } 139 82 140 public ImageryInfo() { 83 141 } … … 112 170 } 113 171 114 public ArrayList<String> getInfoArray() { 115 ArrayList<String> res = new ArrayList<String>(); 116 res.add(name); 117 res.add((url != null && !url.isEmpty()) ? getExtendedUrl() : null); 118 res.add(cookies); 119 if(imageryType == ImageryType.WMS || imageryType == ImageryType.HTML) { 120 res.add(pixelPerDegree != 0.0 ? String.valueOf(pixelPerDegree) : null); 121 } else { 122 res.add(null); 123 } 124 res.add(bounds != null ? bounds.encodeAsString(",") : null); 125 res.add(attributionText); 126 res.add(attributionLinkURL); 127 res.add(attributionImage); 128 res.add(termsOfUseURL); 129 // Shapes 130 String shapesString = ""; 131 if (bounds != null) { 132 for (Shape s : bounds.getShapes()) { 133 if (!shapesString.isEmpty()) { 134 shapesString += ";"; 135 } 136 shapesString += s.encodeAsString(","); 137 } 138 } 139 res.add(shapesString.isEmpty() ? null : shapesString); 140 if(serverProjections != null && serverProjections.size() != 0) { 141 String val = ""; 142 for(String p : serverProjections) { 143 if(!val.isEmpty()) 144 val += ","; 145 val += p; 146 } 147 res.add(val); 148 } 149 return res; 172 public ImageryInfo(ImageryPreferenceEntry e) { 173 name = e.name; 174 url = e.url; 175 eulaAcceptanceRequired = e.eula; 176 for (ImageryType type : ImageryType.values()) { 177 if (type.getUrlString().equals(e.type)) { 178 imageryType = type; 179 break; 180 } 181 } 182 defaultMaxZoom = e.max_zoom; 183 defaultMinZoom = e.min_zoom; 184 if (e.bounds != null) { 185 bounds = new ImageryBounds(e.bounds, ","); 186 if (e.shapes != null) { 187 try { 188 for (String s : e.shapes.split(";")) { 189 bounds.addShape(new Shape(s, ",")); 190 } 191 } catch (IllegalArgumentException ex) { 192 Main.warn(ex.toString()); 193 } 194 } 195 } 196 if (e.projections != null) { 197 serverProjections = Arrays.asList(e.projections.split(",")); 198 } 199 attributionText = e.attribution_text; 200 attributionLinkURL = e.attribution_url; 201 termsOfUseURL = e.terms_of_use_url; 202 countryCode = e.country_code; 150 203 } 151 204 … … 246 299 this.defaultMinZoom = defaultMinZoom; 247 300 } 248 301 249 302 public void setBounds(ImageryBounds b) { 250 303 this.bounds = b; … … 273 326 public void setExtendedUrl(String url) { 274 327 CheckParameterUtil.ensureParameterNotNull(url); 275 328 276 329 // Default imagery type is WMS 277 330 this.url = url; -
trunk/src/org/openstreetmap/josm/data/imagery/ImageryLayerInfo.java
r4428 r4450 11 11 12 12 import org.openstreetmap.josm.Main; 13 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryPreferenceEntry; 13 14 import org.openstreetmap.josm.io.imagery.ImageryReader; 14 15 import org.openstreetmap.josm.io.MirroredInputStream; … … 16 17 import org.xml.sax.SAXException; 17 18 19 /** 20 * Manages the list of imagery entries that are shown in the imagery menu. 21 */ 18 22 public class ImageryLayerInfo { 19 23 … … 39 43 public void load() { 40 44 boolean addedDefault = layers.size() != 0; 41 for(Collection<String> c : Main.pref.getArray("imagery.layers", 42 Collections.<Collection<String>>emptySet())) { 43 ImageryInfo i = new ImageryInfo(c); 44 String url = i.getUrl(); 45 if(url != null) { 46 /* FIXME: Remove the attribution copy stuff end of 2011 */ 47 if(!i.hasAttribution()) { 48 for(ImageryInfo d : defaultLayers) { 49 if(url.equals(d.getUrl())) { 50 i.copyAttribution(d); 51 i.setBounds(d.getBounds()); 52 break; 45 List<ImageryPreferenceEntry> entries = Main.pref.getListOfStructs("imagery.entries", null, ImageryPreferenceEntry.class); 46 if (entries == null) { 47 /* FIXME: Remove old format ~ March 2012 */ 48 boolean hasOld = loadOld(); 49 if (hasOld) { 50 save(); 51 } 52 } else { 53 for (ImageryPreferenceEntry prefEntry : entries) { 54 ImageryInfo i = new ImageryInfo(prefEntry); 55 add(i); 56 } 57 Collections.sort(layers); 58 } 59 if (addedDefault) { 60 save(); 61 } 62 } 63 64 public boolean loadOld() { 65 Collection<Collection<String>> entries = Main.pref.getArray("imagery.layers", null); 66 if (entries != null) { 67 for (Collection<String> c : Main.pref.getArray("imagery.layers", 68 Collections.<Collection<String>>emptySet())) { 69 ImageryInfo i = new ImageryInfo(c); 70 String url = i.getUrl(); 71 if(url != null) { 72 /* FIXME: Remove the attribution copy stuff end of 2011 */ 73 if(!i.hasAttribution()) { 74 for(ImageryInfo d : defaultLayers) { 75 if(url.equals(d.getUrl())) { 76 i.copyAttribution(d); 77 i.setBounds(d.getBounds()); 78 break; 79 } 53 80 } 54 81 } 82 add(i); 55 83 } 56 add(i);57 84 } 85 Collections.sort(layers); 86 return true; 58 87 } 59 Collections.sort(layers); 60 if(addedDefault) 61 save(); 88 return false; 62 89 } 63 90 … … 132 159 133 160 public void save() { 134 Li nkedList<Collection<String>> coll = new LinkedList<Collection<String>>();161 List<ImageryPreferenceEntry> entries = new ArrayList<ImageryPreferenceEntry>(); 135 162 for (ImageryInfo info : layers) { 136 coll.add(info.getInfoArray());163 entries.add(new ImageryPreferenceEntry(info)); 137 164 } 138 Main.pref.put Array("imagery.layers", coll);165 Main.pref.putListOfStructs("imagery.entries", entries, ImageryPreferenceEntry.class); 139 166 } 140 167
Note:
See TracChangeset
for help on using the changeset viewer.