Changeset 7782 in josm
- Timestamp:
- 2014-12-10T21:25:59+01:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/NoteData.java
r7732 r7782 3 3 4 4 import java.util.ArrayList; 5 import java.util.Collections; 6 import java.util.Comparator; 5 7 import java.util.Date; 6 8 import java.util.List; … … 23 25 private final List<Note> noteList; 24 26 private Note selectedNote = null; 27 private Comparator<Note> comparator = DEFAULT_COMPARATOR; 28 29 /** 30 * Sorts notes in the following order: 31 * 1) Open notes 32 * 2) Closed notes 33 * 3) New notes 34 * Within each subgroup it sorts by ID 35 */ 36 public static final Comparator<Note> DEFAULT_COMPARATOR = new Comparator<Note>() { 37 @Override 38 public int compare(Note n1, Note n2) { 39 if (n1.getId() < 0 && n2.getId() > 0) { 40 return 1; 41 } 42 if (n1.getId() > 0 && n2.getId() < 0) { 43 return -1; 44 } 45 if (n1.getState() == State.closed && n2.getState() == State.open) { 46 return 1; 47 } 48 if (n1.getState() == State.open && n2.getState() == State.closed) { 49 return -1; 50 } 51 return Long.valueOf(Math.abs(n1.getId())).compareTo(Long.valueOf(Math.abs(n2.getId()))); 52 } 53 }; 54 55 /** Sorts notes strictly by creation date */ 56 public static final Comparator<Note> DATE_COMPARATOR = new Comparator<Note>() { 57 @Override 58 public int compare(Note n1, Note n2) { 59 return n1.getCreatedAt().compareTo(n2.getCreatedAt()); 60 } 61 }; 62 63 /** Sorts notes by user, then creation date */ 64 public static final Comparator<Note> USER_COMPARATOR = new Comparator<Note>() { 65 @Override 66 public int compare(Note n1, Note n2) { 67 String n1User = n1.getFirstComment().getUser().getName(); 68 String n2User = n2.getFirstComment().getUser().getName(); 69 if (n1User.equals(n2User)) { 70 return n1.getCreatedAt().compareTo(n2.getCreatedAt()); 71 } 72 return n1.getFirstComment().getUser().getName().compareTo(n2.getFirstComment().getUser().getName()); 73 } 74 }; 75 76 /** Sorts notes by the last modified date */ 77 public static final Comparator<Note> LAST_ACTION_COMPARATOR = new Comparator<Note>() { 78 @Override 79 public int compare(Note n1, Note n2) { 80 Date n1Date = n1.getComments().get(n1.getComments().size()-1).getCommentTimestamp(); 81 Date n2Date = n2.getComments().get(n2.getComments().size()-1).getCommentTimestamp(); 82 return n1Date.compareTo(n2Date); 83 } 84 }; 25 85 26 86 /** … … 37 97 public NoteData(List<Note> notes) { 38 98 noteList = notes; 99 Collections.sort(notes, comparator); 39 100 for (Note note : notes) { 40 101 if (note.getId() <= newNoteId) { … … 195 256 196 257 private void dataUpdated() { 258 Collections.sort(noteList, comparator); 197 259 Main.map.noteDialog.setNoteList(noteList); 198 260 Main.map.mapView.repaint(); … … 217 279 dataUpdated(); 218 280 } 281 282 /** @return The current comparator being used to sort the note list */ 283 public Comparator<Note> getCurrentSortMethod() { 284 return comparator; 285 } 286 287 /** Set the comparator to be used to sort the note list. Several are available 288 * as public static members of this class. 289 * @param comparator - The Note comparator to sort by 290 */ 291 public void setSortMethod(Comparator<Note> comparator) { 292 this.comparator = comparator; 293 dataUpdated(); 294 } 219 295 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/NoteDialog.java
r7720 r7782 36 36 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 37 37 import org.openstreetmap.josm.gui.NoteInputDialog; 38 import org.openstreetmap.josm.gui.NoteSortDialog; 38 39 import org.openstreetmap.josm.gui.SideButton; 39 40 import org.openstreetmap.josm.gui.layer.Layer; … … 75 76 private final NewAction newAction; 76 77 private final ReopenAction reopenAction; 78 private final SortAction sortAction; 77 79 private final UploadNotesAction uploadAction; 78 80 … … 90 92 newAction = new NewAction(); 91 93 reopenAction = new ReopenAction(); 94 sortAction = new SortAction(); 92 95 uploadAction = new UploadNotesAction(); 93 96 buildDialog(); … … 121 124 new SideButton(closeAction, false), 122 125 new SideButton(reopenAction, false), 126 new SideButton(sortAction, false), 123 127 new SideButton(uploadAction, false)})); 124 128 updateButtonStates(); … … 144 148 uploadAction.setEnabled(true); 145 149 } 150 //enable sort button if any notes are loaded 151 if (noteData == null || noteData.getNotes().isEmpty()) { 152 sortAction.setEnabled(false); 153 } else { 154 sortAction.setEnabled(true); 155 } 146 156 } 147 157 … … 161 171 @Override 162 172 public void layerAdded(Layer newLayer) { 163 if (Main.isDebugEnabled()) {164 Main.debug("layer added: " + newLayer);165 }166 173 if (newLayer instanceof NoteLayer) { 167 if (Main.isDebugEnabled()) {168 Main.debug("note layer added");169 }170 174 noteData = ((NoteLayer)newLayer).getNoteData(); 171 175 model.setData(noteData.getNotes()); 176 setNoteList(noteData.getNotes()); 172 177 } 173 178 } … … 364 369 } 365 370 } 371 372 class SortAction extends AbstractAction { 373 374 public SortAction() { 375 putValue(SHORT_DESCRIPTION, tr("Sort notes")); 376 putValue(NAME, tr("Sort")); 377 putValue(SMALL_ICON, ImageProvider.get("dialogs", "sort")); 378 } 379 380 @Override 381 public void actionPerformed(ActionEvent e) { 382 NoteSortDialog sortDialog = new NoteSortDialog(Main.parent, tr("Sort notes"), tr("Apply")); 383 sortDialog.showSortDialog(noteData.getCurrentSortMethod()); 384 if (sortDialog.getValue() == 1) { 385 noteData.setSortMethod(sortDialog.getSelectedComparator()); 386 } 387 } 388 } 366 389 }
Note:
See TracChangeset
for help on using the changeset viewer.