KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > gui > history > control > GoNextAction


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.history.control;
25
26 import org.objectweb.fractal.api.control.BindingController;
27
28 import org.objectweb.fractal.gui.history.model.HistoryListener;
29 import org.objectweb.fractal.gui.history.model.HistoryManager;
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 HistoryManager#goNext goNext} method on
40  * an {@link HistoryManager}. This action listens to the history model in order
41  * to enable or disable itfself when the {@link HistoryManager#canGoNext
42  * canGoNext} state changes.
43  */

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

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

60
61   private HistoryManager historyManager;
62
63   /**
64    * Constructs a new {@link GoNextAction} component.
65    */

66
67   public GoNextAction () {
68     putValue(NAME, "Next");
69     putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("F4"));
70     putValue(SHORT_DESCRIPTION, "Next");
71     URL JavaDoc url = getClass().getResource(
72       "/org/objectweb/fractal/gui/resources/1rightarrow.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[] { HISTORY_MANAGER_BINDING };
82   }
83
84   public Object JavaDoc lookupFc (final String JavaDoc clientItfName) {
85     if (HISTORY_MANAGER_BINDING.equals(clientItfName)) {
86       return historyManager;
87     }
88     return null;
89   }
90
91   public void bindFc (
92     final String JavaDoc clientItfName,
93     final Object JavaDoc serverItf)
94   {
95     if (HISTORY_MANAGER_BINDING.equals(clientItfName)) {
96       historyManager = (HistoryManager)serverItf;
97     }
98   }
99
100   public void unbindFc (final String JavaDoc clientItfName) {
101     if (HISTORY_MANAGER_BINDING.equals(clientItfName)) {
102       historyManager = null;
103     }
104   }
105
106   // -------------------------------------------------------------------------
107
// Implementation of the UndoListener interface
108
// -------------------------------------------------------------------------
109

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

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