Ignore:
Timestamp:
2011-08-07T09:08:29+02:00 (13 years ago)
Author:
jttt
Message:

Allow to specify custom pattern for marker text labels

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

Legend:

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

    r1685 r4282  
    88import org.openstreetmap.josm.data.coor.LatLon;
    99import org.openstreetmap.josm.tools.AudioPlayer;
     10import org.openstreetmap.josm.tools.template_engine.TemplateEngineDataProvider;
    1011
    1112/**
     
    2223    public boolean timeFromAudio = false; // as opposed to from the GPX track
    2324
    24     /**
    25      * Verifies the parameter whether a new AudioMarker can be created and return
    26      * one or return <code>null</code>.
    27      */
    28     public static AudioMarker create(LatLon ll, String text, String url, MarkerLayer parentLayer, double time, double offset) {
    29         try {
    30             return new AudioMarker(ll, text, new URL(url), parentLayer, time, offset);
    31         } catch (Exception ex) {
    32             return null;
    33         }
    34     }
    35 
    36     private AudioMarker(LatLon ll, String text, URL audioUrl, MarkerLayer parentLayer, double time, double offset) {
    37         super(ll, text, "speech.png", parentLayer, time, offset);
     25    public AudioMarker(LatLon ll, TemplateEngineDataProvider dataProvider, URL audioUrl, MarkerLayer parentLayer, double time, double offset) {
     26        super(ll, dataProvider, "speech.png", parentLayer, time, offset);
    3827        this.audioUrl = audioUrl;
    3928        this.syncOffset = 0.0;
     
    8473    }
    8574
    86     public static String inventName (double offset) {
    87         int wholeSeconds = (int)(offset + 0.5);
    88         if (wholeSeconds < 60)
    89             return Integer.toString(wholeSeconds);
    90         else if (wholeSeconds < 3600)
    91             return String.format("%d:%02d", wholeSeconds / 60, wholeSeconds % 60);
    92         else
    93             return String.format("%d:%02d:%02d", wholeSeconds / 3600, (wholeSeconds % 3600)/60, wholeSeconds % 60);
     75    @Override
     76    protected TemplateEntryProperty getTextTemplate() {
     77        return TemplateEntryProperty.forAudioMarker(parentLayer.getName());
    9478    }
    9579}
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/ButtonMarker.java

    r3396 r4282  
    1414import org.openstreetmap.josm.data.coor.LatLon;
    1515import org.openstreetmap.josm.gui.MapView;
     16import org.openstreetmap.josm.tools.template_engine.TemplateEngineDataProvider;
    1617
    1718/**
     
    2627
    2728    public ButtonMarker(LatLon ll, String buttonImage, MarkerLayer parentLayer, double time, double offset) {
    28         super(ll, "", buttonImage, parentLayer, time, offset);
     29        super(ll, null, buttonImage, parentLayer, time, offset);
    2930        buttonRectangle = new Rectangle(0, 0, symbol.getIconWidth(), symbol.getIconHeight());
    3031    }
    3132
    32     public ButtonMarker(LatLon ll, String text, String buttonImage, MarkerLayer parentLayer, double time, double offset) {
    33         super(ll, text, buttonImage, parentLayer, time, offset);
     33    public ButtonMarker(LatLon ll, TemplateEngineDataProvider dataProvider, String buttonImage, MarkerLayer parentLayer, double time, double offset) {
     34        super(ll, dataProvider, buttonImage, parentLayer, time, offset);
    3435        buttonRectangle = new Rectangle(0, 0, symbol.getIconWidth(), symbol.getIconHeight());
    3536    }
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/ImageMarker.java

    r1847 r4282  
    3434    public URL imageUrl;
    3535
    36     public static ImageMarker create(LatLon ll, String url, MarkerLayer parentLayer, double time, double offset) {
    37         try {
    38             return new ImageMarker(ll, new URL(url), parentLayer, time, offset);
    39         } catch (Exception ex) {
    40             return null;
    41         }
    42     }
    43 
    44     private ImageMarker(LatLon ll, URL imageUrl, MarkerLayer parentLayer, double time, double offset) {
     36    public ImageMarker(LatLon ll, URL imageUrl, MarkerLayer parentLayer, double time, double offset) {
    4537        super(ll, "photo.png", parentLayer, time, offset);
    4638        this.imageUrl = imageUrl;
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/Marker.java

    r4172 r4282  
    55import java.awt.Point;
    66import java.awt.event.ActionEvent;
    7 import java.awt.event.ActionListener;
    87import java.io.File;
    98import java.net.MalformedURLException;
    109import java.net.URL;
     10import java.util.ArrayList;
    1111import java.util.Collection;
    1212import java.util.HashMap;
    1313import java.util.LinkedList;
     14import java.util.List;
    1415import java.util.Map;
    1516
    1617import javax.swing.Icon;
    1718
     19import org.openstreetmap.josm.actions.search.SearchCompiler.Match;
     20import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent;
    1821import org.openstreetmap.josm.data.coor.CachedLatLon;
    1922import org.openstreetmap.josm.data.coor.EastNorth;
     
    2225import org.openstreetmap.josm.data.gpx.GpxLink;
    2326import org.openstreetmap.josm.data.gpx.WayPoint;
     27import org.openstreetmap.josm.data.preferences.CachedProperty;
    2428import org.openstreetmap.josm.data.preferences.IntegerProperty;
    2529import org.openstreetmap.josm.gui.MapView;
    2630import org.openstreetmap.josm.tools.ImageProvider;
     31import org.openstreetmap.josm.tools.template_engine.ParseError;
     32import org.openstreetmap.josm.tools.template_engine.TemplateEngineDataProvider;
     33import org.openstreetmap.josm.tools.template_engine.TemplateEntry;
     34import org.openstreetmap.josm.tools.template_engine.TemplateParser;
    2735
    2836/**
     
    6169 * @author Frederik Ramm <frederik@remote.org>
    6270 */
    63 public class Marker implements ActionListener {
    64     public final String text;
    65     public final Map<String,String> textMap = new HashMap<String,String>();
    66     public final Icon symbol;
    67     public final MarkerLayer parentLayer;
    68     public double time; /* absolute time of marker since epoch */
    69     public double offset; /* time offset in seconds from the gpx point from which it was derived,
    70                              may be adjusted later to sync with other data, so not final */
    71 
    72     private CachedLatLon coor;
    73 
    74     public final void setCoor(LatLon coor) {
    75         if(this.coor == null) {
    76             this.coor = new CachedLatLon(coor);
    77         } else {
    78             this.coor.setCoor(coor);
    79         }
    80     }
    81 
    82     public final LatLon getCoor() {
    83         return coor;
    84     }
    85 
    86     public final void setEastNorth(EastNorth eastNorth) {
    87         coor.setEastNorth(eastNorth);
    88     }
    89 
    90     public final EastNorth getEastNorth() {
    91         return coor.getEastNorth();
    92     }
     71public class Marker implements TemplateEngineDataProvider {
     72
     73    public static class TemplateEntryProperty extends CachedProperty<TemplateEntry> {
     74        // This class is a bit complicated because it supports both global and per layer settings. I've added per layer settings because
     75        // GPXSettingsPanel had possibility to set waypoint label but then I've realized that markers use different layer then gpx data
     76        // so per layer settings is useless. Anyway it's possible to specify marker layer pattern in Einstein preferences and maybe somebody
     77        // will make gui for it so I'm keeping it here
     78
     79        private final static Map<String, TemplateEntryProperty> cache = new HashMap<String, Marker.TemplateEntryProperty>();
     80
     81        // Legacy code - convert label from int to template engine expression
     82        private static final IntegerProperty PROP_LABEL = new IntegerProperty("draw.rawgps.layer.wpt", 0 );
     83        private static String getDefaultLabelPattern() {
     84            switch (PROP_LABEL.get()) {
     85            case 1:
     86                return LABEL_PATTERN_NAME;
     87            case 2:
     88                return LABEL_PATTERN_DESC;
     89            case 0:
     90            case 3:
     91                return LABEL_PATTERN_AUTO;
     92            default:
     93                return "";
     94            }
     95        }
     96
     97        public static TemplateEntryProperty forMarker(String layerName) {
     98            String key = "draw.rawgps.layer.wpt.pattern";
     99            if (layerName != null) {
     100                key += "." + layerName;
     101            }
     102            TemplateEntryProperty result = cache.get(key);
     103            if (result == null) {
     104                String defaultValue = layerName == null?getDefaultLabelPattern():"";
     105                TemplateEntryProperty parent = layerName == null?null:forMarker(null);
     106                result = new TemplateEntryProperty(key, defaultValue, parent);
     107                cache.put(key, result);
     108            }
     109            return result;
     110        }
     111
     112        public static TemplateEntryProperty forAudioMarker(String layerName) {
     113            String key = "draw.rawgps.layer.audiowpt.pattern";
     114            if (layerName != null) {
     115                key += "." + layerName;
     116            }
     117            TemplateEntryProperty result = cache.get(key);
     118            if (result == null) {
     119                String defaultValue = layerName == null?"?{ '{name}' | '{desc}' | '{" + Marker.MARKER_FORMATTED_OFFSET + "}' }":"";
     120                TemplateEntryProperty parent = layerName == null?null:forAudioMarker(null);
     121                result = new TemplateEntryProperty(key, defaultValue, parent);
     122                cache.put(key, result);
     123            }
     124            return result;
     125        }
     126
     127        private TemplateEntryProperty parent;
     128
     129
     130        private TemplateEntryProperty(String key, String defaultValue, TemplateEntryProperty parent) {
     131            super(key, defaultValue);
     132            this.parent = parent;
     133            updateValue(); // Needs to be called because parent wasn't know in super constructor
     134        }
     135
     136        @Override
     137        protected TemplateEntry fromString(String s) {
     138            try {
     139                return new TemplateParser(s).parse();
     140            } catch (ParseError e) {
     141                System.out.println(String.format("Unable to parse template engine pattern '%s' for property %s. Using default ('%s') instead",
     142                        s, getKey(), defaultValue));
     143                return getDefaultValue();
     144            }
     145        }
     146
     147        @Override
     148        public String getDefaultValueAsString() {
     149            if (parent == null)
     150                return super.getDefaultValueAsString();
     151            else
     152                return parent.getAsString();
     153        }
     154
     155        @Override
     156        public void preferenceChanged(PreferenceChangeEvent e) {
     157            if (e.getKey().equals(key) || (parent != null && e.getKey().equals(parent.getKey()))) {
     158                updateValue();
     159            }
     160        }
     161    }
     162
    93163
    94164    /**
     
    97167     * stuff).
    98168     */
    99     public static LinkedList<MarkerProducers> markerProducers = new LinkedList<MarkerProducers>();
    100 
    101     private static final IntegerProperty PROP_LABEL = new IntegerProperty("draw.rawgps.layer.wpt", 0 );
    102     private static final String[] labelAttributes = new String[] {"name", "desc"};
     169    public static List<MarkerProducers> markerProducers = new LinkedList<MarkerProducers>();
    103170
    104171    // Add one Maker specifying the default behaviour.
     
    110177                // cheapest way to check whether "link" object exists and is a non-empty
    111178                // collection of GpxLink objects...
    112                 try {
    113                     for (GpxLink oneLink : (Collection<GpxLink>) wpt.attr.get(GpxData.META_LINKS)) {
     179                Collection<GpxLink> links = (Collection<GpxLink>)wpt.attr.get(GpxData.META_LINKS);
     180                if (links != null) {
     181                    for (GpxLink oneLink : links ) {
    114182                        uri = oneLink.uri;
    115183                        break;
    116184                    }
    117                 } catch (Exception ex) {}
    118 
    119                 // Try a relative file:// url, if the link is not in an URL-compatible form
    120                 if (relativePath != null && uri != null && !isWellFormedAddress(uri)) {
    121                     uri = new File(relativePath.getParentFile(), uri).toURI().toString();
    122185                }
    123186
    124                 Map<String,String> nameDesc = new HashMap<String,String>();
    125                 for(String attribute : labelAttributes) {
    126                     if (wpt.attr.containsKey(attribute)) {
    127                         nameDesc.put(attribute, wpt.getString(attribute));
     187                URL url = null;
     188                if (uri != null) {
     189                    try {
     190                        url = new URL(uri);
     191                    } catch (MalformedURLException e) {
     192                        // Try a relative file:// url, if the link is not in an URL-compatible form
     193                        if (relativePath != null) {
     194                            try {
     195                                url = new File(relativePath.getParentFile(), uri).toURI().toURL();
     196                            } catch (MalformedURLException e1) {
     197                                System.err.println("Unable to convert uri " + uri + " to URL: "  + e1.getMessage());
     198                            }
     199                        }
    128200                    }
    129201                }
    130202
    131                 if (uri == null) {
     203
     204                if (url == null) {
    132205                    String symbolName = wpt.getString("symbol");
    133206                    if (symbolName == null) {
    134207                        symbolName = wpt.getString("sym");
    135208                    }
    136                     return new Marker(wpt.getCoor(), nameDesc, symbolName, parentLayer, time, offset);
     209                    return new Marker(wpt.getCoor(), wpt, symbolName, parentLayer, time, offset);
    137210                }
    138                 else if (uri.endsWith(".wav"))
    139                     return AudioMarker.create(wpt.getCoor(), getText(nameDesc), uri, parentLayer, time, offset);
    140                 else if (uri.endsWith(".png") || uri.endsWith(".jpg") || uri.endsWith(".jpeg") || uri.endsWith(".gif"))
    141                     return ImageMarker.create(wpt.getCoor(), uri, parentLayer, time, offset);
     211                else if (url.toString().endsWith(".wav"))
     212                    return new AudioMarker(wpt.getCoor(), wpt, url, parentLayer, time, offset);
     213                else if (url.toString().endsWith(".png") || url.toString().endsWith(".jpg") || url.toString().endsWith(".jpeg") || url.toString().endsWith(".gif"))
     214                    return new ImageMarker(wpt.getCoor(), url, parentLayer, time, offset);
    142215                else
    143                     return WebMarker.create(wpt.getCoor(), uri, parentLayer, time, offset);
    144             }
    145 
    146             private boolean isWellFormedAddress(String link) {
    147                 try {
    148                     new URL(link);
    149                     return true;
    150                 } catch (MalformedURLException x) {
    151                     return false;
    152                 }
     216                    return new WebMarker(wpt.getCoor(), url, parentLayer, time, offset);
    153217            }
    154218        });
    155     }
    156 
    157     public Marker(LatLon ll, String text, String iconName, MarkerLayer parentLayer, double time, double offset) {
    158         setCoor(ll);
    159         if (text == null || text.length() == 0) {
    160             this.text = null;
    161         }
    162         else {
    163             this.text = text;
    164         }
    165         this.offset = offset;
    166         this.time = time;
    167         this.symbol = ImageProvider.getIfAvailable("markers",iconName);
    168         this.parentLayer = parentLayer;
    169     }
    170 
    171     public Marker(LatLon ll, Map<String,String> textMap, String iconName, MarkerLayer parentLayer, double time, double offset) {
    172         setCoor(ll);
    173         if (textMap != null) {
    174             this.textMap.clear();
    175             this.textMap.putAll(textMap);
    176         }
    177 
    178         this.text = null;
    179         this.offset = offset;
    180         this.time = time;
    181         // /* ICON(markers/) */"Bridge"
    182         // /* ICON(markers/) */"Crossing"
    183         this.symbol = ImageProvider.getIfAvailable("markers",iconName);
    184         this.parentLayer = parentLayer;
    185     }
    186 
    187     /**
    188      * Checks whether the marker display area contains the given point.
    189      * Markers not interested in mouse clicks may always return false.
    190      *
    191      * @param p The point to check
    192      * @return <code>true</code> if the marker "hotspot" contains the point.
    193      */
    194     public boolean containsPoint(Point p) {
    195         return false;
    196     }
    197 
    198     /**
    199      * Called when the mouse is clicked in the marker's hotspot. Never
    200      * called for markers which always return false from containsPoint.
    201      *
    202      * @param ev A dummy ActionEvent
    203      */
    204     public void actionPerformed(ActionEvent ev) {
    205     }
    206 
    207     /**
    208      * Paints the marker.
    209      * @param g graphics context
    210      * @param mv map view
    211      * @param mousePressed true if the left mouse button is pressed
    212      */
    213     public void paint(Graphics g, MapView mv, boolean mousePressed, boolean showTextOrIcon) {
    214         Point screen = mv.getPoint(getEastNorth());
    215         if (symbol != null && showTextOrIcon) {
    216             symbol.paintIcon(mv, g, screen.x-symbol.getIconWidth()/2, screen.y-symbol.getIconHeight()/2);
    217         } else {
    218             g.drawLine(screen.x-2, screen.y-2, screen.x+2, screen.y+2);
    219             g.drawLine(screen.x+2, screen.y-2, screen.x-2, screen.y+2);
    220         }
    221 
    222         String labelText = getText();
    223         if ((labelText != null) && showTextOrIcon) {
    224             g.drawString(labelText, screen.x+4, screen.y+2);
    225         }
    226219    }
    227220
     
    246239    }
    247240
    248     /**
    249      * Returns an AudioMarker derived from this Marker and the provided uri
    250      * Subclasses of specific marker types override this to return null as they can't
    251      * be turned into AudioMarkers. This includes AudioMarkers themselves, as they
    252      * already have audio.
     241    public static final String MARKER_OFFSET = "waypointOffset";
     242    public static final String MARKER_FORMATTED_OFFSET = "formattedWaypointOffset";
     243
     244    public static final String LABEL_PATTERN_AUTO = "?{ '{name} - {desc}' | '{name}' | '{desc}' }";
     245    public static final String LABEL_PATTERN_NAME = "{name}";
     246    public static final String LABEL_PATTERN_DESC = "{desc}";
     247
     248
     249    private final TemplateEngineDataProvider dataProvider;
     250    public final Icon symbol;
     251    public final MarkerLayer parentLayer;
     252    public double time; /* absolute time of marker since epoch */
     253    public double offset; /* time offset in seconds from the gpx point from which it was derived,
     254                             may be adjusted later to sync with other data, so not final */
     255
     256    private String cachedText;
     257    private int textVersion = -1;
     258    private CachedLatLon coor;
     259
     260    public Marker(LatLon ll, TemplateEngineDataProvider dataProvider, String iconName, MarkerLayer parentLayer, double time, double offset) {
     261        setCoor(ll);
     262
     263        this.offset = offset;
     264        this.time = time;
     265        // /* ICON(markers/) */"Bridge"
     266        // /* ICON(markers/) */"Crossing"
     267        this.symbol = ImageProvider.getIfAvailable("markers",iconName);
     268        this.parentLayer = parentLayer;
     269
     270        this.dataProvider = dataProvider;
     271    }
     272
     273    public final void setCoor(LatLon coor) {
     274        if(this.coor == null) {
     275            this.coor = new CachedLatLon(coor);
     276        } else {
     277            this.coor.setCoor(coor);
     278        }
     279    }
     280
     281    public final LatLon getCoor() {
     282        return coor;
     283    }
     284
     285    public final void setEastNorth(EastNorth eastNorth) {
     286        coor.setEastNorth(eastNorth);
     287    }
     288
     289    public final EastNorth getEastNorth() {
     290        return coor.getEastNorth();
     291    }
     292
     293
     294    /**
     295     * Checks whether the marker display area contains the given point.
     296     * Markers not interested in mouse clicks may always return false.
    253297     *
    254      * @param uri uri of wave file
    255      * @return AudioMarker
    256      */
    257 
    258     public AudioMarker audioMarkerFromMarker(String uri) {
    259         AudioMarker audioMarker = AudioMarker.create(getCoor(), this.getText(), uri, this.parentLayer, this.time, this.offset);
    260         return audioMarker;
     298     * @param p The point to check
     299     * @return <code>true</code> if the marker "hotspot" contains the point.
     300     */
     301    public boolean containsPoint(Point p) {
     302        return false;
     303    }
     304
     305    /**
     306     * Called when the mouse is clicked in the marker's hotspot. Never
     307     * called for markers which always return false from containsPoint.
     308     *
     309     * @param ev A dummy ActionEvent
     310     */
     311    public void actionPerformed(ActionEvent ev) {
     312    }
     313
     314
     315    /**
     316     * Paints the marker.
     317     * @param g graphics context
     318     * @param mv map view
     319     * @param mousePressed true if the left mouse button is pressed
     320     */
     321    public void paint(Graphics g, MapView mv, boolean mousePressed, boolean showTextOrIcon) {
     322        Point screen = mv.getPoint(getEastNorth());
     323        if (symbol != null && showTextOrIcon) {
     324            symbol.paintIcon(mv, g, screen.x-symbol.getIconWidth()/2, screen.y-symbol.getIconHeight()/2);
     325        } else {
     326            g.drawLine(screen.x-2, screen.y-2, screen.x+2, screen.y+2);
     327            g.drawLine(screen.x+2, screen.y-2, screen.x-2, screen.y+2);
     328        }
     329
     330        String labelText = getText();
     331        if ((labelText != null) && showTextOrIcon) {
     332            g.drawString(labelText, screen.x+4, screen.y+2);
     333        }
     334    }
     335
     336
     337    protected TemplateEntryProperty getTextTemplate() {
     338        return TemplateEntryProperty.forMarker(parentLayer.getName());
    261339    }
    262340
     
    266344     */
    267345    public String getText() {
    268         if (this.text != null )
    269             return this.text;
     346        TemplateEntryProperty property = getTextTemplate();
     347        if (property.getUpdateCount() != textVersion) {
     348            TemplateEntry templateEntry = property.get();
     349            StringBuilder sb = new StringBuilder();
     350            templateEntry.appendText(sb, this);
     351
     352            cachedText = sb.toString();
     353            textVersion = property.getUpdateCount();
     354        }
     355        return cachedText;
     356    }
     357
     358    @Override
     359    public List<String> getTemplateKeys() {
     360        List<String> result;
     361        if (dataProvider != null) {
     362            result = dataProvider.getTemplateKeys();
     363        } else {
     364            result = new ArrayList<String>();
     365        }
     366        result.add(MARKER_FORMATTED_OFFSET);
     367        result.add(MARKER_OFFSET);
     368        return result;
     369    }
     370
     371    private String formatOffset () {
     372        int wholeSeconds = (int)(offset + 0.5);
     373        if (wholeSeconds < 60)
     374            return Integer.toString(wholeSeconds);
     375        else if (wholeSeconds < 3600)
     376            return String.format("%d:%02d", wholeSeconds / 60, wholeSeconds % 60);
    270377        else
    271             return getText(this.textMap);
    272     }
    273 
    274     /**
    275      * Returns the Text which should be displayed, depending on chosen preference.
    276      * The possible attributes are read from textMap.
    277      *
    278      * @param textMap A map with available texts/attributes
    279      * @return Text
    280      */
    281     private static String getText(Map<String,String> textMap) {
    282         String text = "";
    283 
    284         if (textMap != null && !textMap.isEmpty()) {
    285             switch(PROP_LABEL.get())
    286             {
    287                 // name
    288                 case 1:
    289                 {
    290                     if (textMap.containsKey("name")) {
    291                         text = textMap.get("name");
    292                     }
    293                     break;
    294                 }
    295 
    296                 // desc
    297                 case 2:
    298                 {
    299                     if (textMap.containsKey("desc")) {
    300                         text = textMap.get("desc");
    301                     }
    302                     break;
    303                 }
    304 
    305                 // auto
    306                 case 0:
    307                 // both
    308                 case 3:
    309                 {
    310                     if (textMap.containsKey("name")) {
    311                         text = textMap.get("name");
    312 
    313                         if (textMap.containsKey("desc")) {
    314                             if (PROP_LABEL.get() != 0 || !text.equals(textMap.get("desc"))) {
    315                                 text += " - " + textMap.get("desc");
    316                             }
    317                         }
    318                     }
    319                     else if (textMap.containsKey("desc")) {
    320                         text = textMap.get("desc");
    321                     }
    322                     break;
    323                 }
    324 
    325                 // none
    326                 case 4:
    327                 default:
    328                 {
    329                     text = "";
    330                     break;
    331                 }
    332             }
    333         }
    334 
    335         return text;
     378            return String.format("%d:%02d:%02d", wholeSeconds / 3600, (wholeSeconds % 3600)/60, wholeSeconds % 60);
     379    }
     380
     381    @Override
     382    public Object getTemplateValue(String name) {
     383        if (MARKER_FORMATTED_OFFSET.equals(name))
     384            return formatOffset();
     385        else if (MARKER_OFFSET.equals(name))
     386            return offset;
     387        else if (dataProvider != null)
     388            return dataProvider.getTemplateValue(name);
     389        else
     390            return null;
     391    }
     392
     393    @Override
     394    public boolean evaluateCondition(Match condition) {
     395        throw new UnsupportedOperationException();
    336396    }
    337397}
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java

    r4230 r4282  
    3232import org.openstreetmap.josm.data.coor.LatLon;
    3333import org.openstreetmap.josm.data.gpx.GpxData;
    34 import org.openstreetmap.josm.data.gpx.GpxLink;
    3534import org.openstreetmap.josm.data.gpx.WayPoint;
    3635import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
     
    7271        this.fromLayer = fromLayer;
    7372        double firstTime = -1.0;
    74         String lastLinkedFile = "";
    7573
    7674        for (WayPoint wpt : indata.waypoints) {
    77             /* calculate time differences in waypoints */
    7875            double time = wpt.time;
    79             boolean wpt_has_link = wpt.attr.containsKey(GpxData.META_LINKS);
    80             if (firstTime < 0 && wpt_has_link) {
     76            if (firstTime < 0) {
    8177                firstTime = time;
    82                 for (GpxLink oneLink : (Collection<GpxLink>) wpt.attr.get(GpxData.META_LINKS)) {
    83                     lastLinkedFile = oneLink.uri;
    84                     break;
    85                 }
    86             }
    87             if (wpt_has_link) {
    88                 for (GpxLink oneLink : (Collection<GpxLink>) wpt.attr.get(GpxData.META_LINKS)) {
    89                     if (!oneLink.uri.equals(lastLinkedFile)) {
    90                         firstTime = time;
    91                     }
    92                     lastLinkedFile = oneLink.uri;
    93                     break;
    94                 }
    9578            }
    9679            Marker m = Marker.createMarker(wpt, indata.storageFile, this, time, time - firstTime);
     
    274257                    tr("Error"),
    275258                    JOptionPane.ERROR_MESSAGE
    276             );
     259                    );
    277260            return null;
    278261        }
    279262
    280263        // make our new marker
    281         AudioMarker newAudioMarker = AudioMarker.create(coor,
    282                 AudioMarker.inventName(offset), AudioPlayer.url().toString(), this, time, offset);
     264        AudioMarker newAudioMarker = new AudioMarker(coor,
     265                null, AudioPlayer.url(), this, time, offset);
    283266
    284267        // insert it at the right place in a copy the collection
     
    425408                        tr("Warning"),
    426409                        JOptionPane.WARNING_MESSAGE
    427                 );
     410                        );
    428411                return;
    429412            }
     
    432415                JOptionPane.showMessageDialog(
    433416                        Main.parent,
    434                         tr("Audio synchronized at point {0}.", recent.text),
     417                        tr("Audio synchronized at point {0}.", recent.getText()),
    435418                        tr("Information"),
    436419                        JOptionPane.INFORMATION_MESSAGE
    437                 );
     420                        );
    438421            } else {
    439422                JOptionPane.showMessageDialog(
     
    442425                        tr("Error"),
    443426                        JOptionPane.ERROR_MESSAGE
    444                 );
     427                        );
    445428            }
    446429        }
     
    462445                        tr("Warning"),
    463446                        JOptionPane.WARNING_MESSAGE
    464                 );
     447                        );
    465448                return;
    466449            }
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/PlayHeadMarker.java

    r2907 r4282  
    5959
    6060    private PlayHeadMarker() {
    61         super(new LatLon(0.0,0.0), "",
     61        super(new LatLon(0.0,0.0), null,
    6262                Main.pref.get("marker.audiotracericon", "audio-tracer"),
    6363                null, -1.0, 0.0);
     
    171171                    tr("Warning"),
    172172                    JOptionPane.WARNING_MESSAGE
    173             );
     173                    );
    174174            endDrag(true);
    175175        } else {
     
    226226                        tr("Warning"),
    227227                        JOptionPane.WARNING_MESSAGE
    228                 );
     228                        );
    229229                endDrag(true);
    230230                return;
     
    241241                    tr("Error"),
    242242                    JOptionPane.ERROR_MESSAGE
    243             );
     243                    );
    244244            endDrag(true);
    245245        }
     
    247247            JOptionPane.showMessageDialog(
    248248                    Main.parent,
    249                     tr("Audio synchronized at point {0}.", ca.text),
     249                    tr("Audio synchronized at point {0}.", ca.getText()),
    250250                    tr("Information"),
    251251                    JOptionPane.INFORMATION_MESSAGE
    252             );
     252                    );
    253253            setCoor(ca.getCoor());
    254254            endDrag(false);
     
    259259                    tr("Error"),
    260260                    JOptionPane.ERROR_MESSAGE
    261             );
     261                    );
    262262            endDrag(true);
    263263        }
     
    294294            return;
    295295        double audioTime = recentlyPlayedMarker.time +
    296         AudioPlayer.position() -
    297         recentlyPlayedMarker.offset -
    298         recentlyPlayedMarker.syncOffset;
     296                AudioPlayer.position() -
     297                recentlyPlayedMarker.offset -
     298                recentlyPlayedMarker.syncOffset;
    299299        if (Math.abs(audioTime - time) < animationInterval)
    300300            return;
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/WebMarker.java

    r2017 r4282  
    2121public class WebMarker extends ButtonMarker {
    2222
    23     public URL webUrl;
     23    public final URL webUrl;
    2424
    25     public static WebMarker create (LatLon ll, String url, MarkerLayer parentLayer, double time, double offset) {
    26         try {
    27             return new WebMarker(ll, new URL(url), parentLayer, time, offset);
    28         } catch (Exception ex) {
    29             return null;
    30         }
    31     }
    32 
    33     private WebMarker(LatLon ll, URL webUrl, MarkerLayer parentLayer, double time, double offset) {
     25    public WebMarker(LatLon ll, URL webUrl, MarkerLayer parentLayer, double time, double offset) {
    3426        super(ll, "web.png", parentLayer, time, offset);
    3527        this.webUrl = webUrl;
     
    4133            JOptionPane.showMessageDialog(Main.parent,
    4234                    "<html><b>" +
    43                     tr("There was an error while trying to display the URL for this marker") +
    44                     "</b><br>" + tr("(URL was: ") + webUrl.toString() + ")" + "<br>" + error,
    45                     tr("Error displaying URL"), JOptionPane.ERROR_MESSAGE);
     35                            tr("There was an error while trying to display the URL for this marker") +
     36                            "</b><br>" + tr("(URL was: ") + webUrl.toString() + ")" + "<br>" + error,
     37                            tr("Error displaying URL"), JOptionPane.ERROR_MESSAGE);
    4638        }
    4739    }
Note: See TracChangeset for help on using the changeset viewer.