KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > gui > selection > model > SelectionNotifier


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

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

45
46   public final static String JavaDoc SELECTION_LISTENERS_BINDING =
47     "selection-listeners";
48
49   /**
50    * The listeners client interface.
51    */

52
53   private Map JavaDoc selectionListeners;
54
55   /**
56    * Constructs a new {@link SelectionNotifier} component.
57    */

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

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

100   public void selectionChanged () {
101     Iterator JavaDoc i = selectionListeners.values().iterator();
102     while (i.hasNext()) {
103       ((SelectionListener)i.next()).selectionChanged();
104     }
105   }
106 }
107
Popular Tags