1 23 24 package org.objectweb.fractal.gui.undo.control; 25 26 import org.objectweb.fractal.api.control.BindingController; 27 28 import org.objectweb.fractal.gui.undo.model.UndoListener; 29 import org.objectweb.fractal.gui.undo.model.UndoManager; 30 import org.objectweb.fractal.swing.AbstractAction; 31 32 import java.awt.event.ActionEvent ; 33 import java.net.URL ; 34 35 import javax.swing.ImageIcon ; 36 import javax.swing.KeyStroke ; 37 38 44 45 public class UndoAction extends AbstractAction implements 46 UndoListener, 47 BindingController 48 { 49 50 54 55 public final static String UNDO_MANAGER_BINDING = "undo-manager"; 56 57 60 61 private UndoManager undoManager; 62 63 66 67 public UndoAction () { 68 putValue(NAME, "Undo"); 69 putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("control Z")); 70 putValue(SHORT_DESCRIPTION, "Undo"); 71 URL url = getClass().getResource( 72 "/org/objectweb/fractal/gui/resources/undo.gif"); 73 putValue(SMALL_ICON, new ImageIcon (url)); 74 } 75 76 80 public String [] listFc () { 81 return new String [] { UNDO_MANAGER_BINDING }; 82 } 83 84 public Object lookupFc (final String clientItfName) { 85 if (UNDO_MANAGER_BINDING.equals(clientItfName)) { 86 return undoManager; 87 } 88 return null; 89 } 90 91 public void bindFc ( 92 final String clientItfName, 93 final Object serverItf) 94 { 95 if (UNDO_MANAGER_BINDING.equals(clientItfName)) { 96 undoManager = (UndoManager)serverItf; 97 } 98 } 99 100 public void unbindFc (final String clientItfName) { 101 if (UNDO_MANAGER_BINDING.equals(clientItfName)) { 102 undoManager = null; 103 } 104 } 105 106 110 public void undoStateChanged () { 111 setEnabled(undoManager.canUndo()); 112 } 113 114 118 public void actionPerformed (final ActionEvent e) { 119 undoManager.undo(); 120 } 121 } 122 | Popular Tags |