source: josm/trunk/src/org/openstreetmap/josm/actions/HistoryInfoAction.java@ 16512

Last change on this file since 16512 was 16512, checked in by GerdP, 4 years ago

fix #19275: Relation list panel: Direct option for history viewer
Apply 19275.2c.patch which enables Ctrl+H in RelationListDialog

  • Property svn:eol-style set to native
File size: 3.9 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions;
3
4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.awt.event.ActionEvent;
8import java.awt.event.KeyEvent;
9import java.util.LinkedHashSet;
10import java.util.Set;
11import java.util.stream.Collectors;
12
13import javax.swing.JList;
14import javax.swing.JTable;
15
16import org.openstreetmap.josm.data.osm.OsmData;
17import org.openstreetmap.josm.data.osm.PrimitiveId;
18import org.openstreetmap.josm.gui.MainApplication;
19import org.openstreetmap.josm.gui.dialogs.OsmIdSelectionDialog;
20import org.openstreetmap.josm.gui.history.HistoryBrowserDialogManager;
21import org.openstreetmap.josm.io.NetworkManager;
22import org.openstreetmap.josm.io.OnlineResource;
23import org.openstreetmap.josm.tools.Shortcut;
24
25/**
26 * Display history information about OSM ways, nodes, or relations.
27 * @since 968
28 */
29public class HistoryInfoAction extends JosmAction {
30
31 /** Action shortcut, made public in order to be used from {@code GettingStarted} page. */
32 public static final Shortcut SHORTCUT = Shortcut.registerShortcut("core:historyinfo", tr("History"), KeyEvent.VK_H, Shortcut.CTRL);
33
34 /**
35 * Constructs a new {@code HistoryInfoAction}.
36 */
37 public HistoryInfoAction() {
38 super(tr("History"), "dialogs/history",
39 tr("Display history information about OSM ways, nodes, or relations."),
40 SHORTCUT, true, "action/historyinfo", false);
41 setHelpId(ht("/Action/ObjectHistory"));
42 setEnabled(true);
43 }
44
45 @Override
46 public void actionPerformed(ActionEvent ae) {
47 // Generic handling of tables displaying OSM primitives
48 Set<PrimitiveId> sel = new LinkedHashSet<>();
49 if (ae.getSource() instanceof JTable) {
50 JTable table = (JTable) ae.getSource();
51 for (int row : table.getSelectedRows()) {
52 for (int col = 0; col < table.getModel().getColumnCount(); col++) {
53 Object value = table.getModel().getValueAt(row, col);
54 if (value instanceof PrimitiveId) {
55 sel.add((PrimitiveId) value);
56 break;
57 }
58 }
59 }
60 } else if (ae.getSource() instanceof JList) {
61 JList<?> list = (JList<?>) ae.getSource();
62 sel = list.getSelectedValuesList()
63 .stream().filter(v -> v instanceof PrimitiveId)
64 .map(v -> (PrimitiveId) v)
65 .collect(Collectors.toCollection(LinkedHashSet::new));
66 }
67 if (!sel.isEmpty()) {
68 HistoryBrowserDialogManager.getInstance().showHistory(sel);
69 return;
70 }
71 // Otherwise show history for currently selected objects
72 OsmData<?, ?, ?, ?> set = getLayerManager().getActiveData();
73 if (set != null && !set.selectionEmpty()) {
74 HistoryBrowserDialogManager.getInstance().showHistory(set.getAllSelected());
75 } else {
76 HistoryObjectIDDialog dialog = new HistoryObjectIDDialog();
77 if (dialog.showDialog().getValue() == dialog.getContinueButtonIndex()) {
78 HistoryBrowserDialogManager.getInstance().showHistory(dialog.getOsmIds());
79 }
80 }
81 }
82
83 /**
84 * Dialog allowing to choose object id if no one is selected.
85 * @since 6448
86 */
87 public static class HistoryObjectIDDialog extends OsmIdSelectionDialog {
88
89 /**
90 * Constructs a new {@code HistoryObjectIDDialog}.
91 */
92 public HistoryObjectIDDialog() {
93 super(MainApplication.getMainFrame(), tr("Show history"), tr("Show history"), tr("Cancel"));
94 setButtonIcons("dialogs/history", "cancel");
95 init();
96 }
97
98 @Override
99 public void setupDialog() {
100 super.setupDialog();
101 buttons.get(0).setEnabled(!NetworkManager.isOffline(OnlineResource.OSM_API));
102 }
103 }
104}
Note: See TracBrowser for help on using the repository browser.