001: // The contents of this file are subject to the Mozilla Public License Version
002: // 1.1
003: //(the "License"); you may not use this file except in compliance with the
004: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005: //
006: //Software distributed under the License is distributed on an "AS IS" basis,
007: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: //for the specific language governing rights and
009: //limitations under the License.
010: //
011: //The Original Code is "The Columba Project"
012: //
013: //The Initial Developers of the Original Code are Frederik Dietz and Timo
014: // Stich.
015: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016: //
017: //All Rights Reserved.
018: package org.columba.core.gui.frame;
019:
020: import java.awt.event.MouseAdapter;
021: import java.awt.event.MouseListener;
022:
023: import javax.swing.JPanel;
024: import javax.swing.event.EventListenerList;
025:
026: import org.columba.api.gui.frame.IContainer;
027: import org.columba.api.gui.frame.IFrameMediator;
028: import org.columba.api.gui.frame.event.FrameEvent;
029: import org.columba.api.gui.frame.event.IFrameMediatorListener;
030: import org.columba.api.selection.ISelectionManager;
031: import org.columba.core.config.ViewItem;
032: import org.columba.core.context.semantic.SemanticContext;
033: import org.columba.core.context.semantic.api.ISemanticContext;
034: import org.columba.core.gui.search.SearchPanel;
035: import org.columba.core.gui.search.api.ISearchPanel;
036: import org.columba.core.resourceloader.GlobalResourceLoader;
037: import org.columba.core.selection.SelectionManager;
038:
039: /**
040: *
041: * @author fdietz
042: *
043: */
044: public class DefaultFrameController implements IFrameMediator {
045:
046: /**
047: * Saves view information like position, size and maximization state
048: */
049: protected ViewItem viewItem;
050:
051: /**
052: * Selection handler
053: */
054: protected ISelectionManager selectionManager;
055:
056: /**
057: * ID of controller
058: */
059: protected String id;
060:
061: private IContainer container;
062:
063: protected EventListenerList listenerList = new EventListenerList();
064:
065: // Menuitems use this to display a string in the statusbar
066: protected TooltipMouseHandler tooltipMouseHandler;
067:
068: protected ISearchPanel searchPanel;
069:
070: protected ISemanticContext semanticContext;
071:
072: /**
073: *
074: */
075: public DefaultFrameController(ViewItem viewItem) {
076:
077: super ();
078:
079: this .viewItem = viewItem;
080:
081: this .id = viewItem.get("id");
082:
083: // init selection handler
084: selectionManager = new SelectionManager();
085:
086: searchPanel = new SearchPanel(this );
087:
088: semanticContext = new SemanticContext();
089:
090: tooltipMouseHandler = new TooltipMouseHandler(this );
091:
092: }
093:
094: public DefaultFrameController(String id) {
095: this (ViewItem.createDefault(id));
096:
097: }
098:
099: /**
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 getString(String sPath, String sName, String sID) {
171: return GlobalResourceLoader.getString(sPath, sName, sID);
172: }
173:
174: /**
175: * @see org.columba.api.gui.frame.IFrameMediator#getContentPane()
176: */
177: public JPanel getContentPane() {
178: return new JPanel();
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 getId() {
203: return id;
204: }
205:
206: class MyMouseAdapter extends MouseAdapter {
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 title) {
221: FrameEvent e = new FrameEvent(this , title);
222: // Guaranteed to return a non-null array
223: Object[] 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])
230: .titleChanged(e);
231: }
232: }
233:
234: }
235:
236: public void fireStatusMessageChanged(String statusMessage) {
237: FrameEvent e = new FrameEvent(this , statusMessage);
238: // Guaranteed to return a non-null array
239: Object[] listeners = listenerList.getListenerList();
240:
241: // Process the listeners last to first, notifying
242: // those that are interested in this event
243: for (int i = listeners.length - 2; i >= 0; i -= 2) {
244: if (listeners[i] == IFrameMediatorListener.class) {
245: ((IFrameMediatorListener) listeners[i + 1])
246: .statusMessageChanged(e);
247: }
248: }
249:
250: }
251:
252: public void fireTaskStatusChanged() {
253: FrameEvent e = new FrameEvent(this );
254: // Guaranteed to return a non-null array
255: Object[] listeners = listenerList.getListenerList();
256:
257: // Process the listeners last to first, notifying
258: // those that are interested in this event
259: for (int i = listeners.length - 2; i >= 0; i -= 2) {
260: if (listeners[i] == IFrameMediatorListener.class) {
261: ((IFrameMediatorListener) listeners[i + 1])
262: .taskStatusChanged(e);
263: }
264: }
265:
266: }
267:
268: public void fireVisibilityChanged(boolean visible) {
269: FrameEvent e = new FrameEvent(this , visible);
270: // Guaranteed to return a non-null array
271: Object[] listeners = listenerList.getListenerList();
272:
273: // Process the listeners last to first, notifying
274: // those that are interested in this event
275: for (int i = listeners.length - 2; i >= 0; i -= 2) {
276: if (listeners[i] == IFrameMediatorListener.class) {
277: ((IFrameMediatorListener) listeners[i + 1])
278: .visibilityChanged(e);
279: }
280: }
281:
282: }
283:
284: public void fireLayoutChanged() {
285: FrameEvent e = new FrameEvent(this );
286: // Guaranteed to return a non-null array
287: Object[] listeners = listenerList.getListenerList();
288:
289: // Process the listeners last to first, notifying
290: // those that are interested in this event
291: for (int i = listeners.length - 2; i >= 0; i -= 2) {
292: if (listeners[i] == IFrameMediatorListener.class) {
293: ((IFrameMediatorListener) listeners[i + 1])
294: .layoutChanged(e);
295: }
296: }
297:
298: }
299:
300: public void fireClosed() {
301: FrameEvent e = new FrameEvent(this );
302: // Guaranteed to return a non-null array
303: Object[] listeners = listenerList.getListenerList();
304:
305: // Process the listeners last to first, notifying
306: // those that are interested in this event
307: for (int i = listeners.length - 2; i >= 0; i -= 2) {
308: if (listeners[i] == IFrameMediatorListener.class) {
309: ((IFrameMediatorListener) listeners[i + 1]).closed(e);
310: }
311: }
312:
313: }
314:
315: public void fireToolBarVisibilityChanged(boolean visible) {
316: FrameEvent e = new FrameEvent(this , visible);
317: // Guaranteed to return a non-null array
318: Object[] listeners = listenerList.getListenerList();
319:
320: // Process the listeners last to first, notifying
321: // those that are interested in this event
322: for (int i = listeners.length - 2; i >= 0; i -= 2) {
323: if (listeners[i] == IFrameMediatorListener.class) {
324: ((IFrameMediatorListener) listeners[i + 1])
325: .toolBarVisibilityChanged(e);
326: }
327: }
328: }
329:
330: public void fireComponentChanged() {
331: FrameEvent e = new FrameEvent(this );
332: // Guaranteed to return a non-null array
333: Object[] listeners = listenerList.getListenerList();
334:
335: // Process the listeners last to first, notifying
336: // those that are interested in this event
337: for (int i = listeners.length - 2; i >= 0; i -= 2) {
338: if (listeners[i] == IFrameMediatorListener.class) {
339: ((IFrameMediatorListener) listeners[i + 1])
340: .switchedComponent(e);
341: }
342: }
343: }
344:
345: /** *********************** container callbacks ************* */
346:
347: public void extendMenu(IContainer container) {
348: // overwrite this method
349: }
350:
351: public void extendToolBar(IContainer container) {
352: // overwrite this method
353: }
354:
355: public void initFrame(IContainer container) {
356: // overwrite this method
357: }
358:
359: /** ********************************************************* */
360:
361: public MouseListener getMouseTooltipHandler() {
362: return tooltipMouseHandler;
363: }
364:
365: /**
366: * @see org.columba.api.gui.frame.IFrameMediator#isInitialized()
367: */
368: public boolean isInitialized() {
369: // TODO Auto-generated method stub
370: return false;
371: }
372:
373: public ISearchPanel getSearchPanel() {
374: return searchPanel;
375: }
376:
377: public ISemanticContext getSemanticContext() {
378: return semanticContext;
379: }
380:
381: }
|