Changeset 9514 in josm for trunk/src/org
- Timestamp:
- 2016-01-17T22:38:38+01:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/UploadAction.java
r9462 r9514 7 7 import java.awt.event.ActionEvent; 8 8 import java.awt.event.KeyEvent; 9 import java.util.HashMap;10 9 import java.util.LinkedList; 11 10 import java.util.List; 12 import java.util.Map;13 11 14 12 import javax.swing.JOptionPane; 15 import javax.swing.SwingUtilities;16 13 17 14 import org.openstreetmap.josm.Main; … … 234 231 235 232 final UploadDialog dialog = UploadDialog.getUploadDialog(); 236 // If we simply set the changeset comment here, it would be 237 // overridden by subsequent events in EDT that are caused by 238 // dialog creation. The current solution is to queue this operation 239 // after these events. 240 // TODO: find better way to initialize the comment field 241 SwingUtilities.invokeLater(new Runnable() { 242 @Override 243 public void run() { 244 final Map<String, String> tags = new HashMap<>(layer.data.getChangeSetTags()); 245 if (!tags.containsKey("source")) { 246 tags.put("source", dialog.getLastChangesetSourceFromHistory()); 247 } 248 if (!tags.containsKey("comment")) { 249 tags.put("comment", dialog.getLastChangesetCommentFromHistory()); 250 } 251 dialog.setDefaultChangesetTags(tags); 252 } 253 }); 233 dialog.setChangesetTags(layer.data); 254 234 dialog.setUploadedPrimitives(apiData); 255 235 dialog.setVisible(true); -
trunk/src/org/openstreetmap/josm/gui/io/ChangesetManagementPanel.java
r9078 r9514 290 290 Changeset cs = (Changeset) cbOpenChangesets.getSelectedItem(); 291 291 if (cs == null) return; 292 changesetCommentModel.setComment(cs.get("comment"));293 292 firePropertyChange(SELECTED_CHANGESET_PROP, null, cs); 294 293 } -
trunk/src/org/openstreetmap/josm/gui/io/TagSettingsPanel.java
r9246 r9514 3 3 4 4 import java.awt.BorderLayout; 5 import java.util. HashMap;5 import java.util.Collections; 6 6 import java.util.Map; 7 7 import java.util.Observable; … … 13 13 14 14 import org.openstreetmap.josm.Main; 15 import org.openstreetmap.josm.data.Version;16 15 import org.openstreetmap.josm.data.osm.Changeset; 16 import org.openstreetmap.josm.data.osm.DataSet; 17 17 import org.openstreetmap.josm.gui.tagging.TagEditorPanel; 18 18 import org.openstreetmap.josm.gui.tagging.TagModel; … … 26 26 private final transient ChangesetCommentModel changesetCommentModel; 27 27 private final transient ChangesetCommentModel changesetSourceModel; 28 /** tags that applied to uploaded changesets by default*/29 private final transient Map<String, String> defaultTags = new HashMap<>();30 28 31 29 protected void build() { … … 81 79 82 80 /** 83 * Initialize panel from changeset.84 * @param cs changeset81 * Initialize panel from the given tags. 82 * @param tags the tags used to initialize the panel 85 83 */ 86 public void initFromChangeset(Changeset cs) { 87 Map<String, String> tags = getDefaultTags(); 88 if (cs != null) { 89 tags.putAll(cs.getKeys()); 90 } 91 if (tags.get("comment") == null) { 92 tags.put("comment", getTagEditorValue("comment")); 93 } 94 if (tags.get("source") == null) { 95 tags.put("source", getTagEditorValue("source")); 96 } 97 String agent = Version.getInstance().getAgentString(false); 98 String created_by = tags.get("created_by"); 99 if (created_by == null || created_by.isEmpty()) { 100 tags.put("created_by", agent); 101 } else if (!created_by.contains(agent)) { 102 tags.put("created_by", created_by + ';' + agent); 103 } 84 public void initFromTags(Map<String, String> tags) { 104 85 pnlTagEditor.getModel().initFromTags(tags); 105 86 } … … 115 96 116 97 /** 117 * Replies the map with the default tags.118 * @ return the map with the default tags98 * @return an empty map 99 * @deprecated No longer supported, returns an empty map 119 100 */ 101 @Deprecated 120 102 public Map<String, String> getDefaultTags() { 121 Map<String, String> tags = new HashMap<>(); 122 tags.putAll(defaultTags); 123 return tags; 103 return Collections.emptyMap(); 124 104 } 125 105 126 106 /** 127 * Sets the map with the default tags.128 * @ param tags the map with the default tags107 * @param tags ignored 108 * @deprecated No longer supported, does nothing; use {@link UploadDialog#setChangesetTags(DataSet)} instead! 129 109 */ 110 @Deprecated 130 111 public void setDefaultTags(Map<String, String> tags) { 131 defaultTags.clear();132 defaultTags.putAll(tags);133 tableChanged(null);134 112 } 135 113 -
trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java
r8870 r9514 20 20 import java.util.Collection; 21 21 import java.util.Collections; 22 import java.util.HashMap; 23 import java.util.Iterator; 22 24 import java.util.List; 23 25 import java.util.Map; … … 39 41 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener; 40 42 import org.openstreetmap.josm.data.Preferences.Setting; 43 import org.openstreetmap.josm.data.Version; 41 44 import org.openstreetmap.josm.data.osm.Changeset; 45 import org.openstreetmap.josm.data.osm.DataSet; 42 46 import org.openstreetmap.josm.data.osm.OsmPrimitive; 43 47 import org.openstreetmap.josm.gui.ExtendedDialog; … … 101 105 private final transient ChangesetCommentModel changesetSourceModel = new ChangesetCommentModel(); 102 106 107 private transient DataSet dataSet; 108 103 109 /** 104 110 * builds the content panel for the upload dialog … … 194 200 // changes 195 201 // 202 pnlChangesetManagement.addPropertyChangeListener(this); 196 203 pnlChangesetManagement.addPropertyChangeListener( 197 204 pnlBasicUploadSettings.getUploadParameterSummaryPanel() … … 267 274 } 268 275 276 /** 277 * Sets the tags for this upload based on (later items overwrite earlier ones): 278 * <ul> 279 * <li>previous "source" and "comment" input</li> 280 * <li>the tags set in the dataset (see {@link DataSet#getChangeSetTags()})</li> 281 * <li>the tags from the selected open changeset</li> 282 * <li>the JOSM user agent (see {@link Version#getAgentString(boolean)})</li> 283 * </ul> 284 * 285 * @param dataSet to obtain the tags set in the dataset 286 */ 287 public void setChangesetTags(DataSet dataSet) { 288 final Map<String, String> tags = new HashMap<>(); 289 290 // obtain from previos input 291 tags.put("source", getLastChangesetSourceFromHistory()); 292 tags.put("comment", getLastChangesetCommentFromHistory()); 293 294 // obtain from dataset 295 if (dataSet != null) { 296 tags.putAll(dataSet.getChangeSetTags()); 297 } 298 this.dataSet = dataSet; 299 300 // obtain from selected open changeset 301 if (pnlChangesetManagement.getSelectedChangeset() != null) { 302 tags.putAll(pnlChangesetManagement.getSelectedChangeset().getKeys()); 303 } 304 305 // set/adapt created_by 306 final String agent = Version.getInstance().getAgentString(false); 307 final String created_by = tags.get("created_by"); 308 if (created_by == null || created_by.isEmpty()) { 309 tags.put("created_by", agent); 310 } else if (!created_by.contains(agent)) { 311 tags.put("created_by", created_by + ';' + agent); 312 } 313 314 // remove empty values 315 final Iterator<String> it = tags.keySet().iterator(); 316 while (it.hasNext()) { 317 final String v = tags.get(it.next()); 318 if (v == null || v.isEmpty()) { 319 it.remove(); 320 } 321 } 322 323 pnlTagSettings.initFromTags(tags); 324 pnlTagSettings.tableChanged(null); 325 } 326 269 327 @Override 270 328 public void rememberUserInput() { … … 280 338 pnlBasicUploadSettings.startUserInput(); 281 339 pnlTagSettings.startUserInput(); 282 pnlTagSettings.initFromChangeset(pnlChangesetManagement.getSelectedChangeset());283 340 pnlUploadStrategySelectionPanel.initFromPreferences(); 284 341 UploadParameterSummaryPanel pnl = pnlBasicUploadSettings.getUploadParameterSummaryPanel(); … … 310 367 } 311 368 369 /** 370 * @deprecated No longer supported, does nothing; use {@link #setChangesetTags(DataSet)} instead! 371 */ 372 @Deprecated 312 373 public void setDefaultChangesetTags(Map<String, String> tags) { 313 pnlTagSettings.setDefaultTags(tags);314 changesetCommentModel.setComment(tags.get("comment"));315 changesetSourceModel.setComment(tags.get("source"));316 374 } 317 375 … … 543 601 if (evt.getPropertyName().equals(ChangesetManagementPanel.SELECTED_CHANGESET_PROP)) { 544 602 Changeset cs = (Changeset) evt.getNewValue(); 603 setChangesetTags(dataSet); 545 604 if (cs == null) { 546 605 tpConfigPanels.setTitleAt(1, tr("Tags of new changeset"));
Note:
See TracChangeset
for help on using the changeset viewer.