KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > common > xmlc > MapEditorDialog


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.xmlc;
24
25 // ToolBox imports
26
import org.enhydra.tool.common.PathHandle;
27 import org.enhydra.tool.common.SwingUtil;
28
29 // Kelp imports
30
import org.enhydra.kelp.common.node.OtterProject;
31
32 // Standard imports
33
import javax.swing.*;
34 import java.awt.*;
35 import java.awt.event.*;
36 import java.io.*;
37 import java.beans.*;
38 import java.util.ResourceBundle JavaDoc;
39
40 /**
41  * Class declaration
42  *
43  *
44  * @author Paul Mahar
45  */

46 public class MapEditorDialog extends JDialog {
47     static ResourceBundle JavaDoc res =
48         ResourceBundle.getBundle("org.enhydra.kelp.common.Res"); // nores
49
public static final int ACTION_OK = 0;
50     public static final int ACTION_CANCEL = 1;
51     private static File startFolder = null;
52     private int option = ACTION_CANCEL;
53     private LocalButtonListener buttonListener = null;
54     private JPanel panelMain = new JPanel();
55     private GridBagLayout layoutMain;
56     private JPanel panelEntry;
57     private GridBagLayout layoutEntry;
58     private JPanel panelButtons;
59     private GridBagLayout layoutButton;
60     private JLabel labelFolder;
61     private JTextField textFolder;
62     private JButton buttonBrowse;
63     private JLabel labelPackage;
64     private JTextField textPackage;
65     private JButton buttonCancel;
66     private JButton buttonOK;
67     private OtterProject project;
68
69     /**
70      * Constructor declaration
71      *
72      *
73      * @param owner
74      * @param title
75      * @param modal
76      */

77     public MapEditorDialog(Frame owner, String JavaDoc title, boolean modal) {
78         super(owner, title, modal);
79         construct();
80     }
81
82     public MapEditorDialog(JDialog owner, String JavaDoc title, boolean modal) {
83         super(owner, title, modal);
84         construct();
85     }
86
87     private void construct() {
88         try {
89             jbInit();
90             pmInit();
91             pack();
92         } catch (Exception JavaDoc ex) {
93             ex.printStackTrace();
94         }
95     }
96
97     /**
98      * Constructor declaration
99      *
100      */

101     public MapEditorDialog() {
102         this(new Frame(), new String JavaDoc(), false);
103     }
104
105     /**
106      * Method declaration
107      *
108      */

109     public void show() {
110         setResizable(false);
111         Point cPoint;
112
113         invalidate();
114         doLayout();
115         pack();
116         cPoint = SwingUtil.getCenteringPoint(getSize());
117         setLocation(cPoint);
118         super.show();
119     }
120
121     /**
122      * Method declaration
123      *
124      */

125     private void pmInit() {
126         buttonListener = new LocalButtonListener();
127         buttonBrowse.addActionListener(buttonListener);
128         buttonOK.addActionListener(buttonListener);
129         buttonCancel.addActionListener(buttonListener);
130         textFolder.setText(new String JavaDoc());
131         textPackage.setText(new String JavaDoc());
132     }
133
134     /**
135      * Method declaration
136      *
137      *
138      * @throws Exception
139      */

140     private void jbInit() throws Exception JavaDoc {
141         layoutMain =
142             (GridBagLayout) Beans.instantiate(getClass().getClassLoader(),
143                                               GridBagLayout.class.getName());
144         panelEntry = (JPanel) Beans.instantiate(getClass().getClassLoader(),
145                                                 JPanel.class.getName());
146         layoutEntry =
147             (GridBagLayout) Beans.instantiate(getClass().getClassLoader(),
148                                               GridBagLayout.class.getName());
149         panelButtons = (JPanel) Beans.instantiate(getClass().getClassLoader(),
150                                                   JPanel.class.getName());
151         layoutButton =
152             (GridBagLayout) Beans.instantiate(getClass().getClassLoader(),
153                                               GridBagLayout.class.getName());
154         labelFolder = (JLabel) Beans.instantiate(getClass().getClassLoader(),
155                                                  JLabel.class.getName());
156         textFolder =
157             (JTextField) Beans.instantiate(getClass().getClassLoader(),
158                                            JTextField.class.getName());
159         buttonBrowse =
160             (JButton) Beans.instantiate(getClass().getClassLoader(),
161                                         JButton.class.getName());
162         labelPackage = (JLabel) Beans.instantiate(getClass().getClassLoader(),
163                                                   JLabel.class.getName());
164         textPackage =
165             (JTextField) Beans.instantiate(getClass().getClassLoader(),
166                                            JTextField.class.getName());
167         buttonCancel =
168             (JButton) Beans.instantiate(getClass().getClassLoader(),
169                                         JButton.class.getName());
170         buttonOK = (JButton) Beans.instantiate(getClass().getClassLoader(),
171                                                JButton.class.getName());
172         panelMain.setLayout(layoutMain);
173         panelEntry.setLayout(layoutEntry);
174         panelButtons.setLayout(layoutButton);
175         labelFolder.setText(res.getString("labelFolder_Text"));
176         textFolder.setPreferredSize(new Dimension(250, 21));
177         buttonBrowse.setText(res.getString("Browse"));
178         labelPackage.setText(res.getString("labelPackage_Text"));
179         textPackage.setPreferredSize(new Dimension(250, 21));
180         buttonCancel.setText(res.getString("Cancel"));
181         buttonOK.setText(res.getString("OK"));
182         getContentPane().add(panelMain);
183         panelMain.add(panelEntry,
184                       new GridBagConstraints(0, 0, 1, 1, 0.2, 0.2,
185                                              GridBagConstraints.CENTER,
186                                              GridBagConstraints.BOTH,
187                                              new Insets(0, 0, 0, 0), 0, 0));
188         panelEntry.add(labelFolder,
189                        new GridBagConstraints(0, 0, 1, 1, 0.2, 0.2,
190                                               GridBagConstraints.WEST,
191                                               GridBagConstraints.HORIZONTAL,
192                                               new Insets(5, 5, 5, 5), 0, 0));
193         panelEntry.add(textFolder,
194                        new GridBagConstraints(0, 1, 1, 1, 0.4, 0.4,
195                                               GridBagConstraints.WEST,
196                                               GridBagConstraints.HORIZONTAL,
197                                               new Insets(5, 5, 5, 5), 200,
198                                               0));
199         panelEntry.add(buttonBrowse,
200                        new GridBagConstraints(1, 1, 1, 1, 0.2, 0.2,
201                                               GridBagConstraints.CENTER,
202                                               GridBagConstraints.NONE,
203                                               new Insets(5, 5, 5, 5), 0, 0));
204         panelEntry.add(labelPackage,
205                        new GridBagConstraints(0, 2, 1, 1, 0.2, 0.2,
206                                               GridBagConstraints.WEST,
207                                               GridBagConstraints.HORIZONTAL,
208                                               new Insets(5, 5, 5, 5), 0, 0));
209         panelEntry.add(textPackage,
210                        new GridBagConstraints(0, 3, 1, 1, 0.4, 0.4,
211                                               GridBagConstraints.WEST,
212                                               GridBagConstraints.HORIZONTAL,
213                                               new Insets(5, 5, 5, 5), 200,
214                                               0));
215         panelMain.add(panelButtons,
216                       new GridBagConstraints(0, 1, 1, 1, 0.2, 0.2,
217                                              GridBagConstraints.CENTER,
218                                              GridBagConstraints.BOTH,
219                                              new Insets(5, 5, 5, 0), 0, 0));
220         panelButtons.add(buttonOK,
221                          new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
222                                                 GridBagConstraints.CENTER,
223                                                 GridBagConstraints.NONE,
224                                                 new Insets(5, 5, 5, 5), 0,
225                                                 0));
226         panelButtons.add(buttonCancel,
227                          new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
228                                                 GridBagConstraints.CENTER,
229                                                 GridBagConstraints.NONE,
230                                                 new Insets(5, 5, 5, 5), 0,
231                                                 0));
232     }
233
234     /**
235      * Method declaration
236      *
237      */

