001: //The contents of this file are subject to the Mozilla Public License Version 1.1
002: //(the "License"); you may not use this file except in compliance with the
003: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004: //
005: //Software distributed under the License is distributed on an "AS IS" basis,
006: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007: //for the specific language governing rights and
008: //limitations under the License.
009: //
010: //The Original Code is "The Columba Project"
011: //
012: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
014: //
015: //All Rights Reserved.
016:
017: package org.columba.core.gui.plugin;
018:
019: import java.awt.BorderLayout;
020: import java.awt.GridLayout;
021: import java.awt.event.ActionEvent;
022: import java.awt.event.ActionListener;
023: import java.awt.event.KeyEvent;
024:
025: import javax.swing.BorderFactory;
026: import javax.swing.JButton;
027: import javax.swing.JComponent;
028: import javax.swing.JDialog;
029: import javax.swing.JFrame;
030: import javax.swing.JPanel;
031: import javax.swing.KeyStroke;
032: import javax.swing.SwingConstants;
033:
034: import org.columba.api.plugin.IExtension;
035: import org.columba.api.plugin.IExtensionHandler;
036: import org.columba.api.plugin.IExtensionHandlerKeys;
037: import org.columba.api.plugin.PluginException;
038: import org.columba.api.plugin.PluginHandlerNotFoundException;
039: import org.columba.api.plugin.PluginLoadingFailedException;
040: import org.columba.core.gui.base.ButtonWithMnemonic;
041: import org.columba.core.gui.base.SingleSideEtchedBorder;
042: import org.columba.core.help.HelpManager;
043: import org.columba.core.plugin.PluginManager;
044: import org.columba.core.resourceloader.GlobalResourceLoader;
045:
046: /**
047: * @author frd
048: */
049:
050: public class ConfigurationDialog extends JDialog implements
051: ActionListener {
052: protected JButton okButton;
053:
054: protected JButton cancelButton;
055:
056: protected JButton helpButton;
057:
058: protected String pluginId;
059:
060: protected AbstractConfigPlugin plugin;
061:
062: protected JPanel pluginPanel;
063:
064: public ConfigurationDialog(String pluginId)
065: throws PluginHandlerNotFoundException,
066: PluginLoadingFailedException {
067: // modal dialog
068: super ((JFrame) null, true);
069:
070: IExtensionHandler h = PluginManager.getInstance()
071: .getExtensionHandler(
072: IExtensionHandlerKeys.ORG_COLUMBA_CORE_CONFIG);
073:
074: IExtension extension = h.getExtension(pluginId);
075: try {
076: plugin = (AbstractConfigPlugin) extension
077: .instanciateExtension(null);
078: } catch (PluginException e) {
079: // TODO Auto-generated catch block
080: e.printStackTrace();
081: }
082:
083: pluginPanel = plugin.createPanel();
084:
085: initComponents();
086:
087: // model->view
088: plugin.updateComponents(true);
089:
090: pack();
091: setLocationRelativeTo(null);
092: }
093:
094: protected void initComponents() {
095: JPanel mainPanel = new JPanel();
096: mainPanel.setLayout(new BorderLayout());
097: mainPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12,
098: 12));
099: getContentPane().add(mainPanel);
100:
101: // centerpanel
102: JPanel centerPanel = new JPanel(new BorderLayout());
103:
104: // centerPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
105: centerPanel.add(pluginPanel);
106: mainPanel.add(centerPanel, BorderLayout.CENTER);
107:
108: JPanel bottomPanel = new JPanel(new BorderLayout());
109: bottomPanel.setBorder(new SingleSideEtchedBorder(
110: SwingConstants.TOP));
111:
112: JPanel buttonPanel = new JPanel(new GridLayout(1, 3, 6, 0));
113: buttonPanel.setBorder(BorderFactory.createEmptyBorder(12, 12,
114: 12, 12));
115: okButton = new ButtonWithMnemonic(GlobalResourceLoader
116: .getString("global", "global", "ok"));
117: okButton.setActionCommand("OK");
118: okButton.addActionListener(this );
119: buttonPanel.add(okButton);
120:
121: ButtonWithMnemonic cancelButton = new ButtonWithMnemonic(
122: GlobalResourceLoader.getString("global", "global",
123: "cancel"));
124: cancelButton.setActionCommand("CANCEL");
125: cancelButton.addActionListener(this );
126: buttonPanel.add(cancelButton);
127: helpButton = new ButtonWithMnemonic(GlobalResourceLoader
128: .getString("global", "global", "help"));
129: buttonPanel.add(helpButton);
130:
131: bottomPanel.add(buttonPanel, BorderLayout.EAST);
132: getContentPane().add(bottomPanel, BorderLayout.SOUTH);
133:
134: // setContentPane(mainPanel);
135: getRootPane().setDefaultButton(okButton);
136: getRootPane().registerKeyboardAction(this , "CANCEL",
137: KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
138: JComponent.WHEN_IN_FOCUSED_WINDOW);
139:
140: // associate with JavaHelp
141: HelpManager.getInstance().enableHelpOnButton(helpButton,
142: "extending_columba_1");
143: HelpManager.getInstance().enableHelpKey(getRootPane(),
144: "extending_columba_1");
145: }
146:
147: public void actionPerformed(ActionEvent e) {
148: String action = e.getActionCommand();
149:
150: if (action.equals("OK")) {
151: // view -> model
152: plugin.updateComponents(false);
153:
154: setVisible(false);
155: } else if (action.equals("CANCEL")) {
156: setVisible(false);
157: }
158: }
159: }
|