KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > gui > graph > model > BasicTools


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.model;
25
26 import org.objectweb.fractal.api.control.BindingController;
27
28 import org.objectweb.fractal.gui.model.Interface;
29
30 import java.util.Map JavaDoc;
31 import java.util.HashMap JavaDoc;
32 import java.util.Iterator JavaDoc;
33
34 /**
35  * Basic implementation of the {@link Tools} interface.
36  */

37
38 public class BasicTools implements Tools, BindingController {
39
40   /**
41    * A collection client interface bound to the {@link ToolsListener listeners}
42    * of this model.
43    */

44
45   public final static String JavaDoc TOOLS_LISTENERS_BINDING = "tools-listeners";
46
47   /**
48    * The tool client interface.
49    */

50
51   private Map JavaDoc toolsListeners;
52
53   /**
54    * The currently selected tool.
55    */

56
57   private int tool;
58
59   /**
60    * The client interface that will be bound by the {@link #BIND} tool.
61    */

62
63   private Interface bindItf;
64
65   /**
66    * Constructs a new {@link BasicTools} component.
67    */

68
69   public BasicTools () {
70     toolsListeners = new HashMap JavaDoc();
71   }
72
73   // -------------------------------------------------------------------------
74
// Implementation of the BindingController interface
75
// -------------------------------------------------------------------------
76

77   public String JavaDoc[] listFc () {
78     return (String JavaDoc[])toolsListeners.keySet().toArray(
79       new String JavaDoc[toolsListeners.size()]);
80   }
81
82   public Object JavaDoc lookupFc (final String JavaDoc clientItfName) {
83     if (clientItfName.startsWith(TOOLS_LISTENERS_BINDING)) {
84       return toolsListeners.get(clientItfName);
85     }
86     return null;
87   }
88
89   public void bindFc (
90     final String JavaDoc clientItfName,
91     final Object JavaDoc serverItf)
92   {
93     if (clientItfName.startsWith(TOOLS_LISTENERS_BINDING)) {
94       toolsListeners.put(clientItfName, serverItf);
95     }
96   }
97
98   public void unbindFc (final String JavaDoc clientItfName) {
99     if (clientItfName.startsWith(TOOLS_LISTENERS_BINDING)) {
100       toolsListeners.remove(clientItfName);
101     }
102   }
103
104   // -------------------------------------------------------------------------
105
// Implementation of the Tools interface
106
// -------------------------------------------------------------------------
107

108   public int getTool () {
109     return tool;
110   }
111
112   public void setTool (final int tool) {
113     if (tool != this.tool) {
114       this.tool = tool;
115       Iterator JavaDoc i = toolsListeners.values().iterator();
116       while (i.hasNext()) {
117         ((ToolsListener)i.next()).toolChanged();
118       }
119     }
120   }
121
122   public Interface getBindInterface () {
123     return bindItf;
124   }
125
126   public void setBindInterface (final Interface i) {
127     this.bindItf = i;
128   }
129 }
130
Popular Tags