001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.gui.dialogs.layer;
003
004import static org.openstreetmap.josm.tools.I18n.tr;
005
006import java.awt.event.ActionEvent;
007
008import javax.swing.AbstractAction;
009
010import org.openstreetmap.josm.gui.dialogs.LayerListDialog.LayerListModel;
011import org.openstreetmap.josm.tools.ImageProvider;
012
013/**
014 * The action to move up the currently selected entries in the list.
015 */
016public class MoveUpAction extends AbstractAction implements IEnabledStateUpdating {
017    private final LayerListModel model;
018
019    /**
020     * Constructs a new {@code MoveUpAction}.
021     * @param model layer list model
022     */
023    public MoveUpAction(LayerListModel model) {
024        this.model = model;
025        putValue(NAME, tr("Move up"));
026        new ImageProvider("dialogs", "up").getResource().attachImageIcon(this, true);
027        putValue(SHORT_DESCRIPTION, tr("Move the selected layer one row up."));
028        updateEnabledState();
029    }
030
031    @Override
032    public void updateEnabledState() {
033        setEnabled(model.canMoveUp());
034    }
035
036    @Override
037    public void actionPerformed(ActionEvent e) {
038        model.moveUp();
039    }
040}