/*
* Copyright 2001-2006 C:1 Financial Services GmbH
*
* This software is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License Version 2.1, as published by the Free Software Foundation.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
*/
package de.finix.contelligent.client.modules;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Iterator;
import javax.swing.Action;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JTabbedPane;
import javax.swing.JToolBar;
import de.finix.contelligent.client.gui.ContelligentAction;
import de.finix.contelligent.client.i18n.Resources;
import de.finix.contelligent.client.modules.event.ModuleAdapter;
import de.finix.contelligent.client.modules.event.ModuleEvent;
import de.finix.contelligent.client.modules.event.ModuleListener;
import de.finix.contelligent.client.util.ActionBundle;
import de.finix.contelligent.client.util.MenuAndToolbarComposer;
import de.finix.contelligent.client.util.MnemonicAbstractAction;
import de.finix.contelligent.client.util.OptionalPopupMenu;
public class ModuleFrame extends JFrame {
private Module module;
private MenuAndToolbarComposer menuAndToolbarComposer;
public ModuleFrame(String title, Module module, boolean tabbed) throws ModuleInitException {
super(title);
this.module = module;
JToolBar toolBar = new JToolBar();
toolBar.setOpaque(false);
JMenuBar menuBar = new JMenuBar();
menuBar.setOpaque(false);
if (!module.isLightweightFrame()) {
setJMenuBar(menuBar);
getContentPane().add(toolBar, BorderLayout.NORTH);
}
if (tabbed) {
JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.addTab(Resources.getLocalString("view"), Resources.genericModule, (java.awt.Component) module);
getContentPane().add(tabbedPane, BorderLayout.CENTER);
} else {
getContentPane().add((java.awt.Component) module, BorderLayout.CENTER);
}
OptionalPopupMenu popupMenu = new OptionalPopupMenu();
popupMenu.addActionGroupName(ContelligentAction.VIEW_ACTION);
popupMenu.addActionBundleName(ActionBundle.TRANSACTION_ACTIONS);
menuAndToolbarComposer = new MenuAndToolbarComposer(menuBar, toolBar, popupMenu);
menuAndToolbarComposer.addOptionalPopupMenu(popupMenu);
menuAndToolbarComposer.addTemporaryActionBundle(ActionBundle.WINDOW_ACTIONS,
new Action[] { new CloseWindowAction() });
module.setMenuAndToolbarComposer(menuAndToolbarComposer);
module.init();
menuAndToolbarComposer.addTemporaryActionBundle(ActionBundle.MODULE_ACTIONS, module.getActions());
// fire module activated event
for (Iterator i = module.getModuleListeners().iterator(); i.hasNext();) {
((ModuleListener) i.next()).moduleActivated(new ModuleEvent(module));
}
module.addModuleListener(new ModuleAdapter() {
public void moduleDestroyed(ModuleEvent event) {
// remove all action bundles from toolbar etc...
dispose();
}
});
/* Add the window listener */
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
close();
}
});
}
public MenuAndToolbarComposer getMenuAndToolbarComposer() {
return menuAndToolbarComposer;
}
public class CloseWindowAction extends MnemonicAbstractAction implements ContelligentAction {
public CloseWindowAction() {
super("close_window_action", Resources.closeWindowIcon);
putValue(TYPE, PUSH_ACTION);
putValue(ACTION_TYPE, FILE_ACTION);
putValue(ACTION_GROUP, FILE_EXIT_GROUP);
putValue(ACTION_POS, FILE_EXIT_EXIT);
putValue(MENU_TARGET, MENU);
putValue(BUTTON_TARGET, NO_BUTTON);
}
public void actionPerformed(ActionEvent e) {
close();
}
}
protected void close() {
// fire module destroyed event
for (Iterator i = module.getModuleListeners().iterator(); i.hasNext();) {
((ModuleListener) i.next()).moduleDestroyed(new ModuleEvent(module));
}
}
}
|