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.BorderLayout;
021: import java.awt.Dimension;
022: import java.awt.Frame;
023: import java.awt.Point;
024: import java.awt.Toolkit;
025: import java.awt.event.WindowEvent;
026: import java.awt.event.WindowListener;
027: import java.io.IOException;
028: import java.io.InputStream;
029: import java.util.Enumeration;
030: import java.util.logging.Level;
031: import java.util.logging.Logger;
032:
033: import javax.swing.JComponent;
034: import javax.swing.JFrame;
035: import javax.swing.JPanel;
036: import javax.swing.JToolBar;
037: import javax.swing.WindowConstants;
038: import javax.swing.event.EventListenerList;
039:
040: import org.columba.api.gui.frame.IContainer;
041: import org.columba.api.gui.frame.IDock;
042: import org.columba.api.gui.frame.IFrameMediator;
043: import org.columba.api.gui.frame.event.FrameEvent;
044: import org.columba.api.gui.frame.event.IContainerListener;
045: import org.columba.api.gui.frame.event.IFrameMediatorListener;
046: import org.columba.api.plugin.ExtensionMetadata;
047: import org.columba.api.plugin.IExtension;
048: import org.columba.api.plugin.IExtensionHandler;
049: import org.columba.api.plugin.IExtensionHandlerKeys;
050: import org.columba.api.plugin.PluginException;
051: import org.columba.api.plugin.PluginHandlerNotFoundException;
052: import org.columba.api.statusbar.IStatusBar;
053: import org.columba.api.statusbar.IStatusBarExtension;
054: import org.columba.core.command.TaskManager;
055: import org.columba.core.config.ViewItem;
056: import org.columba.core.gui.action.AbstractColumbaAction;
057: import org.columba.core.gui.menu.ExtendableMenuBar;
058: import org.columba.core.gui.menu.MenuXMLDecoder;
059: import org.columba.core.gui.search.SearchBar;
060: import org.columba.core.gui.statusbar.StatusBar;
061: import org.columba.core.gui.toolbar.ExtendableToolBar;
062: import org.columba.core.gui.toolbar.ToolBarXMLDecoder;
063: import org.columba.core.gui.util.MenuThrobber;
064: import org.columba.core.io.DiskIO;
065: import org.columba.core.logging.Logging;
066: import org.columba.core.plugin.Extension;
067: import org.columba.core.plugin.PluginManager;
068: import org.columba.core.resourceloader.ImageLoader;
069: import org.flexdock.docking.DockingManager;
070: import org.flexdock.docking.drag.effects.EffectsManager;
071: import org.flexdock.docking.drag.preview.GhostPreview;
072: import org.flexdock.perspective.PerspectiveManager;
073:
074: /**
075: * @author fdietz
076: *
077: */
078:
079: public class DefaultContainer extends JFrame implements IContainer,
080: WindowListener, IFrameMediatorListener {
081:
082: protected static final int DEFAULT_WIDTH = (int) Math.round(Toolkit
083: .getDefaultToolkit().getScreenSize().width * .66);
084:
085: protected static final int DEFAULT_HEIGHT = (int) Math
086: .round(Toolkit.getDefaultToolkit().getScreenSize().height * .66);
087:
088: private static final int DEFAULT_X = (int) Math.round(Toolkit
089: .getDefaultToolkit().getScreenSize().width * .16);
090:
091: private static final int DEFAULT_Y = (int) Math.round(Toolkit
092: .getDefaultToolkit().getScreenSize().height * .16);
093:
094: private static final Logger LOG = Logger
095: .getLogger("org.columba.core.gui.frame");
096:
097: private DefaultFrameController mediator;
098:
099: private ViewItem viewItem;
100:
101: protected ExtendableMenuBar menubar;
102:
103: protected ExtendableToolBar toolbar;
104:
105: protected StatusBar statusBar;
106:
107: protected JPanel contentPane;
108:
109: protected boolean switchedFrameMediator = false;
110:
111: private String windowname;
112:
113: private boolean defaultCloseOperation;
114:
115: protected EventListenerList listenerList = new EventListenerList();
116:
117: private JPanel toolBarPanel = new JPanel();
118:
119: public DefaultContainer(DefaultFrameController mediator) {
120: super ();
121:
122: if (mediator == null)
123: throw new IllegalArgumentException("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")
170: .getImage());
171: windowname = "Columba";
172:
173: setTitle("");
174:
175: // register statusbar at global taskmanager
176: statusBar = new StatusBar(TaskManager.getInstance());
177:
178: // JPanel panel = (JPanel) this.getContentPane();
179: this .getContentPane().setLayout(new BorderLayout());
180:
181: // add statusbar
182:
183: // add toolbar
184: // panel.add(toolbar, BorderLayout.NORTH);
185:
186: contentPane = new JPanel();
187: // contentPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
188: contentPane.setLayout(new BorderLayout());
189:
190: contentPane.add(statusBar, BorderLayout.SOUTH);
191:
192: this .getContentPane().add(contentPane, BorderLayout.CENTER);
193:
194: initDockingConfiguration();
195:
196: // contentPane.add(dockingPort, BorderLayout.CENTER);
197:
198: // createMenuBar();
199:
200: toolBarPanel = new JPanel();
201: toolBarPanel.setLayout(new BorderLayout());
202:
203: // create toolbar
204: toolbar = new ExtendableToolBar();
205: setToolBar(toolbar);
206:
207: // add window listener
208: addWindowListener(this );
209:
210: }
211:
212: private void initDockingConfiguration() {
213: // turn on floating support
214: DockingManager.setFloatingEnabled(true);
215: PerspectiveManager.setRestoreFloatingOnLoad(true);
216:
217: // enable flexdock ghost preview
218: EffectsManager.setPreview(new GhostPreview());
219:
220: }
221:
222: private void createMenuBar() {
223: try {
224: InputStream is = DiskIO
225: .getResourceStream("org/columba/core/action/menu.xml");
226:
227: // create menu
228: menubar = new MenuXMLDecoder(mediator).createMenuBar(is);
229:
230: if (menubar != null) {
231: setJMenuBar(menubar);
232: }
233: } catch (IOException e) {
234: LOG.severe(e.getMessage());
235: }
236: }
237:
238: /**
239: *
240: * @return statusbar
241: */
242: public IStatusBar getStatusBar() {
243: return statusBar;
244: }
245:
246: /**
247: * @see org.columba.api.gui.frame.IContainer#setFrameMediator(org.columba.api.gui.frame.IFrameMediator)
248: */
249: public void setFrameMediator(final IFrameMediator m) {
250: LOG.fine("set framemediator to " + m.getClass());
251:
252: // remove from old mediator's listener list
253: this .mediator.removeListener(this );
254:
255: this .mediator = (DefaultFrameController) m;
256:
257: m.setContainer(this );
258:
259: // use new viewitem
260: viewItem = mediator.getViewItem();
261:
262: switchedFrameMediator = false;
263:
264: mediator.extendMenu(this );
265: mediator.extendToolBar(this );
266: mediator.initFrame(this );
267:
268: // update content-pane
269: setContentPane(m.getContentPane());
270:
271: try {
272: IExtensionHandler handler = PluginManager
273: .getInstance()
274: .getExtensionHandler(
275: IExtensionHandlerKeys.ORG_COLUMBA_CORE_STATUSBAR);
276: Enumeration e = handler.getExtensionEnumeration();
277: while (e.hasMoreElements()) {
278: Extension ext = (Extension) e.nextElement();
279: try {
280: IStatusBarExtension comp = (IStatusBarExtension) ext
281: .instanciateExtension(new Object[] { m });
282: statusBar.addComponent(comp);
283: } catch (PluginException e1) {
284: e1.printStackTrace();
285: }
286: }
287: } catch (PluginHandlerNotFoundException e) {
288: e.printStackTrace();
289: }
290: // add to new mediator's listener list
291: mediator.addListener(this );
292:
293: mediator.fireComponentChanged();
294: }
295:
296: /**
297: * @see org.columba.api.gui.frame.IContainer#switchFrameMediator(org.columba.api.gui.frame.IFrameMediator)
298: */
299: public void switchFrameMediator(IFrameMediator m) {
300: LOG.fine("switching framemediator to " + m.getClass());
301:
302: // remove from old mediator's listener list
303: this .mediator.removeListener(this );
304:
305: this .mediator = (DefaultFrameController) m;
306:
307: m.setContainer(this );
308:
309: // use new viewitem
310: viewItem = mediator.getViewItem();
311:
312: switchedFrameMediator = true;
313:
314: try {
315: InputStream is = DiskIO
316: .getResourceStream("org/columba/core/action/menu.xml");
317:
318: // default core menu
319: menubar = new MenuXMLDecoder(mediator).createMenuBar(is);
320:
321: // setJMenuBar(menubar);
322:
323: } catch (IOException e) {
324: LOG.severe(e.getMessage());
325: }
326:
327: mediator.extendMenu(this );
328:
329: mediator.initFrame(this );
330:
331: // default toolbar
332: toolbar = new ExtendableToolBar();
333: mediator.extendToolBar(this );
334:
335: setToolBar(toolbar);
336:
337: // update content-pane
338: setContentPane(m.getContentPane());
339:
340: try {
341: IExtensionHandler handler = PluginManager
342: .getInstance()
343: .getExtensionHandler(
344: IExtensionHandlerKeys.ORG_COLUMBA_CORE_STATUSBAR);
345: Enumeration e = handler.getExtensionEnumeration();
346: while (e.hasMoreElements()) {
347: Extension ext = (Extension) e.nextElement();
348: try {
349: IStatusBarExtension comp = (IStatusBarExtension) ext
350: .instanciateExtension(new Object[] { m });
351: statusBar.addComponent(comp);
352: } catch (PluginException e1) {
353: e1.printStackTrace();
354: }
355: }
356: } catch (PluginHandlerNotFoundException e) {
357: e.printStackTrace();
358: }
359:
360: // add to new mediator's listener list
361: mediator.addListener(this );
362:
363: fireComponentChanged(mediator);
364:
365: mediator.fireComponentChanged();
366: }
367:
368: /**
369: * @see org.columba.api.gui.frame.IContainer#getFrameMediator()
370: */
371: public IFrameMediator getFrameMediator() {
372:
373: return mediator;
374: }
375:
376: /**
377: * @see org.columba.api.gui.frame.IContainer#getViewItem()
378: */
379: public ViewItem getViewItem() {
380: return viewItem;
381: }
382:
383: /**
384: * Enable/Disable toolbar configuration
385: *
386: * @param id
387: * ID of controller
388: * @param enable
389: * true/false
390: */
391: public void enableToolBar(String id, boolean enable) {
392: getViewItem().setBoolean("toolbars", id, enable);
393:
394: getToolBar().setVisible(enable);
395:
396: // toolbarPane.removeAll();
397: //
398: // if (enable) {
399: // toolbarPane.add(getToolBar());
400: //
401: // }
402:
403: // awt-event-thread
404: // javax.swing.SwingUtilities.invokeLater(new Runnable() {
405: // public void run() {
406: // validate();
407: // }
408: // });
409: }
410:
411: /**
412: * Returns true if the toolbar is enabled
413: *
414: * @param id
415: * ID of controller
416: * @return true, if toolbar is enabled, false otherwise
417: */
418: public boolean isToolBarEnabled(String id) {
419: return getViewItem()
420: .getBooleanWithDefault("toolbars", id, true);
421: }
422:
423: /**
424: * Load the window position, size and maximization state
425: *
426: */
427: public void loadPositions(ViewItem viewItem) {
428: Dimension screenSize = Toolkit.getDefaultToolkit()
429: .getScreenSize();
430:
431: // *20030831, karlpeder* Also location is restored
432: int x = viewItem.getIntegerWithDefault(ViewItem.WINDOW,
433: ViewItem.POSITION_X_INT, DEFAULT_X);
434: int y = viewItem.getIntegerWithDefault(ViewItem.WINDOW,
435: ViewItem.POSITION_Y_INT, DEFAULT_Y);
436: int w = viewItem.getIntegerWithDefault(ViewItem.WINDOW,
437: ViewItem.WIDTH_INT, DEFAULT_WIDTH);
438: int h = viewItem.getIntegerWithDefault(ViewItem.WINDOW,
439: ViewItem.HEIGHT_INT, DEFAULT_HEIGHT);
440: final boolean maximized = viewItem.getBooleanWithDefault(
441: ViewItem.WINDOW, ViewItem.MAXIMIZED_BOOL, false);
442:
443: // if window is maximized -> ignore the window size properties
444: // otherwise, use window size property
445: // but ensure that the window is completly visible on the
446: // desktop
447: x = Math.max(x, 0);
448: y = Math.max(y, 0);
449:
450: final Dimension dim = new Dimension(Math.min(w,
451: screenSize.width - x), Math.min(h, screenSize.height
452: - y));
453:
454: final Point p = new Point(x, y);
455: final Frame frame = this ;
456:
457: if (maximized) {
458: WindowMaximizer.maximize(frame);
459: } else {
460: frame.setLocation(p);
461: frame.setSize(dim);
462: }
463:
464: mediator.loadPositions();
465:
466: // awt-event-thread
467: // javax.swing.SwingUtilities.invokeLater(new Runnable() {
468: // public void run() {
469: //
470: //
471: //
472: //
473: // }
474: // });
475:
476: }
477:
478: /**
479: *
480: * Save current window position, size and maximization state
481: *
482: */
483: private void savePositions() {
484:
485: java.awt.Dimension d = getSize();
486: java.awt.Point loc = getLocation();
487:
488: ViewItem item = getViewItem();
489:
490: boolean isMaximized = WindowMaximizer.isWindowMaximized(this );
491: item.setBoolean(ViewItem.WINDOW, ViewItem.MAXIMIZED_BOOL,
492: isMaximized);
493:
494: if (!isMaximized) {
495: // *20030831, karlpeder* Now also location is stored
496: item.setInteger(ViewItem.WINDOW, ViewItem.POSITION_X_INT,
497: loc.x);
498: item.setInteger(ViewItem.WINDOW, ViewItem.POSITION_Y_INT,
499: loc.y);
500: item.setInteger(ViewItem.WINDOW, ViewItem.WIDTH_INT,
501: d.width);
502: item.setInteger(ViewItem.WINDOW, ViewItem.HEIGHT_INT,
503: d.height);
504: }
505:
506: mediator.savePositions();
507:
508: }
509:
510: /**
511: * @see java.awt.event.WindowListener#windowActivated(java.awt.event.WindowEvent)
512: */
513: public void windowActivated(WindowEvent arg0) {
514: }
515:
516: /**
517: * @see java.awt.event.WindowListener#windowClosed(java.awt.event.WindowEvent)
518: */
519: public void windowClosed(WindowEvent arg0) {
520: }
521:
522: /**
523: * @see java.awt.event.WindowListener#windowClosing(java.awt.event.WindowEvent)
524: */
525: public void windowClosing(WindowEvent arg0) {
526: close();
527: }
528:
529: /**
530: * @see java.awt.event.WindowListener#windowDeactivated(java.awt.event.WindowEvent)
531: */
532: public void windowDeactivated(WindowEvent arg0) {
533: }
534:
535: /**
536: * @see java.awt.event.WindowListener#windowDeiconified(java.awt.event.WindowEvent)
537: */
538: public void windowDeiconified(WindowEvent arg0) {
539: }
540:
541: /**
542: * @see java.awt.event.WindowListener#windowIconified(java.awt.event.WindowEvent)
543: */
544: public void windowIconified(WindowEvent arg0) {
545: }
546:
547: /**
548: * @see java.awt.event.WindowListener#windowOpened(java.awt.event.WindowEvent)
549: */
550: public void windowOpened(WindowEvent arg0) {
551: }
552:
553: /**
554: * @see org.columba.api.gui.frame.View#getToolBar()
555: */
556: public JToolBar getToolBar() {
557: return toolbar;
558: }
559:
560: /**
561: * @see org.columba.api.gui.frame.IContainer#extendMenu(org.columba.api.gui.frame.IFrameMediator,
562: * java.io.InputStream)
563: */
564: public void extendMenu(IFrameMediator mediator, InputStream is) {
565:
566: new MenuXMLDecoder(mediator).extendMenuBar(menubar, is);
567:
568: // finally, add all external extension menu additions
569: // for example: Hello World Plugin
570: try {
571: IExtensionHandler handler = PluginManager
572: .getInstance()
573: .getExtensionHandler(
574: IExtensionHandlerKeys.ORG_COLUMBA_CORE_ACTION);
575: Enumeration e = handler.getExternalExtensionsEnumeration();
576: while (e.hasMoreElements()) {
577: IExtension extension = (IExtension) e.nextElement();
578: // retrieve metadata
579: ExtensionMetadata metadata = extension.getMetadata();
580: String menuId = metadata.getAttribute("menuid");
581: String placeholderId = metadata
582: .getAttribute("placeholderid");
583:
584: if (menuId == null || placeholderId == null)
585: continue;
586:
587: // add action to menu
588: String extensionId = metadata.getId();
589: try {
590: AbstractColumbaAction action = (AbstractColumbaAction) extension
591: .instanciateExtension(new Object[] { mediator });
592: if (action == null)
593: LOG.severe("action could not be instanciated: "
594: + extensionId);
595: else
596: ((ExtendableMenuBar) menubar).insertAction(
597: menuId, placeholderId, action);
598: } catch (PluginException e1) {
599: e1.printStackTrace();
600: }
601: }
602:
603: } catch (PluginHandlerNotFoundException e) {
604: e.printStackTrace();
605: }
606:
607: }
608:
609: /**
610: * @see org.columba.api.gui.frame.View#setContentPane(org.columba.api.gui.frame.neu.FrameView)
611: */
612: public void setContentPane(JPanel view) {
613:
614: LOG.finest("setting content-pane");
615:
616: getContentPane().removeAll();
617:
618: // remove old content pane
619: contentPane.removeAll();
620: // contentPane.remove(mediator.getContentPane());
621:
622: setJMenuBar(menubar);
623:
624: // add animated icon to right-hand side corner of menubar
625: MenuThrobber.setThrobber(menubar);
626:
627: // // add new componnet
628: contentPane.add(view, BorderLayout.CENTER);
629:
630: getContentPane().add(toolBarPanel, BorderLayout.NORTH);
631:
632: contentPane.add(statusBar, BorderLayout.SOUTH);
633:
634: getContentPane().add(contentPane, BorderLayout.CENTER);
635:
636: // show/hide new toolbar
637: enableToolBar(IContainer.MAIN_TOOLBAR,
638: isToolBarEnabled(IContainer.MAIN_TOOLBAR));
639:
640: // getContentPane().validate();
641:
642: if (!switchedFrameMediator) {
643:
644: Dimension screenSize = Toolkit.getDefaultToolkit()
645: .getScreenSize();
646:
647: // *20030831, karlpeder* Also location is restored
648: int x = viewItem.getIntegerWithDefault(ViewItem.WINDOW,
649: ViewItem.POSITION_X_INT, DEFAULT_X);
650: int y = viewItem.getIntegerWithDefault(ViewItem.WINDOW,
651: ViewItem.POSITION_Y_INT, DEFAULT_Y);
652: int w = viewItem.getIntegerWithDefault(ViewItem.WINDOW,
653: ViewItem.WIDTH_INT, DEFAULT_WIDTH);
654: int h = viewItem.getIntegerWithDefault(ViewItem.WINDOW,
655: ViewItem.HEIGHT_INT, DEFAULT_HEIGHT);
656: final boolean maximized = viewItem.getBooleanWithDefault(
657: ViewItem.WINDOW, ViewItem.MAXIMIZED_BOOL, false);
658:
659: // if window is maximized -> ignore the window size properties
660: // otherwise, use window size property
661: // but ensure that the window is completly visible on the
662: // desktop
663: x = Math.max(x, 0);
664: y = Math.max(y, 0);
665:
666: final Dimension dim = new Dimension(Math.min(w,
667: screenSize.width - x), Math.min(h,
668: screenSize.height - y));
669:
670: final Point p = new Point(x, y);
671: final Frame frame = this ;
672:
673: if (maximized) {
674:
675: frame.setVisible(true);
676:
677: WindowMaximizer.maximize(frame);
678:
679: // awt-event-thread
680: javax.swing.SwingUtilities.invokeLater(new Runnable() {
681: public void run() {
682: mediator.loadPositions();
683: }
684: });
685:
686: } else {
687: frame.setLocation(p);
688: frame.setSize(dim);
689:
690: mediator.loadPositions();
691:
692: setVisible(true);
693: }
694: // make window visible
695: // LOG.finest("setVisible()");
696:
697: // load window position
698: // loadPositions(getViewItem());
699:
700: } else {
701: if (!mediator.isInitialized())
702: mediator.loadPositions();
703:
704: validateTree();
705:
706: view.repaint();
707: }
708:
709: switchedFrameMediator = false;
710:
711: }
712:
713: /**
714: * @see org.columba.api.gui.frame.View#extendToolbar(org.columba.core.xml.XmlElement)
715: */
716: public void extendToolbar(IFrameMediator mediator, InputStream is) {
717:
718: new ToolBarXMLDecoder(mediator).extendToolBar(
719: (ExtendableToolBar) getToolBar(), is);
720:
721: }
722:
723: /**
724: * @see org.columba.api.gui.frame.View#getFrame()
725: */
726: public JFrame getFrame() {
727: return this ;
728: }
729:
730: /**
731: * @see org.columba.core.gui.frame.View#getMenuBar()
732: */
733: // public ColumbaMenu getMenuBar() {
734: // return menu;
735: // }
736: /**
737: * Save window properties and close the window. This includes telling the
738: * frame model that this window/frame is closing, so it can be
739: * "unregistered" correctly
740: */
741: public void close() {
742:
743: // save window position
744: savePositions();
745:
746: getFrameMediator().close(this );
747:
748: if (defaultCloseOperation == false)
749: return;
750:
751: if (LOG.isLoggable(Level.FINE)) {
752: LOG.fine("Closing DefaultContainer: "
753: + this .getClass().getName());
754: }
755:
756: // hide window
757: setVisible(false);
758:
759: //
760: // Tell frame model that frame is closing. If this frame hasn't been
761: // opened using FrameManager methods, FrameManager.close does nothing.
762: //
763: FrameManager.getInstance().close(this );
764:
765: }
766:
767: /**
768: * @see org.columba.api.gui.frame.IContainer#addToolBar(javax.swing.JComponent)
769: */
770: public void addToolBar(JComponent c) {
771: // FIXME remove method
772: // toolbarPane.add(c);
773: }
774:
775: /**
776: * @see org.columba.api.gui.frame.IContainer#setToolBar(org.columba.core.gui.toolbar.ToolBar)
777: */
778: public void setToolBar(JToolBar toolbar) {
779: if ((toolbar instanceof ExtendableToolBar) == false)
780: throw new IllegalArgumentException(
781: "only instances of ExtendableToolBar allowed");
782:
783: // getContentPane().remove(this.toolbar);
784:
785: this .toolbar = (ExtendableToolBar) toolbar;
786:
787: // remove old toolbar
788: toolBarPanel.removeAll();
789:
790: toolBarPanel.add(toolbar, BorderLayout.CENTER);
791:
792: // @author fdietz: hackish way of creating a search toolbar
793: //JToolBar searchToolBar = new ExtendableToolBar();
794: SearchBar searchBar = new SearchBar(mediator.getSearchPanel(),
795: mediator);
796: //searchToolBar.addSeparator();
797:
798: //searchBar.install(searchToolBar);
799:
800: // add search bar to main toolbar, in case its a managed frame mediator
801: if (FrameManager.getInstance().isManaged(
802: getFrameMediator().getId())) {
803: searchBar.install(toolbar);
804: }
805:
806: // if ( getFrameMediator() instanceof IDock)
807: // toolBarPanel.add(searchToolBar, BorderLayout.EAST);
808:
809: //
810: // getContentPane().validate();
811:
812: }
813:
814: /**
815: * @see java.awt.Frame#setTitle(java.lang.String)
816: */
817: public void setTitle(String arg0) {
818: String title = windowname;
819:
820: if (Logging.DEBUG) {
821: title += " DEBUG MODE";
822: }
823:
824: if (arg0.length() > 0) {
825: title = arg0 + " - " + title;
826: }
827:
828: super .setTitle(title);
829: }
830:
831: /**
832: * @see org.columba.api.gui.frame.IContainer#setWindowName(java.lang.String)
833: */
834: public void setWindowName(String name) {
835: this .windowname = name;
836: setTitle("");
837: }
838:
839: /**
840: * @see org.columba.api.gui.frame.IContainer#setCloseOperation(boolean)
841: */
842: public void setCloseOperation(boolean close) {
843: this .defaultCloseOperation = close;
844: }
845:
846: public JPanel getContentPanel() {
847: return contentPane;
848: }
849:
850: /** ********************* frame eventing ******************** */
851:
852: public void titleChanged(FrameEvent event) {
853: setTitle(event.getText());
854: }
855:
856: public void statusMessageChanged(FrameEvent event) {
857: getStatusBar().displayTooltipMessage(event.getText());
858: }
859:
860: public void taskStatusChanged(FrameEvent event) {
861: getStatusBar().getDisplayedWorker().cancel();
862: }
863:
864: public void visibilityChanged(FrameEvent event) {
865: if (event.isVisible())
866: setVisible(true);
867: else
868: setVisible(false);
869: }
870:
871: public void layoutChanged(FrameEvent event) {
872: validate();
873: }
874:
875: public void closed(FrameEvent event) {
876: close();
877: }
878:
879: public void toolBarVisibilityChanged(FrameEvent event) {
880: enableToolBar(IContainer.MAIN_TOOLBAR, event.isVisible());
881: }
882:
883: public void switchedComponent(FrameEvent event) {
884: // don't do anything
885: }
886:
887: /** ******************** event listener ****************************** */
888:
889: public void addListener(IContainerListener l) {
890: listenerList.add(IContainerListener.class, l);
891: }
892:
893: public void removeListener(IContainerListener l) {
894: listenerList.remove(IContainerListener.class, l);
895: }
896:
897: public void fireComponentChanged(IFrameMediator mediator) {
898: FrameEvent e = new FrameEvent(this , mediator);
899: // Guaranteed to return a non-null array
900: Object[] listeners = listenerList.getListenerList();
901:
902: // Process the listeners last to first, notifying
903: // those that are interested in this event
904: for (int i = listeners.length - 2; i >= 0; i -= 2) {
905: if (listeners[i] == IContainerListener.class) {
906: ((IContainerListener) listeners[i + 1])
907: .switchedComponent(e);
908: }
909: }
910:
911: }
912:
913: }
|