Changeset 9522 in josm for trunk/src/org
- Timestamp:
- 2016-01-18T00:15:58+01:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/io
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/io/TagSettingsPanel.java
r9514 r9522 19 19 import org.openstreetmap.josm.tools.CheckParameterUtil; 20 20 21 /** 22 * Tag settings panel of upload dialog. 23 * @since 2599 24 */ 21 25 public class TagSettingsPanel extends JPanel implements TableModelListener { 22 26 … … 26 30 private final transient ChangesetCommentModel changesetCommentModel; 27 31 private final transient ChangesetCommentModel changesetSourceModel; 28 29 protected void build() {30 setLayout(new BorderLayout());31 add(pnlTagEditor, BorderLayout.CENTER);32 }33 32 34 33 /** … … 50 49 } 51 50 51 protected void build() { 52 setLayout(new BorderLayout()); 53 add(pnlTagEditor, BorderLayout.CENTER); 54 } 55 52 56 protected void setProperty(String key, String value) { 53 if (value == null) { 54 value = ""; 55 } 56 value = value.trim(); 57 String val = (value == null ? "" : value).trim(); 57 58 String commentInTag = getTagEditorValue(key); 58 if (val ue.equals(commentInTag))59 if (val.equals(commentInTag)) 59 60 return; 60 61 61 if (val ue.isEmpty()) {62 if (val.isEmpty()) { 62 63 pnlTagEditor.getModel().delete(key); 63 64 return; … … 65 66 TagModel tag = pnlTagEditor.getModel().get(key); 66 67 if (tag == null) { 67 tag = new TagModel(key, val ue);68 tag = new TagModel(key, val); 68 69 pnlTagEditor.getModel().add(tag); 69 70 } else { 70 pnlTagEditor.getModel().updateTagValue(tag, val ue);71 pnlTagEditor.getModel().updateTagValue(tag, val); 71 72 } 72 73 } … … 74 75 protected String getTagEditorValue(String key) { 75 76 TagModel tag = pnlTagEditor.getModel().get(key); 76 if (tag == null) return null; 77 return tag.getValue(); 77 return tag == null ? null : tag.getValue(); 78 78 } 79 79 … … 110 110 @Deprecated 111 111 public void setDefaultTags(Map<String, String> tags) { 112 // Deprecated 112 113 } 113 114 115 /** 116 * Initializes the panel for user input 117 */ 114 118 public void startUserInput() { 115 119 pnlTagEditor.initAutoCompletion(Main.main.getEditLayer()); … … 128 132 * Observes the changeset comment model and keeps the tag editor in sync 129 133 * with the current changeset comment 130 *131 134 */ 132 135 class ChangesetCommentObserver implements Observer { … … 140 143 @Override 141 144 public void update(Observable o, Object arg) { 142 if (!(o instanceof ChangesetCommentModel)) return; 143 String newValue = (String) arg; 144 String oldValue = getTagEditorValue(key); 145 if (oldValue == null) { 146 oldValue = ""; 147 } 148 if (!oldValue.equals(newValue)) { 149 setProperty(key, (String) arg); 145 if (o instanceof ChangesetCommentModel) { 146 String newValue = (String) arg; 147 String oldValue = getTagEditorValue(key); 148 if (oldValue == null) { 149 oldValue = ""; 150 } 151 if (!oldValue.equals(newValue)) { 152 setProperty(key, (String) arg); 153 } 150 154 } 151 155 } -
trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java
r9514 r9522 65 65 */ 66 66 public class UploadDialog extends AbstractUploadDialog implements PropertyChangeListener, PreferenceChangedListener { 67 /** 67 /** the unique instance of the upload dialog */ 68 68 private static UploadDialog uploadDialog; 69 69 70 /** 71 * List of custom components that can be added by plugins at JOSM startup. 72 */ 70 /** list of custom components that can be added by plugins at JOSM startup */ 73 71 private static final Collection<Component> customComponents = new ArrayList<>(); 74 72 75 /** 76 * Replies the unique instance of the upload dialog 77 * 78 * @return the unique instance of the upload dialog 79 */ 80 public static synchronized UploadDialog getUploadDialog() { 81 if (uploadDialog == null) { 82 uploadDialog = new UploadDialog(); 83 } 84 return uploadDialog; 85 } 73 /** the "created_by" changeset OSM key */ 74 private static final String CREATED_BY = "created_by"; 86 75 87 76 /** the panel with the objects to upload */ … … 108 97 109 98 /** 99 * Constructs a new {@code UploadDialog}. 100 */ 101 public UploadDialog() { 102 super(JOptionPane.getFrameForComponent(Main.parent), ModalityType.DOCUMENT_MODAL); 103 build(); 104 } 105 106 /** 107 * Replies the unique instance of the upload dialog 108 * 109 * @return the unique instance of the upload dialog 110 */ 111 public static synchronized UploadDialog getUploadDialog() { 112 if (uploadDialog == null) { 113 uploadDialog = new UploadDialog(); 114 } 115 return uploadDialog; 116 } 117 118 /** 110 119 * builds the content panel for the upload dialog 111 120 * … … 117 126 118 127 // the panel with the list of uploaded objects 119 //120 pnl.add(pnlUploadedObjects = new UploadedObjectsSummaryPanel(), GBC.eol().fill(GBC.BOTH));128 pnlUploadedObjects = new UploadedObjectsSummaryPanel(); 129 pnl.add(pnlUploadedObjects, GBC.eol().fill(GBC.BOTH)); 121 130 122 131 // Custom components … … 126 135 127 136 // a tabbed pane with configuration panels in the lower half 128 //129 137 tpConfigPanels = new JTabbedPane() { 130 138 @Override 131 139 public Dimension getPreferredSize() { 132 140 // make sure the tabbed pane never grabs more space than necessary 133 //134 141 return super.getMinimumSize(); 135 142 } 136 143 }; 137 144 138 tpConfigPanels.add(pnlBasicUploadSettings = new BasicUploadSettingsPanel(changesetCommentModel, changesetSourceModel)); 145 pnlBasicUploadSettings = new BasicUploadSettingsPanel(changesetCommentModel, changesetSourceModel); 146 tpConfigPanels.add(pnlBasicUploadSettings); 139 147 tpConfigPanels.setTitleAt(0, tr("Settings")); 140 148 tpConfigPanels.setToolTipTextAt(0, tr("Decide how to upload the data and which changeset to use")); 141 149 142 tpConfigPanels.add(pnlTagSettings = new TagSettingsPanel(changesetCommentModel, changesetSourceModel)); 150 pnlTagSettings = new TagSettingsPanel(changesetCommentModel, changesetSourceModel); 151 tpConfigPanels.add(pnlTagSettings); 143 152 tpConfigPanels.setTitleAt(1, tr("Tags of new changeset")); 144 153 tpConfigPanels.setToolTipTextAt(1, tr("Apply tags to the changeset data is uploaded to")); 145 154 146 tpConfigPanels.add(pnlChangesetManagement = new ChangesetManagementPanel(changesetCommentModel)); 155 pnlChangesetManagement = new ChangesetManagementPanel(changesetCommentModel); 156 tpConfigPanels.add(pnlChangesetManagement); 147 157 tpConfigPanels.setTitleAt(2, tr("Changesets")); 148 158 tpConfigPanels.setToolTipTextAt(2, tr("Manage open changesets and select a changeset to upload to")); 149 159 150 tpConfigPanels.add(pnlUploadStrategySelectionPanel = new UploadStrategySelectionPanel()); 160 pnlUploadStrategySelectionPanel = new UploadStrategySelectionPanel(); 161 tpConfigPanels.add(pnlUploadStrategySelectionPanel); 151 162 tpConfigPanels.setTitleAt(3, tr("Advanced")); 152 163 tpConfigPanels.setToolTipTextAt(3, tr("Configure advanced settings")); … … 167 178 168 179 // -- upload button 169 UploadAction uploadAction = new UploadAction();170 pnl.add(btnUpload = new SideButton(uploadAction));180 btnUpload = new SideButton(new UploadAction()); 181 pnl.add(btnUpload); 171 182 btnUpload.setFocusable(true); 172 183 InputMapUtils.enableEnter(btnUpload); … … 247 258 248 259 /** 249 * constructor250 */251 public UploadDialog() {252 super(JOptionPane.getFrameForComponent(Main.parent), ModalityType.DOCUMENT_MODAL);253 build();254 }255 256 /**257 260 * Sets the collection of primitives to upload 258 261 * … … 288 291 final Map<String, String> tags = new HashMap<>(); 289 292 290 // obtain from previo s input293 // obtain from previous input 291 294 tags.put("source", getLastChangesetSourceFromHistory()); 292 295 tags.put("comment", getLastChangesetCommentFromHistory()); … … 305 308 // set/adapt created_by 306 309 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);310 final String createdBy = tags.get(CREATED_BY); 311 if (createdBy == null || createdBy.isEmpty()) { 312 tags.put(CREATED_BY, agent); 313 } else if (!createdBy.contains(agent)) { 314 tags.put(CREATED_BY, createdBy + ';' + agent); 312 315 } 313 316 … … 359 362 } 360 363 364 /** 365 * Sets the changeset to be used in the next upload 366 * 367 * @param cs the changeset 368 */ 361 369 public void setSelectedChangesetForNextUpload(Changeset cs) { 362 370 pnlChangesetManagement.setSelectedChangesetForNextUpload(cs); 363 371 } 364 372 373 /** 374 * @deprecated No longer supported, does nothing; 375 * @return empty map 376 */ 377 @Deprecated 365 378 public Map<String, String> getDefaultChangesetTags() { 366 379 return pnlTagSettings.getDefaultTags(); … … 368 381 369 382 /** 383 * @param tags ignored 370 384 * @deprecated No longer supported, does nothing; use {@link #setChangesetTags(DataSet)} instead! 371 385 */ 372 386 @Deprecated 373 387 public void setDefaultChangesetTags(Map<String, String> tags) { 388 // Deprecated 374 389 } 375 390 … … 545 560 546 561 UploadStrategySpecification strategy = getUploadStrategySpecification(); 547 if (strategy.getStrategy().equals(UploadStrategy.CHUNKED_DATASET_STRATEGY)) { 548 if (strategy.getChunkSize() == UploadStrategySpecification.UNSPECIFIED_CHUNK_SIZE) { 549 warnIllegalChunkSize(); 550 tpConfigPanels.setSelectedIndex(0); 551 return; 552 } 562 if (strategy.getStrategy().equals(UploadStrategy.CHUNKED_DATASET_STRATEGY) 563 && strategy.getChunkSize() == UploadStrategySpecification.UNSPECIFIED_CHUNK_SIZE) { 564 warnIllegalChunkSize(); 565 tpConfigPanels.setSelectedIndex(0); 566 return; 553 567 } 554 568 setCanceled(false); … … 637 651 } 638 652 653 /** 654 * Returns the last changeset comment from history. 655 * @return the last changeset comment from history 656 */ 639 657 public String getLastChangesetCommentFromHistory() { 640 658 return getLastChangesetTagFromHistory(BasicUploadSettingsPanel.HISTORY_KEY, new ArrayList<String>()); 641 659 } 642 660 661 /** 662 * Returns the last changeset source from history. 663 * @return the last changeset source from history 664 */ 643 665 public String getLastChangesetSourceFromHistory() { 644 666 return getLastChangesetTagFromHistory(BasicUploadSettingsPanel.SOURCE_HISTORY_KEY, BasicUploadSettingsPanel.getDefaultSources());
Note:
See TracChangeset
for help on using the changeset viewer.