Changeset 1857 in josm for trunk/src/org/openstreetmap/josm/data
- Timestamp:
- 2009-07-26T22:52:23+02:00 (17 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data
- Files:
-
- 5 edited
-
DataSetChecker.java (modified) (3 diffs)
-
Preferences.java (modified) (19 diffs)
-
ServerSidePreferences.java (modified) (8 diffs)
-
conflict/ConflictCollection.java (modified) (1 diff)
-
projection/Lambert.java (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/DataSetChecker.java
r1814 r1857 9 9 import org.openstreetmap.josm.Main; 10 10 import org.openstreetmap.josm.data.osm.OsmPrimitive; 11 import org.openstreetmap.josm.gui.OptionPaneUtil; 11 12 import org.openstreetmap.josm.gui.layer.Layer; 12 13 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 14 15 // FIXME: class still needed? 13 16 14 17 public class DataSetChecker { … … 23 26 for (OsmPrimitive osm : ((OsmDataLayer)l).data.allPrimitives()) { 24 27 if (s.contains(osm)) { 25 JOptionPane.showMessageDialog(Main.parent, "cross references"); 28 // FIXME: better message 29 // FIXME: translate message and title 30 OptionPaneUtil.showMessageDialog( 31 Main.parent, 32 "cross references", 33 "Information", 34 JOptionPane.INFORMATION_MESSAGE); 26 35 return; 27 36 } … … 34 43 OsmDataLayer l = (OsmDataLayer)Main.map.mapView.getActiveLayer(); 35 44 if (l.data != Main.main.getCurrentDataSet()) { 36 JOptionPane.showMessageDialog(Main.parent, "Main.ds / active layer mismatch"); 45 OptionPaneUtil.showMessageDialog( 46 Main.parent, 47 "Main.ds / active layer mismatch", 48 "Error", 49 JOptionPane.ERROR_MESSAGE 50 ); 37 51 return; 38 52 } 39 53 } 40 54 41 JOptionPane.showMessageDialog(Main.parent, "working"); 55 OptionPaneUtil.showMessageDialog( 56 Main.parent, "working", "", JOptionPane.INFORMATION_MESSAGE); 42 57 } 43 58 } -
trunk/src/org/openstreetmap/josm/data/Preferences.java
r1722 r1857 31 31 import org.openstreetmap.josm.actions.AboutAction; 32 32 import org.openstreetmap.josm.data.projection.Mercator; 33 import org.openstreetmap.josm.gui.OptionPaneUtil; 33 34 import org.openstreetmap.josm.gui.preferences.ProxyPreferences; 34 35 import org.openstreetmap.josm.tools.ColorHelper; … … 45 46 46 47 /** 47 * Internal storage for the preferenced directory. 48 * Do not access this variable directly! 49 * @see #getPreferencesDirFile() 50 */ 48 * Internal storage for the preferenced directory. 49 * Do not access this variable directly! 50 * @see #getPreferencesDirFile() 51 */ 51 52 private File preferencesDirFile = null; 52 53 … … 131 132 String s; 132 133 if ((s = System.getenv("JOSM_RESOURCES")) != null) { 133 if (!s.endsWith(File.separator)) 134 if (!s.endsWith(File.separator)) { 134 135 s = s + File.separator; 136 } 135 137 locations.add(s); 136 138 } 137 139 if ((s = System.getProperty("josm.resources")) != null) { 138 if (!s.endsWith(File.separator)) 140 if (!s.endsWith(File.separator)) { 139 141 s = s + File.separator; 142 } 140 143 locations.add(s); 141 144 } … … 180 183 final Map<String,String> all = new TreeMap<String,String>(); 181 184 for (final Entry<String,String> e : properties.entrySet()) 182 if (e.getKey().startsWith(prefix)) 185 if (e.getKey().startsWith(prefix)) { 183 186 all.put(e.getKey(), e.getValue()); 187 } 184 188 for (final Entry<String,String> e : override.entrySet()) 185 189 if (e.getKey().startsWith(prefix)) 186 if (e.getValue() == null) 190 if (e.getValue() == null) { 187 191 all.remove(e.getKey()); 188 else192 } else { 189 193 all.put(e.getKey(), e.getValue()); 194 } 190 195 return all; 191 196 } … … 194 199 final TreeMap<String,String> all = new TreeMap<String,String>(); 195 200 for (final Entry<String,String> e : defaults.entrySet()) 196 if (e.getKey().startsWith("color.") && e.getValue() != null) 201 if (e.getKey().startsWith("color.") && e.getValue() != null) { 197 202 all.put(e.getKey().substring(6), e.getValue()); 203 } 198 204 for (final Entry<String,String> e : properties.entrySet()) 199 if (e.getKey().startsWith("color.")) 205 if (e.getKey().startsWith("color.")) { 200 206 all.put(e.getKey().substring(6), e.getValue()); 207 } 201 208 for (final Entry<String,String> e : override.entrySet()) 202 209 if (e.getKey().startsWith("color.")) 203 if (e.getValue() == null) 210 if (e.getValue() == null) { 204 211 all.remove(e.getKey().substring(6)); 205 else212 } else { 206 213 all.put(e.getKey().substring(6), e.getValue()); 214 } 207 215 return all; 208 216 } … … 213 221 214 222 synchronized public void putDefault(final String key, final String def) { 215 if(!defaults.containsKey(key) || defaults.get(key) == null) 223 if(!defaults.containsKey(key) || defaults.get(key) == null) { 216 224 defaults.put(key, def); 217 else if(def != null && !defaults.get(key).equals(def)) 225 } else if(def != null && !defaults.get(key).equals(def)) { 218 226 System.out.println("Defaults for " + key + " differ: " + def + " != " + defaults.get(key)); 227 } 219 228 } 220 229 … … 235 244 synchronized public boolean put(final String key, String value) { 236 245 String oldvalue = properties.get(key); 237 if(value != null && value.length() == 0) 246 if(value != null && value.length() == 0) { 238 247 value = null; 248 } 239 249 if(!((oldvalue == null && (value == null || value.equals(defaults.get(key)))) 240 || (value != null && oldvalue != null && oldvalue.equals(value)))) 250 || (value != null && oldvalue != null && oldvalue.equals(value)))) 241 251 { 242 if (value == null) 252 if (value == null) { 243 253 properties.remove(key); 244 else254 } else { 245 255 properties.put(key, value); 256 } 246 257 save(); 247 258 firePreferenceChanged(key, value); … … 268 279 269 280 private final void firePreferenceChanged(final String key, final String value) { 270 for (final PreferenceChangedListener l : listener) 281 for (final PreferenceChangedListener l : listener) { 271 282 l.preferenceChanged(key, value); 283 } 272 284 } 273 285 … … 282 294 setSystemProperties(); 283 295 final PrintWriter out = new PrintWriter(new OutputStreamWriter( 284 new FileOutputStream(getPreferencesDir() + "preferences"), "utf-8"), false); 296 new FileOutputStream(getPreferencesDir() + "preferences"), "utf-8"), false); 285 297 for (final Entry<String, String> e : properties.entrySet()) { 286 298 String s = defaults.get(e.getKey()); 287 299 /* don't save default values */ 288 if(s == null || !s.equals(e.getValue())) 300 if(s == null || !s.equals(e.getValue())) { 289 301 out.println(e.getKey() + "=" + e.getValue()); 302 } 290 303 } 291 304 out.close(); … … 300 313 properties.clear(); 301 314 final BufferedReader in = new BufferedReader(new InputStreamReader( 302 new FileInputStream(getPreferencesDir()+"preferences"), "utf-8")); 315 new FileInputStream(getPreferencesDir()+"preferences"), "utf-8")); 303 316 int lineNumber = 0; 304 317 ArrayList<Integer> errLines = new ArrayList<Integer>(); … … 322 335 if (prefDir.exists()) { 323 336 if(!prefDir.isDirectory()) { 324 JOptionPane.showMessageDialog(null, tr("Cannot open preferences directory: {0}",Main.pref.getPreferencesDir())); 337 OptionPaneUtil.showMessageDialog( 338 Main.parent, 339 tr("Cannot open preferences directory: {0}",Main.pref.getPreferencesDir()), 340 tr("Error"), 341 JOptionPane.ERROR_MESSAGE 342 ); 325 343 return; 326 344 } 327 } 328 else 345 } else { 329 346 prefDir.mkdirs(); 330 331 if (!new File(getPreferencesDir()+"preferences").exists()) 347 } 348 349 if (!new File(getPreferencesDir()+"preferences").exists()) { 332 350 resetToDefault(); 351 } 333 352 334 353 try { 335 if (reset) 354 if (reset) { 336 355 resetToDefault(); 337 else356 } else { 338 357 load(); 358 } 339 359 } catch (final IOException e1) { 340 360 e1.printStackTrace(); 341 361 String backup = getPreferencesDir() + "preferences.bak"; 342 JOptionPane.showMessageDialog(null, tr("Preferences file had errors. Making backup of old one to {0}.", backup)); 362 OptionPaneUtil.showMessageDialog( 363 Main.parent, 364 tr("Preferences file had errors. Making backup of old one to {0}.", backup), 365 tr("Error"), 366 JOptionPane.ERROR_MESSAGE 367 ); 343 368 new File(getPreferencesDir() + "preferences").renameTo(new File(backup)); 344 369 save(); … … 362 387 public Collection<Bookmark> loadBookmarks() throws IOException { 363 388 File bookmarkFile = new File(getPreferencesDir()+"bookmarks"); 364 if (!bookmarkFile.exists()) 389 if (!bookmarkFile.exists()) { 365 390 bookmarkFile.createNewFile(); 391 } 366 392 BufferedReader in = new BufferedReader(new InputStreamReader( 367 new FileInputStream(bookmarkFile), "utf-8")); 393 new FileInputStream(bookmarkFile), "utf-8")); 368 394 369 395 LinkedList<Bookmark> bookmarks = new LinkedList<Bookmark>(); … … 375 401 Bookmark b = new Bookmark(); 376 402 b.name = m.group(1); 377 for (int i = 0; i < b.latlon.length; ++i) 403 for (int i = 0; i < b.latlon.length; ++i) { 378 404 b.latlon[i] = Double.parseDouble(m.group(i+2)); 405 } 379 406 bookmarks.add(b); 380 407 } … … 387 414 public void saveBookmarks(Collection<Bookmark> bookmarks) throws IOException { 388 415 File bookmarkFile = new File(Main.pref.getPreferencesDir()+"bookmarks"); 389 if (!bookmarkFile.exists()) 416 if (!bookmarkFile.exists()) { 390 417 bookmarkFile.createNewFile(); 418 } 391 419 PrintWriter out = new PrintWriter(new OutputStreamWriter( 392 new FileOutputStream(bookmarkFile), "utf-8")); 420 new FileOutputStream(bookmarkFile), "utf-8")); 393 421 for (Bookmark b : bookmarks) { 394 422 out.print(b.name+"\u001e"); 395 for (int i = 0; i < b.latlon.length; ++i) 423 for (int i = 0; i < b.latlon.length; ++i) { 396 424 out.print(b.latlon[i]+(i<b.latlon.length-1?"\u001e":"")); 425 } 397 426 out.println(); 398 427 } … … 422 451 putDefault("color."+colName, ColorHelper.color2html(def)); 423 452 String colStr = specName != null ? get("color."+specName) : ""; 424 if(colStr.equals("")) 453 if(colStr.equals("")) { 425 454 colStr = get("color."+colName); 455 } 426 456 return colStr.equals("") ? def : ColorHelper.html2color(colStr); 427 457 } … … 481 511 putDefault(key, def); 482 512 String v = get(key); 483 if(v != null && v.length() != 0) 513 if(v != null && v.length() != 0) { 484 514 try { return Double.parseDouble(v); } catch(NumberFormatException e) {} 515 } 485 516 try { return Double.parseDouble(def); } catch(NumberFormatException e) {} 486 517 return 0.0; … … 494 525 for(String a : def) 495 526 { 496 if(d != null) 527 if(d != null) { 497 528 d += "\u001e" + a; 498 else529 } else { 499 530 d = a; 531 } 500 532 } 501 533 putDefault(key, d); … … 506 538 { 507 539 String r =s; 508 if(r.indexOf("§§§") > 0) /* history dialog */540 if(r.indexOf("§§§") > 0) { 509 541 r = r.replaceAll("§§§","\u001e"); 510 else /* old style ';' separation */542 } else { 511 543 r = r.replace(';','\u001e'); 544 } 512 545 if(!r.equals(s)) /* save the converted string */ 513 546 { … … 534 567 for(String a : val) 535 568 { 536 if(s != null) 569 if(s != null) { 537 570 s += "\u001e" + a; 538 else571 } else { 539 572 s = a; 573 } 540 574 } 541 575 } -
trunk/src/org/openstreetmap/josm/data/ServerSidePreferences.java
r1169 r1857 24 24 25 25 import org.openstreetmap.josm.Main; 26 import org.openstreetmap.josm.gui.OptionPaneUtil; 26 27 import org.openstreetmap.josm.io.OsmConnection; 27 28 import org.openstreetmap.josm.io.XmlWriter; … … 48 49 System.out.println("reading preferences from "+serverUrl); 49 50 URLConnection con = serverUrl.openConnection(); 50 if (con instanceof HttpURLConnection) addAuth((HttpURLConnection) con); 51 if (con instanceof HttpURLConnection) { 52 addAuth((HttpURLConnection) con); 53 } 51 54 con.connect(); 52 55 BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream())); … … 56 59 b.append("\n"); 57 60 } 58 if (con instanceof HttpURLConnection) ((HttpURLConnection) con).disconnect(); 61 if (con instanceof HttpURLConnection) { 62 ((HttpURLConnection) con).disconnect(); 63 } 59 64 return b.toString(); 60 65 } catch (IOException e) { … … 77 82 con.getInputStream().close(); 78 83 con.disconnect(); 79 JOptionPane.showMessageDialog(Main.parent, tr("Preferences stored on {0}", u.getHost())); 84 OptionPaneUtil.showMessageDialog( 85 Main.parent, 86 tr("Preferences stored on {0}", u.getHost()), 87 tr("Information"), 88 JOptionPane.INFORMATION_MESSAGE 89 ); 80 90 } catch (Exception e) { 81 91 e.printStackTrace(); 82 JOptionPane.showMessageDialog(Main.parent, tr("Could not upload preferences. Reason: {0}", e.getMessage())); 92 OptionPaneUtil.showMessageDialog( 93 Main.parent, 94 tr("Could not upload preferences. Reason: {0}", e.getMessage()), 95 tr("Error"), 96 JOptionPane.ERROR_MESSAGE 97 ); 83 98 } 84 99 } … … 119 134 public void download(String userName, String password) { 120 135 resetToDefault(); 121 if (!properties.containsKey("osm-server.username") && userName != null) 136 if (!properties.containsKey("osm-server.username") && userName != null) { 122 137 properties.put("osm-server.username", userName); 123 if (!properties.containsKey("osm-server.password") && password != null) 138 } 139 if (!properties.containsKey("osm-server.password") && password != null) { 124 140 properties.put("osm-server.password", password); 141 } 125 142 String cont = connection.download(); 126 143 if (cont == null) return; … … 128 145 try { 129 146 XmlObjectParser.Uniform<Prop> parser = new XmlObjectParser.Uniform<Prop>(in, "tag", Prop.class); 130 for (Prop p : parser) 147 for (Prop p : parser) { 131 148 properties.put(p.key, p.value); 149 } 132 150 } catch (RuntimeException e) { 133 151 e.printStackTrace(); … … 144 162 StringBuilder b = new StringBuilder("<preferences>\n"); 145 163 for (Entry<String, String> p : properties.entrySet()) { 146 if (p.getKey().equals("osm-server.password")) 164 if (p.getKey().equals("osm-server.password")) { 147 165 continue; // do not upload password. It would get stored in plain! 166 } 148 167 b.append("<tag key='"); 149 168 b.append(XmlWriter.encode(p.getKey())); … … 163 182 for (String line = in.readLine(); line != null; line = in.readLine()) { 164 183 StringTokenizer st = new StringTokenizer(line, ","); 165 if (st.countTokens() < 5) 184 if (st.countTokens() < 5) { 166 185 continue; 186 } 167 187 Bookmark b = new Bookmark(); 168 188 b.name = st.nextToken(); 169 189 try { 170 for (int i = 0; i < b.latlon.length; ++i) 190 for (int i = 0; i < b.latlon.length; ++i) { 171 191 b.latlon[i] = Double.parseDouble(st.nextToken()); 192 } 172 193 bookmarks.add(b); 173 194 } catch (NumberFormatException x) { -
trunk/src/org/openstreetmap/josm/data/conflict/ConflictCollection.java
r1750 r1857 67 67 } 68 68 69 protected void addConflict(Conflict<?> conflict) { 69 /** 70 * Adds a conflict to the collection 71 * 72 * @param conflict the conflict 73 * @exception IllegalStateException thrown, if this collection already includes a 74 * conflict for conflict.getMy() 75 */ 76 protected void addConflict(Conflict<?> conflict) throws IllegalStateException { 70 77 if (hasConflictForMy(conflict.getMy())) 71 78 throw new IllegalStateException(tr("already registered a conflict for primitive ''{0}''", conflict.getMy().toString())); -
trunk/src/org/openstreetmap/josm/data/projection/Lambert.java
r1849 r1857 13 13 import org.openstreetmap.josm.data.coor.LatLon; 14 14 import org.openstreetmap.josm.data.Bounds; 15 import org.openstreetmap.josm.gui.OptionPaneUtil; 15 16 16 17 public class Lambert implements Projection { … … 52 53 53 54 public static final double zoneLimits[] = { Math.toRadians(53.5 * 0.9), // between Zone 1 and Zone 2 (in grad *0.9) 54 Math.toRadians(50.5 * 0.9), // between Zone 2 and Zone 355 Math.toRadians(47.51963 * 0.9), // between Zone 3 and Zone 456 Math.toRadians(46.17821 * 0.9) };// lowest latitude of Zone 455 Math.toRadians(50.5 * 0.9), // between Zone 2 and Zone 3 56 Math.toRadians(47.51963 * 0.9), // between Zone 3 and Zone 4 57 Math.toRadians(46.17821 * 0.9) };// lowest latitude of Zone 4 57 58 58 59 public static final double cMinLonZones = Math.toRadians(-4.9074074074074059 * 0.9); … … 84 85 if (lt >= zoneLimits[3] && lt <= cMaxLatZone1 && lg >= cMinLonZones && lg <= cMaxLonZones) { 85 86 // zone I 86 if (lt > zoneLimits[0]) 87 if (lt > zoneLimits[0]) { 87 88 currentZone = 0; 88 // zone II 89 else if (lt > zoneLimits[1]) 89 } else if (lt > zoneLimits[1]) { 90 90 currentZone = 1; 91 // zone III 92 else if (lt > zoneLimits[2]) 91 } else if (lt > zoneLimits[2]) { 93 92 currentZone = 2; 94 // zone III or IV 95 else if (lt > zoneLimits[3]) 93 } else if (lt > zoneLimits[3]) 96 94 // Note: zone IV is dedicated to Corsica island and extends from 47.8 to 97 95 // 45.9 degrees of latitude. There is an overlap with zone III that can be 98 96 // solved only with longitude (covers Corsica if lon > 7.2 degree) 99 if (lg < Math.toRadians(8 * 0.9)) 97 if (lg < Math.toRadians(8 * 0.9)) { 100 98 currentZone = 2; 101 else99 } else { 102 100 currentZone = 3; 101 } 103 102 } else { 104 103 outOfLambertZones = true; // possible when MAX_LAT is used … … 109 108 } else if (layoutZone != currentZone) { 110 109 if ((currentZone < layoutZone && Math.abs(zoneLimits[currentZone] - lt) > cMaxOverlappingZones) 111 || (currentZone > layoutZone && Math.abs(zoneLimits[layoutZone] - lt) > cMaxOverlappingZones)) { 112 JOptionPane.showMessageDialog(Main.parent, 113 tr("IMPORTANT : data positioned far away from\n" 114 + "the current Lambert zone limits.\n" 115 + "Do not upload any data after this message.\n" 116 + "Undo your last action, save your work\n" 117 + "and start a new layer on the new zone.")); 110 || (currentZone > layoutZone && Math.abs(zoneLimits[layoutZone] - lt) > cMaxOverlappingZones)) { 111 OptionPaneUtil.showMessageDialog(Main.parent, 112 tr("IMPORTANT : data positioned far away from\n" 113 + "the current Lambert zone limits.\n" 114 + "Do not upload any data after this message.\n" 115 + "Undo your last action, save your work\n" 116 + "and start a new layer on the new zone."), 117 tr("Warning"), 118 JOptionPane.WARNING_MESSAGE); 118 119 layoutZone = -1; 119 120 } else { … … 130 131 public LatLon eastNorth2latlon(EastNorth p) { 131 132 LatLon geo; 132 if (layoutZone == -1) 133 if (layoutZone == -1) { 133 134 // possible until the Lambert zone is determined by latlon2eastNorth() with a valid LatLon 134 135 geo = Geographic(p, Xs[currentZone], Ys[currentZone], c[currentZone], n[currentZone]); 135 else136 } else { 136 137 geo = Geographic(p, Xs[layoutZone], Ys[layoutZone], c[layoutZone], n[layoutZone]); 138 } 137 139 // translate ellipsoid Clark => GRS80 (WGS83) 138 140 LatLon wgs = Clark2GRS80(geo); … … 197 199 double eslt = Ellipsoid.clarke.e * Math.sin(lat); 198 200 double nlt = 2.0 * Math.atan(Math.pow((1.0 + eslt) / (1.0 - eslt), Ellipsoid.clarke.e / 2.0) * l) - Math.PI 199 / 2.0;201 / 2.0; 200 202 delta = Math.abs(nlt - lat); 201 203 lat = nlt; … … 261 263 s2 *= s2; 262 264 double l = Math.atan((Z / norm) 263 / (1.0 - (ell.a * ell.e2 * Math.cos(lt) / (norm * Math.sqrt(1.0 - ell.e2 * s2))))); 265 / (1.0 - (ell.a * ell.e2 * Math.cos(lt) / (norm * Math.sqrt(1.0 - ell.e2 * s2))))); 264 266 delta = Math.abs(l - lt); 265 267 lt = l;
Note:
See TracChangeset
for help on using the changeset viewer.
