Changeset 7699 in josm for trunk/src/org/openstreetmap/josm/data/osm/NoteData.java
- Timestamp:
- 2014-11-03T09:48:03+01:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/NoteData.java
r7608 r7699 5 5 import java.util.Date; 6 6 import java.util.List; 7 import java.util.Map; 7 8 8 9 import org.openstreetmap.josm.Main; … … 59 60 public void setSelectedNote(Note note) { 60 61 selectedNote = note; 61 Main.map.noteDialog.selectionChanged(); 62 Main.map.mapView.repaint(); 62 if (Main.map != null) { 63 Main.map.noteDialog.selectionChanged(); 64 Main.map.mapView.repaint(); 65 } 66 } 67 68 /** 69 * Return whether or not there are any changes in the note data set. 70 * These changes may need to be either uploaded or saved. 71 * @return true if local modifications have been made to the note data set. False otherwise. 72 */ 73 public synchronized boolean isModified() { 74 for (Note note : noteList) { 75 if (note.getId() < 0) { //notes with negative IDs are new 76 return true; 77 } 78 for (NoteComment comment : note.getComments()) { 79 if (comment.getIsNew()) { 80 return true; 81 } 82 } 83 } 84 return false; 63 85 } 64 86 … … 67 89 * @param newNotes A list of notes to add 68 90 */ 69 public void addNotes(List<Note> newNotes) {91 public synchronized void addNotes(List<Note> newNotes) { 70 92 for (Note newNote : newNotes) { 71 93 if (!noteList.contains(newNote)) { … … 77 99 } 78 100 dataUpdated(); 79 Main.debug("notes in current set: " + noteList.size()); 101 if (Main.isDebugEnabled()) { 102 Main.debug("notes in current set: " + noteList.size()); 103 } 80 104 } 81 105 … … 85 109 * @param text Required comment with which to open the note 86 110 */ 87 public void createNote(LatLon location, String text) {111 public synchronized void createNote(LatLon location, String text) { 88 112 if(text == null || text.isEmpty()) { 89 113 throw new IllegalArgumentException("Comment can not be blank when creating a note"); … … 95 119 NoteComment comment = new NoteComment(new Date(), getCurrentUser(), text, NoteComment.Action.opened, true); 96 120 note.addComment(comment); 97 Main.debug("Created note {0} with comment: {1}", note.getId(), text); 121 if (Main.isDebugEnabled()) { 122 Main.debug("Created note {0} with comment: {1}", note.getId(), text); 123 } 98 124 noteList.add(note); 99 125 dataUpdated(); … … 105 131 * @param text Comment to add 106 132 */ 107 public void addCommentToNote(Note note, String text) {133 public synchronized void addCommentToNote(Note note, String text) { 108 134 if (!noteList.contains(note)) { 109 135 throw new IllegalArgumentException("Note to modify must be in layer"); … … 112 138 throw new IllegalStateException("Cannot add a comment to a closed note"); 113 139 } 114 Main.debug("Adding comment to note {0}: {1}", note.getId(), text); 140 if (Main.isDebugEnabled()) { 141 Main.debug("Adding comment to note {0}: {1}", note.getId(), text); 142 } 115 143 NoteComment comment = new NoteComment(new Date(), getCurrentUser(), text, NoteComment.Action.commented, true); 116 144 note.addComment(comment); … … 123 151 * @param text Comment to attach to close action, if desired 124 152 */ 125 public void closeNote(Note note, String text) {153 public synchronized void closeNote(Note note, String text) { 126 154 if (!noteList.contains(note)) { 127 155 throw new IllegalArgumentException("Note to close must be in layer"); … … 130 158 throw new IllegalStateException("Cannot close a note that isn't open"); 131 159 } 132 Main.debug("closing note {0} with comment: {1}", note.getId(), text); 160 if (Main.isDebugEnabled()) { 161 Main.debug("closing note {0} with comment: {1}", note.getId(), text); 162 } 133 163 NoteComment comment = new NoteComment(new Date(), getCurrentUser(), text, NoteComment.Action.closed, true); 134 164 note.addComment(comment); … … 143 173 * @param text Comment to attach to the reopen action, if desired 144 174 */ 145 public void reOpenNote(Note note, String text) {175 public synchronized void reOpenNote(Note note, String text) { 146 176 if (!noteList.contains(note)) { 147 177 throw new IllegalArgumentException("Note to reopen must be in layer"); … … 150 180 throw new IllegalStateException("Cannot reopen a note that isn't closed"); 151 181 } 152 Main.debug("reopening note {0} with comment: {1}", note.getId(), text); 182 if (Main.isDebugEnabled()) { 183 Main.debug("reopening note {0} with comment: {1}", note.getId(), text); 184 } 153 185 NoteComment comment = new NoteComment(new Date(), getCurrentUser(), text, NoteComment.Action.reopened, true); 154 186 note.addComment(comment); … … 166 198 return User.createOsmUser(userMgr.getUserId(), userMgr.getUserName()); 167 199 } 200 201 /** 202 * Updates notes with new state. Primarily to be used when updating the 203 * note layer after uploading note changes to the server. 204 * @param updatedNotes Map containing the original note as the key and the updated note as the value 205 */ 206 public synchronized void updateNotes(Map<Note, Note> updatedNotes) { 207 for (Map.Entry<Note, Note> entry : updatedNotes.entrySet()) { 208 Note oldNote = entry.getKey(); 209 Note newNote = entry.getValue(); 210 oldNote.updateWith(newNote); 211 } 212 dataUpdated(); 213 } 168 214 }
Note:
See TracChangeset
for help on using the changeset viewer.