001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.actions; 003 004import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 005import static org.openstreetmap.josm.tools.I18n.tr; 006 007import java.awt.event.ActionEvent; 008import java.awt.event.KeyEvent; 009 010import org.openstreetmap.josm.Main; 011import org.openstreetmap.josm.data.osm.OsmData; 012import org.openstreetmap.josm.gui.MainApplication; 013import org.openstreetmap.josm.gui.dialogs.OsmIdSelectionDialog; 014import org.openstreetmap.josm.gui.history.HistoryBrowserDialogManager; 015import org.openstreetmap.josm.io.OnlineResource; 016import org.openstreetmap.josm.tools.Shortcut; 017 018/** 019 * Display history information about OSM ways, nodes, or relations. 020 * @since 968 021 */ 022public class HistoryInfoAction extends JosmAction { 023 024 /** 025 * Constructs a new {@code HistoryInfoAction}. 026 */ 027 public HistoryInfoAction() { 028 super(tr("History"), "dialogs/history", 029 tr("Display history information about OSM ways, nodes, or relations."), 030 Shortcut.registerShortcut("core:historyinfo", 031 tr("History"), KeyEvent.VK_H, Shortcut.CTRL), false); 032 putValue("help", ht("/Action/ObjectHistory")); 033 putValue("toolbar", "action/historyinfo"); 034 MainApplication.getToolbar().register(this); 035 setEnabled(true); 036 } 037 038 @Override 039 public void actionPerformed(ActionEvent ae) { 040 OsmData<?, ?, ?, ?> set = getLayerManager().getActiveData(); 041 if (set != null && !set.selectionEmpty()) { 042 HistoryBrowserDialogManager.getInstance().showHistory(set.getAllSelected()); 043 } else { 044 HistoryObjectIDDialog dialog = new HistoryObjectIDDialog(); 045 if (dialog.showDialog().getValue() == dialog.getContinueButtonIndex()) { 046 HistoryBrowserDialogManager.getInstance().showHistory(dialog.getOsmIds()); 047 } 048 } 049 } 050 051 /** 052 * Dialog allowing to choose object id if no one is selected. 053 * @since 6448 054 */ 055 public static class HistoryObjectIDDialog extends OsmIdSelectionDialog { 056 057 /** 058 * Constructs a new {@code HistoryObjectIDDialog}. 059 */ 060 public HistoryObjectIDDialog() { 061 super(Main.parent, tr("Show history"), tr("Show history"), tr("Cancel")); 062 setButtonIcons("dialogs/history", "cancel"); 063 init(); 064 } 065 066 @Override 067 public void setupDialog() { 068 super.setupDialog(); 069 buttons.get(0).setEnabled(!Main.isOffline(OnlineResource.OSM_API)); 070 } 071 } 072}