KickJava   Java API By Example, From Geeks To Geeks.

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


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.BorderLayout JavaDoc;
21 import java.awt.Dimension JavaDoc;
22 import java.awt.Frame JavaDoc;
23 import java.awt.Point JavaDoc;
24 import java.awt.Toolkit JavaDoc;
25 import java.awt.event.WindowEvent JavaDoc;
26 import java.awt.event.WindowListener JavaDoc;
27 import java.io.IOException JavaDoc;
28 import java.io.InputStream JavaDoc;
29 import java.util.Enumeration JavaDoc;
30 import java.util.logging.Level JavaDoc;
31 import java.util.logging.Logger JavaDoc;
32
33 import javax.swing.JComponent JavaDoc;
34 import javax.swing.JFrame JavaDoc;
35 import javax.swing.JPanel JavaDoc;
36 import javax.swing.JToolBar JavaDoc;
37 import javax.swing.WindowConstants JavaDoc;
38 import javax.swing.event.EventListenerList JavaDoc;
39
40 import org.columba.api.gui.frame.IContainer;
41 import org.columba.api.gui.frame.IDock;
42 import org.columba.api.gui.frame.IFrameMediator;
43 import org.columba.api.gui.frame.event.FrameEvent;
44 import org.columba.api.gui.frame.event.IContainerListener;
45 import org.columba.api.gui.frame.event.IFrameMediatorListener;
46 import org.columba.api.plugin.ExtensionMetadata;
47 import org.columba.api.plugin.IExtension;
48 import org.columba.api.plugin.IExtensionHandler;
49 import org.columba.api.plugin.IExtensionHandlerKeys;
50 import org.columba.api.plugin.PluginException;
51 import org.columba.api.plugin.PluginHandlerNotFoundException;
52 import org.columba.api.statusbar.IStatusBar;
53 import org.columba.api.statusbar.IStatusBarExtension;
54 import org.columba.core.command.TaskManager;
55 import org.columba.core.config.ViewItem;
56 import org.columba.core.gui.action.AbstractColumbaAction;
57 import org.columba.core.gui.menu.ExtendableMenuBar;
58 import org.columba.core.gui.menu.MenuXMLDecoder;
59 import org.columba.core.gui.search.SearchBar;
60 import org.columba.core.gui.statusbar.StatusBar;
61 import org.columba.core.gui.toolbar.ExtendableToolBar;
62 import org.columba.core.gui.toolbar.ToolBarXMLDecoder;
63 import org.columba.core.gui.util.MenuThrobber;
64 import org.columba.core.io.DiskIO;
65 import org.columba.core.logging.Logging;
66 import org.columba.core.plugin.Extension;
67 import org.columba.core.plugin.PluginManager;
68 import org.columba.core.resourceloader.ImageLoader;
69 import org.flexdock.docking.DockingManager;
70 import org.flexdock.docking.drag.effects.EffectsManager;
71 import org.flexdock.docking.drag.preview.GhostPreview;
72 import org.flexdock.perspective.PerspectiveManager;
73
74 /**
75  * @author fdietz
76  *
77  */

