Ignore:
Timestamp:
2009-08-31T10:03:20+02:00 (15 years ago)
Author:
guggis
Message:

applied #3339: patch by xeen: Plugin DirectUpload breaks up tags containing spaces

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/DirectUpload/src/org/openstreetmap/josm/plugins/DirectUpload/UploadDataGui.java

    r16582 r17401  
    2828import java.util.Date;
    2929
    30 import javax.swing.JCheckBox;
     30import javax.swing.JComboBox;
    3131import javax.swing.JLabel;
    3232import javax.swing.JPanel;
     
    4545import org.openstreetmap.josm.tools.Base64;
    4646import org.openstreetmap.josm.tools.GBC;
     47import org.openstreetmap.josm.tools.UrlLabel;
    4748
    4849/**
     
    5152 */
    5253public class UploadDataGui extends ExtendedDialog {
     54    /**
     55     * This enum contains the possible values for the visibility field and their
     56     * explanation. Provides some methods for easier handling.
     57     */
     58    private enum visibility {
     59        PRIVATE      (tr("Private (only shared as anonymous, unordered points)")),
     60        PUBLIC       (tr("Public (shown in trace list and as anonymous, unordered points)")),
     61        TRACKABLE    (tr("Trackable (only shared as anonymous, ordered points with timestamps)")),
     62        IDENTIFIABLE (tr("Identifiable (shown in trace list and as identifiable, ordered points with timestamps)"));
     63       
     64        public final String description;
     65        visibility(String description) {
     66            this.description = description;
     67        }
     68       
     69        /**
     70         * "Converts" a given description into the actual enum. Returns null if no matching description
     71         * is found.
     72         * @param desc The description to look for
     73         * @return visibility or null
     74         */
     75        public static visibility desc2visi(Object desc) {
     76            for (visibility v : visibility.values()) {
     77                if(desc.equals((String)v.description))
     78                    return v;
     79            }
     80            return null;
     81        }
     82       
     83        public String toString() {
     84            return this.name().toLowerCase();
     85        }
     86    }
     87
     88       
    5389    // User for log in when uploading trace
    5490    private String username = Main.pref.get("osm-server.username");
     
    6298    private JTextField descriptionField = new JTextField(50);
    6399    private JTextField tagsField = new JTextField(50);
    64     private JCheckBox publicCheckbox = new JCheckBox();
     100    private JComboBox visibilityCombo = new JComboBox();
    65101
    66102    // Constants used when generating upload request
     
    96132     */
    97133    private JPanel initComponents() {
    98         publicCheckbox.setText(tr("Public"));
    99         publicCheckbox.setToolTipText(tr("Selected makes your trace public in openstreetmap.org"));
     134        JLabel visibilityLabel = new JLabel(tr("Visibility"));
     135        visibilityLabel.setToolTipText(tr("Defines the visibility of your trace for other OSM users."));
     136        for(visibility v : visibility.values()) {
     137                visibilityCombo.addItem((String)v.description);
     138        }
     139        UrlLabel visiUrl = new UrlLabel(tr("http://wiki.openstreetmap.org/wiki/Visibility_of_GPS_traces"), tr("(What does that mean?)"));
    100140
    101141        JLabel descriptionLabel = new JLabel(tr("Description"));
    102142        descriptionField.setToolTipText(tr("Please enter Description about your trace."));
    103143
    104         JLabel tagsLabel = new JLabel(tr("Tags"));
     144        JLabel tagsLabel = new JLabel(tr("Tags (comma delimited)"));
    105145        tagsField.setToolTipText(tr("Please enter tags about your trace."));
    106146
     
    116156        p.add(descriptionField, GBC.eol().fill(GBC.HORIZONTAL));
    117157
    118         p.add(publicCheckbox, GBC.eol());
     158        p.add(visibilityLabel, GBC.std().insets(0,10,0,0));
     159        p.add(visiUrl, GBC.eol().insets(0,10,0,0));
     160        p.add(visibilityCombo, GBC.eol());
    119161
    120162        return p;
     
    160202     * @param GpxData The GPX Data to upload
    161203     */
    162     private void upload(String description, String tags, Boolean isPublic, GpxData gpxData, ProgressMonitor progressMonitor) throws IOException {
     204    private void upload(String description, String tags, String visi, GpxData gpxData, ProgressMonitor progressMonitor) throws IOException {
    163205        progressMonitor.beginTask(null);
    164206        try {
     
    168210                // Clean description/tags from disallowed chars
    169211                description = description.replaceAll("[&?/\\\\]"," ");
    170                 tags = tags.replaceAll("[&?/\\\\.,;]"," ");
     212                tags = tags.replaceAll("[&?/\\\\.;]"," ");
    171213
    172214                // Set progress dialog to indeterminate while connecting
     
    179221                        writeField(baos, "description", description);
    180222                        writeField(baos, "tags", (tags != null && tags.length() > 0) ? tags : "");
    181                         writeField(baos, "public", isPublic ? "1" : "0");
     223                        writeField(baos, "visibility", visi);
    182224                        writeString(baos, "--" + BOUNDARY + "--" + LINE_END);
    183225
     
    378420                  upload(descriptionField.getText(),
    379421                         tagsField.getText(),
    380                          publicCheckbox.isSelected(),
     422                         visibility.desc2visi(visibilityCombo.getSelectedItem()).toString(),
    381423                         ((GpxLayer)Main.map.mapView.getActiveLayer()).data,
    382424                         progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)
Note: See TracChangeset for help on using the changeset viewer.