KickJava   Java API By Example, From Geeks To Geeks.

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


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 // Kelp imports
26
import org.enhydra.kelp.common.ValidationException;
27 import org.enhydra.kelp.common.ValidationUtil;
28 import org.enhydra.kelp.common.xmlc.MapPanel;
29 import org.enhydra.kelp.common.xmlc.MapDialog;
30
31 // Standard imports
32
import javax.swing.*;
33 import javax.swing.border.*;
34 import java.awt.*;
35 import java.beans.*;
36 import java.io.File JavaDoc;
37 import java.awt.event.*;
38 import java.util.ResourceBundle JavaDoc;
39
40 /**
41  * Panel for entering the default options: project name, package
42  * and destination.
43  *
44  * @author Paul Mahar
45  */

46 public class ImportMapPanel extends ImporterPanel {
47     static ResourceBundle JavaDoc res =
48         ResourceBundle.getBundle("org.enhydra.kelp.common.Res"); // nores
49
transient private MapPanel mapPanel;
50     transient private JPanel panelPack;
51     transient private JTextField textPack;
52
53     //
54
transient private JPanel panelEdit;
55     transient private GridBagLayout layoutMain;
56     transient private GridBagLayout layoutPack;
57     transient private TitledBorder borderPack;
58     transient private JButton buttonEdit;
59     transient private GridBagLayout layoutEdit;
60
61     /**
62      * Create default option panel 1 for entering the
63      * following default options: project name, package and
64      * destination.
65      */

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

82     public void readOptions() {
83         String JavaDoc pack = null;
84         String JavaDoc map[][] = new String JavaDoc[0][2];
85
86         pack = getPaths().getPackage();
87         if (pack != null) {
88             textPack.setText(pack);
89         }
90         map = getPaths().getPackageMap();
91         mapPanel.setMap(map);
92     }
93
94     /**
95      * Method declaration
96      *
97      *
98      * @see
99      */

100     public void activated() {
101         initPacks();
102     }
103
104     /**
105      * Write project name, package and destination values from the
106      * swing controls into the option set.
107      *
108      * @exception GeneratorException
109      * Thrown if unable to update option set from Swing control values.
110      */

111     public void writeOptions() throws ValidationException {
112         String JavaDoc pack = new String JavaDoc();
113         String JavaDoc[][] map = new String JavaDoc[0][2];
114
115         if (getPaths() == null) {
116             throw new ValidationException(res.getString("ImportPaths_not_set"));
117         }
118         pack = textPack.getText().trim();
119         getPaths().setPackage(pack);
120         map = mapPanel.getMap();
121         getPaths().setPackageMap(map);
122     }
123
124     /**
125      * Validate project name, package and destination values
126      * in the swing controls.
127      *
128      * @exception ValidationException
129      * Thrown if swing control values are not valid for the
130      * current option set.
131      */

132     public void validateOptions() throws ValidationException {
133         String JavaDoc value = new String JavaDoc();
134
135         // package
136
value = textPack.getText().trim();
137         if (!ValidationUtil.isJavaPackage(value)) {
138             throw new ValidationException(res.getString("Root_invalid_java"));
139         }
140     }
141
142     /**
143      * Get the title to use on the current page.
144      *
145      * @return
146      * A string to place at the top of a CodeGen wizard panel.
147      */

148     public String JavaDoc getPageTitle() {
149         return res.getString("Package_details");
150     }
151
152     /**
153      * Get the instructions for entering option values for the
154      * current page.
155      *
156      * @return
157      * A string to place below the page title.
158      */

159     public String JavaDoc getInstructions() {
160         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
161
162         buf.append(res.getString("Enter_package_details"));
163         buf.append(res.getString("All_the_application"));
164         buf.append(res.getString("defined_at_or_below"));
165         buf.append(res.getString("The_package_map_is"));
166         buf.append(res.getString("for_source_files"));
167         return buf.toString();
168     }
169
170     // /
171
// /
172

173     /**
174      * Method declaration
175      *
176      *
177      * @exception Exception
178      *
179      * @see
180      */

181     private void jbInit() throws Exception JavaDoc {
182         textPack = (JTextField) Beans.instantiate(getClass().getClassLoader(),
183                                                   JTextField.class.getName());
184         panelPack = (JPanel) Beans.instantiate(getClass().getClassLoader(),
185                                                JPanel.class.getName());
186         mapPanel = (MapPanel) Beans.instantiate(getClass().getClassLoader(),
187                                                 MapPanel.class.getName());
188         layoutPack =
189             (GridBagLayout) Beans.instantiate(getClass().getClassLoader(),
190                                               GridBagLayout.class.getName());
191         layoutMain =
192             (GridBagLayout) Beans.instantiate(getClass().getClassLoader(),
193                                               GridBagLayout.class.getName());
194         panelEdit = (JPanel) Beans.instantiate(getClass().getClassLoader(),
195                                                JPanel.class.getName());
196         buttonEdit = (JButton) Beans.instantiate(getClass().getClassLoader(),
197                                                  JButton.class.getName());
198         layoutEdit =
199             (GridBagLayout) Beans.instantiate(getClass().getClassLoader(),
200                                               GridBagLayout.class.getName());
201         panelPack.setLayout(layoutPack);
202         buttonEdit.setText(res.getString("buttonEdit_Text"));
203         buttonEdit.addActionListener(new java.awt.event.ActionListener JavaDoc() {
204             public void actionPerformed(ActionEvent e) {
205                 editPackageMap();
206             }
207
208         });
209         panelEdit.setLayout(layoutEdit);
210         panelEdit.add(buttonEdit,
211                       new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
212                                              GridBagConstraints.CENTER,
213                                              GridBagConstraints.BOTH,
214                                              new Insets(5, 5, 5, 5), 0, 0));
215         panelPack.add(textPack,
216                       new GridBagConstraints(0, 0, 1, 1, 0.1, 0.1,
217                                              GridBagConstraints.WEST,
218                                              GridBagConstraints.HORIZONTAL,
219                                              new Insets(5, 5, 5, 5), 0, 0));
220         this.setLayout(layoutMain);
221         this.add(panelPack,
222                  new GridBagConstraints(0, 0, 1, 1, 0.1, 0.0,
223                                         GridBagConstraints.CENTER,
224                                         GridBagConstraints.BOTH,
225                                         new Insets(5, 5, 5, 5), 0, 0));
226         this.add(mapPanel,
227                  new GridBagConstraints(0, 1, 1, 1, 0.1, 0.1,
228                                         GridBagConstraints.CENTER,
229                                         GridBagConstraints.BOTH,
230                                         new Insets(5, 5, 5, 5), 0, 0));
231         this.add(panelEdit,
232                  new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,
233                                         GridBagConstraints.CENTER,
234                                         GridBagConstraints.BOTH,
235                                         new Insets(5, 5, 5, 5), 0, 0));
236     }
237
238     /**
239      * Method declaration
240      *
241      *
242      * @see
243      */

