/Users/lyon/j4p/src/javagroup/tools/processmanager/LaunchProcessPanel.java

1    // -*- c-basic-offset: 2 -*- 
2     
3    package javagroup.tools.processmanager; 
4     
5    import javagroup.process.ProcessCreationException; 
6    import javagroup.process.ProcessManagerHolder; 
7    import javagroup.swing.HistoryComboModel; 
8     
9    import javax.swing.*; 
10   import java.awt.*; 
11   import java.awt.event.ActionEvent; 
12   import java.awt.event.ActionListener; 
13    
14   public class LaunchProcessPanel extends JPanel implements ActionListener { 
15       /** 
16        * History of commands that have been entered into the combo box * 
17        */ 
18       protected HistoryComboModel _comboModel; 
19       protected JComboBox _classNameField; 
20       protected JButton _launchButton; 
21    
22       public LaunchProcessPanel() { 
23    
24           instantiateComponents(); 
25           addAndLayoutComponents(); 
26           registerListeners(); 
27    
28       } 
29    
30       protected void instantiateComponents() { 
31           _comboModel = new HistoryComboModel(); 
32           _classNameField = new JComboBox(_comboModel); 
33    
34           _classNameField.setEditable(true); 
35           _launchButton = new JButton("Launch"); 
36       } 
37    
38       protected void addAndLayoutComponents() { 
39    
40           GridBagLayout gridbag = new GridBagLayout(); 
41           GridBagConstraints constraints = new GridBagConstraints(); 
42    
43           this.setLayout(gridbag); 
44    
45           constraints.anchor = GridBagConstraints.NORTH; 
46           constraints.fill = GridBagConstraints.HORIZONTAL; 
47           constraints.weightx = 1.0; 
48           constraints.weighty = 0.0; 
49           gridbag.setConstraints(_classNameField, constraints); 
50           add(_classNameField); 
51    
52           constraints.fill = GridBagConstraints.NONE; 
53           constraints.gridheight = GridBagConstraints.REMAINDER; 
54           constraints.weightx = 0.0; 
55    
56           gridbag.setConstraints(_launchButton, constraints); 
57           add(_launchButton); 
58    
59       } 
60    
61       protected void registerListeners() { 
62           _launchButton.addActionListener(this); 
63       } 
64    
65       protected void showErrorDialog(Exception e) { 
66           System.out.println(e); 
67       } 
68    
69       public void actionPerformed(ActionEvent event) { 
70           String class_info = (String) _classNameField.getSelectedItem(); 
71    
72           try { 
73               _comboModel.addToHistory(class_info); 
74               ProcessManagerHolder.getProcessManager() 
75                       .createProcessFromString(class_info).launch(); 
76           } catch (ProcessCreationException e) { 
77               showErrorDialog(e); 
78           } 
79       } 
80   } 
81