KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > gui > undo > control > RedoAction


1 /***
2  * FractalGUI: a graphical tool to edit Fractal component configurations.
3  * Copyright (C) 2003 France Telecom R&D
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Contact: fractal@objectweb.org
20  *
21  * Authors: Eric Bruneton, Patrice Fauvel
22  */

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 JavaDoc;
33 import java.net.URL JavaDoc;
34
35 import javax.swing.ImageIcon JavaDoc;
36 import javax.swing.KeyStroke JavaDoc;
37
38 /**
39  * An action that just calls the {@link UndoManager#redo redo} method on an
40  * {@link UndoManager}. This action listens to the undo model in order to enable
41  * or disable itfself when the {@link UndoManager#canRedo canRedo} state
42  * changes.
43  */

44
45 public class RedoAction extends AbstractAction implements
46   UndoListener,
47   BindingController
48 {
49
50   /**
51    * A mandatory client interface bound to a {@link UndoManager undo} model.
52    * This is the model modified by this controller component.
53    */

54
55   public final static String JavaDoc UNDO_MANAGER_BINDING = "undo-manager";
56
57   /**
58    * The undo client interface.
59    */

60
61   private UndoManager undoManager;
62
63   /**
64    * Constructs a new {@link RedoAction} component.
65    */

66
67   public RedoAction () {
68     putValue(NAME, "Redo");
69     putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("control shift Z"));
70     putValue(SHORT_DESCRIPTION, "Redo");
71     URL JavaDoc url = getClass().getResource(
72       "/org/objectweb/fractal/gui/resources/redo.gif");
73     putValue(SMALL_ICON, new ImageIcon JavaDoc(url));
74   }
75
76   // -------------------------------------------------------------------------
77
// Implementation of the BindingController interface
78
// -------------------------------------------------------------------------
79

80   public String JavaDoc[] listFc () {
81     return new String JavaDoc[] { UNDO_MANAGER_BINDING };
82   }
83
84   public Object JavaDoc lookupFc (final String JavaDoc clientItfName) {
85     if (UNDO_MANAGER_BINDING.equals(clientItfName)) {
86       return undoManager;
87     }
88     return null;
89   }
90
91   public void bindFc (
92     final String JavaDoc clientItfName,
93     final Object JavaDoc serverItf)
94   {
95     if (UNDO_MANAGER_BINDING.equals(clientItfName)) {
96       undoManager = (UndoManager)serverItf;
97     }
98   }
99
100   public void unbindFc (final String JavaDoc clientItfName) {
101     if (UNDO_MANAGER_BINDING.equals(clientItfName)) {
102       undoManager = null;
103     }
104   }
105
106   // -------------------------------------------------------------------------
107
// Implementation of the UndoListener interface
108
// -------------------------------------------------------------------------
109

110   public void undoStateChanged () {
111     setEnabled(undoManager.canRedo());
112   }
113
114   // -------------------------------------------------------------------------
115
// Implementation of the ActionListener interface
116
// -------------------------------------------------------------------------
117

118   public void actionPerformed (final ActionEvent JavaDoc e) {
119     undoManager.redo();
120   }
121 }
122
Popular Tags