1 package org.columba.core.gui.externaltools; 19 20 import java.awt.BorderLayout ; 21 import java.awt.Dimension ; 22 import java.awt.GridLayout ; 23 import java.awt.HeadlessException ; 24 import java.awt.event.ActionEvent ; 25 import java.awt.event.ActionListener ; 26 import java.awt.event.KeyEvent ; 27 import java.awt.event.MouseEvent ; 28 29 import javax.swing.BorderFactory ; 30 import javax.swing.JButton ; 31 import javax.swing.JComponent ; 32 import javax.swing.JDialog ; 33 import javax.swing.JFrame ; 34 import javax.swing.JLabel ; 35 import javax.swing.JList ; 36 import javax.swing.JPanel ; 37 import javax.swing.JScrollPane ; 38 import javax.swing.KeyStroke ; 39 import javax.swing.SwingConstants ; 40 import javax.swing.event.ListSelectionEvent ; 41 import javax.swing.event.ListSelectionListener ; 42 43 import org.columba.api.plugin.IExtension; 44 import org.columba.api.plugin.IExtensionHandler; 45 import org.columba.api.plugin.IExtensionHandlerKeys; 46 import org.columba.api.plugin.PluginHandlerNotFoundException; 47 import org.columba.core.gui.base.ButtonWithMnemonic; 48 import org.columba.core.gui.base.DoubleClickListener; 49 import org.columba.core.gui.base.InfoViewerDialog; 50 import org.columba.core.gui.base.SingleSideEtchedBorder; 51 import org.columba.core.gui.util.DialogHeaderPanel; 52 import org.columba.core.help.HelpManager; 53 import org.columba.core.plugin.PluginManager; 54 import org.columba.core.resourceloader.GlobalResourceLoader; 55 import org.columba.core.resourceloader.IconKeys; 56 import org.columba.core.resourceloader.ImageLoader; 57 58 import com.jgoodies.forms.layout.CellConstraints; 59 import com.jgoodies.forms.layout.FormLayout; 60 61 68 @SuppressWarnings ({"serial","serial"}) 69 public class ExternalToolsDialog extends JDialog implements ActionListener , 70 ListSelectionListener { 71 72 private static final String RESOURCE_PATH = "org.columba.core.i18n.dialog"; 73 74 IExtensionHandler handler; 75 76 protected JButton helpButton; 77 78 protected JButton closeButton; 79 80 protected JButton configButton; 81 82 protected JButton infoButton; 83 84 protected JList list; 85 86 protected String selection; 87 88 91 public ExternalToolsDialog() throws HeadlessException { 92 super(new JFrame (), true); 93 94 setTitle("External Tools"); 96 97 try { 98 handler = PluginManager.getInstance() 99 .getExtensionHandler(IExtensionHandlerKeys.ORG_COLUMBA_CORE_EXTERNALTOOLS); 100 } catch (PluginHandlerNotFoundException e) { 101 e.printStackTrace(); 102 } 103 104 initComponents(); 105 106 pack(); 107 setLocationRelativeTo(null); 108 setVisible(true); 109 } 110 111 protected void initComponents() { 112 JPanel mainPanel = new JPanel (new BorderLayout ()); 113 mainPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12)); 114 115 configButton = new ButtonWithMnemonic("Con&figure..."); 117 configButton.setActionCommand("CONFIG"); 118 configButton.addActionListener(this); 119 configButton.setEnabled(false); 120 121 infoButton = new ButtonWithMnemonic("&Details..."); 123 infoButton.setActionCommand("INFO"); 124 infoButton.addActionListener(this); 125 infoButton.setEnabled(false); 126 127 String [] ids = handler.getPluginIdList(); 128 list = new JList (ids); 129 list.addListSelectionListener(this); 130 list.addMouseListener(new DoubleClickListener() { 131 public void doubleClick(MouseEvent ev) { 132 actionPerformed(new ActionEvent (list, 0, "CONFIG")); 133 } 134 }); 135 136 getContentPane() 137 .add( 138 new DialogHeaderPanel( 139 GlobalResourceLoader.getString(RESOURCE_PATH, 140 "externaltools", "header_title"), 141 GlobalResourceLoader.getString(RESOURCE_PATH, 142 "externaltools", "header_description"), 143 ImageLoader 144 .getIcon(IconKeys.PREFERENCES)), 145 BorderLayout.NORTH); 146 147 getContentPane().add(createPanel(), BorderLayout.CENTER); 148 getContentPane().add(createBottomPanel(), BorderLayout.SOUTH); 149 150 getRootPane().setDefaultButton(closeButton); 151 getRootPane().registerKeyboardAction(this, "CLOSE", 152 KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), 153 JComponent.WHEN_IN_FOCUSED_WINDOW); 154 155 HelpManager.getInstance().enableHelpOnButton(helpButton, 157 "extending_columba_2"); 158 HelpManager.getInstance().enableHelpKey(getRootPane(), 159 "extending_columba_2"); 160 } 161 162 private JPanel createPanel() { 163 JPanel jpanel1 = new JPanel (); 164 FormLayout formlayout1 = new FormLayout( 165 "FILL:DEFAULT:GROW(1.0),3DLU,FILL:DEFAULT:NONE", 166 "CENTER:DEFAULT:NONE,1DLU,FILL:DEFAULT:GROW(1.0),3DLU,CENTER:DEFAULT:NONE"); 167 CellConstraints cc = new CellConstraints(); 168 jpanel1.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12)); 169 jpanel1.setLayout(formlayout1); 170 171 JLabel jlabel1 = new JLabel (); 172 jlabel1.setText("External Tools:"); 173 jpanel1.add(jlabel1, cc.xy(1, 1)); 174 175 JScrollPane scrollPane = new JScrollPane (list); 176 scrollPane.setPreferredSize(new Dimension (250, 150)); 177 jpanel1.add(scrollPane, cc.xy(1, 3)); 178 179 jpanel1.add(createPanel1(), new CellConstraints(3, 3, 1, 1, 180 CellConstraints.DEFAULT, CellConstraints.TOP)); 181 182 return jpanel1; 183 } 184 185 private JPanel createPanel1() { 186 JPanel jpanel1 = new JPanel (); 187 FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:NONE", 188 "CENTER:DEFAULT:NONE,3DLU,CENTER:DEFAULT:NONE,3DLU,CENTER:DEFAULT:NONE"); 189 CellConstraints cc = new CellConstraints(); 190 jpanel1.setLayout(formlayout1); 191 192 jpanel1.add(configButton, cc.xy(1, 1)); 193 194 jpanel1.add(infoButton, cc.xy(1, 3)); 195 196 return jpanel1; 197 } 198 199 private JPanel createBottomPanel() { 200 JPanel bottomPanel = new JPanel (new BorderLayout ()); 201 bottomPanel.setBorder(new SingleSideEtchedBorder(SwingConstants.TOP)); 202 203 JPanel buttonPanel = new JPanel (new GridLayout (1, 3, 6, 0)); 204 buttonPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12)); 205 206 closeButton = new ButtonWithMnemonic(GlobalResourceLoader.getString( 207 "global", "global", "close")); 208 closeButton.setActionCommand("CLOSE"); closeButton.addActionListener(this); 210 buttonPanel.add(closeButton); 211 212 helpButton = new ButtonWithMnemonic(GlobalResourceLoader.getString( 213 "global", "global", "help")); 214 215 buttonPanel.add(helpButton); 216 bottomPanel.add(buttonPanel, BorderLayout.EAST); 217 218 return bottomPanel; 219 } 220 221 public void actionPerformed(ActionEvent e) { 222 String action = e.getActionCommand(); 223 224 if (action.equals("CLOSE")) { 225 setVisible(false); 226 } else if (action.equals("CONFIG")) { 227 new ExternalToolsWizardLauncher().launchWizard(selection, false); 228 } else if (action.equals("INFO")) { 229 AbstractExternalToolsPlugin plugin = null; 230 231 try { 232 IExtension extension = handler.getExtension(selection); 233 234 plugin = (AbstractExternalToolsPlugin) extension 235 .instanciateExtension(null); 236 } catch (Exception e1) { 237 e1.printStackTrace(); 238 } 239 240 String info = plugin.getDescription(); 241 new InfoViewerDialog(info); 242 } 243 } 244 245 250 public void valueChanged(ListSelectionEvent e) { 251 boolean enabled = !list.isSelectionEmpty(); 252 configButton.setEnabled(enabled); 253 infoButton.setEnabled(enabled); 254 selection = (String ) list.getSelectedValue(); 255 } 256 } | Popular Tags |