KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > common > importer > RootPanel


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  * Paul Mahar
21  *
22  */

23 package org.enhydra.kelp.common.importer;
24
25 // ToolBox imports
26
import org.enhydra.tool.common.SwingUtil;
27 import org.enhydra.tool.common.PathHandle;
28
29 // Kelp imports
30
import org.enhydra.kelp.common.ValidationUtil;
31 import org.enhydra.kelp.common.ValidationException;
32
33 // Standard imports
34
import javax.swing.*;
35 import javax.swing.border.*;
36 import java.awt.*;
37 import java.awt.event.ActionEvent JavaDoc;
38 import java.awt.event.ActionListener JavaDoc;
39 import java.beans.*;
40 import java.io.File JavaDoc;
41 import java.util.ResourceBundle JavaDoc;
42
43 /**
44  * Panel for entering the default options: project name, package
45  * and destination.
46  *
47  * @author Paul Mahar
48  */

49 public class RootPanel extends ImporterPanel {
50     static ResourceBundle JavaDoc res =
51         ResourceBundle.getBundle("org.enhydra.kelp.common.Res"); // nores
52
transient private JPanel panelRoot;
53     transient private JTextField textRoot;
54     transient private JButton buttonRoot;
55
56     //
57
transient private JPanel panelFiller;
58     transient private GridBagLayout layoutMain;
59     transient private GridBagLayout layoutRoot;
60     transient private LocalButtonListener buttonListener;
61     transient private TitledBorder borderRoot;
62
63     /**
64      * Create default option panel 1 for entering the
65      * following default options: project name, package and
66      * destination.
67      */

68     public RootPanel() {
69         try {
70             jbInit();
71             pmInit();
72         } catch (Exception JavaDoc ex) {
73             ex.printStackTrace();
74         }
75     }
76
77     /**
78      * Read project name, package and destination values from the
79      * option set into the swing controls.
80      *
81      * @exception GeneratorException
82      * Thrown if unable to update Swing controls with option set values.
83      */

84     public void readOptions() {
85         String JavaDoc path;
86
87         // project root
88
path = getPaths().getRootPath();
89         if (path == null) {
90             textRoot.setText(new String JavaDoc());
91         } else {
92             textRoot.setText(path);
93         }
94     }
95
96     /**
97      * Write project name, package and destination values from the
98      * swing controls into the option set.
99      *
100      * @exception GeneratorException
101      * Thrown if unable to update option set from Swing control values.
102      */

103     public void writeOptions() throws ValidationException {
104         String JavaDoc path = null;
105
106         if (getPaths() == null) {
107             throw new ValidationException(res.getString("Import_paths_not_set1"));
108         }
109
110         // root
111
path = textRoot.getText();
112         getPaths().setRootPath(path);
113     }
114
115     /**
116      * Validate project name, package and destination values
117      * in the swing controls.
118      *
119      * @exception ValidationException
120      * Thrown if swing control values are not valid for the
121      * current option set.
122      */

123     public void validateOptions() throws ValidationException {
124         String JavaDoc value = new String JavaDoc();
125
126         // project name
127
value = textRoot.getText().trim();
128         if (!ValidationUtil.isDirectory(value)) {
129             throw new ValidationException(res.getString("Project_directory_is")
130                                           + res.getString("Directory_not_found_"));
131         }
132     }
133
134     /**
135      * Get the title to use on the current page.
136      *
137      * @return
138      * A string to place at the top of a CodeGen wizard panel.
139      */

140     public String JavaDoc getPageTitle() {
141         return res.getString("Project_Directory");
142     }
143
144     /**
145      * Get the instructions for entering option values for the
146      * current page.
147      *
148      * @return
149      * A string to place below the page title.
150      */

151     public String JavaDoc getInstructions() {
152         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
153
154         buf.append(res.getString("RootInstruct1"));
155         buf.append(res.getString("RootInstruct2"));
156         buf.append(res.getString("RootInstruct3"));
157         return buf.toString();
158     }
159
160     //
161
// PRIVATE
162
//
163

164     /**
165      * Method declaration
166      *
167      *
168      * @exception Exception
169      */

170     private void jbInit() throws Exception JavaDoc {
171         textRoot = (JTextField) Beans.instantiate(getClass().getClassLoader(),
172                                                   JTextField.class.getName());
173         panelRoot = (JPanel) Beans.instantiate(getClass().getClassLoader(),
174                                                JPanel.class.getName());
175         layoutRoot =
176             (GridBagLayout) Beans.instantiate(getClass().getClassLoader(),
177                                               GridBagLayout.class.getName());
178         buttonRoot = (JButton) Beans.instantiate(getClass().getClassLoader(),
179                                                  JButton.class.getName());
180         layoutMain =
181             (GridBagLayout) Beans.instantiate(getClass().getClassLoader(),
182                                               GridBagLayout.class.getName());
183         panelFiller = (JPanel) Beans.instantiate(getClass().getClassLoader(),
184                                                  JPanel.class.getName());
185         buttonRoot.setText("..."); // nores
186
panelRoot.setLayout(layoutRoot);
187         panelRoot.add(textRoot,
188                       new GridBagConstraints(0, 0, 1, 1, 0.1, 0.1,
189                                              GridBagConstraints.WEST,
190                                              GridBagConstraints.HORIZONTAL,
191                                              new Insets(5, 5, 5, 5), 0, 0));
192         panelRoot.add(buttonRoot,
193                       new GridBagConstraints(1, 0, 1, 2, 0.0, 0.0,
194                                              GridBagConstraints.CENTER,
195                                              GridBagConstraints.NONE,
196                                              new Insets(5, 5, 5, 20), 0, 0));
197         this.setLayout(layoutMain);
198         this.add(panelRoot,
199                  new GridBagConstraints(0, 0, 1, 1, 0.1, 0.1,
200                                         GridBagConstraints.CENTER,
201                                         GridBagConstraints.BOTH,
202                                         new Insets(5, 5, 5, 5), 0, 0));
203     }
204
205     /**
206      */

207     private void pmInit() {
208         Border border = BorderFactory.createEtchedBorder();
209
210         borderRoot = BorderFactory.createTitledBorder(border);
211         borderRoot.setTitle(res.getString("borderRoot_Title"));
212         panelRoot.setBorder(borderRoot);
213         buttonListener = new LocalButtonListener();
214         buttonRoot.addActionListener(buttonListener);
215         textRoot.setText(new String JavaDoc());
216     }
217
218     /**
219      */

220     private void browseForDirectory() {
221         File JavaDoc dir = null;
222
223         dir =
224             SwingUtil.getDirectoryChoice(this, textRoot.getText(),
225                                          res.getString("Choose_the_project"));
226         if (dir != null) {
227             textRoot.setText(PathHandle.createPathString(dir));
228         }
229     }
230
231     /**
232      */

233     private class LocalButtonListener implements ActionListener JavaDoc {
234         public void actionPerformed(ActionEvent JavaDoc event) {
235             browseForDirectory();
236         }
237
238     }
239 }
240
Popular Tags