- Timestamp:
- 2013-10-06T17:26:37+02:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r6296 r6299 293 293 */ 294 294 public static void error(Throwable t) { 295 error(t.getClass().getName()+": "+t.getMessage() );295 error(t.getClass().getName()+": "+t.getMessage().trim()); 296 296 } 297 297 … … 302 302 */ 303 303 public static void warn(Throwable t) { 304 warn(t.getClass().getName()+": "+t.getMessage() );304 warn(t.getClass().getName()+": "+t.getMessage().trim()); 305 305 } 306 306 -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/ButtonMarker.java
r4284 r6299 49 49 Point screen = mv.getPoint(getEastNorth()); 50 50 buttonRectangle.setLocation(screen.x+4, screen.y+2); 51 symbol.paintIcon(mv, g, screen.x+4, screen.y+2);51 paintIcon(mv, g, screen.x+4, screen.y+2); 52 52 Border b; 53 53 Point mousePosition = mv.getMousePosition(); -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/Marker.java
r6162 r6299 2 2 package org.openstreetmap.josm.gui.layer.markerlayer; 3 3 4 import java.awt.AlphaComposite; 5 import java.awt.Color; 4 6 import java.awt.Graphics; 7 import java.awt.Graphics2D; 5 8 import java.awt.Point; 6 9 import java.awt.event.ActionEvent; 10 import java.awt.image.BufferedImage; 7 11 import java.io.File; 8 12 import java.net.MalformedURLException; … … 19 23 import java.util.TimeZone; 20 24 21 import javax.swing.I con;25 import javax.swing.ImageIcon; 22 26 23 27 import org.openstreetmap.josm.Main; … … 279 283 private final String text; 280 284 281 public final Icon symbol; 285 protected final ImageIcon symbol; 286 private BufferedImage redSymbol = null; 282 287 public final MarkerLayer parentLayer; 283 public double time; /* absolute time of marker in seconds since epoch */ 284 public double offset; /* time offset in seconds from the gpx point from which it was derived, 285 may be adjusted later to sync with other data, so not final */ 288 /** Absolute time of marker in seconds since epoch */ 289 public double time; 290 /** Time offset in seconds from the gpx point from which it was derived, may be adjusted later to sync with other data, so not final */ 291 public double offset; 286 292 287 293 private String cachedText; 288 294 private int textVersion = -1; 289 295 private CachedLatLon coor; 296 297 private boolean erroneous = false; 290 298 291 299 public Marker(LatLon ll, TemplateEngineDataProvider dataProvider, String iconName, MarkerLayer parentLayer, double time, double offset) { … … 294 302 this.offset = offset; 295 303 this.time = time; 296 // /* ICON(markers/) */"Bridge"297 // /* ICON(markers/) */"Crossing"298 304 this.symbol = iconName != null ? ImageProvider.getIfAvailable("markers",iconName) : null; 299 305 this.parentLayer = parentLayer; … … 308 314 this.offset = offset; 309 315 this.time = time; 310 // /* ICON(markers/) */"Bridge"311 // /* ICON(markers/) */"Crossing"312 316 this.symbol = iconName != null ? ImageProvider.getIfAvailable("markers",iconName) : null; 313 317 this.parentLayer = parentLayer; … … 340 344 } 341 345 346 /** 347 * Sets the marker's coordinates. 348 * @param coor The marker's coordinates (lat/lon) 349 */ 342 350 public final void setCoor(LatLon coor) { 343 351 this.coor = new CachedLatLon(coor); 344 352 } 345 353 354 /** 355 * Returns the marker's coordinates. 356 * @return The marker's coordinates (lat/lon) 357 */ 346 358 public final LatLon getCoor() { 347 359 return coor; 348 360 } 349 361 362 /** 363 * Sets the marker's projected coordinates. 364 * @param eastNorth The marker's projected coordinates (easting/northing) 365 */ 350 366 public final void setEastNorth(EastNorth eastNorth) { 351 367 this.coor = new CachedLatLon(eastNorth); 352 368 } 353 369 370 /** 371 * Returns the marker's projected coordinates. 372 * @return The marker's projected coordinates (easting/northing) 373 */ 354 374 public final EastNorth getEastNorth() { 355 375 return coor.getEastNorth(); 356 376 } 357 358 377 359 378 /** … … 377 396 } 378 397 379 380 398 /** 381 399 * Paints the marker. … … 388 406 Point screen = mv.getPoint(getEastNorth()); 389 407 if (symbol != null && showTextOrIcon) { 390 symbol.paintIcon(mv, g, screen.x-symbol.getIconWidth()/2, screen.y-symbol.getIconHeight()/2);408 paintIcon(mv, g, screen.x-symbol.getIconWidth()/2, screen.y-symbol.getIconHeight()/2); 391 409 } else { 392 410 g.drawLine(screen.x-2, screen.y-2, screen.x+2, screen.y+2); … … 399 417 } 400 418 } 401 419 420 protected void paintIcon(MapView mv, Graphics g, int x, int y) { 421 if (!erroneous) { 422 symbol.paintIcon(mv, g, x, y); 423 } else { 424 if (redSymbol == null) { 425 int width = symbol.getIconWidth(); 426 int height = symbol.getIconHeight(); 427 428 redSymbol = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); 429 Graphics2D gbi = redSymbol.createGraphics(); 430 gbi.drawImage(symbol.getImage(), 0, 0, null); 431 gbi.setColor(Color.RED); 432 gbi.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.666f)); 433 gbi.fillRect(0, 0, width, height); 434 gbi.dispose(); 435 } 436 g.drawImage(redSymbol, x, y, mv); 437 } 438 } 402 439 403 440 protected TemplateEntryProperty getTextTemplate() { … … 465 502 throw new UnsupportedOperationException(); 466 503 } 504 505 /** 506 * Determines if this marker is erroneous. 507 * @return {@code true} if this markers has any kind of error, {@code false} otherwise 508 * @since 6299 509 */ 510 public final boolean isErroneous() { 511 return erroneous; 512 } 513 514 /** 515 * Sets this marker erroneous or not. 516 * @param erroneous {@code true} if this markers has any kind of error, {@code false} otherwise 517 * @since 6299 518 */ 519 public final void setErroneous(boolean erroneous) { 520 this.erroneous = erroneous; 521 if (!erroneous) { 522 redSymbol = null; 523 } 524 } 467 525 } -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/PlayHeadMarker.java
r6296 r6299 274 274 if (time < 0.0) return; 275 275 Point screen = mv.getPoint(getEastNorth()); 276 symbol.paintIcon(mv, g, screen.x, screen.y);276 paintIcon(mv, g, screen.x, screen.y); 277 277 } 278 278 -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/WebMarker.java
r5684 r6299 5 5 6 6 import java.awt.event.ActionEvent; 7 import java.io.File; 7 8 import java.net.URL; 8 9 import java.util.Collections; … … 15 16 import org.openstreetmap.josm.data.gpx.GpxLink; 16 17 import org.openstreetmap.josm.data.gpx.WayPoint; 18 import org.openstreetmap.josm.gui.Notification; 19 import org.openstreetmap.josm.tools.CheckParameterUtil; 17 20 import org.openstreetmap.josm.tools.OpenBrowser; 18 21 … … 25 28 public class WebMarker extends ButtonMarker { 26 29 27 p ublicfinal URL webUrl;30 private final URL webUrl; 28 31 29 32 public WebMarker(LatLon ll, URL webUrl, MarkerLayer parentLayer, double time, double offset) { 30 33 super(ll, "web.png", parentLayer, time, offset); 34 CheckParameterUtil.ensureParameterNotNull(webUrl, "webUrl"); 31 35 this.webUrl = webUrl; 32 36 } … … 35 39 String error = OpenBrowser.displayUrl(webUrl.toString()); 36 40 if (error != null) { 37 JOptionPane.showMessageDialog(Main.parent, 38 "<html><b>" + 39 tr("There was an error while trying to display the URL for this marker") + 40 "</b><br>" + tr("(URL was: ") + webUrl.toString() + ")" + "<br>" + error, 41 tr("Error displaying URL"), JOptionPane.ERROR_MESSAGE); 41 setErroneous(true); 42 new Notification( 43 "<b>" + tr("There was an error while trying to display the URL for this marker") + "</b><br>" + 44 tr("(URL was: ") + webUrl.toString() + ")" + "<br>" + error) 45 .setIcon(JOptionPane.ERROR_MESSAGE) 46 .setDuration(Notification.TIME_LONG) 47 .show(); 48 } else { 49 updateErroneous(); 42 50 } 43 51 } … … 51 59 return wpt; 52 60 } 61 62 private final void updateErroneous() { 63 if ("file".equals(webUrl.getProtocol())) { 64 String path = webUrl.getPath(); 65 try { 66 setErroneous(path.isEmpty() || !new File(path).exists()); 67 } catch (Exception e) { 68 Main.warn(e); 69 setErroneous(true); 70 } 71 } else { 72 setErroneous(false); 73 } 74 } 53 75 } -
trunk/src/org/openstreetmap/josm/tools/OpenBrowser.java
r6248 r6299 29 29 30 30 /** 31 * Displays an external URI using platform associated software. 32 * A web resource will launch platform's browser, an audio file URI will launch audio player, etc. 33 * @param uri The URI to display 31 34 * @return <code>null</code> for success or a string in case of an error. 32 35 * @throws IllegalStateException thrown if no platform is set to which opening the URL can be dispatched, … … 34 37 */ 35 38 public static String displayUrl(URI uri) { 39 CheckParameterUtil.ensureParameterNotNull(uri, "uri"); 36 40 if (Main.applet) { 37 41 try { … … 43 47 } 44 48 } 49 50 Main.info(tr("Opening URL: {0}", uri)); 45 51 46 52 if (Desktop.isDesktopSupported()) { 47 53 try { 48 try { 54 if (Main.platform instanceof PlatformHookWindows) { 55 // Desktop API works fine under Windows, so we don't try any fallback in case of I/O exceptions because it's not API's fault 49 56 Desktop.getDesktop().browse(uri); 50 } catch (IOException e) { 51 // Workaround for KDE (Desktop API is severely flawed) 52 // see http://bugs.sun.com/view_bug.do?bug_id=6486393 53 Main.warn("Desktop class failed. Platform dependent fall back for open url in browser."); 54 displayUrlFallback(uri); 57 } else { 58 // This is not the case with some Linux environments (see below), and not sure about Mac OS X, so we need to handle API failure 59 try { 60 Desktop.getDesktop().browse(uri); 61 } catch (IOException e) { 62 // Workaround for KDE (Desktop API is severely flawed) 63 // see https://bugs.openjdk.java.net/browse/JDK-6486393 64 Main.warn("Desktop class failed. Platform dependent fall back for open url in browser."); 65 displayUrlFallback(uri); 66 } 55 67 } 56 68 } catch (Exception e) { 57 e.printStackTrace();69 Main.warn(e); 58 70 return e.getMessage(); 59 71 } … … 69 81 } 70 82 83 /** 84 * Displays an external URL using platform associated software. 85 * A web resource will launch platform's browser, an audio file URL will launch audio player, etc. 86 * @param url The URL to display 87 * @return <code>null</code> for success or a string in case of an error. 88 * @throws IllegalStateException thrown if no platform is set to which opening the URL can be dispatched, 89 * {@link Main#platform} 90 */ 71 91 public static String displayUrl(String url) { 72 92 try {
Note:
See TracChangeset
for help on using the changeset viewer.