1 17 package org.columba.core.gui.plugin; 18 19 import java.awt.BorderLayout ; 20 import java.awt.GridLayout ; 21 import java.awt.event.ActionEvent ; 22 import java.awt.event.ActionListener ; 23 import java.awt.event.KeyEvent ; 24 25 import javax.swing.BorderFactory ; 26 import javax.swing.JButton ; 27 import javax.swing.JComponent ; 28 import javax.swing.JDialog ; 29 import javax.swing.JFrame ; 30 import javax.swing.JPanel ; 31 import javax.swing.KeyStroke ; 32 import javax.swing.SwingConstants ; 33 34 import org.columba.api.plugin.IExtension; 35 import org.columba.api.plugin.IExtensionHandler; 36 import org.columba.api.plugin.IExtensionHandlerKeys; 37 import org.columba.api.plugin.PluginException; 38 import org.columba.api.plugin.PluginHandlerNotFoundException; 39 import org.columba.api.plugin.PluginLoadingFailedException; 40 import org.columba.core.gui.base.ButtonWithMnemonic; 41 import org.columba.core.gui.base.SingleSideEtchedBorder; 42 import org.columba.core.help.HelpManager; 43 import org.columba.core.plugin.PluginManager; 44 import org.columba.core.resourceloader.GlobalResourceLoader; 45 46 49 50 public class ConfigurationDialog extends JDialog implements ActionListener { 51 protected JButton okButton; 52 53 protected JButton cancelButton; 54 55 protected JButton helpButton; 56 57 protected String pluginId; 58 59 protected AbstractConfigPlugin plugin; 60 61 protected JPanel pluginPanel; 62 63 public ConfigurationDialog(String pluginId) 64 throws PluginHandlerNotFoundException, PluginLoadingFailedException { 65 super((JFrame ) null, true); 67 68 IExtensionHandler h = PluginManager 69 .getInstance().getExtensionHandler(IExtensionHandlerKeys.ORG_COLUMBA_CORE_CONFIG); 70 71 IExtension extension = h.getExtension(pluginId); 72 try { 73 plugin = (AbstractConfigPlugin) extension.instanciateExtension(null); 74 } catch (PluginException e) { 75 e.printStackTrace(); 77 } 78 79 pluginPanel = plugin.createPanel(); 80 81 initComponents(); 82 83 plugin.updateComponents(true); 85 86 pack(); 87 setLocationRelativeTo(null); 88 } 89 90 protected void initComponents() { 91 JPanel mainPanel = new JPanel (); 92 mainPanel.setLayout(new BorderLayout ()); 93 mainPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12)); 94 getContentPane().add(mainPanel); 95 96 JPanel centerPanel = new JPanel (new BorderLayout ()); 98 99 centerPanel.add(pluginPanel); 101 mainPanel.add(centerPanel, BorderLayout.CENTER); 102 103 JPanel bottomPanel = new JPanel (new BorderLayout ()); 104 bottomPanel.setBorder(new SingleSideEtchedBorder(SwingConstants.TOP)); 105 106 JPanel buttonPanel = new JPanel (new GridLayout (1, 3, 6, 0)); 107 buttonPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12)); 108 okButton = new ButtonWithMnemonic(GlobalResourceLoader.getString( 109 "global", "global", "ok")); 110 okButton.setActionCommand("OK"); 111 okButton.addActionListener(this); 112 buttonPanel.add(okButton); 113 114 ButtonWithMnemonic cancelButton = new ButtonWithMnemonic( 115 GlobalResourceLoader.getString("global", "global", "cancel")); 116 cancelButton.setActionCommand("CANCEL"); 117 cancelButton.addActionListener(this); 118 buttonPanel.add(cancelButton); 119 helpButton = new ButtonWithMnemonic(GlobalResourceLoader.getString( 120 "global", "global", "help")); 121 buttonPanel.add(helpButton); 122 123 bottomPanel.add(buttonPanel, BorderLayout.EAST); 124 getContentPane().add(bottomPanel, BorderLayout.SOUTH); 125 126 getRootPane().setDefaultButton(okButton); 128 getRootPane().registerKeyboardAction(this, "CANCEL", 129 KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), 130 JComponent.WHEN_IN_FOCUSED_WINDOW); 131 132 HelpManager.getInstance().enableHelpOnButton(helpButton, 134 "extending_columba_1"); 135 HelpManager.getInstance().enableHelpKey(getRootPane(), 136 "extending_columba_1"); 137 } 138 139 public void actionPerformed(ActionEvent e) { 140 String action = e.getActionCommand(); 141 142 if (action.equals("OK")) { 143 plugin.updateComponents(false); 145 146 setVisible(false); 147 } else if (action.equals("CANCEL")) { 148 setVisible(false); 149 } 150 } 151 } 152 | Popular Tags |