[7782] | 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.data.notes.Note;
|
---|
[12620] | 16 | import org.openstreetmap.josm.tools.Logging;
|
---|
[7782] | 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 |
|
---|
[9078] | 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"));
|
---|
[7782] | 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) {
|
---|
[12279] | 35 | super(parent, title, buttonText, tr("Cancel"));
|
---|
[7782] | 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"));
|
---|
[11821] | 44 | if (currentSortMode == Note.DEFAULT_COMPARATOR) {
|
---|
[7782] | 45 | defaultSort.setSelected(true);
|
---|
[11821] | 46 | } else if (currentSortMode == Note.DATE_COMPARATOR) {
|
---|
[7782] | 47 | dateSort.setSelected(true);
|
---|
[11821] | 48 | } else if (currentSortMode == Note.USER_COMPARATOR) {
|
---|
[7782] | 49 | userSort.setSelected(true);
|
---|
[11821] | 50 | } else if (currentSortMode == Note.LAST_ACTION_COMPARATOR) {
|
---|
[7782] | 51 | lastActionSort.setSelected(true);
|
---|
| 52 | } else {
|
---|
[12620] | 53 | Logging.warn("sort mode not recognized");
|
---|
[7782] | 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 |
|
---|
[12540] | 75 | /**
|
---|
| 76 | * Returns the Note comparator that the user has selected.
|
---|
| 77 | * @return Note comparator that the user has selected
|
---|
| 78 | */
|
---|
[7782] | 79 | public Comparator<Note> getSelectedComparator() {
|
---|
| 80 | if (dateSort.isSelected()) {
|
---|
[11821] | 81 | return Note.DATE_COMPARATOR;
|
---|
[7782] | 82 | } else if (userSort.isSelected()) {
|
---|
[11821] | 83 | return Note.USER_COMPARATOR;
|
---|
[7782] | 84 | } else if (lastActionSort.isSelected()) {
|
---|
[11821] | 85 | return Note.LAST_ACTION_COMPARATOR;
|
---|
[7782] | 86 | } else {
|
---|
[11821] | 87 | return Note.DEFAULT_COMPARATOR;
|
---|
[7782] | 88 | }
|
---|
| 89 | }
|
---|
| 90 | }
|
---|