Changeset 6401 in josm
- Timestamp:
- 2013-11-22T22:19:33+01:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/io
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/io/BasicUploadSettingsPanel.java
r6084 r6401 37 37 public static final String HISTORY_KEY = "upload.comment.history"; 38 38 public static final String HISTORY_LAST_USED_KEY = "upload.comment.last-used"; 39 public static final String SOURCE_HISTORY_KEY = "upload.comment.source"; 39 40 40 41 /** the history combo box for the upload comment */ 41 private HistoryComboBox hcbUploadComment; 42 private final HistoryComboBox hcbUploadComment = new HistoryComboBox(); 43 private final HistoryComboBox hcbUploadSource = new HistoryComboBox(); 42 44 /** the panel with a summary of the upload parameters */ 43 private UploadParameterSummaryPanel pnlUploadParameterSummary; 44 /** the changset comment model */ 45 private ChangesetCommentModel changesetCommentModel; 45 private final UploadParameterSummaryPanel pnlUploadParameterSummary = new UploadParameterSummaryPanel(); 46 /** the changeset comment model */ 47 private final ChangesetCommentModel changesetCommentModel; 48 private final ChangesetCommentModel changesetSourceModel; 46 49 47 50 protected JPanel buildUploadCommentPanel() { 48 51 JPanel pnl = new JPanel(); 49 52 pnl.setLayout(new GridBagLayout()); 53 50 54 pnl.add(new JLabel(tr("Provide a brief comment for the changes you are uploading:")), GBC.eol().insets(0, 5, 10, 3)); 51 hcbUploadComment = new HistoryComboBox();52 55 hcbUploadComment.setToolTipText(tr("Enter an upload comment")); 53 56 hcbUploadComment.setMaxTextLength(Changeset.MAX_COMMENT_LENGTH); 54 57 List<String> cmtHistory = new LinkedList<String>(Main.pref.getCollection(HISTORY_KEY, new LinkedList<String>())); 55 // we have to reverse the history, because ComboBoxHistory will reverse it again 56 // in addElement() 57 // 58 Collections.reverse(cmtHistory); 58 Collections.reverse(cmtHistory); // we have to reverse the history, because ComboBoxHistory will reverse it again in addElement() 59 59 hcbUploadComment.setPossibleItems(cmtHistory); 60 hcbUploadComment.getEditor().addActionListener( 61 new ActionListener() { 62 @Override 63 public void actionPerformed(ActionEvent e) { 64 changesetCommentModel.setComment(hcbUploadComment.getText()); 65 } 66 } 67 ); 68 hcbUploadComment.getEditor().getEditorComponent().addFocusListener( 69 new FocusAdapter() { 70 @Override 71 public void focusLost(FocusEvent e) { 72 changesetCommentModel.setComment(hcbUploadComment.getText()); 73 } 74 } 75 ); 60 final CommentModelListener commentModelListener = new CommentModelListener(hcbUploadComment, changesetCommentModel); 61 hcbUploadComment.getEditor().addActionListener(commentModelListener); 62 hcbUploadComment.getEditor().getEditorComponent().addFocusListener(commentModelListener); 76 63 pnl.add(hcbUploadComment, GBC.eol().fill(GBC.HORIZONTAL)); 64 65 pnl.add(new JLabel(tr("Specify the data source for the changes:")), GBC.eol().insets(0, 8, 10, 3)); 66 hcbUploadSource.setToolTipText(tr("Enter a source")); 67 List<String> sourceHistory = new LinkedList<String>(Main.pref.getCollection(SOURCE_HISTORY_KEY, new LinkedList<String>())); 68 Collections.reverse(sourceHistory); // we have to reverse the history, because ComboBoxHistory will reverse it again in addElement() 69 hcbUploadComment.setPossibleItems(sourceHistory); 70 final CommentModelListener sourceModelListener = new CommentModelListener(hcbUploadSource, changesetSourceModel); 71 hcbUploadSource.getEditor().addActionListener(sourceModelListener); 72 hcbUploadSource.getEditor().getEditorComponent().addFocusListener(sourceModelListener); 73 pnl.add(hcbUploadSource, GBC.eol().fill(GBC.HORIZONTAL)); 77 74 return pnl; 78 75 } … … 82 79 setBorder(BorderFactory.createEmptyBorder(3,3,3,3)); 83 80 add(buildUploadCommentPanel(), BorderLayout.NORTH); 84 add(pnlUploadParameterSummary = new UploadParameterSummaryPanel(), BorderLayout.CENTER);81 add(pnlUploadParameterSummary, BorderLayout.CENTER); 85 82 } 86 83 … … 89 86 * 90 87 * @param changesetCommentModel the model for the changeset comment. Must not be null 88 * @param changesetSourceModel the model for the changeset source. Must not be null. 91 89 * @throws IllegalArgumentException thrown if {@code changesetCommentModel} is null 92 90 */ 93 public BasicUploadSettingsPanel(ChangesetCommentModel changesetCommentModel) { 91 public BasicUploadSettingsPanel(ChangesetCommentModel changesetCommentModel, ChangesetCommentModel changesetSourceModel) { 94 92 CheckParameterUtil.ensureParameterNotNull(changesetCommentModel, "changesetCommentModel"); 93 CheckParameterUtil.ensureParameterNotNull(changesetSourceModel, "changesetSourceModel"); 95 94 this.changesetCommentModel = changesetCommentModel; 96 changesetCommentModel.addObserver(new ChangesetCommentObserver()); 95 this.changesetSourceModel = changesetSourceModel; 96 changesetCommentModel.addObserver(new ChangesetCommentObserver(hcbUploadComment)); 97 changesetSourceModel.addObserver(new ChangesetCommentObserver(hcbUploadSource)); 97 98 build(); 98 99 } … … 125 126 Main.pref.putCollection(HISTORY_KEY, hcbUploadComment.getHistory()); 126 127 Main.pref.putInteger(HISTORY_LAST_USED_KEY, (int) (System.currentTimeMillis() / 1000)); 128 // store the history of sources 129 hcbUploadSource.addCurrentItemToHistory(); 130 Main.pref.putCollection(SOURCE_HISTORY_KEY, hcbUploadSource.getHistory()); 127 131 } 128 132 … … 151 155 152 156 /** 157 * Updates the changeset comment model upon changes in the input field. 158 */ 159 class CommentModelListener extends FocusAdapter implements ActionListener { 160 161 final HistoryComboBox source; 162 final ChangesetCommentModel destination; 163 164 CommentModelListener(HistoryComboBox source, ChangesetCommentModel destination) { 165 this.source = source; 166 this.destination = destination; 167 } 168 169 @Override 170 public void actionPerformed(ActionEvent e) { 171 destination.setComment(source.getText()); 172 } 173 @Override 174 public void focusLost(FocusEvent e) { 175 destination.setComment(source.getText()); 176 } 177 } 178 179 /** 153 180 * Observes the changeset comment model and keeps the comment input field 154 181 * in sync with the current changeset comment 155 182 */ 156 183 class ChangesetCommentObserver implements Observer { 184 185 private final HistoryComboBox destination; 186 187 ChangesetCommentObserver(HistoryComboBox destination) { 188 this.destination = destination; 189 } 190 157 191 @Override 158 192 public void update(Observable o, Object arg) { 159 193 if (!(o instanceof ChangesetCommentModel)) return; 160 194 String newComment = (String)arg; 161 if (! hcbUploadComment.getText().equals(newComment)) {162 hcbUploadComment.setText(newComment);195 if (!destination.getText().equals(newComment)) { 196 destination.setText(newComment); 163 197 } 164 198 } -
trunk/src/org/openstreetmap/josm/gui/io/TagSettingsPanel.java
r6309 r6401 22 22 23 23 /** checkbox for selecting whether an atomic upload is to be used */ 24 private TagEditorPanel pnlTagEditor; 24 private final TagEditorPanel pnlTagEditor = new TagEditorPanel(null); 25 25 /** the model for the changeset comment */ 26 private ChangesetCommentModel changesetCommentModel; 26 private final ChangesetCommentModel changesetCommentModel; 27 private final ChangesetCommentModel changesetSourceModel; 27 28 /** tags that applied to uploaded changesets by default*/ 28 private Map<String, String> defaultTags = new HashMap<String, String>(); 29 private final Map<String, String> defaultTags = new HashMap<String, String>(); 29 30 30 31 protected void build() { 31 32 setLayout(new BorderLayout()); 32 add(pnlTagEditor = new TagEditorPanel(null), BorderLayout.CENTER);33 add(pnlTagEditor, BorderLayout.CENTER); 33 34 } 34 35 … … 37 38 * 38 39 * @param changesetCommentModel the changeset comment model. Must not be null. 40 * @param changesetSourceModel the changeset source model. Must not be null. 39 41 * @throws IllegalArgumentException thrown if {@code changesetCommentModel} is null 40 42 */ 41 public TagSettingsPanel(ChangesetCommentModel changesetCommentModel) throws IllegalArgumentException{ 43 public TagSettingsPanel(ChangesetCommentModel changesetCommentModel, ChangesetCommentModel changesetSourceModel) throws IllegalArgumentException{ 42 44 CheckParameterUtil.ensureParameterNotNull(changesetCommentModel, "changesetCommentModel"); 45 CheckParameterUtil.ensureParameterNotNull(changesetSourceModel, "changesetSourceModel"); 43 46 this.changesetCommentModel = changesetCommentModel; 44 this.changesetCommentModel.addObserver(new ChangesetCommentObserver()); 47 this.changesetSourceModel = changesetSourceModel; 48 this.changesetCommentModel.addObserver(new ChangesetCommentObserver("comment")); 49 this.changesetSourceModel.addObserver(new ChangesetCommentObserver("source")); 45 50 build(); 46 51 pnlTagEditor.getModel().addTableModelListener(this); 47 52 } 48 53 49 protected void set UploadComment(Stringcomment) {50 if ( comment== null) {51 comment= "";54 protected void setProperty(String key, String value) { 55 if (value == null) { 56 value = ""; 52 57 } 53 comment = comment.trim();54 String commentInTag = get UploadComment();55 if ( comment.equals(commentInTag))58 value = value.trim(); 59 String commentInTag = getTagEditorValue(key); 60 if (value.equals(commentInTag)) 56 61 return; 57 62 58 if ( comment.isEmpty()) {59 pnlTagEditor.getModel().delete( "comment");63 if (value.isEmpty()) { 64 pnlTagEditor.getModel().delete(key); 60 65 return; 61 66 } 62 TagModel tag = pnlTagEditor.getModel().get( "comment");67 TagModel tag = pnlTagEditor.getModel().get(key); 63 68 if (tag == null) { 64 tag = new TagModel( "comment", comment);69 tag = new TagModel(key, value); 65 70 pnlTagEditor.getModel().add(tag); 66 71 } else { 67 pnlTagEditor.getModel().updateTagValue(tag, comment);72 pnlTagEditor.getModel().updateTagValue(tag, value); 68 73 } 69 74 } 70 75 71 protected String get UploadComment() {72 TagModel tag = pnlTagEditor.getModel().get( "comment");76 protected String getTagEditorValue(String key) { 77 TagModel tag = pnlTagEditor.getModel().get(key); 73 78 if (tag == null) return null; 74 79 return tag.getValue(); … … 76 81 77 82 public void initFromChangeset(Changeset cs) { 78 String currentComment = get UploadComment();83 String currentComment = getTagEditorValue("comment"); 79 84 Map<String,String> tags = getDefaultTags(); 80 85 if (cs != null) { … … 83 88 if (tags.get("comment") == null) { 84 89 tags.put("comment", currentComment); 90 } 91 if (tags.get("source") == null) { 92 tags.put("source", ""); 85 93 } 86 94 String agent = Version.getInstance().getAgentString(false); … … 123 131 @Override 124 132 public void tableChanged(TableModelEvent e) { 125 String uploadComment= getUploadComment();126 changeset CommentModel.setComment(uploadComment);133 changesetCommentModel.setComment(getTagEditorValue("comment")); 134 changesetSourceModel.setComment(getTagEditorValue("source")); 127 135 } 128 136 … … 133 141 */ 134 142 class ChangesetCommentObserver implements Observer { 143 144 private final String key; 145 146 ChangesetCommentObserver(String key) { 147 this.key = key; 148 } 149 135 150 @Override 136 151 public void update(Observable o, Object arg) { 137 152 if (!(o instanceof ChangesetCommentModel)) return; 138 153 String newValue = (String)arg; 139 String oldValue = get UploadComment();154 String oldValue = getTagEditorValue(key); 140 155 if (oldValue == null) { 141 156 oldValue = ""; 142 157 } 143 158 if (!oldValue.equals(newValue)) { 144 set UploadComment((String)arg);159 setProperty(key, (String) arg); 145 160 } 146 161 } -
trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java
r6315 r6401 100 100 101 101 /** the changeset comment model keeping the state of the changeset comment */ 102 private ChangesetCommentModel changesetCommentModel; 102 private final ChangesetCommentModel changesetCommentModel = new ChangesetCommentModel(); 103 private final ChangesetCommentModel changesetSourceModel = new ChangesetCommentModel(); 103 104 104 105 /** … … 131 132 }; 132 133 133 changesetCommentModel = new ChangesetCommentModel(); 134 135 tpConfigPanels.add(pnlBasicUploadSettings = new BasicUploadSettingsPanel(changesetCommentModel)); 134 tpConfigPanels.add(pnlBasicUploadSettings = new BasicUploadSettingsPanel(changesetCommentModel, changesetSourceModel)); 136 135 tpConfigPanels.setTitleAt(0, tr("Settings")); 137 136 tpConfigPanels.setToolTipTextAt(0, tr("Decide how to upload the data and which changeset to use")); 138 137 139 tpConfigPanels.add(pnlTagSettings = new TagSettingsPanel(changesetCommentModel)); 138 tpConfigPanels.add(pnlTagSettings = new TagSettingsPanel(changesetCommentModel, changesetSourceModel)); 140 139 tpConfigPanels.setTitleAt(1, tr("Tags of new changeset")); 141 140 tpConfigPanels.setToolTipTextAt(1, tr("Apply tags to the changeset data is uploaded to"));
Note:
See TracChangeset
for help on using the changeset viewer.