KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > gui > frame > DefaultFrameController


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.core.gui.frame;
19
20 import java.awt.event.MouseAdapter JavaDoc;
21 import java.awt.event.MouseListener JavaDoc;
22
23 import javax.swing.JPanel JavaDoc;
24 import javax.swing.event.EventListenerList JavaDoc;
25
26 import org.columba.api.gui.frame.IContainer;
27 import org.columba.api.gui.frame.IFrameMediator;
28 import org.columba.api.gui.frame.event.FrameEvent;
29 import org.columba.api.gui.frame.event.IFrameMediatorListener;
30 import org.columba.api.selection.ISelectionManager;
31 import org.columba.core.config.ViewItem;
32 import org.columba.core.context.semantic.SemanticContext;
33 import org.columba.core.context.semantic.api.ISemanticContext;
34 import org.columba.core.gui.search.SearchPanel;
35 import org.columba.core.gui.search.api.ISearchPanel;
36 import org.columba.core.resourceloader.GlobalResourceLoader;
37 import org.columba.core.selection.SelectionManager;
38
39 /**
40  *
41  * @author fdietz
42  *
43  */

44 public class DefaultFrameController implements IFrameMediator {
45
46     /**
47      * Saves view information like position, size and maximization state
48      */

49     protected ViewItem viewItem;
50
51     /**
52      * Selection handler
53      */

54     protected ISelectionManager selectionManager;
55
56     /**
57      * ID of controller
58      */

59     protected String JavaDoc id;
60
61     private IContainer container;
62
63     protected EventListenerList JavaDoc listenerList = new EventListenerList JavaDoc();
64
65     // Menuitems use this to display a string in the statusbar
66
protected TooltipMouseHandler tooltipMouseHandler;
67
68     protected ISearchPanel searchPanel;
69
70     protected ISemanticContext semanticContext;
71
72     /**
73      *
74      */

75     public DefaultFrameController(ViewItem viewItem) {
76
77         super();
78
79         this.viewItem = viewItem;
80
81         this.id = viewItem.get("id");
82
83         // init selection handler
84
selectionManager = new SelectionManager();
85
86         searchPanel = new SearchPanel(this);
87
88         semanticContext = new SemanticContext();
89
90         tooltipMouseHandler = new TooltipMouseHandler(this);
91
92     }
93
94     public DefaultFrameController(String JavaDoc id) {
95         this(ViewItem.createDefault(id));
96
97     }
98
99     /**
100      * @return ViewItem
101      */

102     public ViewItem getViewItem() {
103         return viewItem;
104     }
105
106     /**
107      * Sets the item.
108      *
109      * @param item
110      * The item to set
111      */

112     public void setViewItem(ViewItem item) {
113         this.viewItem = item;
114     }
115
116     /**
117      * @return SelectionManager
118      */

119     public ISelectionManager getSelectionManager() {
120         return selectionManager;
121     }
122
123     /**
124      * Sets the selectionManager.
125      *
126      * @param selectionManager
127      * The selectionManager to set
128      */

129     public void setSelectionManager(ISelectionManager selectionManager) {
130         this.selectionManager = selectionManager;
131     }
132
133     /**
134      * @see org.columba.api.gui.frame.IFrameMediator#getContainer()
135      */

136     public IContainer getContainer() {
137         return container;
138     }
139
140     /**
141      * @see org.columba.api.gui.frame.IFrameMediator#loadPositions(org.columba.core.config.ViewItem)
142      */

143     // public void loadPositions(ViewItem viewItem) {
144
//
145
// }
146
/**
147      * @see org.columba.api.gui.frame.IFrameMediator#savePositions(org.columba.core.config.ViewItem)
148      */

149     // public void savePositions(ViewItem viewItem) {
150
//
151
// }
152
/**
153      * @see org.columba.api.gui.frame.IFrameMediator#setContainer(org.columba.api.gui.frame.IContainer)
154      */

155     public void setContainer(IContainer c) {
156         container = c;
157     }
158
159     /**
160      * @see org.columba.api.gui.frame.IFrameMediator#getView()
161      */

162     public IContainer getView() {
163         return container;
164     }
165
166     /**
167      * @see org.columba.api.gui.frame.IFrameMediator#getString(java.lang.String,
168      * java.lang.String, java.lang.String)
169      */

170     public String JavaDoc getString(String JavaDoc sPath, String JavaDoc sName, String JavaDoc sID) {
171         return GlobalResourceLoader.getString(sPath, sName, sID);
172     }
173
174     /**
175      * @see org.columba.api.gui.frame.IFrameMediator#getContentPane()
176      */

177     public JPanel JavaDoc getContentPane() {
178         return new JPanel JavaDoc();
179     }
180
181     /**
182      * @see org.columba.api.gui.frame.IFrameMediator#close()
183      */

184     public void close(IContainer container) {
185         // overwrite this method
186
}
187
188     public void savePositions() {
189         // overwrite this method
190

191     }
192
193     public void loadPositions() {
194         // overwrite this method
195
}
196
197     /**
198      * Returns iD of controller
199      *
200      * @return iD of controller
201      */

202     public String JavaDoc getId() {
203         return id;
204     }
205
206     class MyMouseAdapter extends MouseAdapter JavaDoc {
207
208     }
209
210     /** ********************** frame eventing ********************* */
211
212     public void addListener(IFrameMediatorListener l) {
213         listenerList.add(IFrameMediatorListener.class, l);
214     }
215
216     public void removeListener(IFrameMediatorListener l) {
217         listenerList.remove(IFrameMediatorListener.class, l);
218     }
219
220     public void fireTitleChanged(String JavaDoc title) {
221         FrameEvent e = new FrameEvent(this, title);
222         // Guaranteed to return a non-null array
223
Object JavaDoc[] listeners = listenerList.getListenerList();
224
225         // Process the listeners last to first, notifying
226
// those that are interested in this event
227
for (int i = listeners.length - 2; i >= 0; i -= 2) {
228             if (listeners[i] == IFrameMediatorListener.class) {
229                 ((IFrameMediatorListener) listeners[i + 1]).titleChanged(e);
230             }
231         }
232
233     }
234
235     public void fireStatusMessageChanged(String JavaDoc statusMessage) {
236         FrameEvent e = new FrameEvent(this, statusMessage);
237         // Guaranteed to return a non-null array
238
Object JavaDoc[] listeners = listenerList.getListenerList();
239
240         // Process the listeners last to first, notifying
241
// those that are interested in this event
242
for (int i = listeners.length - 2; i >= 0; i -= 2) {
243             if (listeners[i] == IFrameMediatorListener.class) {
244                 ((IFrameMediatorListener) listeners[i + 1])
245                         .statusMessageChanged(e);
246             }
247         }
248
249     }
250
251     public void fireTaskStatusChanged() {
252         FrameEvent e = new FrameEvent(this);
253         // Guaranteed to return a non-null array
254
Object JavaDoc[] listeners = listenerList.getListenerList();
255
256         // Process the listeners last to first, notifying
257
// those that are interested in this event
258
for (int i = listeners.length - 2; i >= 0; i -= 2) {
259             if (listeners[i] == IFrameMediatorListener.class) {
260                 ((IFrameMediatorListener) listeners[i + 1])
261                         .taskStatusChanged(e);
262             }
263         }
264
265     }
266
267     public void fireVisibilityChanged(boolean visible) {
268         FrameEvent e = new FrameEvent(this, visible);
269         // Guaranteed to return a non-null array
270
Object JavaDoc[] listeners = listenerList.getListenerList();
271
272         // Process the listeners last to first, notifying
273
// those that are interested in this event
274
for (int i = listeners.length - 2; i >= 0; i -= 2) {
275             if (listeners[i] == IFrameMediatorListener.class) {
276                 ((IFrameMediatorListener) listeners[i + 1])
277                         .visibilityChanged(e);
278             }
279         }
280
281     }
282
283     public void fireLayoutChanged() {
284         FrameEvent e = new FrameEvent(this);
285         // Guaranteed to return a non-null array
286
Object JavaDoc[] listeners = listenerList.getListenerList();
287
288         // Process the listeners last to first, notifying
289
// those that are interested in this event
290
for (int i = listeners.length - 2; i >= 0; i -= 2) {
291             if (listeners[i] == IFrameMediatorListener.class) {
292                 ((IFrameMediatorListener) listeners[i + 1]).layoutChanged(e);
293             }
294         }
295
296     }
297
298     public void fireClosed() {
299         FrameEvent e = new FrameEvent(this);
300         // Guaranteed to return a non-null array
301
Object JavaDoc[] listeners = listenerList.getListenerList();
302
303         // Process the listeners last to first, notifying
304
// those that are interested in this event
305
for (int i = listeners.length - 2; i >= 0; i -= 2) {
306             if (listeners[i] == IFrameMediatorListener.class) {
307                 ((IFrameMediatorListener) listeners[i + 1]).closed(e);
308             }
309         }
310
311     }
312
313     public void fireToolBarVisibilityChanged(boolean visible) {
314         FrameEvent e = new FrameEvent(this, visible);
315         // Guaranteed to return a non-null array
316
Object JavaDoc[] listeners = listenerList.getListenerList();
317
318         // Process the listeners last to first, notifying
319
// those that are interested in this event
320
for (int i = listeners.length - 2; i >= 0; i -= 2) {
321             if (listeners[i] == IFrameMediatorListener.class) {
322                 ((IFrameMediatorListener) listeners[i + 1])
323                         .toolBarVisibilityChanged(e);
324             }
325         }
326     }
327
328     public void fireComponentChanged() {
329         FrameEvent e = new FrameEvent(this);
330         // Guaranteed to return a non-null array
331
Object JavaDoc[] listeners = listenerList.getListenerList();
332
333         // Process the listeners last to first, notifying
334
// those that are interested in this event
335
for (int i = listeners.length - 2; i >= 0; i -= 2) {
336             if (listeners[i] == IFrameMediatorListener.class) {
337                 ((IFrameMediatorListener) listeners[i + 1])
338                         .switchedComponent(e);
339             }
340         }
341     }
342
343     /** *********************** container callbacks ************* */
344
345     public void extendMenu(IContainer container) {
346         // overwrite this method
347
}
348
349     public void extendToolBar(IContainer container) {
350         // overwrite this method
351
}
352
353     public void initFrame(IContainer container) {
354         // overwrite this method
355
}
356
357     /** ********************************************************* */
358
359     public MouseListener JavaDoc getMouseTooltipHandler() {
360         return tooltipMouseHandler;
361     }
362
363     /**
364      * @see org.columba.api.gui.frame.IFrameMediator#isInitialized()
365      */

366     public boolean isInitialized() {
367         // TODO Auto-generated method stub
368
return false;
369     }
370
371     public ISearchPanel getSearchPanel() {
372         return searchPanel;
373     }
374
375
376     public ISemanticContext getSemanticContext() {
377         return semanticContext;
378     }
379
380
381 }
Popular Tags