KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > gui > graph > view > GraphViewNotifier


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.graph.view;
25
26 import org.objectweb.fractal.api.control.BindingController;
27
28 import java.util.HashMap JavaDoc;
29 import java.util.Map JavaDoc;
30 import java.util.Iterator JavaDoc;
31 import java.awt.event.MouseEvent JavaDoc;
32
33 /**
34  * A {@link GraphViewListener} that notifies other {@link GraphViewListener}s.
35  */

36
37 public class GraphViewNotifier implements
38   GraphViewListener,
39   BindingController
40 {
41
42   /**
43    * A collection client interface bound to the {@link GraphViewListener
44    * listeners} of this component.
45    */

46
47   public final static String JavaDoc GRAPH_VIEW_LISTENERS_BINDING =
48     "graph-view-listeners";
49
50   /**
51    * The listeners client interface.
52    */

53
54   private Map JavaDoc graphViewListeners;
55
56   /**
57    * Constructs a new {@link GraphViewNotifier} component.
58    */

59
60   public GraphViewNotifier () {
61     graphViewListeners = new HashMap JavaDoc();
62   }
63
64   // -------------------------------------------------------------------------
65
// Implementation of the BindingController interface
66
// -------------------------------------------------------------------------
67

68   public String JavaDoc[] listFc () {
69     return (String JavaDoc[])graphViewListeners.keySet().toArray(
70       new String JavaDoc[graphViewListeners.size()]);
71   }
72
73   public Object JavaDoc lookupFc (final String JavaDoc clientItfName) {
74     if (clientItfName.startsWith(GRAPH_VIEW_LISTENERS_BINDING)) {
75       return graphViewListeners.get(clientItfName);
76     }
77     return null;
78   }
79
80   public void bindFc (
81     final String JavaDoc clientItfName,
82     final Object JavaDoc serverItf)
83   {
84     if (clientItfName.startsWith(GRAPH_VIEW_LISTENERS_BINDING)) {
85       graphViewListeners.put(clientItfName, serverItf);
86     }
87   }
88
89   public void unbindFc (final String JavaDoc clientItfName) {
90     if (clientItfName.startsWith(GRAPH_VIEW_LISTENERS_BINDING)) {
91       graphViewListeners.remove(clientItfName);
92     }
93   }
94
95   // -------------------------------------------------------------------------
96
// Implementation of the GraphViewListener interface
97
// -------------------------------------------------------------------------
98

99   public void viewChanged () {
100     Iterator JavaDoc i = graphViewListeners.values().iterator();
101     while (i.hasNext()) {
102       ((GraphViewListener)i.next()).viewChanged();
103     }
104   }
105
106   public void mousePressed (final MouseEvent JavaDoc e, final ComponentPart p) {
107     Iterator JavaDoc i = graphViewListeners.values().iterator();
108     while (i.hasNext()) {
109       ((GraphViewListener)i.next()).mousePressed(e, p);
110     }
111   }
112
113   public void mouseReleased (final MouseEvent JavaDoc e, final ComponentPart p) {
114     Iterator JavaDoc i = graphViewListeners.values().iterator();
115     while (i.hasNext()) {
116       ((GraphViewListener)i.next()).mouseReleased(e, p);
117     }
118   }
119
120   public void mouseClicked (final MouseEvent JavaDoc e, final ComponentPart p) {
121     Iterator JavaDoc i = graphViewListeners.values().iterator();
122     while (i.hasNext()) {
123       ((GraphViewListener)i.next()).mouseClicked(e, p);
124     }
125   }
126
127   public void mouseEntered (final MouseEvent JavaDoc e) {
128     Iterator JavaDoc i = graphViewListeners.values().iterator();
129     while (i.hasNext()) {
130       ((GraphViewListener)i.next()).mouseEntered(e);
131     }
132   }
133
134   public void mouseExited (final MouseEvent JavaDoc e) {
135     Iterator JavaDoc i = graphViewListeners.values().iterator();
136     while (i.hasNext()) {
137       ((GraphViewListener)i.next()).mouseExited(e);
138     }
139   }
140
141   public void mouseDragged (final MouseEvent JavaDoc e) {
142     Iterator JavaDoc i = graphViewListeners.values().iterator();
143     while (i.hasNext()) {
144       ((GraphViewListener)i.next()).mouseDragged(e);
145     }
146   }
147
148   public void mouseMoved (final MouseEvent JavaDoc e, final ComponentPart p) {
149     Iterator JavaDoc i = graphViewListeners.values().iterator();
150     while (i.hasNext()) {
151       ((GraphViewListener)i.next()).mouseMoved(e, p);
152     }
153   }
154 }
155
Popular Tags