78
79 public class DefaultContainer extends JFrame JavaDoc implements IContainer,
80         WindowListener JavaDoc, IFrameMediatorListener {
81
82     protected static final int DEFAULT_WIDTH = (int) Math.round(Toolkit
83             .getDefaultToolkit().getScreenSize().width * .66);
84
85     protected static final int DEFAULT_HEIGHT = (int) Math.round(Toolkit
86             .getDefaultToolkit().getScreenSize().height * .66);
87
88     private static final int DEFAULT_X = (int) Math.round(Toolkit
89             .getDefaultToolkit().getScreenSize().width * .16);
90
91     private static final int DEFAULT_Y = (int) Math.round(Toolkit
92             .getDefaultToolkit().getScreenSize().height * .16);
93
94     private static final Logger JavaDoc LOG = Logger
95             .getLogger("org.columba.core.gui.frame");
96
97     private DefaultFrameController mediator;
98
99     private ViewItem viewItem;
100
101     protected ExtendableMenuBar menubar;
102
103     protected ExtendableToolBar toolbar;
104
105     protected StatusBar statusBar;
106
107     protected JPanel JavaDoc contentPane;
108
109     protected boolean switchedFrameMediator = false;
110
111     private String JavaDoc windowname;
112
113     private boolean defaultCloseOperation;
114
115     protected EventListenerList JavaDoc listenerList = new EventListenerList JavaDoc();
116
117     private JPanel JavaDoc toolBarPanel = new JPanel JavaDoc();
118     
119     public DefaultContainer(DefaultFrameController mediator) {
120         super();
121
122         if (mediator == null)
123             throw new IllegalArgumentException JavaDoc("mediator == null");
124
125         this.viewItem = mediator.getViewItem();
126         this.mediator = mediator;
127
128         defaultCloseOperation = true;
129
130         setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
131
132         mediator.setContainer(this);
133         initComponents();
134         createMenuBar();
135         setFrameMediator(mediator);
136
137         mediator.addListener(this);
138     }
139
140     /**
141      *
142      */

143     public DefaultContainer(ViewItem viewItem) {
144         super();
145
146         this.viewItem = viewItem;
147
148         defaultCloseOperation = true;
149
150         setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
151
152         // create new default frame controller
153
mediator = new DefaultFrameController(viewItem);
154
155         initComponents();
156
157         mediator.setContainer(this);
158         createMenuBar();
159
160         mediator.addListener(this);
161     }
162
163     /**
164      *
165      */

166     protected void initComponents() {
167
168         // Set the icon and the title
169
this.setIconImage(ImageLoader.getMiscIcon("icon16.png").getImage());
170         windowname = "Columba";
171
172         setTitle("");
173
174         // register statusbar at global taskmanager
175
statusBar = new StatusBar(TaskManager.getInstance());
176
177         // JPanel panel = (JPanel) this.getContentPane();
178
this.getContentPane().setLayout(new BorderLayout JavaDoc());
179
180         // add statusbar
181

182         // add toolbar
183
// panel.add(toolbar, BorderLayout.NORTH);
184

185         contentPane = new JPanel JavaDoc();
186         // contentPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
187
contentPane.setLayout(new BorderLayout JavaDoc());
188
189         contentPane.add(statusBar, BorderLayout.SOUTH);
190
191         this.getContentPane().add(contentPane, BorderLayout.CENTER);
192
193         initDockingConfiguration();
194
195         // contentPane.add(dockingPort, BorderLayout.CENTER);
196

197         // createMenuBar();
198

199         toolBarPanel = new JPanel JavaDoc();
200         toolBarPanel.setLayout(new BorderLayout JavaDoc());
201         
202         // create toolbar
203
toolbar = new ExtendableToolBar();
204         setToolBar(toolbar);
205         
206         
207
208         // add window listener
209
addWindowListener(this);
210
211     }
212
213     private void initDockingConfiguration() {
214         // turn on floating support
215
DockingManager.setFloatingEnabled(true);
216         PerspectiveManager.setRestoreFloatingOnLoad(true);
217
218         // enable flexdock ghost preview
219
EffectsManager.setPreview(new GhostPreview());
220
221     }
222
223     private void createMenuBar() {
224         try {
225             InputStream JavaDoc is = DiskIO
226                     .getResourceStream("org/columba/core/action/menu.xml");
227
228             // create menu
229
menubar = new MenuXMLDecoder(mediator).createMenuBar(is);
230
231             if (menubar != null) {
232                 setJMenuBar(menubar);
233             }
234         } catch (IOException JavaDoc e) {
235             LOG.severe(e.getMessage());
236         }
237     }
238
239     /**
240      *
241      * @return statusbar
242      */

243     public IStatusBar getStatusBar() {
244         return statusBar;
245     }
246
247     /**
248      * @see org.columba.api.gui.frame.IContainer#setFrameMediator(org.columba.api.gui.frame.IFrameMediator)
249      */

250     public void setFrameMediator(final IFrameMediator m) {
251         LOG.fine("set framemediator to " + m.getClass());
252
253         // remove from old mediator's listener list
254
this.mediator.removeListener(this);
255
256         this.mediator = (DefaultFrameController) m;
257
258         m.setContainer(this);
259
260         // use new viewitem
261
viewItem = mediator.getViewItem();
262
263         switchedFrameMediator = false;
264
265         mediator.extendMenu(this);
266         mediator.extendToolBar(this);
267         mediator.initFrame(this);
268
269         // update content-pane
270
setContentPane(m.getContentPane());
271
272         try {
273             IExtensionHandler handler = PluginManager
274                     .getInstance().getExtensionHandler(IExtensionHandlerKeys.ORG_COLUMBA_CORE_STATUSBAR);
275             Enumeration JavaDoc e = handler.getExtensionEnumeration();
276             while (e.hasMoreElements()) {
277                 Extension ext = (Extension) e.nextElement();
278                 try {
279                     IStatusBarExtension comp = (IStatusBarExtension) ext
280                             .instanciateExtension(new Object JavaDoc[] { m });
281                     statusBar.addComponent(comp);
282                 } catch (PluginException e1) {
283                     e1.printStackTrace();
284                 }
285             }
286         } catch (PluginHandlerNotFoundException e) {
287             e.printStackTrace();
288         }
289         // add to new mediator's listener list
290
mediator.addListener(this);
291
292         mediator.fireComponentChanged();
293     }
294
295     /**
296      * @see org.columba.api.gui.frame.IContainer#switchFrameMediator(org.columba.api.gui.frame.IFrameMediator)
297      */

298     public void switchFrameMediator(IFrameMediator m) {
299         LOG.fine("switching framemediator to " + m.getClass());
300
301         // remove from old mediator's listener list
302
this.mediator.removeListener(this);
303
304         this.mediator = (DefaultFrameController) m;
305
306         m.setContainer(this);
307
308         // use new viewitem
309
viewItem = mediator.getViewItem();
310
311         switchedFrameMediator = true;
312
313         try {
314             InputStream JavaDoc is = DiskIO
315                     .getResourceStream("org/columba/core/action/menu.xml");
316
317             // default core menu
318
menubar = new MenuXMLDecoder(mediator).createMenuBar(is);
319
320             // setJMenuBar(menubar);
321

322         } catch (IOException JavaDoc e) {
323             LOG.severe(e.getMessage());
324         }
325
326         mediator.extendMenu(this);
327
328         mediator.initFrame(this);
329
330         // default toolbar
331
toolbar = new ExtendableToolBar();
332         mediator.extendToolBar(this);
333
334         setToolBar(toolbar);
335
336         // update content-pane
337
setContentPane(m.getContentPane());
338
339         try {
340             IExtensionHandler handler = PluginManager
341                     .getInstance().getExtensionHandler(IExtensionHandlerKeys.ORG_COLUMBA_CORE_STATUSBAR);
342             Enumeration JavaDoc e = handler.getExtensionEnumeration();
343             while (e.hasMoreElements()) {
344                 Extension ext = (Extension) e.nextElement();
345                 try {
346                     IStatusBarExtension comp = (IStatusBarExtension) ext
347                             .instanciateExtension(new Object JavaDoc[] { m });
348                     statusBar.addComponent(comp);
349                 } catch (PluginException e1) {
350                     e1.printStackTrace();
351                 }
352             }
353         } catch (PluginHandlerNotFoundException e) {
354             e.printStackTrace();
355         }
356
357         // add to new mediator's listener list
358
mediator.addListener(this);
359
360         fireComponentChanged(mediator);
361
362         mediator.fireComponentChanged();
363     }
364
365     /**
366      * @see org.columba.api.gui.frame.IContainer#getFrameMediator()
367      */

368     public IFrameMediator getFrameMediator() {
369
370         return mediator;
371     }
372
373     /**
374      * @see org.columba.api.gui.frame.IContainer#getViewItem()
375      */

376     public ViewItem getViewItem() {
377         return viewItem;
378     }
379
380     /**
381      * Enable/Disable toolbar configuration
382      *
383      * @param id
384      * ID of controller
385      * @param enable
386      * true/false
387      */

388     public void enableToolBar(String JavaDoc id, boolean enable) {
389         getViewItem().setBoolean("toolbars", id, enable);
390
391         getToolBar().setVisible(enable);
392
393         // toolbarPane.removeAll();
394
//
395
// if (enable) {
396
// toolbarPane.add(getToolBar());
397
//
398
// }
399

400         // awt-event-thread
401
// javax.swing.SwingUtilities.invokeLater(new Runnable() {
402
// public void run() {
403
// validate();
404
// }
405
// });
406
}
407
408     /**
409      * Returns true if the toolbar is enabled
410      *
411      * @param id
412      * ID of controller
413      * @return true, if toolbar is enabled, false otherwise
414      */

415     public boolean isToolBarEnabled(String JavaDoc id) {
416         return getViewItem().getBooleanWithDefault("toolbars", id, true);
417     }
418
419     /**
420      * Load the window position, size and maximization state
421      *
422      */

423     public void loadPositions(ViewItem viewItem) {
424         Dimension JavaDoc screenSize = Toolkit.getDefaultToolkit().getScreenSize();
425
426         // *20030831, karlpeder* Also location is restored
427
int x = viewItem.getIntegerWithDefault(ViewItem.WINDOW,
428                 ViewItem.POSITION_X_INT, DEFAULT_X);
429         int y = viewItem.getIntegerWithDefault(ViewItem.WINDOW,
430                 ViewItem.POSITION_Y_INT, DEFAULT_Y);
431         int w = viewItem.getIntegerWithDefault(ViewItem.WINDOW,
432                 ViewItem.WIDTH_INT, DEFAULT_WIDTH);
433         int h = viewItem.getIntegerWithDefault(ViewItem.WINDOW,
434                 ViewItem.HEIGHT_INT, DEFAULT_HEIGHT);
435         final boolean maximized = viewItem.getBooleanWithDefault(
436                 ViewItem.WINDOW, ViewItem.MAXIMIZED_BOOL, false);
437
438         // if window is maximized -> ignore the window size properties
439
// otherwise, use window size property
440
// but ensure that the window is completly visible on the
441
// desktop
442
x = Math.max(x, 0);
443         y = Math.max(y, 0);
444
445         final Dimension JavaDoc dim = new Dimension JavaDoc(Math.min(w, screenSize.width - x),
446                 Math.min(h, screenSize.height - y));
447
448         final Point JavaDoc p = new Point JavaDoc(x, y);
449         final Frame JavaDoc frame = this;
450
451         if (maximized) {
452             WindowMaximizer.maximize(frame);
453         } else {
454             frame.setLocation(p);
455             frame.setSize(dim);
456         }
457
458         mediator.loadPositions();
459
460         // awt-event-thread
461
// javax.swing.SwingUtilities.invokeLater(new Runnable() {
462
// public void run() {
463
//
464
//
465
//
466
//
467
// }
468
// });
469

470     }
471
472     /**
473      *
474      * Save current window position, size and maximization state
475      *
476      */

477     private void savePositions() {
478
479         java.awt.Dimension JavaDoc d = getSize();
480         java.awt.Point JavaDoc loc = getLocation();
481
482         ViewItem item = getViewItem();
483
484         boolean isMaximized = WindowMaximizer.isWindowMaximized(this);
485         item.setBoolean(ViewItem.WINDOW, ViewItem.MAXIMIZED_BOOL, isMaximized);
486
487         if (!isMaximized) {
488             // *20030831, karlpeder* Now also location is stored
489
item.setInteger(ViewItem.WINDOW, ViewItem.POSITION_X_INT, loc.x);
490             item.setInteger(ViewItem.WINDOW, ViewItem.POSITION_Y_INT, loc.y);
491             item.setInteger(ViewItem.WINDOW, ViewItem.WIDTH_INT, d.width);
492             item.setInteger(ViewItem.WINDOW, ViewItem.HEIGHT_INT, d.height);
493         }
494
495         mediator.savePositions();
496
497     }
498
499     /**
500      * @see java.awt.event.WindowListener#windowActivated(java.awt.event.WindowEvent)
501      */

502     public void windowActivated(WindowEvent JavaDoc arg0) {
503     }
504
505     /**
506      * @see java.awt.event.WindowListener#windowClosed(java.awt.event.WindowEvent)
507      */

508     public void windowClosed(WindowEvent JavaDoc arg0) {
509     }
510
511     /**
512      * @see java.awt.event.WindowListener#windowClosing(java.awt.event.WindowEvent)
513      */

514     public void windowClosing(WindowEvent JavaDoc arg0) {
515         close();
516     }
517
518     /**
519      * @see java.awt.event.WindowListener#windowDeactivated(java.awt.event.WindowEvent)
520      */

521     public void windowDeactivated(WindowEvent JavaDoc arg0) {
522     }
523
524     /**
525      * @see java.awt.event.WindowListener#windowDeiconified(java.awt.event.WindowEvent)
526      */

527     public void windowDeiconified(WindowEvent JavaDoc arg0) {
528     }
529
530     /**
531      * @see java.awt.event.WindowListener#windowIconified(java.awt.event.WindowEvent)
532      */

533     public void windowIconified(WindowEvent JavaDoc arg0) {
534     }
535
536     /**
537      * @see java.awt.event.WindowListener#windowOpened(java.awt.event.WindowEvent)
538      */

539     public void windowOpened(WindowEvent JavaDoc arg0) {
540     }
541
542     /**
543      * @see org.columba.api.gui.frame.View#getToolBar()
544      */

545     public JToolBar JavaDoc getToolBar() {
546         return toolbar;
547     }
548
549     /**
550      * @see org.columba.api.gui.frame.IContainer#extendMenu(org.columba.api.gui.frame.IFrameMediator,
551      * java.io.InputStream)
552      */

553     public void extendMenu(IFrameMediator mediator, InputStream JavaDoc is) {
554
555         new MenuXMLDecoder(mediator).extendMenuBar(menubar, is);
556
557         // finally, add all external extension menu additions
558
// for example: Hello World Plugin
559
try {
560             IExtensionHandler handler = PluginManager
561                     .getInstance().getExtensionHandler(IExtensionHandlerKeys.ORG_COLUMBA_CORE_ACTION);
562             Enumeration JavaDoc e = handler.getExternalExtensionsEnumeration();
563             while (e.hasMoreElements()) {
564                 IExtension extension = (IExtension) e.nextElement();
565                 // retrieve metadata
566
ExtensionMetadata metadata = extension.getMetadata();
567                 String JavaDoc menuId = metadata.getAttribute("menuid");
568                 String JavaDoc placeholderId = metadata.getAttribute("placeholderid");
569
570                 if (menuId == null || placeholderId == null)
571                     continue;
572
573                 // add action to menu
574
String JavaDoc extensionId = metadata.getId();
575                 try {
576                     AbstractColumbaAction action = (AbstractColumbaAction) extension
577                             .instanciateExtension(new Object JavaDoc[] { mediator });
578                     if (action == null)
579                         LOG.severe("action could not be instanciated: "
580                                 + extensionId);
581                     else
582                         ((ExtendableMenuBar) menubar).insertAction(menuId,
583                                 placeholderId, action);
584                 } catch (PluginException e1) {
585                     e1.printStackTrace();
586                 }
587             }
588
589         } catch (PluginHandlerNotFoundException e) {
590             e.printStackTrace();
591         }
592         
593     }
594
595     /**
596      * @see org.columba.api.gui.frame.View#setContentPane(org.columba.api.gui.frame.neu.FrameView)
597      */

598     public void setContentPane(JPanel JavaDoc view) {
599
600         LOG.finest("setting content-pane");
601
602         getContentPane().removeAll();
603
604         // remove old content pane
605
contentPane.removeAll();
606         // contentPane.remove(mediator.getContentPane());
607

608         setJMenuBar(menubar);
609         
610         // add animated icon to right-hand side corner of menubar
611
MenuThrobber.setThrobber(menubar);
612         
613         // // add new componnet
614
contentPane.add(view, BorderLayout.CENTER);
615
616         getContentPane().add(toolBarPanel, BorderLayout.NORTH);
617
618         contentPane.add(statusBar, BorderLayout.SOUTH);
619
620         getContentPane().add(contentPane, BorderLayout.CENTER);
621
622         // show/hide new toolbar
623
enableToolBar(IContainer.MAIN_TOOLBAR,
624                 isToolBarEnabled(IContainer.MAIN_TOOLBAR));
625
626         // getContentPane().validate();
627

628         if (!switchedFrameMediator) {
629
630             Dimension JavaDoc screenSize = Toolkit.getDefaultToolkit().getScreenSize();
631
632             // *20030831, karlpeder* Also location is restored
633
int x = viewItem.getIntegerWithDefault(ViewItem.WINDOW,
634                     ViewItem.POSITION_X_INT, DEFAULT_X);
635             int y = viewItem.getIntegerWithDefault(ViewItem.WINDOW,
636                     ViewItem.POSITION_Y_INT, DEFAULT_Y);
637             int w = viewItem.getIntegerWithDefault(ViewItem.WINDOW,
638                     ViewItem.WIDTH_INT, DEFAULT_WIDTH);
639             int h = viewItem.getIntegerWithDefault(ViewItem.WINDOW,
640                     ViewItem.HEIGHT_INT, DEFAULT_HEIGHT);
641             final boolean maximized = viewItem.getBooleanWithDefault(
642                     ViewItem.WINDOW, ViewItem.MAXIMIZED_BOOL, false);
643
644             // if window is maximized -> ignore the window size properties
645
// otherwise, use window size property
646
// but ensure that the window is completly visible on the
647
// desktop
648
x = Math.max(x, 0);
649             y = Math.max(y, 0);
650
651             final Dimension JavaDoc dim = new Dimension JavaDoc(Math.min(w, screenSize.width
652                     - x), Math.min(h, screenSize.height - y));
653
654             final Point JavaDoc p = new Point JavaDoc(x, y);
655             final Frame JavaDoc frame = this;
656
657             if (maximized) {
658
659                 frame.setVisible(true);
660
661                 WindowMaximizer.maximize(frame);
662
663                 // awt-event-thread
664
javax.swing.SwingUtilities.invokeLater(new Runnable JavaDoc() {
665                     public void run() {
666                         mediator.loadPositions();
667                     }
668                 });
669
670             } else {
671                 frame.setLocation(p);
672                 frame.setSize(dim);
673
674                 mediator.loadPositions();
675
676                 setVisible(true);
677             }
678             // make window visible
679
// LOG.finest("setVisible()");
680

681             // load window position
682
// loadPositions(getViewItem());
683

684         } else {
685             if (!mediator.isInitialized())
686                 mediator.loadPositions();
687
688             validateTree();
689
690             view.repaint();
691         }
692
693         switchedFrameMediator = false;
694
695     }
696
697     /**
698      * @see org.columba.api.gui.frame.View#extendToolbar(org.columba.core.xml.XmlElement)
699      */

700     public void extendToolbar(IFrameMediator mediator, InputStream JavaDoc is) {
701
702         new ToolBarXMLDecoder(mediator).extendToolBar(
703                 (ExtendableToolBar) getToolBar(), is);
704
705     }
706
707     /**
708      * @see org.columba.api.gui.frame.View#getFrame()
709      */

710     public JFrame JavaDoc getFrame() {
711         return this;
712     }
713
714     /**
715      * @see org.columba.core.gui.frame.View#getMenuBar()
716      */

717     // public ColumbaMenu getMenuBar() {
718
// return menu;
719
// }
720
/**
721      * Save window properties and close the window. This includes telling the
722      * frame model that this window/frame is closing, so it can be
723      * "unregistered" correctly
724      */

725     public void close() {
726
727         // save window position
728
savePositions();
729
730         getFrameMediator().close(this);
731
732         if (defaultCloseOperation == false)
733             return;
734
735         if (LOG.isLoggable(Level.FINE)) {
736             LOG.fine("Closing DefaultContainer: " + this.getClass().getName());
737         }
738
739         // hide window
740
setVisible(false);
741
742         //
743
// Tell frame model that frame is closing. If this frame hasn't been
744
// opened using FrameManager methods, FrameManager.close does nothing.
745
//
746
FrameManager.getInstance().close(this);
747
748     }
749
750     /**
751      * @see org.columba.api.gui.frame.IContainer#addToolBar(javax.swing.JComponent)
752      */

753     public void addToolBar(JComponent JavaDoc c) {
754         // FIXME remove method
755
// toolbarPane.add(c);
756
}
757
758     /**
759      * @see org.columba.api.gui.frame.IContainer#setToolBar(org.columba.core.gui.toolbar.ToolBar)
760      */

761     public void setToolBar(JToolBar JavaDoc toolbar) {
762         if ((toolbar instanceof ExtendableToolBar) == false)
763             throw new IllegalArgumentException JavaDoc(
764                     "only instances of ExtendableToolBar allowed");
765
766         // getContentPane().remove(this.toolbar);
767

768         this.toolbar = (ExtendableToolBar) toolbar;
769
770         // remove old toolbar
771
toolBarPanel.removeAll();
772         
773         toolBarPanel.add(toolbar, BorderLayout.CENTER);
774         
775         // @author fdietz: hackish way of creating a search toolbar
776
//JToolBar searchToolBar = new ExtendableToolBar();
777
SearchBar searchBar = new SearchBar(mediator.getSearchPanel(), mediator);
778         //searchToolBar.addSeparator();
779

780         
781         //searchBar.install(searchToolBar);
782

783         // add search bar to main toolbar, in case its a managed frame mediator
784
if ( FrameManager.getInstance().isManaged(getFrameMediator().getId() ) ) {
785             searchBar.install(toolbar);
786         }
787         
788         
789 // if ( getFrameMediator() instanceof IDock)
790
// toolBarPanel.add(searchToolBar, BorderLayout.EAST);
791

792         //
793
// getContentPane().validate();
794

795     }
796
797     /**
798      * @see java.awt.Frame#setTitle(java.lang.String)
799      */

800     public void setTitle(String JavaDoc arg0) {
801         String JavaDoc title = windowname;
802
803         if (Logging.DEBUG) {
804             title += " DEBUG MODE";
805         }
806
807         if (arg0.length() > 0) {
808             title = arg0 + " - " + title;
809         }
810
811         super.setTitle(title);
812     }
813
814     /**
815      * @see org.columba.api.gui.frame.IContainer#setWindowName(java.lang.String)
816      */

817     public void setWindowName(String JavaDoc name) {
818         this.windowname = name;
819         setTitle("");
820     }
821
822     /**
823      * @see org.columba.api.gui.frame.IContainer#setCloseOperation(boolean)
824      */

825     public void setCloseOperation(boolean close) {
826         this.defaultCloseOperation = close;
827     }
828
829     public JPanel JavaDoc getContentPanel() {
830         return contentPane;
831     }
832
833     /** ********************* frame eventing ******************** */
834
835     public void titleChanged(FrameEvent event) {
836         setTitle(event.getText());
837     }
838
839     public void statusMessageChanged(FrameEvent event) {
840         getStatusBar().displayTooltipMessage(event.getText());
841     }
842
843     public void taskStatusChanged(FrameEvent event) {
844         getStatusBar().getDisplayedWorker().cancel();
845     }
846
847     public void visibilityChanged(FrameEvent event) {
848         if (event.isVisible())
849             setVisible(true);
850         else
851             setVisible(false);
852     }
853
854     public void layoutChanged(FrameEvent event) {
855         validate();
856     }
857
858     public void closed(FrameEvent event) {
859         close();
860     }
861
862     public void toolBarVisibilityChanged(FrameEvent event) {
863         enableToolBar(IContainer.MAIN_TOOLBAR, event.isVisible());
864     }
865
866     public void switchedComponent(FrameEvent event) {
867         // don't do anything
868
}
869
870     /** ******************** event listener ****************************** */
871
872     public void addListener(IContainerListener l) {
873         listenerList.add(IContainerListener.class, l);
874     }
875
876     public void removeListener(IContainerListener l) {
877         listenerList.remove(IContainerListener.class, l);
878     }
879
880     public void fireComponentChanged(IFrameMediator mediator) {
881         FrameEvent e = new FrameEvent(this, mediator);
882         // Guaranteed to return a non-null array
883
Object JavaDoc[] listeners = listenerList.getListenerList();
884
885         // Process the listeners last to first, notifying
886
// those that are interested in this event
887
for (int i = listeners.length - 2; i >= 0; i -= 2) {
888             if (listeners[i] == IContainerListener.class) {
889                 ((IContainerListener) listeners[i + 1]).switchedComponent(e);
890             }
891         }
892
893     }
894
895 }
Popular Tags