244     private void pmInit() {
245         Border border = BorderFactory.createEtchedBorder();
246
247         borderPack = BorderFactory.createTitledBorder(border);
248         borderPack.setTitle(res.getString("borderPack_Title"));
249         panelPack.setBorder(borderPack);
250         textPack.setText(new String JavaDoc());
251     }
252
253     /**
254      * Method declaration
255      *
256      *
257      * @see
258      */

259     private void initPacks() {
260         String JavaDoc pack = null;
261         String JavaDoc[][] map = new String JavaDoc[0][2];
262
263         if (textPack.getText().trim().length() == 0) {
264             pack = getPaths().getDefaultPackage();
265             if (pack != null) {
266                 try {
267                     getPaths().setPackage(pack);
268                 } catch (ValidationException e) {
269                     e.printStackTrace();
270                 }
271                 textPack.setText(pack);
272             }
273         }
274         if (mapPanel.getMap().length == 0) {
275             getPaths().initPackageMap(false);
276             map = getPaths().getPackageMap();
277             mapPanel.setMap(map);
278         }
279     }
280
281     private void editPackageMap() {
282         MapDialog dialog =
283             new MapDialog(((JDialog) this.getTopLevelAncestor()),
284                           res.getString("Edit_Package_Map"), true);
285
286         getPaths().getProject().setPackageMap(mapPanel.getMap());
287         dialog.setProject(getPaths().getProject());
288         dialog.show();
289         mapPanel.setMap(getPaths().getProject().getPackageMap());
290         getPaths().setPackageMap(mapPanel.getMap());
291     }
292
293 }
294
Popular Tags