KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.objectweb.fractal.gui.UserData;
28
29 import java.awt.Rectangle JavaDoc;
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 Display} interface.
36  */

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

44
45   public final static String JavaDoc DISPLAY_LISTENERS_BINDING = "display-listeners";
46
47   /**
48    * An optional client interface TODO javadoc.
49    */

50
51   public final static String JavaDoc USER_DATA_BINDING = "user-data";
52
53   /**
54    * The listeners client interface.
55    */

56
57   private Map JavaDoc displayListeners;
58
59   /**
60    * The user data client interface.
61    */

62
63   private UserData userData;
64
65   /**
66    * The size of this display.
67    */

68
69   private Rectangle JavaDoc screenSize;
70
71   /**
72    * The area of the component graph shown by this display.
73    */

74
75   private Rect displayedArea;
76
77   /**
78    * <tt>true</tt> if this display is anti aliased.
79    */

80
81   private boolean isAntialiasing;
82
83   /**
84    * The max depth at which the component graph is shown by this display.
85    */

86
87   private int maxDepth;
88
89   /**
90    * The max depth at which the component graph is shown by this display.
91    */

92
93   private int displayModeForInterface;
94
95   /**
96    * Constructs a new {@link BasicDisplay} component.
97    */

98
99   public BasicDisplay () {
100     displayedArea = new Rect(0.01, 0.01, 0.99, 0.99);
101     displayListeners = new HashMap JavaDoc();
102     maxDepth = 2;
103     displayModeForInterface = 0;
104   }
105
106   // -------------------------------------------------------------------------
107
// Implementation of the BindingController interface
108
// -------------------------------------------------------------------------
109

110   public String JavaDoc[] listFc () {
111     int size = displayListeners.size();
112     String JavaDoc[] names = new String JavaDoc[size + 1];
113     displayListeners.keySet().toArray(names);
114     names[size] = USER_DATA_BINDING;
115     return names;
116   }
117
118   public Object JavaDoc lookupFc (final String JavaDoc clientItfName) {
119     if (clientItfName.startsWith(DISPLAY_LISTENERS_BINDING)) {
120       return displayListeners.get(clientItfName);
121     } else if (USER_DATA_BINDING.equals(clientItfName)) {
122       return userData;
123     }
124     return null;
125   }
126
127   public void bindFc (
128     final String JavaDoc clientItfName,
129     final Object JavaDoc serverItf)
130   {
131     if (clientItfName.startsWith(DISPLAY_LISTENERS_BINDING)) {
132       displayListeners.put(clientItfName, serverItf);
133     } else if (USER_DATA_BINDING.equals(clientItfName)) {
134       userData = (UserData)serverItf;
135     }
136   }
137
138   public void unbindFc (final String JavaDoc clientItfName) {
139     if (clientItfName.startsWith(DISPLAY_LISTENERS_BINDING)) {
140       displayListeners.remove(clientItfName);
141     } else if (USER_DATA_BINDING.equals(clientItfName)) {
142       userData = null;
143     }
144   }
145
146   // -------------------------------------------------------------------------
147
// Implementation of the Display interface
148
// -------------------------------------------------------------------------
149

150   public Rectangle JavaDoc getScreenSize () {
151     return new Rectangle JavaDoc(screenSize);
152   }
153
154   public void setScreenSize (final Rectangle JavaDoc screenSize) {
155     try {
156       userData.setIntData(UserData.CURRENT_WIDTH, screenSize.width);
157       userData.setIntData(UserData.CURRENT_HEIGHT, screenSize.height);
158     } catch (Exception JavaDoc ex) { }
159     this.screenSize = new Rectangle JavaDoc(screenSize);
160   }
161
162   public Rect getDisplayedArea () {
163     return displayedArea;
164   }
165
166   public void setDisplayedArea (final Rect displayedArea) {
167     Rect oldDisplayedArea = this.displayedArea;
168     if (!displayedArea.equals(oldDisplayedArea)) {
169       this.displayedArea = displayedArea;
170       Iterator JavaDoc i = displayListeners.values().iterator();
171       while (i.hasNext()) {
172         DisplayListener l = (DisplayListener)i.next();
173         l.displayedAreaChanged(oldDisplayedArea);
174       }
175     }
176   }
177
178   public boolean isAntialiasing () {
179     return isAntialiasing;
180   }
181
182   public void setIsAntialiasing (final boolean isAntialiasing) {
183     if (isAntialiasing != this.isAntialiasing) {
184       this.isAntialiasing = isAntialiasing;
185       Iterator JavaDoc i = displayListeners.values().iterator();
186       while (i.hasNext()) {
187         DisplayListener l = (DisplayListener)i.next();
188         l.antialiasingChanged();
189       }
190     }
191   }
192
193   public int getMaxDepth () {
194     return maxDepth;
195   }
196
197   public void setMaxDepth (final int maxDepth) {
198     if (maxDepth != this.maxDepth) {
199       this.maxDepth = maxDepth;
200       Iterator JavaDoc i = displayListeners.values().iterator();
201       while (i.hasNext()) {
202         DisplayListener l = (DisplayListener)i.next();
203         l.maxDepthChanged();
204         try {
205           userData.setIntData(UserData.CURRENT_DEPTH, maxDepth);
206         } catch (Exception JavaDoc ex) { }
207       }
208     }
209   }
210
211   public int getItfNameDisplayMode () {
212     return displayModeForInterface;
213   }
214
215   public void setItfNameDisplayMode () {
216     displayModeForInterface++;
217     if (displayModeForInterface > 2) displayModeForInterface = 0;
218     Iterator JavaDoc i = displayListeners.values().iterator();
219     while (i.hasNext()) {
220       DisplayListener l = (DisplayListener)i.next();
221       l.itfNameDisplayModeChanged();
222     }
223   }
224 }
225
Popular Tags