001: /*
002: * Copyright 2001-2006 C:1 Financial Services GmbH
003: *
004: * This software is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License Version 2.1, as published by the Free Software Foundation.
007: *
008: * This software is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public
014: * License along with this library; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016: */
017:
018: package de.finix.contelligent.client.modules;
019:
020: import java.awt.BorderLayout;
021: import java.awt.event.ActionEvent;
022: import java.awt.event.WindowAdapter;
023: import java.awt.event.WindowEvent;
024: import java.util.Iterator;
025:
026: import javax.swing.Action;
027: import javax.swing.JFrame;
028: import javax.swing.JMenuBar;
029: import javax.swing.JTabbedPane;
030: import javax.swing.JToolBar;
031:
032: import de.finix.contelligent.client.gui.ContelligentAction;
033: import de.finix.contelligent.client.i18n.Resources;
034: import de.finix.contelligent.client.modules.event.ModuleAdapter;
035: import de.finix.contelligent.client.modules.event.ModuleEvent;
036: import de.finix.contelligent.client.modules.event.ModuleListener;
037: import de.finix.contelligent.client.util.ActionBundle;
038: import de.finix.contelligent.client.util.MenuAndToolbarComposer;
039: import de.finix.contelligent.client.util.MnemonicAbstractAction;
040: import de.finix.contelligent.client.util.OptionalPopupMenu;
041:
042: public class ModuleFrame extends JFrame {
043:
044: private Module module;
045:
046: private MenuAndToolbarComposer menuAndToolbarComposer;
047:
048: public ModuleFrame(String title, Module module, boolean tabbed)
049: throws ModuleInitException {
050: super (title);
051:
052: this .module = module;
053:
054: JToolBar toolBar = new JToolBar();
055: toolBar.setOpaque(false);
056: JMenuBar menuBar = new JMenuBar();
057: menuBar.setOpaque(false);
058: if (!module.isLightweightFrame()) {
059: setJMenuBar(menuBar);
060: getContentPane().add(toolBar, BorderLayout.NORTH);
061: }
062:
063: if (tabbed) {
064: JTabbedPane tabbedPane = new JTabbedPane();
065: tabbedPane.addTab(Resources.getLocalString("view"),
066: Resources.genericModule,
067: (java.awt.Component) module);
068: getContentPane().add(tabbedPane, BorderLayout.CENTER);
069: } else {
070: getContentPane().add((java.awt.Component) module,
071: BorderLayout.CENTER);
072: }
073:
074: OptionalPopupMenu popupMenu = new OptionalPopupMenu();
075: popupMenu.addActionGroupName(ContelligentAction.VIEW_ACTION);
076: popupMenu.addActionBundleName(ActionBundle.TRANSACTION_ACTIONS);
077:
078: menuAndToolbarComposer = new MenuAndToolbarComposer(menuBar,
079: toolBar, popupMenu);
080: menuAndToolbarComposer.addOptionalPopupMenu(popupMenu);
081: menuAndToolbarComposer.addTemporaryActionBundle(
082: ActionBundle.WINDOW_ACTIONS,
083: new Action[] { new CloseWindowAction() });
084:
085: module.setMenuAndToolbarComposer(menuAndToolbarComposer);
086: module.init();
087:
088: menuAndToolbarComposer.addTemporaryActionBundle(
089: ActionBundle.MODULE_ACTIONS, module.getActions());
090:
091: // fire module activated event
092: for (Iterator i = module.getModuleListeners().iterator(); i
093: .hasNext();) {
094: ((ModuleListener) i.next())
095: .moduleActivated(new ModuleEvent(module));
096: }
097:
098: module.addModuleListener(new ModuleAdapter() {
099: public void moduleDestroyed(ModuleEvent event) {
100: // remove all action bundles from toolbar etc...
101: dispose();
102: }
103: });
104:
105: /* Add the window listener */
106: addWindowListener(new WindowAdapter() {
107: public void windowClosing(WindowEvent evt) {
108: close();
109: }
110: });
111: }
112:
113: public MenuAndToolbarComposer getMenuAndToolbarComposer() {
114: return menuAndToolbarComposer;
115: }
116:
117: public class CloseWindowAction extends MnemonicAbstractAction
118: implements ContelligentAction {
119: public CloseWindowAction() {
120: super ("close_window_action", Resources.closeWindowIcon);
121: putValue(TYPE, PUSH_ACTION);
122: putValue(ACTION_TYPE, FILE_ACTION);
123: putValue(ACTION_GROUP, FILE_EXIT_GROUP);
124: putValue(ACTION_POS, FILE_EXIT_EXIT);
125: putValue(MENU_TARGET, MENU);
126: putValue(BUTTON_TARGET, NO_BUTTON);
127: }
128:
129: public void actionPerformed(ActionEvent e) {
130: close();
131: }
132: }
133:
134: protected void close() {
135: // fire module destroyed event
136: for (Iterator i = module.getModuleListeners().iterator(); i
137: .hasNext();) {
138: ((ModuleListener) i.next())
139: .moduleDestroyed(new ModuleEvent(module));
140: }
141: }
142: }
|