Ticket #3339: dirupl.2.patch
| File dirupl.2.patch, 6.1 KB (added by , 17 years ago) |
|---|
-
src/org/openstreetmap/josm/plugins/DirectUpload/UploadDataGui.java
27 27 import java.text.SimpleDateFormat; 28 28 import java.util.Date; 29 29 30 import javax.swing.JC heckBox;30 import javax.swing.JComboBox; 31 31 import javax.swing.JLabel; 32 32 import javax.swing.JPanel; 33 33 import javax.swing.JTextField; … … 44 44 import org.openstreetmap.josm.io.GpxWriter; 45 45 import org.openstreetmap.josm.tools.Base64; 46 46 import org.openstreetmap.josm.tools.GBC; 47 import org.openstreetmap.josm.tools.UrlLabel; 47 48 48 49 /** 49 50 * 50 51 * @author subhodip, xeen 51 52 */ 52 53 public 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 53 89 // User for log in when uploading trace 54 90 private String username = Main.pref.get("osm-server.username"); 55 91 private String password = Main.pref.get("osm-server.password"); … … 61 97 private JMultilineLabel OutputDisplay = new JMultilineLabel(" "); 62 98 private JTextField descriptionField = new JTextField(50); 63 99 private JTextField tagsField = new JTextField(50); 64 private JC heckBox publicCheckbox = new JCheckBox();100 private JComboBox visibilityCombo = new JComboBox(); 65 101 66 102 // Constants used when generating upload request 67 103 private static final String API_VERSION = "0.6"; … … 95 131 * @return JPanel with components 96 132 */ 97 133 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?)")); 100 140 101 141 JLabel descriptionLabel = new JLabel(tr("Description")); 102 142 descriptionField.setToolTipText(tr("Please enter Description about your trace.")); 103 143 104 JLabel tagsLabel = new JLabel(tr("Tags "));144 JLabel tagsLabel = new JLabel(tr("Tags (comma delimited)")); 105 145 tagsField.setToolTipText(tr("Please enter tags about your trace.")); 106 146 107 147 JPanel p = new JPanel(new GridBagLayout()); … … 115 155 p.add(descriptionLabel, GBC.eol().insets(0,10,0,0)); 116 156 p.add(descriptionField, GBC.eol().fill(GBC.HORIZONTAL)); 117 157 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()); 119 161 120 162 return p; 121 163 } … … 159 201 * @param boolean Shall the GPX track be public 160 202 * @param GpxData The GPX Data to upload 161 203 */ 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 { 163 205 progressMonitor.beginTask(null); 164 206 try { 165 207 if(checkForErrors(username, password, description, gpxData)) … … 167 209 168 210 // Clean description/tags from disallowed chars 169 211 description = description.replaceAll("[&?/\\\\]"," "); 170 tags = tags.replaceAll("[&?/\\\\. ,;]"," ");212 tags = tags.replaceAll("[&?/\\\\.;]"," "); 171 213 172 214 // Set progress dialog to indeterminate while connecting 173 215 progressMonitor.indeterminateSubTask(tr("Connecting...")); … … 178 220 writeGpxFile(baos, "file", gpxData); 179 221 writeField(baos, "description", description); 180 222 writeField(baos, "tags", (tags != null && tags.length() > 0) ? tags : ""); 181 writeField(baos, " public", isPublic ? "1" : "0");223 writeField(baos, "visibility", visi); 182 224 writeString(baos, "--" + BOUNDARY + "--" + LINE_END); 183 225 184 226 ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); … … 377 419 @Override protected void realRun() throws IOException { 378 420 upload(descriptionField.getText(), 379 421 tagsField.getText(), 380 publicCheckbox.isSelected(),422 visibility.desc2visi(visibilityCombo.getSelectedItem()).toString(), 381 423 ((GpxLayer)Main.map.mapView.getActiveLayer()).data, 382 424 progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false) 383 425 );
