- Timestamp:
- 2010-03-14T12:38:09+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/io
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/io/BasicUploadSettingsPanel.java
r3083 r3133 12 12 import java.awt.event.KeyEvent; 13 13 import java.awt.event.KeyListener; 14 import java.beans.PropertyChangeEvent;15 import java.beans.PropertyChangeListener;16 14 import java.util.Collections; 17 15 import java.util.LinkedList; 18 16 import java.util.List; 17 import java.util.Observable; 18 import java.util.Observer; 19 19 20 20 import javax.swing.Action; … … 25 25 import org.openstreetmap.josm.Main; 26 26 import org.openstreetmap.josm.gui.widgets.HistoryComboBox; 27 import org.openstreetmap.josm.tools.CheckParameterUtil; 27 28 import org.openstreetmap.josm.tools.GBC; 28 29 … … 32 33 * 33 34 */ 34 public class BasicUploadSettingsPanel extends JPanel implements PropertyChangeListener{ 35 static public final String UPLOAD_COMMENT_PROP = BasicUploadSettingsPanel.class.getName() + ".uploadComment"; 35 public class BasicUploadSettingsPanel extends JPanel { 36 36 public static final String HISTORY_KEY = "upload.comment.history"; 37 37 … … 40 40 /** the panel with a summary of the upload parameters */ 41 41 private UploadParameterSummaryPanel pnlUploadParameterSummary; 42 /** the changset comment model */ 43 private ChangesetCommentModel changesetCommentModel; 42 44 43 45 protected JPanel buildUploadCommentPanel() { … … 56 58 new ActionListener() { 57 59 public void actionPerformed(ActionEvent e) { 58 firePropertyChange(UPLOAD_COMMENT_PROP, null,hcbUploadComment.getText());60 changesetCommentModel.setComment(hcbUploadComment.getText()); 59 61 } 60 62 } … … 64 66 @Override 65 67 public void focusLost(FocusEvent e) { 66 firePropertyChange(UPLOAD_COMMENT_PROP, null,hcbUploadComment.getText());68 changesetCommentModel.setComment(hcbUploadComment.getText()); 67 69 } 68 70 } … … 79 81 } 80 82 81 public BasicUploadSettingsPanel() { 83 /** 84 * Creates the panel 85 * 86 * @param changesetCommentModel the model for the changeset comment. Must not be null 87 * @throws IllegalArgumentException thrown if {@code changesetCommentModel} is null 88 */ 89 public BasicUploadSettingsPanel(ChangesetCommentModel changesetCommentModel) { 90 CheckParameterUtil.ensureParameterNotNull(changesetCommentModel, "changesetCommentModel"); 91 this.changesetCommentModel = changesetCommentModel; 92 changesetCommentModel.addObserver(new ChangesetCommentObserver()); 82 93 build(); 83 94 } … … 120 131 } 121 132 122 /** 123 * Replies the current upload comment 124 * 125 * @return 126 */ 127 public String getUploadComment() { 128 return hcbUploadComment.getText(); 129 } 130 131 /** 132 * Sets the current upload comment 133 * 134 * @return 135 */ 136 public void setUploadComment(String uploadComment) { 137 if (uploadComment == null) { 138 uploadComment = ""; 139 } 140 if (!uploadComment.equals(hcbUploadComment.getText())) { 141 hcbUploadComment.setText(uploadComment); 142 } 143 } 144 145 public void initEditingOfUploadComment(String comment) { 146 setUploadComment(comment); 133 public void initEditingOfUploadComment() { 147 134 hcbUploadComment.getEditor().selectAll(); 148 135 hcbUploadComment.requestFocusInWindow(); … … 153 140 } 154 141 155 /* -------------------------------------------------------------------------- */ 156 /* Interface PropertyChangeListener */ 157 /* -------------------------------------------------------------------------- */ 158 public void propertyChange(PropertyChangeEvent evt) { 159 if (evt.getPropertyName().equals(TagSettingsPanel.UPLOAD_COMMENT_PROP)) { 160 String comment = (String)evt.getNewValue(); 161 if (comment == null) { 162 comment = ""; 142 /** 143 * Observes the changeset comment model and keeps the comment input field 144 * in sync with the current changeset comment 145 */ 146 class ChangesetCommentObserver implements Observer { 147 public void update(Observable o, Object arg) { 148 if (!(o instanceof ChangesetCommentModel)) return; 149 String newComment = (String)arg; 150 if (!hcbUploadComment.getText().equals(newComment)) { 151 hcbUploadComment.setText(newComment); 163 152 } 164 if (comment.equals(hcbUploadComment.getText()))165 // nothing to change - return166 return;167 hcbUploadComment.setText(comment);168 153 } 169 154 } -
trunk/src/org/openstreetmap/josm/gui/io/ChangesetManagementPanel.java
r3110 r3133 28 28 import org.openstreetmap.josm.data.osm.ChangesetCache; 29 29 import org.openstreetmap.josm.gui.JMultilineLabel; 30 import org.openstreetmap.josm.tools.CheckParameterUtil; 30 31 import org.openstreetmap.josm.tools.ImageProvider; 31 32 … … 46 47 * </ul> 47 48 */ 48 public class ChangesetManagementPanel extends JPanel implements ListDataListener 49 public class ChangesetManagementPanel extends JPanel implements ListDataListener{ 49 50 public final static String SELECTED_CHANGESET_PROP = ChangesetManagementPanel.class.getName() + ".selectedChangeset"; 50 51 public final static String CLOSE_CHANGESET_AFTER_UPLOAD = ChangesetManagementPanel.class.getName() + ".closeChangesetAfterUpload"; … … 58 59 private JCheckBox cbCloseAfterUpload; 59 60 private OpenChangesetComboBoxModel model; 61 private ChangesetCommentModel changesetCommentModel; 60 62 61 63 /** … … 159 161 } 160 162 161 public ChangesetManagementPanel() { 163 /** 164 * Creates a new panel 165 * 166 * @param changesetCommentModel the changeset comment model. Must not be null. 167 * @throws IllegalArgumentException thrown if {@code changesetCommentModel} is null 168 */ 169 public ChangesetManagementPanel(ChangesetCommentModel changesetCommentModel) { 170 CheckParameterUtil.ensureParameterNotNull(changesetCommentModel, "changesetCommentModel"); 171 this.changesetCommentModel = changesetCommentModel; 162 172 build(); 163 173 refreshGUI(); … … 174 184 } 175 185 186 /** 187 * Sets the changeset to be used in the next upload 188 * 189 * @param cs the changeset 190 */ 176 191 public void setSelectedChangesetForNextUpload(Changeset cs) { 177 192 int idx = model.getIndexOf(cs); … … 204 219 } 205 220 206 /**207 * Replies the default value for "created_by"208 *209 * @return the default value for "created_by"210 */211 protected String getDefaultCreatedBy() {212 Object ua = System.getProperties().get("http.agent");213 return(ua == null) ? "JOSM" : ua.toString();214 }215 216 221 /* ---------------------------------------------------------------------------- */ 217 222 /* Interface ListDataListener */ … … 230 235 231 236 /** 232 * Listens to changes in the selected changeset and accordinglyfires property237 * Listens to changes in the selected changeset and fires property 233 238 * change events. 234 239 * … … 237 242 public void itemStateChanged(ItemEvent e) { 238 243 Changeset cs = (Changeset)cbOpenChangesets.getSelectedItem(); 244 if (cs == null) return; 239 245 if (rbExisting.isSelected()) { 246 // create a clone of the selected changeset and make sure 247 // we keep the current changeset comment (see #4371) 248 cs = new Changeset(cs); 249 cs.put("comment", changesetCommentModel.getComment()); 240 250 firePropertyChange(SELECTED_CHANGESET_PROP, null, cs); 241 if (cs == null) {242 rbUseNew.setSelected(true);243 }244 251 } 245 252 } … … 283 290 } 284 291 Changeset cs = (Changeset)cbOpenChangesets.getSelectedItem(); 292 if (cs == null) return; 293 // create a clone of the selected changeset and make sure 294 // we keep the current changeset comment (see #4371) 295 cs = new Changeset(cs); 296 cs.put("comment", changesetCommentModel.getComment()); 285 297 firePropertyChange(SELECTED_CHANGESET_PROP, null, cs); 286 298 } -
trunk/src/org/openstreetmap/josm/gui/io/TagSettingsPanel.java
r3083 r3133 3 3 4 4 import java.awt.BorderLayout; 5 import java.beans.PropertyChangeEvent;6 import java.beans.PropertyChangeListener;7 5 import java.util.Map; 6 import java.util.Observable; 7 import java.util.Observer; 8 8 9 9 import javax.swing.JPanel; … … 15 15 import org.openstreetmap.josm.gui.tagging.TagEditorPanel; 16 16 import org.openstreetmap.josm.gui.tagging.TagModel; 17 import org.openstreetmap.josm.tools.CheckParameterUtil; 17 18 18 public class TagSettingsPanel extends JPanel implements PropertyChangeListener, TableModelListener { 19 static public final String UPLOAD_COMMENT_PROP = TagSettingsPanel.class.getName() + ".uploadComment"; 19 public class TagSettingsPanel extends JPanel implements TableModelListener { 20 20 21 21 /** checkbox for selecting whether an atomic upload is to be used */ 22 22 private TagEditorPanel pnlTagEditor; 23 /** the model for the changeset comment */ 24 private ChangesetCommentModel changesetCommentModel; 25 23 26 24 27 protected void build() { … … 27 30 } 28 31 29 public TagSettingsPanel() { 32 /** 33 * Creates a new panel 34 * 35 * @param changesetCommentModel the changeset comment model. Must not be null. 36 * @throws IllegalArgumentException thrown if {@code changesetCommentModel} is null 37 */ 38 public TagSettingsPanel(ChangesetCommentModel changesetCommentModel) throws IllegalArgumentException{ 39 CheckParameterUtil.ensureParameterNotNull(changesetCommentModel, "changesetCommentModel"); 40 this.changesetCommentModel = changesetCommentModel; 41 this.changesetCommentModel.addObserver(new ChangesetCommentObserver()); 30 42 build(); 31 43 pnlTagEditor.getModel().addTableModelListener(this); … … 42 54 } 43 55 44 p ublicvoid setUploadComment(String comment) {56 protected void setUploadComment(String comment) { 45 57 if (comment == null) { 46 58 comment = ""; … … 111 123 112 124 /* -------------------------------------------------------------------------- */ 113 /* Interface PropertyChangeListener */114 /* -------------------------------------------------------------------------- */115 public void propertyChange(PropertyChangeEvent evt) {116 if (evt.getPropertyName().equals(ChangesetManagementPanel.SELECTED_CHANGESET_PROP)) {117 Changeset cs = (Changeset)evt.getNewValue();118 initFromChangeset(cs);119 } else if (evt.getPropertyName().equals(BasicUploadSettingsPanel.UPLOAD_COMMENT_PROP)) {120 String comment = (String)evt.getNewValue();121 setUploadComment(comment);122 }123 }124 125 /* -------------------------------------------------------------------------- */126 125 /* Interface TableChangeListener */ 127 126 /* -------------------------------------------------------------------------- */ 128 127 public void tableChanged(TableModelEvent e) { 129 128 String uploadComment = getUploadComment(); 130 firePropertyChange(UPLOAD_COMMENT_PROP, null, uploadComment); 129 changesetCommentModel.setComment(uploadComment); 130 } 131 132 /** 133 * Observes the changeset comment model and keeps the tag editor in sync 134 * with the current changeset comment 135 * 136 */ 137 class ChangesetCommentObserver implements Observer { 138 public void update(Observable o, Object arg) { 139 if (!(o instanceof ChangesetCommentModel)) return; 140 String newValue = (String)arg; 141 String oldValue = getUploadComment(); 142 if (oldValue == null) { 143 oldValue = ""; 144 } 145 if (!oldValue.equals(newValue)) { 146 setUploadComment((String)arg); 147 } 148 } 131 149 } 132 150 } -
trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java
r3083 r3133 80 80 /** the upload button */ 81 81 private JButton btnUpload; 82 83 82 private boolean canceled = false; 83 84 /** the changeset comment model keeping the state of the changeset comment */ 85 private ChangesetCommentModel changesetCommentModel; 84 86 85 87 /** … … 113 115 tpConfigPanels.add(new JPanel()); 114 116 115 tpConfigPanels.setComponentAt(0, pnlBasicUploadSettings = new BasicUploadSettingsPanel()); 117 changesetCommentModel = new ChangesetCommentModel(); 118 119 tpConfigPanels.setComponentAt(0, pnlBasicUploadSettings = new BasicUploadSettingsPanel(changesetCommentModel)); 116 120 tpConfigPanels.setTitleAt(0, tr("Settings")); 117 121 tpConfigPanels.setToolTipTextAt(0, tr("Decide how to upload the data and which changeset to use")); 118 122 119 tpConfigPanels.setComponentAt(1,pnlTagSettings = new TagSettingsPanel( ));123 tpConfigPanels.setComponentAt(1,pnlTagSettings = new TagSettingsPanel(changesetCommentModel)); 120 124 tpConfigPanels.setTitleAt(1, tr("Tags of new changeset")); 121 125 tpConfigPanels.setToolTipTextAt(1, tr("Apply tags to the changeset data is uploaded to")); 122 126 123 tpConfigPanels.setComponentAt(2,pnlChangesetManagement = new ChangesetManagementPanel( ));127 tpConfigPanels.setComponentAt(2,pnlChangesetManagement = new ChangesetManagementPanel(changesetCommentModel)); 124 128 tpConfigPanels.setTitleAt(2, tr("Changesets")); 125 129 tpConfigPanels.setToolTipTextAt(2, tr("Manage open changesets and select a changeset to upload to")); … … 175 179 addWindowListener(new WindowEventHandler()); 176 180 177 // synchronized input of upload comments178 //179 //UploadCommentSynchronizer synchronizer = new UploadCommentSynchronizer();180 //pnlTagSettings.getModeaddTableModelListener(synchronizer);181 pnlTagSettings.addPropertyChangeListener(pnlBasicUploadSettings);182 pnlBasicUploadSettings.addPropertyChangeListener(pnlTagSettings);183 181 184 182 // make sure the the configuration panels listen to each other … … 188 186 pnlBasicUploadSettings.getUploadParameterSummaryPanel() 189 187 ); 190 pnlChangesetManagement.addPropertyChangeListener(pnlTagSettings);191 188 pnlChangesetManagement.addPropertyChangeListener(this); 192 189 pnlUploadedObjects.addPropertyChangeListener( … … 197 194 pnlBasicUploadSettings.getUploadParameterSummaryPanel() 198 195 ); 196 199 197 200 198 // users can click on either of two links in the upload parameter … … 268 266 pnlBasicUploadSettings.startUserInput(); 269 267 pnlTagSettings.startUserInput(); 270 pnlTagSettings.setUploadComment(getUploadComment());271 268 pnlTagSettings.initFromChangeset(pnlChangesetManagement.getSelectedChangeset()); 272 269 pnlUploadStrategySelectionPanel.initFromPreferences(); … … 312 309 */ 313 310 protected String getUploadComment() { 314 return pnlBasicUploadSettings.getUploadComment();311 return changesetCommentModel.getComment(); 315 312 } 316 313 … … 385 382 warnIllegalUploadComment(); 386 383 tpConfigPanels.setSelectedIndex(0); 387 pnlBasicUploadSettings.initEditingOfUploadComment( getUploadComment());384 pnlBasicUploadSettings.initEditingOfUploadComment(); 388 385 return; 389 386 } … … 437 434 public void windowActivated(WindowEvent arg0) { 438 435 if (tpConfigPanels.getSelectedIndex() == 0) { 439 pnlBasicUploadSettings.initEditingOfUploadComment( getUploadComment());436 pnlBasicUploadSettings.initEditingOfUploadComment(); 440 437 } 441 438 }
Note:
See TracChangeset
for help on using the changeset viewer.