Ignore:
Timestamp:
2013-10-06T17:26:37+02:00 (11 years ago)
Author:
Don-vip
Message:

Improve feedback when clicking a web marker pointing to a local file fails

Location:
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/ButtonMarker.java

    r4284 r6299  
    4949        Point screen = mv.getPoint(getEastNorth());
    5050        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);
    5252        Border b;
    5353        Point mousePosition = mv.getMousePosition();
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/Marker.java

    r6162 r6299  
    22package org.openstreetmap.josm.gui.layer.markerlayer;
    33
     4import java.awt.AlphaComposite;
     5import java.awt.Color;
    46import java.awt.Graphics;
     7import java.awt.Graphics2D;
    58import java.awt.Point;
    69import java.awt.event.ActionEvent;
     10import java.awt.image.BufferedImage;
    711import java.io.File;
    812import java.net.MalformedURLException;
     
    1923import java.util.TimeZone;
    2024
    21 import javax.swing.Icon;
     25import javax.swing.ImageIcon;
    2226
    2327import org.openstreetmap.josm.Main;
     
    279283    private final String text;
    280284
    281     public final Icon symbol;
     285    protected final ImageIcon symbol;
     286    private BufferedImage redSymbol = null;
    282287    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;
    286292
    287293    private String cachedText;
    288294    private int textVersion = -1;
    289295    private CachedLatLon coor;
     296   
     297    private boolean erroneous = false;
    290298
    291299    public Marker(LatLon ll, TemplateEngineDataProvider dataProvider, String iconName, MarkerLayer parentLayer, double time, double offset) {
     
    294302        this.offset = offset;
    295303        this.time = time;
    296         // /* ICON(markers/) */"Bridge"
    297         // /* ICON(markers/) */"Crossing"
    298304        this.symbol = iconName != null ? ImageProvider.getIfAvailable("markers",iconName) : null;
    299305        this.parentLayer = parentLayer;
     
    308314        this.offset = offset;
    309315        this.time = time;
    310         // /* ICON(markers/) */"Bridge"
    311         // /* ICON(markers/) */"Crossing"
    312316        this.symbol = iconName != null ? ImageProvider.getIfAvailable("markers",iconName) : null;
    313317        this.parentLayer = parentLayer;
     
    340344    }
    341345
     346    /**
     347     * Sets the marker's coordinates.
     348     * @param coor The marker's coordinates (lat/lon)
     349     */
    342350    public final void setCoor(LatLon coor) {
    343351        this.coor = new CachedLatLon(coor);
    344352    }
    345353
     354    /**
     355     * Returns the marker's coordinates.
     356     * @return The marker's coordinates (lat/lon)
     357     */
    346358    public final LatLon getCoor() {
    347359        return coor;
    348360    }
    349361
     362    /**
     363     * Sets the marker's projected coordinates.
     364     * @param eastNorth The marker's projected coordinates (easting/northing)
     365     */
    350366    public final void setEastNorth(EastNorth eastNorth) {
    351367        this.coor = new CachedLatLon(eastNorth);
    352368    }
    353369
     370    /**
     371     * Returns the marker's projected coordinates.
     372     * @return The marker's projected coordinates (easting/northing)
     373     */
    354374    public final EastNorth getEastNorth() {
    355375        return coor.getEastNorth();
    356376    }
    357 
    358377
    359378    /**
     
    377396    }
    378397
    379 
    380398    /**
    381399     * Paints the marker.
     
    388406        Point screen = mv.getPoint(getEastNorth());
    389407        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);
    391409        } else {
    392410            g.drawLine(screen.x-2, screen.y-2, screen.x+2, screen.y+2);
     
    399417        }
    400418    }
    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    }
    402439
    403440    protected TemplateEntryProperty getTextTemplate() {
     
    465502        throw new UnsupportedOperationException();
    466503    }
     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    }
    467525}
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/PlayHeadMarker.java

    r6296 r6299  
    274274        if (time < 0.0) return;
    275275        Point screen = mv.getPoint(getEastNorth());
    276         symbol.paintIcon(mv, g, screen.x, screen.y);
     276        paintIcon(mv, g, screen.x, screen.y);
    277277    }
    278278
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/WebMarker.java

    r5684 r6299  
    55
    66import java.awt.event.ActionEvent;
     7import java.io.File;
    78import java.net.URL;
    89import java.util.Collections;
     
    1516import org.openstreetmap.josm.data.gpx.GpxLink;
    1617import org.openstreetmap.josm.data.gpx.WayPoint;
     18import org.openstreetmap.josm.gui.Notification;
     19import org.openstreetmap.josm.tools.CheckParameterUtil;
    1720import org.openstreetmap.josm.tools.OpenBrowser;
    1821
     
    2528public class WebMarker extends ButtonMarker {
    2629
    27     public final URL webUrl;
     30    private final URL webUrl;
    2831
    2932    public WebMarker(LatLon ll, URL webUrl, MarkerLayer parentLayer, double time, double offset) {
    3033        super(ll, "web.png", parentLayer, time, offset);
     34        CheckParameterUtil.ensureParameterNotNull(webUrl, "webUrl");
    3135        this.webUrl = webUrl;
    3236    }
     
    3539        String error = OpenBrowser.displayUrl(webUrl.toString());
    3640        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();
    4250        }
    4351    }
     
    5159        return wpt;
    5260    }
     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    }
    5375}
Note: See TracChangeset for help on using the changeset viewer.