KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > gui > clipboard > control > ClipboardAction


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.clipboard.control;
25
26 import org.objectweb.fractal.api.control.BindingController;
27
28 import org.objectweb.fractal.gui.selection.model.SelectionListener;
29 import org.objectweb.fractal.gui.selection.model.Selection;
30 import org.objectweb.fractal.gui.graph.model.GraphModel;
31 import org.objectweb.fractal.gui.model.Factory;
32 import org.objectweb.fractal.gui.clipboard.model.Clipboard;
33 import org.objectweb.fractal.swing.AbstractAction;
34
35 /**
36  * Super class of actions that acts on a clipboard model. This action
37  * listens to a {@link Selection selection} model in order to enable or disable
38  * itfself when the selection changes.
39  */

40
41 public abstract class ClipboardAction extends AbstractAction implements
42   SelectionListener,
43   BindingController
44 {
45
46   /**
47    * A mandatory client interface bound to a {@link Selection selection} model.
48    * This model is used to known the component that must be cut or copied, or
49    * the component into which the clipboard's content must be pasted.
50    */

51
52   public final static String JavaDoc SELECTION_BINDING = "selection";
53
54   /**
55    * A mandatory client interface bound to a {@link GraphModel graph} model.
56    * This graph model is passed as argument to the clipboard model methods by
57    * this controller component.
58    */

59
60   public final static String JavaDoc GRAPH_BINDING = "graph";
61
62   /**
63    * A mandatory client interface bound to a {@link Factory factory}. This
64    * factory is passed as argument to the clipboard model methods by this
65    * controller component.
66    */

67
68   public final static String JavaDoc FACTORY_BINDING = "configuration-factory";
69
70   /**
71    * A mandatory client interface bound to a {@link Clipboard clipboard} model.
72    * This is the model that is modified by this controller component.
73    */

74
75   public final static String JavaDoc CLIPBOARD_BINDING = "clipboard";
76
77   /**
78    * The selection client interface.
79    */

80
81   Selection selection;
82
83   /**
84    * The graph client interface.
85    */

86
87   GraphModel graph;
88
89   /**
90    * The factory client interface.
91    */

92
93   Factory factory;
94
95   /**
96    * The clipboard client interface.
97    */

98
99   Clipboard clipboard;
100
101   /**
102    * Constructs a new {@link ClipboardAction} component.
103    */

104
105   public ClipboardAction () {
106   }
107
108   // -------------------------------------------------------------------------
109
// Implementation of the BindingController interface
110
// -------------------------------------------------------------------------
111

112   public String JavaDoc[] listFc () {
113     return new String JavaDoc[] {
114       SELECTION_BINDING,
115       GRAPH_BINDING,
116       FACTORY_BINDING,
117       CLIPBOARD_BINDING
118     };
119   }
120
121   public Object JavaDoc lookupFc (final String JavaDoc clientItfName) {
122     if (SELECTION_BINDING.equals(clientItfName)) {
123       return selection;
124     } else if (GRAPH_BINDING.equals(clientItfName)) {
125       return graph;
126     } else if (FACTORY_BINDING.equals(clientItfName)) {
127       return factory;
128     } else if (CLIPBOARD_BINDING.equals(clientItfName)) {
129       return clipboard;
130     }
131     return null;
132   }
133
134   public void bindFc (
135     final String JavaDoc clientItfName,
136     final Object JavaDoc serverItf)
137   {
138     if (SELECTION_BINDING.equals(clientItfName)) {
139       selection = (Selection)serverItf;
140     } else if (GRAPH_BINDING.equals(clientItfName)) {
141       graph = (GraphModel)serverItf;
142     } else if (FACTORY_BINDING.equals(clientItfName)) {
143       factory = (Factory)serverItf;
144     } else if (CLIPBOARD_BINDING.equals(clientItfName)) {
145       clipboard = (Clipboard)serverItf;
146     }
147   }
148
149   public void unbindFc (final String JavaDoc clientItfName) {
150     if (SELECTION_BINDING.equals(clientItfName)) {
151       selection = null;
152     } else if (GRAPH_BINDING.equals(clientItfName)) {
153       graph = null;
154     } else if (FACTORY_BINDING.equals(clientItfName)) {
155       factory = null;
156     } else if (CLIPBOARD_BINDING.equals(clientItfName)) {
157       clipboard = null;
158     }
159   }
160 }
Popular Tags