238     protected void closeDialog() {
239         setVisible(false);
240         removeAll();
241         dispose();
242     }
243
244     /**
245      * Method declaration
246      *
247      *
248      * @return
249      */

250     protected int getOption() {
251         return option;
252     }
253
254     /**
255      * Method declaration
256      *
257      *
258      * @return
259      */

260     protected String JavaDoc getFolder() {
261         return textFolder.getText();
262     }
263
264     protected void setFolder(String JavaDoc folder) {
265         textFolder.setText(folder);
266     }
267
268     protected void setProject(OtterProject p) {
269         project = p;
270     }
271
272     protected OtterProject getProject() {
273         return project;
274     }
275
276     /**
277      * Method declaration
278      *
279      *
280      * @return
281      */

282     protected String JavaDoc getPackageName() {
283         return textPackage.getText();
284     }
285
286     protected void setPackageName(String JavaDoc pack) {
287         textPackage.setText(pack);
288     }
289
290     /**
291      * Method declaration
292      *
293      *
294      * @param o
295      */

296     private void setOption(int o) {
297         option = o;
298     }
299
300     /**
301      * Method declaration
302      *
303      */

304     private void browseAction() {
305         File choice;
306
307         if (startFolder == null ||!startFolder.exists()) {
308             if (textFolder.getText().trim().length() == 0) {
309                 startFolder = new File(getProject().getRootPath());
310                 //
311
} else {
312                 startFolder = new File(textFolder.getText());
313             }
314         }
315         choice =
316             SwingUtil.getDirectoryChoice(this, startFolder,
317                                          res.getString("Select_directory_to"));
318         buttonBrowse.requestFocus();
319         if (choice != null) {
320             textFolder.setText(PathHandle.createPathString(choice));
321             startFolder = choice; // persist this choice for next call
322
}
323     }
324
325     /**
326      * Class declaration
327      *
328      *
329      * @author
330      * @version %I%, %G%
331      */

332     class LocalButtonListener implements ActionListener {
333
334         /**
335          * Method declaration
336          *
337          *
338          * @param event
339          */

340         public void actionPerformed(ActionEvent event) {
341             Object JavaDoc source = event.getSource();
342
343             if (source == buttonBrowse) {
344                 browseAction();
345             } else if (source == buttonOK) {
346                 setOption(ACTION_OK);
347                 closeDialog();
348             } else if (source == buttonCancel) {
349                 setOption(ACTION_CANCEL);
350                 closeDialog();
351             }
352         }
353
354     }
355 }
356
Popular Tags