- Timestamp:
- 2014-11-03T09:48:03+01:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 added
- 3 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 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/NoteDialog.java
r7608 r7699 28 28 29 29 import org.openstreetmap.josm.Main; 30 import org.openstreetmap.josm.actions.UploadNotesAction; 30 31 import org.openstreetmap.josm.actions.mapmode.AddNoteAction; 31 32 import org.openstreetmap.josm.data.notes.Note; … … 73 74 private final NewAction newAction; 74 75 private final ReopenAction reopenAction; 76 private final UploadNotesAction uploadAction; 75 77 76 78 private NoteData noteData; … … 79 81 public NoteDialog() { 80 82 super("Notes", "notes/note_open.png", "List of notes", null, 150); 81 Main.debug("constructed note dialog"); 83 if (Main.isDebugEnabled()) { 84 Main.debug("constructed note dialog"); 85 } 82 86 83 87 addCommentAction = new AddCommentAction(); … … 85 89 newAction = new NewAction(); 86 90 reopenAction = new ReopenAction(); 91 uploadAction = new UploadNotesAction(); 87 92 buildDialog(); 88 93 } … … 114 119 new SideButton(addCommentAction, false), 115 120 new SideButton(closeAction, false), 116 new SideButton(reopenAction, false)})); 121 new SideButton(reopenAction, false), 122 new SideButton(uploadAction, false)})); 117 123 updateButtonStates(); 118 124 } … … 132 138 reopenAction.setEnabled(true); 133 139 } 140 if(noteData == null || !noteData.isModified()) { 141 uploadAction.setEnabled(false); 142 } else { 143 uploadAction.setEnabled(true); 144 } 134 145 } 135 146 … … 149 160 @Override 150 161 public void layerAdded(Layer newLayer) { 151 Main.debug("layer added: " + newLayer); 162 if (Main.isDebugEnabled()) { 163 Main.debug("layer added: " + newLayer); 164 } 152 165 if (newLayer instanceof NoteLayer) { 153 Main.debug("note layer added"); 166 if (Main.isDebugEnabled()) { 167 Main.debug("note layer added"); 168 } 154 169 noteData = ((NoteLayer)newLayer).getNoteData(); 155 170 model.setData(noteData.getNotes()); … … 160 175 public void layerRemoved(Layer oldLayer) { 161 176 if (oldLayer instanceof NoteLayer) { 162 Main.debug("note layer removed. Clearing everything"); 177 if (Main.isDebugEnabled()) { 178 Main.debug("note layer removed. Clearing everything"); 179 } 163 180 noteData = null; 164 181 model.clearData(); -
trunk/src/org/openstreetmap/josm/gui/layer/NoteLayer.java
r7608 r7699 73 73 @Override 74 74 public boolean isModified() { 75 for (Note note : noteData.getNotes()) { 76 if (note.getId() < 0) { //notes with negative IDs are new 77 return true; 78 } 79 for (NoteComment comment : note.getComments()) { 80 if (comment.getIsNew()) { 81 return true; 82 } 83 } 84 } 85 return false; 75 return noteData.isModified(); 86 76 } 87 77
Note:
See TracChangeset
for help on using the changeset viewer.