Changeset 8224 in josm for trunk/src/org
- Timestamp:
- 2015-04-18T22:37:12+02:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/NoteData.java
r7937 r8224 3 3 4 4 import java.util.ArrayList; 5 import java.util.Collection; 5 6 import java.util.Collections; 6 7 import java.util.Comparator; 7 8 import java.util.Date; 8 import java.util.List;9 9 import java.util.Map; 10 10 … … 15 15 import org.openstreetmap.josm.data.notes.NoteComment; 16 16 import org.openstreetmap.josm.gui.JosmUserIdentityManager; 17 import org.openstreetmap.josm.tools.Predicate; 18 import org.openstreetmap.josm.tools.Utils; 17 19 18 20 /** … … 23 25 private long newNoteId = -1; 24 26 25 private final List<Note> noteList;27 private final Storage<Note> noteList; 26 28 private Note selectedNote = null; 27 29 private Comparator<Note> comparator = DEFAULT_COMPARATOR; … … 85 87 86 88 /** 87 * Construct a new note container with an empty note list88 */89 public NoteData() {90 noteList = new ArrayList<>();91 }92 93 /**94 89 * Construct a new note container with a given list of notes 95 90 * @param notes The list of notes to populate the container with 96 91 */ 97 public NoteData(List<Note> notes) { 98 noteList = notes; 99 Collections.sort(notes, comparator); 92 public NoteData(Collection<Note> notes) { 93 noteList = new Storage<>(); 100 94 for (Note note : notes) { 95 noteList.add(note); 101 96 if (note.getId() <= newNoteId) { 102 97 newNoteId = note.getId() - 1; … … 107 102 /** 108 103 * Returns the notes stored in this layer 109 * @return List of Note objects 110 */ 111 public List<Note> getNotes() { 112 return noteList; 104 * @return collection of notes 105 */ 106 public Collection<Note> getNotes() { 107 return Collections.unmodifiableCollection(noteList); 108 } 109 110 /** 111 * Returns the notes stored in this layer sorted according to {@link #comparator} 112 * @return sorted collection of notes 113 */ 114 public Collection<Note> getSortedNotes() { 115 final ArrayList<Note> list = new ArrayList<>(noteList); 116 Collections.sort(list, comparator); 117 return list; 113 118 } 114 119 … … 155 160 * @param newNotes A list of notes to add 156 161 */ 157 public synchronized void addNotes( List<Note> newNotes) {162 public synchronized void addNotes(Collection<Note> newNotes) { 158 163 for (Note newNote : newNotes) { 159 164 if (!noteList.contains(newNote)) { 160 165 noteList.add(newNote); 166 } else { 167 final Note existingNote = noteList.get(newNote); 168 final boolean isDirty = Utils.exists(existingNote.getComments(), new Predicate<NoteComment>() { 169 @Override 170 public boolean evaluate(NoteComment object) { 171 return object.getIsNew(); 172 } 173 }); 174 if (!isDirty) { 175 noteList.put(newNote); 176 } else { 177 // TODO merge comments? 178 Main.info("Keeping existing note id={0} with uncommitted changes", String.valueOf(newNote.getId())); 179 } 161 180 } 162 181 if (newNote.getId() <= newNoteId) { … … 165 184 } 166 185 dataUpdated(); 167 if (Main.isDebugEnabled()) {168 Main.debug("notes in current set: " + noteList.size());169 }170 186 } 171 187 … … 256 272 257 273 private void dataUpdated() { 258 Collections.sort(noteList, comparator); 259 Main.map.noteDialog.setNoteList(noteList); 274 Main.map.noteDialog.setNotes(getSortedNotes()); 260 275 Main.map.mapView.repaint(); 261 276 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/NotesDialog.java
r8212 r8224 13 13 import java.util.ArrayList; 14 14 import java.util.Arrays; 15 import java.util.Collection; 15 16 import java.util.List; 16 17 … … 186 187 noteData = ((NoteLayer)newLayer).getNoteData(); 187 188 model.setData(noteData.getNotes()); 188 setNote List(noteData.getNotes());189 setNotes(noteData.getSortedNotes()); 189 190 } 190 191 } … … 193 194 public void layerRemoved(Layer oldLayer) { 194 195 if (oldLayer instanceof NoteLayer) { 195 if (Main.isDebugEnabled()) {196 Main.debug("note layer removed. Clearing everything");197 }198 196 noteData = null; 199 197 model.clearData(); … … 209 207 * @param noteList List of notes to display 210 208 */ 211 public void setNote List(List<Note> noteList) {209 public void setNotes(Collection<Note> noteList) { 212 210 model.setData(noteList); 213 211 updateButtonStates(); … … 265 263 266 264 public NoteTableModel() { 267 data = new ArrayList< Note>();265 data = new ArrayList<>(); 268 266 } 269 267 … … 281 279 } 282 280 283 public void setData( List<Note> noteList) {281 public void setData(Collection<Note> noteList) { 284 282 data.clear(); 285 283 data.addAll(noteList); … … 315 313 dialog.showNoteDialog(tr("Add comment to note:"), NotesDialog.ICON_COMMENT); 316 314 if (dialog.getValue() != 1) { 317 Main.debug("User aborted note reopening");318 315 return; 319 316 } … … 337 334 dialog.showNoteDialog(tr("Close note with message:"), NotesDialog.ICON_CLOSED); 338 335 if (dialog.getValue() != 1) { 339 Main.debug("User aborted note closing");340 336 return; 341 337 } … … 377 373 dialog.showNoteDialog(tr("Reopen note with message:"), NotesDialog.ICON_OPEN); 378 374 if (dialog.getValue() != 1) { 379 Main.debug("User aborted note reopening");380 375 return; 381 376 } -
trunk/src/org/openstreetmap/josm/gui/layer/NoteLayer.java
r8214 r8224 13 13 import java.text.DateFormat; 14 14 import java.util.ArrayList; 15 import java.util.Collection; 16 import java.util.Collections; 15 17 import java.util.List; 16 18 … … 56 58 * @param name The name of the layer. Typically "Notes" 57 59 */ 58 public NoteLayer( List<Note> notes, String name) {60 public NoteLayer(Collection<Note> notes, String name) { 59 61 super(name); 60 62 noteData = new NoteData(notes); … … 63 65 /** Convenience constructor that creates a layer with an empty note list */ 64 66 public NoteLayer() { 65 super(tr("Notes")); 66 noteData = new NoteData(); 67 this(Collections.<Note>emptySet(), tr("Notes")); 67 68 } 68 69 … … 97 98 @Override 98 99 public boolean requiresSaveToFile() { 99 Main.debug("associated notes file: " + getAssociatedFile());100 100 return getAssociatedFile() != null && isModified(); 101 101 } -
trunk/src/org/openstreetmap/josm/io/NoteReader.java
r7732 r8224 195 195 @Override 196 196 public void endDocument() throws SAXException { 197 Main.info("parsed notes: " + notes.size());198 197 parsedNotes = notes; 199 198 } … … 210 209 return sdf.parse(dateStr); 211 210 } catch(ParseException e) { 212 Main.error( "error parsing date in note parser");211 Main.error(e); 213 212 return null; 214 213 }
Note:
See TracChangeset
for help on using the changeset viewer.