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