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.tools.Shortcut;
011
012/**
013 * User action to clear the current selection.
014 */
015public class UnselectAllAction extends JosmAction {
016
017    /**
018     * Constructs a new {@code UnselectAllAction}.
019     */
020    public UnselectAllAction() {
021        super(tr("Unselect All"), "unselectall", tr("Unselect all objects."),
022            Shortcut.registerShortcut("edit:unselectall", tr("Edit: {0}",
023            tr("Unselect All")), KeyEvent.VK_ESCAPE, Shortcut.DIRECT), true);
024
025        setHelpId(ht("/Action/UnselectAll"));
026    }
027
028    @Override
029    public void actionPerformed(ActionEvent e) {
030        if (!isEnabled())
031            return;
032        getLayerManager().getActiveData().setSelected();
033    }
034
035    /**
036     * Refreshes the enabled state
037     */
038    @Override
039    protected void updateEnabledState() {
040        setEnabled(getLayerManager().getActiveData() != null);
041    }
042}