source: josm/trunk/src/org/openstreetmap/josm/gui/NoteSortDialog.java@ 8674

Last change on this file since 8674 was 7937, checked in by bastiK, 9 years ago

add subversion property svn:eol=native

  • Property svn:eol-style set to native
File size: 3.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.Component;
7import java.util.Comparator;
8
9import javax.swing.BoxLayout;
10import javax.swing.ButtonGroup;
11import javax.swing.JLabel;
12import javax.swing.JPanel;
13import javax.swing.JRadioButton;
14
15import org.openstreetmap.josm.Main;
16import org.openstreetmap.josm.data.notes.Note;
17import org.openstreetmap.josm.data.osm.NoteData;
18
19/**
20 * A dialog to allow the user to choose a sorting method for the list of notes
21 */
22public class NoteSortDialog extends ExtendedDialog {
23
24 private JRadioButton defaultSort = new JRadioButton(tr("Default (open, closed, new)"));
25 private JRadioButton userSort = new JRadioButton(tr("Username"));
26 private JRadioButton dateSort = new JRadioButton(tr("Created date"));
27 private JRadioButton lastActionSort = new JRadioButton(tr("Last change date"));
28
29 /**
30 * Construct a new dialog. The constructor automatically adds a "Cancel" button.
31 * @param parent - Parent component. Usually Main.parent
32 * @param title - Translated text to display in the title bar of the dialog
33 * @param buttonText - Translated text to be shown on the action button
34 */
35 public NoteSortDialog(Component parent, String title, String buttonText) {
36 super(parent, title, new String[] {buttonText, tr("Cancel")});
37 }
38
39 /**
40 * Builds and displays the window to the user.
41 * @param currentSortMode - The current sort mode which will be pre-selected in the list
42 */
43 public void showSortDialog(Comparator<Note> currentSortMode) {
44 JLabel label = new JLabel(tr("Select note sorting method"));
45 if (currentSortMode == NoteData.DEFAULT_COMPARATOR) {
46 defaultSort.setSelected(true);
47 } else if (currentSortMode == NoteData.DATE_COMPARATOR) {
48 dateSort.setSelected(true);
49 } else if (currentSortMode == NoteData.USER_COMPARATOR) {
50 userSort.setSelected(true);
51 } else if (currentSortMode == NoteData.LAST_ACTION_COMPARATOR) {
52 lastActionSort.setSelected(true);
53 } else {
54 Main.warn("sort mode not recognized");
55 }
56
57 ButtonGroup bg = new ButtonGroup();
58 bg.add(defaultSort);
59 bg.add(userSort);
60 bg.add(dateSort);
61 bg.add(lastActionSort);
62
63 JPanel panel = new JPanel();
64 panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
65 panel.add(label);
66 panel.add(defaultSort);
67 panel.add(userSort);
68 panel.add(dateSort);
69 panel.add(lastActionSort);
70
71 setContent(panel);
72
73 showDialog();
74 }
75
76 /** @return Note comparator that the user has selected */
77 public Comparator<Note> getSelectedComparator() {
78 if (dateSort.isSelected()) {
79 return NoteData.DATE_COMPARATOR;
80 } else if (userSort.isSelected()) {
81 return NoteData.USER_COMPARATOR;
82 } else if (lastActionSort.isSelected()) {
83 return NoteData.LAST_ACTION_COMPARATOR;
84 } else {
85 return NoteData.DEFAULT_COMPARATOR;
86 }
87 }
88}
Note: See TracBrowser for help on using the repository browser.