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