KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > multiServer > launch > ConfPanel


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  */

22 package org.enhydra.multiServer.launch;
23 import java.awt.*;
24 import java.awt.event.*;
25 import javax.swing.*;
26 import java.io.File JavaDoc;
27 import java.beans.*;
28 public class ConfPanel extends JPanel {
29     private LocalActionListener actionListener = null;
30     private GridBagLayout layoutMain;
31     private JLabel labelHome;
32     private JTextField textHome;
33     private JButton buttonHome;
34     private JLabel labelConfFile;
35     private JTextField textConfFile;
36     private JButton buttonConfFile;
37     private JLabel labelConfDir;
38     private JTextField textConfDir;
39     private JButton buttonConfDir;
40     private JLabel labelPolicy;
41     private JTextField textPolicy;
42     private JButton buttonPolicy;
43     private JLabel labelBrowser;
44     private JTextField textBrowser;
45     private JButton buttonBrowser;
46     private JPanel panelFiller;
47     private BorderLayout layoutFiller;
48
49     public ConfPanel() {
50         try {
51             jbInit();
52             pmInit();
53         } catch (Exception JavaDoc ex) {
54             ex.printStackTrace();
55         }
56     }
57
58     protected void firstFocus() {
59         textHome.requestFocus();
60     }
61
62     protected void initPaths() {
63         textHome.setText(getApp().getHome());
64         textHome.setToolTipText(textHome.getText());
65         textConfFile.setText(getApp().getConfFile());
66         textConfFile.setToolTipText(textConfFile.getText());
67         textConfDir.setText(getApp().getConfDir());
68         textConfDir.setToolTipText(textConfDir.getText());
69         textPolicy.setText(getApp().getPolicy());
70         textPolicy.setToolTipText(textPolicy.getText());
71         textBrowser.setText(getApp().getBrowser());
72         textBrowser.setToolTipText(textBrowser.getText());
73     }
74
75     private LaunchApp getApp() {
76         return LaunchApp.app;
77     }
78
79     private void selectHome() {
80         File JavaDoc selection = null;
81
82         selection = new File JavaDoc(textHome.getText());
83         selection =
84             SwingUtil.getDirectoryChoice(this, selection,
85                                          "Select Enhydra Home Directory");
86         if (selection != null) {
87             textHome.setText(selection.getAbsolutePath());
88             textHome.setToolTipText(textConfDir.getText());
89             getApp().setHome(textHome.getText());
90         }
91     }
92
93     private void selectConfFile() {
94         File JavaDoc selection = null;
95         ExtensionFilter filter = new ExtensionFilter();
96
97         filter.setDescriptionTitle("Configuration");
98         filter.addExtension("conf");
99         selection = new File JavaDoc(textConfFile.getText());
100         selection = SwingUtil.getFileChoice(this, selection, filter,
101                                             "Select Configuration File");
102         if (selection != null) {
103             textConfFile.setText(selection.getAbsolutePath());
104             textConfFile.setToolTipText(textConfFile.getText());
105             getApp().setConfFile(textConfFile.getText());
106         }
107     }
108
109     private void selectConfDir() {
110         File JavaDoc selection = null;
111
112         selection = new File JavaDoc(textConfDir.getText());
113         selection =
114             SwingUtil.getDirectoryChoice(this, selection,
115                                          "Select Configuration Directory");
116         if (selection != null) {
117             textConfDir.setText(selection.getAbsolutePath());
118             textConfDir.setToolTipText(textConfDir.getText());
119             getApp().setConfDir(textConfDir.getText());
120         }
121     }
122
123     private void selectPolicyFile() {
124         File JavaDoc selection = null;
125         ExtensionFilter filter = new ExtensionFilter();
126
127         filter.setDescriptionTitle("Policy");
128         filter.addExtension("policy");
129         selection = new File JavaDoc(textPolicy.getText());
130         selection = SwingUtil.getFileChoice(this, selection, filter,
131                                             "Select Policy File");
132         if (selection != null) {
133             textPolicy.setText(selection.getAbsolutePath());
134             textPolicy.setToolTipText(textPolicy.getText());
135             getApp().setPolicy(textPolicy.getText());
136         }
137     }
138
139     protected void selectBrowser() {
140         File JavaDoc selection = null;
141         ExtensionFilter filter = new ExtensionFilter();
142
143         filter.setDescriptionTitle("Browser");
144         if (System.getProperty("os.name").toLowerCase().indexOf("win") > -1) {
145             filter.addExtension("exe");
146         }
147         selection = new File JavaDoc(textBrowser.getText());
148         selection = SwingUtil.getFileChoice(this, selection, filter,
149                                             "Select Web Browser");
150         if (selection != null) {
151             textBrowser.setText(selection.getAbsolutePath());
152             textBrowser.setToolTipText(textBrowser.getText());
153             getApp().setBrowser(textBrowser.getText());
154         }
155     }
156
157     private void pmInit() {
158         textHome.setPreferredSize(new Dimension(100,
159                                                 textHome.getPreferredSize().getSize().height));
160         textHome.setText(new String JavaDoc());
161         textConfFile.setPreferredSize(new Dimension(100,
162                                                     textConfFile.getPreferredSize().getSize().height));
163         textConfFile.setText(new String JavaDoc());
164         textConfDir.setPreferredSize(new Dimension(100,
165                                                    textConfDir.getPreferredSize().getSize().height));
166         textConfDir.setText(new String JavaDoc());
167         textPolicy.setPreferredSize(new Dimension(100,
168                                                   textPolicy.getPreferredSize().getSize().height));
169         textPolicy.setText(new String JavaDoc());
170         actionListener = new LocalActionListener();
171         buttonHome.addActionListener(actionListener);
172         buttonConfFile.addActionListener(actionListener);
173         buttonConfDir.addActionListener(actionListener);
174         buttonPolicy.addActionListener(actionListener);
175         buttonBrowser.addActionListener(actionListener);
176     }
177
178     private void jbInit() throws Exception JavaDoc {
179         layoutMain =
180             (GridBagLayout) Beans.instantiate(getClass().getClassLoader(),
181                                               GridBagLayout.class.getName());
182         labelHome = (JLabel) Beans.instantiate(getClass().getClassLoader(),
183                                                JLabel.class.getName());
184         labelConfFile =
185             (JLabel) Beans.instantiate(getClass().getClassLoader(),
186                                        JLabel.class.getName());
187         labelConfDir = (JLabel) Beans.instantiate(getClass().getClassLoader(),
188                                                   JLabel.class.getName());
189         labelPolicy = (JLabel) Beans.instantiate(getClass().getClassLoader(),
190                                                  JLabel.class.getName());
191         labelBrowser = (JLabel) Beans.instantiate(getClass().getClassLoader(),
192                                                   JLabel.class.getName());
193         textHome = (JTextField) Beans.instantiate(getClass().getClassLoader(),
194                                                   JTextField.class.getName());
195         textConfFile =
196             (JTextField) Beans.instantiate(getClass().getClassLoader(),
197                                            JTextField.class.getName());
198         textConfDir =
199             (JTextField) Beans.instantiate(getClass().getClassLoader(),
200                                            JTextField.class.getName());
201         textPolicy =
202             (JTextField) Beans.instantiate(getClass().getClassLoader(),
203                                            JTextField.class.getName());
204         textBrowser =
205             (JTextField) Beans.instantiate(getClass().getClassLoader(),
206                                            JTextField.class.getName());
207         buttonHome = (JButton) Beans.instantiate(getClass().getClassLoader(),
208                                                  JButton.class.getName());
209         buttonConfFile =
210             (JButton) Beans.instantiate(getClass().getClassLoader(),
211                                         JButton.class.getName());
212         buttonConfDir =
213             (JButton) Beans.instantiate(getClass().getClassLoader(),
214                                         JButton.class.getName());
215         buttonPolicy =
216             (JButton) Beans.instantiate(getClass().getClassLoader(),
217                                         JButton.class.getName());
218         buttonBrowser =
219             (JButton) Beans.instantiate(getClass().getClassLoader(),
220                                         JButton.class.getName());
221         panelFiller = (JPanel) Beans.instantiate(getClass().getClassLoader(),
222                                                  JPanel.class.getName());
223         layoutFiller =
224             (BorderLayout) Beans.instantiate(getClass().getClassLoader(),
225                                              BorderLayout.class.getName());
226         textHome.setEditable(false);
227         textConfFile.setEditable(false);
228         textConfDir.setEditable(false);
229         textPolicy.setEditable(false);
230         textBrowser.setEditable(false);
231         buttonHome.setText("...");
232         buttonConfFile.setText("...");
233         buttonConfDir.setText("...");
234         buttonPolicy.setText("...");
235         buttonBrowser.setText("...");
236         labelHome.setText("Enhydra home directory:");
237         labelHome.setDisplayedMnemonic('E');
238         labelHome.setLabelFor(textHome);
239         labelConfFile.setText("Bootstrap configuration file:");
240         labelConfFile.setDisplayedMnemonic('S');
241         labelConfFile.setLabelFor(textConfFile);
242         labelConfDir.setText("Configuration directory:");
243         labelConfDir.setDisplayedMnemonic('C');
244         labelConfDir.setLabelFor(textConfDir);
245         labelPolicy.setText("Java policy file:");
246         labelPolicy.setDisplayedMnemonic('P');
247         labelPolicy.setLabelFor(textPolicy);
248         labelBrowser.setText("Browser:");
249         labelBrowser.setDisplayedMnemonic('B');
250         labelBrowser.setLabelFor(textBrowser);
251         panelFiller.setLayout(layoutFiller);
252         this.setLayout(layoutMain);
253         this.add(labelHome,
254                  new GridBagConstraints(0, 0, 1, 1, 0.1, 0.1,
255                                         GridBagConstraints.WEST,
256                                         GridBagConstraints.HORIZONTAL,
257                                         new Insets(5, 5, 2, 5), 0, 0));
258         this.add(textHome,
259                  new GridBagConstraints(1, 0, 1, 1, 0.5, 0.5,
260                                         GridBagConstraints.CENTER,
261                                         GridBagConstraints.HORIZONTAL,
262                                         new Insets(5, 5, 2, 5), 100, 0));
263         this.add(buttonHome,
264                  new GridBagConstraints(2, 0, 1, 1, 0.1, 0.1,
265                                         GridBagConstraints.CENTER,
266                                         GridBagConstraints.NONE,
267                                         new Insets(5, 5, 2, 5), 0, 0));
268         this.add(labelConfFile,
269                  new GridBagConstraints(0, 1, 1, 1, 0.1, 0.1,
270                                         GridBagConstraints.WEST,
271                                         GridBagConstraints.HORIZONTAL,
272                                         new Insets(2, 5, 2, 5), 0, 0));
273         this.add(textConfFile,
274                  new GridBagConstraints(1, 1, 1, 1, 0.5, 0.5,
275                                         GridBagConstraints.CENTER,
276                                         GridBagConstraints.HORIZONTAL,
277                                         new Insets(2, 5, 2, 5), 100, 0));
278         this.add(buttonConfFile,
279                  new GridBagConstraints(2, 1, 1, 1, 0.1, 0.1,
280                                         GridBagConstraints.CENTER,
281                                         GridBagConstraints.NONE,
282                                         new Insets(2, 5, 2, 5), 0, 0));
283         this.add(labelConfDir,
284                  new GridBagConstraints(0, 2, 1, 1, 0.1, 0.1,
285                                         GridBagConstraints.WEST,
286                                         GridBagConstraints.HORIZONTAL,
287                                         new Insets(2, 5, 2, 5), 0, 0));
288         this.add(textConfDir,
289                  new GridBagConstraints(1, 2, 1, 1, 0.5, 0.5,
290                                         GridBagConstraints.CENTER,
291                                         GridBagConstraints.HORIZONTAL,
292                                         new Insets(2, 5, 2, 5), 100, 0));
293         this.add(buttonConfDir,
294                  new GridBagConstraints(2, 2, 1, 1, 0.1, 0.1,
295                                         GridBagConstraints.CENTER,
296                                         GridBagConstraints.NONE,
297                                         new Insets(2, 5, 2, 5), 0, 0));
298         this.add(labelPolicy,
299                  new GridBagConstraints(0, 3, 1, 1, 0.1, 0.1,
300                                         GridBagConstraints.WEST,
301                                         GridBagConstraints.HORIZONTAL,
302                                         new Insets(2, 5, 2, 5), 0, 0));
303         this.add(textPolicy,
304                  new GridBagConstraints(1, 3, 1, 1, 0.5, 0.5,
305                                         GridBagConstraints.CENTER,
306                                         GridBagConstraints.HORIZONTAL,
307                                         new Insets(2, 5, 2, 5), 100, 0));
308         this.add(buttonPolicy,
309                  new GridBagConstraints(2, 3, 1, 1, 0.1, 0.1,
310                                         GridBagConstraints.CENTER,
311                                         GridBagConstraints.NONE,
312                                         new Insets(2, 5, 2, 5), 0, 0));
313         this.add(labelBrowser,
314                  new GridBagConstraints(0, 4, 1, 1, 0.1, 0.1,
315                                         GridBagConstraints.WEST,
316                                         GridBagConstraints.HORIZONTAL,
317                                         new Insets(2, 5, 2, 5), 0, 0));
318         this.add(textBrowser,
319                  new GridBagConstraints(1, 4, 1, 1, 0.5, 0.5,
320                                         GridBagConstraints.CENTER,
321                                         GridBagConstraints.HORIZONTAL,
322                                         new Insets(2, 5, 2, 5), 100, 0));
323         this.add(buttonBrowser,
324                  new GridBagConstraints(2, 4, 1, 1, 0.1, 0.1,
325                                         GridBagConstraints.CENTER,
326                                         GridBagConstraints.NONE,
327                                         new Insets(2, 5, 2, 5), 0, 0));
328         this.add(panelFiller,
329                  new GridBagConstraints(0, 5, 3, 1, 0.5, 0.5,
330                                         GridBagConstraints.CENTER,
331                                         GridBagConstraints.BOTH,
332                                         new Insets(5, 5, 5, 5), 20, 20));
333     }
334
335     class LocalActionListener implements ActionListener {
336         public void actionPerformed(ActionEvent e) {
337             Object JavaDoc source = e.getSource();
338
339             if (source == buttonHome) {
340                 selectHome();
341             } else if (source == buttonConfFile) {
342                 selectConfFile();
343             } else if (source == buttonConfDir) {
344                 selectConfDir();
345             } else if (source == buttonPolicy) {
346                 selectPolicyFile();
347             } else if (source == buttonBrowser) {
348                 selectBrowser();
349             }
350         }
351
352     }
353 }
354
Popular Tags