/Users/lyon/j4p/src/security/WebStartDialog.java

1    package security; 
2     
3    import gui.run.RunButton; 
4    import gui.run.RunTextField; 
5     
6    import javax.swing.JDialog; 
7    import javax.swing.JLabel; 
8    import javax.swing.JPanel; 
9    import java.awt.BorderLayout; 
10   import java.awt.Container; 
11   import java.awt.FlowLayout; 
12   import java.awt.GridLayout; 
13    
14   /** 
15    * Copyright DocJava, inc. 
16    * User: lyon 
17    * Date: Sep 3, 2004 
18    * Time: 9:53:56 AM 
19    */ 
20    
21   /** 
22    * The following is a typical example of the 
23    * kind of effort needed to develop an API. 
24    * Using the BeanDialog, we can greatly speed 
25    * dialog development. 
26    */ 
27   public class WebStartDialog extends JDialog { 
28       private WebStartBean wsb = null; 
29    
30       public WebStartBean getWebStartBean() { 
31           return wsb; 
32       } 
33    
34       public WebStartDialog(WebStartBean webStartBean) { 
35           wsb = webStartBean; 
36           Container c = getContentPane(); 
37           c.setLayout(new BorderLayout()); 
38           JPanel pa[] = getPanels(); 
39           c.add(pa[0], BorderLayout.CENTER); 
40           c.add(pa[1], BorderLayout.LINE_END); 
41           c.add(getButtonPanel(this), BorderLayout.SOUTH); 
42           pack(); 
43           setModal(true); 
44       } 
45    
46       private JPanel[] getPanels() { 
47           JPanel tp = new JPanel(new GridLayout(0, 1)); 
48           int l = 40; 
49           JPanel lp = new JPanel(new GridLayout(0, 1)); 
50           JPanel pa[] = {lp, tp}; 
51           lp.add(new JLabel("vendor")); 
52           tp.add(new RunTextField(wsb.getVendor(), l) { 
53               public void run() { 
54                   wsb.setVendor(getText()); 
55               } 
56           }); 
57           lp.add(new JLabel("codeBase")); 
58           tp.add(new RunTextField(wsb.getCodeBase(), l) { 
59               public void run() { 
60                   wsb.setCodeBase(getText()); 
61               } 
62           }); 
63           lp.add(new JLabel("iconUrl")); 
64           tp.add(new RunTextField(wsb.getIconUrl(), l) { 
65               public void run() { 
66                   wsb.setIconUrl(getText()); 
67               } 
68           }); 
69           lp.add(new JLabel("hostUrl")); 
70           tp.add(new RunTextField(wsb.getHostUrl(), l) { 
71               public void run() { 
72                   wsb.setHostUrl(getText()); 
73               } 
74           }); 
75           lp.add(new JLabel("rootDirectory")); 
76           tp.add(new RunTextField(wsb.getRootDirectory(), l) { 
77               public void run() { 
78                   wsb.setRootDirectory(getText()); 
79               } 
80           }); 
81           lp.add(new JLabel("className")); 
82           tp.add(new RunTextField(wsb.getClassName(), l) { 
83               public void run() { 
84                   wsb.setClassName(getText()); 
85               } 
86           }); 
87           lp.add(new JLabel("keyStoreFile")); 
88           tp.add(new RunTextField(wsb.getKeyStoreFile().toString(), l) { 
89               public void run() { 
90                   wsb.setKeyStoreFile(getText()); 
91               } 
92           }); 
93           lp.add(new JLabel("JarFile")); 
94           tp.add(new RunTextField(wsb.getJarFileName().toString(), l) { 
95               public void run() { 
96                   wsb.setJarFileName(getText()); 
97               } 
98           }); 
99           return pa; 
100      } 
101   
102      public JPanel getButtonPanel(final JDialog parent) { 
103          JPanel jp = new JPanel(new FlowLayout()); 
104          jp.add(new RunButton("OK") { 
105              public void run() { 
106                  wsb.saveInPreferences(); 
107                  parent.setVisible(false); 
108              } 
109          }); 
110          return jp; 
111      } 
112   
113      public static void main(String[] args) { 
114          WebStartBean wsb = WebStartBean.getFromPreferences(); 
115          wsb.setClassName("className"); 
116          WebStartDialog wsd = new WebStartDialog(wsb); 
117          wsd.show(); 
118          WebStartBean webStartBean = wsd.getWebStartBean(); 
119          System.out.println("done wsd=" + webStartBean.toXml()); 
120      } 
121  } 
122