Ticket #3617: WaypointConfigurableTextPreferences.patch

File WaypointConfigurableTextPreferences.patch, 12.1 KB (added by reini122, 16 years ago)
  • src/org/openstreetmap/josm/gui/layer/markerlayer/ButtonMarker.java

    # This patch file was generated by NetBeans IDE
    # This patch can be applied using context Tools: Patch action on respective folder.
    # It uses platform neutral UTF-8 encoding and \n newlines.
    # Above lines and this line are ignored by the patching process.
     
    2525    private Rectangle buttonRectangle;
    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    }
    3131
     
    6161        Rectangle r = new Rectangle(buttonRectangle);
    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    }
    6870}
  • src/org/openstreetmap/josm/gui/layer/markerlayer/Marker.java

     
    99import java.net.MalformedURLException;
    1010import java.net.URL;
    1111import java.util.Collection;
     12import java.util.HashMap;
    1213import java.util.LinkedList;
    1314
     15import java.util.Map;
    1416import javax.swing.Icon;
    1517
    1618import org.openstreetmap.josm.data.coor.CachedLatLon;
     
    1921import org.openstreetmap.josm.data.gpx.GpxData;
    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;
    2527
     
    6062 */
    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;
    6568    public double time; /* absolute time of marker since epoch */
     
    9598     */
    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.
    101105    static {
     
    117121                    uri = new File(relativePath.getParentFile(), uri).toURI().toString();
    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");
     124                Map<String,String> name_desc = new HashMap<String,String>();
     125                for(String attribute:labelAttributes) {
     126                    if (wpt.attr.containsKey(attribute)) {
     127                        name_desc.put(attribute,wpt.getString(attribute));
    127128                    }
    128                 } else if ("name".equals(PROP_NAME_DESC.get())) {
    129                     if (wpt.attr.containsKey("name")) {
    130                         name_desc = wpt.getString("name");
    131129                    }
    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");
    141130
    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");
    147                     }
    148                 }
    149 
    150131                if (uri == null) {
    151132                    String symbolName = wpt.getString("symbol");
    152133                    if (symbolName == null) {
     
    155136                    return new Marker(wpt.getCoor(), name_desc, 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(name_desc), 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);
    161142                else
     
    175156
    176157    public Marker(LatLon ll, String text, String iconName, MarkerLayer parentLayer, double time, double offset) {
    177158        setCoor(ll);
     159        if (text != null && text.length() == 0) {
     160            this.text = null;
     161        }
     162        else {
    178163        this.text = text;
     164        }
    179165        this.offset = offset;
    180166        this.time = time;
    181167        this.symbol = ImageProvider.getIfAvailable("markers",iconName);
    182168        this.parentLayer = parentLayer;
    183169    }
    184170
     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            for(String txt:textMap.keySet()) {
     175                String tmpText = textMap.get(txt);
     176                if (tmpText!=null) {
     177                    this.textMap.put(txt,tmpText);
     178                }
     179            }
     180        }
     181        this.text = null;
     182        this.offset = offset;
     183        this.time = time;
     184        this.symbol = ImageProvider.getIfAvailable("markers",iconName);
     185        this.parentLayer = parentLayer;
     186    }
     187
    185188    /**
    186189     * Checks whether the marker display area contains the given point.
    187190     * Markers not interested in mouse clicks may always return false.
     
    217220            g.drawLine(screen.x+2, screen.y-2, screen.x-2, screen.y+2);
    218221        }
    219222
    220         if ((text != null) && showTextOrIcon) {
    221             g.drawString(text, screen.x+4, screen.y+2);
     223        String labelText = getText();
     224        if ((labelText != null) && showTextOrIcon) {
     225            g.drawString(labelText, screen.x+4, screen.y+2);
    222226        }
    223227    }
    224228
     
    253257     */
    254258
    255259    public AudioMarker audioMarkerFromMarker(String uri) {
    256         AudioMarker audioMarker = AudioMarker.create(getCoor(), this.text, uri, this.parentLayer, this.time, this.offset);
     260        AudioMarker audioMarker = AudioMarker.create(getCoor(), this.getText(), uri, this.parentLayer, this.time, this.offset);
    257261        return audioMarker;
    258262    }
     263
     264    /**
     265     * Returns the Text which should be displayed, depending on chosen preference
     266     * @return Text
     267     */
     268    public String getText() {
     269        if (this.text != null ) {
     270            return this.text;
    259271}
     272        else {
     273            return getText(this.textMap);
     274        }
     275    }
     276
     277    /**
     278     * Returns the Text which should be displayed, depending on chosen preference.
     279     * The possible attributes are read from textMap.
     280     *
     281     * @param textMap A map with available texts/attributes
     282     * @return Text
     283     */
     284    private static String getText(Map<String,String> textMap) {
     285        String text = "";
     286
     287        if (textMap != null && !textMap.isEmpty()) {
     288            switch(PROP_LABEL.get())
     289            {
     290                // name
     291                case 1:
     292                {
     293                    if (textMap.containsKey("name")) {
     294                        text = textMap.get("name");
     295                    }
     296                    break;
     297                }
     298
     299                // desc
     300                case 2:
     301                {
     302                    if (textMap.containsKey("desc")) {
     303                        text = textMap.get("desc");
     304                    }
     305                    break;
     306                }
     307
     308                // auto
     309                case 0:
     310                // both
     311                case 3:
     312                {
     313                    if (textMap.containsKey("name")) {
     314                        text = textMap.get("name");
     315
     316                        if (textMap.containsKey("desc")) {
     317                            if (PROP_LABEL.get() != 0 || !text.equals(textMap.get("desc"))) {
     318                                text += " - " + textMap.get("desc");
     319                            }
     320                        }
     321                    }
     322                    else if (textMap.containsKey("desc")) {
     323                        text = textMap.get("desc");
     324                    }
     325                    break;
     326                }
     327
     328                // none
     329                case 4:
     330                default:
     331                {
     332                    text = "";
     333                    break;
     334                }
     335            }
     336        }
     337
     338        return text;
     339    }
     340}
  • src/org/openstreetmap/josm/gui/preferences/DrawingPreference.java

     
    5858    private JCheckBox inactive = new JCheckBox(tr("Draw inactive layers in other color"));
    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) {
    6364        gui.display.setPreferredSize(new Dimension(400,600));
     
    203204        panel.add(colorTypeVelocityTune, GBC.eop().insets(5,0,0,5));
    204205        panel.add(colorTypeDilution, GBC.eol().insets(40,0,0,0));
    205206
     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));
     214
    206215        panel.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.BOTH));
    207216        JScrollPane scrollpane = new JScrollPane(panel);
    208217        scrollpane.setBorder(BorderFactory.createEmptyBorder( 0, 0, 0, 0 ));
     
    305314        } }
    306315        else { vn = 0; }
    307316        Main.pref.putInteger("mappaint.node.virtual-size", vn);
     317        if (Main.pref.getInteger("draw.rawgps.layer.wpt",-1) != waypointLabel.getSelectedIndex()) {
     318            Main.pref.putInteger( "draw.rawgps.layer.wpt", waypointLabel.getSelectedIndex());
     319            Main.map.repaint();
     320        }
    308321        return false;
    309322    }
    310323}