| 1 |
|
| 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; |
| 16 |
import org.openstreetmap.josm.tools.Logging; |
| 17 |
|
| 18 |
|
| 19 |
|
| 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 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
public NoteSortDialog(Component parent, String title, String buttonText) { |
| 35 |
super(parent, title, buttonText, tr("Cancel")); |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 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 |
Logging.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 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
public Comparator<Note> getSelectedComparator() { |
| 80 |
if (dateSort.isSelected()) { |
| 81 |
return Note.DATE_COMPARATOR; |
| 82 |
} else if (userSort.isSelected()) { |
| 83 |
return Note.USER_COMPARATOR; |
| 84 |
} else if (lastActionSort.isSelected()) { |
| 85 |
return Note.LAST_ACTION_COMPARATOR; |
| 86 |
} else { |
| 87 |
return Note.DEFAULT_COMPARATOR; |
| 88 |
} |
| 89 |
} |
| 90 |
} |