001 // License: GPL. Copyright 2007 by Immanuel Scholz and others 002 package org.openstreetmap.josm.actions; 003 004 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 005 import static org.openstreetmap.josm.tools.I18n.tr; 006 007 import java.awt.event.ActionEvent; 008 import java.awt.event.KeyEvent; 009 010 import org.openstreetmap.josm.Main; 011 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 012 import org.openstreetmap.josm.tools.Shortcut; 013 014 /** 015 * Redoes the last command. 016 * 017 * @author imi 018 */ 019 public class RedoAction extends JosmAction implements OsmDataLayer.CommandQueueListener { 020 021 /** 022 * Construct the action with "Redo" as label. 023 */ 024 public RedoAction() { 025 super(tr("Redo"), "redo", tr("Redo the last undone action."), 026 Shortcut.registerShortcut("system:redo", tr("Edit: {0}", tr("Redo")), KeyEvent.VK_Y, Shortcut.CTRL), true); 027 setEnabled(false); 028 putValue("help", ht("/Action/Redo")); 029 } 030 031 public void actionPerformed(ActionEvent e) { 032 if (Main.map == null) 033 return; 034 Main.map.repaint(); 035 Main.main.undoRedo.redo(); 036 } 037 038 @Override 039 protected void updateEnabledState() { 040 setEnabled(Main.main != null && !Main.main.undoRedo.redoCommands.isEmpty()); 041 } 042 043 @Override 044 public void commandChanged(int queueSize, int redoSize) { 045 if (Main.main.undoRedo.redoCommands.isEmpty()) { 046 putValue(NAME, tr("Redo")); 047 setTooltip(tr("Redo the last undone action.")); 048 } else { 049 putValue(NAME, tr("Redo ...")); 050 setTooltip(tr("Redo {0}", 051 Main.main.undoRedo.redoCommands.getFirst().getDescriptionText())); 052 } 053 } 054 }