1 19 20 package org.netbeans.modules.refactoring.spi.impl; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyChangeListener ; 24 import javax.swing.Action ; 25 import javax.swing.SwingUtilities ; 26 import org.openide.util.HelpCtx; 27 import org.openide.util.NbBundle; 28 import org.openide.util.actions.CallableSystemAction; 29 30 public class RedoAction extends CallableSystemAction implements PropertyChangeListener { 31 32 private UndoManager undoManager; 33 34 public RedoAction() { 35 putValue(Action.NAME, getString("LBL_Redo")); putValue("noIconInMenu", Boolean.TRUE); undoManager = UndoManager.getDefault(); 38 undoManager.addPropertyChangeListener(this); 39 updateState(); 40 } 41 42 public void propertyChange (PropertyChangeEvent event) { 43 updateState(); 44 } 45 46 private void updateState() { 47 String desc = undoManager.getRedoDescription(); 48 String name = getString("LBL_Redo"); 49 if (desc != null) { 50 name += " [" + desc + "]"; } 52 53 final String n = name; 54 Runnable r = new Runnable () { 55 public void run() { 56 setEnabled(undoManager.isRedoAvailable()); 57 putValue(Action.NAME, n); 58 } 59 }; 60 61 if (SwingUtilities.isEventDispatchThread()) { 62 r.run(); 63 } else { 64 SwingUtilities.invokeLater(r); 65 } 66 } 67 68 private static final String getString(String key) { 69 return NbBundle.getMessage(RedoAction.class, key); 70 } 71 72 public void performAction() { 73 undoManager.redo(); 74 undoManager.saveAll(); 75 } 76 77 public org.openide.util.HelpCtx getHelpCtx() { 78 return HelpCtx.DEFAULT_HELP; 79 } 80 81 public String getName() { 82 return (String ) getValue(Action.NAME); 83 } 84 85 protected boolean asynchronous() { 86 return true; 87 } 88 } 89 | Popular Tags |