Changeset 3396 in josm


Ignore:
Timestamp:
31.07.2010 16:28:43 (19 months ago)
Author:
bastiK
Message:

applied #3617 (patch by reini122) - Would like to see waypoint descriptions in JOSM

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
3 edited

Legend:

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

    r3237 r3396  
    2626 
    2727    public ButtonMarker(LatLon ll, String buttonImage, MarkerLayer parentLayer, double time, double offset) { 
    28         super(ll, null, buttonImage, parentLayer, time, offset); 
     28        super(ll, "", buttonImage, parentLayer, time, offset); 
    2929        buttonRectangle = new Rectangle(0, 0, symbol.getIconWidth(), symbol.getIconHeight()); 
    3030    } 
     
    6262        r.grow((inset.top+inset.bottom)/2, (inset.left+inset.right)/2); 
    6363        b.paintBorder(mv, g, r.x, r.y, r.width, r.height); 
    64         if ((text != null) && showTextOrIcon && Main.pref.getBoolean("marker.buttonlabels", true)) { 
    65             g.drawString(text, screen.x+4, screen.y+2); 
     64 
     65        String labelText = getText(); 
     66        if ((labelText != null) && showTextOrIcon && Main.pref.getBoolean("marker.buttonlabels", true)) { 
     67            g.drawString(labelText, screen.x+4, screen.y+2); 
    6668        } 
    6769    } 
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/Marker.java

    r3386 r3396  
    1010import java.net.URL; 
    1111import java.util.Collection; 
     12import java.util.HashMap; 
    1213import java.util.LinkedList; 
     14import java.util.Map; 
    1315 
    1416import javax.swing.Icon; 
     
    2022import org.openstreetmap.josm.data.gpx.GpxLink; 
    2123import org.openstreetmap.josm.data.gpx.WayPoint; 
    22 import org.openstreetmap.josm.data.preferences.StringProperty; 
     24import org.openstreetmap.josm.data.preferences.IntegerProperty; 
    2325import org.openstreetmap.josm.gui.MapView; 
    2426import org.openstreetmap.josm.tools.ImageProvider; 
     
    6163public class Marker implements ActionListener { 
    6264    public final String text; 
     65    public final Map<String,String> textMap = new HashMap<String,String>(); 
    6366    public final Icon symbol; 
    6467    public final MarkerLayer parentLayer; 
     
    9699    public static LinkedList<MarkerProducers> markerProducers = new LinkedList<MarkerProducers>(); 
    97100 
    98     private static final StringProperty PROP_NAME_DESC = new StringProperty( "draw.gpx.layer.wpt", "nameordesc" ); 
     101    private static final IntegerProperty PROP_LABEL = new IntegerProperty("draw.rawgps.layer.wpt", 0 ); 
     102    private static final String[] labelAttributes = new String[] {"name", "desc"}; 
    99103 
    100104    // Add one Maker specifying the default behaviour. 
     
    118122                } 
    119123 
    120                 String name_desc = ""; 
    121                 if (PROP_NAME_DESC.get() == null || "nameordesc".equals(PROP_NAME_DESC.get())) 
    122                 { 
    123                     if (wpt.attr.containsKey("name")) { 
    124                         name_desc = wpt.getString("name"); 
    125                     } else if (wpt.attr.containsKey("desc")) { 
    126                         name_desc = wpt.getString("desc"); 
    127                     } 
    128                 } else if ("name".equals(PROP_NAME_DESC.get())) { 
    129                     if (wpt.attr.containsKey("name")) { 
    130                         name_desc = wpt.getString("name"); 
    131                     } 
    132                 } 
    133                 else if ("desc".equals(PROP_NAME_DESC.get())) { 
    134                     if (wpt.attr.containsKey("desc")) { 
    135                         name_desc = wpt.getString("desc"); 
    136                     } 
    137                 } 
    138                 else if ("both".equals(PROP_NAME_DESC.get()) ) { 
    139                     if (wpt.attr.containsKey("name")) { 
    140                         name_desc = wpt.getString("name"); 
    141  
    142                         if (wpt.attr.containsKey("desc")) { 
    143                             name_desc += " (" + wpt.getString("desc") + ")" ; 
    144                         } 
    145                     } else if (wpt.attr.containsKey("desc")) { 
    146                         name_desc = wpt.getString("desc"); 
     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)); 
    147128                    } 
    148129                } 
     
    153134                        symbolName = wpt.getString("sym"); 
    154135                    } 
    155                     return new Marker(wpt.getCoor(), name_desc, symbolName, parentLayer, time, offset); 
     136                    return new Marker(wpt.getCoor(), nameDesc, symbolName, parentLayer, time, offset); 
    156137                } 
    157138                else if (uri.endsWith(".wav")) 
    158                     return AudioMarker.create(wpt.getCoor(), name_desc, uri, parentLayer, time, offset); 
     139                    return AudioMarker.create(wpt.getCoor(), getText(nameDesc), uri, parentLayer, time, offset); 
    159140                else if (uri.endsWith(".png") || uri.endsWith(".jpg") || uri.endsWith(".jpeg") || uri.endsWith(".gif")) 
    160141                    return ImageMarker.create(wpt.getCoor(), uri, parentLayer, time, offset); 
     
    176157    public Marker(LatLon ll, String text, String iconName, MarkerLayer parentLayer, double time, double offset) { 
    177158        setCoor(ll); 
    178         this.text = text; 
     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; 
    179179        this.offset = offset; 
    180180        this.time = time; 
     
    218218        } 
    219219 
    220         if ((text != null) && showTextOrIcon) { 
    221             g.drawString(text, screen.x+4, screen.y+2); 
     220        String labelText = getText(); 
     221        if ((labelText != null) && showTextOrIcon) { 
     222            g.drawString(labelText, screen.x+4, screen.y+2); 
    222223        } 
    223224    } 
     
    254255 
    255256    public AudioMarker audioMarkerFromMarker(String uri) { 
    256         AudioMarker audioMarker = AudioMarker.create(getCoor(), this.text, uri, this.parentLayer, this.time, this.offset); 
     257        AudioMarker audioMarker = AudioMarker.create(getCoor(), this.getText(), uri, this.parentLayer, this.time, this.offset); 
    257258        return audioMarker; 
    258259    } 
     260 
     261    /** 
     262     * Returns the Text which should be displayed, depending on chosen preference 
     263     * @return Text 
     264     */ 
     265    public String getText() { 
     266        if (this.text != null ) { 
     267            return this.text; 
     268        } 
     269        else { 
     270            return getText(this.textMap); 
     271        } 
     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; 
     336    } 
    259337} 
  • trunk/src/org/openstreetmap/josm/gui/preferences/DrawingPreference.java

    r3298 r3396  
    5959    private JCheckBox useAntialiasing = new JCheckBox(tr("Smooth map graphics (antialiasing)")); 
    6060    private JCheckBox makeAutoMarkers = new JCheckBox(tr("Create markers when reading GPX.")); 
     61    private JComboBox waypointLabel = new JComboBox(new String[] {tr("Auto"), tr("Name"), tr("Desc"), tr("Both"), tr("None")}); 
    6162 
    6263    public void addGui(PreferenceTabbedPane gui) { 
     
    203204        panel.add(colorTypeVelocityTune, GBC.eop().insets(5,0,0,5)); 
    204205        panel.add(colorTypeDilution, GBC.eol().insets(40,0,0,0)); 
     206 
     207        // waypointLabel 
     208        panel.add(Box.createVerticalGlue(), GBC.eol().insets(0, 20, 0, 0)); 
     209 
     210        waypointLabel.setSelectedIndex(Main.pref.getInteger("draw.rawgps.layer.wpt", 0 )); 
     211        colorTypeDilution.setToolTipText(tr("Allows to change the labelling of track waypoints.")); 
     212        panel.add(new JLabel(tr("Waypoint labelling")), GBC.std().insets(20,0,0,0)); 
     213        panel.add(waypointLabel, GBC.eol().fill(GBC.HORIZONTAL).insets(5,0,0,5)); 
    205214 
    206215        panel.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.BOTH)); 
     
    301310        Main.pref.put("mappaint.use-antialiasing", useAntialiasing.isSelected()); 
    302311        int vn = Main.pref.getInteger("mappaint.node.virtual-size", 8); 
    303         if(virtualNodes.isSelected()) { if (vn < 1) { 
    304             vn = 8; 
    305         } } 
    306         else { vn = 0; } 
     312        if (virtualNodes.isSelected()) { 
     313            if (vn < 1) { 
     314                vn = 8; 
     315            } 
     316        } 
     317        else { 
     318            vn = 0; 
     319        } 
    307320        Main.pref.putInteger("mappaint.node.virtual-size", vn); 
     321        Main.pref.putInteger("draw.rawgps.layer.wpt", waypointLabel.getSelectedIndex()); 
    308322        return false; 
    309323    } 
Note: See TracChangeset for help on using the changeset viewer.